Skip to content

Instantly share code, notes, and snippets.

@MichalSkoula
Created September 5, 2019 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichalSkoula/c5082d1ca91a8cfcd47c3fa17733f708 to your computer and use it in GitHub Desktop.
Save MichalSkoula/c5082d1ca91a8cfcd47c3fa17733f708 to your computer and use it in GitHub Desktop.
Simple Arduino code - LM75A thermometer + OLED + Arduino NANO
#include <U8g2lib.h>
#include <LM75A.h>
// Create display instance
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0);
// Create I2C LM75A instance
LM75A lm75a_sensor(false, false, false);
// temperature variable
float temperature_in_degrees = 0;
void setup(void)
{
u8g2.begin();
}
void loop(void)
{
// get temperature
temperature_in_degrees = lm75a_sensor.getTemperatureInDegrees();
delay(500);
// draw everything
u8g2.firstPage();
do {
// print logo
u8g2.setFont(u8g2_font_t0_17b_tf );
u8g2.setCursor(15, 18);
u8g2.print("bastlime.eu");
// print temperature
u8g2.setFont(u8g2_font_inb30_mn);
u8g2.setCursor(0, 55);
if (temperature_in_degrees == INVALID_LM75A_TEMPERATURE) {
u8g2.print("ERROR");
} else {
u8g2.print(temperature_in_degrees);
}
} while (u8g2.nextPage());
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment