Archive for July, 2011

AVR LCD Library

Well here is my library I threw together for interfacing the Jaycar QP-5512 LCD screen to AVR micro controllers. A couple of functions. InitiliseLCD, displayData and writeInstruction.


To use you need to include <util/delay.h> and define F_CPU. Have a gander at the usage of delay.h.
Considering we are passing in the ports and pins as addresses, it’s a little bit of pointer passing. But don’t get phased at all about that.

A slight example of calling the functions.
displayData(&PORTB, &PB7, &PB6, ‘c’);

Do a loop of that function call to print words! Easy!

The code is simple. Have a look for yourself.

For a wiring diagram, look back at this post.

Questions? Comments? Suggestions? Flick us a comment.


Remember last post I said I was going to play with the accelerometer on my TI board? Well, I didn’t lie too much…
I decided to wire a LCD screen up to the board so I could see the data from the accelerometer in real time. That was hard enough…As this post is detailing.

Two days.

That is how long it took me to realise 3.3V logic and 5V logic doesn’t play well together. Two of them.
Let’s take a few steps back and I’ll start from the start.

I wanted to play with the accelerometer on my TI board, but I like seeing what’s happening. The data in/out. What everything is doing. The awesome JFET debugger on the TI board helps a lot with that, but nothing beats a good old LCD screen showing what’s happening. So I thought, “I’ll just grab an LCD screen, hook it up and then play with the accelerometer”.
Good idea idiot.
Armed with my new 5V power supply (Which, turns out, did need the heat sink. That 7805 gets frikken hot) I set out to quickly hook up my LCD screen to my TI board.
For starters, it was a different LCD screen to the first one I had. So all the commands are different, the initialisation is different, the pins are different. After making a massive spaghetti mess of cables to connect the screen up I set out to write some code.
Enter first problem.
I don’t know how to code on TI microcontrollers. I don’t know the routines, the registers, the tips and tricks. Oh I know C syntax. I can code. But not on TI controllers. Just starting off and getting a simple code to compile and run was interesting enough. But I digress. After poking around in the example code that came with the board, I worked out how to set up the Data Direction Registers, well, the TI equivalent anyway.
I cracked out the code I used for the other LCD screen I used previously in my Bluetooth remote. The logic was useable. Had to play around with the pulsing of the enable logic for it to work on the TI compiler. Along with writing my own “delay_ms” and “delay_us” functions.
So. Technically, I have functions that should work. The wires are all connected together properly. Trust me. I had checked those wires about one hundred times.
Still nothing is working.
I couldn’t even get the LCD to initialise.

End day one.

I know!
I’ll hook the screen up to my ATmega8515 on my STK500 and see if I can get it working. Low and behold. It works. The screen initialises and prints text. (After much fiddling around and making an LCD header and source file, just for future use, I might post it up here once I have commented and cleaned it up a little.)
So what am I doing wrong on the TI board?
Move it back and try the new logic from the AVR program.
Still nothing. It’s not the contrast adjust. I play with that every time I try to get it work, tuning it to try and get some text to appear. So what the hell can it be?
Late at night after watching some Starwars, possibly episode 3, maybe 2, it dawns on me.

TI uses 3.3V logic.



That’s it?



End day 2.

This is damn “simple” project is now testing every part of my engineering mind, and it turns out to be a simple little thing like that? I am going to make this thing work if it kills me.
Right. Now I have established I need 5V logic for the LCD and my TI board outputs 3.3V logic, what can I use to bump it up?

A series of 7805’s? Pfft. No. That’s expensive and just silly. Also, The response time would be far too slow. Probably. I didn’t have any spare 7805’s to test it with anyway.

What I need is a way to use 3.3V to switch on 5V.

Hang on.
Isn’t that what transistors are for? Digital switches?(actually, they are current amplifying devices, but can be used as switches, and commonly are) Humm…. I remember playing around with this for a night. Where was that video I watched?

Right. There’s the kinda thing I need to do. How can I adapt that to work with logic? Think Phill! That’s all your mind ever does! Think!


Remember this post? It’s a switch! For logic! I’ll just replace the mechanical switch with the transistor! Genius!

A transistor array!

