'printAddress' was not declared in this scpe

OK problem found, that being a misplaced curly bracket at the end of the code.

Hi All

This is my first time of asking and am a complete novice at this, so please be understanding of this.

I'm trying to write my first code for the Arduino Uno and cobbling two pieces of code together I have managed to get so far but now I get the above error.

The idea is to use up to 10 or 12 DS18B20 temperature sensors and some other analogue sensors to record data from house hold heat sources. Then using the serial USB line to have a program on a Raspberry Pi poll data off the Arduino UNO.

I can read all the analogue and digital inputs and know the DS18B20s work but the error I am getting during compiling gets me and I'm not sure why.

/*
  Serial Call and Response in ASCII
  
*/
                    //Additional code
#include <OneWire.h>
#include <DallasTemperature.h>
                    //Additional ends


int firstSensor = 0;    // first analog sensor
int secondSensor = 0;   // second analog sensor
int thirdSensor = 0;    // digital sensor
int inByte = 0;         // incoming serial byte

                        // Additional code
                        // Data wire is connected to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

                        // Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

                        // Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

int numberOfDevices;    //Number of temperature devices found

DeviceAddress tempDeviceAddress;  // we'll use this variable to store a found device address
                        // *****************New code ends


void setup(void)  
{
  // start serial port at 9600 bps and wait for port to open:
  Serial.begin(9600);
   while (!Serial) 
{
    ; // wait for serial port to connect. Needed for native USB port only
}

  pinMode(2, INPUT);   // digital sensor is on digital pin 2
  establishContact();  // send a byte to establish contact until receiver responds
  
  //New code. Start up the libruary
  sensors.begin();

  // grab a count of devices on the wire
  numberOfDevices = sensors.getDeviceCount();

  // locate devices on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.print(" devices.");

  //  Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)           
  {
    // search wire for the address
    if(sensors.getAddress(tempDeviceAddress, i)) 
        { 
          Serial.print("Found devices ");
          Serial.print(i, DEC);
          Serial.print(" With address");
          printAddress(tempDeviceAddress);
          Serial.println();
        } 
    else 
        {
          Serial.print("Found ghost device at");
          Serial.print(i,DEC);
          Serial.print(" But could not detect address. Check power and cabling");
        }
  }


  // New code ends

 
}


void loop(void) {
  // if we get a valid byte, read analog ins:
  if (Serial.available() > 0) 
  {
    inByte = Serial.read();          // get incoming byte:

    firstSensor = analogRead(A0);    // read first analog input:

    secondSensor = analogRead(A1);   // read second analog input:

    thirdSensor = map(digitalRead(2), 0, 1, 0, 255);    // read switch, map it to 0 or 255

    Serial.print(firstSensor);        // send sensor values:
    Serial.print(",");
    Serial.print(secondSensor);
    Serial.print(",");
    Serial.println(thirdSensor);

     // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures(); 
  
  Serial.print("Celsius temperature: ");
  // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  Serial.print(sensors.getTempCByIndex(0)); 
  Serial.print(" - Fahrenheit temperature: ");
  Serial.println(sensors.getTempFByIndex(0));
  }
}

void establishContact() {
  while (Serial.available() <= 0) {
    Serial.println("0,0,0");   // send an initial string
    delay(300);
  }

// function to print a device address
void printAddress(DeviceAddress deviceAddress) {
  for (uint8_t i = 0; i < 8; i++) {
    if (deviceAddress[i] < 16) Serial.print("0");
      Serial.print(deviceAddress[i], HEX);
  }
  }
}

Sorry it's a bit messy but that's the way my mind works.

Where does the establishContact() function end ?

Good point. I was just looking another question on this forum which asked the very same question. I'll have a look at the answers and try and work out where I'm going wrong.

Thank you for the reply and the question it poses.

Ok found the problem, that being a misplaced curly bracket at the end of the code.