Sunday, April 13, 2014

Raspberry PI CarPC April 2014 updates

Hello!

I have made a lot of work on the project, with great help from Doru Ignat(idorel@gmail.com) and now the complete list of features is:

  • latest Raspberry PI firmware(which supports new models and has fixes for analog sound - no pops any more, you can use the analog out of RPI)
  • linux kernel 3.10.30 with various touch screens support and also lirc
  • reworked XBMC CarPC skin
  • XBMC 13 Gotham beta3(1080p video support, any music and picture format, support playing from archives and more)
  • reworked XBMC touch screen calibration algorithm
  • XBMC calibration plugin for touch screens(eGalax and others)
  • reworked FM Radio plugin
  • latest Navit build from source
  • fixed Navit to alllow using espeak for speech guidance
  • support for WIFI(Airplay, XBMC remotes)

The latest image can be downloaded from the right side of this blog, from the Downloads page.

Cost of the needed hardware parts: 193$
  - Raspberry PI model B: 45$
  - 7 inch display with touch screen for car reverse: 80$
  - HDMI male to HDMI male golden plated cable: 5$
  - 8GB SDHC card: 6$
  - 5V(2A) micro USB charger: 3$
  - Columbus V800 GPS module(or any other): 37$
  - SI4703 FM Radio breakout board: 13$
  - 2 rotary encoders: 4$

After installing the image on an sd card, you have to configure the system for your needs.

Calibrate the touch screen
The touch screen calibration involves two steps and you need a keyboard connected:
  1. Calibrating the touch screen for X11 applications(like Navit). Open the terminal from Desktop and type xinput-calibrator and follow the indications. After the calibration is completed you have to put the output in a file to make this permanent:
    sudo nano /usr/share/X11/xorg.conf.d/01-input.conf
Put here the output of xinput-calibrator. It will be something like:
    Section "InputClass"
        Identifier    "calibration"
        MatchProduct    "eGalax Inc. USB TouchController"
        Option    "Calibration"    "121 1917 317 1741"
        Option    "SwapAxes"    "1"
    EndSection
  2. Calibrating the touch screen for XBMC. In XBMC use the keyboard to go to Programs/Touch Screen Calibration and follow the informations on screen.
Note, that in order to make a better calibration you can move the finger on screen towards the point, before pressing enter(as can be seen on minute 0:52 in the video).
Touch each point and then press enter to go to the next one. At the end, you have to unplug the touch from usb and then plug it back(works on XBMC Gotham).
After this, he calibration is stored permanently in the file /home/pi/touchscreen_axes_calib. You can edit this file to fine tune the position of the cursor if the calibration isn't perfect.
    calib_x_d and calib_y_d - control the cursor displacement up/down/left/right
    calib_x_fact and calib_y_fact - some factors obtained in the calibration process(don't edit them)
    click_confines - defines the area that will be used for click(if the touch moves outside of this area then a drag action will occur) - this area is measured from the first touched point
    touch_mouse - if you want to use a mouse you have to set this to 0, but some touch screens behave as mouses and you have to set this to 1 in order for them to work(with single click). For the most of the touches this can be 0 if you want to also use a mouse, but if you don't want to use a mouse it doesn't mater, let it be 1.


Change the resolution of XBMC
After the touch screen has been calibrated you can set a new resolution for XBMC. Using ssh you have to edit the file /home/pi/.xbmc/userdata/advancedsettings.xml and set your resolution. After this restart the whole system and XBMC should run with your new resolution and the touch screen will be calibrated.

Add a new map for Navit
  1. Go to Navit Planet Extractor and download a .bin file for your area.
  2. Copy the .bin file in your RPI card in /home/pi/.navit/ folder
  3. Edit the file /home/pi/navit_src/build/navit/navit.xml and search for the entry:
       <mapset enabled="yes">
           <map type="binfile" enabled="yes" data="/home/pi/.navit/Romania.bin"/>
       </mapset>
  4. Add your map name here like this:
       <mapset enabled="yes">
           <map type="binfile" enabled="yes" data="/home/pi/.navit/Romania.bin"/>
           <map type="binfile" enabled="yes" data="/home/pi/.navit/new_map.bin"/>
       </mapset>

Setup the GPS receiver
  1. For USB devices. After plugging the device into the usb port type dmesg and you should see somewhere that a new device was mapped on /dev/tty... Most probably the file name would be /dev/ttyACM0.
  2. For Serial(UART) modules. The device will have the file name as /dev/ttyAMA0.
You can test that the device is connected to a file name by calling cat/dev/ttyAMA0, for example and you should see some NMEA output.
Now, copy this file name and put it in the file /home/pi/StartCarPC in the section:
    # Start gpsd
    # /dev/ttyAMA0 - RPI serial port
    # /dev/ttyACM0 - usb port
    sudo killall gpsd
    gpsd /dev/ttyAMA0

Voice configuration for Navit
Each time a road indication has to be made, Navit will execute the file /home/pi/.navit/speech.sh with the indication text. This file will play a sound and the speak the indication, through speakers.
    aplay -r 44100 /home/pi/.navit/notification3.wav & sleep 0.7 && espeak -ven+f4 -s150 -a 150 -p 50 "$1" --stdout | aplay
    /home/pi/.navit/notification3.wav - the sound that will be played each time before an indication
    -ven+f4 - female voice number 4
    -s150 - speed 150 words per minute
    -a150 - amplitude
    -p50 - pitch
You can find more settings in the espeak manual
If you don't want the voice guidance you can press the speaker button in Navit and it will be turned off.

Configure the Controller
The controller can be easily used with Steering wheel controls or other physical controls in your car. To enable this controller, you have to edit the file /home/pi/StartCarPC and search for the entry:
    # Start the GPIO Remote
    #sudo opencarpc-controller /home/pi/gpio_description &
You have to change it to:
    # Start the GPIO Remote
    sudo opencarpc-controller /home/pi/gpio_description &
Now, you can set the configuration file like in this post

Change the car logo in the Home screen
If you want to put another car logo you have to edit the file /home/pi/.xmc/addons/skin.CarPC-touch/16x9/Home.xml and find the entry:
    <posx>580</posx>
    <posy>205</posy>
    <width>550</width>
    <height>550</height>
    <texture>bmw_logo.png</texture>

Here, you can set your new image instead of bmw_logo.png you can put a complete path of the new image.

Set up a WIFI connection
If you want to have internet connection, or airplay or control the whole system using the XBMC remotes, you have to setup a wifi hotspot with your phone and then use an USB WIFI dongle(I am using EDIMAX EW-7811UN dongle).
The system is configured to automatically connect to a wifi hotspot with the following settings:
    wpa-ssid "opencarpc"
    wpa-psk "opencarpc123"

You can find these settings in the file /etc/network/interfaces.

Some pictures with my setup:

Wednesday, February 26, 2014

openCarPC controller v1.1

Hi!

In a previous post I have explained how I have interfaced Raspberry PI GPIOs with XBMC, using buttons and rotary encoders.
I have reworked the application which controls this and now there are more features available.
You can use this post to set up the hardware connections between Raspberry PI GPIO connector and as many buttons and rotary encoders as you like(or you have room for on the RPI GPIO pins).


At this moment my setup has 2 rotary encoders, each of them having also a push button.
You can use this tutorial to set up your car steering wheel controls to control this system.

XBMC builtin functions are now supported.
For a list of available XBMC builtin functions have a look at this link.

Groups of commands are supported.
Commands should be separated by the '+' character. For example:
xbmcbuiltin_PlayerControl(previous)+KB_minus
will execute both commandsa t once when the corresponding button is pressed, or when the rotary encoder is turned in the correct direction.

Multiple groups of commands are supported.
Groups of commands should be separated by the '>' character.
When the action is triggered(button pressed or rotary encoder rotated in the correct direction) the commands are executed consecutively.
For example:
xbmcbuiltin_ActivateWindow(Music)>xbmcbuiltin_ActivateWindow(Videos)
When you press the button for the first time XBMC will switch to Music window. When you press it the second time XBMC will switch to Videos window and when pressed again, XBMC will switch back to Music window.

Note:
The groups of commands were designed to support multiple programs control. At this moment I am working on external radio support so you can set the volume of radio and volume in XBMC at the same time. This will be available in a future post.
This doesn't mean that you can use multiple XBMC commands at once.

To download the latest version, please checkout the Downloads link from the right of the blog, in the openCarPC tools folder. The current version is 1.1.

Have fun!

Saturday, February 8, 2014

OpenCarPC

Hi!

I have worked on some new features for my CarPC. Here are the changes:
First, some videos:

The latest image can be downloaded from the Downloads link on the right of this blog(username:pi, password:a).
Note!
If you do not have any rotary encoder connected or any buttons with a resistor you need to disable the carpc-controller application. You can do this by editing the file /home/pi/StartCarPC and commenting the line which contains carpc-controller.

Hardware updates:
- added ViewHd HDMI to HDMI+audio board
- added SI4703 FM Radio module
- created an expansion board with fm radio module and three connectors(one for GPS receiver and two for rotary encoders)
- added a very cheap board to mix two output channels(RPI and radio) into a single output(which goes to the amplifier, in my case AUX input of the car player)

Software updates:
- added loading movie(created by Doru Ignat)
- added a python server responsible for controlling the radio module via i2c
- added new XBMC plugin for controlling the FM Radio(including storing up to 5 radio stations in a file)
- improved carpc-controller to support sending multiple commands for a single button press or encoder turn(e.g. turning right one rotary encoder can increase the volume in XBMC and the volume of radio at the same time)
- improved the speed in Navit clicking
- improved the Navit OSD for both day and night setup(Navit switches automatically teh setup based on the time of the system).
- added time synchronization mechanism based on GPS readings(RPI does not have a real time clock)

The expansion board.

RE1 and RE2 are rotary encoders.

The FM Radio driver and Python server.
The FM Radio module is connected using i2c communication interface(GPIO0-SDA and GPIO1-SCL of the PI).
The radio driver is contained in the si4703 python class. The Radio server is implemented in the file radio_server.py(which is automatically started at boot time). This server simply opens a socket and waits for data. After any data is received, a couple of if-else statements different radio functions are called base on the incoming data.
The available commands are:
seek_right - search for a new station in the right of the current frequency
seek_left - search for a new station in the left of the current frequency
tune_xx.x - set the current frequency to xx.x MHz
volume_xx - set the volume of the radio module to xx. xx should be between 0 and 15
toggle_mute - toggle mute
get_frequency - get the current frequency
The server reply with the current frequency for each command.

Simple test.
To understand how this radio server-client works you can make the folowing experiment:
1. Plug the gpio expansion board(or wire the radio module to the PI as in the above schematic)
2. [Server] Connect using one ssh window(I use Putty) to the PI and enter the folowing commands:
cd radio
sudo python radio_server.py
The radio server should initialize the  radio module and start the server.
3. [Client] go to the radio folder and use radio_client.py to send commands o the radio server, like in the folowing picture:
The file radio_client.py simply opens an UDP socket, puts an '_' character between arguments and send the obtained string to the server socket.

The radioFM XBMC plugin.
In order to simplify user interaction I have created a new XBMC plugin(radioFM). Its purpose is to allow interacting with the Radio Server(and with the Radio Module) using the touch screen. In order to be able to use this plugin you need to have the radio_server.py started and the FM module plugged in.
Features:
  • The current frequency is displayed at the top.
  • The left and right arrow buttons are for seeking to the next channel(left or right).
  • The bottom 5 buttons are preset channels(these are kept in a file so they are available after reboot).
  • The Set/Tune Channels button is used for changing the mode in which the bottom buttons are operating. By default they are in the 'Tune' mode, so if you presss them the radio will tune to that frequency. If you press the Set/Tune Channels button once you will enter the Set mode, which will allow you to store the current channel in which preset button you like(or in all of them... if you want) by pressing it once. You will see that the frequency will be changed.
Connecting two audio sources(RPI and Radio) to one amplifier.
In order to correctly hook up two audio sources together(putting them in parallel) for a single output you have to use one schematic from this document. I have used the last schematic. Don't forget to use at least 1% tolerance for the resistors.

The new GPIO controller.
The GPIO controller is now using the official XBMC client code from xbmcclient.h.
Now, you can call a lot more XBMC functions for any button pressed or encoder movement.

TODO List:
- update to the latest Raspberry PI firmware(today it is possible but then Navit won't be visible)
- remove the calibration file for XBMC(/usr/share/eGalax/touchscreen_axes_calib) and use the values from the Debian calibration file(/usr/share/X11/xorg.conf.d/01-input.conf)
- create an XBMC addon to allow calibrating the touch screen for both XBMC and X11 windows and also for calibrating the external encoders and button
- create a configuration page(XBMC addon) for the carpc-controller settings
- create a better audio mixer unit
- create a new page for launching different X11 applications