User Tools

Site Tools


en-us_commands:reference:analogread

analogRead()

analogRead() reads the raw analog value of the specified channel.

analogRead command operation flow

int analogRead(uint8_t pin)

Commands

Command Arguments Return Value Operation
analogRead(pin) uint8_t pin — On MPAINO, 0 ~ 19 are overall analog input module channel numbers int Reads the raw analog value of the specified channel.

Example

This example uses MPAINO-8A8R(T) with two X input modules. Select Analog Input Module → X2 in Arduino IDE. CH0 on X1 is 0; CH0 on X2 is 4.

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const int first = analogRead(0);  // Read the raw analog value from X1 CH0.
  const int second = analogRead(4);  // Read the raw analog value from X2 CH0.
  Serial.print(F("X1 CH0: "));
  Serial.println(first);
  Serial.print(F("X2 CH0: "));
  Serial.println(second);
  delay(500);
}

Precautions

  • On MPAINO, analogRead(0~19) returns a raw ADS1118 ADC value, not a value converted to voltage, current or temperature units.
  • For 4~20mA software cutoff and open-circuit detection, use analogRead2(A pin) on MPINO or analogRead2(module channel) on MPAINO.
  • Set the sampling rate with analogReadInit(sps). If not configured, it follows the analogRead() default.
  • The maximum averaging sample count is 20. If samples = 0 or memory allocation fails, return the current raw value.
  • Using both averaging functions allocates separate dynamic buffers and increases SRAM usage.
  • The MPAINO analog input module's DIP switches and actual wiring must match the input type.

Built-in Commands in the Same Category

en-us_commands/reference/analogread.txt · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki