Monday, June 23, 2014

Raspberry Pi Carputer project

I have been thinking about this for a while before, but I haven't done anything because I haven't had a project car. I'm planing on buying it soon so preparing this project in advance seems like a good idea and it will provide me a lot of fun time with tech and software issues.



So the idea is to make a Carputer or CarPC out of Raspberry Pi (RPi) and its options are going to be as the ones placed in new cars by their manufacturers.


Here is my scheme for this:




So here are first steps of this scheme realization:


This is not the scheme that is going to be put into the final project, it's just for testing and installing of the system. Since the CarPc is planned, it can only be realized in a car, but for that I'll need power adapter and many soldering under the dash. All in good time.
While testing phase is going on I use Samsung S3 charger and HDMI output to (for the moment) my 42" TV. 

This is a similar project done well: http://timekiller.org/projects/carpc/

Monitor:
Finaly, the TFT I bought from Ebay arrived today (31.7.2014.) and of course, I went testing the whole thing. It works great, though the screen could be better quality, but what can you expect for less then 40$. Anyway, this TFT is only for testing, when project car arrives and this all proves to work as planned, I'll find a better screen and maybe even a touchscreen.




Powering:
Here is scheme of how I plan to power RPi and USB Hub... I should consider having more power going to hub since it's going to power most of the stuff that are going to work with RPi...



TFT being device made to work on 12V (which is voltage from car battery) while I'm testing it I need to make sure I power it from 12V source. Luckily I had old computer PSU (power supply unit) which I use for this purpose.

Of course this PSU needs to be custom wired to ITSELF so it would produce 12V output. But if you try this, do A bit more research about which wires GO together cause I'm not sure if any yellow, black or green wire can be considered, I understood it from a video (which I can't find now) that it is important which wires you wire (solder). It's not just any yellow to any yellow.
As much as I know, the green wire and one black wire, both from PSU, need to come together (solder or wire them) in order for this to work. Although I saw some other videos where they explain it simpler- like any wire goes together as long as they are the same color. As I said, do a research about this so you won't TOAST yourself.



I was testing this LED Rocker switch on simple USB port to see if it works. I connected it to VCC cable and it works just great.



By using this switch I can turn RPi on/off independently of whether the engine is running or not.
Wiring diagram so the LED can actually work:



