Talk to GPS - Processing does it, can Max?
Hi,
I'm able to use Processing as a server to get info from an integrated GPS unit into Max (mxj net.tcp.recv) but I want to know if it's possible to do it from Max directly using the serial object.
The serial call in Processing is able to find the port /dev/cu.usbserial while the Max one won't seem to find it. Is there a way I can force Max to access that port? Is there some message I can send to serial even if "print" doesn't list the port as available? Is it possible to do it from Javascript, Java, or perhaps directly from C (creating my own object, I guess?)
Thanks,
Modbook (tablet mac) Mac OS X 10.5.4 Max/MSP 5.0.3, GlobalSAT GPS
Andrew,
This is really interesting, and I encourage you to keep at it.
Can you provide more details on the GPS interface? how it works?
documentation? What are you doing in processing to make this work? (a
demo file would be nice). How can I test this myself?
Let us know how it goes--
Jerzy
On 8/26/08, Andrew Roth wrote:
>
> Hi,
>
> I'm able to use Processing as a server to get info from an integrated GPS unit into Max (mxj net.tcp.recv) but I want to know if it's possible to do it from Max directly using the serial object.
>
> The serial call in Processing is able to find the port /dev/cu.usbserial while the Max one won't seem to find it. Is there a way I can force Max to access that port? Is there some message I can send to serial even if "print" doesn't list the port as available? Is it possible to do it from Javascript, Java, or perhaps directly from C (creating my own object, I guess?)
>
> Thanks,
>
> Modbook (tablet mac) Mac OS X 10.5.4 Max/MSP 5.0.3, GlobalSAT GPS
>
I will post the actual files probably within the month as I work out the bugs, I'm coding in JS for the first time in Max.
Basically there is a processing file that reads from the serial ports by Tom Igoe which I'm using as the base. Then I've simply hacked in the code from the TCP/IP example in the processing library. It's not perfect but it gets you the info you need. The GPS I'm using is integrated otherwise I'd imagine you could get it directly from the serial object in Max. (The other problem is that the Moodbook I'm using has a tablet attached to one of the internal usb serial ports so fussing with the serial device often screws up the Wacom digitizer.)
Remember to poke a hole in your firewall.
The next thing I'm doing is running the output from there through a js object that translates the GPS data from Deg MM.Sec(dec) to Decimal Degrees. Though you could probably do that better than myself.
First launch the patcher with an mxj net.tcp.recv object set up for localhost and the port chosen in the processing code (7747).
Good luck, I'll post more as things come together.
/*
GPS NMEA 0183 reader
reads a GPS string in the NMEA 0183 format and returns lat/long.
For more on GPS and NMEA, see the NMEA FAQ:
http://vancouver-webpages.com/peter/nmeafaq.txt
by Tom Igoe
created 1 June 2006
*/
import processing.serial.*;
import processing.net.*;
int linefeed = 10; // linefeed in ASCII
int carriageReturn = 13; // carriage return in ASCII
Serial myPort; // The serial port
int sensorValue = 0; // the value from the sensor
float latDD;
float lonDD;
float latitude = 0.0; // the latitude reading in degrees
String northSouth; // north or south?
float longitude = 0.0; // the longitude reading in degrees
String eastWest; // east or west?
Client c;
String input;
int data[];
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 Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 4800);
// read bytes into a buffer until you get a linefeed (ASCII 13):
myPort.bufferUntil(carriageReturn);
//imported from processing eg.
frameRate(30); // Slow it down a little
c = new Client(this, "127.0.0.1", 7747);
}
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) {
// parse the string:
parseString(myString);
}
}
/*
parseString takes the string and looks for the $GPGLL header.
if it finds it, it splits the string into components at the commas,
and stores them in appropriate variables.
*/
void parseString(String serialString) {
// split the string at the commas
//and convert the sections into integers:
//problem is that it's on GPS degrees, minutes, seconds(dec) and therefore not properly formatted.
String items[] = (split(serialString, ','));
// if the first item in the sentence is our identifier, parse the rest:
if (items[0].equals("$GPGLL") == true) {
latitude = float(items[1]);
northSouth = items[2];
longitude = float(items[3]);
eastWest = items[4];
println(latitude + northSouth + "," +longitude + eastWest);
}
//c.write(items[0] + items[1] + items[2] + items[3] + items[4]+ "n");
c.write(latitude +" " + northSouth + " " + longitude +" " + eastWest + "n");
}
I have used a Garmin GPS with Max and the serial object.
What happens when you send a print message to the serial object?
Seems odd that it won't show up at all.
You could also look at the comport object by jasch, it's a slightly
different implementation of the serial obj.
I haven't had any luck finding the comport object. I have the jasch v4 objects. Do you have it?
it's one of the betas
look here:
www.jasch.ch/dl/jasch_objects_beta/
/*j
> I haven't had any luck finding the comport object. I have the jasch
> v4 objects. Do you have it?
I've never had a problem getting the serial object to talk to a USB device provided all the right drivers were installed. I'm surprised that the Macbook Pro has been giving you problems.
The only thing I can think of is that your GPS device may set itself up at a cu.usbserial port instead of tty.usbserial port. If that's the case, the Max serial object won't work, but processing will do the trick (more on that in a sec).
Another thing you might want to try with your old device is Kismac. It's a strange software that'll allow you to broadcast info from your GPS device through TCP/IP so you can pick it up with the mxj net.tcp.recv object. You could also try to access it through a program like Processing which has a slightly more sophisticated way to read your ports. I will actually be posting a processing locahost "server" I've been using to connect to my max patches from GPS shortly. It's based off of Tom Igoe's Processing sketch for reading NMEA 0183 sentences. I've even gone through the trouble of parsing this info into a matrix, I can post that patch on my website too (it's just on my other computer at the moment and I've barely had time to unpack since I've been home).
Let me know if you are interested in any of these solutions. I personally would be overjoyed if C74 included a way to read from the cu. ports in their external. Come to think of it, I should request that feature officially from Cycling.