Wednesday, April 17, 2013

Zigbee for Raspberry Pi

The hardware setup I'm using is explained in Wireless/Zigbee for PIC Micros. If we can use this as a USB dongle for PC (shown in my previous post), it should be simple enough for using it with our hot favorite Raspberry Pi. FT232R is a very widely used chip with good driver support for Linux as well.

USB-Zigbee Dongle connected to Raspberry Pi (left breadboard), peer being debugged (right breadboard) and Zena analyzer in the background.

For the software side on Raspberry Pi, we have plenty of options, C/C++, python, shell or even the C# application (haven't tried mono on Pi yet). Later this month, I'll post an assembled version of the dongle and with some code examples too.

I'm really excited about this one and keen to show you how I'm using this as the internet gateway for my micros, sensors and robots.

Stay tuned!

Zigbee for C#

Utilizing the setup I have in the Wireless/Zigbee for PIC Micros, I just needed an USB-UART interface to make a Zigbee adapter for the PC. FDTI's USB-Serial IC FT232R has been my favorite for sometime for the serial interface for PICs. And that in fact completes the hardware setup of my USB-Zigbee dongle: a PIC18F26K20, MRF24J40MA and FT232R.

The USB can easily power this micro and radio.

On the firmware side, we can take several approaches to support PC side (a C#, C++ or any application) to send message to and receive message from a Zigbee network. One good approach is to make the RF layer transparent so that PC side using the dongle doesn't have to think about the RF network. It'll simply send message to UART and same message (maintaining the baud rate) will be delivered to the target node. It'll be a good abstraction of the physical RF network.

However, that approach will be a future blog post and for now I'm using a much simpler implementation where PC sends predefined 'commands' with parameters to the dongle and the dongle processes them. Purely for an example, PC can send "light1 on" to the dongle (which is more like a Zigbee gateway device in this case) and dongle will send message to "light1" device to turn it on.

Next week, I'll show how this hardware setup can be used to control devices, sensors or robots wirelessly from a PC or even the internet. By the way, a cool robot is coming up later this month! :)

Monday, April 8, 2013

Wireless/Zigbee for PIC Micros

Back in 2009, my professional work involved leading the firmware project of a low power wireless network of sensors collecting temperature and humidity data. Wireless gateways accumulated the information and sent to a data center over the internet. During that project, I fancied my own Zigbee network for my robots and setting up a network of home monitoring sensors. I eventually bought some Microchip MRF24J40MA modules (which is a completely different platform than my professional work). Unfortunately, the modules had been siting idle for more than 3 years and until very recently, I didn't get a chance to play with them.

Microchip has a great library called Miwi which provides out of the box Zigbee like infrastructure based and P2P protocols. There are plenty of demo boards available as well. However, to fit wireless into projects where space is a luxury, you need to get your hands dirty.

I prefer building my own platforms from the scratch rather than using ready solutions like the microchip demo boards or even the Arduino and Zigbee shields. While Arduino and its sheilds are excellent kits for beginners, I feel I have a different taste. Arduino + Zigbee shields are insanely expensive as well. For example, a set Arduino + Zigbee shields will cost £40 or more while PIC + its radio modules are less than £7. So you can easily have a whole network of PICs with the price of one bulky Arduino Zigbee :). I'm happy with any low level programming challenge the PIC solution will through at me (In fact, that's what I really enjoy doing).

I'm using the PIC18F26K20 for the network. With 64KB ROM, 4K RAM, 16 mips/64 MHz and XLP, it has been adequate for my hobbits works for some years. Here's how my prototypes look like:

Sending data to the Zena network analyzer.

Sending and receiving tests with two sets of modules.

So my Zigbee network is ready to be plugged in (to my next projects). The assembled version of these prototype boards will look very different. I'll introduce the PCB version soon.

Later this week, I'll present how to talk to a micro wirelessly from C#, how to add wireless internet to a PIC and how to add Zigbee support to a Raspberry Pi. Sounds interesting?

Sunday, April 7, 2013

Wifi router/dongle for TV using Raspberry Pi

Like most connected TVs, mine is ethernet only. The lack of wifi and moreover the price of the propitiatory wifi dongle bothered me a bit. With couple of Raspberry Pis collecting dust, I thought of a new place for them. It's behind the TV working as a wifi to ethernet adapter/router. One of the USB ports of the TV can power it (and thus the adapter turns on and off with the TV). Here's how simple it can look.

