This guide explains how to program an ATtiny microcontroller using a USBasp programmer (flashed with updated firmware), the HW-260 ATTiny adapter development board, and tools like Arduino IDE, PlatformIO, avrdude, and SinaProg.
- USBasp Programmer:
- Updated with USBASP11.hex firmware.
- HW-260 ATTiny Adapter Development Board:
- Used for interfacing the USBasp with the ATtiny.
- ATtiny Microcontroller (e.g., ATtiny45).
- Arduino Mega:
- Used for updating USBasp firmware.
- Zadig:
- Installs the correct USB driver for USBasp.
- avrdude:
- Command-line tool for flashing AVR microcontrollers.
- Arduino IDE or PlatformIO:
- For writing and compiling sketches.
- SinaProg 2.1.1:
- GUI for flashing USBasp firmware.
-
Wire the Arduino Mega to USBasp (ICSP Header):
Arduino Mega Pin USBasp ICSP Pin 5V VCC GND GND D11 MOSI D12 MISO D13 SCK D10 RESET -
Load Arduino ISP Sketch on Mega:
- In Arduino IDE, go to File > Examples > 11.ArduinoISP > ArduinoISP.
- Upload this sketch to the Arduino Mega.
-
Flash USBasp Using SinaProg:
- Open SinaProg 2.1.1.
- Select USBASP11.hex firmware.
- Set Programmer: Arduino as ISP.
- Set Target: USBasp.
- Click Write Flash.
-
Download and Open Zadig:
- Install from Zadig website.
-
Install Driver:
- Go to Options > List All Devices.
- Select USBasp from the device list (ensure USBasp is connected to your PC via USB).
- Choose libusbK (v3.x.x) driver.
- Click Replace Driver.
Save this example sketch as blink_test.ino:
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 4 (PB4) as an output.
pinMode(4, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(4, HIGH); // turn the LED on
delay(250); // wait for 250ms
digitalWrite(4, LOW); // turn the LED off
delay(250); // wait for 250ms
}- Select ATtiny45 as the board in Tools > Board.
- Set the clock frequency to 1 MHz (Internal Oscillator) in Tools > Clock.
- Write or open your sketch (e.g., a Blink program).
- Compile the sketch by going to Sketch > Export Compiled Binary.
- Locate the compiled
.hexfile in the sketch folder.
Save this example sketch as blink_test.ino:
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 4 (PB4) as an output.
pinMode(4, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(4, HIGH); // turn the LED on
delay(250); // wait for 250ms
digitalWrite(4, LOW); // turn the LED off
delay(250); // wait for 250ms
}Create a platformio.ini file in your project directory with the following configuration:
[env:attiny45]
platform = atmelavr
board = attiny45
framework = arduino
upload_protocol = usbaspWrite your sketch in src/main.cpp. For example, the Blink program:
// The setup function runs once when you press reset or power the board
void setup() {
// Initialize digital pin 4 (PB4) as an output
pinMode(4, OUTPUT);
}
// The loop function runs over and over again forever
void loop() {
digitalWrite(4, HIGH); // Turn the LED on
delay(250); // Wait for 250ms
digitalWrite(4, LOW); // Turn the LED off
delay(250); // Wait for 250ms
}To compile your sketch using PlatformIO, run:
pio runLocate the compiled .hex file in the /build directory of your project.
-
Place the ATtiny45 into the HW-260 adapter.
-
Connect USBasp to the HW-260 using the following wiring:
USBasp Pin HW-260 Pin VCC VCC GND GND MOSI MOSI MISO MISO SCK SCK RESET RESET
Run the following command to flash the .hex file onto the ATtiny:
avrdude -c usbasp -p t45 -U flash:w:blink_test.hex:iIf the flashing process fails, short the JP3 jumper on the USBasp to enable slow SCK mode. Retry with the following command:
avrdude -c usbasp -p t45 -B 32 -U flash:w:blink_test.hex:i-
Wire the Arduino Mega to USBasp (ICSP Header):
Arduino Mega Pin USBasp ICSP Pin 5V VCC GND GND D11 MOSI D12 MISO D13 SCK D10 RESET -
Load Arduino ISP Sketch on Mega:
- Open Arduino IDE.
- Go to File > Examples > 11.ArduinoISP > ArduinoISP.
- Upload the sketch to the Arduino Mega.
-
Flash USBasp Using SinaProg:
- Short USBasp JP2 jumper (enter USBasp programmingmode).
- Open SinaProg 2.1.1.
- Select USBASP11.hex firmware.
- Set Programmer: Arduino as ISP.
- Set Target: USBasp.
- Click Write Flash.
- Unshort USBasp JP2 jumper.
-
Download and Open Zadig:
- Download Zadig from its website.
-
Install Driver:
- Go to Options > List All Devices.
- Select USBasp from the device list (ensure USBasp is connected to your PC via USB).
- Choose libusbK (v3.x.x) driver.
- Click Replace Driver.
- After programming, disconnect the USBasp to run the sketch on the ATtiny.
- Use the
-Bflag to adjust SCK speed for slower target devices. - Double-check all wiring connections and ensure the ATtiny is properly powered.
- Update USBasp firmware if you encounter compatibility issues.
This guide ensures you can easily program ATtiny microcontrollers with the USBasp and HW-260 adapter. Good luck!