17 June 2010

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


No comments:

Post a Comment