Categories

ESP8266 Project : DS18b20 temperature on an OLED

In this particular example we are going to display temperature readings from a DS18B20 on an OLED display, we will be using a Wemos mini and a variety of shields which make it easy to create projects like this with no wiring.

Lets take a look a the shields and boards

 

Image Summary
The Wemos mini – ESP8266 based board, it comes with various headers. This is the beauty of it you can create stackable projects with the board and pin compatible shields
Not an official Wemos board but readily available featuring the ever popular DS18B20 temperature sensor
A little 64×48 OLED screen
This is simply a base, you plug the Wemos Mini into one side and you can plug a shield or shields into the other side

 

 

 

Parts List

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x Ds18B20 shield

I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then place the DS18b20 shield on top of the Wemos Mini. This image hopefully shows this

 

Code

Various libraries required – you can install these via the library manager, here are links to them

https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library 

You will also have to install the OneWire library

#include <OneWire.h>
#include <SFE_MicroOLED.h> // Include the SFE_MicroOLED library
#define PIN_RESET 255 //
#define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D
// OneWire DS18S20, DS18B20, DS1822 Temperature Example
OneWire ds(D2); // on pin D2 (a 4.7K resistor is necessary)
MicroOLED oled(PIN_RESET, DC_JUMPER); // Example I2C declaration
void setup(void)
{
Serial.begin(9600);
oled.begin();
oled.clear(ALL); // Clear the display's memory (gets rid of artifacts)
oled.display();
}
void loop(void)
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr))
{
ds.reset_search();
delay(250);
return;
}
if (OneWire::crc8(addr, 7) != addr[7])
{
Serial.println("CRC is not valid!");
return;
}
// the first ROM byte indicates which chip
switch (addr[0])
{
case 0x10:
type_s = 1;
break;
case 0x28:
type_s = 0;
break;
case 0x22:
type_s = 0;
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000);
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++)
{
data[i] = ds.read();
}
// Convert the data to actual temperature
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10)
{
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else
{
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
}
oled.clear(PAGE);
oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
oled.setCursor(1, 3);
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
oled.print("Cels = ");
oled.setCursor(1, 12);
oled.print(celsius);
oled.print(" *C");
oled.setCursor(1, 21);
oled.print("Fahr =");
oled.setCursor(1, 30);
oled.print(fahrenheit);
oled.print(" *F");
oled.display();
}

Can’t be bothered typing all that in – Wemos_OLED_DS18b20

 

Output

Here you can see the output and my setup

DS18b20 and WEMOS output

DS18b20 and WEMOS output

 

 

Links

You can hopefully pick this all up for $10

Smart Electronics D1 mini – Mini NodeMcu 4M bytes development board based ESP8266 by WeMos

Shield for WeMos D1 mini V2 DS18B20 Single-bus digital temperature and humidity sensor module sensor

0.66″ inch For Wemos Oled 64X48 IIC I2C LCD OLED LED Display Shield

Dual Base Expansion board for WeMos D1 mini NodeMCU ESP8266

Create a simple barometer using an ESP8266 and a MS5611 sensor

In this particular example we are going to simply display temperature, pressure and altitude readings from a MS5611 sensor on an OLED display. We will be using various Wemos MIni shields and an MS5611 sensor

Here is a little about the MS5611

This barometric pressure sensor is optimized for altimeters and variometers with an altitude resolution of 10 cm. The sensor module includes a high linearity pressure sensor and an ultra-low power 24 bit ΔΣ ADC with internal factory calibrated coefficients. It provides a precise digital 24 Bit pressure and temperature value and different operation modes that allow the user to optimize for conversion speed and current consumption. A high resolution temperature output allows the implementation of an altimeter/thermometer function without any additional sensor. The MS5611-01BA can be interfaced to virtually any microcontroller. The communication protocol is simple, without the need of programming internal registers in the device.

This is the module we used which makes it easy to use the sensor

 

Parts List

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x MS5611 sensor (GY-63)

I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then connect the Ms5611 sensor to the Wemos Mini using cables.

Wemos  Ms5611
3v3 Vcc
Gnd Gnd
SDA SDA
SCL SCL

 

Code

Various libraries required – you can install these via the library manager, here are links to them

https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library 

https://github.com/jarzebski/Arduino-MS5611 library

If you can’t be bothered typing all of this in you can download the sketch from barometer

 

Output

Here you can see the output and my setup

 

 

Links

 

Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos

Double Socket Dual Base Shield for WeMos D1 Mini NodeMCU ESP8266 Diy PCB D1 Expansion board

64X48 IIC I2C LCD OLED LED Dispaly Shield for Arduino Compatible WeMos D1 Mini

GY-63 MS5611-01BA03 Precision MS5611 Atmospheric Pressure Sensor Module Height Sensor Module

Build a luxmeter with an ESP8266 and an OPT3001 sensor

In this particular example we are going to simply display visible light measurements from a OPT3001 sensor on an OLED display. We will be using various Wemos MIni shields and an OPT3001 sensor

Here is a little about the OPT3001

The OPT3001 is a sensor that measures the intensity of visible light. The spectral response of the sensor tightly matches the photopic response of the human eye and includes significant infrared rejection.

The OPT3001 is a single-chip lux meter, measuring the intensity of light as visible by the human eye. The precision spectral response and strong IR rejection of the device enables the OPT3001 to accurately meter the intensity of light as seen by the human eye regardless of light source. The strong IR rejection also aids in maintaining high accuracy when industrial design calls for mounting the sensor under dark glass for aesthetics. The OPT3001 is designed for systems that create light-based experiences for humans, and an ideal preferred replacement for photodiodes, photoresistors, or other ambient light sensors with less human eye matching and IR rejection.

Parts List

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x OPT3001 board

I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then connect the OPT3001 sensor to the Wemos Mini using cables.

Wemos  CJMCU-3001
3v3 Vcc
Gnd Gnd
SDA SDA
SCL SCL

 

Code

Various libraries required – you can install these via the library manager, here are links to them

https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library 

https://github.com/closedcube/ClosedCube_OPT3001_Arduino

If you can’t be bothere dtyping all of this in you can download the sketch from luxmeter 

#include <Wire.h>  // Include Wire if you're using I2C
#include <SFE_MicroOLED.h>  // Include the SFE_MicroOLED library
#include <ClosedCube_OPT3001.h>
#define OPT3001_ADDRESS 0x44
#define PIN_RESET 255 //
#define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D
MicroOLED oled(PIN_RESET, DC_JUMPER);
ClosedCube_OPT3001 opt3001;
void setup()
{
Serial.begin(9600);
oled.begin();
oled.clear(ALL);
oled.display();
opt3001.begin(OPT3001_ADDRESS);
Serial.print("OPT3001 Manufacturer ID");
Serial.println(opt3001.readManufacturerID());
Serial.print("OPT3001 Device ID");
Serial.println(opt3001.readDeviceID());
configureSensor();
printResult("High-Limit", opt3001.readHighLimit());
printResult("Low-Limit", opt3001.readLowLimit());
Serial.println("----");
}
void loop()
{
OPT3001 result = opt3001.readResult();
printResult("OPT3001", result);
delay(500);
}
void configureSensor() {
OPT3001_Config newConfig;
newConfig.RangeNumber = B1100;
newConfig.ConvertionTime = B0;
newConfig.Latch = B1;
newConfig.ModeOfConversionOperation = B11;
OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig);
if (errorConfig != NO_ERROR)
printError("OPT3001 configuration", errorConfig);
else {
OPT3001_Config sensorConfig = opt3001.readConfig();
Serial.println("OPT3001 Current Config:");
Serial.println("------------------------------");
Serial.print("Conversion ready (R):");
Serial.println(sensorConfig.ConversionReady,HEX);
Serial.print("Conversion time (R/W):");
Serial.println(sensorConfig.ConvertionTime, HEX);
Serial.print("Fault count field (R/W):");
Serial.println(sensorConfig.FaultCount, HEX);
Serial.print("Flag high field (R-only):");
Serial.println(sensorConfig.FlagHigh, HEX);
Serial.print("Flag low field (R-only):");
Serial.println(sensorConfig.FlagLow, HEX);
Serial.print("Latch field (R/W):");
Serial.println(sensorConfig.Latch, HEX);
Serial.print("Mask exponent field (R/W):");
Serial.println(sensorConfig.MaskExponent, HEX);
Serial.print("Mode of conversion operation (R/W):");
Serial.println(sensorConfig.ModeOfConversionOperation, HEX);
Serial.print("Polarity field (R/W):");
Serial.println(sensorConfig.Polarity, HEX);
Serial.print("Overflow flag (R-only):");
Serial.println(sensorConfig.OverflowFlag, HEX);
Serial.print("Range number (R/W):");
Serial.println(sensorConfig.RangeNumber, HEX);
Serial.println("------------------------------");
}
}
void printResult(String text, OPT3001 result)
{
if (result.error == NO_ERROR)
{
Serial.print(text);
Serial.print(": ");
Serial.print(result.lux);
Serial.println(" lux");
oled.clear(PAGE);
oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
oled.setCursor(1, 3);
oled.print("Lux: ");
oled.setCursor(1, 12);
oled.print(result.lux);
oled.print(" lux\t");
oled.display();
}
else
{
printError(text,result.error);
}
}
void printError(String text, OPT3001_ErrorCode error) {
Serial.print(text);
Serial.print(": [ERROR] Code #");
Serial.println(error);
}

 

