Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. // Read 1 byte from the BMP085 at 'address'
  2. char bmp085Read(unsigned char address)
  3. {
  4. unsigned char data;
  5.  
  6. Wire.beginTransmission(BMP085_ADDRESS);
  7. Wire.write(address);
  8. Wire.endTransmission();
  9.  
  10. Wire.requestFrom(BMP085_ADDRESS, 1);
  11. while(!Wire.available())
  12. ;
  13.  
  14. return Wire.read();
  15. }
  16.  
  17. // Read 2 bytes from the BMP085
  18. // First byte will be from 'address'
  19. // Second byte will be from 'address'+1
  20. int bmp085ReadInt(unsigned char address)
  21. {
  22. unsigned char msb, lsb;
  23.  
  24. Wire.beginTransmission(BMP085_ADDRESS);
  25. Wire.write(address);
  26. Wire.endTransmission();
  27.  
  28. Wire.requestFrom(BMP085_ADDRESS, 2);
  29. while(Wire.available()<2)
  30. ;
  31. msb = Wire.read();
  32. lsb = Wire.read();
  33.  
  34. return (int) msb<<8 | lsb;
  35. }
  36.  
  37. // Read the uncompensated temperature value
  38. unsigned int bmp085ReadUT()
  39. {
  40. unsigned int ut;
  41.  
  42. // Write 0x2E into Register 0xF4
  43. // This requests a temperature reading
  44. Wire.beginTransmission(BMP085_ADDRESS);
  45. Wire.write(0xF4);
  46. Wire.write(0x2E);
  47. Wire.endTransmission();
  48.  
  49. // Wait at least 4.5ms
  50. delay(5);
  51.  
  52. // Read two bytes from registers 0xF6 and 0xF7
  53. ut = bmp085ReadInt(0xF6);
  54. return ut;
  55. }
  56.  
  57. // Read the uncompensated pressure value
  58. unsigned long bmp085ReadUP()
  59. {
  60. unsigned char msb, lsb, xlsb;
  61. unsigned long up = 0;
  62.  
  63. // Write 0x34+(OSS<<6) into register 0xF4
  64. // Request a pressure reading w/ oversampling setting
  65. Wire.beginTransmission(BMP085_ADDRESS);
  66. Wire.write(0xF4);
  67. Wire.write(0x34 + (OSS<<6));
  68. Wire.endTransmission();
  69.  
  70. // Wait for conversion, delay time dependent on OSS
  71. delay(2 + (3<<OSS));
  72.  
  73. // Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
  74. Wire.beginTransmission(BMP085_ADDRESS);
  75. Wire.write(0xF6);
  76. Wire.endTransmission();
  77. Wire.requestFrom(BMP085_ADDRESS, 3);
  78.  
  79. // Wait for data to become available
  80. while(Wire.available() < 3)
  81. ;
  82. msb = Wire.read();
  83. lsb = Wire.read();
  84. xlsb = Wire.read();
  85.  
  86. up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
  87.  
  88. return up;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement