JVKran/Forced-BME280

Forced-BME280 on 32U4 boards

Closed this issue · 10 comments

#define FORCED_CLIMATE_WIRE //Uncomment this macro to use Wire.h instead of TinyWireM.h
was changed in the include, it is the current version from 9 March 2020

Unfortunately I have problems running it on a 32U4 based board like the Arduino Micro:

After uploading the sketch, the serial port /dev/ttyACM0 gets lost and hence no output on the serial monitor is possible.

Do you have any hints?

Hello Stoccarda, unfortunately I'm unable to reproduce the issue. The BME280 works fine on my Arduino Micro. There are a very large amount of possible causes; hardware problems, wiring specific problems, I2C problems (resistors), etc. However, there are a couple of things I can think about specifically.

  • Make sure you aren't using the RX and TX pins for the I2C bus. This will result in the described behaviour.
  • Serial ports disconnecting could have to do with shorting pins. During an I2C transaction the pins could be shorted.
  • Make sure you are compiling for the right board.

To make sure the BME280 works you could try to display some stats on a display or let a LED blink when a temperature reading in a 'normal' range occurs. Faulty chips usually read a 0 or 1023. Specifically something else should happen but thats a little technical; when you get a plausible reading the chip works.

Last but not least; make sure you have the correct drivers for the Arduino Micro installed. It's one of few Arduinos that have a usb master interface. You could try unplugging it after uploading, then replugging it and openening the Serial Monitor.

I'm afraid this problem isn't specific to this library. I can't help you any further with that. Let me know if any of the above fixed the problem!

Thanks for quick checking and good to know that it works an the Micro too.
I tried both the Micro as well as an ItsyBitsy.

Even when only having
#include <forcedClimate.h>
ForcedClimate climateSensor = ForcedClimate(Wire, 0x77);
in the code (no measurement read), the port disappears (closed).
`avrdude: verifying ...
avrdude: 6376 bytes of flash verified

avrdude done. Thank you.

processing.app.SerialException: Fehler beim Öffnen des seriellen Ports "/dev/ttyACM0".
at processing.app.Serial.(Serial.java:147)
at processing.app.Serial.(Serial.java:82)
at processing.app.SerialMonitor$2.(SerialMonitor.java:130)
at processing.app.SerialMonitor.open(SerialMonitor.java:130)
at processing.app.AbstractMonitor.resume(AbstractMonitor.java:132)
at processing.app.Editor.resumeOrCloseSerialMonitor(Editor.java:2107)
at processing.app.Editor.access$1300(Editor.java:117)
at processing.app.Editor$UploadHandler.run(Editor.java:2081)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: jssc.SerialPortException: Port name - /dev/ttyACM0; Method name - openPort(); Exception type - Port not found.
at jssc.SerialPort.openPort(SerialPort.java:167)
at processing.app.Serial.(Serial.java:136)
... 8 more
Fehler beim Öffnen des seriellen Ports "/dev/ttyACM0"`

It works when using the Adafruit library instead.
In the design, the BME280 and a SSD1306 are controlled by I²C, a second sensor is controlled by RX/TX (Serial1)

Very interesting. Unfortunately I don't have any other 32U4 based microcontrollers. I'm going to investigate it some more. In the mean time, I suggest you to take a closer look at possible causes of the error.

I will do so and keep you updated.
If I can help with any trials, just let me know.
I have a PCB for the sensors and the OLED, and the layout is for a 5V itsyBitsy.

As you can see in the new example sketch, I changed the way the chip and the TwoWire bus are intialized. This should make sure that micrcontroller specific procedures take place before the bus and chip are initialized. If you're interested why that makes sense you could check out the main.cpp of Arduino; all kinds of things happening in the background.

Furthermore, from now on the macro comes commented out. It has to be commented when using with an ATtiny. I figured only a small amount of people would use an ATtiny so that's why.

I also don't include the stdint anymore; this is completely handled by Arduino.h from now on. If it is going to work, this should be it.

I have tried the new .h and this actually made a change:
When running the sketch, the port is no more lost and I get an output in the serial monitor:
17:49:04.523 -> Only temperature: 0
17:49:09.505 -> Temperature: 0, Humidity: 0 and Pressure: 0
The values are not as expected, but it runs!
I expect that no more including stdint made the difference.

My BME280 has address 0x77:
ForcedClimate climateSensor = ForcedClimate(Wire, 0x77);

Success :-)

18:02:16.451 -> Temperature: 2535, Humidity: 3706 and Pressure: 97778
18:02:17.480 -> Only temperature: 2534

The new test.ino works !!!

Both

Wire.begin();
climateSensor.begin();

have to be added in setup().
Thanks for quick reaction.

Just a small suggestion for the test.ino example sketch:
What about an output with 'real' values, i.e. multiplying the values with 0.01

18:02:16.451 -> Temperature: 2535, Humidity: 3706 and Pressure: 97778
18:02:17.480 -> Only temperature: 2534
->
18:02:16.451 -> Temperature: 25.35, Humidity: 37.06 and Pressure: 977.78
18:02:17.480 -> Only temperature: 25.34

You're welcome. And thanks for your quick and useful replies too! Makes such a big difference when tackling these kinds of problems.

I'll add the real life readings. That's currently not the case since most microcontrollers don't have floating point hardware. This makes floating point calculations a lot slower than normal (integer) calculations.

They should return floats now. If that's not the case or you encounter another problem; please open up another issue.