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.

Microcontroller Programming » MKII questions

January 06, 2014
by jmuthe
jmuthe's Avatar

I recently purchased the MKII and some blank ATMEGA 168 and 328 chips and downloaded ATMEL studio 6.1. I then went to this Website which showed me how to upload a chip and it gave me a simple sample code to blink a LED with PB0. This is the webite: http://startingelectronics.com/tutorials/AVR-8-microcontrollers/starting-AVR-development/

I compiled and uploaded the program to the chip correctly but now I am interested in using the MKII to upload some sample Nerdkit programs to the chip like the initialload.c. However, I can't just compile the program by pressing "build" on ATMEL studio 6.1 because this program relies on other h files such as lcd.h and delay.h. I think I will need to use a makefile to compile it. When I was using the USB cable that Nerdkit provided me to program the chips, I simply looked up the COM port on the device manager, and then entered the COM port on the makefile that Nerdkit provided me. However, the MKII doesn't use COM ports. The device manager says Port_#0004.Hub_#0004. How exactly would I enter that information into the Makefile.
P.S. I will eventually do more research on makefiles but for now I just want to get my programs to work.

January 06, 2014
by jmuthe
jmuthe's Avatar

I also want to know how to get the bootloader onto my chip. I'm aware that there is a thread on Nerdkit on how to do this. http://www.nerdkits.com/forum/thread/1358/ However, it didn't work for me. I had a similar problem as Singlecoilx3. When I went to the command prompt and wrote "avrdude -c avrispmkII -p m168 -e" I got a message that said "avrdude: ser_open(): can't open device "com1": the system cannot find the file specified" Singlecoilx3's problem was a bad ribbon cable but that can't be my problem because if I had a bad ribbon cable then I wouldn't have been able to upload the first program from that MK2 website that caused the LED to blink.

January 06, 2014
by Noter
Noter's Avatar

Yep, have to use the make file for nerdkits programs. I have a mkII clone and it works with a programmer name of avrisp2 instead of avrispmkII. Avrdude will automagically find the usb device if the drivers are properly installed. I remember seeing something about windows drivers for the mkII related to avrdude when I was getting it to work on linux but can't recall the details. Google it, there's lots of info on the web about avrdude mkII windows driver.

January 07, 2014
by Ralphxyz
Ralphxyz's Avatar

Using Atmel Studio you do not need a bootloader to load a compiled program (.hex).

Search the Nerdkits forum some more you'll find some of my discussions about using

Atmel Studio with graphic step by steps.

Any .hex can be loaded in two or three steps using Atmel Studio real simple.

Let me know if you cannot get it working I'll post them them again.

Ralph

January 07, 2014
by esoderberg
esoderberg's Avatar

jmuthe,

You can add your lcd and delay files, compile and upload all via Studio: Atmel link files video

January 07, 2014
by jmuthe
jmuthe's Avatar

esoderberg,

I am having trouble using the video to get my program to work so let me tell you what I did. First I opened a new project on Atmel Studio. I then copied and pasted the initialload program's source code to it. Then with the video's instructions, I located all the files in the libnerkit folder and linked them to my program. However when I built the files I still got the error message "lcd.h: No such file or directory" and "delay.h: No such file or directory" I don't understand why I got the message since I see those files linked in the solution explorer.

Ralphxyz,

When I said that I wanted to know how to get the bootloader onto a chip, I know that it is not necessary if I use Atmel Studio but I just wanted to know just to have the knowledge. Also, when you say to check your discussion on Atmel Studio with graphic step by steps, which post do you refer to? You've posted a lot of threads over the years so it is a little hard to figure out which thread of yours that you are referring to. Thanks for your help.

January 08, 2014
by Ralphxyz
Ralphxyz's Avatar

jmuthe, yeah sorry, I also looked and could not find them. I'll redo them so we have a fresh reference.

The bootloader is a .hex file (when compiled) so it is loaded using Atmel Studio just the same as any .hex file.

Once it is loaded you'd not use Atmel Studio to load any other .hex but use the command line.

Loading a .hex using Atmel Studio saves you ~2k of memory.

If you use Atmel Studio often you'd never need a bootloader. Of course you'd need a programmer.

I have to use Atmel Studio for another project so I should put up the instructions today.

Oh hey I remember I had the instructions in the "Library".

Ralph

January 08, 2014
by Noter
Noter's Avatar

