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()

2 comments:

  1. Time of posting: 11:00 AM (??!!)
    Why am i back here at this ungodly hour on a
    Sunday(!!) morning?

    Well, when i got home, i notice one of my rings was missing.
    It's sterling silver (coz i can't wear the cheaper nickel-silver alloys - they give me a nasty rash), but it's not that expensive.
    It's mainly of sentimental value - i bought it in a street market in Silom Road in Bangkok - so i wanted it back.

    Where had i been earlier? Here, & @ Govs Cafe..
    ..found it @ Govs, had a quick brekkie & thort:
    "Since i came all the way into town to look 4 my ring, i may as well stay & do some wrk on a fast 'puter with broadband that's betta than mine & probly no viruses..

    ..so here i am!
    But not 4 long, i'm feelin tired..
    Cya :-)

    ReplyDelete
  2. I'm really NOT sure what Embedded Notices Task 56 actually means - so i've had a 'dollar each way' as a punter (on the geegees or doggies would say)..

    I've saved the results to an array &..
    ..written them to EEPROM & read them back.

    But i Rather Suspect that the array was unnecessary, because it's kinda redundant really..
    ..but then again, Tasks 57 & 58 are a lot easier with an array..

    (sigh) i don't know..
    ..later gator!
    ..outa here!

    ReplyDelete