SparkFun LCD and Freetronics IR Temperature sensor

The LCD and Keypad Shield gives you a handy 16-character by 2-line display, 5 buttons and a controllable backlight.
Post Reply
Interalia
Posts: 6
Joined: Mon Apr 04, 2016 5:29 am

SparkFun LCD and Freetronics IR Temperature sensor

Post by Interalia » Mon Apr 04, 2016 5:49 am

I have a 16x2 LCD and want to have it show the IR sensor temperature.

I have the following code which I modified but seem to have an error. Any ideas?

Code: Select all

/*
 * File:    readTemperature.ino
 * Author:  Andy Gelme (@geekscape) & Angus Gratton (angus at freetronics. com)
 * License: GPLv3
 *
 * For more information see www.freetronics.com/irtemp
 *
 */

#include "IRTemp.h"
#include "LiquidCrystal.h"

LiquidCrystal lcd(12, 11, 9, 8, 7, 6);

static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS;  // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

void setup() {
lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) 
    {
      // display each character to the LCD
      lcd.write(Serial.read());
    }


{
  float irTemperature = irTemp.getIRTemperature(SCALE);
  printTemperature("IR", irTemperature);
}
{
  float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
  printTemperature("Ambient", ambientTemperature);

  delay(1000);
}
{
void printTemperature(char  *type, float  temperature) 


  Serial.print(type);
  Serial.print(" temperature: ");

  if (isnan(temperature)) {
    Serial.println("Failed");
  }
  else {
    Serial.print(temperature);
    Serial.println(SCALE == FAHRENHEIT  ?  " F"  :  " C");
  }
}

Interalia
Posts: 6
Joined: Mon Apr 04, 2016 5:29 am

Re: SparkFun LCD and Freetronics IR Temperature sensor

Post by Interalia » Mon Apr 04, 2016 5:53 am

errors:

IR_andLCD.ino: In function 'void loop()':
IR_andLCD:46: error: 'printTemperature' was not declared in this scope
IR_andLCD:50: error: 'printTemperature' was not declared in this scope
IR_andLCD:58: error: expected initializer before 'Serial'
IR_andLCD:61: error: 'temperature' was not declared in this scope
IR_andLCD:68: error: expected '}' at end of input
IR_andLCD:68: error: expected '}' at end of input
'printTemperature' was not declared in this scope

Interalia
Posts: 6
Joined: Mon Apr 04, 2016 5:29 am

Re: SparkFun LCD and Freetronics IR Temperature sensor

Post by Interalia » Mon Apr 04, 2016 9:43 am

OK - got this far but just need to get to LCD

/*
* File: readTemperature.ino
* Author: Andy Gelme (@geekscape) & Angus Gratton (angus at freetronics. com)
* License: GPLv3
*
* For more information see www.freetronics.com/irtemp
*THIS NOW WORKS!!! Except for reading to LCD.
*/

#include "IRTemp.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 9, 8, 7, 6);

static const byte PIN_DATA = 2; // Choose any pins you like for these
static const byte PIN_CLOCK = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS; // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

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


void loop(void) {
float irTemperature = irTemp.getIRTemperature(SCALE);
printTemperature("IR", irTemperature);

float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
printTemperature("Ambient", ambientTemperature);

delay(1000);
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}

void printTemperature(
char *type,
float temperature) {

Serial.print(type);
Serial.print(" temperature: ");

if (isnan(temperature)) {
Serial.println("Failed");
}
else {
Serial.print(temperature);
Serial.println(SCALE == FAHRENHEIT ? " F" : " C");
}
}
//I know the issue is in the last part. :?

Interalia
Posts: 6
Joined: Mon Apr 04, 2016 5:29 am

SparkFun LCD and Freetronics IR Temperature sensor solution

Post by Interalia » Mon Apr 04, 2016 9:50 am

Code: Select all

/*
 * File:    readTemperature.ino
 * Author:  Andy Gelme (@geekscape) & Angus Gratton (angus at freetronics. com)
 * License: GPLv3
 *
 * For more information see www.freetronics.com/irtemp
 *THIS NOW WORKS!!!
 */

#include "IRTemp.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 9, 8, 7, 6);

static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS;  // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

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


void loop(void) {
  float irTemperature = irTemp.getIRTemperature(SCALE);
  printTemperature("IR", irTemperature);

  float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
  printTemperature("Ambient", ambientTemperature);

  delay(1000);
   // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
}
  }
}

void printTemperature(
  char  *type,
  float  temperature) {

  lcd.print(type);
  lcd.print(" temperature: ");

  if (isnan(temperature)) {
    lcd.println("Failed");
  }
  else {
    lcd.print(temperature);
    lcd.println(SCALE == FAHRENHEIT  ?  " F"  :  " C");
  }
}


Interalia
Posts: 6
Joined: Mon Apr 04, 2016 5:29 am

Re: SparkFun LCD and Freetronics IR Temperature sensor

Post by Interalia » Mon Apr 04, 2016 10:47 am

No if I could only get the LCD to just display the temperature, wait a few seconds and display again, in the same place. This is the code. What is the error???

Code: Select all

/*
 * File:    readTemperature.ino
 * Author:  Andy Gelme (@geekscape) & Angus Gratton (angus at freetronics. com)
 * License: GPLv3
 *
 * For more information see www.freetronics.com/irtemp
 *THIS NOW WORKS!!! Except for reading to LCD.
 */

#include "IRTemp.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 9, 8, 7, 6);

static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;

static const TempUnit SCALE=CELSIUS;  // Options are CELSIUS, FAHRENHEIT

IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);

void setup(void) {
 // set up the LCD's number of columns and rows:
  lcd.begin(16, 1);
  // initialize the serial communications:
  Serial.begin(9600);
}


void loop(void) {
  float irTemperature = irTemp.getIRTemperature(SCALE);
  printTemperature("",irTemperature);
 delay(1000);
   // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());

  // delay at the end of the full loop:
  delay(1000);
  
}
  }
}

void printTemperature(
  char  *type,
  float  temperature) {

  lcd.print(type);
  lcd.print(" temp: ");

  if (isnan(temperature)) {
    lcd.println("Failed");
  }
  else {
    lcd.print(temperature);
    
  }
}


Post Reply

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest