//############################################################## //######### BOARD DUE ############## #define VERSION "test" const char* MAINFILE = __FILE__; /*############################################################### ######## Funktionen und Board Einstellung ########## ###############################################################*/ #define DEBUG #define MON Serial2.print #define MONln Serial2.println #define ADS1115_AI #define ADS1115_LIB_Adafruit // *********** Predefined *********** #define TESTLED_PIN 13 // *********** Predefined END *********** #if defined(ADS1115_AI) || defined(ADS1115_PT1000) #ifdef ADS1115_LIB_Adafruit #include #else #include https://github.com/wollewald/ADS1115_WE https://wolles-elektronikkiste.de/en/ads1115-a-d-converter-with-amplifier #include #endif #endif #ifdef ADS1115_AI #ifdef ADS1115_LIB_Adafruit Adafruit_ADS1115 ADS_AI; /* Use this for the 16-bit version */ byte ADS_AI_addr=0x48; int16_t ADS_AI0, ADS_AI1, ADS_AI2, ADS_AI3; #else #define ADS_AI_I2Caddr 0x48 ADS1115_WE adc = ADS1115_WE(ADS_AI_I2Caddr); int ADS_AI0, ADS_AI1, ADS_AI2, ADS_AI3; #endif float ADS_AI_volts0, ADS_AI_volts1, ADS_AI_volts2, ADS_AI_volts3; #endif unsigned long millis_old=0; byte testled_status=true; void setup(){ Serial.begin(115200); while (!Serial) { ; // wait for serial port to connect. Needed for Native USB only } Serial2.begin(115200); while (!Serial2) { ; // wait for serial port to connect. Needed for Native USB only } pinMode(TESTLED_PIN, OUTPUT); digitalWrite(TESTLED_PIN, testled_status); testled_status=!testled_status; delay(1000); #ifdef ADS1115_AI #ifdef DEBUG Serial.println(F("checkpoint SETUP(): ADS1115_AI")); MONln(F("checkpoint SETUP(): ADS1115_AI")); #endif #ifdef ADS1115_LIB_Adafruit ADS_AI.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV if (!ADS_AI.begin(ADS_AI_addr)) { Serial.println("Adafruit -> Failed to initialize ADS_AI."); MONln("Adafruit -> Failed to initialize ADS_AI."); } #else if(!adc.init()){ Serial.println("wollewald ADS1115 not connected!"); MONln("wollewald ADS1115 not connected!"); }else{ adc.setVoltageRange_mV(ADS1115_RANGE_6144); //comment line/change parameter to change range adc.setMeasureMode(ADS1115_CONTINUOUS); //comment line/change parameter to change mode Serial.println("wollewald ADS1115 set!"); MONln("wollewald ADS1115 set!"); } #endif #endif } void loop(){ static byte zaehler_sec=0; static byte zaehler_10sec=0; if (millis() - millis_old >= 1000) { millis_old = millis(); zaehler_sec++; digitalWrite(TESTLED_PIN, testled_status); testled_status=!testled_status; switch (zaehler_sec) { case 1: #ifdef ADS1115_AI #ifdef ADS1115_LIB_Adafruit Serial.println("Adafruit "); MONln("Adafruit "); #else Serial.println("wollewald "); MONln("wollewald "); #endif #endif debug_output(zaehler_sec,millis_old); break; case 2: debug_output(zaehler_sec,millis_old); break; case 3: debug_output(zaehler_sec,millis_old); break; case 4: debug_output(zaehler_sec,millis_old); break; case 5: debug_output(zaehler_sec,millis_old); break; case 6: #ifdef ADS1115_AI #ifdef ADS1115_LIB_Adafruit if (!ADS_AI.begin(ADS_AI_addr)) { Serial.print(" Failed to initialize Adafruit."); MONln(" Failed to initialize Adafruit."); }else{ Serial.print(" OK to initialize Adafruit."); MONln(" OK to initialize Adafruit."); ADS_AI0 = ADS_AI.readADC_SingleEnded(0); ADS_AI_volts0 = ADS_AI.computeVolts(ADS_AI0); MON(" Adafruit ADS_AI_0: "); MON(ADS_AI0); MON(" "); MON(ADS_AI_volts0); MONln("V"); Serial.print(" Adafruit ADS_AI_0: "); Serial.print(ADS_AI0); Serial.print(" "); Serial.print(ADS_AI_volts0); Serial.println("V"); } #else ADS_AI0 = adc.getRawResult(); ADS_AI_volts0 = adc.getResult_V(); MON(" wollewald ADS_AI_0: "); MON(ADS_AI0); MON(" "); MON(ADS_AI_volts0); MONln("V"); Serial.print(" wollewald ADS_AI_0: "); Serial.print(ADS_AI0); Serial.print(" "); Serial.print(ADS_AI_volts0); Serial.println("V"); #endif #endif debug_output(zaehler_sec,millis_old); break; case 7: debug_output(zaehler_sec,millis_old); break; case 8: debug_output(zaehler_sec,millis_old); break; case 9: debug_output(zaehler_sec,millis_old); break; case 10: debug_output(zaehler_sec,millis_old); zaehler_sec=0; zaehler_10sec++; break; } // 10 Sekunden ENDE if (zaehler_10sec >= 3) { zaehler_10sec=0; #ifdef DEBUG Serial.println(""); Serial.println("30 sec Impuls"); Serial.println("30 Impuls"); MONln(""); MONln("30 sec Impuls"); MONln("30 Impuls"); #endif } } } void debug_output(byte zaehler_sec, unsigned long millis_old ){ Serial.print("Slave_full "); Serial.print(zaehler_sec); Serial.print(" "); Serial.println(millis_old); MON("Slave_full "); MON(zaehler_sec); MON(" "); MONln(millis_old); }