diff --git a/platformio.ini b/platformio.ini index b73b326..657f13e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -369,3 +369,16 @@ build_flags = ${in-debug.build_flags} ${out-usbradio.build_flags} extends = micro, in-debug, out-switchusb src_filter = ${in-debug.src_filter} ${out-switchusb.src_filter} build_flags = ${in-debug.build_flags} ${out-switchusb.build_flags} + +# OhmMeter utility + +[ohm] +src_filter = -<*> + + +[env:esp32-ohm] +extends = esp32, ohm +src_filter = ${ohm.src_filter} + +[env:micro-ohm] +extends = micro, ohm +src_filter = ${ohm.src_filter} diff --git a/readme.md b/readme.md index 19ed06b..95fbf85 100644 --- a/readme.md +++ b/readme.md @@ -33,7 +33,7 @@ Wiring | 6 | 6 | 5 | - | - | - | - | - | P1-9 | | 7 | 7 | 18 | CE | - | - | - | - | P2-7* | | 8 | 8 | 19 | CSN | - | - | - | - | - | -| 9 | 9 | 21 | - | - | - | - | - | - | +| 9 | 9 > 1k Ω | 35 > 1k Ω | - | 330 Ω | 100 Ω | 220 Ω | 680 Ω | 470 Ω | | 10 | 10 | 3 | - | - | - | - | - | - | | 11 | 0 | 1 | - | - | - | - | - | P1-2 | | 12 | - | 22 | - | - | - | - | - | - | @@ -46,12 +46,13 @@ Wiring | 19 | 19 | 25 | - | DATA2 | - | - | - | P2-2 | | 20 | 20 | 33 | - | DATA3 | - | - | - | P2-3 | | 21 | 21 | 32 | - | DATA4 | - | - | - | P2-4 | -| 22 | - | 35 | - | - | - | - | - | - | +| 22 | - | - | - | - | - | - | - | - | | 23 | - | 3.3V VCC | 3.3V VCC | - | - | 3.3V VCC | 3.3V VCC | - | | 24 | 5V VCC OUT | 5V VCC | 5V VCC | 5V VCC | 5V VCC | - | 5V VCC | PX-5 5V VCC | | 25 | GND | GND | GND | GND | - | GND | GND | PX-8 GND | * 2nd player Genesis is incompatible with Radio because it uses the same pins, 1 player Genesis is compatible +Ω This is optional and only used for dongle detection. For DB-25 pin 9: On the micro, run to pin 9 to 5V VCC with a 1k resistor. On ESP32, run to pin 35 to 3.3V VCC with a 1k resistor. On each dongle, run a resistor of the given value between DB-25 pin 9 and GND. Credits / Links --------------- diff --git a/src/OhmMeter.cpp b/src/OhmMeter.cpp new file mode 100644 index 0000000..69f5a33 --- /dev/null +++ b/src/OhmMeter.cpp @@ -0,0 +1,64 @@ + +/* + https://www.circuitbasics.com/arduino-ohm-meter/ + +micro values: + +82: 81.31 +100: 98.71-99.89 + +*/ + +#if defined(ARDUINO_ARCH_ESP32) + +int analogPin = 35; +int Vin = 3.3; +auto steps = 4095.0; + +#else + +int analogPin = 9; +int Vin = 5; +auto steps = 1024.0; + +#endif // ARDUINO_ARCH_ESP32 + +// value of the known resistor +float R1 = 1000; + +#include "Arduino.h" + +int raw = 0; +float Vout = 0; +float R2 = 0; +float buffer = 0; + +void setup() { + Serial.begin(115200); +} + +void loop() { + raw = analogRead(analogPin); + if (raw) { + buffer = raw * Vin; + Vout = (buffer) / steps; + buffer = (Vin / Vout) - 1; + Serial.print("raw: "); + Serial.print(raw); + Serial.print(" Vout: "); + Serial.print(Vout); + + // this is R2 when it's connected to + and R1 is connected to ground + R2 = R1 * buffer; + Serial.print(" R2: "); + Serial.print(R2); + + // this is R2 when it's connected to ground, and R1 is connected to + + R2 = R1 / buffer; + Serial.print(" R2: "); + Serial.println(R2); + } else { + Serial.println("disconnected"); + } + delay(1000); +}