Hi guys I have this system running to control a grow room with high humdity problem I am having is the arduino basically freezes after a random amount of time, it varies and the display comes up with random letters and numbers on it and the sensor is unresponsive, is there something wrong in my code causing this
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "BlueDot_BME280_TSL2591.h"
BlueDot_BME280_TSL2591 bme280;
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
#define HUMIDIFIER 4
#define SETPOINT 90.0
#define DEADBAND 2.0
#define ON false
#define OFF true
void setup() {
Serial.begin(9600);
pinMode(HUMIDIFIER, OUTPUT);
lcd.begin(16, 2); // for 16x2 LCD module
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.setCursor(0, 0);
lcd.print("Temp");
lcd.setCursor(0, 1);
lcd.print("Humidity");
bme280.parameter.I2CAddress = 0x77;
bme280.parameter.sensorMode = 0b11;
bme280.parameter.IIRfilter = 0b100;
bme280.parameter.humidOversampling = 0b101;
bme280.parameter.tempOversampling = 0b101;
bme280.parameter.tempOutsideCelsius = 15;
if (bme280.init_BME280() != 0x60)
{
Serial.println(F("Ops! BME280 could not be found!"));
}
else
{
Serial.println(F("BME280 detected!"));
}
Serial.println();
Serial.println();
}
void loop()
{ delay(1000);
lcd.setCursor(11, 0);
lcd.print(bme280.readTempC(), 2);
//Move the cursor to the end of the word Humidity: and print the reading to 2 decimal places
lcd.setCursor(11, 1);
lcd.print(bme280.readHumidity(), 2);
Serial.print(F("Temperature in Celsius:\t\t"));
Serial.println(bme280.readTempC());
Serial.print(F("Humidity in %:\t\t\t"));
Serial.println(bme280.readHumidity());
if (digitalRead(HUMIDIFIER) == OFF)
{
if (bme280.readHumidity() > SETPOINT + DEADBAND)
{
digitalWrite(HUMIDIFIER, ON);
}
}
else
{
if (bme280.readHumidity() < SETPOINT - DEADBAND)
digitalWrite(HUMIDIFIER, OFF);
}
}
I have an outdoor wheather station based on a BME280 sensor and I am using a transistor to switch the GND of the sensor on and off in order to save power. I have never experienced any problems with the sensor and it has been running for almost two years now. If the softreset method does not work, maybe you can try that as well.
//Pseudocode
digitalWrite(TRANSISTOR, HIGH); //Switch on the sensor
initialize_BME280();
get_BME280_reading();
digitalWrite(TRANSISTOR, LOW); //Switch off the sensor
I am busy writing that into my code, however it's not only the sensor that stops working the display also stops working and gets completely jumbled up, would that be caused by the sensor as well
Mushroom_man:
I am busy writing that into my code, however it's not only the sensor that stops working the display also stops working and gets completely jumbled up, would that be caused by the sensor as well
Probably not, it may be caused by a brown out or some interference - HUMIDIFIER suggests some sort of relay, right? If so, that may be the cause.. If possible, you should post a schematic (drawing or good photo) of your wiring..
I did suspect the relay so I took that out of the system completely and it's still hanging I will post a picture of my wiring as soon as I get home, what is a brown out??
Which LiquidCrystal_I2C are you using that has a method for:
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
The ones I've seen typicall have (address, columns, rows).
Not sure what the identifiers are after the address 0x27 but, assuming they're pin numbers (as might be the case with a non-I2C parallel LCD) pins 0 and 1 are used; note that 0 and 1 are also the pins used by Serial.
Blackfin:
Which LiquidCrystal_I2C are you using that has a method for:
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
The ones I've seen typicall have (address, columns, rows).
Not sure what the identifiers are after the address 0x27 but, assuming they're pin numbers (as might be the case with a non-I2C parallel LCD) pins 0 and 1 are used; note that 0 and 1 are also the pins used by Serial.
sorry it is a i2c display, that was the example I saw and did not think anything of it as it functioned do you thin it could be confusing things
Blackfin:
Which LiquidCrystal_I2C are you using that has a method for:
LiquidCrystal_I2C lcd(0X27, 2, 1, 0, 4, 5, 6, 7);
The ones I've seen typicall have (address, columns, rows).
Not sure what the identifiers are after the address 0x27 but, assuming they're pin numbers (as might be the case with a non-I2C parallel LCD) pins 0 and 1 are used; note that 0 and 1 are also the pins used by Serial.
sorry it is a i2c display, that was the example I saw and did not think anything of it as it functioned do you thin it could be confusing things
So if you're using the I2C IO expander board, they're probably okay as those appear to be the expander IO pins, not the Arduino pins (at least according to the "New-LiquidCrystal") library here:
You read the sensor 3 times. Once for the screen, once for Serial and once for the actual program logic. Those could give 3 different values. Best-practice is to take a reading at the top of loop() and use that same value everywhere.
digitalRead()ing an output pin is a valid technique on processors with extremely limited RAM. (Like, some have no general-purpose RAM at all.) The tiniest Arduino has enough RAM for your program to remember what state it is in without reading a pin.
Putting code on a line after a { makes it more difficult to read.
Writing an if() statement on 2 or more lines without using { and } is asking for trouble. Make it one single line or use the braces.
2 or more blank lines between functions helps break up the code visually and makes it easier to debug.
My i2c wires for the screen are short, probably 10cm, however the wires to the sensor is 5 meter long, I am using 2×10kohm pullup resistors on the sensor cable, and I am using cat 5 communication cable
MorganS:
You read the sensor 3 times. Once for the screen, once for Serial and once for the actual program logic. Those could give 3 different values. Best-practice is to take a reading at the top of loop() and use that same value everywhere.
digitalRead()ing an output pin is a valid technique on processors with extremely limited RAM. (Like, some have no general-purpose RAM at all.) The tiniest Arduino has enough RAM for your program to remember what state it is in without reading a pin.
Putting code on a line after a { makes it more difficult to read.
Writing an if() statement on 2 or more lines without using { and } is asking for trouble. Make it one single line or use the braces.
2 or more blank lines between functions helps break up the code visually and makes it easier to debug.
How long are the I2C wires?
not sure how I would incorporate the reading of the sensor once for all 3 functions???