Add Aosong library

Can somebody please tell me how to add the Aosong aht20 library to the cloud editor?
I have an ESP8266 12E & an AHT25 that worked great on Blynk with the Adafruit library.
Now that I have moved all my projects onto Arduino, I cannot get the AHT to show data.

Hi @stanstan65. Please provide more information about this "Aosong aht20 library".

Were you using Arduino IDE to compile and upload your sketches at that time? Or were using Arduino Cloud Editor? Or were you using some other tool?

Adafruit has created hundreds of libraries. Please provide the exact name of the library you are referring to.

Are you referring to the same library when you say "Aosong aht20 library" and "Adafruit library", or are these two different libraries?

Please post your full sketch.

I'll provide instructions you can follow to do that:

  1. Open your sketch in Arduino Cloud Editor.
  2. Click on the window that contains your sketch code.
  3. Press the Ctrl+A keyboard shortcut (Command+A for macOS users).
    This will select all the text.
  4. Press the Ctrl+C keyboard shortcut (Command+C for macOS users).
    This will copy the selected text to the clipboard.
  5. Open a forum reply here by clicking the "Reply" button.
  6. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
  7. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the copied code into the code block.
  8. Move the cursor outside of the code block markup before you add any additional text to your reply.
  9. Repeat the above process if your sketch has multiple tabs.
  10. Click the "Reply" button to post the output.

On Blynk, Arduino IDE. Using the Adafriut library
I want to try the Aosong library from Enjoyneering, in the Arduino Cloud editor.
I have tried two of the libraries in the Cloud Editor.

Please make a stronger effort to communicate. I guess you think you are saving time by making these vague short posts, but I assure you that is not so.

The people who take the time to provide the helpers here with sufficient information from the start often receive a solution within a matter of minutes. The ones who don't do that might go through days of frustrating back and forth as we struggle to squeeze the information out of them.

The choice of how this will go is yours to make.

If English isn't your first language, you are welcome to compose a detailed description in your native language and then use an automated translation service like Google Translate to translate it to English before posting.

Please answer the question I asked in my previous reply:

Please post a link to where you found that library on the Internet.

Please provide the exact names of the libraries you tried.

1 Like

These are two that I have tried.

I would like to try this one, GitHub - enjoyneering/AHTxx: This is an Arduino library for Aosong ASAIR AHT1x, AHT2x Digital Humidity & Temperature Sensor
Another member had a similar issue to mine but I cannot see the replies anymore, as it has been closed.

OK, I can help with that. All the libraries of the Arduino Library Manager are preinstalled in Arduino Cloud, so we don't need to install those libraries in order to use them in sketches in Arduino Cloud. Unfortunately the author of this library never submitted it for addition in Library Manager, so it is not preinstalled in Arduino Cloud. For this reason, it is necessary to import the library to your Arduino Cloud account in order to use it.

I'll provide instruction you can follow to do that:

A. Download the Library

  1. Click the following link to open the library's GitHub repository homepage in your web browser:
    https://github.com/enjoyneering/AHTxx
  2. Click the "Code ▾" button you see on that page.
  3. Select Download ZIP from the menu.
    A download of the ZIP file of the library will start.
  4. Wait for the download to finish.

B. Fix the Library Metadata

Normally we can simply download a library and then import the downloaded file to Arduino Cloud. Unfortunately this library has a bug that would cause the import to fail so an additional procedure is required in order to prepare it for import.

Fortunately the fix for the bug is very simple:

  1. Extract the downloaded AHTxx-main.zip file.
  2. Delete the downloaded AHTxx-main.zip file.
    :warning: Please be careful when deleting things from your computer. When in doubt, back up!
  3. Start any text editor application.
  4. Use the text editor to open the file named library.properties that is in the extracted library folder.
  5. Change this line in the file:
    name          = AHT1x/AHT2x
    
    to this:
    name          = AHTxx
    
  6. Save the file.
  7. Use an archive utility to ZIP the library folder.
    You probably have an archive utility built in to your file manager program.

C. Import Library

  1. If you are not already, log in to your Arduino account:
    https://login.arduino.cc/login
  2. Click the following link to open the list of your Arduino Cloud sketches in the web browser:
    https://app.arduino.cc/sketches
  3. Click on any sketch, or use the CREATE > New sketch button to create a new sketch.
    The sketch will open in Arduino Cloud Editor.
  4. Click the icon that looks like shelved books ("Libraries") in the bar on the left side of the Cloud Editor page.
    The "Libraries" panel will open.
  5. Click the upward pointing arrow icon at the top of the "Libraries" panel.
    The "Open" dialog will open.
  6. Select the "ZIP" file of the library in the dialog.
  7. Click the "Open" button.
    The "Open" dialog will close.
  8. You will now see an indicator at the top of the "Libraries" panel in place of the upward pointing arrow icon as the library is imported. Wait for this indicator to disappear.

