Skip to main content
Ctrl+K
ac-microcourses 0.0.post1.dev163+g3c7fea0d3 documentation - Home ac-microcourses 0.0.post1.dev163+g3c7fea0d3 documentation - Home
  • πŸ“œ Autonomous Systems for Discovery
  • πŸ’‘ Course 1: Hello World
    • πŸ—ΊοΈ Overview
    • πŸŽ“ Register
    • 🧩 1.0 Orientation
    • 🧩 1.1 Run the demo
    • 🧩 1.2 Blink and read
    • 🧩 1.3 Bayesian optimization
    • 🧩 1.4 Device communication
    • 🧩 1.5 Database Management
    • 🧩 1.6 Connecting the pieces
  • πŸ“ˆ Course 2: Data Science
    • πŸ—ΊοΈ Overview
    • πŸŽ“ Register
    • 🧩 2.0 Orientation
    • 🧩 2.1 Single-objective
    • 🧩 2.2 Multi-objective
    • 🧩 2.3 Batch Optimization
    • 🧩 2.4 Featurization
    • 🧩 2.5 Multi-task
    • 🧩 2.6 Benchmarking
  • 🦾 Course 3: Robotics
    • πŸ—ΊοΈ Overview
    • πŸŽ“ Register
    • 🧩 3.0 Orientation
    • 🧩 3.1 Pumps and Pipettes
    • 🧩 3.2 Serial communication
    • 🧩 3.3 Liquid Handlers
    • 🧩 3.4 Mobile robotics
    • 🧩 3.5 Computer vision
    • 🧩 3.6 Solid sample transfer
  • πŸ§‘β€πŸ’» Course 4: Software Dev.
    • πŸ—ΊοΈ Overview
    • πŸŽ“ Register
    • 🧩 4.0 Orientation
    • 🧩 4.1 Deep dive into Git and GitHub
    • 🧩 4.2 Setting up VS Code
    • 🧩 4.3 Debugging in VS Code
    • 🧩 4.4 Unit testing
    • 🧩 4.5 Automated docs
    • 🧩 4.6 Continuous integration
    • 🧩 4.7 Project templates
    • 🧩 4.8 Launching a free cloud server
    • 🧩 4.9 On-demand cloud simulations
  • 🏒 Course 5: Design Project
    • πŸ—ΊοΈ Overview
    • πŸŽ“ Waitlist
  • Developer Resources
    • Contributions & Help
    • License
    • Authors
  • Repository
  • Show source
  • Suggest edit
  • Open issue
  • .md

🧩 1.2 Blink and Read

Contents

  • πŸ”° Tutorial
    • Getting Started with the Pico (Optional)
    • Onboard LED
    • Onboard Temperature
    • NeoPixels
    • AS7341 Light Sensor
    • Definitions
    • Additional Resources
  • πŸš€ Quiz
  • πŸ“„ Assignment

🧩 1.2 Blink and Read#

Contents

  • 🧩 1.2 Blink and Read

    • πŸ”° Tutorial

    • πŸš€ Quiz

    • πŸ“„ Assignment

πŸ”° Tutorial#

Learn how to write MicroPython scripts and use a Raspberry Pico W microcontroller to send commands to an RGB LED and read data from a light sensor.

../../_images/green-led.jpg

Flashing the RGB LED on the Maker Pi Pico base with a green color.

Getting Started with the Pico (Optional)#

Read the Getting Started with the Pico tutorial, some which overlaps with prior content. Note that the onboard led for the Pico W is accessed via onboard_led = Pin("LED", Pin.OUT) instead of onboard_led = Pin(25, Pin.OUT), which is for the original Pico. For the β€œUse digital inputs and outputs”, β€œControl LED brightness with PWM”, and β€œControl an LED with an analogue input” sections, you can still run the code without the optional hardware (button, wire-lead LED, resistor, potentiometer, breadboard, M-M jumper leads), though you won’t be able to observe the effect.

Onboard LED#

Note

The onboard LED is distinct from the RGB NeoPixel LED that you will be using later in the module.

The script in this section controls the onboard LED (see black callout below).

Pico W onboard LED with callout

βœ… Copy and paste this code into a new file (e.g., onboard_blink.py) in Thonny and run it to see the onboard LED blink every two seconds.

from time import sleep
from machine import Pin

onboard_led = Pin("LED", Pin.OUT)  # Pico W is slightly different than Pico

while True:
    onboard_led.toggle()
    sleep(2)

Onboard Temperature#

Below is a script for reading the Pico W’s onboard temperature sensor.

βœ… Copy and paste this code into a new file (e.g., onboard_temp.py) in Thonny and run it to see the temperature in degrees Celsius.

import machine

adcpin = 4
sensor = machine.ADC(adcpin)


def ReadTemperature():
    adc_value = sensor.read_u16()
    volt = (3.3 / 65535) * adc_value
    temperature = 27 - (volt - 0.706) / 0.001721
    return round(temperature, 1)


T = ReadTemperature()
print(T)

NeoPixels#

βœ… Read the MicroPython documentation for Controlling NeoPixels

βœ… Review MicroPython time module

βœ… Review intro of MicroPython Pin class

AS7341 Light Sensor#

βœ… Read the overview page of the AS7341 Guide and the Pinouts page

βœ… Browse the as7341_sensor MicroPython Module

Definitions#

GPIO (General-Purpose Input/Output) Pins: GPIO refers to the pins on a microcontroller or single-board computer that can be configured as either inputs or outputs to interact with external hardware. These pins can be used to read digital signals (input) or send digital signals (output). GPIO pins are versatile and can be used for various tasks, such as reading sensors, controlling LEDs, or interfacing with other digital devices.

I2C (Inter-Integrated Circuit): I2C is a communication protocol used for connecting and exchanging data between electronic components on a circuit board or between different devices. It stands for Inter-Integrated Circuit and allows multiple digital devices to communicate with each other using a common set of wires, typically two (SDA for data and SCL for clock), making it useful for connecting sensors, displays, and other peripherals in a simple and standardized way.

RGB Color Values: In the context of RGB color representation, 0 to 255 refers to the range of values for each of the three color channels: Red (R), Green (G), and Blue (B). Each channel can have a value between 0 (no intensity) and 255 (maximum intensity), allowing for a total of 256 different levels of intensity for each color. By combining different levels of intensity for these three channels, you can create a wide range of colors by specifying how much red, green, and blue are mixed together. For example, RGB(255, 0, 0) represents full red, RGB(0, 255, 0) represents full green, and RGB(0, 0, 255) represents full blue. Mixing these channels in different proportions produces various colors in the RGB color space.

Spectrophotometer: A spectrophotometer is a scientific instrument used to measure the intensity of light at different wavelengths in a sample. It works by passing a beam of light through the sample and measuring how much light is absorbed or transmitted. Spectrophotometers are commonly used in chemistry, biology, and physics to analyze the concentration of substances in a solution, study the properties of materials, and determine the color or composition of samples by measuring their absorption or emission spectra.

Additional Resources#

  • Introduction to Raspberry Pi Pico guide

  • Raspberry Pi Pico using onboard Temperature Sensor

  • What is Stemma QT?

  • Rob Hamerling’s AS7341 MicroPython Library

  • Maker Pi Pico GitHub Repository

πŸš€ Quiz#

https://q.utoronto.ca/courses/351407/assignments/1286927?display=full_width

https://q.utoronto.ca/courses/367721/assignments/1499672?display=full_width

https://q.utoronto.ca/courses/437793/assignments/1730325?display=full_width_with_nav

πŸ“„ Assignment#

https://q.utoronto.ca/courses/351407/assignments/1286928?display=full_width

https://q.utoronto.ca/courses/367721/assignments/1499673?display=full_width

https://q.utoronto.ca/courses/437793/assignments/1730326?display=full_width_with_nav

previous

🧩 1.1 Run the Demo

next

🧩 1.3 Bayesian Optimization

Contents
  • πŸ”° Tutorial
    • Getting Started with the Pico (Optional)
    • Onboard LED
    • Onboard Temperature
    • NeoPixels
    • AS7341 Light Sensor
    • Definitions
    • Additional Resources
  • πŸš€ Quiz
  • πŸ“„ Assignment

By Sterling G. Baird

Last updated on Apr 29, 2026.