Category Archives: Electronics

Electronics and Related stuff.

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.

 

HP 3478A with no AC Voltage or AC Current Reading


I found this nice unit on eBay at a discounted price as a part unit, because according to the seller, the unit doesn’t read AC voltage or current. Otherwise everything else seem to work perfectly.

After some researching and digging through the schematic. There are few components like K104, U102 and U301, U302 and U303 ICs possibly failed.

Before proceeding further, if you are going to make a similar repair make sure it is disconnected from the AC line and take extreme care not to short battery. Otherwise all the calibration settings in CMOS RAM will be lost and need recalibration.

Once, I received the unit, I began tracing AC signal through K104, U102 and U301, U302 and U303 input. The signal made it through and range switching seem to work just fine. However, the output of U303 (AD536A True RMS-to-DC converter) is stuck at near ground regardless of the input signal.

To confirm that U303 is dead, I cut the JM302 to DAC section and reconfirmed that AD536A is faulty. Then to confirm that meter is still able to read the AC input from the DAC. I placed a .5V at DAC side of JM302 and the meter is responding, so the DAC is able to read the converted AC signal and it is a good sign.

After some research, I finally ordered Analog Devices AD536AKH replacement for U303 from eBay. When the unit arrive, I began surgically removed the old unit by clipping the legs and cleanly removed the old solder and pins before installing the AD536 replacement unit and bridge the JM302 jumper.

The AC volt and current is working now and the reading is slightly off and need recalibration.

Next improvement is to replace the lithium battery.

IMG_0122 IMG_0132IMG_0131 IMG_0135 IMG_0139

Restoring HP 403B AC Voltmeter (10Hz – 2MHz)


The following instructions, document the process that I toke to restore the  HP 403B AC Voltmeter to working order.

Day 1

The unit was a bit dirty when USPS delivered it to my front door. The rechargeable battery pack is showing sign of corrosion.

First, I checked the meter movement and making sure that it is in good shape.

The moment is smooth and doesn’t appear to have any issue. With a 1.5V battery and a variable resistor, I checked the full-scale reading and a few other reading just to confirm the meter linearity.

IMG_9764

A quick check of the voltage across the capacitor C21 and I am getting a steady 42.28V DC.

Next, I checked the battery +13, -6 and -13 supply voltage. I am getting +10, -6.5 and -13, this is because the battery is so old and some of the cell are dead and not evenly charged.

Even though the supply voltage are way off! The good sign is that the unit is fully working.

The battery is showing sign of corrosion and need to be replaced. So, it’s on my next to do list.

IMG_9765

After a quick search, I found suitable replacement battery from eBay. The seller is trying to get rid of his inventory and selling a 25 packs of 3.6V 700mAh for cordless phone for only $0.99. The only catch is the $20.00 shipping.

The meter originally came with 4 x 6.0V 225mAh Nickel-Cadmium Battery but I am going to replace it with 8 x 3.6V 700mAh battery packs made for cordless phone.

The combined voltage will be slightly higher when it is fully charged, however, it doesn’t seem to pose any problem after everything is re-calibrated.

IMG_9775

After tying them together and solder their leads in series connection to make 2 x 14.4V batteries pack.

IMG_9792

 

I reconnect and the battery to the original +13, -6 and -13 leads and put everything back together.

NOTE:  Don’t solder the -13 lead just yet, as you will insert the amp-meter in series with it to adjust the charge rate later on.

IMG_9793

I made some minor change to the orientation of these batteries after soldering them in place, so that the PCB will fit on top.

IMG_9795

With the Amp meter connected in series with -13 power line, I adjust the pot to 6.5mA as suggested by  the manufacturer. You may set it to 11mA, if you plan to use it on battery regularly.

I let it fully re-charge over night before I return to work on it again.

Day 2

As I am going over the calibration procedures.

I notice that when meter is on, it never quite return to zero. It is alway 2 ticks higher.  Which kinda annoy me.

TODO: Investigate to find out which aging components causing this.

But for now, I just re-zero it with the zero adjustment screw. This will affect it accuracy a little bit. However, when checking the voltage indication on each range the reading track very closely to my HP 334A reading. So, for now it is not an issue for me at the moment.

