BMW M3 and M4 - The Icons
BMW Garage BMW Meets Register Today's Posts
home
Technical Sections Track / Autocross / Dragstrip / Driving Techniques

Post Reply
 
Thread Tools Search this Thread
      10-02-2022, 11:29 PM   #1
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

G8x CAN-bus Guide

this is a guide at using CAN-bus (not OBD-II) with G8x. disappointed BMW turned the M Laptimer into trash, i started looking at AIM SOLO2 DL for better track telemetry after using RaceChrono/TrackAddict/Harry's Laptimer with ODB-II dongles (OBDLink MX+, CX+, Kiwi3). honestly, the SOLO2 seems great. it's kinda expensive, but you really get a lot from it, both hardware and software wise. AIM's really only downside is there camera offerings are complete garbage.

if i had a dedicated track car with a roll cage, i probably would have just setup the AIM SOLO2 in a permanent way and moved on with my life. while trying to find a SOLO2 DL in stock with CAN-bus wiring harness, i decided to go over to the RaceChrono forums and see what is going on there. turns out, RaceChrono supports DIY devices over Bluetooth LE.

this is my adventure with CAN-bus and G8x platform using RaceChrono Pro iOS app, ESP32 adruino CAN-bus device, and hacking the CAN-bus data for the G8x platform. this is a work in progress, but i feel like i am at the point things are better than they ever were and its highly usable on the track.

spreadsheet of the CAN-bus data i have decoded so far: https://docs.google.com/spreadsheets...it?usp=sharing

materials/items used:
step 1: tapping into the PT-CAN bus

(PT stands for powertrain??)

one such connection is in the passenger side footwell. CAN-bus wires are always twisted pairs, making them easy to identify. i used posi-taps to tap into the existing wires without messing with the complex factory wiring harness. i used JST connector so i could easily connect/disconnect devices.

CAN-bus cabling color code:
CAN High -> Yellow/White
CAN Low -> Yellow/Black


with this basic connection i was able to see ~1750 can frames per second. basically every message broadcasted by PT-CAN.. so really barely 20 kbps of messages on a 500 kbps CAN-bus.














adding the wire + jst connector, making sure to twist the wires before covering them up for neat install








step 2: figuring CAN-bus data

car makers do not share this data usually, so i setup a Raspberry Pi 3/4 + PiCan2 hat so that i can use tools like candump and cansniff to log and analyze the CAN-bus data afterward.

this is a boring, time consuming step that i can go into more details if people wanted, but i assume no one cares really.

