Need help determining a problem with the air pressure sensor in the Arduino sensor kit base. The altitude read out on the OLED display shows 44330.76m. I have two of these sensor kits and both display the same. All other sensors are functioning properly.
Thanks for the quick reply. It’s not a project, just playing with the Arduino Sensor Kit. This kit has a host of sensors and actuators(temp/humidity, light, sound, acceleration, air pressure, OLED, buzzer, LED, etc) made by Arduino. In the Arduino IDE I’m using File-examples-Arduino_Sensorkit-Combined_Demo coding. The 44330.76m appears to be a coding problem as both kits have the same 44330.76m and I’m not sitting at 145,442 feet, lol. I’ve installed the Arduino_Sensorkit library for the code.
It probably needs to be calibrated, whatever it is reading, you have to terll it that represents your altitude.
I see the library with examples here... GitHub - arduino-libraries/Arduino_SensorKit · GitHub
And the "Combined Demo" here... Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino at main · arduino-libraries/Arduino_SensorKit · GitHub
That "Combined Demo" code is here...
// Combined Demo by Marc MERLIN <marc_soft@merlins.org>
// Reviewed by Pablo Marquínez <p.marquinez@arduino.cc>
// This demo uses all the devices from the Arduino Sensor Kit
// Showing the values on the Display
#include "Arduino_SensorKit.h"
// Uncomment line below if your SensorKit is the variant with the DHT20 sensor
// (It's marked IIC on the PCB and has a black cover, while the DHT11 sensor
// has a blue cover.)
//#define Environment Environment_I2C
#define BUZZER 5
#define BUTTON 4
#define LED 6
#define POT A0
#define MIC A2
#define LIGHT A3
int pot_value;
bool button_state;
int mic_value;
int light_value;
void setup() {
Serial.begin(9600);
pinMode(MIC , INPUT);
pinMode(LIGHT , INPUT);
pinMode(BUTTON , INPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(BUZZER, OUTPUT);
Environment.begin();
Oled.begin();
Oled.setFlipMode(true);
Accelerometer.begin();
Pressure.begin();
}
void loop() {
Oled.setFont(u8x8_font_amstrad_cpc_extended_r);
//cursor values are in characters, not pixels
Oled.setCursor(0, 4);
// If accelerometer and altimeter are queried too close to one another
// this causes a hang, so we read this first.
Oled.print("x:");
Oled.print(Accelerometer.readX());
Oled.print(" y:");
Oled.print(Accelerometer.readY());
Oled.setCursor(0, 5);
Oled.print("z:");
Oled.print(Accelerometer.readZ());
Oled.print(" T:");
Oled.print(Environment.readTemperature());
Oled.print("C");
Oled.setCursor(0, 0);
Oled.print("But:");
pot_value = analogRead(POT);
button_state = digitalRead(BUTTON);
Oled.print(button_state);
if (button_state == true) {
digitalWrite(LED, HIGH);
tone(BUZZER, pot_value);
} else {
digitalWrite(LED, LOW);
noTone(BUZZER);
}
Oled.setCursor(0, 1);
Oled.print("BuzPot: ");
Oled.print(pot_value);
Oled.print("Hz ");
mic_value = analogRead(MIC);
Oled.setCursor(0, 2);
Oled.print("Mic: ");
Oled.print(mic_value);
Oled.print(" ");
light_value = analogRead(LIGHT);
Oled.setCursor(0, 3);
Oled.print("Light: ");
Oled.print(light_value);
Oled.print(" ");
Oled.setCursor(0, 6);
Oled.print("Hum: ");
Oled.print(Environment.readHumidity());
Oled.print("%");
Oled.setCursor(0, 7);
Oled.print("Alt:");
Oled.print(Pressure.readAltitude());
delay(100);
}
HOWEVER; the library (first link in my post) points you to here... GitHub - Seeed-Studio/Grove_BMP280 · GitHub
Which then says about the BMP280...
, for the formula to work properly, you must update the mean sea-level pressure. See the updated
calcAltitude()function and example
The kit: Arduino Sensor Kit – Base – Learn Electronics with Pre-Wired Grove Modules — Arduino Official Store
The bundle:Arduino Sensor Kit Bundle – Best-Selling Grove Sensors with UNO — Arduino Official Store
The sensors in the kit: https://sensorkit.arduino.cc/
Yep, that’s it. I’ve uncommented “//#define Environment Environment_I2C” otherwise the DHT20 sensor won’t return readings to the OLED. I’m brand new at this(checks watch). Have no idea how and where to calibrate the sensor. ( See the updated calcAltitude() function and example. (@Kongduino)). ??? I very much appreciate your help.
Yes, uncommenting that line is telling the code that the OLED (an I2C device) will be used, and probably as a display of your values. Very good start.
There seems to be a problem between the original code for the BMP280 and the Sensor Kit.
The original allows MSL to be edited, the Sensor Kit does not have that variable, but has a "magic number" (which is considered poor programming).
In this link (the first link in my previous post): GitHub - arduino-libraries/Arduino_SensorKit · GitHub
Click on the "examples" folder... Arduino_SensorKit/examples at main · arduino-libraries/Arduino_SensorKit · GitHub
Follow this link: Grove_BMP280 Library for the Barometer
To here: GitHub - Seeed-Studio/Grove_BMP280 · GitHub
Then, the "bmp280_example.ino" to here: Grove_BMP280/examples/bmp280_example/bmp280_example.ino at master · Seeed-Studio/Grove_BMP280 · GitHub
Inside that file, you will see "MSL" and this line:
uint32_t MSL = 102009; // Mean Sea Level in Pa
Now... that I have you confused (sorry, hope not)... go back to the Sensor Kit BMP280 example.... On, about, line 75, you see this function... SEE NEXT POST
float BMP280::calcAltitude(float pressure)
{
float A = pressure/101325;
float B = 1/5.25588;
float C = pow(A,B);
C = 1.0 - C;
C = C /0.0000225577;
return C;
}
See the number "101325"? That seems to be "about" the same as the "MSL" number from the "original" BMP280 example.
So... find your local, real, MSL and put it in the calcAltitude() function found in the Sensor Kit examples. Please, make a variable for this number, probably as MSL or msl so you understand it when you dig into the code again.
It was a mess for me to find, because I had to understand the "magic numbers" used in the calcAltitude() function... to find those I went to the original BMP280 example, where they gave an explanation.
Take it step by step... ask any question...
And... maybe @pert has a way for you to report that a very important "MSL" variable is missing in the Sensor Kit BMP280 example sketch
I also found this function in here (Seeed_BMP280.cpp) of the Sensor Kit: Arduino_SensorKit/src/Grove_-_Barometer_Sensor_BMP280/Seeed_BMP280.cpp at main · arduino-libraries/Arduino_SensorKit · GitHub
But... I do not want to mess up what I wrote in my previous post... so here is that same function:
float BMP280::calcAltitude(float pressure)
{
float A = pressure/101325;
float B = 1/5.25588;
float C = pow(A,B);
C = 1.0 - C;
C = C /0.0000225577;
return C;
}
What are the chances that two of these sensors would give the exact same value, especially before being calibrated, and show such a high altitude figure?
I suspect there is some problem reading the sensor, and the Arduino is getting an invalid reading such as all bits set to 1, which results in the same crazy altitude figure.
This invalid reading could be caused by a wiring problem or faulty sensors or...
Did you use same wire to test both sensors? Try another wire.
Ok, it’s getting late here and my brain is cramping. I’ll start on your posts tomorrow. Thanks so much for your help. I’ll keep you posted.
You will be editing the line in the calcAltitude() in the function in the "Sensor Kit BMP280 "CPP" file" to the correct MSL (in mm) for your location.
You can submit a pull request to the library repository that proposes the change to the library code:
If you don't want to contribute the code changes yourself, alternatively, you can submit an issue to the repository to request that someone else make the change:
The last photo is of the serial monitor when I run the sensor as a stand alone detached from the sensor kit board using: (File-Examples-Arduino_SensorKit-Pressure_Sensor) code. Note that both temp and pressure are both zero. Both are needed to calculate an altitude.
The official sensor kit page says the latest version of the kit replaces the BMP280 with a Infineon DPS310. So, @wclarke , can you tell us which sensor your kit actually has?
(Welcome to the Forum, by the way!)
I am retracting most of what I wrote, above (except for the need for local MSL). The value 101325 is a standard atmosphere in millibars.
Look for what @PaulRB mentioned. The zeroes in the output are telling.
I’m sorry you did all that work trying to help me. I didn’t know the sensor was outputting zeros in both temp and pressure till I detached it from the main board and ran it as a stand alone. Well, we can’t calibrate zeros so I think that’s the problem. I know the I2C address is good because when I unhook it from the UNO the serial monitor is blank. Another fellow points to changing between two air pressure sensors in this kit, the BMP280 to the Infineon DSP310. Again, sorry you did all that work, I did learn a lot from your posts.
Get a macro shot with oblique/raking light of the silver thing with a hole in it. That is the device.
That's the fun part. I like to explore my unknown.









