Last active
November 10, 2025 09:37
-
-
Save maxpromer/9a0076f6c48caf9dc7432f76f3cb36a7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include <Wire.h> | |
| #include <IOXESP32_4-20mA_Receiver.h> | |
| Receiver4_20 sensor(&Wire, 0x45); // Default 0x45 | |
| void setup() { | |
| Serial.begin(115200); | |
| Wire.begin(); // Start I2C | |
| while (!sensor.begin()) { // Start ADC | |
| Serial.println("Not found hardware :("); | |
| delay(2000); | |
| } | |
| } | |
| void loop() { | |
| delay(100); | |
| if (sensor.measure()) { // Update analog value from ADC | |
| int16_t raw = sensor.raw(); // Read raw value (-32768 to 32767) | |
| float current = sensor.current(); // Read current in mA unit | |
| float percent = (current - 4.0) * 100.0 / (20.0 - 4.0); | |
| if (percent < 0) percent = 0; | |
| if (percent > 100) percent = 100; | |
| Serial.printf("Raw=%5d Current=%.02f mA Percent=%.02f%%\n", raw, current, percent); | |
| } else { | |
| Serial.println("Hardware error !"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment