Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Thursday, 13 November 2014

ATTiny85 – Tutorial 10 – Detecting Knocks and Vibration

This tutorial in it’s original form sends the detection of knocks and vibrations from the Freetronics ”Sound” module to the serial monitor. As we don’t have access to a serial monitor from the ATTiny85, instead we are going straight to the extended tutorial, monitoring our knocks and vibrations with an LED.

ATTiny85 Pin Project 10

For this tutorial, the Piezo (Sound module) is connected on A1 (ATTiny85 pin 7) and an LED is connected to 0 (ATTiny85 pin 5).

The Piezo is read using the analogRead Arduino function and, when the analog value read from the Piezo is > 5, it will light up our LED (with a pull down resistor).

/* Project 10: Detecting Vibrations and Knocks */

int knock = 0;

void setup()
{
  pinMode(0, OUTPUT);
}

void loop()
{
  knock = analogRead(A1);
  if(knock>5)
  {
    digitalWrite(0, HIGH);
    delay(300);
    digitalWrite(0, LOW);
  }
}

The sketch is pretty straight forward … the variable knock is assigned the value of analogRead and, if it’s value is > 5 the ATTiny85 turns the LED on with digitalWrite, then waits 300 milliseconds, and then turns the LED off again with digitalWrite.

Tutorial10

You can see from the above image that the wiring is pretty straight forward. Top right of the breadboard is  the 5V regulator. The ATTiny85 was programmed using the ATTiny85 ICSP.

ATTiny85–Detecting Knocks and Vibrations with Freetronics “Sound” module

This is the 10th Freetronics Experimenters Kit tutorial that I’ve converted to the ATTiny85.

Check out the rest of the tutorials here.

Thursday, 6 November 2014

ATTiny85 – Tutorial 9 – Making Sounds

While this looked like a fairly simple tutorial on the face of it, it was actually a bit more difficult.

The main problem that I encountered was that the tone() function is not supported by the ATTiny85 core, so I had to do a bit of hunting around to find an equivalent method for the ATTiny85. As I expected, others had come across this same problem and had already developed a solution for it.

Two of the solutions that I tried (arduino-tiny library and a beep function) were both unsuccessful. Both produced cricket sounds (probably because the timing was wrong). However, I found Simple Tones for ATtiny that produces a nice scale and didn’t cause me too many other problems.

ATTiny85 - Tutorial 09

The connection from the ATTiny85 to the Piezo is very simple. Connect Pin 1 of the ATTiny85 to either pin of the piezo (it isn’t polarised). Connect GND to the other pin of the piezo.

Here is the sketch from the Technoblogy article referred to above (Simple Tones for ATTiny).

/* TinyTone for ATtiny85 */

// Notes
const int Note_C  = 239;
const int Note_CS = 225;
const int Note_D  = 213;
const int Note_DS = 201;
const int Note_E  = 190;
const int Note_F  = 179;
const int Note_FS = 169;
const int Note_G  = 159;
const int Note_GS = 150;
const int Note_A  = 142;
const int Note_AS = 134;
const int Note_B  = 127;

int Speaker = 1;

void setup()
{
  pinMode(Speaker, OUTPUT);
}

void loop()
{
  playTune();
  delay(300);
}

void TinyTone(unsigned char divisor, unsigned char octave, unsigned long duration)
{
  TCCR1 = 0x90 | (8-octave); // for 1MHz clock
  // TCCR1 = 0x90 | (11-octave); // for 8MHz clock
  OCR1C = divisor-1;         // set the OCR
  delay(duration);
  TCCR1 = 0x90;              // stop the counter
}

// Play a scale
void playTune(void)
{
TinyTone(Note_C, 4, 500);
TinyTone(Note_D, 4, 500);
TinyTone(Note_E, 4, 500);
TinyTone(Note_F, 4, 500);
TinyTone(Note_G, 4, 500);
TinyTone(Note_A, 4, 500);
TinyTone(Note_B, 4, 500);
TinyTone(Note_C, 5, 500);
}

