Arduino-OF

Hello! Recently I developed an interactive piece using Arduino-Adobe Air and I would like to move this prototype from Air/AS3 to OF/C++. I would like to know where can I find more information (code-examples) about the way to connect OF-ARDUINO. I know there is a library in progress (cppGlue), and also some examples to use Arduino with ofSerial - Is it right? But I couldn’t find examples or documentation about that. I also read in Safari the wonderful work-in-progress of “Programming Interactivity” (congratulation Joshua for this project), but the Arduino chapter wasn’t developed untill now. I would thanks if someone could tell me where can I find more informatoin about this topic.

Thanks,

Iván
http://www.ivan-marino.net

Thanks Ivan, glad to hear people are finding the chapters. I use a setup like the following to communicate over serial

  
#ifndef _OF_ARDUINO_COMM  
#define _OF_ARDUINO_COMM  
  
#include "ofMain.h"  
#define NUM_BYTES 6  
  
class OFArduino : public ofSimpleApp{  
	  
	public:  
		  
		void setup();  
		void update();  
		void draw();  
  
		bool	bSendSerialMessage;// a flag for sending serial  
		unsigned char bytesRead[NUM_BYTES];// data from serial, we will be trying to read 6			  
		int countCycles;  
		ofSerial serial;  
};  
  
#endif	  

and

  
  
  
void OFArduino::setup(){  
  
	countCycles = 0; // start our count at 0  
	bSendSerialMessage = true; // send a message right away  
	serial.setup("/dev/tty.usbserial-A6004920", 19200);	  
}  
  
void OFArduino::update(){  
	  
	if (bSendSerialMessage){  
		// send a message to the Arduino controller telling it that we're  
		// say "ready to get accelerometer data"  
		serial.writeByte('x');  
		  
		unsigned char bytesReturned[NUM_BYTES];  
		memset(bytesReturned, 0, NUM_BYTES);  
		  
		while( serial.readBytes(bytesReturned, NUM_BYTES) > 0){  
		};  
  
		bSendSerialMessage = false;  
	}  
	  
	countCycles++;  
	  
	if(countCycles == 5) {  
		bSendSerialMessage = true;  
		countCycles = 0;  
	}  
}  
  
  

and then in my Arduino code just check for the message from the serial port notifying that the OF app is ready to receive the data. There’s more info and examples on the forums too if you search on Arduino. There’s also the firmata library too that might make it easier to communicate with the Arduino, take a look at ofStandardFirmata. I’ve used the firmata library both for Processing->Arduino, and OF->Arduino and it’s pretty nice. Hope that helps.

josh

Thanks Joshua. Your answer and your code helps me a lot.
Searching on the forums I also found a couple of examples posted by Alejo. In them, he uses the Arduino Class developed by Erik Sjodin (I use to work with the AS version of this class and Arduino-Firmata), but I couldn’t find the link to download the Class in Erik’s google-code website. Do you know if there is an URL to download the final Class? Is it still under development?

Thanks again

Iván