#21596 - 01/25/10 07:00 PM
Arduino, Marmitek XM10 & Leopard II
|
Sash181
newbie
Registered: 03/10/07
Posts: 23
|
Hi All,
I've been playing around with the Arduino platform for a little while now and have managed to get my Arduino onto my network using a Lantronix XPORT. Great project!
This has opened up a world of opportunities for me to be able to control lights, appliances etc. over the internet.
I first thought to try and send commands from the web by the following method;
Webpage (hosted by XPORT) -> PHP script -> Arduino -> Leopard but have since learned that the Arduino can control a Marmitek XM10 or similar directly.
There is a ton of info for US 120volt systems on the internet but I cannot seem to find much about the 240volt way to do it.
It seems there is some issue with the "zero cross point" that I do not truely understand but would assume is easy enough to change in the Arduino Program to suit the 240volt systems.
I've managed to source some wiring schematics but I am a little lost on the "zero crossing point" issue and what it should be.
Can anyone offer any help?
On another note, if I was to try and get my Leopard to do the work (i.e. Arduino passes the commands onto the Leopard), what would these commands look like? I'd imagine the Arduino would need to mimic the C-Max Control commands. Help on this would be great to.
Cheers Sash
|
|
Top
|
|
|
|
#21731 - 03/25/10 11:20 PM
Re: Arduino, Marmitek XM10 & Leopard II
[Re: Guy Lavoie]
|
Sash181
newbie
Registered: 03/10/07
Posts: 23
|
Hi Guy,
Thanks for the reply. Your knowledge of this stuff is amazing.
I looked at the example code for the Arduino and found the 8.333Ms you were refering to in your reply.
I'm not expecting you to know this sort of code but I thought I'd post it up anyway.
Its Arduino Code;
1./* Arduino Interface to the PSC05 X10 Receiver. BroHogan 3/24/09 2. * SETUP: X10 PSC05/TW523 RJ11 to Arduino (timing for 60Hz) 3. * - RJ11 pin 1 (BLK) -> Pin 2 (Interrupt 0) = Zero Crossing 4. * - RJ11 pin 2 (RED) -> GND 5. * - RJ11 pin 3 (GRN) -> Pin 4 = Arduino receive 6. * - RJ11 pin 4 (YEL) -> Pin 5 = Arduino transmit (via X10 Lib) 7. * NOTES: 8. * - Must detach interrup when transmitting with X10 Lib 9. */ 10. 11.#include "WProgram.h" // this is needed to compile with Rel. 0013 12.#include <x10.h> // X10 lib is used for transmitting X10 13.#include <x10constants.h> // X10 Lib constants 14.#define RPT_SEND 2 // how many times transmit repeats if noisy set higher 15. 16.#include "PSC05.h" // constants for PSC05 X10 Receiver 17.#define TRANS_PIN 5 // YEL pin 4 of PSC05 18.#define RCVE_PIN 4 // GRN pin 3 of PSC05 19.#define ZCROSS_PIN 2 // BLK pin 1 of PSC05 20.#define LED_PIN 13 // for testing 21. 22.volatile unsigned long mask; // MSB first - bit 12 - bit 0 23.volatile unsigned int X10BitCnt = 0; // counts bit sequence in frame 24.volatile unsigned int ZCrossCnt = 0; // counts Z crossings in frame 25.volatile unsigned long rcveBuff; // holds the 13 bits received in a frame 26.volatile boolean X10rcvd = false; // true if a new frame has been received 27.boolean newX10 = false; // both the unit frame and the command frame received 28.byte houseCode, unitCode, cmndCode; // current house, unit, and command code 29.byte startCode; // only needed for testing - sb B1110 (14) 30. 31.x10 SendX10= x10(ZCROSS_PIN,TRANS_PIN);// set up a x10 library instance: 32. 33.void setup() { 34. attachInterrupt(0,Check_Rcvr,CHANGE);// (pin 2) trigger zero cross 35. Serial.begin(9600); 36. pinMode(LED_PIN,OUTPUT); // onboard LED 37. pinMode(RCVE_PIN,INPUT); // receive X10 commands - low = 1 38. pinMode(ZCROSS_PIN,INPUT); // zero crossing - 60 Hz square wave 39. digitalWrite(RCVE_PIN, HIGH); // set 20K pullup (low active signal) 40. digitalWrite(ZCROSS_PIN, HIGH); // set 20K pullup (low active signal) 41.} 42. 43.void loop(){ 44. 45. if (newX10){ // received a new command 46. X10_Debug(); // print out the received command 47. newX10 = false; 48. 49. if (unitCode == 1){ 50. detachInterrupt(0); // must detach interrupt before sending 51. SendX10.write(D,UNIT_5,RPT_SEND); 52. if(cmndCode == ON) SendX10.write(D,ON,RPT_SEND); 53. if(cmndCode == OFF) SendX10.write(D,OFF,RPT_SEND); 54. attachInterrupt(0,Check_Rcvr,CHANGE);// re-attach interrupt 55. } 56. } 57.} 58. 59.void Check_Rcvr(){ // ISR - called when zero crossing (on CHANGE) 60. if (X10BitCnt == 0) { // looking for new frame 61. delayMicroseconds(OFFSET_DELAY); // wait for bit 62. if(digitalRead(RCVE_PIN)) return; // still high - no start bit - get out 63. digitalWrite(LED_PIN, HIGH); // indicate you got something 64. rcveBuff = 0; 65. mask = 0x1000; // bitmask with bit 12 set 66. rcveBuff = rcveBuff | mask; // sets bit 12 (highest) 67. mask = mask >> 1; // move bit down in bit mask 68. X10BitCnt = 1; // inc the bit count 69. ZCrossCnt = 1; // need to count zero crossings too 70. return; 71. } 72. // Begins here if NOT the first bit . . . 73. ZCrossCnt++; // inc the zero crossing count 74. // after SC (first 4 bits) ignore the pariety bits - so only read odd crossings 75. if (X10BitCnt < 5 || (ZCrossCnt & 0x01)){ // if it's an odd # zero crossing 76. delayMicroseconds(OFFSET_DELAY); // wait for bit 77. if(!digitalRead(RCVE_PIN)) rcveBuff = rcveBuff | mask; // got a 1 set the bit, else skip and leave it 0 78. mask = mask >> 1; // move bit down in bit mask 79. X10BitCnt++; 80. 81. if(X10BitCnt == 13){ // done with frame after 13 bits 82. for (byte i=0;i<5;i++)delayMicroseconds(HALF_CYCLE_DELAY); // need this 83. X10rcvd = true; // a new frame has been received 84. digitalWrite(LED_PIN, LOW); 85. X10BitCnt = 0; 86. Parse_Frame(); // parse out the house & unit code and command 87. } 88. } 89.} 90. 91.void Parse_Frame() { // parses the receive buffer to get House, Unit, and Cmnd 92. if(rcveBuff & 0x1){ // last bit set so it's a command 93. cmndCode = rcveBuff & 0x1F; // mask 5 bits 0 - 4 to get the command 94. newX10 = true; // now have complete pair of frames 95. } 96. else { // last bit not set so it's a unit 97. unitCode = rcveBuff & 0x1F; // mask 5 bits 0 - 4 to get the unit 98. newX10 = false; // now wait for the command 99. for (byte i=0; i<16; i++){ // use lookup table to get the actual unit # 100. if (Unit[i] == unitCode){ 101. unitCode = i+1; // this gives Unit 1-16 102. break; // stop search when found! 103. } 104. } 105. } 106. rcveBuff = rcveBuff >> 5; // shift the house code down to LSB 107. houseCode = rcveBuff & 0x0F; // mask the last 4 bits to get the house code 108. for (byte i=0; i<16; i++){ // use lookup table to get the actual command # 109. if (House[i] == houseCode){ 110. houseCode = i+65; // this gives House 'A' - 'P' 111. break; // stop search when found! 112. } 113. } 114. rcveBuff = rcveBuff >> 4; // shift the start code down to LSB 115. startCode = rcveBuff & 0x0F; // mask the last 4 bits to get the start code 116. X10rcvd = false; // reset status 117.} 118. 119.void X10_Debug(){ 120. Serial.print("SC-"); 121. Serial.print(startCode,BIN); 122. Serial.print(" HOUSE-"); 123. Serial.print(houseCode); 124. Serial.print(" UNIT-"); 125. Serial.print(unitCode,DEC); 126. Serial.print(" CMND"); 127. Serial.print(cmndCode,DEC); 128. if(cmndCode == ON)Serial.print(" (ON)"); 129. if(cmndCode == OFF)Serial.print(" (OFF)"); 130. Serial.println(""); 131.} 132. \\\\\\\\\\\\\\\\ TAB NAMED PSC05.H /////////////////// 133.// Defines and constants for PSC05 receiving 134. 135.#define OFFSET_DELAY 500 // uS from zero cross to center of bit (sugg 500-700 us) 136.#define HALF_CYCLE_DELAY 8334 // Calculated 8334 uS between bit repeats in a half-cycle 137. 138.#ifndef ON // use same defines from x10constants.h for rcvd cmnds 139.#define ON B00101 // these are examples 140.#endif 141.#ifndef OFF 142.#define OFF B00111 143.#endif 144. 145.byte House[16] = { // Lookup table for House Code 146. B0110, // A 147. B1110, // B 148. B0010, // C 149. B1010, // D 150. B0001, // E 151. B1001, // F 152. B0101, // G 153. B1101, // H 154. B0111, // I 155. B1111, // J 156. B0011, // K 157. B1011, // L 158. B0000, // M 159. B1000, // N 160. B0100, // O 161. B1100, // P 162.}; 163. 164.byte Unit[16] = { // Lookup table for Unit Code 165. B01100, // 1 166. B11100, // 2 167. B00100, // 3 168. B10100, // 4 169. B00010, // 5 170. B10010, // 6 171. B01010, // 7 172. B11010, // 8 173. B01110, // 9 174. B11110, // 10 175. B00110, // 11 176. B10110, // 12 177. B00000, // 13 178. B10000, // 14 179. B01000, // 15 180. B11000, // 16 181.};
Line 135 and 136 seem to be the values that require changing but I wonder if there is something that needs to be changed in the X10 Lib (or Library).
Any help is appreciated.
Cheers Sash
|
|
Top
|
|
|
|
#21805 - 04/20/10 01:30 AM
Re: Arduino, Marmitek XM10 & Leopard II
[Re: Guy Lavoie]
|
Sash181
newbie
Registered: 03/10/07
Posts: 23
|
Hi Guy,
I've found out what needs to change in the code and one of the X10 libraries;
In the source for your X10.lib, in X10constants.h change: #define BIT_DELAY from 1778 to 2133 #define BIT_LENGTH from 800 to 900
In my example for the X10 Receive function, in PSC05.h change: #define OFFSET_DELAY from 500 to 800
#define HALF_CYCLE_DELAY from 8334 to 10000
Above is copied from the following website;
http://brohogan.blogspot.com/search/label/Home%20Automation
My problem now is that the code above will not compile. Comes up with a "error: stray '#' in program" and highlights the following line in the code;
11.#include "WProgram.h" // this is needed to compile with Rel. 0013
Any help would be appreciated.
Cheers Sash
|
|
Top
|
|
|
|
#22789 - 12/06/11 10:39 AM
Re: Arduino, Marmitek XM10 & Leopard II
[Re: Sash181]
|
Kytic
newbie
Registered: 12/06/11
Posts: 1
|
Hi guys I' ve just bought an XM10, I thought it may be connected directly to RS232 port of PC, but surprize......i have it but I dont know what to do whit it. I don't find documentation.....please help me with some information. How can connect it to an RS232 port an how can i comunicate with it?
|
|
Top
|
|
|
|
Moderator: Dan Smith, Monte G, ADI Tech Support, Guy Lavoie
|
1 registered
(kuro)
and 21 anonymous users online.
|
|
2747 Members
19 Forums
3837 Topics
22714 Posts
Max Online: 67 @ 08/16/11 03:08 PM
|
|
|
|
|
|
1
|
2
|
3
|
4
|
|
5
|
6
|
7
|
8
|
9
|
10
|
11
|
|
12
|
13
|
14
|
15
|
16
|
17
|
18
|
|
19
|
20
|
21
|
22
|
23
|
24
|
25
|
|
26
|
27
|
28
|
29
|
|
|
|
|
|