Skip to main content

Reply to "Sending TMCC Commands to Legacy Base over Serial Connections"

Professor Chaos posted:

Chris, you really don't have to worry about sending bytes together vs independently.  When you do a serial write, the byte gets deposited in an internal buffer. The Arduino can execute tens of thousands of other instructions in the time it takes to send 3 bytes at 9600 baud. So your code puts bytes in the buffer and moves on to to other things;  Arduino routines running in the background will send those bytes out the serial line with the right timing for the selected baud rate.

However, JGL, I am not sure your approach of writing two bytes as an unsigned int will work. Serial.write is listed as taking a single byte, a string, or a pointer to a buffer. I just tried passing an unsigned int to Serial.write and only the second byte was printed.

So the simplest way is to use three writes:

Serial.write(0xFE);
Serial.write(commandByte2);
Serial.write(commandByte3);

 

 

So the way I show it in my previous post is ok?

Professor Chaos posted:

 One thing to keep in mind: if  you are sending multiple 3-byte commands, you have to wait ~ 30 milliseconds between commands or the Base will ignore them. The approach I take is to deposit TMCC  commands into a circular buffer.  Then every pass through loop(), I check to see if at least 30 milliseconds have elapsed since the last command transmitted to the Base. If so, the next command is read from the buffer and sent to the base.

 Is there a tutorial on how to do this? I would to use this on the master so it would the commands so they would not be ignored.

Professor Chaos posted:

If you don't want to build your own level shifter circuit, you can just buy a MAX232-based adapter like this one.  It will invert the RS232 voltages and take care of the negative voltage issue for you.

The Arduino could monitor the base - I believe the base echoes serial commands that are sent from the CAB.  But you can't be certain that this represents the current state of the switch - what if a locomotive tripped the non-derail feature?

A better (though more complex) approach is to direct monitor the switch state.  But how easy that is depends on what kind of switch machine you are using.

Thank you for the info on the Max232. 

Yes, you are right about the current state of the switch. I am hoping that Lionel comes out the switch monitor soon, which would update the base if non-derailing is activated. I am planning on using z-stuff switch machine, the DZ-255 which is a TMCC machine.

Chris 

 

 

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×