Categories

Display temperature on I2C OLED display

Taking our hello world I2C OLED example a bit further, this is our next creation. We connect a DS18B20 temperature sensor and display the temperature on the display

Coding

You need to download and install various libraries and copy them into your Arduino libraries folder.

Dallas 18b20 Temperature Library
“1-Wire” Library

Multi LCD library

 


#include "Arduino.h"
#include "Wire.h"
#include "OneWire.h"
#include "MicroLCD.h"
#include "DallasTemperature.h"

#define DS18B20 2

OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);

//LCD_SH1106 lcd; /* for SH1106 OLED module */
LCD_SSD1306 lcd; /* for SSD1306 OLED module */

void setup()
{
lcd.begin();
sensors.begin();
}

void loop()
{

sensors.requestTemperatures();
lcd.clear();
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" celsius");
delay(1000);
}

 

Links

Share

Connecting an I2C OLED display

Just recently I spotted various I2C OLED displays on sale at reasonable prices and fancied trying to connect these up one of my Arduino’s. Being relatively small size, requiring only 2 connections SDA and SCL from the Arduino but still having good text and graphical capabilities I snapped a couple up cheaply on the net. Here is a picture of the OLED display I bought, these are common on many sites at the moment

i2c oled lcd

i2c oled lcd

The first problem was connecting it up, this proved straightforward enough as the display can take standard 5v and GND and as its an I2C device on my Arduino UNO I hooked up A4 and A5 which are SDA and SCL respectively

Connection

 

Pin Label Arduino PIN I2C Function Notes
GND Ground Ground 0V
VCC Power Power Regulated 5V supply.
SDA A4 SDA Serial data in
SCL A5 SCL  I2C clock

Code

Now finding a working library proved to be problematic, I tried various ones and no success, eventually I located the Multi LCD library and have mirrored it at the following link

There are a few examples but here is a basic hello world that will show you how to display some text


#include <Arduino.h>
#include <Wire.h>
#include <MicroLCD.h>

//LCD_SH1106 lcd; /* for SH1106 OLED module */
LCD_SSD1306 lcd; /* for SSD1306 OLED module */

void setup()
{
lcd.begin();
}

void loop()
{
lcd.clear();
lcd.setFontSize(FONT_SIZE_SMALL);
lcd.println("Hello, world!");
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.println("Hello, world!");
delay(1000);
}

 

Links
I2C 128X64 OLED LCD LED Display Module For Arduino on Amazon

I2C OLED displays on Amazon UK

0.96″ 128×64 I2C Interface White Color OLED Display Module for Arduino / RPi / AVR / ARM / PIC

Share