OLED + Temperature Sensor on Espruino (JavaScript on MCU)
Intro: OLED + Temperature Sensor on Espruino (JavaScript on MCU)
Two short examples of reading temperature by DS18B20 or DHT22 sensor and show it on OLED display (4-wire SPI) or (2-wire I2C).
Everything is wired directly with breadboard wires to the Espruino Pico board.
No external power supply needed.Just Plugin to USB Port or power by USB battery pack.
STEP 1: SPI OLED + DS18B20
>> source on GitHub
Hardware
- SPI OLED display (aliexpress)
- Temperature sensor ([aliexpress)
| OLED | Pico | | ---- |------|Wiring DS18B20 temperature sensor
| GND | A5 |
| VCC | A7 |
| SCL | B5 |
| SDA | B6 |
| RST | B7 |
| D/C | A8 |
| DS18B20 | Pico |Initialize OLED display
| ------- |------|
| GND | GND |
| OUT | A6 |
| VCC | VDD |
var spi = new SPI();Initialize DS18B20 temperature sensor
spi.setup({mosi: B6, sck:B5});
// OLED driver and graphic library
var g = require("SSD1306").connectSPI(spi, A8, B7, function() {
// display is connected...
// do something
});
// Analog pin A6 to read temperature from Dallas DS18B20 sensorRead temperature
// temp sensor is powered by pins VDD and GND of pico
var ow = new OneWire(A6);
var tempSensor = require("DS18B20").connect(ow);
var temperature = tempSensor.getTemp();
console.log("Temp is "+temperature);
STEP 2: I2C OLED + DHT22
>> source on GitHub
Hardware
- I2C OLED display ([aliexpress)
- Temperature sensor (aliexpress)
| OLED | Pico |Wiring DHT22 temperature sensor
| ---- |------|
| GND | A5 |
| VCC | A7 |
| SDL | B6 |
| SDA | B7 |
| DHT22 | Pico |Initialize OLED display
| ------- |------|
| 1: VCC | VDD |
| 2: DATA | A8 |
| 3: N/C | N/C |
| 4: GND | GND |
> N/C = not connected
I2C1.setup({scl:B6,sda:B7});Initialize DHT22 temperature sensor
// OLED driver and graphic library
var g = require("SSD1306").connect(I2C1, function() {
// display is connected...
// do something
});
// Analog pin A8 to read temperature from DHT22 sensorRead temperature
// temp sensor is powered by pins VDD and GND of pico
var tempSensor = require("DHT22").connect(A8);
var temperature;
var humidity;
tempSensor.read(function(dht) {
temperature = dht.temp;
humidity = dht.rh;
console.log("Temp is "+temperature.toString()+" and RH is "+humidity.toString());
});