How to 'Sniff' the CANBUS?

Introduction and miscellaneous that we haven't created categories for, yet
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

How to 'Sniff' the CANBUS?

Post by Alibro »

Hi guys
I have been thinking of converting a car to EV for a couple of years but one of the questions everyone asks is how to control the Dash?
It is one of the BIG stumbling blocks and I suspect may be the reason many projects stall so I decided to look into it first before spending big money on batteries, cars, motors etc.
I ordered a couple of clone Arduino Uno's and a CANBUS shield from Aliexpress and gave it a go in my 2012 C Class.
I have to say I hadn't much success.
When plugged into the ODBII port I got nothing on the monitor
When connected to a pair of CANBUS wires in the boot I got nothing on the monitor but my dash lit up like a Christmas tree with errors flashing. Thankfully after disconnecting the CANBUS shield from the car it was OK but had me worried.
I tried following several online tutorials for this project including

https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/
https://seeeddoc.github.io/CAN-BUS_Shield/
https://www.instructables.com/id/CAN-Bu ... h-Arduino/

This is the UNO I was using https://www.ebay.co.uk/itm/UMTMedia-Ard ... 2749.l2649
This is the shield I was using https://www.diymore.cc/products/mcp2515 ... no-diy-kit

I have to admit after a while I ended up going round in circles so I was wondering what you guys use to read the CANBUS signals?
I need a bigger hammer!
User avatar
Kevin Sharpe
Posts: 1345
Joined: Fri Dec 14, 2018 9:24 pm
Location: Ireland and US
Been thanked: 4 times

Re: How to 'Sniff' the CANBUS?

Post by Kevin Sharpe »

Alibro wrote: Sat May 16, 2020 11:53 am I have to admit after a while I ended up going round in circles so I was wondering what you guys use to read the CANBUS signals?
Have you seen this thread?

viewtopic.php?f=9&t=735
This is a personal post and I disclaim all responsibility for any loss or damage which any person may suffer from reliance on the information and material in this post or any opinion, conclusion or recommendation in the information and material.
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

I read through the thread but most of it raised more questions than answers.
I'm not sure why my car threw a wobbly with the UNO and CANBUS Shield. I've never been any good at programming so I rely on others to write the code and I struggle to understand what the problem is when something goes wrong. I've even bought a genuine UNO and ordered another CANBUS Shield in case my hardware was causing the issue so I'll report back when it arrives.
I need a bigger hammer!
User avatar
dima
Posts: 157
Joined: Sun Dec 09, 2018 9:35 pm
Location: Canada

Re: How to 'Sniff' the CANBUS?

Post by dima »

CAN Shields are not for beginners. MCP2515 can behave differently with different libraries (there are a few to choose from)

I recommend plug-and-play USB dongle that your can read/write with software.

https://www.tindie.com/products/lll7/ca ... erter-uccb

https://store.protofusion.org/product/canable
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

Thanks for the suggestions Dima
I'll try again when the other shield arrives. I was concerned the library I used for the cheapo shield may have been part of the issue hence buying a different one from another source. I couldn't find a library specifically for the board I bought but hoped it would work with any. Maybe it doesn't.
It's already on it's way so rather than desperately throwing more money at the problem I'll try the parts I've already ordered and if no joy I'll look into your suggestions.
I need a bigger hammer!
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

I did some playing about yesterday and made a little progress. I found an OBD2 library with a couple of examples that worked with my Shield. I can now read various things with it like RPM, Temp, Time engine running and a few more.

https://github.com/sandeepmistry/arduino-OBD2

I know a plug and play dongle would be easier as I can't program for S%&t and am new to Arduino but I think it's important to get my head around it as at some stage I want to inject signals to run the dash and it will be much better if I understand what is going on when it comes to fault finding.
I may as well learn this stuff now while I'm gathering the hardware together for my EV project and I'm not busy.
It's not exactly what I wanted but at least I know the Shield is working so now I can try to get the data I want.
I need a bigger hammer!
jon volk
Posts: 572
Joined: Wed Apr 10, 2019 7:47 pm
Location: Connecticut
Been thanked: 2 times

Re: How to 'Sniff' the CANBUS?

Post by jon volk »

Formerly 92 E30 BMW Cabrio with Tesla power
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

Finally this evening I managed to get some canbus data from the OBD2 port using the shield mentioned earlier.
I've been able to use the examples in the OBD2 library to get info like Engine RPM, Coolant and oil temp and about 10 other stats for a week or so but while it's nice to see the thing working it doesn't give me the data I need, so I've been messing about for days copying bits from one sketch to another.
It's been a steep learning curve as I've done almost nothing with Arduino before so to finally get something (without sending the car into a hissy fit) is a big achievement for me.
Now I need to tidy things up a bit and try to interpret the data I'm getting.
How hard can it be? 😋

Edit BTW I had ordered other bits and pieces as advised but they haven't arrived yet so I figured I'd keep trying. :)
I need a bigger hammer!
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

Alibro wrote: Sat May 16, 2020 11:53 am Hi guys
I have been thinking of converting a car to EV for a couple of years but one of the questions everyone asks is how to control the Dash?
It is one of the BIG stumbling blocks and I suspect may be the reason many projects stall so I decided to look into it first before spending big money on batteries, cars, motors etc.
I ordered a couple of clone Arduino Uno's and a CANBUS shield from Aliexpress and gave it a go in my 2012 C Class.
I have to say I hadn't much success.
When plugged into the ODBII port I got nothing on the monitor
When connected to a pair of CANBUS wires in the boot I got nothing on the monitor but my dash lit up like a Christmas tree with errors flashing. Thankfully after disconnecting the CANBUS shield from the car it was OK but had me worried.
I tried following several online tutorials for this project including

https://wiki.seeedstudio.com/CAN-BUS_Shield_V2.0/
https://seeeddoc.github.io/CAN-BUS_Shield/
https://www.instructables.com/id/CAN-Bu ... h-Arduino/

This is the UNO I was using https://www.ebay.co.uk/itm/UMTMedia-Ard ... 2749.l2649
This is the shield I was using https://www.diymore.cc/products/mcp2515 ... no-diy-kit

I have to admit after a while I ended up going round in circles so I was wondering what you guys use to read the CANBUS signals?
So after an embarrassing number of hours faffing about with this I finally got it working. I think I managed to commit every newbie cockup possible including in no particular order
Wrong library for the sketch
Wrong library for the shield
Too many libraries in the libraries folder
Adding or changing libraries without rebooting the Arduino IDE
Wrong baud rate for the serial monitor
Wrong baud rate for the CANBUS in my car
Assuming examples supplied by the shield manufacturer would work with their shield.

If I'd made one of these errors I could have found it and sorted the issue fairly quickly but I was making most of them at the same time so it took a while.
My excuse is ignorance because I'm new to Arduino and haven't programmed anything since I was a kid playing with my VIC20
Unfortunately I'm also a bit stupid so I take longer than some to figure stuff out. 🤔

Here is a video I made showing what I did to get it working.



This was only a test to confirm I could do it, so I won't be going any further until I get the donor car. If anyone has any advice that might be helpful please share.
I need a bigger hammer!
User avatar
4markowen
Posts: 42
Joined: Mon Apr 20, 2020 9:12 am
Location: Nottingham, UK
Has thanked: 21 times
Been thanked: 1 time

Re: How to 'Sniff' the CANBUS?

Post by 4markowen »

experience is a hard teacher, but a good one. You're no longer new to Arduino though :)
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

4markowen wrote: Mon Jun 08, 2020 8:49 am experience is a hard teacher, but a good one. You're no longer new to Arduino though :)
LOL, No longer new to Arduino but still very much novice.
I need a bigger hammer!
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

Here is a great video I just found. The guy not only goes into detail about how to sniff the CAN-BUS but also how to reduce the current draw from his interface.
I need a bigger hammer!
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

I have made a bit more progress on this and posted a video here.



I still have a lot of learning to do on this but at least I'm making some progress, even if it is slow.
I need a bigger hammer!
prensel
Posts: 111
Joined: Mon Nov 25, 2019 1:36 pm
Location: Nijmegen (NL)
Contact:

Re: How to 'Sniff' the CANBUS?

Post by prensel »

Let me give you some good advice: The challenge is NOT getting the Arduino and CANadapter to work.
Your real challenge will be to understand what each of the 64 bits of each CANbus datagram means.

This is not something you will achieve with the setup you are trying to get to work now (which really shouldnt be any issue at all with the wealth of sketches and examples available).

Best thing you can do now is to buy a working CANadapter that your PC (Windows or Linux) does recognize and dive into getting to understand how savvycan or the kvaser tools work.

By the time you know what to send over the bus to get the action you want you can look into getting the Arduino to work and let it sent these datagrams for you.
= Th!nk PIV4 Collection, support, sales =
User avatar
mdrobnak
Posts: 692
Joined: Thu Mar 05, 2020 5:08 pm
Location: Colorado, United States
Has thanked: 1 time
Been thanked: 5 times

Re: How to 'Sniff' the CANBUS?

Post by mdrobnak »

