[ANSWERED] Using Pressure Sensors through Arduino Uno
-
Okay so I've been doing some work with a projection project, and have one (probably more) last thing to figure out before I can start fabrication. There are a few things that I need to accomplish.
Here's what I need:
Isadora to read a Serial Input from the Arduino Uno
Isadora to take the values from that Serial Input, and use it to trigger a shuffle.
Isadora to assess the value of the integer taken from the Serial Input, and only trigger the shuffle once per times it goes over a certain threshold. (example: Arduino sends over values ever 200ms. Isadora reads the values, and triggers the shuffle once it goes over 400. The shuffle will not be triggered again for the entire duration that that specific value is above 400, but will trigger if a different value rises above 400. In practice, these are pressure sensors, and I want Isadora to trigger a shuffle if someone steps on it, but not trigger again if they continue standing on it).
What I have so far:
Arduino sending ASCII text to Isadora.
Isadora is receiving the data, visible in the monitor.
The data changes depending on the pressure applied to the sensor, so Isadora is reading whether or not the sensor is active or not.
I'm stuck there. I'm looking for solutions, but I'm having trouble understanding the serial input parser. That's giving me the most trouble. Below is the code that I have so far.
ARDUINO:
const int sens0 = A0;
const int sens1 = A1;
const int sens2 = A2;
const int sens3 = A3;// Name the Sensor Inputs. Need at least 4 for the project
void setup() {
// Start the serial Port
Serial.begin(9600);
}void loop() {
Serial.println(analogRead(sens0)); //Read input 0
Serial.println(analogRead(sens1)); //Read input 1
Serial.println(analogRead(sens2)); //Read input 2
Serial.println(analogRead(sens3)); //Read input 3
delay(1000); //Set delay to 1 sec
}ISADORA SERIAL INPUT PARSER
"1" (the arduino is set to port 1)
value:integer=3 digits
Any help? Am I going in a totally wrong direction?
-
I don't have your specific sensor to recreate, however something like the following is what I would expect:
Arduino Uno code:
int Sens0 = A0; int Sens1 = A1; int Sens2 = A2; int Sens3 = A3; int SensCapture1; int SensCapture2; int SensCapture3; int SensCapture4; int DelayTime = 25; void setup(void) { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // while the serial stream is not open, do nothing: while (!Serial) ; } void loop(void) { SensCapture1 = analogRead(Sens0); Serial.print("Sens0Data: "); SensCapture2 = analogRead(Sens1); Serial.print("Sens1Data: "); SensCapture3 = analogRead(Sens2); Serial.print("Sens2Data: "); SensCapture4 = analogRead(Sens3); Serial.print("Sens3Data: "); delay(DelayTime); }
'Serial In Watcher - Text' code:
"Sens0Data: " sensor1:float=4.# "Sens1Data: " sensor2:float=4.# "Sens2Data: " sensor3:float=4.# "Sens3Data: " sensor4:float=4.#
Best Wishes
Russell
-
I'll give this a shot. Could you explain what exactly this will be sending? Looking at it, the code is just printing "Sens_Data:" without including the actual data gathered from the sensors.
Also what's the advantage of using Serial.print rather than Serial.println?
-
Hi,
I have based the code on a quick look at two previous projects using PIR and Pulse sensors. I have other project code for accelerometer sensors but I have not looked at them for a while and are more complicated.
The println("...") method prints the string "..." and moves the cursor to a new line. The print("...") method instead prints just the string "...", but does not move the cursor to a new line. Hence, subsequent printing instructions will print on the same line.
[edit] acutely ‘println’ is required in the Arduino code to terminate the data stream. This is important as it allows the Isadora buffer to reset, otherwise it will overrun and cause an annoying error.
I do not claim to be an expert in coding for Arduino just based on these previous project code.
Best wishes
Russell -
Gotcha. Thanks for the clarification! I'm still not seeing any Data printing in the monitor, just the text. Does it need another Serial.Print to print the measurements from the FSP?
-
I just tried the following and it worked with a pulse sensor. So I think the answer is yes it does need to print the sensor. Apologies, I missed that in the first code example. It is much better doing it with an actual set-up to test, which I didn't have earlier.
Arduino code
int PulseSensor = A0; int DelayTime = 25; int PulseCapture; void setup(void) { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // while the serial stream is not open, do nothing: while (!Serial) ; } void loop(void) { PulseCapture = analogRead(PulseSensor); Serial.print("Pulse Data: "); Serial.println(PulseCapture); delay(DelayTime); }
'Serial In Watcher-Text' code
"Pulse Data: " pulse_sensor:float=4.#
-
I was wrong about not requiring 'println', if you don't use it the Isadora buffer may overrun.
Best Wishes
Russell