4/17/2011

Twilight Bee

Chapter 4 shows how to use the XBee direct without help of the Arduino (at least on the sensor side). This was one thing I was really waiting for, because getting rid of the microcontroller makes the whole thing much smaller and less energy consuming (and also cheaper!). There is no logic in the XBee used in the book, but you can already do a lot of things with the existing digital/ analog pins.

Romantic lighting sensor
For the "romantic lighting sensor" a LDR (for more background read this fantastic LDR tutorial) is used as the sensor connected to the XBee. Theory: The "data" is acquired by a voltage divider which ideally and depending on the fixed resistor puts out a voltage of up to 1.2 volts.

I had some LDRs on stock which had values of about 1 kOhm at 100 lux and about 8 kOhm at 10 lux (the darker the more resistance). This was almost equal to the LDRs recommended in the books parts list (page 94) so I could also use the 20kOhm resistor. Could I?

added lines of code to print the values
Although everything is described very well in the book I had to really think about this whole voltage divider idea. I finally think I found (my) error. Until now I always connected the variable resistor to Vcc and the fixed resistor to ground in other experiments. So if the resistance went down (brighter light) the higher the value on the anlaog input pin on the microcontroller and vice versa. The code on pages 101-103 says exactly this. But this time the values were inverse. The brighter the light the lower the resulting value/ volts.

In my example this meant (I added some lines of code to get the results in the serial monitor):

~ 100 lux

~ 100 lux: analogValue of 97 (0.11 volts)
~ 10 lux: analogValue of  611 (0.71 volts)

In the experiment the LDR is connected to ground and the fixed resistor to Vcc. If I calculate the formula:

Vout = (R2 (LDR)/ R1 (fixed resistor) * R2 (LDR)) * Vin



~ 10 lux

I get (at ~ 100 lux, LDR resistance ~ 1 kOhm, fixed resistor = 20 kOhm):
Vout = (1 kOhm/ 20 kOhm + 1 kOhm) * 3.3 volts
Vout = 0.157 volts

for ~ 10 lux (LDR resistance ~ 8 kOhm):
Vout = (8 kOhm / 20 kOhm + 8 kOhm) * 3.3 volts
Vout = 0.94 volts

The calculated values show the same trend I found in the practical excercise.

LDR covered to lower the brightness
The funny thing is that the experiment exactly works as it should be. If it's too bright (in my case at about 20 lux) the light goes out and if it's too dark (< 10 lux) the same. In between the LED is on.

I'm kind of stuck now with this experiment. Do I have an error in reasoning or should the code tell exactly the inverse: analogValue low = too bright, analogValue high = too dark)?


Anyone to the rescue?

230 volts power switch interface

For the "direct actuation example" (chapter 6) I still needed an alternative for the power switch tails (SFE COM-09842) because in europe there is largely 230 volts in the power grid.

Parts of SI 230-2
I found the SI 230-2 230 volts switch interface at ELV (thanks to Olli!) which you can either assemble by yourself (14,95 Euro/ ~ $21.53) or buy the already assembled part (24.95 Euro/ ~$35.90). I chose to build it by myself and it's quite easy to solder and put together. No SMD parts and everything fits very well. Only the instructions could be a bit more detailed.
You can switch the interface with 4-18 volts DC (6-48 mA) with a maximum switching frequency of 0.5 Hz which means you can switch every second or longer.
Assembled SI 230-2
It operates up to 230 volts with 16 amps - so you could drive almost everything needed in the house. The switch input socket is for a 3.5mm audio mono jack plug.

In the meantime I also built the "romantic lighting sensor" and will post the results in a few days.



4/11/2011

Buzz LightBee

Arduino meets XBee.

After some Arduino basics, installing the IDE was quite easy. You only have to watch for installing the windows drivers for the Arduino Uno board. That's what I forgot, but after reading the IDE-installing-tutorial everything went fine.

If you already did some programming in C or any similar language and played with some microcontrollers the IDE and language look quite familiar. If questions arise, there are a lot of tutorials and information available not only on the Arduino Homepage but in serveral other Arduino communities and information sites (s. page 64/ 65) around the web.

Next is heating up the soldering iron because the breakout boards have to be finished. If you plan to order the breakout boards from Sparkfun pay attention to the wrong part number in the parts list on page 67. The right part number is "BOB-08276". If you have to order additional electronics parts like LEDs or resistors, consider buying the 2.54mm/ 0.1" headers and the 2mm female headers there. They might be much cheaper there.

Fixing the male headers
Third hand tool
A very good advice mentioned in the book is putting the male headers into a breadboard and then putting the breakout board on top and soldering both together. After that you can put the female headers into the breakout board, turn it upside down and use a third hand tool to solder the female headers.

3.3V voltage check
Wiring the boards together is quite easy because there aren't that much connections. Just remember to unplug the wire into RX (pin 0) on the Arduino before uploading the compiled code. Also a good advice is checking the voltage BEFORE putting the XBee on the breakout board. One drawback in the printed (black & white) edition is that Vcc/ GND (+/-) are not labeled, so you have to take care when wiring everything together. Any labeling in future (printed) editions would be a great help.

Button system
If you don't want to buy the long jumper wires, you can solder them easily by yourself by connecting any adequate wire and a single headerpin of the male 0.1" headers, solder both together and put a heat shrink tube over the connection.

There is not much more to say about the button and the bell system. Everything is described very well, so I did not hit any roadblock. Except I first had a buzzer which draw too much current and didn't buzz but sounded more like whining, I had no issues at all. After replacing it with a 5mA type, the buzzer was clearly audible.

4/06/2011

Offroad: With RSSI one XBee finds the other

I like manuals.

After my first very basic range experiments (see previous blog Bee-Chat) I questioned myself if there is a more accurate way to determine signal strength. Of course there is and you only have to look into the XBee manual.
Search for "RSSI" (RX Signal Strength Indicator) and you will find at least two sections where the RSSI function is described in detail.

For example in AT-mode, which means the XBee is either capable of command or transparent mode, you could type in "hello" then put the XBee in command mode with "+++" and then enter "ATDB". You get a hexadecimal value which "returns the RSSI value (measured in –dBm) of the last received packet". This only works if there is a direct connection, but for the moment this is the case and it does the job.

Very simple distance check
The lower the value the better. 

I got hexadecimal "1A" when laying two XBees side by side. As far as I understand this means -26dBm. I tried some other positions (inside my house) and the value went up to hexadecimal "5C"/ decimal 92 in the corner furthermost away.


This opens a lot of options for future applications.

If you are one of those people who regularly forget where they left their keys, two XBees could help. Or you need any sort of very simple distance meter (yes, radio waves are not that great for accurate distance measurement), proximity sensor or whatever application where a raw value of distance of two things is needed - two XBees would do. A lot of things might be possible with this already embedded function...

4/05/2011

Bee-Chat

After I could configure one XBee module to communicate via the serial terminal application Tera Term (Hyperterminal/ Windows XP also worked for me) the next step in the book was the "Basic XBee Chat".
I wrote down the low bit of the 64-bit address of each XBee and set up everything as described (PAN ID, ATDH and ATDL). I programmed everything with ATWR to the modules and double checked the configuration by typing in the AT commands without values.
I connected both XBee modules with the computers and both responded to my inputs in Tera Term.

Time to chat.

Nothing happened. Uh.


Finally I ran into trouble (but thats what I like most, at least most of the time). It was quite easy to find my mistake by reading the Troubleshooting and turning my brain on. Of course you have to tell the Coordinator XBee the destination address of the Router XBee and vice versa. The bees chatted a bit and then it was time to do some extra work for them. A range test.

I was impressed how far you can go with only 2 milliwatts. I covered every place in my house which has quite thick stone walls and is 3 floors high plus attic.Every signal was received by the coordinator which sat in the other corner of the house. So there is no need for a bee-network at all - at least in the house - and for everything else there are much more powerful bees out there.

For more thoroughly checks one could build a signal strength meter, if range is crucial. Time to read the XBee manual.

4/04/2011

Talking to my bee

Today I started with the practical part (page 32). I downloaded and installed X-CTU from digi.com and even if digi.com says the software is suited only for 32bit systems everything went well on my Windows 7 64-bit. I don't use Linux or Macintosh on my desktop so I can't say much about that.

After installing and updating the new firmware versions I attached one XBee on the XBee explorer USB adapter and connected it with my USB A-to-B-mini cable to my laptop. Windows automatically installed the required USB/ serial drivers.

With X-CTU I could conduct the "test/ query" option on the "PC Settings Tab". Also reading the modem configuration was easy and worked well from the beginning. I then configured two XBees as described - one as a Coordinator AT and one as a Router AT. I marked them with a label "C" and "R". Again, no hassle at all.

The book makes a wonderful job describing everything so accurate. So there were no problems installing Tera Term, configuring it and typing the three "+++".

OK!

I just talked to my bee!

Using AT commands went smooth again - I just have to get used to not to press return after the three "+++". Talking with one bee now seems easy - next will be the bee-chat.

4/03/2011

Delivered, Part II

Before ultimately beginning with the experiments , I again scanned through the book one more time and looked through the parts lists, almost sure I forgot something to order.

So I discovered that I would need some temperature sensors (LM335) and 3.3V voltage regulators (I took 2 LM 2937 ET3,3 and 2 LF 33 CV instead of LD1117V33). I will explain later, why I took two different regulators. I'm also not sure if the 500 mA they deliver will be sufficient. Anyway I have to substitute the 110V Power Switch Tails (parts list printed edition page 173), because in germany we have 220 volts. I have an idea for a workaround, but more on that later.

LM 335, LM 2937, LF 33 CV, headers and resistors
I also ordered some male and female headers and some resistors which I didn't find in my inventory.
I really like the german online-distributor Reichelt, where you can get almost everything you need if it's about electronic parts. They are almost always a bargain. But this time - and it was the first time ever I had an issue with them - they delivered a parcel weighing 1305 grams but the electronic parts are only 34 grams. Not very eco-friendly - maybe that's their standard package for the smallest deliveries they have.
Xbee explorer, breakout boards, Arduino Uno, breadboard



I planned to etch some pcb's later on as mentioned before. But for the time being I switched back to buy assembled parts. That saves time (I'm already quite impatient to wait any longer to start). So I ordered some required parts at Tinkersoup (thanks to Anton for replying my mail so fast) - there I also got the badly needed xbee breakout boards! That was the fourth order for this project and it went as smooth as all the others. Great service.
And: Thank you Internet!