This sketch works just dandy, straight out of the box. Nice work Technoblogy, nice work indeed.

I need to do some more research to find out how I can get the tone() function from the arduino-tiny library to work satisfactorily, but for now, the above sketch serves my purpose.

Making Sounds with Piezo and the ATTiny85

Well, that concludes Tutorial 9. Enjoy. Once again, 9V to 5V Regulator and ATTiny85 ICSP were used to make this tutorial circuit.

Check out the rest of the tutorials here.

Tuesday, 4 November 2014

ATTiny85 – Tutorial 6 – Making Things Move With Servos

The Freetronics Tutorial 6 replaces the LED and Resistor connection on pin 11 of the Freetronics 11 with the data connection to a simple servo.

The ATTiny85 version does the same thing … not really much sense reinventing the wheel, huh?

ATTiny85 - Lesson 6 - Making Things Move With Servos

As we learn with Tutorial 7, there are three PWM pins on the ATTiny85 to choose from. I went with the easiest and most convenient … our old friend, pin 0.

If you use the sketch from Tutorial 5 in the Freetronics Tutorial with a servo instead of an LED, then this sketch works admirably.

// Tutorial 6: Making things move with servos
int led = 0;
int brightness = 0;
int delayTime = 10;

void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  while(brightness < 255)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness++;
  }
  while(brightness > 0)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness--;
  }
}
 

Of course, I’m using the ++ and – incrementing function rather than brightness = brightness + 1; and brightness = brightness –1; because I think that it looks better, but that’s just me. Let the spirit guide you in your decision …

Lesson 6 - Running

The green jumper connects from ATTiny85 pin 0 to the yellow connector on the servo, Red connects to Orange on the Servo from the 5V rail and the black jumper connects the brown servo connection to GND.

Here’s a short video of the action.

ATTiny85 Controlling a servo with PWM

Check out the rest of the tutorials here.

Monday, 3 November 2014

ATTiny85 – Tutorial 7 – RGB LED

I was playing around looking at the information at hand on the ATTiny85 PWM and I thought that there were only 2 PWM capable pins on the chip … apparently, I was wrong, there are three. PB0, PB1 and PB2 are all PWM. Until I realised that, I was toying with the idea of software based PWM. There are some pretty good articles, tutorials and pages relating to software PWM, so I’ll probably get around to playing with it, some other time.

In the meantime. I had another look over the Freetronics Tutorial #7 – RGB LED and I decided that the code was a little clunky. The RGB values all jump to their random values and there is a lot of blinking … that’s OK if that’s what you want. Anyway, I had a quick play and decided to make the values rise from 0 to their random value and then back down to 0 so that they fade in and out. It’s still a little inelegant, but for the sake of a decent tutorial, I thought that this would be fairly useful.

ATTiny85 - Lesson 7 - RGB LED

My code is as follows

//Tutorial 7: RGB LED *** EXTENDED

int rPin = 0;
int gPin = 1;
int bPin = 2;

void setup()
{
  pinMode(rPin, OUTPUT);
  pinMode(gPin, OUTPUT);
  pinMode(bPin, OUTPUT);
  analogWrite(bPin, random(0, 255));
  analogWrite(gPin, random(0, 255));
  analogWrite(rPin, random(0, 255));
  delay(500);
}

void loop()
{
  upDown(random(0,255), random(0,255), random(0,255));
  delay(500);
}

void upDown(int r, int g, int b)
{
  //bring the colours up
  int rVal, gVal, bVal = 0;
  for(int rVal = 0; rVal < r; rVal++)
  {
    analogWrite(rPin, rVal);
    delay(10);
  }
  for(int gVal = 0; gVal < g; gVal++)
  {
    analogWrite(gPin, gVal);
    delay(10);
  }
  for(int bVal = 0; bVal < b; bVal++)
  {
    analogWrite(bPin, bVal);
    delay(10);
  } 
 
//  return to 0
  while(rVal>0)
  {
    rVal--;
    analogWrite(rPin, rVal);
  }
 
    while(gVal>0)
  {
    gVal--;
    analogWrite(gPin, gVal);
  }
 
    while(bVal>0)
  {
    bVal--;
    analogWrite(bPin, bVal);
  }
 
}

This is still fairly close to the original, with an upDown function that fades each colour in and then all of them out again.

I used my ATTiny85 ICSP to program the ATTiny85 and the 9V to 5V power regulator to supply the solderless bread board.

Lesson 7 - Board

As you can see, there isn’t anything outside of the Arduino core being used in the code, and the wiring is very straight forward. The layout is as per the Freetronics tutorial (more or less … I’ve added a jumper from the top to bottom rails).

Here is how it looks when it’s running. Bear in mind that the cycle uses a random RGB value and splits it up, so it *should* be different for every cycle.

RGB LED Controlled by PWM on the ATTiny85

Well … it’s now well past my bed-time, so I’m calling it a night.

Have fun ATTiny85ers!

Check out the rest of the tutorials here.

ATTiny85 – Tutorial 5 – Dimming LED using PWM

This tutorial is a very simple conversion from ATMEGA328P to ATTiny85, there is only one pin involved in producing output, so we only need to change from pin 11 to pin 0. On the ATTiny85, there are three hardware PWM pins … pin 0, pin 1 and pin2 , so it’s simply a matter of switching over to Pin 0 and away we go.

ATTiny85 - Lesson 5 - Dimming LED with PWM

I’ve changed the sketch for personal taste (and I think, efficiency), you’re free to use the Freetronics version of the code if you like … it’s no great shakes on something this small.

/* project 5: Controlling LED brightness with PWM */

int led = 0;
int brightness = 0;
int delayTime = 10;

void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  while (brightness < 255)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness++;
  }
  while (brightness > 0)
  {
    analogWrite(led, brightness);
    delay(delayTime);
    brightness--;
  }
}

As you will see from the following image, there isn’t much to the wiring for this project.

Tutorial5

And here’s the circuit running through it’s light/dim wizardry.

Tutorial 5 – ATTiny85 - Dimming LED with PWM

Once again, I’m using my ATTiny85 ICSP to program the ATTiny85 using the Arduino UNO and my 9V to 5V power regulator to supply 5V to the circuit.

Check out the rest of the tutorials here.

Friday, 31 October 2014

ATTiny85 Tutorials

I thought that it may be easier for everyone if I put together a single page that lists all of the ATTiny85 tutorials on this blog so that you can come here and launch off to the tutorial that you want to see.

Once again, these are based on the Freetronics Eleven tutorials that you get when you buy the Experimenters Kit.

My goal is to produce an ATTiny85 equivalent for each of the tutorials in that guide, so that you can take advantage of both the Freetronics basic tutorials and my experimentations with the ATTiny85.

I am a hobbyist, not an expert!

Tutorials

Freetronics Tutorial Comments
01 – Controlling an LED  
02 – Controlling 8 LED 4 LED
03 – Reading Digital (On/Off) Input 4 LED
04 – Reading Analog (Variable) Input  
05 – Dimming LED Using PWM  
06 – Making Things Move With Servos  
07 – RGB LED  
08 – Drive More Outputs With A Shift Register 8 LED using 75HC595
09 – Making Sounds Using alternative tone() function
10 – Detecting Vibrations and Knocks  
11 – Light Input Controlling Sound Output  

I’m going to come back to this article and fill in the blanks as I complete the tutorials, so check in from time to time to see how we get along.

I will include the Arduino sketch along with the article so that you can see how the code differs between the chips. I am still planning on doing the same with the ATTiny84 and I’m likely to use the same format.

Typically, the tutorials will include a pin assignment section, an image or video of the completed circuit, the Arduino code and some commentary on the differences that I’ve encountered and the approach that I’ve taken.

Thursday, 30 October 2014

ATTiny85 Tutorial 4 – Reading Analog (Variable) Input

This is the 4th tutorial in the Freetronics Experimenters Kit converted to ATTiny85.

With this tutorial, the main changes from the original tutorial is again the pin assignments. But, also, the ATTiny85 is not connected to the PC via the USB cable, so Serial.begin, Serial.print and Serial.println are redundant. I have removed them from the sketch.

ATTiny85 Pins - Project 4

In this tutorial, the light sensor is connected to first Analog Digital Comparator pin (physical pin 7 ADC1). In your sketch, the analog pins are A1, A2 and A3 … so for the purpose of this tutorial, we’re using A1. The LED is connected on pin 0 … got that, A1 and 0 … right, let’s move on.

The modified sketch is as follows.

int led = 0;
int lightLevel;

void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  lightLevel = analogRead(A1);
  digitalWrite(led, HIGH);
  delay(lightLevel);
  digitalWrite(led, LOW);
  delay(lightLevel);
}

Within the loop function, the ATTiny85 reads the value of the light sensor, this gives a value of 0 – 5V. The value is read as an integer value from 0 – 1023. This value is assigned to the lightLevel variable that is used to set the blink rate of the LED. The more light there is, the slower the blink rate.

breadboard - Project 4

The yellow wire connects the light sensor to A1 on the ATTiny85 and the LED is connected to 0 on the ATTiny85.

To test this circuit, I powered it up and then turned on my LED lamp above the sensor … as you would expect, the blink rate slowed down, then I swung the lamp away from the sensor to give an analog light variation and the blink rate sped up as less light was hitting the sensor … all working as you would expect.

Tutorial 4 circuit running.

Again, I programmed the ATTiny85 using my ATTiny85 ICSP and powered the breadboard using my 5V power regulator.

That’ll do for now, I’ll come back to these tutorials next week.

Check out the rest of the tutorials here.

ATTiny85 Tutorial 8 – Drive More Outputs With A Shift Register

So, I thought that I’d skip ahead a bit and get straight into the control of LED via a shift register. As the ATTiny85 has few pin outs, the main thing to be able to go beyond the simple binary pin to pin scheme is to get a shift register working for you.

For this tutorial, I have tried to fit all of the components onto a half+ board. Of course, I’m using my 5V regulator, so I am cheating slightly. However, the ATTiny85 and the 74HC595 both fit on the board along with the required 8 LED.

The original Arduino sketch includes the instantiation of Serial communication, that hasn’t been enabled on my ATTiny85, so I’m just commenting it out in the sketch. I am also omitting the smoothing capacitor between data and GND, if you want to include it, by all means, knock yourself out.

The shift register tutorial uses only digital pins in the original, so I am substituting like for like in the ATTiny85 platform.

The wiring is a little confusing (probably because I crammed it all into a half+ board), but there really isn’t much to it.

Lesson 08 - Drive More With A Shift Register_bb

So long as you get the connections between the ATTiny85 and the 74HC595, then it’s really just a matter of poke and play (of course, you’ll need to be careful with the Vcc and GND connections!).

ATTiny85 - Connections to Shift Register

I’ve taken the liberty of changing the sketch to something closer to what I’ll actually be using, so beware that there are some functional changes (although very few).

Onto the sketch:

/*
  Shift Register Example
  Turning on the outputs of a 74HC595 using an array.
  Modified for ATTiny85

Hardware:
* 74HC595 shift register
* ATTiny85
* LEDs attached to each of the outputs of the shift register

*/
//Pin connected to ST_CP (12) of 74HC595
int latchPin = 2;
//Pin connected to SH_CP (11) of 74HC595
int clockPin = 3;
////Pin connected to DS (14) of 74HC595
int dataPin = 0;

//holders for information you're going to pass to shifting function
byte data;
byte chaseArray[8];

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
//  Serial.begin(9600);

  chaseArray[0] = 1;   //00000001
  chaseArray[1] = 2;   //00000010
  chaseArray[2] = 4;   //00000100
  chaseArray[3] = 8;   //00001000
  chaseArray[4] = 16;  //00010000
  chaseArray[5] = 32;  //00100000
  chaseArray[6] = 64;  //01000000
  chaseArray[7] = 128; //10000000
 
  //function that blinks all the LEDs
  //gets passed the number of blinks and the pause time
  blinkAll_2Bytes(2, 500);
}

