AvKauf
March 18, 2021, 7:40pm
1
I am trying to run this code to display 2 temperature values on a lcd screen. It runs 8 times then stops and the screen just flashes. Why is this and what can i do to get it run indefinitely. Any help or advice would be greatly appreciated. The code is attached below
Baja_Temp.ino (1.32 KB)
Post code, not pictures.
We are not (all) Ancient Egyptians >:(
AvKauf
March 18, 2021, 8:46pm
3
TheMemberFormerlyKnownAsAWOL:
Post code, not pictures.
We are not (all) Ancient Egyptians >:(
I posted the code as an attachment. I added the picture if someone saw something obvious
Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to follow, download and test
In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless
If the code exceeds the 9000 character inline limit then attach it to a post
OP code:
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_KBV.h> //Hardware-specific library
LCDWIKI_KBV mylcd(ILI9486,A3,A2,A1,A0,A4); //model,cs,cd,wr,rd,reset
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 10
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celsius1 = 0;
float Celsius2 = 0;
void setup() {
sensors.begin(); // Start up the library
Serial.begin(9600);
mylcd.Init_LCD();
Serial.println(mylcd.Read_ID(), HEX);
mylcd.Fill_Screen(BLACK);
}
void loop() {
// put your main code here, to run repeatedly:
sensors.requestTemperatures();
// set the font color
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(4);
// print the sensor value
mylcd.Print_String("Engine Temp", 0, 0);
Celsius1 = sensors.getTempCByIndex(0);
mylcd.Print_Number_Float(Celsius1, 2, 0, 40, '.', 0, ' ');
mylcd.Print_String("Gearbox Temp", 0, 80);
Celsius2 = sensors.getTempCByIndex(1);
mylcd.Print_Number_Float(Celsius2, 2, 0, 120, '.', 0, ' ');
// wait for a moment
delay(2000);
// erase the text you just wrote
}
Can you try this code to see if the halting problem stops?
It basically is your code with the calls to the Dallas sensors halted and Celsius1 & 2 just ticking up by 0.5 each pass of loop().
If this runs indefinitely then the problem would seem to lie in the Dallas logic.
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_KBV.h> //Hardware-specific library
LCDWIKI_KBV mylcd(ILI9486,A3,A2,A1,A0,A4); //model,cs,cd,wr,rd,reset
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 10
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celsius1 = 0.0;
float Celsius2 = 10.0;
void setup()
{
sensors.begin(); // Start up the library
Serial.begin(9600);
mylcd.Init_LCD();
Serial.println(mylcd.Read_ID(), HEX);
mylcd.Fill_Screen(BLACK);
}
void loop()
{
// put your main code here, to run repeatedly:
// don't request anything from sensors for testing
//sensors.requestTemperatures();
// set the font color
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(4);
// print the sensor value
mylcd.Print_String("Engine Temp", 0, 0);
//fake #1 readings in lieu of reading Dallas devices
Celsius1 = Celsius1 + 0.5;
if(Celsius1 >= 55.0 )
Celsius1 = 0.0;
//Celsius1 = sensors.getTempCByIndex(0);
mylcd.Print_Number_Float(Celsius1, 2, 0, 40, '.', 0, ' ');
mylcd.Print_String("Gearbox Temp", 0, 80);
//fake #2 readings in lieu of reading Dallas devices
Celsius2 = Celsius2 + 0.5;
if(Celsius2 >= 65.0 )
Celsius2 = 0.0;
//Celsius2 = sensors.getTempCByIndex(1);
mylcd.Print_Number_Float(Celsius2, 2, 0, 120, '.', 0, ' ');
// wait for a moment
delay(2000);
// erase the text you just wrote
}
AvKauf
March 18, 2021, 9:32pm
7
Hi thanks for your help. I ran your code and the last values it showed was 5.5 and 15.5 before it started flashing. So it seems the error is somewhere else in the code. Any ideas?
JCA34F
March 18, 2021, 10:14pm
8
This works fine on Nano and Serial.print, something wrong with LCD code? Don't have your HW.
/*
//define some colour values
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#include <LCDWIKI_GUI.h> //Core graphics library
#include <LCDWIKI_KBV.h> //Hardware-specific library
LCDWIKI_KBV mylcd(ILI9486,A3,A2,A1,A0,A4); //model,cs,cd,wr,rd,reset
*/
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celsius1 = 0;
float Celsius2 = 0;
void setup() {
sensors.begin(); // Start up the library
Serial.begin(9600);
//mylcd.Init_LCD();
// Serial.println(mylcd.Read_ID(), HEX);
//mylcd.Fill_Screen(BLACK);
}
void loop() {
// put your main code here, to run repeatedly:
// set the font color
//mylcd.Set_Text_colour(WHITE);
//mylcd.Set_Text_Size(4);
// print the sensor value
//mylcd.Print_String("Engine Temp", 0, 0);
Celsius1 = sensors.getTempCByIndex(0);
//mylcd.Print_Number_Float(Celsius1, 2, 0, 40, '.', 0, ' ');
// mylcd.Print_String("Gearbox Temp", 0, 80);
Celsius2 = sensors.getTempCByIndex(1);
//mylcd.Print_Number_Float(Celsius2, 2, 0, 120, '.', 0, ' ');
// wait for a moment
Serial.print(Celsius1);
Serial.print("\t");
Serial.println(Celsius2);
delay(2000);
// erase the text you just wrote
}
AvKauf
March 18, 2021, 10:36pm
9
I used this code and it ran good in the serial monitor. So it must be something with the display. This is the display i am using if anyone is familiar with it.
DC 2.8-3.3V 3.5 inch TFT LCD Display Module TFT Color Screen 480x320
AvKauf:
I used this code and it ran good in the serial monitor. So it must be something with the display. This is the display i am using if anyone is familiar with it.
DC 2.8-3.3V 3.5 inch TFT LCD Display Module TFT Color Screen 480x320
It's unlikely to be the display but something the library.
What variant of the Arduino are you using?
I suspect you have a memory (RAM) issue related to the LCD libraries.
AvKauf
March 22, 2021, 8:17pm
13
Thanks for your help. I ran the code on a Arduino Mega and it works perfectly now.
system
Closed
July 20, 2021, 8:17pm
14
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.