Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Raspberry Pi Pico Emulator in JavaScript

License

NotificationsYou must be signed in to change notification settings

wokwi/rp2040js

Repository files navigation

rp2040js

Raspberry Pi Pico Emulator for theWokwi 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 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:

Run the demo project

Native code

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.

MicroPython code

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.

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 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.

CircuitPython code

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).

Filesystem support

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).

Learn more

License

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


[8]ページ先頭

©2009-2025 Movatter.jp