Showing posts with label ICSP. Show all posts
Showing posts with label ICSP. Show all posts

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.

Thursday, 2 October 2014

Arduino ATTiny84 ISP Shield – PCB – Part 2

Here is the completed Arduino UNO ATTiny84 ICSP (ISP) Shield that I have just completed.

ATTiny84 ICSP Shield 02

While soldering the board, I went through and tested each trace with the multimeter so that I wouldn’t have to go back later and find any dud connectivity. It turns out that there weren’t any shorted or broken traces this time, so it may have been a vein effort, however, I know that when I plug it in and run the circuit, that at least there aren’t any hardware failures.

The Arduino IDE test (using the UNO as an ISP) went without a hitch too, so it seems that all of my errors were caught early on and I ran out of problems … yay!

I am quite pleased with the two ICSP, they work well, have minimum components and an elegant design.

To recap on some of the design elements, below is the connections from the ATTiny84 to the Arduino UNO.

ATTiny84_To_Arduino

You can see that the connections for the ATTiny84 are essentially the same as  theATTiny85, just arranged differently.

I have been thinking about using a tri-coloured LED (common cathode) to replace the three 3mm Red, Green and Blue LED … but that can wait for now, I really don’t need the extra ICSP.

Arduino as ISP for ATTiny84

Following on in the same vein as my previous articles on Arduino as ISP for ATTiny85 IC, this article addresses the ATTin84. I refer you to the previous posts in the thread ATTiny85 thread for more information on plans, designs and etcetera, particularly Arduino as ISP for ATTiny85.

As I have mentioned in previous articles, there are very few differences between the 84 and the 85 in terms of pinouts. The arrangement and number of the pins are probably the most significant differences. The components required are virtually the same (you need a 14 pin DIP rather than an 8 pin … and obviously, you need an ATTiny84 IC).

ATTiny85_To_Arduino

Above is the pinout for the ATTiny85 IC and how it connects to the Arduino UNO. Below is the pinout for the ATTiny84 and how it connects to the Arduino UNO.

ATTiny84_To_Arduino

The differences between the two chips mean that there is some significant difference in the arrangement of the PCB that I designed for the ATTiny85 but the footprint is nearly identical and the ArduinoISP sketch that comes with the Arduino IDE needs no modification at all.

The Blink sketch also does not need modification from the already modified ATTiny85 version of the sketch, however, instead of connecting the LED to pin 5 (PB0), we are now connecting to pin 2 (PB0). Well … I still need to verify that once I’ve finished building the ISP and then breadboarded the ATTiny84 IC in the same test configuration as the previous article. But from my current reading, that should be just Jim Dandy.

Tuesday, 30 September 2014

Arduino ATTiny84 ISP Shield – PCB – Part 1

Following on from my ATTiny84 ICSP Arduino Shield Plan article and in the same vein as the Arduino ATTiny85 ISP Shield articles, I am now in the process of making an Arduino shield for programming the ATTiny84. This is the 16 pin miniature Atmel microprocessor.

ATTiny84_Pinout_thumb1

The above shows the pin configuration of the ATTiny84 that the shield will interface to the Arduino. The relevant pins for ICSP control are Vcc, GND, PB3 (RESET), PA4 (USCK), PA5 (MOSI), and PA6 (MISO).

Once again, the design makes use of the Arduino Pins 7, 8 and 9 for PRG, ERR and HB indicator LED, so while the arrangement of pins is different, the function and interface to the Arduino UNO is the same.

Fritzing-ATTiny84-ICSP_etch_copper_b

The above image is the mirror reverse copper bottom layer converted to a jpeg file. And below is the toner transferred PCB that was created using the above (although, I’ve used the raster PDF version rather than the converted bitmap). Last night I discovered that I got this wrong. The copper trace on the bottom of the PCB should not be reversed. Make sure you print it out correctly. I still get this wrong from time to time.

ATTiny84-ISP-Shield-01_thumb1

I’ve since given the PCB a bit of a scrub with a wet thumb to remove the remaining paper residue and gone over the traces with a medium Staedtler Lumocolor marker to improve the resolution of the traces and pads.

Now all that remains is to etch the board and start populating it in the same manner as the ATTiny85 version.

I also made another 9V to 5V regulated power supply. The only difference that I am making to the new 5V reg is to orient the output +/- on the bottom of the PCB so that I can plug it directly into a solderless breadboard (meaning that I don’t have to chase wires from the reg to the board … more elegant, I think).

9V---5V-Regulator_thumb

Again, scrubbed with wet thumb and then retraced with the marker to give a better resist for the acid bath.

In case you are interested … here is the bitmap copper bottom mirror for transfer toner.

Fritzing-9V-to-5V-Regulator_etch_cop

Well … that’s it for me, tonight.

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.

ATTiny85 ISP For Transfer Printing

Here are the toner transfer images for the Arduino to ATTiny85 ISP.

These images are unscaled so, when you print them, make sure that you print them without scaling (make sure your printer isn’t going to make the image “fit” the page.

The mirrored copper bottom of the board.

Fritzing ATTiny85 ICSP_etch_copper_bottom_mirror

and the silk top of the board.

Fritzing ATTiny85 ICSP_etch_silk_top

I’ve printed from the PDF output from Fritzing, so I cannot guarantee that these will work properly. I would recommend that you print the copper bottom out and then see if it matches up with the pin outs of the Arduino (or clone) that you are using.

These images relate to the Arduino ATTiny85 ISP Shield PCB article.

Saturday, 13 September 2014

Arduino ATTiny85 ISP Shield – PCB – Part 3

Alrighty, following on from my previous post (Arduino ATTiny85 ISP Shield - Part 2), I’ve discovered that the trace on my board for PB1 to Pin 11 was faulty (the toner transfer wasn’t all that good). This resulted in the Arduino reporting an incompatibility error when using the Arduino ISP sketch to upload a sketch to the ATTiny85.

The solution was to “draw” solder along the trace to fix the continuity.

To do that, the copper is heated with the soldering iron and the flux makes the solder to stick to the trace. I call it “drawing” because you are kinda drawing solder on with the iron. Where the copper has pitted too much, the flux doesn’t bond to the copper very well, so I had to go over the trace a couple of times to get a reasonably thick solder line.

I went over the trace a couple of times and built up a continuous line of copper across the break in the line and tested the continuity a couple of times until I got a good signal from the pin to the socket.

The next thing that I did was that I went over the entire board and patched bit’s that looked a little dodgy and where the solder fillets were not quite good enough.

Finally, I plugged in an ATTiny85 chip, connected the shield to the UNO (this time I used the Freetronics Eleven clone), connected the UNO to my PC and launched the Arduino IDE.

First, I loaded the Arduino ISP sketch to the UNO and then I changed the board to ATTiny85 (1MHz clock) and the programmer to the Arduino ISP setting and uploaded the blink sketch to the ATTiny85.

The LED all lit up at the correct time and the IDE reported the usual avrdude miss-error … I am now a happy camper. The design worked, the production of the board worked and finally, the upload of the sketch to the ATTiny85 worked too … woo-frickin-hoo!

Thursday, 11 September 2014

Arduino ATTiny85 ISP Shield – PCB – Part 2

Okay, I’ve now got some etchant, yay!

I tried to use the old etchant, but it was not working well at all. I went and bought some peroxide and some hydrochloric acid. The acid is from the same company that I usually buy, but now it seems they’ve added some iron salts to it (it’s a brick cleaner) and that results in the acid turning red when it mixes with the hydrogen peroxide. It still etches well enough, so, no harm. Interestingly, the hardware store no longer sells the 500ml bottles, their smallest bottle is 2.5L.

Anyway, I etched the board (and another so that I wasn’t wasting the etchant) and it turned out pretty well. I’ve also learned that agitating the acid bath makes it work better (faster) and the etch took just under 10 minutes.

ATTiny85_ISP_ShieldCopper_01

I then went ahead and did a transfer of the silk side.

ATTiny85_ISP_ShieldSilk_01

Which looked like crap.

So I came up with the idea to simply print the silk out and glue it to the top face of the PCB. I painted on a watered down solution of PVA first and then laid the paper on the board, next, I painted the PVA over the top of the paper too, so that it would wear better.

ATTiny85_ISP_ShieldSilk_02

Now I can actually read the silk side better. Nice. I don’t know that it will stand soldering very well though.

ATTiny85_ISP_ShieldPinsBeforeSolder

The pins were put into the board and the plastic blocks were slid up the headers to allow space for soldering.

ATTiny85_ISP_ShieldPinsAfterSolder

After soldering, the plastic blocks were returned to their previous position.

ATTiny85_ISP_Shield_R3Fit

I then tested that the pin headers matched up correctly with the Freetronics Eleven r3 (Arduino clone). They fit nicely, so it’s on to populating the board.

ATTiny85_ISP_Shield_Populated

I started with the resistors, then the 8 pin DIL and finally the LED. There was a bit of a problem with the LED, but it doesn’t stop the board working as an ISP. Actually, two problems. 1) the copper came away from the board, and 2) I got the LED backwards (face palm).

ATTiny85_ISP_Shield_UnoFit

Next, I plugged the shield into the Arduino UNO R3 (genuine) and it fitted well too.

I plugged it all in, loaded the Arduino ISP sketch onto the UNO and then tried to load the blink sketch onto the ATTiny85. No success. My multimeter is in another state at the moment, so I can’t figure out where the problem is. Oh, well … I’ll wait until next week to test the board properly and find out where I went wrong.

Well … I’ve made another PCB for this circuit (with the LED around the right way) and I no longer get the sync error, so that does make a difference. I’m getting an invalid signature error on the new board so it looks like there may be a continuity error somewhere. That’ll definitely have to wait until I’m with my multimeter again.

Now that I’ve done a continuity test of the circuit with the multimeter, I’ve found that the MOSI connection (Arduino Pin 11 to ATTiny85 PB1) is broken. I’m going to need to either solder over the break or get a conductive pen to fix it. Jaycar has a silver conductive pen for $30 … it seems a bit expensive. I think that I’ll go with solder.

Wednesday, 10 September 2014

Arduino ATTiny85 ISP Shield – PCB – Part 1

As promised in Arduino as ISP for ATTiny85 – PCB Revisited, I have transfer printed the design onto a FR4 single sided copper clad board using the modified design.

ATTiny85_ISP_ShieldPCB_01

There were some missing bits in the transfer (as happens from time to time), so I went over the entire trace with a fine Staedtler Lumocolor permanent marker. The Lumocolor is really only ever a backup to toner transfer printing, but I have had some pretty good results using both of them before (Resistance is Not Futile!). You can also see that I’ve filled in the soldering points, that’s so that when I solder, the fillets are stronger (in my humble opinion).The above photo is not too bad, I’ve used a bright white overhead light to illuminate the subject, otherwise it looks like this …

ATTiny85_ISP_ShieldPCB_02

Anyway, enough talk of photography. I didn’t get around to buying any etchant … too poor at the moment, so it’ll have to wait. However, I decided to use some “old” etchant that I haven’t thrown away yet. It should still work, it will probably just take longer and need more agitation than a fresh batch. I guess I’ll find out.

I’ve also printed out the silk layer for applying to the other side. The trick with this is that the copper layer is printed as a normal image, whereas the silk layer is printed as a mirror image. That way, when the two are transferred, they are oriented correctly.

When (if) the etch is finished, I’ll clean the PCB down (acetone and then isopropyl alcohol) and transfer print the silk layer on the top of the PCB and add the pictures of the progress to this article.

Now it’s back to watching telly while I wait for the etch to bite.

Arduino as ISP for ATTiny85 – PCB Revisited

I have revisited the PCB design for the ATTiny85 ISP shield after trying it out a couple of times.

My design goal was to create a shield module for my Arduino R3 that I can use to program an ATTiny85 and that makes use of the indicator LED that are included in the ArduinoISP sketch (that comes with the Arduino IDE).

The bill of materials is fairly small and should be fairly inexpensive.

  • 1 x 8 Pin DIL socket ($0.17)
  • 1 x ATTiny 85 chip ($2.00)
  • 3 x 3mm LED (green, red, blue) ($0.12)
  • 3 x pin headers (2, 4 and 6 pin) ($0.12)
  • 3 x 220 Ω resistors ($0.03)
  • 1 x  40 x 53.5 mm copper clad F4 board ($0.17)

For a total of $2.61 (based on the cost of purchasing these items from eBay).

I plan to use this over and over again, so the cost of the ATTiny85 isn’t really part of the bill of materials, but I’ve included it for completeness sake.

Fritzing ATTiny85 ICSP_pcb

Also, there are some header pins that are only included to give the board a bit more mechanical structure (Arduino connections to pin 6, 3.3V and a GND connection). If you wanted to, you could save yourself $0.03 and not include them, but the shield would be wobbly.

While designing the PCB, I had the Arduino R3 part on in the design so that I could align the header pins correctly. I’ve printed the design out so that I can confirm the alignment. Also, if you really wanted to, you could remove the 3 x LED and associated 220 Ω resistors, but again, why not use them?

The PCB is single sided, so all of the traces should end up on the bottom of the board. The thing that I’ve been struggling with is that the header pins are soldered into the bottom of the board. This makes it a bit challenging to solder as the plastic block for the header pins will make contact with the copper side of the board, making it more difficult to solder. I will push the pins further into the plastic block and put the block on the component side of the PCB. However, that means that the solder fillet will interfere with the insertion of the pins into the Arduino. All that that really means is that the board won’t sit flush against the Arduino … meh.

I’ve put big friendly text on the PCB so that it is all pretty lookin’ when I’m done.

The solderless breadboard edition of the ATTiny 85 / ArduinoISP works pretty well, so I’ll be starting this project tonight. The only thing holding me up at this stage is that I’m out of Hydrogen Peroxide and Hydrochloric Acid at the moment, and I have to go to the Chemist and the Hardware store to restock (bummer). Well, the plan for tonight is to do the transfer printing of the PCB copper side. I won’t do the component side as it will just smudge when I use acetone to clean off the toner from the copper side.

Tuesday, 26 August 2014

ArduinoISP – avrdude

For those of us that have been receiving the avrdude error “” when uploading sketches using the Arduino Uno as an ISP, I have found the following modified version of the ArduinoISP.ino.

I’ve had a look through the sketch and it would appear that the main difference between the two is the inclusion of the SPI library in the header and then later in the sketch setup, the SPI library is included.

Unfortunately, the version number in the ino file is still 04m3, it would have been nice to change that ;) but, woteva.

I would also like to change the pin assignment for the LED indicator lights as there is a lot of cramping around pins 13 – 10 … it would be nice if the LED pins were outside of this area. I’m going to change the pins to

// 3: Heartbeat   - shows the programmer is running
// 2: Error       - Lights up if something goes wrong (use red if that makes sense)
// 1: Programming - In communication with the slave

#define LED_HB    3
#define LED_ERR   2
#define LED_PMODE 1

Pin 3 on the Arduino is PWM so it should still work for doing the heartbeat pulse, hopefully it doesn’t conflict with something I’ve missed.

image

The above Fritzing diagram shows the wiring layout using pins 3, 2, and 1 for the LED indicators and assumes that the sketch has been changed accordingly.

I’ll make the changes tonight and try to reload the blink sketch to the ATTiny85 and see if there are still any avrdude errors appearing in the IDE.

Okay, so I’ve tried it with 3, 2, 1 and it appears that 1 is interfering with TX, so I’ve changed it to 3, 2, 4 instead, now the new ArduinoISP sketch has loaded successfully, it’s on to loading the blink sketch onto the ATTiny85.

No … that didn’t work …

image

back to 9, 8, 7 for the monitoring pins. Still a no go … so it’s back to the original ArduinoISP.ino and just deal with getting the avrdude error … how disappointing … I’ll work on that more later.

UPDATE: I’ve looked into this problem some more and it appears that there may be a fix to the avrdude.conf that could resolve the issue. Check out my article AVRDUDE PAGEL and BS2 for more information. I will be updating that article when I have tested the suggested fix.

Arduino as ISP for ATTiny85

Following on from my previous post (ATTiny85 with Arduino Uno as ISP), I thought that I would have a crack at explaining the method of using the Arduino as an ISP for an ATTiny85.

The first step that I missed, the one that I had a lot of trouble finding, was configuring the Arduino UNO as an Inline Serial Programmer. This is really quite an easy step to complete and doesn’t require anything other than the Arduino UNO, the USB connection to your computer and the IDE.

Connect the UNO to the computer using the USB cable and launch the Arduino IDE.

When the IDE is open, click File > Examples > ArduinoISP. This sketch comes with the IDE, so there isn’t anything to download (so long as you already have the IDE).

In the comment block, the sketch contains the information that you need to connect a device serially to program it.

// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name:    not-mega:         mega(1280 and 2560)
// slave reset: 10:               53
// MOSI:        11:               51
// MISO:        12:               50
// SCK:         13:               52

It also gives you some other information so that you can display the progress of the sketch load from the Arduino.

// Put an LED (with resistor) on the following pins:
// 9: Heartbeat   - shows the programmer is running
// 8: Error       - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave

In addition to the connections from the Arduino to the ATTiny, it really does make sense to add in a couple of LED and resistors to show that the communication between the two is happening and the real time results. I for one am going to go back to my simple ISP PCB design and add in these LED. This is really something that I should have been doing all along.

When the sketch is loaded onto your Arduino, the next step is to connect your ATTiny85. I have simplified the connection diagram here.

ATTiny85_To_Arduino

Connect the ATTiny85 to your Arduino UNO according to the diagram and then connect the LED to the Arduino for real time monitoring of the UNO.

Load the blink sketch into the IDE and change the Board (Tools > Board > ATtiny85 with 1 MHz clock).

The Programmer should be Arduino as ISP (Tools > Programmer > Arduino as ISP), so change that too.

The example Blink sketch has pin 13 configured for the LED. There isn’t a pin 13 on  the ATTiny85, so you will need to change it to something else. For example, Pin 5 on the ATTiny85 maps to PB0, change the sketch to use PB0 instead:

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 0;

Save the sketch (File > Save) and give it a filename that indicates that it is for ATTiny85.

At this point, you could connect an LED to pin 5 of the ATTiny85. Connect the long leg (the Anode) of the LED to pin 5 and then the short leg (Cathode) to a resistor, then the other end of the resistor to pin 4 of the ATTiny85 (Ground).

So far, we have programmed the Arduino UNO as an ISP and connected the ATTiny85 to our ISP. We have also connected the load to the ATTiny85 so that when we’re done, the LED will blink.

Right … upload the sketch (File > Upload Using Programmer or Control-Shift-U). You should see the LED on pin 9 and 7 of the Arduino flashing and then … the LED attached to pin 5 (PB0) of the ATTiny85 will start blinking.

You can expect to get the avrdude error that everyone tells you is OK – “avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85”. At this stage, that kinda means that it all went OK and your sketch is loaded … the proof should be that the LED is blinking on Pin 5 (PB0).

Job Done.

The ArduinoISP sketch handles the reset function of the Arduino, so there is no need to connect a resistor or capacitor across the Arduino RESET pin.

I plan to return to the avrdude error, I’m sure that this is just a configuration issue with boards.txt, but we’ll see.

Hopefully, you will find this article and follow it rather than the plethora of other articles that were probably right for previous versions of IDE/Arduino. Good luck, and watch out for those hungry, hungry hippos.

Monday, 25 August 2014

ATTiny85 with Arduino Uno as ICSP

Well, that was frustrating. I received 5 bright shiny new ATTiny85 from eBay while I was away on a business trip so I couldn’t play with them straight away. That was one minor piece of irritation.

I returned to my apartment where I have all of my electronics gear and got ready to play with the ATTiny85 (I also received 5 x ATTiny84 and 2 x ATMega328P … so there are lots of new toys to play with) and started to play.

I followed a couple of tutorials online and connected my Arduino Uno to my ATTiny85 and then attempted to load the blink sketch (the “Hello World” of physical programming), only to receive the cryptic and unhelpful “avrdude stk500_getsync() not in sync resp=0x00” message in the IDE.

Of course, I searched the Interweb for solutions to this problem but there wasn’t much that was helpful. Many opinions about the wrong USB driver, the chip inserted incorrectly, the presence (and absence) of a capacitor to expiate the Reset on the Uno … all useful for the specific problems that others were facing, I guess. I then stumbled upon an instructable by mr_mac3 (Turn Your Arduino Into and ISP) where the author, very helpfully, includes the step that I was missing. The step, you may ask? Which Step? Well, dear reader, the step where you make your Arduino an ISP (or ICSP if you want).

