73 lines
1.3 KiB
Arduino
Raw Normal View History

2021-01-29 12:31:58 +01:00
//
// FILE: ADS_continuous.ino
// AUTHOR: Rob.Tillaart
// PURPOSE: read analog input
2023-03-31 14:32:54 +02:00
// URL: https://github.com/RobTillaart/ADS1X15
2021-01-29 12:31:58 +01:00
2023-06-13 13:23:03 +02:00
// test
// connect 1 potmeter
2021-01-29 12:31:58 +01:00
//
2023-06-13 13:23:03 +02:00
// GND ---[ x ]------ 5V
// |
//
// measure at x (connect to AIN0).
//
// See https://github.com/RobTillaart/ADS1X15/issues/49
2021-01-29 12:31:58 +01:00
//
#include "ADS1X15.h"
2021-12-11 16:46:06 +01:00
2022-10-17 11:10:46 +02:00
// choose your sensor
2021-01-29 12:31:58 +01:00
// ADS1013 ADS(0x48);
// ADS1014 ADS(0x48);
// ADS1015 ADS(0x48);
// ADS1113 ADS(0x48);
// ADS1114 ADS(0x48);
ADS1115 ADS(0x48);
2023-06-13 13:23:03 +02:00
uint16_t count = 0;
uint16_t value = 0;
uint16_t prev = 0;
uint32_t lastTime = 0;
uint32_t lastSample = 0;
2021-01-29 12:31:58 +01:00
void setup()
{
2023-06-13 13:23:03 +02:00
Serial.begin(500000);
2021-01-29 12:31:58 +01:00
Serial.println(__FILE__);
Serial.print("ADS1X15_LIB_VERSION: ");
Serial.println(ADS1X15_LIB_VERSION);
ADS.begin();
2023-06-13 13:23:03 +02:00
ADS.setGain(0); // 6.144 volt
ADS.setDataRate(7); // 0 = slow 4 = medium 7 = fast
ADS.setMode(0); // continuous mode
ADS.readADC(0); // first read to trigger
2021-01-29 12:31:58 +01:00
}
2021-12-11 16:46:06 +01:00
2021-01-29 12:31:58 +01:00
void loop()
{
2023-06-13 13:23:03 +02:00
uint32_t now = micros();
if (now - lastSample >= 1160) // almost exact 860 SPS
{
lastSample = now;
value = ADS.getValue();
count++;
Serial.print(count);
Serial.print("\t");
Serial.println(value);
}
if (now - 1000000 >= lastTime)
{
lastTime = now;
count = 0;
}
2021-01-29 12:31:58 +01:00
}
2021-12-11 16:46:06 +01:00
2023-06-13 13:23:03 +02:00
// -- END OF FILE --
2021-12-11 16:46:06 +01:00