hybridgroup/gobot

Driver for HC-SR04

Juan1ll0 opened this issue · 11 comments

Hi guys,
I'm writing some code with Gobot for an IOT device that need to measure a water tank level. I'm think that using an HC-SR04 is a good option but i find that Gobot doesn't have support for this sensor. I found library at https://github.com/raspberrypi-go-drivers/hcsr04 that works fine. I know that this sensor can not be used under "firmata" adaptor because of "pulseIn" function is not implemented, but with another adaptor like "raspi" Can I found any solution?. Is any sensor supported by Gobot similar to this?

I'm trying to write a new Gobot Driver adopting code of https://github.com/raspberrypi-go-drivers/hcsr04 to gobot using a "DirectPinDriver" but doesn't work. Can somebody tell me if is posible?

Like already mentioned, firmata is not best suitable because "pulsIn". I just add some issues as reference:

Hi @Juan1ll0 , please could you provide your new driver (with an example) by a Draft-PR to dev-branch. So maybe we can find a solution.

Hi @Juan1ll0 , please could you provide your new driver (with an example) by a Draft-PR to dev-branch. So maybe we can find a solution.

Sorry it doesn't work the code only compiles. I try to transform code like structs, pins and similar but it doesn't work. For example the mentioned project used github.com/stianeikeland/go-rpio/v4 and I transform pins to DirectPinDriver gobot implementation and similar things. The code I worte implent the gobot interface Driver like this guide explain https://gobot.io/documentation/guides/adding-hardware-support/ and you can do: hsrc04 := hcsr04.NewHCSR04(raspberry, "17","27") and works perfectly but doesn't give you measurements.

@Juan1ll0 please create a branch with your code and file a Draft-PR or add the files here (e.g. as zip) and I can do that.

OK. I'll do it

@Juan1ll0 please create a branch with your code and file a Draft-PR or add the files here (e.g. as zip) and I can do that.

You've got at https://github.com/hybridgroup/gobot/pull/872. Sorry about my code but i'm not an experto on go. Than you by your interest.
It fails test sorry but I can't write then yet, it was only a concept test

Ok, could you please describe:

  • which adaptor do you use and which specific hardware and installed OS/FW
  • how is the setup (e.g. you could provide an example in your PR)
  • what exactly does not work (Do you have a specific error, timeout etc?)

Ok, could you please describe:

  • which adaptor do you use and which specific hardware and installed OS/FW
  • how is the setup (e.g. you could provide an example in your PR)
  • what exactly does not work (Do you have a specific error, timeout etc?)

I use a raspberry pi 4 with Raspian, with Gobot 1.16 and Go 1.18.

Adaptor: raspi
Setup: On pins 11 for trigger and 13 for echo
Error: Timeout - message: ERRO[0000] impossible to measure distance error="echo not received after 60 milliseconds"

I thought the problem is on function StartDistanceMonitor or in getPinStateChangeTime i will continue investigating.

@Juan1ll0 please see my remarks in PR.