Home Automation

 Uncategorized  No Responses »
Sep 292008
Home Automation

If you did not know, the purpose of using this microcontroller is to create something like this: It’s an alarm clock which turns on the light gradually, simulating the light levels similar to a sunrise. Everyone knows it’s easy to wake up in the morning in summer. I hope make me wake up easily in winter too.

Philips does not sell that one in Japan (and not in US either), and amazon.de does not send electronic stuff outside the German speaking countries, so I’m on my own here. National sells something similar for even more money, but where’s the fun if you buy ready-built stuff…

While planning this project, I set my eye on the larger picture: complete home automation. Controll all light and power sockets from a central place. Have sensors like humidity/temperature/touch to tell a computer what to do. Like: at 6am gradually turn on the light in the bed room. If it’s cold, then turn on the heater in bed and living room. When I leave the bed room, turn off light and heater shortly later. When I leave the house, turn off all lights and all heaters. Would work fine in a single household. In my case, it would not work at all though. But the point is, I could make that.

The question now is: how to connect all those sensors and output devices. 4 choices I see:

  • use extra cables
  • use existing cables
  • use wireless (radio)
  • use wireless (IR)

Using new cables is not very attractive as this is rather ugly. There’s no raised floor in our appartment, so using
EIA-485 or cabled Ethernet is out for now.

Using existing (power) cables would be good if there would exist something easy to use. Something like X10. It communicates via power lines, but has problems with reliability in modern households and when more than one power phase is in use. I could not find anything for Japan. Maybe not possible to use or not allowed to use.

One could use Ethernet-over-power-lines. Maybe using one Ethernet connected controller per room would be ok, but some rooms in this apartment we live in are rather large, so the problem of connecting a light on/off switch still exists as I would need to run a cable from the switch to the microcontroller. But the amount of cables would be far smaller than if everything would have a cable go to a central patch room.

IR has the problem of not being able to cross rooms, so a lot of repeaters would be needed (1 per room).

Wireless does sound expensive. Wi-Fi would be neat as it interfaces well to any computer, but it’s expensive if you have a simple on/off switch and want to automize it: You’d need Ethernet (most small microcontrollers don’t have it), and a wireless bridge. Those are usually quite large and need their own power. I count about 20 lamps and about 24 switches. That’s a lot of Wi-Fi going on. Bluetooth would be better, but the Bluetooth stack is quite complicated and ready-to-use modules which take out the complexity are quite expensive.

An alternative I heard about years ago is
ZigBee: a mesh capable wireless network in the (crowded) 2.4GHz range, with slow transmission rate, but cheap to implement. “Cheap” is what they mentioned for Bluetooth too, but this at US$65 is not what I call cheap. 44 of those (20 lamps and 24 switches) plus the microcontroller to talk to it.

ZigBee is now called IEEE 802.15.4. That means it’s hopefully not going to die too soon. The best part is: at about US$25 (see here as an example) it’s much cheaper than e.g. Bluetooth.

And now the best part: those XBee modules, which implement ZigBee and offer:

  • a serial interface with either a pass-through-mode or a more capable API mode
  • 10 digital I/O pins
  • 6 ADC channels
  • PWM output even
  • runs on 3.3V as the LPC2148 does
  • it’s small
  • it’s comparably cheap

Most switches or sockets don’t need anything but a single I/O pin, so in my example of 20 lamps and 24 switches, it’ll be 44 of those modules. If sockets/switches are physically near, then they can be combined, reducing the number likely by one third. That would be at US$25 per piece, US$750 for 30 of them. Quite doable.

I’ll get some of those modules and see what they can do.

Sep 122008
Compiling jcwren's LPC2148 Demo

Turns out using CodeSourcery’s gcc is not problem-free: to use jcwren’s highly recommended lpc2148 demo code, it’s needed to compile newlib, the C library for embedded machines, with one particular option, as otherwise you’ll get errors when linking the demo code. When not using newlib, all is fine though. Since I do want to use the code, I had to configure newlib accordingly.

The hint came from Dan on the LPC2000 mailing list:

One more thing…. your demo requires the version of newlib without
the syscall stubs and without reentrant syscalls. WinARM and most
distributions don’t have this.

Here in short the way to compile the tool chain (see also http://www.gnuarm.com/support.html)

  1. Get binutils-2.1.7, gcc-4.3.2, newlib-1.16.0 (the version from cvs has small changes which are not 100% compatible with 1.16.0)
  2. Compile binutils for arm-elf and install, and then add the bin directory of the installed binaries to PATH:
    ../binutils-2.17/configure --target=arm-elf --prefix=/opt/cross --enable-interwork --enable=multilib --with-float=soft
  3. Configure and compile first stage of gcc:
    ../gcc-4.3.2/configure --target=arm-elf --prefix=/opt/cross --enable-interwork --enable-multilib --with-float=soft --enable-languages="c,c++" --with-newlib --with-headers=../newlib-1.16.0/newlib/libc/include
    Configure and compile newlib:
    ../newlib/src/configure --target=arm-elf --prefix=/opt/cross --enable-interwork --enable-multilib --with-float=soft --disable-newlib-supplied-syscalls
  4. Compile the rest of gcc

The arm-elf-objdump is awfully slow though and strace shows lots of
open("../../../../../newlib/src/newlib/libc/stdlib/mbrtowc.c", O_RDONLY) = -1 ENOENT (No such file or directory)

with changing values for mbrtowc.c, but about 100 repetitions of each such line for each source file. That was the only problem I faced. Since objdump is not needed, I’ll simply skip it unless really needed.