Abdurraziq / ZMPT101B-arduino

Arduino library for ZMPT101B voltage sensor.
MIT License
66 stars 32 forks source link

Compilation error on Arduino MKR 1010 wifi #15

Open meehollak opened 4 months ago

meehollak commented 4 months ago

Apologies if this is the wrong place for this. I am trying to compile the example code that ran on my Uno over to an MKR 1010 but now getting compile errors. Specifically…

/Users/adam/Dropbox (Personal)/Arduino/libraries/ZMPT101B/src/ZMPT101B.cpp: In member function 'float ZMPT101B::getRmsVoltage(uint8_t)':
/Users/adam/Dropbox (Personal)/Arduino/libraries/ZMPT101B/src/ZMPT101B.cpp:60:55: error: 'ADC_SCALE' was not declared in this scope
   readingVoltage += sqrt(Vsum / measurements_count) / ADC_SCALE * VREF * sensitivity;
                                                       ^~~~~~~~~
/Users/adam/Dropbox (Personal)/Arduino/libraries/ZMPT101B/src/ZMPT101B.cpp:60:67: error: 'VREF' was not declared in this scope
   readingVoltage += sqrt(Vsum / measurements_count) / ADC_SCALE * VREF * sensitivity;
                                                                   ^~~~

Any thoughts as to what is going on?

lukyanetsv commented 2 months ago

@meehollak you should add microcontroller MKR1010 into the library like this:

#if defined(AVR)
    #define ADC_SCALE 1023.0f
    #define VREF 5.0f
#elif defined(ESP8266)
    #define ADC_SCALE 1023.0
    #define VREF 3.3
#elif defined(ESP32)
    #define ADC_SCALE 4095.0
    #define VREF 3.3
#endif