Cannot See where I am going Wrong!!

Hello everyone.

I have stitched this sketch together from two sketches that work on there own.

I keep getting an error that says "{" is not supposed to be there. In layman terms for you Gurus.

Here is the sketch.

/*
Demonstration sketch for Adafruit i2c/SPI LCD backpack
using MCP23008 I2C expander
( i2c/SPI LCD Backpack )

This sketch prints "Hello World!" to the LCD
and shows the time.

The circuit:

  • 5V to Arduino 5V pin
  • GND to Arduino GND pin
  • CLK to Analog #5
  • DAT to Analog #4
    */

// include the library code:
#include <Wire.h>
#include <LiquidTWI.h>
#include <OneWire.h>
#include <DallasTemperature.h>

int tempPin = 0;
int lightPin = 1;

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidTWI lcd(0);

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

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

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

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// Arduino 1-Wire Address Finder

DeviceAddress insideThermometer = { 0x28, 0x61, 0x40, 0x15, 0x06, 0x00, 0x00, 0x6B };
DeviceAddress outsideThermometer = { 0x28, 0x2E, 0x72, 0x48, 0x05, 0x00, 0x00, 0x9C };
//DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);

// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);
//sensors.setResolution(dogHouseThermometer, 10);
}

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));

}

void loop()

{

// Display Temperature in C
int tempReading = analogRead(tempPin);
float tempVolts = tempReading * 5.0 / 1024.0;
float tempC = (tempVolts - 0.5) * 100.0;
float tempF = tempC * 9.0 / 5.0 + 32.0;
// ----------------
lcd.setCursor(3, 0);
lcd.print("ROOM TEMP ");
lcd.setCursor(6,1);
lcd.print(tempF);

delay (5000);

lcd.clear();

// Display LIGHT SENSOR on first row

lcd.setCursor(2, 0);
lcd.print("LIGHT SENSOR");

// ----------------
int lightReading = analogRead(lightPin);
lcd.setCursor(7, 1);
lcd.print(lightReading);

delay(5000);

lcd.clear();

// Display Dallas TEMP 0 on first row
lcd.setCursor(3, 0);
lcd.print("Dallas TEMP 0 ");
printTemperature(insideThermometer);
lcd.setCursor(7, 1);
lcd.print(insideThermometer);

delay(5000);

lcd.clear();

// Display Dallas TEMP 1 on first row
lcd.setCursor(3, 0);
lcd.print("Dallas TEMP 1 ");
printTemperature(outsideThermometer);
lcd.setCursor(7, 1);
lcd.print(outsideThermometer);

delay(5000);

lcd.clear();

}

Can you see what I am not seeing and give my some guidance.

Thanks to all that reply.

onecansay.

Can you see what I am not seeing and give my some guidance.

I can see that you did not post code properly.

I can see that your indenting sucks.

I can see a whole lot of useless white space.

I can see that the stupidest function ever posted on the internet does not have a closing }.

Maybe this can help:

/*
 Demonstration sketch for Adafruit i2c/SPI LCD backpack
 using MCP23008 I2C expander
 ( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )

 This sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * 5V to Arduino 5V pin
 * GND to Arduino GND pin
 * CLK to Analog #5
 * DAT to Analog #4
*/

// include the library code:
#include <Wire.h>
#include <LiquidTWI.h>
#include <OneWire.h>
#include <DallasTemperature.h>



int tempPin = 0;
int lightPin = 1;


// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidTWI lcd(0);

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

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

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

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x61, 0x40, 0x15, 0x06, 0x00, 0x00, 0x6B };
DeviceAddress outsideThermometer = { 0x28, 0x2E, 0x72, 0x48, 0x05, 0x00, 0x00, 0x9C };
//DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };


void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);

  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  //sensors.setResolution(dogHouseThermometer, 10);
}

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));

  }
}




  void loop()


  {


    // Display Temperature in C
    int tempReading = analogRead(tempPin);
    float tempVolts = tempReading * 5.0 / 1024.0;
    float tempC = (tempVolts - 0.5) * 100.0;
    float tempF = tempC * 9.0 / 5.0 + 32.0;
    // ----------------
    lcd.setCursor(3, 0);
    lcd.print("ROOM  TEMP ");
    lcd.setCursor(6, 1);
    lcd.print(tempF);

    delay  (5000);

    lcd.clear();

    // Display LIGHT SENSOR on first row

    lcd.setCursor(2, 0);
    lcd.print("LIGHT SENSOR");

    // ----------------
    int lightReading = analogRead(lightPin);
    lcd.setCursor(7, 1);
    lcd.print(lightReading);

    delay(5000);



    lcd.clear();

    //  Display Dallas TEMP 0 on first row
    lcd.setCursor(3, 0);
    lcd.print("Dallas TEMP 0 ");
    printTemperature(insideThermometer);
    lcd.setCursor(7, 1);
    //lcd.print(insideThermometer);  // you can't print this in the LCD this way


    delay(5000);



    lcd.clear();


    //  Display Dallas TEMP 1 on first row
    lcd.setCursor(3, 0);
    lcd.print("Dallas TEMP 1 ");
    printTemperature(outsideThermometer);
    lcd.setCursor(7, 1);
    //lcd.print(outsideThermometer);  // you can't print this in the LCD this way

    delay(5000);



    lcd.clear();

  }

But you need to read the forum rules before post.

Hey luisilva, thanks for the help.

For those of us trying to learn this, your wonderful response shows some civility.

Yes, open source.

Yes, open to CONSTRUCTIVE criticism.

Will look at the code again.

Open to someone calling me stupid. Nope.

onecansay.

Open to someone calling me stupid. Nope.

He didn't call you stupid, he called the function you made, stupid. There is a difference.

BTW, the problem was there:

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));
 
  }
 

         <<<<<<<<<<<<<<<<<<<<< here you miss one '}'


    void loop()

You open 3 '{' and only close 2 (with '}').

Hey luisilva, I changed what you suggested. Yes, it compiled and loaded. When I try to put in the 'parameter '[lcd.print(outsideThermometer);] I get this.

/arduino-1.0.5/hardware/arduino/cores/arduino/Print.h:63: note: size_t Print::print(long unsigned int, int)

Whoa, that is a little beyond my limit at this time.

Here is the code I used to get the Temp probes to work.

The addresses are not the same but I changed them to work.// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// Arduino 1-Wire Tutorial

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

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

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

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// Arduino 1-Wire Address Finder

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };
DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };

void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);
sensors.setResolution(dogHouseThermometer, 10);
}

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));
}
}

void loop(void)
{
delay(2000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();

Serial.print("Inside temperature is: ");
printTemperature(insideThermometer);
Serial.print("\n\r");
Serial.print("Outside temperature is: ");
printTemperature(outsideThermometer);
Serial.print("\n\r");
Serial.print("Dog House temperature is: ");
printTemperature(dogHouseThermometer);
Serial.print("\n\r\n\r");
}

And to HazardsMind, point taken.

As I teach other in another genre, never do I say the mistakes they make are stupid.

onecansay

Hey again luisilva. I seen your {} suggestion but without that change is compiled, loaded and worked.

Problem is the actual temp will not come up on the second line of the display.

When I un-comment the line you suggested I get the error.

Have I not properly declared something?

Scratching head.

Is it because of the 1 wire scenario?

Thanks for your help.

onecansay

Once again luisilva, thanks for pointing me in the right direction.

My problem was the proper declaration upline.

{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error getting temperature");
} else {
lcd.print("C: ");
lcd.print(tempC);
lcd.print(" F: ");
lcd.print(DallasTemperature::toFahrenheit(tempC));

}

I had "serial.print" instead of the above.

Once again, a heartfelt THANK YOU.

oncansay.

onecansay:
Once again

We see that you haven't read the forum rules for posting code. Always use code tags, the # button above the smileys.