The strange thing is that, on these HP AC Voltmeter. There is only mechanical zero adjustment. Unlike most VTVM that I had restored. Where you have to adjust  mechanical zero, AC and DC zero.

Day 3

While calibrating, I notice that on 0.01 and 0.03 range. The meter doesn’t work at all and it’s alway peaking.

It seem the meter is fully deflected when those range are selected.

At first, I though some resistors in the voltage divider network are bad. But after checking these resistors, switches and signal path. Everything checked out ok.

So, to diagnose this further. I connected the oscilloscope to take a peek at the signal at each stages.

After tracing the signal path on the diagram, the original input signal is amplified and then going into the resistor divisor network.

When I connecting the probe and observe the output at R20 and R22, There is 11mV p-p (.048us or 21MHz) voltage showing  on the scope.

IMG_9805

IMG_9802

In the 0.01 and 0.03 range, the original signal coming out of the voltage divider  is so small compare that with the 11mV p-p noise.

The noise is swamping the original signal and causing significant meter reading error.

NOTE: According to the manufacturer manual, this may be caused by a noisy transistor and need replacing.

But first, I wanted to try to fix it by adding a filtering capacitors.

After adding a 0.1uF 50V to +13V and -13V to ground, this seem to eliminate the noise.

To install the capacitors, I find some open space on the PC board and solder them in place.

This help to remove the noise and making 0.01 and 0.03 range working again.

IMG_9808As seen below the signal is much cleaner now.

IMG_9799

Day 4

Spend a few hours calibrating the meter the best I can. Due to lack of a signal generator that can put out 30V 300kHz sine wave, I have to put off those calibration steps.

At the moment, the meter is track accurately from 1mV to 1V from 10Hz – 2MHz.

TODO:

  • Recap
  • Finish up calibration at 300kHz

 

Link to Service Manual:

Click to access HP-403B-Manual-SNprefix-403.pdf

Making a simple crystal tester


Remember from my previous post in Restoring Heathkit IT-17 tube tester? Where I mentioned that I got a box of tubes for $20 buck!

Well, under this pile of tubes there are bunches these little crystal modules that was made for WWII radios communication equipment.

I wanted to get rid of them on ebay but I need some way of assuring that they are working and the frequency is still as accurate as marked before I list them.

After some research on Internet, I found couple of plans which can be build quite easily. I wanted to make some modification to the circuit to use 2N3904 since I have bunches of them on hand. After fiddling with it for a while in LTSpice, I got a working circuit.

I then use KiCAD to draw the circuit and create a PCB layout from it and here is the final circuit and PCB:

crystal_tester_plot PCB

Making the PCB

This time, I wanted to try the toner transfer method to create a polished and professionally looking PCB. However, my stupid Samsung laser printer keep on jamming and it is low in toner. The final laser printed PCB artwork has many flaws and some traces are spotty.

After transferring the toner to the copper clad, I have to manually use the permanent marker to cleanup these traces. After etching the PCB and installing the components, this is what I got.

IMG_9369 IMG_9367

Here the circuit is being used for the first time to test an unknown crystal, the green LED is lid to indicating that the crystal is working perfectly.

IMG_9372

One down, plenty more to go. 🙂

IMG_9365

Restoring Heahkit IT-17 Tube Tester


I acquired quite a bit of old test equipments lately and some of them are based on old vacuum tubes. Most of the time during the restoration process, I am able to get them working without the need of the tube tester. So, a tube tester is on my wish list but it’s not a high priority.

Out of a blue, I stumbled up on a Craigslist listing of 10+ test equipments at really good deal. The piece that I am really interested in buying was the Heathkit IT-17, the rest are nice too but I have no use for them at the moment.

The seller listed it pretty early in the morning, so the chance of it still available when I saw the ad was pretty slim. So, I decided contacted him late in the night anyway.

Early next morning, I got a response back and they are still available. I was so elated when I heard the news. I immediately arranged the time to drop by and drove 50+ miles to Oxnard to pick them up. While I was there he also offered to sell me a box of tubes at really good price.

