ESP8266 and DS18B20 sensor and MIcropython example

In this example we look at a DS18b20 example in Micropython for an ESP8266. Once again we use uPyCraft and again we use Wemos shields.

Lets remind ourselves about the DS18B20

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.

Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems

Requirements

Lets take a look a the shields and boards that are required for this example

 

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
This is not an official Wemos shield – this uses a DS18B20 and is connected to D2. This does mean that you can use another I2C device
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

I connect the Wemos Mini to the dual base and then put the DS18B20 shield along side this, you can connect the Wemos DS18B20 shield directly to the Wemos Mini if you want.

Name Link
Wemos Mini D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
Wemos DS18B20 Temperature Sensor Shield DS18B20 Temperature Sensor Shield Wemos D1 Mini D1 Mini Pro ESP NodeMCU

Code

Create a new file called ds.py and import it into uPyCraft

from machine import Pin
import time, ds18x20
import onewire
ow = onewire.OneWire(Pin(4)) # create a OneWire bus on GPIO12
 
ds = ds18x20.DS18X20(ow)
 
roms = ds.scan()
ds.convert_temp()
time.sleep_ms(750)
 
for rom in roms:
    print(ds.read_temp(rom))

 

Output

You should see something like this

Ready to download this file,please wait!
..
download ok
exec(open(‘ds.py’).read(),globals())
26.4375
>>>

Links

 

Wemos Mini and various shields ebook

As you may know looking at this web site we are big fans of the Wemos mini and the various shields that you can buy for this hardware. We have decided to write an ebook and publish it on the Kindle store and of course any money recieved through commision will go towards buying new modules, sensors and shields. We also want to design our own shields which this would help fund.

There will be descriptions of each chapter, code examples (which is available via a github link in the book) and expected output. Here are the contents of the ebook so you can see what we have added

Contents 2
About the ESP8266 4
The Wemos Mini and shields 5
Setting up the Arduino IDE 6
Basic examples 7
Flash an LED example 7
Basic Wifi example 8
I2Scanner example 9
Basic Webserver example 11
Read and write to the eeprom 16
ESP specific APIs 18
A look at SHA-1 20
The ticker library 21
Sampling analog data 22
Control a Wemos using an application on your PC 23
A look at SPIFFS 28
Setup your ESP8266 as an Action point 32
DHT Shield example 33
The 1 button shield 36
WS2812B RGB Shield 37
OLED Shield 40
Barometric Pressure Shield 43
TFT 2.4 Touch Shield 46
BMP180 Shield 55
DS18B20 Shield 57
PIR Shield 60
Micro SD Card Shield 62
IR Controller Shield 64
Ambient light Shield (BH1750) 67
DHT Pro Shield 69
RGB LED Shield 71
SHT30 Shield 74
TFT 1.4 Shield 76
Matrix LED Shield 84
Buzzer Shield 87
Relay Shield 90
Other Shields 91
DHT22 readings on an OLED display simple project 93
OLED shield bitcoin ticker example 96
PIR shield warning example 100
BMP180 versus SHt30 temperature comparison 101
Save sensor values to an SD card 102
Conclusion 105

We receive a percentage of the profits from Amazon which we reinvest into this site with regards domain name renewal, web site hosting and purchasing any parts we use – we don’t get any samples or freebies from any companies (but live in hope).

So please support the site by purchasing the ebook from the following links

 

Site Link
Amazon US Buy here
Amazon UK Buy here
Amazon DE Buy here
Amazon FR Buy here
Amazon ES Buy here
Amazon IT Buy here
Amazon NL Buy here
Amazon JP Buy here
Amazon BR Buy here
Amazon CA Buy here
Amazon MX Buy here
Amazon AU Buy here
Amazon IN Buy here

 

ESP8266 RGB LED examples in Micropython

In this example we look at some WS2812B RGB LEDs example in Micropython for an ESP8266. Once again we use uPyCraft and again we use Wemos shields.

WS2812B is a intelligent control LED light source that the control circuit and RGB chip are integrated in a package of 5050 components. It internal include intelligent digital port data latch and signal reshaping amplification drive circuit. Also include a precision internal oscillator and a 12V voltage programmable constant current control part, effectively ensuring the pixel point light color height consistent.

