Segunda-feira , 22 de Junho DE 2015

Recover/unbrick any sw Bricked Zigbee XBee, with Arduino only (no PCB explorer)

 Ok, so first of all, some things you'll need, for sure:

  1. Windows PC. MAC or Linux won't cut it, because:
  2. You need a legacy version (windows only) of X-CTU program (current one is 5.2.8.6), AND NOT THE LATEST ONE!!!!
  3. An Arduino (pretty much any model, I used Uno)
  4. Breadboard and wires
  5. Also make sure you have the XBEE S (2 in this case) drivers from http://www.digi.com/support/productdetail?pid=3430&type=drivers

 

So, this method works with ANY XBee module that is not Hardware bricked, i.e. that was destroyed due to some high voltage or misuse of some kind. This tutorial is meant for people that, just like me, put the wrong version of a given firmware, and also destroyed the bootloader of XBee (even if you didn't, you can use this method), and can therefore do ABSOLUTELY NOTHING with it, not restoring, not reading it back, NOTHING.

 

A pre-requisite for this unbricking, is that you need to completely wipe out all the code inside the Arduino. It is mandatory, because you will use the Tx/Rx pins from arduino to flash the XBee module, and therefore need to clear all the noise from these two pins that might be generated by any existent programming in the arduino. Use the Arduino SDK, and upload the following code to do just that:

 

Now, to the configuration. About the connections that you need to do:

This is the pinout of XBee module. You need to program them like:

Pin 1    ------    Vcc   ------   3.3v

Pin 5    ------    Reset  ----   (leave this wire hanging loose, for later)

Pin 10   ------   GND   ------   0v

Pin 12   ------    CTS   ------   3.3v

Pin 14   ------    DTR   ------   3.3v

Pin 16   ------    RTS   ------   3.3v

Pin 2    ------    Dout   ------   Tx

Pin 3    ------    Din     ------   Rx

 

Im not sure about the order of Tx/Rx pins, as I'm using the arduino shield to interface with the module. Figure out in your case. The looks are:

 

You need to use the arduino to grab the voltage 3.3v (NEVER THE 5v, otherwise you might damage the XBee module) and ground, and transfer them to the board. As you will have several wires pluging into either voltage or ground, you need a breadboard for that. The other couple of wires you see in this board are the Tx and Rx, the wires being used to communicate with the actual XBee board to upload the new firmware. Everything else, you plug into the breadboard (You can also see a rubber band in the pic. that is just to hold the wires without having to solder them). In this picture I forgot to plug the Pin 1 and Pin 10 (Vcc and GND), I've plugged them after the picture ;)

 

After all this wiring, you need to run X-CTU legacy version:

 

Choose the firmware version you want, but I recommen you any with "AT version", and not API

 

Unlike what it was told in many other sources for the baudrate (some say 115200, others 38400, 19200,....), it doesn't matter which one you select in the PC settings' tab. why? it will fail (remember, no bootloader to read). And as soon as you write the firmware, the baudrate will automatically change itself to 9600. Therefore, use this one from the start. DO NOT TOUCH ANY OTHER OPTION. All is good. Switch tab to "Modem Configuration".

This version is so important, and no other and newer version will suit the tast, because this version has a unique treat, that is the option "Always update firmware" you see here. Tick that, select the firmware YOU KNOW WILL WORK (the firmware that was there before you screwing things up), and hit write:

 

 

As you can see, it writes at 9600. IT WRITES! YEEEEEAHHHH!

This is one of the firmwares that works for my XBee Series 2. In case of doubt, please consult this page to assess which firmware family you CAN and CAN'T use: http://knowledge.digi.com/articles/Knowledge_Base_Article/The-Major-Differences-in-the-XBee-Series-1-vs-the-XBee-Series-2

 

From now on, you can double check if the module is unbricked, by trying to read it again. 

Published by fxsf às 23:07

Zigbee XBee modules with Arduino and Atmega8 uController + Breadboard

In this exercise I just tried to use two zigbee series 2 modules (1 Coordinator and 1 End Device) to communicate between themselves, and I wanted to see whether I coud use an external microcontroller (of my choosing, anything, really, that would require command console flashing and not a fancy easy going IDE just like Arduno SDK :P ) with it, and what would be the effort level. 

 

The two XBee modules

In this picture we see two arduino Uno at the bottom of the shield, but only one of them was used. The other was replaced by the Atmega8 microcontroller, all the required wiring (to flash and run it), and a led with a capacitor of 220 Ohm. (In the picture we can also see the USBasp module, to program it).

 

Never mind the circuitry at the background, you can do yours, or ask me about mine ;) Now, the goal: one of the zigbee modules (the coordinator) will start the network and look for peers that might have the same PAN ID (network group id). As it is off course the case, it will find and join the other end device into the network. This process is done automatically with the firmwares I've flashed into both modules (using the X-CTU program from DIGI - http://www.digi.com/products/wireless-wired-embedded-solutions/zigbee-rf-modules/xctu). 

 

