Hack star
Published © GPL3+

Learn to Drive 8 LEDs on Raspberry Pi Pico Simulator - 2022

Learn to Drive 8 LEDs with 1 line Code on Raspberry Pi Pico. You can change the code and play with the Raspberry Pi Pico simulator.

BeginnerProtip1 hour1,260
Learn to Drive 8 LEDs on Raspberry Pi Pico Simulator - 2022

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
LED
DIYables LED
×1
Resistor
DIYables Resistor
×1
Jumper Wires
DIYables Jumper Wires
×1
Breadboard
DIYables Breadboard
×1
Starter Kit
DIYables Starter Kit
Alternatively
×1

Software apps and online services

Wokwi Pi Pico Simulator

Story

Read more

Schematics

8 LEDs and Raspberry Pi Pico

Code

Code for driving the 8 LEDs using Raspberry Pi Pico

Arduino
/**  
 * 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 < 8; i++) {
    enable_sio(i);
  }
  
  // Enable output on pins GP0 to GP7:
  // sio_hw->gpio_oe points to 0xd0000020 (GPIO_OE)
  sio_hw->gpio_oe = 0b11111111;

  // Set initial pin pattern
  // sio_hw->gpio_out points to 0xd0000010 (GPIO_OUT)
  sio_hw->gpio_out = 0b10101010;
}

void loop() {
  // sio_hw->gpio_togl points to 0xd000001c (GPIO_OUT_XOR)
  sio_hw->gpio_togl = 0b11111111;
  delay(1000);
}

Credits

Hack star

Hack star

75 projects • 99 followers
an Arduino enthusiast and an electronic hobbyist

Comments