connecting pyboard to CAN BUS
Re: connecting pyboard to CAN BUS
You're not allowed to allocate memory from within an interrupt handler.
recv needs to allocate a buffer to return its results.
See: http://docs.micropython.org/en/latest/p ... rules.html for more background.
recv needs to allocate a buffer to return its results.
See: http://docs.micropython.org/en/latest/p ... rules.html for more background.
Re: connecting pyboard to CAN BUS
What is a purpose of 120Ohm resistors in this scheme? I suppose they are for CAN bus termination... but I've seen that such resistors do connect CANH and CANL on the bus ends.PappaPeppar wrote:Here is a skin that I know Works.
https://github.com/HenrikSolver/pybcanskin
Re: connecting pyboard to CAN BUS
With two PyBoards (one is a sender in a loop, another is a receiver in a loop) I've found that if receiver is unable to read fast enough - then sender fails with OSError 16 (device busy). Is it a correct way to do: sender should try-except and retry on fail? But what if sender sends a message with id, that is not being accepted by any of devices?
-
- Posts: 30
- Joined: Thu Dec 18, 2014 10:38 pm
Re: connecting pyboard to CAN BUS
With CAN, all messages are received and acknowledged by all nodes on the bus. Then the filters decides if the message shall interrupt the software or the message shall be discarded. But if the bus it faulty or overloaded, you can get into a situation that messages from a node can not be sent to the bus. In that case you will get OSError 16. This will also happen when you call send() faster than the messages can be transmitted to the bus. At 1 Mbit/s you can send about one message each ms. I guess that this is what happens in your case. You can try to set the timeout argument to something sensible instead of catching the exception. It is documented here http://docs.micropython.org/en/latest/p ... b.CAN.send
Re: connecting pyboard to CAN BUS
yeah. Looks like it worked ) https://youtu.be/zVPl3wx_bmI
Re: connecting pyboard to CAN BUS
Here is my example code (still in progress)
Re: connecting pyboard to CAN BUS
in case if someone is interested in both CAN interface (1 and 2) cross-talk or even connecting to outer CAN bus - I have 10 PCBs for this. Actually 9 ) It is designed for two Microchip MCP2562 CAN transceivers
Soldered all components and now testing
Soldered all components and now testing
Re: connecting pyboard to CAN BUS
not tested in car yet, but there is a question... do I need to power my board from the car (OBD2 port for example) to get same ground with car`s CAN bus? Or is it just fine to connect CANH and CANL into OBD2 while having separate power supply for PyBoard? Google doesn't help so much. There are some CAN bus "hackers" that mention their arduino shield experience, but not actually saying HOW they connect them )
Re: connecting pyboard to CAN BUS
The CAN bus uses a diffferential signal. Given that, connecting the GND of PyBoard to the GND of the car is not mandatory, but it might help in case of noise & spikes. If you power PyBoard from the car's power network, then a common GND can be assumed anyhow. Us proper twisted & shielded cables, unless tehse are very short.