upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the DFRobot URM37 Ultrasonic Ranger. More...

Detailed Description

This library was tested with the DFRobot URM37 Ultrasonic Ranger, V4. It has a range of between 5 and 500 centimeters (cm). It supports both analog distance measurement, and UART based temperature and distance measurements. This driver does not support PWM measurement mode.

For UART operation, the only supported baud rate is 9600. In addition, you must ensure that the UART TX/RX pins are configured for TTL operation (the factory default) rather than RS232 operation, or permanent damage to your URM37 and/or MCU will result. On power up, the LED indicator will blink one long pulse, followed by one short pulse to indicate TTL operation. See the DFRobot wiki for more information:

(https://www.dfrobot.com/wiki/index.php?title=URM37_V4.0_Ultrasonic_Sensor_%28SKU:SEN0001%29)

urm37.jpg

An example using analog mode

// Instantiate a URM37 sensor on analog pin A0, reset pin on D2,
// trigger pin on D3 with an analog reference voltage of 5.0
upm::URM37 sensor(0, 2, 3, 5.0);
// Every half a second, sample the URM37 and output the measured
// distance in cm.
while (shouldRun) {
cout << "Detected distance (cm): " << sensor.getDistance() << endl;
upm_delay_us(500000);
}

An example using UART mode

// Instantiate a URM37 sensor on UART 0, with the reset pin on D2
upm::URM37 sensor(0, 2);
// Every half a second, sample the URM37 and output the measured
// distance in cm, and temperature in degrees C
while (shouldRun) {
cout << "Detected distance (cm): " << sensor.getDistance() << endl;
cout << "Temperature (C): " << sensor.getTemperature() << endl;
cout << endl;
upm_delay_us(500000);
}

Public Member Functions

 URM37 (int aPin, int resetPin, int triggerPin, float aref=5.0)
 
 URM37 (int uart, int resetPin)
 
 ~URM37 ()
 
void reset ()
 
float getDistance (int degrees=0)
 
float getTemperature ()
 
uint8_t readEEPROM (uint8_t addr)
 
void writeEEPROM (uint8_t addr, uint8_t value)
 

Protected Attributes

urm37_context m_urm37
 

Constructor & Destructor Documentation

URM37 ( int  aPin,
int  resetPin,
int  triggerPin,
float  aref = 5.0 
)

URM37 object constructor (Analog mode)

Parameters
aPinAnalog pin to use
resetPinGPIO pin to use for reset
triggerPinGPIO pin to use for triggering a distance measurement
arefThe analog reference voltage, default 5.0
URM37 ( int  uart,
int  resetPin 
)

URM37 object constructor (UART mode)

Parameters
uartDefault UART to use (0 or 1).
resetPinGPIO pin to use for reset
~URM37 ( )

URM37 object destructor

Here is the call graph for this function:

Member Function Documentation

void reset ( )

Reset the device. This will take approximately 3 seconds to complete.

Here is the call graph for this function:

float getDistance ( int  degrees = 0)

Get the distance measurement. A return value of 65535.0 in UART mode indicates an invalid measurement.

Parameters
degreesin UART mode, this specifies the degrees to turn an attached PWM servo connected to the MOTO output on the URM37. Default is 0. Valid values are 0-270. This option is ignored in analog mode.
Returns
The measured distance in cm

Here is the call graph for this function:

float getTemperature ( void  )

Get the temperature measurement. This is only valid in UART mode.

Returns
The measured temperature in degrees C

Here is the call graph for this function:

uint8_t readEEPROM ( uint8_t  addr)

In UART mode only, read a value from the EEPROM and return it.

Parameters
addrThe address in the EEPROM to read. Valid values are between 0x00-0x04.
Returns
The EEPROM value at addr

Here is the call graph for this function:

void writeEEPROM ( uint8_t  addr,
uint8_t  value 
)

In UART mode only, write a value into an address on the EEPROM.

Parameters
addrThe address in the EEPROM to write. Valid values are between 0x00-0x04.
valueThe value to write
Returns
The EEPROM value at addr

Here is the call graph for this function:

Collaboration diagram for URM37:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: