Tuesday, December 30, 2014

Sending Messages Between Two nRF24L01 Modules using Arduino

During the holidays I took some 2.4 GHz radio modules from our lab to my home far away from Colombo and tried different interesting things. One of the things I tried is establishing simple communication between nRF24L01 modules to transfer some data. For this purpose I connected two of those radio modules to two Arduino Uno boards and programmed using Arduino IDE and RF24 library. In this article, I'm writing down the steps I followed for my own future reference. I tried it in a machine which runs Ubuntu 12.04 LTS.

(1) Download https://github.com/maniacbug/RF24 library as a ZIP file. Extract it and renamed as 'RF24maniacbug'. Create a directory called 'libraries' in your sketchbook directory inside home directory ('~/sketchbook') only if it wasn't available initially and copy the 'RF24maniacbug' directory into it. I forked the same github project of maniacbug into my account for my future use which is available at https://github.com/asanka-code/RF24.

(2) Wire up the nRF24L01 module with Arduino board according to the pin connection details in the following table. We need two setups like this to be able to send and receive data.
nRF24L01 Pin Arduino Uno Pin
GND GND
VCC 3V3
CE 9
CSN 10
SCK 13
MOSI 11
MISO 12

(3) Plug the two Arduino boards to the computer using two USB cables. Start two instances of Arduino IDE and select the two serial devices separately in two IDE instances. In my machine, one Arduino board was detected as /dev/ttyACM1 and the other as /dev/ttyACM2.

(4) From each Arduino IDE, move in the following menu path and open the GettingStarted example program (sketch). Compile and upload that program into both Arduino boards.

File->Examples->RF24maniacbug->GettingStarted

(5) Open serial monitor in both Arduino IDEs and set the baud rate to 57600. It should show some status information of the nRF24L01 module connectivity to the Arduino board.
Output of serial monitors of sender and receiver
Now, type 'T' on the serial monitor of a one device and then it will start sending messages to the other device. The other device should start sending responses for each message from the first. If we need to change the roles of sender and receiver, type R in the current sender and it will switch to the listening mode. Then type T in the initial receivers serial monitor to make it the sender.

References:
[1] http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/
[2] https://github.com/maniacbug/RF24
[3] I forked maniacbug's RF24 repository for my future use which is available at
https://github.com/asanka-code/RF24

Saturday, December 27, 2014

Zigbee Communication Between Two Arduino Boards

In this post, I'm writing down the steps I followed to exchange some simple wireless messages between two Arduino boards which are attached with Xbee wireless modules. For this purpose, I used two Arduino Uno boards, two Xbee shields which are the model of Seeed Studio XBee Shield v2.0 and two XBee modules from Digi XBee S2 module type.

Initially I searched through the web and found out that I have to configure XBee modules to create a Zigbee network by setting PAN IDs and some other stuff. For that there are two methods available as I read in the web. I attempted to try the first method which is using X-CTU tool from Digi international to configure XBee S2 modules. However, my efforts went in vain due to some reason which I still didn't figured out. The second method of configuring XBee S2 modules is using some tool such as PuTTy to communicate with the module from our PC. However I didn't try that second method yet. So, that means I didn't configure the XBee S2 modules at all.

Without making any configurations, we can simply transmit some data from an XBee S2 module which can be received by another XBee S2 module. That is what finally I did and write in this article about. For that purpose we just need two little programs (sketches) for Arduino boards. I will list down the steps I followed one by one.

(1) First of all, take an XBee shield and connect it to the Arduino Uno board. Then attach an XBee S2 module to the shield. Do the same to another set of Arduino board, XBee Shield and XBee S2 module so that we have to setups.

Assembled units

(2) Then, we need to program the Arduino boards. For this purpose, we should remove the two jumpers on Seeed Studio XBee shields. That's is to prevent Arduino IDE from sending programming data into the XBee S2 module while programming the Atmega MCU of the Arduino  Uno board. After removing the jumpers, we are ready to program them. From the two programs shown below, put the sender program (sketch) to one Arduino board and put the receiver program (sketch) to the other Arduino board.

Sender program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("H"); //turn on the LED
  delay(2000);
  Serial.println("L");//turn off the LED
  delay(2000);
}

Receiver program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
char msg = ' '; //contains the message from arduino sender
const int led = 13; //led at pin 13

void setup() {
  Serial.begin(9600);//Remember that the baud must be the same on both arduinos
  pinMode(led,OUTPUT);
}

void loop() {
  while(Serial.available() > 0) {
    msg=Serial.read();
    if(msg=='H') {
      digitalWrite(led,HIGH);
    }
    if(msg=='L') {
      digitalWrite(led,LOW);
    }
    msg = ' ';
    delay(1000);
  }
}

(3) After putting two programs into the two separate Arduino boards, we should disconnect them from the USB cables from PC. To connect the XBee S2 modules TX and Rx pins with the correct Rx and TX pins of the Arduino board, place the two jumpers in correct place of the XBee shield. Following picture shows the two jumpers in correct position.
Jumpers placed on XBee shield
(4) Connect the receiver device first into the PC using USB cables to power it up. You will notice that its on-board LED connected to Arduino pin 13 is not blinking yet. It need the command messages from the sender device to blink it according to our program. Then connect the sender device to the PC using USB cable to power it. After a short while you will notice that now receiver device is blinking its on-board LED in pin 13 giving the proof of wireless message exchange.

Our two modules powered up :)
Cheers!

Saturday, December 20, 2014

Using RPL in Contiki

When working on a sensor network application or an evaluation of a research work, sometimes we need to have a network setup which runs RPL routing protocol on sensor nodes. If we are working on Contiki OS platform, we are lucky to have not only the implementation of RPL protocol but also some sample applications which use RPL. To understand it, the best example would be simple-udp-rpl which resides in the path contiki-2.7/examples/ipv6/simple-udp-rpl of contiki source code. There are two source files inside this directory which draw our attention. First one is unicast-receiver.c file which is the receiver of unicast messages in the RPL routing tree and therefore behaves as the root node. The second file is unicast-sender.c which implements a unicast sending functionality to the root node of the RPL routing tree.

The best way to easily try out RPL on Contiki is to use Cooja simulator. First, we need to start Cooja simulator by moving into the contiki-2.7/tools/cooja directory from a linux terminal and issuing the command ant run. It will start Cooja simulation window and then we need to start a new simulation as usual. When adding motes, first we should add a Sky mote and browse and select unicast-receiver.c file as the program code to run on this mote. This will be our root node of the RPL tree. Then again add few other Sky motes but this time, use the file unicast-sender.c as the application code allowing them to be sender nodes in the RPL tree. To witness how packets from sender nodes traverse through the RPL tree over multiple hops to the root node, it would be better to keep some nodes out of the radio range of root node so that they are only accessible through some other forwarder nodes in the tree. The first figure depicts my node setup in the simulation.

After setting up the simulation with nodes with relevant applications, we can start simulation  by clicking on the Start button of Cooja simulator. After a while all the nodes started up with Contiki OS, we will start to see that every sender node periodically transmits a packet which travel through the RPL tree to the root node. Both sender and receiver nodes prints a string about these events which can be evident from the mote output window of Cooja simulator. Second figure in this article depicts some excerpt from the mote output window with sender and receiver message logs. Even though the RPL implementation of Contiki OS is a bit complicated to understand easily, these two simple sender and receiver applications would be helpful if we need to setup a scenario where we need our nodes to simply communicate using RPL without too much troubles.

~******~

Wednesday, December 17, 2014

Prof. Margot and Ravihansa from QUT, Australia.

Ravihansa and Prof. Margot
Last week was a so much busy time. In ICTer 2014 conference, I had been assigned various duties and therefore I had to run here and there to organize different things for about a week. Mainly I was assigned to facilitate a workshop conducted by the Zone24x7 company on 13th December and also a session in 12th December. However, I involved in many other works and lot of those things were really interesting. Besides all the things, I decided to write today about two interesting workshops I attended and a keynote speech in ICTer conference.

Ravihansa Rajapakse was once a student at University of Colombo School of Computing (UCSC) and was a one year senior to me. After he finished his bachelors degree, he worked in our junior academic staff. Now he is in Queensland University of Technology (QUT), Australia studying for his PhD. He came to Sri Lanka for the ICter conference not alone but with his supervisor who is a very nice lady. She is Prof. Margot Brereton from QUT. Ravihansa conducted a very interesting workshop in 10th December and then Prof. Margot delivered her keynote speech at ICTer conference in 11th. She did another nice workshop in 13th December. I was lucky to attend all these events while managing my time for various official duties.

