#include "Wire.h" #include #define OLED_SDA 21 #define OLED_SCL 22 #define PIN_4_20MA 36 #define PIN_VEGETRO 0 unsigned int pos; int value = 0, i, sum, input; long tim_e; void scanI2C(){ byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for(address = 0x01; address < 0x7f; address++){ Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0){ Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error == 4){ Serial.print("Unknow error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } //delay(1); } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("I2C scan done"); } void setup() { Serial.begin(9600); Serial.println("Started"); #ifdef ESP32 adcAttachPin(PIN_VEGETRO); // Full scale 11db 3,3V; linear till 2,6V // 6db range full scale 1,8V analogReadResolution(12); //ADC conversion resolution 12 bits (9-12) analogSetWidth(12); //ADC read resolution 9-16 bits if not equal, it will be shifted analogSetAttenuation(ADC_0db); //For all pins attenuation: ADC_0db, ADC_2_5db, ADC_6db, ADC_11db analogSetPinAttenuation(PIN_VEGETRO, ADC_11db); #endif // scanI2C(); } void loop() { sample_Vegetronix(15); delay(500); } int sample_Vegetronix(int readings){ value = 0; int samples[readings-1]; int maxdev=0; sum=0; tim_e = micros(); for(i=0; imaxdev) maxdev = abs(samples[i] - value); } Serial.print(maxdev); float percent = (maxdev * 100.0)/value; Serial.print(", "); Serial.print(percent); Serial.println("%"); // Serial.print(" /Conv(usec): "); // Serial.println(micros() - tim_e); }