Advertisement
microrobotics

ADS1110 Changin MUX mode

May 6th, 2023
1,643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2.  
  3. const int ADS1110_ADDRESS = 0x48; // I2C address of the ADS1110
  4.  
  5. void setup() {
  6.   Wire.begin();
  7.   Serial.begin(9600);
  8.  
  9.   // Configure the ADS1110
  10.   Wire.beginTransmission(ADS1110_ADDRESS);
  11.   Wire.write(0x85); // Config register address
  12.   Wire.write(0x83); // Single-ended measurement on AIN0, gain = 2/3, mode = continuous conversion, data rate = 860 SPS
  13.   Wire.endTransmission();
  14. }
  15.  
  16. void loop() {
  17.   // Start a conversion
  18.   Wire.beginTransmission(ADS1110_ADDRESS);
  19.   Wire.write(0x80); // Conversion register address
  20.   Wire.endTransmission();
  21.  
  22.   // Wait for the conversion to finish (13 ms for 860 SPS)
  23.   delay(15);
  24.  
  25.   // Read the conversion result (MSB first)
  26.   Wire.requestFrom(ADS1110_ADDRESS, 2);
  27.   byte msb = Wire.read();
  28.   byte lsb = Wire.read();
  29.   int result = (msb << 8) | lsb;
  30.  
  31.   // Print the result
  32.   Serial.print("AIN0 voltage: ");
  33.   float voltage = result * 0.1875 / 1000; // Calculate voltage (16-bit result * LSB value * Vref / gain / 1000)
  34.   Serial.print(voltage, 4); // Print voltage with 4 decimal places
  35.   Serial.println(" V");
  36.  
  37.   delay(1000); // Wait for 1 second before taking the next measurement
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement