17 June 2010

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



No comments:

Post a Comment