Excuse the horrible pun. I'm having a terrible Monday.
My project involves controlling a servo motor using an Arduino Mega. Working perfectly, a remote control button would be pressed, which the Arduino would read and then begin turning the motor. Once the motor achieves its final position, the Arduino (Mega) should send out a CAN signal which another Arduino reads. The second Arduino then displays what has happened on the Serial Port.
Currently, I've successfully got the Mega reading the remote signal, moving the motor, and sending out (what I think is) the correct signal. However, the other Arduino seems to read absurd values, and therefore, my "
if(message.data == 17)
" code falls flat on its face.
I'm using the MCP2515 library that some gentleman called David Harding had created, and I saw it modified somewhere random online. The library's CAN signal has a message.ID which is a "long" variable, and a "byte data" array for sending 8 bytes of CAN data. I am comparing "message.data" with no success.
I tried displaying the data at both ends. So, "Serial.println(message.data)" at the transmission end shows the _correct_ value, but the same thing at Receiver end doesn't. What is remarkable is that the Receiver always displays the same two values, always alternately, regardless of what CAN message is actually transmitted.
This might be an issue with the MSBFirst thing, although I've had it this way for both sides, or maybe something to do with buffers not getting cleared? It has two RX buffers, but it always receives in the first node, so I don't think that is an issue either.
The code is pretty long, so I have attached both the Transmit and Receive sketches.
Any help will be most appreciated. I'm losing my head!