since there is no pulseIn() in processing i'm thinking of using it in arduino:
int duration = pulseIn(13, HIGH);
and passing the int to processing
I already have the standartFirmata loaded on the arduino and a sketch on processing, how do i access this int in the processing sketch??
how do i access this int in the processing sketch??
Yes you write your own sketch and do a Serial.println() with the value.
At the processing end you use:-
void serialEvent(Serial scope) { // this gets called every time a line feed is received
String recieved = scope.readString() ;
println(recieved + " from serial port"); // show it at the bottom of the processing window
// also do the stuff you want to do when you get things back from the arduino
}
Having first done:-
Serial scope;
// then open the port and then do
scope.bufferUntil(10); // to tell it to call the serialEvent() function when it receives a line feed.
how do i access this int in the processing sketch??
Yes you write your own sketch and do a Serial.println() with the value.
At the processing end you use:-
void serialEvent(Serial scope) { // this gets called every time a line feed is received
String recieved = scope.readString() ;
println(recieved + " from serial port"); // show it at the bottom of the processing window
// also do the stuff you want to do when you get things back from the arduino
}
Having first done:-
Serial scope;
// then open the port and then do
scope.bufferUntil(10); // to tell it to call the serialEvent() function when it receives a line feed.
I need it the other way around thou, in the arduino end i need a:
int distance = 0; //for example
and at the processing i need to acess that int like so:
void draw(){
rect(100,100,50,distance);
} //again just an example
i already have all the firmate to conect the arduino hardware to processing i just need to acess an int in the arduino firmata in the processing code
i just need to acess an int in the arduino firmata in the processing code
This is like saying "I already know how to fly in an airplane; now I need to learn to fly without the airplane". Unless you are a bird, you can't. Get over it.
PaulS:
This is like saying "I already know how to fly in an airplane; now I need to learn to fly without the airplane". Unless you are a bird, you can't. Get over it.
Do yourself a big favor and ditch Firmata. Now.
how?? i dont know how to connect the arduino to processing in any other way, also:
That is exactly what that code will do for you.
you two are telling me different things, all i need to is to be able to pass an int, any int, to processing, please help i have no idea what do
option 1. ditch firmata, ok i could look other ways up but this doesnt rlly solve my problem
option 2. ????
i dont know how to connect the arduino to processing in any other way
Processing is supplied with examples that contain both Processing and Arduino code. They are in the Libraries>Serial I/O section of the examples. The SerialCallResponse example transfers the results of analogRead()s from the Arduino into Processing. It should give you a start.
i rlly appreciate you guys' help, but i think you guys are starting to get away from the initial problem i have, is this not as simple as i am thinking? is there more to it than just accessing the int in processing?? all i need is to declare a variable in arduino, and be able to acess that variable in processing, is it rlly that hard, is there more to it???
all i need is to declare a variable in arduino, and be able to acess that variable in processing
does not agree with
int duration = pulseIn(13, HIGH);
Declaring a variable is one thing. Storing the result of a function call is another. You can't use pulseIn() with standardfirmata. You could modify the SerialCallResponse sketches to pass the result of pulseIn() across serial to Processing.
No we are not.
I am showing you what code to put in processing to receive a variable sent from the arduino.
I said
do a Serial.println() with the value.
So that means you have to do that in a sketch that you run on the arduino.
Everything you print in the arduino will be received in processing with that code I posted.
is this not as simple as i am thinking?
Difficult to know we are not mind readers. However you have not said in enough detail what you want to do. You might think you have but you have not.
How many values do you need to transfer?
How often do you need to do this?
Do you want the numbers to come from the arduino at regular time intervals or do you want to ask for them from processing.
ll i need is to declare a variable in arduino, and be able to acess that variable in processing
Declaring a value is just defining it. If you want to do that there is no need for an arduino. If you want the value to be a read of a pin or some other function then you need to send it to processing.
i am sorry, i have realized i might not have been completely clear with you guys, i'll say exactly what i want to do and how
i want to use a distance sensor in the arduino hardware, and use that distance in processing, i already have the code which works in arduino, but there is no pulseIn() method in processing (with is used inthe code in arduino), so in my mind i was thinking of getting the distance from the sensor in the arduino sketch, and passing that value to processing, but of course i might have been trying to do the wrong thing, i hope this helps and thanks for the help
this is my arduino code for the sensor that works, it prints the distance value:
Not be any stretch of the imagination. The Firmata sketch is simply not capable of being expanded in the way that you think is possible.
i just have no clue what to do then, any suggestions of how to connect a distance sensor to processing?? my code is in my previous post, i'm just clueless now, before i thought i had the right idea but i guess not really, any help much appreciated.
i just have no clue what to do then, any suggestions of how to connect a distance sensor to processing?
That code will send data to the serial port, which Processing can read. Printing " cm" after the value is silly. Processing should expect a value in centimeters. The value should be sent to the serial port using Serial.println().
Insert Quote
so i dont need any firmata or sketch to connect arduino to processing???
if i can just output a value in the serial port, and read it in processing how would i do this?? read the value in the port?
You need a sketch in the arduino, that you have already. Get rid of the strings like the cm on the reading to make things easier.
To read it in processing you the code I have posted.
What is wrong with you? You seem to be totally ignoring everything we say. You keep asking the same question over and over and ignoring the answer.
Maybe this whole project is just too much for you. I would advise doing some simpler projects and learning some stuff until you get a clue. Then come back to this and read the answers you have been given again.