logo elektroda
logo elektroda
X
logo elektroda

Connecting Two AHT2x Sensors to XH-WB3S (BK7238) with Multiple I2C Addresses

taggbricka 159 5
ADVERTISEMENT
  • #1 21588260
    taggbricka
    Level 6  
    Is it possible to have two AHT2x compatible sensors on one XH-WB3S, Chipset BK7238 ?
    The AHT30 breakout boards I am using have no obvious way to change the I2C address.
    Intended measurement before and after a cooler.

    This did not work as I hoped:
    backlog startdriver AHT2x 7 8 1 2; startdriver AHT2x 23 28 3 4;
  • ADVERTISEMENT
  • Helpful post
    #2 21588784
    max4elektroda
    Level 20  
    It's not possible with the current driver. Enhancing it for multiple sensors (on different pins) might be possible. If you are willing to wait I can try, but it will take some time, I need to finish other tasks before starting a new one.
  • ADVERTISEMENT
  • #3 21589639
    taggbricka
    Level 6  
    I really appreciate it if you give it a try. Don't know if this is a fringe application or if anyone else might find it useful.
    It is a hobby project, I have no time pressure from anyone.
  • ADVERTISEMENT
  • #4 21592919
    max4elektroda
    Level 20  
    After fighting with my own errors, I think I finally made a working version.
    Thanks for your feedback to find them!

    Here's a version for your BK7238, will make a PR in some minutes, just need to cleanup all the debug output ...

    For your sensors on pins 7/8 and 23/28 please use:

    backlog startdriver AHT2x 7 8 1 2; AHT2X_Addsensor 23 28 3 4;
  • ADVERTISEMENT
  • #5 21592948
    taggbricka
    Level 6  
    This is working correctly on my device!
    Thank you!

    Added after 3 [minutes]:

    Connecting Two AHT2x Sensors to XH-WB3S (BK7238) with Multiple I2C Addresses
  • #6 21592955
    max4elektroda
    Level 20  
    Opened PR #1696 for this.

    I think I found a BMP280+AHT20 board and an AHT10. Let me solder them, so I can provide a screenshot...

    Usage is extended by a command

    AHT2X_Addsensor <CLK Pin> <DATA Pin> [Channel temperature] [Channel humidity]


    All other commands have been extended to add an optional <Sensor number> as last argument to address it, as shown in code.

    "Calibrate" will work on sensor 0 if only 1 or 2 arguments are given.
    In order to change a sensor != 0, you must give temp-dalta AND humidity-delta AND sensor-number
    Or has someone a better idea?

    All other commands will default to all sensors.

        //cmddetail:{"name":"AHT2X_Calibrate","args":"<DeltaTemp> [DeltaHumidity - default 0] [Sensor - default 0]",
       //cmddetail:"descr":"Calibrate the AHT2X Sensor as Tolerance is +/-2 degrees C.",
       //cmddetail:"fn":"AHT2X_Calibrate","file":"driver/drv_aht2x.c","requires":"",
       //cmddetail:"examples":"AHT2X_Calibrate -4 10 <br /> meaning -4 on current temp reading and +10 on current humidity reading for first sensor"}
       CMD_RegisterCommand("AHT2X_Calibrate", AHT2X_Calibrate, NULL);
       //cmddetail:{"name":"AHT2X_Cycle","args":"<IntervalSeconds> [Sensor - default: all sensors]",
       //cmddetail:"descr":"This is the interval between measurements in seconds, by default 1. Max is 255.",
       //cmddetail:"fn":"AHT2X_cycle","file":"drv/drv_aht2X.c","requires":"",
       //cmddetail:"examples":"AHT2X_Cycle 60 <br /> measurement is taken every 60 seconds"}
       CMD_RegisterCommand("AHT2X_Cycle", AHT2X_Cycle, NULL);
       //cmddetail:{"name":"AHT2X_Measure","args":"[Sensor - default: all sensors]",
       //cmddetail:"descr":"Retrieve OneShot measurement.",
       //cmddetail:"fn":"AHT2X_Measure","file":"drv/drv_aht2X.c","requires":"",
       //cmddetail:"examples":"AHT2X_Measure"}
       CMD_RegisterCommand("AHT2X_Measure", AHT2X_Force, NULL);
       //cmddetail:{"name":"AHT2X_Reinit","args":"[Sensor - default: all sensors]",
       //cmddetail:"descr":"Reinitialize sensor.",
       //cmddetail:"fn":"AHT2X_Reinit","file":"drv/drv_aht2X.c","requires":"",
       //cmddetail:"examples":"AHT2X_Reinit"}
       CMD_RegisterCommand("AHT2X_Reinit", AHT2X_Reinit, NULL);
       //cmddetail:{"name":"AHT2X_Addsensor","args":"<CLK Pin> <DATA Pin> [Channel temperature] [Channel humidity]",
       //cmddetail:"descr":"Add another AHT2X with CLK and DATA pin and (optional) channels for temp and hum",
       //cmddetail:"fn":"AHT2X_Addsensor","file":"driver/drv_aht2x.c","requires":"",
       //cmddetail:"examples":"AHT2X_Addsensor 10 11 4 5<br /> Sensor with CLK on pin 10 Data pin 11, channel for temp 4 channel for hum 5"}
       CMD_RegisterCommand("AHT2X_Addsensor", CMD_AHT2X_AddSensor, NULL);


    Added after 58 [minutes]:

    I really had two AHTx based sensors around - sorry I didn't find them before, so @taggbricka had to do all the tests.
    So it's working for me, too:
    Screenshot of a text interface listing commands for AHT2X, AHT10, and BMP280 sensors.


    Spoiler:
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[0] Temperature:28.723907C Humidity:51.635075%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=15 data=17) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.340149C Humidity:52.094936%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[0] Temperature:28.734207C Humidity:53.675556%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=15 data=17) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.365707C Humidity:53.588200%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[0] Temperature:28.745651C Humidity:51.850891%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=15 data=17) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.362656C Humidity:52.093315%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.348923C Humidity:51.718330%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[0] Temperature:28.767776C Humidity:51.458168%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=15 data=17) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.397369C Humidity:51.644611%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[0] Temperature:28.752518C Humidity:51.457882%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=15 data=17) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.391647C Humidity:51.619244%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=7 data=8) .
    Info:SENSOR:AHT2X_Measure: Sensor[0] Temperature:28.748894C Humidity:51.473236%
    Info:SENSOR:AHT2X_Measure: Measuring sensor clk=15 data=17) .
    Info:SENSOR:AHT2X_Measure: Sensor[1] Temperature:28.372955C Humidity:51.601124%
ADVERTISEMENT