Question: Using Arduino zero / uno display the light and temperature in the form of a bar graph from the BME 2 8 0 Sensor and
Using Arduino zerouno display the light and temperature in the form of a bar graph from the BME Sensor and BH sensor using SDI protocol. Display this information on the Arduinos build in LCD.
Code I've done so far:
#include
#include
#include
#include
#include
#include Adjust if you're using a different display
#define BHFVIPIN A
#define PBPIN
#define TFTCS
#define TFTMOSI
#define TFTRST
#define TFTDC
#define TFTSCLK
#define DIRO Assuming this is the pin for SDI direction control
AdafruitBME bme;
AdafruitST tft AdafruitSTTFTCS TFTDCTFTMOSI,TFTSCLK TFTRST;
float temperature;
int lightData;
const int arraySize ;
float temperatureArrayarraySize;
int lightArrayarraySize;
int deviceAddress ; Add your device address here
void setup
Serial.begin;
Serialbegin SERIALE;
if bme.beginx The IC address might be x try this if x doesn't work
Serial.printlnCould not find a valid BME sensor check wiring!";
while ;
if SDbegin
Serial.printlnSD card initialization failed!";
while ;
tftinitRINITRBLACKTAB; Or the appropriate initialization for your display
tftsetRotation;
tftfillScreenSTXXBLACK;
pinModeDIRO OUTPUT;
pinModePBPIN, INPUTPULLUP;
Serial.printlnSetup completed!";
void loop
if digitalReadPBPIN LOW
Serial.printlnButton pressed, starting measurement...";
int sensorStatus startMeasurement;
if sensorStatus
Serial.printlnBoth sensors measured successfully.";
sendContinuousData;
logData;
arrayFull;
displayGraphs; Display temperature graph
delay;
displayGraphs; Display light graph
else
Serial.printlnSensor reading failed";
int startMeasurement
int temperatureToggle ;
int luxToggle ;
temperature bme.readTemperature;
Serial.printTemperature: ;
Serial.printlntemperature;
if isnantemperature
temperatureToggle ;
lightData analogReadBHFVIPIN;
Serial.printLight Data: ;
Serial.printlnlightData;
if lightData
luxToggle ;
return temperatureToggle luxToggle;
void sendContinuousData
String dataString StringdeviceAddress Stringtemperature StringlightData;
Serial.printSending continuous data: ;
Serial.printlndataString;
SDISenddataString;
void SDISendString message
Serial.printSDI Message: ;
Serial.printlnmessage;
digitalWriteDIRO LOW;
delay;
Serialprintmessage r
;
Serialflush;
Serialend;
Serialbegin SERIALE;
digitalWriteDIRO HIGH;
void logData
File dataFile SDopendatalogtxt FILEWRITE;
if dataFile
You need to implement a way to get the current time, like using a RTC module
Serial.printlnLogging data...";
dataFile.printTime: ;
dataFile.print Sensor: ;
dataFile.printTemp: ;
dataFile.printtemperature;
dataFile.print C Light: ;
dataFile.printlnlightData;
dataFile.close;
Serial.printlnData logged successfully.";
else
Serial.printlnError opening datalog.txt;
void arrayFull
Serial.printlnShifting array data...";
for int i ; i arraySize; i
temperatureArrayi temperatureArrayi;
lightArrayi lightArrayi;
temperatureArrayarraySize temperature;
lightArrayarraySize lightData;
Serial.printlnArrays updated.";
void displayGraphsint sensorSelection
tftfillScreenSTXXBLACK;
Serial.printDisplaying graph for: ;
switch sensorSelection
case :
Serial.printlnTemperature;
displayBarGraphtemperatureArray "Temp C;
break;
case :
Serial.printlnLight Data";
Convert lightArray to float before displaying
float tempLightArrayarraySize;
for int i ; i arraySize; i
tempLightArrayifloatlightArrayi; Casting int to float
