#include <Adafruit_HTU21DF.h>
#include <Adafruit_BMP085.h>
#include <Adafruit_MPU6050.h>
#include <SD.h> // sd card library
#include <SPI.h> // SPI communication library between the SD card reader and the Arduino Chip
#include <Wire.h>
Adafruit_MPU6050 accelgyro;
Adafruit_BMP085 bmp;
Adafruit_HTU21DF humidity;
const int chipSelect = 4;
int16_t ax, ay, az; // define acceleration data
int16_t gx, gy, gz; // define gyroscopic data
#define LED_PIN 13
bool blinkState = false;
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
humidity.begin();
bmp.begin();
// initialize devices (GY-87)
Serial.println("Initializing I2C devices...");
// SD Card Initialization
if (SD.begin(chipSelect))
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
// initialize bmp085
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {} }
// initialize HTU21D
if (!humidity.begin()) {
Serial.println("Could not find a valid HTU21D sensor, check wiring!");
while (1) {} }
// initialize mpu6050
accelgyro.initialize();
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
accelgyro.setI2CBypassEnabled(true); // set bypass mode for gateway to hmc5883L
// configure Arduino LED for checking activity
pinMode(LED_PIN, OUTPUT);
double sea_level_altitude = bmp.readSealevelPressure(); // define and read sea level pressure assuming 'standard' barometric pressure of 1013.25 millibar = 101325 Pascal
}
void loop() {
double temp = bmp.readTemperature(); // define and read temperature
double pressure = bmp.readPressure(); // define and read pressure
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // read raw accel/gyro measurements from device
double altitude = bmp.readAltitude(); // define and read altitude
double real_altitude = bmp.readAltitude(101500); // define and read real altitude
double humidity = humidity.readHumidity();
// printing out the temperature
Serial.print("Temperature = ");
Serial.print(temp); Serial.println(" *C ");
//printing out the humidity
Serial.print("Humidity = ");
Serial.print(humidity); Serial.println(" % ");
// printing out the pressure
Serial.print("Pressure = ");
Serial.print(pressure); Serial.println(" Pa ");
// printing out the altitude
Serial.print("Altitude = ");
Serial.print(altitude); Serial.println(" m ");
// printing out the pressure at sea level
Serial.print("Pressure at sealevel (calculated) = ");
Serial.print(sea_level_pressure); Serial.println(" Pa ");
// printing out the 'real' altitude
Serial.print("Real altitude = ");
Serial.print(real_altitude); Serial.println(" m ");
// printing out the acceleration data
Serial.println("Accel: ");
Serial.print("ax: "); Serial.print(ax); Serial.println("g ");
Serial.print("ay: "); Serial.print(ay); Serial.println("g ");
Serial.print("az: "); Serial.print(az); Serial.println("g ");
// printing out the gyroscopic data
Serial.println("Gyro: ");
Serial.print("gx: "); Serial.print(gx); Serial.println(" deg/sec ");
Serial.print("gy: "); Serial.print(gy); Serial.println(" deg/sec ");
Serial.print("gz: "); Serial.print(gz); Serial.println(" deg/sec ");
sdcard_file = SD.open("data.txt", FILE_WRITE);
if (sdcard_file) { // writing the data in the MicroSD card
sdcard_file.print("Temperature = ");
sdcard_file.print(temp); sdcard_file.println(" *C ");
sdcard_file.print("Humidity = ");
sdcard_file.print(humidity); sdcard_file.println(" % ");
sdcard_file.print("Pressure = ");
sdcard_file.print(pressure); sdcard_file.println(" Pa ");
sdcard_file.print("Altitude = ");
sdcard_file.print(altitude); sdcard_file.println(" m ");
sdcard_file.print("Pressure at sealevel (calculated) = ");
sdcard_file.print(sea_level_pressure); sdcard_file.println(" Pa ");
sdcard_file.print("'Real' altitude = ");
sdcard_file.print(real_altitude); sdcard_file.println(" m ");
sdcard_file.println("Acceleration data : ");
sdcard_file.print("ax: "); sdcard_file.println(ax); sdcard_file.println("g ");
sdcard_file.print("ay: "); sdcard_file.println(ay); sdcard_file.println("g ");
sdcard_file.print("az: "); sdcard_file.println(az); sdcard_file.println("g ");
sdcard_file.println("Gyroscopic data: ");
sdcard_file.print("gx: "); sdcard_file.println(gx); sdcard_file.println(" deg/sec ");
sdcard_file.print("gy: "); sdcard_file.println(gy); sdcard_file.println(" deg/sec ");
sdcard_file.print("gz: "); sdcard_file.println(gz); sdcard_file.println(" deg/sec ");
sdcard_file.close(); // close the file
}
else { // if the file didn't open, print an error:
Serial.println("Error opening test.txt");
}
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
delay(2000); // repeat the loop every 2000 milliseconds that is 2 seconds
}
I tried everything to make it work but it didn't. No matter what I did I got: ArduSatLFLV_Code_1:1:10: fatal error: HTU21D.h: No such file or directory compilation terminated. exit status 1 HTU21D.h: No such file or directory
I tried reinstalling the libraries both manually and through the library management thing. Also the SD and SPI libraries work just fine given that they are built in.
The documentation: Installing Libraries | Arduino Documentation | Arduino Documentation
States:
NB: the Library will be available to use in sketches, but with older IDE versions examples for the library will not be exposed in the File > Examples until after the IDE has restarted.
IDE version and OS?
Is the IDE Portable, installed with installer, or from MS Store?
And when "reinstalling" are you sure you have first completely deleted the folder?
And are you sure you haven't multple library copies (installed/copied elsewhere)?
EDIT:
Tried to compile and run the "HTU21DFtest" example sketch? (please note the #include on the example also... The library is note referenced with angle brackets but with double quotes...)
You're compiling for which board? Uno? ESP? What?
IDE version: 1.8.19
OS: Windows 11
I did delete the whole folder when reinstalling the lib
I did try to compile the test files in the libraries but they also did not recognize I2Cdev.h for example, they always had some missing dependencies
I am compiling to an Arduino Mega 2560
I just tried installing the library (from library manager) and the example code compiled like a charm. So, it's something in your system and/or code, I suspect.
But on your latest error report you said it can't find I2CDev (in real world it should be "Adafruit_I2CDevice.h", please always use real and complete names..), what about the first error on "HTU21D.h"? And why "HTU21D.h" and not "Adafriut_HTU21DF.h"? I suspect you have a weird libraries "mix"...
First uninstall the Adafruit libraries (HTU21 requires two more dependency libraries, remove them all) from the library manager, and check if you have any other "HTU*" library installed and remove them also. Then exit the IDE and remove any remaining folder on your entire system (make a full search for "Adafruit*" and "HTU21" over your whole local drives).
Then start the IDE again and install the Adafruit library back, it should prompt you to install the two dependencies also. Now run the example again and see if it works.
If not, I'm sorry but I can't tell you why, it's still something with your sistem and I can't say what, you need to deeply investigate the issue.
PS: you haven't answered to another question I made you: what kind of IDE installation? portable? installer? Microsoft? What?...
#include "Adafruit_MPU6050.h"
#include "Adafruit_HTU21DF.h"
#include "Adafruit_BMP085.h"
#include "Adafruit_I2CDevice.h"
#include <SD.h> // sd card library
#include <SPI.h> // SPI communication library between the SD card reader and the Arduino Chip
#include <Wire.h>
MPU6050 accelgyro;
Adafruit_BMP085 bmp;
HTU21D htu = Adafruit_HTU21DF();
const int chipSelect = 4;
int16_t ax, ay, az; // define acceleration data
int16_t gx, gy, gz; // define gyroscopic data
#define LED_PIN 13
bool blinkState = false;
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
htu.begin();
bmp.begin();
// initialize devices (GY-87)
Serial.println("Initializing I2C devices...");
// SD Card Initialization
if (SD.begin(chipSelect))
{
Serial.println("SD card is ready to use.");
} else
{
Serial.println("SD card initialization failed");
return;
}
// initialize bmp085
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {} }
// initialize HTU21D
if (!htu.begin()) {
Serial.println("Couldn't find HTU21D sensor!");
while (1);
}
// initialize mpu6050
accelgyro.initialize();
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
accelgyro.setI2CBypassEnabled(true); // set bypass mode for gateway to hmc5883L
// configure Arduino LED for checking activity
pinMode(LED_PIN, OUTPUT);
double sea_level_altitude = bmp.readSealevelPressure(); // define and read sea level pressure assuming 'standard' barometric pressure of 1013.25 millibar = 101325 Pascal
}
void loop() {
double temp = bmp.readTemperature(); // define and read temperature
double pressure = bmp.readPressure(); // define and read pressure
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); // read raw accel/gyro measurements from device
double altitude = bmp.readAltitude(); // define and read altitude
double real_altitude = bmp.readAltitude(101500); // define and read real altitude
double humidity = humidity.readHumidity();
// printing out the temperature
Serial.print("Temperature = ");
Serial.print(temp); Serial.println(" *C ");
//printing out the humidity
Serial.print("Humidity = ");
Serial.print(humidity); Serial.println(" % ");
// printing out the pressure
Serial.print("Pressure = ");
Serial.print(pressure); Serial.println(" Pa ");
// printing out the altitude
Serial.print("Altitude = ");
Serial.print(altitude); Serial.println(" m ");
// printing out the pressure at sea level
Serial.print("Pressure at sealevel (calculated) = ");
Serial.print(sea_level_pressure); Serial.println(" Pa ");
// printing out the 'real' altitude
Serial.print("Real altitude = ");
Serial.print(real_altitude); Serial.println(" m ");
// printing out the acceleration data
Serial.println("Accel: ");
Serial.print("ax: "); Serial.print(ax); Serial.println("g ");
Serial.print("ay: "); Serial.print(ay); Serial.println("g ");
Serial.print("az: "); Serial.print(az); Serial.println("g ");
// printing out the gyroscopic data
Serial.println("Gyro: ");
Serial.print("gx: "); Serial.print(gx); Serial.println(" deg/sec ");
Serial.print("gy: "); Serial.print(gy); Serial.println(" deg/sec ");
Serial.print("gz: "); Serial.print(gz); Serial.println(" deg/sec ");
sdcard_file = SD.open("data.txt", FILE_WRITE);
if (sdcard_file) { // writing the data in the MicroSD card
sdcard_file.print("Temperature = ");
sdcard_file.print(temp); sdcard_file.println(" *C ");
sdcard_file.print("Humidity = ");
sdcard_file.print(humidity); sdcard_file.println(" % ");
sdcard_file.print("Pressure = ");
sdcard_file.print(pressure); sdcard_file.println(" Pa ");
sdcard_file.print("Altitude = ");
sdcard_file.print(altitude); sdcard_file.println(" m ");
sdcard_file.print("Pressure at sealevel (calculated) = ");
sdcard_file.print(sea_level_pressure); sdcard_file.println(" Pa ");
sdcard_file.print("'Real' altitude = ");
sdcard_file.print(real_altitude); sdcard_file.println(" m ");
sdcard_file.println("Acceleration data : ");
sdcard_file.print("ax: "); sdcard_file.println(ax); sdcard_file.println("g ");
sdcard_file.print("ay: "); sdcard_file.println(ay); sdcard_file.println("g ");
sdcard_file.print("az: "); sdcard_file.println(az); sdcard_file.println("g ");
sdcard_file.println("Gyroscopic data: ");
sdcard_file.print("gx: "); sdcard_file.println(gx); sdcard_file.println(" deg/sec ");
sdcard_file.print("gy: "); sdcard_file.println(gy); sdcard_file.println(" deg/sec ");
sdcard_file.print("gz: "); sdcard_file.println(gz); sdcard_file.println(" deg/sec ");
sdcard_file.close(); // close the file
} else { // if the file didn't open, print an error:
Serial.println("Error opening test.txt");
}
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
delay(2000); // repeat the loop every 2000 milliseconds (2 seconds)
}
The error message reads:
Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
code:1:10: fatal error: Adafruit_MPU6050.h: No such file or directory
compilation terminated.
exit status 1
Adafruit_MPU6050.h: No such file or directory
If you change their places, it will just give the exact same error but with the library you put in front of it. I am beyond hopeless. This is for a science fair and I will be so screwed if it won't work...
The error is saying the compiler can't find that include header file. If included with double quotes tells the compiler to search the file inside the same folder of the project (on my reply I enclosed some library names between double quotes but just to show the name, I didn't mean you should do that on all libraries), while angle brackets "<" and ">" mean they're inside global libraries folder(s). And I don't know if this library "mix" have something to be taken into consideration and we're missing (as I don't have those devices I can't tell you exactly).
Anyway, first of all, I already asked you this but I can't find your answer: have you tried to compile the "HTU21DFtest" example sketch? If not, please do it now!
And what about the other example codes of the Adafruit libraries?
(Just a doubt: do you see the Adafruit libraries examples under File menu, yes?)
If all Adafruit examples compile without errors, now you could try using those #include lines at the beginning of your code instead of the ones you already have:
#include <Adafruit_MPU6050.h>
#include <Adafruit_HTU21DF.h>
#include <Adafruit_BMP085.h>
#include <SD.h> // sd card library
#include <SPI.h> // SPI communication library between the SD card reader and the Arduino Chip
...
Please note #include <Adafruit_MPU6050.h> already includes "Adafruit_I2CDevice.h" and "Wire.h" (see header code) so it's not necessary to call them again.