Go Down

Topic: Problems storing thermistor-data to EEPROM and printing (Read 350 times) previous topic - next topic

Ruckus

Code: [Select]
#include <EEPROM.h>

int thermistorPin = A0; // Arduino-pin connected between thermistor and 10k-resistor
int Vo;

float R1 = 10000; // Constant resistor-value
float T0 = 298.15; // T0 for thermistor
float Rntc, temp, temp_c; //
float beta = 3486; // Found via https://www.elfadistrelec.no/Web/Downloads/_t/ds/bx_cx_dx_gx_rx-series_eng_jap_tds.pdf

float temperatureInC(int pinNumber){
  /*Calculates temperature in celsius using a simplified version of
   the Steinhart-Hart-formula
  */

  int voltage;
  voltage = analogRead(pinNumber);
  Rntc = R1 * (1023.0 / Vo - 1.0); // 1023 is the number og analog-levels on arduino-pin
  temp = 1 / T0;
  temp += 1/beta * log(Rntc/R1);
  temp = 1 / temp; // Here the temperature is calculated in Kelvin
  temp = temp - 273.15;

  return temp;
  }
 
    int address = 0;
    int address2 = 0;

    int valueEEPROM = analogRead(thermistorPin) / 5;

    float tempEEPROM(int something){
      EEPROM.read(something);
    }

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

void loop() {
  float printValue = valueEEPROM * 5;
  for(int i = 0; i < 12; i++){
    EEPROM.write(address, valueEEPROM);
    address++;
    delay(3000);
    if(address = EEPROM.length()){
      address = 0;
    }
  if(EEPROM.read(address2) != 0){
    temp_c = temperatureInC(printValue);
    Serial.print(temp_c);
    address2++;
  }
 }
}


I am a poorly experienced programmer and have only been programing in c on the arduino for about two weeks as part of a school-subject (in other words: don't be too harsh if my code is completely useless). What I want and try to do here, is reading an analog-pin (A0) and store that value in EEPROM. When an address's value no longer equals to 0, I want to convert this value to a temperature in celsuis and print this on-screen. Using the delay-function, the loop reads the thermistorpin every 3000nd millisecond, hence, the temperature is being calculated every 3000nd millisecond. For later, I would also want to advance the code to write at what time the different measurements from the different addresses were taken, but I think I would be able to manage myself.
This is all part of an assignment that calls for us to measure the temperature in a room over the course of a day. The arduino will be left in the room with a battery as the power-source. The data shall be retrieveable when the computer is connected to the arduino and I figured using EEPROM would be fitting for this task.

So far the code will compile for the arduino, but nothing is being printed.

I am using an arduino Uno

Nick_Pyner

Your proposed project is incoherent but it appears that you might want to record temperatures at 20 second intervals for a day, from one sensor, and later from several. That looks like 28800 readings - to start with.

First up, do you have an EEPROM that can handle all that data? Even if you do, I submit you would find it easier to use an SD card.

Second, what sort of room is it that warrants temperature readings so frequent? And with a thermistor? I suspect the results will make for some very boring reading.


PaulS

Code: [Select]
float temperatureInC(int pinNumber){
  /*Calculates temperature in celsius using a simplified version of
   the Steinhart-Hart-formula
  */

  int voltage;
  voltage = analogRead(pinNumber);
  Rntc = R1 * (1023.0 / Vo - 1.0); // 1023 is the number og analog-levels on arduino-pin
  temp = 1 / T0;
  temp += 1/beta * log(Rntc/R1);
  temp = 1 / temp; // Here the temperature is calculated in Kelvin
  temp = temp - 273.15;

  return temp;
  }

Why does this function need to return the value in a global variable?

Why do you need two lines of code to declare and initialize a variable?

Code: [Select]
    int valueEEPROM = analogRead(thermistorPin) / 5;
What is the relationship between the value read from a pin that appears to have a thermistor connected to it and some value to be written to/read from EEPROM?

Code: [Select]

    float tempEEPROM(int something){
      EEPROM.read(something);
    }

You lied. You said this function would return a float. It does not. It is pointless to read from EEPROM if you don't care what you read. The documentation for the read() method will tell you what "something" needs to be.

Code: [Select]
    if(address = EEPROM.length()){
      address = 0;
    }

Why are you assigning the length of EEPROM to address in an if statement? The assigned value will certainly not be 0, since the amount of EEPROM is not 0, and since any positive or negative value is true, you will end up with address equal to 0 every time.

= != ==

On every pass through loop(), you write the same nonsense value to the same EEPROM address. Then, you read from some other address, and pass some useless value to temperatureInC() that it thinks is a pin number.

What were you thinking?
The art of getting good answers lies in asking good questions.

Go Up