Grog,

I am using a MatBotix Sensor and want to use the single pin.  I am going crazy trying to ping it and get the time elasped, much like the UltraSonicSensor.  I did the PIRs without using the PIR Service and attached a PinArrayListener and get my passive reads no problem.  I can rewire that matbotix, although I have dug all the way down to msg.java and serial.java and arduino.java and just want to find a way to perform the PulseIn() feature of Arduino.  Hit the pin with a 1, and then read the pin for the 0, and calculate the MS.  I cannot seem to easily get at those Milliseconds. 

I tried with 1 pin, but as you know that causes a serial read error as they are both accessing the same address.  I tried a dummy pin, but then I do not get the read.  A trigger does not return the delay in MS.  There must be an easy way that I am just missing.  Please Help!

 

Gareth

3 years 9 months ago

Watcha Jim,

Which MatBotix Sensor do you have ?

On my MatBotix Sensor I have also an "AN" pin which can be used instead of the PWM/BW timeing pins.

Basically it gives an analog out in relation to distance.

It might be a quick workaround to simply read it in as an analog ... analog>distance formulas can be found here depending on your device :- https://www.maxbotix.com/downloads.htm

I resoldered to use the AN (Analog Pin).  I noticed that Msg.java would need to be updated to do what I need to do, resulting in an update to the Adruino client as well.  I set up PinArrayListeners for the PIR pins and it reads the values (1 and 0) fine.  I tried the same with the Analog pins and it appears that the values are returned as integer (int) via the listeners. OnPinArrayListener().  I added a Serial.t oLong() rather than the Serial.toInt() and the value is now 1023, which means it is HIGH.  

I tried to enablePin() although that will give me integer values as well via its Polling mechanism.  So I just made a loop of read()  (it defaults to analog via the first letter via pindef) from the Pin and see the value of 1023.  I see that Mapper is called to clip the value so I assume that it runs through Serial.java as that is the only place a true - read - operation is performed.  I attempted to set a trigger, although that did not seem to work.  

Is the proper method to just write a loop and read for a predetermined period of time?    Thank you!!!!

 

GroG

3 years 9 months ago

Hi SurferJim,
The PulseIn method is avoided because it blocks the thread until an echo is heard or it times out.  This can be very problematic in the communication between the Arduino service and MrlComm because they are expecting a heartbeat.

I don't understand why Msg would need to be modified - perhaps you can submit a pr so I get a better understanding of what your trying to do.

Cheers.

I have a MatBotic Acoustic Sensor.  It works on one pin, either digital or analog.  I need to pulse the Analog pin to set it HIGH, and then read the value from the Analog pin.  I attached a PinListener, although the code returns an integer.  I also tried setting a trigger, but that did not seem to work.  I need the value read from the Analog pin.  So, I am currently just setting up a for loop and doing a analog read of the pin.  The value seems to come back to what I set it to, and is not getting the value from its sensor.  How may I read an Analog pin and get the Analog value which should be in a range from 0-1023.  That value represents a distance.  Thank you.