The Heathkit IT-17

The unit was really an ugly duckling and disgustingly dirty when I pull it out of the box. The back cover is dirty and the paint are peeling. The good thing is that the front panel is still in pretty good shape.

IMG_8862 IMG_8856IMG_8763 IMG_8762 IMG_8761 IMG_8760

Restoring

With the case opened, I quickly examined all the soldering join and looking for burned components. Everything looks good. I went ahead and replaced all bad carbon resistors that are out of tolerance and cleaned all switches and pots with contact cleaner.

I initially followed the IT-3117 instructions, since I can’t find the original IT-17 manual anywhere on the Internet. The only thing I found was the IT-17 schematic and the two are quite similar in design. I proceeded to check the continuity from the switch to all the pins on each socket, they are all good. The filament voltage, however, it is really off and the line test is off-center but the unit is functional.

Testing

With the tube tester semi functional, I decided to give it a test run. With a box of unknown condition tubes at hand, I tried to test some of them. After going through 1/4 tubes in the box I got 2/3 of the tubes are bad and 1/3 are good.

With 2/3 bad tubes start piling up, I started to question the tube tester functionality because who would keep a bunches of bad tubes???

Manual Testing

I decided to do manual testing on 6L6 which was tested bad earlier.

  1. Connected pin 2 and 7 to external power supply the filament is glowing nicely at 6.3 DC. So, the filament is fine.
  2. When connected to the socket on the test tube. The filament is not glowing at all, 0V is measured between 2 and 7.
  3. When 6L6 is not installed, there is 6.3V between pin 2 and 7.
  4. I decided to plug 6L6 tube back in and use the alligator jumper wire and connect pin 2 and 7 to corresponding wire on the switch bank. The filament start glowing nicely. This confirm the socket is making clean contact, but the wiring is possibly bad.
  5. Measuring the resistant from the switch to pin 2, the wire has 50+ Ohm?? Note to self – Don’t trust the continuity beep!!!
  6. After some tracing, it appears that the original builder missed one solder join on one of socket. After fixing that the 6L6 filament start glowing again and the tube tested fine now.

Calibrating Tube Tester

All original instructions assumed that all parts are new and working to spec. So, some of these assumptions are no longer valid since the meter is old and not that accurate. This is true at least in my case, when the meter is zeroed, the reading are way off.

I have to come up with alternative way of calibrating it and ensuring that the tube tester result are some what usable.

Calibrating Line Test Indicator

  1. With no tube in any of the socket
  2. Set all switch to center position, then set A to bottom
  3. Set the filament to 110
  4. Connect a voltmeter black lead on pin 1 and connect red lead on any other pin so we can read the filament voltage. This is important, since the during line voltage adjustment, the meter is connected to 110V tap on the filament winding. At 110V the meter should be reading 50 or .5mA. If not check the 1K and 75K resistor and make sure they are within tolerance.
  5. Turn set line until the filament voltage reading is 110V RMS. Cut a piece of electrical tape in triangle shape and tape it to set line dial to mark this position. This is the correct line voltage for use with the tube tester.
  6. When set line voltage is properly adjusted, the filament voltage reading should be 110V. At this point the meter should be reading exactly 50 or .5mA. This is assuming that the 1K, 75K and your meter are good. If 1K and 75K are good but the meter is not at 50, the meter reading is off. In that case,insert an amp meter in series with the panel meter to get the correct reading, it should be around .5mA. Then adjust the panel meter so that it’s indicating the same reading by turning the zero adjust screw on the panel meter. Once that is done, your set line switch and meter is properly calibrated to show proper line voltage. NOTE don’t adjust the mechanical zero from now on it will screw up the reading.
  7. Next insert a known good tube and set the tube tester accordingly. Then the plate control is adjusted so that the meter is reading from 0 to 100, the measured value from amp meter still inserted in series with the panel meter is recorded at each point to produce a table and chart.
  8. From now on, after testing using the original instructions. Take the reading and use the table to map it to actual value in mA or multiply that by 100 to get % scale.

IT-17_meter_adj

If you find this information helpful and would like to see more. Please support my future project.

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