久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3505|回復: 1
打印 上一主題 下一主題
收起左側

GY68BMP180氣壓模塊Arduino的源程序分享

[復制鏈接]
跳轉到指定樓層
樓主
ID:286851 發表于 2018-3-7 14:14 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
分享 GY68BMP180 氣壓模塊   Arduino 的例程序

  1. //Arduino 1.0+ Only
  2. //Arduino 1.0+ Only

  3. /*Based largely on code by  Jim Lindblom

  4. Get pressure, altitude, and temperature from the BMP085.
  5. Serial.print it out at 9600 baud to serial monitor.
  6. */

  7. #include <Wire.h>

  8. #define BMP085_ADDRESS 0x77  // I2C address of BMP085

  9. const unsigned char OSS = 0;  // Oversampling Setting

  10. // Calibration values
  11. int ac1;
  12. int ac2;
  13. int ac3;
  14. unsigned int ac4;
  15. unsigned int ac5;
  16. unsigned int ac6;
  17. int b1;
  18. int b2;
  19. int mb;
  20. int mc;
  21. int md;

  22. // b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
  23. // so ...Temperature(...) must be called before ...Pressure(...).
  24. long b5;

  25. void setup(){
  26.   Serial.begin(9600);
  27.   Wire.begin();

  28.   bmp085Calibration();
  29. }

  30. void loop()
  31. {
  32.   float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
  33.   float pressure = bmp085GetPressure(bmp085ReadUP());
  34.   float atm = pressure / 101325; // "standard atmosphere"
  35.   float altitude = calcAltitude(pressure); //Uncompensated caculation - in Meters

  36.   Serial.print("Temperature: ");
  37.   Serial.print(temperature, 2); //display 2 decimal places
  38.   Serial.println("deg C");

  39.   Serial.print("Pressure: ");
  40.   Serial.print(pressure, 0); //whole number only.
  41.   Serial.println(" Pa");

  42.   Serial.print("Standard Atmosphere: ");
  43.   Serial.println(atm, 4); //display 4 decimal places

  44.   Serial.print("Altitude: ");
  45.   Serial.print(altitude, 2); //display 2 decimal places
  46.   Serial.println(" M");

  47.   Serial.println();//line break

  48.   delay(1000); //wait a second and get values again.
  49. }

  50. // Stores all of the bmp085's calibration values into global variables
  51. // Calibration values are required to calculate temp and pressure
  52. // This function should be called at the beginning of the program
  53. void bmp085Calibration()
  54. {
  55.   ac1 = bmp085ReadInt(0xAA);
  56.   ac2 = bmp085ReadInt(0xAC);
  57.   ac3 = bmp085ReadInt(0xAE);
  58.   ac4 = bmp085ReadInt(0xB0);
  59.   ac5 = bmp085ReadInt(0xB2);
  60.   ac6 = bmp085ReadInt(0xB4);
  61.   b1 = bmp085ReadInt(0xB6);
  62.   b2 = bmp085ReadInt(0xB8);
  63.   mb = bmp085ReadInt(0xBA);
  64.   mc = bmp085ReadInt(0xBC);
  65.   md = bmp085ReadInt(0xBE);
  66. }

  67. // Calculate temperature in deg C
  68. float bmp085GetTemperature(unsigned int ut){
  69.   long x1, x2;

  70.   x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
  71.   x2 = ((long)mc << 11)/(x1 + md);
  72.   b5 = x1 + x2;

  73.   float temp = ((b5 + 8)>>4);
  74.   temp = temp /10;

  75.   return temp;
  76. }

  77. // Calculate pressure given up
  78. // calibration values must be known
  79. // b5 is also required so bmp085GetTemperature(...) must be called first.
  80. // Value returned will be pressure in units of Pa.
  81. long bmp085GetPressure(unsigned long up){
  82.   long x1, x2, x3, b3, b6, p;
  83.   unsigned long b4, b7;

  84.   b6 = b5 - 4000;
  85.   // Calculate B3
  86.   x1 = (b2 * (b6 * b6)>>12)>>11;
  87.   x2 = (ac2 * b6)>>11;
  88.   x3 = x1 + x2;
  89.   b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;

  90.   // Calculate B4
  91.   x1 = (ac3 * b6)>>13;
  92.   x2 = (b1 * ((b6 * b6)>>12))>>16;
  93.   x3 = ((x1 + x2) + 2)>>2;
  94.   b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;

  95.   b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  96.   if (b7 < 0x80000000)
  97.     p = (b7<<1)/b4;
  98.   else
  99.     p = (b7/b4)<<1;

  100.   x1 = (p>>8) * (p>>8);
  101.   x1 = (x1 * 3038)>>16;
  102.   x2 = (-7357 * p)>>16;
  103.   p += (x1 + x2 + 3791)>>4;

  104.   long temp = p;
  105.   return temp;
  106. }

  107. // Read 1 byte from the BMP085 at 'address'
  108. char bmp085Read(unsigned char address)
  109. {
  110.   unsigned char data;

  111.   Wire.beginTransmission(BMP085_ADDRESS);
  112.   Wire.write(address);
  113.   Wire.endTransmission();

  114.   Wire.requestFrom(BMP085_ADDRESS, 1);
  115.   while(!Wire.available())
  116.     ;

  117.   return Wire.read();
  118. }

  119. // Read 2 bytes from the BMP085
  120. // First byte will be from 'address'
  121. // Second byte will be from 'address'+1
  122. int bmp085ReadInt(unsigned char address)
  123. {
  124.   unsigned char msb, lsb;

  125.   Wire.beginTransmission(BMP085_ADDRESS);
  126.   Wire.write(address);
  127.   Wire.endTransmission();

  128.   Wire.requestFrom(BMP085_ADDRESS, 2);
  129.   while(Wire.available()<2)
  130.     ;
  131.   msb = Wire.read();
  132.   lsb = Wire.read();

  133.   return (int) msb<<8 | lsb;
  134. }

  135. // Read the uncompensated temperature value
  136. unsigned int bmp085ReadUT(){
  137.   unsigned int ut;

  138.   // Write 0x2E into Register 0xF4
  139.   // This requests a temperature reading
  140.   Wire.beginTransmission(BMP085_ADDRESS);
  141.   Wire.write(0xF4);
  142.   Wire.write(0x2E);
  143.   Wire.endTransmission();

  144.   // Wait at least 4.5ms
  145.   delay(5);

  146.   // Read two bytes from registers 0xF6 and 0xF7
  147.   ut = bmp085ReadInt(0xF6);
  148.   return ut;
  149. }

  150. // Read the uncompensated pressure value
  151. unsigned long bmp085ReadUP(){

  152.   unsigned char msb, lsb, xlsb;
  153.   unsigned long up = 0;

  154.   // Write 0x34+(OSS<<6) into register 0xF4
  155.   // Request a pressure reading w/ oversampling setting
  156.   Wire.beginTransmission(BMP085_ADDRESS);
  157.   Wire.write(0xF4);
  158.   Wire.write(0x34 + (OSS<<6));
  159.   Wire.endTransmission();

  160.   // Wait for conversion, delay time dependent on OSS
  161.   delay(2 + (3<<OSS));

  162.   // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  163.   msb = bmp085Read(0xF6);
  164.   lsb = bmp085Read(0xF7);
  165.   xlsb = bmp085Read(0xF8);

  166.   up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);

  167.   return up;
  168. }

  169. void writeRegister(int deviceAddress, byte address, byte val) {
  170.   Wire.beginTransmission(deviceAddress); // start transmission to device
  171.   Wire.write(address);       // send register address
  172.   Wire.write(val);         // send value to write
  173.   Wire.endTransmission();     // end transmission
  174. }

  175. int readRegister(int deviceAddress, byte address){

  176.   int v;
  177.   Wire.beginTransmission(deviceAddress);
  178.   Wire.write(address); // register to read
  179.   Wire.endTransmission();

  180.   Wire.requestFrom(deviceAddress, 1); // read a byte

  181.   while(!Wire.available()) {
  182.     // waiting
  183.   }

  184.   v = Wire.read();
  185.   return v;
  186. }

  187. float calcAltitude(float pressure){

  188.   float A = pressure/101325;
  189.   float B = 1/5.25588;
  190.   float C = pow(A,B);
  191.   C = 1 - C;
  192.   C = C /0.0000225577;

  193.   return C;
  194. }
復制代碼

所有資料51hei提供下載:
bmp085_arduino.rar (2.25 KB, 下載次數: 18)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:310897 發表于 2018-4-18 14:55 | 只看該作者
感謝樓主分享!
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 热久久久| 成人av一区 | 欧美人妇做爰xxxⅹ性高电影 | 国产成人免费视频网站高清观看视频 | 福利视频一区二区 | 欧美精品在线一区二区三区 | 欧美一区二区三区在线视频 | 亚洲欧洲精品成人久久奇米网 | 91丨九色丨国产在线 | 日韩欧美网 | 亚洲 日本 欧美 中文幕 | 久久久久久久久久影视 | 成人精品一区二区 | 天天干天天草 | 中文字字幕一区二区三区四区五区 | 免费视频一区二区 | xxxcom在线观看 | 精品视频久久久久久 | 91精品一区 | 成人久久18免费网站图片 | 精品欧美一区二区三区精品久久 | 国产精品久久av | 人人玩人人干 | 日韩在线资源 | 成人1区2区 | 欧美日本韩国一区二区 | 亚洲区一区二 | 一区二区av | 亚洲福利视频网 | 成人黄色电影在线播放 | 色婷婷综合成人av | 精品欧美视频 | www.99精品| 精品三区 | 国产日韩精品视频 | 大久| 国产视频在线一区二区 | 久久精点视频 | 九九看片 | 91精品免费视频 | 成年人黄色小视频 |