Go Down

Topic: JSN-SR04T long range ultrasonic wange finder Mininmum Range  (Read 60498 times) previous topic - next topic

enjoyneering

Hi, teckel

Thanks for the answer. I want to make my library better and I need your help. Tell me a little more about problems in libraries like mine? Thank you.

teckel

Hi, teckel

Thanks for the answer. I want to make my library better and I need your help. Tell me a little more about problems in libraries like mine? Thank you.
Blocking mode programming paradigm, uses slower functions that use more memory instead of direct port manipulation, median function is rudimentary and inflexible, uses floating point math which is far slower and uses much more memory, uses simple pulseIn() method like the basic ping library which is slow and prone to problems, etc.


Basically, I wrote NewPing to replace libraries like this which were just a basic port high, port low, pulseIn, which didn't work well in real-world situations.  People can choose to use whatever library they wish, but I would advice people to use NewPing to reduce memory, increase speed, and avoid problems.  It's also been tested for over 7 years by hundreds of thousands of users.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

enjoyneering

I take a different approach - use as many standard Arduino framework features as possible, so I do not have problems (like you do) with the Arduino MCU Zoo (AVR,Teensy, ESP8266, ESP32, STM32, Nordic RN52). For examle I have not seen direct port manipulations for popular ESP8266, ESP32, STM32, Nordic RN52 in your library. Correct me if I wrong. Why are you mixing the Arduino framework with low AVR-GCC, etc.? It will be cleaner & loop faster if you made all code in avr-gcc, esp-udf, stm hal etc.

I'm to trying to say that you library is bad. It is different. With your fast low level port manipulation you lose the versatility of the Arduino. This is an examle:

"This allows a
// properly developed sketch to multitask. Be aware that because the ping_timer method uses Timer2,
// other features or libraries that also use Timer2 would be effected. For example, the PWM function on
// pins 3 & 11 on Arduino Uno (pins 9 and 11 on Arduino Mega) and the Tone library. Note, only the PWM
// functionality of the pins is lost
(as they use Timer2 to do PWM), the pins are still available to use.
// NOTE: For Teensy/Leonardo (ATmega32U4) the library uses Timer4 instead of Timer2."


P.S. Do not blame me that the library is slow, blame Arduino framework. :) If you want fast code, then the Arduino framework is not for you.

teckel

I take a different approach - use as many standard Arduino framework features as possible, so I do not have problems (like you do) with the Arduino MCU Zoo (AVR,Teensy, ESP8266, ESP32, STM32, Nordic RN52). For examle I have not seen direct port manipulations for popular ESP8266, ESP32, STM32, Nordic RN52 in your library. Correct me if I wrong. Why are you mixing the Arduino framework with low AVR-GCC, etc.? It will be cleaner & loop faster if you made all code in avr-gcc, esp-udf, stm hal etc.

I'm to trying to say that you library is bad. It is different. With your fast low level port manipulation you lose the versatility of the Arduino. This is an examle:

"This allows a
// properly developed sketch to multitask. Be aware that because the ping_timer method uses Timer2,
// other features or libraries that also use Timer2 would be effected. For example, the PWM function on
// pins 3 & 11 on Arduino Uno (pins 9 and 11 on Arduino Mega) and the Tone library. Note, only the PWM
// functionality of the pins is lost
(as they use Timer2 to do PWM), the pins are still available to use.
// NOTE: For Teensy/Leonardo (ATmega32U4) the library uses Timer4 instead of Timer2."


P.S. Do not blame me that the library is slow, blame Arduino framework. :) If you want fast code, then the Arduino framework is not for you.
That's only if you're using timer methods that are non-blocking mode.  There's no timer conflict with non-timer methods.  I'm mixing AVR and non-AVR as that doesn't change the speed or size of the code as all of that is processed at compile time, not in execution on the microcontroller.

Again, to each his own, I just wouldn't suggest using the library.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

iliazark

I bought one of those parking sensors from aliexpress and it has a lower limit of 30cm...
Having reverse engineering it, does't seem to me that switching from output to input is actually the problem. In my case, the sensing side of the circuit is always listening.
As far as I understand, one problem is the fact that it transmits 20 pulses (in my case at least) and that limits the minimum distance to about 10cm. The biggest problem though by far, is the oscilations on the output transformer that occur once the pulses from the microcontroller have stopped.
I am gonna try replacing the microcontroller with one that I can programm and adding a little aditional circuitry to dumpen the oscilation once the pulses have finished.
I think by reducing the number of pulses and with the additional circuitry, I will be able to get reaadings down to about 10cm

shelly_sanders7291

I bought one of those parking sensors from aliexpress and it has a lower limit of 30cm...
Having reverse engineering it, does't seem to me that switching from output to input is actually the problem. In my case, the sensing side of the circuit is always listening.
As far as I understand, one problem is the fact that it transmits 20 pulses (in my case at least) and that limits the minimum distance to about 10cm. The biggest problem though by far, is the oscilations on the output transformer that occur once the pulses from the microcontroller have stopped.
I am gonna try replacing the microcontroller with one that I can programm and adding a little aditional circuitry to dumpen the oscilation once the pulses have finished.
I think by reducing the number of pulses and with the additional circuitry, I will be able to get reaadings down to about 10cm
Or you could just save the hassle and buy other waterproof ultrasonic sensors. There are other IP67 waterproof rated ultrasonic sensors with 3cm minimum distance costing around $20.

iliazark

Or you could just save the hassle and buy other waterproof ultrasonic sensors. There are other IP67 waterproof rated ultrasonic sensors with 3cm minimum distance costing around $20.
Yes but that's not fun..
Can you link some of those 3cm minimum distance sensors?
I suspect they use two sensors for transmiting and recieving.
I want to mount them on my car so the single sensor ones are more suitable for me.

teckel

Yes but that's not fun..
Can you link some of those 3cm minimum distance sensors?
I suspect they use two sensors for transmiting and recieving.
I want to mount them on my car so the single sensor ones are more suitable for me.
Single sensors never work at close range. The problem isn't switching time between sending and receiving, it's that the sensor needs time to settle vibration from sending to be able to listen.

The only option is to put the sensor in a deep tube, where the mouth of the tube is the minimum sensor distance.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

shelly_sanders7291

Yes but that's not fun..
Can you link some of those 3cm minimum distance sensors?
I suspect they use two sensors for transmiting and recieving.
I want to mount them on my car so the single sensor ones are more suitable for me.
Yes, you are correct, it does use 2 sensors, 1 for transmitting and 1 for receiving.

teckel

My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

Go Up