Hello everyone,
I have a DH1106 OLED that i want to display temperature from the sensor (DS18B20). I compiled a temperature sketch using serial monitor and it worked. I also compiled the u8glib library "Hello World" example and it worked on the OLED.
Now I want to combine the 2 sketches in 1 so it displays the temperature on the OLED screen. I have some issues combining them together as I am a beginner and i don't know how to combine 2 sketches.
These are the sketches:
Temperature Sketch (using serial monitor):
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius=0;
float Fahrenheit=0;
void setup(void)
{
Serial.begin(9600); //monetor output lines in the code
sensors.begin(); //requesting data from sensor
}
void loop(void)
{
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
Serial.print(" C ");
Serial.print(Celcius);
Serial.print(" F ");
Serial.println(Fahrenheit);
delay(1000);
}
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello World!");
}
u8glib "Hello World" example (i have deleted the comments so it will be easier to copy):
#include "U8glib.h"
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 22, "Hello World!");
}
void setup(void) {
// flip screen, if required
// u8g.setRot180();
// set SPI backup if required
//u8g.setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(50);
}
This is the sketch were I tried to combine both previous sketches together, were issues occur:
#include <U8glib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float Celcius=0;
float Fahrenheit=0;
void setup(void)
{
//sensor
u8g.begin(9600); //monetor output lines in the code
sensors.begin(); //requesting data from sensor
//display
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
}
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_osb21);
u8g.drawStr( 0, 0, sensors);
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw(u8g);
//sensor
sensors.requestTemperatures();
Celcius=sensors.getTempCByIndex(0);
Fahrenheit=sensors.toFahrenheit(Celcius);
u8g.print(" C ");
u8g.print(Celcius);
u8g.print(" F ");
u8g.println(Fahrenheit);
delay(1000);
} while( u8g.nextPage() );
// rebuild the picture after some delay
//delay(50);
}
The error i get is:
exit status 1
no matching function for call to 'U8GLIB_SH1106_128X64::begin(int)'
I appreciate any comment that will contribute to my learning.
Thank you.