By NASA - Public Domain, Wikimedia Commons
Micro Electro Mechanical Systems
| Arduino | ESP32 | RPi 2 |
|---|---|---|
| AVR ATMega328P | Tensilica Xtensa LX6 | ARM Cortex A53 |
| 8 bit | 32 bit | 32 bit |
| 1 core | 2 core | 4 core |
| 20 MHz | 240 MHz | 900 MHz |
| 2 KB RAM | 520 KB RAM | 1 GB RAM |
| 32 KB Flash | 16 MB Flash | MicroSDHC |
# Set up the i2c bus, which is on pins 21 and 22.
# Then wake up the acc/gyr module by writing to
# its status register.
import machine
i2c = machine.I2C(
freq=400000,
scl=machine.Pin(22),
sda=machine.Pin(21)
)
i2c.writeto_mem(104, 107, bytes([0]))
# Read a single record from the acc/gyr and expand
# it into a tuple of seven signed numbers:
# ax, ay, az, temperature, gx, gy and gz.
import struct
def read_acc():
return struct.unpack(
">7h",
i2c.readfrom_mem(104, 0x3b, 14)
)
import time
# Wait for the WLAN to be available.
while not network.WLAN().isconnected():
time.sleep(0.1)
# Connect up to an MQTT server
import umqtt.simple
cli = umqtt.simple.MQTTClient(
'r0kk1t',
'iot.eclipse.org'
)
cli.connect()
# Grab data and send timestamp plus data in an MQTT
# message.
while True:
zz = [ time.ticks_ms() ] + list(read_acc())
msg = ' '.join("%d" % x for x in zz)
cli.publish('r0kk1t', msg)
time.sleep(0.1)
import network w = network.WLAN() w.active(True) w.config(protocol=network.MODE_LR) from esp import espnow espnow.init()
import struct
pfmt = "%12d %12d" + " %6d" * 7
while True:
msg = espnow.recv()
if msg:
print(pfmt % struct.unpack(">LL7h", msg[1]))
video: John Spencer
rainbow snake logo: 2018.pycon-au.org
Nick Moore
Slides:
Content and images © Nick Moore except where otherwise noted