The step that I was missing was simply that, before you can program the ATTiny85 from the Arduino UNO, you have to load the Arduino ISP sketch onto the Arduino UNO. Holy Schemolly, what an ass basket! Once this step was completed, the Arduino UNO worked as an ICSP.

I had a couple of other issues, like rather than routing the power and ground via the +/- rails on the prototype board, I ran them straight to the correct pins of the ATTiny85 (that also made a difference). With the UNO that I’m using and the version of the IDE, there wasn’t any need to bypass the reset … that happens in the Arduino ISP sketch.

ATTiny85_01

ATTiny85_02

After the Arduino ISP sketch was loaded, I loaded the new sketch (the example Blink)I changed the Board to ATTiny85 with Internal 1 MHz clock and left the programmer on AVR ISP and changed the LED pin to 0. Next, I compiled the sketch and uploaded the sketch to the ATTiny85. I received the obligatory “avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny85” message that I happily ignored and then connected my 2x2 SMD LED to ground and to the ATTiny85 pin 0 and, presto … blinky goodness was found.

Next, I loaded my sinusoidal fade sketch (modified from another tutorial) and ran it on the ATTiny85 … again, success! Woot!

Now that I have succeeded in loading a sketch onto the ATTiny85 from the Arduino UNO it’s on to the PCB version of the rats nest.

Monday, 11 August 2014

ATTiny85 ICSP Arduino Shield – Plan

 

Following on from my plans with the ATTiny84 chip, I’ve also ordered some ATTiny85 chips from eBay.

Like the ATTiny84, building an ICSP is going to be useful for programming the chip (ATTiny84 ICSP).

The ATTiny85 has 8 pins, rather than the princely sum of 14 pins with the ATTiny84.

ATTiny85_Pinout

The location of the VCC, MOSI, MISO, Reset, Clock and GND pins are almost completely different from the ATTiny84, so the layout of a ICSP for this chip is also … entirely different. There are some … unfortunate … crossing over of pins that makes this design a little more challenging.

I’m using a couple of 0Ω resistors as jumpers in this design, I could have just used some more jumpers, but, what the hell.

Fritzing ATTiny85 ICSP_pcb

I will certainly be bread-boarding this before I commit to making a PCB for it, but, so far, here is the plan based on the pin-out that I have copied from the ATMEL ATTiny85 data sheet.

When you compare the ATTiny85 pins with the ATTiny84 pins:

ATTiny84_Pinout

There are a few challenges, but it is still similar enough that it isn’t completely incomprehensible.

Now that I’ve received the chips … I just have to wait for a fortnight before I can have a good play (the tyranny of working in a different state from where I live … like THAT isn’t becoming a serious pain in the arse).

Tuesday, 29 July 2014

ATTiny84 ICSP Arduino Shield – Plan

A side issue for the ATTiny84 is loading sketches from the Arduino IDE. The approach that I have seen in several guises is using an Arduino Uno to program the ATTiny84. 42 Bots has fairly common design (from what I have seen on the Interweb) - Programming ATTiny84/ATTiny44 With Arduino Uno.

The approach appears to be consistent with several other designs. The main trick is loading the Master Tiny board definitions into the Arduino IDE. I had a bit of a hassle with this as it seems that the IDE has to be completely shut down and restarted to recognise the new hardware.

As it is likely that I’ll want to reproduce this at some stage, I figured that it would be sensible to create a shield for my Arduino that I can drop the ATTiny84 into the DIP socket, transfer the program and then pop the MCU out. I’d then drop the programmed ATTiny84 into my live circuit and continue.

From:

Programming an Attiny84 or Attiny44 with Arduino Uno

I got:

Fritzing ATTiny84 ICSP_bb

as a wiring diagram … and from that it becomes:

Fritzing ATTiny84 ICSP_pcb

There really isn’t much to the board other than it’s pin locations aligning with the sockets in the Arduino Uno. That, and the 10uF capacitor terminating the UNO Reset pin.

I’ll make this up as a PCB so that I can simply attach it to the UNO as a shield and, I’m away.

Paypal Donations

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