npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rp2040js

v1.0.1

Published

Raspberry Pi Pico (RP2040) Emulator

Downloads

526

Readme

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 RPI_PICO-20230426-v1.20.0.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. 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 in the MicroPython CI test.

Filesystem support

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 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 https://github.com/wokwi/rp2040js/issues/88 for a workaround.

CircuitPython code

To run the CircuitPython demo, you can follow the directions above for MicroPython, except download adafruit-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 install
npm 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).

Filesystem support

For CircuitPython, you can create a FAT12 filesystem in Linux using the truncate and mkfs.vfat utilities:

truncate fat12.img -s 1M  # make the image file
mkfs.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 needed
sudo mount -o loop fat12.img fat12/  # mount the filesystem to the folder
sudo cp code.py fat12/  # copy code.py to the filesystem
sudo umount fat12/  # unmount the filesystem

While CircuitPython does not typically use a writeable filesystem, note that this functionality is unavailable (see MicroPython filesystem support section for more details).

Learn more

License

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