« February 2007 | Main | April 2007 »

March 02, 2007

GPS BETTER DATA

RMC PARSED DATA

I manipulated the code a bit, most likely making some mistakes, but i parsed the data now that I realized for the purpose of the Tsunameter location RMC better fits my needs.

// import the serial library:
import processing.serial.*;

int utc = 0; // UTC Time
float latitude = 0.0; // the longitude reading in degrees
String northSouth; // north or south?
float longitude = 0.0; // the longitude reading in degrees
String eastWest; // east or west?
float speed = 0.0; // the speed over ground
float course = 0.0; // the course over ground
int date = 0;
float magnetic = 0.0;
int linefeed = 10; // linefeed in ASCII
int carriageReturn = 13; // carriage return in ASCII
Serial myPort; // The serial port

void setup() {
// List all the available serial ports
println(Serial.list());

// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[2], 4800);

// read bytes into a buffer until you get a carriage return (ASCII 13):
myPort.bufferUntil(carriageReturn);
}

void draw() {
// not doing anything here
}

// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():

void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil(linefeed);
// if you got any bytes other than the linefeed:
if (myString != null) {
// print it:
parseString(myString);
}
}
//Then replace println(myString); above with parseString(myString);
//Then add this method at the end of the program:
void parseString(String serialString) {
// split the string at the commas
//and convert the sections into integers:
String items[] = (split(serialString, ','));
// if the first item in the sentence is our identifier, parse the rest:
if (items[0].equals("$GPRMC") == true) {
// move the items from the string into the variables:
utc = int(items[1]);
latitude = float(items[3]);
northSouth = items[4];
longitude = float(items[5]);
eastWest = items[6];
speed = float(items[7]);
course = float(items[8]);
date = int(items[9]);
magnetic = float (items[10]);

//println (UTC + latitude + northSouth + longitude + eastWest + speed + course + date + magnetic);
println ("UTC:" + utc + "," + "LATITUDE:" + latitude + northSouth + "," + "LONGITUDE:" + longitude + eastWest + "," + "SPEED:" + speed + "," + "COURSE:" + course + "," + "DATE:" + date + ","
+ "MAGNETIC:" + magnetic);
}
}

And here is the result:

RCM.png

March 06, 2007

TSUNAMI PERFORMANCE

POSSIBLE PERFORMANCE FOR LIVE IMAGE PROCESSING

I have been struggling with the idea of having a performance on the Tsunami for quite some time. At first i thought of an interactive installation, then a dance piece and now that I am working on building a tiny mock of a tsunami detection system, i thought it would be a great interface for site-specific performances wherever there is water or an ocean.

The prototype (it will just give a rough idea of some of the components necessary for the Tsunameter system) will include for now:

-GPS receiver (for position, speed and altitude)
-Accelerometer (possible for wave ondulation)
-Hydrophone (to "listen" to the ocean)
-Depth Sounder/Fish Finder (for point of reference and wave height calculations)
-Later a Zigbee Radio, or Bluetooth or Cellphone module (for wireless datalogging)
-Microcontroller to handle the signals

tsunameter_protoc.png

What I am hoping to achieve for the class is to write a series of simple Jitter patches that can:

-use the accelerometer information maybe for some data vizualization of the roughness of the water;
-use the hydrophone sound to add a site-specific and acoustic element to the performace;
-use the data from the sensors to move the images-video in a non linear way during my performance which might still be a mixture of dance, theatre and typical sri lankan or local dancing.

I would ideally like to add some instruments like percussion and have the space interact with me in a very effective but quite simple way.

Example of wave visualization:

wave.png

Example of possible video manipulation (obviously a little bit more complex than this one, just to give hte idea!):

sample.png


March 11, 2007

GPS SPARKFUN MODULE

GPS READING ATTEMPT

I have been trying to interface the GPS Module EM406 from Sparkfun with Arduino, and then later Arduino Mini. I have had some issued figuring out the pin connections, but now what i am struggling with is the code. This is the code i borrowed from the Tutorials and made some changes to:

#include
#include

#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 0;
byte tx = 1;
byte SWval;
char dataformat [7] = "$GPRMC";
char messageline[80] = "";
int i = 0;

void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
//digitalWrite(rx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
//SWprint('h'); //debugging hello
//SWprint('i');
//SWprint(10); //carriage return
Serial.begin (4800);
}

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit4800Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit4800Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}

void char2string()
{
i=0;
messageline[0] = SWread();
if (messageline [0] == 36) //string starts with $
{
i++;
messageline [i] = SWread();
while (messageline[i] != 13 & i<80) //carriage return or max size
{
i++;
messageline [i] = SWread ();
}
messageline [i+1] = 0; //make end to string
}
}

void loop()
{
digitalWrite (13,HIGH);
char2string();
if (strncmp(messageline, dataformat, 6) == 0 & i>4){
for (int i=0; i Serial.println(messageline [i], BYTE);
}
}
//Serial.print(SWread(), BYTE); use this to get all GPS output comment out from char2string till here
}

Unfortunately this is what i get for data and i only receive serial data when pressing the RESET button:

gpsdataerror.png

"$GPRMC" is the NMEA format that I am looking to parse out. Any suggestions?

March 12, 2007

GPS SPARKFUN MODULE $GPRMC

FINALLY!

So finally, by using 2 digital pins on the Arduino for serial communication it worked! I might need to parse some data out that i don't need, but this is looking good! Now i can move to adding the accelerometer.

#include
#include

#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;
char dataformat [7] = "$GPRMC";
char messageline[80] = "";
int i = 0;

void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
//digitalWrite(rx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
//SWprint('h'); //debugging hello
//SWprint('i');
//SWprint(10); //carriage return
Serial.begin (4800);
}

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit4800Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit4800Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}

void char2string()
{
i=0;
messageline[0] = SWread();
if (messageline [0] == 36) //string starts with $
{
i++;
messageline [i] = SWread();
while (messageline[i] != 13 & i<80) //carriage return or max size
{
i++;
messageline [i] = SWread ();
}
messageline [i+1] = 0; //make end to string
}
}

void loop()
{
digitalWrite (13,HIGH);
char2string();
if (strncmp(messageline, dataformat, 6) == 0 & i>4){
for (int i=0; i Serial.print(messageline [i], BYTE);
}
}
//Serial.print(SWread(), BYTE); use this to get all GPS output comment out from char2string till here
}

And here's what the serail monitor spits out:

GPSgood!.png

March 13, 2007

ADXL 3xx ACCELEROMETER

ACCELEROMETER TEST

So i now am going to implement the Tsunameter mock with an accelerometer. Since i have never used one before i am not sure of what normal values are, but this is what the mock looks like so far:

mock.jpg

The code i used for the Arduino is probably not correct, but so far it just reads in the serial data from the 3 axes of the accelerometer, from there i am assuming i am supposed to do some kind of math or calculation to calibrate the data, but for now this is what it looks like:

acc.png

And after i figure out how to exactly implement the accelerometer, then i will add the hydrophone i received today.

hydrophone.jpg

March 17, 2007

ACCELEROMETER AND GPS

ADDING THE TWO CODES TOGETHER

I have been working this weekend on adding the 2 pieces of codes together, i had to settle for 4800 Serial communication and i have been having some isses in displaying and parsing the string of the GPS.

First i fixed the GPS code so that i could finally have the serial printing stop after the date and then add a new line feed. So now it looks like this:

GPSvert.png

Although it still has a few issues.

The new accelerometer and GPS code is this:


#include
#include

#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;
char dataformat [7] = "$GPRMC";
char messageline[80] = " ";
int i = 0;
int ledPin = 13;
int xPin = 2;
int yPin = 1;
int zPin = 0;
int valX = 0;
int valY = 0;
int valZ = 0;

void setup() {

pinMode(ledPin, OUTPUT);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
//digitalWrite(rx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
//SWprint('h'); //debugging hello
//SWprint('i');
//SWprint(10); //carriage return
Serial.begin (4800);
}

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit4800Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit4800Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}

