]> jspc29.x-matter.uni-frankfurt.de Git - avr.git/commitdiff
LANTelnetToI2C_Board: implement a 0.91 OLED Display for on board monitoring w/ IP...
authorOle Artz <ole.artz@t-online.de>
Thu, 17 Mar 2022 10:13:49 +0000 (11:13 +0100)
committerJan Michel <mail@janmichel.eu>
Thu, 17 Mar 2022 10:33:37 +0000 (11:33 +0100)
esp32/EthernetUART/LANTelnetToI2C_Board/LANTelnetToI2C_Board.ino
esp32/EthernetUART/LANTelnetToI2C_Board/live_telnet_data_plot.py [new file with mode: 0644]
esp32/EthernetUART/LANTelnetToI2C_Board/quickstart 4CH ADC_Ethernet Portable Board.pdf [new file with mode: 0644]
esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py [new file with mode: 0644]

index bd0f40228d857f20c0789b6709e548cc8fdd0270..8363a5b2ebb24a27497eb834cb66efb717dcb4c9 100644 (file)
@@ -5,16 +5,17 @@
 # ### for START TELNET SERVER                   ### #
 # ### for LAN to I2C                            ### #
 # ### connected to 4 CH ADC                     ### #
+# ### connected to 0.91 OLED Display            ### #
 # ###                                           ### #
 # ### author: O.Artz                            ### #
 # ###                                           ### #
-# ### UPDATE 2021-07-01                         ### #
+# ### UPDATE 2022-01-20                         ### #
 # ###                                           ### #
 #####################################################
 
-ETH MAC: 24:6F:28:1E:C5:57 
-IPv4: 192.168.8.64
-Telnet: 192.168.8.64 2323
+ETH MAC: 24:6F:28:1E:C7:DF
+IPv4: 192.168.8.63
+Telnet: 192.168.8.63 2323
 
 Visual Status via Board LEDs:
 ETH Start                 -> Green LED blink for 1 sec
@@ -22,25 +23,25 @@ Telnet work               -> Green LED on
 ETH Disconnected/stopped  -> Orange LED on
 */
 
-//load needed Libaries
-#include <ETH.h>                //for Telnet Server Connection
-#include <Wire.h>               //for I2C Connection
-#include <Adafruit_ADS1015.h>   //for external ADC
+// load needed Libaries
+#include <Adafruit_ADS1015.h> //for external ADC
+#include <ETH.h>              //for Telnet Server Connection
+#include <Wire.h>             //for I2C Connection
 //__________________________________________
-#include <SPI.h>                //for display control
-#include <Adafruit_SSD1306.h>   //for OLED display driver
+#include <Adafruit_SSD1306.h> //for OLED display driver
+#include <SPI.h>              //for display control
 
-//for screen
+// for screen
 #define SCREEN_WIDTH 128 // OLED display width, in pixels
 #define SCREEN_HEIGHT 32 // OLED display height, in pixels
 
 // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
-// The pins for I2C are defined by the Wire-library. 
+// The pins for I2C are defined by the Wire-library.
 // On an arduino UNO:       A4(SDA), A5(SCL)
 // On an arduino MEGA 2560: 20(SDA), 21(SCL)
 // On an arduino LEONARDO:   2(SDA),  3(SCL), ...
 #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
-#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
+#define SCREEN_ADDRESS 0x3C //< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
 #define NUMFLAKES 10 // Number of snowflakes in the animation example
@@ -48,189 +49,232 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 #define imageWidth 106
 #define imageHeight 32
 
-const unsigned char logo_bmp [] PROGMEM =
-{
-0xfc, 0x0f, 0xc0, 0x03, 0xf8, 0x3f, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80, 0xfc, 0x0f, 
-  0xc0, 0x07, 0xf8, 0x3f, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x00, 0xfc, 0x0f, 0xc0, 0x0f, 
-  0xf0, 0x3f, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xfe, 0x40, 0xfc, 0x0f, 0xc0, 0x1f, 0xe0, 0x3f, 
-  0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xfc, 0xc0, 0xfc, 0x0f, 0xc0, 0x3f, 0xc0, 0x3f, 0xff, 0xfc, 
-  0x0f, 0xff, 0xff, 0xff, 0xf1, 0xc0, 0xfc, 0x0f, 0xc0, 0x3f, 0x80, 0x3f, 0x00, 0x00, 0x0f, 0xff, 
-  0xff, 0xff, 0xe7, 0xc0, 0xfc, 0x0f, 0xc0, 0x7f, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 
-  0x8f, 0xc0, 0xfc, 0x0f, 0xc0, 0xfe, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x3f, 0xc0, 
-  0xfc, 0x0f, 0xc1, 0xfc, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfc, 0xff, 0xc0, 0xfc, 0x0f, 
-  0xc3, 0xf8, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf1, 0xff, 0xc0, 0xfc, 0x0f, 0xc7, 0xf8, 
-  0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x8f, 0xff, 0xc0, 0xfc, 0x0f, 0xcf, 0xf0, 0x00, 0x3f, 
-  0x00, 0x00, 0x0f, 0xff, 0xfc, 0x3f, 0xff, 0xc0, 0xfc, 0x0f, 0xcf, 0xe0, 0x00, 0x3f, 0x00, 0x00, 
-  0x0f, 0xff, 0xe0, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 0xdf, 0xe0, 0x00, 0x3f, 0xff, 0xf0, 0x0f, 0xfe, 
-  0x0f, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xf0, 0x0f, 0x80, 0xff, 0xff, 
-  0xff, 0xc0, 0xfc, 0x0f, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
-  0xfc, 0x0f, 0xff, 0xf8, 0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 
-  0xfd, 0xfc, 0x00, 0x3f, 0xff, 0xf0, 0x0f, 0xf8, 0x1f, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 0xf8, 0xfc, 
-  0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xc1, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 0xf0, 0xfe, 0x00, 0x3f, 
-  0x00, 0x00, 0x0f, 0xff, 0xf8, 0x7f, 0xff, 0xc0, 0xfc, 0x0f, 0xe0, 0x7f, 0x00, 0x3f, 0x00, 0x00, 
-  0x0f, 0xff, 0xff, 0x0f, 0xff, 0xc0, 0xfc, 0x0f, 0xe0, 0x7f, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 
-  0xff, 0xe3, 0xff, 0xc0, 0xfc, 0x0f, 0xc0, 0x3f, 0x80, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf8, 
-  0xff, 0xc0, 0xfc, 0x0f, 0xc0, 0x3f, 0x80, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfe, 0x3f, 0xc0, 
-  0xfc, 0x0f, 0xc0, 0x1f, 0xc0, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0x9f, 0xc0, 0xfc, 0x0f, 
-  0xc0, 0x0f, 0xe0, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xc7, 0xc0, 0xfc, 0x0f, 0xc0, 0x0f, 
-  0xe0, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf3, 0xc0, 0xfc, 0x0f, 0xc0, 0x07, 0xf0, 0x3f, 
-  0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf9, 0xc0, 0xfc, 0x0f, 0xc0, 0x07, 0xf0, 0x3f, 0x00, 0x00, 
-  0x0f, 0xff, 0xff, 0xff, 0xfc, 0xc0, 0xfc, 0x0f, 0xc0, 0x03, 0xf8, 0x3f, 0x00, 0x00, 0x0f, 0xff, 
-  0xff, 0xff, 0xfe, 0x40, 0xfc, 0x0f, 0xc0, 0x03, 0xfc, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 
-  0xff, 0x00, 0xfc, 0x0f, 0xc0, 0x01, 0xfc, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x80
-};
+const unsigned char logo_bmp[] PROGMEM = {
+    0xfc, 0x0f, 0xc0, 0x03, 0xf8, 0x3f, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff,
+    0xff, 0x80, 0xfc, 0x0f, 0xc0, 0x07, 0xf8, 0x3f, 0xff, 0xfc, 0x0f, 0xff,
+    0xff, 0xff, 0xff, 0x00, 0xfc, 0x0f, 0xc0, 0x0f, 0xf0, 0x3f, 0xff, 0xfc,
+    0x0f, 0xff, 0xff, 0xff, 0xfe, 0x40, 0xfc, 0x0f, 0xc0, 0x1f, 0xe0, 0x3f,
+    0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xfc, 0xc0, 0xfc, 0x0f, 0xc0, 0x3f,
+    0xc0, 0x3f, 0xff, 0xfc, 0x0f, 0xff, 0xff, 0xff, 0xf1, 0xc0, 0xfc, 0x0f,
+    0xc0, 0x3f, 0x80, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xe7, 0xc0,
+    0xfc, 0x0f, 0xc0, 0x7f, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff,
+    0x8f, 0xc0, 0xfc, 0x0f, 0xc0, 0xfe, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff,
+    0xff, 0xff, 0x3f, 0xc0, 0xfc, 0x0f, 0xc1, 0xfc, 0x00, 0x3f, 0x00, 0x00,
+    0x0f, 0xff, 0xff, 0xfc, 0xff, 0xc0, 0xfc, 0x0f, 0xc3, 0xf8, 0x00, 0x3f,
+    0x00, 0x00, 0x0f, 0xff, 0xff, 0xf1, 0xff, 0xc0, 0xfc, 0x0f, 0xc7, 0xf8,
+    0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0x8f, 0xff, 0xc0, 0xfc, 0x0f,
+    0xcf, 0xf0, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xfc, 0x3f, 0xff, 0xc0,
+    0xfc, 0x0f, 0xcf, 0xe0, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xe0, 0xff,
+    0xff, 0xc0, 0xfc, 0x0f, 0xdf, 0xe0, 0x00, 0x3f, 0xff, 0xf0, 0x0f, 0xfe,
+    0x0f, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 0xff, 0xf0, 0x00, 0x3f, 0xff, 0xf0,
+    0x0f, 0x80, 0xff, 0xff, 0xff, 0xc0, 0xfc, 0x0f, 0xff, 0xf8, 0x00, 0x3f,
+    0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x0f, 0xff, 0xf8,
+    0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc0, 0xfc, 0x0f,
+    0xfd, 0xfc, 0x00, 0x3f, 0xff, 0xf0, 0x0f, 0xf8, 0x1f, 0xff, 0xff, 0xc0,
+    0xfc, 0x0f, 0xf8, 0xfc, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xc1, 0xff,
+    0xff, 0xc0, 0xfc, 0x0f, 0xf0, 0xfe, 0x00, 0x3f, 0x00, 0x00, 0x0f, 0xff,
+    0xf8, 0x7f, 0xff, 0xc0, 0xfc, 0x0f, 0xe0, 0x7f, 0x00, 0x3f, 0x00, 0x00,
+    0x0f, 0xff, 0xff, 0x0f, 0xff, 0xc0, 0xfc, 0x0f, 0xe0, 0x7f, 0x00, 0x3f,
+    0x00, 0x00, 0x0f, 0xff, 0xff, 0xe3, 0xff, 0xc0, 0xfc, 0x0f, 0xc0, 0x3f,
+    0x80, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf8, 0xff, 0xc0, 0xfc, 0x0f,
+    0xc0, 0x3f, 0x80, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfe, 0x3f, 0xc0,
+    0xfc, 0x0f, 0xc0, 0x1f, 0xc0, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff,
+    0x9f, 0xc0, 0xfc, 0x0f, 0xc0, 0x0f, 0xe0, 0x3f, 0x00, 0x00, 0x0f, 0xff,
+    0xff, 0xff, 0xc7, 0xc0, 0xfc, 0x0f, 0xc0, 0x0f, 0xe0, 0x3f, 0x00, 0x00,
+    0x0f, 0xff, 0xff, 0xff, 0xf3, 0xc0, 0xfc, 0x0f, 0xc0, 0x07, 0xf0, 0x3f,
+    0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xf9, 0xc0, 0xfc, 0x0f, 0xc0, 0x07,
+    0xf0, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xfc, 0xc0, 0xfc, 0x0f,
+    0xc0, 0x03, 0xf8, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xfe, 0x40,
+    0xfc, 0x0f, 0xc0, 0x03, 0xfc, 0x3f, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff,
+    0xff, 0x00, 0xfc, 0x0f, 0xc0, 0x01, 0xfc, 0x3f, 0x00, 0x00, 0x0f, 0xff,
+    0xff, 0xff, 0xff, 0x80};
 //__________________________________________
 
-//how many clients should be able to telnet to this ESP32
+// how many clients should be able to telnet to this ESP32
 #define MAX_SRV_CLIENTS 10
 
 #define SDA 5
 #define SCL 32
 
-#define ISMYADDR() (rxbuf[1] == '0' && (rxbuf[2] == '0' )) //|| rxbuf[2] == '1' || rxbuf[2] == '2' || rxbuf[2] == '3') )
+#define ISMYADDR() (rxbuf[1] == '0' && (rxbuf[2] == '0')) //|| rxbuf[2] == '1' || rxbuf[2] == '2' || rxbuf[2] == '3') )
 
-Adafruit_ADS1115 ads(0x48); /* Use this for the 16-Bit version */
+Adafruit_ADS1115 ads(0x48); //Use this for the 16-Bit version
 
 WiFiServer server(2323);
 WiFiClient serverClients[MAX_SRV_CLIENTS];
 
-//used to check the number every time, cause could changed
+// used to check the number every time, cause could changed
 volatile static bool eth_connected = false;
 
+bool show_connection = true;
 uint8_t rxcnt = 0, txpoint = 0;
-uint8_t rxbuf[11];
-uint8_t txbuf[12];
-uint8_t val, new_gain;
+uint8_t rxbuf[11], txbuf[12];
+uint8_t val, new_gain, new_unit;
+float vol_div_fac, dev_trans_fac;
+uint16_t new_vol_div_fac, new_dev_trans_fac;
 int16_t adc0, adc1, adc2, adc3;
 float fadc0, fadc1, fadc2, fadc3;
+float offset0, offset1, offset2, offset3;
+int16_t new_offset_val;
+int chan_offset_num, offset_val;
 uint8_t setGAIN = 0xFFFF;
 float setADCconversion;
 float acGAIN[] = {0.1875, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125};
 adsGain_t asetGAIN[] = {GAIN_TWOTHIRDS, GAIN_ONE, GAIN_TWO, GAIN_FOUR, GAIN_EIGHT, GAIN_SIXTEEN};
 int counter = 0;
-
-
-void WiFiEvent(WiFiEvent_t event)
-{
-  switch (event){
-    case SYSTEM_EVENT_ETH_START:
-      Serial.println("ETH Started");
-      //set eth hostname here
-      digitalWrite(2,LOW);
-      digitalWrite(15,HIGH);
-      delay(500);
-      digitalWrite(15, LOW); 
-      ETH.setHostname("esp32-ethernet");
-      break;
-      
-    case SYSTEM_EVENT_ETH_CONNECTED:
-      Serial.println("ETH Connected");
-      digitalWrite(2,LOW);
-      digitalWrite(15,HIGH);
-      break;
-      
-    case SYSTEM_EVENT_ETH_GOT_IP:
-      Serial.print("ETH MAC: ");
-      Serial.print(ETH.macAddress());
-      Serial.print(", IPv4: ");
-      Serial.print(ETH.localIP());
-      if (ETH.fullDuplex()) {
-        Serial.print(", FULL_DUPLEX");
-      }
-      Serial.print(", ");
-      Serial.print(ETH.linkSpeed());
-      Serial.println("Mbps");
-      eth_connected = true;
-      break;
-      
-    case SYSTEM_EVENT_ETH_DISCONNECTED:
-      Serial.println("ETH Disconnected");
-      digitalWrite(15,LOW);
-      digitalWrite(2,HIGH);
-      eth_connected = false;
-      break;
-      
-    case SYSTEM_EVENT_ETH_STOP:
-      Serial.println("ETH Stopped");
-      digitalWrite(15,LOW);
-      digitalWrite(2,HIGH);
-      eth_connected = false;
-      break;
-      
-    default:
-      break;
+String possible_units[] = {"mV", "mA", "mbar", "degC"};
+String unit;
+
+void WiFiEvent(WiFiEvent_t event) {
+  switch (event) {
+  case SYSTEM_EVENT_ETH_START:
+    Serial.println("ETH Started");
+    // set eth hostname here
+    digitalWrite(2, LOW);
+    digitalWrite(15, HIGH);
+    delay(500);
+    digitalWrite(15, LOW);
+    ETH.setHostname("esp32-ethernet");
+    break;
+
+  case SYSTEM_EVENT_ETH_CONNECTED:
+    Serial.println("ETH Connected");
+    digitalWrite(2, LOW);
+    digitalWrite(15, HIGH);
+    break;
+
+  case SYSTEM_EVENT_ETH_GOT_IP:
+    Serial.print("ETH MAC: ");
+    Serial.print(ETH.macAddress());
+    Serial.print(", IPv4: ");
+    Serial.print(ETH.localIP());
+    if (ETH.fullDuplex()) {
+      Serial.print(", FULL_DUPLEX");
+    }
+    Serial.print(", ");
+    Serial.print(ETH.linkSpeed());
+    Serial.println("Mbps");
+    eth_connected = true;
+    break;
+
+  case SYSTEM_EVENT_ETH_DISCONNECTED:
+    Serial.println("ETH Disconnected");
+    digitalWrite(15, LOW);
+    digitalWrite(2, HIGH);
+    eth_connected = false;
+    break;
+
+  case SYSTEM_EVENT_ETH_STOP:
+    Serial.println("ETH Stopped");
+    digitalWrite(15, LOW);
+    digitalWrite(2, HIGH);
+    eth_connected = false;
+    break;
+
+  default:
+    break;
   }
 }
 
-void setup(){
-//for Telnet Server Connection   
-  pinMode(2, OUTPUT); // yellow LED
-  pinMode(15, OUTPUT); // green LED 
+void start_telnet() {
+  // for Telnet Server Connection
+  pinMode(2, OUTPUT);  // yellow LED
+  pinMode(15, OUTPUT); // green LED
   Serial.begin(115200);
   Serial.println("\nConnecting");
+  
   WiFi.onEvent(WiFiEvent);
   delay(1000);
-  //start UART and the server
-  ETH.begin(1,17,23,18,ETH_PHY_LAN8720,ETH_CLOCK_GPIO0_IN);
+  // start UART and the server
+  ETH.begin(1, 17, 23, 18, ETH_PHY_LAN8720, ETH_CLOCK_GPIO0_IN);
   server.begin();
   server.setNoDelay(true);
 
-  while (eth_connected == false);
-
   Serial.print("Ready! Use 'telnet ");
   Serial.print(ETH.localIP());
   Serial.println(" 2323' to connect");
 
-  //visual status for telnet work
-  digitalWrite(2,LOW);
-  digitalWrite(15,HIGH);
+  // visual status for telnet work
+  digitalWrite(2, LOW);
+  digitalWrite(15, HIGH);
+}
 
-//for I2C Connection
+void setup() {
+  start_telnet();
+  // for I2C Connection
   Wire.begin(SDA, SCL); // Initiate the Wire library
 
-  //Setting for external ADC measurment range  
-  // val                                                            ADS1015  ADS1115
-  //                                                                -------  -------
-  // 0 ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV
-  // 1 ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
-  // 2 ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
-  // 3 ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
-  // 4 ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
-  // 5 ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV
-
-  val = 2; //chose as default for external adc setting
-  set_adc_gain(val); 
+  // for display__________________________________________________________
+  restart_screen();
+  start_screen();
+  connection_screen();
+  // test_screen();
+
+//Setting for external ADC measurment range  
+// val                                                            ADS1015  ADS1115
+//                                                                -------  -------
+// 0 ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV
+// 1 ads.setGain(GAIN_ONE);        // 1x gain   +/- 4.096V  1 bit = 2mV      0.125mV
+// 2 ads.setGain(GAIN_TWO);        // 2x gain   +/- 2.048V  1 bit = 1mV      0.0625mV
+// 3 ads.setGain(GAIN_FOUR);       // 4x gain   +/- 1.024V  1 bit = 0.5mV    0.03125mV
+// 4 ads.setGain(GAIN_EIGHT);      // 8x gain   +/- 0.512V  1 bit = 0.25mV   0.015625mV
+// 5 ads.setGain(GAIN_SIXTEEN);    // 16x gain  +/- 0.256V  1 bit = 0.125mV  0.0078125mV
+
+  val = 2; // chose as default for external adc setting
+  set_adc_gain(val);
+
+// Chose right Unit
+// val  Unit
+// 0    mV
+// 1    mA
+// 2    mbar
+// 3    degC
+
+  new_unit = 0; //default mV
+  set_unit(new_unit);
+
+// Channel Offset
+  new_offset_val = 0; //default
+  chan_offset_num = 5; //default all channels
+  set_offset(new_offset_val, chan_offset_num);
+
+// Device Transformationfactor
+  new_dev_trans_fac = 1000; //default
+  set_device_transformation_factor(new_dev_trans_fac);
+
+// Input voltage divider
+  new_vol_div_fac = 1000; //default w/o voltage devider, 1000 cause will devider by 1000 to sent float by telnet
+  set_voltage_divider_factor(new_vol_div_fac);
 
   Serial.print("\nADC Settings");
-  Serial.print("\nActual Gainfactor: "); Serial.print(asetGAIN[val]);
-  Serial.print("\nConversionfactor: "); Serial.print(setADCconversion); Serial.println();
+  Serial.print("\nActual Gainfactor: ");
+  Serial.print(asetGAIN[val]);
+  Serial.print("\nConversionfactor: ");
+  Serial.print(setADCconversion);
+  Serial.println();
 
-//for display__________________________________________________________
-  restart_screen();
-  start_screen();
-  //test_screen();
 }
 
 void restart_screen() {
   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
-  if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, false, false)) {
+  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS, false, false)) {
     Serial.println(F("SSD1306 allocation failed"));
-    for(;;); // Don't proceed, loop forever
+    for (;;); // Don't proceed, loop forever
   }
 
   // Show initial display buffer contents on the screen --
   // the library initializes this with an Adafruit splash screen.
-  //display.display();
-  
+  // display.display();
+
   delay(1000); // Pause for 2 seconds
   display.clearDisplay();
 }
 
-void start_screen() { 
+void start_screen() {
   display.clearDisplay();
-  display.setTextSize(1);      // Normal 1:1 pixel scale
+  display.setTextSize(1);              // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE); // Draw white text
-  display.cp437(true);         // Use full 256 char 'Code Page 437' font
+  display.cp437(true);                 // Use full 256 char 'Code Page 437' font
 
   display.drawBitmap(0, 0, logo_bmp, imageWidth, imageHeight, SSD1306_WHITE);
   display.setCursor(108, 0);
@@ -241,17 +285,36 @@ void start_screen() {
   display.write("J.M.");
   display.setCursor(108, 24);
   display.write("O.A.");
-  
+
   display.display();
-  delay(3000); // Pause for 2 seconds
-  }
+  delay(3000); // Pause for 3 seconds
+}
+
+void connection_screen() {
+  display.clearDisplay();
+  display.setTextSize(1);              // Normal 1:1 pixel scale
+  display.setTextColor(SSD1306_WHITE); // Draw white text
+  display.cp437(true);                 // Use full 256 char 'Code Page 437' font
+
+  display.setCursor(0, 0);
+  display.write("ETH MAC:");
+  display.setCursor(25, 8);
+  display.print(ETH.macAddress());
+  display.setCursor(0, 16);
+  display.print("IPv4:");
+  display.setCursor(25, 24);
+  display.print(ETH.localIP());
+
+  display.display();
+  delay(5000); // Pause for 5 seconds
+}
 
 void test_screen() {
   display.clearDisplay();
-  display.setTextSize(1);      // Normal 1:1 pixel scale
+  display.setTextSize(1);              // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE); // Draw white text
   display.setCursor(0, 0);
-  display.cp437(true);         // Use full 256 char 'Code Page 437' font
+  display.cp437(true); // Use full 256 char 'Code Page 437' font
   display.write("CHECKER");
   display.display();
   display.startscrollright(0x00, 0x07);
@@ -259,86 +322,97 @@ void test_screen() {
   display.stopscroll();
 }
 
-void show_CH() {
+void show_CH(String unit) {
   display.clearDisplay();
-  
-  display.setTextSize(2);      // Normal 1:1 pixel scale
+
+  display.setTextSize(2);              // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE); // Draw white text
-  display.cp437(true);         // Use full 256 char 'Code Page 437' font
+  display.cp437(true);                 // Use full 256 char 'Code Page 437' font
   display.setCursor(0, 0);
   display.write("CH1");
-  display.setCursor(SCREEN_WIDTH*5/8, 0);
+  display.setCursor(SCREEN_WIDTH * 5 / 8, 0);
   display.write("CH3");
-  display.setCursor(0, SCREEN_HEIGHT/2);
+  display.setCursor(0, SCREEN_HEIGHT / 2);
   display.write("CH2");
-  display.setCursor(SCREEN_WIDTH*5/8, SCREEN_HEIGHT/2);
+  display.setCursor(SCREEN_WIDTH * 5 / 8, SCREEN_HEIGHT / 2);
   display.write("CH4");
-  display.setCursor(SCREEN_WIDTH*10/28, SCREEN_HEIGHT*1/4);
-  display.write("mV"); 
-  delay(500);
+  display.setTextSize(1);
+  if (unit.length() == 4) {
+    display.setCursor(SCREEN_WIDTH * 10 / 28, SCREEN_HEIGHT * 2 / 5);
+  } else if (unit.length() == 2) {
+    display.setCursor(SCREEN_WIDTH * 11 / 28, SCREEN_HEIGHT * 2 / 5);
+  }
+  display.print(unit);
+  delay(1000);
   display.display();
-  
 }
 
-void show_VAL(int dadc0, int dadc1, int dadc2, int dadc3) {
+void show_VAL(int dadc0, int dadc1, int dadc2, int dadc3, String unit) {
   display.clearDisplay();
-  
-  display.setTextSize(2);      // Normal 1:1 pixel scale
+
+  display.setTextSize(2);              // Normal 1:1 pixel scale
   display.setTextColor(SSD1306_WHITE); // Draw white text
-  display.cp437(true);         // Use full 256 char 'Code Page 437' font
+  display.cp437(true);                 // Use full 256 char 'Code Page 437' font
   display.setCursor(0, 0);
   display.print(dadc0);
-  display.setCursor(SCREEN_WIDTH*5/8, 0);
+  display.setCursor(SCREEN_WIDTH * 5 / 8, 0);
   display.print(dadc2);
-  display.setCursor(0, SCREEN_HEIGHT/2 );
+  display.setCursor(0, SCREEN_HEIGHT / 2);
   display.print(dadc1);
-  display.setCursor(SCREEN_WIDTH*5/8, SCREEN_HEIGHT/2 );
+  display.setCursor(SCREEN_WIDTH * 5 / 8, SCREEN_HEIGHT / 2);
   display.print(dadc3);
-  display.setCursor(SCREEN_WIDTH*10/28, SCREEN_HEIGHT*1/4);
-  display.write("mV"); 
-  delay(1000);
+  display.setTextSize(1);
+  if (unit.length() == 4) {
+    display.setCursor(SCREEN_WIDTH * 10 / 28, SCREEN_HEIGHT * 2 / 5);
+  } else if (unit.length() == 2) {
+    display.setCursor(SCREEN_WIDTH * 11 / 28, SCREEN_HEIGHT * 2 / 5);
+  }
+  display.print(unit);
+  delay(1);
   display.display();
-  
 }
 
-void loop(){
-//for Telnet Server Connection    
+void loop() {
+  // for Telnet Server Connection
   uint8_t i;
   if (eth_connected == true) {
-    //check if there are any new clients
+    // check if there are any new clients
     if (server.hasClient()) {
-      for(i = 0; i < MAX_SRV_CLIENTS; i++) {
-        //find free/disconnected spot
+      for (i = 0; i < MAX_SRV_CLIENTS; i++) {
+        // find free/disconnected spot
         if (!serverClients[i] || !serverClients[i].connected()) {
-          if(serverClients[i]) serverClients[i].stop();
+          if (serverClients[i])
+            serverClients[i].stop();
           serverClients[i] = server.available();
-          if (!serverClients[i]) Serial.println("available broken");
+          if (!serverClients[i])
+            Serial.println("available broken");
           Serial.print("\nNew client: ");
-          Serial.print(i); Serial.print(' ');
+          Serial.print(i);
+          Serial.print(' ');
           Serial.println(serverClients[i].remoteIP());
           break;
         }
       }
       if (i >= MAX_SRV_CLIENTS) {
-        //no free/disconnected spot so reject
+        // no free/disconnected spot so reject
         server.available().stop();
       }
     }
-    //check clients for data
+    // check clients for data
     String getstring;
 
-    for(i = 0; i < MAX_SRV_CLIENTS; i++) {
+    for (i = 0; i < MAX_SRV_CLIENTS; i++) {
       if (serverClients[i] && serverClients[i].connected()) {
-        if(serverClients[i].available()) {
-          //get data from the telnet client and push it to I2C
-          while(serverClients[i].available()) {getstring = char(serverClients[i].read());
-            for(uint8_t m=0; m < getstring.length(); m++){
+        if (serverClients[i].available()) {
+          // get data from the telnet client and push it to I2C
+          while (serverClients[i].available()) {
+            getstring = char(serverClients[i].read());
+            for (uint8_t m = 0; m < getstring.length(); m++) {
               getdata(getstring.charAt(m));
             }
           }
         }
-      }
-      else {
+      } else {
         if (serverClients[i]) {
           serverClients[i].stop();
         }
@@ -346,29 +420,58 @@ void loop(){
     }
   }
 
-  get_adc_val(); //get the actual measured values from adc
-  delay(1000);
+  get_adc_val(); // get the actual measured values from adc
+
+  delay(100);
+}
+
+void set_offset(int16_t new_offset_val, int chan_offset_num) {
+  if (chan_offset_num == 0) {
+    offset0 = new_offset_val;
+  } else if (chan_offset_num == 1) {
+    offset1 = new_offset_val;
+  } else if (chan_offset_num == 2) {
+    offset2 = new_offset_val;
+  } else if (chan_offset_num == 3) {
+    offset3 = new_offset_val;
+  } else if (chan_offset_num == 5) {
+    offset0 = new_offset_val;
+    offset1 = new_offset_val;
+    offset2 = new_offset_val;
+    offset3 = new_offset_val;
   }
+}
+
+void set_voltage_divider_factor(float new_vol_div_fac) {
+  vol_div_fac = new_vol_div_fac/1000.0;
+}
+
+void set_device_transformation_factor(float new_dev_trans_fac) {
+  dev_trans_fac = new_dev_trans_fac/1000.0;
+}
+
+void set_unit(uint8_t new_unit) {
+  unit = possible_units[new_unit];
+}
 
 void set_adc_gain(uint8_t new_gain) {
-  //Set the ADC Gain parameter and choose the right conversion factor
-  ads.setGain(asetGAIN[new_gain]); 
+  // Set the ADC Gain parameter and choose the right conversion factor
+  ads.setGain(asetGAIN[new_gain]);
 
   setADCconversion = acGAIN[new_gain];
-  }
+}
 
 void get_adc_val() {
-  //Get the actual ADC measurment values in dimension of mV
+  // Get the actual ADC measurment values in dimension of mV
   adc0 = ads.readADC_SingleEnded(0);
   adc1 = ads.readADC_SingleEnded(1);
   adc2 = ads.readADC_SingleEnded(2);
   adc3 = ads.readADC_SingleEnded(3);
 
-  fadc0 = adc0 * setADCconversion;
-  fadc1 = adc1 * setADCconversion;
-  fadc2 = adc2 * setADCconversion;
-  fadc3 = adc3 * setADCconversion;
+  fadc0 = adc0 * setADCconversion * vol_div_fac * dev_trans_fac + offset0;
+  fadc1 = adc1 * setADCconversion * vol_div_fac * dev_trans_fac + offset1;
+  fadc2 = adc2 * setADCconversion * vol_div_fac * dev_trans_fac + offset2;
+  fadc3 = adc3 * setADCconversion * vol_div_fac * dev_trans_fac + offset3;
 
   String sadc0 = String(fadc0);
   String sadc1 = String(fadc1);
@@ -376,172 +479,254 @@ void get_adc_val() {
   String sadc3 = String(fadc3);
 
   int dadc0 = fadc0;
-  int dadc1 = fadc1;  
+  int dadc1 = fadc1;
   int dadc2 = fadc2;
   int dadc3 = fadc3;
-  
-  String sbuf = String("\nAIN0: " + sadc0 + "mV\n" + "AIN1: " + sadc1 + "mV\n" + "AIN2: " + sadc2 + "mV\n" + "AIN3: " + sadc3 + "mV\n ");
+
+  //String unit = possible_units[new_unit];
+  String sbuf = String("\nAIN0: " + sadc0 + ' ' + unit + "\n" + "AIN1: " + sadc1 + ' ' + unit + "\n" + "AIN2: " + sadc2 + ' ' + unit + "\n" + "AIN3: " + sadc3 + ' ' + unit + "\n ");
 
   Serial.print(sbuf); // for serial output
-  
+
   size_t len = sbuf.length();
 
   uint8_t buf[len];
-  sbuf.toCharArray((char*)buf, len); // Copies the String’s characters to the supplied buffer.
+  sbuf.toCharArray((char *)buf, len); // Copies the String’s characters to the supplied buffer.
 
   counter += 1;
-    if (counter == 1) {
-      show_CH();
-    }
-    else if (counter == 4) {
-      counter = 0;
-    }
-    else {
-      show_VAL(dadc0, dadc1, dadc2, dadc3);
-    }
+  if (counter == 1) {
+    if (eth_connected == true) {
+      if (show_connection == true) {
+        connection_screen();
+        show_connection = false;
+        }
+      }
+    show_CH(unit);
+  } else if (counter == 100) {
+    counter = 0;
+  } else {
+    show_VAL(dadc0, dadc1, dadc2, dadc3, unit);
+  }
+
+  if (eth_connected == false) {
+    show_connection = true;
+  }
 
 send_answer_buf(buf, len); //for telnet output
send_answer_buf(buf, len); // for telnet continous output
 }
 
 uint8_t nib_to_hex(uint16_t in, uint8_t nib) {
-  uint8_t t = (in >> (nib*4)) & 0xF;
-  if (t <= 9) {return t + 0x30;}
-  return t - 10 + 0x61;
-  }
-uint8_t hex_to_int(uint8_t h) { //assumes valid number
-  if (h < 0x40) return h-0x30;
-  if (h < 0x50) return h-0x41+10;
-                return h-0x61+10;
+  uint8_t t = (in >> (nib * 4)) & 0xF;
+  if (t <= 9) {
+    return t + 0x30;
   }
+  return t - 10 + 0x61;
+}
+
+uint8_t hex_to_int(uint8_t h) { // assumes valid number
+  if (h < 0x40)
+    return h - 0x30;
+  if (h < 0x50)
+    return h - 0x41 + 10;
+  return h - 0x61 + 10;
+}
 
-void sub1(uint8_t* c1, uint8_t* c2) {
-  uint8_t b = hex_to_int(*c1)*16 + hex_to_int(*c2);
+void sub1(uint8_t *c1, uint8_t *c2) {
+  uint8_t b = hex_to_int(*c1) * 16 + hex_to_int(*c2);
   b -= 1;
-  *c1 = nib_to_hex(b,1);
-  *c2 = nib_to_hex(b,0);
-  }
+  *c1 = nib_to_hex(b, 1);
+  *c2 = nib_to_hex(b, 0);
+}
 
-void send_answer_buf(uint8_tbuf, size_t len) {
+void send_answer_buf(uint8_t *buf, size_t len) {
   uint8_t i;
-  for(i = 0; i < MAX_SRV_CLIENTS; i++) {
+  for (i = 0; i < MAX_SRV_CLIENTS; i++) {
     if (serverClients[i] && serverClients[i].connected()) {
       serverClients[i].write(buf, len);
       delay(1);
-      }
     }
   }
+}
 
-void send_answer_hex(uint8_trxbuf, uint16_t v) {
-  txbuf[0]='A';
-  txbuf[1]=rxbuf[1];
-  txbuf[2]=rxbuf[2];
-  txbuf[3]=rxbuf[3];//Switch deactivated
-  txbuf[4]=rxbuf[4];
-  txbuf[5]=rxbuf[5];
-  txbuf[6]=nib_to_hex(v,3);
-  txbuf[7]=nib_to_hex(v,2);
-  txbuf[8]=nib_to_hex(v,1);
-  txbuf[9]=nib_to_hex(v,0);
-  txbuf[10]='\n';
+void send_answer_hex(uint8_t *rxbuf, uint16_t v) {
+  txbuf[0] = 'A';
+  txbuf[1] = rxbuf[1];
+  txbuf[2] = rxbuf[2];
+  txbuf[3] = rxbuf[3]; // Switch deactivated
+  txbuf[4] = rxbuf[4];
+  txbuf[5] = rxbuf[5];
+  txbuf[6] = nib_to_hex(v, 3);
+  txbuf[7] = nib_to_hex(v, 2);
+  txbuf[8] = nib_to_hex(v, 1);
+  txbuf[9] = nib_to_hex(v, 0);
+  txbuf[10] = '\n';
   txbuf[11] = 0;
   size_t len = 12;
   send_answer_buf(txbuf, len);
-  }
+}
 
 void forward_msg(uint8_t i) {
-  sub1(&rxbuf[1],&rxbuf[2]);
-  memcpy ((uint8_t*)txbuf,(uint8_t*)rxbuf,i);
+  sub1(&rxbuf[1], &rxbuf[2]);
+  memcpy((uint8_t *)txbuf, (uint8_t *)rxbuf, i);
   txbuf[i] = 0;
-//  send_answer_buf(txbuf);
-  }  
+  //  send_answer_buf(txbuf);
+}
+
 uint8_t is_my_address(uint8_t s) {
   if (ISMYADDR()) {
-    //rxbuf[2] -= '0'; // write number to buffer, instead of ascii.
+    // rxbuf[2] -= '0'; // write number to buffer, instead of ascii.
     return 1;
   } else {
     forward_msg(s);
     return 0;
   }
 }
-                  
+
 void getdata(uint8_t buf) {
   // get data by register mode
   if (rxcnt != 0 || (buf == 'A' || buf == 'W' || buf == 'R')) {
     rxbuf[rxcnt++] = buf;
   }
-  if (buf == '\n' || buf == '\r') {  //End of Command
+  if (rxcnt != 0 & buf == '\n' || buf == '\r') { // End of Command
 
-//answer
+    // answer
     if (rxbuf[0] == 'A') {
-    
-        memcpy ((uint8_t*)txbuf,(uint8_t*)rxbuf,10);
-        txbuf[11] = 0;
-        size_t len = 12;
-        send_answer_buf(txbuf, len);
+      memcpy((uint8_t *)txbuf, (uint8_t *)rxbuf, 10);
+      txbuf[11] = 0;
+      size_t len = 12;
+      send_answer_buf(txbuf, len);
     } else if (rxbuf[0] == 'S') { // Scann of chain, returns number of boards
-          txbuf[0]  = 'S';
-          uint8_t length = rxcnt - 2 ; // Length of Counter
-          //read current counter value
-          uint32_t cnt = 0;
-          if (length == 0){
-            length = 1;
-          } else {
-            uint32_t base = 1;
-            for (uint8_t i = length; i > 0; i--){
-              cnt += hex_to_int(rxbuf[i])*base;
-              base *= 16;
-            }
+
+      txbuf[0] = 'S';
+      uint8_t length = rxcnt - 2; // Length of Counter
+      // read current counter value
+      uint32_t cnt = 0;
+      if (length == 0) {
+        length = 1;
+      } else {
+        uint32_t base = 1;
+        for (uint8_t i = length; i > 0; i--) {
+          cnt += hex_to_int(rxbuf[i]) * base;
+          base *= 16;
+        }
+      }
+      // inc counter value
+      cnt++;
+      // send to next uC
+      if ((cnt % 16) == 0)
+        length++;
+      for (uint8_t i = length; i > 0; i--) {
+        txbuf[i] = nib_to_hex(cnt, length - i);
+      }
+      if (length > 8)
+        length = 8; // skip to keep a clean ending of message
+      txbuf[length + 1] = 10;
+      txbuf[length + 2] = 0;
+      send_answer_buf(txbuf, length);
+      rxcnt = 0;
+    } else if (is_my_address(10)) { // message is for this uC
+
+      // write
+      if (rxbuf[0] == 'W') {
+        // ADCsettings
+        if (hex_to_int(rxbuf[5]) == 9) {
+          //    uint8_t val =
+          //    (hex_to_int(rxbuf[7])*16+hex_to_int(rxbuf[8]))&0xFF;
+          new_gain = (hex_to_int(rxbuf[9]));
+          set_adc_gain(new_gain);
+
+          send_answer_hex(&rxbuf[0], new_gain);
+        }
+        if (hex_to_int(rxbuf[5]) == 11) {
+          //units
+          if (hex_to_int(rxbuf[4]) == 0) {
+            new_unit = (hex_to_int(rxbuf[9]));
+            set_unit(new_unit);
+  
+            send_answer_hex(&rxbuf[0], new_unit);
           }
-          // inc counter value
-          cnt++;
-          //send to next uC
-          if ((cnt % 16) == 0) length++;
-          for (uint8_t i = length; i > 0; i--){
-              txbuf[i] = nib_to_hex(cnt,length-i);
+          
+          //transformationfactor
+          if (hex_to_int(rxbuf[4]) == 1) {
+            new_dev_trans_fac = (hex_to_int(rxbuf[6]) * 4096 + hex_to_int(rxbuf[7]) * 256 + hex_to_int(rxbuf[8]) * 16 + hex_to_int(rxbuf[9]));
+            set_device_transformation_factor(new_dev_trans_fac);
+
+            send_answer_hex(&rxbuf[0], new_dev_trans_fac);
           }
-          if (length > 8) length = 8; // skip to keep a clean ending of message
-          txbuf[length+1] = 10;
-          txbuf[length+2] = 0;
-          send_answer_buf(txbuf, length);
-          rxcnt = 0;
-    } else if (is_my_address(10)){ // message is for this uC
-
-//write 
-    if (rxbuf[0] == 'W'){
-    //ADCsettings
-    if (hex_to_int(rxbuf[5]) == 9) {
-//    uint8_t val = (hex_to_int(rxbuf[7])*16+hex_to_int(rxbuf[8]))&0xFF;
-    new_gain = (hex_to_int(rxbuf[7])*16+hex_to_int(rxbuf[8]))&0xFF;
-
-    set_adc_gain(new_gain);
-
-    send_answer_hex(&rxbuf[0], new_gain);
-    }
-    }
+          
+          //input Voltage Divider
+          if (hex_to_int(rxbuf[4]) == 2) {
+            new_vol_div_fac = (hex_to_int(rxbuf[6]) * 4096 + hex_to_int(rxbuf[7]) * 256 + hex_to_int(rxbuf[8]) * 16 + hex_to_int(rxbuf[9]));
+            set_voltage_divider_factor(new_vol_div_fac);
 
-//read
-    if (rxbuf[0] == 'R'){
-    //read single ADC Channel
-    if (hex_to_int(rxbuf[5]) == 10) {
-    uint16_t adc_val = 0xFFFF;
-        //CH0
-        if (hex_to_int(rxbuf[4]) == 0) {adc_val=fadc0*16;
+            send_answer_hex(&rxbuf[0], new_vol_div_fac);
+          }
         }
-        //CH1  
-        if (hex_to_int(rxbuf[4]) == 1) {adc_val=fadc1*16;
+        if (hex_to_int(rxbuf[5]) == 12) {
+          //offset
+          new_offset_val = (hex_to_int(rxbuf[6]) * 4096 + hex_to_int(rxbuf[7]) * 256 + hex_to_int(rxbuf[8]) * 16 + hex_to_int(rxbuf[9]));
+          chan_offset_num = (hex_to_int(rxbuf[4]));
+          set_offset(new_offset_val, chan_offset_num); 
+
+          send_answer_hex(&rxbuf[0], new_offset_val);
+          }
+      }
+
+      // read
+      if (rxbuf[0] == 'R'){
+        // read single ADC Channel
+        if (hex_to_int(rxbuf[5]) == 10) {
+          uint16_t adc_val = 0xFFFF;
+          // CH0
+          if (hex_to_int(rxbuf[4]) == 0) {
+            adc_val = fadc0 * 16;
+          }
+          // CH1
+          if (hex_to_int(rxbuf[4]) == 1) {
+            adc_val = fadc1 * 16;
+          }
+          // CH2
+          if (hex_to_int(rxbuf[4]) == 2) {
+            adc_val = fadc2 * 16;
+          }
+          // CH3
+          if (hex_to_int(rxbuf[4]) == 3) {
+            adc_val = fadc3 * 16;
+          }
+          send_answer_hex(&rxbuf[0], adc_val);
         }
-        //CH2
-        if (hex_to_int(rxbuf[4]) == 2) {adc_val=fadc2*16;
+        if (hex_to_int(rxbuf[5]) == 11) {
+          uint16_t device_set = 0xFFFF;
+          if (hex_to_int(rxbuf[4]) == 1) {
+            device_set = dev_trans_fac;
+          }
+          if (hex_to_int(rxbuf[4]) == 2) {
+            device_set = vol_div_fac;
+          }
+          send_answer_hex(&rxbuf[0], device_set);
         }
-        //CH3  
-        if (hex_to_int(rxbuf[4]) == 3) {adc_val=fadc3*16;
+        if (hex_to_int(rxbuf[5]) == 12) {
+          uint16_t device_set = 0xFFFF;
+          if (hex_to_int(rxbuf[4]) == 0) {
+            offset_val = offset0;
+          }
+          if (hex_to_int(rxbuf[4]) == 1) {
+            offset_val = offset1;
+          }
+          if (hex_to_int(rxbuf[4]) == 2) {
+            offset_val = offset2;
+          }
+          if (hex_to_int(rxbuf[4]) == 3) {
+            offset_val = offset3;
+          }
+          if (hex_to_int(rxbuf[4]) == 5) {
+            offset_val = offset0;
+          }
+          send_answer_hex(&rxbuf[0], offset_val);
         }
-    send_answer_hex(&rxbuf[0], adc_val);                                        
-    }
-    }
+      }
     }
-    if (rxcnt >= 10 || buf == '\n' || buf == '\r') { rxcnt = 0; }
     }
-  }
+  if (rxcnt >= 10 || buf == '\n' || buf == '\r') {
+  rxcnt = 0;}
+}
diff --git a/esp32/EthernetUART/LANTelnetToI2C_Board/live_telnet_data_plot.py b/esp32/EthernetUART/LANTelnetToI2C_Board/live_telnet_data_plot.py
new file mode 100644 (file)
index 0000000..9f596a8
--- /dev/null
@@ -0,0 +1,98 @@
+__author__ = "Artz, Ole"
+__email__ = "ole.artz@stud.uni-frankfurt.de"
+
+
+import socket
+import sys
+import matplotlib.pyplot as plt
+import matplotlib.animation as animation
+
+
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+AIN0_list = list()
+AIN1_list = list()
+AIN2_list = list()
+AIN3_list = list()
+
+unit = str()
+plot_title = str()
+filename = str(sys.argv[3]) #ADC_ETHERNET_val.txt
+
+
+fig = plt.figure('ADC_Ethernet 4 CH Measurment')
+ax1 = fig.add_subplot(1,1,1)
+
+def connection():
+    HOST = str(sys.argv[1]) #192.168.8.63
+    PORT = int(sys.argv[2]) #2323
+
+    s.connect( (HOST,PORT) )
+
+
+def get_data(): 
+    reader = s.recv(1024).decode()
+    try:
+        with open(filename, 'r') as file:
+            file_history = str(file.read())
+        with open(filename, "w") as file:
+            file.write(file_history + '\n' + str(reader))
+    except:
+        with open(filename, "w") as file:
+            file.write(str(reader))
+            file.close()
+
+    return reader
+
+
+def split_data(reader):
+    
+    unit = reader[reader.rfind(' ')+1:reader.rfind('\n')]
+    
+    AIN0_list.append(float(reader[reader.find('AIN0: ') + 6:reader.find(unit)-1]))
+    AIN1_list.append(float(reader[reader.find('AIN1: ') + 6:reader.find(unit, reader.find('AIN1: '))-1]))
+    AIN2_list.append(float(reader[reader.find('AIN2: ') + 6:reader.find(unit, reader.find('AIN2: '))-1]))
+    AIN3_list.append(float(reader[reader.find('AIN3: ') + 6:reader.find(unit, reader.find('AIN3: '))-1]))
+    
+    return unit
+
+# check for split data works fine    
+#    print(AIN0_list)
+#    print(AIN1_list)
+#    print(AIN2_list)
+#    print(AIN3_list)
+    
+
+def animate(i):
+    reader = get_data()        
+    unit = split_data(reader)
+        
+    ax1.clear()
+    ax1.plot(AIN0_list, 'r', label="AIN0")
+    ax1.plot(AIN1_list, 'b', label="AIN1")
+    ax1.plot(AIN2_list, 'g', label="AIN2")
+    ax1.plot(AIN3_list, 'y', label="AIN3")
+       
+    if unit == 'mV':
+        plot_title = 'Voltage'
+    elif unit == 'mA':
+        plot_title = 'Current'
+    elif unit == 'mbar':
+        plot_title = 'Pressure'
+    elif unit == 'degC':
+        plot_title = 'Temperature'
+    
+    plt.title(plot_title)
+    plt.xlabel('~0.5s')
+    plt.ylabel(unit)
+    plt.legend(loc=2)
+
+
+def main(): 
+    connection()
+    
+    ani = animation.FuncAnimation(fig, animate, interval=500)
+    plt.show()
+
+if __name__ == '__main__':
+    main()
diff --git a/esp32/EthernetUART/LANTelnetToI2C_Board/quickstart 4CH ADC_Ethernet Portable Board.pdf b/esp32/EthernetUART/LANTelnetToI2C_Board/quickstart 4CH ADC_Ethernet Portable Board.pdf
new file mode 100644 (file)
index 0000000..ec1532d
Binary files /dev/null and b/esp32/EthernetUART/LANTelnetToI2C_Board/quickstart 4CH ADC_Ethernet Portable Board.pdf differ
diff --git a/esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py b/esp32/EthernetUART/LANTelnetToI2C_Board/telnet_data_plot.py
new file mode 100644 (file)
index 0000000..44fb030
--- /dev/null
@@ -0,0 +1,86 @@
+__author__ = "Artz, Ole"
+__email__ = "ole.artz@stud.uni-frankfurt.de"
+
+import matplotlib.pyplot as plt
+import sys
+
+
+AIN0_list = list()
+AIN1_list = list()
+AIN2_list = list()
+AIN3_list = list()
+
+unit = str()
+plot_title = str()
+filename = str(sys.argv[1]) #ADC_ETHERNET_val.txt
+
+fig = plt.figure('ADC_Ethernet 4 CH Measurment')
+ax1 = fig.add_subplot(1,1,1)
+
+def split_data():
+    
+    with open(filename, "r") as file:
+        lines = file.readlines()
+        file.close()
+
+    for line in lines:
+        if line.startswith('AIN0'):
+            end_of_val = line.rfind(' ')
+            new_val = float(line[6:end_of_val])
+            
+            AIN0_list.append(new_val)
+
+            unit = line[end_of_val+1:len(line)-1]
+                    
+        if line.startswith('AIN1'):
+            end_of_val = line.rfind(' ')
+            new_val = float(line[6:end_of_val])
+            
+            AIN1_list.append(new_val)
+      
+        if line.startswith('AIN2'):
+            end_of_val = line.rfind(' ')
+            new_val = float(line[6:end_of_val])
+            
+            AIN2_list.append(new_val)
+
+        if line.startswith('AIN3'):
+            end_of_val = line.rfind(' ')
+            new_val = float(line[6:end_of_val])
+            
+            AIN3_list.append(new_val)
+
+    return unit
+
+
+def plotter():
+    unit = split_data()
+
+    ax1.clear()
+    ax1.plot(AIN0_list, 'r', label="AIN0")
+    ax1.plot(AIN1_list, 'b', label="AIN1")
+    ax1.plot(AIN2_list, 'g', label="AIN2")
+    ax1.plot(AIN3_list, 'y', label="AIN3")
+    
+    if unit == 'mV':
+        plot_title = 'Voltage'
+    elif unit == 'mA':
+        plot_title = 'Current'
+    elif unit == 'mbar':
+        plot_title = 'Pressure'
+    elif unit == 'degC':
+        plot_title = 'Temperature'
+    
+    plt.title(plot_title)
+    plt.xlabel('~0.5s')
+    plt.ylabel(unit)
+    plt.legend(loc=2)
+    
+    plt.show()
+        
+def main():
+    plotter()
+
+
+if __name__ == '__main__':
+    main()