BrianPugh / rp2040js

A Raspberry Pi Pico Emulator in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rp2040js

Raspberry Pi Pico Emulator for the Wokwi Simulation Platform. It blinks, runs Arduino code, and even the MicroPython REPL!

Online examples

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 the wokwi-pi-pico docs and the Pi Pico MicroPython Guide.

If you want to develop your own application using the Raspberry Pi Pico simulator, the following examples may be helpful:

Run the demo project

Native code

You'd need to get hello_uart.hex by building it from the pico-examples repo, then copy it to the rp2040js root directory and run:

npm install
npm start

MicroPython code

To run the MicroPython demo, first download rp2-pico-20210902-v1.17.uf2, place it in the rp2040js root directory, then run:

npm install
npm run start:micropython

and enjoy the MicroPython REPL! Quit the REPL with Ctrl+X.

You can replace rp2-pico-20210902-v1.17.uf2 with any recent MicroPython or CircuitPython release built for the RP2040.

With MicroPython – and probably also CircuitPython – you can use the filesystem on the Pico. This becomes useful as more than one script file is used in your code. Just put a LittleFS formatted filesystem image called littlefs.img into the rp2040js root directory, and your main.py will be automatically started from there.

A simple way to create a suitable LittleFS image containing your script files is outlined in create_littlefs_image.py. So, using littlefs-python, you can do the following:

from littlefs import LittleFS
files = ['your.py', 'files.py', 'here.py', 'main.py']
output_image = 'output/littlefs.img'  # symlinked/copied to rp2040js root directory
lfs = LittleFS(block_size=4096, block_count=352, prog_size=256)
for filename in files:
    with open(filename, 'rb') as src_file, lfs.open(filename, 'w') as lfs_file:
        lfs_file.write(src_file.read())
with open(output_image, 'wb') as fh:
    fh.write(lfs.context.buffer)

Other ways of creating LittleFS images can be found here or here.

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 wokwi#88 for a workaround.

Learn more

License

Released under the MIT licence. Copyright (c) 2021, Uri Shaked.

About

A Raspberry Pi Pico Emulator in JavaScript

License:MIT License


Languages

Language:TypeScript 99.9%Language:JavaScript 0.1%Language:Shell 0.0%