Sunday, April 18, 2010

Week 8: Interrupts

Lab 1: External Interrupts.

TBC

Monday, April 12, 2010

Task 34 - 45



34) Write a program to generate 100 random numbers between 0 and 9 to the screen.

long randNumber;

void setup(){
Serial.begin(9600);

// if analog input pin 0 is unconnected, random analog
// noise will cause the call to randomSeed() to generate
// different seed numbers each time the sketch runs.
// randomSeed() will then shuffle the random function.
randomSeed(analogRead(0));

for(int i = 1; i less than 101; i++)
{
randNumber = random(0, 10);
Serial.print(randNumber);
delay(50);
}
}

35) Same as above but this time put your outputs in a numbered list like this: 1. 7 2. 4.
At first I tried putting all the stuff to be printed out into one line like this:
Serial.print( i + ". " + randNumber);
But the apparently the arduino doesn't like to concatenate. The following is what I did to get it to print out correctly.

for(int i = 1; i less than 101; i++)
{
randNumber = random(0, 10);
Serial.print(i);
Serial.print(". ");
Serial.println(randNumber);

36) Same but also output the average (mean) of the 100 numbers with a suitable message.

Same as above, but after the for loop I have included the average:

//mean =
average = sum/100;
Serial.print("Average = ");
Serial.println(average);

The variables "sum" and "average" are initialised first as doubles = 0;

37) Same but this time see if you can drive the baud rate up as far as possible before the output data gets scrambled. Also, what is the slowest speed the Arduino serial will output at? Write your findings in your blog.

For the randomNumbers code the baud rate min was 9600 and max was 14400. Anything outside of this just brought up random text symbols.

38) Write a program to output the value of your LDR whenever you press the button.

const int buttonPin = 2; // the number of the pushbutton pin

int buttonState = 0; // variable for reading the pushbutton status

int photoCellPin = 0;
int photoCellReading;

void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

Serial.begin(9600);
}

void loop(){
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
photoCellReading = analogRead(photoCellPin);
Serial.print("analog reading = ");
Serial.print(photoCellReading);
if (photoCellReading less than 10)
{Serial.println(" - Dark");}
else
if (photoCellReading
less than
200)
{Serial.println(" - Dim");}
else
if (photoCellReading
less than
500)
{Serial.println(" - Light");}
else
if (photoCellReading
less than
800)
{Serial.println(" - Bright");}
else
{Serial.println(" - Very Bright");}
delay(1000);

}
else
{
Serial.print("button is off.");
}
delay(1000);
}

(photos to be added)

39) Same as 38 but this time write your output like this :
Reading number 1 is 345
Reading number 2 is 123
Reading number 3 is 876 etc...

A new variable "count" is created at the top.
int count = 0;

void loop(void)
{

//inside if statement for if the button is pushed

count++;
photoCellReading = analogRead(photoCellPin);
Serial.print("Reading number is ");
Serial.print(Count);
Serial.print(" = ");

Serial.print(photoCellReading);


40)Find an interesting article on the YABB news section and provide a screen shot and a short report on why you found it interesting.

10th Anniversary Surprise !
I found it interesting that this forum has been around for 10 years and it seems that they are genuinely valuing their contributors. Seems like a good time to sign up too as they are seem to be hinting to giving something away on the 4th of July.


41) Register for YABB but don't contribute yet. Take a screen shot of part of your registration process to confirm you've done it.



42) Write a short list of rules for a bulletin board like YABB. Watch some thread over two weeks and be ready to make a contribution.

YaBB asks users before they register to agree to certain rules such as "you will not post any material which is false, defamatory, inaccurate, abusive, vulgar, hateful, harassing, obscene, profane, sexually-oriented, threatening, invasive of a person's privacy, or otherwise in violation of ANY law."

and

"You remain solely responsible for the content of your messages, and you agree to indemnify and hold harmless this forum, and any related websites to this forum. We at this forum also reserve the right to reveal your identity (or any information we have about you) in the event of a complaint or legal action arising from any information posted by you. "

or like the Golden rule from the bitlan site "
lease remember the golden rule, and before you do anything, anything, think to yourself, "Will doing this make me look like an idiot?" If the answer is yes, maybe, or even sometimes no, just don't do it. "

simple things to take others into consideration would be good rules for a forum.
These are basic rules for when I use a forum:
  • Corecct speeling (*correct spelling).
  • Correct information (know that what you are contributing is correct).
  • Be polite (No need to be offensive).

43) You'll need to look at some project sites to get some good ideas for your minor and major projects. Some have been shown in class. Write a list of four good project sites and include a link and a screen shot for each with a comment in your blog.



44) Present to the class a report on one of your assigned devices. You need to tell us what it does and give a little demo of it working on a simple Arduino project. Include in your talk at least three Impress or PowerPoint slides on a USB pen or similar.

Completed - Presentation about the piezo buzzer with Andrew. Demonstration was the tune "twinkle twinkle little star".

45)Explore the way your infrared transmitter sends pulses to the receiver. Set up a little demonstration to be marked in class. You may share this project with another person but both members have to know what's going on. Transmission from one Arduino to another is especially excellent.

For this I created a simple IR detector by using the blink code in Arduino. By connecting the IR emitter to pin 13 and ground, it acts as the LED. When it "blinks" it sends out an IR signal. The I connected the positive end of the IR receiver to 3V, an LED positive end to the IR's negative and then connected the negative end of the LED to ground. This circuit means that the LED will "blink" when there is an IR connection. When something interrupts the signal or the signal gets blocked, the LED will not blink.

(photo coming soon).


Sunday, April 11, 2010

Arduino Pro:


This board is designed for advanced users who want to leave a board embedded in a project: it's cheaper than a Diecimila and easily powered by a battery, but requires additional components and assembly.


