Skip to content
/ uc-lab Public

👽 Template and Examples for Raspberry Pi Pico (C/C++) and AVR (C), built via Docker. WS2812B driver inside.

License

Notifications You must be signed in to change notification settings

duddel/uc-lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uC Lab

build rpico build avr

This repository contains

License

The source code in this repository is licensed under the MIT license (if not stated otherwise). For Licenses of thirdparty components, see below.

Thirdparty

Raspberry Pi Pico Lab

  • The official SDK is cloned into the Docker image, see rpico/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

Features

Feature Example Info Tested on boards
blink rpico/src/main_blink.c Hello world blink example pico, pico_w
debounce rpico/src/main_debounce.c Button debouncer pico, pico_w
ws2812 rpico/src/main_ws2812.c Basic ws2812 light controls pico, pico_w

Kick-start

A Docker installation and basic Docker knowledge is required.

  1. Build the Docker image:
cd rpico
docker build -t rpico .
  1. Build the examples via Docker with one of these commands. Replace <pico_board> with the desired board to build for, such as pico or pico_w.
cd rpico

# Bash
docker run --rm -v $(pwd):/code -w /code rpico /bin/bash ./build.bash <pico_board>

# Powershell
docker run --rm -v ${PWD}:/code -w /code rpico /bin/bash ./build.bash <pico_board>
  1. Drop any UF2 binary from build_<pico_board>/ directory onto the Pico following the official documentation.

Advanced usage

The 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.c to start with
  • Delete unneeded build targets from rpico/CMakeLists.txt
    • Each main_[...].c/.cpp file 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 ...

More control over the build command:

cd rpico

# Bash
docker run --rm -v $(pwd):/code -w /code rpico /bin/bash -c "mkdir -p build && cd build && cmake -DPICO_BOARD=pico .. && make"

# Powershell
docker run --rm -v ${PWD}:/code -w /code rpico /bin/bash -c "mkdir -p build && cd build && cmake -DPICO_BOARD=pico .. && make"

Start Docker container with an interactive shell:

cd rpico

# Bash
docker run --rm -it -v $(pwd):/code rpico

# Powershell
docker run --rm -it -v ${PWD}:/code rpico

AVR Lab

  • Using default gcc-avr and avr-libc, see avr/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

Examples and Helper Modules

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

Set up Docker

A Docker installation and basic Docker knowledge is required. Run these commands in the repository root.

First, build the Docker image (once).

cd avr
docker build -t avrlab .

Build a project

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 avrlab /bin/bash -c "cd src/blink && make hex"

# Powershell
docker run --rm -v ${PWD}:/code avrlab /bin/bash -c "cd src/blink && make hex"

Advanced (more Control over Container)

Start container with interactive shell.

cd avr

# Option 1: Auto-removing container after usage
# Bash
docker run --rm -it -v $(pwd):/code avrlab

# Powershell
docker run --rm -it -v ${PWD}:/code avrlab

# Option 2: Named container
# Bash
docker run -it -v $(pwd):/code --name avrlab_01 avrlab

# Powershell
docker run -it -v ${PWD}:/code --name avrlab_01 avrlab

# For option 2, start container like this
docker start -i avrlab_01

Build a project.

cd src/blink
make hex

avrdude Example Commands

  • Install avrdude on host (recommended)
  • Use stk500v1 compatible ISP (e.g. using Arduino with ISP example sketch)

Program

avrdude -p attiny85 -P com3 -c stk500v1 -b 19200 -U flash:w:src/blink/main.hex

Fuses

Attention: 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

References

[1] https://www.engbedded.com/fusecalc/

About

👽 Template and Examples for Raspberry Pi Pico (C/C++) and AVR (C), built via Docker. WS2812B driver inside.

Topics

Resources

License

Stars

Watchers

Forks

Languages