5/18/2011

Lights, Camera, Actuate! - Part II

Sometimes it's a good advice just to let one or two days pass and everything works. I started from scratch as I hit a roadblock while doing the "Direct Actuation Example". In the end everything worked, but it was a rocky road.

XBee Coordinator and three XBee Router (nodes) connected
As you can see in the picture I configured three nodes (XBee Router AT firmware 2270) with the following AT commands: ATID 2001, ATJV 1 and ATD0 4 (digital pin DIO 0 digital LOW, physical pin 20). Maybe it's a good habit to reset/ restore values after you used the XBees in other projects and to flash the firmware when starting a new project. That's what I also did for the Coordinator, which I programmed in API mode, with ATID 2001, and ATAP 2 (API mode 2). I'm not sure if this might be the source for the problems - in the past I only checked "Enable API" and "Use Escape Characters (ATAP =2)" in X-CTU on the "PC Settings"-Tab. and wrote the AT commands to the XBee. Everything seemed to work. This time I configured API mode 2 on the "Modem Configuration Tab" and then wrote the AT commands to the XBee.

In the picture at number "1" you can see a node queried and responding with the actual state DIO 0 (physical pin 20). Number "2" shows a pushed rocker switch and the toggled pin 20 on another node.

This was my Breadboard configuration where the 3.5mm jack plug goes to my power switch (see blog). I used a BC547A instead of the 2N3904 but many of the standard NPN-transistors will do. I took a 10k ohm resistor which fed about 0.5mA to the base of the transistor (Ibase = Vcc-Vbe/ Rbase). Enough to drive the minimum 6 mA needed by the power switch optocoupler to drive the relay in the power switch.


For testing purposes I configured a breadboard with only a LED to show if the XBee DIO 0 was LOW or HIGH. This was my breadboard configuration.
Breadboard with XBee Router, voltage regulator and transistor to drive LED
ALWAYS check the pin configuration of the electronic parts. For example the pin layout for 2N3904 is "EBC" (Emitter-Base-Collector from left). The BC547A I used has "CBE". A BD139 has "ECB". Confused?
In my breadboard layout above there is a BC547A and the voltage regulator is a LC33FV, which has Vin, GND and Vout (from left).

5/16/2011

Lights, Camera, Actuate?

This is the first time I really ran into trouble - the "Direct Actuation Example" (chapter 6, page 172) doesn't work.

I configured everything as described in the book (Coordinator API (ATAP=2) via USB connected to PC, Router AT on breadboard with voltage regulator, transistor and power switch) but unfortunately the processing code gives me an "XBee request timed out" error.
I can click on the red rocker switch but nothing happens - I just get further timeout errors.
I reconfigured everything many times, re-wrote the firmware and AT commands on the XBees, replaced the XBees with others (I have four at the moment) but I keep getting the timeout error.
I'm quite new to Processing and don't know much about the xbee api - I'm not even sure that this is a software error.

So I'm stuck at the moment. 

As I can see there are some people out there following the blog, maybe one of them might have a solution to my problem.

While I was preparing the direct actuation example I had some issues with the wiring depicted in figures 6-4 and 6-5 on pages 178/ 179 and the text on page 176 describing the PowerSwitch Tail in the book. See the Errata for further information.

There is a new PowerSwitch Tail available at powerswitchtail.com and now they also have a 240 volts version! This might be even better than the one I purchased at ELV (s. blog posting), because you might switch it directly with your XBee (3.3 volts with 3mA!) with no need for the extra resistor and transistor.

And guess what's driving the relay this time? An optocoupler! What a coincidence!

5/09/2011

Offroad: Salvage Time

For the "Direct Actuation Example" (page 172 and following) I will have to deviate from the proposed course of action due to two reasons. First in germany we have a 230 volts AC power grid. That means I have to substitute the 110 volts power switch tails (SFE COM-09842) with a 230 volts version as proposed in one of the preceding blogs 230 volts power switch interface .
Second I would like to build an RF alternative where no direct connection between microcontroller/ XBee and the switching device is needed. For that project I needed only one additional (electronic) part and was to stingy to order it online and pay a multiple of shipping costs compared to the tiny electronic part I needed. I was surprised how much of "them" I found in my pile of old electronic devices waiting to be salvaged (you can find more about that here). Could you guess what I was looking for?
Details shortly.

Update:

I was looking for

You can switch a lot of things with the help of optocoupler. They have names like "4N35", "CNY17F-4" or "PC817". The special thing is that the circuits aren't galvanically connected. You can learn a lot of optocoupler here.

5/07/2011

Sleeping Be(e)auty

Voltage regulator LM2937, XBee (End Device), LM335
One thing I was really waiting for was the "sleep mode" feature of the XBees. This might be a huge energy saver.Mobile Sensors with XBees running on two batteries without microcontroller could be as tiny as a pocket lighter and run for months (or years) without changing the power source!
Thinking about solar powered/ energy harvesting devices they could even stay longer connected to a (sensor-) network with the possibility of bidirectional communication (transmitting sensor data or actuate a device). A lot of applications could come into mind where neither wires nor a AC power source is required.

With "Sleep Mode" End Devices are introduced in Chapter 6 which differ from routers mostly by falling asleep for a certain amount of time. Because they do, you might have trouble. I will tell you later what my personal experiences were while digging through the first pages of the chapter.

To begin with you have to configure the XBee as an end device and configure the corresponding AT commands for your intended project. Again everything is described very well in the book. Until text meets "expert" (me).

WARNING.

Check all the settings twice while programming the commands via the terminal. After writing it to the XBee flash your bee might turn into a lifeless piece of epoxide resin if you made a "fat finger trade"  - that means you typed in any command that turns the XBee into a dumb object. Or into a hyperactive. As I did.

In the parts list of the "Simple Sensor with Sleep Project" there is an alternative configuration with two AA batteries mentioned. If you read my blog entry about the LM335 issues, you might have noticed, that I had some problems getting exact temperature readings if the supply voltage falls below a certain value. I suspect unless the batteries are very, very fresh you might get into trouble with this double AA option and get erroneus readings. I tried it with batteries and rechargeable batteries and both didn't work at room temperature.

But everything worked fine with "normal" supply voltage. I put my multimeter into current measurement mode and could observe how the current consumption fell from about 41.75mA to 2.39mA for a second to go up again like the interval (ATSM4, ATSP64, ATST14) programmed into the XBee.

LM335 directly connected to PIN 13
2.39mA.Hm. That's not zero while sleeping. The LM335 draws 1mA at 25°C (supply voltage 3.3V, resistor 330 ohms). The rest goes to the voltage regulator (quiescent current 1.4mA, datasheet says 2mA so that's in line with the specs). I did some tests and connected the Vcc of the LM335 (330 ohms resistor) to pin 13. This pin is only "HIGH" when the XBee awakes. So the temperature sensor only draws current, when the sleep mode is inactive. At room temperature everything worked well - I got the same temperature readings as before. I'm still thinking about getting the 3.3 volts without voltage regulator. Two batteries are not sufficient for the LM335, three would be too much for the XBee (Vcc limits: 2.1 - 3.6 volts). Any hint how to solve this problem is appreciated.

One last word regarding typing in the AT commands for the sleep mode. Somehow while testing some options I typed in something wrong. The result was a non- or better hyperactive reacting XBee. I spent a lot of time to get the device into command mode with the help of the terminal in X-CTU. If you look for the green "DTS"-light and at the same time typing in the "+++" you have a chance to talk again to the XBee. I was lucky and tried to program the settings described in the book. And again my XBee got hyperactive. In the end I flashed a router firmware (after an arcade like typing to get into command mode) and then went back to an end device firmware. Keep in mind to activate "always update firmware".

5/01/2011

Offroad: Programmable XBees

If you were wondering if there is a way to put some logic into the XBees have a look at the digi.com Website. Under "Learning Center -> Video and Recordings" you find a lot of XBee related video stuff. One of the recent additions to the XBee product line (see XBee/ RF Family Features Comparison) are the programmable XBees. They are called "XBee-Pro ZB (S2B)" (XBee-PRO Programmable Extended Range Embedded RF Modules) and have a 32 KB Flash/ 2KB RAM Freescale MC9S08QE application processor. You get full insight of the new Bees if you search for "Programmable XBee" in the video section.

4/30/2011

LM 335 issues

2.9 volts, 2* 3.3 volts
Those LM335 issues as stated in my last blog entry are still bothering me. I did some additional tests and found out something interesting (at least for me). If the voltage drops below 3 volts, the LM335 begins to post erroneous values. That may be no surprise because the circuit has a typical operating output voltage of 2.98 volts (at 25°C) according to the datasheet (page 2 "Temperature Accuracy").

I wonder if 3.3 volts as used in the preceding experiments are enough power to operate the LM335. I couldn't find any minimum operating voltage specs in the datasheet except an application information on page 6 ("Minimum Temperature Sensing") where V+ is 15 volts for three temperature sensors. My guess is, apart from powering the LM335 with the needed current  through R1 (400µA to 5mA) you need at least 5 volts for stable operation. Tell me if I'm on the wrong track.
I'm also still wondering how to calculate R1, which in my understanding supplies the required current to the LM335. Any input from a reader would be very welcome.
At the moment I'm preparing chapter 6 "Sleeping, then changing the world" where operation with two AA-Batteries is used to power the end nodes. Having the questions above I'm wondering if any operation only from batteries and without voltage regulator is possible at all. The XBees will be no problem - they operate from 2.1 to 3.6 volts according to the datasheet (the PRO needs 3 to 3.4 volts). But what about the LM335?

Update: While surfing the web I found some entries how to calculate R1. As the temperature sensor acts like a voltage divider and everything bases on Ohms law you have to calculate the circuit voltage (in our experiment 3.3 volts) minus the LM335 voltage (depending on the temperature, at 25°C 2.98 volts) and divide it by the needed current (400µA to 5 mA). In short: R1= (Vcc - Vlm335)/ (0.4 to 5mA).
That gives you an envelope which you have to adjust to your expected temperature range.

Sounds a bit confusing? Here are some examples:

Vcc is 3.3 volts, temperature is 25°C (= 2.98volts Vout LM335):

R1 = (3.3V - 2.98V)/ 0.0004A = 800 ohms (400µA = 0.0004A)
R1 = (3.3V - 2.98V)/ 0.005A = 64 ohms (5mA = 0.005A)

So for "room temperature" (25°C) the suggested value of 300 ohms for the circuit works well (everything from 800 to 64 ohms actually should work at least exactly with 25°C ambient temperature according to the datasheet).

What if temperatur changes?

It's 10mV per °K so to reach 3.3V as output from the LM335, everything above 55°C might be a problem because supply voltage almost equals LM335 output voltage (2.73 volts + 0.55 volts = 3.28 volts). At -40°C (= 2,33 volts Vout LM335) and 64 ohms (as calculated above) you would exceed the current with a value of 6.25mA. With 300 ohms you are still safe (3.3mA current for LM335 at -40°C).

So from -40°C to ~55°C and 3.3 volts supply voltage taking 300 ohms for R1 we might be safe.

What if supply voltage changes?

Let's assume supply voltage drops to 2.93 volts generated by two (rechargeable) batteries. At "room temperature" (= 2.98 volts Vout LM335 at 25°C) we might have a problem (at least in a normal climate condition).
Temperature has to drop to about 10°C or lower (2,83 volts Vout LM335) where you could use a R1 from 2 ohms (5mA LM335 current) to 20 ohms (400 µA LM335 current). With the suggested 300 ohms you would fall below the required current for the LM335.