The Arduino Pro is a microcontroller board based on the ATmega168 (datasheet) or ATmega328 (datasheet). The Pro comes in both 3.3V / 8 MHz and 5V / 16 MHz versions. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a battery power jack, a power switch, a reset button, and holes for mounting a power jack, an ICSP header, and pin headers. A six pin header can be connected to an FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.

The Arduino Pro is intended for semi-permanent installation in objects or exhibitions. The board comes without pre-mounted headers, allowing the use of various types of connectors or direct soldering of wires. The pin layout is compatible with Arduino shields. The 3.3V versions of the Pro can be powered with a battery.

The Arduino Pro was designed and manufactured by SparkFun Electronics.

This information was taken from: http://arduino.cc/en/Main/ArduinoBoardPro

Thursday, March 18, 2010

Infrared research:

http://www.youtube.com/watch?v=P1pGKZzYbUk

http://www.rtfa.net/tag/arduino

http://robot-overlord.blogspot.com/2009/04/simple-ir-detection-circuit-tutorial.html

Interesting Websites for ideas...


1) http://www.instructables.com/




2) http://www.arduino.cc/playground/Projects/ArduinoUsers




3)www.youtube.com




IR Tailgate Buddy: Robotic Power Wheels Vehicle
http://www.youtube.com/watch?v=Pbob9y5NMQ0



4) http://www.coolcircuit.com/




More tasks...

34) Write a program to generate 100 random numbers between 0 and 9 to the screen.
35) Same as above but this time put your outputs in a numbered list like this:
1. 7
2. 4
3. 9 etc til you get to 100.
36) Same but also output the average (mean) of the 100 numbers with a suitable message.
37) Same but this time see if you can drive the baud rate up as far as possible before the output data gets scrambled. Also, what is the slowest speed the Arduino serail will ouitput at? Write your findings in your blog.
38) Write a program to output the value of your LDR whenever you press the button.
39) Same as 38 but this time write your output like this :
Reading number 1 is 345
Reading number 2 is 123
Reading number 3 is 876 etc...

Next topic will be on reporting back about the YABB board.

Thursday, March 11, 2010

LED project...


My plan for the LED project was to create an electronic dice. I found an example on the internet and tryed to base mine off that. To get the dice to act realisticly, the lights formation would have to be randomized. There was a page on the arduino website which was really useful = http://www.arduino.cc/en/Reference/Random Then i worked out the formation and how it would work. The LEDs would be grouped so that when the random number was called, each LED would not need to be callled individually. The groups were 1, 2, 3 & 4. Code:
int pinLeds1 = 10; //2 corner LEDs
int pinLeds2 = 9; //2 outer middle LEDs
int pinLeds3 = 8; //Other 2 corner LEDs
int pinLed4 = 7; //middle LED
int buttonPin = 6; //Button input reader
int buttonState; //On or off (HIGH/LOW)
int rGen; //random generator variable
int time = 4000; //hold for 4 seconds.

void setup () {
pinMode (pinLeds1, OUTPUT);
pinMode (pinLeds2, OUTPUT);
pinMode (pinLeds3, OUTPUT);
pinMode (pinLed4, OUTPUT);
pinMode (buttonPin, INPUT);
randomSeed(analogRead(0));
}

void loop() {
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH){ //if the button has been pressed
rGen = random(1, 7); //rGen=random number between 1 and 6.

if (rGen == 1){ //light up centre light.
digitalWrite (pinLed4, HIGH);
delay (time);
}

if (rGen == 2){ //Light up 2 corner lights.
digitalWrite (pinLeds1, HIGH); delay (time);
}
if (rGen == 3){ //Light up 2 corner and middle lights.
digitalWrite (pinLeds3, HIGH);
digitalWrite (pinLed4, HIGH);
delay (time);
}
if (rGen == 4){ //Light up all 4 corners.
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds3, HIGH);
delay (time);
}

if (rGen == 5){ //Light up all 4 corners plus middle light.
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds3, HIGH);
digitalWrite (pinLed4, HIGH);
delay (time);
}
if (rGen == 6){ //light up all except middle.
digitalWrite (pinLeds1, HIGH);
digitalWrite (pinLeds2, HIGH);
digitalWrite (pinLeds3, HIGH);
delay (time);
}
} //else if not pressed and time has ended turn all off.
digitalWrite (pinLeds1, LOW);
digitalWrite (pinLeds2, LOW);
digitalWrite (pinLeds3, LOW);
digitalWrite (pinLed4, LOW);
}//end.

At run time, something was not right and nothing lit up at all. Because I was basing mine on one i found on the internet, i went back and looked through what the example had. The bread board i was using was a completely different set up. The example had a ground row that all the resistors were connected too. Mine did not. After checking all the wires and LEDs were connected in the right pattern and formation, I went to check through my code. As this is very low level code it would have been easy to spot any errors, but there appeared to be none. With no other resources avalible to me, I had to show what I had created in class, even though it did not work.

After borrowing another bread board from Adam which had a ground row in it, i was able to re wire up my project and test it! My excitement faded when only a few of the LED lit up, but i quickly realised it was because several of my resistors were ones that I found lying around home, and were not the right level to allow much power to the LEDs. I replaced my ones from home with 7 X 220 ohm resistors that I got from Ashley, reset the Arduino, uploaded the code once again and this time SUCCESS!!! The LEDs light up perfectly and in the formation that was originally intended.

So my main issues for this project were: Lack of basic knowledge (this stuff is all still quite new to me), lack of correct equipment, and fiddly small components!!! (My eyes hurt so much). Other than this, I am very pleased with the final outcome.

Even if all the LEDs are green :P