BMW G8x CAN-bus Guide

i wrote this guide over at bimmerpost:

gist here is that ESP32 is much much faster than nRF52 chips for CAN + BLE.

i have managed to get quite a list of decoded can bus values:
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 50 hz
brake pressure rear 50 hz
i have identified the messages, still figuring out the actual units / data range.

intake temperature
fuel level

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.

i wrote my own CAN-bus driver for ESP32 (interrupt based) and i can handle 2500+ messages / second with many many CPU cycles to spare. The bluetooth stack is trash and i am hoping to write my own limited BLE stack with basic advertising and notify/read/write support for RaceChrono, as i am not limited by BLE bandwidth or ESP32 CPU, but the ESP32 BLE drivers (i have tried quite a few)

still have to release my source code on github, but waiting until i get out to the track later this month to give it a proper run before releasing the code.

here is a video of all this working in RaceChrono:


  • I love it.

    PS. I'm planning to create a curated list of "RaceChrono DIY" GitHub projects, and your's will fit perfectly once you release the source code and parts list etc. This way people will find inspiration from other people's projects little bit easier.
  • Great work!
    Have you seen my project on GitHub? Would you be interested in contributing?
    I've already started to add ESP32 support, but haven't gone down the rabbit hole of driver stack optimization :)
  • Oh lol I see one of your projects is forked from mine.
    Looking forward to see your changes and pull requests!
  • i started with yours when i started with that nRF52 chip, but at the end of the day, when i switched to ESP32, i wrote it from scratch since your stuff was heavily nRF52 based, the CAN-bus chip was different, etc. since the ESP32 is dual-core, i wrote my own ESP32 CAN driver (interrupt based) that runs on one core, bluetooth stuff runs on the other using a freertos queue to pass data between the 2 cores. freertos queue data structure isn't the greatest, but its plenty fast enough and at this point, the BLE stack is the biggest bottleneck in my setup.

    the reason i wrote my own CAN-bus driver is that, one, most of the stuff out there is some real dumb programming in C/C++. sorry to say something like that, but man some of the most inefficient code i've ever seen, but for most applications that are not latency bound, probably works 99% of the time. two, i didn't care about implementing the entire can-bus protocol. so i optimized the read-only path, short circuiting asap, either at the hardware filter level, or in the interrupt service handler, not copying/reading data unless its a pid i care about.

    i would like to do similar for the BLE side, since that suffers from similar problems. and again, i would only implement the very basic stuff needed for racechrono, not try and fix the entire arduino/esp32 BLE stack.
  • Following this....great work so far!
  • @timurrrr Did you get the boards running? :smiley:
  • @MagnusThome No :neutral: I should have more time next week to tinker with it. Had basically back-to-back events for the last few weeks.
  • i have decided to put up my code on github a little early. still working on documentation. still waiting on a new feather wing board to arrive also so i can make a few youtube videos on putting it all together as well.

    so its definitely still a work in progress, but since i am at the point now where i can go to the track with what i got, i figured its good enough to get out there at this point.
  • @timurrrr Maybe post one of the extra boards to @dirtyfreebooter ? What do you think?

  • this is my current setup. i don’t have easy access to 12v and ground, so for me, i will be using a 3.7v lipo battery solution, as a ~800 mAh lipo battery lasts all day.

    i am going try and make videos for each part (downloading code from github, uploading to ESP32), hoping that it is enough to help someone that isn’t a computer person, but motivated enough to be able to do this themselves.

    the can-bus wires where easy to identify for my car, bmw g80, given the twisted pair, and internet forums. identifying a 12v power and ground in that complex wiring harness is much harder and i don’t have access to any wiring diagrams, so its just easier for me to use a solution that is battery powered, then risk messing up that harness or shorting the car in a damaging way.
  • Nice work @dirtyfreebooter! I decoded many of the same codes for my F82 M4, but alas have not delivered on my intent to document and share.

    I do, however have a transformation formulae for front and rear BP that seem to work well enough. I think that was one of the tougher transformations to figure out if I recall.

    Front BP: bitsTointLE(raw,40,16)*(-3.2808399)+104986.88

    Rear BP: bitsTointLE(raw,16,16)*(-3.2808399)+104986.88

    Here’s a short example of them in use: (and yes I have a lot of work to do on car control). Note, while presented on a video overlay is novel and somewhat interesting, I like plotting them against each other to see common places on a track that the rear brake kicks (presumably to correct understeer)—which I see A LOT, BTW, on exit of turn 10b at Road Atlanta

    Happy to further collaborate as the G8x and F8x platforms look to be very similar

  • @dirtyfreebooter Would you consider adding a link about my board in your thread on bimmerpost? With my boards auto shutoff it's a good fit for anyone who wants to connect to the OBD2 connector with its always on power.
Sign In or Register to comment.