Friday, December 15, 2017
Home » Flowstone Workshop » Flowstone Workshop 6

Flowstone Workshop 6

Flowstone-Header

The Automated Home: Rudiments of FlowStone progamming open up huge vistas 

FLOWSTONE WORKSHOP 6-2Welcome to the FlowStone workshop number 6, where we give a beginners guide to computer programming using the FlowStone free graphical programming language. In this issue we are going to look at programming the Automated Home or as I prefer ‘Robots you can live in!’

It’s funny that only ten or twenty years ago many of the things we take for granted in our homes were pure science fiction but the limiting factor of growth in this home automation market has always been ‘wires’. Think about everything from your 5.1 surround home cinema, computer network, to your security systems, wires, wires, wires. So in order for our robotic home to take shape first we needed the technology to eliminate the

Luckily we are at this point now where wireless technology is quickly coming at us, and cell phones and WIFI are good examples, but what about for the home? Well there are a few interesting things coming out soon in FlowStone that are already done for you: X10, Zigbee, and The Owl (Sounds like the title of a children’s book).

X10 WIRELESS 

The X10 protocol has been around for a while; this was originally designed to send data messages over you domestic mains wiring in the home. This is achieved by plugging in various devices into the wall sockets or light sockets and sending data over the mains wiring to turn them on and offer from some sort of base station. X10 also now has a wireless option that can be controlled from the same base station. Examples of X10 products are: power sockets, light sockets, home security, garage openers, etc.

FLOWSTONE WORKSHOP 6-1
The Marmitek X10 Products we use.

What’s cool with X10 is that it is an official standard so products from different manufacturers will all work together. The key as far as programming is the base station element and we use the Marmitek CM15 Pro USB interface for this. This provides both wired (through the mains) and wireless interfaces. Another benefit of X10 is that the devices are produced in such high quantities that the prices are very low. The down side is that the stock software is usually pretty primitive, but since we will be programming our own software using FlowStone this is not an issue. Also, since the data is sent over the mains wiring, occasionally the data can get corrupted or lost, so you need to keep this in mind when writing your program.

So for our first X10 programming challenge let’s use a switchable power socket and a PIR (Passive Infrared ) intruder detector. The aim being to turn on a table lamp when someone enters the room (We could also use an X10 Lamp Bulb Socket in the lamp itself as an alternative).

SET THE X10 ID 

X10 works on a simple ID system where there are 16 house letters (ABCD…P) and 16 device numbers for each house letter (1-16). You can use any combination within a single house, the only consideration is that your neighbors could in theory have some devices on the same number, but it is unlikely. So for simplicity let’s make our PIR detector ID ‘A1’ (the default), and our Power Socket ID ‘A2’. This is physically selected on the plug device by two rotary switches.

FLOWSTONE WORKSHOP 6-3
Switch, selector and X10 FlowStone Module.
FLOWSTONE WORKSHOP 6-4
PIR X10 detection program.

Next plug the socket into the wall and the table lamp into the socket, and make sure the batteries are fitted to the PIR detector.

Now to the programming, as always with FlowStone the really difficult stuff is already done, i.e., the CM15 Module that talks to the USB device, so it’s just a case of programming what we want to happen. However, we do need to install the CM15 SDK files as well as FlowStone in order for FlowStone to be able to communicate with the CM15 Pro. Links to this download are on the DSPRobotics site (www.dsprobotics.com/support).

The X10 module has two inputs: Commands and Send. The commands for X10 are quite simple and well documented, e.g., ‘A2 ON’ – turns on device ‘2’, home ID ‘A’. So it’s just a case of presenting the correct command strings to the command input and the triggering send. In our case: ‘A2 ON’ and ‘A2 OFF’ to control the power socket.

To do this we can use a selector module and a switch module to give us the ability to switch our lamp on and off.

Using the above project makes a good first test. (A) Have you set the correct ID on the socket? And, (B) can you communicate with it?

FLOWSTONE WORKSHOP 6-6
The Netvox wireless products we used.