OS and Applications:
After trying out many different distros for RPi (Rasbmc, Xbian, OpenElec, Raspbian etc.) at the end I decided to stick with Raspbian for now on and see how it will handle all needs for this whole project to work. For now on solutions are found for most of the issues.
I really hate LXDE, so I replaced it with Openbox since I have most experience with that environment.
Setting up Openbox for RPi:
http://engineerdemos.blogspot.com/2012/07/install-window-manager-openbox-and.html
Here is pretty much how it looks for now. Shortcuts of basic applications are placed in tint2 panel, conky is showing cpu, ram and disk usage. Background is of course the header of my webpage www.xw0rks.tk.
Shortcuts on tint2 panels are (from left to right) File manager (#pcmanfm for now), Midori web browser, Navit GPS navigation software, Network manager (wpa_gui) and shotdown button which is self-explanatory.



Custom GUI:
Finally, I have managed to get some time to check all those tutorials for Python and make my own simple GUI for all those applications I neen.
Here is how it looks like:

Police button runs shell script that use GPIO pins of RPI to control the red and blue blinking lights that are going to be installed on the car. Just in case you were wodering. When that project is done, video of it will be in this blog.
 
As I update this app I'll update next source code:

#RPi_CPC GUI
from Tkinter import *
from subprocess import call
import subprocess as sub
import os
import sys

#create the window
root = Tk()
root.configure(background="black")
root.attributes('-fullscreen', True)

#MENU FUNCTIONS
def shutdown():
 call (["poweroff"]);
def reboot():
 call (["reboot"]);
def exit():
 quit();

#MENU###################
menu = Menu(root, bg="black", fg='chartreuse')
root.config(menu=menu)
subMenu = Menu(menu, bg="black", fg='red')
menu.add_cascade(label="Options", menu=subMenu)
subMenu.add_separator()
subMenu.add_command(label="POWER OFF", font="Courier 15 bold ", command=shutdown)
subMenu.add_separator()
subMenu.add_separator()
subMenu.add_command(label="RESTART RPI!", font="Courier 15 bold", command=reboot)
subMenu.add_separator()
subMenu.add_separator()
subMenu.add_command(label="EXIT", font="Courier 15 bold ", command=exit)
subMenu.add_separator()
########################

#functions
def popo():
 call (["./police.sh"]);
def gps():
 call (["navit"]);
def music():
 os.system('lxterminal -e mocp &');
def web():
 call (["netsurf"]);
def video():
 call (["vlc"]);
def blueman():
 call (["blueman-browse"]);
def wifi():
 call (["wpa_gui"]);
site = Label(root, text="RPi_CPC system - www.Xw0rkS.tk", font="Helvetica 12 bold italic", bg="black", fg="chartreuse")
site.grid(columnspan=2)

# frames
frame = Frame(root, bg='black')
frame.grid()

#buttons
police = Button(frame, text="Police", bg='black', fg='chartreuse', font="Halvetica 20 bold italic", command=popo, height=3, width=14)
gps = Button(frame, text="GPS", bg='black', fg='chartreuse', font="Helvetica 20 bold italic", command=gps, height=3, width=14)
music = Button(frame, text="Music", bg='black', fg="chartreuse", font="Helvetica 20 bold italic", command=music, height=3, width=14)
web = Button(frame, text="Web", bg='black', fg="chartreuse", font="Helvetica 20 bold italic", command=web, height=3, width=14)
video = Button(frame, text="Video", bg='black', fg="chartreuse", font="Helvetica 20 bold italic", command=video, height=3, width=14)
bt = Button(frame, text="Bluetooth", bg='black', fg="chartreuse", font="Helvetica 20 bold italic", command=blueman, height=3, width=14)
wifi = Button(frame, text="WiFi", bg='black', fg="chartreuse", font="Helvetica 20 bold italic", command=wifi, height=3, width=14)

#OBD
speed = Label(frame, text="KM/H =", font="Helvetica 20 bold italic", bg="black", fg="chartreuse", height=2, width=10)
rpm = Label(frame, text="RPM =", font="Helvetica 20 bold italic", bg="black", fg="chartreuse", height=2, width=10)

#temp = Label(frame, text="0 *c", font="Helvetica 20 bold italic", bg="black", fg="chartreuse", height=2, width=10)
police.grid(row=1, column=3)
gps.grid(row=1, column=0)
music.grid(row=2, column=0)
web.grid(row=1, column=1)
video.grid(row=2, column=1)
#speed.grid(row=1, column=2)
police.grid(row=1, column=2)
bt.grid(row=3, column = 0)
wifi.grid(row=3, column=1)
rpm.grid(row=2, column=2)
speed.grid(row=3, column=2)

### Status Bar ###
#status = Label(root, height=2, width=50, font="Courier 10 bold", bg="black", fg="chartreuse")
#wid = status.winfo_id()
#os.system('xterm -into %d +sb -fg chartreuse &' % wid)
#status.grid(row=4, column=0, columnspan=4)

#end
root.mainloop()



KEYBOARD SHORTCUTS:
This is how I added keyboard shortcuts to Openbox rc.xml file for them to work properly and to make all this system easier to use (because I don't have touch screen, at least I should be able run programs with one push of a button).
Location: /home/pi/.configure/openbox/rc.xml
This is how keyboard shortcuts should be set in rc.xml file.

Shortcuts:
Super + e = Midori web browser
F7 = Terminal (lxterminal)
F2 = Run dialog (gmrun)
F9 = killing omxplayer process... - Now this needs a bit of explanation. Since Raspbian is not supposed to stream media like movies in this case, no regular video player will work properly. When videos are played in vlc, totem, even the mplayer they would lag so much it would not be possible to watch any of them. #omxplayer is made specially for RPi systems and all videos played in that program work without problem, but there is an issue; when you use it over desktop environment, like #openbox in this case, you lose control of it when it plays anything and it won't stop till the end of the video (cause it's meant to be used over CLI otherwise without any graphical interface) thus I made this simple keyboard shortcut so I can stop video from playing anytime I want.


PANEL:
This is code for tint2rc file which configures tint2 panel you see on the bottom.
Location: /home/pi/.configure/tint2/tint2rc


# Tint2 config file by Kexolino

# Background definitions

# ID 1
rounded = 0
border_width = 1
background_color = #000000 70
border_color = #ffffff 80

# ID 2
rounded = 0
border_width = 0
background_color = #000000 100
border_color = #ffffff 100

# Panel
panel_monitor = all
panel_position =  bottom center horizontal
panel_size = 100% 30
panel_margin = 0 0
panel_padding = 0 0 10
panel_dock = 0
wm_menu = 1
panel_layer = normal
panel_background_id = 1

# Panel Autohide
autohide = 0
autohide_show_timeout = 0.2
autohide_hide_timeout = 1
autohide_height = 0
strut_policy = follow_size

# Taskbar
taskbar_mode = single_desktop
taskbar_padding = 0 0 10
taskbar_background_id = 0
taskbar_active_background_id = 0

# Tasks
urgent_nb_of_blink = 20
task_icon = 1
task_text = 1
task_centered = 0
task_maximum_size = 200 32
task_padding = 10 4
task_background_id = 0
task_active_background_id = 2
task_urgent_background_id = 0
task_iconified_background_id = 0

# Task Icons
task_icon_asb = 100 0 0
task_active_icon_asb = 100 0 0
task_urgent_icon_asb = 100 0 0
task_iconified_icon_asb = 100 0 0

# Fonts
task_font = Droid Sans 9
task_font_color = #ffffff 100
task_active_font_color = #FFFFFF 100
task_urgent_font_color = #ff0000 100
task_iconified_font_color = #999999 70
font_shadow = 0

# System Tray
systray = 1
systray_padding = 0 6 15
systray_sort = left2right
systray_background_id = 0
systray_icon_size = 16
systray_icon_asb = 100 0 0

# Clock
time1_format = %H:%M
time1_font = Droid Sans 9
clock_font_color = #FFFFFF 100
clock_tooltip =
clock_padding = 10 6
clock_background_id = 2
clock_lclick_command = gsimplecal
time1_timezone =
time2_timezone =
clock_tooltip_timezone =

# Tooltips
tooltip = 0
tooltip_padding = 2 2
tooltip_show_timeout = 0.0
tooltip_hide_timeout = 0.0
tooltip_background_id = 2
tooltip_font = Droid Sans 9
tooltip_font_color = #FFFFFF 100

# Mouse
mouse_middle = none
mouse_right = close
mouse_scroll_up = toggle
mouse_scroll_down = iconify

# Battery
battery = 0
battery_low_status = 20
battery_low_cmd = notify-send "battery low"
battery_hide = 96
bat1_font = Liberation Mono 8
bat2_font = Liberation Mono 8
battery_font_color = #B5B5B5 100
battery_padding = 2 0
battery_background_id = 0

# End of config


CONKY (System monitoring):
It is great thing to have system monitoring software on screen all the time so you would know what is going on with your RPi. My plan for conky isn't actually to display info only from RPi but later also from OBD2 scanner, so I won't have to run any additional applications to see data from my car. In short, Conky will display all data possible both from RPi and Car's ECU.
This is how my .conkyrc file looks like right now.
Next image might not exactly represent previous .conkyrc file:

Here is how my autostart.sh file does the job now...


For this to work script for Openbox needs to be created in configuration folder.
Script is:
~/.config/openbox/autostart.sh

Here is how script looks like:

omxplayer /home/pi/Videos/animation.mp4
nitrogen --set-zoom /home/pi/wallpaper.jpg
tint2 &
conky &

First omxplayer is playing the animation, the second line sets wallpaper, the third loads that tint2 panel and the fourth loads conky.



MUSIC:

Choosing music player wasn't hard. Application mocp is music player working with command line interface (CLI) so it's light as it can be.
It can be installed with: sudo apt-get install moc (read moc not mocp).
But it was a bit harder launching it like other applications from panel and keyboard shortcuts.

To launch it from tint2 panel you need to make your own icon launcher since it's cli application.

This is mocp.desktop file that I made so it would have working shortcut that launches it, place it on desktop (that is /home/pi/Desktop). But first you'll have to make a tiny script which is actually the application that the shortcut will launch before you continue doing anythinig with that shortcut file.

Script looks simply like this: lxterminal -e mocp

Save it as mocp.sh also in Desktop location.

Now you will see from the tint2rc script which has configuration for shortcuts that it has already line which points out to shortcut file:

launcher_item_app = /home/pi/Desktop/mocp.desktop

That is how to make shortcut on tint2 panel. Now this is how to make keyboard shortcut.

Add next lines to rc.xml file located at /home/pi/.config/openbox/ next to other keybind sections (as you see I start mocp with Ctrl+F11 key combo)


<keybind key="C-F11">
<action name="Execute">
<startupnotify>
<enabled>true</enabled>
<name>Music_player</name>
</startupnotify>
<command>sh /home/pi/Desktop/mocp.sh</command>
</action>
</keybind>



Here is my config file for mocp that you need to place in /home/pi/.moc/ folder in order for it to work and after that you can make your own configuration with it, like setting up themes, default location of your music folder etc.

If you get "Fatal_error: Configuration file not secured". Just go to ~/.moc folder > Right click on config file> Premissions > and change all of the options to "Only owner".


Here is how player looks like in my setup:


OnBoard Diagnostics (OBD):
I've lookup internet for some opensource obd scanners for linux and I ran into PyOBD, but I prefer python application made by Paul Bartek.
His application has neat interface and it's simple. For now it will do and if I ever manage to get better in python I might make some changes by myself.
Right now, the only change I made is logo :)
If you want to check his work on this follow him on Youtube.



I asked and he respond:




NETWORK CONNECTION:
First we need to enable Wifi as it is going to be only connection to outside world since this will be CarPc... here is HTG_tutorial.

GPS:
Here are some useful pages for installing GPS software on linux:
http://fsckin.com/2008/04/06/review-four-linux-gps-packages/
http://ubuntuguide.org/wiki/Ubuntu_Oneiric_Maps_and_GPS
http://www.gpsdrive.de/
http://blog.retep.org/2012/06/18/getting-gps-to-work-on-a-raspberry-pi/


Making Navit work on RPi:
http://www.raspberrypi.org/forums/viewtopic.php?f=41&t=57978
Something like this looks perfect for this project. It's free (Open source) GPS navigation software GpsDrive.

I will try to work with gpsdrive after I get everything right, so for now Navit will do the work. Here is navit map of my town in light and dark color scheme: 


USB HUB
So Hub wasn't just that simple story, there are compatible ones and have to be powered out side of RPi... So that makes job with lighter power source bit more complicated. Here are lists of compatible hubs for RPi: http://elinux.org/RPi_Powered_USB_Hubs
Anyway, I got this Self powered 10 port USB Hub from ebay and it works just fine:


This is how I managed to cool overclocked RPi. It's 12v cooler from some old graphic card that I found in my stash of old hardware parts. Since it's 12v I simply connected it to same wires of PSU as I did the monitor, as it can be seen on this photo.
I use those aluminium plates which seal wholes of computer case rear side where PCI devices are coming out when they are installed, I bend it to fit the case and glue cooler to one of them. It works perfectly. It's keeping temperature of RPi CPU bellow 30 degrees Celsius most of the time while it works. 

TESTING
I finally did a test of all this for the first time. The thing that made me do this now is that I've managed to make my old bluetooth dongle work on USB hub, new OBD2 dongle arrived so I was so eager to test that obd gui from Paul Bartek.
The thing that disapointed me was the fact that USB hub and RPi couldn't be powered from same wires, each needs to have their own power wires.
First driving test in Opel Vectra 2.0 DTi, not much of RPi work could be seen here, but I was running that OBD monitoring tool by +Paul Bartek


Enjoy the ride (day and night testing)
 

New stuff came from ebay that will help me continue my project. The part I'm referring to right now is the Vesa Case for RPi.
It looks nice as it is but I wanted to add some carbon flavor to it. So I "carbonized" the bottom part and it looks like this now:
Next thing was placing all the stuff in the BMW. Since I'm going to change all the scheme latter (on spring) I'm not going to post how project looks at the moment, I'm just posting the photo of how the screen blended on Bemmers dash.
I'm still not sure about the spot for the screen, but right now, this will do just fine.
Couldn't managed to place monitor anywhere better then here and like this:
So the mess at the moment is on this level:


Next thing I hope mini wireless keyboard is going to make this less complicated for the eyes and nerves. Will need to do some soldering of which I will probably post a video.

Raspberry PI switch turned out great:

Installation of Rear view camera and setting up TFT screen with RPi:





Whole installation is getting closer to ending. Lots of work still left to do:


Installing Amplifier:


Here is some testing of OpenElec and wireless keyboard in my E34

New Raspberry Pi 2 arrived and is replacing the B version:

Today is 10.Jan.2016.
Long time passed since I haven't updated this post.
This is what happened during this time.
Raspberry Pi 2 was damaged when I was trying to find proper power supply jack for it inside the car.
It didn't gave any picture on the screen, so I sold it very cheep.
Few days ago I ordered Raspberry Pi 3.
Hopefully this time project will go better.
BMW went trough many changes, mostly on interior. I've made it easier for working on this RPI project.
New videos are coming up and probably whole thing is going be different from first attempts and much easier since now I have more experience and more tools to work with.
I also made one of my stores into my new workshop so that will also make this project easier.


 RPi 3 arrived today (28.jun 2016)

This time I'll try to put whole project into single video. Things are looking good so far.





Please visit my page: www.xw0rks.tk
You can also donate to my page if you find all my work helpful, any amount would be appreciated.
And it would mean a lot if you would subscribe to my channel: www.youtube.com/XW0RKS
Follow me on twitter: twitter.com/xamidovic