Tuesday, 9 February 2016

pi with xbee in python code


Raspberry Pi with xbee in python-gkarthik


ZigBee is a communication device used for the data transfer between the controllers, computers, systems, really anything with a serial port. As it works with low power consumption, the transmission distances is limited to 10–100 meters line-of-sight.   ZigBee devices can transmit data over long distances by passing data through a mesh network of intermediate devices to reach more distant ones. ZigBee is typically used in low data rate applications that require long battery life and secure networking. Its main applications are in the field of wireless sensor network based on industries as it requires short-range low-rate wireless data transfer. The technology defined by the ZigBee specification is intended to be simpler and less expensive than other wireless  networks.
Here we make use of an interface of Zigbee with Raspberry Pi2 for a proper wireless communication. Raspberry Pi2 has got four USB ports, so it is better to use a Zigbee Dongle for this interface. Now we want to check the communication between the two paired ZigBee modules.
Modules Needed :
  1. Raspberry Pi2
  2. XBee 1mW Wire Antenna- Series 1 (2 No:)
  3. XBee Explorer Dongle  (2 No:)
The two Zigbee must be paired with the same baudrate (for Ex: 9600) with X-CTU Software. Attach the two Zigbee’s to the two dongle’s and connect one pair on the USB port of the Raspberry Pi2. Connect the other pair to the USB port of a computer or a Laptop. Install the FTDI Driver on the Computer /laptop to provide usb communication. Create a hyperterminal, select  the corresponding com port and the baudrate for the connected device.

FTDI Virtual Com Port(VCP) driver Installation

Many embedded devices communicate over the serial port connection as most modern computers lack a hardware serial port; USB adapters provide the serial interface. Here we are discussing how to open a serial connection to an embedded device on Windows XP.
The FTDI makes USB communication with a micro controller or serial device .The chip on the board translates the serial data coming from a device into USB data and vice-versa. It is widely used to upload firmware to the Various development boards, but it can communicate with any serial-enabled device
The CDM driver provides access to virtual COM port (VCP).If you plug in your FTDI device, your computer will not immediately recognize it. In order to function with a terminal program, the FTDI requires special device drivers. The drivers for various operating systems can be found on the FTDI website. The particular driver one needs is Virtual COM Port, or VCP. It allows the USB device to appear as a COM port to be used with a terminal.
Download the latest available CDM drivers from the FTDI web site and unzip them to a location on your PC
How to Install
Connect the device to a spare USB port on your PC.  If the device is based on the FT2232, the Microsoft composite device driver is automatically loaded in the background and a little popup bubble in the bottom right corner of the screen that says Found New Hardware FT232R USB UART.
After a few seconds Windows Found New Hardware Wizard will launch
Select “No, not this time” from the options available and then click “Next” to proceed with the installation.

At the next screen, Select “Install from a list or specific location (Advanced)” as shown above in Figure and then click “Next”

Select “Search for the driver in these locations” and enter the file path in the combo-box (“C:\CDM 2.02.04″ in Figure or browse to it by clicking the browse button.  Once the file path has been entered in the box, click Next to proceed.

If Windows XP is configured to warn when unsigned (non-WHQL certified) drivers are about to be installed, the message dialogue shown in above Figure will be displayed unless installing a Microsoft WHQL certified driver.  Click on “Continue Anyway” to continue with the installation.  If Windows XP is configured to ignore file signature warnings, no message will appear.

It should copy some required driver files and installing the software, then come up with this window display a message indicating that the installation was successful Click “Finish” to complete the installation for the first port of the device.

If the device is based on the FT2232 almost immediately, another window will pop up; this time it will say USB Serial Port. As before, click Install from a list or specific location. The procedure for installing the second port is identical to that for installing the first port from the first screen of the Found New Hardware Wizard.
The Found New Hardware Wizard will again launch automatically to install the COM port emulation drivers. Select “No, not this time” From the options and click “Next” to proceed with the installation.
Select “Install from a list or specific location (Advanced)” and then click “Next“.

Browse to the same folder again and click Next to proceed.

Again the warning message will pop up,If Windows XP is configured to warn when unsigned (non-WHQL certified) drivers are about to be installed, the message dialogue shown in above Figure will be displayed unless installing a Microsoft WHQL certified driver.  Click on “Continue Anyway” to continue with the installation.  If Windows XP is configured to ignore file signature warnings, no message will appear.

The below  screen shown will be displayed as Windows  copies the required driver files.

Now the required device driver is installed, you may need to reboot the computer.

Connect your FTDI device to a spare USB port on your PC,Now a popup bubble in the bottom right corner of the screen that says Found New Hardware USB Serial Port.

OK now you can verify that the driver installed properly..
Right Click on the my computer Icon in the Desktop click Manage (Open start=>run=>compmgmt.msc) then come up with this window.

Click on the Device Manager Button Look for an entry under Ports (COM & LPT)

It shows USB Serial Port (COM) the COM number may vary but it should be something like COM3 or COM4 the COM number may be as high as COM99 so just look for the USB serial port. The COM stands for “communication”, and each one has a unique number, known as the COM Port number. In this case the COM Port number is COM4. If you don’t see the COM port, verifies the cable is plugged in, and check that VCP FTDI driver is installed.
Right click on the selection then click on properties the above window is come up and here you can change the port setting.

XBee Explorer Dongle

Testing xbee:
XBee Explorer board with USB A Type connector for the XBee line of products which can be used as Dongle – can avoid USB cable and LAPTOP friendly!! . The board is populated with high current LDO to support most of  XBee modules including XBee Pro! .The XBee Explorer Dongle will help you to reduce lot of hassles normally facing to implement Xbee Network.We have also added two more LED’s (SLEEP & Associate) apart from normal 4 LED. This help you to use latest versions XBee Modules as well.  The module is self powered from USB Port itself, thanks to low dropout regulator.
After Power up the explorer Dongle board will create a virtual COM port in PC , and you can communicate with the module same as serial port devices. The Explorer board is built with FT232RL Chip from FTDI and drivers are available for Windows ,Linux and MAC.
This unit works with all XBee modules including the Series 1 and Series 2.5, standard and Pro version. Plug the Xbee Module into the XBee Explorer Dongle , attach to the LAPTOP, and you will have direct access to the serial and programming pins on the XBee unit.
 Features:
  • USB A Type Connector
  • Built in SMD fuse for protecting PC USB Port
  • Powered from PC USB Port
  • High Current (500ma) 3V3 Voltage Regulator for XBee/XBee PRO Module
  • 5 Onboard Status LEDs (Associate,Sleep,Tx,Rx and RSSI)
  • Onboard Power LED
  • High qualty PTH PCB and made by Automatic Pick and Place Machine
Specifications:
PIN Diagram:
PIN descriptions are given below:
Layout:
How to Test:
Test your XBee Explorer Dongle with  PC:
  • When XBee Explorer Dongle is connected with USB port of PC,the PWR (blue) LED will glow on the top of module ,it shows power indication.
  • For a quick installation on XBee Explorer Dongle and connection details please read the blog…   
  •  Here we are using a paired Zigbee, to construct a simple point-to-point network.One of the devices must be a Coordinator  and the other must be a Router (an ‘endpoint’ device).
  • After completion of installation setup SLP LED(Green) is turn ON and also ASSOC LED(Red) will blink rapidly 2 times per seconds(Association Confirmation received to the endpoint device from the Coordinator) or ASSOC LED will not blink if the End Device has not associated.
  • During the transmission   TXD led blinks as per the data rate and at the time of reception RXD led  blinks.
  • RSSI LED(yellow) on top of the board is connected to the RSSI (Received Signal Strength Indicator) pin of the XBee module. XBee outputs a PWM signal on this pin which is directly proportional to the quality of the RF signal, until the last packet was received by it. This PWM signal applied to the  RSSI LED will vary its brightness as per the quality of the RF signal,better the RF signal brighter the LED.
Here below one example is shown: 
  • Placing  XBee module  on XBee Explorer Dongle is shown below.
  • In this example we are making communication between two paired zigbee COM PORT of coordinator zigbee is set in Hyperterminal and wrote a message like here it is “Hai Xbee connected” sent it to end point Xbee.
  • And we opened other terminal window i.e realterm and COM PORT set in realterm terminal window is of End point Xbee and received message sent from coordinator Xbee in realterm.Click here to download realterm.
Note:The above message  shown in hyperterminal is written from coordinator XBee and simultaneously sent to the end device  XBee.
n the Raspberry Pi2 section open the LX terminal and type lsusb.

The response showed inside a red box indicates the presence of a usb device in the module. Write a python script to perform Zigbee communication which is given below.
The two zigbee must be in a line of sight and check the results in the Python shell and in the hyperterminal of the computer.

 The Communication could also be established with two Raspberry Pi or with another controller it self.
import serial

# Enable USB Communication
ser = serial.Serial('/dev/ttyUSB0', 9600,timeout=.5)

while True:
ser.write('Hello User \r\n') # write a Data
gk = ser.readline().strip()
print 'Received Data : '+ gk

Tuesday, 26 January 2016

arm-linuc-gcc installation

A compiler is a program that turns source code into executable code. Like all programs, a compiler runs on a specific type of computer, and the new programs it generates also run on a specific type of computer.
The computer on which the  compiler runs on is called the host, and the computer the new programs run on is called the target. When the host and target are the same type of machine, the compiler is a native compiler. When the host and target are different, the compiler is a cross compiler.
In our case Friendly ARM is the Target device & PC/Laptop is the Host.We’ve to install the Cross Compiler on the Host to enable deploying programs on to the target FriendlyARM device.In this post I shall explain the process of cross compiler installation on a Linux (Ubuntu 12.04) running Host Computer.
To start with copy the Linux directory from the DVD supplied along with the Friendly ARM device.Paste it to the /tmp  directory of File system.
              copyto_tmp
Open up the Terminal type cd /  & go to root.Change directory to /tmp/linux by typing
cd /tmp/linux
              cd_tmp
Type  ls command to list out the contents.
arm-linux-gcc-4.4.3.tar.gz  is the file we’ve to unTar.
            TAR
Enter the following command to untar the linux-gcc file.
                sudo_tar
Use sudo to be a super user .Also note the capital letter C , a space after it & a forward slash /
Type in your super user password.
The command line arguments we use with tar command are  x , v  , z , & f.
        x   is to extract/restore contents of tar file.
        v  is Verbose output i.e, to display the files being restored from tar file
        z  is to use zip/gzip to read or restore from tar file.
        f  is to specify the filename used to tar out from
This command will extract arm-linux-gcc to the directory    /opt/FriendlyArm/toolschain/4.4.3
     extaract
To run the compiler you’ve to add the PATH to the compiler environment variable of the system.
Change directory to Root  cd /    & then go to bin directory by typing
cd /opt/FriendlyArm/4.4.3/bin
       bash_edit1
We’ve to edit the hidden system file .bashrc ( a  ‘ . ‘  indicates that it is a hidden file) & add the PATH at the end of file.
To do that type    sudo gedit /root/.bashrc
Type your super user password.
.bashrc file will open up.Scroll down to the end of file & add the path as
   export PATH=$PATH:/opt/FriendlyArm/toolschain/4.4.3/bin
& save it.
     bash_edit2
To Restart shell ,type      source ~/.bashrc   or you’ve to logout & login back.
(Note the usage of  ~ for root )
    restart_shell
The Cross Compile environment has been successfully installed.
Type  echo $PATH   to verify the installation path.
         ECHO_PATH
Now type   arm-none-linux-gnueabi-cc –v
Note that the gnu compiler make use of EABI , the new Embedded Application Binary Interface.
The compilation process is perfect you will see the following screen.
       arm_linux
Now you are ready to cross compile your C code.

mini 2440 porting os

Friendly ARM Mini 2440 is a Single-Board Computer(SBC) built on 400 MHz Samsung S3C2440 ARM9 processor  & 3.5” Touch screen LCD is provided with mini 2440.
It has up to 256MB RAM & up to 1GB NAND Flash and 2 MB NOR Flash with BIOS.

farm2 

Image 2
Friendly Arm Mini2440 is factory preloaded with Linux Qtopia operating system.This post is intended to revive the operating system in case of non booting of device.
Mini2440 has a Flash NAND ROM of 1 GB &  2MB NOR alternate Bootloader.Top left is switch S2 for NOR/NAND boot selection.To the bottom left is the power ON/OFF switch S1.Slide this switch to left for power ON..
NAND flash is used in all removable memory cards because of fast write & erase operations (but slow random access).Because of NAND’s multiplexed command address & data bus it requires lesser number of pins for interface.
NOR flash memory has an advantage of fast Random access ability.It allows for Execute in place (XIP) capability which is often a requirement in Embedded applications.
Friendly Arm uses both types of flash memory.
Friendly ARM is capable of running 3 types of Operating system, Linux,Windows CE(Compact Edition 5.0 or 6.0) & Android.
Friendly Arm boards are available with 1GB Flash memory.Next to SD socket on mini2440 board you see Samsung NAND Flash chip.
                          Image 8
As seen in above picture,S92ALU16J7OTF102 IC is the NAND flash chip (1GB) which is the maximum available Flash memory for MINI2440.
K9K8G08U08 is NOR Flash IC.
In this post I shall demonstrate installation of Linux Qtopia on to NAND flash of Mini2440.
Mini 2440 comes preloaded with a SuperVivi bootloader in NOR flash.It is used to install Operating system on to NAND flash.SuperVivi is the BIOS for mini2440 & is used as a tool to download & burn OS image  to the Flash onboard.
Your Host Computer operating system may be Windows 7 /XP or Linux Ubuntu 12.04.It is easier to install Qtopia on FriendlyArm device from a Windows 7 running PC.Later we shall see how to develop programs in Linux Environment & load it to Mini2440.
From the DVD supplied along with the Friendly Arm collect the required software.
Go to    /images/linux  folder of DVD .
Or you can download it from my Skydrive here.
Copy the following software to a separate folder ,say mini2440 on Desktop :
1.  rootfs_qtopia_qt4   2. supervivi-128M   3. vboot  4. zImage_X35

Image 5
Keep S1 switch found at bottom left in OFF mode (slide to Right).
Connect the 5v/2A adapter pin to the power socket found above the S1 switch.
Connect the RS232 cable to the DB9 connector seen above the power socket.Generally an USB to UART board is used to connect this RS232 to USB of your PC.
Connect the USB-B (device USB) seen above the Ethernet connector to another USB port of your PC.Remember to use the USB cable supplied along with the device.I’ve wasted a whole day by using a cable bought  from market.USB download was not possible & finally using the USB cable  that came along with the device solved the problem.
Keep the S2 switch found above the left corner in NOR mode.(slide the switch to left).
Open up the Device Manager to confirm that USB-UART board used to connect DB9 of Friendly Arm to USB of PC is detected.If not detected,download the driver from here & install it.
Image 20

Now visit the download site of FriendlyArm      http://www.friendlyarm.net/downloads
Download the USB driver & DNW tool .

                              Image8
Take a look at the files & software we collected & stored at mini2440 folder on desktop
Image 21
Unzip the downloaded driver file usb-downloaddr-setup_20090421.zip (1.49 MB) & double click on setup file.
Image9
Screenshots of driver installation are as below.
Image 9    Image 10

Open the Device Manager under the Control Panel.
Now power ON the FriendlyArm by sliding S1 switch to Left.
If the drivers are installed,you see Friendly Arm detected under “Universal Serial Bus Controllers”.
Image 7
We shall make use of a Terminal software to work with Supervivi BIOS .
Download Terminal software PuTTy from here.
You can also use Hyperterminal.But I prefer to use PuTTy as it is fast & reliable.
Open up PuTTy & in the welcome window do the settings as below :
1. Select Connection type as “Serial”.
2.Under Serial line enter the port number (in our case it is COM2).To know the port no. allotted ,open up Device manager & under Ports(Com&Lpt) you see the COM port number allotted to the USB-UART board we have used to connect DB9 of mini2440 to PC.
                     Image 6
3. Enter baud rate as 115200 under Speed.
                                 Image13

4. Save the settings by providing a name mini2440, so that you can load it latter.
5.Now load the saved setting by selecting mini2440 & clicking “Load”.
     A blank black window opens up.Click Enter to see the FriendlyArm BIOS setup under Putty terminal.
                      Image14
Now Unzip the downloaded DNW tool .Double click DNW
At the title bar you see USB:x indicating that USB is NOT ready for transfer of data.
 Image11  
Click Configurations –> Options
Select COM port as COM2 (as seen in Device Manager) ,Baud Rate as 115200.
Download address should be 0x3000000.
Image12
Click Connect under Serial Port.If Drivers are installed properly
USB:OK along with COM2,115200 is displayed on the title bar.
Image15
If  USB:OK is not displayed ,check up the Device Manger for “FriendlyArm “ entry.Else you have to install the drivers again.
Caution : Remember to open the Putty terminal  first & then fire up DNW.If you keep open DNW & try to connect COM port through Putty,it will show error.
Here is the list of activities we’ve to do :
1. Press  x to Format NAND Flash.
2. Press v  to download Supervivi via USB. From DNW transmit supervivi_128m file.
3. Press k to  download the Linux Kernel. From DNW transmit zImage_x35.
4. Press  y to  download yaffs root image.From DNW transmit  rootfs_qtopia_qt4  image.

Type  x  to start Formatting the NAND flash.
Image22
Type  v  to download the Supervivi  file.Terminal will display “USB host connected.Waiting a download “.
Image23
From within DNW select USB Port –> Transmit –> Transmit & browse to the folder
mini2440 where we collected all files & software.Select supervivi_128M file & click OPEN
Image24

Image25
Now type  k to download the Linux Kernel.
Image26
From DNW click USB Port—> Transmit  –> Transmit & browse to select file zImage_X35.
Image27

Image 28
Type  y  to download the yaffs root image which is the file system for QTopia.
Image29
From DNW  select USB Port –> Transmit –> Transmit & browse to the image file rootfs_qtopia_qt4 in the mini2440 folder
Image31

Image 30

Now switch off the device by sliding S1 to right.
Slide switch S2 on top to NAND position (slide Right).
Power ON the device by sliding S1 to left position.
QTopia Linux will start booting on the device.