Hi i am working on computer vision. I am using roborealm. I use a txt file to send data to processing, then I have to send data from Processing to arduino. I tryed with serial communication serial.Write(); in processing Serial.Read() in arduino but it don't works, i try also with arduino library using two digital ports like interrupts to communicate, but it don't works again. Have you some advise to me?
Have you some advise to me?
Yes; tell us what it is that "doesn't work".
I'm quite sure that both Processing's serial.Write, and Arduino's Serail.read both "work", so unless you explain why they appear not to work for you, it is going to be tough helping you.
It would also make it easier to help you if you posted your code - for both the Arduino and the Processing application.
I have to send a integer from 0 to 100 that is the focus value of camera, cog_area that is the value of motion detection in front of camera and cog_x that is the x value of the tacked motion. How can I do it?
Now I use roborealm to create a txt file where I take the 3 values with processing loadString(). after splitting I have to send the 3 value via serial to arduino. Can you give me some advise to me?
In your first post, you said
I tryed with serial communication serial.Write(); in processing Serial.Read() in arduino but it don't works
So, that means you have some Processing code and some Arduino code. One or the other, or both, fails to do what you want. Post that code, and we'll help you get it working.
Hi Pauls!
Here it is something that i write to try, a simple hello world.
I receive data with processing from a txt file (ok working), 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. But this don't works, my problem is here...
processing 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("fucking 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:
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
The Processing code you are using assumes that you are running Firmata on the Arduino. Are you? Which version?
Hi.
I had a similar problem.
I wanted to read out a gyro, mounted on the arduino and show its position in processing.
It finally worked, I see my arduino board and it rotates.
But I couldn´t send int from arduino to processing. I had to translate the ascii-values so processing does what I want.
I would be really interested if there´s a possibilty to receive int, float, double in processing.
This would help me a lot.
Thanks for posting this.
The Arduino has a Serial.write method that sends bytes to the serial port. Processing's Serial::read() function reads bytes.
An int can be written by writing the low order byte followed by the high order byte (by using bit shifting), and can be reassembled in the Processing code by reading the low order byte and the high order byte, and using & and bitshifting.
Floats and doubles can be sent the same way, except that there are more bytes to extract, send, read, and re-assemble.
(by using bit shifting),
Or by using the function lowByte and highByte provided by the environment.
http://www.arduino.cc/en/Reference/LowByte
http://arduino.cc/en/Reference/HighByte
True, but bit shifting will work for any sized number to output. If outputting and int, lowByte and highByte are all that is needed. If outputting a float or a double, bit shifting will be required.
Bit shifting will be required on the Processing side.
So, might as well learn how it works.
If outputting a float or a double, bit shifting will be required.
Not if you've got the union on your side ;D
I'm a confederate.
^^
ok. i did it kind of this way, too.
but i was interested if this is the only way.
it´d be much easier if you could transmit valus and calculate with them immediately.
thank you.
it´d be much easier if you could transmit valus and calculate with them immediately
Well, the serial line is effectively a byte-wide channel, so someone or something has to break down and reassemble larger datatypes.
Couple of gotchas to watch out for are
- endianness,
- alignment and packing for structures.