Thursday, April 21, 2011

7 Segment Displays

As a part of my project to build a breathalyzer using the MQ-3, I needed a nice way of displaying how much drink you've had. I had some 7-segment displays in my box of stuff that I had bought previously. They are from futurlec. Datasheets can be found by googling 7DR8021BS.


2-digit 7-segment display (I accidentally blew the middle decimal point, which is why you cant see it - its blacked out with some texta).

These 7-segs use common outputs for each segment, and a separate input for each digit:


The segments are labelled as in the next image - I believe this is standard.


Since the outputs are common I had to switch between digit #0 and digit #1 really quickly while at the same time connecting the outputs to ground to make whatever digit I want display. I could have used a 4511 driver chip for this, but I still need some transistors to connect the output to ground. Also the 4511 only drives 7 segments (so no decimal point) so instead I decided to use a 595 shift register. Same amount of pins on my Arduino to drive it, but more outputs!

My initial design used a bunch of discrete transistors, but this got messy fast. Even though it worked, I wasn't satisfied. It also meant a HEAP of extra soldering if/when I put this on perfboard:


Original design - note the upside-down arduino to control it.


Too many transistors!


As I refined my design, I discovered that you can get a transistor array on an IC - the ULN2803a. This IC has a common ground, so it switches directly to ground - which is ideal for these displays.

When coding for a setup such as this, you just need to switch stuff super fast. The first thing I did was work out what number (in binary) represented each digit I wanted to display. Then you just turn off everything, shift the digit into the shift-register (to drive the transistors) and turn on one of your inputs. Then repeat. eg:

for(;;)
{
turn off both of your inputs (digit 0 and 1)
shift some data into the 595 chip to set-up the output transistors for digit 0
turn on input 0
sleep for a milli or something (not strictly necessary)

turn off both of your inputs (digit 0 and 1)
shift some data into the 595 chip to set-up the output transistors for digit 1
turn on input 1
sleep for a milli or something (not strictly necessary)
}

Theres obviously a bit more code around it than this, but you get the idea.

Wednesday, April 20, 2011

Arduino

Today I'm going to harp on about programmable micro controllers. Some of my older posts indicated that I was/am working on a computer-controlled pinball machine. That project is still going (albeit hasn't been worked on for a while) but while prototyping things and learning how TTL chips worked, I discovered the awesomeness of microcontrollers. I initially bought myself a Basic Stamp from parallax, which was good, although I had to program it using an RS232(serial) port, which I had a hard time finding. I had to resort to using an old laptop for this.


Basic Stamp

I learned some of Parallax's basic language and set about working out how to use 595 and 4094 and 165 and other chips that I would need. The 595 and 4094's are shift registers see one of my older posts for 4094, and wait for an upcoming post about the 595.

So things were good for a while and then on one day without warning, the magic smoke escaped from my basic stamp. God knows why, but it ended up being a good thing(tm). After some research I decided that an Arduino would be the way to go.


My Arduino (may or may not be a knock off).

I believe most Arduinos are made in italy (and say so) but mine says made in china. It could be a knock off - but who knows. One of the perils of being cheap and buying on ebay, i suppose. It's open source hardware so nothing dodgy took place, although I would have liked to support the nice people over at Arduino or wherever.

Anyway so an Arduino provides you with a bunch of IO pins that you can read/write from/to as well as some analog pins (which come in very handy when using an MQ-3 alcohol gas detector!). It's all programmed in C, using the wiring/processing library which abstracts the jesus out of port IO. I know this because I have recently successfully programmed an atMega8 chip (more about this later).

The moral here is, if you want to do anything with electronics, go out and buy yourself an Arduino. It's well worth it. Also get a breadboard and hookup wire.

Thursday, April 14, 2011

The Bluff Trail

Went hiking last weekend. It was fun. Starting near Howqua (past Mansfield) at 8 mile flat, we did the bluff trail circuit (details here).
This starts off as a moderate climb over some mountain along 8 mile spur and then down again.


8 Mile Spur views

Then the fun came when we had to climb The Bluff itself which is a huge mountain (1726m). Well worth it though as the views were fantastic - especially Mt Eadley Stoney to the east:



Mt Eadley Stoney

Climbing the bluff was quite difficult, there was some pretty serious rocks to climb up to get to the summit. Difficult with an 18kg pack on your back.

Slept the first night at the Bluff Hut which is a few k's from the summit of The Bluff. Handily, there were already some people there with a fire going for us. It then was massively windy and rainy ALL night - had to get a good nights sleep.


The Bluff Hut - early morning

The next day we travelled along the 16 mile jeep track (not for 16 miles) which was mostly down hill to the Howqua River. We missed the turnoff to the west to go along the river and ended up about a half k out of our way at Pikes Flat (no big deal, I always wanted to see Pikes Flat anyway).


Pikes Flat

Walked along the river to Ritchies hut for lunch (no pre-made fire this time).


Ritchies Hut

Then along the 'high track' back to 8 mile flat (the start/finish point of this circuit). There was the option of taking the 'low track' but there were some pretty serious river crossings (like up to my waist serious) that would have sucked.


High Track

Monday, April 4, 2011

Im blogging again

So after a reasonable hiatus in which I have done many, many things (including building and moving into a new house - yay) I'm going to start writing about stuff again.

In keeping with the amateur electronics-ey theme of this, my first post back is going to be all about the venerable MQ-3 Alcohol Gas Detector that I picked up a while back after reading some articles about it on hackaday and various other sites.

I picked a couple up from Little Bird Electronics (whom I highly recommend) as well as handy-dandy carrier boards:
http://littlebirdelectronics.com/products/alcohol-gas-sensor-mq3 and
http://www.pololu.com/catalog/product/1479 (i cant seem to find this on little-bird anymore though.)

It's pretty easy to wire up your own circuit which mimics the carrier board, but the carrier board makes life even easier. Ignore what the data-sheet says and use a 1k resistor (I think the datasheet says to use 200 or something, but I could be horribly, horribly wrong on that).

Solder your MQ-3 onto the carrier board - it turns out that there is no polarity so you can solder it on any way you like, and it'll just work. Add the resistor and a pin header to make life easy:



I bent my pin-header out a bit to make blowing in it easier - especially when cables are connected. Also there are 2 sets of spots that you can connect your resistor to. It's a bit hard to see, but if you look at the traces, it makes exactly 0 difference which set you connect it to.

Now the other thing I hear about the MQ-3 is that it needs to be 'burned' in. It has a little heater in it that runs off +5v. After turning the MQ-3, it needs to heat up. In normal use this should take around a minute to warm up and the reading to stabilise, but I read around the traps that you need to plug it in and turn it on for 24-48 hours to make it work more betterer (this is, I'm assured, a technical term).

Coming next: Ardunios, shift registers and 7 segment displays!