Difference: HardwareAccessAndMicropython (4 vs. 5)

Revision 52019-05-14 - UliRaich

Line: 1 to 1
 
META TOPICPARENT name="WorkshopSlides"

Start Presentation

Slide 1: Setting up and IoT

Changed:
<
<

Session 2: Micropython and
Hardware access

Uli Raich
Formally CERN, Geneva, Switzerland

>
>

Session 2: Micropython and

Hardware access

Uli Raich

Formally CERN, Geneva, Switzerland

 

The WeMos D1 mini CPU card

esp8266.png wemosEsp32.png

ESP8266

cost: 2.21 Euros

ESP32

cost: 4.1o Euros

Line: 42 to 42
 

How to program the processor

Changed:
<
<
esp8266Programming.png Several development tools are available:
  • ESP_IDF: The official Espressif development tool.
    Includes a gcc compiler for the ESP8266 and the ESP32

Please see
https://docs.espressif.com/projects/esp-idf/en/latest/

  • The Arduino IDENeeds extensions for these processors
    and the different CPU boards

see:
https://www.arduino.cc/en/Main/Software

  • MicroPython

see:
https://micropython-docs-esp32.readthedocs.io/en/esp32_doc/

>
>
esp8266Programming.png Several development tools are available:
  • ESP_IDF: The official Espressif development tool.
    Includes a gcc compiler for the ESP8266 and the ESP32

Please see:
https://docs.espressif.com/projects/esp-idf/en/latest

  • The Arduino IDENeeds extensions for these processors
    and the different CPU boards

see:

https://docs.espressif.com/projects/esp-idf/en/latest

  • MicroPython

see:
https://micropython-docs-esp32.readthedocs.io/en/esp32_doc

 

Flashing the code

Line: 151 to 151
  The Linux version did not work for me
Changed:
<
<
I found a version based on PyQt5 (new version of QT) which was even worse.
>
>
I found a version based on PyQt5 (new version of QT) which was even worse.
 
Changed:
<
<
I tried to correct as much as I could to make the PyQt5 version usable on Linux:
>
>
I tried to correct as much as I could to make the PyQt5 version usable on Linux:
  https://github.com/uraich/uPyCraft-Qt5
Line: 295 to 294
  neopixelCode.png
Added:
>
>

The I2C bus

I2C stands for Inter-Integrated-Circuit. It was invented by Philips Semiconductor

in 1982. Slow, short distance.

Quite a number of sensors in the "WeMos D1 sensor shield collection use the I2C bus

  • SHT30 temperature and humidity sensor
  • DS1307 real time clock
  • The BMP180 barometric pressure and temperature sensor

  • The SSD1306 OLED (Organic Light Emitting Diode) display

The physical bus

The CPU (master) connects to the sensors (slaves) through

2 digital lines:

  • SCL: the clock
  • SDA: the data

i2cBus.png

I2C start and stop sequence

When the master want to talk to the slave it issues a start sequence

It terminates the transfer with a stop sequence

i2cStartStop.png

I2C addressing

When talking to a slave the master sends a seven bit address

followed by a read/write bit

This allows to access at most 128 devices

i2cAddress.png

I2C data transfer

Data is transmitted 8 bits at a time followed by an acknowledge bit.

If acknowledge is low, transfer ok, otherwise: send stop sequence

i2cData.png

I2C write cycle

  • Send start sequence
  • Send I2C address and R/W bit low
  • Send internal register number
  • Send data byte
  • Optionally send further data bytes
  • Send stop sequence

I2C read cycle

  • Send start sequence
  • Send slave address with R/W low
  • Send address of internal register
  • Send a start sequence again
  • Send slave address with R/W high
  • Read data byte
  • Send stop sequence

I2C in Micropython

i2c_uP.png

Scanning the I2C bus

i2cScan.png

The SHT30 digital temperature and relative humidity sensor

The SHT30 is a digital temperature and humidity sensor based on the I2C bus

Here is its data sheet.

Temperature precision: +- 0.3 °C

Relative humidity: +- 3 %

Works on 2.4V – 5.5 V

sht30Block.png

A look at the SHT30 driver

https://afnog.iotworkshop.africa/pub/AFNOG/HardwareAccessAndMicropython/sht30.py.txt

Reading out the SHT30

sht30Code.png

Results from the SHT30

sht30Results.png

WeMos D1 mini sensor and actuator shields (1)

