Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1993 - 1
// BMP085_output
2
// by Filipe Vieira
3
// Simple example of library usage with almost every BMP085 and lib features being used.
4
 
5
#include <Wire.h>
6
#include <BMP085.h>
7
 
8
BMP085 dps = BMP085();
9
long Temperature = 0, Pressure = 0, Altitude = 0;
10
 
11
void setup(void) {
12
  Serial.begin(9600);
13
  Wire.begin();
14
  delay(1000);
15
 
16
  dps.init();
17
 
18
  showall();
19
 
20
  Serial.println("Registers dump");
21
  Serial.println("==========================================================");
22
  dumpRegisters();
23
  Serial.println("Calibration data");
24
  Serial.println("==========================================================");
25
  dps.dumpCalData();
26
 
27
  delay(5000);
28
}
29
 
30
 
31
void loop(void) {
32
  dps.getTemperature(&Temperature);
33
  dps.getPressure(&Pressure);
34
  dps.getAltitude(&Altitude);
35
 
36
  Serial.print("Temp(C):");
37
  Serial.print(Temperature);
38
  Serial.print("  Alt(cm):");
39
  Serial.print(Altitude);
40
  Serial.print("  Pressure(Pa):");
41
  Serial.println(Pressure);
42
}
43
 
44
void showall(void) {
45
  Serial.println("Current BMP085 settings");
46
  Serial.println("==========================================================");
47
  Serial.print("device address                  = 0x");
48
  Serial.println(dps.getDevAddr(), HEX);
49
  Serial.print("Mode                            = ");
50
  switch (dps.getMode()) {
51
    case MODE_ULTRA_LOW_POWER:
52
      Serial.println("MODE_ULTRA_LOW_POWER");
53
      break;
54
    case MODE_STANDARD:
55
      Serial.println("MODE_STANDARD");
56
      break;
57
    case MODE_HIGHRES:
58
      Serial.println("MODE_HIGHRES");
59
      break;
60
    case MODE_ULTRA_HIGHRES:
61
      Serial.println("MODE_ULTRA_HIGHRES");
62
      break;
63
  }
64
}
65
 
66
void dumpRegisters() {
67
  byte ValidRegisterAddr[]={0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF,0xF6,0xF7,0xF8,0xF9};
68
  byte _b, i, totregisters = sizeof(ValidRegisterAddr);
69
  Serial.println("---dump start---");
70
  Serial.println("Register address|Register data");
71
  Serial.println("Reg.address(hex,dec) Reg.data(bin,hex,dec)");
72
  for (i=0;i<totregisters;i++){
73
    Serial.print("0x");
74
    Serial.print(ValidRegisterAddr[i], HEX);
75
    Serial.print(",");
76
    Serial.print(ValidRegisterAddr[i], DEC);
77
    Serial.print(",");
78
    dps.readmem(ValidRegisterAddr[i], 1, &_b);
79
    Serial.print("b");
80
    print_bits(_b);
81
    Serial.print(",0x");
82
    Serial.print(_b,HEX);
83
    Serial.print(",");
84
    Serial.println(_b,DEC);
85
  }
86
  Serial.println("---dump end---");
87
}
88
 
89
void print_bits(byte val){
90
  int i;
91
  for(i=7; i>=0; i--)
92
    Serial.print(val >> i & 1, BIN);
93
}
94
/* void print_unit16(uint16_t val){
95
  int i;
96
  for(i=15; i>=0; i--)
97
    Serial.print(val >> i & 1, BIN);
98
}
99
*/