/* Einfaches Leistungsmessgeraet 144MHz bis 10368MHz -40 bis +10dBm Am AD8317 Eingang ist ein 6dB Daempfungsglied fest eingebaut um die S11 zu verbessern. Kalibrieren: Bei offenen Messkopf mit Poti auf den gewaehlten Frequenzbereich "V= 0" einstellen Eine Korrekturkurve fuer die verschiedenen Frequenzbereich kann eingegeben werden. Die Korrekturkurve von -50 bis +10dBm fuer jeden Frequenzbereich ermitteln und eintragen. Mit der Set-Taste kann der Deltawert zB. Bodenrauschen oder Sonnenrauchen angenehm gemessen werden. Messkurve auch fuer 739MHz hinzugefuegt https://www.arduino.cc/en/Tutorial/BuiltInExamples/Smoothing https://github.com/RobTillaart/MultiMap https://www.analog.com/media/en/technical-documentation/data-sheets/ad8317.pdf */ #include LiquidCrystal_I2C lcd(0x27,16,2); String ver = "Version 1"; //Herbst 2021 String projekt = "Arduino P-Meter:"; #include "MultiMap.h" const int numReadings = 10; int d2 = 2; // Delta Messung int d3 = 3; // 2m int d4 = 4; // 70cm int d5 = 5; // 23cm int d6 = 6; // 13cm int d7 = 7; // 6cm int d8 = 8; // 3cm int d9 = 9; // 739MHz int readings[numReadings]; // the readings from the analog input int readIndex = 0; // the index of the current reading int total = 0; // the running total int average = 0; // the average int inputPin = A1; int k = 0; int i = 0; int ii = 0; float inp2[] = {2, 12, 26, 111, 185, 335, 402}; // Referenzwerte 2m float inp70[] = {7, 34, 104, 235, 328, 480, 576}; // Referenzwerte 70m float inp23[] = {17, 95, 237, 388, 542, 633, 759}; // Referenzwerte 23cm float inp13[] = {4, 37, 170, 266, 473, 564, 859}; // Referenzwerte 13cm float inp6[] = {0, 20, 60, 120, 240, 480, 800}; // Referenzwerte 6cm float inp3[] = {3, 10, 21, 123, 248, 456, 547}; // Referenzwerte 3cm float inp739[] = {17, 73, 179, 321, 415, 569, 682}; // Referenzwerte 739MHz float out[] = {-50, -40, -30, -20, -10, -0, 10}; float dBm = 0; float delta = 0; float deltaV = 0; char s[5]; //---------------------------------------------------------- void setup() { delay(1000); // wichtig wegen Bootloader // initialize serial communication with computer: Serial.begin(9600); // initialize all the readings to 0: for (int thisReading = 0; thisReading < numReadings; thisReading++) { readings[thisReading] = 0; } pinMode(d2, INPUT_PULLUP); pinMode(d2, INPUT_PULLUP); pinMode(d3, INPUT_PULLUP); pinMode(d4, INPUT_PULLUP); pinMode(d5, INPUT_PULLUP); pinMode(d6, INPUT_PULLUP); pinMode(d7, INPUT_PULLUP); pinMode(d8, INPUT_PULLUP); pinMode(d9, INPUT_PULLUP); lcd.init(); lcd.backlight(); lcd.setCursor(0,0); lcd.print(projekt); lcd.setCursor(0,1); lcd.print(ver); delay(3000); lcd.clear(); } //---------------------------------------------------------- void SerialPrint() { Serial.print(total); Serial.print(" "); Serial.print(average); Serial.print(" "); Serial.print(deltaV,1); Serial.print(" "); Serial.println(dBm,1); } //---------------------------------------------------------- void Display() { String z0, ss; dtostrf(k, 3, 0, s ); ss = s; z0 = "V=" + ss; dtostrf(deltaV, 5, 1, s ); ss = s; z0 = z0 + " D=" + ss + "dB"; lcd.setCursor(0,0); lcd.print(z0); //------------------ if (digitalRead(d3) == LOW) z0 = "2m "; if (digitalRead(d4) == LOW) z0 = "70cm"; if (digitalRead(d5) == LOW) z0 = "23cm"; if (digitalRead(d6) == LOW) z0 = "13cm"; if (digitalRead(d7) == LOW) z0 = "6cm "; if (digitalRead(d8) == LOW) z0 = "3cm "; if (digitalRead(d9) == LOW) z0 = "739M"; dtostrf(dBm, 5, 1, s ); ss = s; z0 = z0 + " P=" + ss + "dBm"; lcd.setCursor(0,1); lcd.print(z0); } //---------------------------------------------------------- void s_delay(unsigned long ms) { unsigned long start = millis(); while (millis() - start < ms); } //---------------------------------------------------------- void loop() { i++; ii++; total = total - readings[readIndex]; readings[readIndex] = analogRead(inputPin) - 10; total = total + readings[readIndex]; readIndex = readIndex + 1; if (readIndex >= numReadings) readIndex = 0; average = total / numReadings; k= average; // dBm = multiMap(average, inp70, out, 7); //----- if (digitalRead(d3) == LOW) dBm = multiMap(average, inp2, out, 7); if (digitalRead(d4) == LOW) dBm = multiMap(average, inp70, out, 7); if (digitalRead(d5) == LOW) dBm = multiMap(average, inp23, out, 7); if (digitalRead(d6) == LOW) dBm = multiMap(average, inp13, out, 7); if (digitalRead(d7) == LOW) dBm = multiMap(average, inp6, out, 7); if (digitalRead(d8) == LOW) dBm = multiMap(average, inp3, out, 7); if (digitalRead(d9) == LOW) dBm = multiMap(average, inp739, out, 7); //----- if (digitalRead(d2) == LOW) delta = dBm; // Set Delta deltaV = dBm - delta; if (readIndex < 1) { if (i > 50) { Display(); i = 0; } if (ii > 100) { SerialPrint(); ii = 0; } } s_delay(10); }