GPIO to recognize Dry Hopper empty/not empty

Hello,

We have a Dry Hopper spreader for our drone. The spreader system contains an optical sensor for recognizing when the hopper is empty versus not empty. We’re attempting to query the sensor in Lua scripting, but not having any luck. Hoping someone can point me in the right direction.

Configuration

  • Cube Orange+
  • ESP200 Spreader System. Optical Empty sensor connected to AUX5.
  • Parameter Settings:
    • SERVO13_FUNCTION: -1 (GPIO)
    • RPM1_TYPE: 2 (GPIO)
    • RPM1_PIN: 54 (AUX 5)

Expected readings from Optical Empty Sensor

  • Hopper empty: 0v
  • Hopper not empty: 5v

Solution A

Outside of Update Loop

local EMPTY_SENSOR_PIN = 13
local empty_sensor = analog:channel()

if not empty_sensor:set_pin(EMPTY_SENSOR_PIN) then
    log_error(ADSST_ERROR.ID_003, string.format("Error setting Analog Empty Sensor Pin: %d", EMPTY_SENSOR_PIN))
    empty_sensor = nil
end

Within Update Loop

if empty_sensor ~= nil then
	log_info(ADSST_INFO.ID_004, string.format("Analog Empty Sensor Voltage %0.2f", empty_sensor:voltage_latest()))
end

Test Results

  • Function call empty_sensor:set_pin(EMPTY_SENSOR_PIN) returns true.
  • No obstruction in path of optical beam: Continuously receive voltage reading anywhere between 0.49 and 0.50
  • Place obstruction in path of optical beam: Continuously receive voltage reading anywhere between 0.49 and 0.50

Solution B

Outside of Update Loop

local EMPTY_SENSOR_PIN = 54
local empty_sensor = PWMSource()

if not empty_sensor:set_pin(EMPTY_SENSOR_PIN) then
    log_error(ADSST_ERROR.ID_003, string.format("Error setting PWM for Empty Sensor Pin: %d", EMPTY_SENSOR_PIN))
    empty_sensor = nil
end

Within Update Loop

if empty_sensor ~= nil then
	log_info(ADSST_INFO.ID_004, string.format("PWM Empty Sensor reading: %d", empty_sensor:get_pwm_us()))
end

Test Results

Function call empty_sensor:set_pin(EMPTY_SENSOR_PIN) returns false.

Solution C

Within Update Loop

local empty_sensor_reading = RPM:get_rpm(0)

if empty_sensor_reading ~= nil then
	log_info(ADSST_INFO.ID_004, string.format("RPM Empty Sensor reading: %d", empty_sensor_reading))
else
	log_error(ADSST_ERROR.ID_003, "Error obtaining RPM Empty Sensor reading.")
end

Test Results

Function call RPM:get_rpm(0) consistently returns false, regardless whether or not the optical sensor is blocked.

Conclusion

I am thinking that I am on the right track with Solution A, yet the voltage readings remain consistent regardless of whether the optical sensor beam is blocked or not blocked.

Suggestions that anyone may have are greatly appreciated.

Regards,
Dave

Set the pin as a button .

1 Like

Have not yet tried @geofrancis recommendation…in meantime I realized I posted to the incorrect Copter version…

So I updated the posting to the Copter 4.5 category…we’re running Copter 4.5.4.

https://ardupilot.org/copter/docs/common-buttons.html

Hello @geofrancis,

Can you explain why I would want to use a button implementation for this?

I’m trying to read output from an optical sensor, where that output is reported in voltage.

It seems to me a button implementation would be for input as opposed to output.

does your hopper only give a binary output where low signal is empty and high is not empty? or is it giving out a variable signal? like analog or PWM? if it’s just off and on then it’s treated as a button.

button input is just the name of the binary input on Ardupilot, you can use it for triggering auxiliary functions or for a lua script to read.

1 Like

Hello @geofrancis,

I read the Ardupilot documentation on the button implementation and kind of undestand why that should work…

I then implemented the code from the button example that you provided…and yup…it works :slight_smile:

I also set BTN_ENABLE to 1 and BTN_PIN1 to 54.

Thank you very much.

[Edited for completeness]

1 Like