To rephrase, in the interest of comprehension:
When I send a closed or thrown signal using my Digitrax throttle the servo {on my Arduino} does not move but the closed or thrown signal shows on my JMRI loconet monitor. When I press the button {on my Arduino} the servo moves, and a signal is sent to the JMRI loconet monitor showing closed or open. I cannot get the servo {attached to my Arduino} to move using my Digitrax throttle. I hope the explains the problem more clearly.
Wally, does that accurately state your problem?
If so, it indicates that for some reason your Arduino sketch is not seeing the appropriate Loconet traffic generated by your Digitrax throttle, but is otherwise functional.
Thanks for your reply, As you stated, that is the exact problem.
Thanks again for your input. I do not use a DS64 or DS74 but the interface in the attached sketch which I have tested on numerous sketches, and it functions correctly.
Do you have any code that successfully reads from Loconet on that interface? I'd forget the servos for now, just prove you can read status.
Then go back and inspect the code posted in post#65. There's loconet reception code there that is completely missing from your latest posting.
sounds like your Arduino code is intended to be like a DS64/74 in that it receives
locoNet commands to control the servos -- not transmit them
would you mind telling where you live?
Port Elizabeth, South Africa
Thanks for the information. Using the turnout address in switch mode on my Digitrax throttle, I send either closed or open command to the Arduino via my Loconet interface board and move the servo moves one way or the other. When I push the button on the control panel the servo moves but I receive no indication in the JMRI Loconet monitor that the servo has moved. Thanks once again.
I think I now understand why I cant send messages to the loconet. As widbill stated my code has the following statement missing "LnPacket = LocoNet.receive();"Could someone please tell me how to include this statement into my code. Thanks
I give up. Please proofread your messages for content. This:
Using the turnout address in switch mode on my Digitrax throttle, I send either closed or open command to the Arduino via my Loconet interface board and move the servo moves one way or the other. When I push the button on the control panel the servo moves but I receive no indication in the JMRI Loconet monitor that the servo has moved.
Is a complete contradiction to the problem statement I clarified earlier. Yet your next statement, which is extremely unclear, seems to indicate you've recognized, finally, that you have the problem we've been pointing at.
As widbill stated my code has the following statement missing "LnPacket = LocoNet.receive();"Could someone please tell me how to include this statement into my code.
As for your request, look at what I said in #86, and read the code in #65 - the answer is there. What is missing is extremely clear. You continue to make requests that people code stuff for you, without making any real attempt to think, or code it yourself.
Please, try.
see the example
Thanks for all your help and comments.
Is your code in post#74 current?
I'd be happy to help out with a little code, but like @camsysca, I have become confused as to what's happening and what the problem is.
Reiterating, I know nothing about loconet, but looking at your posts above (particularly the code), here is what I think is happening:
- The servos attached to your Arduino can be operated by the switches connected to the Arduino
- When this servo operation occurs, a loconet message is sent which you can see on your monitor.
- The message sent does nothing to the servo, the Arduino already dealt with that. Perhaps it sends out a status message to a controller somewhere.
- The Digitrax throttle (whatever that is) can instruct servos to move to set turnouts. You're trying to use it to control the servos attached to the Arduino. You see appropriate commands from the throttle in the monitor program but the Arduino controlled servos don't react.
Please review and correct my understanding if it's inaccurate.
I think there's something wrong with your addresses too. You're using Arduino pin numbers as addresses - is that appropriate?
I'd suggest again that you need some more minimal code to verify that the Arduino is able to send, receive and react to loconet messages. Can you use the serial port for debug output?
I agree, @wildbill , and I think you identified earlier that the necessary code to 'catch' that Loconet message, and exercise the correct servo, is what's missing from @Greatnorthern 's posted code. However, I don't work in the Arduino<>Loconet area, I'm just another DCC Digitrax user; I don't know exactly what's required to go 'that extra mile' - I just think it must start with the code snippets obvious in post#65. One of these days, I may have to dig into this for my own needs, but I don't have that time or need right now. Somebody here must know, but how to ressurrect them from the sidelines, who knows?
Well, the suggestions of @wildbill und @camsysca are correct. All the code to receive Loconet commands is still missing.
First of all I would try one of the Loconet examples to check if all the HW is correct. This was already suggested in #93 by @gcjr .
If that works, and the commands from the digtrax throttle can be seen in serial monitor you should extend your sketch with the neccessary loconet commands. What you need is the
Loconet.receive() that should be called with every loop cycle. You can it call as first statement in loop().
To recognize the switch commands you need to create a function:
void notifySwitchRequest( uint16_t Address, uint8_t Output, uint8_t Direction ) {
// check for the correct address and call swithing your tunout here
}
This function will be called from Loconet.receive() if a switching packet is received.
[Edit] My LocoNet test equipment isn't fuctional at the moment, so I cannot check things. But I don't have a Digitrax throttle anyway. I always created the switching packets via JMRI
the code could be re-structured as follows
code to set a servo position should be separated from the button code so that it can be similarly called when either a button is pressed or a LocoNet msg called
loop() should have separate code to monitor for button presses and LocoNet packets.
i have no LocoNet I/F to test with, but the following compiled
void
setServo (
int n,
int pos )
{
if (HIGH == pos)
pointServo [n].write (servoHighPos[n]);
else
pointServo [n].write (servoLowPos[n]);
servoPos [n] = pos;
}
// -----------------------------------------------------------------------------
void loop ()
{
for (byte n = 0; n < Nsw; n++) {
byte sw = digitalRead (switchPin [n]);
if (swState [n] != sw) {
swState [n] = sw;
delay (20); // debounce
if (LOW == sw) { // pressed
if (servoPos[n] == LOW ) {
setServo (n, HIGH);
setLNTurnout (servoPin [n], TURNOUT_DIVERGING);
}
else {
setServo (n, LOW);
setLNTurnout (servoPin [n], TURNOUT_NORMAL);
}
EEPROM.update (n, servoPos[n]);
}
}
}
LnPacket = LocoNet.receive ();
if (LnPacket) {
Serial.print (" RX: ");
for (int n = 0; n <= getLnMsgSize (LnPacket); n++) {
char s [80];
sprintf (s, " %02x", LnPacket->data [n]);
Serial.print (s);
}
Serial.println ();
// if switch msg, call setServo() w/ sw # and position
}
}
the code simply prints the received LocoNet packet. I don't know the format of LocoNet packets: how to recognize a sw command, the sw # or position
You don't need to. The LocoNet library interprets it for you and calls a suitable callback function with the relevant information from the Loconet packet.
