No output to LCD here

I am following a youtube video:

Connections are:

LCD I2C backboard:
VCC to 5v on Arduino
GND to GND on Arduino
SDA to A4 on Arduino
SCL to A5 on Arduino

BMP280:
VCC to Pin 12 on Arduino
GND to GND on Arduino
SDA to SDA on Arduino
SCL to SCL on Arduino

The LCD does display output from other sketches and and the BMP280 does show an output to a serial monitor, but using the sketch there is nothing at all on the LCD.
I have tried 2 LCD displays and 2 BME280 sensors to no avail.

Also in the video the author says that the I2C scanner program should find the I2C addresses of both the LCD and the BME280, but it does not find a I2C address from the BME280, only the LCD.

Thanks

RJax_Arduino_LCD_BME280_orig.ino (6.1 KB)

(deleted)

Yes the LCD does light up and I can also set the contrast until the squares are barely visible. As I said , it does show an output from other sketches.

(deleted)

The scanner only finds 1 device which is the LCD screen : 39 (0x27)., when both devices are connected. Then when I disconnect the LCD screen and connect the BMP289 sensor to the same pins, it is found with an address of 118 (0x76).

If I connect the BMP280 to the pins the author has, then the scanner does not find any devices.

LiquidCrystal_I2C lcd(0x3F, 16, 2);

The scanner only finds 1 device which is the LCD screen : 39 (0x27).,

There seems to be a conflict there. You have 0x3f for the LCD address in the begin, but 0x27 reported by the scanner.

OP code so we don't have to download it. Read the how to use this forum-please read sticky to see how to properly post code and some advice on how to ask a good question. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

 /*
* Display values from BME280 on LCD1602-I2C or LCD2004
* 
* Written/Updated by Ahmad Shamshiri on July 27, 2019 at 18:42 
* in Ajax, Ontario, Canada for Robojax.com
* Watch Video instruction for this code:https://youtu.be/mXY_6LOekkw
* 
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface. The device's I2C address is either 0x76 or 0x77.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 **************************************************************************
 
 */

#include <Wire.h>

#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
const int bmeVinPin = 12;// 5V pin for BME280

#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 or 0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);


void setup() {
    pinMode(bmeVinPin, OUTPUT);// set pin as output
    digitalWrite(bmeVinPin,HIGH);// always keep it high (5V) for BMB280 module
    bool status;
    
    // default settings
    // (you can also pass in a Wire library object like &Wire2)
    status = bme.begin();  
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }
  // initialize the LCD, 
  lcd.begin(16,2);
  // Turn on the blacklight and print a message.
  lcd.backlight();     
  lcd.print("Robojax Video");
  lcd.setCursor (0,1); // go to start of 2nd line
  lcd.print("BME280 Test");
  delay(2000);

}


void loop() { 
    // Robojax.com BME280 Code
   lcd.clear();// clear previous values from screen
lcdDisplay(
             // to print Celsius:
             0, // character 0 
             0, // line 0
             "Celsius: ", 

             // to print Celsius
             99, // character undefined
             0, // line 0
             getBME('C'),
             'd'
             );  
             
  lcdDisplay(
             // to print Fahrenheit:
             0, // character 0 
             1, // line 1
             "Fahr.: ", 

             // to print Fahrenheit
             99, // character undefined
             1, // line 0
             getBME('F'),
             'd'
             );     
    delay(5000);
  lcd.clear();// clear previous values from screen    
lcdDisplay(
             // to print Kelvin:
             0, // character 0 
             0, // line 0
             "Kelvin :", 

             // to print Celsius
             99, // character undefined
             0, // line 0
             getBME('K'),
             'k'
             );      
  lcdDisplay(
             // to print humidity text
             0, // character 0 
             1, // line 1
             "Humidity: ", 

             // to print humidity
             99, // character undefined
             1, // line 1
             getBME('H'),
             '%' 
             );  
    delay(5000); 
  lcd.clear();// clear previous values from screen    
lcdDisplay(
             // to print pressure text
             0, // character 0 
             0, // line 1
             "Pres.:", 

             // to print pressure
             99, // character undefined
             0, // line 1
             getBME('P'),
             'p' 
             );  
  lcdDisplay(
             // to print altitude text
             0, // character 0 
             1, // line 1
             "Ap. Alt.:", 

             // to print Altitude
             99, // character undefined
             1, // line 1
             getBME('A'),
             'm' 
             );                   
        delay(5000);

     // Robojax.com BME280 Code
}// loop end



