NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Everything Else » Can you upload arduino code to the nerdkit MCU?

May 03, 2010
by Solorbob
Solorbob's Avatar

I know they use the same MCU, but is there a way to get some arduino code loaded onto a chip with the nerdkit bootloader on it?

I searched the forum, but I didn't see a thread that looks like it would cover it.

Thanks, Shawn

May 04, 2010
by Rick_S
Rick_S's Avatar

If you can locate the *.hex file that the arduino software compiles, you can send it over to the nerdkit using avrdude. If you look at the make file for the nerdkit, the last operation (the upload section) is to send the compiled file over to the chip. All you would have to do is enter that line from a "dos" window.

For example:

avrdude -c avr109 -p m168 -b 115200 -P com1 -U flash:w:progname.hex:a

Where progname.hex would be replaced by the hex file name created by arduino and com1 would be replaced by the com port used on your pc.

The key is locating the hex file. I'm not sure where arduino stores it's files, or for that matter if it even keeps them once it's done it's thing.

If you're using linux, YMMV and someone else may be able to talk you thru.

If it works, let us know how it went. That way, we'll all be one step farther ahead.

Thanks,

Rick

May 04, 2010
by Solorbob
Solorbob's Avatar

Thanks Rick. I'll start poking around to see what I can find out about the hex file.

May 04, 2010
by Solorbob
Solorbob's Avatar

While searching around I found a thread on the nk forum talking about how to do this upload.
http://www.nerdkits.com/forum/thread/518/

thx Shawn

May 04, 2010
by Solorbob
Solorbob's Avatar

Rick,

Yes, this does work. I was able to get the blink.pde compiled and loaded onto my nerdkit. I created an Arduino directory and created the following make file. I just move over and rename the arduino hex file to this local directory. I run the make like normal.

make file:

AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P COM6

arduino-upload: arduino.cpp.hex avrdude ${AVRDUDEFLAGS} -U flash:w:arduino.cpp.hex:a

thanks for the help, Shawn

May 05, 2010
by Rick_S
Rick_S's Avatar

No problem, Great to know it works that easily. This can open up a whole new world for projects to modify...

Rick

July 01, 2011
by raildoc
raildoc's Avatar

I modified my Makefile to upload an Ardino_cpp.hex.a file to a 168 Nerdkit. Followed all directions (two threads) in Forum to upload Ardinuo to AVR. Now I get error message from last line of makefile from avrdude: target pattern contains no '%' . Help! Thanks.

July 01, 2011
by Noter
Noter's Avatar

Let's have a look at that makefile. Can you post it?

July 01, 2011
by raildoc
raildoc's Avatar

Makecode File:

GCCFLAGS=-g -Os -Wall -mmcu=atmega168 LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P /dev com4 LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o all: read.cpp-upload

read.cpp.hex: read.c make -C ../libnerdkits avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o read.cpp.o read.cpp.c ${LINKOBJECTS} avr-objcopy -j .text -O ihex read.cpp.o read.cpp.hex

read.cpp.ass: read.cpp.hex avr-objdump -S -d read.cpp.o > read.ass AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P COM4 read-upload: read.cpp.hex.avrdude avrdude ${AVRDUDEFLAGS} -U flash:w:read.cpp.hex:a

Thanks for the interest, raildoc

July 01, 2011
by Noter
Noter's Avatar

Hard to follow like that, can you post it as a code block so it's not all run together?

July 01, 2011
by raildoc
raildoc's Avatar

Noter, thanks again.

 GCCFLAGS=-g -Os -Wall -mmcu=atmega168 
 LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
 AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P /dev com4
 LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o
 all:   read.cpp-upload

 read.cpp.hex:  read.c
      make -C ../libnerdkits
      avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o read.cpp.o read.cpp.c ${LINKOBJECTS}
      avr-objcopy -j .text -O ihex read.cpp.o read.cpp.hex

  read.cpp.ass: read.cpp.hex
      avr-objdump -S -d read.cpp.o > read.ass
AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P COM4
read-upload:    read.cpp.hex.avrdude
avrdude ${AVRDUDEFLAGS} -U flash:w:read.cpp.hex:a
July 01, 2011
by Noter
Noter's Avatar

Don't think you need the AVRDUDEFLAGS defined twice and commands need to be indented. Remove one of the AVRDUDEFLAGS and indent the avrdude command and I think you'll be ok.

GCCFLAGS=-g -Os -Wall -mmcu=atmega168 
LINKFLAGS=-Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm
AVRDUDEFLAGS=-c avr109 -p m168 -b 115200 -P /dev com4
LINKOBJECTS=../libnerdkits/delay.o ../libnerdkits/lcd.o ../libnerdkits/uart.o
all:   read.cpp-upload

read.cpp.hex:  read.c
    make -C ../libnerdkits
    avr-gcc ${GCCFLAGS} ${LINKFLAGS} -o read.cpp.o read.cpp.c ${LINKOBJECTS}
    avr-objcopy -j .text -O ihex read.cpp.o read.cpp.hex

read.cpp.ass: read.cpp.hex
    avr-objdump -S -d read.cpp.o > read.ass

read-upload:    read.cpp.hex.avrdude
    avrdude ${AVRDUDEFLAGS} -U flash:w:read.cpp.hex:a
July 01, 2011
by Noter
Noter's Avatar

By the way, I don't use a Mac but I think you need another slash in the AVRDUDEFLAGS like so ... -P /dev/com4

Copy the AVRDUDEFLAGS line from a working makefile to be sure it's correct.

July 02, 2011
by Rick_S
Rick_S's Avatar

I think that MAC uses a variation of what is shown in the original NK makefiles. I think the COMx format is just a Windows thing.

Someone please correct me if I'm wrong but these are the differences as I have seen them (I can only confirm Windows though) Wink

Linux:

-P /dev/ttyUSB0

Windows:

-P com4

MAC:

-P /dev/cu.PL2303-0000101D

Keep in mind each will change based on the port location. I also do not own a MAC but you can reference THIS FORUM POST FROM RALPH which explains the MAC thing a bit better. (He actually owns a MAC Mini).

I'm not sure what type of computer you own or what OS you are running but either way, you'll need to change that parameter as well.

Rick

July 04, 2011
by raildoc
raildoc's Avatar

Thanks much guys. I finally cleaned-up my makefile syntax. It now works like a charm! This is a great time-saving tool to convert existing coded Arduino apps to Nerdkit. Regards!

Post a Reply

Please log in to post a reply.

Did you know that the sparks present in motors can be dangerous for your microcontroller and other electronics? Learn more...