1
- /* *****************************************************************************
1
+ /*
2
2
Read all the regigsters of the BME280
3
3
BME280 Arduino and Teensy example
4
4
Marshall Taylor @ SparkFun Electronics
14
14
This sketch configures the BME280 to read all measurements. The sketch also
15
15
displays the BME280's physical memory and what the driver perceives the
16
16
calibration words to be.
17
-
18
17
*/
19
18
20
19
#include " Wire.h"
@@ -25,18 +24,17 @@ BME280 mySensor; //Global sensor object
25
24
void setup ()
26
25
{
27
26
Serial.begin (9600 );
27
+ while (!Serial); // Needed for printing correctly when using a Teensy
28
28
Serial.println (" Reading all registers from BME280" );
29
29
30
30
Wire.begin ();
31
31
32
32
if (mySensor.beginI2C () == false ) // Begin communication over I2C
33
33
{
34
- Serial.println (" The chip did not respond. Please check wiring." );
34
+ Serial.println (" The sensor did not respond. Please check wiring." );
35
35
while (1 ); // Freeze
36
36
}
37
37
38
- Serial.print (" Displaying ID, reset and ctrl regs\n " );
39
-
40
38
Serial.print (" ID(0xD0): " );
41
39
printyPrintHex (mySensor.readRegister (BME280_CHIP_ID_REG));
42
40
@@ -52,19 +50,21 @@ void setup()
52
50
Serial.println ();
53
51
54
52
Serial.println (" Displaying all regs:" );
55
- uint8_t memCounter = 0x80 ;
56
- uint8_t tempReadData;
57
- for (int rowi = 8 ; rowi < 16 ; rowi++)
53
+ byte memCounter = 0x80 ;
54
+ for (byte row = 8 ; row < 16 ; row++)
58
55
{
59
56
Serial.print (" 0x" );
60
- Serial.print (rowi , HEX);
57
+ Serial.print (row , HEX);
61
58
Serial.print (" 0:" );
62
- for (int coli = 0 ; coli < 16 ; coli++)
59
+
60
+ for (byte column = 0 ; column < 16 ; column++)
63
61
{
64
- tempReadData = mySensor.readRegister (memCounter);
65
- Serial.print ((tempReadData >> 4 ) & 0x0F , HEX);// Print first hex nibble
66
- Serial.print (tempReadData & 0x0F , HEX);// Print second hex nibble
62
+ byte tempReadData = mySensor.readRegister (memCounter);
63
+
64
+ if (tempReadData < 0x10 ) Serial.print (" 0" );
65
+ Serial.print (tempReadData, HEX);
67
66
Serial.print (" " );
67
+
68
68
memCounter++;
69
69
}
70
70
Serial.println ();
0 commit comments