After that, I had to program the logic of both microcontrollers. So what I did was the following: I want to send 2 characters from one uController to the other, and having the other turning the LED on or off, depending on the character sent. for that, upload to one of the microcontrollers (for e.g. the arduino, with arduino SDK), the program that will send the characters. REJOICE, the program is already built under examples/communication/PhysicalPixel of the Arduino SDK. Now, the other one will controll the LED, and it is a matter of initializing the serial port, reading the serial port, and do an IF-ELSE case. Because I'm using an Atmega8, I had to program it with a slight different code, but the Arduino SDK equivalent code is here:

 

CommSoftwareSerial-Blink.zip

 

The outcome is as expected:

 

What this Atmega8 receives is:

 

L stands for Low (turn off the led), and H for High (turn on the led). And a little video showing the execution is here as well ;)  :

 

 

 

 

 

 

Published by fxsf às 22:08
Segunda-feira , 25 de Maio DE 2015

Atmega8 + Bluetooth HC05

 This project consists on having a breadboard, the processor Atmega8 without any board, and in the act of programming it and permeating it with bluetooth communication for your personal projects.

 

 

So, in this image we can see the entire hardware used: 

1 x USB ISP programmer (usbasp)

1 x atmega8

1 x itead bluetooth shield from arduino (containing the HC05 BT shield)

2 x ceramic capacitators

1 x external quartz oscilator of 16MHz

1 x led (color of your choosing)

 - x wires

 

I am not covering here how to program the microcontroller with the ISP, but I'm leaving here the schematics with the pin layouts you need to do so, as well as all the command lines I needed to program it:

 

 

 

Here are the command lines:

 

# ping the chip, and all its information (to see whether it's properly connected)
avrdude -c usbasp -p atmega8 -P usb -v

# make the bit fuse. DO NOT TOUCH THIS UNLESS YOU'RE CERTAIN.
avrdude -c usbasp -p m8 -U lfuse:w:0b11111111:m -U hfuse:w:0b11001001:m

# Compilar um programa (the included path is from the OSX. Figure out where are the needed files in your PC)
avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega8 -DF_CPU=16000000L  -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/standard program.cpp -o program.cpp.o

avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega8 -o program.cpp.elf program.cpp.o /var/folders/rn/szrph81d41g26wn1xd61tf5h0000gn/T/build4757347194695071985.tmp/core.a -L/var/folders/rn/szrph81d41g26wn1xd61tf5h0000gn/T/build4757347194695071985.tmp -lm

avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 program.cpp.elf program.cpp.eep

avr-objcopy -O ihex -R .eeprom program.cpp.elf program.cpp.hex

# erase the chip, before flashing with the .hex file created
avrdude -c usbasp -p atmega8 -P usb -e

# flashing the atmega8
avrdude -C avrdude.conf -v -p m8 -c usbasp -P usb -b 115200 -D -Uflash:w:program.cpp.hex:i

 

An example of a batch file is made available at the end, as a makefile, to automatize the entire process.

 The first image shows that my connections are already made. A special note to the necessity to use an external clock, because the one provided inside the uController does not have the resolution required to support the programming. Hence, a couple of .22 pF ceramic capacitators are needed, and linked to both the ground and the oscilator. From the oscilator, you link each of its "feet" to the XTAL 1 and 2 from the scheme above.

Next image shows the connections of the oscilator in a better way, as well as the led turned off.

 

 

The led will blink whenever it receives bluetooth communication:

 

Now, I connected my phone to it. the uController scans all the communications, and when the received communication is (in this case) a given character (in this case, the caracter 'x'), it will reply with an "ok" message:

 

 

 Batch makefile:  flashuC.sh   dependencies.zip  (dependency libraries and configuration files to use this makefile)

Published by fxsf às 15:47
Segunda-feira , 18 de Agosto DE 2014

IoT Application and Interoperability of Complex Systems

 

 

 
 
Published by fxsf às 14:19
Sexta-feira , 27 de Junho DE 2014

Multiple Bluetooth devices connected simultaneously: OSX, Lego NXT, Arduino, Phone, etc...

 

I programmed an OS X application that is able to connect to several Bluetooth devices with the profile SPP (Serial Port Profile). As you can see with the print screen, I've connected 2 phones (tablets with Android), two Lego Mindstorm NXTs, and an Arduino UNO. This application allows you to send and receive text messages through this protocol, and if it detects a Lego NXT, a new type of window will pop up, allowing you to control the NXT servos and sensors. All you have to do is specify the sensor and hit poll (the poll of the servos is not working at this time, but the most important, i.e. the sensors, is). As you read, it also connects several NXTs simultaneously, and in such case, several NXT Controlling windows will pop up, allowing you to controll them all.

 

APP:  Bluetooth_HUB.app.zip

Xavier

 

PS: if you don't want to integrate several BT devices, and you just want to play with your NXT, you can use this app: NXT_Controller.app.zip. Of all the ones I found on the internet, that's the finest :). Remember, one NXT at a time.

Published by fxsf às 18:57
Quinta-feira , 19 de Junho DE 2014

Bluetooth: Server with multiple clients (OS X + Arduinos)

 My current goal has been roaming around integration of complex systems, i.e. Internet of Things (IoT). At the beginning of this project I was confronted with many sources constantly stating that it was impossible to connect several gadgets simultaneously with Bluetooth, that that was only possible in theory (which, then again, one could only integrate 7 slaves to a master). Also, I once found that the version of Bluetooth did count, that BT 2.0 could only connect to one device at a time, whilst with BT 4.0 LE we would be able to connect up to 7 devices. What I'm sure, though, is that you truly are limited by the category of the gadget, that is you can only connect one type of some devices (like audio speakers or BT printers), while that constraint doesnt happen with other BT Classes. 

So, as you can see, this project started with heavy research, research that wasn't always backed up by more than suspitions, doubts, rumors, and too few examples online. I started with Java, but I soon found that the BT implementation jars wouldn't work out with Mac OSX, as they only work with 32 bits, and there is no Java 32 bits for Mac OSX, only 64bits. Going to C/C++ didn't prove helpful, because for that I needed to use Apple's Bluetooth framework either way, and that path would be far more painful and frustrating than just using XCode + Objective C, and develop something with the native tools I had. And so I initiated a tiny bit less frustrating Objective-C learning curve. Bottom line: It worked!

 

To start such integration, I chose to create a device layer in my computer, that is able to accept and connect any type of device. I used Mac OSX with XCode, and I developed an application for mac osx that accepts several arduinos (I don't have many many arduinos to test the limit, so I'll leave that to you). I am also trying to connect to a LEGO NXT microcontroller, I did it successfully with this same code, but it is not being covered here (as programming to the NXT is a whole new discussion). Scheme:

 

 