/*
 * @brief returns temperature or relative humidity
 * @param "type" is character
 *     C = Celsius
 *     K = Kelvin
 *     F = Fahrenheit
 *     H = Humidity
 *     P = Pressure
 *     A = Altitude
 * @return returns one of the values above
 * Usage: to get Fahrenheit type: getBME('F')
 * to print it on serial monitor Serial.println(getBME('F'));
 * Written by Ahmad Shamshiri on July 13, 2019. Update July 25, 2019
 * in Ajax, Ontario, Canada
 * www.Robojax.com 
 */
float getBME(char type)
{
   // Robojax.com BME280 Code
  float value;
    float temp = bme.readTemperature();
  if(type =='F')
   {
    value = temp *9/5 + 32;//convert to Fahrenheit 
   }else if(type =='K')
   {
    value = temp + 273.15;//convert to Kelvin
   }else if(type =='H')
   {
    value = bme.readHumidity();// read humidity
   }else if(type =='P')
   {
    value = bme.readPressure() / 100.0F; // read pressure
   }else if(type =='A')
   {
    value = bme.readAltitude(SEALEVELPRESSURE_HPA);// read altitude
   }else{
    value = bme.readTemperature();// read temperature
   }
   return value;
    // Robojax.com BME280 Code
}//getBME



/*
 * lcdDisplay(int tc, int tr, String title, int vc, int vr, float value)
 * displays value and title on LCD1602
 * How to use:
 * If you wan to diaplay: "Temp.: 340.45K" starting from first character
 * on second row.
 * use:
 * lcdDisplay(0, 1, "Temp.: ", 340.45,'K')
 *   
 *   'd' is degree symbol
 * tc  is character number  (0)
 * tr is row in the lcd (1)
 * title is the text (Voltage:)
 * vc value for character 
 * vr value for  row or line
 * value is the value (13.56)
 */
void lcdDisplay(int tc, int tr, String title, int vc, int vr, float value,char symbol)
{
   // Robojax.com LCD1602 for BME280 Demo

   lcd.setCursor (tc,tr); //
   lcd.print(title);
   if(vc !=99)
   {
   lcd.setCursor (vc,vr); //
   }   
   lcd.print(value);
   if(symbol == 'd')
   {
    lcd.print((char)223);
   }else if(symbol =='%')
   {
    lcd.print("%");
   }else if(symbol =='k')
   {
    lcd.print("K");
   }else if(symbol =='p')
   {
    lcd.print("hPa");
   }else if(symbol =='m')
   {
    lcd.print("m");
   }
 // Robojax.com LCD1602 for BME280 Demo
}

@groundfungus,
Sorry about the wrong I2C address, I did have it correct at 0x27 earlier, but forgot to correct it in the ciode I uploaded

The reason I did it as an attachemnt is because it is over 9000 lines long, and I was not allowed or able to upload it in between code tags.

Thanks and I have the hd44780 library included, but still no output to the display.

Which example are actually referring to because each of the 3 examples I tried to compile, give an error at line 90 in the lcdiSpeed example:

LCDiSpeed:90:2: error: #error "Special purpose sketch: Use i/o class example wrapper sketch instead."
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."
^
exit status 1
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."

It is the same error in the other 2 examples

I have the hd44780 library included, but still no output to the display.

You want to be using the hd44780_I2Cexp.h ioClass. Your library includes should look like this. lcd.begin(cols,rows) in setup

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip

The troubleshooting diagnostic sketch is I2CexpDiag

Thanks, and the troubleshooting sketch ran without any problems, and gave a I2C address of 0x27.

I then added the 2 lines from your snippet and uploaded the sketch frm my OP. Still no output to the LCD display tho'.

#include <Wire.h>
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header

hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip
// Include NewLiquidCrystal Library for I2C
#include <LiquidCrystal_I2C.h>

