Learning about micro-controllers using the Minipov

If you are interested in learning about micro controllers and building your own projects then I would recommend the MiniPOV kit from Adafruit Industries.  This is a kit and will need to be assembled so if you do not have a soldering iron you will need to borrow one.  From this you will learn to build kits and solder, program a AVR micro-controller, and control some LED‘s.

My kit was the MiniPOV2 which is programmed using the parallel port but there is now a version for the serial port as well.  There are some example programs supplied which are written in C but not too difficult to understand.  I also purchased a hall effect sensor for a few cents which allows you to trigger your code when passing a magnet.

The detailed instructions on the website are very easy to follow even for beginners and there is also a great forum with loads of support.  Here is some code I put together using the examples provided.  This code will spell out a word each time the sensor passes a magnet.  I testes this by attaching the unit to the wheel of a bike and putting a magnet on the upright.

#include <avr/io.h> // this contains all the IO port definitions
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <util/delay.h>
#include <avr/pgmspace.h>

// This function basically wastes time
void delay_ms( uint16_t milliseconds)
{
for( ; milliseconds > 0; milliseconds–)
{
_delay_ms( 1);
}
}

// We use these macros because binary constants arent always supported. ugh.
#define HEX__(n) 0x##n##UL
#define B8__(x) ((x&0x0000000FLU)?1:0) \
+((x&0x000000F0LU)?2:0) \
+((x&0x00000F00LU)?4:0) \
+((x&0x0000F000LU)?8:0) \
+((x&0x000F0000LU)?16:0) \
+((x&0x00F00000LU)?32:0) \
+((x&0x0F000000LU)?64:0) \
+((x&0xF0000000LU)?128:0)
#define B8(d) ((unsigned char)B8__(HEX__(d)))

// store all the image data in program memory (ROM)
// instead of RAM (the default)
const uint8_t large_image[] PROGMEM = {
B8(00000000),
B8(00000000),
B8(00000000),
B8(00000000),
B8(00000000),
B8(00000000),
B8(00000000),
B8(10000010),
B8(11111110),
B8(10100010),
B8(00100010),
B8(01011100),
B8(10000000),
B8(10000000),
B8(11000000),
B8(10111010),
B8(00100110),
B8(10111000),
B8(11000000),
B8(10000000),
B8(00000000),
B8(01111100),
B8(10000010),
B8(10000010),
B8(10000010),
B8(01000110),
B8(00000000),
B8(10000010),
B8(11111110),
B8(10010010),
B8(00010000),
B8(10010010),
B8(11111110),
B8(10000010),
B8(00000000),
B8(10000010),
B8(11111110),
B8(10010010),
B8(10111010),
B8(11000110),
B8(00000000),
B8(00000000),
B8(10000010),
B8(11111110),
B8(10000010),
B8(10000000),
B8(11100000),
B8(00000000),
B8(00000000),
};

// special pointer for reading from ROM memory
PGM_P largeimage_p PROGMEM = large_image;

#define NUM_ELEM(x) (sizeof (x) / sizeof (*(x)))
int imagesize = NUM_ELEM(large_image);

uint8_t j = 0;

int main(void) {

DDRB = 0xFF; // set port B to output only
PORTB = 0; // turn off all LEDs

DDRD = 0xFB; // one input on pin D2
PORTD = 0x04; // turn on pullup on pin D2

while (1) {
if (PIND & 0x4) { // if the sensor switch is off…
PORTB = 0x0;
} else { // if the sensor switch is on…

for (j =0; j < imagesize + 1; j++)
{
PORTB = pgm_read_byte(largeimage_p + j);
delay_ms(5);
}
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s