The data transfer protocol use single NZR communication mode. After the pixel power-on reset, the DIN port receive data from controller, the first pixel collect initial 24bit data then sent to the internal data latch, the other data which reshaping by the internal signal reshaping amplification circuit sent to the next cascade pixel through the DO port. After transmission for each pixel,the signal to reduce 24bit. pixel adopt auto reshaping transmit technology, making the pixel cascade number is not limited the signal transmission, only depend on the speed of signal transmission.

LED with low driving voltage, environmental protection and energy saving, high brightness, scattering angle is large, good consistency, low power, long life and other advantages. The control chip integrated in LED above becoming more simple circuit, small volume, convenient installation

Requirements

Lets take a look a the shields and boards that are required for this example

 

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
WS2812 shield – intelligent control RGB (16777216 colors) LED light source shield.
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

I connect the Wemos Mini to the dual base and then put the RGB LED shield along side this, you can connect the Wemos RGB LED shield directly to the Wemos Mini if you want.

Name Link
Wemos Mini D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
Wemos RGB LED shield For WeMos D1 MINI WS2812B RGB Full Color Shield Board

Code

Example 1

from machine import Pin
import neopixel
 
pixels = neopixel.NeoPixel(Pin(4, Pin.OUT), 1)
pixels[0] = (0xff, 0x00, 0x22)
pixels.write()

Example 2

from machine import Pin
import neopixel
import time
 
pixels = neopixel.NeoPixel(Pin(4, Pin.OUT), 1)
 
while True:
	pixels[0] = (0xff, 0x00, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0xff, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0x00, 0xff)
	pixels.write()
	time.sleep(1)

Example 3

from machine import Pin
import neopixel
import time
 
pixels = neopixel.NeoPixel(Pin(4, Pin.OUT), 1)
 
while True:
	pixels[0] = (0xff, 0x00, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0xff, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0x00, 0xff)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0xff, 0xff, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0xff, 0xff)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0xff, 0x00, 0xff)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0xff, 0xff, 0xff)
	pixels.write()
	time.sleep(1)

Links

 

Wemos and DHT Pro shield Micropython example

In this example we look at a DHT PRO example in Micropython for an ESP8266. Once again we use uPyCraft and again we use Wemos shields.

The DHT pro is actually an AM2302 sensor from the same company as the DHT11

A reminder of the AM2302 from the datasheet

AM2302 capacitive humidity sensing digital temperature and humidity module is one that contains the compound has been calibrated digital signal output of the temperature and humidity sensors. Application of a dedicated digital modules collection technology and the temperature and humidity sensing technology, to ensure that the product has high reliability and excellent long-term stability. The sensor includes a capacitive sensor wet components and a high-precision temperature measurement devices, and connected with a high-performance 8-bit microcontroller.

The product has excellent quality, fast response, strong anti-jamming capability, and high cost. Each sensor is extremely accurate humidity calibration chamber calibration. The form of procedures, the calibration coefficients stored in the microcontroller, the sensor within the processing of the heartbeat to call these calibration coefficients. Standard single-bus interface, system integration quick and easy. Small size, low power consumption, signal transmission distance up to 20 meters, making it the best choice of all kinds of applications and even the most demanding applications

 

Requirements

Lets take a look a the shields and boards that are required for this example

 

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
This is not an official Wemos shield – its called the DHT Shield but its based on the AM2302
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

I connect the Wemos Mini to the dual base and then put the DHT shield along side this, you can connect the Wemos DHT shield directly to the Wemos Mini if you want.

Name Link
Wemos Mini D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
DHT PRO shield DHT Pro Shield for WeMos D1 mini DHT22 Single-bus digital temperature and humidity sensor module sensor

Code

 

from machine import Pin
import dht
import time
 
while True:
	sensor = dht.DHT22(Pin(2))
	sensor.measure()
 
	print('Temperature = %.2f' % sensor.temperature())
	print('Humidity = %.2f' % sensor.humidity())
	time.sleep(3)

 

Output

You should see something like the following in uPyCraft

Ready to download this file,please wait!
..
download ok
exec(open(‘dht22.py’).read(),globals())
Temperature = 26.10
Humidity = 32.60
Temperature = 26.20
Humidity = 32.50
Temperature = 26.10
Humidity = 32.50
Temperature = 26.20
Humidity = 32.60

 

Links

https://akizukidenshi.com/download/ds/aosong/AM2302.pdf