Help with a little project.
in
Integration and Hardware
•
1 year ago
Hey! I just recently got into playing around with arduino and processing. And I came up with a little project and I have run into a few issues.
So the little project I have is this. I have the Arduino, and connected on a breadboard 3 variable resistors connecting to A0, A1, A2. Pretty simple. What I want to do is send the data from each resistor to a processing program and simply control a shape. Size and X and Y position.
The code on the board.
My issue is that when I get it into processing it doesn't seem like very consistent data. In the serial monitor on the board it looks good. But not so much from processing. I also have a question about mapping the variable.
That is the processing code I am currently working with. Import the serial Library, connect to the board and then this is where I am a little lost/think I am going something wrong. I call .read on my port (is this and object or a class?) and I assign it to the variables, but I never tell it that the sensor connected to A0 I want to be valS (size) etc. How do I go about doing that? Is there a way to see what is being sent to the program from the board and assign it to variables?
If I could get a little help on this that would be great! If something doesn't make sense let me know.
Thanks
So the little project I have is this. I have the Arduino, and connected on a breadboard 3 variable resistors connecting to A0, A1, A2. Pretty simple. What I want to do is send the data from each resistor to a processing program and simply control a shape. Size and X and Y position.
- int val1 = 0;
int val2 = 0;
int val3 = 0;
int sensorPin1 = A0;
int sensorPin2 = A1;
int sensorPin3 = A2;
void setup(){
Serial.begin(9600);
}
void loop(){
val1 = analogRead(sensorPin1);
val2 = analogRead(sensorPin2);
val3 = analogRead(sensorPin3);
Serial.write(val1);
Serial.write(val2);
Serial.write(val3);
}
The code on the board.
My issue is that when I get it into processing it doesn't seem like very consistent data. In the serial monitor on the board it looks good. But not so much from processing. I also have a question about mapping the variable.
- import processing.serial.*;
Serial port;
float valS;
float valX;
float valY;
void setup(){
size(800, 800);
// println(Serial.list());
String arduinoPort = Serial.list()[0];
port = new Serial(this, arduinoPort, 9600);
}
void draw(){
if (port.available() > 0){
valS = port.read();
valS = map(valS, 0, 255, 0, height);
valX = port.read();
valX = map(valX, 0, 255, 0, height);
valY = port.read();
valY = map(valY, 0, 255, 0, height);
}
fill(#243a94);
print("valS: ");
println(valS);
print("valX: ");
println(valX);
print("valY: ");
println(valY);
ellipse(valX , valX, valS, valY);
delay(1000);
}
That is the processing code I am currently working with. Import the serial Library, connect to the board and then this is where I am a little lost/think I am going something wrong. I call .read on my port (is this and object or a class?) and I assign it to the variables, but I never tell it that the sensor connected to A0 I want to be valS (size) etc. How do I go about doing that? Is there a way to see what is being sent to the program from the board and assign it to variables?
If I could get a little help on this that would be great! If something doesn't make sense let me know.
Thanks
1