You can now use the library you imported in your Arduino Cloud sketches.


Please let me know if you have any questions or problems while following those instructions.

Examples

The library developer provides some example sketches that demonstrate the usage of the library. You can study these to learn how to use the library in your own sketches.

I'll provide instructions you can follow to access the examples:

  1. If it isn't already open, select "Libraries" from the menu on the left side of the Arduino Cloud Editor window to open the Libraries panel.
  2. Select the "Custom" tab in the Libraries panel.
  3. Click the "❯ Examples" at the bottom of the "AHTxx" entry in the list of "custom" libraries.

A list of all the example sketches of the library will appear. Click any of those examples to open it in the editor.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "AHT25"
  https://create.arduino.cc/cloud/things/ffa13efa-b57c-488b-abbc-1cdcd179b793 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float boardHumid;
  float boardTemp;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <Wire.h>
#include <AHTxx.h>

float ahtValue;                               //to store T/RH result

AHTxx aht20(AHTXX_ADDRESS_X38, AHT2x_SENSOR); //sensor address, sensor type
void setup()
{

  Serial.begin(115200);
  Serial.println();
  
  while (aht20.begin() != true)
  {
    Serial.println(F("AHT2x not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free

    delay(5000);
  }


  // Defined in thingProperties.h
  initProperties();
 
 aht20.begin();
  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}


  
  // Your code here 
unsigned long last_ts = 0;

  void loop() {
   ArduinoCloud.update(); 
   
 if (millis() > last_ts + 2000) 
    last_ts = millis();
  


  /* DEMO - 1, every temperature or humidity call will read 6-bytes over I2C, total 12-bytes */
  Serial.println();
  Serial.println(F("DEMO 1: read 12-bytes"));

  ahtValue = aht20.readTemperature(); //read 6-bytes via I2C, takes 80 milliseconds

  Serial.print(F("Temperature...: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
    Serial.print(ahtValue);
    Serial.println(F(" +-0.3C"));
  }
  else
  {
    printStatus(); //print temperature command status

    if   (aht20.softReset() == true) Serial.println(F("reset success")); //as the last chance to make it alive
    else                             Serial.println(F("reset failed"));
  }

   //measurement with high frequency leads to heating of the sensor, see NOTE

  ahtValue = aht20.readHumidity(); //read another 6-bytes via I2C, takes 80 milliseconds

  Serial.print(F("Humidity......: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
    Serial.print(ahtValue);
    Serial.println(F(" +-2%"));
  }
  else
  {
    printStatus(); //print humidity command status
  }

   //measurement with high frequency leads to heating of the sensor, see NOTE

  /* DEMO - 2, temperature call will read 6-bytes via I2C, humidity will use same 6-bytes */
  Serial.println();
  Serial.println(F("DEMO 2: read 6-byte"));

  ahtValue = aht20.readTemperature(); //read 6-bytes via I2C, takes 80 milliseconds

  Serial.print(F("Temperature: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
    Serial.print(ahtValue);
    Serial.println(F(" +-0.3C"));
  }
  else
  {
    printStatus(); //print temperature command status
  }

  ahtValue = aht20.readHumidity(AHTXX_USE_READ_DATA); //use 6-bytes from temperature reading, takes zero milliseconds!!!

  Serial.print(F("Humidity...: "));
  
  if (ahtValue != AHTXX_ERROR) //AHTXX_ERROR = 255, library returns 255 if error occurs
  {
    Serial.print(ahtValue);
    Serial.println(F(" +-2%"));
  }
  else
  {
    printStatus(); //print temperature command status not humidity!!! RH measurement use same 6-bytes from T measurement
  }

   //recomended polling frequency 8sec..30sec
}


/**************************************************************************/
/*
    printStatus()

    Print last command status
*/
/**************************************************************************/
void printStatus()
{
  switch (aht20.getStatus())
  {
    case AHTXX_NO_ERROR:
      Serial.println(F("no error"));
      break;

    case AHTXX_BUSY_ERROR:
      Serial.println(F("sensor busy, increase polling time"));
      break;

    case AHTXX_ACK_ERROR:
      Serial.println(F("sensor didn't return ACK, not connected, broken, long wires (reduce speed), bus locked by slave (increase stretch limit)"));
      break;

    case AHTXX_DATA_ERROR:
      Serial.println(F("received data smaller than expected, not connected, broken, long wires (reduce speed), bus locked by slave (increase stretch limit)"));
      break;

    case AHTXX_CRC8_ERROR:
      Serial.println(F("computed CRC8 not match received CRC8, this feature supported only by AHT2x sensors"));
      break;

    default:
      Serial.println(F("unknown status"));    
      break;
  }
}

Can anybody see any problems with this code before I try again?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.