Reading GPIO input from script

I have a flow meter sensor that output PWM. how can I read that value from that sensor connecting to GPIO pin in Lua script?
I read this GPIO. If I set board count to less then output pins will AP read the value automatically and what I have to do is just read from the script?

We cant do PWM in or GPIO with scripts currently, it would be a great feature to add.

You should be able to do it with the binding desc (on master) you would add
AP_HAL::PWMSource userdata type and hal.gpio function bindings. Hopefully it will just be a matter of adding to the auto generated bindings but you may need custom bindings.

Analogue in would be another one that would be very useful.

Thanks you very much. I will need to dig through to AP::HAL then. can you give me a hint which method read input, please?

I had successfully read flow sensor with Lua script. I add a function in vehical.cpp. the code I use from AP_BattMonitor_FuelLevel_PWM the read function. I just modify a little bit.

1 Like

So Sitha_Sek, do you still use Lua scripts or just modify ap_vehical.cpp and rebuild the ardupilot ?
Thanks :smiley:

I add the function to use in Lua script. So that I can do some more test for other related algorithm.