• Stars
    star
    399
  • Rank 108,077 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Raspberry Pi Pico Emulator in JavaScript

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

More Repositories

1

avr8js

Arduino (8-bit AVR) simulator, written in JavaScript and runs in the browser / Node.js
TypeScript
482
star
2

easyeda2kicad

Convert EasyEDA designs to KiCad EDA
TypeScript
288
star
3

kicad-jlcpcb-bom-plugin

Export a JLCPCB Compatible BOM directly from your KiCad schematic
Python
189
star
4

wokwi-elements

Web Components for Electronics and IoT Parts
TypeScript
185
star
5

wokwi-docs

Documentation for the Wokwi Simulator
JavaScript
128
star
6

siliwiz

Silicon Layout Wizard
JavaScript
120
star
7

wokwi-features

Wokwi Feature requests & Bug Reports
72
star
8

splendida

256 WS2812B LEDs arranged in Fermat's Spiral Shape
Python
44
star
9

esp8266js

ESP8266 Simulator in JavaScript
TypeScript
37
star
10

good-arduino-code

Frontend for goodarduinocode.com - A curated collection of Arduino coding examples
TypeScript
30
star
11

wokwi-vscode-micropython

MicroPython in Wokwi for VS Code
Python
25
star
12

wokwigw

Wokwi IoT Network Gateway
Go
24
star
13

wokwi-boards

Custom board definitions for wokwi.com
JavaScript
23
star
14

web-gdb

GDB running inside the browser (using v86)
JavaScript
20
star
15

attiny-hvsp-programmer

ATtiny High-voltage Serial Programmer with Chip Erase function
C++
19
star
16

pioasm-wasm

Raspberry Pi Pico pioasm compiled to Web Assembly
JavaScript
17
star
17

wokwi-cli

Wokwi Command Line Interface (for CI use cases)
TypeScript
17
star
18

wokwi-ci-action

Use the Wokwi Embedded Systems Simulator in your CI workflow
15
star
19

esp32-http-server

ESP32 HTTP Server Example for Wokwi
C++
14
star
20

wokwi-playgrounds

Playgrounds for Wokwi.com
C++
12
star
21

rp2040js-circuitpython

CircuitPython Simulator using RP2040js
JavaScript
12
star
22

the-skull

The Skull CTF, A mind-bending hardware puzzle in three acts
12
star
23

esp32-idf-hello-wifi

ESP32 IDF WiFi Example for VSCode + Wokwi
C
12
star
24

wokwi-builders

Project builders for various environments
Dockerfile
12
star
25

wokwi-animator

Arduino OLED Animations tool
TypeScript
11
star
26

uf2

USB Flashing Format (UF2) JavaScript Library
TypeScript
11
star
27

esp32-async-web-server-example

ESP32 Async Web Server Example: Control 2 LEDs from a web page hosted on the ESP32 (simulate with Wokwi for VS Code)
C++
11
star
28

arduino-libraries

Online Playgrounds for popular Arduino libraries
C++
10
star
29

esp-idf-oled-ssd1306

I2C OLED with ESP-IDF and Wokwi Simulation
C
9
star
30

arduino-lcd-helloworld

Arduino + LCD1602 example for Wokwi Visual Studio Code extension
C++
7
star
31

esp32-test-binaries

Precompiled firmware binaries for testing ESP32 chips on Wokwi
Python
7
star
32

wasm-avr-gdb

Web Assembly build of AVR GDB
Dockerfile
7
star
33

esp32c6-hello-world

ESP32-C6 on Wokwi for VS Code
C
6
star
34

esp32c6-i2c-lp

ESP32-C6 LP I2C (Low Power) on Wokwi Example
C
6
star
35

pico-sdk-blink

Pico SDK Blink with Wokwi Simulation
CMake
6
star
36

esp32p4-hello-world

ESP32-P4 on Wokwi for VS Code (preview)
C
6
star
37

arduino-simon-game

Simon Game for Arduino with Score Display + Wokwi Simulation
C++
5
star
38

inverter-chip

Inverter Chip for Wokwi
C
5
star
39

esp32-ntp-clock

ESP32 NTP Clock Example (using Platform IO)
C++
5
star
40

avr8js-research

AVR8js Performance Research
TypeScript
5
star
41

skullfet

Skull shaped MOSFET cells for the Efabless's 130nm process
Python
4
star
42

hdl-parser

Parser for nand2tetris HDL (Hardware Description Language), written in JavaScript
JavaScript
4
star
43

