Problems compiling temperature sensor 1 wire code

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)

Hi Kawoogie

Take the integrated code and remove the comments you added to explain the problem. Check that when you compile, you get the same error messages.

Then, in the IDE, do CTRL-T. Do you get an error message about too many curly brackets ({ or })?

If so, you have a mismatch between opening and closing brackets. The problem may be near the function that is reported in the error message.

Regards

Ray

Hi Ray,

Thanks for the suggestions. I did as you suggested. I missed a bracket, but once I added that, I still have compiler issues. I have attached my updated code. Here is the error messages it gives now:

Arduino: 1.5.7 (Windows 8), Board: "Arduino Uno"

Tort_robot_Temp_sensor_troubleshooting.ino:10:23: error: variable or field 'printTemperature' declared void
Tort_robot_Temp_sensor_troubleshooting.ino:10:23: error: 'DeviceAddress' was not declared in this scope

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Does anybody have any suggestions for these errors? I have been trying all kinds of things.

Tort_robot_Temp_sensor_troubleshooting.ino (12 KB)

The problem is in your function printTemperature().

Simple fix: You don't call this function anywhere. If you don't need it, remove it from the program.

More complicated fix:

void printTemperature(DeviceAddress deviceAddress)

The function uses the custom data type DeviceAddress which is created by a typedef in the DallasTemperature library. A peculiarity of the Arduino IDE is that you can't use custom types defined in libraries as arguments to functions in the main program.

Easiest fix is to change your function definition to use the actual data type:

void printTemperature(uint8_t deviceAddress[8])

Another solution would be to edit the DallasTemperature library to remove the typedef and, instead, create a separate .h file with the typedef in it, which you would include in your program.

Thanks Ray!

Huge help. Your post is very informative. It now compiles. I changed this line

void printTemperature(DeviceAddress deviceAddress)

to this line

void printTemperature(uint8_t deviceAddress[8])

I wouldn't have gotten it to compile without your help.