This project was first covered here.
Connect the host to the Pico using a USB data lead. Some USB leads only supply power. They will not work.
The blinker.py
script runs on the Pico, but you should rename it to main.py.
Install it on the Pico using the Thonny editor.
- Open the gist on GitHub.
- Copy the code to your clipboard.
- Open Thonny and make sure it has connected to the Pico.
- Paste the code into the Thonny editor window.
- Save it on the Pico as main.py.
- Close the Thonny editor!
If you leave the Thonny editor open it will keep the serial port open on the host, and the serial program below will not work!
Since you saved the program as main.py it will run on the Pico automatically.
The talker.py
script runs on the Raspberry Pi. It uses PySerial to send commands from the host to the
Pico and read the result.
To use it
- Run pip3 install pyserial.
- Copy talker.py into a directory of your choice.
- In that directory, run python3 to start an interactive session.
- Type
from talker import Talker
- Type
t = Talker()
If you are running on Windows, you will need to typet = Talker('COM6')
replacing COM6 by whatever port the Pico is connected to. - Type
t.send('2 + 2')
- Type
t.receive()
- if all is well, this will print the result 4. - Type
t.send('on()'
- the on-board LED on the Pico should turn on. - Type
t.send('off()'
- the on-board LED on the Pico should turn off. - When you have finished,
type t.close()
.