I am attempting to write a piece of code to calculate altitude from pressure and temperature recorded on an arduino nano. This is my code:
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp;
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
int temp = 0;
int pressure = 0;
int altitude = 0;
void setup() {
// put your setup code here, to run once:
Serial.println(F("BMP280 Sensor event test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1) delay(10);
}
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500);
bmp_temp->printSensorDetails();
}
void loop() {
// put your main code here, to run repeatedly:
sensors_event_t temp_event, pres_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pres_event);
temp = temp_event.temperature;
pressure = pres_event.pressure;
altitude = (((101.325/ (pressure/1000))^1/5.257)-1)*(temp +273.15))/0.0065;
Serial.print(temp);
Serial.print(",");
Serial.print(pressure)
Serial.print(",");
Serial.print(altitude);
}
I keep on getting the error:
exit status 1
invalid operands of types 'double' and 'double' to binary 'operator^'
How do I go about fixing this? I am new to arduino and C and would appreciate any help Thank you
^is a bitwise XOR logic operator. It works only with integral types.If you want to raise a number to some power, use std::pow() function.