Sony Arouje

a programmer's log

Archive for December 2014

Connecting XBee to Raspberry pi

with 19 comments

Last one week I was doing some research in RF communication and controlling devices using RF. So what am I going to control here, I wanted to control the water pump running in my hydroponic reservoir without running wires from my raspberry pi. This way I can extend my hydroponic system to more balconies without buying extra RPi, a single RPi will send a switch on/off command and the RF client will switch on/off the motor via a relay. Also I don’t need to setup a wifi network in my controller RPi’s.

My research for RF communication platform leads to Zigbee protocol and XBee component. XBee is a very popular Zigbee complaint product from Digi. For my testing I got two XBee Pro S2 and two XBee explorer. The explorer I bought uses USB to A/B cable, if you are buying it make sure buy A/B cable as well. You will get micro usb explorer as well.

To configure the XBee’s I use the X-CTU software from Digi, you can download it free from Digi’s website. I use the Legacy X-CTU for configuring my modules and Next Generation X-CTU for issuing commands. Configuration is pretty simple and so many sites will walk you through it. I configure my XBee’s as shown below. One XBee act as Coordinator and enabled API mode and another XBee act as router and enabled Router AT.

XBee Coordinator

  • Modem: XBP24-ZB
  • Function Set: ZIGBEE CORDINATOR API
  • PAN: <set a pan id, say 123>
  • Destination Address Low: FFFF

XBee Router

  • Modem: XBP24-ZB
  • Function Set: ZIGBEE ROUTER AT
  • PAN: <set a pan id, say 123>
  • Destination Address Low: 0000

I left all other settings as default.

Connecting to Raspberry pi

For testing I connected the XBee coordinator to my computer and XBee Router to my RPi. In RPi I created a simple node app to send some text message to coordinator. Below diagram will show you, how I connected Router XBee to my RPi. Here we use serial communication between RPi and XBee. RPi has only one set of serial communication pin and by default it’s configured for console I/O, there are so many tutorial out there to free it up and I use one from them.

connection_diagram_bb

image developed using Fritzing

I connected the XBee directly using jumper wires, the above diagram is just for illustration for that I use the breadboard.

Connect RPi 3.3 volt to XBee 3.3 volt pin, Ground to XBee ground, Rx to Xbee Tx (Data Out), Tx to XBee Rx (Data In).

Sending some data from Router Xbee to Coordinator

Now I wanted to send some data from Router XBee connected to my RPi  to the coordinator connected to my Computer.

I created a small app using node js, below is the code. To run the code we have to install two node modules.

  • xbee-api: npm install xbee-api
  • serialport: npm install serialport
var util = require('util');
var SerialPort = require('serialport').SerialPort;
var xbee_api = require('xbee-api');

var C = xbee_api.constants;

var xbeeAPI = new xbee_api.XBeeAPI({
    api_mode: 1
});

var serialport = new SerialPort("/dev/ttyAMA0", {
    baudrate: 9600,
    parser: xbeeAPI.rawParser()
});

serialport.on("open", function () {
    var frame_obj = {
        type: 0x10, 
        id: 0x01, 
        destination64: "0013A200407A25A7",
        broadcastRadius: 0x00,
        options: 0x00, 
        data: "Hello world" 
    };
    
    serialport.write(xbeeAPI.buildFrame(frame_obj));
    console.log('Sent to serial port.');
});

serialport.on('data', function (data) {
    console.log('data received: ' + data);
});


// All frames parsed by the XBee will be emitted here
xbeeAPI.on("frame_object", function (frame) {
    console.log(">>", frame);
});

 

When I run the above node app, I can see the data receiving in my Coordinator’s X-CTU app. I could also send a Remote AT (0x17) command to the router to one of the Digital pin and could turn On/Off a LED.

Seems like the communication is working fine. Let’s see what I can come up next.

 

download

Scan using your mobile phone and access/share the post from your phone.

Written by Sony Arouje

December 20, 2014 at 6:07 pm

Posted in Raspberry Pi

Tagged with , ,

Working of my very basic and crude Aeroponic System

with 3 comments

Here I will just show you a video of my Aeroponic system. As you can see its very basic, I didn’t want to spend much money to test whether my system works, so I used cost effective materials.

In one of my previous post I explained about how I used Rasberry pi to control the motor. If you haven’t read it, please check that out too.

 

Low Pressure Aeroponic System

 

What Next?

  • From this initial test run, I could see my system is a success. Now I will add more pillars and a high capacity tank.
  • Automate day to day activities. For e.g. I have to add nutrients to the reservoir once in two day. Using a Peristaltic pump and a motor driver I can automate the process with a click of a button from my mobile app. 
download

Scan using your mobile phone and access/share the post from your phone.

Written by Sony Arouje

December 11, 2014 at 2:22 pm

Posted in Raspberry Pi

Tagged with

%d bloggers like this: