How to use Raspberry USB RP2040
I recently bought a Raspberry Pi USB RP2040.
This is just a small post to explain how to use it with Python (especially with CircuitPython).
When you plug it into your computer, it appears as a USB storage device named RPI-RP2.
On the CircuitPython website, you can download the latest version of CircuitPython for the Raspberry Pi RP2040 here.
Once downloaded, simply copy and paste the .uf2 file into the RPI-RP2 device. The device will reboot and appear under the name CIRCUITPY.
The main script must be named code.py, and this is where you should place your code.
A small example to open the CMD and run a command.
To do this, you need to use the “keyboard” library. You can download the library here.
-
Download the “bundle” (the pack) that matches your version. Look for the link for Version 10.x. Choose the file ending with mpy-…zip.
-
Unzip this file on your computer.
-
Open the folder you just unzipped and go to the lib subfolder it contains.
-
Look for the folder named adafruit_hid and copy it.
-
Paste this adafruit_hid folder inside the lib folder you created on your CIRCUITPY drive.
Here is an example of code to open CMD and run a command (in this case, “ipconfig”):
import time
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
time.sleep(2)
kbd.press(Keycode.WINDOWS, Keycode.R)
kbd.release_all()
time.sleep(0.5)
layout.write('cmd\n') # if the keyboard is set to French, replace with 'c;d\n'
time.sleep(1)
layout.write('ipconfig\n')And there you go, you can now use your Raspberry Pi USB RP2040 to automate tasks by simulating keyboard strokes!