wokwi_chip_ll

Wokwi Custom Chip API in Rust
Rust
4
star
44

TinyDebug

ATtiny85 Serial-like debug interface for the Wokwi.com simulator
C++
4
star
45

wokwi-gdbserver

Debug Arduino/ESP32 Code running in the Wokwi Simulator using GDB
JavaScript
4
star
46

rust_chip_inverter

Inverter Custom Chip example in Rust
Rust
4
star
47

led-2d-spiral

2D LED Spiral for Wokwi AVR Simulator
JavaScript
4
star
48

esp32-arduino-debug

Docker container for source-level debugging of ESP32 Arduino applications (using xtensa-GDB)
Dockerfile
4
star
49

wokwi-circuitpython-libraries

CircuitPython libraries, packed for use in Wokwi
JavaScript
4
star
50

firmware-assets

Firmware Assets
3
star
51

web-avr-gdb

avr-gdb running in a web-browser
JavaScript
3
star
52

openroad-docker

OpenROAD docker image (with GUI enabled)
Dockerfile
3
star
53

wrapped_skullfet

Skull MOSFET, wrapped for Caravel
Verilog
3
star
54

wokwi-embed-bridge-example

Example for using Wokwi together with Platform.io (Prototype)
Python
3
star
55

esp-idf-hello-world

ESP IDF Hello World, precompiled for ESP32 and configured for Wokwi
3
star
56

esp32p4-mipi-dsi-panel-demo

Precompiled ESP32-P4 + MIPI DSI panel example, ready to simulate in Wokwi
3
star
57

led-3d-cube

3D LED Cube for Wokwi AVR Simulator
JavaScript
3
star
58

stm32-hello-wokwi

STM32 Nucleo64 + Wokwi Example (C031C6)
C
2
star
59

chip_framebuffer_example

Wokwi Framebuffer Chip in Rust example
Rust
2
star
60

platform-io-esp32-counter-ci

ESP32 Pushbutton Counter (Platform IO) with Wokwi CI
C++
2
star
61

fastled-monaco

FastLED auto complete + goodies for Monaco Editor
TypeScript
2
star
62

simon-verilog

Simon Says game, written in Verilog and simulated on Wokwi
Verilog
2
star
63

led-3d-spiral

3D LED Spiral for Wokwi AVR Simulator
JavaScript
2
star
64

littlefs-wasm

LittleFS compiled to Web Assembly
JavaScript
2
star
65

wokwi-chip-clang-action

Compiles Custom Chips written in C for the Wokwi Simulator (https://wokwi.com)
Dockerfile
1
star
66

platform-io-esp32-http-client

ESP32 HTTP Client with Wokwi CI example
C++
1
star
67

verispell

SPELL implementation in Verilog
Verilog
1
star
68

astyle-wasm

Artistic Style (AStyle) compiled for Web Assembly
JavaScript
1
star
69

wokwi-TaskScheduler

TaskScheduler challenges and playgrounds
C++
1
star
70

the-skull-xmas

Christmas Firmware for The Skull
C++
1
star
71

wokwi

Wokwi
1
star
72

wokwi-tests

Integration tests for the Wokwi simulation platform
C++
1
star
73

openmpw-docker

Docker container with OpenMPW PDK + tools: yosys, magic, klayout, ngspice, gtkwave, etc
Dockerfile
1
star
74

wokwi-library-index

Index for the Wokwi Library Manager
JavaScript
1
star
75

attiny-hvsp-captures

High-voltage Serial Programming ATtiny85 logic analyzer captures
1
star
76

led-web-socket

LED Web Socket Transmitter (for use with Wokwi.com simulator)
JavaScript
1
star
77

tiny-tapeout-test-simple

7 Segment GDS fun
Verilog
1
star
78

soulmate-streamer

Stream pixel data from Wokwi to Soulmate
HTML
1
star
79

esp32-hello-wokwi-ci

Using Wokwi CLI to the ESP32 projects with GitHub actions
1
star
80

mbedtls-wasm

mbedTLS, compiled for Web Assembly
JavaScript
1
star
81

ngspice-wasm

ngspice compiled into Web Assembly
Shell
1
star
82

wokwi_chips_api

Wokwi Custom Chips API in Rust
Rust
1
star
83

silife

Game of Life, in Silicon
Verilog
1
star
84

embedded-research-workshop-gitpod

Gitpod workspace for Wokwi for Embedded System Security Research workshop
1
star
85

esp32-roms

ESP32 bootrom binaries
JavaScript
1
star