Hi there forum,
Feeling frustrated is usually the edge of learning something... and I'm frustrated.... feeling a bit stupid even. Hope you guys can make me learn. Guess my bigest problem is with C, programming for the arduino is my first experience with C.
I've been playing around with all sorts of sensors, my latest "project" is reworking a sample sketch to get a function which can give me the reading of a Dallas 18c20. Not exactly rocket science, but I seem to have goofed somewhere. And I can't find where.
The sample sketch I've got reads the temperature just fine... if I put my finger on the sensor the reading goes up, if I take my finger away the reading goes down. Just as you would expect.
My own sketch gives a reading... and that reading never changes.
This is the sketch
// ds18b20 stuff
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress MyDallas = { 0x28, 0x32, 0x11, 0x4E, 0x07, 0x00, 0x00, 0xA3 };
void setup(void) {
// put your setup code here, to run once:
Serial.begin(9600);
sensors.begin();
sensors.setResolution(MyDallas, 10);
}
void getTemp(DeviceAddress deviceAddress){
float tempC = sensors.getTempC(deviceAddress);
Serial.print(tempC);
//return tempC;
}
void loop(void) {
// put your main code here, to run repeatedly:
delay(2000);
//float temp = getTemp(MyDallas);
Serial.print("Temperatuur is: ");
//Serial.print(temp);
getTemp(MyDallas);
Serial.print(" graden C\n\r");
// temp = 0;
}
I've already build the getTemp() function back to a void function printing the value. It should return the reading as a float. But that didn't make a difference.
At the moment I'm quite at a loss on what the problem is. Any help - even a rtfm (with pointer to) - would be apreciated.
Peter