WIRELESSLY LOGGING DATA USING WITTY FOX SI7021
In this tutorial, we will see how to interface the Witty Fox Si7021 breakout board with the Witty Fox Storm Board. The Si7021 is a humidity and temperature sensor. The Si7021 I2C sensor is a monolithic CMOS IC integrating humidity and temperature sensor elements, an analog-to-digital converter, signal processing, calibration data, and an I2C Interface. The Si7021 breakout is directly compatible with the Witty Fox ESP 32 Dev Board through the dedicated I2C ports P9 or P10.
We will use the wireless logging feature built into the WFStorm library to read the humidity and temperature readings wirelessly from the Storm Board, and the wireless OTA functionality to upload code to our Storm Board. You can check out our previous tutorial on uploading code to the Storm Board wirelessly.
Now coming to the steps, plug in your Witty Fox board into the I2C header which is located right next to the programming header.
In order to use/read data from the Si7021 module, install the Adafruit Si7021 library using the Library Manager in the Arduino IDE.
Ensure you have installed the latest WFStorm library. The wireless logging feature has been added recently, so ensure you reinstall the updated library. You can install the Witty Fox Storm library from our Github Repository. Download the repository as a 'zip' file. In your Arduino IDE, go to Sketch > Include Library > Add .ZIP library. Once you install the updated WFStorm library, you can go to examples and open the Si7021WirelessLogging example. We will explain the code in detail to understand what each section does.
This section contains the include directives for the needed libraries and the global variables, and it creates an Adafruit sensor object. We shall use this object to read data from the Si7021 module.
Next, we have the setup function where we enable logging in to the Witty Fox WFStorm library. We then configure the OTA. This has been explained in detail in our Wireless programming with Witty Fox Storm Board blog.
Once this is done, we set the logging mode to log on both the serial interface and on WiFi.
Next is a snippet taken directly from the Adafruit Si7021 library example. It initializes the sensor and prints information about it.
Since we don't need this information on the wireless logs, we can let the Serial.print statements as it is, and not change them to wfLog functions.
Next is the 'Loop' function where we use the Adafruit sensor object to read data from the Si7021 sensor, and we log it using the wfLog functions to ensure it's logged both on serial as well as WiFi, as per our configuration in the setup function above.
The final block is a while loop which calls the wfHandleOTA function in a loop with 10ms delay. This is to ensure that the Storm Board is always listening to OTA invites from the Arduino IDE, to allow us to upload code to it wirelessly. The below code block will ensure that one reading is taken from the sensor every 3 seconds and logged on both serial interface and WiFi.
Ensure your computer is connected to the Storm32 AP. Then go to Tools and select the ESP32 network port. Once you upload this code to your Storm Board, connect your phone to the Storm32 network and use any TCP client app to listen to the wireless logs. One of the apps that you can try is TCP Telnet Terminal.
This concludes the tutorial on reading data from the Si7021 module and logging it wirelessly. You can use this to build your own automated weather reporting system.
For a better understanding, watch a step by step video tutorial:
Feel free to come up with other cool ideas and do share them with us. Comment below if you get stuck or have any further questions.