@armor
Good day armor thank you for the code and explanation but i think im missing something. I just compiled your code and although it compiled when i flashed it to the photon it did not appear on the arduino serial monitor like the other programs i worked with. If i remove the SYSTEM_MODE(MANUAL) line of code than the photon breathes green. Why is the temperature humidity and pressure measurements not displaying on the serial monitor? See attached.
Are you using an Original Adafruit Sensor or a compatible one like the GY-BME/P280?
I tested the example code on an GY and it does not work! Also green blinking at the end with no output at serial monitor with hardware SPI connected on D5.
@mhdevx
Well its the only port available for selection and its also the only port that worked for other programs i used when testing the serial monitor.
Please find the image of my configuration attached: 3V3 connected to VCC on the sensor, GND connected to GND and CS connected to A2 (as coded using armor’s code above)
I also connected the photon to BME280 sensor as the bme820test.ino was coded: where i connected the SDI as i would have MOSI to D2, SDO as MISO to D3, SCK to D4 and CSB as CS to D5.
@Postler
It is actually a CJMCU-280E BME280 found here
but even without the sensor connected the the photon does not seem to be sending any information to the serial monitor and it should because of the following lines of code:
Serial.println(F(“BME280 test”));
// if (!bme.begin(0x76)) {
if (!bme.begin()) {
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
while (1);
nothing is being displayed to the monitor as if there is no communication taking place between the photon and serial monitor.
When i flash the bme280test.ino example found in the library my photon also breathes green (instead of cyan) indicating its connected to wifi but is not connected to the cloud. And no serial communication appears on the serial monitor. With the example armor uploaded the photon breathes white (offline) and again no serial communication appears data appears on the serial monitor.
I think you will find that connecting SDI (MOSI) to A5, SDO (MISO) to A4 and SCK to A3 will make it work. The library is using the standard hardware SPI port and that is definitely not on D2, D3 and D4.
Is the serial monitor you are using set to 9600 baud and are you using the right COM port? You will need to go to settings, devices and see which COM port has been assigned to you photon once you have connected to the USB.
Regarding the serial monitor, did you installed Particle CLI? This serial window on your screenshot looks like something else (but I’m using Mac, so might be different on Windows).
@armor
Those are the pins that were coded in the example. However I did flash the code you uploaded which specified CS to be connected to A2. Even if these pins were incorrect the lines of code in the setup up loop should display on the serial monitor
Yes it is. And yes it is the correct com port as well becuase when I run other programs they display on the serial monitor. Im 100% sure it is the correct baudrate and com port.
@mhdevx
Yes I did install The particle CLI but if I’m not mistaken that allows for serial communication on the particle desktop dev. Which didn’t work for any of my programs so I read a thread which said I could use the arduinoIDE serial monitor to view serial data and it worked fine for my other programs. So that serial monitor displayed is the aruino ide serial monitor
Thank you for the response Bko. The picture i upload was done according to the code armor uploaded where he said I only need to use the CS pin which must be connected to A2.
The when i used the other code i did the connections as i stipulated in the above messages. I connected the rest of it according to the pins specified in the photons doc manual.
Correct me if I'm wrong but even if the connection between the micro and the sensor were incorrect the code in the setup would still execute and should've displayed on the serial Monitor due to the following code:
Serial.println(F("BME280 test"));
And
Since this does not display does is not indicate that the fault is not likely to be the connection but something else ?
@Alli, I believe @armor was referring to only specifying CS in the Adafruit_BME280 constructor. He was not referring to the wiring. In order for the BME280 to work using SPI, you will need four pins to be connected as @armor said here:
The Photon's default SPI port is on pins A3 (SCK), A4 (MISO) and A5 (MOSI) with the CS pin being any pin but typically A2 since it is the default. Without having all the Photon to BME280 board pins connected, your code will never work.
As for the console output, you may want to create a simple app that prints "Hello" to the console very second so you can establish that your console program actually works. Then move on to the BME280 testing.
@peekay123
Okay thanks for clearing that up.
When I first connected the photon to the sensor I connected the way armor specified
SCK to A3
MISO to A4
MOSI to A5
CS to A2
And I had the same problem.
Also want to ask: Will it make if I use the arduino ide serial monitor instead of the console?
Also I can undertand the fact that if my connections were incorrect my entire code would not execute but wouldn’t the code in the setup loop:
Serial.println(F(“BME280 test”));
Serial.println(“Could not find a valid BME280 sensor, check wiring!”);
execute and display on the serial monitor/console ?
I have tested it with many other programs. Even with the hello world it’s working perfectly fine. I’m not sure what’s wrong.
I think I’m just going to switch to another library and use the I2C protocol instead.
Thanks everyone for the assitance.
@Alli, I believe the issue is with the CSB pin on your BME280 board. It needs to be set as follows:
Interface selection is done automatically based on CSB (chip select) status. If CSB is connected to VDDIO, the I²C interface is active. If CSB is pulled down, the SPI interface is activated. After CSB has been pulled down once (regardless of whether any clock cycle occurred), the I²C interface is disabled until the next power-on-reset. This is done in order to avoid inadvertently decoding SPI traffic to another slave as I²C data. Since the device startup is deferred until both VDD and VDDIO are established, there is no risk of incorrect protocol detection because of the power-up sequence used. However, if I²C is to be used and CSB is not directly connected to VDDIO but is instead connected to a programmable pin, it must be ensured that this pin already outputs the VDDIO level during power-on-reset of the device. If this is not the case, the device will be locked in SPI mode and not respond to I²C commands.
So for SPI operation, CSB must be connected to GND.
@peekay123@bko
Hello. Thank you for the advice and assistance but nothing seems to be working to resolve this issue. I decided to use I2C with the Control everything library instead and everything is working great.
Thank you all for your time and help. i really appreciate the support i received from the particle community.
@Alli I am a newbie in microcontroller programming and encountered the same problem when using SPI interface with CS as A2 as recommended by @Postler and even performed as using D1,D2… but no luck.
will be grateful to you if able to get assistance on I2C programming for this sensor.
(P.S. I am needing it for my school project)
Firstly, make sure that you have connected your BME280 correctly to your particle device. I used a particle photon, thus pins D0 and D1 (SDA and SCL) are the I2C pins as shown in the pinout diagram in this link:
Ensure that your BME280 is connected to the photon as shown in this link:
You will need to include the CE_BME280 library in your project first. Then use these instructions in your program to poll measurements from your BME280:
Pressure = (bme.readPressure()/100); //Pressure measurements in hPa
Temperature = bme.readTemperature();
Humidity = bme.readHumidity();
Its as simple as that. If you are still having a problem, post the program you created so that we can see what you are doing and try to help