Category Archives: Micro-Controller

Fixing avrdude stk500v2_ReceiveMessage(): timeout on Mega 2560 board with CH340G on Linuxmint 19


If you have a Mega 2560 clone with CH340G chip, you might encounter this problem when trying to Upload your sketch on Mega 2560 through USB to serial interface.

Using Port : /dev/ttyUSB0
Using Programmer : wiring
Overriding Baud Rate : 115200
avrdude: stk500v2_ReceiveMessage(): timeout
stk500v2_ReceiveMessage(): timeout on Mega 2560

It seem the latest version of stk500boot_v2_mega2560.hex fixed some bugs and created more headache for us that use clones.

I encountered this problem in an environment where I have two identical setup with Mega 2560 with RAMP 1.4 shield both uses CH340G chip. One seem to work fine when uploading Repetier Firmware through USB port and the other giving the above error messages.

There was a recent bugs fixes in Mega 2560 bootloader stk500boot_v2_mega2560.hex which fixed some bugs but now is preventing uploading sketch to Mega 2560 through the USB port. Which is a real pain as the ass.

Whenever you use Arduino to flash the bootloader your Mega 2560 will be flashed with the stk500boot_v2_mega2560.hex. Which will break your Mega 2560 board. This is confirmed Arduino 1.8.7 and 1.8.8 releases.

What you need to do is manually flash the Mega 2560 clone with older working version with a USBasp.

$/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino14/bin/avrdude -C$/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino14/etc/avrdude.conf -v -patmega2560 -cusbasp -Pusb -Uflash:w:$/arduino-1.8.8/hardware/arduino/avr/bootloaders/stk500v2/Mega2560-prod-firmware-2011-06-29.hex:i -Ulock:w:0x0F:m

$/arduino-1.8.8/hardware/arduino/avr/bootloaders/stk500v2/
or
https://github.com/arduino-org/Arduino/tree/master/hardware/arduino/avr/bootloaders/stk500v2

Environments:

Linuxmint 19.1
CH341 default module
Arduino 1.8.8
USBasp v2 with usbasp.atmega8.2011-05-28.hex updated firmware
Mega 2560 with CH340G

 

 

 

Advertisement

Getting Arduino Uno Clone with CH340B to work on Linuxmint 19


 Please consider donate through My Amazon Wishlist

Just got sometime to upgrade my Dell T3600 and HP Probook 4520s to Linuxmint 19 and everything almost worked flawlessly.

While going through setting up my ardruino development environments. I encountered a problem. So, I will share it here.

Thing are looking much better for CH340 chipset support on Linuxmint 19. It almost worked right out of the box on my Dell T3600 desktop machine with the default ch341 kernel module. No more messing around with custom building CH34x module from source.

All that is needed on Dell T3600 is adding yourself to dialout group using the following command and you are ready to go.

sudo usermod -aG dialout $USER

On my HP Probook 4520s laptop, however I am still getting permission issue. I remember I added self to dialup group on this laptop earlier when I setup USBasp. Some how I am still see the following error.

avrdude: Warning: cannot open USB device: Permission denied

This can easily fixed by finding out the idVendor and idProduct of the Uno board when it is attached.

$ lsusb
Bus 002 Device 004: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

Then create a udev rule.

sudo vim “/etc/udev/rules.d/99-CH340-USB-Serial.rules”

with the following rule

SUBSYSTEM=="usb", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", GROUP="dialout"

Then add self to dialout user group.

sudo usermod -aG dialout $USER

Then logoff and login again.

Unplug your Uno clone then restart udev.

sudo /etc/init.d/udev restart

Reconnect your Uno device.

$ ls -l /dev/ttyU*
crw-rw—- 1 root dialout 188, 0 Nov 30 10:48 /dev/ttyUSB0

Sketch upload through USB should now work once you select the proper board and port:

Board: Arduino/Genuino Uno
Port: /dev/ttyUSB0

There are time after reflash the bootloader from Arduino 1.8.7, 1.8.8 menu. After which when you try to upload sketch you get this funky error.

Using Port                    : /dev/ttyUSB0
Using Programmer              : arduino          
Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding 
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00

This can be resolved by using USBasp and Arduino 1.0.6 to reflash the bootloader. My USBasp v2 has usbasp.atmega8.2011-05-28.hex firmware installed.

~/arduino-1.0.6/hardware/tools/avrdude -C~/arduino-1.0.6/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -cusbasp -Pusb -Uflash:w:~/arduino-1.0.6/hardware/arduino/bootloaders/optiboot/optiboot_atmega328.hex:i -Ulock:w:0x0F:m

