This project demonstrates bare-metal programming on an Arduino using C. The code directly manipulates hardware registers to control basic peripherals like LEDs and buttons, without relying on the Arduino libraries.
This project blinks an LED connected to pin PB5 (Arduino Uno's digital pin 13) by directly controlling the pin using hardware registers.
In this project, an LED is controlled using a button connected to pin PB4 (Arduino Uno's digital pin 12). A pull-up resistor is enabled on the button pin to ensure stable input, and the button’s state is debounced in software to avoid noise. The project is modularized, with functions for initializing the pins and reading the button state.
In this project, we implement Pulse Width Modulation (PWM) to control the brightness of an LED connected to pin PB1 (Arduino Uno's digital pin 9). This project demonstrates:
- Configuration of Timer1 for 16-bit Fast PWM mode
- Direct manipulation of Timer1 registers (TCCR1A, TCCR1B, ICR1, OCR1A)
- Generation of a PWM signal with variable duty cycle
- Gradual increase and decrease of LED brightness in a continuous cycle
The code uses Timer1's 16-bit resolution (0-65535) for smooth brightness transitions. The LED's brightness is controlled by adjusting the PWM duty cycle, creating a visually appealing "breathing" effect.
Follow these steps to compile and upload the code to your Arduino:
-
Navigate to the project directory:
cd path/to/project/directory
-
Open the Makefile and update the USB port connection to match your Arduino's port. For example:
sed -i 's/ARDUINO_PORT = \/dev\/ttyACM0/ARDUINO_PORT = \/dev\/ttyUSB0/' Makefile
Replace
/dev/ttyUSB0
with the actual port your Arduino is connected to. -
Compile the code:
make
-
Upload the compiled code to the Arduino:
make flash
The datasheets provide detailed technical information needed for using the Arduino configuring the microcontroller.
- Arduino Uno Documentation: This Arduino site provides the datasheet for the Uno showing the pinout and other hardware specifications for the Arduino Uno board. It's useful for understanding which pins are connected to specific microcontroller functions.
- ATmega328P Datasheet: This datasheet provides technical details on the ATmega328P microcontroller, which is used in the Arduino Uno. It’s essential for understanding timers, registers, and how to control peripherals at a low level.
© 2024 Emanuel Alvarez