Adsense HTML/JavaScript

Friday, August 28, 2020

TensorFlow Lite Micro support on the ESP32

The ESP32 is widely used MCU with Wi-Fi/BT/BLE. With TensorFlow Lite for Microcontrollers executing on ESP32, this opens up scenarios for all kinds of use-cases that are triggered by local inference. ESP32 has 2 CPU cores and a bunch of optimizations, making it easier to run heavy TF Micro workfloads. 

ESP32 is pretty powerful for a microcontroller. Clocked at 240MHz, with just a single core it can do the detection well under 1 second (roughly ~700ms; additional optimizations are on the way to reduce this even further). This leaves the second core free for other tasks from your application.

more on Announcing TensorFlow Lite Micro support on the ESP32

Tuesday, August 18, 2020

MicroPython (ESP32): micropython.mem_info() to get memory information

 The function mem_info() of micropython module Print information about currently used memory. If the verbose argument is given then extra information is printed.

The information that is printed is implementation dependent, but currently includes the amount of stack and heap used. In verbose mode it prints out the entire heap indicating which blocks are used and which are free.

ref: https://docs.micropython.org/en/latest/library/micropython.html?highlight=mem_info#micropython.mem_info




Monday, August 17, 2020

STM32F411CEU6 + SSD1306 I2C OLED

 

This video show 0.96 inch 128x64 OLED with SSD1306 I2C driver, drive by STM32F411CEU6 minimum development board, STM32F411CEU6 minimum development board + SSD1306 I2C OLED, using stm32duino/Arduino_Core_STM32 on Arduino IDE using ssd1306 library.

To install stm32duino/Arduino_Core_STM32 on Arduino IDE/Windows 10 and program STM32F411CEU6 minimum development board, read the post HERE.

Then:

- Install ssd1306 library in Arduino IDE Library Manager.

- Open Examples > ssd1306 > demos > ssd1306_demo

- Connect the SSD1306 I2C OLED to STM32F411CEU6 minimum development board following the comments in the demo code.


STM32F411	SSD1306 I2C OLED
----------------------------
3V3			VCC
GND			GND
B7			SDA
B6			SCL


Friday, August 14, 2020

Simple digital input/output on ESP32/MicroPython

 


A simple exercise of digital input/output on ESP32/MicroPython, digitalIn.py.

from machine import Pin
from time import sleep

LED2 = Pin(2, Pin.OUT)
IN32 = Pin(32, Pin.IN, Pin.PULL_UP);

while True:
    v = IN32.value()
    LED2.value(v)
    print(v)
    sleep(0.1)

  • Note that GPIO6-11 are usually used for SPI flash.
  • GPIO34-39 can only be set as input mode and do not have software pullup or pulldown functions.


Thursday, August 13, 2020

Simple web server on ESP32 using MicroPython


It's a ESP32/MicroPython exercise to implement a simple web server.


ap.py
try:
    import usocket as socket
except:
    import socket
  
import network
import esp
import uos

uname = uos.uname()

ap = network.WLAN(network.AP_IF)
ap.active(True)

ssid = "ssid"
password = "password"
ap.config(essid=ssid, password=password)

while ap.active() == False:
    pass

print('Access Point Active')
print(ap.ifconfig())
print("Connect to " + ssid + ":" + "password = " + password);
print("Visit: " + ap.ifconfig()[2] + ":80")

print('===== ===== =====')

res_01 = """<html>
    <head><meta name="viewport" content="width=device-width, initial-scale=1"></head>
    <body>
    <h1>Hello, MicroPython@ESP32!</h1>"""
res_02= """
    </body>
    </html>"""

res_something = "sysname: " + uname.sysname + "<br/>"\
    "nodename: " + uname.nodename + "<br/>" +\
    "release: " + uname.release + "<br/>" +\
    "version: " + uname.version + "<br/>" +\
    "machine: " + uname.machine + "<br/>"

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)

while True:
    conn, addr = s.accept()
    youraddr = str(addr)
    request = conn.recv(1024)

    conn.send(res_01)
    conn.send(res_something)
    conn.send("<br/><br/>")
    conn.send(youraddr)
    conn.send("<br/><br/>")
    conn.send(request)
    conn.send(res_02)
    conn.close()


Tuesday, August 11, 2020

microPython exercise (ESP32): get system info

The uos module contains functions for filesystem access and mounting, terminal redirection and duplication, and the uname and urandom functions. Its uname() function return a tuple containing information about the underlying machine and/or its operating system. The tuple has five fields in the following order, each of them being a string:

  • sysname – the name of the underlying system
  • nodename – the network name (can be the same as sysname)
  • release – the version of the underlying system
  • version – the MicroPython version and build date
  • machine – an identifier for the underlying hardware (eg board, CPU)

Example, sysinfo.py

import uos

uname = uos.uname()
print(uname)
print("sysname: " + uname.sysname)
print("nodename: " + uname.nodename)
print("release: " + uname.release)
print("version: " + uname.version)
print("machine: " + uname.machine)


Thursday, August 6, 2020

Install esptool/thonny on Ubuntu 20.04, to flash MicroPython firmware for ESP32.

Since Thonny 3.2, MicroPython is supported officially (details). Now you can use Thonny as MicroPython IDE, including install MicroPython firmware on device.

This video show how to install Thonny and esptool on Ubuntu 20.04, to flash MicroPython firmware for ESP32.


Basically, install with command:
$ sudo apt install python3-pip
$ pip3 install esptool
$ sudo pip3 install thonny
$ sudo apt install python3-tk

Download microPython firmware for SP32:
esp32-idf3-20200805-unstable-v1.12-663-g9883d8e81.bin is used here.

Also add permission to user to access the USB port:
$ sudo usermod -a -G dialout <user>
$ sudo chmod a+rw <port>

Run Thonny:
$ thonny

Select MicroPython for ESP32:
Tools > Options... > Interpreter > (or Run > Select interpreter)
> Select MicroPython (ESP32) from the drop-down list.

My first MicroPython script run on ESP32:
from machine import Pin
from time import sleep
led = Pin(2, Pin.OUT)
while True:
  led.value(1)
  sleep(0.4)
  led.value(0)
  sleep(0.4)
  led.value(1)
  sleep(0.4)
  led.value(0)
  sleep(0.4)
  led.value(1)
  sleep(0.4)
  led.value(0)
  sleep(2.0)

Useful links:

Related:

More ESP32/MicroPython exercises: