- Notifications
You must be signed in to change notification settings - Fork54
A Raspberry Pi Pico Emulator in JavaScript
License
wokwi/rp2040js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Raspberry Pi Pico Emulator for theWokwi Simulation Platform. It blinks, runs Arduino code, and even the MicroPython REPL!
If you are just looking to play around with the Raspberry Pi Pico Simulator, check out the Wokwi Simulator:
For more information, take a look at thewokwi-pi-pico docs and thePi Pico MicroPython Guide.
If you want to develop your own application using the Raspberry Pi Pico simulator, the following examples may be helpful:
- Blink LEDs with RP2040js, from scratch - Press "Run" and patiently wait for the code to compile ;-)
You'd need to gethello_uart.hex
by building it from thepico-examples repo, then copy it to the rp2040js root directory and run:
npm installnpm start
You can also specify the path to the image on the command line and/or load an UF2 image:
npm run start -- --image ./my-pico-project.uf2
A GDB server will be available on port 3333, and the data written to UART0 will be printedto the console.
To run the MicroPython demo, first downloadRPI_PICO-20230426-v1.20.0.uf2, place it in the rp2040js root directory, then run:
npm installnpm run start:micropython
and enjoy the MicroPython REPL! Quit the REPL with Ctrl+X. A different MicroPython UF2 image can be loaded by supplying the--image
option:
npm run start:micropython -- --image=my_image.uf2
A GDB server on port 3333 can be enabled by specifying the--gdb
flag:
npm run start:micropython -- --gdb
For using the MicroPython demo code in tests, the--expect-text
can come handy: it will look for the given text in the serial output and exit with code 0 if found, or 1 if not found. You can find an example inthe MicroPython CI test.
With MicroPython, you can use the filesystem on the Pico. This becomes useful as more than one script file is used in your code. Just put aLittleFS formatted filesystem image calledlittlefs.img
into the rp2040js root directory, and yourmain.py
will be automatically started from there.
A simple way to create a suitable LittleFS image containing your script files is outlined increate_littlefs_image.py.So, usinglittlefs-python, you can do the following:
fromlittlefsimportLittleFSfiles= ['your.py','files.py','here.py','main.py']output_image='output/littlefs.img'# symlinked/copied to rp2040js root directorylfs=LittleFS(block_size=4096,block_count=352,prog_size=256)forfilenameinfiles:withopen(filename,'rb')assrc_file,lfs.open(filename,'w')aslfs_file:lfs_file.write(src_file.read())withopen(output_image,'wb')asfh:fh.write(lfs.context.buffer)
Other ways of creating LittleFS images can be foundhere orhere.
Currently, the filesystem is not writeable, as the SSI peripheral required for flash writing is not implemented yet. If you're interested in hacking, see the discussion in#88 for a workaround.
To run the CircuitPython demo, you can follow the directions above for MicroPython, except downloadadafruit-circuitpython-raspberry_pi_pico-en_US-8.0.2.uf2 instead of the MicroPython UF2 file. Place it in the rp2040js root directory, then run:
npm installnpm run start:circuitpython
and start the CircuitPython REPL! The rest of the experience is the same as the MicroPython demo (Ctrl+X to exit, using the--image
and--gdb
options, etc).
For CircuitPython, you can create a FAT12 filesystem in Linux using thetruncate
andmkfs.vfat
utilities:
truncate fat12.img -s 1M# make the image filemkfs.vfat -F12 -S512 fat12.img# create the FAT12 filesystem
You can then mount the filesystem image and add files to it:
mkdir fat12# create the mounting folder if neededsudo mount -o loop fat12.img fat12/# mount the filesystem to the foldersudo cp code.py fat12/# copy code.py to the filesystemsudo umount fat12/# unmount the filesystem
While CircuitPython does not typically use a writeable filesystem, note that this functionality is unavailable (see MicroPython filesystemsupport section for more details).
Released under the MIT licence. Copyright (c) 2021-2023, Uri Shaked.
About
A Raspberry Pi Pico Emulator in JavaScript
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.