I'm having a little trouble getting the value converted correctly to a pressure reading.
I have a 4-20mA signal coming in as a 1-5v signal. at 1v its 330count and 5v its 1632 count
I have tried to get the reading two differetn ways below but can't seem to get it right.
Also after I get the value I'm also trying to round to nearest whole number which I dont even know where to begin
#include <Wire.h>
#include <Adafruit_ADS1015.h>
// Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
void setup(void)
{
Serial.begin(9600);
Serial.println("Hello!");
Serial.println("Getting single-ended readings from AIN0..3");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC!
// ADS1015 ADS1115
// ------- -------
// ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
// ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
// ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
// ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
ads.begin();
}
void loop(void)
{
int16_t adc0, adc1, adc2, adc3;
int16_t pressure1;
float pressure2;
//float pressure1 = 0.0;
float voltage1 = 0.0;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
voltage1 = adc0 * .003;
pressure1 = map(adc0, 333, 1584, 0, 5000); //The 331 value of sensor is around 0psi
pressure2 =(adc0 - 333)*5000/(1580-333);
Serial.print("AIN0: ");
Serial.print(adc0);
Serial.print("\tvoltage1: ");
Serial.println(voltage1, 7);
Serial.print("\tpressure1: ");
Serial.println(pressure1, 7);
Serial.print("\tpressure2: ");
Serial.println(pressure2, 7);
Serial.println();
Serial.print("AIN0: "); Serial.println(adc0);
Serial.print("AIN1: "); Serial.println(adc1);
Serial.print("AIN2: "); Serial.println(adc2);
Serial.print("AIN3: "); Serial.println(adc3);
Serial.println(" ");
delay(1000);
}
Thanks,