M5PaperColor: Can't read both SHT40 and battery data?
-
Hello, new M5PaperColor user here. While trying to familiarize myself with its functions, I've tried to modify the "PaperColor SHT40 Temperature & Humidity" sketch to also include the battery data, to get an idea of how the frequency of screen refreshes impacts its runtime.
But although the M5.Power functions work fine in the "PaperColor Battery" sketch, they just return values of 0 or -1 in this one. When I comment out all the SHT40 code, the battery functions work as expected. But as soon as I uncomment the sht4.begin() statement, the battery functions quit giving useful data again.
Is there a way to retrieve valid data from both subsystems, or is there really no way for a sketch that gathers environmental data to also warn the user when the battery is getting low?
-
Hello @Shipbrook
M5Unified uses Wire1 for internal I2C and Wire for external I2C.
The example for SHT40 incorrectly uses Wire which causes issues as soon as other internal I2C communication is required, e.g. reading battery status.
The quick way to fix this is replacing Wire with Wire1 in below line:
//if(!sht4.begin(&Wire, SHT40_I2C_ADDR_44, SHT_SDA_PIN, SHT_SCL_PIN, 400000U)) if(!sht4.begin(&Wire1, SHT40_I2C_ADDR_44, SHT_SDA_PIN, SHT_SCL_PIN, 400000U))The better way is to get the actual port used by M5Unified for internal I2C and the use that information:
i2c_port_t PortIn = M5.In_I2C.getPort(); TwoWire * WireIn = (PortIn == 1) ? &Wire1 : &Wire; if(!sht4.begin(WireIn, SHT40_I2C_ADDR_44, SHT_SDA_PIN, SHT_SCL_PIN, 400000U))Thanks
Felix
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login