// simple project using Arduino UNO and 128x64 SSD1306 IIC OLED Display, created by upir, 2023
// youtube channel: https://www.youtube.com/upir_upir
// YOUTUBE VIDEO: https://youtu.be/Eyvzw_ujcS0
// WOKWI sketch: https://wokwi.com/projects/372481402319579137
// More videos with Arduino UNO and OLED screens: https://www.youtube.com/playlist?list=PLjQRaMdk7pBZ1UV3IL5ol8Qc7R9k-kwXA
// Links from the video:
// Lopaka editor: https://lopaka.app/
// 128x64 SSD1306 OLED Display 1.54": https://s.click.aliexpress.com/e/_DCYdWXb
// 128x64 SSD1306 OLED Display 0.96": https://s.click.aliexpress.com/e/_DCKdvnh
// 128x64 SSD1306 OLED Display 2.42": https://s.click.aliexpress.com/e/_DFdMoTh
// Arduino UNO: https://s.click.aliexpress.com/e/_AXDw1h
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h> // library requires for IIC communication
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); // initialization for the used OLED display
static const unsigned char image_dsfs_bits[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x1f,0x00,0x00,0x00,0x00,0xf8,0x1f,0x00,0x00,0x00,0x3c,0x80,0x01,0x00,0x00,0x00,0xfe,0x80,0x01,0x00,0x18,0x00,0xe6,0x83,0x01,0x00,0x1f,0x00,0x87,0xff,0x1f,0xe0,0x0f,0x00,0x03,0xff,0x3f,0xf8,0x07,0x00,0x1f,0xff,0x7f,0xff,0x03,0x00,0xfc,0x03,0xe0,0xcf,0x01,0x00,0xf0,0x03,0xc0,0xe1,0x00,0x00,0x80,0x03,0x00,0x70,0x00,0x00,0x00,0x03,0x00,0x38,0x60,0x00,0x00,0x03,0x00,0x1c,0x60,0x00,0x00,0x03,0x00,0x0e,0xf0,0x00,0x00,0xff,0xff,0x07,0xf0,0x00,0x00,0xff,0xff,0x03,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static const unsigned char image_b43b4dea_8292_4e26_a548_3e81e9e057ef_200_bits[] = {0xff,0xff,0x1f,0x00,0x00,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0xfc,0x01,0x00,0x00,0x00,0x80,0x07,0x00,0x00,0x00,0x1c,0x0f,0x00,0x00,0xf0,0x10,0x1e,0x00,0x00,0x90,0x11,0x38,0x00,0x00,0x00,0x33,0x3b,0x00,0x00,0x00,0x37,0x32,0x00,0xff,0xe0,0x3f,0x32,0x00,0xff,0xfe,0x3f,0x73,0x00,0xe0,0xc2,0xff,0x71,0x00,0xe0,0xc0,0xff,0x70,0x00,0xe0,0xe0,0x7f,0x74,0x00,0xc0,0xf8,0x3f,0x74,0x00,0xc0,0xcc,0xff,0xf7,0x1f,0xc0,0xc4,0x7f,0xf0,0x1f,0xc0,0xc5,0x0e,0x00,0x00,0x80,0x8d,0x0c,0x00,0x00,0x80,0x81,0x38,0x01,0x00,0x80,0x87,0xe0,0x01,0x00,0x00,0x8f,0x01,0x00,0x00,0x00,0x3c,0x00,0x00,0x00,0x00,0xf8,0x1f,0x00,0x00,0x00,0xe0,0xff,0xff,0x1f,0x00,0x00,0xff,0xff,0x1f};
int a_bar=A0;
//int a_toil=A1;
int a_turbo=A2;
int bar0;
int bar1;
int toil0;
int toil1;
int toil2;
int turbo0;
int turbo1;
int turbo2;
int c1;
int i;
double bar;
double toil;
double turbo;
int bar_int;
int toil_int;
int turbo_int;
float Vin=5.0; // [V]
float Rt=1000; // Resistor t [ohm]
float R0=20000; // value of rct in T0 [ohm]
float T0=298.15; // use T0 in Kelvin [K]
float Vout=0.0; // Vout in A0
float Rout=0.0; // Rout in A0
// use the datasheet to get this data.
float T1=273.15; // [K] in datasheet 0º C
float T2=373.15; // [K] in datasheet 100° C
float RT1=27513; // [ohms] resistence in T1
float RT2=950; // [ohms] resistence in T2
float beta=0.0; // initial parameters [K]
float Rinf=0.0; // initial parameters [ohm]
float TempK=0.0; // variable output
float TempC=0.0; // variable output
void setup(void) {
u8g2.begin(); // start the u8g2 library
pinMode(1, INPUT);
//parâmetros
beta=(log(RT1/RT2))/((1/T1)-(1/T2));
Rinf=R0*exp(-beta/T0);
}
void int_u_char(){
bar0 = (bar_int/100)%10;
bar1 = (bar_int/10)%10;
toil0 = abs((toil_int/100)%10);
toil1 = abs((toil_int/10)%10);
toil2 = abs(toil_int%10);
turbo0=(turbo_int/100)%10;
turbo1=(turbo_int/10)%10;
turbo2=turbo_int%10;
}
void ocitaj_parametre(){
Vout=Vin*((float)(analogRead(1))/1024.0); // calc for ntc
Rout=(Rt*Vout/(Vin-Vout));
TempK=(beta/log(Rout/Rinf)); // calc for temperature
TempC=TempK-273.15;
toil_int=TempC;
bar = map(analogRead(a_bar),0,1023,0,1030);
bar_int=bar;
turbo = map(analogRead(a_turbo),0,1023,0,300);
turbo_int=turbo;
}
void ispis(){
ocitaj_parametre();
int_u_char();
}
void loop(void) {
u8g2.clearBuffer(); // clear the internal memory
// code from https://lopaka.app/
u8g2.setFontMode(1);
u8g2.setBitmapMode(1);
u8g2.drawXBM(2, 5, 42, 20, image_dsfs_bits);
u8g2.setFont(u8g_font_profont22);
ispis();
u8g2.setCursor(10, 45);
u8g2.print(bar0);
u8g2.drawStr(19, 45, ".");
u8g2.setCursor(28, 45);
u8g2.print(bar1);
u8g2.setCursor(2, 63);
if(toil0>0){
u8g2.print(toil0);
}
else u8g2.drawStr(2, 63, " ");
if(toil_int<0){
if(toil1==0){
u8g2.drawStr(15, 63, "-");
}
else{
u8g2.drawStr(2, 63, "-");
u8g2.setCursor(15, 63);
u8g2.print(toil1);
} i=0;
}
else if(toil1>0||toil0>=1){
u8g2.setCursor(15, 63);
u8g2.print(toil1);
}
else u8g2.drawStr(15,63," ");
u8g2.setCursor(28, 63);
u8g2.print(toil2);
u8g2.setFont(u8g_font_profont29);
u8g2.setCursor(67, 58);
u8g2.print(turbo0);
u8g2.drawStr(79, 58, ".");
u8g2.setCursor(90, 58);
u8g2.print(turbo1);
u8g2.setFont(u8g_font_profont17);
u8g2.setCursor(108, 50);
u8g2.print(turbo2);
u8g2.setFont(u8g_font_profont10);
u8g2.drawStr(42, 45, "BAR");
u8g2.drawStr(107, 58, "BAR");
//u8g2.setFont(u8g2_font_t0_15b_me);
u8g2.drawStr(42, 63, "C");
//u8g2.drawStr(2, 56, "73.6");
u8g2.setCursor(2, 56);
u8g2.drawXBM(84, 7, 37, 26, image_b43b4dea_8292_4e26_a548_3e81e9e057ef_200_bits);
u8g2.sendBuffer(); // transfer internal memory to the display
delay(100);
// increase the progress value to go over 0-100
}