Hello,
I'm using an Arduino Uno + ADS1115 for reading two analog signals of two pressure sensors. I'm using the ADS1115 for more accuracy.
First of all, I'm not a programmer, so my MO is trial & error. However, I can read both sensors and use the raw digital signal for converting it to pressure.
My Problem is, if I just use one sensor the respective pin assignment is correct, i.e. relative pressure in Pin 0 and absolute pressure on Pin 1. If I try to read both sensors at the same time, I have to switch the pin assignment by hand, i.e. switch the signal wires even though I have assigned them differently in the code.
When measuring this gives me switching values sporadically of the two pressure sensors.
Ground and VDD for the ADS are coming from the Arduino (5V).
I don't see what's causing the problem, so any help would be appreciated.
Maybe my assignment of the respective pins is incorrect?! IDK. So any help would be much appreciated. Thanks in advance.
/*Used PINS
* 2 - DS18B20
*
*/
/*Used PINS ADS
* 0 - rel pressure sensor connected to analog input
* 1 - abs pressure sensor connected to analog input
*
*/
//-------------------------------------------------------------------------------
//ADS1115
//16 bit ADC - 15bit for measuring + 1bit for +/- sign
#include "ADS1X15.h" //include library https://github.com/RobTillaart/ADS1X15
#include <Wire.h> //library to communicate with I2C devices
ADS1115 ADS(0x48); //initialize ADS1115 on I2C bus 1 with default address 0x48
void begin() {
if (!ADS.isConnected()) {
// error ADS1115 not connected
}
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
//relative pressure sensor
int16_t current_bit_rel_p_sensor = 0; //variable to store bit relative pressure sensor
float current_mbar_rel_p_sensor = 0.0; //measured mbar
//-------------------------------------------------------------------------------
//absolute pressure
int16_t current_bit_abs_p_sensor = 0; // variable absolute pressure Sensor to store the value read
float current_mbar_abs_p_sensor = 0.0; //measured mbar
//-------------------------------------------------------------------------------
//Temperaturesensor DS18B20
// library
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
const int ONE_WIRE_BUS = 2;
/********************************************************************/
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
DallasTemperature sensors(&oneWire);
//Address of DS18B20 from address sniffer
//Sensor 1
byte sensor_1_int[8] = {40, 203, 2, 7, 214, 1, 60, 109};
byte sensor_1_hex[8] = {0x28, 0xCB, 0x02, 0x07, 0xD6, 0x01, 0x3C, 0x6D};
float temperature_DS18B20 = 0; // variable temperature Sensor
//-------------------------------------------------------------------------------
//Printing
unsigned long counter = 0; //counting the intervalls
unsigned long currentMillis = 0; //storing current elapsed time
unsigned long previousMillis = 0; //storing previous elapsed time
const int interval = 1000; //intervalls in milliseconds
//-------------------------------------------------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//-------------------------------------------------------------------------------
//ADS1115
//16 bit ADC - 15bit for measuring + 1bit for +/- sign
Wire.begin();
ADS.begin();
ADS.setGain(0); //set the gain value, indicating the maxVoltage that can be measured, Adjusting the gain allowing to make more precise measurements
// value Max Voltage Notes
// 0 ±6.144V default
// 1 ±4.096V
// 2 ±2.048V
// 4 ±1.024V
// 8 ±0.512V
// 16 ±0.256V
ADS.setMode(0); // Operational mode (of measurement) → 0 = CONTINUOUS, 1 = SINGLE (default)
float max_voltage = ADS.getMaxVoltage(); // returns the max voltage with the current gain
Serial.print("max Voltage for measurement: ");
Serial.println(max_voltage);
Serial.println();
//-------------------------------------------------------------------------------
//Temperatursensor DS18B20
// Start up the library and initialize the bus
sensors.begin(); // Start up the library
sensors.setResolution(sensor_1_int, 10);
sensors.setWaitForConversion(false);
}
//-------------------------------------------------------------------------------
void loop() {
// put your main code here, to run repeatedly:
ADS1115_ADC(); //calling the function ADS1115_ADC
rel_pressure_sensor_secondary_chamber(); //calling the function rel pressurecontrol
abs_pressure_sensor_primary_chamber(); //calling the function abs pressure control
temperature_sensor_DS18B20(); //calling the function temperature_sensor_DS18B20
printing_results(); //printing the results on serial monitor
}
//-------------------------------------------------------------------------------
//ADS1115
void ADS1115_ADC(){
//relative pressure sensor
current_bit_rel_p_sensor = ADS.readADC(0); //Reading the ADC , pin = 0...3
//absolute pressure sensor
current_bit_abs_p_sensor = ADS.readADC(1); //Reading the ADC , pin = 0...3
}
//-------------------------------------------------------------------------------
//relative pressure secondary chamber
void rel_pressure_sensor_secondary_chamber(){
current_mbar_rel_p_sensor = 0.093470098*current_bit_rel_p_sensor - 30.89787357;
}
//-------------------------------------------------------------------------------
//absolute pressure primary chamber
void abs_pressure_sensor_primary_chamber(){
current_mbar_abs_p_sensor = 0.047408649*current_bit_abs_p_sensor - 277.1272511;
}
//-------------------------------------------------------------------------------
//Temperatursensor DS18B20
void temperature_sensor_DS18B20(){
sensors.requestTemperatures();
temperature_DS18B20 = sensors.getTempC(sensor_1_int); //get temperature from the sensor addressing him with his serialnumber
}
//-------------------------------------------------------------------------------
//Printing results on serial monitor
void printing_results() {
//-----------------------------------------------------------------------------------------------------------
//Printing only once per interval
currentMillis = millis(); //current time
if (currentMillis - previousMillis >= interval) {
counter += 1;
//-----------------------------------------------------------------------------------------------------------
Serial.print("Time [sec]:\t");
Serial.print(counter); // counter = measurement time in sec
Serial.print("\t"); //Tabstop between results
//empty space for excel calculations
Serial.print("\t");
//-----------------------------------------------------------------------------------------------------------
//abs pressure
Serial.print("abs. pressure sensor measurement chamber [mbar]:\t");
Serial.print(current_mbar_abs_p_sensor,2); // print the input of the absolut pressure sensor, rounded to 2 places
Serial.print("\t"); //Tabstop between results
//-----------------------------------------------------------------------------------------------------------
//rel pressure
Serial.print("rel. pressure sensor sec. chamber [mbar]:\t");
Serial.println(current_mbar_rel_p_sensor,2); // print the output of the rel. pressure sensor, rounded to 2 places
Serial.print("\t"); //Tabstop between results
//-------------------------------------------------------------------------------
//Temperatursensor DS18B20
Serial.print("Temperature [°C]:\t");
Serial.println(temperature_DS18B20); // print the input of the temperature sensor
previousMillis = currentMillis; //resetting counter
}
}