The options:
  1. You could use a second power supply/ step-up converter with at least 3.8 volts (according to the datasheet the LM335 operates up to 100°C). You might have to adjust the resistor value for R1 to your expected temperature range. Same for digital sensors like DS18S20/ DS18B20 because power supply ist 3 to 5.5 volts according to the datasheet.
  2. Take an alternative temperature sensor like the TMP36. This part needs a supply voltage from 2.7 to 5.5 volts which would be almost perfect for two-batterie powered devices and maybe also for a two rechargeable batterie-pack if the voltage stays above 1.35 volts each (I'm not sure how low the voltage might drop before the TMP36 quits working).
For more insight on temperature sensors there is a great tutorial at Ladyada.net.

4/29/2011

Hot and cold bee(r)s

Voltage regulator, XBee, LM335
One of the most common applications (with microcontrollers) is measuring temperature. Whether it's the current outside temperature, the climate in your freezer or for controlling the heating installation in your house - you will need at least a thermal sensor. With XBee you need no long wires at all and additionally you can create a temperature network around the house and display everything on your computer (with a little help of Processing). Awesome!

LM2937ET-3.3 (top), LF33CV (bottom)
That's what the "Simple Sensor Network" is about in chapter 5. New to the game are 3.3 volt regulators and the very ubiquitous temperature sensor LM 335 (Datasheet). I couldn't get the recommended LD1117V33 and bought two different voltage regulators instead - LM2937ET-3.3 and LF33CV . Two different ones because I wanted to test how much power they use while regulating and which one would be better for any power saving mode, if there is a difference at all (more on that later). In any case check the order of the legs - in my case for both regulators from left to right with the writing on the front: IN, GND, OUT (the LD1117V33 has GND, OUT, IN).

Update 5-15-2011: I was revisiting the voltage regulator wiring as I was beginning the "Direct Actuation Example" in Chapter 6, pages 172 following. It looks like the LD1117V33 is wired the wrong way in Figure 5-6. According to the datasheet the legs are GND, Vout and Vin when viewed from the front. The upper rail for GND  in Figure 5-6 is connected to Vout, Vcc 3.3 volts is connected to Vin. It also looks like the capacitor and the hookup wires from the power plug are connected the wrong way. So be careful and double check the whole voltage regulation for this experiment. The text and figures 5-4 and 5-7 seem to be ok. I submitted it to the Errata and got the following answer:
"Unfortunately 3.3V regulators do not have standardized lead arrangements. As the instructions say on page 145, 'The regulator has three legs - typically, ground, output, and input - when viewed from the front (where the writing is). Sometimes these legs are in a different order, so find and check the data sheet if you're not sure!'
Fritzing uses one of the alternate pin arrangements (IGO). We can bring this up with them and redo the diagram in a future printing, but the caution still applies." 
 
Setting up the three XBees is a nobrainer - the AT commands are very well explained in the same chapter so no surprise at all. If you haven't done so it's now time to solder another breakout board for the new XBee. Then everything has to be placed on the breadboards.

There is little room near the voltage regulator if you take (bigger) capacitors (e.g. suited for higher voltages) - Figure 5-4 looks a bit crowded near the regulator. I took capacitors with a small form factor rated for 16 volts which might be more than enough. Anyway you could place them as suggested in Figure 5-6 (page 149) then you have more room for everything. I'm not sure the capacitors should be very near the regulator, maybe someone out there could answer this question.

Be aware that the resistor connected to the + (middle pin) of the LM335 is 300 ohms and not 300 kohms as described in figure 5-6 and 5-7.The voltage regulator (labeled with "7833") and the temperature sensor are both labeled "U2" in Figure 5-7 - only a minor typo - but you should "cut" the ground connection from Pin1 (XBee) and the voltage regulator. Figure 5-6 shows the correct connections.

Next is installing "Processing". Everything went fine on my computer and I only had to replace the COM-port entry which is "COMx"  (x stands for the port number) in Windows. I had two sensors connected and after starting the Simple_Sensor_Network.pde everything took place like it is described in the book. There was only one error in the lower window: "[XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.PacketStream] Found unescaped special byte base10=19,base16=0x13,base2=00010011 at position 4". The program worked anyway.



One thing you really have to think about if you are planning to use the LM335 is calibrating the sensor. I have five sensors and some are "wrong" up to 3 degrees centigrade. I also had some trouble calibrating the sensors and it looked like they were still shifting after calibrating them. In the past I used to take the (digital 1-wire) DS18x20 temperature sensors - I'm still not sure if there is a way to connect them directly to the XBee and send the data to the coordinator for displaying it on the computer (another new item on my TO-DO-list).