Login | Register
SearchMy Stuff
My ProfileMy PreferencesMy Mates RSS Feed
2
Reply to Topic
Author Discussion

Salgar

Original Poster:

3,005 posts

70 months

[news] 
Thursday 8th November 2012 quote quote 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

rxtx

4,772 posts

96 months

[news] 
Thursday 8th November 2012 quote quote all
Nice. I assume the data is coming through serially hence why you log each item separately? Might be easier when looking at the data afterwards (since there are only milliseconds between logs) to log each set with one timestamp.

mojitomax

1,670 posts

78 months

[news] 
Thursday 8th November 2012 quote quote all
Very cool. I still can't get mine to run openelec properly but I think it might be a hardware problem. I've ordered a new one to check. Doh!

Well done

13aines

1,344 posts

35 months

[news] 
Friday 9th November 2012 quote quote all
Mega cool!

mattzmith

34 posts

56 months

[news] 
Wednesday 14th November 2012 quote quote all
that is seriously cool! (if you have slightly gimpy engineering tendencies)

watching this topic with interest...
Advertisement

Salgar

Original Poster:

3,005 posts

70 months

[news] 
Monday 10th December 2012 quote quote 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.

vdubbin

1,978 posts

83 months

[news] 
Monday 10th December 2012 quote quote all
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?

OlberJ

13,964 posts

119 months

[news] 
Monday 10th December 2012 quote quote all
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?

Mr Happy

4,480 posts

106 months

[news] 
Monday 10th December 2012 quote quote all
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)

nsi

316 posts

84 months

[news] 
Monday 10th December 2012 quote quote all
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

Salgar

Original Poster:

3,005 posts

70 months

[news] 
Monday 10th December 2012 quote quote 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,005 posts

70 months

[news] 
Monday 10th December 2012 quote quote 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,005 posts

70 months

[news] 
Monday 10th December 2012 quote quote 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,005 posts

70 months

[news] 
Monday 10th December 2012 quote quote 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.

driver67

545 posts

51 months

[news] 
Monday 10th December 2012 quote quote all

Have a look at the torque obd app for android.

Does all of what your looking at and will help you diagnose the obd codes for your rasperry pi !

julian64

10,447 posts

140 months

[news] 
Monday 10th December 2012 quote quote all
driver67 said:
Have a look at the torque obd app for android.

Does all of what your looking at and will help you diagnose the obd codes for your rasperry pi !
Yep I have a cheap chinese £20 dongle plugged into my BMW and the torque opd app just shoes the dials on its screen. Will even let you record and do 0-60 times automatically.


nsi

316 posts

84 months

[news] 
Monday 10th December 2012 quote quote all
Salgar said:
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.
Hi, thanks for replying. There's an android app called Torque ( http://torque-bhp.com/wiki/Main_Page ) which does a lot of stuff from ODB. However it doesn't have the facility for the additional sensors I want. (Gear position, clutch/brake and brake temps. I'll have to install my own sensors for those.)

On the Pi I assume there must be some software which can take a number generated by one program, and then display it?


I'm not entirely sure what I mean by "digits". I sort of assume that I can create global variables and then have some bits of software which will 'write to them' (one being the OBD2 software, the other being my own stuff which will pull from GPIO pins) and then these global variables will be 'looked at' by another program which will then handle all the drawing to screen.

Regards my current programming skill; I'm pretty good with VBA because I use it a lot in my job. So I'm familiar with some of the basics of programming logic. I also did a maths degree, so I can learn these things fairly easily. However I've never used Linux before the Pi, and never used Python either. I've been trying to educate myself by watching videos on a youtube channel by this guy: http://www.youtube.com/user/RaspberryPiBeginners

I'd say his videos are about my level for the time being; i.e. I kind of need to be told what to type in to get things setup, but once the program is in and installed I can get a grip of an idea on how to customise it.

Sorry to hear about your size constraints, I'm going to install in a car - so I'm more flexible with sensors and stuff.

I'll appreciate any assistance on this! Cheers biggrin

julian64

10,447 posts

140 months

[news] 
Monday 10th December 2012 quote quote all
nsi said:
Hi, thanks for replying. There's an android app called Torque ( http://torque-bhp.com/wiki/Main_Page ) which does a lot of stuff from ODB. However it doesn't have the facility for the additional sensors I want. (Gear position, clutch/brake and brake temps. I'll have to install my own sensors for those.)

On the Pi I assume there must be some software which can take a number generated by one program, and then display it?


I'm not entirely sure what I mean by "digits". I sort of assume that I can create global variables and then have some bits of software which will 'write to them' (one being the OBD2 software, the other being my own stuff which will pull from GPIO pins) and then these global variables will be 'looked at' by another program which will then handle all the drawing to screen.

Regards my current programming skill; I'm pretty good with VBA because I use it a lot in my job. So I'm familiar with some of the basics of programming logic. I also did a maths degree, so I can learn these things fairly easily. However I've never used Linux before the Pi, and never used Python either. I've been trying to educate myself by watching videos on a youtube channel by this guy: http://www.youtube.com/user/RaspberryPiBeginners

I'd say his videos are about my level for the time being; i.e. I kind of need to be told what to type in to get things setup, but once the program is in and installed I can get a grip of an idea on how to customise it.

Sorry to hear about your size constraints, I'm going to install in a car - so I'm more flexible with sensors and stuff.

I'll appreciate any assistance on this! Cheers biggrin
Probably going to cause a stir here but I would say stop with python, and switch to c on the pi.

Reason being that although python is native to the pi linux system, c is gaining a lot of ground with the pi because it is orders of magnitude faster.

I find that phython is quicker to code especially for a VBA user, but once you get c it won't take you long.

Look on the pi site and you'll see someone has done a comparison, with sampling to show just how much faster c is than python in terms of operating the gpio ports.

If you are some time in the future going to try inserting the digits on the video c will have much less limitation than python.

nsi

316 posts

84 months

[news] 
Monday 10th December 2012 quote quote all
Hi Julian, thanks for the comment. I won't argue against C being faster (I'll take that as given) but because you say "I find that phython is quicker to code especially for a VBA user," I think that I'll be best off Keeping It Simple Stupid for the time being, lol!

Unlike the OP I've no grand plans to overlay this with video yet. I first of all want to get it on screen and written to a log file. I'll then plan to do as he's done and consider an overlay done afterwards on a PC.

Oh, and for the OP I just thought of something which could make doing the overlays easier... how about a GPIO activated LED which you can place in the camera shot? This would be lit up by your software and it's lighting logged to the log file with a time stamp. You could then use it's appearance on the video image to sync to that time stamp? Similar idea to the old "clapper board" they used to use to sync the video and sound for movies.

roverspeed

556 posts

82 months

[news] 
Monday 10th December 2012 quote quote all
Interesting project indeed.

Just hopefully to save you a sensor or 2. but you shouldn't need an extra sensor for gear position.

I used another Android program that uses OBDII coding and you insert the Gear ratio's and final drive ratio into it and it calculates what gear you are in by the engine RPM and speed. (AlapHDcorder i think its called)

I am pretty sure you could do the clutch in some other roundabout way through the ODB info as well. Maybe load? When i am engine braking engine load is at 0, however in neutral/coasting engine load is at 17% (required for idling of course) So surely parameters could be set by that?
2
Reply to Topic