For you to have arduino communicating through Bluetooth, you need to have a BT Shield, and I chose mine, ITEAD BT v2.2:

 

 And I tried this with 2 BT arduinos:

 

 

 I plugged in each arduino to both my USB ports (that's right, more than this, and I would have to buy an USB HUB), and then I used the follow command in the command line:

 

  • screen /dev/tty.usbmodem1411 38400                   (arduino on the first usb port)
  • screen /dev/tty.usbmodem1421 38400                   (arduino on the second usb port)

Off course that the USB port used will be different than mine, but you can figure that out with little debug. These commands create a serial connection with your native OSX, hence no need to use extra software (helpful, right? Told you). The two arduinos already have the code updated at this point, to be able to send text through bluetooth and to receive and display received text through BT. Looks like this:

 

 

The OSX App I develop is as follows:

You have a status text at the beginning, then the box where you can write your own text, and, when you hit Enter, that same text will be broadcasted to all the BT devices connected (I put a limit of 10 connected devices in the code, just stating...). The last box is where you receive any text sent from the devices, any connected device. The square box attached is how we can pair and add any BT device:

 

And then, the following happens:

 

 

The status message gets updated, and now we can write any text to be broadcasted. The first arduino already got it :)  :

 

 

The replies of the arduino are duly shown:

 

Now lets add the other arduino:

 

And now, lets send a message to BOTH the arduinos:

 

All working:P  :

 

Try the app:   BluetoothHub.app.zip (the OSX master app) BT_Slave.ino (code for the arduino slaves).

 

Conclusion:

It is possible to connect devices simultaneously and using mac osx as server, and with different BT versions (OSX has BT 4.0 and arduino shields are BT 2.0). I also didn't have to rely on multi-threading solution, as the COCOA frameworks handle events nicely.  Again, I didn't try the scalability of this, but I am a step closer to integrate all possible devices under the same framework! Next step, integrate different devices with different profiles.

 

Published by fxsf às 15:28
Segunda-feira , 09 de Junho DE 2014

Arduino + Adafruit CC3000 WIFI shield to Consume Tomcat+Netbeans WebServices

Dear All,

I am giving my 2 cents to the community of Arduino, whatever little that may be. My goal is to widen the support available to Arduino, to the WIFI shield from Adafruit CC3000, and how to use those to connect to a WebServer made in your computer: Netbeans 8 + Tomcat 8.0.8. With this, I want others NOT to have the time consuming learning curve I had. 

Conceptually speaking, I am using a webserver in my own laptop (MacOS), with WebServices deployed in Java+Tomcat. Then, I use Arduino as a CLIENT, to consume SOAP Web Services. The Idea is not to put the Arduino as a Server, as some tried with the Yun project, but to create an autonomous Agent (with the arduino as Brain, like a car, whatever...), and having the Arduino asking questions to the server via WebServices. 

1st) The first step was to make the webservices available NOT ONLY in Localhost. While developing to Arduino, I constantly made the stupid error of considering that Localhost from Arduino and my PC was the same! DUUUUHHHH. Make sure your tomcat can receive requests from outside localhost, as without this, communication is dead.

2nd) Go To http://localhost:8080/ (or the url you use to manage Tomcat or your application server), Manager App, and make sure your app is deployed. Go to Netbeans, select your webservice, mouse right click and select "Test Web Service". In my case, I got:

 

  • ddress: http://localhost:8080/CloudTest/Xav13ruaPRO
  • WSDL: http://localhost:8080/CloudTest/Xav13ruaPRO?wsdl
  • Implementation class: WSHandler.Xav13ruaPRO

You need this information (Address and WSDL) to do the Job.

3rd) Go To http://www.soapui.org/, and download The SoapUI Pro Trial. You have a 15 days trial, so don't worry. Why do you need it? Well... you don't NEEEEED it, but you need a way to know exactly how to manually formulate the SOAP request in Arduino. This app is for that. See the video in that page, create a project, and paste the WSDL link of your webservices (in my case, http://localhost:8080/CloudTest/Xav13ruaPRO?wsdl). Then, choose the tabs "RAW" and "XML", and you will have (in my case) the following:

