I got my PSC04 in the mail a couple days back. I thought I could use the Arduino code and hardware as is, but apparently the PSC05 connection doesn't make the PSC04 happy. I simply removed the pullup resistor and added a jumper to ground and it works fine. I simplified my code to almost nothing so as to make sure the basic transmit function works. What I found is that the XTB-IIR does not like the PSC04 for some reason. Perhaps someone could give some guidance?
This is my code:
#define DEBUG
#define VERSION "Attic Fan Controller TEST 20130407"
#include <dht11.h>
#include <SimpleTimer.h>
#include <X10ex.h>
#define POWER_LINE_MSG "PL:"
#define POWER_LINE_BUFFER_ERROR "PL:_ExBuffer"
#define SERIAL_DATA_MSG "SD:"
#define SERIAL_DATA_THRESHOLD 1000
#define SERIAL_DATA_TIMEOUT "SD:_ExTimOut"
#define MODULE_STATE_MSG "MS:"
#define MSG_DATA_ERROR "_ExSyntax"
// Fields used for serial and byte message reception
unsigned long sdReceived;
char bmHouse;
byte bmUnit;
byte bmCommand;
byte bmExtCommand;
// Initialize timer
SimpleTimer timer;
// X10 related values
#define Fan1_HC 'E' // Fan_1 on house code C
#define Fan1_UC 1 // Fan_1 on unit code 1
#define Fan2_HC 'E' // Fan_1 on house code C
#define Fan2_UC 2 // Fan_1 on unit code 1
// general constants
#define FanRunTime 2000
#define X10CommandDelay 1000 // delay after sending command to avoid collisions
// X10 Power Line Communication Library
X10ex x10ex = X10ex(
2, // Zero Cross Interrupt Number (2 = "Custom" Pin Change Interrupt)
4, // Zero Cross Interrupt Pin (Pin 4-7 can be used with interrupt 2)
5, // Power Line Transmit Pin
6, // Power Line Receive Pin
true, // Enable this to see echo of what is transmitted on the power line
powerLineEvent, // Event triggered when power line message is received
1, // Number of phases (1 = No Phase Repeat/Coupling)
60 // The power line AC frequency (e.g. 50Hz in Europe, 60Hz in North America)
);
void setup()
{
Serial.begin(9600);
Serial.println(VERSION);
x10ex.begin();
Serial.println("X10 active");
}
void loop()
{
delay(FanRunTime);
TurnOnFan_1();
TurnOnFan_2();
delay(FanRunTime);
TurnOffFan_1();
TurnOffFan_2();
delay(FanRunTime);
}
void TurnOnFan_1()
{
// turn fan1 on and start run timer
Serial.println("Turn ON Fan 1");
x10ex.sendCmd(Fan1_HC, Fan1_UC, CMD_ON, 1);
delay(X10CommandDelay);
}
void TurnOnFan_2()
{
// turn fan1 on and start run timer
Serial.println("Turn ON Fan 2");
x10ex.sendCmd(Fan2_HC, Fan2_UC, CMD_ON, 1);
delay(X10CommandDelay);
}
void TurnOffFan_1()
{
// turn off fan1 and start delay timer
Serial.println("Turn OFF Fan 1");
x10ex.sendCmd(Fan1_HC, Fan1_UC, CMD_OFF, 1);
delay(X10CommandDelay);
}
void TurnOffFan_2()
{
// turn off fan2 and start delay timer
Serial.println("Turn OFF Fan 2");
x10ex.sendCmd(Fan2_HC, Fan2_UC, CMD_OFF, 1);
delay(X10CommandDelay);
}
//**************************************************************
// Process messages received from X10 modules over the power line
void powerLineEvent(char house, byte unit, byte command, byte extData, byte extCommand, byte remainingBits)
{
// Display any recieved messages
printX10Message(POWER_LINE_MSG, house, unit, command, extData, extCommand, remainingBits);
}
void printX10Message(const char type[], char house, byte unit, byte command, byte extData, byte extCommand, int remainingBits)
{
printX10TypeHouseUnit(type, house, unit, command);
// Ignore non X10 commands like the CMD_ADDRESS command used by the IR library
if(command <= 0xF)
{
Serial.print(command, HEX);
if(extCommand || (extData && (command == CMD_STATUS_ON || command == CMD_STATUS_OFF)))
{
printX10ByteAsHex(extCommand);
printX10ByteAsHex(extCommand == EXC_PRE_SET_DIM ? extData & B111111 : extData);
}
}
else
{
Serial.print("_");
}
Serial.println();
}
void printX10ByteAsHex(byte data)
{
Serial.print("x");
if(data <= 0xF) {
Serial.print("0");
}
Serial.print(data, HEX);
}
byte charHexToDecimal(byte input)
{
// 0123456789 => 0-15
if(input >= 0x30 && input <= 0x39) input -= 0x30;
// ABCDEF => 10-15
else if(input >= 0x41 && input <= 0x46) input -= 0x37;
// Return converted byte
return input;
}
void printX10TypeHouseUnit(const char type[], char house, byte unit, byte command)
{
Serial.print(type);
Serial.print(house);
if(
unit &&
unit != DATA_UNKNOWN/* &&
command != CMD_ALL_UNITS_OFF &&
command != CMD_ALL_LIGHTS_ON &&
command != CMD_ALL_LIGHTS_OFF &&
command != CMD_HAIL_REQUEST*/)
{
Serial.print(unit - 1, HEX);
}
else
{
Serial.print("_");
}
}
The other files required are the x10eh library found here (author Thomas Mittet):
https://code.google.com/p/arduino-x10/source/browse/trunk/Libraries/?r=66#Libraries%2FX10ex%253Fstate%253DclosedWhen viewing the signal on the XTBM, I see that 3/4 of the time the signal works fine but the rest of the time I get a collision. If I turn off the XTB-IIR, the PSC04 transmits correctly every time. This is sending the signal from a standard outlet remote from the XTB-IIR, but the signal from the PSC04 and XTB-IIR are both over 9.00. I moved to a different location and tried again and with the repeater plugged in, I was getting mostly collisions and very few successful signals.
The last check was to move the setup to the XTB-IIR and plug it into the booster port on the front of it. Using the same hardware and software, I got no collisions and all signals were received by the XTBM from a different circuit.
Does anyone have any clue why this could be happening? I made sure to try without anything plugged into the circuit just to eliminate any signal suckers/noise generators. I can play with the timing between signals, but the timing of the signal going to the PSC04 seems correct if it's working without the XTB-IIR connected or when plugged into the XTB-IIR booster port.