Arduino溫度氣壓傳感器模組 BMP180 (GY68)資料備份
Arduino溫度氣壓傳感器模組 BMP180 (GY68)資料備份
資料來源: https://atceiling.blogspot.com/2019/09/arduino70-bmp180-gy68.html
GITHUB: https://github.com/jash-git/Jash-good-idea-20220201-001/tree/main/20220214%E8%B3%87%E6%96%99%E6%94%B6%E8%97%8F
元件實體圖
Code
#include <SFE_BMP180.h> #include <Wire.h> SFE_BMP180 pressure; // 建立一個物件名為 pressure #define ALTITUDE 25 // 台灣西部海岸大約的海平面高度 void setup() { Serial.begin(9600); Serial.println("REBOOT"); // 初始設定 if (pressure.begin()) Serial.println("BMP180 init success"); else { // 初始化錯誤,一般是連接問題 Serial.println("BMP180 init fail\n\n"); while(1); // 永久停在這裡 } } void loop() { char status; double T,P,p0,a; // 每 10秒鐘偵測一次 // If you want sea-level-compensated pressure, as used in weather reports, // you will need to know the altitude at which your measurements are taken. // We're using a constant called ALTITUDE in this sketch: Serial.println(); Serial.print("provided altitude: "); Serial.print(ALTITUDE,0); Serial.print(" meters, "); Serial.print(ALTITUDE*3.28084,0); Serial.println(" feet"); // 如果要測量高度,而不是壓力,就需要提供已知的基本壓力 // 取得溫度量測值 // Start a temperature measurement: // If request is successful, the number of ms to wait is returned. // If request is unsuccessful, 0 is returned. status = pressure.startTemperature(); if (status != 0) { // 等待感測完成 delay(status); // 取得完整溫度測量,感測值存在變數T,函數回傳 1表示成功,0表示失敗 status = pressure.getTemperature(T); if (status != 0) { // 顯示感測值 Serial.print("temperature: "); Serial.print(T,2); Serial.print(" .C, "); Serial.print((9.0/5.0)*T+32.0,2); Serial.println(" .F"); // 量測壓力 // 參數設定從 0 到 3 (最高的解析度,等待較久) // 感測成功會傳回等待多少 ms,如果不成功會傳回 0 status = pressure.startPressure(3); if (status != 0) { // 等待感測完成 delay(status); // 取得完整的壓力感測值,感測值存在變數 P,這個函數需要先前取得的溫度 T // 假使溫度變化不大,可以只取得一次的值即可,函數執行成功會傳回 1,失敗傳回 0 status = pressure.getPressure(P,T); if (status != 0) { // 列出感測值 Serial.print("absolute pressure: "); Serial.print(P,2); Serial.print(" mb, "); Serial.print(P*0.0295333727,2); Serial.println(" inHg"); // 壓力感測值傳回絕對壓力,會隨著高度而變化,要移除高度的影響,需使用 sealevel 函數在目前的高度, // 這個數字常被用在氣象報告中,參數 P = 絕對壓力(毫巴), 高度 = 目前高度(公尺/米). // 傳回值 p0 = sealevel函數的補償壓力(毫巴) p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO) Serial.print("relative (sea-level) pressure: "); Serial.print(p0,2); Serial.print(" mb, "); Serial.print(p0*0.0295333727,2); Serial.println(" inHg"); // 如果要從壓力感測值得知高度,需使用高度函數 altitude,以及先言算出的基準壓力. // 參數 P = 絕對壓力(毫巴), p0 = 基準壓力(毫巴). 傳回值 a = 高度(公尺/米) a = pressure.altitude(P,p0); Serial.print("computed altitude: "); Serial.print(a,0); Serial.print(" meters, "); Serial.print(a*3.28084,0); Serial.println(" feet"); } else Serial.println("error retrieving pressure measurement\n"); } else Serial.println("error starting pressure measurement\n"); } else Serial.println("error retrieving temperature measurement\n"); } else Serial.println("error starting temperature measurement\n"); delay(5000); // 暫停5秒 }
3 thoughts on “Arduino溫度氣壓傳感器模組 BMP180 (GY68)資料備份”
https://atceiling.blogspot.com/2019/09/arduino70-bmp180-gy68.html
https://www.puhy.cz/dokumentace/datove_listy/datovylist_308550-1-m467.pdf [gy-68 bmp180 datasheet]
https://stackoverflow.com/questions/42022000/which-pins-should-i-take-for-i2c-on-arduino-uno/42022566 / https://www.hackster.io/akshayjoseph666/interface-i2c-16×2-lcd-with-arduino-uno-just-4-wires-273b24 [arduino uno sda scl 接角]
[材料]
• Arduino Uno x 1
• GY-68 BMP180
• 連接線 x 4條
[接線與電路圖]
UNO BMP180(GY-68)
3V(VCC) VCC
GND GND
A4(SDA) SDA
A5(SDL) SDL
http://programmermagazine.github.io/201311/htm/article1.html
今天我們要介紹怎麼讓多台 Arduino 互相通訊。我們所用的通訊協定是 I2C Protocol,I2C 只需要兩支腳位就可以讓設備建立通訊,這兩支腳位一個叫作 SDA (Serial DAta line),另一個叫作 SCL (Serial CLock Line)。
Arduino UNO 板子上,SDA 是在 analog pin 4,而 SCL 是在 analog pin 5
單晶片中UART、I2C、SPI三介面基本介紹
https://makerpro.cc/2016/07/learning-interfaces-about-uart-i2c-spi/