One thing we did find was that the CM15 was sensitive to plugging in the USB cable, so I would advise that you plug the usb cable in first, then plug the CM15 to the mains power.

So that’s it – our first X10 computer program that gives you software control over your lights! Next to add the PIR detector and automate the process. The PIR detector communicates wirelessly with the CM15 hardware so when it is working you will see various codes appearing from device A1. The code we are interested in is ‘RF a1 On’, which indicates an intruder has been detected. So quite simply we can ignore the rest and just look for this code. To do this we connect a String Queue module to the X10 module that intercepts the incoming X10 data and then splits off the end of the data string to just show the part we are interested in, then it compares this data with ‘RF a1 On’ to see if we have an intruder.

If an intruder is detected we then toggle a timer to switch the light on for so many seconds; this timer simply selects ‘a2 On’, then waits, then selects ‘a2 OFF’.

ZIGBEE 

Our second example uses some Zigbee devices based on the Zigbee wireless protocol. The possibilities are very similar to X10 only slightly more robust and totally wireless. In this case we are going to use some wireless products from Netvox inside FlowStone. Netvox makes a whole range of home automation products from control to security. For our example we are going to replicate the same project as we did for the X10 so that you can see exactly how it compares.

FLOWSTONE WORKSHOP 6-7

FLOWSTONE WORKSHOP 6-8
The Netvox PIR module in FlowStone.
FLOWSTONE WORKSHOP 6-9
The Netvox Power socket module in FlowStone
FLOWSTONE WORKSHOP 6-10
The finished project in FlowStone.

We are going to use the Netvox USB dongle, and a wireless PIR (passive Infrared) detector, plus a wireless mains plug socket to turn our table lamp on.

In this case we first need to initialize the Zigbee network. This is done using the Netvox USB dongle that sends and receives the wireless data. To do this we need to send a start command to the Netvox USB module in FlowStone together with the port number (it’s a virtual COM port) and the baud rate. If the USB dongle is connected the ON output will go high and indicate this. We can now go and start the PIR and Power Socket modules in FlowStone which we have done using a wireless link called NVCON.

Each physical module has a unique ID Number that you need to use to identify which module you are communicating with. Using this system, you can communicate to literally hundreds of different modules on a single network.

Once these modules are started and have communicated with the actual hardware you are all set. From now on when the PIR detects an intruder it will output an alarm state which we can then use to trigger a timed pulse to turn our light on via the mains power socket module. The great thing with the Zigbee products is that it is a closed loop system so you know your message has been received and in addition you also get some other data like the current current and power going through the device that is very useful.

FLOWSTONE WORKSHOP 6-11
The Owl wired up in FlowStone.

THE OWL 

Finally ‘The Owl’ is a wireless USB home energy meter, this sends real-time and historic data based on your home energy usage. Currently there are two types supported, one with an LCD screen and one without. Using FlowStone we can make our own energy monitoring system that can store the data and display graphs of power usage etc.

FLOWSTONE WORKSHOP 6-12
The Owl USB Energy Meter.

To connect to the Owl meter in FlowStone you need to use the Owl module. This auto-finds the port where the owl is connected and scans the wireless network to see which devices are available. Much in the same way the Zigbee network works, each device has a unique serial number that can be used to identify the device.

Once connected the Owl Module outputs the current in amps being used by the building which we have converted into KW. The Owl hardware supports both single and three phase power systems making it a very versatile and low cost solution.

CONCLUSION 

Using these combinations of home automation products we can easily take control of our home. There are, of course, far more possibilities to automate a whole home using FlowStone with touch screens, fancy GUIs, and much more. But this is the first step to understanding the programming. The great thing with all of these products is that they are very good value for the money, so there is nothing stopping you from downloading FlowStone free of charge and giving home automation a go!

As always examples of these projects are available to download from our DSPRobotics site: www.dsprobotics.com/support

Links 

DSPRobotics, www.dsprobotics.com
Marmitek, www.marmitek.com
Netvox, www.netvox.com.tw
The Owl, www.theowl.com
Zigbee, www.zigbee.org

Leave a Reply

Your email address will not be published. Required fields are marked *