Our prototype :D
First of all, I have to write about Mr. Ravihansa's workshop which was so interesting than I ever thought. I knew him for several years as he was a senior to me in my undergraduate degree. However, this is the first time I got a chance to be in the audience of a lecture or a workshop conducted by him. His workshop title was "Build First Plan Later: The Voice of DIY Approach in Today's Design". The whole point he tried to convince us from this workshop as I understood was, sometimes it's better to build things with the user instead of designing and building something separately and then applying it to the user context. He brought various things such as fruits, stationaries, clay, etc and in addition to that, he had brought few kits called Makey Makey. Mr. Dulan Wathugala who was once a great teacher and a mentor to us also attended to this workshop which made me so happy. We had a chat during the tea break of the workshop about various new technological trends.

Among different activities we did, the main task was to organize as a group and then select one person as a client who has a special requirement. This requirement is having some loved one in a long distance so that this group member has a need to be connected with the loved one. The task of the group is to talk with her and identify a method which provides a connectedness between her and the loved one. We formed a group where we had me, Chathura Suduwella and three members from software development unit (SDU) of UCSC. Actually I didn't know those three before this workshop and while performing the group work I made a friendship with them too. One girl in our group is selected as the client whose parents are living out of Colombo while she lives in Colombo. Our goal is to make a connection between she and her parents in some way other than standard communication mechanisms such as telephone calls, text messages, etc. After having interviews with our group member who is the client and also after a long brainstorming among the group members, finally Chathura came up with a great idea which everybody liked.

Makey Makey
Our idea was to create a small pot with a plant which has some automated functionalities. It has a small water container with an electric valve. A control signal can water the plant. Additionally, there will be some UV lights around the plant which can be turned on and off when necessary. We will put this automated plant in the living room of our clients parents house. We will put sensors in the house of our client girl so that we can track whether she has left home in the morning in a predefined time and also return home in the evening within a predefined time. Perhaps we can get this information from the sensor fixed onto a door of her living place in Colombo. Additionally, we can connect some sensor to track weather she used her plate for meals providing us the valuable information about her eating times. All these information is transferred from her living place in Colombo to her parents house where the automated plant resides. Our idea is to make the system to water the plant and provide light conditions when she leave home in the morning, return back in the evening and eat within a predefined time. Our hope is that the condition of the plant will reflect the good living condition in our clients life to her parents.

After this first workshop next day I attended to the keynote speech of Prof. Margot Brereton where she talked about different ways people have introduced ICT solutions for problems in the communities around the world and how they have succeeded and failed. Her keynote speech reflects a similar idea to Ravihansa's workshop where the importance of designing solutions with the user instead of for the user is highlighted. After her keynote speech, I took a picture of Prof. Margot and Ravihansa for the purpose of including in this article. Finally in last Saturday, there was another little workshop conducted by Prof. Margot where she helped us to visualize a problem by drawing with a paper and some color pens. Each participant was given a chance to select some problem with which they are dealing these days and then draw the connections of people and every other thing that relates to the problem. This method helps to identify the important parts of the problem and what are the things that should be considered when thinking about the solution.

As always, I enjoy meeting new people and getting to know various new things that broaden my understanding and improve my thinking about the world around me. Among various things I saw and people I met during the ICTer 2014 conference days, Professor Margot and Ravihansa are very important people and the knowledge and experiences they brought to me from Australia is awesome.

~********~

Saturday, December 6, 2014

Capturing WiFi Packets in Monitor Mode With Wireshark

I've used Wireshark for looking at different network packets and their contents. However recently I wanted to observe WiFi networks around me using Wireshark without actually connecting to any of those networks. For this purpose we have to run our wireless card in monitor mode which allows us to eavesdrop WiFi packets in wireless networks around us passively. I searched in the web to learn how to do it in my Asus laptop which runs Ubuntu 12.04 LTS. So, I'm writing down how I did it in my platform. There's an important thing to keep in mind that not all the wireless cards support monitor mode. If your wireless card doesn't support it, you are in trouble.

Steps to follow in a terminal:

// setting wlan0 to monitor mode
sudo ifconfig wlan0 down
sudo iwconfig wlan0 mode monitor
iwconfig wlan0
sudo ifconfig wlan0 up

// install wireshark if you haven't yet
sudo apt-get install wireshark

// run wireshark with root priviledges
sudo wireshark

Now Wireshark GUI window will open up and then you can select your wlan0 interface to start capturing packets. Following screenshot shows my Wireshark window with various WiFi packets.

Wireshark window with captured WiFi packets


References: