LCD 16x2 with sensor

Hi!
I’m new to Arduino programming.
I need to program a sensor (Adafruit TSL2591, brightness sensor), to display the values ​​on a 16x2 LCD I2C screen.
I have the sensor program on the official website, but I don’t know how to make the display on the LCD screen.

I mention that I can’t display anything on the LCD in ”standard programming”. Only Bill’s HD44780 programs work for me. I do not know why.

Can you help me with some advice on the structure of the program?

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);
void displaySensorDetails(void)
{
  sensor_t sensor;
  tsl.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux"); 
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void configureSensor(void)
{
 tsl.setGain(TSL2591_GAIN_LOW);    // 1x câștig
 
  tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
   
  Serial.println("------------------------------------");
  Serial.print  ("Câștig:     ");
  tsl2591Gain_t gain = tsl.getGain();
  switch(gain)
  {
    case TSL2591_GAIN_LOW:
      Serial.println("1x ");
      break;
    case TSL2591_GAIN_MED:
      Serial.println("25x ");
      break;
    case TSL2591_GAIN_HIGH:
      Serial.println("428x ");
      break;
    case TSL2591_GAIN_MAX:
      Serial.println("9876x ");
      break;
  }
  Serial.print  ("Timp:       ");
  Serial.print((tsl.getTiming() + 1) * 100, DEC);
  Serial.println(" ms");
  Serial.println("------------------------------------");
  Serial.println("");
}

void setup(void)
{
  Serial.begin(9600);
 
  Serial.println("Starting Adafruit TSL2591 Test!");
 
  if (tsl.begin())
  {
    Serial.println("Found a TSL2591 sensor");
  }
  else
  {
    Serial.println("No sensor found ... check your wiring?");
    while (1);
  }
  displaySensorDetails();
  configureSensor();
}

void unifiedSensorAPIRead(void)
{
  sensors_event_t event;
  tsl.getEvent(&event);
 
  Serial.print("[ "); Serial.print(event.timestamp); Serial.print(" ms ] ");
  if ((event.light == 0) |
      (event.light > 4294966000.0) |
      (event.light <-4294966000.0))
  {
    Serial.println("RecepÈ›ie invalidă");
  }
  else
  {
    Serial.print(event.light); Serial.println(" lux");
  }
}

void loop(void)
{
  unifiedSensorAPIRead();
  delay(250);
}

TSL2591.txt (2.41 KB)

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); 
void displaySensorDetails(void)
{
  sensor_t sensor;
  tsl.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");  
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void configureSensor(void)
{
 tsl.setGain(TSL2591_GAIN_LOW);    // 1x câștig
  
  tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
   
  Serial.println("------------------------------------");
  Serial.print  ("Câștig:     ");
  tsl2591Gain_t gain = tsl.getGain();
  switch(gain)
  {
    case TSL2591_GAIN_LOW:
      Serial.println("1x ");
      break;
    case TSL2591_GAIN_MED:
      Serial.println("25x ");
      break;
    case TSL2591_GAIN_HIGH:
      Serial.println("428x ");
      break;
    case TSL2591_GAIN_MAX:
      Serial.println("9876x ");
      break;
  }
  Serial.print  ("Timp:       ");
  Serial.print((tsl.getTiming() + 1) * 100, DEC); 
  Serial.println(" ms");
  Serial.println("------------------------------------");
  Serial.println("");
}

void setup(void) 
{
  Serial.begin(9600);
  
  Serial.println("Starting Adafruit TSL2591 Test!");
  
  if (tsl.begin()) 
  {
    Serial.println("Found a TSL2591 sensor");
  } 
  else 
  {
    Serial.println("No sensor found ... check your wiring?");
    while (1);
  } 
  displaySensorDetails();
  configureSensor();
}

void unifiedSensorAPIRead(void)
{ 
  sensors_event_t event;
  tsl.getEvent(&event);
 
  Serial.print("[ "); Serial.print(event.timestamp); Serial.print(" ms ] ");
  if ((event.light == 0) |
      (event.light > 4294966000.0) | 
      (event.light <-4294966000.0))
  {
    Serial.println("Recepție invalidă");
  }
  else
  {
    Serial.print(event.light); Serial.println(" lux");
  }
}

void loop(void) 
{ 
  unifiedSensorAPIRead();
  delay(250);
}

sorry, i don't understand

What don’t you understand?
It’s your code.

@oo_miti_oo

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

oo_miti_oo:
I mention that I can’t display anything on the LCD in ”standard programming”. Only Bill’s HD44780 programs work for me. I do not know why.

That makes no sense. :roll_eyes:

At this point in time, Bill’s HD44780 programs are the “standard” means of operating a 1602 LCD display with an I2C “backpack”. There are no other “standard programs” as those originally built into the IDE are for versions of the backpack no longer (made or) sold for quite a few years now.

There are other usable libraries such as fmalpartida’s, but you have to install them in a particular manner and you have to go through some experimentation to configure them. Bill’s library does it for you.

So the examples provided with Bill’s HD44780 library are what you use use as the basis for your program; you use them to initialise the display and then you add your own code to print to the display an a manner somewhat similar to the serial port except that you need to carefully format what you print to match the limited space on the display.

oo_miti_oo,
I don't understand what you are wanting / trying to do.
Tell us more about what you are wanting to do and what you have tried that is't working the way you expect it to wok.

--- bill