Sábado , 26 de Dezembro DE 2015

Arduino and Zigbee: CC2530

 This is one of the DIY examples we can do for the internet of things, and the one I implemented in my home. The objective was to make a light turn on or off, and having a radio switch sending the ON or OFF command through the air. 

 

 

There are many reasons why anybody would want to do something like this. Mine was that I a garage,  a corridor, and  some stairs in between with lights on them. I have movement sensors both in the garage and the corridor (because both the garage and the corridor have their respective lights), but I needed to have the lights from the stairs to turn on from BOTH the movement sensors. Instead of running 220v cables through the walls from both movement sensors, I've connected both movement sensors with zigbee-enabled radios hooked up to arduinos, and the zigbee coordinator right by the lights to be turned on at the stairs. With this, these lights turn on from both directions (coming down to the garage, or going up from it). 

 

The devices I used was the CC2530 radios from Texas Instruments. In the picture above we can see the arduino Uno used, as well as the radio transceiver coupled onto its development board. This transceiver has a range of 1.5km (if I remember correctly) in straight line, so I pretty much love the range. This ends up being the reason for doing this with Zigbee and not with other enabling communication technologies like Bluetooth or Wifi.  We can see better the radio in the following picture:

 

 There are many ways we could approach the problem with this hardware. We do not need to deploy the hardware on sight with the development board, but you can choose to do so (I wanted to save this board for future developments). Another design choice of yours is whether to simply bypass the arduino altogether and develop the entire code for the microcontroller CC2530. I did both options, but I ended up choosing this one. The vendor of this chip provides some code examples for you to deploy with IAR workbench with 8051 addon (the family of the processor of CC2530), and it brings binaries of firmware for you to directly deploy into the devices (containing either the zigbee coordinator or the zigbee router profiles). I developed the code in IAR, deployed it, and even though I could bypass the use of another microcontroller in this (hence less hardware and energy spent), the problem of buying hardware from China is that the development board is not the same as of Texas Instruments. Because of that, all the examples of Z-Stack provided by TI for this Chip do not suffice, and Therefore I prefer deploying another microcontroller and have the transceiver behaving as expected, rather than having things not working and not knowing exactly why. 

 

The receptor, turning on/off the light, with the zigbee coordinator profile:

 

 

 

 In the above picture I am using the CC2530 without the development board, a 5v relay to act on the lights (turn them on or off), and a power transformer (step down voltage from 220v to 5v), provided that we are powering the circuit with the main current and not with batteries. These are the commands sent by the sender/switch, which gives the commands:

 

 


The sender, the switch giving the commands to the light receptor, with the zigbee router profile:

 

 

For you to understand the switch, and why the choice of electronic components I did, I have to clarify some things. First, I want the arduino and CC2530 to be permanently turned on, but I want to have the command being sent with a current coming from  a 220v wire provenient from a movement sensor:

 

So, I have two considerations right here. The first one is that I need to have a power step transformer (step down from 220v AC to 5v DC). The second thing is that because I have to have two power transformers (one for arduino + CC2530, another for 220v signal control), the base line (ground) will likely not be the same, and because of that, the arduino will misbehave when receiving (or not) this electrical 5v+ signal. Arduino needs to have the same 0 or 5 volts coming from the same energy source with the same ground. To solve this second issue, I chose to apply a relay, with a transistor and a resistor (and that is what you see two pictures above, for the sender):

 

 

(PIN 2 is the control pin I used in the arduino to read whether the light should be turned on or not). The GND and VCC from the picture are the 220v coming from the main power, which originate from the movement sensor. The transistor used is the BC547 NPN bipolar, coupled with a 10K ohm resistor. Basically what this does is whenever the relay is powered on by the movement sensor, the arduino receives 5v control signal that it understands (regulated by itself). Now soldered, outside the breadboard :)   :

 

 

 

The result, after assembed, and ready for deployment:

 

 

 

 

CODE:    :)

ArduinoLight.ino   ArduinoSwitch.ino

 

 

Published by fxsf às 01:20
Quinta-feira , 27 de Novembro DE 2014

TinyOS, LEGO NXT, and OSX

I created a project that consists in the main repository of TinyOS and the project NXTMOTE. The project NXTMOTE doesn't work right out of the box; you can't do the "make" command, under the applications, and expect them to work. Therefore, in order for you to use the NXT with TinyOS, you need to add the new target "nxtmote" to TinyOS. I've done just that, and even though I couldn't integrate the upload tool "fwflash" as I wanted (that is, just doing "make nxtmote install" under the application folder), I can still do it manually.

 

Keep in mind, though, that this is not further development on the NXTMOTE, whose development seems to have ended many years back. This is just a successful attempt on running NXTMOTE on OSX. Every application that didn't compile before with this target, won't compile now. 

For this to work, you have to already have NESC compiler installed on your system, and after downloading this package, you have to export the $(installationFolder)/tinyOSsourceNXT/misc/src/libnxt/ to your path:

 

export PATH="$(installationFolder)/tinyOSsourceNXT/misc/src/libnxt/:$PATH"

 

