Thursday, February 11, 2010

Arduino speaks Nerd(kit) and Nerd(kit) speaks Arduino

Both the Arduino and Nerdkit are based on ATMega168/328.  So, one would guess that binary program code should work essentially the same on both.  I put this to the test with a simple program.  I made (modified existing code that came as samples) programs to blink an LED for each kit.  The Arduino sketch (code) is:



int ledPin =  13;    // LED connected to digital pin 13
// The setup() method runs once, when the sketch starts
void setup()   {                
  // initialize the digital pin as an output:
  pinMode(ledPin, OUTPUT);     
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()                     
{
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(1000);                  // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(500);                  // wait for a second
}


and the c code for Nerdkit is:

#define F_CPU 14745600
#include
#include
#include
#include
#include
#include
#include "../libnerdkits/delay.h"
#include "../libnerdkits/lcd.h"


int main() {
  // LED as output
  DDRB |= (1<
  
  // loop keeps looking forever
  while(1) {
    // turn on LED
    PORTB |= (1<
    //delay for 300 milliseconds to let the light stay on
    delay_ms(300);
    // turn off LED
    PORTB &= ~(1<
    //delay for 800 milliseconds to let the light stay off
    delay_ms(800);
  }
  return 0;
}





Both produce code that blinks an LED on pin PB5 of the ATmega168/328.  I was able to use AVRDUDE to upload the .hex file generated by Arduino IDE to the Nerdkit and vice versa.  The only tricks were getting the AVRDUDE options correct.  Well, that and changed the Arduino IDE to build for 168 which the Nerdkit has.  (Nifty GUI to ease uploading .hex to the Arduino found at NGCoders.)

This result should have been expected... and was.  But what was proved is that the different bootloaders did not affect the outcome.  At least with such a simple program.

Nerdkit on left, Arduino Duemilanove on the right, both running the identical .hex code.





A micro effort to blog a bit about micro-controllers

I am interested in and am enjoying working with micro-controllers.  My thought with this blog is to create a diary, in essence, of what I have done and am doing.  This will largely serve my own purposes for documenting what I have learned.  It will also be a place I can refer friends or others to when discussing something I have done.  If anyone else finds it interesting, that's great too.  I have to warn you... I am no expert.  Some of the stuff I have done may be dumb and some conclusions I have come to may be wrong.  I tend to work by finding an example of something I am interested in and then modifying it for my own purposes or curiosity.  That means I am building on the efforts of others.  It also means I don't always understand fully something I have done.  But, learning is a process.  Each time I struggle with something I learn a little more.


I first got interested in micro-controllers around 10 years ago.  I bought a Basic Stamp education kit from Peter H. Anderson (www.phanderson.com).  I recommend Peter Anderson's stuff.  Lots of good educational stuff at good prices.  Lots of good info at his site.  I messed with this stuff for a good while but got interested in something else (koi ponds, I think) and put it back in the closet.


Recently my interest was rejuvenated by a chance encounter with a website, www.nerdkits.com.  I wish I could remember what I was doing when I stumbled this site.  Anyway, I ordered up a nerd kit and my interest has taken off again.  I have since bought an Arduino Duemilanove.  And I dug out my old Basic Stamp.  


I have various thoughts about making something useful out of all this stuff.  For now I am content just to figure stuff out and get it working.  That is the process I am talking about here.