10 LED Patterns on Raspberry Pi Pico Simulator

by sharepksn in Circuits > Raspberry Pi

623 Views, 4 Favorites, 0 Comments

10 LED Patterns on Raspberry Pi Pico Simulator

2021-05-07_16h48_40.png

Learn how to create your LED chaser or LED pattern circuits online using the free Wokwi Raspberry Pi Pico simulator

Introduction to Raspberry Pi Pico


Raspberry Pi Pico is a little, fast, and versatile board built using RP2040, a brand new microcontroller chip devised by Raspberry Pi in the UK. You can have a look at the datasheet of Pico. You will find the getting started guide on Pi Pico here. Below are the features of the RP2040 microcontroller:

  • Dual ARM Cortex-M0+ @ 133MHz
  • 264kB on-chip SRAM in six independent banks
  • Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus
  • DMA controller
  • Fully-connected AHB crossbar
  • Interpolator and integer divider peripherals
  • On-chip programmable LDO to generate core voltage
  • 2 on-chip PLLs to generate USB and core clocks
  • 30 GPIO pins, 4 of which can be used as analogue inputs
  • Peripherals ◦ 2 UARTs ◦ 2 SPI controllers ◦ 2 I2C controllers ◦ 16 PWM channels ◦ USB 1.1 controller and PHY, with host and device support ◦ 8 PIO state machine

​Naming Convention of Raspberry Pi Pico Simulator

2021-05-07_17h02_22.png
2021-05-07_17h03_22.png

Presently the Raspberry Pi Pico simulator supports RP2040 MCU. In the future, there may be new releases in the MCU family.

In the next set, we will look at the code

The project link is here: https://wokwi.com/arduino/projects/297912292682498...

LED Patterns

pattern 1 pico online simulator.gif
pattern 2 pico online simulator.gif
pattern 3 pico online simulator.gif
pattern 4 pico online simulator.gif
2021-05-07_16h48_40.png

Here is the code - you can find the link to the Pico simulation page for wokwi above

/**
Controlling the Pi Pico GPIO with direct register access (SIO registers + IO Bank 0 registers)
   Code example from the Raspberry Pi Pico Deep Pico - The Deep Dive course:
   https://hackaday.io/course/178733-raspberry-pi-pico-and-rp2040-the-deep-dive
*
* Enables the SIO function for the given pin, by writing to the relevant CTRL register.
   (e.g. GPIO0_CTRL at 0x40014004) */
void enable_sio(int pin) {
  uint32_t *PIN_CTRL_REG = (uint32_t*)IO_BANK0_BASE + pin * 2 + 1;
  *PIN_CTRL_REG = 5; // 5 = SIO function
}
void setup() {
  // Enable the SIO function for pins GP0 to GP7
  for (int i = 0; i < 16; i++) {
    enable_sio(i);
  }
  // Enable output on pins GP0 to GP7:
  // sio_hw->gpio_oe points to 0xd0000020 (GPIO_OE)
  sio_hw->gpio_oe = 0b1111111111111111;
  // Set initial pin pattern
  // sio_hw->gpio_out points to 0xd0000010 (GPIO_OUT)
  sio_hw->gpio_out = 0b1010101010101010;
}
void loop() {
#if 0
  //pattern 1
  for (int i = 0; i < 20; i++) {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(420 - 20 * i);
  }
  //pattern 2
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = 65535 >> i;
    delay(300);
  }
  //pattern 3
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = (65535 >> i);
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }
  //pattern 4
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = 1 << i;
    delay(100);
  }
#endif
  //pattern 5
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_out = 32767 >> i;
    delay(100);
  }
  //pattern 6
  sio_hw->gpio_out = 65535;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(200);
  }
  //pattern 7
  sio_hw->gpio_out = 65280;
  for (int i = 0; i < 8; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }
  //pattern 8
  sio_hw->gpio_out = 61680;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }
  //pattern 9
  sio_hw->gpio_out = 52428;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }
  //pattern 10
  sio_hw->gpio_out = 43690;
  for (int i = 0; i < 16; i++)
  {
    sio_hw->gpio_togl = 0b1111111111111111;
    delay(300);
  }
}

Support for Raspberry Pi Pico Simulator

pattern x pico online simulator.gif

You can hop on to the discord channel for any support related to the Raspberry Pi Pico simulator.