Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

Docker Image

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

Raspberry Pi Pico Lab

  • 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

Features

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

Build

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 blink

Load Program onto Device

To 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 -f

Finally, load a program like so:

picotool load blink.uf2 -f

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 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"

AVR Lab

  • Using default gcc-avr and avr-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

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

Build

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"

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/

[2] https://github.com/raspberrypi/pico-sdk-tools

About

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

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages