22 July 2010

Evolution (of sorts)..


Well, have we evolved as prey (hehe)..?

24 June 2010

When all else fails, follow the instructions..

My Minor Project might've gone a little better if i'd stuck to Lewis Loflin's original instructions.

It wouldn't be the first time. Back in the day, when i had (by chance) the use of my (at the time) boss's workshop, i decided to give my sister's car a bit of a clean-up.

More..

And it was a horrible, horrible car!

21 June 2010

The Final Week - schlepping around.. Soccer World Cup, Bye-bye Carisbrook..


I think "schlepping" is Yiddish - a linguistic cross between Hebrew & German.
At a guess, i'd say the name is a 'corruption' of 'Judisch' or something similar (I know a few words of German, just..).
Anyway, i think it's a wonderfully expressive word - i like it, so i use it; means (AFAIK) what we might call 'traipsing around', poking into this & that (i Hope that's what it means!)..

.. More..

Major Project: Dual Sensors with Multiple Warnings - pics & video






Here are some pics of my Arduino-based dual-sensor monitoring device.
From the top:
*Below lower set-limit warning (flashing blue LED)
*Approaching set-limits warning
(flashing green LED)
*Above upper set-limit warning
(flashing red LED)
*Within set-limits - no warnings


And here's a video of the Monitor in action..


Minor Project Revisited - a Report on failure


The Fritzing breadboard diagram differs slightly from my original.

