Arduino Forum

Using Arduino => Microcontrollers => Topic started by: simplesi on Aug 06, 2011, 10:08 pm

Title: Cheapest way to program standalone project
Post by: simplesi on Aug 06, 2011, 10:08 pm
I've just bought a starter kit that came with an Arduino Uno and I'd like to build a standalone version of an IR Transcoder  Sketch (to make my TV remote control my DVD player) and it seems I can't use it to directly program a standalone ATMega 328 chip because of a unresolved software issue with the UNO optiboot bootloader  :(

As a family man with a strict budget for my toys :) I'd like to know what the cheapest way to get my sketch from a Uno onto a standalone project.

Any ideas please :)

regards
Simon
PS Loving Arduino :)
Title: Re: Cheapest way to program standalone project
Post by: (deleted) on Aug 06, 2011, 10:12 pm
(deleted)
Title: Re: Cheapest way to program standalone project
Post by: westfw on Aug 06, 2011, 10:14 pm
There are several ways of disabling auto-reset when using ArduinoISP with an Uno.
Search the forums for other "bootloader" posts.
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 06, 2011, 11:28 pm
@drew - thats the right price :)  but are there any instructions on how to use one (or a compatbile equivalent) to upload a Uno sketch with it?
@westfw - I've found a few (I've even found a post saying that the Uno does work with ArduinoISP!) - have you got a link to one you used yourself?
regards
Simon
Title: Re: Cheapest way to program standalone project
Post by: CrossRoads on Aug 06, 2011, 11:53 pm
Are you in the US?
I'm using this one.
http://www.mdfly.com/index.php?main_page=product_info&cPath=5&products_id=415

Here it is in action programming my '1284 based "Bobuino"
Add these 2 lines to programmers.txt after download/install the driver, link is on the same page.

usbasp.name=MDFLY
usbasp.protocol=usbasp

(http://www.crossroadsfencing.com/bootload_no_file.jpg)
Title: Re: Cheapest way to program standalone project
Post by: (deleted) on Aug 06, 2011, 11:53 pm
(deleted)
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 07, 2011, 08:51 am
@drew and crossroads - ta very much :)

Simon
Title: Re: Cheapest way to program standalone project
Post by: dc42 on Aug 09, 2011, 11:03 am
I've just moved a sketch from Arduino Uno to a virgin processor in my own hardware, using the Arduino Uno itself as a programmer. See http://miscsolutions.wordpress.com/2011/08/09/prototyping-small-embedded-projects-with-arduino/ (http://miscsolutions.wordpress.com/2011/08/09/prototyping-small-embedded-projects-with-arduino/).
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 13, 2011, 01:12 am
@dc42
I was hoping there was someway to it without addtional hardware (discounting the capacitor or course :)

My barebone kits of parts has arrived so I'll give your method a go tomorrow and let you know how I got on :)

Simon
Title: Re: Cheapest way to program standalone project
Post by: CrossRoads on Aug 13, 2011, 03:24 am
This has to be one of the least expensive USB AVR programmers I have seen.
http://www.nkcelectronics.com/pocket-avr-programmer.html
I just received one today.  Comes with a 10-pin to 6-pin cable to  plug onto ICSP pins as well.
Title: Re: Cheapest way to program standalone project
Post by: retrolefty on Aug 13, 2011, 03:44 am
Quote
I'd like to know what the cheapest way to get my sketch from a Uno onto a standalone project.


Cheapest method has to be:

1. Upload sketch to your arduino Uno board.
2. Remove 328p chip from Uno and install it in your standalone project 28 pin DIP socket.
3. Purchase replacement $6 328p chip with bootloader and install it into the Uno board.


Lefty


Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 13, 2011, 10:44 pm
I wish my Uno had come like that but it came with a square chip soldered directly to the board :(

Simon
Title: Re: Cheapest way to program standalone project
Post by: retrolefty on Aug 13, 2011, 10:56 pm

I wish my Uno had come like that but it came with a square chip soldered directly to the board :(

Simon


The is because you have a Uno SMD model, and that is unfortunate. I think I read that they came out with the Uno SMD model because there was a shortage of 328p chips in the DIP package so they started building Uno SMD boards until the supply situation improved. Now they seem to offer both Uno and Uno SMD boards? Not sure if that is all true or not, but as long as the standard DIP version of the Uno is avalible I see no reason in the world one should buy the SMD version.

Lefty

Title: Re: Cheapest way to program standalone project
Post by: Bobnova on Aug 13, 2011, 11:55 pm
ArduinoISP and bare new chips is cheaper than buying pre-bootloader'd chips.  Chips w/bootloader are definitely the easiest.
Title: Re: Cheapest way to program standalone project
Post by: Techone on Aug 14, 2011, 07:42 pm
@simplesi

I know how you feel to be on a low budget. The cheapest way that I am thinking is to get : USB-to-TTL adapter, an ATmega328 with pre-loaded bootloader , a 16 MHz crystal and wires. Check this site to how to do it : http://www.dalewheat.com/ (http://www.dalewheat.com/)

The company that I shop for Arduino & PICAXE : http://www.robotshop.com/ca/ (http://www.robotshop.com/ca/) but they don't have crystal ( Located in Montreal, Quebec and they have store in the US ) and http://www.hvwtech.com/ (http://www.hvwtech.com/), they carry crystals, ZIP <-- Zero-Insertion-Socket ( located in Calgary , Alberta ) 

The only part you need to purchase once is the USB-TTL adapter.

I hope this help.
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 14, 2011, 08:01 pm
@dc42
I've not managed to get it working so :(

I'm using this set of parts
http://www.oomlout.co.uk/component-bundle-for-arduino-compatible-arcb-p-227.html

and have wired it up like this
http://arduino.cc/en/Tutorial/ArduinoToBreadboard (1st image)

which (if I've understood thinks properly :) ) is the equivalent of connecting ICSPs together as per your blog.

Any suggestions?

Simon
PS I' m the IDE attempts to upload, after a minute it comes up with this error
Code: [Select]
avrdude: Yikes!  Invalid device signature.
        Double check connections and try again, or use -F to override


Title: Re: Cheapest way to program standalone project
Post by: CrossRoads on Aug 14, 2011, 08:26 pm
Next hardware purchase, try this:
http://www.nkcelectronics.com/arduino-runtime-board-rev-b.html
All parts needed can be found at www.dipmicro.com really inexpensively.
Put the uController in a socket.

For programming:
http://www.nkcelectronics.com/breakout-board-for-ft232rl-usb-to-ser232.html
or this
http://www.nkcelectronics.com/ftdi-basic-breakout.html
Make a 6-pin cable that can plug from one to the other for downloading sketches: Vcc, Gnd, Reset, Tx, Rx,

Or use an ISP programmer
http://www.nkcelectronics.com/pocket-avr-programmer.html
This one comes with a 10pin to 6pin cable to plug onto the UCSP header.

Then if some accident happens again during development you only need replace the ATMega328 (or 168 if you decide you can live with less memory).
With the programmer you can also easily download bootloaders, so you don't need to buy blank parts and save a few dollars. 3-4 projects and it pays for itself.
http://www.newark.com/atmel/atmega328p-pu/ic-8bit-mcu-megaavr-20mhz-dip-28/dp/15R0268
http://www.mouser.com/ProductDetail/Atmel/ATMEGA328P-PU/?qs=sGAEpiMZZMtVoztFdqDXO6rEZqxeooRg

I bought a tube of 10, planning ahead some and also taking advantage of the price break.
Title: Re: Cheapest way to program standalone project
Post by: dc42 on Aug 14, 2011, 10:41 pm
Hi,

1. Yes the first image in that tutorial is equivalent to what I suggested in my blog, except that you also need the capacitor connected to the Uno to suppress the auto reset.

2. Since you bought the MCU with bootloader already programmed in, you should be able to upload a sketch to it using the second image in that tutorial, if you don't mind it always running the bootloader before it runs your program.

3. What is the exact marking on the MCU? The "Invalid device signature" might mean that your mcu is an atmega328 instead of atmega328p. The marking in full should be ATMEGA328P-PU. There is a fix for this if your device doesn't have a P in the right place.
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 14, 2011, 10:44 pm
@crossroads
Why spend £5 when you can spend £0 :)

At them moment, I'm hoping the $5 lead from Hong Kong will do the job WHEN it arrives :)

In the meantime, I'll continue to try it the cheap (but hard way) :)

Simon
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 14, 2011, 10:55 pm
@dc42
Quote

1. ..except that you also need the capacitor connected to the Uno to suppress the auto reset.

Got one strapped between GND and Reset on Uno :) [edit]correction from Gnd and 5V ![/edit]
Quote
2. Since you bought the MCU with bootloader already programmed in, you should be able to upload a sketch to it using the second image in that tutorial, if you don't mind it always running the bootloader before it runs your program.

I don't care if it makes a cup of tea as long as it uploads and works :)
Quote
3. What is the exact marking on the MCU?

Well on using the sort of image enhancing tools used in Blade Runner I've managed to decipher the black writing on black plastic as saying ATMEGA?28-PU (where the ? is truely indecipherable!)
Hopefully this is my issue and you'll be winging an answer on its way to me :-)

Simon
Title: Re: Cheapest way to program standalone project
Post by: retrolefty on Aug 14, 2011, 11:16 pm
Quote
Got one strapped between GND and 5V on Uno


I hope you mean ground and reset pin?

Lefty
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 14, 2011, 11:33 pm
Quote
I hope you mean ground and reset pin?

Yes - I did :)
Simon
Title: Re: Cheapest way to program standalone project
Post by: dc42 on Aug 14, 2011, 11:36 pm
Sounds like you have the ATMEGA328-PU instead of ATMEGA328P-PU. You need to edit the avrdude.conf file. See http://arduino.cc/forum/index.php/topic,68889.0.html (http://arduino.cc/forum/index.php/topic,68889.0.html).
Title: Re: Cheapest way to program standalone project
Post by: CrossRoads on Aug 14, 2011, 11:59 pm
simplesi,
I like to acquire a tool now & then to have it in place for the next project.
I also don't like waiting 3 weeks for parts from the far east.

That's also why I wirewrap a lot of my projects - can be done in a day, vs waiting weeks to have a board that needs to be assembled still.
Altho with iteadstudio's 10 100x100mm boards for $29.90 delivered, I am learning to be more patient!
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 15, 2011, 12:46 am
@dc42
I'm running into the same error msgs as h4t :(

Basically just changing the signature in avrdude.conf makes no diff - same error msg.

Adding in new entrys in avrdude.conf and adding a new board just gives the
Quote
unknown MCU 'm328au' specified

(in my case its m328 as thats the name I tried to give mine)

This is a good game :)

regards
Simon
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 15, 2011, 01:05 am
@dc42
BTW
Quote
2. Since you bought the MCU with bootloader already programmed in, you should be able to upload a sketch to it using the second image in that tutorial, if you don't mind it always running the bootloader before it runs your program.

I believe I can't use the second method because I can't remove my soldered in 328 in my Uno :(

Simon
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 15, 2011, 12:09 pm
Well I've got into cmd line AVRDude territoy now.

Using this
Code: [Select]
avrdude -b 19200 -p atmega328p -C ..\etc\avrdude.conf -c stk500v1 -P com2
I'm getting
Code: [Select]
avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.

(if I remove the power lead from my Uno to the breadboard I get
Code: [Select]
avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50
avrdude: initialization failed, rc=-1
which I think shows that I've got some of the wires corrected properly)

So I got very brave an attempted to force upload a new bootloader
Code: [Select]
C:\Apps\arduino-0022\hardware\tools\avr\bin>avrdude -b 19200 -p atmega328p -C ..\etc\avrdude.conf -c stk500v1 -P com2 -F -U flash:w:optiboot_atmega328.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
avrdude: Expected signature for ATMEGA328P is 1E 95 14
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "optiboot_atmega328.hex"
avrdude: input file optiboot_atmega328.hex auto detected as Intel Hex
avrdude: writing flash (32748 bytes):

Writing | ################################################## | 100% 0.56s

avrdude: 32748 bytes of flash written
avrdude: verifying flash memory against optiboot_atmega328.hex:
avrdude: load data flash data from input file optiboot_atmega328.hex:
avrdude: input file optiboot_atmega328.hex auto detected as Intel Hex
avrdude: input file optiboot_atmega328.hex contains 32748 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 37.58s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x00
avrdude: verification error; content mismatch

avrdude: safemode: Fuses OK

Which as you can see failed miserably :(
Title: Re: Cheapest way to program standalone project
Post by: dc42 on Aug 15, 2011, 03:18 pm
Looks like it failed right from the start, because 0x000000 doesn't look like a valid device signature. I suspect that the mcu isn't responding to the programming commands at all. I would check the breadboard wiring and the wiring to your Arduino very carefully. You might consider posting a photo of it.

You are right, I forgot your mcu was soldered in when I suggested uploading your program as shown in the second diagram.

I'm assuming that COM2 really is the port that your Arduino appears on - mine appears on COM5.
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 15, 2011, 09:47 pm
Quote
Looks like it failed right from the start, because 0x000000 doesn't look like a valid device signature. I suspect that the mcu isn't responding to the programming commands at all. I would check the breadboard wiring and the wiring to your Arduino very carefully. You might consider posting a photo of it.

I've rebuilt the circuit on a different breadboard and as soon as I work out how to upload an image on this forum I'll post it

Quote
I'm assuming that COM2 really is the port that your Arduino appears on - mine appears on COM5.

I hope so :) My compuer initially assigned my Uno to COM26 but COM2 was free so I changed it in Device Manager - Ports - Ardunio - Properties -Port Settings - Advanced (I'm on XP) just in case anything had a problem with high com port numbers :)
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 16, 2011, 12:23 am
Finally making progress in a forward direction  :D
I came across http://www.adafruit.com/forums/viewtopic.php?f=25&t=19260&start=0 thread and downloaded optiloader and modified it so that it did not attempt to program but just read the signature of the connected MCU.

As before, with all other attempts using AVRDude and my Uno running ArduinoISP - signature came back as 0 :(

I tried all sorts of lead replacements and then I finally removed the 2 small caps across the crystal and now optiloader is returning a sig of 9514 (the sig for an ATMega328-PU)

So I'm off to start again with ArduinoISP - wish me luck :)

Simon
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 16, 2011, 12:34 am
OK - still moving forward :)
Uploaded ArduinoISP and changed preferences.txt and added capacitor to Uno.
reloaded IDE and uploaded a modifed Blink (does pin5 instead of 13 just to keep it away from programming lines)
Got
Code: [Select]
avrdude: Expected signature for ATMEGA328P is 1E 95 0F
Off to do avrdude.conf sig change

Simon
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 16, 2011, 12:45 am
Yippee!!!!!!!  :smiley-mr-green: :smiley-mr-green: :smiley-mr-green:
I have a blinking LED on my breadboard :)

Cinderella can go to the ball  :smiley-mr-green:
(Or to put it another way - an Arduino Uno can be used as a programmer for the cost of a 10uF capacitor - so the cheapest way so far is £0.05 (it cost me 23pence for a pack of 5 :) )

Thanks everyone and very much thanks to dc42 for sticking with me :)

Simon
Title: Re: Cheapest way to program standalone project
Post by: dc42 on Aug 16, 2011, 09:10 am
I'm glad you got it working. If it was removing the capacitors that made it work, then I suspect they were the wrong value capacitors, e.g. 22nF instead of 22pF.
Title: Re: Cheapest way to program standalone project
Post by: MarkT on Aug 16, 2011, 10:57 am

ArduinoISP and bare new chips is cheaper than buying pre-bootloader'd chips.  Chips w/bootloader are definitely the easiest.


And ATmega168's are significantly cheaper than ATmega328's if you don't need the extra RAM/ROM...
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 16, 2011, 11:36 am
Quote
then I suspect they were the wrong value capacitors, e.g. 22nF instead of 22pF

:smiley-red:
Schoolboy error :(
I'd assumed the 2 little ones in the kit were smaller in value than the 2 bigger ones :lol:
(I'd used the 100nF provided for PSU filtering instead of the 22pF :) )

I think I need to invest in one of those little devices with a magnifying glass and a couple of croc clips :)

Simon
Title: Re: Cheapest way to program standalone project
Post by: simplesi on Aug 25, 2011, 11:51 pm
Well, my cheap programmer eventually arrrived from HK
http://www.ebay.co.uk/itm/USBASP-USBISP-AVR-Programmer-AVRDude-USB-Port-/180666590548#vi-desc (http://www.ebay.co.uk/itm/USBASP-USBISP-AVR-Programmer-AVRDude-USB-Port-/180666590548#vi-desc)
and I downloaded the USBasp driver
http://www.fischl.de/usbasp/ (http://www.fischl.de/usbasp/)
connected the leads reset/vcc/gnd/miso/sck/mosi to the same pins on my ATmega328-PU  and used this
Code: [Select]
avrdude -c usbasp -p m328p -C ../etc/avrdude.conf
(which gave me the expected device error msg due to using a 328-PU and not a 328P-PU )
Code: [Select]
avrdude: Device signature = 0x1e9514
avrdude: Expected signature for ATMEGA328P is 1E 95 0F

I did the Shift-Compile trick to find where my system keeps its hex file and then just used
Code: [Select]
avrdude -c usbasp -p m328p -C ../etc/avrdude.conf -U flash:w:BlinkPin2.cpp.hex -u -F and it ignored the device signature and uploaded and ran it :)
Title: Re: Cheapest way to program standalone project
Post by: dc42 on Aug 26, 2011, 11:09 am
That's a neat (and inexpensive) little programmer! I'd buy one if it had the 6-pin connector and cable instead of the 10-pin one.
Title: Re: Cheapest way to program standalone project
Post by: (deleted) on Aug 26, 2011, 11:43 am
(deleted)