Writing temperature values to ST7920 LCD

How can I take readings displayed in the serial monitor and display them on the screen? Instead of text, I want to display the temperature. Partially completed below:

#include <Arduino.h>
#include <U8g2lib.h>
#include <OneWire.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif 


#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 7

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

float tempC = 0;

U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, /* clock=*/ 53, /* data=*/ 51, /* CS=*/ 49, /* reset=*/ 8);

void setup(void) 
{
  u8g2.begin();
  //New code for DS1820 here:
  sensors.begin();
  pinMode(3, OUTPUT);
  analogWrite(3, 0);
  Serial.begin(9600);
}

void loop(void) 
{
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(10,20,"Text");
    u8g2.drawFrame(0,0,128,64);
  } while ( u8g2.nextPage() );
  
  delay(1000);

}

Suggestions?

If you do a successful verify, you can highlight the display library (U8g2kib), then right click and select Go to Definition. Now you can see what all the member functions are. You probably want something like write, but before that some sort of positioning call like row and col and of course clear the old display first.
What I do in these cases is goto the library manager entry for the library and click the 3 dots beside the name then select examples.

I'm sorry but I don't really understand. I found a tool to scan the device address but I don't know how to use it. How do I turn the data it's collecting into something that u8g2 can print to screen?

I have the temperature as some float value. What do I do with it for u8g2 to display it?

You should

  • request the temperature
  • read the temperature
  • convert it
  • output it

I cannot test it right now, but it should translate to something like this:

void loop(void) 
{
// requesting
sensors.requestTemperatures();
delay(1500);

// reading
int tempC = sensors.getTempCByIndex(0);

// formatting
char buf[20];
snprintf(buf, sizeof(buf), "It is %d °C", tempC);

// output
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_ncenB14_tr);
    u8g2.drawStr(10,20, &buf);
    u8g2.drawFrame(0,0,128,64);
  } while ( u8g2.nextPage() );
  
  delay(1000);

}

So this code will not be suitable.

You can use dtostrf() function to change a float into a string like this:

float tempC = 12.3;

char tempCstr[6];

dtostrf(tempC, 5, 1, tempCstr);

u8g2.drawStr(10, 20, &tempCstr);


Better start off with a float then...

int tempC = should be
float tempC = sensors.getTempCByIndex(0);

Leo..

Cheers. I eventually worked it out. It works. Now I have a new problem with my BME280 sensor.

How? What is your code now?

Please provide a wiring diagramm and code. What is it doing and what do you expect?