marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Honda CAN bus Pi Project

Fri Aug 10, 2018 5:27 pm

Hello everyone. I'm fairly new to the Raspberry Pi, my first small electronics project. I'm also an engineering student. This project is mostly centered around Canbus. And hopefully putting my project up here will help others and help me when I hit a road block.

So first a quick overview of my project. To help get experience for fun and also to help with a future job, I'm doing this project. I have a RaspberryPi 3 with a PiCan2 board hooked up to my 2015 Honda Civic Si thru the OBDII port to access the Fast Can. Eventually I'll get the PiCanDuo board to access both the Fast Can and the Body Can, but that's later. I want to access some things like when Vtec is on, RPM is in a certain range, load of the engine is above a certain amount, etc. I want to then run my own program that will actuate an exhaust cutout. So when "vtec just kicked in yo" lol the exhaust will become a straight thru exhaust, but only during high load, high rpm situations. There's a product out there that already does this. I think it's called Vtec Climax but it's several hundred dollars and I want to do it myself, as I'm sure you all can understand.

So here is the progress I've made. I got a Pi 3 and the PiCan2 board hooked up. I'm waiting on a Mini Black Hat Hack3r to split the GPIOs so I can use the unused ones on a breadboard for prototyping (additional switches I have planned, LEDs for when the system is working, etc.). I setup the Pi and finally connected it to the internet to update it. To give context to why that last part was difficult for me, I'm running the Pi entirely thru command line issues from my Macbook connected thru an ethernet cable. The reason is because that how this project will run, without a screen or keyboard. Once the project is done, it will sit inside the car and operate all by itself, only needing to connect to my laptop for occasional update. At least this is my hope, lol. So after that I found out the PiCan2 board has an LED circuit. I downloaded wiringPi's code for GPIO use and got the LED to work via command lines. I then wrote a program that did the same thing, turn on and off the LED. Some of this may seem simple to you, but it is my first time doing something like this and is huge steps for me. But trying to mimic what I've learning in school and my internship of taking a big software project and breaking it down to little projects.

The stage I'm at is now the Canbus part. I am using the linux-can-utils software (from Volkswagen I think, haha). I have started to decode some of the Can packets, but it is difficult. The problem I have right now is with the cansniffer.c program. I noticed several other characters after the 8 bits of each can packet. Sometimes they are just "........" sometimes they change rapidly and with no perceivable pattern. What is this data???? or is it just garbage to be ignored???? Does anybody know?

Thanks for all your help in advanced. I hope this project is of interest to some people.
Last edited by marcellatwin on Sun Aug 26, 2018 6:11 pm, edited 1 time in total.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Wed Aug 15, 2018 4:53 am

Hello again. So there's been some updates. First I answered the question from my last post about the random characters after the CanBus data. I emailed Craig Smith, a "CanBus hacker" who has a YouTube channel and a book about CanBus hacking where I learned how to use the cansniffer program a little bit more. He replied that it was ASCII data and not really of much use unless you are looking for a VIN or something.

So with his advice and other research I've done 2 decoding sessions with my car. One just sitting in the garage by myself trying to figure the program out. Key thing was I wasn't moving. The other was about 2 hours on the highway with someone else driving. This helped a lot as I could say, "go to 5th, now floor it, now 6th, left off the throttle, clutch in, clutch out, etc." We could only do some much with traffic. The plan is the do another session at night or early morning on Saturday where there won't be any traffic on desolate county roads. But I'm also going to try to find if there is anybody that has already decoded my particular car's CanBus, cause this might take a while to decode everything I need.

In the mean time, I've combed thru the candump and cansniffer programs to try to write my own program to take each Can data packet and try to at least display what I've decoded so far, like throttle position and speed. I'll post that code later once I've added a little more structure to it.

If anyone has suggustions as to decoding or know where CanBus data has already been decoded please let me know.

Below is the data I've decoded so far.
Screen Shot 2018-08-14 at 21.44.28.png
Screen Shot 2018-08-14 at 21.44.28.png (217.43 KiB) Viewed 3557 times
Last edited by marcellatwin on Sun Aug 26, 2018 6:11 pm, edited 1 time in total.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Wed Aug 15, 2018 7:30 pm

For those of you who are car people, this is my motivation:

https://www.youtube.com/watch?v=cMGyUm-4v8E

That video was the review of the Vtec Climax that I'm replicating with some differences. As stated before, this item is too expensive (over $350) and I want the experience of coding and building this myself.

I've fine tune the code for the displaying of certain canbus data (translated) onto the terminal, like my own primitive dashboard. But I still can't figure out how to get the address off the socket for the canbus data coming in. Anybody have any ideas?

Here is the forum post on that specific issue: viewtopic.php?f=91&t=220451&p=1352963#p1352963

Soon I should get my switches and Mini Black Hat Hack3r so I can split the GPIOs and have a prototyping breadboard AND PiCan2 board hooked up at the same time. They are shipping from England to the USA so it might take a few more days (shipped a week ago). Pictures will definitely follow.
Last edited by marcellatwin on Sun Aug 26, 2018 6:11 pm, edited 1 time in total.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Thu Aug 16, 2018 4:27 pm

It finally arrived! The Mini Black Hat Hack3r. Now I can finally connect the breadboard AND the PiCan2 board to the same GPIO on the Pi. Here is some pics showing my new set up:
39294986_1665401383588389_2110536913390665728_n.jpg
39294986_1665401383588389_2110536913390665728_n.jpg (236.29 KiB) Viewed 3493 times
This is the whole setup. It went from being just 2 boards screwed together, nice and compact, but now... This will be interesting to test with in a moving car haha.
39248909_243361189839962_8584667969957658624_n.jpg
39248909_243361189839962_8584667969957658624_n.jpg (185.84 KiB) Viewed 3493 times
This is the PiCan2 board on top of the Black Hat. The holes didn't line up so I could only put in the screws right over the pin connections to keep them in. I'll need to figure something out for when it goes in the car more permanently.
39287205_465000094000187_3433186334305419264_n.jpg
39287205_465000094000187_3433186334305419264_n.jpg (247.45 KiB) Viewed 3493 times
This is the breadboard and the 3 LEDs I'm testing that will eventually go in the car. Yellow for powered on but not ready. Essentially the Pi's boot up time and initialization of my program. Green for system active, program running correctly. Red for exhaust active, cutout valve open. Yes I know it is not the prettiest breadboard set up, but I'm new to this and I only have 10k resistors or 220, so I had to stack them. But the good thing is I was able to turn on and off all the LEDs on the first try, which is a victory for me, lol.
Last edited by marcellatwin on Sun Aug 26, 2018 6:11 pm, edited 1 time in total.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Sun Aug 26, 2018 6:10 pm

So for an update. I finally got my own program to connect to the CAN bus and started reading in just the CAN IDs that I know, convert them to decimals by combining the bytes together, scale them to numbers we understand, and output them to the screen to see if I decoded them correctly. For the most part it is working. I'm having some issues with my "dash" program (cause it is like my own dashboard) flickering as it is running in a while loop. I'm working on trying to figure out the "curses" library to see if that can help me by printing out the stuff that doesn't change first (like "Throttle: ", "RPM: ") and only refresh the numbers from the CAN packets. I'll let you know once that is working and show the code.

As for the CANs I decoded. Most of them were not spot on. The throttle was a completely different scaling than I thought. When at FULL throttle, the bytes read FF CB. So that is 65,483 and if that is 100% throttle, I divide by 654 or 655 to get 100. But when we tested it, FULL throttle only read out as 74ish. Only once I changed the scaling to 492 did I get FULL throttle to read 100. Weird and will require further looking into. RPMs is another story. I think I had the wrong bytes, but once I decided to try different bytes and it suddenly worked, without scaling. Again have to look into. Same thing with speed. I might not be shifting the byte right when combining them, but as of right now, I do have Throttle, RPMs, and Speedo read out, all working. I've decoded a lot more since last time: water/oil temp (not sure which one is which), fuel mileage (MPG), fuel tank level, etc. I'll post those IDs once I verify them again on another driving session. With school starting tomorrow it might be a while before the next update, but the first weeks of school are usually pretty laxed so I'll try to keep on it.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Fri Aug 31, 2018 3:31 pm

Another update. Made a ton of progress, at least in my opinion. I finally got rid of the flickering issue. I really researched the curses.h library and found what I needed. Now the program displays more than twice the data and doesn't flickers a smidge. I've also found what was wrong with my scaling. Really studpid mistake. I was referencing the CAN packet's data array with (1-8) rather than (0-7). Idiot mistake lol. So I was looking at the byte to the right of EVERYTHING. Once I fixed that it the data looked a lot cleaner and scaling made sense. I've also decoded a lot more. Things like the AC compressor, turn signals, seat belt, etc. Here is everything I've decoded so far and some of the questions that are still unanswered.
Capture.JPG
Capture.JPG (226.22 KiB) Viewed 3385 times
Capture2.JPG
Capture2.JPG (150.25 KiB) Viewed 3384 times
Vtec is one of the last CAN IDs I need to start making the mechanical part of this project.

chodyjones
Posts: 1
Joined: Mon Dec 17, 2018 4:08 pm

Re: Honda CAN bus Pi Project

Mon Dec 17, 2018 4:25 pm

