Hello,
I am trying to connect two DS18B20 temperature sensors via a 1 wire bus. The code complies and runs fine when I use this basic, simple code I found online:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_PIN 8
OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);
// Temperature probe addresses. One for water tank, the other for house ambient
DeviceAddress Probe01 = { 0x28, 0x07, 0xD3, 0x14, 0x05, 0x00, 0x00, 0x88 };
DeviceAddress Probe02 = { 0x28, 0x53, 0x7C, 0x54, 0x05, 0x00, 0x00, 0xC6 };
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
// Initialize the Temperature measurement library
sensors.begin();
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster) for 1 wire devices
sensors.setResolution(Probe01, 10);
sensors.setResolution(Probe02, 10);
}
void loop()
{
delay(1000);
// Command all devices on bus to read temperature of 1 wire devices
sensors.requestTemperatures();
Serial.print("Probe 01 temperature is: ");
printTemperature(Probe01);
Serial.println();
Serial.print("Probe 02 temperature is: ");
printTemperature(Probe02);
Serial.println();
Serial.println();
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error getting temperature ");
}
else
{
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
The problem I am having is when I try to integrate this code with the rest of my code, it doesn't compile. I have tried quite a few things and read a bunch of stuff online, but nothing seems to help.
I have attached the code integrated with the rest of the code so far. I have been building it piece by piece.
Here are the compiler messages:
Arduino: 1.5.7 (Windows 8), Board: "Arduino Uno"
Build options changed, rebuilding all
Tort_Robot_MK_I.ino:11:23: error: variable or field 'printTemperature' declared void
Tort_Robot_MK_I.ino:11:23: error: 'DeviceAddress' was not declared in this scope
Tort_Robot_MK_I.ino: In function 'void ReadTemperature()':
Tort_Robot_MK_I.ino:287:31: error: 'printTemperature' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
I don't know why I get these error messages only when I put this code into my bigger code. It runs fine when I use just the code on its own to run the sensors. It is probably something simple, stupid, and obvious I am doing. Any help would be greatly appreciated. I am out of ideas.
Tort_Robot_MK_I.ino (16 KB)