connecting pyboard to CAN BUS

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: connecting pyboard to CAN BUS

Post by dhylands » Sun Sep 04, 2016 6:16 am

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.

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Sun Sep 04, 2016 4:35 pm

PappaPeppar wrote:Here is a skin that I know Works.
https://github.com/HenrikSolver/pybcanskin
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.

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Fri Sep 16, 2016 2:07 pm

finally got my PCBs for my car project. Also waiting for a version for PyBoard with two interconnected transceivers on a single board.
Image

Image

Image

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Fri Sep 30, 2016 11:55 am

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?

Image

PappaPeppar
Posts: 30
Joined: Thu Dec 18, 2014 10:38 pm

Re: connecting pyboard to CAN BUS

Post by PappaPeppar » Fri Sep 30, 2016 3:19 pm

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

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Sat Oct 01, 2016 6:52 pm

yeah. Looks like it worked ) https://youtu.be/zVPl3wx_bmI

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Sun Oct 02, 2016 1:30 am

Here is my example code (still in progress)

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Tue Oct 11, 2016 12:27 pm

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

Image

Soldered all components and now testing

User avatar
kamikaze
Posts: 154
Joined: Tue Aug 16, 2016 10:10 am
Location: Latvia
Contact:

Re: connecting pyboard to CAN BUS

Post by kamikaze » Mon Oct 31, 2016 7:41 am

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 )

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: connecting pyboard to CAN BUS

Post by Roberthh » Mon Oct 31, 2016 8:32 am

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.

Post Reply