WiFly RN-134 Breadboard Testing

I’ve mentioned before that I bought one of these RN-134 “SuRF” boards from coolcomponents.co.uk. My aim is to write some code for AVR microprocessors that will be able to POST data to a service on the web. Maybe I could even get it to send ebMS 3.0 messages. I reckon it would be cool to be able to send an ebMS 3.0 message without needing a computer. Anyway, I digress...

But ... before I jump in and start writing AVR code, I wanted to test my WiFly board. It has taken me some effort to get this procedure working, so I thought that I had better blog it – before I forget. Then, when I buy another WiFly, I can come back to this page.

To send commands and data to the WiFly I’m using TeraTerm (Windows Hyperterminal has problems with the WiFly, apparently, so don’t use it). Oh, and I’ve done all this on Windows 7.

To connect to my PC, I’m using one of these - mainly because I had one lying around. It gives me a virtual com port on my computer and exposes TTL serial signals to my breadboard. Since I’m just testing, I don’t want to solder anything to the WiFly board, so I’m going to use the WiFly’s RS232 interface, the board already has header pins for it, like this:

Wifly RS232 port

Pins 5 and 9 of this RS232 interface can go directly to the GND and 5v pins exposed by my USB-to-serial adapter; this will supply power to the WiFly. But the RX and TX pins expect RS232 voltages (not the TTL signals coming from the USB adapter). Enter the MAX232 chip which will convert the signals for us:
WiFly MAX232 connections
Pins R1IN and R2IN are connected to my USB adapter, whilst R1OUT and R2OUT are connected to the RS232 headers on the WiFly board. Now we have all this in place, we should be able to fire up the WiFly and connect to it via the virtual com port on the PC.

Open TeraTerm and make a serial connection to COMx. The serial settings should be 9600 baud, 8 data bits, no parity, no flow control, 1 stop bit. You should get a connection.

Type ‘$$$’ and we should get the ‘CMD’ message returned from the WiFly. Tip: type three $ signs in quick succession, don’t do what I did and pause between each key press. The WiFly expects this string to be entered in a short space of time.

OK, we’re in. You can see all the default settings by typing:

get everything<enter>

...and the WiFly should list back all the settings to you. They should match these default settings.

So... what would you need to change, to join your wifi network? Enter these commands:

set wlan ssid [your ssid]<enter>
set wlan key [your 128 bit wep key]<enter>
save<enter>
reboot<enter>

Tip: when you change something, don’t forget to type ‘save’. Your changes will not be written to the configuration unless you use the save command!

Now, the WiFly should restart and you should see it connected, assuming your wifi has DHCP. NOTE: I’m assuming 128-bit WEP, you’ll have to adapt this procedure if you have other security settings on your wifi.

You should now be able to find out the ip address of the module on your network. Type ‘$$$’ again to get back into command mode, since we’ve rebooted the WiFly. Now enter:

get ip<enter>

The device should list back the details of its ip address. Now you can ping it from a PC on your network. Hopefully you’ll get responses back and know that the device is connected!

I’ll try and make another post describing how to get the WiFly to return the html source of a webpage over the serial port, but for now I’ve done enough documenting...

NOTE: I did not find the documentation for the WiFly to be the best, I would have liked to see a test procedure like this included. However, before I bought the WiFly I asked Roving Networks some questions via e-mail and they came straight back to me with responses. This is amongst the best support I have ever received from any manufacturer. Encouraged by this I went ahead and bought the device. I’m pleased that I did – this board is a great product. People at Roving Networks: you have my thanks.

WiFly 802.11 b/g Super Module

WiFly Module

I've bought one of these WiFly modules from coolcomponents.co.uk.  It's great!  I'm in the middle of documenting my set up and test procedure, so that life will be easier the next time I set one up.  I have had it acting as a web server (serving up simple pages that were sent to it via RS232).  I have also got it to read other websites and send back the html source over RS232.  Not bad, my next step will be to connect it to an ATmega168 and have some code running on the web without the need for a computer.

So ... I'll post more about that later.

Microprocessor virtualisation

On one of my web-wanderings I discovered a piece of software called VMLAB. It allows you to build a virtual prototype of a microprocessor circuit, without any actual hardware! Very cool.  Even better - it's freeware.  This had to be downloaded and tried out :-)

Since I have recently been messing about with HD44780 compatible LCD displays, I couldn't resist trying that.  So here is an example I knocked up:

Virtual LCD and microprocessor in VMLAB

Not bad ... an ATmega168 driving an HD44780 compatible LCD all done virtually, without all that mucking about with actual hardware.  I did try sending some user defined characters to the virtual LCD, but that didn't seem to work, maybe that was pushing it.

Simplest ATmega168 program

So how would you know that your code is running?  Just about the simplest thing that you can do with a microprocessor is flash an LED on and off.  So we'll start with that.  You'll need to attach an LED and a resistor in series from pin 28 of the ATmega168 (assuming that you have the DIP format).  So take a wire from pin 28 on the ATmega and attach it to the positive pin of an LED.  Then attach the negative pin of the LED to one  wire of the resistor.  Finally, attach the other wire on the resistor to Ground.  When the program code turns on pin 28, power will flow through the LED through the resistor and then to Ground.  So the LED will come on.  Cool.

Obviously LEDs are diodes, so they only go one way round (the resistor can go any way round).  The purpose of the resistor is to limit the current and prevent the LED from burning out.  The exact resistor value does not matter in this case, anything from 200 to 1,000 (1k) Ohms should be fine.  The lower the value of the resistor the brighter the LED will be.

