Categories

Follow

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

Wemos and DHT11 example in Micropython

In this example we look at a DHT11 example in Micropython for an ESP8266. Once again we use uPyCraft and again we use Wemos shields. In this example we will use the original DHT version 1.0.0 shield which was based on the DHT11 . Later shields use the DHT12.

A reminder of the DHT11

The DHT11 digital temperature and humidity sensor is a composite Sensor contains a calibrated digital signal output of the temperature and humidity. 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 resistive sense of wet components and an NTC temperature measurement devices, and connected with a high-performance 8-bit microcontroller.

 

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 the original DHT11 shield – still available from many sellers. The later version uses a DHT12 which is an 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 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
Wemos DHT11 1PCS DHT Shield for WeMos D1 mini DHT11 Single-bus digital temperature and humidity sensor module sensor

Code

 

from machine import Pin
import dht
import time
 
while True:
	sensor = dht.DHT11(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(‘dht.py’).read(),globals())
Temperature = 29.00
Humidity = 16.00
Temperature = 28.00
Humidity = 17.00
Temperature = 28.00
Humidity = 17.00
Temperature = 28.00
Humidity = 17.00

 

Links

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

ESP8266 and OLED Micropython example

In this example we show an example written in Micropython using the uPycraft IDE. This time we will be trying out the Wemos OLED shield connected to a Wemos Mini.

Requirements

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

 

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
A  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 – optional

Parts List

I connect the Wemos Mini to the dual base and then put the OLED shield along side this. You can connect the OLED 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 OLED shield OLED Shield for WAVGAT D1 mini 0.66″ inch 64X48 IIC I2C
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

Code

This is a basic example

from machine import Pin,I2C
import ssd1306
 
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)  #Init i2c
 
lcd=ssd1306.SSD1306_I2C(64,48,i2c)             #create LCD object,Specify col and row
lcd.text("ESP8266",0,0)                        
lcd.text("test",0,16)                       
lcd.text("123456",0,32)                        
lcd.show()                                      #display

and another example

import time
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
 
 
width = 64
height = 48
 
i2c = I2C(scl=Pin(5), sda=Pin(4))
oled = SSD1306_I2C(width, height, i2c)
 
oled.fill(1)
oled.show()
 
time.sleep(2)
 
oled.fill(0)
oled.show()
 
time.sleep(2)
 
oled.pixel(0, 0, 1)
oled.show()
 
time.sleep(2)
 
oled.pixel(63, 47, 1)
oled.show()
 
time.sleep(2)
 
oled.text('Hello', 0, 0)
oled.text('World', 0, 10)
oled.show()
 
time.sleep(2)
 
oled.invert(True)
 
time.sleep(2)
 
oled.invert(False)

ESP8266 Micropython I2C Scanner

This is a simple very short code example in which we show how to create a basic I2CScanner in Micropython using the uPyCraft IDE for an ESp8266.

The arduino equivalent is one that I use frequently and is one of the most useful sketches for figuring out why a sensor may not be working correctly with a library or code – usually because teh default I2C address differs from the sensor you buy

 

Code

import machine
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
 
print('Scan i2c bus...')
devices = i2c.scan()
 
if len(devices) == 0:
  print("No i2c device !")
else:
  print('i2c devices found:',len(devices))
 
  for device in devices:  
    print("Decimal address: ",device," | Hexa address: ",hex(device))

 

Output

All going well you should output like the following in uPyCraft – this is a Wemos OLED shield connected to a Wemos Mini

 

Ready to download this file,please wait!

download ok
exec(open(‘i2cscanner.py’).read(),globals())
Scan i2c bus…
i2c devices found: 1
Decimal address: 60 | Hexa address: 0x3c
>>>
>>>