So, if I understand correctly, what you're asking is not how to use more than one sensor, but rather how to use the URM37. Is that right? If so, I first recommend that you start with the simplest setup, containing ONLY ONE URM37 and nothing more. According to this page <http://www.dfrobot.com/wiki/index.php/URM37_V3.2_Ultrasonic_Sensor_%28SKU:SEN0001%29>, the URM37 has several different modes of operation, configurable via EEPROM. In order to behave similarly to the SRF05 you'd need to configure it to the "PWM passive" control mode. The Arduino sketch on that page gives you an idea how to do that. Note that this is a one-time process per sensor, so it doesn't strictly need to live inside your code. Other than that, you'd need to connect your trigger pin to "comp/trig" and notice that opposite polarity than the URM37 (that is, you pull low to trigger). Also, the pulse width conversion would have a different scaling factor. Since the comp/trig pin is sometimes used as output from the sensor, I would put a series resistor (220 ohm or so) between the IOIO pin and it. As an alternative, you can connect over UART.
On Wed, Jan 7, 2015 at 10:37 AM, Cesar Quiroz <[email protected]> wrote: > Hello folks, > > I'm doing a similar project done by > http://www.robotfreak.de/blog/en/tutorial/ioio-robotics-tutorial-1-ultrasonic-sensor/732 > But, I want to use three ultrasonic sensors and i'm trying to modify the > code example, see below: > How to do for three sensors? The code below, demonstrate with two sensors, > but only one is working. > I'd three sensors, one is SRF05 and the rest is URM37. > > package ioio.examples.ultrasonic; > > public class IOIOUltrasonicSensorActivity extends AbstractIOIOActivity { > /* ultrasonic sensor */ > private ProgressBar progressBar1_; > private TextView textView2_; > private ProgressBar progressBar2_; > private TextView textView3_; > private int echoSeconds; > private int echoDistanceCm; > private int echoSeconds_; > private int echoDistanceCm_; > > /** > * Called upon creation for initialization > */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > /* ultrasonic sensor */ > progressBar1_ = (ProgressBar) findViewById(R.id.progressBar1); > textView2_ = (TextView) findViewById(R.id.textView2); > progressBar2_ = (ProgressBar) findViewById(R.id.progressBar2); > textView3_ = (TextView) findViewById(R.id.textView3); > } > > class IOIOThread extends AbstractIOIOActivity.IOIOThread { > /* ultrasonic sensor */ > private DigitalOutput triggerPin_; > private PulseInput echoPin_; > //private DigitalOutput triggerPin2_; > //private PulseInput echoPin2_; > /** > * Called every time a connection with IOIO has been established. (opens > * pins) > * > * @throws ConnectionLostException > * (if IOIO connection is lost) > */ > > public void setup() throws ConnectionLostException { > try { > /* ultrasonic sensor */ > echoPin_ = ioio_.openPulseInput(6, PulseMode.POSITIVE); > triggerPin_ = ioio_.openDigitalOutput(7); > //echoPin2_ = ioio_.openPulseInput(10, PulseMode.POSITIVE); //TRIG > //triggerPin2_ = ioio_.openDigitalOutput(11); // > } catch (ConnectionLostException e) { > throw e; > } > } > > /** > * Loop section > */ > > public void loop() throws ConnectionLostException { > try { > // read HC-SR04 ultrasonic sensor > triggerPin_.write(false); > sleep(5); > triggerPin_.write(true); > sleep(1); > triggerPin_.write(false); > echoSeconds = (int) (echoPin_.getDuration() * 1000 * 1000); > echoDistanceCm = echoSeconds / 29 / 2; > //read URM37 ultrasonic sensor > //triggerPin2_.write(false); > //sleep(5); > //triggerPin2_.write(true); > //sleep(1); > //triggerPin2_.write(false); > //echoSeconds_ = (int) (echoPin2_.getDuration() * 1000 * 1000); > //echoDistanceCm_ = echoSeconds_ /29 /2; > /* update UI */ > updateViews(); > > sleep(20); > } catch (InterruptedException e) { > ioio_.disconnect(); > > } catch (ConnectionLostException e) { > throw e; > > } > } > } > > /** > * A method to create our IOIO thread. > */ > > @Override > protected AbstractIOIOActivity.IOIOThread createIOIOThread() { > return new IOIOThread(); > } > > private void updateViews() { > runOnUiThread(new Runnable() { > @Override > public void run() { > textView2_.setText(String.valueOf(echoDistanceCm)); > progressBar1_.setProgress(echoDistanceCm); > //textView3_.setText(String.valueOf(echoDistanceCm_)); > //progressBar2_.setProgress(echoDistanceCm_); > } > }); > } > } > > -- > You received this message because you are subscribed to the Google Groups > "ioio-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/ioio-users. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "ioio-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/d/optout.
