This repository contains
- A Dockerfile to ⬇️ create an image that can build all projects in this repository
- Template and Examples in
C/C++for the ⬇️ Raspberry Pi Pico using the official SDK, via Docker - Template and Examples in
Cfor ⬇️ AVR Microcontrollers, optionally built via Docker
The source code in this repository is licensed under the MIT license (if not stated otherwise). For Licenses of thirdparty components, see below.
- Raspberry Pi Pico ws2812 PIO driver (rpico/src/ws2812.pio)
- rpico/src/ws2812.pio (license in file)
- AVR Makefile template (avr/Makefile_template)
- origin:
WinAVR-20100110 - license: see avr/Makefile_template
- each AVR example project in avr/src/ contains a
Makefile, which is an adjusted copy of avr/Makefile_template
- origin:
All projects in this repository can be built with the Docker image, generated from Dockerfile.
Build the Docker image:
docker build -t uc-lab .Optionally, you can start a Docker container with an interactive shell to work in directly. But it is recommended to skip this step and use the simple build commands, described for each platform below.
# Option 1: Use a container that deletes itself after usage (--rm)
# Bash
docker run --rm -it -v $(pwd):/code uc-lab
# Powershell
docker run --rm -it -v ${PWD}:/code uc-lab
# Option 2: Create a named container that can be reused
# Bash
docker run -it -v $(pwd):/code --name uclab_01 uc-lab
# Powershell
docker run -it -v ${PWD}:/code --name uclab_01 avrlab
# For option 2, start the container like this
docker start -i uclab_01- The official SDK is cloned into the Docker image, see Dockerfile for details
- Check out the examples in rpico/src/
- Utilize existing code for an own project or start with a basic example
- Having Docker in place, the projects can be built with a single command
| Feature | Example | Info |
|---|---|---|
| blink | rpico/src/main_blink.c | Hello world blink example |
| debounce | rpico/src/main_debounce.c | Button debouncer |
| serial | rpico/src/main_serial.c | Serial via USB. Connect from PC with rpico/src/serial_pc.py |
| ws2812 | rpico/src/main_ws2812.c | Basic ws2812 light controls |
All examples tested on boards: pico, pico_w, pico2, pico2_w, waveshare_rp2350_zero
This builds the examples in an auto-removing container, from the image created above. Replace <pico_board> with the desired board to build for, such as pico or pico_w. Recommended in most cases.
cd rpico
# Bash
docker run --rm -v $(pwd):/code uc-lab /bin/bash ./build.bash <pico_board>
# Powershell
docker run --rm -v ${PWD}:/code uc-lab /bin/bash ./build.bash <pico_board>Optionally, append the name of a build traget to only build a single example.
# Example: Build only the blink example for pico board
docker run --rm -v ${PWD}:/code uc-lab /bin/bash ./build.bash pico blinkTo load a program onto the Pico board, drop a UF2 binary from build_<pico_board>/ directory to the removable drive, with the BOOTSEL button mechanism (or similar, for other boards).
Alternatively, use picotool [2] to load a program without pressing the BOOTSEL button.
For this to work, (1) enable stdio via usb in CMakeLists.txt for your target:
pico_enable_stdio_usb(<YOUR_TARGET> 1)And (2), call stdio_usb_init() (or stdio_init_all()) in your main().
With this program running on the Pico, picotool can put it into BOOTSEL mode (-f option) and load a program. Test the connection like so:
picotool info -fFinally, load a program like so:
picotool load blink.uf2 -fThe above should suffice for simple building of the examples. Here are some more things to do.
Use this repository as a template for an own project:
- Fork or download this repository
- Delete unneeded source files from rpico/src/
- e.g. just keep
main_blink.cto start with
- e.g. just keep
- Delete unneeded build targets from rpico/CMakeLists.txt
- Each
main_[...].c/.cppfile in rpico/src/ has a corresponding block in rpico/CMakeLists.txt defining an executable target - e.g. just keep the block starting with
add_executable(blink ...
- Each
More control over the build command:
cd rpico
# Bash
docker run --rm -v $(pwd):/code uc-lab /bin/bash -c "mkdir -p build && cd build && cmake -DPICO_BOARD=pico .. && make"
# Powershell
docker run --rm -v ${PWD}:/code uc-lab /bin/bash -c "mkdir -p build && cd build && cmake -DPICO_BOARD=pico .. && make"- Using default
gcc-avrandavr-libc, see Dockerfile for details - Mainly written for
ATtiny85, if not stated otherwise - Check out the examples in avr/src/
- Utilize existing code for an own project or start with a basic example
- Having Docker in place, the projects can be built with a single command
Example projects, roughly sorted by complexity.
| Example | Code | Info |
|---|---|---|
| blink | avr/src/blink/main.c | Hello world blink example |
| timemeas | avr/src/timemeas/main.c | No delay blink example using time measure |
| togglebutton | avr/src/togglebutton/main.c | Debounced button input |
| states | avr/src/states/main.c | Simple state logic with debounced button input |
| choreo | avr/src/choreo/main.c | Concurrent pin output sequences |
| sleep_pci | avr/src/sleep_pci/main.c | Sleep and wake-up via pin change interrupt |
| pwm | avr/src/pwm/main.c | PWM signal with Timer/Counter0,1 |
| ws2812b | avr/src/ws2812b/main.c | WS2812B control via Bit-Banging |
| moodlight | avr/src/moodlight/main.c | Multiple WS2812B light sequences, switchable, auto-sleep |
| hot_wire | avr/src/hot_wire/main.c | Simple hot wire game |
Helper modules.
| Module | API | Code | Info |
|---|---|---|---|
| choreo | avr/src/choreo.h | avr/src/choreo.c | Time-uncritical concurrent execution of simple tasks |
| debounce | avr/src/debounce.h | avr/src/debounce.c | Button debouncer |
| timemeas | avr/src/timemeas.h | avr/src/timemeas.c | Time measurement using Timer/Counter0 |
| ws2812b | avr/src/ws2812b.h | avr/src/ws2812b.c | WS2812B interface |
| zzz | avr/src/zzz.h | avr/src/zzz.c | Power down sleep mode |
This builds a project in an auto-removing container, from the image created above. Recommended in most cases.
cd avr
# Bash
docker run --rm -v $(pwd):/code uc-lab /bin/bash -c "cd src/blink && make hex"
# Powershell
docker run --rm -v ${PWD}:/code uc-lab /bin/bash -c "cd src/blink && make hex"- Install
avrdudeon host (recommended) - Use
stk500v1compatible ISP (e.g. using Arduino with ISP example sketch)
avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U flash:w:src/blink/main.hexAttention: inappropriate fuse settings can brick the microcontroller, check [1]
# Set 1MHz clock
avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U lfuse:w:0x62:m
# Set 8MHz clock
avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U lfuse:w:0xE2:m