<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Using Android in Industrial Automation</title>
	<atom:link href="http://android.serverbox.ch/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://android.serverbox.ch</link>
	<description>Technical Blog of Nexus-Computing GmbH Switzerland</description>
	<lastBuildDate>Sat, 04 May 2013 15:25:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Embedded Android Tutorial: Part II, Setting up the Arduino to measure light intensity and reconfigure the Pandaboard&#8217;s kernel for communication</title>
		<link>http://android.serverbox.ch/?p=792&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=embedded-android-tutorial-part-ii-setting-up-the-arduino-to-measure-light-intensity-and-reconfigure-the-pandaboards-kernel-for-communication</link>
		<comments>http://android.serverbox.ch/?p=792#comments</comments>
		<pubDate>Sat, 04 May 2013 15:25:15 +0000</pubDate>
		<dc:creator>Andreas Rudolf</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=792</guid>
		<description><![CDATA[In this post we are going to set up the Arduino Uno to measure light intensity. Furthermore, we configure and recompile the Pandaboard&#8217;s kernel to communicate with the Arduino Uno through USB-serial. For measuring light, we will require some kind of photoresistor. If you do not have any spare ones around, you can easily get [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=792"></g:plusone></div><p>In this post we are going to set up the <strong>Arduino Uno to measure light intensity</strong>. Furthermore, we <strong>configure and recompile the Pandaboard&#8217;s kernel to communicate with the Arduino Uno</strong> through USB-serial.</p>
<p>For measuring light, we will require some kind of <strong>photoresistor</strong>. If you do not have any spare ones around, you can easily get them on ebay. A photoresistor is a resistor that <strong>changes its resistance depending on the current light</strong> intensity. In the end, we will simply measure an analogue voltage that changes depending on the attached photoresistor.</p>
<p><strong>For this tutorial you will need:</strong></p>
<ul>
<li>Pandaboard with Linaro&#8217;s Android build from Part I</li>
<li>Arduino Uno</li>
<li>1 Photoresistor</li>
<li>1 Resistor with a value around 3 kilo-ohm (we are using 3.9kOhm)</li>
<li>Breadboard</li>
<li>3 jumper wire cables (male-male)</li>
</ul>
<p><strong>Lets get started with setting up the Arduino Uno</strong><br />
The following diagram shows the components and connections for interacting with the Arduino Uno. As can be seen, we <strong>will measure the voltage in between the photoresistor and the common resistor</strong>, as this terminal is connected to the Arduino&#8217;s analog in <strong>pin A0</strong>. At normal daylight, our photoresistor has a resistance of around 3kOhm (measured with a multimeter). So we choose the other resistor at around the same value of 3.9kOhm (this was just the closest resistor value we had lying around). This way, when there is normal light, the voltage at the A0 pin will be about half of 5V, so 2.5V, and yielding an ADC value of 128. If there is more light, the photoresistor&#8217;s resistance drops and the voltage at the terminal rises. And vice versa if there is less light.<br />
<a href="http://android.serverbox.ch/wp-content/uploads/2012/11/arduino_lightlogger.png"><img src="http://android.serverbox.ch/wp-content/uploads/2012/11/arduino_lightlogger-245x300.png" alt="" title="arduino_lightlogger" width="245" height="300" class="alignnone size-medium wp-image-801" /></a><br />
So take out your breadboard and said components and try to rebuild the above diagram. If you do not have a photoresistor, you can also just attach a jumper cable to the A0 pin and measure different voltages such as the on-board 5V, 3.3V and GND pins.</p>
<p>Depending on your setup, this should look something like that &#8230;<br />
<a href="http://android.serverbox.ch/wp-content/uploads/2012/11/eat2_arduino_only.jpg"><img src="http://android.serverbox.ch/wp-content/uploads/2012/11/eat2_arduino_only-300x231.jpg" alt="" title="eat2_arduino_only" width="300" height="231" class="alignnone size-medium wp-image-812" /></a><br />
&#8230; and like this when connected to the Arduino Uno<br />
<a href="http://android.serverbox.ch/wp-content/uploads/2012/11/eat2_arduino_connected.jpg"><img src="http://android.serverbox.ch/wp-content/uploads/2012/11/eat2_arduino_connected-300x233.jpg" alt="Arduino connected to breadboard" title="eat2_arduino_connected" width="300" height="233" class="alignnone size-medium wp-image-814" /></a></p>
<p>We will of course also need some <strong>firmware running on the Arduino</strong>. The following code will measure the voltage at the A0 pin 10 times per second and send back the <strong>values over the serial communication interface</strong>. So build and upload the following source file:<br />
<a href='http://android.serverbox.ch/wp-content/uploads/2012/11/serverbox_arduino_lighlogger.c'>serverbox_arduino_lighlogger.c</a></p>
<p><strong>Communication between the Arduino and your host computer</strong></p>
<p>Once this is done, we can already try if everything works so far by connecting the Arduino to our host computer via USB. Right after connecting, run dmesg in a terminal. You should see something like new USB device, and the corresponding name, ttyACM0 in our case:</p>
<pre>
user@host:~$ dmesg
...
[185930.828750] usb 1-2.4.2: new full-speed USB device number 21 using ehci_hcd
[185930.924549] cdc_acm 1-2.4.2:1.0: ttyACM0: USB ACM device
</pre>
<p>Let&#8217;s have a look at the newly created device node <strong>on the host computer</strong>:</p>
<pre>
user@host:~$ ls -l /dev/ttyACM*
crw-rw---- 1 root dialout 166, 0 Nov 28 17:38 /dev/ttyACM0
</pre>
<p>The Arduino shows itself as a device node with major number 166, which is used for <strong>USB ACM devices</strong>. You can double check that in the kernel documentation under /opt/android/source/kernel/Documentation/devices.txt. The actual ACM device is the small ATmega16u2 controller right next to the USB connector. We will use this device node for serial communication, so we need to adjust the permissions:</p>
<pre>
user@host:~$ sudo chmod 666 /dev/ttyACM0
</pre>
<p>Now there are many different ways to read from the serial console. I personally like to use <a href="http://www.der-hammer.info/terminal/" title="Hammer Terminal">hterm</a> (you will need the ia32-libs package if your host is 64 Bit.. which should already be installed if you followed the guide in part 1). You can also use gtkterm, or even minicom. Our firmware on the Arduino simply writes the current ADC value (0&#8230;255) to the serial console. So if this output is interpreted as ASCII symbols, this will pretty much look like bogus. Some terminal programs such as hterm allow you to change the output type to hex or dec. Minicom does not have this functionality however. If you want to use a terminal program, just remember to use the following settings:</p>
<pre>
Port: /dev/ttyACM0
Speed: 9600baud
Data-Parity-Stopbits: 8N1
</pre>
<p>In this tutorial we will use a small program which <strong>reads directly from the created serial device node</strong>.<br />
<a href='http://android.serverbox.ch/wp-content/uploads/2012/11/termios.c'>termios.c</a><br />
Download the above source file, compile it with gcc and run it.</p>
<pre>
user@host:~$ gcc termios.c -o termios
user@host:~$ ./termios
read 136: 166
read 1: 157
read 1: 159
read 1: 160
read 1: 160
read 1: 158
...
</pre>
<p>If you do not see any output, make sure the device node still has the <strong>appropriate permissions</strong> as set above (<em>sudo chmod 666 /dev/ttyACM0</em>), also the device node name <strong>/dev/ttyACM0 is hard-coded</strong> in this example. So if your device node is called ttyACM1 for example, make sure to adjust it in termios.c as well. If everything works, try to <strong>shade</strong> your photoresistor or <strong>brighten it up</strong> with a flash light. The values should update accordingly.</p>
<p><strong>Configuring the Pandaboard to communicate with the Arduino</strong><br />
One can communicate between the Arduino and the Pandaboard pretty much in the same way. However, the current Pandaboard kernel <strong>does not have USB ACM support</strong> yet. So we need to <strong>reconfigure and recompile the kernel</strong> with this configuration enabled. With the new kernel running, a device node /dev/ttyACM0 will be created on the Pandaboard as soon as the Arduino is connected, just like on our host computer.<br />
The current kernel configuration is called <em>android_omap4_defconfig</em>. We will use this config and <strong>add USB ACM support</strong>.</p>
<pre>
user@host:/opt/android/source/kernel$ cp arch/arm/configs/android_omap4_defconfig .config
user@host:/opt/android/source/kernel$ make menuconfig ARCH=arm
</pre>
<p>Now navigate to <em>Device drivers</em>, <em>USB support</em>, and enable <em>USB Modem (CDC ACM) support</em> by pressing &#8220;Y&#8221;. Navigate back with Escape and save your changes. We will also <strong>save the new config</strong> for later:</p>
<pre>
user@host:/opt/android/source/kernel$ mv .config arch/arm/configs/android_omap4_cdc_defconfig
user@host:/opt/android/source/kernel$ make clean
user@host:/opt/android/source/kernel$ make mrproper
</pre>
<p>Our kernel was automatically built through the Android build system and we need to make adjustments so that from now on our <strong>modified kernel configuration</strong> is used.</p>
<pre>
user@host:/opt/android/source/kernel$ cd ..
user@host:/opt/android/source$ gedit device/linaro/pandaboard/BoardConfig.mk
</pre>
<p>In the above BoardConfig.mk file, we <strong>replace all occurences</strong> of <em>android_omap4_defconfig</em> with our new config <em>android_omap4_cdc_defconfig</em>. Now we are ready to rebuild the kernel:</p>
<pre>
user@host:/opt/android/source$ . build/envsetup.sh
user@host:/opt/android/source$ choosecombo 1 pandaboard 3
user@host:/opt/android/source$ make boottarball TARGET_TOOLS_PREFIX=../android-toolchain-eabi/bin/arm-linux-androideabi-
</pre>
<p>The new kernel will be found in the <strong>out folder</strong> and needs to be copied onto the SD card&#8217;s boot partition:</p>
<pre>
user@host:/opt/android/source$ cp out/target/product/pandaboard/boot/uImage /media/boot
user@host:/opt/android/source$ sync
user@host:/opt/android/source$ umount /media/*
</pre>
<p>Congratulations! You have just recompiled and deployed the kernel to <strong>support USB ACM devices</strong>. On the Pandaboard&#8217;s Android terminal, run &#8216;dmesg&#8217; right after connecting the Arduino to your Pandaboard. You should see that a new device node /dev/ttyACM0 was created.</p>
<p>So what now? We have ACM support enabled on our Pandaboard&#8217;s kernel, now we <strong>need a user space program</strong> to actually read from the created device node. The cool thing is that we already have an existing command line program, the exact same as above &#8211; <a href='http://android.serverbox.ch/wp-content/uploads/2012/11/termios.c'>termios.c</a> &#8211; which we used on the host computer. Earlier we used gcc to compile this program for the host computer, this time however we need to <strong>cross-compile the exact same program</strong> for our target, the Pandaboard, and thus compile it for an ARM architecture.</p>
<p>Again, there are multiple ways to do this. Here we will present a method that is very <strong>similar to the way that Android&#8217;s external projects are built</strong>. First of all download the <a href="http://developer.android.com/tools/sdk/ndk/index.html" title="Android Native Development Kit" target="_blank">Android Native Development Kit (Android NDK)</a>. Make sure that you choose the right version (Linux 64-bit). Extract the Android NDK anywhere you like, it&#8217;s also a good idea to <strong>add the installation directory to your PATH variable</strong>. Inside the extracted Android NDK folder, there are many good sample applications for using JNI and also a well-written documentation in html form. Be sure to check that out some time. For now, we are <strong>only going to use the &#8216;ndk-build&#8217; executable</strong> inside the Android NDK top folder. When calling the &#8216;ndk-build&#8217; executable from the command line, it will look for a <strong>sub-folder called &#8216;jni&#8217;</strong> (relative to the current working directory), and within this folder it will parse a file named Android.mk. The reason for that is that ndk-build is normally used in conjunction with a Java/Android project (just like the ones created with Eclipse ADT Bundle), and all native C code inside an Android project source folder is placed in a sub-folder called jni. Inside this jni folder there should be at least said Android.mk file and also of course the native source file, termios.c in our case.</p>
<pre>
user@host:~$ mkdir termios
user@host:~$ cd termios
user@host:~/termios$ mkdir jni
user@host:~/termios$ cd jni
user@host:~/termios/jni$ gedit termios.c
user@host:~/termios/jni$ gedit Android.mk
</pre>
<p>The contents for termios.c can again be downloaded <a href='http://android.serverbox.ch/wp-content/uploads/2012/11/termios.c'>here</a>. The contents for the Android.mk file should be :</p>
<pre>
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= termios.c
LOCAL_MODULE := termios
include $(BUILD_EXECUTABLE)
</pre>
<p>(compare this to /opt/android/source/external/ping/Android.mk)<br />
Within the created termios folder call &#8216;ndk-build&#8217;</p>
<pre>
user@host:~/termios$ ndk-build
</pre>
<p>This will cross-compile the program termios.c as an executable for our ARM target architecture and save it under termios/libs/armeabi/termios. Use the <strong>Android Debug Bridge (adb)</strong> to push this file to the target, and then execute it on the Pandaboard. You should see a similar output as on the host computer.</p>
<pre>
user@host:~/termios$ adb push libs/armeabi/termios /termios
user@host:~/termios$ adb shell
root@android:/# chmod 777 termios
root@android:/# ./termios
</pre>
<p>In this tutorial&#8217;s next part we will show you how to create a JNI wrapper function and thus how to use <strong>JNI to communicate with external hardware</strong> from within an Android Java application.</p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=792"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=792</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedded Android Tutorial: Part I, Setting up the Pandaboard with the Linaro Android Build</title>
		<link>http://android.serverbox.ch/?p=716&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=embedded-android-tutorial-part-i-setting-up-the-pandaboard-with-the-linaro-android-build</link>
		<comments>http://android.serverbox.ch/?p=716#comments</comments>
		<pubDate>Thu, 08 Nov 2012 18:18:58 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=716</guid>
		<description><![CDATA[Recently we have been setting up the Pandaboard with Android to get started with Embedded System Development. In this first post we would like to share of what steps were necessary to set up the build environment, Android source from Linaro and toolchain to get started on an Ubuntu 12.04 64 Bit machine. Android Build [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=716"></g:plusone></div><p><br/><br />
Recently we have been setting up the Pandaboard with Android to get started with Embedded System Development.</p>
<p>In this first post we would like to share of what steps were necessary to set up the build environment, Android source from Linaro and toolchain to get started on an Ubuntu 12.04 64 Bit machine.</p>
<p>Android Build and Version: Linaro Android Build, 4.1.1 Jellybean<br />
Host Machine: Lenovo T420, Ubuntu 12.04 64 Bit<br />
Hardware Target: Pandaboard<br />
Deployment Target: SD-Card</p>
<blockquote><p>Please note that since the Android ICS release, the Android Source can (sadly) only be built on a 64 bit OS, without the need to do workarounds.</p></blockquote>
<p><strong>Important Links for further reading:</strong></p>
<p><strong><a href="https://wiki.linaro.org/Platform/Android">Linaro Android Project</a><br />
</strong><strong><a href="http://source.android.com/source/initializing.html">Build Environment Initializing</a></strong><br />
<strong><a href="https://android-build.linaro.org/">Current Linaro Build version information</a></strong></p>
<p><strong>Setting up the build environment</strong></p>
<p>Before you can get started to build the Android Source code and Kernel, you need to set up the build environment properly. Part of this is installing packages from the Ubuntu repositories (for instance build tools like make and host side gcc etc.) and also the java version (from sun/oracle) which cannot be found in the current Ubuntu repositories.</p>
<p>Also we recommend you set up some primary build workspace for instance in &#8220;/opt/android/&#8221;. If you are new to Ubuntu and the Bash you will find countless excellent tutorials in the net. For this guide you should already be familiar with the command line and some of Linux most prominent tools.</p>
<p><strong>Let&#8217;s get started</strong></p>
<p>We assume you are user <strong>user</strong> on a machine <strong>host</strong>.</p>
<p>First of all grab a terminal on you Host machine either by finding it in the start menu or by hitting ctrl+alt+t.</p>
<p>Now let&#8217;s set up some workspace for our source in the /opt directory.</p>
<pre>user@host:~$ sudo mkdir /opt/android
user@host:~$ sudo chown -R user.user /opt/android
user@host:~$ cd /opt/android
user@host:/opt/android$ </pre>
<p>Following the guide on the source.android.com site we set up the packages required for building android.</p>
<pre>user@host:/opt/android$ sudo apt-get install -f git-core gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 libgl1-mesa-dev g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386
user@host:/opt/android$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
user@host:/opt/android$ sudo apt-get install lib32ncurses5-dev
</pre>
<p>Also we need some additional packages for debugging over the serial console and to set up the bootloader for android.</p>
<pre>user@host:/opt/android$ sudo apt-get install minicom
user@host:/opt/android$ sudo apt-get install ia32-libs
user@host:/opt/android$ sudo apt-get install u-boot-tools</pre>
<p>At some point we noticed some libraries had problems installing. Be sure to do this command after installing all the packages&#8230;</p>
<pre>
user@host:/opt/android$ sudo apt-get install -f
</pre>
<p>That should do it.</p>
<div style="color:#990000;">For the next part: It turns out the Linaro Build compiles fine with just OpenJDK. If you do have the OpenJDK already installed you can skip this part and go to <a href="#fetch">Fetching the Android Source Code</a>.</div>
<pre style="color:#990000;">
user@host:/opt/android$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~12.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
</pre>
<p>Now we need to install java. This is a tricky part, since it used to be much easier to do this in Ubuntu a while back. As far as we know Oracle forced Canonical to take down the binaries of java from their repositories. What a shame &#8230;<br />
For the setup we configured the java installation by hand.</p>
<p>Navigate <a href="http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u34-oth-JPR" target="_blank">here</a> and select the .bin of the 64 bit download (jre-6u34-linux-x64.bin). Because they seem very interested of who downloads their java they want you to register on their website. We actually did not try to build the source with iced-tea java, so we do not know if that works as well. However we cannot wait to be able to <strong>skip</strong> oracle&#8217;s java for building android.</p>
<p>As soon as you grabbed the binary you can do the following to install it and let Ubuntu know where to find all the commands.</p>
<pre>
user@host:~/Downloads$ chmod a+x jre-6u34-linux-x64.bin
user@host:~/Downloads$ mv jre-6u34-linux-x64.bin /opt/android &#038;&#038; cd /opt/android
user@host:/opt/android$ ./jre-6u34-linux-x64.bin
user@host:/opt/android$ sudo update-alternatives --install "/usr/bin/java" "java" "/opt/android/jdk1.6.0_34/bin/java" 1
user@host:/opt/android$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/android/jdk1.6.0_34/bin/javac" 1
user@host:/opt/android$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" user@host:/opt/android$ "/opt/android/jdk1.6.0_34/bin/javaws" 1
user@host:/opt/android$ sudo update-alternatives --config java
user@host:/opt/android$ sudo update-alternatives --config javac
user@host:/opt/android$ sudo update-alternatives --config javaws</pre>
<p>To be sure check what happens if you execute the &#8220;java&#8221; command and check the version with &#8220;java -version&#8221;. The output should look something like this:</p>
<pre>
user@host:/opt/android$ java -version
java version "1.6.0_34"
Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.9-b04, mixed mode)
</pre>
<p><a id="fetch"><strong>Fetching the Android Source Code</strong></a></p>
<p>For this step you should probably get a few cups of coffee ready since depending on your network connection it might take quite a while.<br />
First you need to fetch &#8220;repo&#8221; which is a tool that helps you to keep track of all the necessary Android GIT repositories (GIT is by the way awesome, you should look into it if you have not done that already).</p>
<pre>
user@host:/opt/android$ mkdir ~/bin/
user@host:/opt/android$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo
user@host:/opt/android$ chmod a+x ~/bin/repo
</pre>
<p>Before we fetch the source code we also fetch the Linaro toolchain which is needed to cross compile the Android source code. Also we install the linaro image tools to deploy the Android/Kernel/uBoot images to the SD-Card once built.</p>
<p>Note: Before you do the next two steps, decide which build version you want to use. Have a look at <a href="https://android-build.linaro.org/" target="_blank">the build version table</a> for the latest releases.</p>
<pre>
user@host:/opt/android$  wget http://snapshots.linaro.org/android/~linaro-android/toolchain-4.7-2012.10/1/android-toolchain-eabi-linaro-4.7-2012.10-1-2012-10-15_16-19-17-linux-x86.tar.bz2
user@host:/opt/android$ tar -xvf android-toolchain-eabi-linaro-4.7-2012.10-1-2012-10-15_16-19-17-linux-x86.tar.bz2
user@host:/opt/android$ sudo apt-get install linaro-image-tools
</pre>
<p>At this point we create a &#8220;source&#8221; subdirectory and start fetching the Android source code from the Linaro repository.</p>
<pre>
user@host:/opt/android$ mkdir source &#038;&#038; cd source
user@host:/opt/android$ repo init -u git://android.git.linaro.org/platform/manifest.git -b linaro-android-12.10-release -m staging-panda.xml
user@host:/opt/android$ repo sync
</pre>
<p>The upper commands may differ from what version you are using.</p>
<p><strong>Building the Source Code</strong></p>
<p>As soon as the source is downloaded you are ready to give it a first build. In the source directory do the following to start building for the pandaboard:</p>
<pre>
user@host:/opt/android/source$ . build/envsetup.sh
user@host:/opt/android/source$ choosecombo 1 pandaboard 3
user@host:/opt/android/source$ make -j4 TARGET_TOOLS_PREFIX=../android-toolchain-eabi/bin/arm-linux-androideabi- boottarball systemtarball userdatatarball
</pre>
<p>Make sure though that the toolchain is actually in the folder &#8220;/opt/android/android-toolchain-eabi&#8221;.</p>
<p>Now depending on if your package installation process from the beginning was successful or not, the build will complete successfully and output three tarballs (boot.tar.bz2, system.tar.bz2 and userdata.tar.bz2).</p>
<p>If the build is not successful then go back to the start of the guide and make sure ALL your packages install correctly (if apt throws errors just do a &#8220;sudo apt-get install -f&#8221; with no packages as arguments).</p>
<p>After completion of compiling source code (the kernel was compiled as well with the command before) you should now format an SD card and deploy the images.</p>
<p>If you are using GNOME (if you are not sure that you are then you ARE using GNOME <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ), then you also need to do a few tricks so the SD-Partitioning runs without problems. Linaro has just updated their deployment guide recently for this.</p>
<pre>
user@host:/opt/android/source$ TMP1=$(dconf read /org/gnome/desktop/media-handling/automount)
user@host:/opt/android/source$ TMP2=$(dconf read /org/gnome/desktop/media-handling/automount-open)
user@host:/opt/android/source$ dconf write /org/gnome/desktop/media-handling/automount false
user@host:/opt/android/source$ dconf write /org/gnome/desktop/media-handling/automount-open false
</pre>
<p>The above steps are currently untested, but we trust that the guys did a good job on this <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now insert you SD-Card into your card-reader. Check with &#8220;sudo fdisk -l&#8221; which devices are available for you. Be really careful here to not pick the wrong device, since all contents of the chosen one will be DELETED irrecoverably.</p>
<p>So if your SD-Card is on &#8220;/dev/mmcblk0&#8243; then you would do the following command. Note that depending on your SD-Card Reader it is possible the device is found under &#8220;/dev/sdX&#8221;.</p>
<pre>
user@host:/opt/android/source$ cd out/target/product/pandaboard
user@host:/opt/android/source/out/target/product/pandaboard$ linaro-android-media-create --mmc /dev/mmcblk0 --dev panda --boot boot.tar.bz2 --system system.tar.bz2 --userdata userdata.tar.bz2
</pre>
<p>During this time the SD-Card is being formated and partitioned properly. We had sometimes difficulties on some hosts with running this script, however, the automount trick should fix the issue.</p>
<p>Now restart the automount feature of gnome</p>
<pre>
dconf write /org/gnome/desktop/media-handling/automount $TMP1
dconf write /org/gnome/desktop/media-handling/automount-open $TMP2
</pre>
<p>The last thing we need to do is to install the proprietary drivers of the OEM for the Pandaboard. This is done by grabbing the binaries and pushing them to the system partition of the SD-Card.</p>
<p>For this purpose remove the SD-Card and Plug it back in after re-enabling the automount feature of gnome.</p>
<p>The second partition of your SD-Card holds the contents of the &#8220;system&#8221; image. In our case this was /dev/mmcblk0p2, it might differ for you depending on your SD-Card reader it could be something like /dev/sdXp2 as well.</p>
<pre>
user@host:/opt/android/source/out/target/product/pandaboard$ wget http://people.linaro.org/~vishalbhoj/install-binaries-4.0.4.sh
user@host:/opt/android/source/out/target/product/pandaboard$ chmod a+x install-binaries-4.0.4.sh
user@host:/opt/android/source/out/target/product/pandaboard$ ./install-binaries-4.0.4.sh dev/mmcblk0p2
</pre>
<p>You are almost done. Be sure to ALWAYS do a &#8220;sync&#8221; and an &#8220;umount&#8221; BEFORE you remove your SD-Card. Doing otherwise can screw up your files!</p>
<pre>
user@host:/opt/android/source/out/target/product/pandaboard$ sync
user@host:/opt/android/source/out/target/product/pandaboard$ sudo umount /dev/mmcblk0
</pre>
<p>Now put your SD-Card into your Pandaboard and see it booting.</p>
<p><strong>Console via USB-Serial Converter</strong></p>
<p>For debugging you can now use minicom. To do so, hook up your USB-Serial converter to your Beagleboard and on the host run minicom.</p>
<p>In the config go to &#8220;Serial port setup&#8221; then press &#8220;a&#8221; and change the device according to your serial device node (&#8220;/dev/ttyUSB0&#8243; or something), then press ENTER to confirm and hit &#8220;f&#8221; to disable hardware flow control. Now hit ENTER twice and select &#8220;save setup as panda&#8221;.</p>
<pre>
user@host:/opt/android/source/out/target/product/pandaboard$ sudo minicom -s panda
</pre>
<p>Exit the terminal at any time using &#8220;ctrl+a, z, q&#8221; and reconnect with your new config using</p>
<pre>
user@host:/opt/android/source/out/target/product/pandaboard$ sudo minicom panda
</pre>
<p>You should now be able to start with the real fun. You downloaded and compiled the Android source and set up the SD-Card for deployment.</p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=716"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=716</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>OsciPrime &#8211; An Open Source Android Oscilloscope, new release</title>
		<link>http://android.serverbox.ch/?p=660&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=osciprime-an-source-android-oscilloscope-new-release</link>
		<comments>http://android.serverbox.ch/?p=660#comments</comments>
		<pubDate>Mon, 18 Jun 2012 17:30:47 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Java]]></category>
		<category><![CDATA[Android Native]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=660</guid>
		<description><![CDATA[Today, it is my pleasure to announce the release of our all new open source Android application of the OsciPrime Oscilloscope. We worked eagerly to bring a large amount of requested and desired features to our Android application, and guess what, it is all Open Source. With the new release we also announced that we [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=660"></g:plusone></div><p>Today, it is my pleasure to announce the release of our all new open source Android application of the OsciPrime Oscilloscope. We worked eagerly to bring a large amount of requested and desired features to our Android application, and guess what, it is all Open Source.</p>
<p><img src="http://www.osciprime.com/img/banner.png" alt="OsciPrime Oscilloscope" /></p>
<p>With the new release we also announced that we are in the process of making our hardware board available for ordering. Check all news out on our product website <a traget="_blank" href="http://www.osciprime.com" title="osciprime website">www.osciprime.com</a>.</p>
<p>Features and improvements of the new application are:</p>
<pre>
=> Mutlitouch Interface
=> Control Interleave, Attenuation, Offset, Zoom, etc.
=> Using the new Android USB API for communication with the hardware board
=> Neat new User Interface, as modular as possible
=> Improved processing performance for both Audio and USB
</pre>
<p><img src="http://www.osciprime.com/img/screen.png" alt="Screenshot of the OsciPrime Android App" /></p>
<p>If you want to support our open source development and always receive the newest version of the scope, then <strong>consider purchasing</strong> our application from the Android Market <a traget="_blank" href="https://play.google.com/store/apps/details?id=ch.nexuscomputing.android.osciprimeics" title="here">here</a>.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/_xoNZ0Jt4Wo" frameborder="0" allowfullscreen></iframe></p>
<p><strong>If you want to meet us and find out more about the project</strong>, then join us on the 10. of July 2012 at the <strong><a href="http://schedule2012.rmll.info/OsciPrime-An-Open-Source-Android-Oscilloscope" target="_blank">Libre Software Meeting</a></strong> in Geneva, where we are going to present our Open Source Project.</p>
<p>Head over to our OsciPrime Website to catch the latest source code and APK. <a href="http://www.osciprime.com/index.php?p=source" title="link" traget="_blank">here</a>.</p>
<p>We are eager to hear your thoughts and improvements of the applications in the comments section.</p>
<p><a traget="_blank" href="http://www.osciprime.com" title="OsciPrime Website">OsciPrime Website</a><br />
<a traget="_blank" href="https://play.google.com/store/apps/details?id=ch.nexuscomputing.android.osciprimeics" title="OsciPrime on the Android Market">OsciPrime Android Market Site</a><br />
<a traget="_blank" href="http://www.osciprime.com/index.php?p=source" title="OsciPrime Source Code">OsciPrime Source Code</a></p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=660"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=660</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android USB Host + Arduino: How to communicate without rooting your Android Tablet or Phone</title>
		<link>http://android.serverbox.ch/?p=549&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=android-usb-host-arduino-how-to-communicate-without-rooting-your-android-tablet-or-phone</link>
		<comments>http://android.serverbox.ch/?p=549#comments</comments>
		<pubDate>Thu, 09 Feb 2012 15:45:40 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=549</guid>
		<description><![CDATA[Intro In the past two posts we have explained the basics of USB communication with the Arduino Uno (also applicable for Arduino Mega). Programming the Arduino Uno with Eclipse on Linux Arduino USB transfers In this post we&#8217;ll put everything together and show you how to communicate between your Android application and the Arduino using [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=549"></g:plusone></div><h2>Intro</h2>
<p>In the past two posts we have explained the basics of USB communication with the Arduino Uno (also applicable for Arduino Mega).</p>
<ul>
<li><a href="http://android.serverbox.ch/?p=394" title="Programming the Arduino Uno with Eclipse on Linux" target="_blank">Programming the Arduino Uno with Eclipse on Linux</a></li>
<li><a href="http://android.serverbox.ch/?p=427" title="Arduino USB transfers" target="_blank">Arduino USB transfers</a></li>
</ul>
<div class="wp-caption alignright" style="width: 610px"><img alt="" src="http://android.serverbox.ch/wp-content/header.jpg" title="Galaxy Nexus to Arduino UNO via USB" width="600" height="392" /><p class="wp-caption-text">Galaxy Nexus to Arduino UNO via USB</p></div>
<p>In this post we&#8217;ll put everything together and show you how to communicate between your <strong>Android</strong> application and the Arduino using nothing but the <strong>Android USB host API</strong>. Remember, this approach has <strong>nothing to do with Android ADK</strong>! Unlike Android ADK, your <strong>Android device will act as the USB host</strong>, while your <strong>Arduino board will act as the USB device</strong>.</p>
<p>For the following application to work, you will require an Android device that supports USB host mode as well as the USB host API. Most Android 3.1+ tablets will suffice (some may require an USB OTG adapter). Also, the Galaxy Nexus has host mode enabled and matches the requirements (you will need an USB OTG adapter however).</p>
<p>This example consists of two parts:</p>
<ul>
<li>
<strong>The Android application that makes use of the USB API</strong><br />
A simple Android app that let&#8217;s you regulate the brightness of an LED on the Arduino using a slider. It also features a button to &#8220;enumerate&#8221; the USB device.
</li>
<li>
<strong>Firmware for the Arduino that does some serial I/O with the Android app</strong><br />
Very basic firmware for the Arduino. An interrupt is generated when a new byte is received. The received data controls the brightness of the Arduino&#8217;s on-board LED.<br />
(implemented via usleep-style software pwm in the main loop).
</li>
</ul>
<h2>The Arduino firmware</h2>
<p>In the main loop the firmware asserts and clears the LED pin of the Arduino (PB5). Here is a shortened excerpt:</p>
<pre>	
int main(void) {
	//initialization
	initIO();
	uart_init();
	sei();

	uint8_t i = 0;
	volatile uint8_t pause;

	for(;;){//this is the main loop
		pause = data;
		PORTB |= (1 << LED);
		for(i = 0; i < pause; i++)
			_delay_us(10);
		PORTB &#038;= ~(1 << LED);
		for(i = 0; i < 255-pause; i++)
			_delay_us(10);
	}
}
</pre>
<p>During a period of 2550[us], the LED is asserted for a duration of pause*10 [us] and cleared for (255-pause)*10[us]. Simply put, this is a very simple <strong>software PWM</strong>.</p>
<p>During that time, "data" and consequently "pause" may be changed within an <strong>interrupt routine</strong> form the serial USART port. This happens when the Android side sends data to the Arduino. The interrupt routine is extremely basic:</p>
<pre>
ISR(USART_RX_vect) {//attention to the name and argument here, won't work otherwise
	data = UDR0;//UDR0 needs to be read
}
</pre>
<p>The RX data has to be read in the ISR (interrupt service routine) from UDR0; have a look at the <a href="http://www.atmel.com/devices/ATMEGA328P.aspx?tab=documents" target="_blank">Atmega328P reference manual</a> for further details. Since we are doing no multi-buffering shenanigans the handling is extremely simple (no need to call cli() or anything).</p>
<p>The rest of the code is initialization of the I/O pins and UART functionality. Download the complete example here: <a href="http://android.serverbox.ch/wp-content/led_pwm.c" target="_blank">led_pwm.c</a></p>
<div class="wp-caption alignright" style="width: 610px"><img alt="" src="http://android.serverbox.ch/wp-content/uno.jpg" title="Controlled LED on the UNO by the firmware" width="600" height="392" /><p class="wp-caption-text">Controlled LED on the UNO by the firmware</p></div>
<p><a name="app549">&nbsp;</a></p>
<h2>The Android app</h2>
<p>The Android application uses the basic knowledge of the preceding blog post <a href="http://android.serverbox.ch/?p=427" title="Arduino USB transfers" target="_blank">Arduino USB transfers</a>. During USB initialization, the Arduino USB serial converter is set up and after that, <strong>communication is done using the bulk IN endpoint</strong> of the very same serial converter.</p>
<p>With both the aforementioned firmware installed your Arduino board and the Android application installed on your phone or tablet, you will be able to control the brightness of the Arduino Uno's built-in LED with a slider on your Android device. Again, please <strong>note that this will only work with devices that actually support both USB host mode</strong> (hardware, kernel requirement) <strong>as well as the Android USB host API</strong> (Android OS requirement).</p>
<p>The source code is available here: <a href="http://android.serverbox.ch/wp-content/UsbController.tar.gz" target="_blank">UsbController.tar.gz</a>*<br />
* You may need to change the PID value in UsbControllerActivity.java on line 38, if you have an Arduino Uno Rev3 or higher. You can check the VID/PID value with 'lsusb' after connecting the Arduino to your computer.</p>
<p>Many parts of the code are probably familiar to Android SW engineers. The <strong>most interesting section is in the class UsbController</strong> where the Arduino device is set up and communication is initiated. So let's have a closer look at the <strong>inner class UsbRunnable within UsbController</strong>:</p>
<pre>
private class UsbRunnable implements Runnable {
	private final UsbDevice mDevice;

	UsbRunnable(UsbDevice dev) {
		mDevice = dev;
	}

	@Override
	public void run() {//here the main USB functionality is implemented
		UsbDeviceConnection conn = mUsbManager.openDevice(mDevice);
		if (!conn.claimInterface(mDevice.getInterface(1), true)) {
			return;
		}
		// Arduino USB serial converter setup
		conn.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
		conn.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80,
				0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);

		UsbEndpoint epIN = null;
		UsbEndpoint epOUT = null;

		UsbInterface usbIf = mDevice.getInterface(1);
		for (int i = 0; i < usbIf.getEndpointCount(); i++) {
			if (usbIf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
				if (usbIf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)
					epIN = usbIf.getEndpoint(i);
				else
					epOUT = usbIf.getEndpoint(i);
			}
		}

		for (;;) {// this is the main loop for transferring
			synchronized (sSendLock) {//ok there should be a OUT queue, no guarantee that the byte is sent actually
				try {
					sSendLock.wait();
				} catch (InterruptedException e) {
					if (mStop) {
						mConnectionHandler.onUsbStopped();
						return;
					}
					e.printStackTrace();
				}
			}
			conn.bulkTransfer(epOUT, new byte[] { mData }, 1, 0);

			if (mStop) {
				mConnectionHandler.onUsbStopped();
				return;
			}
		}
	}
}
</pre>
<p>After the USB interface has been claimed the Arduino USB serial converter is initialized by issuing the following control transfers:</p>
<pre>
conn.controlTransfer(0x21, 34, 0, 0, null, 0, 0);
conn.controlTransfer(0x21, 32, 0, 0, new byte[] { (byte) 0x80,
				0x25, 0x00, 0x00, 0x00, 0x00, 0x08 }, 7, 0);
</pre>
<p>The first call sets the control line state, the second call sets the line encoding (9600, 8N1).<br />
For communication, an additional thread is used to <strong>send data without blocking</strong> the Activity's main UI thread. By notifying sSendLock of the UsbController the data will be transferred. After submission, the thread will go into "wait" again. This way, even if submission takes more time than expected, the Activity's main thread will not be blocked and hence <strong>the app will not become unresponsive</strong>.</p>
<div class="wp-caption alignright" style="width: 610px"><img alt="" src="http://android.serverbox.ch/wp-content/usbcontroller.png" title="Screenshot of the Android App" width="600" height="337" /><p class="wp-caption-text">Screenshot of the Android App</p></div>
<p>Also note that in the Android Manifest none of the XML-style device filters are needed, since enumeration happens by the user in the app when pressing the "enumerate" button. Device filters - and therefore automatic activity launch when connecting the Arduino - are not used in this example in order to make the code simpler to comprehend. However, this could be easily implemented with a few lines of additional code.</p>
<p>For developing this example we have used a <strong>Galaxy Nexus Phone</strong> with an USB-OTG adapter cable. It has also been successfully tested with an <strong>Android Tablet, the Acer Iconia Tab A500</strong>, this tablet does not need any additional adapter cables.</p>
<p>This post concludes the 3-Part Arduino USB communication series. Feel free to post any questions or feedback/ideas in the comments section or contact us via E-Mail (<a href="http://www.nexus-computing.ch">http://www.nexus-computing.ch</a>).</p>
<p>All code you find in this post can be used under GPL for your own projects.</p>
<p>The following section "About Android and USB Host" again concludes why USB-Host is becoming more and more important for mobile devices and points out main differences between Android ADK (Android Accessory Development Kit) and the Android USB Host API.</p>
<p><strong>EDIT: control transfers for FTDI equiped Arduinos</strong><br/><br />
Since we got requested a lot if the FTDI Usb-Serial converter will work too, here ist the control transfer code that needs to be exchanged. No warranties though <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>
conn.controlTransfer(0x40, 0, 0, 0, null, 0, 0);// reset
conn.controlTransfer(0x40, 0, 1, 0, null, 0, 0);// clear Rx
conn.controlTransfer(0x40, 0, 2, 0, null, 0, 0);// clear Tx
conn.controlTransfer(0x40, 0x03, 0x4138, 0, null, 0, 0);
</pre>
<h2>Source Links</h2>
<p>Android App: <a href="http://android.serverbox.ch/wp-content/UsbController.tar.gz" target="_blank">UsbController.tar.gz</a>*<br />
Arduino main: <a href="http://android.serverbox.ch/wp-content/led_pwm.c" target="_blank">led_pwm.c</a></p>
<p>* You may need to change the PID value in UsbControllerActivity.java on line 38, if you have an Arduino Uno Rev3 or higher. You can check the VID/PID value with 'lsusb' after connecting the Arduino to your computer.</p>
<h2>About Android and USB Host</h2>
<p>Lately it has become more and more popular to use tablets or mobile phones to communicate with the outside world over USB. After all, <strong>many devices now feature a full USB Host</strong>, either with a USB-OTG converter or even with a full sized USB Type A interface. Also, the future promises even more host availability on mobile phones. This opens up an entire range of new possibilities for already existing hardware as well as newly designed hardware for phones.</p>
<p>Not too long ago, Android received its <strong>own USB API</strong>. It was at the Google I/O in summer 2011 when the "Android Open Accessory Development Kit" was announced and released. However it lacked of a few crucial points. The API implied that there is an <strong>external USB host</strong>, acting as a "master" if you will.<br />
On the one hand, this means that an already existing <strong>USB device mode gadget cannot work with your Android device</strong>. Therefore, if a manufacturer wanted to support Android phones it was necessary to create new hardware as well as new firmware. Secondly, the new hardware had to be designed to power itself and also deliver power the Android device; this implied that <strong>mobile gadgets require their own power source</strong>. And secondly, there was another issue: only devices running Android 2.3.4+ were shipped with the new API. Even then, it was up to the manufacturer to actually include the required stack in the OS.</p>
<p>But wait, there is another way to communicate over USB. At the same time (Google I/O) the Android USB Host API has been published for Android 3.1+. Starting with the second half of 2011, Android devices appeared which supported USB OTG (although devices with Android version &lt; 3.1 were not supporting the API). With an appropriate <strong>adapter it has become possible for Android to act as USB Host</strong>. This meant that already present USB hardware has become compatible with the OS. As long as the kernel on the Android device supported the USB standard driver of the hardware (mass storage, input, etc.), Android would be able to use it and therefore open up a new range of extra devices compatible with the system.</p>
<p>However, there are many devices that have not been "compatible" from the beginning. For instance, let's say your common RFID reader. It most likely uses a USB-serial port and probably comes with a Linux or Windows driver as well as some software. Most <strong>Android tablets will come without the usb-serial driver</strong> for your RFID reader however. Therefore, if you want to load your driver you will need to <strong>root your tablet</strong>, determine the version of your current kernel, <strong>find the kernel sources online</strong>, hope that everything compiles to have your driver ready and then load it onto your tablet. In the end, when you finally have your kernel driver running, you will be required to write C code as well as some JNI glue to communicate with your Activity or Service in Android. All in all, this approach is <strong>not very straightforward</strong>.</p>
<p><strong>Writing your own USB soft driver</strong></p>
<p>There is a very elegant solution to aforementioned problem. It <strong>requires far less skills in hacking and porting</strong> than the mentioned approach. However, you will require some advanced knowledge in Android programming as well as some USB know-how.<br />
You can write your own "soft driver" in Android. Since the USB Host API has been released, it is now possible to communicate with any USB device using the <strong>most commonly seen USB transfers</strong> (control, interrupt, bulk). In the end, your result will be portable across all Android devices that have USB host enabled and have Android version 3.1+. Moreover, this <strong>solution does NOT require root access</strong> to the tablet or phone. It is currently the only viable solution that does not require the user to have any know-how of rooting/hacking the device and risk losing warranty in the process.<br />
The <a href="#app549">above Android application</a> uses exactly this approach. It represents a <strong>very basic soft driver</strong> for the Arduino's on-board USB-to-serial converter.</p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=549"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=549</wfw:commentRss>
		<slash:comments>218</slash:comments>
		</item>
		<item>
		<title>Arduino USB transfers</title>
		<link>http://android.serverbox.ch/?p=427&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=arduino-usb-transfers</link>
		<comments>http://android.serverbox.ch/?p=427#comments</comments>
		<pubDate>Mon, 09 Jan 2012 10:55:45 +0000</pubDate>
		<dc:creator>Andreas Rudolf</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=427</guid>
		<description><![CDATA[In this post we will show you how to communicate between the Arduino Uno and your computer using plain USB bulk and control transfers, not relying on a serial communication interface. Our development computer runs Ubuntu 11.10 (Oneiric Ocelot). This is a follow up to Programming the Arduino Uno with Eclipse on Linux. The next [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=427"></g:plusone></div><p>In this post we will show you how to communicate between the Arduino Uno and your computer using <strong>plain USB bulk and control transfers</strong>, not relying on a serial communication interface. Our development computer runs Ubuntu 11.10 (Oneiric Ocelot).</p>
<p>This is a follow up to <a href="http://android.serverbox.ch/?p=394" title="Programming the Arduino Uno with Eclipse on Linux" target="_blank">Programming the Arduino Uno with Eclipse on Linux</a>. The next post in this series is <a href="http://android.serverbox.ch/?p=549" title="Android USB Host + Arduino: How to communicate without rooting your Android Tablet or Phone">Android USB Host + Arduino: How to communicate without rooting your Android Tablet or Phone</a>.</p>
<p>The Arduino Uno has an on-board <strong>USB-to-serial converter</strong> (ATMega8u2 or ATMega16u2 since rev. 3). The preloaded firmware on this converter presents itself as an USB Communication Device Class (<strong>CDC</strong>). Usually, no further software driver is needed on the host computer. You can simply plug in the Arduino Uno to your computer, and you will be able to communicate with the Arduino&#8217;s main microcontroller, the ATMega328, over an emulated serial communication interface.</p>
<p>For many applications, a serial communication interface is just fine. You can use minicom, gtkterm or a similar terminal application to send and receive data from your microcontroller. Or even use a python serial library and start off from there. In some circumstances however, you might not have the possibility to open a serial communication. Android for instance does not have a native serial communication interface, instead it features an USB host API. In this case, you must <strong>rely solely on USB control and bulk transfers</strong>.</p>
<p>When you connect an Arduino Uno to your linux computer with an USB cable, you will notice that a new device node /dev/ttyACM0 or similar is created. For this purpose, check out the last few lines from dmesg right after connecting the Arduino Uno.<br />
<code>$ dmesg | tail<br />
...<br />
[] usb 1-5.2: new full speed USB device number 43 using ehci_hcd<br />
[] cdc_acm 1-5.2:1.0: ttyACM0: USB ACM device</code></p>
<p>In the above example, the Arduino Uno is assigned to USB device number 43, and a new device node /dev/ttyACM0 is created. This device node is automatically created by the <strong>module cdc_acm</strong> and represents a serial communication interface which you can use with minicom, gtkterm, etc. However, we are not going to do that. We want to find out how to talk to this device using USB transfers, right? <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Further investigations with the vendor (0&#215;2341) and product (0&#215;0001) id &#8230;<br />
<code>lsusb -v -d 2341:0001</code><br />
&#8230; yield more interesting information about this device. For instance, <strong>bNumInterfaces = 2</strong> shows that there are two available interfaces. This stems from the mentioned pre-loaded <a href="https://github.com/arduino/Arduino/tree/master/hardware/arduino/firmwares">Arduino firmware</a>. There you will see two projects:</p>
<ul>
<li><a href="https://github.com/arduino/Arduino/tree/master/hardware/arduino/firmwares/arduino-usbdfu" title="Arduino USB DFU bootloader firmware" target="_blank">arduino-usbdfu</a> is the Arduino USB DFU bootloader firmware, which is used for flashing the ATmega8u2 or ATmega16u2 respectively.</li>
<li><a href="https://github.com/arduino/Arduino/tree/master/hardware/arduino/firmwares/arduino-usbserial" title="Arduino USB Serial Firmware" target="_blank">arduino-usbserial</a> is the real firmware of the USB-to-serial converter. This is where the magic happens <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </li>
</ul>
<p>Again, looking at the output of &#8230;<br />
<code>lsusb -v -d 2341:0001</code><br />
&#8230; you will see <strong>two interface descriptors</strong>. The first one with bInterfaceNumber=0 is the DFU bootloader, and the second one with bInterfaceNumber=1 is our usb-serial firmware interface descriptor. You can double-check that in <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/firmwares/arduino-usbdfu/Descriptors.c" target="_blank">arduino-usbdfu/Descriptors.c</a> and <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/firmwares/arduino-usbserial/Descriptors.c" target="_blank">arduino-usbserial/Descriptors.c</a> respectively.</p>
<p>The <strong>starting point</strong> of the usb-serial project is in <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/firmwares/arduino-usbserial/Arduino-usbserial.c" target="_blank">firmwares/arduino-usbserial/Arduino-usbserial.c</a>. At the top, a variable <strong>VirtualSerial_CDC_Interface</strong> is initialized, and it is then passed in the main&#8217;s for-loop:<br />
<code>...<br />
CDC_Device_USBTask(&#038;VirtualSerial_CDC_Interface);<br />
USB_USBTask();</code></p>
<p>The function CDC_Device_USBTask() is part of the <strong>LUFA-lib</strong> (<a href="http://code.google.com/p/lufa-lib/" target="_blank">Lighweight USB Framework Library</a>), and is defined in <a href="http://code.google.com/p/lufa-lib/source/browse/trunk/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c" target="_blank">CDCClassDevice.c</a>. Likewise, this source file can be considered as the <strong>heart-piece</strong> of the usb-serial firmware. There we find all important functions such as CDC_Device_SendByte and CDC_Device_ReceiveByte. You will notice that almost every function <strong>returns immediately if no LineEncoding/Baudrate has been set</strong>. Luckily, the function CDC_Device_ProcessControlRequest (also in <a href="http://code.google.com/p/lufa-lib/source/browse/trunk/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c" target="_blank">CDCClassDevice.c</a>) unravels the mysteries of setting the LineEncoding, Baudrate, LineState, etc. Here is a shortened excerpt:<br />
<code>
<pre>
void CDC_Device_ProcessControlRequest() {
 switch (USB_ControlRequest.bRequest){
  case CDC_REQ_SetLineEncoding:
  if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)){
   CDCInterfaceInfo->State.LineEncoding.BaudRateBPS = Endpoint_Read_32_LE();
   CDCInterfaceInfo->State.LineEncoding.CharFormat  = Endpoint_Read_8();
   CDCInterfaceInfo->State.LineEncoding.ParityType  = Endpoint_Read_8();
   CDCInterfaceInfo->State.LineEncoding.DataBits    = Endpoint_Read_8();
  }
...
</pre>
<p></code></p>
<p>Now we&#8217;re cooking <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . To set the LineEncoding we therefore need to send an USB control request with bRequest = CDC_REQ_SetLineEncoding = 0&#215;20 (as defined in <a href="http://code.google.com/p/lufa-lib/source/browse/trunk/LUFA/Drivers/USB/Class/Common/CDCClassCommon.h" target="_blank">CDCClassCommon.h</a>) and with bmRequestType = 0&#215;21. Also, the data must hold 7 bytes with corresponding values.</p>
<p>Once you know which requests to look for, it is pretty straightforward. Use an USB sniffer like wireshark and observe what happens when you plug in your Arduino board. With wireshark, you can also search for a specific bmRequestType by applying a filter like:<br />
<code>usb.bmRequestType == 0x21</code></p>
<p>As it turns out, there are <strong>two important control transfers</strong> when connecting the Arduino board to the computer. The first one has bRequest = CDC_REQ_SetControlLineState = 0&#215;22 = 34 and the second one bRequest = CDC_REQ_SetLineEncoding = 0&#215;20 = 32.</p>
<p>If you want to try it for yourself, download and run <a href="http://android.serverbox.ch/wp-content/atmega8u2.py">this python script</a> (with sudo). This script will initialize the usb-serial-converter with USB control transfers and then send single bytes from your computer to the Arduino Uno using bulk transfers. Just make sure to <strong>remove the cdc_acm module</strong> beforehand by issuing:<br />
<code>$ sudo rmmod cdc_acm</code><br />
As this module will otherwise lock access to the USB device. Also, you will need appropriate software running on your Arduino board. You may download this <a href='http://android.serverbox.ch/wp-content/uploads/2011/12/main1.c'>source code</a> and flash it onto the device. This will set the duty cycle of a PWM signal on PIN3 according to the byte received from the computer. Also it will light up the on-board LED if the received byte is an odd value and shut it off when an even value is received.</p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=427"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=427</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Programming the Arduino with Eclipse on Linux</title>
		<link>http://android.serverbox.ch/?p=394&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=programming-the-arduino-uno-with-eclipse-on-linux</link>
		<comments>http://android.serverbox.ch/?p=394#comments</comments>
		<pubDate>Tue, 20 Dec 2011 15:48:20 +0000</pubDate>
		<dc:creator>Andreas Rudolf</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=394</guid>
		<description><![CDATA[This is the first of a series of three posts. The ultimate goal is to setup a communication interface between an Arduino Uno/Mega board and an Android tablet over USB. Everything will be as user-friendly as possible, i.e. no root will be required on your Android tablet. The following posts Arduino USB transfers and Android [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=394"></g:plusone></div><p>This is the first of a series of three posts. The ultimate goal is to setup a communication interface between an Arduino Uno/Mega board and an Android tablet over USB. Everything will be as user-friendly as possible, i.e. no root will be required on your Android tablet. The following posts <a href="http://android.serverbox.ch/?p=427" title="Arduino USB transfers">Arduino USB transfers</a> and <a href="http://android.serverbox.ch/?p=549" title="Android USB Host + Arduino: How to communicate without rooting your Android Tablet or Phone">Android USB Host + Arduino: How to communicate without rooting your Android Tablet or Phone</a> conclude the series.</p>
<p><a href="http://android.serverbox.ch/wp-content/uploads/2011/12/part11.png"><img src="http://android.serverbox.ch/wp-content/uploads/2011/12/part11-300x204.png" alt="" title="part1c" width="300" height="204" class="aligncenter size-medium wp-image-542" /></a></p>
<p>The <a href="http://arduino.cc/en/Main/ArduinoBoardUno">Arduino Uno</a> is a popular and affordable hardware platform which comes with its own IDE and core libraries for programming. If you like the Arduino IDE you may skip this post, however, if you feel more comfortable developing in Eclipse this might help you out.<br />
We are using Ubuntu 11.10 (oneiric ocelot) and Eclipse 3.6.1 (helios), although this should not play an important role (as it turns out, Eclipse Indigo might need a few tweaks, check the end of this post). Also, setting up Eclipse for programming the Arduino Uno Atmega328P is pretty straightforward. Nevertheless, here is a quick how-to for the Arduino Uno (Arduino Mega 2560 below):</p>
<ol>
<li>
Install avrdude and AVR libraries:<br />
<code>sudo apt-get install gcc-avr avr-libc avrdude</code>
</li>
<li>Start Eclipse and <strong>install CDT Plugin</strong> (C/C++ Development Tools):
<ul>
<li>Help -> Install New Software&#8230;</li>
<li>Work with: (your current Eclipse version)<br />i.e. &#8220;Helios &#8211; http://download.eclipse.org/releases/helios&#8221;</li>
<li>Download the &#8220;pending&#8221; software package (don&#8217;t worry, download starts automatically <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</li>
<li>Choose &#8220;Programming Languages&#8221; and select &#8220;C/C++ Development Tools&#8221;</li>
<li>Accept and continue by restarting Eclipse</li>
</ul>
</li>
<li>Install <strong>AVR Eclipse Plugin</strong>:
<ul>
<li>Help -> Install New Software&#8230;</li>
<li>Add new repository: http://avr-eclipse.sourceforge.net/updatesite/</li>
<li>Re-download the &#8220;pending&#8221; software package, download will be faster since it is probably cached <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </li>
<li>Download AVR Eclipse Plugin and restart Eclipse</li>
</ul>
</li>
<li>Create new C project named &#8220;BlinkBlink&#8221;:
<ul>
<li>Project Type <strong>AVR Cross Target Application</strong> (Empty Project, AVR-GCC Toolchain)</li>
<li>Click next&#8230;</li>
<li>Untick &#8220;Debug&#8221; (in Debug mode, no hex-files are generated and avrdude can&#8217;t flash the device)</li>
<li>Click Advanced settings&#8230;</li>
<li>AVR -> AVRDude -> Programmer configuration&#8230;</li>
<li>Create a new programmer and name it &#8220;Arduino Uno&#8221;. Make sure this newly created programmer configuration is selected for the current project.
<ul>
<li>Programmer Hardware: <strong>Arduino</strong></li>
<li>Override default port: <strong>/dev/ttyACM0</strong> or similar</li>
<li>Override default baudrate: <strong>115200</strong></li>
</ul>
</li>
<li>AVR -> Target Hardware:
<ul>
<li>MCU Type: <strong>ATmega328P</strong> (or load from MCU)</li>
<li>MCU Clock Frequency: <strong>16000000</strong> (default external clock source of Arduino Uno)</li>
</ul>
</li>
</ul>
</li>
<li>Click Apply and OK to leave the properties window and click Finish to create the new project in the workspace.</li>
<li>Create a new source file main.c and copy the contents from <a href="http://android.serverbox.ch/wp-content/uploads/2011/12/main.c">this link</a>. Make sure to save main.c before proceeding (File -> Save).</li>
<li>Project -> Build Project</li>
<li>Click on the AVR Button within Eclipse to upload the generated hex file from BlinkBlink/Release/BlinkBlink.hex.<br />
Your Arduino Uno&#8217;s LED should be blinking on and off repeatedly. If somehow it doesn&#8217;t work, right-click your Project and select Properties. Make sure all AVR and Programmer settings are active as mentioned above.
</li>
</ol>
<p>For the Arduino Mega 2560 you should choose <strong>Atmel STK500 Version 2.x firmware</strong> as Programmer Hardware, and <strong>ATMega2560</strong> as target hardware, the rest is the same as with the Arduino Uno. Also, if you are using the above source file for testing, you should change the definition of LED from PB5 to PB7, since the LED on the Arduino Mega is on Pin7 of Port B.</p>
<p><strong>Update:</strong> if you are using Eclipse Indigo, some specific AVR symbols such as DDRB (data direction register of port b) may not be recognized.<br />
To solve this problem go to preferences&#8230;
<ul>
<li>C/C++</li>
<li>Language Mappings</li>
<li>Add the following mappings:
<ul>
<li>Content Type: C Header File / Language: GNU C</li>
<li>Content Type: C Source File / Language: GNU C</li>
</ul>
</li>
</ul>
<p>Your Language Mapping preference window should look like the following screenshot:<br />
<a href="http://android.serverbox.ch/wp-content/uploads/2011/12/scr.png"><img src="http://android.serverbox.ch/wp-content/uploads/2011/12/scr.png" alt="" title="Eclipse Indigo AVR Language Mappings" width="713" height="514" class="aligncenter size-full wp-image-556" /></a><br />
If it still does not work, also try adding this line at the beginning of your main.c source file:<br />
<code>#include &lt;avr/iom128.h&gt;</code></p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=394"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=394</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Creating a Serial to USB driver using the Android USB-Host API</title>
		<link>http://android.serverbox.ch/?p=370&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=370</link>
		<comments>http://android.serverbox.ch/?p=370#comments</comments>
		<pubDate>Fri, 16 Sep 2011 10:11:58 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=370</guid>
		<description><![CDATA[Lately we have received many concerns about using the serial interface on Android (Honeycomb with USB-Host). The way to usually communicate with a USB-Serial device in Linux, is to create a virtual serial interface and use it like a normal serial interface. For instance if you connect an FTDI controller via USB, a device /dev/ttyUSBX [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=370"></g:plusone></div><p>Lately we have received many concerns about using the serial interface on Android (Honeycomb with USB-Host). The way to usually communicate with a USB-Serial device in Linux, is to create a virtual serial interface and use it like a normal serial interface. For instance if you connect an FTDI controller via USB, a device /dev/ttyUSBX will be created.</p>
<div id="attachment_377" class="wp-caption alignleft" style="width: 330px"><a href="http://android.serverbox.ch/wp-content/uploads/2011/09/serial.png"><img src="http://android.serverbox.ch/wp-content/uploads/2011/09/serial.png" alt="" title="USB-Serial Connection" width="320" height="240" class="size-full wp-image-377" /></a><p class="wp-caption-text">USB-Serial Connection connects streams to Bulk Endpoints</p></div>
<p>However, behind the scenes you are actually communicating with the device using plain USB Bulk transfers. This job is done by the USB-Serial driver for you (ftdi_sio for instance). If you like to avoid using the kernel driver for some reason you can do this by using a library based on libusb called <a href="http://www.intra2net.com/en/developer/libftdi/" target="_blank">&#8220;libftdi&#8221;</a>.</p>
<p>If you look at the source code you will notice that this library manages the connection (depending on the chip type) to the serial controller. Part of this task for instance is resetting TX/RX or setting the baudrate, which is not entirely trivial as it turns out.</p>
<p>Reading data is pretty simple (if your IN packet returns more than two bytes there is data ready). While when sending data you have to be sure not to write more than the max packet size defined by the controller. For details see the source code of libftdi.</p>
<p>Looking at Android there is a core problem with serial devices. As shown in a previous article it is pretty complicated to <a href="http://android.serverbox.ch/?p=285" target="_blank">get started with building the driver</a>. However, the even more painful part is, that there is no API-featured way to receive permissions for the /dev/USBX device node! So root is required.</p>
<p>But Hey! With libftdi, or it&#8217;s implementation it is now possible to write your own driver using the Android USB Host API. In the attached example application a connection to a VNC2 Controller is opened and each seconds one byte is transferred. For the example LEDs on the board are toggled. Using the Bulk OUT EP a rs232 &#8220;write&#8221; is emulated.</p>
<p><a href='http://android.serverbox.ch/wp-content/uploads/2011/09/FTDI_USB.tar.gz'>Download the Android source</a><br />
Note that you should change the VID_PID String according to your device &#8220;VVVV:PPPP&#8221;.<br />
Also note that if you would like to test if this works on your computer you should first remove the ftdi_sio driver using:<br />
<code>$ sudo rmmod ftdi_sio</code>.</p>
<p>Debugging on your Ubuntu machine:<br />
It&#8217;s probably much easier to debug on your workstation. Recently I found pyusb pretty helpful:<br />
<code>$ sudo apt-get install python-usb</code>.<br />
Here is a python script that will get you started: <a href="http://android.serverbox.ch/wp-content/main.py" target="_blank">main.py</a>.</p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=370"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=370</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Honeycomb Tablet optimized version of the Android Oscilloscope</title>
		<link>http://android.serverbox.ch/?p=354&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=honeycomb-tablet-optimized-version-of-the-android-oscilloscope</link>
		<comments>http://android.serverbox.ch/?p=354#comments</comments>
		<pubDate>Fri, 19 Aug 2011 11:24:42 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=354</guid>
		<description><![CDATA[The ultimate goal of our Bachelors Thesis one year ago was to deliver a &#8220;market-ready&#8221; version of our oscilloscope project where you can just install an app from the market and connect the oscilloscope over USB. Before the &#8220;Tablet Age&#8221; our idea was to set up the OTG port of a phone for host mode. [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=354"></g:plusone></div><p>The ultimate goal of our Bachelors Thesis one year ago was to deliver a &#8220;market-ready&#8221; version of our oscilloscope project where you can just install an app from the market and connect the oscilloscope over USB.</p>
<p>Before the &#8220;Tablet Age&#8221; our idea was to set up the OTG port of a phone for host mode. However, this requires rooting the phone as well as adding a voltage supply to the connector. Not a very elegant solution.</p>
<p>When the first tablets with honeycomb arrived (3.0) we managed to use the host port on a rooted device to get our oscilloscope working. Still, root was required.</p>
<p>With Honeycomb 3.1 it was not only possible to acquire permission of the USB device it also became possible to program USB with the Java API rather than to go native with libusb.</p>
<p>Therefore we have written a tablet optimized version of our oscilloscope. With the all new user interface comes the ability to connect to our USB oscilloscope. You can get the application from the <a href="https://market.android.com/details?id=ch.serverbox.android.osciprime&amp;feature=more_from_developer" target="_blank">Android Market</a> with your 3.0 and up tablet. Get the source code: <a href="http://android.serverbox.ch/wp-content/uploads/2011/08/HoneyOsciPrime.tar.gz">HoneyOsciPrime.tar.gz</a>, or the APK <a href="http://android.serverbox.ch/wp-content/HoneyOsciPrime.apk">HoneyOsciPrime.apk</a>. You can always download our Layout Files <a href="http://web.fhnw.ch/technik/projekte/eit/Fruehling2010/DiCerRud/">here</a> and build your own oscilloscope or contact us for support.</p>
<div id="attachment_356" class="wp-caption alignnone" style="width: 2570px"><a href="http://android.serverbox.ch/wp-content/uploads/2011/08/IMG_20110819_123201.jpg"><img class="size-full wp-image-356" title="Acer A500 running OsciPrime" src="http://android.serverbox.ch/wp-content/uploads/2011/08/IMG_20110819_123201.jpg" alt="" width="2560" height="1920" /></a><p class="wp-caption-text">Acer A500 running OsciPrime</p></div>
<div id="attachment_357" class="wp-caption alignnone" style="width: 1290px"><a href="http://android.serverbox.ch/wp-content/uploads/2011/08/device-2011-08-14-000312.png"><img class="size-full wp-image-357" title="Screenshot of the new Honeycomb OsciPrime App" src="http://android.serverbox.ch/wp-content/uploads/2011/08/device-2011-08-14-000312.png" alt="" width="1280" height="800" /></a><p class="wp-caption-text">Screenshot of the new Honeycomb OsciPrime App</p></div>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=354"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=354</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Creating a remote Scroll Wheel for your Linux Machine using Android, Bluetooth and uinput</title>
		<link>http://android.serverbox.ch/?p=334&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-remote-scroll-wheel-for-your-linux-machine-using-android-bluetooth-and-uinput</link>
		<comments>http://android.serverbox.ch/?p=334#comments</comments>
		<pubDate>Mon, 25 Jul 2011 17:59:30 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Java]]></category>
		<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=334</guid>
		<description><![CDATA[Scrolling long documents can be tiring for your index finger on a mouse wheel or on a touch pad. What if you could use your phones touch screen to scroll a document on your computer? While maybe not the most ergonomically solution it may well be a good example of how to work with bluetooth, [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=334"></g:plusone></div><p>Scrolling long documents can be tiring for your index finger on a mouse wheel or on a touch pad. What if you could use your phones touch screen to scroll a document on your computer? While maybe not the most ergonomically solution it may well be a good example of how to work with bluetooth, uinput and Android.</p>
<p><a href="http://android.serverbox.ch/wp-content/uploads/2011/07/scrolling.png"><img src="http://android.serverbox.ch/wp-content/uploads/2011/07/scrolling.png" alt="" title="scrolling" width="599" height="471" class="aligncenter size-full wp-image-338" /></a></p>
<p><strong>Setup</strong><br />
Android Phone ( >= 2.1)<br />
Ubuntu Laptop with Bluetooth<br />
Two great Tutorials:<br />
Bluez: <a href="http://people.csail.mit.edu/albert/bluez-intro/x604.html">http://people.csail.mit.edu/albert/bluez-intro/x604.html</a><br />
uinput: <a href="http://thiemonge.org/getting-started-with-uinput">http://thiemonge.org/getting-started-with-uinput</a></p>
<p><strong>Concept</strong><br />
The application consists of two parts:</p>
<ul>
<li>A client side on the phone that serves as touch pad to scroll.</li>
<li>A server part on the computer that receives commands from the phone and emulates scroll movement for uinput.</li>
</ul>
<p>The Client is a simple Android Activity spawning a Bluetooth Thread. Touch events then result in a Bluetooth packet that tell the server if the user moved up or down. The source code is very straight forward; only Thread synchronization is a bit tricky as well as the way how the application is stopped (locks etc.).</p>
<p>The Server application connects the world of Bluetooth (RFCOMM/SDP) with the uinput event input system. Basically the server registers an SDP entry and then listens on an RFCOMM channel for incoming connections. As soon as a connection is established a new input device is created and scroll events are sent. Note that you probably need to be root (or use sudo) on the Linux machine to feed uinput new events.</p>
<p><strong>Instructions</strong></p>
<ul>
<li>Pair your Android phone with the Linux device</li>
<li>Start the server on your Linux device: <code>$ sudo ./btserver </code>(make sure BT is turned on, else there could be a segfault -> working on that)</li>
<li>Install and start the app on the phone. In the menus select your Linux device.</li>
</ul>
<p><strong>Building Dependencies</strong><br />
To build the dev-libbluetooth package was necessary on our Ubuntu machine.</p>
<p>The code is available under GPL. Have fun playing around with it <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Note: It&#8217;s very straight forward to create a remote control for your Linux machine with the sources. Key presses can be emulated very easily with uinput.</p>
<p><strong>Source Code</strong><br />
<a href='http://android.serverbox.ch/wp-content/uploads/2011/07/Android-Simple-Scrolling.tar.gz'>Android Sources</a><br />
<a href='http://android.serverbox.ch/wp-content/scrollpad++.apk'>Android APK</a><br />
<a href='http://android.serverbox.ch/wp-content/scrolling.tar.gz'>Server code for Linux</a><br />
<a href='https://market.android.com/details?id=ch.serverbox.android.scrolling&#038;feature=search_result'>Our App on the Android Market</a></p>
<p>Leave a comment if you like what we did or have some improvements <img src='http://android.serverbox.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=334"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=334</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to programmatically remove/hide the system bar in Honeycomb (requires root)</title>
		<link>http://android.serverbox.ch/?p=306&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-programmatically-removehide-the-system-bar-in-honeycomb-requires-root</link>
		<comments>http://android.serverbox.ch/?p=306#comments</comments>
		<pubDate>Mon, 27 Jun 2011 11:15:07 +0000</pubDate>
		<dc:creator>Manuel Di Cerbo</dc:creator>
				<category><![CDATA[Android Platform]]></category>

		<guid isPermaLink="false">http://android.serverbox.ch/?p=306</guid>
		<description><![CDATA[Without the system bar it is almost impossible to control your Honeycomb tablet. Since no hardware control buttons are enforced for the tablet the system bar is the only way to control your slate. However, if your application incorporates a way of removing the bar and on leaving restarting the bar there is no reason [...]]]></description>
				<content:encoded><![CDATA[<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=306"></g:plusone></div><p>Without the system bar it is almost impossible to control your Honeycomb tablet. Since no hardware control buttons are enforced for the tablet the system bar is the only way to control your slate.</p>
<p>However, if your application incorporates a way of removing the bar and on leaving <strong>restarting</strong> the bar there is no reason why not to support such a feature.</p>
<p>The easy part: Restarting the bar</p>
<p>Restarting the bar is pretty simple, drop to a shell and start the service using the &#8220;am&#8221; command:<br />
<code># am startservice -n com.android.systemui/.SystemUIService</code></p>
<p>The difficult part is to shut it permanently down. One way is to navigate to the application settings and shut it down with the &#8220;force close&#8221; button. However, attempting to kill the process with</p>
<p><code># killall com.android.systemui</code></p>
<p>will remove the bar for a few seconds. Sadly, it will return eventually since in the applications manifest file the &#8220;persistent&#8221; parameter enforces the system to restart the service unless it is shut down properly by the &#8220;system&#8221; user itself.</p>
<p>The following magic line will shut down the bar permanently if executed as root:</p>
<p><code># service call activity 79 s16 com.android.systemui</code></p>
<p>What it does is sending the Activitymanager a shutdown signal for the systemui service.<br />
This method was tested on an Iconia A500 with Android 3.01; although it should work with other devices as well (since the source code that we use is common).</p>
<p><strong>Putting it together</strong></p>
<p>To remove the system bar from your application create and execute a process:</p>
<p><code>Process proc = Runtime.getRuntime().exec(new String[]{"su","-c","service call activity 79 s16 com.android.systemui"});<br />
proc.waitFor();<br />
</code></p>
<p>To restore the system bar use the following code snippet:</p>
<p><code>Process proc = Runtime.getRuntime().exec(new String[]{"am","startservice","-n","com.android.systemui/.SystemUIService"});<br />
proc.waitFor();<br />
</code></p>
<div class="plus-one-wrap"><g:plusone href="http://android.serverbox.ch/?p=306"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://android.serverbox.ch/?feed=rss2&#038;p=306</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
