I'm working on a larger project where I want to use a number of sensors and libraries, and in order to keep the code clean, I'd like to wrap certain libraries into my own classes. I'm trying this with the Adafruit SHT31 temperature sensor as an example:
main:17:25: error: request for member 'getTemp' in 'ambienttemp', which is of non-class type 'ambientTemp()'
I feel like I'm somehow not initializing the Adafruit_SHT31 correctly, which in their example code is done with Adafruit_SHT31 sht31 = Adafruit_SHT31();
Any thoughts how to fix this would be much appreciated!
Thanks, gfvalvo! This solved the error, and the code now compiles but when I run it on the Uno it seems to hang. I still assume I'm doing something wrong in the initializer list when creating an instance of the Adafruit_SHT31, but I can't figure out what it is.
.begin() is a memberfunction of Adafruit_SHT31 .
All the examples show, that this member function gets called in setup.
But you call it in the constructor.
Don't call things in the constructor which might need hardware access. HW might not be ready at this point.
Create your own begin member function and call it in setup.
ps.: why this trailing _ in sht31_ ? just leave it away.
Thanks so much noiasca! That solved it. I wrapped the begin() function and called it from my main process and it works! Posting the working code below for future reference if anybody needs it: