Pages: [1]   Go Down
Author Topic: the LCD not frequently updated  (Read 4527 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi ive got this code( the dallas multiple temperature one) which i have modified to output to a serial LCD, it outputs fine to the serial port immediatley and VERY frequently, but when i output it to the LCD (activate the code to 'lcd.print(something)' ) the values are only updated every 6 secconds as opposed to 1 or 2, which happens to be the amount of time it takes to do a full loop of the calculations and the runthrough of the lcd commands with the delay.

if i remove the delay it outputs fine, but i cannot read the results on the LCD as their too fast, help pls

Code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

#define ONE_WIRE_BUS 10 //digital pin 10
#define TEMPERATURE_PRECISION 12 //12byte precision so i get more than just XX.50 Celcius etc

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress Tture1, Tture2;
DeviceAddress Tture3;
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();

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

  // report parasite power requirements
  Serial.print("Parasite power is: ");
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");


  if (!sensors.getAddress(Tture1, 0)) Serial.println("Unable to find address for Device 0");
  if (!sensors.getAddress(Tture2, 1)) Serial.println("Unable to find address for Device 1");
  if (!sensors.getAddress(Tture3, 2)) Serial.println("Unable to find address for Device 2");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(Tture1);
  Serial.println();

  Serial.print("Device 1 Address: ");
  printAddress(Tture2);
  Serial.println();

  Serial.print("Device 2 Address: ");
  printAddress(Tture3);
  Serial.println();

  sensors.setResolution(Tture1, 12);
  sensors.setResolution(Tture2, 12);
  sensors.setResolution(Tture3, 12);

  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(Tture1), DEC);
  Serial.println();

  Serial.print("Device 1 Resolution: ");
  Serial.print(sensors.getResolution(Tture2), DEC);
  Serial.println();

  Serial.print("Device 2 Resolution: ");
  Serial.print(sensors.getResolution(Tture3), DEC);
  Serial.println();
}

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



/*
device 0 = 286A98BA0200005E
device 1 = 28AEA2BA02000024
device 2 = 288195BA02000063
*/
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress); //the LOT
  Serial.print("Temp C: ");
  Serial.print(tempC);

  //   float temp1 = sensors.getTempC(Tture1);
  //   float temp2 = sensors.getTempC(Tture2);
  //   float temp3 = sensors.getTempC(Tture3);

 lcd.begin(16, 2);

    lcd.clear();
    lcd.print("TEST1 ");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print("C");

  lcd.setCursor(0, 1);
    lcd.print("TEST2 ");
    lcd.print(sensors.getTempCByIndex(1));
    lcd.print("C");


delay(1000);


//     float temp3 = sensors.getTempC(Tture3);
  lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("TEST3 ");
    lcd.print(sensors.getTempCByIndex(2));
    lcd.print("C");
    delay(1000);
    
}

// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
  Serial.print("Resolution: ");
  Serial.print(sensors.getResolution(deviceAddress));
  Serial.println();    
}


// main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}



void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus
  Serial.print("Loading...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  printData(Tture1);
  printData(Tture2);
  printData(Tture3);

}
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46264
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at your printTemperature function.
Code:
void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress); //the LOT

    lcd.print(sensors.getTempCByIndex(0));
delay(1000);

    lcd.print(sensors.getTempCByIndex(1));
    lcd.print(sensors.getTempCByIndex(2));
    delay(1000);
}
It takes time (~3/4 of a second) to get the temperature. Then, 2 seconds of useless delay.

If the getTempCByIndex method is not caching temperature data, it could take ~3/4 of a second per call to get the temperature.

This function is called 3 times in loop.

So, I'm not surprised that it takes 6 seconds between updates.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yer im aware of that, but im just not too sure how to fix the problem with a single 16x2 display
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 551
Posts: 46264
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
not too sure how to fix the problem with a single 16x2 display
In the editor, place the cursor in front of the delay statement. Hold down the shift key, and click at the end of the statement. Then, press the delete key. Upload again. Much faster this time, I'll bet.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6935
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe the OP didn't write all the code he posted so he was not sure about things Paul mentioned in the code. From my point of view, the delays that Paul mentioned are not doing anything useful. If they are, I don't see any comment of why they need to be there. Romove them and see what happens.
Logged


Pages: [1]   Go Up
Jump to: