Quantcast
Channel: Engineering(DIY)

STM32F3 Discovery + Eclipse + OpenOCD

$
0
0
Hi,

ST launched in September a very interesting development board(STM32F3-Discovery). It is a very cheap one(I have got myself one for ~10$). It has a debugger integrated(STLINK) and also some great sensors:
- ST MEMS LSM303DLHC, which contains 3 axis accelerometer(to measure acceleration intensity on each axis) and 3 axis magnetometer(to measure angles to a fixed point - the Earth's magnetic North)
- ST MEMS L3GD20, which has 3 axis gyrometer(to measure rotation speed)
This board is very good for automated pilot controller projects.

After unpacking the board I have found that it was supported just by commercial software and tools. As I am an opensource kind of guy I have struggled myself some time to get this working with Eclipse, OpenOCD and a free toolchain, on Linux.
I have used Ubuntu, but I think the process is the same on every distribution. Also, with little adjustments it can work on Windows.

Here are some steps, that you have to follow to get the led blinking example to work:
1. Install Java Runtime Environment. Here are some steps for Ubuntu:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

2. Install Eclipse. Get Eclipse IDE from here (grab the Eclipse IDE for C/C++ Developers) and unpack it somewhere

3. Install GDB Hardware Debugging. Open Eclipse go to Help->Install New Software and then search for GDB Hardware Debugging and install it.

   Install GNU ARM Eclipse plugin. Get it from here and install it from Help->Install New Software->Add->Archive and select the downloaded .zip file.

4. Install some dependencies. Paste following text in Terminal:
sudo apt-get install git zlib1g-dev libtool flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential libftdi-dev libusb-1.0.0-dev

5. Install OpenOCD(version>0.6.1). Get it from here and unpack it. Then, navigate to the extracted folder and type in Terminal:
./configure --enable-maintainer-mode --enable-stlink 
make 
sudo make install

6. Add rule for Stlink to be accessed without sudo. Type in Terminal:
sudo gedit /etc/udev/rules.d/99-stlink.rules
Paste the following text:
ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3748", MODE="0666"
Type in Terminal:
sudo udevadm control --reload-rules
Now, with the board connected to PC you can enter  in Terminal:
openocd -f /usr/local/share/openocd/scripts/board/stm32f3discovery.cfg
The following text should appear:
Open On-Chip Debugger 0.6.1 (2012-10-29-22:02)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
srst_only separate srst_nogate srst_open_drain
Info : clock speed 1000 kHz
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
You can close the Terminal now.

7. Install toolchain.  You can use Codesourcery toolchain, like described in this step, or you can use GCC Arm Embeddedtoolchain(fromhere) which has support for hardware floating point unit and which is free and it is easier to install.
For Codesourcery follow the next steps:
Go to Codesourcery and download IA32 GNU/Linux Installer. To install it open the Terminal and navigate to the folder where it is downloaded. Type:
chmod a+x arm-2012.03-56-arm-none-eabi.bin 
./arm-2012.03-56-arm-none-eabi.bin
Then select next at every step. 

8. Download sample project. Go to this page and download stm32f3.tar.gz file and unpack it.

9. Open the project in Eclipse. Open Eclipse and go to Workbench. Click File->Import and then select General->Existing Projects into Workspace. Select the downloaded project and click finish.
This is a makefile project, so you have to edit makefile if you want to change some project settings. The frst thing you should do is open the Makefile file and check at the very beginning if the toolchain path is correct. This should be like:
TC = <path_to_toolchain>/arm-none-eabi
Now you can build. right click on project name and select build. The correct output is in the Console tab from Eclipse(ignore the warnings and errors from Problems tab).

10. Debugging. After the project was builded correctly select Run->External Tools->External Tools Configuration. Select OpenOCD(restart) in the left tab and click run.
Now, right click project and select Debug as->Debug Configuration and then
select in the left stm32f3-debug and then click Debug.
Note: If you want to add more source files you can add them in the src folder. New headers should be added into hdr folder. If you want to add another folder you have to specify it like the LIB_SRCS in the Makefile and also create LIB_OBJS like variable in the Makefile.

Happy free coding and debugging! :-)

Free ARM toolchain with floating point unit support

$
0
0
Hi,

The previous post(STM32F3 Discovery + Eclipse + OpenOCD) was based on the CodeSourcery Lite toolchain, which doesn't support floating point unit.
I have found an alternative: gcc-arm-embedded

You just have to download the Linux installation tarball and unpack it somewhere. After this, you have to edit the file Makefile from the project from this or this post and set TC variable to the new toolchain.
You have to set it like this:
TC = /path_to_toolchain/gcc-arm-none-eabi-x_x-xxxxqx/bin/arm-none-eabi
There is another way, like I did. Enter in Terminal:
gedit ~/.bashrc
add the line at the end of the file:
PATH=$PATH:/path_to_toolchain/gcc-arm-none-eabi-x_x-xxxxqx/bin/
then save and close the file and then enter in Terminal:
source ~/.bashrc
Now you can run arm-none-eabi-gcc in every folder you like. For this case, you should set the TC just like in the picture above.

Then, you have to scroll down and find FPU variable
and set it like this:
FPU= -mfpu=fpv4-sp-d16 -mfloat-abi=hard

Now you are ready to develop great things.

Happy coding!

STM32F3-Discovery Usart with printf

$
0
0
Hi,

The next step after setting up the Development Environment for STM32F3-Discovery was to communicate with computer via serial port.
I have added usart support to my board using USART2 module, which had TX connected to PA2 pin and RX to PA3 pin(both with alternate function set to 7).

The next step was to connect the pins to PC serial port. I have used a MAX3232 module(note that you need a chip with 3.3V support).

After using printf function I have noticed that linker asks for some functions like _write which are used internally. I have added a file newlib_subs.c to implement these function.

You can download the example project from here.
The settings for usart communication are:
baudrate: 115200
parity: none
data bits: 8
stop bits: 1
flow control: none

If you want to use interrupts to read from USART you can use the code from here.

You can checkmy project via svn from my repository using:
svn checkout http://andrei-development.googlecode.com/svn/branches/dev/stm32f3-discovery


STM32F3 Discovery on Windows with Eclipse and OpenOCD

$
0
0
Hi!

Because of a lot of requests, I have decided to make the Windows version of the tutorial for setting up STM32F3-Discovery board, with free tools.

First, download ST-LINK V2 driver from here. Open the archive and install what is in it.
Then plug the device and let the driver install.
Now, get the latest OpenOCD installer from here and extract it somewhere. Copy <openocd_path>\scripts\board\stm32f3discovery.cfg to <openocd_path>\bin folder
Now you should be able to connect to the board in Command Prompt like this:
D:\embedded\openocd-0.7.0-dev-121112115725\bin>openocd-0.7.0-dev-121112115725.ex
e -f stm32f3discovery.cfg
Open On-Chip Debugger 0.7.0-dev-00079-g08ddb19 (2012-11-12-17:14)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.sourceforge.net/doc/doxygen/bugs.html
adapter speed: 1000 kHz
srst_only separate srst_nogate srst_open_drain
Info : clock speed 1000 kHz
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Now close the Command Prompt.

Download latest Eclipse.
Go to Eclipse download page and download Eclipse IDE for C/C++ developers. Extract it and start eclipse.exe. Go to Workbench.

Set up Eclipse.
Go to Help->Install New Software, select All Available Sites in Work With dropdown list. Enter "GDB Hardware Debugging" in the search box and install the package. Download Arm Eclipse Plugin from here and then go to Help->Install New Software in Eclipse. Click Add and then click archive and select the previous downloaded file. Then select the packet and install it.

Install GCC Arm Embedded toolchain from here.

Now we need some Linux tools like make and rm for Windows. Download Cygwin from here. Select whichever mirror you want. Search for "make" and select the binary from Devel dropdown. Click next and wait for it to install.
Now, download this project and import it in Eclipse Workspace. Right click project and select  Properties->C/C++ Build->Environment. Here, check if PATH variable has link to toolchain and to Cygwin binaries folders. Here, you can add <gcc-arm-none-eabi-4_6-2012q4/arm-none-eabi/include> path for the Eclipse IDE to find some headers like stdint.h.
If everything  was installed correctly you should be able to clean the project and to build it.

With the project selected, click Run->External Tools->External Tools Configurations and select from the left the configuration named OpenOCD(win). Check if the path for OpenOCD at top is correct.
Now, click Run.

After this, click Run->Debug Configurations and select from the left Navigation-debug. In the Debugger tab check if the arm-none-eabi-gdb.exe path is correct. Now click Debug and you should see the Debug Window from Eclipse and the Program counter pointing at the first instruction from main().

Adding 7inch display with touchscreen to Raspberry PI

$
0
0
Hi!

First thing I got in mind when seeing Raspberry PI was "car PC project".
The targeted display was 7 inch with touchscreen. I have found a lot of displays on Ebay.

I have got myself one for 85 dollars with free shipping(this; if it is not available any more you can search "reversing driver board hdmi" on ebay and you will find others). The display driver board has hdmi input and an on board resistive touchpanel with usb controller board.

It took less than a month to receive it(in Romania). After unpack, it worked out of the box with Ubuntu 12.10(display + touchpanel) and with Windows, but for Windows I had to install some drivers also received in the package.

I have installed latest Raspbian image on a SD_Card and tried it on my Raspberry PI model B, but the touchpanel didn't show any input. After searching a lot I have decided that I have to recompile the raspbian kernel and add support for touchpanel. This sounded very new to me but it seemed to be an easy task.

First thing, I have run lsusb to see the touch controller type(on RaspberryPI):
pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 1c4f:0002 SiGma Micro Keyboard TRACER Gamma Ivory
Bus 001 Device 005: ID 0eef:0001 D-WAV Scientific Co., Ltd eGalax TouchScreen
Last device is the touch controller, from eGalax.

Edit: If you don't want to build the kernel by yourself, you can download mine from here. After his, you have to replace file /boot/kernel.img and /lib/firmware and /lib/modules/ on the SD card.

Building a new kernel(in UBUNTU 12.10).
Get kernel sources.
wget https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz
tar -zxvf  rpi-3.6.y.tar.gz
Install some dependencies.
sudo apt-get install git libncurses5 libncurses5-dev qt4-dev-tools build-essential
Install toolchain.
The best way to do the kernel compilation is on a Desktop/Laptop machine, which will be much more fast than on the Raspberry PI. I have did this in Ubuntu 12.10:
sudo apt-get install gcc-arm-linux-gnueabi
After download of the kernel archive has finished unpack it and then navigate with terminal to the extracted folder.
Be sure thaat the sources objects are cleaned. Type:
make mrproper
Create a folder for the generated kernel:
mkdir ../kernel
Generate the .config file:
make O=../kernel/ ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig
Configure the kernel:
make O=../kernel/ ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- xconfig
In the opened window press the | button to collapse all items. Then, navigate to Device Drivers->Input Device Support->TouchScreens and select it. Here, be sure to check also your touch screen controller if it is other than eGalax, or if it is not selected. Now press save.

With the changes being made you can now compile the kernel:
make O=../kernel/ ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- -k -j3
Note: -j3 option from the end means to enable parallel build. The number should be number of cpu cores + 1(I have dual core cpu).

The build took about 20 minutes on my PC. After the build completes, you will have the new kernel in ../kernel folder, created above.

Create the kernel image:
cd ../
git clone git://github.com/raspberrypi/tools.git
Note: You need to have git installed.

Navigate to tools/mkimage and then run:
./imagetool-uncompressed.py ../../kernel/arch/arm/boot/Image
This command will generate the kernel image(kernel.img file).

Build modules:
Go back to the linux-rpi-3.6.y folder.
mkdir ../modules/
make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/

Replace the kernel:
Get latest firmware:
wget https://github.com/raspberrypi/firmware/archive/next.tar.gz
tar -zxvf next.tar.gz
In the small partition(/boot) do:
  • replace /boot/bootcode.bin with firmware-next/boot/bootcode.bin
  • replace /boot/kernel.img with the previously created kernel image
  • replace /boot/start.elf with firmware-next/boot/start.elf
In the big partition(/root) do:
  • replace /lib/firmware with <modules_builded_above_folder>/lib/firmware
  • replace /lib/modules with <modules_builded_above_folder>/lib/modules
  • replace /opt/vc with firmware-next/hardfp/opt/vc/
Now your card should contain the new image. Safely eject your SD card and then unplug it from the card reader and then put the card in Raspberry PI and start X(startx). Plug the touch controller in one usb and check if you can move the cursor(or you can start with he touch already plugged in).

After I have started X, my touch input was working but the axes were switched and also not calibrated.

Calibration for the touchscreen(in Raspberry PI). 
Note: The next steps are performed in the Raspberry PI's Debian Wheezy. This is a method for calibrating the touchscreen which will work just for Xserver and Xserver based applications.

Install xinput_calibrator.
Install some dependencies:
sudo apt-get install libx11-dev libxext-dev libxi-dev x11proto-input-dev
Download xinput_calibrator somewhere in the Raspberry PI's folder structure.
wget http://github.com/downloads/tias/xinput_calibrator/xinput_calibrator-0.7.5.tar.gz
Unpack it and then navigate to the unpacked folder and then install it using:
./configure
make
sudo make install
After this step you should run xinput_calibrator(from Xserver terminal console: first startx then open console and then run it).
xinput_calibrator
Follow the on screen instructions(touching some points on screen) and after calibration is complete you will receive a message like this:
Calibrating EVDEV driver for "eGalax Inc. USB TouchController" id=8
    current calibration values (from XInput): min_x=1938, max_x=114 and min_y=1745, max_y=341

Doing dynamic recalibration:
    Setting new calibration data: 121, 1917, 317, 1741


--> Making the calibration permanent <--
  copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'
Section "InputClass"
    Identifier    "calibration"
    MatchProduct    "eGalax Inc. USB TouchController"
    Option    "Calibration"    "121 1917 317 1741"
    Option    "SwapAxes"    "1"
EndSection

For Raspbian you have to create a file:
sudo nano /usr/share/X11/xorg.conf.d/01-input.conf
Add in this file the content above(starting with Section "InputClass" line) and then save it(ctrl+O).

Note:
Please make sure that you don't have sections like
MatchProduct    "eGalax Inc. USB TouchController"
in otherfiles from /usr/share/X11/xorg.conf.d/ folder(highest number files are processed last, thanks to Jasmin).

Now touchscreen should be calibrated and after reboot it will keep the settings.
Once, I had to run xinput_calibration again in order to have the pointer to the desired points. You can update the numbers given by the xinput_calibration utility in the
usr/share/X11/xorg.conf.d/01-input.conf file in order to have the best calibration at boot.

Soon I will add some pictures.

Andrei

Build XBMC Frodo from source in Raspbian on Raspberry PI

$
0
0
Hi!

After struggling couple of days in finding the best way to build XBMC on Raspberry PI I have finally got a working solution(haven't discovered how I can cross-compile it, which would be the best choice).
This takes about 15 hours, on my Raspberry PI model B, but the good news is that 'make' takes about 12 hours, so you don't need to watch it, just come from time to time to see if it is working. Besides the build messages displayed on screen you have the whole logs for rbp_depends, configure, make and make install steps. If anything goes wrong you can investigate these files(the last one reached) and search for the first error
log_1_rbp_depends.log
log_2_configure.log
log_3_make.log
log_4_make_install.log
This tutorial is for Linux Host Machine but it can be easily adapted to any other OS.
Let's get this started!

1. Get the latest Raspbian Wheezy image from http://www.raspberrypi.org/downloads and put it on an SD card:
You have couple of possibilities to do this. In Linux you can use:
sudo dd bs=1M if=raspbian_wheezy_image_path of=/dev/sd_card_path
2.Get XBMC 12 source code from http://xbmc.org/download/. On the Source Code section, download the zip file from where it says: "Stable release sources are available here".
If you get the code from git it will probably get an unstable version, which is the latest code. When I have build from source I have got XBMC 13 alpha 1 which worked, but no addon was working.
Transfer xbmc folder to your /home/pi/ directory or wherever you like.
Now you can plug the card in Raspberry PI and follow the next steps.

Note. The easiest way to do this is via ssh(first, enable it using sudo raspi-config menu), from a computer. Just connect in Terminal using:
ssh pi@x.x.x.x
where x.x.x.x is the ip address of your device. You can get the ip address by typing ifconfig. Then you just copy/paste the commands into Terminal.

3. Set minimum amount of video memory and create a swap partition:
sudo raspi-config
Here you should expand_rootfs, disable overscan, configure_keyboard, change_pass, change_timezone and enable ssh. Select memory_split and enter 16 then restart.
Now, to create a swap partition, use the following:
dd if=/dev/zero of=/home/pi/swapfile1 bs=1024 count=204800
sudo mkswap /home/pi/swapfile1
sudo chown root:root /home/pi/swapfile1
sudo chmod 0600 /home/pi/swapfile1
sudo swapon /home/pi/swapfile1
The swap file is needed as extra memory for the compiler. This will prevent you from getting errors like:
gcc: internal compiler error: Killed (program cc1)

4. Update the system and install some dependencies:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install autotools-dev comerr-dev dpkg-dev libalsaplayer-dev libapt-pkg-dev:armhf libasound2-dev libass-dev:armhf libatk1.0-dev libavahi-client-dev libavahi-common-dev libavcodec-dev libavformat-dev libavutil-dev libbison-dev:armhf libbluray-dev:armhf libboost1.49-dev \
    libbz2-dev:armhf libc-dev-bin libc6-dev:armhf libcaca-dev libcairo2-dev libcdio-dev libclalsadrv-dev libcrypto++-dev libcups2-dev libcurl3-gnutls-dev \
    libdbus-1-dev libdbus-glib-1-dev libdirectfb-dev libdrm-dev libegl1-mesa-dev libelf-dev libenca-dev libept-dev libevent-dev libexpat1-dev libflac-dev:armhf \
    libfontconfig1-dev libfreetype6-dev libfribidi-dev libgconf2-dev libgcrypt11-dev libgdk-pixbuf2.0-dev libgl1-mesa-dev libgles2-mesa-dev \
    libglew-dev:armhf libglewmx-dev:armhf libglib2.0-dev libglu1-mesa-dev libgnome-keyring-dev libgnutls-dev libgpg-error-dev libgtk2.0-dev libhal-dev \
    libhunspell-dev:armhf libice-dev:armhf libicu-dev libidn11-dev libiso9660-dev libjasper-dev libjbig-dev:armhf libjconv-dev libjpeg8-dev:armhf libkrb5-dev \
    libldap2-dev:armhf libltdl-dev:armhf liblzo2-dev libmad0-dev libmicrohttpd-dev libmodplug-dev libmp3lame-dev:armhf libmpeg2-4-dev libmysqlclient-dev \
    libncurses5-dev libnspr4-dev libnss3-dev libogg-dev:armhf libopenal-dev:armhf libp11-kit-dev libpam0g-dev:armhf libpango1.0-dev libpcre++-dev libpcre3-dev \
    libpixman-1-dev libpng12-dev libprotobuf-dev libpthread-stubs0-dev:armhf libpulse-dev:armhf librtmp-dev libsamplerate0-dev:armhf \
    libsdl-image1.2-dev:armhf libsdl1.2-dev libslang2-dev:armhf libsm-dev:armhf libsmbclient-dev:armhf libspeex-dev:armhf \
    libsqlite3-dev libssh-dev libssh2-1-dev libssl-dev libstdc++6-4.6-dev libtagcoll2-dev libtasn1-3-dev libtiff4-dev libtinfo-dev:armhf libtinyxml-dev \
    libts-dev:armhf libudev-dev libv8-dev libva-dev:armhf libvdpau-dev:armhf libvorbis-dev:armhf libvpx-dev:armhf libwebp-dev:armhf libwibble-dev \
    libx11-dev:armhf libx11-xcb-dev libxapian-dev libxau-dev:armhf libxcb-glx0-dev:armhf libxcb-render0-dev:armhf libxcb-shm0-dev:armhf \
    libxcb1-dev:armhf libxcomposite-dev libxcursor-dev:armhf libxdamage-dev libxdmcp-dev:armhf libxext-dev:armhf libxfixes-dev libxft-dev libxi-dev \
    libxinerama-dev:armhf libxml2-dev:armhf libxmu-dev:armhf libxrandr-dev libxrender-dev:armhf libxslt1-dev libxss-dev:armhf libxt-dev:armhf \
    libxtst-dev:armhf libxxf86vm-dev libyajl-dev libzip-dev linux-libc-dev:armhf lzma-dev mesa-common-dev python-dev python2.7-dev x11proto-composite-dev \
    x11proto-core-dev x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev x11proto-gl-dev x11proto-input-dev x11proto-kb-dev x11proto-randr-dev \
    x11proto-record-dev x11proto-render-dev x11proto-scrnsaver-dev x11proto-xext-dev x11proto-xf86vidmode-dev x11proto-xinerama-dev xtrans-dev \
    libnfs-dev libplist-dev avahi-daemon zlib1g-dev:armhf swig java-package libafpclient-dev liblockdev1-dev autoconf automake libtool gcc udev openjdk-6-jre \
    cmake g++ libudev-dev build-essential autoconf ccache gawk gperf mesa-utils zip unzip curl
This will take some time depending on your internet speed.

5. Copy libraries headers and create some symlinks for libraries:
sudo cp -R /opt/vc/include/* /usr/include
sudo cp /opt/vc/include/interface/vcos/pthreads/* /usr/include/interface/vcos
sudo ln -fs /opt/vc/lib/libEGL.so /usr/lib/libEGL.so
sudo ln -fs /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so
sudo ln -fs /opt/vc/lib/libEGL.so /usr/lib/arm-linux-gnueabihf/libEGL.so.1
sudo ln -fs /opt/vc/lib/libEGL_static.a /usr/lib/libEGL_static.a
sudo ln -fs /opt/vc/lib/libEGL_static.a /usr/lib/arm-linux-gnueabihf/libEGL_static.a
sudo ln -fs /opt/vc/lib/libGLESv2.so /usr/lib/libGLESv2.so
sudo ln -fs /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so
sudo ln -fs /opt/vc/lib/libGLESv2.so /usr/lib/arm-linux-gnueabihf/libGLESv2.so.2
sudo ln -fs /opt/vc/lib/libGLESv2_static.a /usr/lib/libGLESv2_static.a
sudo ln -fs /opt/vc/lib/libGLESv2_static.a /usr/lib/arm-linux-gnueabihf/libGLESv2_static.a
sudo ln -fs /opt/vc/lib/libbcm_host.so /usr/lib/libbcm_host.so
sudo ln -fs /opt/vc/lib/libbcm_host.so /usr/lib/arm-linux-gnueabihf/libbcm_host.so
sudo ln -fs /opt/vc/lib/libvchiq_arm.a /usr/lib/libvchiq_arm.a
sudo ln -fs /opt/vc/lib/libvchiq_arm.a /usr/lib/arm-linux-gnueabihf/libvchiq_arm.a
sudo ln -fs /opt/vc/lib/libvchiq_arm.so /usr/lib/libvchiq_arm.so
sudo ln -fs /opt/vc/lib/libvchiq_arm.so /usr/lib/arm-linux-gnueabihf/libvchiq_arm.so
sudo ln -fs /opt/vc/lib/libvcos.a /usr/lib/libvcos.a
sudo ln -fs /opt/vc/lib/libvcos.a /usr/lib/arm-linux-gnueabihf/libvcos.a
sudo ln -fs /opt/vc/lib/libvcos.so /usr/lib/libvcos.so
sudo ln -fs /opt/vc/lib/libvcos.so /usr/lib/arm-linux-gnueabihf/libvcos.so
There is a problem when compiling, with the file /usr/include/interface/vmcs_host/vcgencmd.h which includes the wrong vchost_config.h, so I have created a command to put the right inclusion:
sudo sed -i 's/#include "vchost_config.h"/#include "linux\/vchost_config.h"/' /usr/include/interface/vmcs_host/vcgencmd.h
6. Install taglib, libcec and libshairport.
cd <pah_to_xbmc_dir>
make -C lib/taglib
sudo make -C lib/taglib install
cd <any_directory>
git clone --depth 5 https://github.com/Pulse-Eight/libcec.git
cd libcec
./bootstrap
./configure --prefix=/usr/local
make
sudo make install
cd <path_to_xbmc_dir>
make -C lib/libshairport
sudo make -C lib/libshairport install
7. Configure and compile XBMC
cd <path_to_xbmc_dir>
export TARGET_SUBARCH="armv6zk"
export TARGET_CPU="arm1176jzf-s"
export TARGET_FLOAT="hard"
export TARGET_FPU="vfp"
export TARGET_FPU_FLAGS="-mfloat-abi=$TARGET_FLOAT -mfpu=$TARGET_FPU"
export TARGET_EXTRA_FLAGS="-Wno-psabi -Wa,-mno-warn-deprecated"
export TARGET_COPT="-Wall -pipe -fomit-frame-pointer -O3 -fexcess-precision=fast -ffast-math  -fgnu89-inline"
export TARGET_LOPT="-s -Wl,--as-needed"
export CFLAGS="-march=$TARGET_SUBARCH -mcpu=$TARGET_CPU $TARGET_FPU_FLAGS -mabi=aapcs-linux $TARGET_COPT $TARGET_EXTRA_FLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-march=$TARGET_SUBARCH -mtune=$TARGET_CPU $TARGET_LOPT"
Fix some errors:
sed -i 's/USE_BUILDROOT=1/USE_BUILDROOT=0/' tools/rbp/setup-sdk.sh
sed -i 's/TOOLCHAIN=\/usr\/local\/bcm-gcc/TOOLCHAIN=\/usr/' tools/rbp/setup-sdk.sh
Run:
sudo sh tools/rbp/setup-sdk.sh
Fix other errors:
sed -i 's/cd $(SOURCE); $(CONFIGURE)/#cd $(SOURCE); $(CONFIGURE)/' tools/rbp/depends/xbmc/Makefile
Run:
make -C tools/rbp/depends/xbmc/ 2>&1 | tee log_1_rbp_depends.log
Configure:
./configure --prefix=/usr/local --build=arm-linux-gnueabihf \
            --host=arm-linux-gnueabihf --localstatedir=/var/lib \
            --with-platform=raspberry-pi --disable-gl --enable-gles \
            --disable-x11 --disable-sdl --enable-ccache --enable-optimizations \
            --disable-external-libraries --disable-goom --disable-hal \
            --disable-pulse --disable-vaapi --disable-vdpau --disable-xrandr \
            --enable-airplay --disable-alsa --enable-avahi --enable-libbluray \
            --enable-dvdcss --disable-debug --disable-joystick --disable-mid \
            --enable-nfs --disable-profiling --disable-projectm --enable-rsxs \
            --enable-rtmp --disable-vaapi --disable-vdadecoder \
            --disable-external-ffmpeg --enable-optical-drive \
            --enable-player=omxplayer 2>&1 | tee log_2_configure.log
After configuration completes, please run he following command:
sed -i 's/ifeq (1,1)/ifeq (0,1)/' tools/TexturePacker/Makefile
Compile(this will take about 12 hours):
make 2>&1 | tee log_3_make.log
8. Install XBMC 12 in Raspbian.
sudo make install 2>&1 | tee log_4_make_install.log
After this step you have to run raspi-config again and to set video memory to 128 and then restart. Now you should be able to run XBMC using
/usr/local/lib/xbmc/xbmc.bin
Note: If you are running via xbmc command, or from XFCE menu->Multimedia->XBMC it will not start. The same command can be used to run XBMC from terminal or from XFCE interface.
In addition you can also install PVR Addons and XVDR addon(but this is not necessary):
cd <any_directory>
git clone --depth 5 git://github.com/opdenkamp/xbmc-pvr-addons.git
cd xbmc-pvr-addons/
./bootstrap
./configure --prefix=/usr/local --enable-addons-with-dependencies
sudo make install
cd <any_directory>
git clone git://github.com/pipelka/xbmc-addon-xvdr.git
cd xbmc-addon-xvdr
sh autogen.sh
./configure --prefix=/usr/local
sudo make install
Note
If you want to modify sources after the compilation is completed, you just have to modify them and then run make again, which will build only the affected parts(couple of minutes), but remember to keep the video memory at maximum 32MB when you are building, and also keep the swap partition.

Many thanks to:
  • XBIAN forums 
  • http://www.raspbian.org/RaspbianXBMC (mpthompson)

Raspberry PI, Raspbian, XBMC and eGalax 7 inch touchscreen

$
0
0
Hello!

I have spent some time lately trying to find a solution to get my 7 inch eGalax touchscreen to work with  Raspbian(Debian Wheezy) in XBMC 12 Frodo and finally got it working as I wanted.

My Setup
  • Raspberry PI model B: ~30$
  • 7 inch display with touchscreen for car rear view camera, from eBay(touchscreen is connected to one USB port): 80$
  • HDMI male to HDMI male connector(from eBay): <2$
  • 4GB SDHC class 4 card
  • 12V(500mA) AC to DC adapter for powering the display
  • 5V(1A) microUSB AC to DC converter for powering the PI
  • USB keyboard


Edit:  I have uploaded my image with XBMC 12 build with eGalax touchscreen support(download it from here, with md5sum c59330154143d9e5e43217322bbd92ce). It seems that you need to request permission and I will give you access. The account is pi and password: a.

Here is what you need to do in order to have a system with Raspberry PI, Raspbian OS and XBMC 12 Frodo stable with eGalax touchscreen working correctly(which means axes calibrated and click working with just one tap&release action):


1. Get latest Raspbian image from here and flash it to an SD card.

2. Build your own kernel with eGalax touchscreen support, like in this post(you will only need to replace kernel.img file and /lib/modules and /lib/firmware folders on the SD card).

3. Build XBMC 12 on Raspberry PI using this tutorial.
Note: After downloading XBMC archive, get this archive and unpack it anywhere.
Apply patches to xbmc files:
cd <patches_folder>
patch -p1 <path_to_xbmc>/xbmc/input/linux/LinuxInputDevices.cpp < LinuxInputDevices_cpp.patch
patch -p1 <path_to_xbmc>/xbmc/input/MouseStat.cpp < MouseStat_cpp.patch
patch -p1 <path_to_xbmc>/xbmc/input/MouseStat.h < MouseStat_h.patch
4. Touchscreen calibration.
Copy the eGalaxCalibration folder from the archive(downloaded above) to /usr/share/ on Raspberry PI. Here, you should have the file touchscreen_axes_calib. It contains four values for the axes calibration and one value for swapping axes.
The simplest way to swap axes is to switch the four wires cable plug's orientation which comes from the touchscreen to the touch controller.

Here is how the calibration was done.

the original behavior(no calibration)

In the picture above, we see that "touch panel values frame" differs from "touch panel physical size frame". When we are pressing the touch we are moving in the "touch panel physical size frame" but when the touch screen is not calibrated the arrow from XBMC is in another place.
  • "touch panel physical size frame" is the screen starting from (0,0) on the left top corner and going to (width, height) in the right bottom corner.
  • "touch panel values frame" is the frame which contains all the number the touch controller is giving.
We see that these frames differs a lot. Our main scope is to overlap the "touch panel values frame" to the "touch panel physical size frame".

In order to do this we need to do three steps(the third one is done in software):
a. Scale the value read from the touch driver x and y) in order to fit 0->width range and respectively 0->height range of the "touch panel physical size frame" the scale value for x axis is:
                       "touch panel physical size frame" width
calib_x_fact = -------------------------------------------------
                            "touch panel values frame" width


                       "touch panel physical size frame" height
calib_y_fact = -------------------------------------------------
                            "touch panel values frame" height

"touch panel values frame" width and height are coming from your XBMC resolution(I have height=1280 and height=720).
"touch panel physical size frame" width and height are a little more trickier to find but nothing hard. In step 2 above, you have calibrated the touchscreen in XFCE. You got some values returned by xinput_calibrator, something like:
Section "InputClass"
    Identifier   "calibration"
    MatchProduct    "eGalax Inc. USB TouchController"
    Option    "Calibration"    "1977 32 1893 131"
EndSection
In my case,
"touch panel physical size frame" width is 1977 - 32 = 1945
"touch panel physical size frame" height is 1893 - 131 = 1762
Now, compute the values and put them in /usr/share/eGalaxCalibration/touchscreen_axes_calib file

b. Translate the "touch panel values frame" to the left and up, to match "touch panel physical size frame".
I didn't find a logical method to do this, because we don't know exactly "where is" the "touch panel values frame", so, in order to find calib_x_d and calib_y_d you have to first set them both to zero and then start XBMC. Now, put some sharp pointer on the screen and observe the distances between the cursor on the screen and your pointer's position. Try to approximate these x and y deviations(measured in pixels) and put them in the /usr/share/eGalaxCalibration/touchscreen_axes_calib file.

c. Revert direction of axes. This is done in the software(from patches).

4. Math behind.
To accomplish these transformations the following formula was implemented in the file
xbmc/input/linux/LinuxInputDevices.cpp
pointer.x = screen_width - value_read.x * calib_x_fact - calib_x_d;
pointer.y = screen_height - value_read.y * calib_y_fact - calib_y_d;

After I have successfully calibrated the touchscreen I have discovered that single click was not possible from the touchscreen, just double click. After digging through the code, I have found that this was caused by drag action which was triggered because the previous values of the touch were far(more than 5 pixels) from a new press. For example, at the start of the program, cursor is set at 0,0 coordinates; if user is trying to press a button, let's say at 100, 300, the program will calculate the distance between these two points and will find out that this is greater than 5.
(100-0)x(100-0) + (300 - 0)x(300-0) is greater than 5x5
This works when you double click, because the previous point in the second click action is very close to the second click point. This also works for mouses, because the previous value of the pointer is always very close to the new value of the pointer(because mouse's pointer drags on the screen and it doesn't jump).

I have developed an algorithm to avoid this issue:
When the user is pressing the screen(x,y), the touch values are being set to (screen_width+1, screen_height+1 -> outside of the visible screen) just at the first event read(which is BTN_TOUCH PRESS).
After this event, the program will receive multiple X and Y absolute values events. The first two events, one for X and one for Y are used to set the previous X value, respectively previous Y value to the current X respective current Y values. And from now on distance is measured and this is preventing no unwanted drag action.
The user's finger/pointer will not stay at a single point, because the touchscreen's lack of precision, so it will move around 5-6 pixels in x and y directions.
I have also set the click distance to 7. You can change this by changing click_confines value in xbmc/input/MouseStat.h. Originally it was set to 5, but this is not very good for touch screens(I had to click with a sharp pointer and with my nail always, but with a value of 7 I can click with my finger with a slight touch -> really nice).

Enjoy!

CarPC first build

$
0
0
Hi!

After working a lot at my CarPC project I have decided to take a break and post about it.

A short preview is here:

You can download my 4GB image from here
If you want to build it by yourself please follow my previous tutorials but replace the three patches with the single patch from here, which is for XBMC12.2. Also read my previous post to find how to calibrate the screen axes.

Features:
  • auto start XBMC
  • eGalax touch screen support with configurable greater area for touch event(8 pixels)
  • improved skin with larger buttons and smooth transitions(link for the skin)
  • System Power OFF button
  • usbmount enabled(so usb MSD's are plug and play)
The new calibration file contains one more entry: click_confines which defines the area for XBMC to distinguish between click and drag actions(touch moves less than 8 pixels before release than action is click, else the action is drag).

Have fun!
Andrei

Car PC project(August 2013 update)

$
0
0
This is an update for my CarPC project.


The main features are:
Hardware:
Software:
[Operating System]
    - Raspbian Wheezy 9.February.2013
    - Custom kernel 3.6.11
        - eGalax touch screen module
        - si470x usb radio module
        - snd-usb-audio module

[Media Center]
    - omxplayer
    - XBMC 12.2 Frodo
        - sources with objects build on 27.July.2013
        - skin: CarPC-touch
            - system shutdown button
            - system restart button
            - reload skin button
            - switch to camera view button
        - modified spectrum analyzer(OpenGL with no rotation)
        - eGalax touch screen calibrated
        - eGalax touch screen click&drag fix
        - black rectangle behind XBMC removed
        - patch to add getMousePosition feature to xbmcgui module(used to redirect clicks from the Navigation skin page to X11 using xdotool)

[Navigation]
    - Navit build from source
    - Zoom In, Zoom Out buttons
    - Click sent from XBMC to X11 (Navit Window)

Car Modding
I had to relocate my original Radio/CD player in the trunk and keep it set on aux input source. This included buying about 60m of wires and also harness:
1. Metra 71-9003 Bmw Mini Factory Radio OEM Wire Harness
2.Scosche VW03B 2002+ Vw Audi BMW Radio Stereo Harness

 front without OEM Radio/CD player
trunk with relocated OEM Radio/CD player
Mounted Raspberry PIin the armrest
Safety:
    - The wires are 2mm in diameter with good insulation, resistant at temperature variations
    - I have added fuses(1.5A for the radio, 1A for Raspberry PI, 1A for display, 0.1A for reverse camera trigger, 0.1A for reverse camera video signal)

Bugs:
     - sound pops(will soon disappear by using this hdmi to hdmi and audio splitter)
    - Navigation is behind Video Player -> Navigation isn't visible while playing videos

OpenElec with support for eGalax touch screen

$
0
0
Hi!

Lately I have tested OpenElec for Raspberry PI and found out that it is very very fast, very very small and also it has some great addons(wifi, bluetooth and more).
Speed/size features on an 512MB RaspberryPI:
  - a complete boot is less than 25 seconds
  - cpu is around 30% load
  - memory used is 32%
  - total system size is less than 300MB

Next, I will guide you through the instructions for building(cross compile) latest OpenElec  for Raspberry PI with touch screen support.
For this tutorial let's assume that you have a Linux machine where you will work.

1. Get the latest OpenElec.
git clone git://github.com/OpenELEC/OpenELEC.tv.git

2. Add kernel touch screen module support.
Open the file OpenELEC.tv/projects/RPI/linux/linux.arm.conf and search for "CONFIG_INPUT_TOUCHSCREEN". Replace the whole text line with the following lines:
CONFIG_INPUT_TOUCHSCREEN=y
CONFIG_TOUCHSCREEN_USB_COMPOSITE=m
CONFIG_TOUCHSCREEN_USB_EGALAX=y
CONFIG_TOUCHSCREEN_USB_PANJIT=y
CONFIG_TOUCHSCREEN_USB_3M=y
CONFIG_TOUCHSCREEN_USB_ITM=y
CONFIG_TOUCHSCREEN_USB_ETURBO=y
CONFIG_TOUCHSCREEN_USB_GUNZE=y
CONFIG_TOUCHSCREEN_USB_DMC_TSC10=y
CONFIG_TOUCHSCREEN_USB_IRTOUCH=y
CONFIG_TOUCHSCREEN_USB_IDEALTEK=y
CONFIG_TOUCHSCREEN_USB_GENERAL_TOUCH=y
CONFIG_TOUCHSCREEN_USB_GOTOP=y
CONFIG_TOUCHSCREEN_USB_JASTEC=y
CONFIG_TOUCHSCREEN_USB_ELO=y
CONFIG_TOUCHSCREEN_USB_E2I=y
CONFIG_TOUCHSCREEN_USB_ZYTRONIC=y
CONFIG_TOUCHSCREEN_USB_ETT_TC45USB=y
CONFIG_TOUCHSCREEN_USB_NEXIO=y
CONFIG_TOUCHSCREEN_USB_EASYTOUCH=y

3. Fix ppl version in OpenElec.
Open the file OpenELEC.tv/packages/toolchain/math/ppl/meta and change PKG_VERSION from "1.1pre9" to "1.1pre10"

4. Put touch screen calibration file into the system.
Navigate to folder OpenELEC.tv/projects/RPI/ and create the file usr/share/eGalaxCalibration/touchscreen_axes_calib. This file should have the following contents:
calib_x_d=-21;calib_x_fact=0.658097686;calib_y_d=-50;calib_y_fact=0.408626561;swap_axes=0;click_confines=8
To set up these values please visit this post(at section 4).

5. Put XBMC 12.2 patch.
Get my latest patch from here, rename it to xbmc-300-eGalaxPatch.patch and put it in the folder OpenELEC.tv/packages/mediacenter/xbmc/patches/12.2-18397e1

6. Build OpenElec.
Navigate to OpenElec folder and type:
PROJECT=RPi ARCH=arm make -j3
-j3 option is to use parallel build(if you have more than one cpu's set this number as nb_cpus+1). This option will speed up the build process.
The build process will take couple of hours, but you have o come back once(in the first 10 minutes) and press ENTER for the kernel touch screen modifications to be approved.

7. Install or Update your OpenElec card.
Go to OpenElec build instructions page for RPI and follow the "Install instructions" chapter.

Have fun!

Keep your linux clock synchronized with gps time

$
0
0
A big problem for a CarPC is that you need a real time clock to synchronize your system with.
For my CarPC, I don't have any RTC module on Raspberry PI, but I do have a gps always connected, which provide accurate date and UTC time.
I have found some tutorials on how I can set up ntp to update the system clock based on gpsd but they didn't worked with any of my gps devices:
ST22 SkyTraq GPS receiver
Columbus V-800
I have followed some links with no luck. I got:
"gpsd:WARN: can't use GGA time until after ZDA or RMC has supplied a year."
or
"gps data is no good"
or
"unrecognized ... sentence"

I have decided to make my own time synchronization based on parsing raw gps data.
You can download an archive containing the scripts from here.

How does it work?
First connect your gps module:
gpsd /dev/ttyAMA0
Then, to get the raw data I used:
gpspipe -R -n10
This command will get the first 10 lines from gps raw data. I got this:
pi@raspberrypi ~ $ gpspipe -R -n10
{"class":"VERSION","release":"3.6","rev":"3.6","proto_major":3,"proto_minor":7}
{"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyAMA0","activated":"2013-10-06T09:42:18.793Z","flags":1,"driver":"Generic NMEA","native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}]}
{"class":"WATCH","enable":true,"json":false,"nmea":false,"raw":2,"scaled":false,"timing":false}
$GPGGA,094220.784,4425.1141,N,02602.8254,E,1,05,1.6,96.1,M,37.0,M,,0000*6D
$GPGSA,A,3,25,05,29,31,21,,,,,,,,3.1,1.6,2.7*3A
$GPGSV,3,1,09,29,61,061,29,21,58,214,37,25,41,146,38,31,33,245,35*72
$GPGSV,3,2,09,05,25,056,30,16,14,314,,18,09,170,19,12,04,138,20*76
$GPGSV,3,3,09,06,02,278,*49
$GPRMC,094220.784,A,4425.1141,N,02602.8254,E,000.0,191.5,061013,,,A*6E
$GPVTG,191.5,T,,M,000.0,N,000.0,K,A*01
The Shell part.
To set UTC time for our unix system we have to issue a command like this:
date -u -s "2013/10/05 12:48:00"
From the raw gps output, we see that GPRMC gives all the needed information about the date and time(see here what the fields mean).
My idea was to capture just GPRMC data from this output and send it as a parameter to a C program which will parse the string and create a new string as needed to set time.
To get the GPRMC string from the raw gps output I have did the following bash command:
gpspipe -R -n10 | sed -n "/GPRMC/,/*/p"
Decomposition of the command:
gpspipe -R -n10 - this outputs the first 10 lines from the gps raw output.
sed -n "/GPRMC/,/*/p" - extracts the line starting with the string GPRMC
I have used unix pipes(| character) to pass the output from gpspipe -R -n10 to the sed command.
The output from this command will be like this:
pi@raspberrypi ~ $ gpspipe -R -n10 | sed -n "/GPRMC/,/*/p"
$GPRMC,100201.786,A,4425.1179,N,02602.8192,E,000.0,191.5,061013,,,A*61
$GPVTG,191.5,T,,M,000.0,N,000.0,K,A*01
 Now, to pass this as program arguments(assuming the program's name is set_date) we have to do the following:
./set_date 21 $(gpspipe -R -n10 | sed -n "/GPRMC/,/*/p")
The C program part.
In this example, argc will be 4 and argv will be as follows:
argv[0] - "./set_date"
argv[1] - "21"
argv[2] - "$GPRMC,100201.786,A,4425.1179,N,02602.8192,E,000.0,191.5,061013,,,A*61"
argv[3] - "$GPVTG,191.5,T,,M,000.0,N,000.0,K,A*01"

The GPRMC output gives 100201 for time and 061013 for date. This means:
UTC time is 10:02:01 and date is 06 October 2013. GPRMC does not provide the full year, so we have to provide the century as an argument to the C program to compute the correct date.

We are only interested in argv[1] and argv[2], so, in the C program we will convert argv[1] to int using atoi(argv[1]) and we will have the century and after this we have to parse argv[2] using sscanf to get the two numbers for time: 100201 and for date 061013. Let's assume we got these numbers in two uint32_t variables:
rawDate = 61013
rawTime = 100201
To get useful data from here we have to do this:
hour = timeRaw / 10000;
minute = (timeRaw % 10000) / 100;
second = (timeRaw % 10000) % 100;

century = atoi(argv[1]);
day = dateRaw / 10000;
month = (dateRaw % 10000) / 100;
year = (century - 1) * 100 + (dateRaw % 10000) % 100;
After this, to create the command we can use sprintf to put everything in an outputBuffer and then call system(outputBuffer) to execute the command.

Control XBMC from the Raspberry PI GPIO's

$
0
0
I have recently worked on adding external controls for my Raspberry PI CarPC project because while driving it is better to have some physical controls to rely on, rather than looking at the touch screen to find the buttons.
This post provide information on how to set up buttons or rotary encoders to control XBMC from Raspberry PI.

Rotary encoder
Rotary encoders are very cheap and very nice controls(eBay link). You can find them in car stereos for volume control. You can also use them to browse through menu items or to skip to next song etc.
They are looking very similar to a potentiometer, but there are major differences: they can be turned in both directions with infinite steps(you know just the direction of the spin), they provide digital output, a full rotation have a number of steps and they have push button also.
Connections for Raspberry PI should be done as follows:
    + pin to 3.3V
    GND pin to Raspberry PI GND
    SW to one GPIO
    CLK and DT to two GPIOs
When the push button is pressed the pin labelled SW is connected to GND. This can be set up as any push button(see below).

Push button
A push button can have two states on or off. There are two ways to hook up a button to a logical circuit(e.g Raspberry PI GPIO's):
We have to use the first setup(with pull up resistor) for the tool to work properly. So, for the push button of the rotary encoder above, we have to cable it like this:
 
The tool
I have created a tool to allow you interface rotary encoders(and also push buttons) with Raspberry PI GPIO's. Also you can set an XBMC command to be executed for click, left rotation and right rotation.
The tool can be otbained from my Google Code project(link to page).
It is very easy to use it. You just have to accomplish two steps:
    - copy rpi-xbmc-remote in a place where it can be accessed from anywhere(e.g. /usr/bin)
    - call it using sudo rpi-xbmc-remote /path/to/configuration/file

The configuration file
Example:

ip:localhost

button:7:KB:return

encoder:clk:23:KB:up:dt:24:KB:down
The configuration file can reside anywhere on the disk. It provides a way to define two kind of inputs for XBMC: regular button and rotary encoder.Lines should be less than 100 characters in length. Lines starting with # are comments and are not being processed.
 

Example of regular button definition: 
button:7:KB:return
    - 'button' means it is a regular button
    - '7' means use GPIO7 for this button
    - 'KB' means XBMC device map
        "KB" - Standard keyboard map
        "XG" - Xbox Gamepad
        "R1" - Xbox Remote
        "R2" - Xbox Universal Remote
        "LI:devicename" - valid LIRC device map where 'devicename' is the actual
name of the LIRC device
    - 'return' means XBMC button name to be called(see XBMC keymaps)

Example of rotary encoder definition:

encoder:clk:23:KB:up:dt:24:KB:down
    - 'encoder' means it is a rotary encoder
    - '23' means use GPIO23 for rotary encoder CLK
    - 'KB' means XBMC device map for rotary encoder left turn(same as above)
    - 'up' means XBMC button name to be sent for left turn of the rotary encoder
    - '24' means use GPIO24 for rotary encoder DT
    - 'KB' means XBMC device map for rotary encoder right turn(same as above)
    - 'return' means XBMC button name to be called(see XBMC keymaps)

Keep in mind!
You have to put a pull up resistor for every push button you define in the configuration file. If you don't do this then the state of the button will be variable when not pressed(it will oscillate between 0 and 1) and it will behave like it is pressed randomly.


Have fun!

OpenCarPC

$
0
0
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

openCarPC controller v1.1

$
0
0
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!

Raspberry PI CarPC April 2014 updates

$
0
0
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.

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:


Raspberry PI CarPC September 2014 updates

$
0
0
Hello!

I have made some progress on my CarPC project and here are the main changes:
- support for Raspberry PI Model B+
- update XBMC to 13.2 stable
- update kernel to 3.16.0
- reworked radio(rds is available but not yet enabled because of some high cpu usage - will fix this shortly)
- update system available(only ~150MB for download instead of a whole image)
- file system restructuring
- new skin
- forum released(Engineeryng-Diy Forum)

First of all the installation process(this is only for a fresh install, update coming soon):
- write a fresh image with the latest Raspbian from http://www.raspberrypi.org/downloads/
- copy the carpc folder in /home/pi/ on the SD card(gt this folder from my Downloads page/updates)
- plug the image in RPI and start it
--- use the auto menu to expand file system
--- change password to 'a'
--- enable boot into desktop-> Desktop Log in as user 'pi' at the graphical desktop
--- enable ssh, disable overscan, disable serial messages
--- Change Internalisation Options -> Locale and Timezone to your country
- connect a keyboard and open the terminal or connect using ssh
- change user permissions for pi: sudo chmod -R a+rwx /home/pi
- type cd /home/pi/carpc/ and then ./carpc-install.sh and then wait for the system to install
Note! If you get Cannot mkdir: Permission denied running this script then you should type sudo chmod -R a+rwx /home/pi/carpc/ and then run the script again.
- after this, you should reboot(sudo reboot)

Calibrate the touch screen
Forget about xinput-calibrator and X11 calibration metods.
If you have calibration file(/home/pi/touchscreen_axes_calib) from a previous installation you can use it.
If you don't, then use the touch screen calibration plugin. This plugin works if you set correctly the Raspberry PI resolution in /boot/config.txt. Follow the steps in this video.

Add a map for navigation
Go to Navit Planet Extractor and download a .bin file for your area.
Copy the .bin file in your RPI card in /home/pi/.navit/ folder. Rename the .bin file to map1.bin, map2.bin, map3.bin or map4.bin.

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.
You can set the configuration file like in this post.

Change the car logo in the Home screen
The car logo is a png file in /home/pi/config/logo.png.

New skin
Thanks to Doru, a new skin is available: CarPC-touch_carbon.

Comments moving to forum
From now on, a forum is available for any issues/suggestions(http://engineeringdiy.freeforums.org/). Due to this, comments on this blog will be disabled.

Have fun!
Andrei

Raspberry PI CarPC November 2014 updates

$
0
0
Hi,

I have made a new release of the CarPC software for Raspberry PI.
Updates:
 - RDS radio support(new radio application)
 - new application for managing everything on GPIO which takes about 3% of cpu(gpio interrupts are now used instead of polling mechanism)
 - new FM Radio XBMC addon
 - kernel 3.17.0
 - optimised Navit and XBMC priorities to remove hang times

Minor issues:
[Radio FM addon]: I tried different ways to set the height of the height of an item in xbmcgui.ControlList but it seems that nothing is working(I have tried adding as a parameter and also using setItemHeight). If you have any other idea please let me know.

In order to have RDS working pin22(GPIO25) from RPI should be connected to Radio(SI4703) GPIO2 pin. This is the full schematic for one SI4703 radio module and two rotary encoders:

Grab the latest update from here.

Installation instructions are in the README inside the archive. Don't forget to(sudo apt-get update & sudo apt-get upgrade).
For any issues please use the Forum to avoid filling this blog with comments.


Have fun and keep your eyes on the road while driving!

RaspberryPI CarPC tutorial

$
0
0

1. Installation process(fresh install):
- write a fresh image with the latest RaspbianOS image from http://www.raspberrypi.org/downloads/
- copy the carpc folder in /home/pi/ on the SD card(get the latest release archive from my Downloads page/updates)
- plug the image in RPI, connect an USB keyboard and start it
--- use the auto menu to expand file system
--- change user password
--- enable ssh, disable overscan, disable serial messages
--- change Internalisation Options -> Locale and Timezone to your country
--- expand disk size to at least 4GB
--- enable Boot to Console(mandatory)
- restart
- type cd /home/pi/carpc/ and then ./carpc-install.sh and then wait for the system to install
- after this, you should reboot(sudo reboot) and the system should start

2. Calibrate the touch screen
Forget about xinput-calibrator and X11 calibration metods.
If you have calibration file(/home/pi/touchscreen_axes_calib) from a previous installation you can use it(put it in /home/pi/).
If you don't, then use the touch screen calibration plugin. This plugin works if you set correctly the Raspberry PI resolution in /boot/config.txt. Follow the steps in this video.

3. Add a map for navigation
Go to Navit Planet Extractor and download a .bin file for your area.
Copy the .bin file in your RPI card in /home/pi/.navit/ folder. Rename the .bin file to map1.bin.

4. Setup the GPS receiver
Open the file /home/pi/startup/StartCarPC and find the line gpsd /dev/ttyAMA0
Replace /dev/ttyAMA0 with your gps device file name. Here is how to find the file name:
  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, using UART TX/RX pins the device will have the file name /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.

5. 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.

6. Add FM Radio module, physical buttons or physical rotary encoders
Here is my hardware schematic containing:
 - SV1 - Raspberry PI B, B+ connector
 - RADIO - SI4703 breakout board
 - RE1 and RE2 - two rotary encoders
CarPC hardware set-up example
Each function of push buttons, rotary encoders can be configured using the Controller, like in the step below.

7. Configure the Controller

Modify the configuration file(/home/pi/config/gpio_description) like in this post.

8. Set the car logo in the Home screen
Put your car logo .png image in /home/pi/config/logo.png.

9. Skin
Thanks to Doru we have CarPC-touch_carbon.

10. Issues
The forum is available for any issues/suggestions.


Have fun!
Andrei

Raspberry PI CarPC January 2015 updates

$
0
0

Hi,
Here are the updates I have recently worked on:
 - migration to KODI stable 14.0
 - Raspbian OS from 24 december 2013
 - linux kernel 3.18.1 with touchscreen drivers
 - updates to Radio and Navigation addons

You can install the build using the tutorial link on the right side of the blog. Please don't forget about the forum for any comments.

Enjoy the screenshots and Happy new Year!







Raspberry PI 2 CarPC

$
0
0
Hi,

Here are the updates I have recently worked on:
 - Raspberry PI 2 support
 - KODI 14.1
 - linux kernel 3.18.7-v7 with touchscreen drivers(thanks to Chris Coat)
 - radio backend fixed to support RDS RadioText and better RDS StationName
 - interrupts are coming from WiringPI C library instead of Python via sockets
 - new skin from Doru(new Skin Settings page)
 - CarPC folder now lives in /opt/ instead of /home/pi/
 - boot process schematic
 - code is moving to github(https://github.com/bboyandru/)

You can install the build using one of the two tutorials:
 - advanced users guide
 - beginner users guide (thanks to Piero Longega)

Please don't forget about the forum for any comments.

Some screenshots:
Home screen

 
FM radio with RDS

Kodi Settings page

Skin Settings

Skin Settings - Buttons


Enjoy and keep your eyes on the road while driving!