Gy21

Struct Gy21 

Source
pub struct Gy21<I2C, DL> { /* private fields */ }
Expand description

Represents the GY-21 sensor

Implementations§

Source§

impl<I2C: Write + Read, DL> Gy21<I2C, DL>
where DL: DelayMs<u8>,

Source

pub const fn new(i2c: I2C, delay: DL) -> Self

Create a new GY-21 sensor from an I2C bus and a delay object with the default I2C address (0x40)

The I2C object must be created with a frequency <= 400kHz, which is the maximum the sensor is able to keep up with as stated by the datasheet.

let gy_21 = Gy21::new(i2c, delay);
Source

pub const fn with_address(i2c: I2C, delay: DL, address: u8) -> Self

Create a new GY-21 sensor from an I2C bus, a delay object and an I2C address

let gy_21 = Gy21::with_address(i2c, delay, 0x40);
Source

pub fn temperature(&mut self) -> Result<f32, CommError<I2C>>

Read the temperature

let reading = match gy_21.temperature() {
    Ok(val) => val;
    Err(_) => panic()!
}
§Errors

Will return an error in the following cases:

  • Write(i2c_err) if writing to the I2C bus fails
  • Read(i2c_err) if reading the I2C bus fails
Source

pub fn humidity(&mut self) -> Result<f32, CommError<I2C>>

Read the relative humidity

let reading = match gy_21.humidity() {
    Ok(val) => val;
    Err(_) => panic()!
}
§Errors

Will return an error in the following cases:

  • Write(i2c_err) if writing to the I2C bus fails
  • Read(i2c_err) if reading the I2C bus fails
Source

pub fn dew_point_temp(&mut self) -> Result<f32, CommError<I2C>>

Calculate the dew point temperature based on temperature and relative humidity readings

The dew point of a given body of air is the temperature to which it must be cooled to become saturated with water vapor.

let reading = match gy_21.dew_point_temp() {
    Ok(val) => val;
    Err(_) => panic()!
}
§Errors

Will return an error in the following cases:

  • Write(i2c_err) if writing to the I2C bus fails
  • Read(i2c_err) if reading the I2C bus fails

Auto Trait Implementations§

§

impl<I2C, DL> Freeze for Gy21<I2C, DL>
where I2C: Freeze, DL: Freeze,

§

impl<I2C, DL> RefUnwindSafe for Gy21<I2C, DL>
where I2C: RefUnwindSafe, DL: RefUnwindSafe,

§

impl<I2C, DL> Send for Gy21<I2C, DL>
where I2C: Send, DL: Send,

§

impl<I2C, DL> Sync for Gy21<I2C, DL>
where I2C: Sync, DL: Sync,

§

impl<I2C, DL> Unpin for Gy21<I2C, DL>
where I2C: Unpin, DL: Unpin,

§

impl<I2C, DL> UnwindSafe for Gy21<I2C, DL>
where I2C: UnwindSafe, DL: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.