-
Notifications
You must be signed in to change notification settings - Fork 131
WeederBoards
This is an introduction to the use of Weeder serial interface boards on the Misterhouse home control program.
There is an initial explanation of serial output in MisterHouse docs, and various text files and programs in the examples and other directories. Unfortunately in the demo programs the more complicated the Perl the less the comments attached so I got a bit lost. This is my attempt to help beginners, i.e. me.
The range of interface boards produced by Weeder Technologies at http://www.weedtech.com provide serial to parallel, A/D, D/A, relay and other interfaces using a special protocol that allows multiple boards to be connected to one serial output. They only cost around $60 but Europeans beware that shipping and tax will nearly double the price so find a friend on a business trip to USA, then it only costs you a pint, a stein, or a bottle, depending on you country (update: there are now European distributors).
The (newer) Weeder I/O board provides serial RS232 to 14 I/O lines all individually controlled as in or out but also with some grouping capability (4,8 parallel). Each board has a DIP switch to set an address which is a letter from A to P or a to p, each pin (line) is designated by a letter from A to N, and commands are typically another letter H,L,B,S,M,R,W,I,T,X.
So a typical control command for board A, set to logic High, on pin N, requires AHN to be sent on the serial output with no line feed but followed by carriage return. Then same board, logic Low, on same pin, is ALN. No initialization is required for simple outputs. To make a pin an input it has to be initialized, so to make board A, have a simple Switch input, on pin C, requires initialization by sending ASC and carriage return. Then if that pin is grounded the board sends a message ACL plus carriage return. Note the pin identity is second letter unlike the initialization command. It’s easy to get confused here. When the pin is switched High again it produces ACH. The board also echoes back what has been sent to it (can be disabled) and also sends something when reset or on error. You have to give it a breathing space between commands so it can send the echo and think a bit. All this is in the data sheet.
Speed is 9600, 8bit, 1 stop, hardware flow control(?) ( note flow control may need to be set in Windows via settings, control panel, system, device manager, ports). The settings probably mean only Weeder boards can be used on that serial port but multiple boards with different addresses can be cascaded on one serial port.
In mh.private.ini set up the port as the weeder special one for naming convenience and clarity, but you could just use a generic serial designation if you prefer.:
weeder = com1 # or com2 etc
weeder_baudrate = 9600 # got to set it, Windows default is only 1200
You can now refer to this port as ‘weeder’ I am using the # for comments to make it a bit Perl like, and will use some special MisterHouse commands, look them up in the documentation.
Example : We will give the board address A and set up pins A and B as inputs (??? - Mising example)
Example : use pins M and N as outputs. ( for testing connect LED in series with 300ohm resistor between the output connection N and +5volts)
$LEDoutput = new serial_item (‘AHN’ ‘LED_N_off’ ‘weeder’); # when we use the name LED_N_off the data ‘AHN’ will be sent to the port weeder which will put logic high on the pin N which has the effect of turning it off.
$LEDoutput -> add (‘ALN’ ‘LED_N_on’); # note -> don’t use = here, and we don’t need to mention the weeder a second time.
$LEDoutput -> add (‘AHM’ ‘LED_M_off’); # now we are getting prepared for the M pin
$LEDoutput -> add (‘ALM’ ‘LED_M_on’); # no data has been sent yet
No data has been sent yet, this is not initialisation of the Weeder board, it is MisterHouse preparation. A way of thinking of this is that we have set up a table called $LEDoutput and associated it with the serial port weeder. In this table are a list of names like LED_N_on and next to them a list of data like ALN so that we can refer to the table and the name and get a specific data entry. The table name and the names in it can be made more meaningful, but the data is of course special to the application.
We should now be able to use instructions like:
set $LEDoutput ‘LED_N_on’;
I guess this checks all the entries under $LEDoutput to find LED_N_on then gets the data defined to belong to this name and sends it to the port given in the first definition line. This could be used as part of a program as it is but to have it as part of the TK command inputs or voice commands we need some more preparation.
To do this we set up some voice commands :
# Category = weeder
# category is not essential but sets up a heading in certain parts of MH
$v_turn_N_on = new Voice_Cmd(‘turn_N_on’); # ok this isn’t very efficient I know
$v_turn_N_off = new Voice_Cmd(‘turn_N_off’); # but it is nice and clear
$v_turn_M_on = new Voice_Cmd(‘turn_M_on’);
$v_turn_M_off = new Voice_Cmd(‘turn_M_off’);
# now to make them do something :
if ($v_turn_N_on) { # test if the voice command is true, ie has been spoken or selected from TK
set $LEDoutput ‘LED_N_on’; # turn it on
}
Repeat for other commands. I know a proper Perl programmer will compress this into a couple of lines but then it is not so clear what is happening.
If we want to receive data as well we have to prepare MisterHouse for it. In fact we will already be getting error messages in MisterHouse because the Weeder board sends a power up message that MisterHouse doesn’t understand. The Weeder also echoes back the commands sent to it, but MisterHouse does not raise an error on that data because it recognizes it has been defined. That is the clue to how to define input data, - define it the same way the output data was defined and it will be in the system, just don’t try sending it or the Weeder board might get confused.
Various users have contributed weeder-related code over time that you can use as a reference:
- https://github.com/hollie/misterhouse/blob/master/lib/Weeder_Light.pm
- https://github.com/hollie/misterhouse/blob/master/code/public/weeder_david.pl
- https://github.com/hollie/misterhouse/blob/master/code/public/weeder_doorbell.pl
- https://github.com/hollie/misterhouse/blob/master/code/public/garage_door_code.pl