void char2string()
{
i=0;
messageline[0] = SWread();
if (messageline [0] == 36) //string starts with $
{
i++;
messageline [i] = SWread();
while (messageline[i] != 13 & i<64) //carriage return or max size
{
i++;
messageline [i] = SWread ();
}
messageline [i] = 0; //make end to string
}
}

void loop()
{
digitalWrite (13,HIGH);
char2string();
if (strncmp(messageline, dataformat, 6) == 0 & i>4){
for (int i=0; i Serial.print(messageline [i], BYTE);
}
Serial.print(10, BYTE);
}
// read the accelerometer pins
valX = analogRead(xPin);
valY = analogRead(yPin);
valZ = analogRead(zPin);

Serial.print("X: ");
Serial.println(valX, DEC);
Serial.print("Y: ");
Serial.println(valY, DEC);
Serial.print("Z: ");
Serial.println(valZ, DEC);
delay (250);
//Serial.print(SWread(), BYTE); use this to get all GPS output comment out from char2string till here
}

This is what i get:

AccGps.png

But it only displays one byte of the GPS reading at the time, while i want the entire string. I can't figure out what's wrong with it.

March 18, 2007

GPS AND ADXL BETTER CODE!

AFTER SLEEPLESS NIGHTS...

I managed to finally print the sensors inputs better. I still have to do averages and standard deviation on the accelerometer input but i managed to finally have the GPS string printed completely.

The new code is:

#include
#include

#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94

byte rx = 6;
byte tx = 7;
byte SWval;
char dataformat [7] = "$GPRMC";
char messageline[80] = "";
int i = 0;
int xPin = 2;
int yPin = 1;
int zPin = 0;
int valX = 0;
int valY = 0;
int valZ = 0;

void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(zPin, INPUT);
digitalWrite(tx,HIGH);
//digitalWrite(rx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
//SWprint('h'); //debugging hello
//SWprint('i');
//SWprint(10); //carriage return
Serial.begin (4800);
}

void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit4800Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit4800Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit4800Delay);
}

int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit4800Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit4800Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit4800Delay);
delayMicroseconds(bit4800Delay);
return val;
}
}

void char2string()
{
i=0;
messageline[0] = SWread();
if (messageline [0] == 36) //string starts with $
{
i++;
messageline [i] = SWread();
while (messageline[i] != 13 & i<64) //carriage return or max size
{
i++;
messageline [i] = SWread ();
}
messageline [i] = 0; //make end to string
}
}

void loop()
{
digitalWrite (13,HIGH);
char2string();
if (strncmp(messageline, dataformat, 6) == 0 & i>4){
for (int i=0; i //Serial.print(10,BYTE);
Serial.print(messageline [i], BYTE);
// read the accelerometer pins
}
Serial.println(10, BYTE);
valX = analogRead(xPin);
valY = analogRead(yPin);
valZ = analogRead(zPin);

Serial.print("X: ");
Serial.println(valX, DEC);
Serial.print("Y: ");
Serial.println(valY, DEC);
Serial.print("Z: ");
Serial.println(valZ, DEC);
//delay (250);
Serial.print(10,BYTE);
}
//Serial.print(SWread(), BYTE); use this to get all GPS output comment out from char2string till here
}

And here's the result:

newresult.png

March 23, 2007

SERIAL DATA IN MAX

GPS AND ACCELEROMETER DATA IN MAX

Thanks to Luke's help, I managed to get the serial data parsed out in Max. I am starting to visualize the data to try to make some sense of it. This is my first patch for this project. Many more to follow.

Maxpatch.png

March 27, 2007

GL AND SMOOTHING ATTEMPT

ATTEMPT IN MAX TO SMOOTH OUT X,Y,Z AND OPEN GL

I have been trying to smooth out the signal coming in from the accelerometer. I started by dividing by 2, although i think i will remove that part. Then i made the average between the new and old value. I will apply a simple averaging or moving averaging math to the Arduino program or I will do it in MAX. I can't figure out which one is more reliable and less energy consuming. I think MAX would be the best option, but with Serial data sometimes i have seen it crash.

patch_gl.png


Then I started playing with the plane with Open GL objects, but i am still far from a good result. I will see what i can do.

sq1.png sp2.png sp3.png