Progress Bar

Skip to main content

Jaycar
...

Duinotech Uno Programmer

Duinotech Uno Programmer

Difficulty
Test & Tools

Summary

Recently, we had to program a big pile of Uno's for some workshops we were running, getting kids to build the Snake Game Project. We didn't want to worry the kids with the programming side of it, so we needed a pile of preprogrammed Uno's for them to build with. The idea of using an Uno to program an Uno sounds a bit meta, but with a USB Host Shield, we managed to program our Uno's. In fact, the programming only takes about three seconds per board, which is even faster than we could unpack them. Some soldering required.

Materials Required

1Duinotech UNO r3 Main BoardXC4410
1Arduino Compatible USB Host Expansion BoardXC4456
1Duinotech Arduino Compatible Prototyping ShieldXC4482
1Red 5mm LED 8mcd Round DiffusedZD0150
3Green 5mm LED 80mcd Round DiffusedZD0170
1470 Ohm 0.5 Watt Metal Film Resistors - Pack of 8RR0564
1Red Snap Action Keyboard Switch - PCB MountSP0720

The button is used to start the process and LEDs are mostly to give an idea of whether the programming is proceeding correctly, and could be replaced by components on a breadboard or even just a jumper wire connected to D3 to start the process. To build the shield, we did the following. Start by mounting the buttons and LEDs as shown. The position isn't critical, but because we're using the component legs under the board, they might not be long enough if the position changes. Don't trim the legs yet! Note that the anodes (long leg, without the flat) are facing towards the digital pins (top of picture).

Flip the board over, and solder the anodes to their respective pins, D4-D6 for the green LEDs and D7 for the red LED. Solder the cathodes and cut them off, saving them for making connections later, including D3 for the switch.

The resistors are next, one for each LED. Again, solder in place, but do not trim.

Now connect the loose ends of the resistors, with the other ends all going to ground.

This is all the soldering that is needed. All that is left is to put the USB Host Shield on top of the Uno, and the plug the assembled Prototyping Shield into the top of the USB Host Shield.

The following is a summary of the connections that have been made. The connections on the USB Host shield cannot be easily changed, but are good to know in case you need to modify the project.

Uno

Proto Shield

USB Host Shield

D3

To GND via Button

D4

To GND via green LED and resistor

D5

To GND via green LED and resistor

D6

To GND via green LED and resistor

D7

To GND via red LED and resistor

D9

INT

D10

SS

D11

MOSI

D12

MISO

D13

SCK


The sketch that is uploaded to the programmer actually includes a copy of the sketch code that programmed to the second Uno. In the code we have supplied, this is the Snake Game, but later we'll show you how to change this. There is one library needed to make the project work, for the USB Host Shield, and this can be installed via the Library Manager. Go to Sketch>Include Library>Manage Libraries and search for 'usb host' (with a space), and install the 'USB Host Shield Library 2.0' as seen below.

The sketch is based heavily on the 'acm_terminal' example from this library. After the library is installed, it should simply be a case of selecting the Uno board and serial port and clicking upload. To test, plug a second Uno into the USB Host shield's socket, and press the button. If everything is working, the three green LEDs should light up in quick succession.

If you have it hooked up to a computer, the serial monitor (115200 baud) will give more detailed information. If you are having issues, be aware of the following. This project will only work on Uno boards that have a 16u2 IC as USB-Serial converter. The duinotech Uno is an example that will work. Some Uno boards use a different USB-Serial converter, and the sketch does not recognize this. Other main boards such as the Mega and Leonardo will not work because they use a different upload protocol, and have a different device ID.

The sketch provides a minimal interface which interacts with the bootloader and performs three main functions, which correspond to the three green LEDs. The first is to reset and check the correct bootloader is responding. The second is to upload the sketch code, and the third is to verify the sketch code. If only one or two LEDs light up, then this will give some indication of where the process is failing.

Once you have determined that the default sketch is working correctly, you can modify it to upload a different target sketch. The first proviso is to ensure that the target sketch is below 17004 bytes (under Arduino 1.6.7- different versions may compile to slightly different sizes), as the main sketch is 15252 bytes, and both need to be less than the available flash memory of 32256 bytes. This can be checked when compiling on the status window:

Note that the whole memory is read, even if the sketch is less than 32256 bytes. Each line is 16 bytes and we only need to keep the number of bytes mentioned by the compiler above, which will vary depending on your target sketch. It may help to paste the data into a spreadsheet program to help count the lines. The other important thing is that the number of bytes in [] should equal the number of bytes in the array. Then replace the entire contents of the 'sketch.h' file (the second tab) with the new data.

Another option is to use the 'Export Compiled Binary' option (Sketch>Export Compiled Binary) and convert this using an Excel spreadsheet that we have created. This will save two .hex files in the sketch folder (where the sketch is saved). Open the one without bootloader in a text editor such as Wordpad.

Note that the whole memory is read, even if the sketch is less than 32256 bytes. Each line is 16 bytes and we only need to keep the number of bytes mentioned by the compiler above, which will vary depending on your target sketch. It may help to paste the data into a spreadsheet program to help count the lines. The other important thing is that the number of bytes in [] should equal the number of bytes in the array. Then replace the entire contents of the 'sketch.h' file (the second tab) with the new data.

Another option is to use the 'Export Compiled Binary' option (Sketch>Export Compiled Binary) and convert this using an Excel spreadsheet that we have created. This will save two .hex files in the sketch folder (where the sketch is saved). Open the one without bootloader in a text editor such as Wordpad.

And copy and paste the text into cell A2 of the spreadsheet.

Then select all of column 'B' and replace the contents of the sketch.h tab with what has been copied. We have tested this with a few small sketches and it seems to work OK.

Future Improvements

Although this function may be of limited use, it is possible to program the Duinotech Uno Programmer sketch to the target. In the sketch file, there are the lines:

Similar projects you may be interested in

Test & Tools
Laser Beam Timer
Difficulty

Jaycar-RCT-Hero
Test & Tools
Resistor & Capacitor Tester
Difficulty

Portable Soil Moisture Meter
Test & Tools
Portable Soil moisture meter
Difficulty

Test & Tools
Wireless Garden Monitor
Difficulty