Apart from this, I had to specify some paths manually in some Makefiles, like the file "Makerules" under /support/make/Makerules. If you get some erros related to not being able to find the specified target, then it means it is not reaching every Makefile*. For instance, in this "Makerules" file, you can find  on the line 83 the following:

 

TOSMAKE_PATH += /Users/Xavier/Documents/tinyOS/tinyOSsourceNXT_test/support/make/platforms/at91/

 

This is the path for the platform at91, of the NXT. Needless to say, it will be different in your case, so in your case remove the prefix "/Users/Xavier/Documents/tinyOS/tinyOSsourceNXT_test", and add your instalation folder. If you don't know which one is it, just perform the command pwd in the console, and you'll find it.

 

After this, you should be done with the prerequisites. If you're not, PLEASE INSTALL THE TINYOS PROJECT ALONE, and see what you're missing.

To verify the installation, you can compile the Blink application, as I did:

 

cd $(installationFolder)/tinyOSsourceNXT/apps/Blink

make nxtmote

 

(if, in here, you get the error "build/nxtmote/app.c: failed to truncate target: No such file or directory"), then it means it cant create a folder for the build. In this case, before the make, do:

 

mkdir build/nxtmote

make nxtmote

 

 

If successful, you should see this:

 

To upload, the command is as follows:

 

fwflash build/nxtmote/main.ihex

 

 

THAT'S IT. What did you get? This:

 

 

 

Project: tinyOSsourceNXT.tar.bz2

Published by fxsf às 18:57
Sexta-feira , 07 de Novembro DE 2014

Contiki OS on Mac OSX + Zolertia Z1 MOTES(msp430-gcc-47)

 It is possible to run Contiki OS on OSX, but it took me several days to do so. Fortunately it is easy as eating pie, so here it goes:

 

 

http://zolertia.com/products/z1

 

1 ) Get Contiki OS

 

git clone https://github.com/contiki-os/contiki.git contikiOS

 

or 

 

wget https://sourceforge.net/projects/contiki/files/Contiki/Contiki%202.7/contiki-2.7.zip

 

for the latest 2.7 version of contiki.

 

 

2 ) Compile/install the TOOLCHAIN for msp430 processors

 

It is crucial that you use the development version, as the long term supported toolchain msp430, on version 4.6.3, has a bug on the display of the mote's readings in the console (as shown in the image):

 

sudo port install msp430-binutils-devel msp430-gcc-devel msp430-gdb-devel msp430-libc-devel msp430mcu-devel mspdebug 

 

This is MANDATORY, and, at the end, you should have the following packages installed:

msp430-addr2line  

msp430-cpp        

msp430-gcc-ar     

msp430-ld         

msp430-ranlib     

msp430mcu-config

msp430-ar         

msp430-elfedit    

msp430-gcc-nm     

msp430-ld.bfd     

msp430-readelf    

mspdebug

msp430-as         

msp430-g++        

msp430-gcc-ranlib 

msp430-nm         

msp430-size        

msp430-c++        

msp430-gcc        

msp430-gcov       

msp430-objcopy    

msp430-strings      

msp430-c++filt    

msp430-gcc-4.7.0  

msp430-gprof      

msp430-objdump    

msp430-strip       

 

 

3 ) Install the support for the Zolertia Z1 hardware

 

Install the latest VCI drivers from SiLabs:

"CP210x USB to UART Bridge VCP Drivers

 

The CP210x USB to UART Bridge Virtual COM Port (VCP) drivers are required for device operation as a Virtual COM Port to facilitate host communication with CP210x products. These devices can also interface to a host using the USBXpress direct access driver."

http://www.silabs.com/products/mcu/Pages/USBtoUARTBridgeVCPDrivers.aspx

 

BSL (Bootstrap Loader).

You have more than one option (see http://processors.wiki.ti.com/index.php/BSL_(MSP430)), but I chose mine, based on python as contikiOS itself

 

PySerial

pyserial (download from http://pypi.python.org/pypi/pyserial)

(in command line:) python setup.py install

 

PYTHON-MSP430-TOOLS

python-msp430-tools (not mandatory, but it helped me debuging several problems)

download ActivePython (https://code.activestate.com/pypm/python-msp430-tools/)

(in command line:) pypm install python-msp430-tools

 

In order to fix the following error while "make login" into the mote: 

"... serialdump-linux: cannot execute binary file"

we need to do the extra steps:

 

 

4 ) Recompile the file contiki/tools/sky/serialdump.c

 

This is so because the serialdump-linux was compiled for 32bit environments:

 

cd contiki/tools/sky

 

edit serialdump.c file:

 

mate serialdump.c

 

edit the following lines:

 

#define BAUDRATE B57600

#define BAUDRATE_S "57600"

 

for Z1's correct baudrate:

 

"#define BAUDRATE B115200

#define BAUDRATE_S "115200""

 

(in command line:)  gcc -o serialdump-macos serialdump.c

 

 

5 ) Edit the file contiki/platform/z1/Makefile.common

 

In the line 63: 

 

"SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux"

 

and put your compilation:

 

"SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-macos"

 

 

 

 

Published by fxsf às 20:02

About Me

Links