I keep saying that the ATtiny is the same thing as an Arduino but smaller. Let's take a look at 8pin chips such as the ATtiny13, the ATtiny45 and the ATtiny85. What a pin can do is controlled by your program.
Notice how each pin has so many numbers and labels. Physical pin 1 is next to a notch in the chip but it is also named PB5 reset pin. This project will remind us to check exactly where we are on a very small circuit board.
SOC system on a chipThis is a DIP dual inline package, named for the two rows of pins. We can add power and ground and our chip will run whatever program has been loaded into flash memory.
We are going to assemble an ATtiny development board. A hardware environment for software development.
- HW-260 DevBoard
- 3x2pin header for ICSP port
- ATtiny Chip - ATtiny13/25/45/85
It is worth it. On this board, the USB is not ready to be used for programming. We add the header so that we can connect an external programmer such as a USBasp or USBtiny.
Soldering must be performed in a well ventilated area. Take your time. Let your iron heat up. Be careful.
Working with solder is not easy and practice helps you improve. Clean surfaces help spread melted solder into connections. Chips can be sensitive to electrical static shock.
Apply solder the back of the board. Avoid overheating. Melt the solder so that it flows into the space between the board and the metal pin. Check that solder has not stretched between pins and shorted them together.
Pins are reversed when you look at this side of the board. A guide to pin identification is printed on the back of the board. Connectors are keyed so that they only go in one way.
Finished BoardUse the multimeter buzzer setting to verify each of the 6 pins in the header make good connection. Reflow your solder if necessary.
Insert chip into socket. Be careful with circuit orientation and watch for dot, triangle, square markings to indicate the first pin. Align notch in chip and in socket.
Incorrect handling can damage components. Straighten bent chip pins carefully.
Board FeaturesFactory made connections to useful circuits.
- All 8 pins of the ATtiny chip
- P1 has a resistor and built-in LED circuit
- USB connector has power and DATA+, DATA-
- P2 and P3 wired to USB connector
- SPI Serial Port Interface + I2C bus
- 5volt power regulation
- Socket. Program chip and remove
This Digispark schaltplan diagram by Dietrich Kinderman shows JP3 the 8pin header. We will equip only the top 6 pins in order to make an ICSP programming port.
Having this port on our board means we can plug a programmer device such as a USBasp or USBtiny directly into our board. Be careful with connector orientation and we can trust our wiring.
More information about AVR programming at Arduino as ISP. Project AVR Programmers I : Arduino ISP Arduino programs Arduino shows how to make a programmer device with a Uno board.
Connect ProgrammerPower LED on HW-260 board should light. Chip will run program from flash. That program may or may not blink built-in LED.
ATtinies have an incredible codebase of projects. They are in so many of the programmable devices you never thought about. What kind of computer runs your USB thumbdrive?
Look at Arduino for components and code. The ATtiny85 is equivalent to ATmega8 MCU in flash and RAM. The HW-260 board is good to go for circuits that have USB, I2C, SPI buses. It turns USB power into 5volts that you can power sensors, displays, external devices.
Digistump have built on the ATtiny85 in their DigiSpark development board. Like a postage stamp it comes with a bootloader you may find interesting. Adding a bootloader consumes flash space but means you can upload your program on the USB port like you do with Arduino.
Demo CodeThis Arduino sketch will toggle IOs on PORTB. Expect to see built-in LED to blink. Change delay value for blink speed.
#define F_CPU 16000000UL
#include<avr/io.h>
#include<util/delay.h>
int main(){ DDRB = 0x1F;
while(1){ PORTB++; delay(100); }}
Upload firmware to devboard. More information at Program ATtiny with Arduino IDE and ATtiny Assembler Program.
Or we can use the command line terminal.
Look in the Arduino output and see flash command. White line of text is avrdude upload information.
We have so little flash for our program. Do we want to install a bootloader?
Probably not
- Most projects we need PB3 and PB4 for IO
- Most projects won't use the USB port
- HW-260 board breaks out pins for 6pin programming port
- Still get 5v power from USB port with no data
Having a bootloader means our chip can talk to a PC as an Arduino programmable device. Using some of our flash memory for a bootloader is very convenient. Instead of using an external programmer device we can program our chip through the USB just like an Arduino.
When we connect the USB of our HW-260 board into a computer we get power. The PC tries to recognize the device but with no program to talk on USB our ATtiny is ignored. But a Digispark board with bootloader talks to the PC and gets a vendor id and product id.
TroubleshootingCheck chip and programmer orientation. Look for dot on chip. Check label that you have the correct ATtiny chip. Check that you are programming code for that chip.
A very likely cause of upload problems is solder joints. Remove chip and re-melt your solder. Use your multimeter to check all connections. Check for pins soldered together and for spaces around the pins.
You can improve the programmer's connection to a board by choosing a slower baud rate for serial communication. Add the avrdude parameter -b 9600 for 9600 bit per second.
You can backup the code from a programmed chip. There are GUI versions of avrdude.
We can open the hex file with notepad. This format was developed for punch card and magnetic tape. The holes in paper are ones and zeroes, our intel hex file uses hexadecimal numbers. This is a healthy hex file.
Comments