Hi! I'm having problems when trying to read from two Adafruit AHT10 Temp/Humidity sensors simultaneously. The library AHTX1 is a copy of AHTX0 but i've changed the default address to 0x39 instead of 0x38 (I have soldered the sensors differently). I can't get different values from the sensors, seems like both the Ref and Shoe varaibles hold the same values. Is there any good approach to solving this?
void loop(void){
sensors_event_t humidity, temp;
refSens.getEvent(&humidity, &temp);
tempRef= temp.temperature;
humiRef = humidity.relative_humidity;
shoeSens.getEvent(&humidity, &temp);
tempShoe= temp.temperature;
humiShoe = humidity.relative_humidity;
I appreciate all help!
This is the initialization
Adafruit_AHTX0 shoeSens;
Adafruit_AHTX1 refSens;
int lastTimeOff;
int tempShoe;
int humiShoe;
int tempRef;
int humiRef;
shoeSens.begin(&Wire, 0x38);
refSens.begin(&Wire, 0x39);
Welcome to the forum
Please post your full sketch
Run the Arduino I2C address scanner program, for each sensor alone, to check whether that operation was successful.
Thanks
Here is the full sketch:
#include <Wire.h>
#include <Adafruit_AHTX0.h>
#include <Adafruit_AHTX1.h>
#include <U8x8lib.h>
#include <Arduino.h>
// I2C
// GND = BLUE
// VDD = RED
// SCL = YELLOW
// SDA = BLACK
U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(U8X8_PIN_NONE);
Adafruit_AHTX0 shoeSens;
Adafruit_AHTX1 refSens;
int lastTimeOff;
int tempShoe;
int humiShoe;
int tempRef;
int humiRef;
void setup(void){
Wire.begin();
Wire.setClock(340000);
Serial.begin(9600);
u8x8.setI2CAddress(0x78);
u8x8.begin();
u8x8.setFont(u8x8_font_artossans8_r);
u8x8.clearDisplay();
pinMode(2,OUTPUT); // fan
pinMode(3,OUTPUT); // heat
pinMode(4, INPUT); // start breaker
shoeSens.begin(&Wire, 0x38);
refSens.begin(&Wire, 0x39);
}
void loop(void){
sensors_event_t humidity, temp;
refSens.getEvent(&humidity, &temp);
tempRef= temp.temperature;
humiRef = humidity.relative_humidity;
shoeSens.getEvent(&humidity, &temp);
tempShoe= temp.temperature;
humiShoe = humidity.relative_humidity;
bool breaker = digitalRead(4); // If a shoe is placed
if(breaker == HIGH){
int currentTime = millis();
int timeDiff = currentTime - lastTimeOff;
// Just graphical
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("ShoeTemp: "));
u8x8.print(tempShoe);
u8x8.setCursor(0, 2);
u8x8.print(F("ShoeHumi: "));
u8x8.print(humiShoe);
delay(1000);
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("Temp: "));
u8x8.print(tempRef);
u8x8.setCursor(0, 2);
u8x8.print(F("Humi: "));
u8x8.print(humiRef);
if (timeDiff < 30000){ // Force fan and heat on for the first 30 seconds
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("STARTING"));
}
else if (tempShoe > 70){ // Shut of at temperatures over 70C
digitalWrite(2, LOW);
}
else if (humiRef-humiShoe < 10){ // Shoe is dry if humidity difference is less than 10
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
else if (timeDiff < 7200000){ // Restart heating if not over 70C anymore
digitalWrite(2, HIGH);
}
else { // Safety shut of after 2 hours
digitalWrite(2, LOW);
digitalWrite(3, LOW);
}
}
else {
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("Temp: "));
u8x8.print(tempRef);
u8x8.setCursor(0, 2);
u8x8.print(F("Humi: "));
u8x8.print(humiRef);
int lastTimeOff = millis();
delay(1000);
}
}
I've had the I2C scanner running for ~10 min without any signal loss with any of my three nodes
Does the I2C address scanner program verify that your address changes were successful, and correct?
What do you mean by "three nodes"?
I think so. Maybe 'slaves' is a better name. The I2C scanner shows that it found devices at 0x38, 0x39 and 0x3C (two AHT10:s and one SSD1306 OLED screen)
You may be using the .begin() method incorrectly. There are three parameters.
See the library code at GitHub - adafruit/Adafruit_AHTX0: Arduino library for AHT10 and AHT20 sensors!
/*!
* @brief Sets up the hardware and initializes I2C
* @param wire
* The Wire object to be used for I2C connections.
* @param sensor_id
* The unique ID to differentiate the sensors from others
* @param i2c_address
* The I2C address used to communicate with the sensor
* @return True if initialization was successful, otherwise false.
*/
bool Adafruit_AHTX0::begin(TwoWire *wire, int32_t sensor_id,
uint8_t i2c_address) {
More informed help would be available on the Adafruit forum.
Thanks for that info, now i have added the extra sensor_id parameter in the .begin() method and i have made some progress but still the values in tempShoe and tempRef are always the same, as with humiShoe and humiRef
i have added the extra sensor_id parameter.
That makes two. There are THREE parameters in the .begin() method.
Post the revised code.
Yes maybe I was unclear. Here is the revised code (also scaled back to a bare minimum - but the problem still persists)
#include <Wire.h>
#include <Adafruit_AHTX0.h>
#include <U8x8lib.h>
#include <Arduino.h>
// I2C
// GND = BLUE
// VDD = RED
// SCL = YELLOW
// SDA = BLACK
// Objects
U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(U8X8_PIN_NONE);
Adafruit_AHTX0 shoeSens;
Adafruit_AHTX0 refSens;
// Global variables
int delayTime = 1000;
int lastTimeOff = millis();
int tempRef;
int humiRef;
int tempShoe;
int humiShoe;
void setup(){
// Outputs
Wire.begin();
Serial.begin(9600);
u8x8.setI2CAddress(0x78);
u8x8.begin();
u8x8.setFont(u8x8_font_artossans8_r);
u8x8.clearDisplay();
// Inputs
shoeSens.begin(&Wire, 0, 0x38);
refSens.begin(&Wire, 1, 0x39);
}
void loop(){
sensors_event_t humidity, temp;
if (refSens.getEvent(&humidity, &temp)) {
tempRef= temp.temperature;
humiRef = humidity.relative_humidity;
}
if (shoeSens.getEvent(&humidity, &temp)) {
tempShoe= temp.temperature;
humiShoe = humidity.relative_humidity;
}
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("Temp: "));
u8x8.print(tempRef);
u8x8.setCursor(0, 2);
u8x8.print(F("Humi: "));
u8x8.print(humiRef);
delay(delayTime);
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("ShoeTemp: "));
u8x8.print(tempShoe);
u8x8.setCursor(0, 2);
u8x8.print(F("ShoeHumi: "));
u8x8.print(humiShoe);
delay(delayTime);
}
The values printed at the screen are read from the same sensor but with a minimal delay. Say that tempRef is 22.7C then tempShoe will be somewhere around 22.6-22.8C even though that sensor is placed in a much hotter climate. So the two variables tempRef and TempShoe are different, but read from the same sensor with a ever so small delay.
I just noticed that you are using the same structure for both sensors. I don't see why that would not work as expected, but suggest to something like this instead:
void loop(){
sensors_event_t humidity, temp;
if (refSens.getEvent(&humidity, &temp)) {
tempRef= temp.temperature;
humiRef = humidity.relative_humidity;
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("Temp: "));
u8x8.print(tempRef);
u8x8.setCursor(0, 2);
u8x8.print(F("Humi: "));
u8x8.print(humiRef);
delay(delayTime);
}
if (shoeSens.getEvent(&humidity, &temp)) {
tempShoe= temp.temperature;
humiShoe = humidity.relative_humidity;
u8x8.clearDisplay();
u8x8.setCursor(0, 0);
u8x8.print(F("ShoeTemp: "));
u8x8.print(tempShoe);
u8x8.setCursor(0, 2);
u8x8.print(F("ShoeHumi: "));
u8x8.print(humiShoe);
delay(delayTime);
}
}
system
Closed
October 22, 2024, 1:02pm
14
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.