====== Lab 01 ====== ===== Exercise Objectives ===== * Installation of necessary SW * Introduce MicroPython Environment * First program ===== Micropython on Raspberry Pi Pico W ===== https://micropython.org/download/rp2-pico-w/ https://thonny.org/ https://github.com/cpwood/Pico-Go https://docs.micropython.org/en/v1.9.3/pyboard/ ====== First code ====== In Thonny command line and write there from machine import Pin This will import functionality will import class [[https://docs.micropython.org/en/latest/library/machine.Pin.html|Pin]] necessary to control GPIO pins. Intenal LED is connected to pin with symbolic name 'LED', so we can create objected to control this pin. Second parameter of the object constructor of direction of communication. led = Pin('LED', Pin.OUT) If the object exists, try following: pin.on() Other commands: led.off(), led.toggle() ====== Blinking using delay ====== This version of program uses [[https://docs.micropython.org/en/latest/library/time.html#time.sleep_ms|sleep_ms()]]. Create script called **main.py** and save it to the RPi Pico. If the name of the script is as mentioned, code will be executed after restart. from machine import Pin import time led = Pin('LED', Pin.OUT) while True: time.sleep_ms(1000) led.toggle() ====== Blinking using timer ====== More advanced program uses [[https://docs.micropython.org/en/latest/library/machine.Timer.html|Timer]]. from machine import Pin, Timer led = Pin('LED', Pin.OUT) timer = Timer() def blink(timer): led.toggle() timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)