John Bradnam
Published © GPL3+

Using the new ATtiny Processors with Arduino IDE

Use the latest ATtiny processors in the Arduino Environment. These have the memory capacity of ATmega chips in smaller and cheaper packages.

BeginnerProtip1 hour2,989
Using the new ATtiny Processors with Arduino IDE

Things used in this project

Hardware components

Microchip Technology ATTiny16x4
14 Pin SOIC package.
×1
Resistor 10k ohm
Resistor 10k ohm
4K7 1/4 watt resistor
×1
Capacitor 10 µF
Capacitor 10 µF
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Prototyping Kit, Breadboard
Prototyping Kit, Breadboard

Story

Read more

Schematics

Adaptor Schematic

Adaptor Board

Adaptor Schematic and Board

Adaptor Schematic and Board in Eagle Format

ATtiny1614 Datasheet

Code

Blink_ATTiny1614.ino

C/C++
Blink example on a ATTiny1614
/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  BOARD: ATtiny1614/1604/814/804/414/404/214/204
  Chip: ATtiny1614
  Clock Speed: 20MHz
  Programmer: jtag2updi (megaTinyCore)

  Pin mapping: https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x14.md
  
*/

#define LED_BUILTIN 0 //PA4 (Pin 2)

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

ColorChanger1614.ino

C/C++
Color changing LED example for ATTiny16x4
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

/*-----------------------------------------------------------------------------
	ATTiny1614 Pins mapped to Ardunio Pins

             +--------+
         VCC + 1   14 + GND
 (SS)  0 PA4 + 2   13 + PA3 10 (SCK)
       1 PA5 + 3   12 + PA2 9  (MISO)
 (DAC) 2 PA6 + 4   11 + PA1 8  (MOSI)
       3 PA7 + 5   10 + PA0 11 (UPDI)
 (RXD) 4 PB3 + 6    9 + PB0 7  (SCL)
 (TXD) 5 PB2 + 7    8 + PB1 6  (SDA)
             +--------+

PA0 to PA7 can be analog or digital
PWM on D0, D1, D6, D7, D10

Mapping of Physical pins onto Adaptor Board

1  - PA5 
2  - VCC
3  - PA4
4  - PA6
5  - PB3
6  - PB2
7  - PA7
8  - PA0
9  - PB1
10 - PB0
11 - PA1
12 - PA3
13 - GND
14 - PA2


  BOARD: ATtiny1614/1604/814/804/414/404/214/204
  Chip: ATtiny1614
  Clock Speed: 16MHz
  Programmer: jtag2updi (megaTinyCore)

  Pin mapping: https://github.com/SpenceKonde/megaTinyCore/blob/master/megaavr/extras/ATtiny_x14.md

-----------------------------------------------------------------------------*/

#define LED 2	//(PA6)
#define PIXELS 1
#define POT 0	//(PA4)

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, LED, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() 
{
  //Serial.begin(115200);

  pinMode(POT, INPUT);
  pinMode(LED, OUTPUT);

  strip.begin();
  strip.setBrightness(255);
  strip.show(); // Initialize all pixels to 'off'
}

void loop() 
{
  uint8_t angle = map(analogRead(POT), 0, 1023, 0, 255);
  uint32_t color = Wheel(angle);
  //Serial.println("Angle: " + String(angle) + ", Color: " + String(color));
  colorWipe(color, 5);
}
  
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) 
{
  for(uint16_t i=0; i<strip.numPixels(); i++) 
  {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) 
{
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) 
  {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) 
  {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

SpenceKonde - jtag2updi.zip

C/C++
Ardunio Sketch for ATMEGA328 system such as a UNO, NANO or MINI
No preview (download only).

Credits

John Bradnam

John Bradnam

30 projects • 19 followers

Comments