MaxBotixSonar class

The Sensor sub-class for the MaxBotix ultrasonic range finders.

Base classes

class Sensor
The "Sensor" class is used for all sensor-level operations - waking, sleeping, and taking measurements.

Constructors, destructors, conversion operators

MaxBotixSonar(Stream* stream, int8_t powerPin, int8_t triggerPin = -1, int16_t maxRange = 9999, uint8_t measurementsToAverage = 1, bool convertCm = false)
Construct a new MaxBotix Sonar object.
MaxBotixSonar(Stream& stream, int8_t powerPin, int8_t triggerPin = -1, int16_t maxRange = 9999, uint8_t measurementsToAverage = 1, bool convertCm = false)
Construct a new MaxBotix Sonar object.
~MaxBotixSonar()
Destroy the MaxBotix Sonar object.

Public functions

String getSensorLocation(void) -> String override
Get the pin or connection location between the mcu and the sensor.
bool setup(void) -> bool override
Do any one-time preparations needed before the sensor will be able to take readings.
bool wake(void) -> bool override
Wake the sensor up, if necessary. Do whatever it takes to get a sensor in the proper state to begin a measurement.
bool addSingleMeasurementResult(void) -> bool override
Get the results from a single measurement.

Function documentation

MaxBotixSonar::MaxBotixSonar(Stream* stream, int8_t powerPin, int8_t triggerPin = -1, int16_t maxRange = 9999, uint8_t measurementsToAverage = 1, bool convertCm = false)

Construct a new MaxBotix Sonar object.

Parameters
stream An Arduino data stream for TTL or RS232 communication. See notes for more information on what streams can be used.
powerPin

The pin on the mcu controlling power to the MaxSonar. Use -1 if it is continuously powered.

  • The MaxSonar requires a 2.7V - 5.5V power supply.
triggerPin The pin on the mcu controlling the "trigger" for the MaxSonar. Use -1 or omit for continuous ranging.
maxRange Maximum valid measurement reported by the specific sensor model (e.g. 5000 or 9999 or 765).
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.
convertCm Convert centimeter range data from certain models to millimeters. Default false.

MaxBotixSonar::MaxBotixSonar(Stream& stream, int8_t powerPin, int8_t triggerPin = -1, int16_t maxRange = 9999, uint8_t measurementsToAverage = 1, bool convertCm = false)

Construct a new MaxBotix Sonar object.

Parameters
stream An Arduino data stream for TTL or RS232 communication. See notes for more information on what streams can be used.
powerPin

The pin on the mcu controlling power to the MaxSonar. Use -1 if it is continuously powered.

  • The MaxSonar requires a 2.7V - 5.5V power supply.
triggerPin The pin on the mcu controlling the "trigger" for the MaxSonar. Use -1 or omit for continuous ranging.
maxRange Maximum valid measurement reported by the specific sensor model (e.g. 5000 or 9999 or 765).
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.
convertCm Convert centimeter range data from certain models to millimeters. Default false.

String MaxBotixSonar::getSensorLocation(void) override

Get the pin or connection location between the mcu and the sensor.

Returns String Text describing how the sensor is attached to the mcu.

bool MaxBotixSonar::setup(void) override

Do any one-time preparations needed before the sensor will be able to take readings.

Returns bool True if the setup was successful.

This sets pin mode on the trigger pin. It also sets the expected stream timeout for modbus and updates the _sensorStatus. No sensor power is required. This will always return true.


bool MaxBotixSonar::wake(void) override

Wake the sensor up, if necessary. Do whatever it takes to get a sensor in the proper state to begin a measurement.

Returns bool True if the wake function completed successfully.

Verifies that the power is on and updates the _sensorStatus. This also sets the _millisSensorActivated timestamp.

For the MaxSonar, this also reads and dumps any returned "header" lines from the sensor.


bool MaxBotixSonar::addSingleMeasurementResult(void) override

Get the results from a single measurement.

Returns bool True if the function completed successfully.

This asks the sensor for a new result, verifies that it passes sanity range checks, and then adds the value to the result array.

This also un-sets the _millisMeasurementRequested timestamp (sets _millisMeasurementRequested to 0) and updates the _sensorStatus.