en-us_commands:reference:analogreadinit
Table of Contents
analogReadInit()
analogReadInit() sets the sampling rate of the analog input module.
void analogReadInit(uint16_t sps)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
analogReadInit(sps) | uint16_t sps | void | Sets the sampling rate of the analog input module. |
Example
void setup() { Serial.begin(115200); // Use autocomplete constants analogReadInit(IANALOG_SPS_250); // Set the analog input module's sampling rate. } void loop() { for (uint8_t ch = 0; ch < 4; ch++) { Serial.print("CH"); Serial.print(ch); Serial.print(" = "); Serial.println(analogRead(ch)); // Read the raw analog value of the specified channel. } }
Precautions
- Settings other than SPS, such as PGA, input MUX and Single-shot mode, are not changed.
- Higher SPS reduces conversion wait time, but check for value fluctuations due to field wiring and signal noise.
- The internal ADS1118 maximum RATE is 860 SPS. Since the same channel is converted twice, the maximum requested return target is 475 SPS.
analogReadInit(128)uses the nearest higher RATE of 250 SPS, rather than 256 SPS, which the ADS1118 does not provide.- SPI communication and function processing add time, so the actual measurement SPS may be lower than the target.
analogRead()converts the same channel twice to prevent channel-value displacement. Include both conversion times when calculating the total channel update time.
Built-in Commands in the Same Category
en-us_commands/reference/analogreadinit.txt · Last modified: by 127.0.0.1
