User Tools

Site Tools


en-us_commands:reference:analogread

This is an old revision of the document!


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

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  int ai0 = analogRead(0);
  int ai4 = analogRead(4);
  int32_t avg0 = analogReadAvg(0, 5);
  float avg0f = analogReadAvgf(0, 5);
 
  Serial.print("AI0: ");
  Serial.println(ai0);
 
  Serial.print("AI4: ");
  Serial.println(ai4);
 
  Serial.print("AI0 AVG: ");
  Serial.println(avg0);
 
  Serial.print("AI0 AVG float: ");
  Serial.println(avg0f, 2);
 
  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 Command List

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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki