I get the value of symbols like "#" "$" "!" ect. with bmp280 with hardware SPI.

I Have a BMP280 wired up to my Arduino micro like shown in the attachments. When I upload the following code I sometimes get a “#”, “$”, “!”, or whatever symbol it may be, but I don’t know why.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_BMP280.h>

#define BMP_CS (4)

Adafruit_BMP280 bmp(BMP_CS);

void setup() {
  Serial.begin(9600);

  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
  }

  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
                  Adafruit_BMP280::SAMPLING_X2,
                  Adafruit_BMP280::SAMPLING_X16,
                  Adafruit_BMP280::FILTER_X16,
                  Adafruit_BMP280::STANDBY_MS_500);
}

void loop() {
  Serial.write("A=");
  Serial.write(bmp.readAltitude(1013.25));
  Serial.write("\n");

  delay(500);

}

I’m kind of new to this but if I were to take a guess I’d think it’s some sort of way of saying something could be wrong with wiring or something like that, though I don’t have any evidence for that. I have also tried wiring up the bmp280 with i2c and software SPI but they did not work either.

If by 'I sometimes get' you mean what appears in the Serial monitor, then you might want to check the Arduino reference for Serial.Write, just to make sure your using it correctly.

Replace the Serial.write() with Serial.print() or Serial.println() and it will work a lot better.

Indeed do look up the difference between the two :slight_smile:

write() doesn't do any conversion, it just pushes out 8 bits as is from the internal representation.
You want a human-readable string representing a number, you have to use print().