General

URM37: Two ultrasonic Sensors + Arduino

userHead Account cancelled 2013-01-01 03:03:12 8367 Views2 Replies
Hi everybody,

I'm trying to use two URM37 ultrasonic receiver for a mesurement tool. But I can't get them working together.

What is tested:
- both sensors work correct (if used alone)
- testet with Arduino IDE 1.0 / 1.01 / 1.02 same results
- used latest libary from dfrobot (08.05.2012 by Lauren)
- tested several Pins, no changes.

Code so far:
Code: Select all
...
#include <SoftwareSerial.h>
#include "URMSerial.h"

URMSerial urm;  
URMSerial urm2;
...


Setup()

...
  urm.begin(7,6,9600);                 // RX Pin, TX Pin, Baud Rate

  urm2.begin(13,12,9600); 
...


Loop()

...

	value = getMeasurement();
	value2 = getMeasurement2();
	
...


Functions:

// USM37

int getMeasurement()
{

int val;
  // Request a distance reading from the URM37
  switch(urm.requestMeasurementOrTimeout(DISTANCE, val)) // Find out the type of request
  {
  case DISTANCE: // Double check the reading we recieve is of DISTANCE type
    //    Serial.println(value); // Fetch the distance in centimeters from the URM37
    return val;
    break;
  case TEMPERATURE:
    return val;
    break;
  case ERROR:
    Serial.println("Error");
    break;
  case NOTREADY:
    Serial.println("Not Ready");
    break;
  case TIMEOUT:
    Serial.println("Timeout");
    break;
  } 

  return -1;
}


int getMeasurement2()
{

int val;
  // Request a distance reading from the URM37
  switch(urm2.requestMeasurementOrTimeout(DISTANCE, val)) // Find out the type of request
  {
  case DISTANCE: // Double check the reading we recieve is of DISTANCE type
    //    Serial.println(value); // Fetch the distance in centimeters from the URM37
    return val;
    break;
  case TEMPERATURE:
    return val;
    break;
  case ERROR:
    Serial.println("Error2");
    break;
  case NOTREADY:
    Serial.println("Not Ready2");
    break;
  case TIMEOUT:
    Serial.println("Timeout2");
    break;
  } 

  return -1;
}

**************************************************************************************

only the scond sensor returns distance-values, the first sensor returns -1.
when I change the order in the Setup-section the other Sensor reports distance-values.

So it seemes that only the last entry in the Setup-section is used.

What am I doing wrong? Could it be the Arduino board (using Arduino Duemillanove with ATmega 328)?


Thank you very much for any advice.

Steve
2013-05-03 23:32:31 Good Morning Guys,

Did you ever managed to get this problem solved? Im experiencing exactly the same befaviour in a project im trying to make using 2 URM37. Asked in the arduino forum and other places for help with no luck... yet...

Wiring is correct, hardware also they work fine by themselves, but just the second sensor gets measurement when working together.

Thanks a lot in advance,
Julian

userHeadPic juliflash
2013-01-26 04:39:48 Hi Steve,

I have quite same behaviour when using an URM37 device and trying to discuss with another device using a SowtwareSerial port.

like this :
------------------------------------
#include <SoftwareSerial.h>
#include "URMSerial.h"

URMSerial urm; 
SoftwareSerial ss(6,7);
.....

void setup()
{
  Serial.begin(9600);
  urm.begin(2,3,9600);                // RX Pin, TX Pin, Baud Rate of URM37device
  ss.begin(9600);              // Serial soft port to discuss with GPS board
...
--------------------------------------


It seems that multiple instances of URMSerial are not supported ??  :(
as URMSerial uses SoftwareSerial combination of both instances occurs errors...

Perhaps somebody can help ?? (have another post according to this URM37 device)

Thanks
userHeadPic XLR