Use the REPL
Objective
- Use the REPL (Read-Evaluate-Print-Loop)
Use REPL
The REPL means Read-Evaluate-Print-Loop, this feature helps you to interact with the serial console that means you can program the Raspberry Pi Pico to measure “Somethin” like temperature and print it on the REPL. In The Mu Python editor, you can find it with the icon and label Serial
For more information, you can follow these web links.
- https://learn.adafruit.com/welcome-to-circuitpython/interacting-with-the-serial-console
- https://learn.adafruit.com/welcome-to-circuitpython/the-repl
Press Ctrl+c to enter REPL
If you are running the last code (blinking led), once you connect your board to Mu editor you will open the Serial then you will press CTRL + C to open the REPL. Here you will se the following statement:
Code done running.
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 7.0.0 on 2021-09-20; Raspberry Pi Pico with rp2040
>>>
The REPL will tell you the CircuitPython version (7.0.0) and your board (Raspberry Pi Pico with rp2040). Now you can interact introducin Python Code directly to the REPL (Terminal). The first command we are going to use is help()
>>> help()
Welcome to Adafruit CircuitPython 7.0.0!
Please visit learn.adafruit.com/category/circuitpython for project guides.
To list built-in modules please do `help("modules")`.
The response recommends to explore the buil-in modules of our board by executing the command help(“modules”) . Let’s see what happens.
>>> help("modules")
__main__ bitops microcontroller storage
_bleio board micropython struct
_eve builtins msgpack supervisor
adafruit_bus_device busio neopixel_write synthio
adafruit_pixelbuf collections onewireio sys
aesio countio os terminalio
alarm digitalio pulseio time
analogio displayio pwmio touchio
array errno qrio traceback
atexit fontio rainbowio ulab
audiobusio framebufferio random usb_cdc
audiocore gc re usb_hid
audiomixer getpass rgbmatrix usb_midi
audiomp3 imagecapture rotaryio vectorio
audiopwmio io rp2pio watchdog
binascii json rtc
bitbangio keypad sdcardio
bitmaptools math sharpdisplay
Plus any modules on the filesystem
>>>
These modules are built-in the board, these are the feature we can use without adding any other library. This can make us think if we are using other sensor or devices we will require to add some external libraries. However, for the moment we will work with the internal modules to explore the potential of the Raspberry Pi Pico + Mu Editor + REPL + Internal Temperature sensor.
import board
Try to import a module in this case use the command import board. After doing enter the command is execuated and you will see that nothing happens. However we have not seen any error too. Now try to execute the command dir(board) to explore all the components (pins) of the board that we can use right now.
>>> import board
>>> dir(board)
['__class__', '__name__', 'A0', 'A1', 'A2', 'A3', 'GP0', 'GP1', 'GP10', 'GP11', 'GP12', 'GP13', 'GP14', 'GP15', 'GP16', 'GP17', 'GP18', 'GP19', 'GP2', 'GP20', 'GP21', 'GP22', 'GP23', 'GP24', 'GP25', 'GP26', 'GP26_A0', 'GP27', 'GP27_A1', 'GP28', 'GP28_A2', 'GP3', 'GP4', 'GP5', 'GP6', 'GP7', 'GP8', 'GP9', 'LED', 'SMPS_MODE', 'VBUS_SENSE', 'VOLTAGE_MONITOR', 'board_id']
>>>
Those are the list of name of pins we can use from the Raspberry Pi Pico. Look at the end of the list you will find a pin called LED. Now you can check those name with the following image Raspberry Pi Pico Pinout.
Return to serial console
To return to the serial console just press CTRL+D and you will see again the blinking led program. As you can see when you enter to REPL the program of the Raspberry Pi Pico is paused. In REPL mode you can interact directly with your board.