Skip to content

Commit

Permalink
v 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinlyonsrepo committed Dec 22, 2022
1 parent b2c7a3b commit 49db2e6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,12 @@ Supports sensors features:
**Connections**

The Sensor uses I2C for communication's. Data is outputted (eg to a PC) via a USB.
Can be set up for any I2C interface and speed. By default I2C0, GPIO16(SDATA) and GPIO17(SCLK) & 100kHz.
If you want to use the other I2C port (I2C1) in addition to changing in the main.ccp,
The user must change it in library header as well, could not find a way around this.

* i2c_inst_t *i2c = i2c0 to i2c_inst_t *i2c = i2c1

Can be set up for any I2C interface and bus speed. By default I2C0, GPIO16(SDATA) and GPIO17(SCLK) & 100kHz.

**Files**

The main.cpp contains tests showing library functions
There is also an library (ahtxx.cpp and ahtxx.h),
There is also an library (ahtxx.cpp and ahtxx.hpp),

**Output**

Expand Down
2 changes: 2 additions & 0 deletions extra/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

* version 1.0.0 November 2022
* first release
* version 1.0.1 December 2022
* Change so user can pick any I2C interface (IC20 or IC21)


11 changes: 7 additions & 4 deletions include/ahtxx/ahtxx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@ typedef enum ASAIR_I2C_SENSOR_e{
class LIB_AHTXX
{
private:
i2c_inst_t *i2c = i2c0;
i2c_inst_t *i2c;
uint8_t _address;
uint8_t _SDataPin;
uint8_t _SClkPin;
uint16_t _CLKSpeed = 100; //I2C bus speed in khz typically 100-400
ASAIR_I2C_SENSOR_e _sensorName;
uint8_t _rawDataBuffer[6] = {AHT10_ERROR, 0, 0, 0, 0, 0};
int16_t returnValue = 0;
bool isConnected = false;

public:
// Constructor
LIB_AHTXX(uint8_t , ASAIR_I2C_SENSOR_e);
LIB_AHTXX(uint8_t address, i2c_inst_t* i2c_type, uint8_t sdata , uint8_t sclk ,uint16_t clockspeed);

void AHT10_InitI2C(i2c_inst_t* i2c_type, uint8_t sdata , uint8_t sclk ,uint16_t clockspeed);
void AHT10_DeInit(i2c_inst_t* i2c_type);
void AHT10_InitI2C(ASAIR_I2C_SENSOR_e sensorName);
void AHT10_DeInit();
bool AHT10_begin();
uint8_t AHT10_readRawData();
float AHT10_readTemperature(bool);
Expand Down
38 changes: 21 additions & 17 deletions src/ahtxx/ahtxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,32 @@
#include "../include/ahtxx/ahtxx.hpp"

// Constructor Desc init the sensor data types call before begin()
// Param 1 I2C address
// Param 2 Enum with Sensor types
// Param 1 : I2C address
// Param 2 : IC2 interface , ic20 or i2c1
// Param 3 : Data pin I2C
// Param 4 : Clock pin I2C
// Param 5 : I2C Clock speed in Khz 0-400Khz

LIB_AHTXX::LIB_AHTXX(uint8_t address, ASAIR_I2C_SENSOR_e sensorName) {
LIB_AHTXX::LIB_AHTXX(uint8_t address, i2c_inst_t* i2c_type, uint8_t SDApin, uint8_t SCLKpin, uint16_t CLKspeed) {
_address = address;
_sensorName = sensorName;
i2c = i2c_type;
_SClkPin = SCLKpin;
_SDataPin = SDApin;
_CLKSpeed = CLKspeed;
}

// Function Desc Initialise the I2C
// Param 1 : IC2 interface ic20 i2c1 etc
// Param 2 : Data pin I2C
// Param 3 : Clock pin I2C
// Param 4 : I2C Clock speed in Khz 0-400Khz
// Param 1 :: Enum with Sensor types
// NOTE :: call before begin method

void LIB_AHTXX::AHT10_InitI2C(i2c_inst_t* i2c_type, uint8_t SDApin, uint8_t SCLKpin, uint16_t CLKspeed) {
i2c_inst_t *i2c = i2c_type;
void LIB_AHTXX::AHT10_InitI2C(ASAIR_I2C_SENSOR_e sensorName) {
_sensorName = sensorName;
//init I2C
i2c_init(i2c, CLKspeed * 1000);
gpio_set_function(SDApin, GPIO_FUNC_I2C);
gpio_set_function(SCLKpin, GPIO_FUNC_I2C);
gpio_pull_up(SDApin);
gpio_pull_up(SCLKpin);
gpio_set_function(_SDataPin, GPIO_FUNC_I2C);
gpio_set_function(_SClkPin, GPIO_FUNC_I2C);
gpio_pull_up(_SDataPin);
gpio_pull_up(_SClkPin);
i2c_init(i2c, _CLKSpeed * 1000);
}

// Function desc: Initialize I2C & configure the sensor, call this function before
Expand Down Expand Up @@ -288,9 +291,10 @@ uint8_t LIB_AHTXX::AHT10_getBusyBit(bool readI2C) {
}


void LIB_AHTXX::AHT10_DeInit(i2c_inst_t* i2c_type)
void LIB_AHTXX::AHT10_DeInit()
{
i2c_inst_t *i2c = i2c_type;
gpio_set_function(_SDataPin, GPIO_FUNC_NULL);
gpio_set_function(_SClkPin, GPIO_FUNC_NULL);
i2c_deinit(i2c);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
#include "pico/stdlib.h"
#include "ahtxx/ahtxx.hpp"

LIB_AHTXX myAHT10(AHT10_ADDRESS_0X38, AHT10_SENSOR);
LIB_AHTXX myAHT10(AHT10_ADDRESS_0X38, i2c0, 16, 17, 100);

int main(void) {

float AHT10_temperature;
stdio_init_all(); // Initialize chosen serial port, 38400 default baudrate.
busy_wait_ms(500);
busy_wait_ms(1000);

printf("AHT10 Start \r\n");
myAHT10.AHT10_InitI2C(i2c0, 16, 17, 100);
myAHT10.AHT10_InitI2C(AHT10_SENSOR);
busy_wait_ms(500);

// Start the sensor comms
Expand Down

0 comments on commit 49db2e6

Please sign in to comment.