Problem with ST7920 128x64 lcd + DS18B20

Hello to everyone :slight_smile:

I want to thank all of you who helps each other at this forum. There has been very useful information and impressive projetcs.
(I’m from Finland so there might be some bad english in my text)

I have been working with my mega 2560 r3 for a while. I’m trying to learn arduino’s code enviroment and i had some studies for avr but those are forgotten long time ago. (approx 9years ago…)

Now i found this nice piece of hardware to study again this “world of possibilities” but now im stuk with my project.
My configuration
1x arduino mega 2560 r3
1x ST7920 based 128x64 lcd in serialmode
2x TMP636GZ temperature sensors
1x DS18B20 1-wire temperature sensor

I have succesfully programmed TMP636GZ sensors to showup on lcd but now I’m trying to add DS18B20 sensors but I don’t understand how.
There is print overload error with u8g so i think the value is wrong format but i just don’t understand how to get correct format to show temperature value on ST7920 lcd from BS18B20.

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

U8GLIB_ST7920_128X64_4X u8g(18, 16, 17);	

int sensorPin0 = A0; // select the input pins for the sensors

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

DallasTemperature sensors(&oneWire);
DeviceAddress st0 = { 0x28, 0x29, 0x1A, 0x5A, 0x05, 0x00, 0x00, 0x09 };

float temp0 = 0; // variables for output temps 
//float temp1 = 0; // tempX = ((analogRead(sensorPinX) * 2.5) - 500) /10
float stC = 0;

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  
}

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  
  u8g.setPrintPos(1, 10); //setting print position for string T1
  u8g.print("T1");        //printing T1
  u8g.setPrintPos(20,10); //Setting print position for float temp0
  u8g.print(temp0);  //Printing temperature
  
  u8g.setPrintPos(1,40);
  u8g.print("S1");
  u8g.setPrintPos(20,40);
  u8g.print(stC);  
  
}

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

void loop() {
  // read the value from the sensors and convert to degree celsius
  
  temp0 = ((analogRead(sensorPin0) * 2.5) - 500) /10;
    
  //get all sensor values
  sensors.requestTemperatures(); 
  stC = (tempC); 
// picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(500);

}

Forgot to mention:

I'm not trying to go the easiest way... I have tried searching through forum and reading other codes for days but still can't find solution that works on my case.

This project is moving forward step by step and i have done pretty much research and studying for this but now i need some help from anyone who has more knowledge :~

I have succesfully programmed TMP636GZ sensors to showup on lcd

No, you haven't. You can't program those sensors. What you CAN do is program the Arduino, to read those sensors and to display some data on the LCD.

but now I'm trying to add DS18B20 sensors but I don't understand how.

There is plenty of sample code around to read those sensors. You've (poorly) adapted some. The printTemperature() function is NOT accomplishing anything. Get rid of it. Read the sensor directly every where where you currently call printTemperature(). Or, rename the function to getTemperature(), change it's return type to float, and make it actually return something.

There is print overload error with u8g so i think the value is wrong format

You need to convert the float you are trying to print to a string, and print that string. dtostrf() is the usual way to convert a float to a string.

PaulS thank's for reply

No, you haven't. You can't program those sensors. What you CAN do is program the Arduino, to read those sensors and to display some data on the LCD.

Yes you are ringht. thats what i mentioned but i write wrong :roll_eyes:

You need to convert the float you are trying to print to a string, and print that string. dtostrf() is the usual way to convert a float to a string.

Can you explain why i need string? I have understanded that u8g can show floats on the screen or am i wrong?

I think that adaption is the thing i just need to practice more :)

arihuttuFIN: I'm trying to add DS18B20 sensors but I don't understand how. There is print overload error with u8g so i think the value is wrong format but i just don't understand how to get correct format to show temperature value on ST7920 lcd from BS18B20.

It looks like the main reason why you are struggling to get any joy with the DS18B20 is that most of the code for it is missing. The best source for this sensor is here

http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

Which you might already be aware of. You already have the address sniffer.

The only noteworthy lines in your code are

  u8g.setPrintPos(20,10); //Setting print position for float temp0
  u8g.print(temp0);  //Printing temperature

which suggest pretty strongly that the display you have is rather like any other display. The DS18B20 returns floats so you should be able to just print them and I can't see why you need to have anything to do with strings. If you are obliged to use strings with the other sensors, replacing them with DS18B20s sounds like a rather good idea.

From what I can see, the only time you need to use strings in a data feed is when a receiving terminal programme demands it, which isn't often. I'm not aware of any hardware device that demands to be fed with strings.

Nick thanks for reply :slight_smile:

The lcd is basic from dfrobot (by finnish supplier) and works fine with u8glib
http://www.dfrobot.com/index.php?route=product/product&path=53_130&product_id=240#.UwzF2c6PKB1

I did some more research, googling and found few answers and now i can compile the skets and I can get the temp value by the index.

I found this vid and i think it might help me much

here is the edited code and i did some cleaning that it might be easier to read

But now I need to know the correct command for reading named device address like

DeviceAddress serialt0 = { 0x28, 0x29, 0x1A, 0x5A, 0x05, 0x00, 0x00, 0x09 };

I found few command’s from samples but they won’t “open” to me or they are pretty complex i think :~

#include "U8glib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <wire.h>

U8GLIB_ST7920_128X64_4X u8g(18, 16, 17);	
int sensorPin0 = A0; // select the input pins for the sensors
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress serialt0 = { 0x28, 0x29, 0x1A, 0x5A, 0x05, 0x00, 0x00, 0x09 };

float temp0 = 0; // variables for output temps 
float stempC0 = 0;

void setup() {
  // setting reference point
  analogReference(INTERNAL2V56); //setting reference point for analog read
 

  Serial.begin(9600);   // start serial port
  sensors.begin();  // Start up the library
  sensors.setResolution(serialt0, 10); // set the resolution to 10 bit
}

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  
  u8g.setPrintPos(1, 10); //setting print position for string T1
  u8g.print("T1");        //printing T1
  u8g.setPrintPos(20,10); //Setting print position for float temp0
  u8g.print(temp0);       //pinting temp0
  
  u8g.setPrintPos(1,40);
  u8g.print("S1");
  u8g.setPrintPos(20,40);
  u8g.print(stempC0);  
}
void loop() {
  temp0 = ((analogRead(sensorPin0) * 2.5) - 500) /10;
  
  sensors.requestTemperatures();
  // stempC0 = sensors.getTempC(serialt0);     ***won't work***?
  stempC0 = sensors.getTempCByIndex(0);       ****works fine***

// picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(500);

}

I'm not aware of any hardware device that demands to be fed with strings.

What do you think an LCD is going to do with binary data? Now, it would be nice to think that the class that is being used derived from the Print class which supplies all the binary to ASCII conversion tools needed, but that is probably not the case here.

Now I think I found the ringht (is it call or command)

stempC0 = sensors.getTempC(serialt0);

Or is it? It work's fine with one sensor and I'll try tomorrow with couple more...

There is print overload error with u8g so i think the value is wrong format but i just don't understand how to get correct format to show temperature value on ST7920 lcd from BS18B20.

Did you solve the problem with u8g.print()? U8glib reuses the Arduino print procedure. It really identical to it. Documentation is here: http://arduino.cc/en/Serial/Print

Oliver

Hi oliver

Yes it was solved by changin the way set the value

way i tried and failed. goes mainly like this

float tempC = sensors.getTempC(deviceAddress);
stC = (tempC);
u8g.setPrintPos(20,10); //Setting print position
u8g.print(stC);  //Printing temperature    ***And this was the point where error occures****

And way that worked perfectly on this stage of build

#include "U8glib.h"
#include <OneWire.h>
#include <DallasTemperature.h> 
#include <wire.h>

U8GLIB_ST7920_128X64_4X u8g(18, 16, 17);	
int sensorPin0 = A0; // select the input pins for the sensors

#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);         
DallasTemperature sensors(&oneWire);
DeviceAddress serialt0 = { 0x28, 0x29, 0x1A, 0x5A, 0x05, 0x00, 0x00, 0x09 };[/b]
float temp0 = 0; // variables for output temps 
float stempC0 = 0;  

void setup() {
  // setting reference point
  analogReference(INTERNAL2V56); //setting reference point for analog read

  Serial.begin(9600);   // start serial port
  sensors.begin();  // Start up the library
  sensors.setResolution(serialt0, 10); // set the resolution to 10 bit
}

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here  
  u8g.setFont(u8g_font_unifont);
  
  u8g.setPrintPos(1, 10); //setting print position for string T1
  u8g.print("T1");        //printing T1
  u8g.setPrintPos(20,10); //Setting print position for float temp0
  u8g.print(temp0);       //pinting temp0
  
  u8g.setPrintPos(1,40);
  u8g.print("S1");
  u8g.setPrintPos(20,40);
  u8g.print(stempC0);
}
void loop() {
  temp0 = ((analogRead(sensorPin0) * 2.5) - 500) /10;
  sensors.requestTemperatures();
  stempC0 = sensors.getTempC(serialt0);

// picture loop
  u8g.firstPage();  
  do {
    draw();
  } while( u8g.nextPage() );
  
  // rebuild the picture after some delay
  delay(500);

}

arihuttuFIN: But now I need to know the correct command for reading named device address like

DeviceAddress serialt0 = { 0x28, 0x29, 0x1A, 0x5A, 0x05, 0x00, 0x00, 0x09 };

The code you post is still incomplete. The link I posted has all you need to read the named addresses. You already have the code to sniff the addresses. There are two ways to use the DS18B20 with one-wire:

  1. by named addresses using previously sniffed names

  2. by index

You have to make up your mind which to use - one or the other. I use named addresses, principally because I was using it before I ever heard of the index method, and I see no point in using the index method anyway. Others may see it differently. You never use both in the same job.

Glad you figured it out. I would have suggested using miles burtons library.

http://www.milesburton.com/?title=Dallas_Temperature_Control_Library.

Hi criomod
I already have the newest version of burton’s library but I cannot find full list of call’s.

@Nick
Woul’d you explain exactly what i’m missing
Here’s the definitions and setup

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress serialt0 = { 0x28, 0x29, 0x1A, 0x5A, 0x05, 0x00, 0x00, 0x09 };
float stempC0 = 0;
**************
Serial.begin(9600); // start serial port
sensors.begin();  // Start up the library
sensors.setResolution(serialt0, 10); // set the resolution to 10 bit (good enough?)

And then I read the temperature and put it in the variable “float stempC0” and show it on the lcd

u8g.setPrintPos(1,40);
u8g.print("S1");
u8g.setPrintPos(20,40);
u8g.print(stempC0);
************
sensors.requestTemperatures();
stempC0 = sensors.getTempC(serialt0);

I tought that’s all I need on this point when I just want to show it on LCD and I don’t need the serial monitor part right now
And the temp is correct on the lcd and can be manipulated by heating the sensor

arihuttuFIN: @Nick Woul'd you explain exactly what i'm mising

Well it's pretty hard to tell. The last code you posted didn't even have a loop, so you can't expect much useful comment. I don't think this matters. If you have what you expect on the LCD, you are on your way. You may have some redundant code, but that will probably come out in the wash.