S2000 Racing and Competition The S2000 on the track and Solo circuit. Some of the fastest S2000 drivers in the world call this forum home.

Reading from CAN bus with OBDLinx MX and RaceChrono

Thread Tools
 
Old 05-06-2022, 11:16 PM
  #1  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default Reading from CAN bus with OBDLinx MX and RaceChrono

Update

You can now using an OBDLinx MX or MX+ to read CAN-bus data into RaceChrono Pro. Use this to add brake pressure and steering angle to the data already available through an OBD reader.

Notes:
  • Under the vehicle profile in RC, you will need to set the Default protocol to 6 (11 bit, 500kbaud), at least for 2006-2007 cars. For 2008+ it might be either this or protocol 7 (29 bit).
  • You'll get poor or no results trying to enable the OBDLinx as both an OBD reader and CAN-bus reader at the same time. So you'll want to disable it under the OBD-II devices list, and add it under Other devices as a CAN-bus reader.
  • Since you won't have it logging as an OBD reader, you will lose the RPM, throttle position, speed, and coolant temperature readings from there. Fortunately, these can be re-implemented via the CAN-bus, and should be faster/more accurate that way too.
Once you've added the OBDLinx MX or MX+ as a CAN-bus reader, open the vehicle profile, set the default protocol to 6, and then at the bottom you can add can-bus channels. Each of these will require a PID and an equation to translate between the raw data and the human readable format you want. See posts 10 and 14 below for what to enter there:
https://www.s2ki.com/forums/s2000-ra.../#post24931244
https://www.s2ki.com/forums/s2000-ra.../#post24931898

Ultimately you can do something like this. Speed=yellow, throttle pink, brake green, steering angle blue:



Got an upshift, some heel-toe, trail braking, catch a little slide... Not sure how much I'll use the steering trace, but having brake pressure to go along with throttle is really nice to analyze what you're doing (and what you're doing wrong!)

Original post
----

Recently RaceChrono Pro has added an option to add an OBDLink MX or MX+ bluetooth OBD2 reader as a CAN bus reader, and theoretically to read custom data from the CAN bus this way. I'm thinking this could be a poor man's way to add data like steering angle and brake pressure without adding any additional hardware beyond bluetooth GPS and OBD2 reader.

However, I'm completely new to trying to understand the CAN bus, so haven't gotten very far! I found some posts here and elsewhere from @Gernby that listed the data available via several PIDs (below), but first I need to get it to actually receive data. I'm using the android app 'serial bluetooth terminal' to try and test; am able to connect to the OBDlink MX there; I can send ATZ (reset), ATSPx (set protocol to x, ie 1-9), and ATMA (monitor all).

Now, from what I've read, the AP2 CAN bus protocol is ISO 15765-4 CAN (29 bit ID, 500kbaud), which I believe should be ATSP7. However, when I set ATSP7 and then ATMA I don't get any output. I do get output with ATSP6, but it's full of data error messages along with the data.

6 is the same as 7 except for being 11 bit instead of 29 bit, so I think maybe the extra bits are causing the data errors, but then I'm not sure why I don't get anything from ATMA when choosing protocol 7. Also if I try ATSP0 (automatic protocol) and then ATMA it just gets stuck on 'Searching" for the protocol, seemingly forever.

I wonder if I need to change my buffer settings in some way, or if there's an initialization command I need to send, but I'm pretty over my head at this point.

FWIW I also tried skipping the terminal and just interrogating the PIDs that are supposed to contain info using racechrono, but likewise there I wasn't able to get any live data out of it.

Maybe someone who has a clue here can point me in the right direction, or if you have an OBDlink MX, give it a try yourself? Sure would be cool to get this working, if it's indeed possible!

Originally Posted by Gernby
Most of the traffic on the CAN Bus seems encrypted, but not all of it. I spent a TON of time trying to figure out what the non-encrypted data was, which required some custom software. It's been a while since I looked at it, so I'm not sure if the spreadsheet I'm looking at is the latest / most accurate, but here is a summary:

PID Data Byte
106 D4= Misfire? D5 = Starter D7 = Brake Pressure
166 D1 = Fuel Status? D8 = Bitwise Data
170 D1 = Throttle pedal
198 D1 & D2 = Steering Wheel D3 = Lateral Accellerometer
300 D1 = ECT D2 = Ambient Temp or IAT D5 & D6 = RPM D7 = Bitwise stats D8 = Fuel Trims?
448 D1 & D2 = Speed D3 & D4 = Speed 2 D5 & D6 = Speed 3 D7 & D8 = Speed 4
Note: elsewhere I see 106 D3 listed as the brake pressure byte, so planning to check both if I can ever get this working.
The following users liked this post:
SlowTeg (07-14-2022)
Old 05-12-2022, 07:46 AM
  #2  

 
_valtsu_'s Avatar
 
Join Date: Nov 2016
Location: Finland
Posts: 191
Received 21 Likes on 19 Posts
Default

I might be able to help. My S2000 didn't have originally Can-Bus, but now it has thanks to standalone ecu. I have general knowledge about obd2 and Can-Bus. I have also used Racechrono long time.
Can you provide some links where did you find information about S2000 Can-bus protocol and where did you find the commands that you are using to communicate with OBDLink mx using the serial bluetooth terminal?
I'm afraid that you are confusing Can-Bus and OBD2. They are not the same thing. What you are trying to do is read Hondas own Can-Bus messages, not the OBD2 messages.
To receive messages you need to get bus speed and the ID bit length right.

Here is some good information about the subject:
https://racechrono.com/forum/discuss...s-data-logging
Old 05-12-2022, 01:52 PM
  #3  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default

Originally Posted by _valtsu_
I might be able to help. My S2000 didn't have originally Can-Bus, but now it has thanks to standalone ecu. I have general knowledge about obd2 and Can-Bus. I have also used Racechrono long time.
Can you provide some links where did you find information about S2000 Can-bus protocol and where did you find the commands that you are using to communicate with OBDLink mx using the serial bluetooth terminal?
I'm afraid that you are confusing Can-Bus and OBD2. They are not the same thing. What you are trying to do is read Hondas own Can-Bus messages, not the OBD2 messages.
To receive messages you need to get bus speed and the ID bit length right.

Here is some good information about the subject:
https://racechrono.com/forum/discuss...s-data-logging
Yes, I understand that OBD and CAN bus are not the same thing, but that messages on the car's CAN bus can be read through the OBD connection.

The commands I'm using are just standard ELM327 commands, eg from here: https://www.sparkfun.com/datasheets/...T_Commands.pdf

I gathered data from a number of different sources. Gernby posted in a few different threads, like this one:
https://www.s2ki.com/forums/s2000-ta.../#post23684976
There's also this thread that discusses reading steering angle etc.
https://direct.forum.autosportlabs.c...ic.php?p=28602

So that's where the PIDs are from. As far as the protocol, I can't find the original source that told me it was 29-bit, 500 kbaud, but here's one from imstimpy that also has some stuff to say about headers and targets:
https://forum.autosportlabs.com/viewtopic.php?t=4671

I don't have a full enough understanding yet to understand what he's saying there though.

I'm not able to get anything just setting the protocol to 7 (which is 29-bit, 500kbaud) and monitoring all data. I do get data setting the protocol to 6 (11-bit), but I don't know that it's CAN data.



Old 05-12-2022, 02:04 PM
  #4  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default

RaceChrono allows you to specify the protocol, the default header to use, and any initialization commands to be sent. You can then define PIDs to read from, and an equation to apply to them (to perform bitmasking, scaling, etc.) That second part should be easy enough once I can get it to actually read live data, but just setting it to protocol 7 isn't doing anything, so I assume either the default header is wrong or other initialization commands are needed.
Old 05-13-2022, 06:55 AM
  #5  

 
_valtsu_'s Avatar
 
Join Date: Nov 2016
Location: Finland
Posts: 191
Received 21 Likes on 19 Posts
Default

Ok. So the ATSP7 command 7 is not right. That is an OBD2 protocol. On Racechrono I found the protocol setting from the OBD2 settings.
Basically OBD communication works like this: The obd reader sends a message thru Can-Bus "I wan't to know what is TPS%" and then the ECU send the message to tell what is TPS%. All the OBD communication works like this.
Now you just wan't to read Can-Bus message stream. You don't want to send anything to the bus.
So I'm pretty sure you don't need to setup any protocol. Those are only for OBD.

You need to setup on Racechrono the OBDLink as Can-Bus reader and then setup specific channels and pids.
Old 05-13-2022, 11:47 AM
  #6  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default

Originally Posted by _valtsu_
Ok. So the ATSP7 command 7 is not right. That is an OBD2 protocol. On Racechrono I found the protocol setting from the OBD2 settings.
Basically OBD communication works like this: The obd reader sends a message thru Can-Bus "I wan't to know what is TPS%" and then the ECU send the message to tell what is TPS%. All the OBD communication works like this.
Now you just wan't to read Can-Bus message stream. You don't want to send anything to the bus.
So I'm pretty sure you don't need to setup any protocol. Those are only for OBD.

You need to setup on Racechrono the OBDLink as Can-Bus reader and then setup specific channels and pids.
Take a look at the CAN bus options in Racechrono. You'll need to add a CAN reader first (can use an OBDLink if you have one), and then go into the vehicle settings. You do need to specify a protocol there. (Or use the default to auto-detect.) I've tried auto-detecting, as well as setting it to 7, but am not getting any live data in testing with RC. (It also gives the option to change the default message header, and to send initialization commands.) That's why I took a step back to try to see what I could get by directly using a serial reader. There, I don't get any data stream by setting the protocol to 7, and if I set it to 0/auto it just hangs on 'Searching'. If I set it to 6, I do get a stream of data, but I can't pick out any of the IDs that have been identified for things like steering angle or brake pressure, so I'm not sure it's the right data stream.
Old 05-14-2022, 09:48 AM
  #7  

 
_valtsu_'s Avatar
 
Join Date: Nov 2016
Location: Finland
Posts: 191
Received 21 Likes on 19 Posts
Default

Originally Posted by Nate Tempest
Take a look at the CAN bus options in Racechrono. You'll need to add a CAN reader first (can use an OBDLink if you have one), and then go into the vehicle settings. You do need to specify a protocol there. (Or use the default to auto-detect.) I've tried auto-detecting, as well as setting it to 7, but am not getting any live data in testing with RC. (It also gives the option to change the default message header, and to send initialization commands.) That's why I took a step back to try to see what I could get by directly using a serial reader. There, I don't get any data stream by setting the protocol to 7, and if I set it to 0/auto it just hangs on 'Searching'. If I set it to 6, I do get a stream of data, but I can't pick out any of the IDs that have been identified for things like steering angle or brake pressure, so I'm not sure it's the right data stream.
I did take a look, but I don't have OBDLink, so I can't test that. Just to be sure did you do it like this? :
Settings -> Add other device -> OBDLink LX/MX/MX+ Bluetooth (CAN-Bus) or Wifi device
Then go into vehicle settings:
Under CAN-Bus channels: Add channel

When I do that same using DIY device I don't have to specify any protocol.
Old 05-14-2022, 01:31 PM
  #8  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default

Originally Posted by _valtsu_
I did take a look, but I don't have OBDLink, so I can't test that. Just to be sure did you do it like this? :
Settings -> Add other device -> OBDLink LX/MX/MX+ Bluetooth (CAN-Bus) or Wifi device
Then go into vehicle settings:
Under CAN-Bus channels: Add channel

When I do that same using DIY device I don't have to specify any protocol.
Ah, yes, I've done that. And then I can turn on 'test connection' in that section and it connects to the obdlink. But when I open any of the channels I added and select live data, I get nothing, just all zeros.

You're right that the protocol settings are under the obd2 section, not the canbus section, but my understanding was that they affect both. (Those settings are there even if I don't have an obd2 reader configured, just the obdlink as a canbus reader.)
Old 05-14-2022, 03:41 PM
  #9  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default

Got it figured out! I thought I'd tried this before, but ultimately I just needed to set the protocol in RaceChrono to 6 (11-bit). Once I did that, I was able to get live data. So far I've configured and tested steering angle and brake pressure. (I'm not sure of the scaling on the brake pressure, so I just set it to brake percentage, and scaled it from 0 to as hard as I'd ever reasonably press the pedal.)

Going to see what else I can add now, then will share the config.
Old 05-14-2022, 10:23 PM
  #10  

Thread Starter
 
Nate Tempest's Avatar
 
Join Date: Jun 2017
Posts: 524
Received 70 Likes on 55 Posts
Default

Alright, so I've got the following channels configured:

Accelerator position:
PID: 170
Equation: A*100/255
Byte 0, scaled to 100%

Brake position:
PID: 106
Equation: max((bytestouint(raw,5,2) - 57448), 0)/4.0
Bytes 5-6. Scaled this one experimentally. At zero brake pressure it reads 57448, so subtracting that amount brings it to 0. Pressing the pedal harder than I ever would on track brings it up to about 400 from there, so I'm just dividing by 4 to get a 0-100% scale. (Using 4.0 causes it to return a float, so we get a resolution of 0.25%.)

Engine RPM
PID: 300
Equation: bytestouint(raw,4,2)
Bytes 4-5 give the RPM directly.

Steering angle
PID: 198
Equation: bytestoint(raw,0,2) / 10.0
Bytes 0-1, divided by 10 gives the steering angle in degrees. (Using 10.0 instead of 10 causes the result to be a float rather than an int, for more precision).

Now, these ones I know I've got the right PIDs, but I'm less sure about the definitions and scaling:

Coolant temperature
PID: 300
Equation: A
The raw value in byte 0, given by 'A' I think is the temperature in °F
For degrees C,
Equation: (A-32)*5.0/9

See below

Intake air temperature (I think. Possibly ambient temperature.)
PID: 300
Equation: B
Byte 1. The raw data appears to be in degrees F.

See below
Lateral acceleration
PID: 198
Equation: bytestoint(raw,2,1)/10
Fairly sure those are the right bytes, but I'm not sure about the scaling here. 10 appears reasonable, but once I get some actual data traces I need to compare it to my phone data to check. Could be in m/s² (9.8066) or ft/s² (32.174).
Edit: the live data seems to be extremely noisy. Unless I've got something wrong beyond just the scaling, I can't see it being useful for analysis.

Speed
PID: 448
Equation:
((bytestouint(raw,0,2)/64)*40+float(bytestouint(raw,6,2))/255*40)/3.6

PID 448 has four speed representations at various resolutions, in bytes 0-1, 2-3, 4-5, and 6-7. According to @imstimpy they max out at 160kph, 120kph, 80kph, and 40kph respectively. (Edit: Actually, I bet it's actually fractions of 100mph, since that would be a round number, and is very close to 160kph.) So they have progressively greater resolution. I don't really understand why it would be done this way given that there's no value to the middle two then - you can always use the most course reading to determine the range, and then the finest one for the precise number. And because the top one maxes out at 160, there's no way to differentiate between speeds 0-160 and 160-320.

Anyway, at least up to 160kph, the equation above should give the speed in m/s, which racechrono will then convert to kph or mph depending on your units setting. (And even above that, you can still compare it to your GPS speed if you think there's an issue with the latter, just mentally adding 160kph.)
Still need to test this one as well.
Edit: see below

Thoughts

So, this is pretty cool! Even just having the steering angle and brake pressure in addition to existing data will be a huge help when analyzing laps. Definitely worth setting up for anyone who already has an OBDLink MX. Depending on how the lateral accelerometer data from the car looks, that might eliminate the value of a separate precision accelerometer too. So it looks like this is a pretty decent option for a budget data logging setup. If you don't have any equipment yet, you'd need the OBDLinx MX+ ($140; the non-plus version isn't sold anymore), a bluetooth GPS - probably the Qstarz BL-818GT ($160), and RaceChrono Pro ($25). For not a whole lot more though, you could also look at a Racecapture Track for $450, plus CircuitStorm (or SoloStorm if you're doing autocross).

Both options would allow for future expansion analog inputs. With the racecapture it would mean adding one of their AnalogX modules ($150). With the RaceChrono setup, you could look at a RaceDAC (190 Euros).
The following users liked this post:
bdo (07-04-2022)


Quick Reply: Reading from CAN bus with OBDLinx MX and RaceChrono



All times are GMT -8. The time now is 09:46 AM.