Skip to content

Utilizing bare-metal C programming to control Arduino pins and interact with input and output peripherals directly, without relying on the Arduino libraries. This repository demonstrates low-level register manipulation for efficient and precise hardware control.

Notifications You must be signed in to change notification settings

emanalva/bare-metal-arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Bare-Metal Arduino Coding in C

Overview

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.

Project 1: Blink an LED

This project blinks an LED connected to pin PB5 (Arduino Uno's digital pin 13) by directly controlling the pin using hardware registers.

Project 2: Button-Controlled LED

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.

Project 3: PWM-Controlled LED Brightness

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.

Steps to Upload Code to Arduino

Follow these steps to compile and upload the code to your Arduino:

  1. Navigate to the project directory:

    cd path/to/project/directory
  2. 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.

  3. Compile the code:

    make
  4. Upload the compiled code to the Arduino:

    make flash

Datasheet Links

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

About

Utilizing bare-metal C programming to control Arduino pins and interact with input and output peripherals directly, without relying on the Arduino libraries. This repository demonstrates low-level register manipulation for efficient and precise hardware control.

Topics

Resources

Stars

Watchers

Forks