Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python in Hardware

Python in Hardware

Stelios Petrakis

February 24, 2017
Tweet

More Decks by Stelios Petrakis

Other Decks in Technology

Transcript

  1. Disclaimer(s) • I am a software developer • No prior

    hardware knowledge • That’s my first hardware project • No, seriously.
  2. ESP8266 • Low cost • Wi-Fi (802.11 b/g/n) • 32-bit

    RISC CPU • 40KB RAM • GPIO ports for external sensors • USB port for flashing
  3. MicroPython • Successfully funded Kickstarter project • Offers a great

    alternative to C • Based on Python 3 • Small subset of the Python library • Optimized for microcontrollers • REPL!
  4. Getting Started • Esptool.py ◦ Flashing ESP, installing new firmware

    • Platform.io ◦ Serial Ports monitoring • Beware of kernel panic USB issue in Sierra!
  5. 1...2...3...Python! • Connect your ESP in USB • Find the

    port ✏ ls -la /dev/cu.* • Flash the ESP ✏ esptool.py --port /dev/ttyUSB0 erase_flash • Download and install the Micropython firmware for ESP ✏ esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect 0 esp8266-2016-05-03-v1.8.bin • Open ports ✏ platformio serialports monitor -b 115200 • REPL!
  6. Use your ESP without USB • Configure WebREPL ◦ import

    webrepl_setup • Set the ESP to always connect to your Wi-Fi ◦ import network ◦ wlan = network.WLAN(network.STA_IF) ◦ wlan.active(True) ◦ wlan.connect('stelabouras', 'password') ◦ wlan.ifconfig() # Get ESP IP • Visit http://micropython.org/webrepl/ and enter ESP local IP ◦ You can now upload and download files to/from your ESP ◦ WebREPL >>> Terminal REPL (at least for me!)
  7. Scripting • Boot.py ◦ Runs first on power up/reset and

    contains low-level code that sets up the board • Main.py ◦ Runs after boot.py and contains your main script • Yeelight example time! ◦ Running an altered Yeelight library version for MicroPython ◦ The code