gist of what i have is (note i wasn't looking for all these, some just came out of looking for other data):
  • RPM 100hz
  • throttle 100hz
  • gear 50hz
  • longitudinal acceleration 50 hz
  • lateral acceleration 50 hz
  • yaw rate 50 hz
  • speed 50 hz
  • wheel speed (for each wheel) 50 hz
  • battery voltage 10 hz
  • air temperature 1 hz
  • steering angle 5 hz
  • coolant temperature ~5 hz
  • engine oil temperature ~5 hz
  • gearbox shift speed (S1,S2,S3) 10 hz

very close to having:
  • brake pressure front
  • brake pressure rear
i have identified the messages, still figuring out the actual units / data range.

missing:
  • intake temperature
  • fuel level

i have gear from 2 different pids, one of 50 hz, the other is 1 hz, but will send out updates instantly whenever the gear changes, so that is preferred, since it reduces the CAN-bus + bluetooth LE traffic without sacrificing any telemetry accuracy.

step 3: assembly ESP32 arduino device



I went with an Adafruit S3 feather ESP32 board, mainly because it had BLE 5.0, battery connector, USB-C for charging / serial port: https://www.adafruit.com/product/5477. I originally tried a Adafruit Huzzah32 ESP32 board, but the USB micro-B was annoying since GoPro and Racebox Mini are all USB-C. Also the Huzzah32 was an older ESP32 with Bluetooth 4.0, but even if i sent the entire CAN-bus of 25 kbps, i would still have plenty of bluetooth LE bandwidth in either 4.0 or 5.0.

ESP32 chip contains a CAN-bus chip, but you still need a transceiver, so went with the feather wing CAN-bus transceiver, so it all fit in a nice little package. i still have to 3d print a case for all this...

https://copperhilltech.com/can-bus-f...ing-for-esp32/

this did require some basic soldering. but because i got a feather ESP32 and feather wing can-bus transceiver, i just had to solder all PINs, even though the transceiver only uses 2. made for a solid build without a lot of guess work or arduino knowledge.









step 4: racechrono

RaceChrono is awesome. far and above TrackAddict and Harry's Laptimer IMHO and for the DIY crowd, the only track software that support this kind of thing.

in racechrono, once your ESP32 is up and running, you can go to settings and other devices and add a bluetooth LE, can-bus device.

then you can add channels and provide formulas converting any raw CAN-bus data into human readable values. i have included a column in that spreadsheet of the racechrono formulas i use.





step 5: source code for ESP32 device

i wrote my own customer CAN-bus driver stack to greatly optimize the read-only track telemetry case. looking to do the same for the Bluetooth LE driver as i think the arduino BLE drivers are what's bottlenecking this entire situation.

source code is on my github: https://github.com/joeroback/racechrono-canbus

full album:
View post on imgur.com

Last edited by dirtyfreebooter; 10-22-2022 at 11:30 AM.. Reason: added github link
Appreciate 18
DRLane3987.00
forcefed2547.50
pinky_chi172.00
beachBmmr1447.00
Nugget649.50
Ximian1914.50
moonluv8102492.50
playswcars3626.00
stormlv932.00
DM5PAV375.00
ngl118.00
3some!15.00
Ojala6.00
M4Tejas770.00
      10-02-2022, 11:30 PM   #2
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

Video of RaceChrono:

note that because of some bluetooth le performance issues, i have temporarily throttled some can frames:
  • 100 hz -> 33 hz (every 3rd message)
  • 50 hz -> 25 hz (every other message)
any messages at 25 hz or less, i deliver them as-is. no throttling.

just to tone down the amount of messages. honestly, i dont think i need RPM at 100 hz anyways.

you'll also notice in the video, i can still use my OBDLink MX+ with this setup, which allows me to get intake temperature and fuel level, 2 data values i am still searching for.


Last edited by dirtyfreebooter; 10-02-2022 at 11:35 PM..
Appreciate 5
DRLane3987.00
beachBmmr1447.00
ngl118.00
Jon H391.50
      10-03-2022, 09:59 AM   #3
flsupraguy
First Lieutenant
397
Rep
382
Posts

Drives: M5
Join Date: Mar 2018
Location: FL

iTrader: (0)

This is gold! Thanks!
Appreciate 1
      10-03-2022, 12:56 PM   #4
DRLane
Brigadier General
DRLane's Avatar
United_States
3987
Rep
3,408
Posts

Drives: E92 M3
Join Date: Oct 2018
Location: Colorado

iTrader: (21)

Garage List
2008 m3  [6.63]
Joe, you're badass! Decoding the CAN signals is incredible. I wish I has your technical knowledge and skills.

Hope the G8X community appreciates.
__________________
Not a Doctor, those are just my initials.
Appreciate 1
      10-04-2022, 03:36 PM   #5
pinky_chi
Private
United_States
172
Rep
99
Posts

Drives: G80 6mt
Join Date: Mar 2022
Location: SoCal

iTrader: (0)

Wow this is awesome. Thanks for sharing!
Appreciate 1
      10-15-2022, 03:50 PM   #6
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

updated post with link to github repo with ESP32 Arduino source code.

https://github.com/joeroback/racechrono-canbus

documentation is still a work in progress and i am waiting on a new feather wing board so that i can make an youtube video of assembling the hardware and doing the basic soldering.

i'll post another update here once i have more videos available over the next few months.
Appreciate 1
pinky_chi172.00
      10-22-2022, 11:30 AM   #7
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

Video on soldering the ESP32 pieces together:

Appreciate 0
      10-22-2022, 12:08 PM   #8
moonluv810
Captain
moonluv810's Avatar
No_Country
2493
Rep
616
Posts

Drives: 2017 BMW X3, 2018 BMW M3, 2022
Join Date: Sep 2017
Location: Erie, CO

iTrader: (0)

Much respect for the dedication and attention to details!
Appreciate 1
      11-11-2022, 09:02 PM   #9
BMWRacer523
Lieutenant Colonel
BMWRacer523's Avatar
2519
Rep
1,773
Posts

Drives: G80 M3 Competition xDrive
Join Date: Aug 2021
Location: NJ

iTrader: (0)

You went deep! Appreciate the effort.
Appreciate 1
      01-18-2023, 01:41 AM   #10
davidmct-M3
First Lieutenant
234
Rep
319
Posts

Drives: BMW 440i with MPSSK
Join Date: Mar 2022
Location: UK

iTrader: (0)

Great work. I am thinking about a little project to interrupt the throttle control so it goes idle only unless authorised as an antitheft mechanism. Complexity will probably be in authentication from phone to allow full power.
Appreciate 0
      05-27-2023, 08:02 AM   #11
ngl
Second Lieutenant
ngl's Avatar
118
Rep
208
Posts

Drives: BMW 228i
Join Date: Aug 2017
Location: Romania

iTrader: (0)

Amazing work.

There is another very useful piece of information in the PT-CAN that is yet to be discovered, the Oil Pressure. Being able to monitor it can help prevent an engine failure.
__________________
Quaife LSD | BC Racing Coilovers | H&R ARB | F8x LCA+TS | Wiechers Strutbar | Mishimoto CAI | Mishimoto Oil Cooler | Mishimoto Oil Catch Can | Mishimoto FMIC | VRSF DP | Masata TIC | Masata CP | DV+ | Custom Kline Exhaust | GTS Style Roll Cage | Sparco Evo QRT | Brey-Krause seat mounts | Schroth Profi 2 ASM 6p | 10" Android HU| xHP Stage3 | BM3 | RaceCapture Data Logger
Appreciate 0
      07-14-2023, 04:27 AM   #12
dmr
Private
Canada
63
Rep
72
Posts

Drives: G87
Join Date: Jul 2023
Location: Montreal

iTrader: (0)

Late to the party, but that's awesome work!

I am looking at creating my own decoder and documenting all codes on the BMW CAN bus (at least for my G87), happened on this thread.

Quick question for the OP: have you checked to see if CAN H and CAN L are broken out on the OBD II port? According to the spec, they should be available on pins 6 and 14, respectively.

Also, besides engine / performance data, have you also seen messages for the rest of the onboard systems (infotainment, door lock, lights, etc)? I would imagine you have chosen to ignore those for your project.

In my E46 days, I'd tapped into the CD changer twisted pair for all "ibus" messages and used steering wheel buttons to operate Paul Stroffegen's MP3 player (https://www.pjrc.com/mp3/index.html).

Here, I'm interested in unlocking some hidden options that are in BMW's firmware.

OP, if you're still working at the list of codes, I'd be happy to contribute.
Appreciate 0
      07-21-2023, 02:07 PM   #13
808AWD325xi
Ballin' out of control.
808AWD325xi's Avatar
No_Country
519
Rep
1,289
Posts

Drives: 2009 335i
Join Date: Jul 2007
Location: Moline, IL

iTrader: (0)

Quote:
Originally Posted by dirtyfreebooter View Post
[...]
missing:
  • intake temperature
  • fuel level
[...]
Cool project. SocketCAN rocks!

Fuel level might be 0x373 (Tank capacity/range).
__________________
Alpina B3 Flash/BMS OCC/ER CP/ETS 5/HKS BOV/M3 Control Arms
Appreciate 0
      07-31-2023, 05:17 PM   #14
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

Quote:
Originally Posted by discreet_mayor View Post
Late to the party, but that's awesome work!

I am looking at creating my own decoder and documenting all codes on the BMW CAN bus (at least for my G87), happened on this thread.

Quick question for the OP: have you checked to see if CAN H and CAN L are broken out on the OBD II port? According to the spec, they should be available on pins 6 and 14, respectively.

Also, besides engine / performance data, have you also seen messages for the rest of the onboard systems (infotainment, door lock, lights, etc)? I would imagine you have chosen to ignore those for your project.

In my E46 days, I'd tapped into the CD changer twisted pair for all "ibus" messages and used steering wheel buttons to operate Paul Stroffegen's MP3 player (https://www.pjrc.com/mp3/index.html).

Here, I'm interested in unlocking some hidden options that are in BMW's firmware.

OP, if you're still working at the list of codes, I'd be happy to contribute.
The CAN bus PINs on the OBD-II are still on restricted gateway and are still request/reply, adding latency. I have connected directory to the PT-CAN (Powertrain CAN bus) so its just broadcast messages to listen to. At the end of the day, Bluetooth LE stack in ESP32/IDF is the largest bottleneck.

OBD-II would be nice given the CAN + power is easily available, but the interface is just too slow for 10hz+ on multiple channels IMHO.

I have not looked for anything other than performance related messages, so i cannot say, but given this is specifically the PT-CAN, you might have to tap into a different CAN-bus network to see things like steering wheel buttons. But again, I have never attempted to look for those, so maybe.

I have that spreadsheet of codes, if you have codes decoded, i would love to hear about them, i could update the spreadsheet or add you as a editor, so you can add them yourself.
Appreciate 0
      07-31-2023, 05:18 PM   #15
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

Quote:
Originally Posted by 808AWD325xi View Post
Cool project. SocketCAN rocks!

Fuel level might be 0x373 (Tank capacity/range).
oh cool, i'll have to check out that PID and see. thanks for the tip
Appreciate 0
      08-01-2023, 04:03 PM   #16
808AWD325xi
Ballin' out of control.
808AWD325xi's Avatar
No_Country
519
Rep
1,289
Posts

Drives: 2009 335i
Join Date: Jul 2007
Location: Moline, IL

iTrader: (0)

Quote:
Originally Posted by dirtyfreebooter View Post
oh cool, i'll have to check out that PID and see. thanks for the tip
You're welcome! I hope it works. A lot of F/G CAN arbitration IDs are the same.
__________________
Alpina B3 Flash/BMS OCC/ER CP/ETS 5/HKS BOV/M3 Control Arms
Appreciate 0
      08-07-2023, 02:52 PM   #17
razorlab
New Member
14
Rep
11
Posts

Drives: 2020 Supra
Join Date: Dec 2022
Location: Mid-Hudson, NY

iTrader: (0)

dirtyfreebooter

I've been doing the same with my 2020 Supra. It looks like the G series M3/M4 share the same ID's!

I see you have some I don't, and I have some that you don't.

Check out my spreadsheet here: https://docs.google.com/spreadsheets...f=true&sd=true

Have you found anything new since posting this?
Appreciate 1
Nugget649.50
      10-02-2023, 12:49 AM   #18
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

Quote:
Originally Posted by razorlab View Post
dirtyfreebooter

I've been doing the same with my 2020 Supra. It looks like the G series M3/M4 share the same ID's!

I see you have some I don't, and I have some that you don't.

Check out my spreadsheet here: https://docs.google.com/spreadsheets...f=true&sd=true

Have you found anything new since posting this?
someone on github pointed me to someone working on G29/J29 and they had a few PIDs i was missing, so i updated the git repo for the ESP32, along with my spreadsheet for the RaceChrono formulas

https://github.com/joeroback/racechrono-canbus/issues/1

updated spreadsheet: https://docs.google.com/spreadsheets...it?usp=sharing

some of the new pids
  • engine torque
  • gearbox torque
  • accelerator pedal (slightly different than throttle)
  • battery voltage
  • fuel (used, lamp, range)
  • maximum rpm
  • ABS
  • ASC (automatic stability control)

one PID i still haven't found is gearbox temperature.

i will admit tho, i did get rid of my g80 and replaced with 992 GT3, so BMW stuff may not get updated unless requested on github, since i dont have a BMW to test with, tho i am planning on loading this onto a friend's m235iR in a few weeks for a track day. i think all of this should work fine on all F/G series and any toyotas sharing the same engines and ECUs
Appreciate 1
Ojala6.00
      10-19-2023, 08:47 PM   #19
truymenh
Registered
5
Rep
4
Posts

Drives: f80
Join Date: Jan 2020
Location: us

iTrader: (0)

can you share raw data from pt-can, i'm interesting in this project too
Appreciate 0
      03-08-2024, 03:59 PM   #20
dirtyfreebooter
Captain
dirtyfreebooter's Avatar
United_States
339
Rep
655
Posts

Drives: Vespa
Join Date: Nov 2010
Location: Boulder, CO

iTrader: (2)

Quote:
Originally Posted by truymenh View Post
can you share raw data from pt-can, i'm interesting in this project too
sorry, i don't have any raw data saved and i don't have g80 anymore.
Appreciate 0
Post Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -5. The time now is 04:20 AM.




g80
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
1Addicts.com, BIMMERPOST.com, E90Post.com, F30Post.com, M3Post.com, ZPost.com, 5Post.com, 6Post.com, 7Post.com, XBimmers.com logo and trademark are properties of BIMMERPOST