I've used CMRI for quite a while now, but must admit that I do not understand how it works.
The following short sketch is part of a much larger one, but I just want to test the handshake between the Arduino and CMRI.
void setup() {
Serial.begin(9600,SERIAL_8N2);
int hs = 0; // handshake
int b = 0; // blink
while (hs != 1) {
cmri.process();
hs = cmri.get_bit(23); // JMRI reset light turns this on
cmri.set_bit(b, tstLight); // step thru 12 sensors and blink
b +=1;
if (b> 12) {
b = 0;
tstLight = !tstLight;
}
}
cmri.process(); // doesn't work with or without this line
tstLight = true;
cmri.set_bit(16,tstLight); // turn off reset
digitalWrite(13,1);
}
void loop() {
// put your main code here, to run repeatedly:
}
The while loop flashes sensors on the JMRI panel and waits for a reset light on the panel to be clicked.
But the last cmri.set_bit never arrives at JMRI.
Why do the first 12 sensors work, but once a bit is received, the final set_bit doesn't?
@johnwasser, Thank you for the link. I was rather hoping the OP would take the trouble to provide it.
It looks like it should be easy to interface with that protocol using an Arduino. I have built a very similar system for communication between a Python program on my PC and an Arduino.
@GordB, the PDF does not seem to describe the Arduino library you are using. Perhaps you can post a link to its documentation.
Problem solved - pilot error, as usual. The communications were working, but my logix (sic - that's what JMRI calls it) at he receiving end
was faulty.