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

30 comments:

  1. Hi.

    I can use your image file to install on cubieboard2

    Thank you.

    ReplyDelete
  2. You are Nº1 !! Thankz for sharing

    ReplyDelete
    Replies
    1. Hi master,
      My video don’t go to full screen i can see the small rpi logo in top left and when loads the desktop the task bar. Because i don’t have your gpio remote i have to disable it (windows open and closing without doing nothing) and x11 cursor its not visible in xbmc.
      Many thanks for sharing you hard work.
      Camolas.

      Delete
    2. (windows open and closing without doing nothing) , I have the same issue, how can I solve it? How or where dissable gpio remote?

      Thanks a lot

      Delete
    3. Hi!

      If you don't have any gpio connections you have to stop the carpc-controller from starting. I have updated the post with a note. Please have a look!

      Delete
    4. Hi master,

      I have a touch calib problem when going from home screen to navit e think its because the X11 dont take control of touch calib (runing navit from X11 works great), any idea?
      Im trying to install the hello world script but no success one time more any idea?
      I want to put my modest program working with yours dont now if is better to do with the "script-way" or the navit (i tried changing the navit to my sec but no image) can you please tech me?
      You are top
      Bye

      Delete
  3. Hi thanks very much, yes it works!!

    ReplyDelete
  4. Thanks a lot Andrei, your work is very impressive!
    I still have two questions.
    Do you have your car antenna connected to the SI4703 module and which values have your resistors R1 and R2?

    ReplyDelete
    Replies
    1. I have connected the car antenna main wire to the ground of the jack on the SI470 board, as this is the FMIP pin. See here how the chip is connected: http://www.soliddigi.com/portfolio/breakout-board-for-si4703-fm-tuner.
      The signal of the fm antenna can be improved by matching the impedance of the car's antenna, which probably is 50 ohm with the impedance of the si470 breakout board. This is a very complex operation and i have to study more, but if you have any more experience in rf domain please let me know of any improvements.
      R1 and R2 have 1Kohm value, but actually you can use any resistors, as long as they don't get too much current.

      Delete
  5. This is so great! I'll try to build something like this for my own car.
    How do you deal with powering off the car? Do you have to remember to power off the RPi before it loses electricity? Or have you found a way to deal with this?
    Also, would you mind explaining in a word or two how you connect the hardware to the car battery?

    Thanks, greetings!
    Peter

    ReplyDelete
    Replies
    1. In my setup i have the shutdown button in the home screen, but you can search on the internet, there are couple of automatic on/off switches.

      Delete
  6. Great progress, I've been following your blog for a while.

    For audio mixing, check out the TLV320 codec chips like http://www.ti.com/product/tlv320aic3254-q1
    That chip has both analog and I2S input, so you could directly use the rpis I2S output.
    THe only downside might be designing a board for it.

    Do you have plans for displaying RDS information from the FM chip?

    ReplyDelete
  7. Hi Andrei,

    respect for this cool project. Exactly what I wanted to setup for my car.
    With your latest build I'm able to use the new PI USV (www.piusv.de) which needs i2c drivers.
    Everything seems to work correctly now except the calibration of the touch screen
    ( which is not exactly yours, but also eGalax )
    The Y-Axis works correct, but the X-Axis is mirrored. I tried to follow your explanation about the calibration, but no changes in /usr/share/eGalax..../touchscreen_axis_calib seem to have an effect to the touchfield behavior.

    Is there another file where I have to change settings?

    Here are my parameters: xinput : Option "Calibration" "84 1990 1863 106"

    and /usr/share/eGalaxCalibration/touchscreen_axes_calib: calib_x_d=1280;calib_x_fact=-0.660474716;calib_y_d=720;calib_y_fact=0.41025641;swap_axes=1;click_confines=8

    maybe you'll find the error?

    regards


    ReplyDelete
    Replies
    1. Hi,
      I see that you are are setting calib_y_d to 720 and calib_y_fact positive. This means that the y pointer will be moved down with 720 pixels.
      From the way you set calib_x_d and calib_x_fact the x axis is mirrored. If you want to disable the mirroring you have to set it like:
      calib_x_d=0;calib_x_fact=0.660474716;
      You can see if the values are loaded properly by starting xbmc by hand over ssh with /usr/local/lib/xbmc/xbmc.bin

      Regards

      Delete
  8. Hi Andrei, I downloaded your latest image (Feb 16 2014) and wrote to the sd card - but raspberry is not booting up at all. I tried downloading and writing the image using win32diskimager a couple of times - but no luck.

    Am I missing anything?

    ReplyDelete
    Replies
    1. Hello,
      I think you have the newer raspberry pi and it is a problem with the firmware i use.
      I will soon release a new image with latest firmware which should work on all RPIs

      Delete
  9. Hi Andrei,

    I've searched a lot and built my own concept to create an car pc, but then I saw your project and thought...wow
    So I'm looking forward to use your project in my car
    What is the best practise to do this? Just buy exactly the same things as you did, download your images and put the rPI in my car?
    Thanks for your project!

    ReplyDelete
    Replies
    1. Hi,
      The best way is to buy similar hardware to avoid issues. The hardware i use is the cheapest found on market.

      Delete
  10. Any updates Andrei? You've gone quiet. :)

    ReplyDelete
    Replies
    1. Please see my latest post: http://engineering-diy.blogspot.ro/

      Delete
  11. Andrei; I'm using your most recent downloads. The XBMC loads up and runs. The mouse (generic Microsoft) moves around the screen, but no button clicks work. I am able to highlight objects and using the ENTER key, activate them. I do not have this problem with any other Raspian builds (the mouse works fine....)

    Also, when I exit the XBMC, the screen goes totally blank. I am unable to do anything.

    How can I either exit XBMC and get to an LX terminal, or how do I boot and prevent XBMC from loading in the first place?

    Thanks.

    ReplyDelete
  12. Hello Andrei,
    I wanted to ask whether it is possible to get this touchscreen calibration addon?! I'm using my selfcompiled version of XBMC with your patches - only missing thing is your addon. Where can I get this? Have you updated your touchscreen patch? Can I get the newest one and the addon? Or where can I find it?

    Thank you very much for your work! Where can I donate?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Hi,

      You can get my latest patches for XBMC Gotham and Navit also from my Downloads page in the top right corner of this blog. If you wat to donate you can use my paypal address on the top right of this blog also.
      Thank you!

      Delete
  13. Okay just found the patches and now I've a working build! I've installed the CarPC Skin and it works but I can't see the calibration addin... btw I'm using OpenElec...! Please help me...

    ReplyDelete
    Replies
    1. Hi,

      I have uploaded the calibration plugin, but you also have a look at the patches because there are some functions needed(xbmcgui.getRawMousePosition).

      Delete
  14. Hi Andrei,

    Sorry to trouble you (again). I have SI4703 FM module connected exactly as you have. My pi has loaded into XBMC but I have connected by SSH and followed your instructions. I get this ...

    pi@raspberrypi ~ $ cd radio
    pi@raspberrypi ~/radio $ sudo python radio_server.py
    Starting Radio Module...
    /home/pi/radio/si4703.py:25: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
    GPIO.setup(0 ,GPIO.OUT) ## SDA
    Exception in method 'update_registry' while trying to read from si4703
    Traceback (most recent call last):
    File "radio_server.py", line 6, in
    fm.init()
    File "/home/pi/radio/si4703.py", line 34, in init
    si4703.update_registry(self)
    File "/home/pi/radio/si4703.py", line 160, in update_registry
    reordered_registry = si4703.convert_reg_readings(self, raw_data, 1)
    File "/home/pi/radio/si4703.py", line 97, in convert_reg_readings
    first_byte = str(bin(old_registry[i]))
    IndexError: list index out of range

    Is this because it is already loaded and running in xbmc? This radio stuff is all new to me :)

    Any help is appreciated. Cheers mate.

    Chris

    ReplyDelete