Output

Here you can see the output and my setup

 

 

Links

 

Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos

Double Socket Dual Base Shield for WeMos D1 Mini NodeMCU ESP8266 Diy PCB D1 Expansion board

64X48 IIC I2C LCD OLED LED Dispaly Shield for Arduino Compatible WeMos D1 Mini

OPT3001 CJMCU-3001 ambient light sensor eye like measurement light intensity single chip illumination meter

Arduino traffic light example

This was a a simple board that I bought which basically consists of a red, yellow and green LED on a board, rather than buying seperate components and using a breadboard this is a reasonably low cost solution.

 

Code

In the example we use Pin 5 , 6 and 7 for the green, yellow and red LEDs

 

byte pinLedRed = 7;
byte pinLedYellow = 6;
byte pinLedGreen = 5;
 
void setup()
{
    // Initialize the pins as output pins
    pinMode(pinLedRed, OUTPUT);
    pinMode(pinLedYellow, OUTPUT);
    pinMode(pinLedGreen, OUTPUT);
}
 
void loop()
{
 
    //Red signal
    digitalWrite(pinLedRed, HIGH); // RED on
    delay(5000); // 5 secs
 
    //Yellow + Red
    digitalWrite(pinLedYellow, HIGH); // YELLOW on
    delay(1000); // 1 sec
 
    //Green signal
    digitalWrite(pinLedRed, LOW); // RED  off
    digitalWrite(pinLedYellow, LOW); // YELLOW off
    digitalWrite(pinLedGreen, HIGH); // GREEN  on
    delay(5000); // 5 secs
 
    //Yellow signal
    digitalWrite(pinLedGreen, LOW); // GREEN  off
    digitalWrite(pinLedYellow, HIGH); // YELLOW  on
    delay(1000);
    digitalWrite(pinLedYellow, LOW); // YELLOW  off
 
}

 

Link

The traffic light board only costs about $1

LED traffic lights light-emitting module / digital signal output Traffic light module / electronic building blocks

Roll the dice codebug example

A simple dice game on a codebug

Go to http://www.codebug.org.uk/create/ and paste the code in, the good thing is this also generates a Python and blockly example

Code

var delay;
var pressed;
var count;
 
 
codebug_direction('U');
codebug_sleepafter(1);
io_configure(0, IO_DIGITAL_INPUT);
io_configure(1, IO_DIGITAL_INPUT);
io_configure(2, IO_DIGITAL_INPUT);
io_configure(3, IO_DIGITAL_INPUT);
io_configure(4, IO_DIGITAL_INPUT);
io_configure(5, IO_DIGITAL_INPUT);
io_configure(6, IO_DIGITAL_INPUT);
io_configure(7, IO_DIGITAL_INPUT);
io_configure_pullup(0, 0);
io_configure_pullup(2, 0);
io_configure_pullup(3, 0);
io_configure_pullup(4, 0);
io_configure_pullup(5, 0);
 
 
delay = 60;
pressed = 0;
count = 1;
while (true) {
  if (io_get_input('A') == 1) {
    pressed = 1;
    fivebyfivedisplay.clear();
    fivebyfivedisplay.update();
    while (io_get_input('A') == 1) {
      count = count + 1;
    }
    count = count % 6;
  }
  if (1 == pressed) {
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 1, 1, 1]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 1, 0], [0, 1, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    if (0 == count) {
      count = 6;
    }
    if (1 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]));
      fivebyfivedisplay.update();
    } else if (2 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0]]));
      fivebyfivedisplay.update();
    } else if (3 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    } else if (4 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    } else if (5 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    } else if (6 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    }
    pressed = 0;
  }
}

 

To test this out , simply upload the example – following the instructions on the website. Press the A button to roll the dice