O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Getting Started with Embedded Python: MicroPython and CircuitPython

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 33 Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Quem viu também gostou (20)

Anúncio

Semelhante a Getting Started with Embedded Python: MicroPython and CircuitPython (20)

Anúncio

Mais recentes (20)

Getting Started with Embedded Python: MicroPython and CircuitPython

  1. 1. Getting Started with Embedded Python (MicroPython and CircuitPython) @iAyanPahwa/iayanpahwa
  2. 2. About Me Embedded Software Engineer at Mentor Graphics - A Siemens Business Part time blogger Full time maker Mentor Graphics is world leader in Electronics Design Automation(Tools Business). I work for Automotive Embedded Software Division, which deals in providing custom solutions, OS and BSP for IVI and ADAS systems. Contact: https://iayanpahwa.github.io
  3. 3. People who are really serious about software should make their own hardware - Alan Kay Motivation - @iAyanPahwa/iayanpahwa
  4. 4. Motivation @iAyanPahwa/iayanpahwa
  5. 5. What is MicroPython The MicroPython project is an open source implementation of Python 3 that includes a small subset of the Python standard libraries, and is optimised to run on microcontrollers with constrained environments like limited ROM, RAM and processing power. It came about after a successful Kick-starter campaign by Damien George. @iAyanPahwa/iayanpahwa
  6. 6. Python 3 IoT (Devices) Microcontrollers In a NutShell @iAyanPahwa/iayanpahwa
  7. 7. Opportunities @iAyanPahwa/iayanpahwa
  8. 8. @iAyanPahwa/iayanpahwa
  9. 9. ~20MHz System Clock ~32Kb RAM ~16MB ROM Single Core Register Level Access Microcontrollers @iAyanPahwa/iayanpahwa
  10. 10. MicroPython - A small stripped down version on Python3 which runs as firmware on microcontrollers, exposes all the low level modules, acting as an operating system. - It is packed full of advanced features such as an interactive prompt, arbitrary precision integers, closures, list comprehension, generators, exception handling and more. - Yet it is compact enough to fit and run within just 256k of code space and 16k of RAM. - MicroPython aims to be as compatible with normal Python as possible to allow you to transfer code with ease from the desktop to a microcontroller or embedded target. - Python APIs for low level hardware modules- GPIOs, UART, PWM, ADC, i2c, SPI. - Runs directly on bare-metal or under OS env or as emulator. @iAyanPahwa/iayanpahwa
  11. 11. Python vs μPython vs Arduino Refer: https://github.com/micropython/micropython/wiki @iAyanPahwa/iayanpahwa
  12. 12. Boards Supported @iAyanPahwa/iayanpahwa
  13. 13. The PyBoard
  14. 14. The ESP8266 160Kb RAM 802.11 b/g/n 4MB Flash GPIO, ADC, I2c, SPI @iAyanPahwa/iayanpahwa
  15. 15. Functions & Libraries Supported @iAyanPahwa/iayanpahwa
  16. 16. Interaction Serial REPL (115200 BAUD RATE) WEB REPL, works over LAN File System mounts on host Tools to transfer source code(ex: AMPY) Emulation on linux host Unicorn web based emulator @iAyanPahwa/iayanpahwa
  17. 17. Interaction: Serial Loading uP on ESP8266 board Install esptool - pip install esptool Download uP firmware.bin from GitHub release pages for your board. Erase flash - esptool.py --port /path/to/ESP8266 erase_flash Flash uP firmware - esptool.py --port /path/to/ESP8266 -- baud 460800 write_flash --flash_size=detect 0 firmware.bin Connect Serial console - screen /dev/tty… 115200 @iAyanPahwa/iayanpahwa
  18. 18. Interaction: WebREPL Setting up WebREPL > import webrepl_setup > Enter ‘E’ to enable it > Enter and confirm password(defaults micropythoN) > Enter ‘y’ to reboot and save changes @iAyanPahwa/iayanpahwa
  19. 19. Interaction: WebREPL @iAyanPahwa/iayanpahwa
  20. 20. Interaction: Unicorn https://micropython.org/unicorn @iAyanPahwa/iayanpahwa
  21. 21. Interaction: Live https://micropython.org/live @iAyanPahwa/iayanpahwa
  22. 22. Interaction: Emulator @iAyanPahwa/iayanpahwa
  23. 23. (DEMO) HELLO WORLD OF ELECTRONICS @iAyanPahwa/iayanpahwa
  24. 24. Interaction: Hello WORlD // Classic way of Blinking LED #include “Board_Defination_File.h” int main(void) { while(1){ DDRB |= (1 << 7); PORTB |= (1 << 7); _delay_ms(1000); PORTB &= ~(1 << 7); _delay_ms(1000); } } // Make Pin Output // Send logic 1 to the pin //Send logic 0 to the pin @iAyanPahwa/iayanpahwa
  25. 25. Interaction: h3llO WORlD > from machine import Pin > from time import sleep # Make Pin behave as output > led = Pin(2, Pin.OUT) > while True: # Send digital logic 1 to the pin > led.on() > sleep(1) # Send digital logic 0 to the pin > led.off() > sleep(1) MicroPython Way @iAyanPahwa/iayanpahwa
  26. 26. Interaction: Advance File System on Flash to store: WiFi credentials (SSID, PASSOWRD) boot.py - POST operations main.py - main executable You can mount the fs over network, or transfer files over webREPL or tools like AMPY. @iAyanPahwa/iayanpahwa
  27. 27. CircuitPython https://github.com/adafruit/circuitpython Adafruit fork of MicroPython maintained for educational purpose around boards sell by Adafruit industries. Centred Around ATMEL SAMD21 and ESP8266 SoCs. Various new modules added like capacitive touch APIs, Sound outputs, USB HID etc. Bluetooth Low energy support with newly supported NRF SoC port.
  28. 28. DISCLAIMER: The stunts will be performed by experts under expert supervision and no matter how many times you test before, chances of live demo failures are incalculable :P SHOW TIME @iAyanPahwa/iayanpahwa
  29. 29. DEMOS @iAyanPahwa/iayanpahwa
  30. 30. Temperature and Humidity Measurement > import dht, machine > from time import sleep # Make Pin behave as output > d = dht.DHT11(machine.Pin(4)) > while True: # Measure temp and humidity > d.measure() # Print Values > d.temperature() > d.humidity() > sleep(2) @iAyanPahwa/iayanpahwa
  31. 31. NeoPixel * 1 wire to control multiple LEDs, color and brightness. * 8-bit format for Red, Green, Blue * RRGGBB * 0-ff or 0-255
  32. 32. NeoPixel > import machine, neopixel # Initialize GPIO and number of pixels > np = neopixel.NeoPixel(machine.Pin(4), 8) # Set a Pixel color in RGB format > np[0] = (255, 0, 0) >np.write() @iAyanPahwa/iayanpahwa
  33. 33. Thank You @iAyanPahwa /iayanpahwa

×