golemparts / rppal

A Rust library that provides access to the Raspberry Pi's GPIO, I2C, PWM, SPI and UART peripherals.
MIT License
1.24k stars 97 forks source link

InputPin trait not implemented #105

Closed Xavientois closed 2 years ago

Xavientois commented 2 years ago

I am trying to use the gpio pins to read in data from a DHT11 temperature and humidity sensor. However, when I pass my pin to the new method, I get the following compiler error saying that the InputPin trait is not implemented:

error[E0277]: the trait bound `&InputPin: embedded_hal::digital::v1::InputPin` is not satisfied
  --> src/main.rs:25:32
   |
25 |     let mut dht11 = Dht11::new(&pin);
   |                     ---------- ^^^^ the trait `embedded_hal::digital::v1::InputPin` is not implemented for `&InputPin`
   |                     |
   |                     required by a bound introduced by this call
   |
   = note: required because of the requirements on the impl of `embedded_hal::digital::v2::InputPin` for `&InputPin`
note: required by a bound in `Dht11::<GPIO>::new`
  --> /home/.cargo/registry/src/github.com-1ecc6299db9ec823/dht11-0.3.1/src/lib.rs:78:20
   |
78 |     GPIO: InputPin<Error = E> + OutputPin<Error = E>,
   |                    ^^^^^^^^^ required by this bound in `Dht11::<GPIO>::new`

error[E0277]: the trait bound `&InputPin: embedded_hal::digital::v1::OutputPin` is not satisfied
  --> src/main.rs:25:32
   |
25 |     let mut dht11 = Dht11::new(&pin);
   |                     ---------- ^^^^ the trait `embedded_hal::digital::v1::OutputPin` is not implemented for `&InputPin`
   |                     |
   |                     required by a bound introduced by this call
   |
   = note: required because of the requirements on the impl of `embedded_hal::digital::v2::OutputPin` for `&InputPin`
note: required by a bound in `Dht11::<GPIO>::new`
  --> /home/.cargo/registry/src/github.com-1ecc6299db9ec823/dht11-0.3.1/src/lib.rs:78:43
   |
78 |     GPIO: InputPin<Error = E> + OutputPin<Error = E>,
   |                                           ^^^^^^^^^ required by this bound in `Dht11::<GPIO>::new`

I am confused by this, as it looks like the trait should be implemented. Here is my source code:

    let pin = Gpio::new()?.get(DHT11_PIN)?.into_input();
    let mut dht11 = Dht11::new(&pin);

I am not sure whether I should be posting this issue here or in the DHT11 repo, but I haven't been able to figure out the cause of the problem.

Xavientois commented 2 years ago

Switching to using the into_output method on the Pin fixed this error. I still don't understand why it was saying that it did not implement InputPin, but I will close this for now, as it is no longer a blocker for me.