Hey guys,
I am trying to send data to my arduino over the CAN bus. Unfortunately I am not receiving any messages. According to the can stats most of the transmissions time out. I also ran a loopback test, which failed. Does anybody know why this is happening?
DroneCAN is not required when using the Lua bindings. You can (and must) process individual frames at a fairly low level when developing a CAN driver with ArduPilot Lua scripting. For example, I have a CANOpen driver for some industrial motor controllers that works quite well and is completely independent of DroneCAN. Unfortunately, I can’t share the source for that here.
Assuming the wiring is correct, the CAN_write example should send a valid frame that can be read/parsed by a connected Arduino device. I think the mcp2515 library should be sufficient for that.
Your own code includes an extremely short timeout of 100 microseconds. The example uses 10000 microseconds - perhaps the message is timing out every time. I’m not sure how CAN message calls from Lua are scheduled, but I do know that scripting is prioritized fairly low in the grand scheme of things, and scripting runtimes are often on the order of milliseconds as a result. So, a timeout of under 1ms is extremely brief in ArduPilot scripting terms.
Thank you for your hint. I increased the timeout, but it still does’nt work. I also tried the example script, but when I use CAN:get_device(20) (like in the example script) instead of CAN.get_device(20) I get the following error: “CAN:get_device expected 1 arguments got 2”.
Since the loopback test fails, I think it might be a wiring issue, but i really don’t know what could be wrong with only 3 wires ( High <-> High, Low <-> Low, GND <-> GND). The arduino is powered by my computer.
The “colon” notation is a sort of syntax sugar, where the colon referenced method receives a “self” object as the first argument to approximate object oriented behavior.
The master branch has a PR to enforce consistency in using the colon syntax across most, if not all bindings. 4.3 and earlier may encounter errors with some of the recent examples, as you discovered. Your fix is correct for the branch on which you are working.
Failing physical access to your hardware and an oscilloscope, it’s hard to diagnose the problem.
Hey, just wanted to let you know that everything is working now. The problem was a missing termination resistor and a different clock speed on the Arduino. Thank you for your help.