Send commands to X10 devices using CM17A dongle

I am trying to reproduce Arduino Playground X10 project using electric imp. I use pin1, pin2 and ground from April board connected to Female DB9 of CM17A as follow:
pin1 -> 4(DTR),
pin2 -> 7(RTS),
ground -> 5(GND).
I wrote device code according to FireCracker (CM17A) Communications Specification but for some reason I can’t make it work.
I added logging to my code but still can’t figure out what may be wrong.
Below you can see my code for device. This code will send command “ON” to “A8” device once imp device is started. The logging includes 3 lines:

  1. 5 bytes sent to DTR/RTS with taken time
  2. bits sent to DTR(pin1)
  3. bits sent to RTS(pin2)
    I tried to change timeout between bits in different ranges but without luck.
    I would greatly appreciate if somebody can help me and point in right direction to debug the code I wrote or debug electric imp signals. I already bought second electric imp and April board thinking that maybe something is wrong with my first one but unfortunately it was not the case. I still can’t make it work.
    Thank you in advance.

`

DTR <- hardware.pin1;
RTS <- hardware.pin2;

DTR.configure(DIGITAL_OUT);
RTS.configure(DIGITAL_OUT);

local bitDelay = 0.001; //1ms

server.log(“Device Started”);

agent.on(“command”, function(arg){
SendCommand(arg.unit, arg.command);
});

function SendCommand(unit, cmd)
{

local houseArray = [ 0x60, 0x70, 0x40, 0x50, 0x80, 0x90, 0xA0, 0xB0, 0xE0, 0xF0, 0xC0, 0xD0, 0x00, 0x10, 0x20, 0x30 ];
local unitArray =  [ 0x00, 0x10, 0x08, 0x18, 0x40, 0x50, 0x48, 0x58 ];
local log="";
local log1="";
local log2="";

cmd = cmd.tointeger();
server.log("Command received: " + unit + "(" + cmd + ")");

//Parse Parameters
unit = unit.tolower();
local houseIndex = unit[0] - 'a';
local unitCode = unit.slice(1).tointeger() - 1;
local commandCode;
local houseCode = houseArray[houseIndex];
if(unitCode > 7 && (cmd == 1 || cmd == 2 ))
{
    houseCode = houseCode | 0x4;
    unitCode -= 8;
}

switch(cmd)
{
    case 1: { commandCode = unitArray[unitCode]; break;}
    case 2: { commandCode = unitArray[unitCode] | 0x20; break;}
    case 3: { commandCode = 0x88; break; }
    case 4: { commandCode = 0x98; break; }
    case 5: { commandCode = 0x90; break; }
    case 6: { commandCode = 0xA0; break; }
    case 7: { commandCode = 0x80; break; }
}
//End Of Parse Parameters

local messageBuff = array(5);
messageBuff[0] = 0xD5;                      //First byte of Header
messageBuff[1] = 0xAA;                      //Second byte of Header
messageBuff[2] = houseCode;                 //House Code 
messageBuff[3] = commandCode;               //Command Code for unit
messageBuff[4] = 0xAD;                      //Footer

DTR.write(0);                               //Put Firecracker into ready mode
RTS.write(0);                           
imp.sleep(bitDelay);

DTR.write(1);
RTS.write(1);
imp.sleep(bitDelay);

for (local i=0; i<5; i++){
    local startMillis = hardware.millis();
	for(local mask = 0x80; mask > 0; mask = mask >>1 )
	{
		if( mask & messageBuff[i] ) 
		{
			DTR.write(0);              // 1 = RTS HIGH/DTR-LOW
			log += "1";
		}
		else
	    {   
			RTS.write(0);              // 0 = DTR-HIGH/RTS-LOW
			log += "0";
	    }
		imp.sleep(bitDelay);                 

        log1 += DTR.read();
        log2 += RTS.read();
        
        DTR.write(1);
        RTS.write(1);
		imp.sleep(bitDelay);
	}  
	log += " " + (hardware.millis() - startMillis) + "ms ";
}
server.log(log);
server.log(log1);
server.log(log2);
imp.sleep(1);
DTR.write(0);
RTS.write(0);

}

SendCommand(“A8”, “1”);

`

Are you certain the issue is a software issue? I’m not familiar with X10 or the CM17A, but if they’re hooking it directly up to an Arduino, there’s a good chance that it need 5V signals, not 3v3 signals. You may need to connect it through a logic level shifter.

It does appear that the CM17A is actually powered by the DTR/RTS lines. As Matt says, an Arduino is at 5v (and can supply more current than an imp) so this not working isn’t totally surprising.

Really, that part seems intended for a PC, which will generally be driving +/-12v on those lines (RS232 levels)

Thank you for comments. I will try to use logic level shifter.

Did you get this working? Just starting to look at migrating my house off X10 and was considering using ElectricImp for some of the migration tools.