Home Espruino Espruino temperature display project

Espruino temperature display project

In this project we will display temperature from a DS18B20 on an OLED display.

Here is a picture of my project, you can see the temperature displayed on the OLED and the DS18B20 sesnor with an onboard power indicator LED

espruino-temp-project

LCD Wiring:

LCD pin Espruino
GND GND
VCC 3.3
SDA B7
SCL B6

DS18B20 Wiring:

DS18B20 module Espruino
GND GND
VCC 3.3
DQ (Data pin) B13

 

Layout

Here is a layout diagram of the project, the DS18B20 module I used is represented on the breadboard

espruino-and-oled-and-ds18b20_bb

 

Code

The code is fairly simple, you can change the pin that the DS18B20 connects to on the following line – var ow = new OneWire(B3);

There is also a temperature conversion from celsius to fahrenheit – var fahr = celsius * 1.8 + 32;

Another line worth looking at is the rounding of the temperature reading – celsius = Math.round(celsius*10)/10;

 

[codesyntax lang=”javascript”]

require("DS18B20");
require("SSD1306");
// I2C
I2C1.setup({scl:B6,sda:B7});

var ow = new OneWire(B3);

var g, temp;

function onInit() {
  clearInterval();

  temp = require("DS18B20").connect(ow);
  g = require("SSD1306").connect(I2C1, function() {
    setInterval(onTimer, 500);
  });
}

function onTimer() {
  // Get the temperature
  var celsius = temp.getTemp();
  var fahr = celsius * 1.8 + 32;
  // Round it to the nearest 0.1
  celsius = Math.round(celsius*10)/10;
  fahr = Math.round(fahr*10)/10;
  // display the celsius and fahr
  g.clear();
  g.setFontBitmap(); // simple 8x8 font
  g.drawString("Temperature",2,0);
  g.drawLine(0,10,84,10);
  g.setFontVector(20); // large font
  g.drawString(celsius+ " c", 0, 15);
  g.drawString(fahr+ " f", 0, 40);
  g.flip(); // copy this to the screen
};

onInit();

[/codesyntax]

 

Links
MK00237 Small temperature sensor temperature measurement module DS18B20 module 18B20 module

128X64 0.96 Inch OLED LCD LED Display Module Yellow, blue double color and white e For Arduino 0.96″ IIC SPI

You may also like