User Tools

Site Tools


en-us_commands:reference:ianalogread2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en-us_commands:reference:ianalogread2 [2026/09/07 23:35] – 바깥 편집 127.0.0.1en-us_commands:reference:ianalogread2 [2026/09/14 20:30] (current) – external edit 127.0.0.1
Line 14: Line 14:
  
 ===== Example ===== ===== Example =====
 +
 +This example scales the MPINO-8A4R(T)-S 4–20mA input ''A2'' to 0–100%.
  
 <code cpp> <code cpp>
 void setup() { void setup() {
-  analogReference(EXTERNAL);  // If required by the MPINO product 
   Serial.begin(115200);   Serial.begin(115200);
 } }
  
 void loop() { void loop() {
-  int32_t percent = IanalogRead2(A2, 0, 100);  // Map the 4–20mA input value to the specified integer range. +  const int32_t percent = IanalogRead2(A2, 0, 100);  // Scale the A2 4–20mA input to an integer percentage.
   if (percent == ANALOG_READ2_ERROR) {   if (percent == ANALOG_READ2_ERROR) {
-    Serial.println("4-20mA wire break or input error");+    Serial.println(F("4-20mA input error"));
   } else {   } else {
 +    Serial.print(F("A2: "));
     Serial.println(percent);     Serial.println(percent);
   }   }
- 
   delay(500);   delay(500);
 } }
Line 36: Line 36:
 ===== Precautions ===== ===== Precautions =====
  
-  * Set the module DIP switches and wiring for 0~20mA current I/O.+  * In this example, ''A2'' is a current input on MPINO-8A4R(T)-S. For another product, check its pin map for supported 4–20mA channels and wiring.
   * An input of approximately 3.6~4.0mA returns the normal value ''0''; inputs below 3.6mA return an error value.   * An input of approximately 3.6~4.0mA returns the normal value ''0''; inputs below 3.6mA return an error value.
   * Error values help detect open circuits. The user must implement final alarms and safety actions in the program.   * Error values help detect open circuits. The user must implement final alarms and safety actions in the program.
Line 48: Line 48:
   * The analog output circuit requires an external 12~24V supply. USB power alone may not provide normal output.   * The analog output circuit requires an external 12~24V supply. USB power alone may not provide normal output.
   * Verify actual current input/output with measuring instruments after preparing a test product.   * Verify actual current input/output with measuring instruments after preparing a test product.
 +
 +===== Built-in Commands in the Same Category =====
 +
 +  * [[:en-us_commands:reference:ianalogread2f|IanalogRead2f() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/ianalogread2.1788791733.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki