pub struct Gy21<I2C, DL> { /* private fields */ }Expand description
Represents the GY-21 sensor
Implementations§
Source§impl<I2C: Write + Read, DL> Gy21<I2C, DL>
impl<I2C: Write + Read, DL> Gy21<I2C, DL>
Sourcepub const fn new(i2c: I2C, delay: DL) -> Self
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);Sourcepub const fn with_address(i2c: I2C, delay: DL, address: u8) -> Self
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);Sourcepub fn temperature(&mut self) -> Result<f32, CommError<I2C>>
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 failsRead(i2c_err)if reading the I2C bus fails
Sourcepub fn humidity(&mut self) -> Result<f32, CommError<I2C>>
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 failsRead(i2c_err)if reading the I2C bus fails
Sourcepub fn dew_point_temp(&mut self) -> Result<f32, CommError<I2C>>
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 failsRead(i2c_err)if reading the I2C bus fails
Auto Trait Implementations§
impl<I2C, DL> Freeze for Gy21<I2C, DL>
impl<I2C, DL> RefUnwindSafe for Gy21<I2C, DL>where
I2C: RefUnwindSafe,
DL: RefUnwindSafe,
impl<I2C, DL> Send for Gy21<I2C, DL>
impl<I2C, DL> Sync for Gy21<I2C, DL>
impl<I2C, DL> Unpin for Gy21<I2C, DL>
impl<I2C, DL> UnwindSafe for Gy21<I2C, DL>where
I2C: UnwindSafe,
DL: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more