I am relatively new to arduino and am in the process of creating a battery discharger. I have written all the software and everything worked fine with the SPI display and the internal ADC but I needed extra resolution accuracy from the ADC and went and purchased a number of ads1115 modules. The problem I have is that when I incorporate the wire.h library and as soon as my code hits 'ads115.begin();', the screen goes blank I assume as a result of both devices sharing the SDA and SCK lines. Am i missing something obvious ? Any help would be appreciated as I'm pulling my hair out as I'm experiencing a complete mental block at the moment.
Welcome to the forum
Please post the sketch that you are having problems with, using code tags when you do
If the display uses the SPI interface and the ADS1115 uses the I2C interface then they will not share any common signal pins so a schematic of your project would help too
Your Arduino Uno does not have a lot of memory. Your sketch and the library for the display use too much SRAM memory. The Adafruit ADS1115 library allocates memory when calling the .begin() function. I'm not sure that your project can be done with a Arduino Uno.
(everything I just wrote is a wild guess)
Update on problem. I have taken the ads1115 module and tried it on a different mega2560 and i get the same problem. Forgetting the project completeley, I wired the 1115 to an UNO, uploaded adafruits code and the 1115 worked and displayed its results on the ser monitor. I took the same 1115, connected it a mega 2560 uploaded adafruits code again and the mega 2560 freezes as soon as it is issued with "ads.begin". Tried on another 2560 as well just in case. It seems to be an issue with the 1115 and a mega 2560. the code is one of the basic examples that come with the Adafruit_ADS1X15 library. The weird thing is that even with a 2560 out of the box with no adc connected the code still freezes ?
PS can someone please explain the best way of uploading schematics and code for future reference. Thanks.
I'm quite sure that a naked Mega2560 running just the begin() method of that library does not freeze. Even with other devices connected a current IDE version should avoid the freezes.
By using the upload button in the editor?
So my guesses were wrong, but I have another guess
The BusIO library combines I2C and SPI. When the .begin() of a sensor is called, the BusIO creates a new object for the I2C bus, but that SPI bus is also included somewhere. Maybe there is a conflict there somehow.
This is the Code
#include <Adafruit_ADS1X15.h>
//Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
Adafruit_ADS1015 ads; /* Use this 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
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
while (1);
}
}
void loop(void)
{
int16_t adc0, adc1, adc2, adc3;
float volts0, volts1, volts2, volts3;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
volts0 = ads.computeVolts(adc0);
volts1 = ads.computeVolts(adc1);
volts2 = ads.computeVolts(adc2);
volts3 = ads.computeVolts(adc3);
Serial.println("-----------------------------------------------------------");
Serial.print("AIN0: "); Serial.print(adc0); Serial.print(" "); Serial.print(volts0); Serial.println("V");
Serial.print("AIN1: "); Serial.print(adc1); Serial.print(" "); Serial.print(volts1); Serial.println("V");
Serial.print("AIN2: "); Serial.print(adc2); Serial.print(" "); Serial.print(volts2); Serial.println("V");
Serial.print("AIN3: "); Serial.print(adc3); Serial.print(" "); Serial.print(volts3); Serial.println("V");
delay(1000);
}
I upload this to my UNO and it runs absolutely fine. Connections to 5v,Gnd, SCL and SDA. Loop repeats and voltage is displayed.
I Upload it to a completely naked 2560 and it displays the "hello" and "adc Range" text.Any text after this line
if (!ads.begin()) {
fails to execute. I can only assume that this is what was happening in my first post where the tft screen would no longer update . It doesnt even display an error message with no ADC connected.
What version of the IDE do you use? Have you updated the Arduino AVR code?
Have you tried to insert a serial output line into setup()? The current code does a lot of things after the begin() method and before the next serial output happens.
1.8.14
I only started using arduino a few months ago so i assume the version I would have downloaded would have been pretty up to date.
Current is version 1.8.19. But your version already has a timeout for Wire functions, so there's almost no chance to let that block infinitely. Do you have an original Arduino Mega2560?
What version of the Adafruit_ADS1X15 and Adafruit_BusIO libraries do you use? The Library Manager will tell you.
the adafruit_ADS1x15 ia 2.3.0 the busio is 1.9.3
The mega2560 is an elegoo clone. I have just done a new install of arduino ide on my pc instead of my works laptop. intalled busio from the manage libraries but still does exactly the same. Maybe it is because of the clone as it works ok on a UNO (Authentic)
I have only exact schematics of the original board, I have no clue what the clone contains. But I see no way for a naked Mega2560 to block on that call. Did you have success using I2C with other devices and that board?
going to try one of my i2c displays and let you know how I get on. I really appreciate the help.
Just connected up a 16x2 lcd and that doesnt work either. Looks like i may have picked up some bad ones because I know ive used an elegoo with a 1.8inch i2c display before.
