Hello. I have been working on this circuit
I have 5V GND, SCL and SDA connected directly to an Arduino Mega. The MAX665 is used to invert the voltage to give -5V. The OPA633 is a voltage follower. Below (not shown) are multiplexers used to select which signal I want.
I am using two channels on the ADS1115. Channel 1 reads the voltage between the output of the voltage follower and 5V. This is because I need to be able to read signals from +-4V. If the output of the voltage follower is -4V then the ADS should have 0.5V applied to it.
In order to take into account the true voltage of the power supply which is used to calculate what the voltage follower is actually outputting I measure the power supply voltage after being divided by 2.
The relevant code used is here. I am using PlatformIO on VSCode
#include <Arduino.h>
#include <LiquidCrystal_I2C.h> // Library for Displays
#include <SoftwareSerial.h> // For Serial Connection
#include <Wire.h> // Library for I2C comm
#include <Adafruit_ADS1X15.h> // Library for Adafruit external ADC
#include <string.h>
Adafruit_ADS1115 ads; // 16-bit ADC
float VSupply; // Supply voltage (used in the voltage divider network between VMeasured and VOut)
float VMeasured; // Voltage measured
float VOut; // Voltage output from voltage follower
float VIn; // Voltage input to voltage follower
int voltage[n]; // Actual capacitor voltage
void setup() {
Serial.begin(9600);
delay(100);
Wire.begin(); delay(100);
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
while (1);
}
Serial.println("ADS has begun"); delay(100);
}
void loop() {
memset(voltage, 0, sizeof(voltage)); // Resets all voltages to 0
VSupply = float(ads.readADC_SingleEnded(3))*0.0003737950501; // 0.1875mV per division * 1.993543181 (from resistor network)
delay(10);
//Serial.println(VSupply);
for (char chanIx = 1; chanIx <= n; chanIx++){
for (char multiIx = 0; multiIx <= 1; multiIx++){ // Positive signals then negative signal
multiplexerSelection(multiIx, chanIx);
VMeasured = float(ads.readADC_SingleEnded(1))*0.0001875028611; // Voltage measured at ADC
//Serial.println(VMeasured);
VOut = VMeasured*1.92244898 - 0.92244898*VSupply; // Voltage output by voltage followe
Serial.println(VOut);
VIn = 0.030744603353506 +
VOut* (1.003118305649884 +
VOut*(-0.002849417026801 +
VOut* (0.001515368245624 +
VOut* (0.001391459694530 +
VOut*(-0.000916959891801 +
VOut*(-0.000182340997645 +
VOut* (0.000152729097959))))))); // 7th order polynomial fit to get accurate VIn from VOut
voltage[chanIx-1] += VIn*correction[ chanIx -1 + 12*multiIx ]*(1 + multiIx*-2);
}
voltage[chanIx-1] = abs(voltage[chanIx-1]);
}
}
The setup will work for a bit then I receive this error on the serial monitor.
Exception in thread rx:
Traceback (most recent call last):
File "C:\Users\William\.platformio\python3\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Users\William\.platformio\python3\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "c:\users\william\.platformio\penv\lib\site-packages\serial\tools\miniterm.py", line 499, in reader
data = self.serial.read(self.serial.in_waiting or 1)
File "c:\users\william\.platformio\penv\lib\site-packages\serial\serialwin32.py", line 259, in in_waiting
raise SerialException("ClearCommError failed ({!r})".format(ctypes.WinError()))
serial.serialutil.SerialException: ClearCommError failed (PermissionError(13, 'The device does not recognize the command.', None, 22))
Afterwards, if I reset the Arduino, the code never executes past ads.begin(). It's not that I receive an error that it failed to initialize - it gets hung up and never exits. Seemingly randomly, sometimes if I go away for a bit and plug the Arduino back in it will work again (for a bit). Also, when I probe the signal at CH1 I see a voltage of about 0.2V where I would expect to see 2.5V since the voltage follower is outputting 0 V and the power rail is still 5V. Probing the resistance between CH1 and GND shows about 450 ohms.
When I take the ADS1115 out of the circuit and put a new one the same thing happens. When I put the old ADS1115 on a breadboard and connect it to power, GND, SDA, and SDL it functions.
Quite a weird problem. Any ideas on the cause and what I should do to further troubleshoot?

