Fads to Obsessions and Beyond...




Free domain for life, exceptional technical support, website transfer

Flash a LED ('Hello World' for ATtiny micro's)

Demonstrate programming ATtiny85/Digispark with Arduino IDE - flashing a LED (the "hello world" example of microcontrollers).

Microcontrollers are effectively a 'computer' on a single chip that contains a CPU, memory and programmable inputs/outputs (1). Consequentially, this provides an economical solution in the DIY situation to relatively easily digitally control a wide variety of devices and produce solutions to myriad problems, that a more traditional 'analog electronics' approach would require extensive electrical engineering knowledge and skill.

Various microcontroller families (PIC, ARM, AVR, etc) typically have onboard functionality such as analog-to-digital converters (ADC), Pulse Width Modulation (PWM), programmable timers, voltage comparators and general purpose input/output pins (GPIO) which with programming via EEPROM and flash enable sophisticated solutions with only relatively simple external ancillary circuitry. Such minimum external circuitry typically involves a suitable power supply, perhaps an oscillator and connections for the programming of the microcontroller.

While many applications require a "myriad" of GPIO's for controlling various outside peripherals and or input from sensors (and hence need "larger" microcontrollers with multiple ports), in the DIY arena there are also many occasions where there are only a couple of inputs/outputs required to be controlled. In this scenario the ATtiny range of microcontrollers are advantageous in terms of physical size and cost per GPIO/onboard peripheral available. Particularly when considering that an ATtiny85 on a Digispark "development" board can be purchased from ebay for ~$1 (which provides a surface mounted ATtiny85 with 5V regulator and PCB tracks to enable insertion into a USB socket). The ATtiny85/Digispark coupled with the Arduino IDE for programming enables "simple" projects to be developed quickly and easily deployed for a few dollars in total.

Details on how to setup the Arduino IDE and environment to programme ATtiny85 microcontrollers are given in the ATtiny85 introduction. This information is used to demonstrate the practical implementation of programming an ATtiny85/Digispark to blink a series of LED's (the microcontroller circuit analogous to the 'hello world' application of the 'programming world').


The Digispark board has a surface mount ATtiny85 with headers for all pins. Additionally, the board provides a 5V regulator for external DC power input and PCB copper traces that enable insertion into standard USB connector which can then be used for DC power source. There is an onboard LED to indicate power-on and an additional LED/resistor connected to pin1 for user control.

For convenience for this simple test, the USB power supply is used. Additionally, a further external LED/resistor is used to demonstrate how the Digispark board can be used to power external components via the USB connector.

Again for convenience for this simple test, the ATtiny85 onboard oscillator is used rather than an external crystal source.

ISP programming is used as detailed in the ATtiny85 introduction.


Note: Image loading can be slow depending on server load.

  • ATtiny85 SchematicATtiny85 Schematic

    Silver Membership registration gives access to full resolution schematic diagrams.

    ATtiny85 Schematic

    ATtiny85 Schematic

This project did not require a PCB.

The construction was done using prototyping board. See the photographs and schematic diagram sections.

Qty Schematic Part-Reference Value Notes
Resistors
1R13301/4W, 10% 
Diodes
1D1Green LED 
Integrated Circuits
1U1Digispark/ATtiny85microcontroller datasheet
Miscellaeous
3J1wiresDupont pin jumper wires
Description Downloads
Bill of Materials Text File Download

Before connecting the Digispark to the USB port, check for any shorts (direct positive voltage to ground connection) as this could damage both the Digispark board and the USB/PC.

Programming the ATtiny85

The Arduino sketch for blinking the two connected LED's is as follows:

Code Snippet 1:


void setup() {                
  // initialize the digital pins as an output.
  pinMode(0, OUTPUT); // red LED 
  pinMode(1, OUTPUT); // green LED   
}

void loop() {
  digitalWrite(0, HIGH);   // red LED on
  digitalWrite(1, LOW);    // green LED off 
  delay(1000);             // wait for a second
  digitalWrite(0, LOW);
  digitalWrite(1, HIGH); 
  delay(1000);
}
   				

Once the circuit has been constructed as per the schematic (photographs of the circuit laid-out on breadboard given in the Photographs Section), the green and red LED's should alternately flash for one (1) second each.

The circuit is the basic minimum required to enable the ATtiny85 microcontroller to operate after being programmed with a suitable .hex file. So this circuit was only laid out on a breadboard.

Before connecting the Digispark to the USB port, check for any shorts (direct positive voltage to ground connection) as this could damage both the Digispark board and the USB/PC.

If the green LED fails to flash with a period of one (1) second, carefully check your breadboard circuit against the schematic and the photographs in the Photographs Section. Look for "gotcha's" like the LED polarity.

Note: Video loading can be slow depending on server load.


Comments/Questions

No comments yet.

Add Comment/Question

Only Logged-In Members can add comments

"If we could sell our experiences for what they cost us, we'd all be millionaires".

Please donate any amount to help with hosting this web site.

If you subscribe (only $2/annum) you can view the site without advertisements and get emails abouts updates etc.

X

Sorry!

Only logged-in users with Silver Membership and above can download.


Silver Membership is only $2, so join now!