I’ve also integrated the Atmega328P version of the WidgetBoard into the Arduino development environment so please update your boards.txt with the one from SVN.
I have successfully re-compiled and re-flashed the firmware source to remove the console on ttyS0, as suspected the console attached to ttyS0 was the root of my problems, now avrdude will talk to the WidgetBoard!
and here is my WidgetBoard booting my test blinky on ContikiOS as seen by the gateway ttyS0
now back to writing the contiki radio driver…..
I’ve had some mixed success with the serial port hack on the Airlive device since my previous post.
After setting up the uclib development environment I have now successfully compiled avrdude so I can program the RFM12WidgetBoard located inside the device, however I had a couple of issues when trying to talk to the WidgetBoard.
Nothing happens when trying to query the WidgetBoard…data is going out the serial port but nothing being returned.
First problem I found….crossed Tx and Rx due to a silkscreen error on the WidgetBoard, the silkscreen for TxO and RxI are wrong way around on the PCB.
After fixing this problem and re-testing Avrdude it’s still not working….so further testing…..
Serial port is definitely working and I now have a serial console to the device. When I connect up a terminal program via my FTDI USB ttl serial cable I can see the boot process and logon to the console via ttyS0, which is probably one of my problems, the bootloader may be getting confused by the console chatter.
The trace below confirms this. I’ve re-flashed the WidgetBoard with my blinky example from the Contiki port, besides blinking the LEDS it also outputs a string “There is” to the serial port, you can see by the trace what the WidgetBoard is sending, and the output sent back by the console.
By default this kernel has the console attached to ttyS0 (see my previous post and the dmesg dump) so one of my next steps will is to recompile the kernel and disable the serial console access attached to ttyS0.
The WidgetMesh network development for the Widgets is now underway, the last couple of days I’ve been learning how everything fits together in Contiki OS, as far as drivers go and how they communicate with the upper stacks, lots of looking through existing code. I now have a reasonable idea of how things should work and how I need to write my driver.
That said the biggest problem with the WidgetMesh is going to be on chip resources, especially with the ATMega168 and maybe even the ATMmega328P, I’m not looking at running an IP stack on the mesh (well at least not yet), but the gateway/coordinator device needs to keep track of the nodes in the network. It’s role is to manage node associations, link forming and routing within the mesh, so this will require more ram than most of the nodes will have, especially in larger networks. It’s also the gateway to the world for the data collected.
I’ve been scratching my head as to what I’m going to use. I was leaning towards an ARM7 hooked up to a RFM12 or WidgetBoard, something along the lines of a make controller as I have a couple at home from past tinkering, or one of these ARM9 devices running Linux, the MMnet1001, from Propox, Both these have onboard Ethernet and plenty of resources for what I want. But it turns out that I had a solution at home already, in the form of an Airlive NAS device, WMU-6000FS. The Airlive NAS comes with Ethernet, WIFI and x2 USB ports, also PATA or SATA hard drive, all this runs from a 12V supply, so I could also run this from a SLA battery.
The Airlive WMU-6000FS is a not so great NAS device that I evaluated for work project involving offsite replication. The project was eventually shelved.
The great thing is that it runs embedded Linux, after a bit of research found that I can re-flash the current device easily with a distribution from http://mgb111.pradnik.net/ will allow me to make changes to the system, whereas the current flavour is embedded and is Read only, all changes are lost at boot, however no documentation anywhere regarding serial ports, or in fact if one exists onboard.
I proceeded to re-flash the board with FW C009-M2 Advanced firmware, this gave me console access, once in I checked that Linux is detecting a Serial Port.
-bash-3.2# dmesg | grep ttyS0 Kernel command line: rw console=ttyS0,38400 ttyS00 at 0x03f8 (irq = 4) is a 16550A -bash-3.2#
A UART is being detected and is used by the system as a console.
Here are the memory and CPU as reported by dmesg, so plenty of resource for what I want.
Initializing CPU#0 Calibrating delay loop... 44.33 BogoMIPS Memory: 29984k/32768k available (1418k kernel code, 2396k reserved, 337k data, 56k init, 0k highmem) Checking if this processor honours the WP bit even in supervisor mode... Ok. Dentry cache hash table entries: 4096 (order: 3, 32768 bytes) Inode cache hash table entries: 2048 (order: 2, 16384 bytes) Mount cache hash table entries: 512 (order: 0, 4096 bytes) Buffer cache hash table entries: 1024 (order: 0, 4096 bytes) Page-cache hash table entries: 8192 (order: 3, 32768 bytes) CPU: After generic, caps: 00000000 00000000 00000000 00000000 CPU: Common caps: 00000000 00000000 00000000 00000000 CPU: Cyrix Cx486SLC
This can only mean one thing. Time for surgery!
Disassembly is very easy, two screws at the rear allow the extruded aluminium case to slide off , at least it’s solid. Inside is a 1TB drive that I had swapped out with the original some time ago, so If all goes to plan then I’ll have plenty of storage available for the Wireless Sensor Network.
I love it when designers of hardware have fore thought to design in for future expansion, adding a second antenna is going to be simple enough, just drill out the rear cover to suit, actually the cover already as the markings on the inside for this.
Search for the Serial Port
Prime serial port candidate CN2 (10 pin socket centre of shot) , The processor (top left) is an RDC 3210, a 486 equivalent. The datasheets (no longer available from RDC website, but found via Google) tells me that the CPU has a single onboard UART that the pin outs coincide with the rough location of the CN2 header, either it CN2 or part of the larger connecter, but I doubt it.
Continuity tests of CN2 confirm that this in indeed the serial port, some further checking and voltage measurements confirm everything I need is there. Whoot!
|5||Serial In (Rx-I)|
|8||Serial Out (Tx-O)|
Adding the WidgetBoard
I moved the Wi-Fi antenna SMA across to the spare and added in an SMA pigtail to suit a 915Mhz GSM antenna that I use for my WidgetBoards.
Next wire in the Serial port to an external header
WidgetBoard trying out it’s new home with SMA pigtail connected. Actually this is the first of my Widgetboards to use the Atmega 328P processor.
I used the third spare antenna connecter on the right for an external reset button for the WidgetBoard, may not be required, but hey, if the DTR reset does not work at least I can force the issue.
All wired up and safe and sound in a simple card surround to stop any shorts from happening.
All boxed up to see how it all all goes together, 2.4Ghz and 915Mhz antennas side by side and reset bottom right.
The next step is to get minicom and do some further testing, along with getting a version of avrdude working from the Linux console, this will allow me re-flash the WidgetBoard locally if the need arises.
I’ve just committed my current progress on porting Contiki Operating System to the RFM12WidgetBoard to SVN.
- Serial working
- LED API implemented.
- Event timers now working.
- Added blinky example that demonstrates all of the above.
Now compiling to 5166 bytes of flash and using 387 bytes of ram.
Well, back from a short break away (kid free woohoo!) and onto some widget builds. I thought I’d document how I do my widget construction. I actually find building SMD devices much easier than the PTH variety.
I have all my components in some neat snap together containers, this allows me to have everything at hand for the build.
[Click on images for larger size)
1) Solder paste is applied to the boards sparingly, ready for component placement
2) Components placed on each board, I usually do a board at a time. You will see x3 boards without any RF modules, these will be added at a later time depending on what band is required.
My SMD toaster oven setup.
The toaster oven is unmodified straight out of the box connected to the PID temperature controller.
PID Ramp controller with Solid State Relay output driver from E-Bay, that allows me to store up to 64 different temperature/time steps, each step can have their own PID parameters. The ramp controller allows me to set and store my solder temperature profiles and when enabled will cycle through the temperature profile.
The PID controller is installed in an external SCSI case I salvaged from an old external tape drive.
The thermocouple is a K-type with the shroud removed to give a fast response to temperature changes, I also have it wired to a spare PCB to give me a good indication of the PCB surface temperature in the oven
Rear of PID controller case, I’ve wired a power point directly a 10A solid state relay and fuse. The SSR is driven by the PID output, so power is only applied when heat is required. This allows me to use any unmodified toaster oven.
Batch ready for baking, carefully placed onto tray so no components are moved in the process.
All I do now is start the Temperature controller and let it do the rest (after closing the door) Since the Toaster oven is unmodified in any way I just turn it’s temperature knob to the max temperature and the same goes for it’s timer. The bottom power light turns on when temperature controller is heating.
My hi-tech fuse and bootloader programmer ready for programming. The headers give me good connections and allows for easy changeover.
Fuse and bootloader being programmed
For the next version of the widget, I’m planning to have an on board boost regulator. This design will allows the widget to run from just about any voltage source as low as 0.7v (so NiMh will be fine) and up to 5.5v, this boost regulator in conjunction with a standard LDO regulator will give me a nice input voltage range of 0.7v – 12V. Before I finalise the design I wanted to test things to see how well it’ll work.
I ordered in a couple of battery holders from Polou with an integrated boost regulator, since the widgets are designed for 3.3v operation I ordered this model http://www.pololu.com/catalog/product/796, that provides a 3.3v 100mA supply from a single AA battery, I’m not too sure what the minimum voltage is, but is running fine on a single NiMh cell.
Well today they arrived and I now have one hooked up to my solar powered widget. Installation was simple as the small pcb on the rear of the battery holder allows me to direct access to the cell contacts, so I soldered the solar cell +ve and –ve on the respective contacts.
From some previous tests with my solar powered widget, I was finding that the batteries would start charging when the solar cell output reached around 2.8 –2.9v, this is fine for during the day with the solar cell in direct sunlight, now with the single cell I’m finding that inside under artificial light I’m charging at around 1.5v, with plenty of overhead left.
You can see below the voltage output of the boost regulator is ~3.3v (3.322 to be exact) and the voltage from my solar cell is ~1.52v, this is inside under some standard down lights while writing this post at the kitchen table (actually one of the down lights is dead so I could expect a little more output from the cell)
Just to try something different I removed the battery, seeing if the regulator could run direct from the solar cell, unfortunately it doesn’t, I doubt the cell in the current light conditions can provide enough start up current for the regulator, I will however try it in the natural sunlight tomorrow.
With the addition of the boost regulator, and the widget in max power savings between sensor reading (when asleep widget is drawing 1.5uA, which is most of the time) then the widget should run indefinitely from the single cell….or maybe I could just get away with a solar cell and a super cap now there’s a future project….
Just thought I’d post an update on what’s happening in the widget development world.
Limited Production Run
I have a very limited number of widget kits available for purchase. This limited batch of widget kits also include a bare prototype personality at no cost with each widget to get you started in your wireless applications.
Introductory price of $US25ea (or $20ea for 5+) include headers, bare prototype boards, 10Mhz low profile crystal, switch, all smd components are pre-assembled and tested, latest bootloader and RFM12 test program loaded.
SMA Pigtail: $2.50 for externally mounting SMA antenna.
SMA Edge: $2.50 for mounting SMA antenna onto PCB
SMA R/A antenna 900Mhz only: $4.50 to suit SMA connectors above
CR123 Battery Holder: $2.50
I’ve yet to get full details and pictures available or a means to order online yet, so contact me in the mean time if you’re interested, please let me know the band of the RF module required when ordering, e.g 915Mhz, 868Mhz or 433Mhz.
The v1.1 of the widget bootloader for 8Mhz and 10Mhz boards are now available in the download area. These have been updated to incorporate the onboard LEDS and provide visual indication when entering the bootloader.
Source now in SVN
All the arduino source that I’ve changed for the widgets is now in SVN on the project page. This includes:
- Bootloader source.
- modified boards.txt that include the 8 and 10Mhz versions of the RFM12Widget.
- Modified wiring_analog.c to read Widget battery voltage.
This can be checked out/copied directly to your arduino install directory by overwriting the existing files. The arduino environment will need to be restarted for the boards.txt file to take effect.
I’ve started incorporating the user feedback into the next revision of PCBs. Still a bit of work to be done on the PCB layouts.
Started preliminary design for a simple mesh network.
Ultimately I would like to have the ability for the widgets to provide Zigbee type functionality (not compatibility) along with frequency hopping as standard, that is transparent to the application. Only very early days so far.
I want to deploy widgets around the home, both inside and out, so I needed to find something that would allow some protection from the environment to the electronics, cheaply and easily.
On the weekend while doing some shopping I found the solution in the kitchen area of the local discount store, at $1.50 a piece it was the right fit for the job. They probably won’t like U/V in the long run, but will see how they go, at that price I can replace cheaply.
(click picture for more details)
Waterproof/Dustproof housing with easy access to the internals.
This will be the standard sensor node housing. The widget Boards and battery pack are fixed via velcro so I can easily remove for reprogramming etc.
I still need to look at airflow of sorts for temperature, humidity and pressure sensors, will probably look at putting a couple of small vents in, this will compromise the waterproofing.
To mount these I can put some velcro on the back and mount it on any horizontal or vertical surface.
Open and showing details of SMA pigtail connection, batteries (x2 AA side mounted) and widget board velcroed to the container (personality board removed)
Same as above, but this is for my outside sensor nodes where I’ve mounted a Solar Cell sealed on the outside, I did some initial testing and there was a filtering effect of the plastic lid and the cell, so I decided to put the cell on the outside to get maximum efficiency, it was a pretty messy job after I used silastic to seal everything, the cell now has a smear of silicone haze across it that is appearing very difficult to remove. So in future I think I’ll live with the slight degraded Cell performance and mount it inside, where it fits perfectly, that way I can use a couple of blobs of hot glue to fix the cell to the lid.
In my previous blog entry I described adding a solar cell to the widget and how I could measure the voltage produced by the Solar Cell, however I still need to monitor actual battery voltage easily, and preferably with not a lot of additional hardware.
Problems reading ones own voltage.
Measuring ones own voltage has a couple of problems:
You can’t just measure VCC directly, i.e. you can’t connect an analog pin to VCC. The reason is the battery voltage varies, and since the default AREF is tied to VCC you will always read VCC unless you use some form of a reference not tied to VCC.
I can also use a reference diode and a resistor between VCC and GND, to form an external reference voltage, the diode has a known voltage drop across it so this can be measured using the default AREF. We can calculate the battery voltage by measuring the volt drop across the diode. While this will work, the circuit will always consume a small amount of power, even when not being used, remember I want to get as much life out of my batteries as possible. So it rules this out as a solution.
For the same reasons as 1) I can’t use a simple voltage divider and the default AREF. As the voltage varies so too will my readings.
I can use a simple voltage divider and the internal 1.1v bandgap reference for my AREF, the same as I used for my solar cell voltage monitor in the previous blog entry. Again this will work, but also as in 2) this will always consume some power even when not being used, so is ruled out as a solution in this case.
No Extra components?
We can however measure VCC voltage with no external components by simply reading the value of the internal bandgap reference voltage (1.1v) which is always fixed regardless of the battery voltage, and by using the default AREF which is tied to VCC, so will vary as the battery voltage changes. We now have a way of measuring the voltage change against a fixed reference.
V_BAT = (VREF * 1024) / analogRead(14);
|fixed reference voltage in this case 1.1v, but could be referenced to an external reference.|
|raw ADC reading from MUX channel 14|
You might see in the above formula, that analogRead() function is reading channel 14. But analogRead() only supports channels 0-7 right?
Correct, but what we are doing is to read the internal ADC channels after we make a small change to the Arduino source code.
Changes to “wiring_analog.c”
To take an ADC measurement of the internal bandgap we need to switch to ADC MUX channel 14 (23.8.1 in reference manual). However to do this with the arduino wiring library we need to make changes to “wiring_analog.c” as per http://code.google.com/p/arduino/issues/detail?id=10. This change allows us to read from all ADC MUX channels, internal and external.
Once you’ve made the change to “wiring_analog.c” then use the following example sketch to read your VCC/Battery Voltage.
When this method won’t work.
If you have a voltage regulator or a protection diode inline between your battery and VCC, then this will only show the voltage at VCC, not the true battery voltage.
If you have a voltage regulator then you will always read what it puts out, and not give a true indication of battery voltage. I guess you could still use the method as a form of low battery measurement. i.e. when the battery falls below regulation values I guess the regulator will fail to regulate and you should get a lower than normal reading. however I haven’t tested this theory.
If you only have a protection Diode then measure the volt drop across it and compensate in your calculations, it will still give you a good indication of battery voltage.
Some other uses for this method is for auto-calibration of sensors as described by ladyada(you need to go to the bottom of the page)
One of the tasks I want to use the widget boards for is a Wireless Sensor Network around the house for measuring environmental values. The sensors that I want to live outdoors will need to be self sufficient in terms of power, so I wanted to see if I could charge the batteries via solar, of course this can be done, but again I want to do it as cheaply and as simply as possible, I also want the widget board to monitor the solar voltage and report it back.
I already had a 3.6v 0.2w cell that I picked up some time ago from Sure Electronics for about $10 for 5. The spec for this cell is max voltage (under load) is 3.6v and max current is 60mA, more than enough to trickle charge x2 AA NIMH batteries.
The Batteries should not require much of a top up as the node will be sleeping most of the time, from the power saving discussion @ JEELabs, by adding the solar, I should be able to just leave the node without having to change batteries (replacing failed batteries aside).
To measure the voltage produced by the solar cell I need a voltage divider that would produce 1.1v max @ 3.6v.
Why 1.1v I hear you ask? The reason for the A/D full scale input voltage of 1.1V is that I’ll be using the ATMega168 internal bandgap reference as the AREF source for the onboard A/D and not the default AREF.
There are a couple for reasons for this. The internal bandap reference itself is a 1.1v voltage reference, because the battery voltage may change over time (remember I’m not using any onboard voltage regulators) so as the VCC / battery voltage changes, so would my A/D voltage readings unless I use a reference voltage. Now as the reference is 1.1v this means that my input must not go above 1.1v else I will go over scale and get an incorrect reading.
I’m not going to bore you with the math so a quick calculation using an online voltage divider calculator (http://www.daycounter.com/Calculators/Voltage-Divider-Calculator.phtml)
Input Voltage = 3.6v
Output Voltage = 1.0v (remember I don’t want to go over 1.1V so I’ve given myself some headroom)
Gave the values for R1 = 26K and R2 = 10K
Luckily I had both these values, however for the 26K I only had one in 5% tolerance, the 10K I had as 1% (I like to use low tolerance resistors for voltage dividers so my error is minimised),upon testing the 26K resistor actually read 26.4K on my meter, so after plugging these real values in my actual FS Vout is 0.989v, pretty close to 1.0V.
A blocking diode is also required to prevent any damage to the Solar cell by the batteries, see the circuit and photo below.
(Click for larger image)
(Click for larger image and notes)
Arduino Sketch to read the voltage produced by the solar cell, next step is to find a waterproof housing and add some environmental sensors.
Another benefit of taking voltage readings of the solar cell is I now have a light sensor.
The other day when playing around with different fuse settings on the Widget Board, I incorrectly wrote the wrong values, oops one bricked board However all is not lost.
With a second working Widget Board and a simple Arduino sketch , I used the following procedure to recover from my mishap.
First I installed the following sketch onto a working Widget Board
What this sketch does is generate a 1.2MHz clock signal on the INT1 port of the Widget Board. (Click the picture below to see the the full trace )
Next I attached this signal to the XTAL1 pin (Pin 7) of the AtMega168v on the bricked board (I just held it against the crystal pin).
While holding this connection on the pin, I then fired up AVR-DUDE and rewrote the correct fuse settings, after confirming that the fuse values could be read back I then remove the wire and everything was back to normal.
So all is not lost
I’ve started to document the Wireless Widget Board in the wiki, documentation is currently all over the place, but slowly getting there. Currently I’m working on the build instructions so those of you that I’ve sent PCBS to can at least have a parts list.
I’ve also put up an initial bill of materials. But it would be great if someone can do a Octopart BOM and share it.
Initial building instructions can be found here: http://code.google.com/p/strobit/wiki/Rfm12BuildingInstructions with more to come.