void loop() {

  for (int j = 0; j < 8; j++) {
    //load the light sequence you want from array
    data = chaseArray[j];
    //ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, 0);
    //move 'em out
    shiftOut(dataPin, clockPin, data);
    //return the latch pin high to signal chip that it
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(60);
  }
}

 

// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // This shifts 8 bits out MSB first,
  //on the rising edge of the clock,
  //clock idles low

  //internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  //clear everything out just in case to
  //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  //for each bit in the byte myDataOut
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that 000001 or "1" will go through such
  //that it will be pin Q0 that lights.
  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    //if the value passed to myDataOut and a bitmask result
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000
    // and proceeds to set pinState to 1.
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else { 
      pinState= 0;
    }

    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin 
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  }

  //stop shifting
  digitalWrite(myClockPin, 0);
}


//blinks the whole register based on the number of times you want to
//blink "n" and the pause between them "d"
//starts with a moment of darkness to make sure the first blink
//has its full visual effect.
void blinkAll_2Bytes(int n, int d) {
  digitalWrite(latchPin, 0);
  shiftOut(dataPin, clockPin, 0);
  shiftOut(dataPin, clockPin, 0);
  digitalWrite(latchPin, 1);
  delay(200);
  for (int x = 0; x < n; x++) {
    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, 255);
    shiftOut(dataPin, clockPin, 255);
    digitalWrite(latchPin, 1);
    delay(d);
    digitalWrite(latchPin, 0);
    shiftOut(dataPin, clockPin, 0);
    shiftOut(dataPin, clockPin, 0);
    digitalWrite(latchPin, 1);
    delay(d);
  }
}

Running

I thoroughly recommend that you do this tutorial on the Arduino first before attempting the ATTiny85 version, so that you know what to expect and how the connections work. Other than that, this makes a nice and tiny board project, now I need to play with laying this out on a board so that I can etch it … that should be fun.

5V Reg - Powered

Testing the ATTiny85 Shift Register Sub Board

The above video is the ATTiny85 and 75HC595 sub board connected to breadboarded LED. This is the next step on from the breadboard version in this article, but uses the same sketch and is functionally identical.

Check out the rest of the tutorials here.

Friday, 19 September 2014

ATTiny85 Tutorial 3 – Reading Digital (On/Off) Input

I’m still trying to find the time to do these tutorial projects in amongst the rest of the things that I’m doing … so here goes with Tutorial 3 – Reading Digital (On/Off) Input for the ATTiny85.

The main thing to note here is that I’m only using 4 LED rather than the 8 LED that you will find in the Freetronics tutorials. Of course, that’s because the ATTiny85 doesn’t have the masses of pins that the UNO does, so I’ve scaled it back to 4 LED and modified the sketch accordingly.

The other thing to consider is that the available pins for the ATTiny85 are enumerated differently, so, rather than having pins 6 through to 13, we have pins 0 – 4. I need to use one of those pins as a digital input, so that leaves me with 0 – 3.

ATTiny85 Pin assignment

I’ve marked out the pins with the associated sketch variable so that you can see at a glance what connects where.

And here’s the sketch that I loaded onto the ATTiny85 (using my handy-dandy ATTiny85 ICSP from my previous article).

int ledCount = 4;
int ledPins[] = {0,1,2,3};
int ledDelay = 300;
int buttonPin = 4;

void setup() {
  for(int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT);
  }
  pinMode(buttonPin, INPUT);
}

void loop() {
  for(int thisLed = 0; thisLed < ledCount; thisLed++) {
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    while(digitalRead(buttonPin) == HIGH) {
      delay(10);
    }
    digitalWrite(ledPins[thisLed], LOW);
  }
}

The sketch initialises the ledCount variable, the ledPins integer array, the ledDelay and the buttonPin variable. The setup function sets the led pins as output and the button pin as input.

