The full code is pasted at the bottom of my post (I do not have upload privileges yet).
Hi All,
I'm building a light sensor using the Adafruit TSL2591 HDR sensor, and I am encountering a problem where the the output of a single variable, lux, displays differently in the serial monitor (about 222) and the LCD printout (about 866). As far as I can tell, there is no opportunity for the variable to change between the two print statements:
void loop() {
lcd.setCursor(4, 1);
uint16_t lux = read();
lcd.print(lux);
Serial.print(F("Lux: ")); Serial.println(lux, 6);
delay(1000);
}
I am (completely) new to the Arduino IDE, so I might be missing something obvious. My guess was that there is some difference in the variable types that the Serial.print() and LiquidCrystal.print() accept, but that does not appear to be the case in the reference documents (Docs: Serial.print(), LiquidCrystal.print()).
I also found this post that describes a similar problem, which is why I added delay(1000) to the loop, but that did not help.
Does anyone have an idea of why this might be happening?
Full Code:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_TSL2591.h"
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591);
void configureSensor(void) {
tsl.setGain(TSL2591_GAIN_MED);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
}
uint32_t read(void) {
uint32_t lum = tsl.getFullLuminosity();
uint16_t ir = lum >> 16;
uint16_t full = lum & 0xFFFF;
uint32_t lux = tsl.calculateLux(full, ir);
return lux;
}
void setup() {
lcd.begin(16, 2);
lcd.print("Lux:");
configureSensor();
Serial.begin(9600);
}
void loop() {
lcd.setCursor(4, 1);
uint16_t lux = read();
lcd.print(lux);
Serial.print(F("Lux: ")); Serial.println(lux, 6);
delay(1000);
}