A pair of HC-SR04P ultrasonic sensors connected to Core module


#1

Good evening.

I would like to use two HC-SR04P ultrasonic sensors for the upcoming project. My question is how to connect both of them to work properly simultaneously. @martin.grames used one connected to port eight (P8) and P9, but where to connect another one? Is necessary to use some module like sensor module?


#2

Unfortunately, currently only one sensor can be used with the firmware on PINs P8 for Echo and P9 for Trig.
I can edit the firmware during the weekend and then send it as pull request.


#3

Thanks great. :slight_smile:


#4

Hi,
right now we do not have library for SR04p written in a way, that you could use multiple sensors.
Thanks @martin.grames for your help. I do have only one sensor but I can try to test your updated library.
Martin


#5

Any updates?
Thanks for your care @martin.grames.


#6

Done and pushed to branch multiple-hc_sr04 :slight_smile:
I wrote info in czech to my blog:


#7

Brilliant! Thanks @martin.grames. I’ll try it.


#8

Thank you for new driver. I have just a single sensor but I try it soon.

Based on my calculations (please check it, I might be wrong) and the sensor datashett you can get up to 4 meters distance (this sounds great, maybe too optimistic? :slight_smile: ). This takes the sound 13 ms to travel 4m, times two
because the sound goes the same distance back is 24 ms. So it can take up to 24ms in the measurement loop. So your 30 ms timeout seems perfect choice.
Now this is for further discussion, but you should disable the IRQ interrupts during measurement, because they can mess your measurement. On the other side disabling interrupts can collide with some other BigClown libraries who depends on EXTI gpio interrupts which you don’t miss, but they will be handled a bit later then planned. So this is needed to be considered and tested further. From our SDK right now I do not recall any library which would have issues with this delay but I might be wrong :slight_smile:

How many sensors would you need to have connected at the same time?

Martin


#9

Hi @hub.martin.
That’s for your point of view.
For me I only need to measure distance by two sensors.
I’m not sure if @martin.grames need to connect more than one sensor right now.

+Matouš S.


#10

Proved, it works. :grinning: Great job @martin.grames.