wemosButton.png wemosWS2812.png wemosOLED.png
Pushbutton WS2812 cascadable rgb LED SSD1306 OLED display
wemosDS18B20.png wemosDHT11.png wemosLedMatrix.png
DS118B20 temperature sensor DHT11 temperature and relative humidity sensor 8x8 LED Matrix

Wemos D1 mini sensor and actuator shields (2)

wemosBuzzer-v2.png wemosDataLogger-v2.png wemosSHT30.png
Passive Buzzer Data Logger SHT30 temperature and humidity sensor
tripleBase.png proto.png
triple base my prototype board: LED + photo resistor

Pinouts of shields

shieldPins.png

Documentation for the demo programs

Demo programs for all the shields are available on github:

https://github.com/uraich/MicroPython_IoTDemos

A short description of every program can be found in the README

The data logger

The data logger features a DS1307 Real Time Clock (RTC) backed up by a battery

An SD card socket also provided.

This allows to store large amounts of data locally

The RTC keeps the time and measurements can be supplied with a time tag

Programs to set and read the RTC are provided.

One of the programs setting the RTC gets the time from and NTP server

such that manual specification of the current date and time are not needed.

wemosDataLogger-v2.png
https://github.com/uraich/MicroPython_IoTDemos/tree/master/drivers/ds1307

The push button shield

pushbuttonCode.png wemosButton.png

DS18B20 shield

ds18b20Code.png wemosDS18B20.png
   

SSD1306 48x64 OLED display

This one is also an I2C device


It provides 48*64 pixels and allows to

  • Write a few characters of text
  • Do simple graphics
The ssd1306 class inherits from the


framebuf class included in Micropython such that all

drawing methods of the framebuf are available for drawing:


https://docs.micropython.org/en/latest/library/framebuf.html


For an example see:

https://github.com/uraich/MicroPython_IoTDemos/tree/master/drivers/oled

wemosOLED.png

The DHT11 shield

dht11Code.png wemosDHT11.png
The DHT11 is a digital temperature
and relative humidity sensor. It uses
a proprietary protocol of
communication with its controlling
host implemented in the
dht.DHT11 class

The LED matrix

The LED matrix has 8x8 LEDs on it, which can individually be switched on or off.

In addition to the mled class which takes care of the communication between the host

and the device and which has classes to clear the display,

set a pixel on or off and to change the brightness,

I wrote a class matrix which takes a number 0..64 and

lights this number of LEDs starting from bottom left

wemosLedMatrix.png

The buzzer

This shield implements a passive buzzer.

A passive buzzer takes a frequency(an active buzzer takes a signal level)

and produces a sound at this frequency.


This means that the frequency can be changed and a tune can be played.

In

https://github.com/uraich/MicroPython_IoTDemos/tree/master/drivers/buzzer

you will find a program interpreting songs on

RTTTL (Ring Tone Text Transfer Language)

and playing these on the buzzer

A small song library is also provided

wemosBuzzer-v2.png

The prototype module

This is a home build module featuring a photo-resistor

measuring the light intensity impinging on it.

It provides an analogue value converted to digital

by the ADC on the WeMos D1 CPU

Please note that the ESP8266 has a single 10 bit ADC

while the ESP32 has 3 12 bit ADCs.

A MUX provides up to 18 analogue channels


The light intensity can be changed with an LED

proto.png

The triple base

This module allows to easily stack a rather larger number of shields to a sandwich.

Make sure however that the GPIO lines used by the modules do not clash

tripleBase.png

Exercises

Now it is up to

You

to do the work!


The exercises are here:

https://afnog.iotworkshop.africa/do/view/AFNOG/Session2

 %SLIDESHOWEND%

Uli Raich - 2019-05-13

Line: 335 to 525
 
META FILEATTACHMENT attachment="ws2812Chain.png" attr="" comment="" date="1557837762" name="ws2812Chain.png" path="ws2812Chain.png" size="20395" user="UliRaich" version="1"
META FILEATTACHMENT attachment="neopixelCode.png" attr="" comment="" date="1557838009" name="neopixelCode.png" path="neopixelCode.png" size="81843" user="UliRaich" version="1"
META FILEATTACHMENT attachment="neopixel.png" attr="" comment="" date="1557838010" name="neopixel.png" path="neopixel.png" size="169433" user="UliRaich" version="1"
Added:
>
>
META FILEATTACHMENT attachment="i2cAddress.png" attr="" comment="" date="1557842993" name="i2cAddress.png" path="i2cAddress.png" size="1289" user="UliRaich" version="1"
META FILEATTACHMENT attachment="i2cBus.png" attr="" comment="" date="1557842993" name="i2cBus.png" path="i2cBus.png" size="1675" user="UliRaich" version="1"
META FILEATTACHMENT attachment="i2cStartStop.png" attr="" comment="" date="1557842993" name="i2cStartStop.png" path="i2cStartStop.png" size="2722" user="UliRaich" version="1"
META FILEATTACHMENT attachment="i2cData.png" attr="" comment="" date="1557843941" name="i2cData.png" path="i2cData.png" size="1286" user="UliRaich" version="1"
META FILEATTACHMENT attachment="i2c_uP.png" attr="" comment="" date="1557843981" name="i2c_uP.png" path="i2c_uP.png" size="254570" user="UliRaich" version="1"
META FILEATTACHMENT attachment="i2cScan.png" attr="" comment="" date="1557844339" name="i2cScan.png" path="i2cScan.png" size="138064" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sht30Block.png" attr="" comment="" date="1557844867" name="sht30Block.png" path="sht30Block.png" size="27925" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sht30.py.txt" attr="" comment="" date="1557845020" name="sht30.py.txt" path="sht30.py.txt" size="6612" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sht30Code.png" attr="" comment="" date="1557845226" name="sht30Code.png" path="sht30Code.png" size="87083" user="UliRaich" version="1"
META FILEATTACHMENT attachment="sht30Results.png" attr="" comment="" date="1557845238" name="sht30Results.png" path="sht30Results.png" size="172569" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosWS2812.png" attr="" comment="" date="1557845717" name="wemosWS2812.png" path="wemosWS2812.png" size="147704" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosOLED.png" attr="" comment="" date="1557845721" name="wemosOLED.png" path="wemosOLED.png" size="142541" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosButton.png" attr="" comment="" date="1557845726" name="wemosButton.png" path="wemosButton.png" size="116035" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosDHT11.png" attr="" comment="" date="1557845732" name="wemosDHT11.png" path="wemosDHT11.png" size="116136" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosDS18B20.png" attr="" comment="" date="1557845736" name="wemosDS18B20.png" path="wemosDS18B20.png" size="73173" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosLedMatrix.png" attr="" comment="" date="1557845743" name="wemosLedMatrix.png" path="wemosLedMatrix.png" size="112402" user="UliRaich" version="1"
META FILEATTACHMENT attachment="tripleBase.png" attr="" comment="" date="1557846667" name="tripleBase.png" path="tripleBase.png" size="200805" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosSHT30.png" attr="" comment="" date="1557846679" name="wemosSHT30.png" path="wemosSHT30.png" size="105373" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosDataLogger.png" attr="" comment="" date="1557846695" name="wemosDataLogger.png" path="wemosDataLogger.png" size="270203" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosBuzzer.png" attr="" comment="" date="1557846714" name="wemosBuzzer.png" path="wemosBuzzer.png" size="258738" user="UliRaich" version="1"
META FILEATTACHMENT attachment="shieldPins.png" attr="" comment="" date="1557846782" name="shieldPins.png" path="shieldPins.png" size="69919" user="UliRaich" version="1"
META FILEATTACHMENT attachment="protoBoard.png" attr="" comment="" date="1557846824" name="protoBoard.png" path="protoBoard.png" size="904008" user="UliRaich" version="1"
META FILEATTACHMENT attachment="proto.png" attr="" comment="" date="1557846884" name="proto.png" path="proto.png" size="116931" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosDataLogger-v2.png" attr="" comment="" date="1557847299" name="wemosDataLogger-v2.png" path="wemosDataLogger-v2.png" size="74486" user="UliRaich" version="1"
META FILEATTACHMENT attachment="wemosBuzzer-v2.png" attr="" comment="" date="1557847306" name="wemosBuzzer-v2.png" path="wemosBuzzer-v2.png" size="111488" user="UliRaich" version="1"
META FILEATTACHMENT attachment="ds18b20Code.png" attr="" comment="" date="1557848024" name="ds18b20Code.png" path="ds18b20Code.png" size="66399" user="UliRaich" version="1"
META FILEATTACHMENT attachment="pushbuttonCode.png" attr="" comment="" date="1557848026" name="pushbuttonCode.png" path="pushbuttonCode.png" size="67126" user="UliRaich" version="1"
META FILEATTACHMENT attachment="dht11Code.png" attr="" comment="" date="1557852263" name="dht11Code.png" path="dht11Code.png" size="55780" user="UliRaich" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback