My Raspberry Pi Project - OBD2 Data Recorder

My Raspberry Pi Project - OBD2 Data Recorder

Author
Discussion

Salgar

Original Poster:

3,283 posts

185 months

Thursday 8th November 2012
quotequote all
Hi Everyone,

I thought I'd write a little post about what I'm doing with my raspberry pi.

For anyone that doesn't know, the raspberry pi is a tiny cheap full computer : http://www.raspberrypi.org/faqs

I stared at it for ages wondering what I could use it for. Then I decided I could use it as a data recorder for my motorbike, as it would fit under the seat of my Street Triple.

So I went ahead and started researching bits of it.
First I bought an USB -> OBD2 cable: http://www.ebay.co.uk/itm/280593613318?ssPageName=...
The cable is a cable which supports many different versions of the OBD2 port standard, so I was sure it could probably speak to my bike.

The raspberry pi itself takes power from a micro USB connection. I wanted to give it power from my bike battery, but obviously if I left it there it would just drain the battery while I wasn't riding the bike. Ideally, it would be connected in to the key on/off, but that would take a lot more work and a lot more hurting the bike wiring than I'd be willing to do.

So the next thing I bought was this bike power cable, which inlines a switch and a fuse and ends in a female USB port (Although you can get any kind of power or usb connection on the end): http://www.ebay.co.uk/itm/380434044136?ssPageName=...

This will allow me to switch off the pi at the end of a ride, hopefully I don't forget to do this, this is an area for improvement in the future.

The last thing I bought was a green case for the raspberry pi, to go with my green triumph (see below) smile

<programming talk>

The next thing was writing the code, I found a python library which had stopped development in 2009 called pyobd. I used this as a base for what I wanted to do, I found a few bugs in the code and generally it wasn't written very generically, it was written to be used by one GUI app that came with it. I didn't want a GUI app, obviously, under my seat. So I forked their repository and started working on making it more like what I wanted it for.
My repository is here: https://github.com/roflson/pyobd

</programming talk>

Last night I managed to get most of it working together on my laptop. I'm just waiting for the case, then I'm going to put it all together and go for a long ride smile Here is the log file I produced last night.

logfile said:
18:49:57:167,rpm,1516,
18:49:57:684,speed,0.0,MPH
18:49:58:201,throttle_pos,0.78431372549,%
18:49:58:717,rpm,1464,
18:49:59:233,speed,0.0,MPH
18:49:59:750,throttle_pos,0.392156862745,%
18:50:00:266,rpm,1594,
18:50:00:783,speed,0.0,MPH
18:50:01:299,throttle_pos,8.23529411765,%
18:50:01:818,rpm,3478,
18:50:02:338,speed,0.0,MPH
18:50:02:855,throttle_pos,0.392156862745,%
After I've got it all working and ironed out any bugs. the next thing I want to do is get a GPS receiver in the other USB port and log location too.

Using all of this I should be able to write code which works as a lap timer for any track, or track all my journeys on my bike and have pretty google maps/earth style maps which use the 'height' of the line as a speed marker and possible the colour as acceleration.

The other thing I want to do is sync it all with a GoPro that I'm getting soon and produce some good videos which have F1 style 'throttle position, rpm and speed' dials in the corner.

Obviously, I never go over the speed limit, so I'll have to think about that before releasing any of this kind of data into the public.






Edited by Salgar on Thursday 8th November 15:32

Salgar

Original Poster:

3,283 posts

185 months

Monday 10th December 2012
quotequote all
Hi, brief update here

So I went on holiday just after my first update for a couple of weeks. Then I started a new job, so haven't had much time to play with this.

While on holiday I bought myself a gopro 3 though, which is fun, and I finally got to use it yesterday. I hooked up the Pi under the seat of my bike, and the gopro too and off I went for a ride.

Amazingly, everything worked!

I now have a video of some of my ride, as well as a big log file full of data.

I did some research into programs that can convert log files into digital displays on the video (speedo, rpm, throttle), and found RaceRender 2, as well as Dashware. They both appear to be pretty good, Dashware is a little more powerful, but is actually very difficult to use if you don't have associated GPS data. And RaceRender is a lot easier to use, and cheaper, but you can't customize the dials as much.

The problem with all of this has boiled down to the fact that I have a very old laptop, and my OH has a newer mac, but still not very powerful. The Video that the new gopro produces is such a high bitrate that I can't even play it on my laptop!

I did some experimenting though and managed to produce a video with the dials, although the speedo is slightly out of sync with the video. Would be easily correctable, except the preview video plays with such lag that I can't see what's happening.

However it all works! I took the video yesterday with the gopro attached to my bike with the sucker mount and it caused a lot of shaking, so I'm going to mount it on my helmet next time.

Hopefully I'll have an example video up soon, perhaps my journey to work which is short and has good sunrises and people cutting me up (and not much chance of me speeding accidentally).

Will take some more pictures soon too.

Salgar

Original Poster:

3,283 posts

185 months

Monday 10th December 2012
quotequote all
vdubbin said:
That's proper awesome! Especially for work on the code, that's where I'd fall over.
Did you have to put any sort of shock/vibration protection into the case?
I don't right now, but there are no moving parts and there's very limited space under the seat of my bike so it's wedged quite well.

Salgar

Original Poster:

3,283 posts

185 months

Monday 10th December 2012
quotequote all
OlberJ said:
It's cool and i'll be watching to see how it turns out for you.

The Raspberry Pi is a bit stone soup though is it not? How much have you spent on peripherals if you don't mind me asking?
Not much, the most expensive bit was the power cable/fuse/switch for my bike which was about £25, but if I was feeling slightly more full of effort I'm sure it could be made for more like £5

The OBD2 cable was £15ish

I did have to buy the case/SD card too which were about £10 each.

Salgar

Original Poster:

3,283 posts

185 months

Monday 10th December 2012
quotequote all
Mr Happy said:
I was thinking about doing the same kind of thing, however instead of using a raspberry pi, I was going to use an arduino with a couple of different shields.

Never actually thought about running the Pi... how did you go about piping video into it? Is it through USB or did you re-encode the video with the data overlay after the ride? (ie is it recorded live with the info overlay or post-produced)
I didn't connect the video to the pi, unfortunately gopros don't have this option really.

I record the video and the logging separately and then overlay the data afterwards.
The program I tried out yesterday, RaceRender, has syncing options but mostly you just do it by sight/sound to try and match up the start of the video and the start of the logging data, but it's not too hard. I also want to actually edit the video after i've added the overlay because one long continuous ride is fairly dull.

Salgar

Original Poster:

3,283 posts

185 months

Monday 10th December 2012
quotequote all
nsi said:
Hi,

I also plan a similar project - except instead of just writing a log file, I want live read outs. I.e. I'd hook up the OBD2 socket to the Pi, and then the Pi to a screen. I'd then need something to read the OBD and "publish" the variables I guess, then something else to grab those and make some dials/read outs.

I also want to hook up some more sensors to it too, so I can have micro switches which can detect the gear lever position, and also brake/clutch application and also brake temperature. These things are not in my OBD2 feed, so I'll need to write some program to read and publish those. Then have the display program look at these and also the parameters published by the OBD2 software.

Does this sound possible? Any keywords I should be googling for, since as a total Linux noob I don't know what to look for.

Cheers
Sorry for the stupid 4 post reply everyone smile

This is interesting. There are actually bluetooth OBD2 readers already, which can hook up to an iPad/Android app to give you live data if that's what you want. However if you want to do it the DIY route, then sure, anything's possible. For the OBD2 stuff you can certainly just use a similar system to what I have. How you'll turn the live textual data into graphical dials etc is up to you, there probably isn't anything like this right now. You can certainly show a bunch of numbers on the screen though to start with. As for the other sensors, the raspberry pi has GPIO pins, i.e. analog pins which can be read. Your electronics knowledge will probably have to be better than mine though to use those to turn sensor readings into numbers or using the other USB port somehow.

One of my biggest problems at the moment is actually the available space under my seat, each of the cables/connectors I have seemed to have come with 4m of cable, and I can barely get my seat closed without a very precise setup. And by very precise I mean lots of pushing and hoping.

As for where to start, it's hard to say without knowing how much you know. Can you program at all? If so, learn some python, it has the best support on the pi, and the OBD2 and GPIO on the pi has python support. If you have any questions about how to set things up, how to test things, how to get things running on startup, feel free to give me a PM.

Salgar

Original Poster:

3,283 posts

185 months

Monday 10th December 2012
quotequote all
A 3-axis/something for lean angles is a great idea. eharding, what hardware do you have? does the i2c connect to the gpio or is it translated to usb via a virtual com port or something?

Roverspeed - I've been thinking about just that, it can't be that hard to determine what the gear should be based on the RPM and the speed. Although I imagine it might get a bit dodgy at low revs, although should still be quite possible. Might lookup the maths for that and write that up myself.

As for the C vs Python decision, my day job is writing c++ all day, but I would much prefer to do this in Python, and I don't really even know python very well. I agree that it's possible that a few things might not be fast enough, but the baud rate of the OBD2 cable is 38400 or something, which I'm sure python can keep up with. It's also much easier to change things at a whim, and there are also many ready made libraries for things like this. The Pi is definitely not the fastest, but when that becomes a problem i'll address it.

The next step is to buy a USB GPS receiver to get a mini map going possibly. Also I think I'll incorporate the gear calculations.