Table of Contents

analogRead2()

analogRead2() reads the corrected 4~20mA input value of the specified channel.

analogRead2 command operation flow

uint16_t analogRead2(uint8_t ch)

Commands

Command Arguments Return Value Operation
analogRead2(ch) uint8_t ch — MPINO: analog pin such as A0; MPAINO: overall module channel number starting at 0 uint16_t Reads the corrected 4~20mA input value of the specified channel.

Example

Connect an X input module to MPAINO-8A8R(T) and select Analog Input Module → X. Set CH0 DIP switches 20mA and GND to ON, then connect the 4–20mA signal.

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const uint16_t value = analogRead2(0);  // Read the corrected 4–20mA value from CH0.
  if (value == ANALOG_READ2_ERROR) {
    Serial.println(F("4-20mA input error"));
  } else {
    Serial.println(value);
  }
  delay(500);
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List