SavvyCAN or BUSMaster (From ETAS / Bosch) are probably the best free tools. I use Vehicle Spy, but it is far from free. :( And, yes, the data is the issue, not so much getting the physical setup / data capture done.
The first thing I try and do is - control the things you can -- press the brake pedal, open / close doors, etc... Unplug the coolant temperature sensors and see what happens on the dash, see what data changed... See what seems to rise with RPM (probably split over two bytes). It's not a quick task, but definitely rewarding when done.

-Matt
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

Thanks for the advice guys.
When I started this I knew Nothing about CAN and virtually nothing about Arduino so what I have done is not worthless. I've learned a lot and yes I still have a lot to learn but at least I'm making progress even if it is slow.
For me getting the Arduino and CAN adapter working WAS a challenge because I didn't have a clue.
I will probably end up buying a working CAN adapter in the end but I have more time than money so I'll persist for now and see what happens. Hopefully I'll learn enough to make an informed decision when I go to buy said CAN adapter.

The car I plan to convert is a 2004 Landrover Freelander which probably doesn't have that much CAN anyway so I'll give it a go and see what happens.
Why A Freelander? I like them and I have one so why not?
OK there are probably many good reasons why not but as you may have gathered I'm a bit stubborn and once I get an idea in my head.......
I need a bigger hammer!
User avatar
mdrobnak
Posts: 692
Joined: Thu Mar 05, 2020 5:08 pm
Location: Colorado, United States
Has thanked: 1 time
Been thanked: 5 times

Re: How to 'Sniff' the CANBUS?

Post by mdrobnak »

2004 should be pretty simple in terms of CAN, yes. Maybe 10-15 IDs likely. Significantly less than the 100+ in the Tesla Model 3...

The ECU will probably have 1-3 IDs. One of those is gonna have RPM in it. Likely with some torque values for any traction control.
Another one of them will probably have temperatures and such in them, probably which lights on the dash, too. You should be able to get the dash happy pretty easily, except for ABS / traction control lights, as those come from that unit directly.

-Matt
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

When I get started I'll report back with my findings.
These cars are pretty basic but they do have hill descent control which operates the ABS.
I don't think they have traction control because spinning wheels just keep spinning, I have tried to use them off road and they are OK but not great. They have a fluid filled VCU transferring torque to the rear wheels which is purely mechanical so nothing clever to worry about there.
I need a bigger hammer!
DaveH
Posts: 91
Joined: Sat Jun 13, 2020 9:04 am
Location: Hull, UK
Has thanked: 1 time
Been thanked: 8 times

Re: How to 'Sniff' the CANBUS?

Post by DaveH »

What signals do you need to use on the Freelander? I have reverse engineered a 2009 Freelander, I'm not sure if it's the same generation but even if not, if it has CAN it will be similar. I have details of RPM, speed, accelerator position, brake, reverse etc.
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

DaveH wrote: Mon Jul 06, 2020 9:27 pm What signals do you need to use on the Freelander? I have reverse engineered a 2009 Freelander, I'm not sure if it's the same generation but even if not, if it has CAN it will be similar. I have details of RPM, speed, accelerator position, brake, reverse etc.
To be honest I don't know yet, I'm assuming I'll need various engine parameters, speed, rpm etc. I've still to dig into the Freelander but it would be great if you could share your findings.
Thanks
I need a bigger hammer!
DaveH
Posts: 91
Joined: Sat Jun 13, 2020 9:04 am
Location: Hull, UK
Has thanked: 1 time
Been thanked: 8 times

Re: How to 'Sniff' the CANBUS?

Post by DaveH »

An easy one to look for first would be accelerator position - you can do it with the engine off. On the '09 it's ID 279 (decimal), lower 10 bits of bytes 2 and 3 (where byte 0 is the first). You divide it by 10 to get a percentage.

Another one to look for is engine speed, which is in ID 298, lower 13 bits of bytes 6 and 7.

There were about 40 different IDs on the '09, all 8 bytes long.
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

Thanks, I'll be looking at it in the day or two to see what I can find. I know the OBD2 port is different in some way to my Merc as with the same setup that worked in the Merc I got nothing in the Freelander so I'll need to figure out what the difference is or maybe hook in under the bonnet.
Like I said earlier, this might be simple stuff for those of you used to working with CAN but it's still all new to me.
I'm assuming the CAN ID's will be similar to BMW's as it's the M47 BMW engine in my car. If it was a K series petrol it would have a cable going to a throttle body instead of a TPS.
I need a bigger hammer!
prensel
Posts: 111
Joined: Mon Nov 25, 2019 1:36 pm
Location: Nijmegen (NL)
Contact:

Re: How to 'Sniff' the CANBUS?

Post by prensel »

What Freelander is this, the TD4 ?
I had one of these and all diagnostics went though K-line adapters like BMW had.
Even my BMW Carsoft did work on the Freelander in resetting faults.
So I wonder what data there is on the CANbus, does it even have CANbus btw ?
There's a big difference between the Freelander 1 and Freelander 2 versions.
The latter has OBD2 and CANbus, the Freeby 1 almost certainly not.

Altough the PLUG does look the same between OBD and OBD2, the signals are not.
= Th!nk PIV4 Collection, support, sales =
Alibro
Posts: 855
Joined: Sun Feb 23, 2020 9:24 am
Location: Northern Ireland
Has thanked: 268 times
Been thanked: 149 times
Contact:

Re: How to 'Sniff' the CANBUS?

Post by Alibro »

It's a TD4 Freelander 1, I managed to get the CAN data off it this evening and it looks like there isn't much going on.
Here is a photo of my laptop with CAN data collected from the ECU.
https://photos.app.goo.gl/1j9aZq5EAX7i3Ugs5
Attachments
IMG_20200707_213858946.jpg
I need a bigger hammer!
User avatar
mdrobnak
Posts: 692
Joined: Thu Mar 05, 2020 5:08 pm
Location: Colorado, United States
Has thanked: 1 time
Been thanked: 5 times

Re: How to 'Sniff' the CANBUS?

Post by mdrobnak »

LOL. Those are the IDs from the E46 era BMWs.
Post Reply