Super interesting. I like the Idea. And have a 2012 si. And I have an idea scraping CANBUS OBD data as well. My plan is to scrape this data and hook the PI to the Backup Camera Feed to IMID. I would like to toggle this by when the IMID is on the Wallpaper screen. I'm not sure if a CAN-BUS msg is broadcast when this happens. I have a Pi but have not CANBUS board. On the display, I would like to build out gauges that display coolant temp and other data. I hate there is no coolant temp gauge in these cars and only dummy lights.

sconner5525
Posts: 2
Joined: Sat Mar 30, 2019 6:09 pm

Re: Honda CAN bus Pi Project

Sat Mar 30, 2019 6:52 pm

This is a good start on decoding the Honda.

In frame 324 [8]:

byte 1 is the ECT (engine coolant temperature). Subtract 40 to get the temperature in C.
byte 2 is the IAT (intake air temperature). Subtract 40 to get the temperature in C.

quicksilvertypec
Posts: 1
Joined: Sun Mar 31, 2019 9:02 pm

Re: Honda CAN bus Pi Project

Sun Mar 31, 2019 9:04 pm

marcellatwin wrote:
Fri Aug 31, 2018 3:31 pm
Another update. Made a ton of progress, at least in my opinion. I finally got rid of the flickering issue. I really researched the curses.h library and found what I needed. Now the program displays more than twice the data and doesn't flickers a smidge. I've also found what was wrong with my scaling. Really studpid mistake. I was referencing the CAN packet's data array with (1-8) rather than (0-7). Idiot mistake lol. So I was looking at the byte to the right of EVERYTHING. Once I fixed that it the data looked a lot cleaner and scaling made sense. I've also decoded a lot more. Things like the AC compressor, turn signals, seat belt, etc. Here is everything I've decoded so far and some of the questions that are still unanswered.


Vtec is one of the last CAN IDs I need to start making the mechanical part of this project.
Cool project! I want to do something similar with my 2012 Civic Si (micro controller with safties based on throttle, AFR, boost, etc.).

Where you able to find more CAN IDs? That is the time-consuming part. I appreciate you sharing with the community!

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Tue Apr 02, 2019 5:52 am

Hello everyone. I apologize for not updating sooner. I have entered into my final year of my engineering degree and as such my senior capstone project. It has taken over my life and I have not had any time to work on this at all. Good thing thou is one of the classes I'm taking is Microprocessors + Lab, which we learn about embedded systems and programming them. It has really helped me figure somethings out on this project, but I have just not had time to code anything new up and test it. But once the summer hits and I get settled in my summer internship (Volvo in North Carolina) I will start to work on this again.
chodyjones wrote: Super interesting. I like the Idea. And have a 2012 si. And I have an idea scraping CANBUS OBD data as well. My plan is to scrape this data and hook the PI to the Backup Camera Feed to IMID. I would like to toggle this by when the IMID is on the Wallpaper screen. I'm not sure if a CAN-BUS msg is broadcast when this happens. I have a Pi but have not CANBUS board. On the display, I would like to build out gauges that display coolant temp and other data. I hate there is no coolant temp gauge in these cars and only dummy lights.
My guess is that screen has some CAN messages on the Low speed CAN. I've been working on the HighCAN and when I can afford it, I'm going to get the PiCanDuo board which allows 2 CAN signals simultaneously. But the LowCAN is where a lot of the infotainment stuff is, so where you can toggle the iMID from the steering wheel. Also when you go into reverse a CAN message is sent on the HighCAN. I totally agree about the temps. Hopefully that helps. Let me know how your project comes along.
sconner5525 wrote: This is a good start on decoding the Honda.

In frame 324 [8]:

byte 1 is the ECT (engine coolant temperature). Subtract 40 to get the temperature in C.
byte 2 is the IAT (intake air temperature). Subtract 40 to get the temperature in C.
Oh ok, thanks! That really helps and makes sense. Why the 40 degree offset, do you know? Also do you know if there is a oil temp at all? Or do they just use the water temp and figure the oil temp is directly proportional. You wouldn't happen to know the VTEC activation CAN frame?????
quicksilvertypec wrote: Cool project! I want to do something similar with my 2012 Civic Si (micro controller with safties based on throttle, AFR, boost, etc.).

Where you able to find more CAN IDs? That is the time-consuming part. I appreciate you sharing with the community!
I haven't worked on it much lately as I mentioned above. I swear I will update you guys as soon as I get some new ones down. I'm mostly working on a few software things, like a filter for some of the data to derive acceleration trends (doing something similar in class) and screen buffers for when I eventually get a screen for custom gauges. And absolutely! Maybe I'm too much an academic at the moment but sharing this is the only way other people like me are going to learn. Keeping to yourself is a little greedy to me. Hell, Tesla shared all of their patents cause they know it will take more then just them to solve problems. So I say share it.

Thanks everyone for the help and I will keep you guys updated soon.

User avatar
rpdom
Posts: 14173
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Honda CAN bus Pi Project

Tue Apr 02, 2019 6:56 am

