System on a Chip, or System on a Module
Arduino | ESP8266 |
---|---|
AVR ATMega328P | Tensilica Xtensa LX106 |
8 bit | 32 bit |
1 core | 1 core |
20 MHz | 80/160 MHz |
2 KB RAM | 160 KB RAM |
32 KB Flash | 4 MB Flash |
Arduino | ESP8266 | ESP32 |
---|---|---|
AVR ATMega328P | Tensilica Xtensa LX106 | Tensilica Xtensa LX6 |
8 bit | 32 bit | 32 bit |
1 core | 1 core | 2 core * |
20 MHz | 80/160 MHz | 160/240 MHz |
2 KB RAM | 160 KB RAM | 520 KB RAM |
32 KB Flash | 1 - 4 MB Flash | 4 - 16 MB Flash |
original image: zeptobars.com
original image: zeptobars.com
original image: zeptobars.com
ESP32-DevKitC / Sparkfun ESP32 Thing / AdaFruit HUZZAH32
original images: espressif.com and sparkfun.com and adafruit.com
IoT Development Framework
C SDK for building programs to run on ESP32
Contains LWIP, examples, instructions for building toolchain
For more background, see
Damien's talk about the Kickstarter campaign
from PyConAU 2016
github: micropython/micropython-esp32
$ git clone --recursive https://github.com/micropython/micropython-esp32.git $ more micropython-esp32/ports/esp32/README.md
OR
http://micropython.org/downloads#esp32
$ pip install esptool $ esptool.py write_flash --flash_mode dio 0x1000 esp32-20170919-v1.9.2-272-g0d183d7f.bin
$ miniterm.py /dev/ttyUSB0 115200 --raw MicroPython v1.9.2-272-g0d183d7f on 2017-09-19; ESP32 module with ESP32 Type "help()" for more information. >>>
$ miniterm.py /dev/ttyUSB0 115200 --raw MicroPython v1.9.2-272-g0d183d7f on 2017-09-19; ESP32 module with ESP32 Type "help()" for more information. >>> help() Welcome to MicroPython on the ESP32!
(... etc ...)
>>> help('modules') __main__ flashbdev random uos _boot framebuf re upip _onewire gc select upip_utarfile _thread hashlib socket urandom apa106 heapq ssl ure array inisetup struct uselect binascii io sys usocket btree json time ussl builtins machine ubinascii ustruct cmath math ucollections utime collections micropython uctypes utimeq dht neopixel uerrno uzlib ds18x20 network uheapq zlib errno onewire uio esp os ujson
$ miniterm.py /dev/ttyUSB0 115200 --raw MicroPython v1.9.2-272-g0d183d7f on 2017-09-19; ESP32 module with ESP32 Type "help()" for more information. >>> import machine >>> pin = machine.Pin(5, machine.Pin.OUT) >>> pin.value(True)
>>> import machine >>> import time >>> pin = machine.Pin(5, machine.Pin.OUT) >>> while True: ... pin.value(True) ... time.sleep(1) ... pin.value(False) ... time.sleep(1)
>>> import machine >>> import time >>> pin = machine.Pin(5, machine.Pin.OUT) >>> while True: ... pin.value(True) ... time.sleep(1) ... pin.value(False) ... time.sleep(1)
Using REPL as a file transfer protocol: slow and very alpha
modules/: pre-compiled and frozen into the runtime
scripts/: source frozen into the runtime
Also upip, a micropython package manager
>>> import os >>> os.listdir() ['boot.py'] >>> f = open('hello.world', "w") >>> f.write("Hello, World!") 13 >>> f.close() >>> os.listdir() ['boot.py', 'hello.world']
>>> import network >>> w = network.WLAN(network.STA_IF) >>> w.active(True) >>> w.connect("SSID","PASSWORD") >>> w.ifconfig() ('192.168.1.101', '255.255.255.0', '192.168.1.1', '192.168.1.1')
>>> import socket >>> s = socket.socket() >>> s.connect(('example.com', 80)) >>> s.write('GET / HTTP/1.0\r\n') 16 >>> s.write('Host: example.com\r\n\r\n') 21 >>> s.readline() b'HTTP/1.0 200 OK\r\n' >>> s.close()
>>> import machine >>> i2c = machine.I2C( ... freq=400000, ... scl=machine.Pin(22), ... sda=machine.Pin(21) ... ) >>> i2c.scan() [104]
>>> import machine >>> i2c = machine.I2C( ... freq=400000, ... scl=machine.Pin(22), ... sda=machine.Pin(21) ... ) >>> i2c.readfrom_mem(104, 59, 14) b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>>> i2c.writeto_mem(104, 107, bytes([0])) >>> i2c.readfrom_mem(104, 59, 14) b'\xf3\x90\x00\x0cB\xa0\xf6\x10\xfd\x1d\x00\xa4\xff\x9d'
>>> import struct >>> struct.unpack( ... ">7h", ... i2c.readfrom_mem(104, 59, 14) ... ) (-3016, 32, 17024, -2768, -758, 224, -133)
class Accelerometer: def __init__(self, i2c=None, address=104): self.i2c = i2c or machine.I2C(freq=400000, scl=machine.Pin(22), sda=machine.Pin(21)) self.address = address self.i2c.writeto_mem(self.address, 107, bytes([0]) def read_xyz(self): return struct.unpack( ">3h", self.i2c.readfrom_mem(104, 59, 6) )
>>> import esp >>> dir(esp) ['__name__', 'flash_read', 'flash_write', 'flash_erase', 'flash_size', 'flash_user_start', 'gpio_matrix_in', 'gpio_matrix_out', 'neopixel_write', 'dht_readinto'] >>> esp.flash_size() 4194304
esp-idf/components/spi_flash/include/esp_spi_flash.h
/** * @brief Get flash chip size, as set in binary image header * * @note This value does not necessarily match real flash size. * * @return size of flash chip, in bytes */ size_t spi_flash_get_chip_size();
ports/esp32/modesp.c
#include "esp_spi_flash.h" STATIC mp_obj_t esp_flash_size(void) { return mp_obj_new_int_from_uint(spi_flash_get_chip_size()); }
ports/esp32/modesp.c
#include "esp_spi_flash.h" STATIC mp_obj_t esp_flash_size(void) { return mp_obj_new_int_from_uint(spi_flash_get_chip_size()); }
ports/esp32/modesp.c
#include "esp_spi_flash.h" STATIC mp_obj_t esp_flash_size(void) { return mp_obj_new_int_from_uint(spi_flash_get_chip_size()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size);
ports/esp32/modesp.c
#include "esp_spi_flash.h" STATIC mp_obj_t esp_flash_size(void) { return mp_obj_new_int_from_uint(spi_flash_get_chip_size()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) }, { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) }, };
ports/esp32/modesp.c
#include "esp_spi_flash.h" STATIC mp_obj_t esp_flash_size(void) { return mp_obj_new_int_from_uint(spi_flash_get_chip_size()); } STATIC MP_DEFINE_CONST_FUN_OBJ_0(esp_flash_size_obj, esp_flash_size); STATIC const mp_rom_map_elem_t esp_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_esp) }, { MP_ROM_QSTR(MP_QSTR_flash_size), MP_ROM_PTR(&esp_flash_size_obj) }, }; STATIC MP_DEFINE_CONST_DICT(esp_module_globals, esp_module_globals_table); const mp_obj_module_t esp_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&esp_module_globals, };
ports/esp32/mpconfigport.h
extern const struct _mp_obj_module_t esp_module; #define MICROPY_PORT_BUILTIN_MODULES \ { MP_OBJ_NEW_QSTR(MP_QSTR_esp), (mp_obj_t)&esp_module }, \
esp32/Makefile
SRC_C = \ modesp.c \
>>> import esp >>> dir(esp) ['__name__', 'flash_read', 'flash_write', 'flash_erase', 'flash_size', 'flash_user_start', 'gpio_matrix_in', 'gpio_matrix_out', 'neopixel_write', 'dht_readinto'] >>> esp.flash_size() 4194304
... a bit like mobile phones in the 1990s
... or motorcars in the 1920s
On the one hand
information wants to be expensive,
because it's so valuable.
The right information in the right place
just changes your life.
On the other hand,
information wants to be free,
because the cost of getting it out
is getting lower and lower all the time.
Wednesday, September 27
Connected Community HackerSpace (CCHS)
Nick Moore
Mnemote Pty Ltd
Slides:
Content © Mnemote Pty Ltd except where otherwise noted