/* ////////////////////////////////////////////////////////////////// ARDUINO/Genuino Project "MADIMOD-77110", Environmental Monitoring https://www.changpuak.ch/electronics/Arduino-Madimod-77110-I2C.php Software Version 21.0 25.07.2025 by ALEXANDER SSE FRANK The Serial Parser was written by Christian Monstein, used in "Easy_Diseqc V1.2", Monstein ETH Zurich, 20.06.2018 ////////////////////////////////////////////////////////////////// */ #include #include #include // DISPLAY #define OLED_MOSI 11 #define OLED_CLK 13 #define OLED_DC 9 #define OLED_CS 8 #define OLED_RESET 10 bool OLED_UPSIDE_DOWN = false ; Adafruit_SH1106 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); #if (SH1106_LCDHEIGHT != 64) #error("Height incorrect, please fix Adafruit_SH1106.h!"); #endif int BeepPin = 5 ; bool DEBUG = false ; // SERIAL COMMUNICATION String buffer ; // ///////////////////////////////////////////////////////////////////// // SUBROUTINES SENSOR // ///////////////////////////////////////////////////////////////////// float Messwert = 0.0 ; byte error = 0x00 ; void I2CScan() { byte error, address ; for(address = 1; address < 127; 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.println(address,HEX); } } } void MEASURE() { // THIS IS A PRESSURE MPL115A2 //// // START CONVERSION // EXTRA BRACKETS ARE NEEDED DUE TO DECLARATION // OF VARIABLES INSIDE CASE STATEMENT unsigned int Padc_MSB = 0x00 ; unsigned int Padc_LSB = 0x00 ; unsigned int Tadc_MSB = 0x00 ; unsigned int Tadc_LSB = 0x00 ; unsigned int a0_MSB = 0x00 ; unsigned int a0_LSB = 0x00 ; unsigned int b1_MSB = 0x00 ; unsigned int b1_LSB = 0x00 ; unsigned int b2_MSB = 0x00 ; unsigned int b2_LSB = 0x00 ; unsigned int c12_MSB = 0x00 ; unsigned int c12_LSB = 0x00 ; Wire.beginTransmission(0x60); Wire.write(0x12); Wire.write(0xAF); error = Wire.endTransmission(); // WAIT FOR MEASUREMENT TO COMPLETE delay(5); // max. 3 ms // READ ALL MEMORY LOCATIOSN Wire.beginTransmission(0x60); Wire.write(0x00); Wire.endTransmission(); Wire.requestFrom(0x60,12); if ( Wire.available() ) { // READ MSB AND LSB Padc_MSB = Wire.read(); // 0x00 Padc_LSB = Wire.read(); // 0x01 Tadc_MSB = Wire.read(); // 0x02 Tadc_LSB = Wire.read(); // 0x03 a0_MSB = Wire.read(); // 0x04 a0_LSB = Wire.read(); // 0x05 b1_MSB = Wire.read(); // 0x06 b1_LSB = Wire.read(); // 0x07 b2_MSB = Wire.read(); // 0x08 b2_LSB = Wire.read(); // 0x09 c12_MSB = Wire.read(); // 0x0A c12_LSB = Wire.read(); // 0x0B } // COMBINE MSB AND LSB unsigned long Padc = ( ( Padc_MSB << 8 ) + Padc_LSB ) >> 6 ; unsigned long Tadc = ( ( Tadc_MSB << 8 ) + Tadc_LSB ) >> 6 ; float a0 = ( a0_MSB << 5 ) + ( a0_LSB >> 3 ) + ( a0_LSB & 0x07 ) / 8.0 ; float b1 = ( ( ( ( b1_MSB & 0x1F ) * 0x100 ) + b1_LSB ) / 8192.0) - 3 ; float b2 = ( ( ( ( b2_MSB - 0x80 ) << 8 ) + b2_LSB ) / 16384.0 ) - 2 ; float c12 = ( ( ( c12_MSB * 0x100 ) + c12_LSB ) / 16777216.0 ) ; // CALCULATE PRESSURE float Pcomp = a0 + ( b1 + c12 * Tadc ) * Padc + b2 * Tadc ; float PressurekPa = Pcomp * 0.0635 + 50 ; float PressuremBar = 10 * PressurekPa ; // Serial.println(error,DEC); // Serial.write(" mBar");Serial.write("\n"); Messwert = PressuremBar ; // RESULT IS mbar } // ///////////////////////////////////////////////////////////////////// // SUBROUTINES DISPLAY. // ///////////////////////////////////////////////////////////////////// void UpDateDisplay() { display.clearDisplay() ; display.setTextSize(1) ; display.setTextColor(WHITE) ; display.setCursor(0, 0) ; display.println("MADIMOD-77110-I2C") ; display.drawLine(0, 12, 128, 12, WHITE) ; display.drawLine(0, 63, 128, 63, WHITE) ; display.setCursor(0, 25) ; display.setTextSize(3) ; if(Messwert < 1000.0) display.print(" ") ; display.print(Messwert,2) ; Serial.println(Messwert,2) ; display.display() ; } // ///////////////////////////////////////////////////////////////////// // SUBROUTINES BEEPER // ///////////////////////////////////////////////////////////////////// const unsigned int BEEPlength = 99 ; void BEEP(unsigned int data) { unsigned int pointer = 0 ; for(int i=31; i>0; i--) { pointer = (1 << i) ; if((pointer & data) > 0) digitalWrite(BeepPin, HIGH) ; else digitalWrite(BeepPin, LOW) ; delay(BEEPlength) ; } digitalWrite(BeepPin, LOW) ; // JUST IN CASE :-) } // ///////////////////////////////////////////////////////////////////// // S E T U P // ///////////////////////////////////////////////////////////////////// void setup() { // START SERIAL COMMUNICATIONS Serial.begin(115200) ; // START WIRE - I2C Wire.begin() ; // START OLED display.begin(SH1106_SWITCHCAPVCC); if(OLED_UPSIDE_DOWN) display.setRotation(2) ; // 180 degrees // SHOW STARTUP SCREEN display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.println("MADIMOD-77110-I2C") ; display.drawLine(0, 12, 128, 12, WHITE) ; display.setTextSize(1) ; display.setCursor(0, 20) ; display.println("ARDUINO/GENUINO BASED") ; display.setCursor(0, 32) ; display.println("ENVIRONMENTAL MONITOR") ; display.setCursor(0, 44) ; display.println("(C) WWW.CHANGPUAK.CH") ; display.setCursor(0, 56) ; display.println("BUILT 05.12.2025") ; display.display() ; delay(999) ; // BEEPER BEGIN pinMode(BeepPin, OUTPUT) ; digitalWrite(BeepPin, HIGH) ; delay(999) ; digitalWrite(BeepPin, LOW) ; // CHECK SENSOR I2CScan() ; } // ///////////////////////////////////////////////////////////////////// // M A I N L O O P // ///////////////////////////////////////////////////////////////////// void loop() { // ///////////////////////////////////////////////////////////////// // CHECK SERIAL PORT if (Serial.available() > 0) // ///////////////////////////////////////////////////////////////// { buffer = Serial.readString() ; // /////////////////////////////////////////////////////// if (buffer.startsWith("*IDN?")) // /////////////////////////////////////////////////////// { Serial.println("MADIMOD-77110-I2C BY CHANGPUAK.CH") ; } else // /////////////////////////////////////////////////////// if (buffer.startsWith("HELP")) // /////////////////////////////////////////////////////// { Serial.println("> HELP"); Serial.println("RTFM."); } buffer = "" ; // erase buffer for next command } delay(9999) ; MEASURE() ; UpDateDisplay() ; } // ///////////////////////////////////////////////////////////// // END OF FILE. // /////////////////////////////////////////////////////////////