From cb3a07bb2559e39b67869fab8e8ab4927f722227 Mon Sep 17 00:00:00 2001 From: Liz Date: Tue, 15 Jul 2025 08:20:39 -0400 Subject: [PATCH] adding ideal diode examples --- .../.uno.test.only | 0 .../Arduino_Ideal_Diode_Monitor.ino | 45 +++++++++++++++++++ .../CircuitPython_Ideal_Diode_Monitor/code.py | 33 ++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/.uno.test.only create mode 100644 Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/Arduino_Ideal_Diode_Monitor.ino create mode 100644 Ideal_Diode_Examples/CircuitPython_Ideal_Diode_Monitor/code.py diff --git a/Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/.uno.test.only b/Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/.uno.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/Arduino_Ideal_Diode_Monitor.ino b/Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/Arduino_Ideal_Diode_Monitor.ino new file mode 100644 index 000000000..a4ad0e162 --- /dev/null +++ b/Ideal_Diode_Examples/Arduino_Ideal_Diode_Monitor/Arduino_Ideal_Diode_Monitor.ino @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +// LM73100 IMON Current Monitoring + +const int IMON_PIN = A0; // IMON connected to analog pin A0 +const float RIMON = 1500.0; // RIMON resistor value in ohms (1.5kΩ) +const float GIMON = 2.5; // GIMON typical value in μA/A (from datasheet, typical is 2.5) +const float VREF = 5.0; // Arduino reference voltage (5V for most Arduinos) +const int ADC_RESOLUTION = 1024; + +void setup() { + Serial.begin(9600); + pinMode(IMON_PIN, INPUT); + + Serial.println("LM73100 Current Monitor Started"); + Serial.println("================================"); + Serial.print("RIMON: "); + Serial.print(RIMON); + Serial.println(" ohms"); + Serial.print("GIMON: "); + Serial.print(GIMON); + Serial.println(" μA/A"); + Serial.println("================================\n"); +} + +void loop() { + int adcValue = analogRead(IMON_PIN); + float vimon = (adcValue * VREF) / ADC_RESOLUTION; + float iout_A = vimon / (RIMON * GIMON); + float iout_mA = iout_A * 1000.0; + + Serial.print("ADC Value: "); + Serial.print(adcValue); + Serial.print(" | VIMON: "); + Serial.print(vimon, 3); + Serial.print(" V | Output Current: "); + Serial.print(iout_mA, 2); + Serial.print(" mA ("); + Serial.print(iout_A, 3); + Serial.println(" A)"); + + delay(500); // Read every 500ms +} diff --git a/Ideal_Diode_Examples/CircuitPython_Ideal_Diode_Monitor/code.py b/Ideal_Diode_Examples/CircuitPython_Ideal_Diode_Monitor/code.py new file mode 100644 index 000000000..d9c98cce9 --- /dev/null +++ b/Ideal_Diode_Examples/CircuitPython_Ideal_Diode_Monitor/code.py @@ -0,0 +1,33 @@ +# SPDX-FileCopyrightText: 2025 Liz Clark for Adafruit Industries +# +# SPDX-License-Identifier: MIT +# LM73100 IMON Current Monitoring + +import time +import board +from analogio import AnalogIn + +RIMON = 1500.0 # 1.5kΩ +GIMON = 2.5 # μA/A +analog_in = AnalogIn(board.A0) + +def get_voltage(pin): + return (pin.value * 3.3) / 65536 + +print("LM73100 Current Monitor Started") +print("================================") +print(f"RIMON: {RIMON} ohms") +print(f"GIMON: {GIMON} μA/A") +print("================================\n") + +while True: + # Read voltage from IMON pin + vimon = get_voltage(analog_in) + + # Calculate output current + iout_A = vimon / (RIMON * GIMON) + iout_mA = iout_A * 1000.0 + + print(f"ADC: {analog_in.value} | VIMON: {vimon:.3f}V | Current: {iout_mA:.2f} mA") + + time.sleep(0.5)