This project implements a Christmas tree using an Arduino Uno and LEDs.
- x1 Arduino Uno
- x1 breadboard
- x3 red LEDs
- x3 green LEDs
- x1 yellow LEDs
- x7 220 Ohm resistors
- x10 jumper wires male-to-male
- Debian-based Linux distro
- rustc / cargo
- gcc-avr
- avrdude
To download and run rustup, execute the following command:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup allows to install and configure the Rust compiler (rustc) and package manager (cargo).
The following commands allow to install the necessary AVR tools:
sudo apt update
sudo apt install gcc-avr
sudo apt install avrdude
AVR is the architecture that the Arduino Uno microcontroller is based on (ATmega328P microcontroller).
In the project Cargo.toml file:
- Add the dependency for the panic handler under the [dependencies] section:
[dependencies] panic-halt = "0.2.0" - Add the dependency for the AVR HAL at the end of the file:
[dependencies.arduino-hal] git = "https://github.com/Rahix/avr-hal" rev = "4cbb163" features = ["arduino-uno"] - Change the edition field at the top of the file:
edition = "2018"
At the end run the following command to setup the project
cargo update
- Create a folder called .cargo in the project root directory
- Inside the new folder create a file called config.toml
- Write the following lines in the config.toml file:
[build] target = "avr-atmega328p.json" [unstable] build-std = ["core"] - Download the avr-atmega328p.json file from https://github.com/Rahix/avr-hal/tree/main/avr-specs inside the project root directory
- If not already present, at the end of the avr-atmega328p.json file add the field:
"panic-strategy": "abort"
Run the command:
rustup override set nightly-2021-01-07
This will set the rust buildchain to a version which is compatible with the AVR toolchain.
To compile the project run the command
cargo build
for the debug version, or
cargo build --release
for the release (optimized) version.
This will create a xmas-tree.elf file inside the target/avr-atmega328p/debug or target/avr-atmega328p/release folder.
To flash the program to the Arduino:
- Connect the Arduino to the computer via the USB cable
- Run the commands:
or
cd target/avr-atmega328p/debugthencd target/avr-atmega328p/releaseavrdude -p m328p -c arduino -P /dev/ttyACM0 -b 115200 -U flash:w:xmas-tree.elf
where /ttyACM0 is usually the device file associated to a connected Arduino.
The image below shows the circuit.
Every LED is controlled separately by a specific Arduino digital pin; digital pins number 2 through 8 were chosen.
Every LED is connected to ground through a 220 Ohm resistor. One of the ground rails of the breadboard is connected to one of the Arduino GND pins, while the other rail is wired to the first one.