The actual transistors I am using are c1815. A small signal audio amplifier. Not really the most optimal for a transistor switch, but what I had with me anyway. Still works.

But hang on. This will invert the logic. This design makes the output active low with active high input. This had to be reflected in code, obviously. But if you do this hack method, remember to invert your output.

Right. Let’s get this baby working.

Look at that!

My pretty TI board and my transistor array are being nice together. After I realised I had to ground the R/W line on the LCD screen. Silly mistakes for everyone! I have enough spare!

So there you go.

After 3 and a bit days of fiddling around. I have a working 5V logic LCD screen interfacing with a 3.3V logic TI microcontroller.

Hope you enjoyed this epic post of silly mistakes. Proving, you can interface 3.3V logic with 5V logic.

EDIT: I had better point out, this is a one way logic converter. For output from the microcontroller only. You can’t read anything in from the screen using this method.

I still haven’t found my spring from my solder sucker. Curses!

Bench Power Supply

Well, I got off my arse and designed and built a little bench power supply. Just a quick little thing capable of outputting 5V @ 1A and 3.3V @ 1.5A (Assuming you have a wall pack capable of outputting that much current).
It has pretty much no over current protection or anything fancy like that. The only protection in it is what is built into the voltage regulators. As I said. It’s simple. Schematics!

As you can see, a simple LM 7805 and LM 317 configuration with smoothing capacitors. Pretty LEDs to show that its working, a couple of switches to turn each segment on and off as needed and input power from a wall pack. To calculate the resistance needed on the 317 to get your desired voltage, simple use one of the many online calculators. The input voltage can be anything above 7V if you want to use both voltages. If you just want to use the 3.3V line, 5V input will be sufficent.

Throwing it together.
Onto the breadboard I go! An electronics hobbyists best friend. Fairly simple to put together. Plug plug and plug, it’s all together!

Yay! The right voltages… After about half an hour playing around wondering why I was getting 0V all the way through. Turns out plugging in the 7805 the right way REALLY helps… That and grounding it… Man I am an idiot…

So, it’s all tested and working and whatnot. To the prototype board! Let’s make it a little more permanent. Again, fairly simple? Not when Phill’s been drinking!
For starters, the prototype board that I chose to use had the worst track layout I have ever seen. I spend almost an hour just planning how to get it onto the board! If I had been smart, I would have taken a photo of the tracks, but I didn’t think of that, so just imagine the worst layout of copper tracks you can.

So, everything has been placed. Time to solder! I am ashamed to say, this job was some of the worst soldering I have ever done… Shit was going everywhere… Doesn’t help that halfway through I lost the spring out of my solder sucker, So it became really hard to get rid of the excess solder everywhere. *facepalm* I still haven’t found it…It was on my desk, but then it wasn’t…
So I solder everything together. Plug in the power, and… Nothing. Again. Nothing. Tonight was just not my night.
Break out the old multimeter, trace the voltages through it…What do I find? 12V has sneakily joined up with the ground somewhere…
Keep looking. Where can 12 be getting through? Bloody hell. Half an hour later. I also find that I didn’t ground the 7805… again. Fix that up… Still nothing… Turns out I joined the wrong two tracks together underneath the 317. I connected the input and ground lines, instead of the ground and output line… I am on a ball tonight… Fix that. Viola! Working! Finally!

Now. What can I stick it in? The power supply you dirty minded fool. Look around for a suitable container. What do I see? A dead modem! Small, yet plenty of space for my little circuit. Get hacking with a drill and jigsaw blade. Cut some holes for the terminals and switches. Hot glue the circuit and LEDs in. Screw the terminals in. Pop in the switches. Easy!

Now, as you can see in one of the pictures, I have a heat sink to attach to the regulators, but as I am lacking thermal paste and little nuts and bolts to attach them to the heat sink, for now I’m just going to hope it doesn’t overheat. Shouldn’t unless I draw excessive current and have my input voltage rather high.

Also, you can see I made a little 9V battery adapter to make the whole power supply somewhat portable. You never know. Might come in handy one day.

Well. That’s that adventure over with. I now have a handy bench supply of 5V and 3.3V. Now I’m going to fiddle with the accelerometer on my TI MSP430 board from last post.

Keep it real.