For a project I had to exchange data between my computer and a MicroPython microcontroller via USB connection. There are many examples for receiving data from the microcontroller, but only a few examples for sending data from the computer to the microcontroller.
For this reason I wrote a Python and Node.js program myself, which exchanges data with a Raspberry Pi Pico and lights up the microcontroller's built-in LED.
Thus, data can be exchanged between on the PC with Python or Node.js and on the microcontroller with MicroPython or CircuitPython.
MicroPython:
- Node.js <----> MicroPython
- Python <----> MicroPython
CircuitPython:
- Node.js <----> CircuitPython
- Python <----> CircuitPython
Load the script from the MicroPython folder to a microcontroller running MicroPython or if you want to use CircuitPython then load the script from the CircuitPython folder on a microcontroller with CircuitPython.
I have developed the script with a Raspberry Pi Pico. But it is also compatible for other MicroPython / CircuitPython compatible controllers. You may have to change the LED pin number.
Sending and receiving data between a Node.js application and a MicroPython or CircuitPython microcontroller.
- Install Node.js
- Clone the repo
git clone https://github.com/chrissreichl/PC_to_MicroPython_via_USB.git
- Install serialport package
npm i serialport
- Connect the microcontroller via USB to your computer.
- Search the COM port number of the microcontroller in your device manager.
- Adjust the COM port number in the
main.js
sample script if necessary. - Start the
main.js
script in your terminalnode main.js
Now the LED of the microcontroller should light up for 2 seconds and you should see an output in the terminal. Congratulations, you have successfully sent commands via USB to the MicroPython/CircuitPython microcontroller!
Sending and receiving data between a Python application and a MicroPython or CircuitPython microcontroller
- Install Python
- Clone the repo
git clone https://github.com/chrissreichl/PC_to_MicroPython_via_USB.git
- Install pyserial
pip install pyserial
- Connect the microcontroller via USB to your computer.
- Search the COM port number of the microcontroller in your device manager.
- Adjust the COM port number in the
main.py
sample script if necessary. - Start the
main.py
script in your terminalpython main.py
Now the LED of the microcontroller should light up for 2 seconds and you should see an output in the terminal. Congratulations, you have successfully sent commands via USB to the MicroPython/CircuitPython microcontroller!
Distributed under the MIT License. See LICENSE.txt
for more information.