Raspberry Pi Wiring and Libraries?

Hi all,

Been looking forward to tinkering with the car since I saw this project, but instead of getting the full M2 I opted for the Interface Board that I’d be using in conjunction with one of my many Raspberry Pi’s. I’ve been looking around and I can’t seem to find any documentation on how exactly to connect to the Interface Board and get some tools up and running to take a look at what’s going through the CAN Bus. I’m rather new to the whole car-hacking scene, but I do work in software development so just getting pointed in the right direction is probably good enough to get me rolling.

I’m assuming that I’ll need some connection to the CAN0 or CAN1 Tx/Rx, through the GPIO’s on the RPi, but as for how to read data from and send data to the car I’m not seeing anything in the docs. Any help would be greatly appreciated.

Hey there! Just today, we added a page to our new documentation system to help with projects like yours:

http://docs.macchina.cc/m2/technical-references/byob.html

This page will help as you physically hook up other microcontrollers (like Raspberry Pi’s) to the interface board.

One of the projects on our list to do is a tutorial of how to do basic CAN read/write through the Interface board with a Pi Zero - haven’t gotten to that quite yet. We’ll probably do a “simple” SocketCAN example to start with.

As you move forward, we encourage you to post up both questions and successes so we can all help and learn together. Thanks for your interest!

1 Like

Awesome! Took a look at it and it seems to be about what I expected. I’ll see what I can figure out on my own playing with SocketCAN, but if you need a guinea pig for your upcoming tutorial just let me know!

This is a crazy idea but maybe it could just work - I wrote a program called SavvyCAN that can run on Linux and use socketcan devices. If you wanted you might try compiling it for RPi. It uses QT and I think you can compile QT apps for RPi. Anyway, maybe it’s not what you’re after but perhaps it might be worth trying to compile it. I’ve compiled it for Android once and it did run.

Sure, I’d be up for giving it a go – I’ve got a few of my Pi’s accessible from outside home so I could probably get it building on my dev server and drop it on whichever Pi I end up using for the M2 from there. Where’s the most current version?

Please correct me if I am wrong… (Going from memory and not looking at schematics, specs etc)

For most CANBUS stuff you have a controller and a transceiver. The transceiver handles the electrical connections to the bus and the controller does the heavy lifting for the protocol its self.

The Arduino DUE has the Controller for 2 ports built in but need the transceiver to work. I believe the Arduino Due uses the MCP2515 controller which is what the due_can driver is for. The transceiver is in the M2 interface board and doesn’t require any additional software to control.

Problem you will run into with the RPI is that it doesn’t come with a controller so you either have to add on a board with a controller such as the MCP2515 or build a software module to do it all yourself. If I understand correctly, if you write a software module to do it yourself you should obtain full unfettered access to the CANBUS but may take up significant processor time.

You could potentially pick up something like this for your RPI that provides 12 volts to your RPI and provides 2 complete canbus interfaces. To make it work with the M2 you could bypass the transceivers on this board and instead make the connections to the M2. Sort of a hack way of doing it but should work without requiring you to do a bunch of extra work
.

Nothing says you couldn’t use the pican or something similar to make a proof of concept and then from there build an add on board that would allow you to have just the controller on board once you know your setup works.

You may also not need the SMPS option if you are able to power the RPI from the M2. I actually have a non SMPS single channel PiCAN 2. Wish I had realized what the SMPS option was for when I bought it. (Allows power from the vehicle directly. )

2 Likes

Doh! I was thinking that the Pi had built in CAN controllers like some other boards. Rod, you are absolutely right.

I guess one could still interface directly to the SWCAN and LIN/K-Line channels directly with a Pi.

And J1850.

But then again the Motorola Controller looks to be SPI controlled and should be reasonably easy to create a board to do so. Might be smarter to make a carrier board for a RPI with the canbus controllers built in. And have the RPI header setup in a manner to easily allow a RPI Zero or a standard RPI to be connected.

I also got the interface board and was hoping on getting a Raspberry Pi Zero W up and running with the M2. I found a tutorial for the mcp2515 that was mentioned previously that might be of some help: https://harrisonsand.com/can-on-the-raspberry-pi/ :grin:

@ronaes, did you ever make any more progress on this? I’m curious.

Just be aware that if your using one of those boards you already have the interface in place. Using the M2 at that point is a waste of time if your using just CANBUS.

The PICAN can be had with 12volt input and 2 CANBUS connections. I haven’t tried mine with SWCAN to see if it will work with it but it probably will. I have a PICAN without the 12volt option and only one port. Works nicely.

If you want to try to get it to interface into the M2 you have to cut the traces on the add on board you buy between the MCP2515 and the onboard transceiver and connect those lines to your M2. (May be other issues as well but I am not aware of them)

Basically what your looking at is to do CANBUS you need the controller (MCP2515, Arduino Due, Freescale i.mx series) and a transceiver. The M2 interface board has the Transceiver onboard and uses the controllers of the Arduino DUE from the processor board. Since the RPI doesn’t have the controller you need to add one for each CANBUS. If you use any canbus shield they already have both the controller and transceiver. So realistically this is why I mentioned you would have to chop up your board, or build one from scratch with just the MCP2515’s onboard.

1 Like