Author: thepragmaticmonk

I am a guy, who believes pragmatically, we can make our lives simpler and clutter-free. Most of my articles would be straightforward and have minimum twist and dreamy angles.

eGalax touchscreen and Banana Pi and Raspbian OS

I have been using an eGalax Touchscreen monitor with my Raspberry Pi, for a while. With the new Banana Pi board, I wanted to use the same eGalax TS Monitor and try my web kiosk project. After a lot of research and trials,I finally came up with a much more straight forward and simple tutorial, that explains the steps, as in detail, as possible.

Setup specs:

Build PC:
Intel core i3@2.4GHz
4GB RAM
Ubuntu 14.04 LTS 32-bit Desktop OS
HDD space available: 120GB
2/4MBits internet

Banana Pi:
SD card: 8GB class 10 SDHC UHS-1
2A power supply via microUSB DC IN.
A/V output by: HDMI
TS i/o by: USB
US Keyboard

Prologue:
Download the “Raspbian_For_BananaPi_v3.1” file from here and burn it on a good SD card with sufficient space(at least 4GB) and speed(at least class 4). If you need help in installing the image onto the SD card, follow the instructions given here.

Verify if the SD card is bootable or not. While booting, you should see the green led on the board blink often and texts start appearing in your monitor and finally a Desktop interface appears.

The default login details are:
username: bananapi
password: bananapi

Shutdown the bananapi and insert the SD card in your computer’s SD card reader, running a linux OS.

Now, we are ready to start building the modified OS kernel.

Step 1:
Install the cross-compiler tools.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential u-boot-tools uboot-mkimage binutils-arm-linux-gnueabihf gcc-4.7-arm-linux-gnueabihf-base g++-4.7-arm-linux-gnueabihf gcc-arm-linux-gnueabihf cpp-arm-linux-gnueabihf libusb-1.0-0 libusb-1.0-0-dev git wget fakeroot kernel-package zlib1g-dev libncurses5-dev

Note: If you are using later versions of linux, uboot-mkimage would have been replaced by
u-boot-tools. You can remove the uboot-mkimage from the install list.

Step 2:
Create a directory where you will build the OS.
mkdir newos

and cd into it.
cd newos

Step 3:
Download the BSP packages
git clone https://github.com/LeMaker/bananapi-bsp.git
took about 5-10 seconds.

Step 4:
Compile everything.

cd bananapi-bsp
./configure Bananapi

Once the configure script finished without any errors, then do:
make linux-config

It will download bananapi packages from git, which took about 1-2 hours on my system and then menuconfig would open automatically.
In the menuconfig screen, go to:

Device drivers->Input Device Support->Touchscreens->USB Touchscreen Driver

Mark the “USB Touchscreen Driver” option as built-in by pressing the ‘Y’ key, i.e. a * symbol in the []s alongside the option, should appear.
NOTE: Do not select the “EETI eGalax multi-touch panel support” option.

Press ESC key again and again, until you get a dialog box asking if you want to save the configuration changes. Select the YES option.
The build will continue and complete, in a few seconds.

Now, on the command line, issue
make

It will build the USB touchscreen driver into the kernel and take about 10-15 minutes(as in my system) to complete.

Step 5:
Copy the kernel components to your SD card:

sudo cp build/Bananapi_hwpack/kernel/uImage /media/username/boot
(first FAT partition of the SD card)
sudo cp build/Bananapi_hwpack/kernel/script.bin /media/username/boot

Step 6:
Copy the new compiled library modules & firmware

sudo cp -r build/Bananapi_hwpack/rootfs/lib /media/username/disk2
(Second EXT4 partition of SD card)
sudo cp -r build/Bananapi_hwpack/rootfs/etc /media/username/disk2

Step 7:
Unmount/Eject the SD card and boot it with Banana Pi.
Check if, your touches on the Desktop screen, moves the mouse cursor and then use your calibration program(for eg. eCalib), if necessary, to calibrate the TS inputs.

References:
#1: http://forum.lemaker.org/viewthread.php?tid=1706
#2: http://forum.lemaker.org/1562-1-1-egalax_touchscreen_and_banana_pi.html

Of CodeLite and Boost libraries

The fastest way to start writing wxWidgets and C/C++  code is to get the CodeLite IDE. Its open source, free and supports multiple OSes. And add the Boost C++ library into the mix, you can build some really good cross-platform applications. While, wxWidgets comes pre-configured with CodeLite installer ,  for Boost,  we need to manually link up stuff.

Here’s the clear and up-to-date information on how to setup boost with codelite, in Windows.

Before we begin:

  1. Download the “CodeLite 5.4 Installer for Windows (8, 7, Vista and XP) with MinGW TDM-GCC 4.8.1 included”  package located here(http://downloads.codelite.org/).
  2. Download a suitable version of “7z for Windows” from here(http://www.7-zip.org/download.html) and Install it on your system. I recommend 7-Zip 9.20 version.
  3. Download boost sources, available as “boost_1_55_0.7z” from here.(http://sourceforge.net/projects/boost/files/boost/1.55.0/)

Now, follow the following steps:

    1. Extract the codelite-5.4-mingw4.8.1.exe file from the codelite-5.4-mingw4.8.1.exe.7z file, that you just downloaded and run the setup.NOTE: You must install codelite to a path that does NOT contain any spaces or parentheses, eg: C:\mycodelite
    2. Extract the boost_1_55_0.7z to a path that does NOT contain any spaces or parentheses, eg: C:\myboostdir
    3. Tell CodeLite where to find boost libs:
      Go to Settings > Build Settings… > Compilers Tab
      Select the “gnu g++” option and click on the plus sign to expand the option >
      Select “Advanced”
      Then,
      In “Include Paths” textfield, add the path where the boost libs would be available, in this case:
      C:\myboostdir
      In “Libraries Paths” textfield, fill in the path above, i.e. C:\myboostdir.
      Click “Ok” and close the dialog box.
    4. In CodeLite , Press Alt+W and then N, to Create a New workspace.
      In the “New Workspace” dialog box, fill in the “Workspace name” and select a proper path for the project.
      Again, preferably the project path should not contain any spaces and parentheses.
      Press the “Create” button.
    5. Then, in the new workspace, press Alt+W and then P,to Create a new project.
      In the “New Project” dialog box, select the Template->Console->Simple executable(g++) and fill in a project name in the “Project name” field and click on “Ok”.
    6. In the workspace view, select the main.cpp file and paste the below code.

      #include <boost/lambda/lambda.hpp>
      #include <iostream>
      #include <iterator>
      #include <algorithm>

      int main()
      {

      using namespace boost::lambda;
      typedef std::istream_iterator in;
      std::for_each(
      in(std::cin), in(), std::cout << (_1 * 3) << ” ” );
      return 0;

      }

    7. Press F7 to build the project.
      * If you see no build errors, you’re good to go, to the next step.
      * If you see 1 or 2 warnings, especially pertaining to the boost headers, ignore them. (Reference: http://www.boost.org/doc/libs/1_55_0/more/getting_started/windows.html#errors-and-warnings) else you should look at the steps 1 to 5 above again.
    8. To test your application, open a cmd window:
      * Press Win + R . In the Run dialog box, type in “cmd”, without quotes and press enter.
      * cd to the directory where the project was created in.
      * cd to the Debug directory.
      * Run the executable file in that directory as follows:codelite test

If you get the output as in image above, you have setup codelite correctly, so far. If you don’t check the code carefully or review the steps 1 to 7.

Now, if you want to use any of the separately-compiled Boost libraries, you’ll need to build and install it. To do this:

    1. Go to the directory tools\build\v2\
    2. Run bootstrap.bat
    3. Run b2 install –prefix=PREFIX where PREFIX is the directory where you want Boost.Build to be installed, eg: C:\myboostdir\builddir
    4. Add PREFIX\bin to your PATH environment variable.
    5. Then, cd to the Boost root directory(C:\myboostdir) and invoke b2 as follows:
      b2 -j 4 toolset=gcc link=static --with-system --with-thread --with-date_time --with-regex --with-serialization stage debug

      NOTE:The above b2 command will setup basic libraries to use with boost.asio.
      If you intend to build the complete set of libraries, you should run(This may take about 2-3 hours or more, depending on computer hardware specs):
      b2 -j 4 toolset=gcc --build-type=complete stage
      To see an exhaustive list of options, refer: Boost.build documentation at http://www.boost.org/boost-build2/doc/html/bbv2/overview/invocation.html
    6. Go to the workspace view and there select your “Project” and right-click on it. Go to the “Settings” menu item. In Settings dialog box, edit the “Library Paths:” and the “Libraries:” as shown in the screenshot below.
      codelite settings
      Press “OK” and close the dialog box.
    7. Replace the code in the main.cpp with the one below:
      #include <boost/regex.hpp>
      #include <iostream>
      #include <string>int main()
      {

      std::string line;
      boost::regex pat( “^Subject: (Re: |Aw: )*(.*)” );
      while (std::cin)
      {

      std::getline(std::cin, line);
      boost::smatch matches;
      if (boost::regex_match(line, matches, pat))
      std::cout << matches[2] << std::endl;

      }

      return 0;

      }

    8. Press F7 to build the project.
    9. In the open cmd window, cd to the directory where the project was created in.
      * cd to the Debug directory.
      * run the executable file in that directory as shown in the screenshot below:
      boost and codelite

If you see the output as shown above, you have a working boost + codelite system. Congratulations!

Please do drop in a comment and let me know how it goes.

Reference:     http://www.boost.org/doc/libs/1_55_0/more/getting_started/windows.html

Configure eth0 on Raspberry Pi

Connecting my RasPi to my home LAN, was quite easy. Although, the no. of ways I could connect them together are many,  I decided to go the old-school way. Simply connect the Ethernet port of my Router and RasPi , via a straight through cable and get started. My router had already been assigned an IP address, i.e.  192.168.137.1

The next thing I had to do was configure the eth0 interface on my RasPi and assign it a static IP.

These are the steps I followed:

    1. Open the network interfaces file:
      sudo vi /etc/network/interfaces
    2. In there, replaced the following lines:
      auto eth0 
      iface eth0 inet dhcp
      with this:
      auto eth0
      iface eth0 inet static

      address 192.168.137.2
      netmask 255.255.255.0
      gateway 192.168.137.1
      nameserver 192.168.137.1

    3. Then opened resolv.conf file:    sudo vi /etc/resolv.conf
    4. In the file, removed all lines and typed in only this line:
      nameserver 192.168.137.1
      Where, 193.168.137.1 is my gateway, which would help me to connect my RasPi on LAN, with internet.
      Save the file and exit the file editor.
    5. Now in terminal, restart the network interfaces:
      sudo networking restart
    6. Then ping my gateway:
      ping 192.168.137.1
      If it pings, then, ethernet interface is ready to use, else you  should reboot RasPi and retry pinging again.

Using RTC PCF8563 on Raspberry PI running Raspbian OS

I built the RTC circuit. Now, I had to start using the “RTC to keep time, in Raspbian OS”! Well,after a bit of digging and experiment, here’s what I did.

I used a PCF8563 RTC with Raspberry Pi Model B, running latest version of Raspbian OS (Release date: 2014-01-07).

NOTE: RTC PCF8563 is supported in the latest Raspbian OS kernels. No need to build a custom kernel.

  • First, sudo vi /etc/modprobe.d/raspi-blacklist.conf
    • Then, comment out the following lines, by prepending them with a # character:
#blacklist i2c-bcm2708
  • Second, you need to configure to load modules at startup.
    • Open the file: sudo vi /etc/modules
    • Add the following lines, at the end of the file:
      i2c-bcm2708
      i2c-dev
      rtc-pcf8563
  • Install i2c-tools:
    sudo apt-get install i2c-tools

    and then REBOOT

  • After reboot, check to see if your h/w is connected and working:
    sudo  i2cdetect -y 1

    If your h/w is working you should see a 0x51 in the output of the above command.

  • Now, you need to add the rtc clock to work right at every boot:
    • Open /etc/rc.local:    sudo vi /etc/rc.local
    • Add the following lines, right before the line containing exit 0 (the exit 0 should be the last line of the rc.local file)
      modprobe i2c-bcm2708
      echo pcf8563 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
      modprobe rtc-pcf8563
      hwclock -s
    • Now reboot again.
  • To change the date in rtc:
    • Check the current date and time in Raspbian OS: date
    • Set the date and time in your Raspbian OS(you should have set the correct timezone, before this step):

date -s "MMM DD HH:MM:SS"

Where, MMM=first 3 letters of months, DD=new date and HH:MM:SS = 24 hr format hours:minutes:seconds.
You should enclose the parameters, within double quotes. For more information check man page of date.

  • To view the current date and time stored in the RTC Pi:   hwclock -r
  • Set the Linux system time to the value in the RTC Pi:   hwclock –s
  • To set the RTC Pi with a custom time directly, use:

hwclock --set --date="2014-12-25 00:00:00" --utc
and then use:
hwclock --hctosys

For more information about hwclock, refer the man page.

  • Done!