We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › is it the USB-Serial adapter or me
Page Index Toggle Pages: 1
is it the USB-Serial adapter? or me? (Read 1579 times)
is it the USB-Serial adapter? or me?
Sep 13th, 2009, 10:46pm
 
Hi everyone,

I'm at the very beginning stages of developing a system for an art installation.  I'm using Processing with an Arduino and a USB-Serial converter (Tripp-Lite U209-000-R) to talk to a projector (Eiki LC-X999) from my sketch.  I downloaded an open source driver for the USB-Serial adapter, since this serial adapter was developed only for Windows machine.  I found the driver here: whoops just found that I'm a newbie and can't add URL's to posts yet... but I found it through google "U209-000-R OS X" under at erdelynet  

I believe that I'm able to talk to the adapter from the Mac, gauged by the fact the adapter shows up in my tty* device list and when I send write commands the LED on it lights up.

My trouble is that the projector is not responding to the commands I am sending from the sketch.  But if I use the exact same hardware minus (USB-Serial converter, DB-9 to mini-DIN cable, projector) on a Windows XP system via HyperTerminal I am able to send commands and have the projector respond accordingly.  Right now all I'm trying to do is turn it on, which is done as follows:

ASCII -- C00
Hex -- 43 30 30
and immediately following the command the projector requires a carriage return and line feed.
ASCII -- CRLF
Hex -- 0D 0A

all in all, my hex string for turn-on should be (which again, works in hyperterminal by typing 'C00<enter>'):  43 30 30 0D 0A

I'm not sure if the issue lies in the OS X driver for the USB-Serial adapter, or in the way that I'm writing the code, or in the ASCII to hex conversions that I'm doing...  The conversion is done as a combination of variable declarations before setup() and then when writing to the serial port a call to hex() is used.  The serial port write is carried out in the function initProjector().

Also, the connection parameters are matched between the platforms: 19200, 8-N-1.

Any help would be very, very, very much appreciated!!!

Thanks,
Sarah


// Import libraries
import processing.video.*;
import processing.serial.*;

// Camera Capture parameters
Capture cam;
MovieMaker mm;  // Declare MovieMaker object
PImage bkg;

// Arduino serial port parameters
Serial myArduino;
int inByte;

// temp  var
int i;

// Projector serial port parameters and commands
Serial myProjector;
int stringlen = 5;
int inByteProj;

// ASCII to hex translation
byte ascii0 = '0';
byte ascii1 = '1';
byte ascii2 = '2';
byte ascii3 = '3';
byte ascii4 = '4';
byte ascii5 = '5';
byte ascii6 = '6';
byte ascii7 = '7';
byte ascii8 = '8';
byte ascii9 = '9';
byte asciiLF = 10;     //x0A
byte asciiCR = 13;     //x0D
byte asciiA = 'A';
byte asciiB = 'B';
byte asciiC = 'C';
byte asciiD = 'D';
byte asciiE = 'E';
byte asciiF = 'F';


void setup() {
 size(640,480);
//  size(1280, 854);  // full screen
 
 // cam = new Capture(this, 320, 240);
 String[] devices = Capture.list();
 println(devices);
 cam = new Capture(this, width, height, devices[1]);
 cam.frameRate(30);

   
 // Create MovieMaker object with size, filename,
 // compression codec and quality, framerate
 mm = new MovieMaker(this, width, height, "test_vid.mov", 12, MovieMaker.VIDEO, MovieMaker.BEST, 3);
 
 // Backround image...
 bkg = loadImage("/Users/sbearse/Pictures/goodbye/providence2.jpg");
 
 // Serial port parameters
 println(Serial.list());
 myArduino = new Serial(this, Serial.list()[ 2], 9600);
 myProjector = new Serial(this, Serial.list()[ 4], 19200);

 // Initialize the projector
 initProjector();

 background(204);
}

void draw() {  
   if (cam.available() == true) {
   cam.read();
   image(cam, 0, 0);
   mm.addFrame();  // Add window's pixels to movie
   
   if (myArduino.available() > 0)
   { int inByte = myArduino.read();
     println(inByte);
    }
   }
 }


void keyPressed() {
 if (keyPressed) {
   if (key == 'x') {
   mm.finish();  // Finish the movie if space bar is pressed!
   println("finish");
 }
 if (key == 's') {
   initProjector();
 }
}
}

void initProjector() {
byte[] projON = new byte[stringlen];
projON[0] = asciiC;
projON[1] = ascii0;
projON[2] = ascii0;
projON[3] = asciiCR;
projON[4] = asciiLF;

 for(i=0; i<stringlen; i++) {
   // write each hex byte to serial port
   myProjector.write(hex(projON[i]));
   // print each byte to verify data
   print(hex(projON[i]));
   }
   
 println();
 // delay 40ms, requirement of projector
 delay(40);
}
Re: is it the USB-Serial adapter? or me?
Reply #1 - Sep 16th, 2009, 6:20pm
 
Hi,
Just wanted to mark this as a resolved issue.  In case others are interested...

Getting communication up and running was a matter of downloading the driver from the osx-pl2303 project at sourceforge.  (still a newbie and can't post links).  

And removing the hex() command from the myProjector.write call.  Projector does actually want ASCII formatted characters, and not hex.

Onwards to the next issue... Smiley

Sarah
Re: is it the USB-Serial adapter? or me?
Reply #2 - Sep 17th, 2009, 6:33am
 
Page Index Toggle Pages: 1