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.

Monday 27 October 2014

ATX Lab Power Supply – Plan

Well, my next project is a more reliable power supply for my bench. So far, I’ve managed my power needs by using a 9V battery, a 5V USB cable that I modified, or a AC power adaptor.

That’s been fine, to a point, but it doesn’t really give me the power that I need to supply multiple projects, plus, I’m forever having to set the power up to connect to my projects. I’ve made a couple of USB power cables and modified a couple of AC power adaptors that have the right DC power output, but I guess I want to go further.

I will be acquiring an old ATX PC power supply unit that I plan to modify to provide me with 3.3V, 5V, 12V and a variable power supply. The 3.3V, 5V and 12V will really just be a matter of minor modification to the ATX power supply. I intend to use an LM317 to build a variable supply from one of the 12V outputs on the ATX.

I’ll also build a new case for the power supply so that it both looks decent and is a bit safer. I don’t want to have an ugly and dangerous power supply on my desk, my darling wife would, most likely, object (truth is … so would I).

When I have the ATX, I’ll go ahead and void the warranty so that I can see how many of which value supplies I have to play with. I’ll also go through some testing to make sure that the on board supplies do what it says on the box.

According to Pinouts R U and Help With PCS the 20 pin Molex connection provides the following:

20 pin molex atx-psu-pinouts

3 x 3.3V, 5 x 5V and 1 x 12V. There are some other connections (like ground, power OK, and power on). I can use the 3.3V and 5V as they are, but I’ll need to do something with the 12V so that I can get 12V as well as 1.25V – 11V (I think … there is some power drop across the LM317, so I’ll need to test that).

I think that what I can do is provide a SPDT switch on the 12V rail to either give me 12V or power through the LM317. Ideally, I’ll need a voltmeter on the adjustable power rail so that I can see what power I’m dialling in.

The 12V rail will go out to the LM317 with a potentiometer and voltmeter. I will keep the cooling fan in the build so that power that is dissipated as heat can be managed.

I’ll drill a few holes in the front to put in some banana plug connectors through the case.

I’ve found some pretty nice designs online so far, so I’ll be able to simplify my design process somewhat.

Anyway, that’s the plan so far. I’ll follow up when I have the ATX and I’ll make sure that I record the discovery and design phases.

Monday 20 October 2014

AC Adaptor Power Supply – Acrylic Enclosure

This weekend I made an enclosure for my AC Adaptor. The requirements were pretty simple … make an enclosure that has holes for the power switch, potentiometer, input wires, output wires and for the nuts to anchor it to the base.

I also wanted the enclosure to be clear so that the LED power indictor would make the device light up when it was powered … I didn’t want to have to look for a single 5mm LED on a black enclosure, so I decided that it would be a good idea to make it from clear acrylic. It would also add to a 70’s kind of vibe, a.la. “Orac” from Blake’s 7.

Another reason that I thought that a clear enclosure would be good was that I had spent some time and effort in making the simple breadboard design uncluttered and “pure”, and I didn’t want to hide the electronics away from the world. It is what it is, and there is a certain aesthetic appeal.

So, with that in mind, I went and (carefully) hacked up some 5mm clear acrylic sheet. I did the rip sawing of the sheet using a jigsaw with a hacksaw blade (24 TPI – teeth per inch). I made a guide from a straight piece of pine that I had lying around and this gave me a piece that was about 10cm x 80cm. I then cut the work piece using a chop saw. I got some chip-out on the cuts with the chop saw because the blade was just a standard timber blade with 3 TPI. I’ll be getting a higher TPI blade for the chop saw when I can afford it.

After cutting the sides, base and lid, I then measured out where the holes should be, and the diameter of the holes. The Potentiometer needed a 6mm hole, the switch needed a 5mm hole and the holes for the wires and nuts were all 3mm.

Then i had to cut another top and another face piece because I had not accounted for the height of the breadboard inside the case (d’oh!). The breadboard sits on 4x12mm threaded nylon standoff spacers … I forgot the 4mm of nut that came through the bottom of the standoff.

I used an general purpose Tarzan’s Grip glue (the kind you use for gluing plastic models together). This kind of glue melts the plastic pieces together and forms a weld. You don’t want to use a cyanoacrylate (superglue) because:

  1. It doesn’t glue the pieces together well enough and
  2. It causes “ghosting” on the plastic … kind of a white smut on the surface that is very difficult to get off.

I then used some acetone to clean up the joints. You need to use some care with acetone in this case because it can also cause some ghosting and because breathing in the fumes is toxic. I dipped a cotton bud into the acetone and then rubbed the joints vigorously.

Then I sanded the edges until I was happy with the surface … I could have sanded more and I could have gone to a higher grit (I only went as high as a 600 grit). I didn’t want the joints to be invisible as I wanted them to catch some of the glow from the LED. This was going to highlight the edges and make them more of a feature.

Here is the end result.

Enclosure 01

With the power turned off … and

Enclosure 02jpg

With the power turned on.

At the moment, the top is just sitting on the enclosure. I want to make some acrylic hinges from some cut-off pieces so that the enclosure is all one piece.

The only real downside to using clear acrylic for the enclosure is that it shows up fingerprints very well … and I don’t want to keep cleaning it.

The next thing that I want to make for this is the bending jig for the heating element so that I can actually use it to bend acrylic. Well … that’s a project for later.

NOTE: After using this circuit with a 12V Adaptor, the potentiometer started smoking, so I would NOT recommend that you use it for anything beyond 9V. For 12V, you would need a higher resistance potentiometer at least.

Further Note: After more investigation, this is entirely the wrong approach for building a variable voltage supply. I’m now going to start looking at building one based on an LM317 transistor.

Thursday 16 October 2014

AC Adaptor Power Supply – Recycle – Part 2

CAUTION: Modification of AC Power Adaptors is potentially dangerous. Read the specifications on the adaptor and observe output and polarity. Mistakes with AC Power can kill you. If you are unsure of the specifications of the adaptor that you are tinkering with … throw it away and get one that you know. Do not do ANY soldering on the adaptor or it’s cable when the adaptor is plugged in. I take NO responsibility for your safety, that’s your job.

Okay, so I’ve repeated the safety warning … I’ve completed the breadboard edition of the circuit and, honestly, this is enough. I don’t need to make a PCB for this at all.

Power Supply - 01_thumb[1]

This is the top view of the supply. The power comes in from the left (at the moment it is connected to a 9V NiMH battery, but I intend to connect it to a 9V AC Adaptor). You can see the layout, it’s pretty straight forward.

Power Supply - 02

This view shows the arrangement more clearly. I have spaced everything to fit on a 50 mm x 70 mm prototype board. It could be smaller, but it really doesn’t need to be.

Power Supply - 03

I’ve pad soldered the components and used the component legs to bridge. It’s a pretty tidy solder job and I’m pleased with that aspect of the build.

Power Supply - 04

When the SPDT switch is thrown, the LED lights up to indicate that there is power running through the circuit.

When I built this on the solderless breadboard, I had the unattached SPDT pin connected to GND and another indicator LED connected to the wiper (Leg 2) of the potentiometer. There was also a connection from Leg 1 to GND in t he solderless breadboard version. When it was running, the 9V battery was getting very hot, so I decided to cut these elements from the circuit rather than try to work it out (I know, sometimes I’m lazy) … I figured that there was re-routed power going back to the terminal block (and on to the 9V battery). I was going to look at putting in an IN4001 diode to protect the power source … not sure if that would have any benefit, but I’ll re-breadboard it at some later date and report back and improve the circuit.

I probably should connect Leg 1 on the potentiometer to ground via a resistor, but what the hay … this configuration works out just fine. There isn’t much variation in the power output when you spin the dial though. With a charged 9V battery I get 8.9V through to 8.1V when turning the pot.

I plan to make an enclosure out of acrylic sheet and using the circuit to supply power to a resistive wire for a heating element.

AC Adaptor Power Supply – Recycle

NOTE: This project was a bit of a failure … I’m redoing this project using an LM317 instead of just using a POT to try to adjust the power. If you follow this project, you will only end up with a pretty circuit that doesn’t do anything very useful.

CAUTION: Modification of AC Power Adaptors is potentially dangerous. Read the specifications on the adaptor and observe output and polarity. Mistakes with AC Power can kill you. If you are unsure of the specifications of the adaptor that you are tinkering with … throw it away and get one that you know. Do not do ANY soldering on the adaptor or it’s cable when the adaptor is plugged in. I take NO responsibility for your safety, that’s your job.

In my previous article on power supplies for electrolytic etching I made use of an old AC Adaptor (wall wart) to provide power via a switch and potentiometer to an anode and cathode used in a simple circuit to an electrolytic etching bath. The adaptor recycle can be used for other purposes, and in fact I made a polystyrene hot-wire cutter using this same circuit. Now that I’ve used the project in a couple of different “tools” I suppose that it’s time to revisit the design and see what can be improved or changed.

My new application for this project is in a tool that will be used to bend acrylic sheet. There are a couple of interesting articles that can be found on various sites scattered across the interweb. I’m not going to list any here, they change too often. You can look at sites like lifehack and instructables for some pretty good examples of polystyrene cutters. The power supply is really what I’m interested in, so I’m going to focus on that for now.

Essentially, the AC Adaptor power is passed through a circuit adding a switch to make it easier to turn the power on and off, and through a suitably resistant potentiometer to allow the user to adjust the output power, effectively controlling the heating element (or in the case of the electrolytic etcher, the copper electrolysis anode). It’s also a good idea to install a power indicator in the circuit to improve safety (a visual indicator that there is current passing through the circuits output terminals.

So, in my case, I’m using this supply for three tools and two different types.

  • Heat:
    • Polystyrene Hot Cutter;
    • Acrylic Heat Bender; and
  • Current:
    • Electrolytic Etcher

So there is some versatility in the simple circuit.

Fritzing - Power with Pot and Switch_bb

The circuit above has two two pin screw terminal posts. The left-hand side is where the AC Adaptor will be connected to the circuit and the right-hand side is where the power will be output.

There are 6 parts (well 7 if you include the circuit board):

  • 2 x 2 pin screw terminals;
  • 1 x Red LED;
  • 1 x 220Ω resistor;
  • 1 x SPDT switch;
  • 1 x B 10kΩ potentiometer (the resistance value of the pot should be increased to 100kΩ if you are using adaptors between >9 and 16V, I’m using a 9V adaptor, so 10kΩ … larger than that and you should probably not be using the adaptor at all).

I have connected the input power to a SPDT switch. This is where we turn the power to the output off. Of course, the power to the circuit is still live, you need to turn the wall socket off to completely power the circuit off.

The 3rd leg of the SPDT connects to the power indicator LED, which is connected to ground via a 220 ohm resistor. Additionally, the 3rd leg of the SPDT connects to the Power (leg 3) of the B10K potentiometer. The Wiper (leg 2) of the B10K potentiometer connects to the positive output terminal.

The negative input terminal connects to the resistor of the power indicator LED (as mentioned previously) and to the negative output terminal.

Connecting the load anode/cathode is done via the output terminal. I have a couple of banana plug to alligator clip connectors that I use, but bare wire end to spade connectors or any other appropriate connectors should be OK.

This is a good project candidate for mounting in a project box. I’m planning on bending some acrylic sheet to make the project box for this circuit … or you could make a pretty one by adding an instrument panel like my Steam Punk themed Electrolytic Etcher panel.

Tuesday 14 October 2014

Prototype Embedded Electronics – Together

Now that I have completed the three circuits that I had planned to embed in the Steam Punk prop (Torch, Pulsing/Fading LED, LED Chaser) it’s time to put them together in a single main/sub configuration as they would be in the prop. I had to cheat a little here … I couldn’t find one of my male to male DuPont connectors and, rather than make a new one, I opted for the easier option of replacing the 2x2 SMD circuit with the 4 x 5 LED “Desk Light” circuit. In terms of testing the components together, this should really have no practical impact on the outcome. Sure, they are through hole components … and a lot more of them, so the only real difference from the perspective of testing the overall concept is that it will draw more power from the battery. In the embedded scenario, I need to rebuild ALL of the component circuits, so there really isn’t anything lost there.

I have connected a 9V battery to my trusty solderless breadboard and then connected each of the components to the power rails. The Torch and Pulsing/Fading circuits are connected to the 9V directly, whereas the LED Chaser is connected to 9V via a 5V Regulator (I opted for an early version of this as I didn’t need the optional LED power indicator).

The result is as expected … it all works just dandy. I should probably go ahead and work out power consumption so that I have an idea of how long the battery will last in the prop. I’m still toying with the idea of also embedding a battery charger circuit … but it is easy and cheap enough to use a commercial – “off the shelf” charger so I’m not going to bother with that … yet.

There are still more tweaks and optimisations that I am planning, but that’s for later.

I present to you the prototype embedded electronics of the Steam Punk prop …

Fiat Lux

Combined embedded electronic circuits for a planned Steam Punk Cosplay prop

DC Power Connector – Wiring and Testing

Last night I decided to repurpose an old 9V AC Adaptor for use in my electronics projects. The connector at the end was not suitable for my purposes, so I cut it off and soldered in a standard 2.1 x 5.5 barrel connector.

When I tested the power on the “completed” job, I noticed that I was getting none of the results that I was expecting.

Firstly, I was getting a negative value where I was expecting a positive, and secondly, the 9V that I was expecting … was showing 11.98V (let’s be gentle and say 12V). The AC Adaptor clearly shows that it is supposed to be 9V output … WFT? Also, the polarity symbol on the AC Adaptor shows that the sheath is supposed to be negative while the pole is supposed to be positive. I am annoyed (and rightly annoyed … with myself).

What I should have done was to perform some tests of the barrel connector first.

DC Power Connector (Male)

With the above diagram in mind, how can I test it? Simple …

Turn the multimeter on and switch it to continuity test.

Hold the black probe against the positive tab (that should be the short tab at the top in the diagram) and place the red probe into the positive inner jack. There should be a continuity buzz coming from he multimeter showing that there is a continuous circuit. Just to be sure, change the position of the red probe to the outer sheath of the barrel. There should be no continuity, so no buzz from the multimeter.

Now hold the black probe against the negative tab (that should be the long tab with the crimp tabs) and place the red probe against the outer sheath of the barrel. This should result in a closed circuit … so … buzz. Again, test that the negative tab does not connect to the inner jack by moving the red probe to the positive jack. While the final step isn’t really necessary since you have already tested continuity of this path for the positive rail, it doesn’t hurt to check it twice.

This test should reveal the way that the tabs on the back of the plug are routed and you should now know where you are soldering to.

PC Power Connector (Female)

Testing the terminal is a bit more fiddly. The post at the back of the terminal should be the positive rail, while the post under the terminal should be negative. On a three post terminal, the post on the side should close when the plug is inserted into the terminal.

I only care about the positive and negative connections.

To test this (at the moment, I’m talking about continuity testing) you will need to test each post and connection independently. The difficulty here lies in the fact that the spring will be making contact with the post, creating a circuit. You need to slide a non-conductive strip between the post and the spring clip. Something like a toothpick should do the trick.

When this is done place the black probe against the back post of the terminal and touch the red probe to the post in the middle of the socket at the front of the terminal. You may need to use alligator clips to attach the black probe to the rear post so that you can turn the socket over and poke around inside it. When you have contact with both the rear post and the post inside the terminal, you should get a buzz. Move the red probe to the spring clip inside the plug hole. You should not get a buzz here.

Attach your black probe to the post underneath the terminal and go back to probing the post and the clip with the red probe. This time, you should get a buzz when probing the spring clip and no buzz when probing the post.

Remove the non-conductive spacer from the terminal.

Thirdly, test that the plug and socket circuits are good. To do this, plug the male connector into the female socket. With the black probe attached to the short tab of the connector, probe the rear post with the red probe. You should get a buzz. With the black probe attached to the long tab of the connector, probe the post underneath the terminal. Again … buzz. You will probably also get a buzz at this stage if you probe the side post of the terminal.

Now that you know the polarity of the socket, you can happily match that up with your circuit.

You should note that I’m talking from the perspective of normal polarity, some circuits and some installations have these reversed … and that’s OK. The important thing is that you know which pole is which when you are connecting it to your circuit.

The most common use for this kind of connector (for home users and hobbyists) is to connect a 9V battery to a circuit board.

Monday 13 October 2014

ATTiny85 Shift Register – Sub Board Populated

This weekend I completed the preparation work on the LED Sub Board for the ATTiny85 Shift Register board.

The preparation work was simply cutting the board to shape and filing it down to make it round.

Tonight, I populated the board with the resistors (SMD 0805 120Ω), the pin headers and the 3mm blue LED. There really wasn’t much involved in this other than getting down and doing it. I could have made my live a little easier by spacing the pin headers more … but, you live and learn.

LED Sub-board 01

The trickiest part was soldering the SMD resistors. I did this by first clipping the resistor onto the board with a spring clip and soldering one side (the inside edge) and then going around and soldering the outside. After that, I soldered the pin headers and finally, the LED. I gave the board, LED and pins a test using the multimeter and found that the pin header for LED 2 was dry soldered, so I went over it again until I had a decent solder filet.

LED Sub-board 02

The top of the board looks pretty straight forward, nothing much to see.

This is still a prototype board, so I’m not terribly fussed. I’m happy with the shaping of the board, but, again, I could make my life easier by making this slightly larger. In the final version, I plan to have sockets instead of LED soldered to the board as the LED will be mounted on the inside of a Steam Punk prop … not held flat to a disc.

ATTiny85 Shift Register – Chasing LED Sub Board

Well, as far as a prototype goes, I think I’m happy with the outcome. I’ve learned some useful stuff about this type of circuit and I can use what I’ve learned when I’m making the version that will mount inside the prop, such as the spacing of the pin headers and the spacing and size of the screw mounting holes.

This project will probably end up as wearable electronics, I plan to mount the sub-board in opaque resin and make a badge out of it. I’ll also decrease the delay interval in the Arduino sketch to run roughly double the speed.

Thursday 9 October 2014

Testing Arduino Code

There are a couple of ways that you can test your Arduino code, not least of which is compiling your sketch and then uploading it to your microprocessor and making sure it runs OK … however, that doesn’t help in revealing any problems in the code.

If there are major problems then, sure, the IDE will whine and you’ll hear about it. But what if there’s a silent problem in your code that you can’t necessarily find sooner?

I’m currently looking at using a C language IDE (CodeLite) as a testing ground for my code. I haven’t gone too far yet, so there are likely to be some issues (for instance, the byte data type is missing in GCC … apparently, so I’m using the char data type instead).

My thinking is that I should be able to use the C IDE to reveal any problems in my code by sending the data that I want to monitor to stdout and use stepping to inspect the values and variables as it goes along.

Other things to consider … a standard C application starts with int main() rather than void setup() and you have to explicitly define and call the loop() function, oh there are other differences that I’m sure to find along the way, but for simply testing function blocks to make sure that the data that my function is sending (and to a lesser extent, the function structure and flow), can be inspected discretely.

Playing with my Shift Register code, I created the following main.c file

code_grab

and then I ran the code …

cmd_grab

showing that the values being passed are correct.

I can also create a couple of different functions that do the same so that I can then have a look at them from an efficiency, memory and timing perspective to decide on which way is the best for my application.

Anyway, it’s all learning, poking and prodding. I’m not sure how others approach testing their Arduino code … but then, I’m a software tester by profession.

Wednesday 8 October 2014

ATTiny85 Shift Register – Main Board Populated

Tonight, I populated the main board for this project and made the necessary connecting wires. You can see the previous post at ATTiny85 Shift Register – Etched.

I started out by making the 9 DuPont Female to Female 1 Pin wires, 8 yellow and 1 black. The yellow wires connect Q1 – Q8 on the shift register to (ultimately) LED 1 – LED 8 on the sub-board. This was mostly a process that took time. I cut the wires to 100mm, stripped 5mm from both ends of the wire, tinned the wires, tinned the DuPont connectors, soldered the wire to the DuPont connectors, slipped the pin housing onto the connector … job done. Although, 9 wires with a little finessing ended up taking me about 45 minutes to complete, I’m glad that job is done.

ATTiny85 and 74HC595 - Populated 02

The next task was to populate the Main Board with the 8 and 16 pin DIP and the pin headers … there aren’t any heat sensitive components here, so it was, again, just a process.

ATTiny85 and 74HC595 - Populated 01

Tested the board and connections with the multimeter, all happy.

ATTiny85 and 74HC595 - Populated 03

After that, dropped in the ATTiny85 and 74HC595

I still have to pull the ATTiny85 and upload the modified Shift Register sketch onto it. I plan to test the main board by connecting it to 8 LED and resistors on a solderless breadboard. But … I’m too lazy and I think that I’ve done enough tinkering today.

huh … what do you know … I’m not that lazy!

Testing the ATTiny85 Shift Register board

Putting the Electronics together – Planning

The main reason that I’ve been tinkering with electronics is my longer term goal of embedding some interesting lighting effects into a Steam Punk prop. That was where all of this started.

Now I have some decisions to make about which lighting effect circuits I want to include.

I want:

  • A pulsing/fading light acting as a power indicator and with a cool translucent – through hole cover (i.e. the Mac power indicator);
  • Chasing lights to come on when the trigger is pulled; and
  • A torch-light at the front of the prop

I’ve done a couple of pulse fade circuits, all with varying degrees of success (well … appearance). My two favourites are the 9V PUT transistor pulse fade that I found in the Make! book and the ATTiny85 pulsing LED that I modified from the Arduino as ISP sketch. The PUT version is neat and quite cheap, it doesn’t require any expensive parts (relatively), the most costly part is the PUT transistor (2N6027), but, at around $0.27AUD per transistor, I can live with that, this pushes the PUT version to around $0.73 per board. The ATTiny85 version has far fewer parts, but the ATTiny85 is much more expensive than a PUT transistor so it ends up costing around $2.48AUD.

The Chasing Lights is a bit of a no brainer, I’m going to go with the ATTiny85 + LED Sub-board option. The total cost of the board and sub-board comes to $4.37AUD.

Finally, I’m going to rebuild the 2x2 SMD LED Matrix project and change the layout a little. This was a great learning circuit for a couple of reasons and at a cost of around $0.49 it’s nice a cheap too!

There are a couple of additional costs, such as switches. For the chasing lights, I’ll either use a momentary switch or a lever switch, which way I go is going to depend on the way that I design the trigger for the prop. Apart from that, there’s about $1.00 worth of wire.

So, the embedded electronics come in at (PUT) $6.59 or (ATTiny84) $8.34 … plus the switches.

Electronics Block Diagram

The above block diagram shows the overall design using the ATTiny85 Pulse/Fade component while the one below shows the overall design using the PUT Pulse/Fade component.

Electronics Block Diagram - Alternative Pulse

With the PUT Pulse/Fade, I’ve dropped a switch and put the SMD LED onto the 9V power source, rather than the 5V regulated power source.

My next step from here is to put these circuit boards together on a prototype “board” to test the overall concept.

9V to 5V Regulator with Indicator LED

Well, I was going to call it a night a couple of hours ago, but I decided to make the new 5V Reg board.

This is pretty much the same design as the previous 5V regulator, it still uses an LM7805, still has one input but now has two outputs … mostly for mechanical stability when connected to a solderless breadboard. I have added a LED (and resistor) into the circuit so that the LED lights up when connected to power.

5V Reg with LED - Etched

Here is the copper side of the board. it’s now 20mm x 25mm, so it’s bigger than the previous version. The increase in size is to accommodate the additional output pin header, the LED and the resistor.

5V Reg - Idle

When the power is disconnected, the LED (and the circuit) is idle.

5V Reg - Powered

Connected to power, the 3mm LED lights up.

I’ve tested the two pairs of output pin headers and they show 4.98V, the input pin header shows 8.96V, so it doesn’t look like the LED is affecting the output voltage (of course it shouldn’t) this just means that the battery will not last quite as long … it should still last a long time though, the battery is rated at 200 milliamp hours, the actual bleed time is dependent on the load amps. Either way … new power regulator … cool!

Here’s the evolution of the power regulator so far:

1st version of the regulator board …

9V_5V_VoltageRegulator_01

2nd version of the regulator board …

New Version 9V to 5V Reg

Current version of the regulator board …

5V Reg - Powered

There’s still room for improvement for the board, I could go SMD and try to make it smaller, but then, SMD electrolytic capacitors aren’t much smaller and a SOT LM7805 isn’t that much smaller either … I think that I’m happy with the design as it is at the moment.

Tuesday 7 October 2014

ATTiny85 Shift Register – Etched Boards

Okay, so I’ve etched the boards for the ATTiny85 + Shift Register and the LED + Resistor sub-board.

ATTiny85 and 74HC595 - Etched

This is the main board, top left is the ATTiny85, middle is the 74HC595 and the row of 9 pins at the bottom is the interface to the sub-board.

This went fairly well, I tested all of the traces and found that the board measures up OK.

LED Sub-board - Etched

And, above is the sub-board with LED and SMD (0805) resistors coming in to two pin headers (4 pin and 5 pin) for the interface to the main board. As you can see in the picture, there is some misalignment in the transfer. This happened because I needed to overprint the board (the first run with toner transfer didn’t work very well). It also lead, more seriously, to three points on the board where the misalignment resulted in bridging. All of the bridges occurred on the SMD pads. I cut the trace with a scalpel and the scraped off the copper to make sure that the bridge was removed.

After testing the modified/corrected board with the multimeter on continuity, I found that I had eliminated all of the bridges and there were no gaps in the trace that would cause the board to fail.

Next, I’ll be drilling and filling.

Finally, here’s another 5V regulator (LM7805) circuit with a power indicator LED and resistor.

5V Reg with LED - Etched

This is just the same as the last one with two modifications:

  1. I’ve added a second set of pin headers to improve the mechanical stability of the board when it is plugged in to a solderless breadboard; and
  2. LED and resistor (far left in the above image).

Well, that’s it for tonight. Good luck and happy soldering!

ATTiny85 Shift Register – With Sub Board

Breaking the design of the circuit into a controller board and LED sub-board arrangement seems to be a bit … inefficient. Of course, this could be just because of my design.

Fritzing - ATTiny85 - Shift Register - 3_pcb

On this board there are just the ATTiny85, 74HC595 (Shift Register) and the necessary pin blocks for connecting it to the round LED sub board. There’re probably more efficient designs for this, but I’ve simply removed the LED and resistors and then re-routed the traces.

Fritzing - LED Sub Board - Round_pcb

The LED sub-board is probably more like what I wanted. At the moment, the 9 pin headers are aligned for main and sub-board simply connecting using a straight forward pin block pairing. However, I’m likely to connect the main and sub-board with jumper wires rather than male pin block to female pin block, so the arrangement of the pin headers on the main board are kinda irrelevant and I could make the design more efficient on the main board, for instance, I could have the pin header right up against the 74HC595, meaning that the routing would be much less of a dogs breakfast. That would also mean that I could re-orient the ATTiny85 and have the traces from that to the 74HC595 more straight forward too.

With that in mind … the arrangement of the main board should probably be more like the following.

Fritzing - ATTiny85 - Shift Register - 4_pcb

This is a much more straight forward design and doesn’t waste any space. The new design (above) is 40mm x 40mm, so I can save a bit of space using this layout rather than the one above. 1 wire to carry the GND and 8 for the Q0 – Q7 pins on the 74HC595 chip.

That should probably cover the design side fairly well. OK, so this is the design that I’m going to go with.

I guess the other thing that I like more about this design is that I can have a couple of LED sub-boards with different coloured and sized LED and play with the visual design of the board more.

ATTiny85 Shift Register – Plan

I’ve been struggling for a while to work out a design for an ATTiny85 circuit with a shift register and 8 LED laid out on a single sided copper clad PCB. My main issue has been with the overlapping of traces.

Well, today I think that I’ve created a design that will work.

Fritzing - ATTiny85 - Shift Register - 2_pcb

I’m going to start making this board tonight and see if my design is right and then I’ll start tinkering with the design. I want to make a circular chasing light on a @40mm diameter board. So far, my designs for this circuit have left a lot to be desired so I’ll see how I get along.

The main questions to be answered in this design are:

  • Can I re-arrange the LED and resistors around a circular PCB; and
  • Is the design sufficiently optimised.

Ultimately, the chasing LED circuit will be embedded in another device, so I need the PCB to be of an optimal size. Once the board design is proven, then I can jigger around with it some more.

Honestly, I don’t mind if the circuit doesn’t live up to my expectations, it’s all learning.

Of course, the alternative is a sub-board with the LED and resistors on it.

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.

Wednesday 1 October 2014

9V to 5V Regulated Power Supply – Revisit

Just a quick revisit on the 5V Regulated Power Supply circuit. When I made the previous version I oriented the output pin header facing up. This was done so that I would be able to componentize the circuit within other embedded projects.

After using the circuit a couple of times with solderless breadboard prototyping for the ATTiny85 IC, I realised that I had missed an opportunity. With the output header pins facing up, I had to use a female to male DuPont wire connector to connect the circuit to the solderless breadboard. If I were to change the orientation so that the output header pins were facing down, then I could connect the circuit directly to the solderless breadboard without intervening jumpers.

I made another of these handy little circuits and soldered the output header pins to the bottom of the PCB. There were no other changes made to the PCB at all, nothing!

New Version 9V to 5V Reg

After soldering it up, I gave it a test. Connecting the regulator to the solderless breadboard and a pair of jumpers on the +/- rails of the board and then to the multimeter on 20V power measurement, the regulator gave me a steady 4.98V (0.996 below 5V) so the circuit still works just dandy.

Then I connected a load circuit to the jumpers (again, my “go to” load circuit, the 2x2 SMD LED matrix), and of course it works just peachy. With the same voltage reading as the other circuit, I figure that there isn’t much need to do any more testing than this.

Job done … yay!

I could probably improve this design by adding another pair of header pins in front of the existing output pins. These additional pins would only be soldered to copper pads and are not part of the circuit, but would improve the mechanical stability of the sub-board when plugged in to the solderless breadboard.

Paypal Donations

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