You do not need to include this library any more.

the troubleshooting sketch ran without any problems

Are you saying that the library diagnostic sketch I2CexpDiag ran correctly and the display works properly with hd44780.h?

When you run this I2C scanner with both the lcd and the bmp280, does it show both devices?

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

avalon66:
Thanks and I have the hd44780 library included, but still no output to the display.

Which example are actually referring to because each of the 3 examples I tried to compile, give an error at line 90 in the lcdiSpeed example:

LCDiSpeed:90:2: error: #error "Special purpose sketch: Use i/o class example wrapper sketch instead."
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."
^
exit status 1
#error "Special purpose sketch: Use i/o class example wrapper sketch instead."

It is the same error in the other 2 examples

You are trying to build the wrong sketches.
There is lots of documentation that comes with the hd44780 library, a wiki on the github page, and the default github page, that explains where the proper example sketches are as well as where to find the diagnostic sketch for the i2c based backpacks like you are using.

--- bill

avalon66:
As I said , it does show an output from other sketches.

Start by comparing the lcd code in the other sketches (where the lcd works) with that in the sketch you posted. Correct any differences.

Or just copy/paste the known good code into your sketch.

That should solve your problem there and then without having to worry about all the nitty gritty details.

[/quote]

bperrybap:
You are trying to build the wrong sketches.
There is lots of documentation that comes with the hd44780 library, a wiki on the github page, and the default github page, that explains where the proper example sketches are as well as where to find the diagnostic sketch for the i2c based backpacks like you are using.

--- bill

I downloaded the latest version of hd444780 from Github, and found the I2CexpDiag sketch, which wasn't in the hd44780 version I had.

@cattledog

I removed the LiquidCrystal_i2C library file now.

Yes I am saying thatb the I2CexpDiag did run correctly and found the address of the lcd screen, but when I run the scanner sketch with both devices connected, lcd screen and bme280, only the lcd screen address is found, with no other devices found.

@wvmarie

I changed this:

status = bme.begin();  
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);

to this:

status = bme.begin();  
    if (!status) {
        lcd.begin(16,2);
        lcd.print("Could not find a valid BME280 sensor, check wiring!");
        while (1);

And the error message prints out onto the LCD, then nothing else.

As the bme280 is not found where it is connected to, scl and sda, is there any other way of getting it recognised connected anywhere else·, as well as the lcd screen. Both devices need sda and scl connections.

Then when I disconnect the LCD screen and connect the BMP289 sensor to the same pins, it is found with an address of 118 (0x76).

If I connect the BMP280 to the pins the author has, then the scanner does not find any devices.

Have you confirmed with a multimeter that on the Arduino you are using, the SDA and SCL pins are indeed physically connected to A4 and A5? Are you using male headers a breadboard or an Arduino with female headers?

Will the display run on either set of pins? If you jumper the working pins so that both devices are connected to the same two pins is the BMP sensor recognized?

There was no connections between the male SDA and female A4 pins, nor between the male SCL and female A5 pins on the arduino, using a multimeter.

I am using both male and female pins as above.

The LCD display does not show any output when connected to the male SDA and SCL pins.

I then used a breadboard to connect both the VCC , GND and all SDA and SCL pins. The lcd display now shows data output when the sketch is running.

I can't believe I didn't think of doing that my self, doh!

Thanks for your help

avalon66:
I downloaded the latest version of hd444780 from Github, and found the I2CexpDiag sketch, which wasn't in the hd44780 version I had.

Doing a download from github and then either a manual install or a zip install often results in incorrect library installation as you can't simply unzip a .zip file from gihub into the proper "libraries" location and get a proper install of the library due to the way github names their zip files.
There is no need to download anything from github. When using the IDE library manager, it will install the library for you and you can even select the version you want to install if you dont' want the latest released version.

Not sure what library you were using.
The hd44780 library has included I2CexpDiag in every release including the very first release (0.5.0-a) on Jul 30, 2016

--- bill

Ooops, yes the version I had does indeed have the said sketch in it. I was not looking in the correct folder, ie, ioClass.

Thanks for correcting me.