HIDE NAV

Lab 1 - Multi-Blink

Practice three ways to generate square waves



Summary

Create a classic 'hello world' LED blinker, then change it to run using PWM & Alarms.
Demonstrate control multiple LEDs blinking at different rates.

1. Basic wiring & wiring verification
  - create a pico project: blink-cpu-timed
  - wire 2-4 exteral leds
  - ensure all gpios output independant signals using gpio_put()

2.  PWM Muli-Blink
  -create a pico project: blink-pwm-timed
  - use same wiring
  - setup all gpio pins (including 25/built-in) as PWM
  - alternate - use a dimmer

3.  Alarm Multi-Blink
  - create a pico project: blink-alarm-timed
  - use same wiring
  - setup all gpio pins (including 25/built-in) as gpio
  - setup an one or more alarms to toggle the pins at different rates



Required Equipment and Supplies

- Rasperry Pi Pico with Headers - pinout diagram

- LED - indicator [x2-4]

- 820Ω Resistor [x2-4]

- USB Micro Cable

- Breadboard

- Cables and 22ga wire as needed



Wiring

- Only begin adding external LEDs after your basic blink and alarm blink are working.

- LEDs consume very little power, you may power everything from the USB cable.

- Use VBus or Vsys to supply your breadboard power rail from the Pi Pico.

- Connect each LED to separate GPIO pin and in series with a current limiting resistor connected to ground like the example below.

Part 1 - CPU Timed Blink


Part 1 - Sample Code - CPU Timed Blink


#include "pico/stdlib.h"
#define LED_ONB 25

int main() {
// setup and  initialize
gpio_init(LED_ONB);
gpio_set_dir(25, GPIO_OUT);

// primary loop
	while (true) {
		gpio_put(LED_ONB, 1);
		sleep_ms(500);
		gpio_put(LED_ONB, 0);
		sleep_ms(500);
	}
}

Part 2 - PWM Timed Blink



PWM Period Timing Formula


PWM Duty Cycle Formula


PWM Pulse Width Timing Formula