Show Posts
Pages: [1]
1  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: February 28, 2013, 10:51:57 am
Hi everyone, I would like to ask if it's possible to hold a value, I mean, if I remove my hand from the sensor, then the sensor measure out of range, I would like that the last value sent for serial (usb) was the measure from my hand to the sensor before remove... This is my sketch which I found in this post, BTW really useful!!!

You would write your sketch to hold a value.  Once one cycle of pinging all the sensors is complete, it goes to the oneSensorCycle() function.  This is where you would analyze the results.  If you wanted to hold those results and stop pinging, this is where you would do it.  The 15 sensor sketch help post shows how you would stop the ping process and resume.  If you only want to know when something is in the way of one of the sensors and then hold those results.  In the oneSensorCycle() function you would detect something was in the way, stop the pings, and do whatever you wanted with that information.  When you wanted to restart the pings, you would use the restart code.

That's about the best I can do shy of writing your script for you, and what fun would that be?

Tim
Thank you Tim!!! I'm going to work with these advices!!
2  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: February 28, 2013, 06:39:07 am
Hi everyone, I would like to ask if it's possible to hold a value, I mean, if I remove my hand from the sensor, then the sensor measure out of range, I would like that the last value sent for serial (usb) was the measure from my hand to the sensor before remove... This is my sketch which I found in this post, BTW really useful!!!

Code:
#include <NewPing.h>

#define SONAR_NUM     4 // Number or sensors.
#define MAX_DISTANCE 200 // Maximum distance (in cm) to ping.
#define PING_INTERVAL 33 // Milliseconds between sensor pings (29ms is about the min to avoid cross-sensor echo).

unsigned long pingTimer[SONAR_NUM]; // Holds the times when the next ping should happen for each sensor.
unsigned int cm[SONAR_NUM];         // Where the ping distances are stored.
uint8_t currentSensor = 0;          // Keeps track of which sensor is active.

NewPing sonar[SONAR_NUM] = {     // Sensor object array.
  NewPing(12, 11, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping.
  NewPing(10, 9, MAX_DISTANCE),
  NewPing(8, 7, MAX_DISTANCE),
  NewPing(6, 5, MAX_DISTANCE)
};

void setup() {
  Serial.begin(115200);
  pingTimer[0] = millis() + 75;           // First ping starts at 75ms, gives time for the Arduino to chill before starting.
  for (uint8_t i = 1; i < SONAR_NUM; i++) // Set the starting time for each sensor.
    pingTimer[i] = pingTimer[i - 1] + PING_INTERVAL;
}

void loop() {
  for (uint8_t i = 0; i < SONAR_NUM; i++) { // Loop through all the sensors.
    if (millis() >= pingTimer[i]) {         // Is it this sensor's time to ping?
      pingTimer[i] += PING_INTERVAL * SONAR_NUM;  // Set next time this sensor will be pinged.
      if (i == 0 && currentSensor == SONAR_NUM - 1) oneSensorCycle(); // Sensor ping cycle complete, do something with the results.
      sonar[currentSensor].timer_stop();          // Make sure previous timer is canceled before starting a new ping (insurance).
      currentSensor = i;                          // Sensor being accessed.
      cm[currentSensor] = 0;                      // Make distance zero in case there's no ping echo for this sensor.
      sonar[currentSensor].ping_timer(echoCheck); // Do the ping (processing continues, interrupt will call echoCheck to look for echo).
    }
  }
  // The rest of your code would go here.
 
}

void echoCheck() { // If ping received, set the sensor distance to array.
  if (sonar[currentSensor].check_timer())
    cm[currentSensor] = sonar[currentSensor].ping_result / US_ROUNDTRIP_CM;
}

void oneSensorCycle() { // Sensor ping cycle complete, do something with the results.
  for (uint8_t i = 0; i < SONAR_NUM; i++) {
      Serial.print(cm[i]);
}
3  Using Arduino / Networking, Protocols, and Devices / Re: serial to osc on: February 07, 2013, 11:11:13 am
YEp! Thanx! I've got my data now in Processing! Now I have to transform to OSC! Thanks again!
4  Using Arduino / Networking, Protocols, and Devices / Re: serial to osc on: February 06, 2013, 07:26:42 am
Hey I want to do the same stuff! I want to control a virtual instrument of Ableton Live with 4 sensors with OSC protocol... So is it totally necessary to use another device in your arduino board? via USB? And you said Kostantinos about sending the data to Processing, how does it work??
Thank!!
5  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: February 06, 2013, 07:14:51 am
Hi everyone! I have a question... if I use 4 ultrasonic sensors and I want to send the data to Processing for transforming the data to OSC, can I use the 15 sensors sketch but with 4?? I don't know how can i do it...

Code:
#define SONAR_NUM       4 // Number of sensors.
yeah, I know that, but i want to know how to send to processing, How can processing read this data???.... coz from processing i can transform the data to OSC...or am I wrong?? smiley-roll-sweat
Thank u!

What do you mean by "i want to know how to send to processing"?  What is "processing"?  What is "OSC"?

The sketch pings the sensors and stores the values in the cm[] array.  In the pingResult() function the contents of the cm[] array are output via serial.  If you want to send that data to something else, whatever "processing" and "OSC" is, you would simply replace the contents of the pingResults() function with whatever you wanted to do with the results.  We have no idea what you want to do with the results, but the data is there for you to do whatever you want with it.  The pingResults() function is where you should do your magic with the results.

I have a post with help and alternative code for the 15 sensor sketch.

Tim
First of all, thank you for answering Tim! Processing is a language like, java, C++, etc... and OSC it's a protocol like MIDI for controlling a virtual instrument or whatever in your computer... My project is with 4 ultrasonic sensors to get the results and transform them into OSC so you can control eg. Ableton Live or whatever, moving your hands you can change a synth's parameters in real time.... Your code works perfectly for my 4 sensors! Now with your advice I'm going to try "play" with the data... Maybe I could obviate "Processing" and finding a library for Arduino which I can handle OSC... hahahaha sorry I'm rambling...
Anyway Thanks for ur code again!!!
6  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: February 05, 2013, 11:50:28 am
Hi everyone! I have a question... if I use 4 ultrasonic sensors and I want to send the data to Processing for transforming the data to OSC, can I use the 15 sensors sketch but with 4?? I don't know how can i do it...

Code:
#define SONAR_NUM       4 // Number of sensors.
yeah, I know that, but i want to know how to send to processing, How can processing read this data???.... coz from processing i can transform the data to OSC...or am I wrong?? smiley-roll-sweat
Thank u!
7  Using Arduino / Sensors / Re: NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.5 on: February 04, 2013, 10:39:59 am
Hi everyone! I have a question... if I use 4 ultrasonic sensors and I want to send the data to Processing for transforming the data to OSC, can I use the 15 sensors sketch but with 4?? I don't know how can i do it...
8  International / Proyectos / Re: Arduino+sensores SR04+protocolo OSC+Ableton Live, DUDA! on: January 30, 2013, 06:21:58 pm
Muchas gracias por contestar!! voy a echarle un ojo!!
9  International / Proyectos / Arduino+sensores SR04+protocolo OSC+Ableton Live, DUDA! on: January 30, 2013, 07:19:00 am
Hola, mi proyecto es el siguiente, mediante 4 sensores de ultrasonido poder controlar un instrumento virtual de ableton live por OSC, pudiendo rutear los 4 sensores a 4 parámetros del Instrumento virtual. He conseguido hacer funcionar los 4 sensores SR04 y que en la terminal de Arduino muestre en pantalla las distancias en tiempo real de cada sensor. Y aquí es donde estoy atrapado, no se como transformar esos datos de distancias a información OSC y asi luego poder usarlos en Ableton....
No se si se me escapa algún paso o si necesito algo más, estaria agradecido si alguien tiene alguna idea por que he mirado y no encuentro nada...
Gracias! smiley-cry
10  Topics / E-Textiles and Craft / Re: ayuda programa para conectar 2 sensores ultrasonicos srf04 al arduino on: January 24, 2013, 07:05:33 am
Hola! conseguiste finalmente hacer que funcionasen los 2 sensores a la vez?? A mi me gustaría hacer que funcionasen 4 SRF04, aun que con 2 ya estaría contento... smiley
Pages: [1]