I'm trying to make a general code for reading and writing data from a temperature sensor to and from EEPROM for later use (i plan to buy an EEPROM chip soon, but just experimenting with the arduino's on board for now.
Two questions really, first i tried to write code to send each Temp. readings to the EEPROM with each reading going to a new address (code is based on basic temperature input to serial, and EEPROM examples combined basically, as i have to start somewhere being an absolute beginner to programming).
#include <EEPROM.h>
int tempPin = 0; //initialise temperature pin analog 0.
int i;
void setup()
{
Serial1.begin(9600); //begin serial connect.
Serial.begin(9600);
}
void loop()
{
float temperature = getVoltage(tempPin);
temperature = (temperature - .5) * 100; //convert mV to deg.
EEPROM.write(i,temperature); //write to EEPROM, new address>new reading
Serial.println(EEPROM.read(i));
i++;
delay(3000);
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814); //convert to right voltage range
}
I get complete garbage when it outputs though and and i'm not sure why any ideas? ive searched the forum and found functions to call values etc. which seem similar.., but have a feeling im just missing something simple i should understand but don't.
Secondly once i can get this initial code working, is there a way to fill up each address with bytes (rather than just 1), then move to the next address and so forth?
thanks for any help you can give!