The loop cycles through the array making each LED turn on and then turn off, when the LED is HIGH, if the momentary button is held down, the LED stays HIGH until the momentary button is released, then it just keeps going through the cycle.

Project3

As you can see from the above image, the wiring for this circuit is also pretty straight forward. You will note in the top right hand corner, I’m using my 9V to 5V power regulator mini-board. This is another circuit that I completed in a previous post.

This is a very simple tutorial and it does not require any hard to find parts. Instead of using my regulator, I could have connected the positive rail to the 5V of the Arduino and the negative rail to the GND of the Arduino and then slaved the power from the Arduino via a USB connection to my computer, that’s OK and it’s the easiest way to do it if you don’t already have a 5V regulated power supply. Also, you could have breadboarded the ICSP rather than using a dedicated circuit … but since I have them and I built them for this purpose … I’m going to use them!

Well … there you go, Tutorial #3 – Reading Digital (On/Off) Input converted for the ATTiny85 for your entertainment and my fun.

Check out the rest of the tutorials here.

Tuesday, 16 September 2014

ATTiny85 Tutorial 2 – Controlling 5 LED

This tutorial expands on the simple blinking LED by adding more LED to the board. One of the challenges with using the ATTiny85 is that there are far fewer pins that you can use to do stuff. This is, of course, also an advantage as it means that the ATTiny85 is much smaller and, therefore, more practical in small spaces. You have a greatly reduced footprint to shove into small appliances.

To keep to the spirit of the Freetronics tutorial, I have reduced the number of LED from 8 to 5, as that is the maximum number of pins that can be used without reassigning the RESET (PCINT5) pin. The RESET pin is able to be reassigned, however, changing it back to RESET requires high voltage programming and I’m not going into that here.

So, the connections and layout part.

Lesson 02 - Controlling 5 LED_bb

The pin scheme is fairly straight forward

  • LED 1 connects to PIN 5
  • LED 2 connects to PIN 6
  • LED 3 connects to PIN 7
  • LED 4 connects to PIN 2
  • LED 5 connects to PIN 3

The cathode of each LED connects to a resistor, each resistor connects to the ground rail.

The sketch is also quite straight forward. Instead of assigning the pin ID to a static variable, we are assigning it to an array and then iterating through the array step by step turning the LED HIGH and then, after the defined delay, back to LOW.

/*
  Control 5 LED
*/
int ledCount = 5;
int ledPins[] = {0, 1, 2, 3, 4};
int ledDelay = 125;

// the setup routine runs once when you press reset:
void setup() {               
for (int thisLed = 0; thisLed < ledCount; thisLed++)
  {
    pinMode(ledPins[thisLed], OUTPUT);    
  }
}

void loop() {
  for (int thisLed = 0; thisLed < ledCount; thisLed++)
  {
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed], LOW);
  }
  for (int thisLed = ledCount; thisLed > 0; thisLed--)
  {
    digitalWrite(ledPins[thisLed], HIGH);
    delay(ledDelay);
    digitalWrite(ledPins[thisLed], LOW);
  }
}

There were some errors in the Freetronics sketch that meant that copy and pasting was not practical. There was a trailing “\” character and the loop variable for the ledCount contained a typo. The above code works and has been tested … feel free to copy/paste it if you want … or just type it out, it isn’t long.

The code will result in each LED illuminating in turn for 125 milliseconds in a kind of scanning LED fashion.

Check out the rest of the tutorials here.

Monday, 15 September 2014

ATTiny85 Tutorial 1 – Control an LED

The first tutorial that pretty much everyone covers is the “Hello World” tutorial of physical programming … connecting a single LED to the microprocessor and causing it to blink.

This is a very simple project and the outlook is sunny.

For this tutorial, you will need to prepare your ATTiny85 with the Blink sketch that comes with the Arduino IDE. This sketch uses the Arduino Pin 13 as the output pin, however, the ATTiny85 doesn’t have a Pin 13. To hook up our ATTiny85, we’re going to need to work out which pin would be compatible with the Arduino Pin 13. So … what are the characteristics of Arduino Pin 13? Pin 13 kinda special, apart from being a Digital interface, it is also an SPI pin (MOSI – Master Out Slave In) for asynchronous communication … typically used for data connection, like when you are connecting your ATTiny85 to the ATMegaxxxx for programming. For this tutorial, you don’t need to access that functionality, but we are looking for a Digital pin on the ATTiny85

