When using two (multiple) MB1040, LV-MaxSonar-EZ4 is there anything special needed to be done?


We’re using two MB1040, LV-MaxSonar-EZ4 on our bot to figure out if we’re parallel to the walls. Since the Roborio reads in the analog inputs in a round robin fashion do we need to do any of this chaining stuff: https://www.maxbotix.com/tutorials1/031-using-multiple-ultrasonic-sensors.htm?

We’ve wired them up via GND, +5v, and Analog to the Roborio analog ports.

Code: https://github.com/PearceRobotics/deep-space-2019/pull/26/files


I’m not sure what you mean by “reads in the analog inputs in a round robin fashion”. The roborio reads the pins. That has nothing to do with when the maxbotics sensors will send their pings. If they are pointing at the same wall, then there is likely to be cross talk between the two sensors if they aren’t sequenced.


Ah thank you for your answer, that makes sense. I should have realized that the reading of the voltage via the analog port has nothing to do with the actual sensor pinging.


So I’m looking at the MaxBotIx docs, specially the section:

Sequentially Read Each MaxSonar/Continuous Looping

To have the circuit continuously loop so the chain is always giving an analog voltage output, connect pin 5 of the last sensor in the sequence to pin 4 of the first sensor in sequence with a 1K resistor in sequence between the pin 5 output and pin 4 input.

It sounds like you daisy chain tx -> rx and you trigger the loop via the rx on the first sensor in the chain. Is that correct?

If so, what port can we use on the roborio to send the initial trigger to the first sensor’s rx to kick off the continuous loop?


Bump, looking for how we should initially trigger rx on the first sensor via the rio


Hook it up to a DIO pin. You’ll have to tri-state the pin after driving it high, which requires some non-standard hackery currently (you can’t use a standard DigitalOutput). The code looks something like this (I’m assuming you’re using Java):

import edu.wpi.first.hal.DIOJNI;
import edu.wpi.first.hal.HAL;

int channel = 0; // the DIO port number
int handle = DIOJNI.initializeDIOPort(HAL.getPort((byte) channel), false);
DIOJNI.setDIO(handle, (short) 1); // set the output high
Timer.sleep(0.00002); // sleep 20 us
DIOJNI.setDIODirection(handle, true);  // make an input (to tri-state)
DIOJNI.freeDIOPort(handle);  // free the handle


Thank you for the code snippet!
When you say hook it up to a DIO pin, that just means the first sensor’s rx pin to the signal pin of the DIO right?
What does tri stating the pin mean?


Right. You have to follow the figure with the daisy chain and 1K resistor looping back to the first RX pin, and also hook up the first RX pin to a DIO pin on the Rio.

Tri-stating the DIO means that the RoboRIO is not applying a drive voltage–basically it lets the output “float”. A digital output notionally has two states–drive low and drive high, but because it’s implemented with transistors (one that connects the output to the ground rail and one that connects the output to the supply rail), it’s possible to turn off both transistors simultaneously for a third state that doesn’t drive anything to the output.


Thank you very much for the explanation, that makes a ton of sense. We will try it out and let you know the results!! (Possibly tomorrow at competition?)