CANhack.de CAN-Interface RKS+CAN
CAN Hardware, CAN Software, CAN Protocols - CAN Bus Forum for Your CAN Bus Project.

MCP2515: CAN Bus with Raspberry Pi Tutorial

 
New Topic Reply 🔗 🖨 CANhack.de - Index » Microcontrollers and Electronics, Programming
Author Message
Metaln00b
Hacker
Hacker


Joined: 08/08/2017
Posts: 28
Karma: +7 / -0   Thank you, like it!

2003 Smart CDI
CAN Support

Post18-08-2017, 18:21    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

USE AT YOUR OWN RISK!!!

Hardware:

Take a Raspberry Pi running the latest Jessie FULL version, specifically 4.9.35-v7+ (2017).
The Linux kernel includes almost everything you need. For older operating systems, the configurations may be slightly different, but you can use the familiar "how-to" guides for those cases.

I can only recommend the StromPi because it offers the possibility of connecting the Raspberry Pi to the mains power supply.

There's a CAN bus interface available, which is called MCP2515 on the network. Actually, that's one of the chips used, but that doesn't really matter for now.
The component can be identified by the "NiRen" marking on the circuit board.

It is important to disconnect the power supply of the TJA1050 and then provide it with a separate 5V power source.
Because if the GPIO pins of the Raspberry Pi are powered with 5V, you will have created a paperweight.
So, connect the 3V3 from the Raspberry Pi to the VCC of the MCP2515, and connect the 5V directly to the TJA1050 (but please remember to isolate them!).
If you search online, you'll quickly find something, although it includes a capacitor to ground, which isn't strictly necessary.

Please note the scratch mark on the right side, next to the soldered cable.

I also replaced the 8 MHz quartz crystal with a 16 MHz one. (It's not necessary to do this, but it seems you can achieve higher baud rates as a result.)


Here is the standard tutorial .

Software:
Once the operating system installation is complete, you can immediately start making some adjustments to the settings.

Does the standard tutorial not work for you?

Very simple.

The tutorial is quite old.

In the terminal:

sudo apt-get install can-utils // Installing
sudo raspi-config // Enable SPI

with

sudo nano /boot/config.txt

The line with...

dtparam=spi-on // Optionally, comment this out

"then add the following line:"

dtoverlay=mcp2515-can0, oscillator=16000000,interrupt=25 // Important: Space after the comma before "oscillator"! Use oscillator=8000000 for an 8MHz quartz crystal.

"Those who don't want to constantly start the CAN interface manually (using commands like `sudo ip link set can0 up type can bitrate 500000`) can use..."

sudo nano /etc/network/interfaces

at the end of the line.
Code:

auto can0
iface can0 can static
bitrate 500000

supplement. It's also included again with the important and correct indentation in the standard TuT documentation.

Save and restart.

After the restart.

sudo ip link set can0 up type can bitrate 500000

with

ifconfig

It checks whether can0 is present in the first line. The 1000 zeros are normal because the CAN bus functions like a network, but addressing is done via IDs.

There are still ways to test the software without a real CAN bus; just search for "vcan" or "vcan0 mcp2515," and you'll find something.

Regarding my software:

The spell checker modifies the source code. That's why I uploaded it as a ZIP archive.

Have fun!



You are not permitted to view these file(s), please log in or register for extended rights or status updates.



Translated on 11-08-2026, 6:27.
Back to top Profile PM Garage
postmann
CAN-Profi
CAN-Profi


Joined: 05/23/2013
Posts: 145
Karma: +64 / -0   Thank you, like it!


CAN Support

Post18-08-2017, 20:26    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

That looks really interesting; I think I'll get a Raspberry Pi and try to build that. icon_smile.gif


Translated on 11-08-2026, 6:33.
Back to top Profile PM
Metaln00b
Hacker
Hacker


Joined: 08/08/2017
Posts: 28
Karma: +7 / -0   Thank you, like it!

2003 Smart CDI
CAN Support

Post18-08-2017, 21:50    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

postmann wrote:
That looks really interesting; I think I'll get a Raspberry Pi and try to build it myself. icon_smile.gif


Please change "vcan0" to "can0" because "vcan" was only used for testing.
`frame.id` and the number indicate the specific byte (0-7) within the array.

If you have questions, don't feel obligated to ask icon_wink.gif.

Sure, here is the translation of the text from German to English:

"LG" can be translated as "Best regards" or "Sincerely". It is a common abbreviation for "Liebe Grüße", which means "Warm greetings" in English.


Translated on 11-08-2026, 6:34.
Back to top Profile PM Garage
Metaln00b
Hacker
Hacker


Joined: 08/08/2017
Posts: 28
Karma: +7 / -0   Thank you, like it!

2003 Smart CDI
CAN Support

Post01-09-2017, 10:34    Subject: Send with Canplayer: Easy & Reliable Data Transfer Quote

I've now used an Arduino to display various values on a screen. Everything works perfectly in the car regarding receiving data.

The Raspberry Pi and the Arduino are connected via 2 MCP2515 modules. Both are configured at 500kbps.

Now I have made a recording on the Smart CAN bus using candump candump -l can0, so that I don't always have to connect to the car, because I would like to test my Arduino onboard computer at my desk.

Then I have a log file (which also contains data) that I play back using canplayer -I candump-xxx.log, and the Arduino should process and display it.
Previously, I had to use sudo ifconfig can0 txqueuelen 1000 to resolve the message sendto: No buffer space available.

Unfortunately, nothing is being sent, so nothing is reaching the Arduino. It also seems like something is running, because I have to interrupt the sending process with Ctrl+C.

I use the MCP2515 in both. On the Arduino, the MCP is connected to listenonly.

I read that it might be because the MCP isn't detecting the 5V that the bus should have.

Both devices receive data without any problems when they are in the car. Therefore, the problem seems to be only related to sending data.

Does anyone have any ideas?

Thank you in advance.


Translated on 11-08-2026, 6:37.
Back to top Profile PM Garage
chipy
Guest




 


Free account, no CAN development support

Post01-09-2017, 10:59    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

Hello,

How do you access the CAN bus in a car to trace its signals?
Can it be accessed via the OBD connector?
What type of vehicle?
Or does one have to go behind the paneling?
Are there any specific areas along the bus route where it's easy to access the cables?
Can you send me a trace that includes steering wheel buttons, ignition, and lights?
I could then try sending it to my radio; I can adjust the vehicle type setting.


Translated on 11-08-2026, 6:40.
Back to top
Metaln00b
Hacker
Hacker


Joined: 08/08/2017
Posts: 28
Karma: +7 / -0   Thank you, like it!

2003 Smart CDI
CAN Support

Post01-09-2017, 11:40    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

chipy wrote:
Hello,

How do you access the CAN bus in a car to trace its signals?
Can it be accessed via the OBD connector?
What type of vehicle?
Or does one have to go behind the paneling?
Are there any specific areas along the bus route where it's easy to access the cables?
Can you send me a trace that includes steering wheel buttons, ignition, and lights?
I could then try to send it to my radio; I can adjust the vehicle type setting.



I can't tell you that. What kind of car do you have? I'm doing this on my Smart. Unfortunately, there's no CAN bus connection at the OBD port in the Smart, so you have to tap into the speedometer. Since the Smart apparently doesn't have a gateway, all messages are received everywhere.

It won't help you much if I send you my recording because each car uses a different ID for certain purposes. I don't know how it works with OBD2 specifically, but with standardized OBD connectors, the CAN bus is present, and that's where you can tap in.

As far as I've followed your thread, it seems that your vehicle uses different CAN-BUS systems for multimedia and engine management.

I'm not sure how familiar you are with the subject matter, but perhaps you should do some more research on what a CAN bus is. *No offense intended.*


Translated on 11-08-2026, 6:42.
Back to top Profile PM Garage
chipy
Guest




 


Free account, no CAN development support

Post01-09-2017, 12:04    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

It won't do you any good if I send you my recording, because each car uses a different ID for certain purposes.
I can adjust the vehicle type on the radio, for example, to 'BENZ (Smart)'.

Unfortunately, there is no CAN bus available at the OBD connector; you have to tap into it at the instrument cluster.
'Surely, the Smart isn't that old, is it?'
I'm surprised that the CAN pins are not connected on the OBD port.

Since the Smart only has one bus, that simplifies the testing process. Could you please send me a trace, preferably with the ignition on and the lights turned on?
Or, at what point does the radio turn on when the key is inserted?
But 'ignition on, lights on' would definitely be number one.
On the other hand, with ignition enabled, there are probably even more messages that would need to be filtered in order to determine what turns on the radio.


Translated on 11-08-2026, 6:45.
Back to top
Metaln00b
Hacker
Hacker


Joined: 08/08/2017
Posts: 28
Karma: +7 / -0   Thank you, like it!

2003 Smart CDI
CAN Support

Post01-09-2017, 13:17    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

chipy wrote:

"Surely, the Smart isn't that old, is it?"
I'm surprised that the CAN pins are not connected on the OBD port.


Smart cars with a CDI engine manufactured before 2003 do not have an OBD2 system; it was only introduced starting in 2004.

All other types of engines, such as gasoline engines, have an OBD2 system according to the "EU standard"!

Furthermore, it's becoming a bit "off-topic" icon_wink.gif icon_razz.gif.
You're posting questions in every thread, and some of them lose context that way. Maybe you could ask those questions in the thread you already started... sorry about the multiple threads (there are already two about your project).


Translated on 11-08-2026, 6:47.
Back to top Profile PM Garage
postmann
CAN-Profi
CAN-Profi


Joined: 05/23/2013
Posts: 145
Karma: +64 / -0   Thank you, like it!


CAN Support

Post01-09-2017, 17:29    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

If you can select the "BENZ(Smart)" option on your radio, it's either for a smart Forfour, as it shares the same audio components as the A-Class and B-Class models, or for a 453 model (in which case, it should more accurately be labeled "Renault (smart)").

For the older CityCoupe and Roadster models, there is no CAN bus connection at the radio; they were supplied with power and controlled using analog signals.


Translated on 11-08-2026, 6:49.
Back to top Profile PM
Metaln00b
Hacker
Hacker


Joined: 08/08/2017
Posts: 28
Karma: +7 / -0   Thank you, like it!

2003 Smart CDI
CAN Support

Post03-09-2017, 15:38    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

Problem solved.

When connecting two controllers together, a jumper must be placed on pin J1 of the MCP2515 to terminate the CAN bus.

Sure, here is the translation of the text from German to English:

"LG" can be translated as "Best regards" or "Sincerely". It is a common abbreviation for "Liebe Grüße", which means "Warm greetings" in English.


Translated on 11-08-2026, 6:50.
Back to top Profile PM Garage
alex
Guest




 


Free account, no CAN development support

Post03-09-2017, 16:34    Subject: MCP2515: CAN Bus with Raspberry Pi Tutorial Quote

If there are only two devices, trust each one and use a 120-ohm termination at each end of the bus.

'But one probably suffices; without it, the transceivers are likely to have such a high impedance that, if they drive the bus to a dominant state, it won't return to a recessive state when they shut down.'


Translated on 11-08-2026, 6:51.
Back to top
New Topic Reply 🔗 🖨 CANhack.de - Index » Microcontrollers and Electronics, Programming
Similar articles and topics
Topic Forum
No new posts Can-Bus Botschaft auswerten CAN Bus General
No new posts Analyzing CAN signals with a PC in the E90 CAN Bus General
No new posts CANopen Daten auswerten Microcontrollers and Electronics, Programming
No new posts Analyzing CAN messages in an Audi A5 using a microcontroller Microcontrollers and Electronics, Programming
Jump to:  
You cannot post new topics in this forum.