- C 83.6%
- Python 10.5%
- CMake 5.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| include | ||
| src | ||
| CMakeLists.txt | ||
| conanfile.py | ||
| README.md | ||
lf-aht21
Reusable AHT21 Temperature & Humidity Sensor driver library for the Raspberry Pi Pico C SDK, packaged as a Conan package. This is designed for the AHT21 / AM2301B breakout modules.
This is part of the Lost + Found suite of projects.
🛠️ Usage with CMake
Copy the driver directory into your project as a subdirectory:
add_subdirectory(lib/lf-aht21)
target_link_libraries(your_project PRIVATE
lf-aht21
)
And in your C/C++ code:
#include "lf_aht21.h"
🔌 Hardware Setup
Connect the AHT21 breakout I2C pins to your Raspberry Pi Pico:
- Pico GP4 (SDA) <-> Breakout SDA
- Pico GP5 (SCL) <-> Breakout SCL
- Pico GND <-> Breakout GND
- Pico 3V3 OUT <-> Breakout VCC
💡 Example
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"
#include "lf_aht21.h"
#define I2C_PORT i2c0
#define PIN_SDA 4
#define PIN_SCL 5
int main() {
stdio_init_all();
sleep_ms(2000);
// Initialize I2C
i2c_init(I2C_PORT, 100 * 1000);
gpio_set_function(PIN_SDA, GPIO_FUNC_I2C);
gpio_set_function(PIN_SCL, GPIO_FUNC_I2C);
gpio_pull_up(PIN_SDA);
gpio_pull_up(PIN_SCL);
// Create and initialize device context
lf_aht21_t sensor;
if (!lf_aht21_init(&sensor, I2C_PORT, LF_AHT21_I2C_ADDR)) {
printf("Failed to initialize driver context!\n");
return -1;
}
// Ping device to verify it's connected
if (!lf_aht21_ping(&sensor)) {
printf("AHT21 sensor not responding at address 0x%02X!\n", sensor.i2c_addr);
return -1;
}
printf("AHT21 sensor detected successfully.\n");
while (true) {
float temp = 0.0f;
float hum = 0.0f;
if (lf_aht21_read_data(&sensor, &temp, &hum)) {
float temp_f = temp * 9.0f / 5.0f + 32.0f;
printf("Temperature: %.2f °C (%.2f °F) | Humidity: %.2f %%\n", temp, temp_f, hum);
} else {
printf("Failed to read AHT21 sensor!\n");
lf_aht21_reset(&sensor);
}
sleep_ms(1500);
}
return 0;
}
⚙️ Prerequisites: Setting up Conan with uv
To install the Conan CLI package manager securely and in an isolated environment on your system, it is recommended to use uv:
# Install Conan globally as an isolated tool
uv tool install conan
📦 Consumption via Forgejo Conan Registry
The package is hosted and distributed through the Forgejo Conan Package Registry at git.clowderlabs.com.
1. Add the Remote Registry
Add the remote repository to your local Conan configuration:
conan remote add clowder https://git.clowderlabs.com/api/packages/blong/conan
2. Authenticate
Log in using your personal access token:
conan remote login -p <your_token> clowder <username>
3. Add to your Project
Add the dependency to your conanfile.txt (or conanfile.py):
[requires]
lf-aht21/0.0.1
Then install the dependencies:
conan install . --output-folder=build --build=missing
🛠️ Local Testing
To test building and exporting this Conan package locally without uploading, run:
conan export .
This will register lf-aht21/0.0.1 in your local Conan cache for offline testing.