marcellatwin wrote:
sconner5525 wrote: This is a good start on decoding the Honda.

In frame 324 [8]:

byte 1 is the ECT (engine coolant temperature). Subtract 40 to get the temperature in C.
byte 2 is the IAT (intake air temperature). Subtract 40 to get the temperature in C.
Oh ok, thanks! That really helps and makes sense. Why the 40 degree offset, do you know?
As they are a byte, I suspect they are returning an unsigned value between 0 and 255. Subtract 40 from that will give you a temperature range of -40°C to +215°C.
Signature is on holiday.

sconner5525
Posts: 2
Joined: Sat Mar 30, 2019 6:09 pm

Re: Honda CAN bus Pi Project

Sun Apr 21, 2019 6:53 pm

I am not sure why the -40 offset is used with ECT and IAT but I have seen this with other manufacturers as well (Dodge, GM, Ford, Nissan/Infiniti, Toyota). They probably use the same temperature sensor.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Wed May 22, 2019 4:12 am

rpdom wrote: As they are a byte, I suspect they are returning an unsigned value between 0 and 255. Subtract 40 from that will give you a temperature range of -40°C to +215°C.
That makes perfect sense. Thanks. I'll add that to the code.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Wed May 22, 2019 4:20 am

So a bit of an update.

I FOUND IT!!! I FINALLY F&^%ING FOUND IT!!!

The VTEC activation CAN frame!!! The CAN ID is 0x320 and it's byte 1 (second byte). The first hex digit of that byte is 0 when VTEC is OFF (RPMS < 5,000), then changes to 4 when VTEC is ON (> 5,000).

Man it was difficult. So I should get to bed so I'm awake during work. There's a few more updates but I will get to those later. I will update you guys soon. Good thing is Volvo has asked me to do a project for them that is extremely similar to what I'm doing here. So I should be able to make a LOT of progress on other aspects of this project.

Update will be coming soon.

marcellatwin
Posts: 32
Joined: Sat Jan 27, 2018 6:41 pm
Location: USA

Re: Honda CAN bus Pi Project

Wed May 29, 2019 5:48 pm

So I finally have time to update.

So yes, as per my last post, I found the Vtec CAN message. I found it by having my wife video tape the cansniffer program and I drove between 4500 and 5200 rpm in 3rd gear for about 15 miles saying out loud ON, OFF, ON, OFF each time we went in and out of vtec. I then watched the video several times looking over every line (CAN ID) and every byte. After about a dozen times I finally found it. Since I already had the code ready and just commented out, it was quick to add it in. Since I don't have the Honda with me at my internship I can't test anything until September. But I can continue doing somethings like cleaning up the code, creating a digital dash, and start researching the mechanical part of the active exhaust.

I thought that I would test with my VW Jetta I have with me since the base code for the CAN is from the VW Research Group. But once I plugged into the Jetta I found they have a different system and you have to send messages to get any CAN data when reading from the OBDII port, which I am. I would need to splice into wires before the "OBD Gateway", which I'm not going to for this car.

So if I haven't mentioned before I think pneumatic will be the best way for the mechanical active exhaust. It's quick acting, cheap to make, and powerful compared to hydraulics or electric actuators, especially with respect to costs. So I'm going to start researching air tanks and compressors and valves. And I already have the Pi that can control all the values for start up, shut down, and maintenance like draining the air tank.

So other updates... I've updated to Stretch finally. There was an issue initially which caused the linker to error out and I couldn't compile for several days. But with the help of the people on this forum I was able to figure it out; purge the compiler and reinstall it. I've also got the SSH streamlined with auto login via scripts. I've also learned about scripts and have a few scripts for compiling since the compiling commands are getting pretty long, library includes, warnings, optimizations, etc. I've also finally figured out how to view the Desktop of the Pi over VNC. And also got FileZilla to SFTP for transferring files back and forth. All of this has really sped up my workflow. Especially compared to logging in manually, copying files to a USB, and transfer from Pi to computer. It took about 2 minutes for each transfer. (Yeah I know, total Noob, but I'm learning by myself) Now I have it linked to Sublime Text 3 and can edit and save and it transfers to the Pi in about 2 seconds. Talk about an efficiency gain. I've also finally made my program multi-threaded, with one collecting data and the other displaying the text on the terminal. After doing that though I'm getting an occasional slow down every second or so. Not sure what's going on, maybe I can put it up on here with a video.

I've started to work on understanding an OpenVG library to make a digital dash. All I've got so far is a black window with Hello World text and a blue circle (a sample program provided with the library that I just edited the size of). This is the new part of the project. I have to figure out how to have the screen show data that is constantly changing. So I need to research and figure out how screen buffers work to get a smooth display.

Any suggestions, questions, comments, thoughts, feedback, etc. on the project so far??? Thanks for listening.

Return to “Other projects”