Don't forget to also wire up the other basic pins on the Atmega (I've blogged about that before).  Now we can get to some code.  I've put the source code here: http://www.codehosting.net/blog/files/led_blink.zip

Extract the contents of the zip file to a folder and open the files using Programmers Notepad from WinAVR.  Connect up your usbtiny programmer, ensure that the power is on and we're ready to go. 

Go to the Tools menu of Programmers Notepad and click on [WinAVR] Program.  The program should compile, get loaded onto the microprocessor and the LED should start to blink!  Woo-hoo.

NOTE: I have also used the "ponyser" serial port programmer.  This can be used as an alternative, by changing these lines of the makefile:

Put a # at the start of line 202 and remove the # from line 201:
AVRDUDE_PROGRAMMER = ponyser
#AVRDUDE_PROGRAMMER = usbtiny

Remove the # at the start of line 206 and make sure that the COM port matches the one you're using:
AVRDUDE_PORT = COM1

Finally remove the # from the start of line 227:
AVRDUDE_FLAGS += -P $(AVRDUDE_PORT)

You should now be able to use a serial port programmer instead (my example uses COM1).

Programming the ATmega168

There are several ways to get your program onto an ATmega168, the way I'm doing it is with one of these programmers and some jumper wires  - essentially I followed the SparkFun tutorial here.  This is something that I'm working on at the moment:

 

But you could also use one of these Olimex development boards, which is another way I have tried (and means that you can dispense with all those jumper wires).

The AVR pocket programmer is good because pretty much any PC has USB these days (you can also use serial or parallel ports to program an ATmega).  But the pocket programmer can also provide a 5v power supply from USB.

If you want to build your own programmer (which would probably be the cheapest option) then take a look that this, which should get you able to build a programmer for the cost of some wire, resistors and a parallel port connector (assuming that you have a PC with a parallel port).  For me, I found it easiest to just buy something from SparkFun.  In my experience the pocket programmer only works when attached to a USB hub, I've never managed to get it to work when plugged directly into the USB port of my PC - I've never bothered to find out why.

Of course, the other thing you'll need is a development tool, so that you can compile your source code and get the resulting output file copied to the processor.  I'm using WinAVR, or more specifically the portable version which is here.  The portable version means that I can put my development environment on a memory stick and use it on whatever computer I happen to be sat in front of.  Very nifty.

So when you're armed with 1) a programmer, and 2) a copy of WinAVR ...you should be ready to go.  You'll need some code to compile!  I'm going to post that next.

Improved Annoyatron Schematic

I have been starting to learn to use Eagle, so that I can document my circuit diagrams.  Being quite new to designing hardware I'm learning that it's not good enough to just keep a copy of the source code anymore!  So, here is the very simple circuit that makes up my improved Annoyatron:

It's very simple to knock this up on a small breadboard, you just need the ATMega168, a speaker and a battery, just like this:

Obviously, the ATmega168 is overspecified, but I have a few of them and it's easier to mess around with one type of processor.  I really will try to post the source code and some notes on how to get the source code onto the processor as a program.  Honest.

New Soldering Iron

I've just bought one of these soldering irons.  I don't know why I didn't do it ages ago!  It's been useful since I've been taking things apart again, for example here is an infrared receiver that I've just removed from an old set-top box:

de-soldered IR receiver

The new iron made a nice job of it, I set the temperature to a reasonably high level and heated the pins at the back of the board whilst tugging the otherside with a pair of pliers.  Each pin came away very easily.  I've only had it for a day, but so far it has been fantastic.  Plus it's great to have an iron without a power cable, it's much less fiddly.

Running the ATmega168

...so like me you've gone and got an ATmega168 from somewhere like http://www.sparkfun.com (which is where I get a lot of my stuff).  It probably cost you about £2.50. Obviously you'd like to get it to do something meaningful, so what do you need to do?  Take a look at this pinout for the processor:

Drop the processor into a breadboard, making sure that it straddles the middle row.  All we need to do is connect pins 1, 7 and 20 to a +5v DC supply and pins 8 and 22 to Ground.  That's all there is to it.  It's useful to note that the purpose of supplying power to pin 1 is to tell the microprocessor that it is not being reset.  Not supplying power to this pin will prevent any code from running, it will remain in reset mode.  We could use this pin like a reset button on a PC by adding a button and a resistor, but we won't worry about that right now.  I'm saying use a 5v supply because it's a nice easy voltage to find (for example, USB will supply 5v with 1A current, which is fine), but the processor should work with a supply between 2.7v and 5.5v (see the datasheet here if you're interested).  I often use a spare PC power supply, because they normally have a 5v output and are not expensive.

 

OK, so the processor may be running - but we've not put any code onto it yet.  So that's the next thing on our todo list.

Improved annoyatron

I think that it's good to keep your hand in with some plain old C programming once in a while.  So I ocasionally mess around with microprocessors. I've been working on an improved annoyatron, with my version it will pretend to be a mobile phone - by playing a simple ringtone. This is what it currently looks like:

annoyatron 2.0

 I've used an AVR ATmega168 microprocessor, which is over spec, but I had a couple of them lying around.  In fact all of the other components except for the button cell battery and holder were things that I had sitting around.  What tends to happen is that before I throw anything away, I take it to bits to see if I can remove anything.  Even a salvaged switch can be useful one day.  And it's fun to take stuff apart :-)

So ... what I'll try to do is post more about this - what development tools I've used and what I have discovered along the way.  I'll be sure to refer back to it if nobody else does.