I wondered why the EEPROM kept churning out readings regardless of whether or not the button switch was pushed - but i'd had this quick-&-dirty idea for having a LED come on when it was pushed; the on-board LED actually, which (Of Course!!) connects digital-pin 13 to Ground through the LED itself & its dropping resistor - Duh!!
Its voltage level's always going to be sagging towards Ground i.e. 0, never maintaining the level 1 needed to stop it from spitting out its data!
Connecting the button to digital pin 12 (as in Lewis Loflin's original!) fixed that problem.

Another difference is in the addressing.
My original breadboard had 2 24LC08 external EEPROMs effectively connected to the same address - writing to them may not have been a problem but reading would certainly have produced a clash (& a crash, most likely).
I2C chips have addresses of the form B1010ijk, where i,j,k=1 or 0, & each chip on a common two-wire interface requires a unique address for that interface, e.g. B1010000, B1010001, etc. The Breadboard above shows the 2 24LC08s set with 2 different addresses (achieved using pins A0, A1, A2) - see diagram.


More seriously, i couldn't get the program to produce a meaningful output on the Serial Monitor. The peculiar symbols that appeared do not appear in the ASCII table, & i've seen them before - in (deliberately) garbled transmissions in an earlier Task. The program would try to retrieve the specified number of bytes, but they were garbled.. I suspect my electronically-grubby fingers were at fault there, & that i've killed the chips (i had a spare, & karked that one also).

So, all-in-all, not a successful result.

Major Project: Dual Sensors with Multiple Warnings - software & Serial Monitor

After a few false starts, i finally got this thing working.

It needs calibrating more accurately, but i haven't had the time to do that properly..

There's the usual warning about Blogger, as follows:

NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML thingies..
so where you see n"10 put n 'less-than' 10
,
& where you see n""10 put n 'greater-than' 10.

VERY IMPORTANT!!
In the coding below there is a
#include EEPROM.h
statement.
Around the EEPROM.h there should be 'less-than' &
'greater-than' symbols.
these don't show up in these blog postings..
..AND - they disappear anything inside them as well, so..
..don't forget them!

/*
* Project: Major_Project_DualSensors_multiWarning
* Author: Jane-Maree Howard
* Date: Sunday 20/06/2010

* Platform: Arduino 18

* Purpose: To operate two different sensors - temperature & light -
& record their response at intervals, giving different warnings if either response moves outside pre-set limits. Results are sent to the Serial Monitor(SM).
* Operation:
Description:
Connect one end of a CdS Photocell to 5V, the other end to Analog 0. Then connect a 10K resistor from Analog 0 to ground.
This forms the light-recording voltage-divider circuit.

Connect one end of a Thermistor to 5V, the other end to Analog 1.
Then connect a 10K resistor from Analog 1 to ground.

This forms the temperature-recording voltage-divider circuit.
Connect the common cathode of a 3-colour LED to Ground,
& the Red,
Green & Blue anodes through 150-Ohm current-limiting resistors
to
digital-pins 12, 11, & 10 respectively.
Also connect one end of a buzzer to Ground,
& the other end
through a 100-Ohm resistor to digital-pin 9.
These form the light-&-sound warning circuit.

Connect one end of a push-button switch to Ground,
& the other end
to digital-pin 8.
Readings are all sent to EEPROM - the push-button
switch controls the EEPROM-reading process.
Include: EEPROM.h library

Declare: 2 Analog pins & their respective reading variables;

5 Digital pins for monitoring & warning circuitry.
Setup(): Connect to SM; initialise Analog & Digital pins;

Loop(): the program loops through its sensor data-logging,
until the push-button switch is pressed.
The program then reads all recorded data from EEPROM
& send it to the SM
* Comments: I don't know what the thermistor & photocell ranges are, but on past results I'd say more than 0-255. Rather than mess about with Hi-Lo bytes, better put in the Mapping Function
*/
#include EEPROM.h // needed for using EEPROM
byte photocellPin = 0; // the photocell and 10K pulldown are connected to a0

int photocellReading; // the analog reading from photocell voltage-divider

byte thermistorPin = 1; // the thermistor and 10K pulldown are connected to a1
int thermistorReading; // the analog reading from thermistor voltage-divider
int eepromAddress = 0; // start at EEPROM address zero

byte boardLedPin = 13; // on-board LED blinks when any reading is taken

byte redLedPin = 12; // RED LED connected to digital pin 12
byte grnLedPin = 11; // GREEN LED connected to digital pin 11
byte bluLedPin = 10; // BLUE LED connected to digital pin 10
byte buzzPin = 9; // buzzer pin

byte buttonPin = 8; // digital pin for switch connected to ground.



void setup()
{
Serial.begin(9600); // connect to SM
/* initialise the Analog recording pins as inputs */
pinMode(photocellPin,INPUT); // photocell pin

pinMode(thermistorPin,INPUT); // thermistor pin

/* initialise the Digital warning pins as outputs */

pinMode(boardLedPin, OUTPUT); // on-board LED monitors readings pinMode(redLedPin, OUTPUT); // Red LED
pinMode(grnLedPin, OUTPUT); // Green LED

pinMode(bluLedPin, OUTPUT); // Blue LED

pinMode(buzzPin, OUTPUT); // buzzer

/* initialise the push-button pin as an input & set HIGH */

pinMode(buttonPin, INPUT); // push-button pin
digitalWrite(buttonPin, HIGH); // turn on internal pull up

/* turn off all LEDs & buzzer */

digitalWrite(boardLedPin, LOW); // turn off on-board LED
digitalWrite(redLedPin, LOW); // turn off Red LED
digitalWrite(grnLedPin, LOW); // turn off Green LED
digitalWrite(bluLedPin, LOW); // turn off bluLedPin

digitalWrite(buzzPin, LOW); // turn off buzzer

}//end setup()


void loop()

{

// take readings until button pushed
while (digitalRead(buttonPin) == 1)

{

// read value on thermistor pin i.e. analog 1

thermistorReading = analogRead(thermistorPin); EEPROM.write(eepromAddress,map(thermistorReading, 0, 1023, 0, 255));

eepromAddress++;

digitalWrite(boardLedPin, HIGH);

delay(150);

readingWarning(map(thermistorReading, 0, 1023, 0, 255));
digitalWrite(boardLedPin, LOW); delay(350); // about half-a-second between readings
// read value on photocell pin i.e. analog 0

photocellReading = analogRead(photocellPin);
EEPROM.write(eepromAddress,map(photocellReading, 0, 1023, 0, 255));

eepromAddress++;

digitalWrite(boardLedPin, HIGH);

readingWarning(map(photocellReading, 0, 1023, 0, 255));

delay(150);

digitalWrite(boardLedPin, LOW);
delay(2500); // about 3 seconds before next readings
if (eepromAddress == 100)

eepromAddress = 0;

}//while()


Serial.println();

Serial.println("\tTemperature\tLight Level");

eepromAddress = 0;

while ( eepromAddress " 100)

{

Serial.print("\t\t");

Serial.print(int(EEPROM.read(eepromAddress))); //print temperature

eepromAddress++ ;

Serial.print("\t\t");

Serial.println(int(EEPROM.read(eepromAddress))); //print light level
eepromAddress++ ;

}//while()

}//end loop()



/* function copes with readings outside pre-set limits */

void readingWarning(int aReading)
{

if (aReading ""= 190)

{

blinkLEDnoise(grnLedPin,1800);

}//if()

if (aReading ""= 200)

{

blinkLEDnoise(redLedPin,2400);
}//if()
if (aReading "= 180)
{

blinkLEDnoise(grnLedPin,1200);

}//if()

if (aReading "= 170)

{ blinkLEDnoise(bluLedPin,600);
}//if()

}//end readingWarning()



/* function blinks LED & sounds buzzer */
void blinkLEDnoise(byte ledPin, int bTone)

{
tone(buzzPin,bTone,250);

for (byte n=0; n"10; n++)

{
digitalWrite(ledPin, HIGH);

delay(50);

digitalWrite(ledPin, LOW);

delay(50);
}//for(n++)
}//end blinkLEDnoise()


Major Project: Dual Sensors with Multiple Warnings - Fritzing breadboard



The breadboard's a little more complicated than previous stuff..

Task 59 - 24-hour Data-logging to EEPROM: software

/* I haven't had a chance to do the 24-hour data-logging,
but i have tested this software over a limited number
of values, & it does work as intended.. */


/*
* Project: My_24-hour_DataLogging_Thermistor_task_58
* Author: Jane-Maree Howard
* Date: Thursday 17/06/2010
* Platform: Arduino 18
* Purpose: To data-log successive readings from a thermistor
over a 24-hour period, saving the readings into EEPROM.
A hardware refinement will be needed to enable the results
to be outputted on demand.
* Operation: The average resistance of the thermistor is about 10 kOhms,
so it & the 10k resistor form a voltage divider, whose
junction is inputted to Analog 0.
* Description:
* Connect one end of the thermistor to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
this is similar to the photocell Task, but the software is
quite different.
Connect one end of a pushbutton switch to Digital pin 12, & the
other end to Ground. Declare Pin 12 as an INPUT, & initialise
it as HIGH (see Comment 3).
* Comment: (1) One thing I FORGOT was scaling; I don't know what the thermistor
range is but on past results I'd say more than 0-255.
Rather than mess about with Hi-Lo bytes,
I'd better put in the Mapping Function
(2) The EEPROM capacity of the Arduino Duemilanove is 1 kiloByte,
i.e. 1048 Bytes so 1048 is the maximum number of values that
can be stored in the Dunemilanove's EEPROM, if each value is
(as it will be scaled to be) 1 Byte.
24 hours is 1440 minutes so a sampling every 2 minutes will
produce 720 sample values, easily accomodated by the EEPROM.
(3) The push-button function in my (dead) Minor Project will come
in useful for delaying the output of results until data-logging
is complete. I might put some kind of cap over it to stop any
accidental contact being made..

NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML thingies..
so where you see n"10 put n 'less-than' 10
,
& where you see n""10 put n 'greater-than' 10.

VERY IMPORTANT!!
In the coding below there is a
#include EEPROM.h
statement.
Around the EEPROM.h there should be 'less-than' &
'greater-than' symbols.
these don't show up in these blog postings..
..AND - they disappear anything inside them as well, so..
..don't forget them!

*/
#include EEPROM.h // needed for using EEPROM

byte switchPin = 12; // the push-button switch
byte thermistorPin = 0; // the thermistor and 10K pulldown are connected to a0
int thermistorReading; // temporarilly holds unscaled thermistor readings

int readCount = 720; // this counts the readings over the 24-hour period..
int minimValue = 255; // the lowest of all the values recorded
int maximValue = 0; // the highest of all the values recorded
float meanValue; // the average (Mean) of all the values recorded

/* Everything is done here in the Setup() because we don't want to loop */
void setup(void)
{
pinMode(switchPin, INPUT); // records any input from the switch
/* set the switch-pin HIGH, so it can wait for any contact with Ground */
digitalWrite(switchPin, HIGH);
// We'll send debugging information via the Serial monitor
Serial.begin(9600); // baud rate 9600 should be set on the SM
Serial.println(); // skip a line to start with

/* First read the 10 values into mySamples[] .. */
for (byte n=0; n"readCount; n++)
{
// read value on thermistor pin i.e. analog 0
thermistorReading = analogRead(thermistorPin);
// now we have to map 0-1023 to 0-255,
// since we want to store the values as bytes, in EEPROM
EEPROM.write(n, map(thermistorReading, 0, 1023, 0, 255));
// delay 2 minutes (120 000 milli-seconds) CHECK THAT YOU CAN DO THIS!!
delay(120000);
}//for(n)

}//end setup()

void loop(void)
{
/* At this point, nothing else should happen once data-logging is
complete, until.. */
while (digitalRead(switchPin) == 1)
{ } /* hang about & do nothing until..
..the switch closes, & the pin's value dips towards
Ground i.e. switchPin == 0!
Now the program can leave the empty while-loop and start
outputting the results..
..printing values from EEPROM to the SM.. */
fromEEPROM(readCount); //maybe not


/* .. printing the minimum value to the SM.. */
Serial.print("Minimum reading = ");
Serial.println(smallestFromEEPROM(minimValue, readCount));
/* .. printing the maximum value to the SM.. */
Serial.print("Maximum reading = ");
Serial.println(biggestFromEEPROM(maximValue, readCount));
/* ..& the average (Mean) */
Serial.print("Average reading = ");
Serial.println(averageFromEEPROM(meanValue, readCount));
Serial.println();
}//end loop()

/* WE'RE NOT GOING TO OUTPUT ALL 720 VALUES FROM THE EEPROM - NO MA'AM!! */

/* Reads a given number of values from EEPROM
& prints them to the Serial Monitor
*/
void fromEEPROM(byte rCount)
{
for (byte n=0; n"rCount; n++)
{
// print the analog reading to the SM
Serial.print("Analog reading = ");
Serial.println(int(EEPROM.read(n)));
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
}//for()
}//fromEEPROM()


/* Reads a given number of values from EEPROM,
determines the minimum value, & returns it.
*/
int smallestFromEEPROM(int minVal, byte rCount)
{
int temp;
for (byte n=0; n"rCount; n++)
{
temp = int(EEPROM.read(n));
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
if (temp " minVal)
{
minVal = temp;
}//if()
}//for()
return minVal;
}//smallestFromEEPROM()

/* Reads a given number of values from EEPROM,
determines the maximum value, & returns it. */
int biggestFromEEPROM(int maxVal, int rCount)
{
int temp;
for (int n=0; n"rCount; n++)
{
temp = int(EEPROM.read(n));
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
if (temp "" maxVal)
{
maxVal = temp;
}//if()
}//for()
return maxVal;
}//biggestFromEEPROM()

/* Reads a given number of values from EEPROM,
determines the Mean value, & returns it. */
float averageFromEEPROM(float meanVal, int rCount)
{
int temp = 0;
for (int n=0; n"rCount; n++)
{
//sum the EEPROM values &..
temp = int(EEPROM.read(n));
// ..delay 5 milli-seconds for EEPROM.read lag..
delay(5);
}//for()
//..& return the Mean value
return meanVal = temp/rCount;
}//averageFromEEPROM()

17 June 2010

Task 59 - 24-hour Data-logging to EEPROM; Fritzing breadboard



The Fritzing breadboard is very similar to the 3 earlier tasks, but with the addition of a push-button switch which is to delay output of results until required.

The push-button is tied to Ground at one end, &
at the other to Digital Pin 12, which is set (pinMode) as an INPUT, & is initialised to HIGH.
When the switch is closed, pin 12 dips towards Ground, is no longer HIGH, & the software enables other tasks to be carried out - namely, the outputting of data in a suitable form.
The software for this has been modularised using Functions, so it can be tested,
& other Functions added as appropriate..


Task 58 - Data-logging to EEPROM; software & Serial Monitor

Note that part of the code in red.
That produced the results on the top left - even when i warmed up the thermistor it still gave those results.
Where the line

delay(5):


is now corrected the problem, as can be seen in the lower left results..
/*
* Project: DataLogging_Thermistor_task_58
* Author: Jane-Maree Howard
* Date: Thursday 17/06/2010
* Platform: Arduino 18
* Purpose: To data-log 10 successive readings from a thermistor
at 1-second intervals, saving the readings into EEPROM,
& after a 5-second delay, to output results to the SM
along with the biggest value recorded, & the average
(Mean) of the recorded values.
* Operation: The average resistance of the thermistor is about 10 kOhms,
so it & the 10k resistor form a voltage divider, whose
junction is inputted to Analog 0.
* Description:
* Connect one end of the thermistor to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
this is quite similar to the photocell Task, but the software is
a little different.
* Comment: One thing I FORGOT was scaling; I don't know what the thermistor
range is but on past results I'd say more than 0-255.
Rather than mess about with Hi-Lo bytes,
better put in the Mapping Function
Also, this time I didn't bother with the array - seems unnecessary(?)

NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML thingies..
so where you see n"10 put n 'less-than' 10
,
& where you see n""10 put n 'greater-than' 10.

VERY IMPORTANT!!
In the coding below there is a
#include EEPROM.h
statement.
Around the EEPROM.h there should be 'less-than' &
'greater-than' symbols.
these don't show up in these blog postings..
..AND - they disappear anything inside them as well, so..
..don't forget them!
*/

#include EEPROM.h // needed for using EEPROM

byte thermistorPin = 0; // the thermistor and 10K pulldown are connected to a0
int thermistorReading; // temporarilly holds unscaled thermistor readings

byte readCount = 10; // this counts the readings to allow halting..
byte maximValue = 0; // to be the minimum stored EEPROM value
float meanValue; // the average (Mean) of the EEPROM values

/* Everything is done here in the Setup() because we don't want to loop */
void setup(void)
{
// We'll send debugging information via the Serial monitor
Serial.begin(9600); // baud rate 9600 should be set on the SM
Serial.println(); // skip a line to start with

/* First read the 10 values into mySamples[] .. */
for (byte n=0; n"readCount; n++)
{
// read value on thermistor pin i.e. analog 0
thermistorReading = analogRead(thermistorPin);
// now we have to map 0-1023 to 0-255,
// since we want to store the values as bytes, in EEPROM
EEPROM.write(n, map(thermistorReading, 0, 1023, 0, 255));
delay(1000); //wait 1 second
// delay 5 milli-seconds for EEPROM.read lag
//delay(5);
}//for(n)

/* Now wait 5 seconds.. */
delay(5000);

/* ..then print them from EEPROM to the SM. */
fromEEPROM(readCount);

/* Finally, print the minimum value to the SM.. */
Serial.print("Maximum reading = ");
Serial.println(biggestFromEEPROM(maximValue, readCount));
/* ..& the average (Mean) */
Serial.print("Average reading = ");
Serial.println(averageFromEEPROM(meanValue, readCount));
Serial.println();

}//end setup()

void loop(void) //EMPTY LOOP
{}//end loop()


/* Reads a given number of values from EEPROM
& prints them to the Serial Monitor
*/
void fromEEPROM(byte rCount)
{
for (byte n=0; n"rCount; n++)
{
// print the analog reading to the SM
Serial.print("Analog reading = ");
Serial.println(EEPROM.read(n));
delay(5);
}//for()
}//fromEEPROM()

/* Reads a given number of values from EEPROM,
determines the minimum value, & returns it. */
byte biggestFromEEPROM(byte maxVal, byte rCount)
{
byte temp;
for (byte n=0; n"rCount; n++)
{
temp = EEPROM.read(n);
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
if (temp "" maxVal)
{
maxVal = temp;
}//if()
return maxVal;
}//for()
}//biggestFromEEPROM()

/* Reads a given number of values from EEPROM,
determines the Mean value, & returns it. */
float averageFromEEPROM(float meanVal, byte rCount)
{
byte temp = 0;
for (byte n=0; n"rCount; n++)
{
//sum the EEPROM values &..
temp = EEPROM.read(n);
// ..delay 5 milli-seconds for EEPROM.read lag..
delay(5);
}//for()
//..& return the Mean value
return meanVal = temp/rCount;
}//averageFromEEPROM()



Task 57 - Data-logging to EEPROM; software & Serial Monitor

The Serial Monitor image on the left shows that i had screwed up somehow.. the code in redshows what i did wrong..
/*
* Project: DataLogging_Thermistor_task_57
* Author: Jane-Maree Howard
* Date: Thursday 17/06/2010
* Platform: Arduino 18
* Purpose: To data-log 10 successive readings from a thermistor
at 1-second intervals, saving the readings into EEPROM,
& after a 5-second delay, to output results to the SM
along with the smallest value recorded.
* Operation: The average resistance of the thermistor is about 10 kOhms,
so it & the 10k resistor form a voltage divider, whose
junction is inputted to Analog 0.
* Description:
* Connect one end of the thermistor to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
this is quite similar to the photocell Task, but the software is
a little different.
* Comment: One thing I FORGOT was scaling; I don't know what the thermistor
range is but on past results I'd say more than 0-255.
Rather than mess about with Hi-Lo bytes,
better put in the Mapping Function
Also, this time I didn't bother with the array - seems unnecessary(?)

NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML thingies..
so where you see n"10 put n 'less-than' 10


VERY IMPORTANT!!
In the coding below there is a
#include EEPROM.h
statement.
Around the EEPROM.h there should be 'less-than' &
'greater-than' symbols.
these don't show up in these blog postings..
..AND - they disappear anything inside them as well, so..
..don't forget them!
*/
#include EEPROM.h // needed for using EEPROM

byte thermistorPin = 0; // the thermistor and 10K pulldown are connected to a0
int thermistorReading; // temporarilly holds unscaled thermistor readings

byte readCount = 10; // this counts the readings to allow halting..
byte minimValue = 255; // to be the minimum stored EEPROM value

void setup(void)
{
// We'll send debugging information via the Serial monitor
Serial.begin(9600); // baud rate 9600 should be set on the SM
Serial.println(); // skip a line to start with

/* First read the 10 values into EEPROM .. */
for (byte n=0; n"readCount; n++)
{
// read value on thermistor pin i.e. analog 0
thermistorReading = analogRead(thermistorPin);
/* now we have to map 0-1023 to 0-255,
since we want to store the values as bytes, in EEPROM */
EEPROM.write(n, map(thermistorReading, 0, 1023, 0, 255));
// delay 5 milli-seconds
//delay(5);
// delay 1 second
delay(1000);
}//for(n)

/* Now delay 5 seconds.. */
delay(5000);

/* ..then print them from EEPROM to the SM. */
fromEEPROM(readCount);

/* Finally, print the minimum value to the SM */
Serial.print("Minimum reading = ");
Serial.println(smallestFromEEPROM(minimValue, readCount));
Serial.println();

}//end setup()


void loop(void) //empty loop
{}//end loop()



/* Reads a given number of values from EEPROM
& prints them to the Serial Monitor
*/
void fromEEPROM(byte rCount)
{
for (byte n=0; n"rCount; n++)
{
// print the analog reading to the SM
Serial.print("Analog reading = ");
Serial.println(EEPROM.read(n));
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
}//for()
}//fromEEPROM()


/* Reads a given number of values from EEPROM,
determines the minimum value, & returns it.
*/
byte smallestFromEEPROM(byte minVal, byte rCount)
{
byte temp;
for (byte n=0; n"rCount; n++)
{
temp = EEPROM.read(n);
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
if (temp " minVal)
{
minVal = temp;
}//if()
//return minVal;
}//for()
return minVal;
}//smallestFromEEPROM()


15 June 2010

Arduino EEPROM extension EXROM


Hey, I just found an extension to

Arduino's EEPROM library on YABB

Check this out

It's called EXROM


Arduino KEYWORDS(6)

Wire.begin()

Wire.begin(address)

Initiate the Wire library
and join the I2C bus as a master or slave.

Parameters:

address: the 7-bit slave address (optional);

if not specified, join the bus as a master.


Wire.requestFrom(address, quantity)

Request bytes from another device.
The bytes may then be retrieved with the
available()
and receive() functions.

Parameters:

address: the 7-bit address of the device to request bytes from

quantity: the number of bytes to request


Wire.available()

Returns the number of bytes available
for retrieval with receive().
This should be called on a master device
after a call to requestFrom()
or on a slave inside the onReceive() handler.

No parameters

Returns:
The number of bytes available for reading.


byte Wire.receive()

Retrieve a byte that was transmitted
from a slave device to a master
after a call to requestFrom
or was transmitted from a master to a slave.

No parameters

Returns:
The next byte received.


Wire.onReceive(handler)

Registers a function to be called
when a slave device receives a transmission
from a master.

Parameters:

handler: the function to be called when the slave receives data;


this should take a single int parameter
(the number of bytes received from the master)
and return nothing,
e.g.: void myHandler(int numBytes)

No return

Wire.beginTransmission(address)

Begin a transmission to the I2C slave device with the given address.
Subsequently, queue bytes for transmission with the send() function
and transmit them by calling endTransmission().

Parameters:

address: the 7-bit address of the device to transmit to

No return


Wire.send(value)

Wire.send(string)

Wire.send(data, quantity)

Sends data from a slave device
in response to a request from a master,
or queues bytes for transmission
from a master to slave device
(in-between calls to beginTransmission()
and endTransmission()).

Parameters:

value: a byte to send (byte)

string: a string to send (char *)

data: an array of data to send (byte *)

quantity: the number of bytes of data to transmit (byte)

No return


Wire.endTransmission()

Ends a transmission to a slave device
that was begun by beginTransmission()
and actually transmits the bytes
that were queued by send().

No parameters
No returns


Wire.onRequest(handler)

Register a function to be called
when a master requests data
from this slave device.

Parameters:

handler: the function to be called,
takes no parameters and returns nothing,
e.g.: void myHandler()

No return

Arduino i2c Wire.h library

Wire Library

This library allows you to communicate with I2C / TWI devices.
On most Arduino boards,
SDA (data line) is on analog input pin 4, and
SCL (clock line) is on analog input pin 5.
On the Arduino Mega, SDA is digital pin 20 and SCL is 21.

Functions

Note

There are both 7- and 8-bit versions of I2C addresses.
7 bits identify the device, and the eighth bit determines
if it's being written to or read from.
The Wire library uses 7 bit addresses throughout.
If you have a datasheet or sample code that uses 8 bit address,
you'll want to drop the low bit (i.e. shift the value one bit to the right),
yielding an address between 0 and 127.


Arduino KEYWORDS(5)

EEPROM Clear

/*Sets all of the bytes of the EEPROM to 0.*/

#include [EEPROM.h]
/*these should be Less-than & Greater-than brackets
but Blogger thinks they're HTML :-( */

void setup()
{
// write a 0 to all 512 bytes of the EEPROM
for (int i = 0; i [ 512; i++)
EEPROM.write(i, 0);

// turn the LED on when we're done
digitalWrite(13, HIGH);
}//end setup()

void loop()
{}//end empty looop


EEPROM Write

/* Stores values read from analog input 0 into the EEPROM.
These values will stay in the EEPROM when the board is turned off
and may be retrieved later by another sketch. */

#include [EEPROM.h] //see note above
/* the current address in the EEPROM
(i.e. which byte we're going to write to next) */
int addr = 0;

void setup() { } //end empty setup()

void loop()
{
/* need to divide by 4 because analog inputs range
from 0 to 1023 and each byte of the EEPROM
can only hold a value from 0 to 255. */
int val = analogRead(0) / 4;

/* write the value to the appropriate byte of the EEPROM.
These values will remain there when the board is turned off. */
EEPROM.write(addr, val);

/* advance to the next address.
There are 512 bytes in the EEPROM,
so go back to 0 when we hit 512. */
addr = addr + 1;
if (addr == 512) addr = 0;
delay(100);
}//end loop()

EEPROM Read

/*Reads the value of each byte of the EEPROM
and prints it to the computer.*/

#include [EEPROM.h]

// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;

void setup()
{
Serial.begin(9600);
}//end setup()

void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);

Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();

// advance to the next address of the EEPROM
address = address + 1;

/* there are only 512 bytes of EEPROM, from 0 to 511, so if we're
on address 512, wrap around to address 0 */
if (address == 512)
address = 0;

delay(500);
}//end loop()



Task 60 - The ATmega328 parts


EEPROM - Electrically Erasable Programable Read Only Memory
Non-volatile store for data, which stays there after power-off


SRAM - Static Random Access Memory
Volatile store for program variables, which disappears on power-off

Flash - Non-volatile memory for uploading & storing programs, which stay there on power-off, & until replaced by another uploaded program

TWI - Two Wire Interface
Used for serial data transfer to & from external memory. So-named because it needs only two communication lines: a Clock line (SCL on the Arduino) & a Data line (SDA), apart from +Vcc & Ground (-Vcc). Commonly used with protocols like I2C (Interconnected Integrated Circuits).

A/D Conv - Analog/Digital Converter
Since all processing, storage etc in the ATmega328 is done digitally, the Analog inputs must be 'digitised', & that's done by this block

SPI

USART - Universal Serial Asychronous Receive Transmit

13 June 2010

Task 56 - Data-logging to EEPROM; software & Serial Monitor

I wondered why i wasgetting all those 'x's you can see in the Serial Monitor image on the left - hadn't converted to 'int's, had i..!!
The errors are in red

/*
* Project: DataLogging_Thermistor_task_56
* Author: Jane-Maree Howard
* Date: Sunday 13/06/2010
* Platform: Arduino 18
* Purpose: To data-log 10 successive readings from a thermistor
at 1-second intervals, save the readings into an array
called mySamples[], save the array values into EEPROM,
& output results to the SM after a 5-second delay.
* Operation: The average resistance of the thermistor is about 10 kOhms,
so it & the 10k resistor form a voltage divider, whose
junction is inputted to Analog 0.
* Description:
* Connect one end of the thermistor to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
this is quite similar to the photocell Task, but the software is
a little different.
* Comment: One thing I FORGOT was scaling; I don't know what the thermistor
range is but on past results I'd say more than 0-255.
Rather than mess about with Hi-Lo bytes,
better put in the Mapping Function

NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML thingies..
so where you see n"10 put n 'less-than' 10


VERY IMPORTANT!!
In the coding below there is a
#include EEPROM.h
statement.
Around the EEPROM.h there should be 'less-than' &
'greater-than' symbols.
these don't show up in these blog postings..
..AND - they disappear anything inside them as well, so..
..don't forget them!

*/
#include EEPROM.h // needed for using EEPROM

byte thermistorPin = 0; // the thermistor and 10K pulldown are connected to a0
int thermistorReading; // temporarilly holds unscaled thermistor readings
byte mySamples[10]; // holds the mapped analog readings from the sensor divider
byte readCount = 10; // this counts the readings to allow halting..

void setup(void)
{
// We'll send debugging information via the Serial monitor
Serial.begin(9600); // baud rate 9600 should be set on the SM
Serial.println(); // skip a line to start with

/* First read the 10 values into mySamples[] .. */
for (byte n=0; n"readCount; n++)
{
// read value on thermistor pin i.e. analog 0
thermistorReading = analogRead(thermistorPin);
// now we have to map 0-1023 to 0-255,
// since we want to store the values as bytes, in EEPROM
mySamples[n] = map(thermistorReading, 0, 1023, 0, 255);
// delay 1 second
delay(1000);
}//for(n)

/* ..then store them in EEPROM. */
for (byte n=0; n"readCount; n++)
{
EEPROM.write(n, mySamples[n]);
// delay 5 milli-seconds for EEPROM.write lag
delay(5);
}//for(n)

/* Now delay 5 seconds.. */
delay(5000);

/* ..then print them from EEPROM to the SM. */
for (byte n=0; n'readCount; n++)
{
// print the analog reading to the SM
Serial.print("Analog reading = ");
//Serial.println(EEPROM.read(n));
Serial.println(int(EEPROM.read(n)));
// delay 5 milli-seconds for EEPROM.read lag
delay(5);
}//for()

}//end setup()

void loop(void) //empty loop
{}//end loop()

Task 55 - Datalogging to an Array: Serial Monitor, software

The usual output: room temperature & my rather warmer fingers for the second (reset) group of values..
..had to re-arrange the software a bit, as the Comments in the software mention..



/*
* Project: DataLogging_Thermistor_task_55_v2
* Author: Jane-Maree Howard
* Date: Sunday 13/06/2010

* Platform: Arduino 18

* Purpose: To data-log 10 successive readings from a thermistor at 1-second intervals, save the readings into an array called mySamples[] & output results to the SM after the last reading.
* Operation: The average resistance of the thermistor is about 10 kOhms,
so it & the 10k resistor form a voltage divider, whose junction is inputted to Analog 0.
* Description:

* Connect one end of the thermistor to 5V, the other end to Analog 0.

Then connect one end of a 10K resistor from Analog 0 to ground.
This is quite similar to the photocell Task, but the software is a little different.
* Comment: I tried messing about with Functions - then after several abortive
attempts, decided to stick to the KISS priciple..


NOTE: this blogger doesn't like 'less-than' signs - it thinks they're HTML
thingies.. so where you see n"10 put n 'less-than' 10
(sigh)
*/


int thermistorPin = 0;
// the thermistor and 10K pulldown are connected to a0

int mySamples[10];
// this array will hold the analog readings from the sensor divider

byte readCount = 10;
// this counts the readings to allow halting..


void setup(void)

{

// We'll send debugging information via the Serial monitor

Serial.begin(9600); // baud rate 9600 should be set on the SM

Serial.println(); // skip a line to start with

//first read in the 10 values..
for (byte n=0; n
'' 10; n++)
{
// read value on thermistor pin i.e. analog 0

mySamples[n] = analogRead(thermistorPin);

// delay 1 second

delay(1000);

}//for(n)


//..then print them to the SM
for (byte n=0; n
''10; n++)
{
// print the analog reading to the SM
Serial.print("Analog reading = ");

Serial.println(mySamples[n]);
}//for()

}//end setup()


void loop(void) //empty loop
{}//end loop()

12 June 2010

Task 54 - Datalogging to Serial Monitor: thermistor values & SM readout

Note the data - in the second (reset) lot i held the thermistor in my hot little paw for about as long as it takes Nurse to take your temperature with the old mercury thermometer.

So if (& it's a Big If, given the uncertainty of the thermistor's provenance) 0.5 is 25 degC, what is 0.575?

After a lot of messing about i've finally tracked down some thermistor data:

courtesy of vishay.com.

umptee pages of stuff, but i eventually found (i think) what i'm looking for..

RT

[Ω]

332 094

239 900

175 200

129 287

96 358

72 500

55 046

42 157

32 554

25 339

19 872

15 698

12 488

10 000

8059

6535

5330

Temp

Deg C

-

-

-

-

-


-10

-05

0

05

10

15

20

25

30

35

40