Feeds:
Posts
Comments

Archive for February, 2012

In this post I’ll show how to establish a serial communication (over USB) between the BeagleBoard and Arduino using a Java program. The Program will  send commands from BB-XM to toggle a LED on the Arduino.

Hardware components:

Arduino Set Up
Before begin interfacing BeagleBoard with Arduino, you must have the Arduino IDE installed and configured. Once it is done, upload the following sketch from your PC:

void setup(){

Serial.begin(9600);
pinMode(13, OUTPUT);

}

void loop (){

if (Serial.available()) {

//read serial as ascii integer
int ser = Serial.read();

//The ascii equivalent of numbers 0-9 are 48-57
if(ser >= 48 && ser <= 57) {
   int xTimes = ser - 48;
   Serial.print("Blink LED x");
   Serial.println(xTimes,DEC);
   TooglePin(13,xTimes);
   }
 }

}

void TooglePin(int pin,int n){

   for (int i = 0; i < n; i++) {
   digitalWrite(pin, HIGH);
   delay(1000);
   digitalWrite(pin, LOW);
   delay(1000);
  }
}

This sketch will basically set Arduino to read incoming serial data as ascii
integer, if it’s between 0-9 then the pin 13 (LED) is toogled xTimes (incoming command).

BeagleBoard Set Up
For the Software Angstrom Linux will be used, the default kernel has support for tty ACM devices (Arduino) if not you can use opkg to install the kernel module:

opkg install kernel-module-cdc-acm

when Arduino is attached to the Beagleboard, something like that should be displayed:

[ 7963.286163] usb 2-2.4: new full speed USB device using ehci-omap and address 16
[ 7963.417602] usb 2-2.4: New USB device found, idVendor=2341, idProduct=0043
[ 7963.425354] usb 2-2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[ 7963.433959] usb 2-2.4: Manufacturer: Arduino (www.arduino.cc)
[ 7963.439788] usb 2-2.4: SerialNumber: 7493430303035111E150
[ 7963.459197] cdc_acm 2-2.4:1.0: ttyACM0: USB ACM device

Not so well known but the full Java Standard Edition can run on the BeagleBoard, luckily it is available in the Angstrom package feed.
you need to install for that the openjdk-6 java runtime environment on the BeagleBoard:

opkg install openjdk-6-jre

For Java serial communication the RxTx library is needed:

opkg install librxtx-java librxtx-jni

Now the BeagleBoard is ready to talk to Arduino using Java:

SerialComm.java

import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;

import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class SerialComm
{
/** Milliseconds to block while waiting for port open */
private static final int TIME_OUT = 2000;

/** Default bits per second for COM port. */
private static final int DATA_RATE = 9600;

public SerialComm()
{
super();
}

void connect ( String portName ) throws Exception
{
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
{
System.out.println("Error: Port is currently in use");
}
else
{
CommPort commPort = portIdentifier.open(this.getClass().getName(),TIME_OUT);

if ( commPort instanceof SerialPort )
{
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(DATA_RATE,
                               SerialPort.DATABITS_8,
                               SerialPort.STOPBITS_1,
                               SerialPort.PARITY_NONE);

InputStream in = serialPort.getInputStream();
OutputStream out = serialPort.getOutputStream();

(new Thread(new SerialReader(in))).start();
(new Thread(new SerialWriter(out))).start();

}
else
{
System.out.println("Error: Only serial ports are handled by this example.");
}
}
}

/** */
public static class SerialReader implements Runnable
{
InputStream in;

public SerialReader ( InputStream in )
{
this.in = in;
}

public void run ()
{
byte[] buffer = new byte[1024];
int len = -1;
try
{
while ( ( len = this.in.read(buffer)) > -1 )
{
System.out.print(new String(buffer,0,len));
}
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}

/** */
public static class SerialWriter implements Runnable
{
OutputStream out;

public SerialWriter ( OutputStream out )
{
this.out = out;
}

public void run ()
{
try
{
int c = 0;
while ( ( c = System.in.read()) > -1 )
{
this.out.write(c);
}
}
catch ( IOException e )
{
e.printStackTrace();
}
}
}

public static void main ( String[] args )
{
try
{
(new SerialComm()).connect(args[0]);
}
catch ( Exception e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

This simple code open a serial connection and then interact with it (receiving and sending data).
To be compiled on a Host PC (with an installed JDK) using:

javac SerialComm.java

The compiled classes need to be transferred on the BeagleBoard file system then can be started with:

root@beagleboard:~# java -cp .:/usr/share/java/RXTXcomm.jar \
-Djava.library.path=/lib:/usr/lib/jni \
-Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0 \
SerialComm /dev/ttyACM0

The Java program need to be supplied with the Serial port name /dev/ttyACM0 as an argument. Now you can blink the LED from the Beagle by simply writing on the console numbers between 0-9 :

Advertisement

Read Full Post »

In this post , I’ll describe  a practical use of the Beagleboard :  It’s about building a Wireless IP camera for Home surveillance.

Hardware components:

This slideshow requires JavaScript.

The Set-up of the Wi-Fi dongle and the camera were described in previous posts on this blog.

For the Software I used Angstrom Linux and  MJPG-Streamer which is not available as an Angstrom package but I had to build it manually for the Beagleboard:

First checkout the source from the Subversion repository :

svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer

then cross compile it by issuing :

cd  mjpg-streamer/mjpg-streamer &&
make CC=arm-angstrom-linux-gnueabi-gcc

If the build is successful it will generate “mjpg_streamer” binary and  plugins : a set of shared libraries (*.so)
that you need to transfert to the  filesystem of the SDCard  plus the “www” folder.

Finally  you can lunch the mjpg-streamer webserver with :

./mjpg_streamer -i "./input_uvc.so -d /dev/video0 -y" -o "./output_http.so -w ./www"

(or put it in a script that start automatically)

The mjpg-streamer is listening on the TCP PORT 8080 so you’ll able to view the video stream by pointing any  browser on the beagleboard IP address:

http://beagleboard:8080

you can also configure your router to allow external access from the Internet on your video stream by enable 8080 port  forwarding.

Here is a live demo video (view from my balcony):

and here is a nightly stream demo:

Read Full Post »

I just made the first steps to make Android ICS working with the ULCD7 🙂

I’ll write a how-to and publish the patches as soon as I have finished.

here are the first pictures:

Read Full Post »