Using ADS1115 + 2.4 tft lcd + Leonardo

Hello Everyone,

I am trying to integrate oxygen sensor with UNO. I am using ADS1115 to boost the signal and read on UNO.

my data is visible on serial monitor but my 2.4" tft lcd by adafruit is blank. can anyone please help.

Below is my code:

#include <Wire.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <Adafruit_ADS1X15.h>

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin


// Assign human-readable names to some common 16-bit color values:
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
float CalFactor = 0.0;
float Voltage1 = 0.0;
float Oxy = 0.0;
//int16_t adc0; // 16 bits ADC read of input A0
Adafruit_ADS1115 ads;

void setup(void) {
  ads.begin();
  Serial.begin(9600);
  int16_t adc0;
  ads.setGain(GAIN_SIXTEEN);
  adc0 = ads.readADC_SingleEnded(0);
  Voltage1 = ((adc0) * 0.256 * 1000 / 32768);
  CalFactor = ((Voltage1 + .0069) / 21);
  Oxy = ((Voltage1 + .0069) / CalFactor);
  //Serial.println(F("TFT LCD test"));

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();

  uint16_t identifier = tft.readID();

  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }

  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  //Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

   Serial.println(F("Done!"));
}

void loop(void) {
  int16_t adc0;
  adc0 = ads.readADC_SingleEnded(0);
  Voltage1 = ((adc0) * 0.256 * 1000 / 32768);
  Oxy = ((Voltage1 + .0069) / CalFactor);
   {
    tft.setRotation(0);
    testText();
    delay(2000);
  }
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Oxy");
  Serial.println(Oxy);
  tft.setTextSize(2);
  //return micros() - start;
}

What does the serial monitor show?

it show the reading of oxygen sensor like

There is some problem with ADS1115, it is doing something that is not allowing anything to display but not sure how to solve it

If the ADS1115 is using I2C then you cannot use A4 for the reset line on the display because A4 is used for I2C.

ADS is connected to SDA & SCL pic of UNO. rest VDD and GND is connected to there respective pins

No, I meant what LCD does the sketch detect?

Do you have a simple "Hello world" sketch for the display?

No, i used default graphic test and it is working

Where is the reset line of the display connected? You CAN NOT use A4 - it is SCA.

Connect the display reset line to the RESET pin on the UNO, and change the code to define LCD_RESET as 0 (the number zero, not the capital letter O).

can you please let me know how to do it in my code.

i am using TFT shield
https://zbotic.in/product/2-4″-inch-touch-screen-tft-display-shield-for-arduino-uno-mega/?utm_source=Google%20Shopping&utm_campaign=27.02%20Rev1&utm_medium=cpc&utm_term=6846&gclid=Cj0KCQjw78yFBhCZARIsAOxgSx1b4XIOmkw9jU2r6jsJvjCR8hrL4-WEoEy9mknKG8QyolW2f4-_-7oaAm99EALw_wcB

i did the change LCD_RESET as 0 but display reset line how to connect to uno ?

one more clarification, i am using leonardo not UNO. sorry for the mistake in my previous post

Ignore my advice about the reset line, on the leonardo the I2C is on digital pins 2 and 3, which is probably causing problems because of the pinmode being changed between the tft and I2C uses.

Thanks for the link to the actual display Shield.

Unfortunately you can not use I2C with this shield on a Uno nor on a Leonardo.

The Uno shares SDA with LCD_RST on PC4.
Leonardo shares SDA with LCD_D2
Leonardo shares SCL with LCD_D3

Either use a different ADC chip e.g. SPI or OneWire.
Or use a MEGA2560, Due, Zero, ... which have separate I2C pins.

David.

ok. will try to use other display type and update

A TFT shield that uses the SPI interface will leave plenty of GPIO pins and avoid I2C.

A hardware mod "works" on a Uno.

A software mod might "work" on the Leonardo. i.e. enable Wire before every ADS1115 read. disable Wire afterwards.
pinMode() the I2C pins back to OUTPUT for the TFT.

There is always a risk that a random bit pattern on LCD_D2, LCD_D3 might "start" the I2C. Unlikely but quite possible.

David.

Hello David,

Thanks for your advice, but you need to help me with enabling and disable the wire as i am not sure how to do it.

i have seen OLED displays but they have pins
GND: Power Ground

VCC: Power + (DC 3.3 ~5v)

SCL: Clock Line

SDA: Data Line

same pins are with ADS1115. how to use both together?

There is a Wire.begin() function that enables I2C but no Wire.end() to disable it.

I can only suggest that you use Wire.begin() before every ADS1115 function and pinMode(SDA, OUTPUT) and pinMode(SCL, OUTPUT) afterwards. Hope that pinMode() disables the TWI. Otherwise you call TWCR = 0; as well as pinMode()

Untested. This is no good on a Uno. But it might "work" on the Leonardo.

Just remember that the I2C Slave will see every wiggle on LCD_D2, LCD_D3. The wiggles are much faster than I2C but bear in mind that sh*t happens.

In #12 you say : one more clarification, i am using leonardo not UNO. sorry for the mistake in my previous post
Please edit your thread Title. It says Uno

David.

Thats great. now its working and i can see data on my screen. now just need to clear my code.
here is the code after the suggestion:

#include <Wire.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <Adafruit_ADS1X15.h>

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin


// Assign human-readable names to some common 16-bit color values:
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
float CalFactor = 0.0;
float Voltage1 = 0.0;
float Oxy = 0.0;
//int16_t adc0; // 16 bits ADC read of input A0
Adafruit_ADS1115 ads;

void setup(void) {
  ads.begin();
  Serial.begin(9600);
  int16_t adc0;
  ads.setGain(GAIN_SIXTEEN);
  adc0 = ads.readADC_SingleEnded(0);
  Voltage1 = ((adc0) * 0.256 * 1000 / 32768);
  CalFactor = ((Voltage1 + .0069) / 21);
  Oxy = ((Voltage1 + .0069) / CalFactor);
  pinMode(SDA,OUTPUT);
  pinMode(SCL,OUTPUT);
  TWCR=0;
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());

  tft.reset();

  uint16_t identifier = tft.readID();

  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    return;
  }

  tft.begin(identifier);

  Serial.println(F("Benchmark                Time (microseconds)"));

  Serial.print(F("Screen fill              "));
  //Serial.println(testFillScreen());
  delay(500);

  Serial.print(F("Text                     "));
  Serial.println(testText());
  delay(3000);

   Serial.println(F("Done!"));
}

void loop(void) {
  int16_t adc0;
  adc0 = ads.readADC_SingleEnded(0);
  Voltage1 = ((adc0) * 0.256 * 1000 / 32768);
  Oxy = ((Voltage1 + .0069) / CalFactor);
  pinMode(SDA,OUTPUT);
  pinMode(SCL,OUTPUT);
  TWCR=0;
   {
    tft.setRotation(1);
    testText();
    delay(2000);
  }
}

unsigned long testText() {
  tft.fillScreen(BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(GREEN);
  tft.setTextSize(5);
  tft.println("Oxygen");
  tft.print(Oxy);
  tft.print("%");
  Serial.println(Oxy);
  tft.setTextSize(2);
  
}

now need help to draw graph also for this data and store in SD card.
can someone please modify or help to modify the code for the same.