Raspberry Pi with the cute Asus N10 wifi dongle gave me everything I needed for the adapter. I just needed to set up the DHCP host for ethernet and the routing. Not being an expert of routing, troubleshooting it was a bit distressful but the hour was well worth. HD streaming was smooth and BBC iPlayer never felt so delightful! :)

Thursday, April 4, 2013

Raspberry Pi Weather station (in 5 mins)

Here is an example of how small scripts can give you amazing makes. Here's my weather station using the LCD display I mentioned in my previous post: An LCD display for Raspberry Pi.

(Photos updated: April 7, 2013)

It's displaying weather forecast for Cambridge, UK. That's a miserable weather indeed :). As you can guess, the first line is the current condition followed by next two day's forecast which includes high and low temperatures (in Celsius). The last line is the date and time of update.

The awesome bit is you can make this with 20 lines of scripting and in less than 5 mins. Here is how it works:
  1. Grabs the weather data from Yahoo weather feed.
  2. Extracts key weather data from the xml feed, and
  3. Displays the data to the LCD.
The whole thing is done with this shell script (which I'm sure can be further reduced a lot):

Most of the script above is for converting the rss weather feed xml into those few lines to display. It writes the information in a file which is then read and displayed to LCD by a python script. Here's the python script to display the info in green color only:
#!/usr/bin/env python
from pylcdsysinfo import BackgroundColours, TextColours, TextAlignment, TextLines, LCDSysInfo
from time import sleep
d = LCDSysInfo(); d.clear_lines(TextLines.ALL, BackgroundColours.BLACK)
d.dim_when_idle(False);d.set_brightness(127);d.save_brightness(127, 255)
f = open('yw', 'r'); col = TextColours.GREEN; c = 1;
for line in f:
        d.display_text_on_line(c, line, False, TextAlignment.LEFT, col)
 c = c + 1

That's 20 lines of scripting doing it all! Yet another example of how awesome shell and python scripts are.

You can run this every hour simply by adding a cron job. There is a bit of details involved before you can use this code. You need the python lib for the LCD and also a bit of info on how Yahoo weather feed works: To get the forecast for your location, you need the WOEID (Google: WOEID finder) and to pass it to the Yahoo weather feed url.

I understand I should provide detailed steps for beginners, perhaps as an instructable. If you want to see the detailed steps, do let me know in the comments :).

Wednesday, April 3, 2013

An LCD display for Raspberry Pi

Hooking up a portable lcd display to Raspberry Pi can open up tons of ideas. PC or network status monitor, notifier for email, tweets, comments or feeds, weather station or a display for a robot are just a few ideas one could think of in about ten and half seconds :).

With too many options to pick from, I suddenly came across this one.

It's an assembled 2.8 inch color graphics LCD with on board LCD controller and a resolution of 320x240. Found on ebay and it's almost a brand-less product.

What caught my attention is the USB interface, good looking form factor and the software support. It's based on libusb, so can be programmed from many languages. There are code examples using C# and a python port is also easily found. It should be simple to plug this into the Raspberry Pi or the PC and displaying some text in python or c# in a couple of minutes. No soldering or jumper wire required. It also works as a tiny photo frame with an on board 2 mb flash. For the downside, it has a poor refresh rate.

In the next post, I'll show how to build a Raspberry Pi weather station using this LCD under 5 minutes. If you had this display, how would you use it? Do share you ideas. If it is an easy one, I might give it a try.

Tuesday, April 2, 2013

[Kontroller]: A bit of intro!

Setting up this blog simply to share my works on embedded, robotics and vision. I try to play with these when I get a chance. Here's the list of the first few entries coming up:

Tomorrow, 3rd April:
     An LCD display for Raspberry Pi

Later this week:
     Raspberry Pi Weather station
     Wifi router/dongle for TV using Raspberry Pi
     Portable Wifi camera using Raspberry Pi

And, for next week:
     Wireless/Zigbee for PICs
     Wireless/Zigbee temperature monitor
     Zigbee for C#
     Zigbee for Raspberry Pi
     Internet connected PICs

Interesting enough for bookmarking the site? Thanks for your time!

Edited: April 7, 2013, the original intro was a bit boring :)