Try โ€‚โ€‰HackMD

Mini-Tutorial: WokWi MicroPython Simulation

While you are waiting for the Raspberry Pi Pico W (RP2040), you can still practice concepts that we are learning in the course.

Emulating RP2040 with WokWi

Wokwi is an open-source simulator for Arduino, ESP32, STM32, and other microcontroller projects. We will be using the MicroPython simulator for the Raspberry Pi Pico W (RP2040):
https://wokwi.com/projects/new/micropython-pi-pico

Let's look at the pinout diagram for the Raspberry Pi Pico W board:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More โ†’

The physical pin locations are numbered 1 through 40. There are labels at each pin to indicate what kind of communication the pins support.

Connect the 3V3 pin to the top (+) rail. Connect a GND pin to the (-) rail. Connect the GP16 pin to the anode (longer wire) of the LED. Finally, add a resistor to reduce the current to the LED (220 or 330 Ohm, typically).

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More โ†’

Here is the code that you will need:

# Import libraries
from machine import Pin # import Pin definitions
import time # import timer library

# define GP16 as output pin
redLED = Pin(16, Pin.OUT)

# start loop
while True:    
    redLED.on() # turn on red LED
    time.sleep(0.3) # wait 0.3 seconds
    redLED.off() # turn off red LED
    time.sleep(0.8) # wait 0.8 second

If everything is wired correctly, you can start the simulation!

Completed tutorial here:
https://wokwi.com/projects/400021799366179841

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’
Note: You will not be able to access your home Wi-Fi network from the emulator.
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’
Note: Not all sensors are available for simulation in WokWi, such as the DHT11.
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More โ†’
Warning: The simulator may not have the same pin layout as your physical devices. Always refer to the manufacturer datasheet!

About WokWi

Wokwi is an open-source simulator for Arduino, ESP32, STM32, and other microcontroller projects. It typically supports Arduino code (C/C++), but we are using an experimental feature which supports MicroPython with the Raspberry Pi Pico W (RP2040).

  1. Create a sketch by selecting a template.
  2. Add the breadboard, sensors, actuators, and connect with wires.
  3. Write the relevant code.
  4. Click Run to simulate the real-time behavior.