"RAW" (The header for the HTTP request):

  • POST http://localhost:8080/CloudTest/Xav13ruaPRO HTTP/1.1
  • Accept-Encoding: gzip,deflate
  • Content-Type: text/xml;charset=UTF-8
  • SOAPAction: ""
  • Content-Length: 208
  • Host: localhost:8080
  • Connection: Keep-Alive
  • User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

The "Content-Length: 208" is reaaaaalllllllly important, to the point that if you miss this length, you will get an error answer from your server. So, I like this software because of this feedback.

"XML":

  • <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsh="http://WSHandler/">
  •    <soapenv:Header/>
  •    <soapenv:Body>
  •       <wsh:ServerName/>
  •    </soapenv:Body>
  • </soapenv:Envelope>

You can also use netbeans to generate a sample SOAP request, for the same purpose. My case, in netbeans, it gave me:

  • <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  •     <soap:Body>
  •         <ns0:ServerName xmlns:ns0="http://WSHandler/"/>
  •     </soap:Body>
  • </soap:Envelope>

So, really similar, but you need the HTTP part PLUS the SOAP Envelope part.

4th) The Arduino Code.

#define WEBPAGE      "/CloudTest/Xav13ruaPRO"
...
Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 8080);
  if (www.connected()) {
    Serial.println("TCP Connection   OK!\n\n");   
    www.fastrprint(F("POST "));
    www.fastrprint(WEBPAGE);
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: 10-22-240-187...DoesntMatter.....com.pt:8080\r\n"));
    www.fastrprint(F("Accept-Encoding: gzip,deflate\r\n")); 
    www.fastrprint(F("Content-Type: text/xml;charset=UTF-8\r\n"));
    www.fastrprint(F("Content-Length: 208\r\n"));
    www.fastrprint(F("Connection: Keep-Alive\r\n"));
    www.fastrprint(F("User-Agent: Apache-HttpClient/4.1.1 (java 1.5)\r\n"));
    www.fastrprint(F("SOAPAction: \"\"\r\n")); www.fastrprint(F("\r\n"));
    
    www.fastrprint(F("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"));
      www.fastrprint(F("<soap:Body>\r\n"));
        www.fastrprint(F("<ns0:ServerName xmlns:ns0=\"http://WSHandler/\"/>\r\n"));
      www.fastrprint(F("</soap:Body>\r\n"));
    www.fastrprint(F("</soap:Envelope>\r\n"));
    
    www.fastrprint(F("\r\n"));
    
    www.println();
  }


Attached, you have the full code, for the shield mentioned.

5th: The result, Which is the most important part:

Hello, Xavier!
Free RAM: 1151
Initializing...
Attempting to connect to OpenFCT ...    Connected!
Requesting address from DHCP server...   OK

IP Addr: 11.22.231.199
Netmask: 255.255.254.0
Gateway: 11.22.231.1
DHCPsrv: 11.22.231.3
DNSserv: 11.22.231.33
10-22-240-187.un....com.pt -> 11.22.231.199

TCP Connection   OK!
-------------------------------------
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/xml;charset=utf-8
Transfer-Encoding: chunked
Date: Wed, 28 May 2014 11:04:25 GMT

6e
<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body>
8f
<ns2:ServerNameResponse xmlns:ns2="http://WSHandler/">
<return>Server Name: Xav13rua PRO</return>
</ns2:ServerNameResponse></S:Body></S:Envelope>
0

-------------------------------------

Disconnecting

 

 

 

In here, my webservice gives the return string "Server Name: Xav13rua PRO". This is a webservice to retrieve the host name of the server.

 

 Code:  WebClient (code for arduino),  conf_arduino.txt (this is to configure the Bluetooth shield, in command mode. the set of commands I performed).

 

 

Published by fxsf às 16:44

About Me

links