Το Mercury διαθέτει είτε έναν αισθητήρα πίεσης Bosch BMP390 είτε Bosch BMP581 boreboard.
Αυτό το script σας δείχνει πώς να ανιχνεύσετε ποιον έχετε και να διαβάσετε τη θερμοκρασία και πίεση του και να τις μετατρέψετε σε υψόμετρο.
Η τυπική μετατροπή που χρησιμοποιείται σε αυτό το πρόγραμμα υποθέτει πίεση 1013.25 Hpa (μέση) και περιβαλλοντική θερμοκρασία 15 βαθμών κελσίου.
Εάν βρείτε την πρόγνωση καιρού για τη θέση και την ώρα σας και εισάγετε αυτή την πίεση αντ' αυτής, θα πρέπει να σας εμφανίσει περίπου το ύψος σας πάνω από το επίπεδο της θάλασσας με αυτό το script.
Εάν χρησιμοποιείτε τον online μεταγλωττιστή και uploader, μην ξεχάσετε να συνδέσετε το Serial monitor μετά την επαναφορά (πάτημα κουμπιού power) του Mercury για να δείτε τις πληροφορίες που έρχονται.
// Pressure sensor test example for Mercury altimeters (altimetercloud.com) #include "Wire.h" #include "Mercury_Pins.h" // There are quite a few options for libraries we've chosen these for our example #include "Adafruit_BMP3XX.h" #include "Adafruit_BMP5xx.h" Adafruit_BMP3XX bmp3; Adafruit_BMP5xx bmp5; bool hasBMP581 = false; bool hasBMP390 = false; float seaLevelHpa = 1013.25; // The forecast sea level weather pressure for your location. float ambientTemp = 15.0; // The ambient temperature in degrees celcius void setup() { Serial.begin(115200); // Turn on the power to the sensors on the Mercury altimeter pinMode(VACC, OUTPUT); digitalWrite(VACC, HIGH); delay(100); // Start I2C on the Mercurys SDA and SCL pins Wire.begin(SDA, SCL); // Detect which pressure sensor is present on your Mercury, earlier revisions had a Bosch BMP390 and later revisions (3+) have the Bosch BMP581 if (bmp5.begin(0x47, &Wire)) { hasBMP581 = true; Serial.println("BMP581 found"); } else if (bmp3.begin_I2C(0x77, &Wire)) { hasBMP390 = true; Serial.println("BMP390 found"); } else { Serial.println("No sensor found!"); } } void loop() { float temp = 0, pressure = 0, alt = 0; // Read the detected sensor for it's pressure and temperature if (hasBMP581 && bmp5.performReading()) { temp = bmp5.temperature; pressure = bmp5.pressure; } else if (hasBMP390 && bmp3.performReading()) { temp = bmp3.temperature; pressure = bmp3.pressure / 100.0; } else { delay(500); return; } // Convert the pressure to altitude using the standard international standard using sea level forecast pressure and ambient temperature. alt = ((ambientTemp + 273.15) / 0.0065) * (1.0 - pow(pressure / seaLevelHpa, 0.190266669)); Serial.printf("Temp: %.1fC Pressure: %.2f hPa Alt: %.1f m\n", temp, pressure, alt); delay(500); }#pragma once /* * Mercury (ESP32-C6) Pin Definitions * Board-specific GPIO assignments */ // ── Status LED (NeoPixel) ── #define LEDPOWER 3 // NeoPixel power (drive HIGH to enable) #define LED 2 // NeoPixel data signal // ── I2C Bus ── #define SDA 21 // I2C data #define SCL 22 // I2C clock // ── Sensor Power ── #define VACC 20 // Sensor power rail (drive HIGH to enable) // ── General Purpose Ports ── #define GP06 6 // GP06 port #define GP07 7 // GP07 port // ── High Current Output ── #define OUT1 5 // High current output (e.g. pyro / relay) // ── Battery Bar LEDs ── #define BL1 4 // Battery LED 1 (lowest) #define BL2 14 // Battery LED 2 #define BL3 15 // Battery LED 3 #define BL4 18 // Battery LED 4 #define BL5 19 // Battery LED 5 (highest) // ── Indicators ── #define DISK 8 // Disk activity LED // ── Analogue / Detection ── #define BATIN 0 // Battery voltage (1:1 divider) #define USBDETECT 1 // USB power detect (HIGH = USB present) #define BUTTON 9 // BUTTON on the board, boot button but can be used