### Serial Monitor Setup Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-pi-pico.md Example code to ensure the setup waits for the Serial Monitor connection before printing messages. ```cpp void setup() { Serial.begin(115200); while (!Serial) { delay(10); // wait for serial port to connect. Needed for native USB } // Now you can safely print message: Serial.println("Hello, Serial Monitor!"); } ``` -------------------------------- ### Wokwi CLI command example Source: https://github.com/wokwi/wokwi-docs/blob/main/style-guide.md Example showing the correct way to reference the Wokwi CLI command, without prompt marks. ```bash wokwi-cli ``` -------------------------------- ### Sample libraries.txt file Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/guides/libraries.md Example of a libraries.txt file showing how to install libraries, including specific versions. ```text # Sample libraries.txt file: Servo FastLED # Install a specific version of a library: MySensors@2.3.0 ``` -------------------------------- ### Install library Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/vscode/vscode-micropython.md Example command to install the ssd1306 library using mpremote. ```bash mpremote connect port:rfc2217://localhost:4000 mip install ssd1306 ``` -------------------------------- ### ESP-IDF support example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/vscode/project-config.md Example configuration for ESP-IDF apps using flasher_args.json. ```toml [wokwi] version = 1 firmware = 'build/flasher_args.json' elf = 'build/example_app.elf' ``` -------------------------------- ### Wire Placement Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/diagram-format.md An example of the wire placement mini-language instructions. ```json ["v10", "h5", "*", "v-15", "h10"] ``` -------------------------------- ### Install Dependencies Source: https://github.com/wokwi/wokwi-docs/blob/main/README.md Installs the necessary dependencies for local development using npm. ```bash npm install ``` -------------------------------- ### Start Local Development Server Source: https://github.com/wokwi/wokwi-docs/blob/main/README.md Starts the local development server for the wokwi-docs project. Changes are reflected live. ```bash npm start ``` -------------------------------- ### Color Examples Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-led-bar-graph.md Examples demonstrating different color attributes for the LED bar graph. ```html ``` ```html ``` ```html ``` ```html ``` -------------------------------- ### Example requirements.txt Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/guides/circuitpython.md An example of a 'requirements.txt' file used to specify Adafruit CircuitPython libraries for a Wokwi project. Wokwi automatically downloads and installs these libraries. ```text # requirements.txt example adafruit_display_text adafruit_dht ``` -------------------------------- ### Wokwi configuration example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/guides/custom-chips-to-wasm.md An example excerpt from wokwi.toml showing how to configure a custom chip. ```toml [[chip]] name = 'inverter' # To use the chip in diagram.json, add a part with "chip-inverter" type. binary = 'chips/inverter.chip.wasm' ``` -------------------------------- ### Starting GDB Session Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/gdb-debugging.md Example of initiating a GDB session and setting a temporary breakpoint. ```gdb (gdb) tbreak setup Temporary breakpoint 1 at 0x2ca: file sketch.ino, line 28. (gdb) c Continuing. Temporary breakpoint 1, setup () at sketch.ino:28 28 pinMode(LED_BUILTIN, OUTPUT); (gdb) ``` -------------------------------- ### Arduino code example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-tv.md A simple example that draws a circle using the TVout library. ```cpp // Connect SYNC to Arduino pin 9, IN to Arduino pin 7 #include TVout TV; void setup() { TV.begin(PAL, 120, 96); TV.clear_screen(); TV.draw_circle(60, 48, 32, WHITE); } void loop() { } ``` -------------------------------- ### Arduino code example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-led-ring.md Example code for controlling the wokwi-led-ring with an Arduino. ```cpp #include #define RING_PIN 2 #define NUM_PIXELS 16 Adafruit_NeoPixel ring(NUM_PIXELS, RING_PIN, NEO_GRB + NEO_KHZ800); void setup() { ring.begin(); for (int i = 0; i < NUM_PIXELS; i++) { ring.setPixelColor(i, ring.Color(0, 150, 0)); // Green } ring.show(); } void loop() { delay(10); } ``` -------------------------------- ### Arduino code example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-membrane-keypad.md Example code demonstrating how to use the Keypad library with the wokwi-membrane-keypad component. ```cpp #include const uint8_t ROWS = 4; const uint8_t COLS = 4; char keys[ROWS][COLS] = { { '1', '2', '3', 'A' }, { '4', '5', '6', 'B' }, { '7', '8', '9', 'C' }, { '*', '0', '#', 'D' } }; uint8_t colPins[COLS] = { 5, 4, 3, 2 }; // Pins connected to C1, C2, C3, C4 uint8_t rowPins[ROWS] = { 9, 8, 7, 6 }; // Pins connected to R1, R2, R3, R4 Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); void setup() { Serial.begin(9600); } void loop() { char key = keypad.getKey(); if (key != NO_KEY) { Serial.println(key); } } ``` -------------------------------- ### Arduino code example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-led-strip.md Example code for controlling a NeoPixel LED strip with an Arduino. ```cpp #include #define STRIP_PIN 2 #define NUM_PIXELS 8 Adafruit_NeoPixel strip(NUM_PIXELS, STRIP_PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); for (int i = 0; i < NUM_PIXELS; i++) { strip.setPixelColor(i, strip.Color(150, 0, 0)); // Red } strip.show(); } void loop() { delay(10); } ``` -------------------------------- ### Take Screenshot Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Example usage of the 'take-screenshot' step to compare a component's screenshot with a reference. ```yaml take-screenshot: part-id: 'oled1' compare-with: 'screenshots/oled-1.png' ``` -------------------------------- ### Coordinate Mapping Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Example C++ code demonstrating how to map touch controller coordinates to display coordinates. ```cpp TS_Point p = ts.getPoint(); // Flip to match display coordinates p.x = map(p.x, 0, 240, 240, 0); p.y = map(p.y, 0, 320, 320, 0); ``` -------------------------------- ### Touch Move Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Example usage of the touch-move command to simulate a drag event. ```yaml touch-move: part-id: esp32s3box x: 150 y: 200 ``` -------------------------------- ### Touch Release Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Example usage of the touch-release command to simulate releasing a touch. ```yaml touch-release: part-id: esp32s3box ``` -------------------------------- ### Touch Step Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Example usage of the 'touch' step to simulate a touch tap on a touchscreen part. ```yaml touch: part-id: esp32s3box x: 120 y: 160 duration: 100ms ``` -------------------------------- ### Arduino code example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-led-matrix.md Example Arduino code for controlling the LED matrix using the Adafruit NeoPixel library. ```cpp #include #define MATRIX_PIN 2 #define ROWS 8 #define COLS 8 #define NUM_PIXELS (ROWS * COLS) Adafruit_NeoPixel matrix(NUM_PIXELS, MATRIX_PIN, NEO_GRB + NEO_KHZ800); void setup() { matrix.begin(); for (int i = 0; i < NUM_PIXELS; i++) { matrix.setPixelColor(i, matrix.Color(0, 0, 150)); // Blue } matrix.show(); } void loop() { delay(10); } ``` -------------------------------- ### Custom Character Animation Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-lcd1602.md This example shows how to animate a custom character by modifying it line-by-line in the loop function. ```cpp void loop() { uint8_t heart2[8] = {0}; for (int i = 0; i < 8; i++) { heart2[i] = heart[i]; lcd.createChar(3, heart2); delay(100); } delay(500); } ``` -------------------------------- ### Customizing Channel Names Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/guides/logic-analyzer.md Example of how to set custom channel names for the logic analyzer in Wokwi. ```json { "type": "wokwi-logic-analyzer", "id": "logic1", "attrs": { "channelNames": "SCL,SDA,RST" } } ``` -------------------------------- ### Install ESP-IDF Wokwi extension Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/cli-installation.md Installs the ESP-IDF extension for Wokwi CLI. ```bash pip install idf-wokwi ``` -------------------------------- ### Basic wokwi.toml Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/vscode/project-config.md A basic wokwi.toml file configuration. ```toml [wokwi] version = 1 firmware = 'path-to-your-firmware.hex' elf = 'path-to-your-firmware.elf' ``` -------------------------------- ### Install Wokwi CLI on Windows Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/cli-installation.md Installs the Wokwi CLI using a PowerShell command. ```powershell iwr https://wokwi.com/ci/install.ps1 -useb | iex ``` -------------------------------- ### Custom Chip Configuration Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/vscode/project-config.md Example of how to load a custom chip from a WASM binary into your wokwi.toml configuration. ```toml [[chip]] name = 'inverter' # To use the chip in diagram.json, add a part with "chip-inverter" type. binary = 'chips/inverter.chip.wasm' ``` -------------------------------- ### Install Wokwi CLI on Linux/macOS Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/cli-installation.md Installs the Wokwi CLI using a curl command. ```bash curl -L https://wokwi.com/ci/install.sh | sh ``` -------------------------------- ### Arduino code example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-neopixel.md Example code for controlling a NeoPixel with an Arduino. ```cpp #include #define LED_PIN 6 Adafruit_NeoPixel pixel(1, LED_PIN, NEO_GRB + NEO_KHZ800); void setup() { pixel.begin(); pixel.setPixelColor(0, pixel.Color(150, 0, 0)); // Red pixel.show(); } void loop() { delay(100); } ``` -------------------------------- ### Build Firmware Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Command to build the microcontroller firmware using PlatformIO. ```bash pio run ``` -------------------------------- ### UART Initialization and Callbacks Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/chips-api/uart.md Example demonstrating how to initialize a UART device with configuration, including RX/TX pins, baud rate, and callback functions for receiving data and transmission completion. ```cpp static void on_uart_rx_data(void *user_data, uint8_t byte) { // `byte` is the byte received on the "RX" pin } static uint8_t on_uart_write_done(void *user_data) { // You can write the chunk of data to transmit here (by calling uart_write). } // ... const uart_config_t uart1 = { .tx = pin_init("TX", INPUT_PULLUP), .rx = pin_init("RX", INPUT), .baud_rate = 115200, .rx_data = on_uart_rx_data, .write_done = on_uart_write_done, .user_data = chip, }; ``` -------------------------------- ### Resistor Examples with Values Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-resistor.md Examples demonstrating different resistance values for the wokwi-resistor component. ```html ``` ```html ``` ```html ``` -------------------------------- ### Python Serial Connection Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/vscode/project-config.md Connecting to the serial port using PySerial's RFC2217 support. ```python import serial ser = serial.serial_for_url('rfc2217://localhost:4000', baudrate=115200) ser.write(b'hello') ``` -------------------------------- ### Initialize Wokwi Project Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/cli-usage.md Initializes your project for Wokwi by generating wokwi.toml and diagram.json files. ```bash wokwi-cli init ``` -------------------------------- ### Part Definition Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/diagram-format.md Example of how to define a red LED called "led1" at position (x=100, y=50). ```json { "id": "led1", "type": "wokwi-led", "left": 100, "top": 50, "attrs": { "color": "red" } } ``` -------------------------------- ### Simulation Output Example Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/wokwi-ci/automation-scenarios.md Example output from a successful Wokwi CLI simulation run. ```text Wokwi CLI v0.18.3 (786fa8e49d9c) Connected to Wokwi Simulation API 1.0.0-20251028-g60747fe2 Starting simulation... ets Jul 29 2019 12:21:46 [DHT22 Sensor Test (ESP32)] Expected text matched: "ets Jul 29 2019 12:21:46" rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:1156 load:0x40078000,len:11456 ho 0 tail 12 room 4 load:0x40080400,len:2972 entry 0x400805dc DHT22 test! [DHT22 Sensor Test (ESP32)] Expected text matched: "DHT22 test!" Humidity: 45.80% Temperature: 23.50°C [DHT22 Sensor Test (ESP32)] Expected text matched: "Humidity: 45.80% Temperature: 23.50°C" Humidity: 45.80% Temperature: 23.50°C [DHT22 Sensor Test (ESP32)] Expected text matched: "Humidity: 45.80% Temperature: 23.50°C" Humidity: 66.90% Temperature: 21.50°C [DHT22 Sensor Test (ESP32)] Expected text matched: "Humidity: 66.90% Temperature: 21.50°C" [DHT22 Sensor Test (ESP32)] Scenario completed successfully ``` -------------------------------- ### Simulating a button press Source: https://github.com/wokwi/wokwi-docs/blob/main/docs/parts/wokwi-pushbutton.md This example demonstrates how to simulate a button press on 'btn1' for 200ms using automation scenarios. ```yaml - set-control: part-id: btn1 control: pressed value: 1 - delay: 200ms - set-control: part-id: btn1 control: pressed value: 0 ```