After checking for differences in optiboot_atmega328.hex they are identical in 1.0.6 and 1.8.8 releases. The only differences is the avrdude used. In 1.0.6 the./arduino-1.0.6/hardware/tools was used where as in 1.8.8 the ~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino14/bin

 

Geting USBasp v2.0 to work with Linuxmint


 Please consider donate through My Amazon Wishlist

I recently bricked by Arduino Uno board and any attempt to upload new sketch will produce and error. I had tried to reflash the firmware multiple times using my serial programmer that I build a while back but no luck getting it to work. I end up purchasing a USBasp v2.0 programmer from eBay.

USBASPV2.0

USBasp v2.0 should work right out of the box on Linux in most cases. On Arduino IDE, you only need to sett the following:

Board: Arduino/Genuino Uno
Programmer: USBasp

The Port setting is not used and the menu item should be grayed out. You should be able to burn bootloader or upload Sketch using the USBasp programmer with the above settings.

Or reflash the boot loader from command line.

/path/to/arduino-1.8.2/hardware/arduino/avr/bin/avrdude -C/path/to/arduino-1.8.2/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -cusbasp -Uflash:w:/path/to/arduino-1.8.2/hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328.hex:i -Ulock:w:0x0F:m

 

On some system. A tty device is created when USBasp is connected. In my case /dev/ttyS0. However when Port is set to /dev/ttyS0 in Arduino IDE. You will see the following errors:

avrdude: Warning: cannot open USB device: Permission denied
avrdude: error: could not find USB device with vid=0x16c0 pid=0x5dc vendor=’www.fischl.de’ product=’USBasp’

To Fix Permission denied error. As root edit “/etc/udev/rules.d/99-USBasp.rules” with the following:

SUBSYSTEM=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="dialout"

Add self to dialout user group.

sudo usermod -aG dialout $USER

Then logoff and login again.

Unplug USBasp device then restart udev.

sudo /etc/init.d/udev restart

 

To reflash the Arduino Uno boot loader

In the Arduino IDE Tool menu. Set the following:

Board: Arduino/Genuino Uno
Programmer: USBasp

Then select Tools/Burn Bootloader.

 

Fixing upload problem with Arduino Uno Clone with CH340 on Linux


 Please consider donate through My Amazon Wishlist

If you are running Linuxmin 19 use this instead.

I just got my first Arduino Uno board with a CNC shield and wanted to setup the development environment on my freshly installed Linuxmint 18.1 laptop to start playing with it.

Once I got the Arduino IDE installed and tried to upload some of the example sketches. I was greeted with the following errors.

         Using Port                    : /dev/ttyUSB3
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
...

After Googling to get some idea of what is the problem. It seem that this clone is using the CH340G USB to serial chip instead of the FTDI chipset used on the Genuine board.

lsusb

Bus 002 Device 005: ID 03f0:231d Hewlett-Packard Broadcom 2070 Bluetooth Combo
Bus 002 Device 004: ID 1bcf:2805 Sunplus Innovation Technology Inc.
Bus 002 Device 015: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter

The ch341 module that came with Linuxmint distribution was able to detect and load the module but uploading sketch using USB to serial communicating with this chipset is still a problem.

lsmod | grep ch34
ch341                  20480  0
usbserial              40960  7 ch341,qcserial,usb_wwan

To resolve this. First remove the ch341 module and replace it with one build locally from source provided by the manufacturer.

sudo rmmod ch341
sudo mv /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial/ch341.ko~

Then download the driver source from here.

Unzip it and compile the kernel module locally and install it.

cd ~/CH341SER_LINUX
sudo make 
sudo mv ch34x.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial
sudo depmod -a

Unplug the board and reconnect and reconfirm the board selection is “Arduino/Genuino Uno” and the port is properly selected in Arduino IDE and the upload should work.

 

Building a simple Programmer for ATMEGA8


Woke up pretty late this morning and feeling bored, so I wasted an hour this morning building a simple in circuit serial programming interface for use with the PonyProg software to program the ATMEGA8 micro-controller.

I intended to use this programmer for ATMEGA8 micro-controller which I recently bough from eBay. For now, I need to create the interface and do some testing with PonyProg to see how it goes.

The circuit that I used is based on one published here which is based on one published on here with some minor modification.

It’s quite simple to build but the challenging part is fitting it in DB-9 hood.

IMG_0161

IMG_0164 IMG_0163IMG_0165

IMG_0166

Links:

http://electronics-diy.com/avr_programmer.php

http://www.lancos.com/prog.html