how to program attiny85 without arduino

Tiny85 Programming Without Arduino: Simple & Step-by-Step Guide

By Mark Johnson
AD

If you're eager to explore the capabilities of the Attiny85 microcontroller without the Arduino IDE, you're in the right place. This guide will walk you through the process of programming the Attiny85 using the AVR Library for C/C++ and the GNU toolchain. By the end, you'll have a solid understanding of how to code and flash this versatile 8-bit microcontroller.

Before we dive in, ensure you have the required tools and components. You'll need an Attiny85 microcontroller, a USBtinyISP programmer/isp programmer, and some jumper wires. Additionally, install the GNU toolchain (avr-gcc), AVRdude, and Make on your computer. For Windows users, consider using a pre-bundled package like WinAVR.

Setting Up the Development Environment

With your tools ready, let's set up the development environment for the Attiny85.

AD
ATtiny85 can't be programmed
ATtiny85 can't be programmed
How to program ATTiny85 with Arduino Uno (part 1)
How to program ATTiny85 with Arduino Uno (part 1)
Programmer for ATtiny 85
Programmer for ATtiny 85

Installing the AVR Library

The AVR Library is a crucial component for C/C++ development. You can install it via package managers like apt-get or brew, or download it from the GitHub repository.

To use it with your projects, create a new folder for your project and add the following lines to your makefile:

ATtiny85 PWM Primer Tutorial Using Arduino - EDN
ATtiny85 PWM Primer Tutorial Using Arduino - EDN
Attiny 85 Digispark Board
Attiny 85 Digispark Board

include ..\path\to\avr-libc\user_maps.mak

LDFLAGS = -mmcu=attiny85 -DF_CPU=8000000L -Battiny85 -Wl,--gc-sections

AD

Structuring Your Makefile

Here's a basic structure for your makefile that you can use as a template. Make sure to replace 'main.c' with the name of your source file:

SRC = main.c

OBJ = $(SRC:.c=.o)

AD

avr-objs = $(OBJ)

all: program.hex firmware.elf

program: program.hex avrdude -p attiny85 -c usbtiny -U flash:w:program.hex

AD

firmware: program.elf avr-objcopy -j .text -j .data -O ihex -R .eeprom program.elf strap.hex

program.hex: $(avr-objs) avr-gcc -Os -DF_CPU=8000000L -mmcu=attiny85 -DFury -DARDUINO_BBoARD -c -o $@ $^

Programming the Attiny85

Now that your environment is set up, let's write some code and program the Attiny85.

Writing Your First AVR Program

Here's a simple Blink sketchport you can use as a starting point. Save this as 'main.c' in your project folder:

// Define the LED pin #define LED_PIN 1

int main() { DDRB |= (1 << LED_PIN); // Set LED pin as output

while (1) { PORTB |= (1 << LED_PIN); // Turn on LED

_delay_ms(1000); // Wait for 1 second

PORTB &= ~(1 << LED_PIN); // Turn off LED

_delay_ms(1000); // Wait for 1 second

}

Compiling and Flashing the Attiny85

To compile your code, navigate to your project folder in the terminal and type 'make'. This will create the 'program.hex' file in your project folder, which you can then flash to the Attiny85 using the 'make program' command.

Final tip: Always double-check your connections and consult the Attiny85's datasheet when in doubt. Enjoy your newfound freedom from the Arduino IDE!

AD