I'm glad to learn that by using Atmel studio you can avoid the make utility all together. I suppose most people would prefer it that way. However if you decide you want to do things the old way with your mkII here is a link that may get you going on your windows box - http://eliaselectronics.com/using-the-avrispmkii-with-avrdude-on-windows/.

January 08, 2014
by Ralphxyz
Ralphxyz's Avatar

Hi Paul, Happy New Year!!

There is also a Extension to Atmel Studio for using a Makefile, I have not used it but saw it while updating Atmel Studio 6.1.

Here is how one programs a mcu with a .hex file:

Do I need to explain this? You can load the bootloader (foodloader.hex) or any .hex file.)

Ralph

January 08, 2014
by Noter
Noter's Avatar

Hi Ralph, hope you had a happy new year too!

I missed my chance with Atmel Studio because I don't have a single windows pc left. The good news is that linux gives better performance and the price is definitely right for an old retired guy like me. :-)

January 08, 2014
by Ralphxyz
Ralphxyz's Avatar

Yeah, I probable have 6 computers sitting around with XP still on them I'll probable put Linux on them.

I'm just getting my Raspberry Pi(s) running, they have been sitting in a drawer for at least two years.

I finally came up with a specific need for them, my 3D printer(s).

Atmel Studio is a very robust IDE, but you have to take the time to learn how to use it which I never had, well I had the time I just never did it.

I use it about once or twice a year now so I have to re-learn it whenever I happen to need it.

Ralph

January 08, 2014
by Noter
Noter's Avatar

Check out the Zorin OS 8 distribution when you're ready. Supposedly makes the transition from XP to linux easier.

I bet it feels good to finally use those Pi(s). I sure wish I had a 3D printer sometimes, especially when it's time to put a project in a box. Maybe some day ...

January 09, 2014
by Ralphxyz
Ralphxyz's Avatar

My 3D printer experience has been a challenge. On January 1st last year I placed a order for a new printer supposedly production ready. It was offered at a discount for a beta production and delivery cycle, the printer was allready "production ready" so this was not supposed to be a beta run for the printer itself.

Well I am still waiting, with very limited communications from the manufacturer.

Of course I saved over $500.00.

then I bought another 3D printer from the same company (QU-BD). The first <$200.00 3D printer. It is a kit that came with missing parts. I have it 90% assembled and will probable make the missing parts with my scroll saw. The printer is laser cut mdf. Amazing the precision of the laser cutter (I definitely am thinking about making a laser cutter).

Ralph

January 09, 2014
by Ralphxyz
Ralphxyz's Avatar

Hey jmuthe, are you all set? Everything working?

Ralph

January 09, 2014
by esoderberg
esoderberg's Avatar

jmuthe,

When you "add" the file in Studio, use "add" instead of "add as link"; this will add a copy to your project folder. Then instead of the original Nerdkit code of:

 #include "../libnerdkits/lcd.h"

use:

#include "lcd.h"

This should help if the problem you're having is the link path.

If you're still having problems with the compile, open the configuration manager under the "project" tab. This will allow you to set all of the parameters you would set up with the makefile per Nerdkit guide.

January 09, 2014
by jmuthe
jmuthe's Avatar

I've had some success but some failure. I first used initialload.hex which was originally created with a Nerkit Atmega chip after I used the Nerdkit makefile to create it. I first uploaded the initiaload.hex file to a blank chip and I know that program worked because I connected an LCD to the chip and the LCD displayed the message "Congratulations Your Nerdkit is alive." I then tried to load the foodloader.hex file to the same chip and I got a message that said that the program uploaded correctly, so I assumed that the bootloader was in the chip. I asumed that I could program it the same way I program the chips that come from Nerdkit by using their makefile and USB to TTL cable. However, when I tried to load one of my programs to the chip, it didn't accept the program.

I then connected the Atmega chip that I got from Nerdkit, which came with the bootloader in it, and connected it to the MK2. I used the MK2 to erase the chip and put the iniitalload.hex file into it. The chip accepted it and the program worked with the LCD. I then erased the chip and programmed the foodloader.hex file into it. However, this chip seemed to accept the bootloader because when I tried to load a new program into it with the USB cable and a makefile, it accepted it and the program worked.

I got confused by the results. If I programmed my blank chip with the bootloader file then how come it didn't work when I tried to put a new program in it with a USB cable? Is there another step that I have to do in order to get a blank chip to work like a Nerdkit chip or do I just have a partially broken chip?

January 09, 2014
by Noter
Noter's Avatar

The new chip has to have fuses set to enable the bootloader. I think they are listed in one of the makefiles in the bootloader directory or you could just read them from the nerdkit chip and then set the same values in the new chip. Be careful though, serial programming is enabled by one of those fuses and if it accidentally get's turned off you won't be able to program the chip again with out a HV parallel programmer. The fuse values are fully documented in the datasheet on the chip. I find the online fuse calculators to be helpful when figuring out fuse values. Like http://www.engbedded.com/fusecalc/.

January 10, 2014
by Ralphxyz
Ralphxyz's Avatar

That is why I always kept a Nerdkit mcu handy, I would often have to reference the fuse settings no matter how many documents I made with the settings it was always quicker to just look at the Nerdkit mcu.

Starting with a blank mcu the fuse settings definitely have to be changed.

Ralph

January 13, 2014
by jmuthe
jmuthe's Avatar

I was able to set the fuses and upload the bootloader into the blank chip so now I could program them with the USB cable just like the chips that came from Nerdkit. Thank you all for your help guiding me. However, I now want to know how to load a program into a blank chip directly from the MK2, without using a bootloader. As I mentioned before, it is easy enough if the program is simple but if it relies on other h files, like initialload.c, then it is a little more complicated to link the files together for me. I still want to know how to do this. Would I alter the original makefile or is there some other method. I tried to follow esoderbeg's advice but unfortunately it didn't work. He mentioned to go to configuration manager but I am not sure what to do exactly when I get there. Could anybody be more specific for me?

January 14, 2014
by Ralphxyz
Ralphxyz's Avatar

Well if you use Atmel Studio just do it like you put the foodloader on.

You would not use a Makefile.

If you want to know how to do it from the command line someone else will have to answer.

Ralph

January 15, 2014
by jmuthe
jmuthe's Avatar

Ralphxyz,

I have been able to put other hex files into blank chips (like initialload.hex) using the MKII and Atmel Studios. I did it by loading the chip with the initialload.hex program the same way that I loaded it with the footloader.hex program. However, intitialload.hex was originally created in the traditional Nerdkit method by using a makefile, USB cable, and a chip with a bootloader in it. Once the hex file is created, I could load it onto blank chips using MKII and Atmel Studios. However, in order to create the hex file in the first place I still need to use a chip with a bootloader in it, a USB cable, and the makefile. I know that I could load hex files into blank chips but how would I create these hex files without having to use a chip with a bootloader and a USB cable.

January 15, 2014
by Noter
Noter's Avatar

The old fashioned nerdkit method of using a makefile does a couple of things, 1) it runs avr-gcc to compile and link the source code to create the hex file and 2) it runs avrdude which uses the serial cable to upload the hex file in to a chip via the bootloader. So you don't have to do step 2 to get a hex file, just step 1. It would be worth your while to learn about and understand the avr-gcc command in step 1 as well as the avrdude command in step 2. It's not absolutely necessary to use a makefile or learn anything about the make utility, you can run avr-gcc and/or avrdude in a regular command window just like any other command. I think it is be a good idea to run them in a command window while learning about the various operands they accept. Often I will run avrdude in a command window when I'm using a new programmer or starting with new chip because I can invoke terminal mode and use interactive commands to verify it is communicating correctly with the chip. After I get it figured out I edit my makefile with command line changes I discover are necessary and then use the make utility for ongoing program development.

The video that Eric linked to is a little hard to understand simply because the guy's english is not that great but otherwise shows how to either link to or copy those other h files in your atmel studio project. The video never mentions using the configuration manager so probably you can stay out of it. However, you do have to change the #include statements to remove the path part of the h file names as Eric says in his second post. That is where he mentions the config manager if you want to put other things from your nerdkit makefile into your atmel studio project but that would be rather difficult unless you understand the what and why about those other things in the makefile, which takes us back to my first paragraph.

January 16, 2014
by jmuthe
jmuthe's Avatar

Okay, I got it to load the program using the Atmel link video that esoderberg show me. The reason why it didn't work for me was because there was no data in the lcd.c program. This prevented the initialload.c program from linking to the lcd.h file. I must have erased the data in the file by accident. Thank you all for your help. I appreciate it.

Post a Reply

Please log in to post a reply.

Did you know that 20 LEDs can be controlled from 11 microcontroller pins, to make a twinkling heart outline? Learn more...