1- /* *****************************************************************************
1+ /*
22 Read all the regigsters of the BME280
33 BME280 Arduino and Teensy example
44 Marshall Taylor @ SparkFun Electronics
1414 This sketch configures the BME280 to read all measurements. The sketch also
1515 displays the BME280's physical memory and what the driver perceives the
1616 calibration words to be.
17-
1817*/
1918
2019#include " Wire.h"
@@ -25,18 +24,17 @@ BME280 mySensor; //Global sensor object
2524void setup ()
2625{
2726 Serial.begin (9600 );
27+ while (!Serial); // Needed for printing correctly when using a Teensy
2828 Serial.println (" Reading all registers from BME280" );
2929
3030 Wire.begin ();
3131
3232 if (mySensor.beginI2C () == false ) // Begin communication over I2C
3333 {
34- Serial.println (" The chip did not respond. Please check wiring." );
34+ Serial.println (" The sensor did not respond. Please check wiring." );
3535 while (1 ); // Freeze
3636 }
3737
38- Serial.print (" Displaying ID, reset and ctrl regs\n " );
39-
4038 Serial.print (" ID(0xD0): " );
4139 printyPrintHex (mySensor.readRegister (BME280_CHIP_ID_REG));
4240
@@ -52,19 +50,21 @@ void setup()
5250 Serial.println ();
5351
5452 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++)
5855 {
5956 Serial.print (" 0x" );
60- Serial.print (rowi , HEX);
57+ Serial.print (row , HEX);
6158 Serial.print (" 0:" );
62- for (int coli = 0 ; coli < 16 ; coli++)
59+
60+ for (byte column = 0 ; column < 16 ; column++)
6361 {
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);
6766 Serial.print (" " );
67+
6868 memCounter++;
6969 }
7070 Serial.println ();
0 commit comments