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 › send int from processing to arduino
Page Index Toggle Pages: 1
send int from processing to arduino (Read 1740 times)
send int from processing to arduino
Feb 6th, 2010, 10:29pm
 
Hi guys!
Here it is something that i write to try, a simple hello world of computer vision. I use roborealm, (a GUI video processing and computer vision software). I receive data with processing from a txt file (ok working) where i save with roborealm variable values, i use it for an if (ok working) i use tts to sintetyze speech (ok working) and I want to use arduino library to change a digital pin state from low to high...
in arduino code i have an if that calls a function of servo steering if state is HIGH. But this  don't works, my problem is here...

processing code:
Code:
import cc.arduino.*;
import guru.ttslib.*;
import processing.serial.*;
int data = 0;
int comPin = 3;
int perception = 0;
int something = 0;
Serial Serial;  
Arduino arduino;
TTS tts;


void setup() {
 /*String portName = Serial.list()[0];
 Serial = new Serial(this, portName, 9600);*/
 arduino = new Arduino(this, Arduino.list()[0], 57600);
 arduino.pinMode(comPin, Arduino.OUTPUT);
 tts = new TTS();
 println(Serial.list());
 size(200, 200);
 background(200);
 stroke(255);
 frameRate(2);
}

void draw() {
/*
 data = Serial.read();
 if (data == 'A') {
   tts.speak("Oh my god! I am alive!");
   tts.speak("Why?!");
   delay(200);
 }
  if ( data == 'B') {
   tts.speak("Lets go I want to understand something");
   delay(200);
 }
 if (data == 'C') {
   tts.speak("crappity smacking obstacle");
   delay(200);
 }
 */
  String[] lines = loadStrings("cogx.txt");
  if (lines.length == 2) {
  int[] nums = int(split(lines[0], ';'));
  int detect = nums[0] + nums[1] - 640;
  int focus = nums[0] + nums[2] - 640;
  if (focus < random( 220, 400)) {
  arduino.digitalWrite(comPin, arduino.HIGH);
  tts.speak("Oh");
  delay(200);
  tts.speak("I got something");
  delay (400);
  arduino.digitalWrite(comPin, arduino.LOW);
 
}
}
}


arduino code:
Code:
void receiver() {
int state = digitalRead(comPin);
if (state == HIGH) {
flip();
digitalwrite(comPin, LOW);
}


My problem is also that i use serial communication (that is commented) in processing code to receive  calls from arduino to say sentences of ttslib. My problem is that arduino library and serial don't works toghether, i think I have to use one of theese. But serial.write on arduino code don't work properly, i tried to send letters, numbers...but it seems that processing don't take it
Page Index Toggle Pages: 1