Thursday, November 10, 2011

Test on Wednesday 16/11/11

There will be a test on some of the topics covered during our course on the date above.

It will be a written test but you can refer to anything on the Internet and will need to be able to write and run programs in the Arduino environment. Please bring your Arduinos to the test and also bring a LDR, light dependent resistor as you will be asked to write a program that will involve analogue input.

There will be a question about the front page of the Atmel pdf for the AVR328. You should be able to explain most of the features mentioned there.

There will be a question about different embedded buses and their main features.

You will be asked to write a schematic for a robotic circuit.

There will be other questions on work covered in class.

There will be a revision class the day before so bring any questions along to that.

Sunday, November 6, 2011

Toggling a LED

This is a better way of getting the classic LED toggling Blink program to turn the LED to to alternate state. I'd seen this elsewhere but forgot about it.It was recently suggested by David Beath, a student in our class.

boolean ledState = 0; //in the setup

digitalWrite(13,(ledState = !ledState)); // in the loop

Tuesday, November 1, 2011

PROGMEM example

#include <avr/pgmspace.h>
 char buffer [5];
 word serialCount;
void setup(void)
{
    Serial.begin(38400);
    Serial.println("\nPress space bar .");
//    while (Serial.read() != 32)   delay(1); // Wait for space
 
}
const int mydata[10][10] PROGMEM = {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', 'A',
    '1', '1', '2', '3', '4', '5', '6', '7', '8', 'B',
    '2', '1', '2', '3', '4', '5', '6', '7', '8', 'C',
    '3', '1', '2', '3', '4', '5', '6', '7', '8', 'D',
    '4', '1', '2', '3', '4', '5', '6', '7', '8', 'E',
    '5', '1', '2', '3', '4', '5', '6', '7', '8', 'F',
    '6', '1', '2', '3', '4', '5', '6', '7', '8', 'G',
    '7', '1', '2', '3', '4', '5', '6', '7', '8', 'H',
    '8', '1', '2', '3', '4', '5', '6', '7', '8', 'I',
    '9', '1', '2', '3', '4', '5', '6', '7', '8', 'Z' };

void loop(void) {
    int i,j;
    byte n;
    Serial.println("\nData by Rows.");
    for (i=0; i < 100;i++) {
  // Serial.println(" ");
        if ((i %8)==0) Serial.print("|");
        if ((i %16)==0) Serial.println("");
   n = pgm_read_byte_near(i);
 // Serial.print(n, HEX);
          Serial.print(" ");
          sprintf(buffer, "%02x", n);
          Serial.print(buffer);
          serialCount++;
          
         // Serial.print("\t"); 
     }
    
    Serial.println(" ");
    Serial.println("\nData by Columns.");
    for (i=0; i < 10; i++) {
   Serial.println(" ");
   for (j=0; j < 10; j++) {
  n = pgm_read_word_near(&mydata[j][i]);
  Serial.print(n, BYTE);
   }
    }
    Serial.println(" ");    setup();    Serial.println(" ");  //start over
}
 

Tuesday, October 25, 2011

Timer0 First Program- Polling

/*
  Timer 0 Experiment
 */
int state = 1;
byte ticks, tocks;
long loopCounter;
long popCounter;
unsigned long time;
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT); 
  TIMSK0 = 0;     //turn off Interrupt for Timer0
  TCCR0B = 5; //Prescaler divieds by 1024 
  Serial.begin(9600);
}

void loop() {

   while(byte(TIFR0 &0x01) ==0){}; // loop til flag goes up
    TIFR0 = 1;      //clear flag
    ticks++;
  
    if (ticks == 60) {
      ticks=0; 
      ToggleLED();
  //    Serial.print("TT ");
    }
}
void ToggleLED(){
  if (state==1) {
    digitalWrite(13,LOW);
    state = 0;
  }
  else {
    digitalWrite(13,HIGH);
    state=1;
 //   Serial.print("I've tohggled");
  } 
} 

Sunday, September 18, 2011

IIC or I2C or TWI

The TWI bus

Good tutorial from DigiKey

other training modules of electronic parts from digikey

A good introduction to IIC with an Arduino Focus is here.


The Arduino library with functions that handle the TWI bus is the Wire Library

A good example of using IIC eeproms with Arduinos is here.

A typical IIC device is the eeprom below.





An Arduino setup


and you can join up two Arduinos using the IIC bus




This code worked for me straight from the forum to the freetronics eleven at 24LC256.

And here's the data on the24LC256 eeprom.


Tuesday, September 13, 2011

ZigBee


This is the quickest way to get two Arduinos to talk to each other wirelessly

Tuesday, August 30, 2011

Accelerometers

How do we sense movement and store and display it? Study this IC and come up with a schematic and software to read and display outputs. See the associated task.