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
kamikaze
Posts: 128
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

connecting pyboard to CAN BUS

Postby kamikaze » Fri Aug 26, 2016 6:38 pm

Hi. I want to play with my Audi A6 (C5, 2004) CAN BUS. So I'm planning to connect pyboard to car`s CAN bus wires... what would you recommend me to use? Something like https://www.sparkfun.com/products/13262 or is it just fine to connect pyboard directly ?

User avatar
dhylands
Posts: 2319
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: connecting pyboard to CAN BUS

Postby dhylands » Fri Aug 26, 2016 6:48 pm

You'll need something half way in between.

The sparkfun board has bot a CAN controller (MCP2515) and a CAN transceiver (MCP2551).

The pyboard has a builtin CAN controller. If you want to use that, then you just need a CAN transceiver.

If you want, you can connect to the Sparkfun board using the SPI bus, but then you'll need to write your own driver (pyb.CAN only talks to the builtin CAN controller).

User avatar
kamikaze
Posts: 128
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sat Aug 27, 2016 2:33 pm

is it a better idea to find a 3.3V CAN tranceiver like from TI? http://www.ti.com/lsds/ti/interface/can ... ducts-wwe# the only problem here is that it is SOIC, not DIP

User avatar
dhylands
Posts: 2319
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: connecting pyboard to CAN BUS

Postby dhylands » Sat Aug 27, 2016 11:15 pm

The MCP2551 is available in DIP and SOIC formats, although it looks like its a 5V device, and 3.3v doesn't look like it will be interpreted as a logic high, so you'd need a voltage converter.

Using an SOIC with an SOIC to DIP adapter like this: https://www.sparkfun.com/products/13655 might be the best way if you want to use an SOIC device.

chrismas9
Posts: 24
Joined: Wed Jun 25, 2014 10:07 am

Re: connecting pyboard to CAN BUS

Postby chrismas9 » Sun Aug 28, 2016 1:41 am

I use the Microchip MCP series DIP CAN transceivers regularly with STM32. They are a 5V device but fully compatible with 5V tolerant 3.3V MCU's. No level translator is required.

The transmitter input requires <0.8V and >2V for logic 0 and 1 respectively which the STM32 can do.
The receiver output gives <0.8 and >3.5V out for logic 0 and 1 respectively and the 5V tolerant STM32 inputs will read these correctly.

Note that other brands of DIP CAN transceiver, eg TI SN65 series won't work with STM32. They need 3.5V logic 1 on the transmitter input.

folke
Posts: 8
Joined: Thu Jun 04, 2015 3:26 pm

Re: connecting pyboard to CAN BUS

Postby folke » Sun Aug 28, 2016 5:46 am

Hi,

I used a MCP2562 transceiver that has separate pins for logic supply and bus supply, so it fits any controller using 1.8–5.5V.
It's available in PDIP and SOIC.

Greetings
Folke

User avatar
kamikaze
Posts: 128
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Thu Sep 01, 2016 12:41 am

I have connected CAN1 and CAN2 (Rx1->Tx2, Tx1->Rx2) with wires directly and trying to send/receive a message. With no luck.

Code: Select all

from pyb import CAN

can1 = CAN(1, CAN.NORMAL)
can2 = CAN(2, CAN.NORMAL)

can1.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
can2.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))

can1.send('magic', 123)
can2.recv(0)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 110] ETIMEDOUT


any ideas?

User avatar
kamikaze
Posts: 128
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Thu Sep 01, 2016 10:49 pm

sometimes I'm getting OSError 16 which is device or resource busy. But can1/can2.any(0) is always False. What is wrong? when playing with CAN.LOOPBACK - everything works. Why CAN1 <-> CAN2 doesn't?

User avatar
dhylands
Posts: 2319
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: connecting pyboard to CAN BUS

Postby dhylands » Fri Sep 02, 2016 2:08 am

I suspect that it has something to do with the fact that the recv is synchronous. So you can't send while receiving.

In order to send and receive with the existing code, you'd probably need to use 2 pyboards.

That's just a guess on my part, and not backed by anything more than a hunch.

User avatar
kamikaze
Posts: 128
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Fri Sep 02, 2016 1:50 pm

what do you think about following scheme?

Image

I'm going to create a CAN bus shield PCB that will be able to join my car`s CAN bus. And to make both PyBoard CAN buses to interconnect even if nothing is connected to P2. Looks like it is no go to connect CAN1 with CAN2 directly.

Also... do I need to add termination resistors into the scheme for both tranceivers?


Return to “The MicroPython pyboard”

Who is online

Users browsing this forum: No registered users and 1 guest