ATTiny85_Pinout

The above shows the pinout scheme for the ATTinyx5. We could use PCINT0, PCINT1, PCINT3, PCINT4 or PCINT5 (or … any pin that isn’t VCC or GND). For simplicity sake, we’ll use PCINT0.

Having decided on which pin we are going to use as output in our experiment the next step is to change the example sketch.

Open the example sketch File > Examples > 01. Basics > Blink in the Arduino IDE

IDE_LoadBlink

The sketch that is loaded is the basic blink sketch

The only change that needs to be made to the example sketch is the pin variable

So you change:

int led = 13;

to

int led = 0;

And then you can upload the sketch to the ATTiny85 (remembering to first set up the Arduino as an ISP as per the previous article (Arduino as ISP for ATTiny85).

When the sketch is loaded, you can pop the chip out of the ISP shield and put it in your breadboard as per the following diagram.

Lesson 1 - Controlling an LED_bb

By convention, I’m using the Fritzing example 5V regulator (with the added 9V battery) to show the input source. Practically, I use my 5V regulator board from my previous article in it’s place.

The ATTiny85 is oriented with the dot bottom left, make sure that you orient your chip and connections correctly.

A jumper wire connects PCINT0 to the LED anode and the LED cathode is connected to the GND rail via a resistor (I’m using a 220 ohm resistor, but you should use the correct resistor for your LED).

When the power is connected, the LED blinks.

That concludes the first tutorial. I recommend that you also read the Freetronics tutorial so that you can compare the ATTiny85 implementation with the UNO clone implementation.

Check out the rest of the tutorials here.

Sunday, 14 September 2014

Freetronics Eleven Tutorial to ATTiny85

Right-o … now that I have my Arduino to ATTiny85 ICSP working, it’s time to start working out the practical differences between the Arduino and the ATTiny85.

When I bought my Freetronics Experimenters Kit from Jaycar, the kit came with an Experimenters Guide (Experimenters Kit - Getting Started Guide). The guide, whilst basic, was very helpful and was quite good. The guide is designed to give the experimenter some confidence in the platform and their own ability, so … job done.

What I plan to do is to work through the 11 tutorials in the guide and apply them to the ATTiny85. Some tutorials have to be modified right from the get-go because of the simple fact that there aren’t as many pins on the ATTiny85 as there is on a UNO or UNO clone board. The one that I’m thinking of here is “Project 2: Controlling 8 LEDs”. Sure, you can control 8 LED with an ATTiny85, but the tutorial is about handling each LED from a single pin. This could be done using a shift register or charlieplexing, but that isn’t in the spirit of the tutorial, so instead this will be “Controlling 6 LED”.

I won’t be going over the ICSP and uploading sketches to the ATTiny85, that was pretty much covered in the Arduino ATTiny85 ISP articles.

I will preface each of the tutorials with the pertinent information from the original tutorial and show the converted breadboard layout and sketch from the perspective of the programmed ATTiny85.

Because of the absence of the UNO in the tutorial, it is expected that the breadboard will take it’s power source from a 5V regulated power supply. I recommend that, if you want to build these tutorials, that you also build that circuit (9V to 5V voltage regulator).

Basic with 5V Reg_bb

The first Tutorial “01 - Controlling an LED” is the simple blink sketch and really doesn’t need much explanation, however, I will be starting with this tutorial as a basic building block tutorial and it may prove useful to some.

I am also considering doing the same thing with an ATTiny84 so that there will be a source of these tutorials on the Interweb where people who are interested in starting out with the 84 and 85 can come and see the tutorials from the perspective of the platform that they are using.

Anyway … on with the show.

Paypal Donations

Donations to help me to keep up the lunacy are greatly appreciated, but NOT mandatory.