domingo, 14 de abril de 2013

Electret, Xbee 868 pro and Cosm graphs


The pupose of this project is to take noise measurements from a electret microphone, read them with atmega328p ADC and send through xbee 868 pro to a computer where a dongle with another xbee 868 receives the values and send to cosm for showing a graph.

I will detail here the tips dealing with xbee and cosm, you can read about taking the electret output in a previous post.

I used xbee 868 pro just because is what I have in hand. Atmega328p is powered at 5V, from a 7805 regulator, so I used a xbee regulated explorer board from sparkfun to connect the xbee. It has a micrel 5205 voltage regulator to suply 3.3V to xbee, and a tricky diode at DIN pin to convert signal lines from 5V to 3.3V.


This diode is worth some comments, as it gave me some headache, and made me learn some things about pull up resistors, and how they are used for example for I2C bus. I recommend this reading about it:

Atmega328p output pins are [4.2 - 5]V (5V supply), so, [3.2 - 4V] (diode 1V forward) after DIN diode at Xbee DIN input. And Xbee inputs are [0.8VCC - VCC], that is [2.64-3.3] (3.3V supply). That is supposed to match, but reality is that it is mandatory to have xbee internal pull up at DIN pin activated for this to work. DIN pull up is not activated by default at 868 pro module, you need to activate it with the PR AT command. Don't know what is the exact reason of this not working without it.

Another tip about using Xbee with atmega328p is about the xbee-arduino library. I had some confusion with API mode, You can configure API mode with AT commands (or X-CTU software), setting AP parameter to 1 (API mode) or 2 (API mode with escaped characters). And after that, everything you send through xbee serial uart will be encapsulated in an API message, so you won't need to create a API message using xbee-arduino library, or you will end up with a complete API message encapsulated inside another xbee api message, but probably you will not be a fool such as I... Rest of the Xbee configuration, destination address broadcast, same net id on both xbee modules, 38400 baud rate (for some reason I had problems using 9600).

This is a photo of the board that take electret values, amplifies them with LM386 N1 and send wirelessly though xbee:



In the recepction part I have a small pc, with a xbee usb dongle. It has a c# program that manually parse xbee API message and send the value to Cosm. Here you have the atmega and c# solution. I use SoftwareSerial to connect to Xbee beacuse "standard" tx and rx pins of atmega are used to program the micro and debugging through serial monitor. The important part about sending values to Cosm is this:


byte[] postArray = Encoding.ASCII.GetBytes(value.ToString());
WebClient wc = new WebClient();
wc.Headers.Add("X-PachubeApiKey", apiKey);
byte[] response = wc.UploadData("http://www.pachube.com/api/" + feedId + ".csv", "PUT", postArray);



And here you can see the graph obtained at Cosm:







No hay comentarios:

Publicar un comentario