I have an Arduino Uno R3 and was using the I2C tabs on the board located here to chat with this BME280. The setup I'm using is pretty sweet and have two TRRS 3.5mm audio cables (4 wires) one in male the other in female. Each of those guys are 6' long. So we're talking 12 feet length with a plug in the middle. I chose to use 5v instead of the called for 3.3v due to the cable length. (Tried it on the breadboard and 5v worked fine). I've been doing some reading on this but seems the online debates are actually just making me more confused. And I may be over complicating this. Anyway..
The issue I'm having is during the setup the LCD freezes and goes blank when the MCU tries to call the sensor. Obviously those built in pull ups just aren't enough (or too much actually). The part Im getting confused about is I've read I can disable the built-in resistors with something like:
digitalWrite(SDA, 0);
digitalWrite(SCL, 0);
directly after the "status = bme.begin(0x76);" and then drop 2 1kohm's on those scl&sda tabs? Is this correct or do I have to use a different set of pins. Im using a LCD shield in this project so I'd prefer not to use different pins if I can get away with it. Finally I was curious about my clock speed. Do I need to turn down my clock speed with:
wire.setClock(10000);
as well as changing the pullup values??
My code (just in case):
/* Temperature controlled relay using a BME280 sensor and a SainSmart 16x2 LCD w/ Keypad
The key pad has all buttons tied to A0 with different resistence values on each button to call the desired character
Programmed by Jerimy
*/
#include <DFR_LCD_Keypad.h> //simply has keypad resistance limits
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define RELAY 13 // Relay for the A/C unit
#define ALTITUDE 191.0 // Altitude of Brownsville MD (my town)
int last_key, key;
float setTemp = 74.5; //default temperature so it doesn't start at zero when changing temps
int val = 0; //The value to test our keypad resistence value
const int redLED = 12; // red LED A/C is on
const int greenLED = 11; // green LED A/C is off
float temperature;
float humidity;
float pressure;
Adafruit_BME280 bme; // I2C
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DFR_LCD_Keypad keypad(A0, &lcd);
//***********************************************************************************************************************
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
lcd.setCursor(0, 0);
lcd.print("Big Bud Sys By:");
lcd.setCursor(0, 1);
lcd.print("DNozz");
delay(2000);
lcd.clear(); //clear the screen
lcd.print("Reading Sensors");
bool status;
delay(2000);
lcd.clear(); //clear the screen
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
digitalWrite(greenLED, HIGH); //Green LED On
digitalWrite(redLED, LOW); //Red LED Off
digitalWrite(RELAY, LOW); //Turn off Relay
status = bme.begin(0x76); //The I2C address of the sensor I use is 0x76
// if m.controller can't "find" the sensor at address 0x76
if (!status) {
lcd.print("check wiring");
Serial.println("Can't find the BME280 sensor, check wiring!");
while (1);
}
if (status) {
lcd.print("Sensor Working");
Serial.println("Sensor is Working");
delay(1500);
}
lcd.clear();
lcd.print("Up & Down change");
lcd.setCursor(0, 1);
lcd.print("the temperature");
delay(3000);
lcd.clear();
lcd.print("Left - On");
lcd.setCursor(0, 1);
lcd.print("Right - OFF");
delay(3000);
lcd.clear();
lcd.print("Hit select for");
lcd.setCursor(0, 1);
lcd.print("Humid. & Pres.");
delay(3000);
lcd.clear();
}
//***********************************************************************************************************************
void loop() {
//val = analogRead(0); // read the value from the sensor connected to A0.
//Serial.println(val); //Prints the value coming in from the analog sensor for testing.
getPressure();
getHumidity();
getTemperature();
// Controls the relay and LEDs based on the set temperature
if (temperature >= setTemp) {
digitalWrite(RELAY, HIGH); {
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
// while (setTemp - temperature < 1) { //THIS IS WHERE I NEED HELP!!! want to A/C to cool 4 degrees past the set temp to avoid repeated on and off.
// digitalWrite(RELAY, HIGH); // This while statement doesnt work at all!!
// digitalWrite(greenLED, HIGH);
// }
}
}
if (temperature <= setTemp - 2) {
digitalWrite(RELAY, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
// General display of current sensor readings
lcd.setCursor(0, 0);
String temperatureString = String(temperature, 1);
lcd.print("Temp: ");
lcd.print(temperatureString);
lcd.print((char)223);
lcd.print("F ");
lcd.setCursor(0, 1);
lcd.print("Set Temp= ");
lcd.print(setTemp, 1);
lcd.print((char)223);
lcd.print("F ");
//looking for changes on A0 (button presses)
last_key = keypad.get_last_key();
key = keypad.read_key();
if (key != last_key) { // a button was pushed!
lcd.clear();
lcd.setCursor(0, 0);
switch (key) {
case KEY_UP: {
setTemp += 0.1;
//lcd.print("Temp Set to: ");
//lcd.print(setTemp);
//delay(800);
break;
}
case KEY_DOWN: {
setTemp -= 0.1;
//lcd.print("Temp Set to: ");
//lcd.print(setTemp);
//delay(800);
break;
}
case KEY_SELECT: {
String humidityString = String(humidity, 0);
lcd.print("Hum: ");
lcd.print(humidityString);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Prs: ");
String pressureString = String(pressure, 2);
lcd.print(pressureString);
lcd.print(" hPa");
delay(5000);
break;
}
case KEY_LEFT: {
digitalWrite(RELAY, HIGH); {
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
lcd.print("Cooling ON");
delay(800);
break;
}
}
case KEY_RIGHT: {
digitalWrite(RELAY, LOW); {
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
lcd.print("Cooling OFF");
delay(800);
break;
}
}
}
}
}
// This is the BME280 setup stuff and believe it has to be outside the loop brackets or it
// throws an error on line 80 "getPressure was not declared in scope"
float getTemperature()
{
temperature = bme.readTemperature();
temperature = Celcius2Fahrenheit(temperature);
}
float getHumidity()
{
humidity = bme.readHumidity();
}
float getPressure()
{
pressure = bme.readPressure();
pressure = bme.seaLevelForAltitude(ALTITUDE, pressure);
pressure = pressure / 100.0F;
}
float Celcius2Fahrenheit(float celsius)
{
return celsius * 9 / 5 + 32;
}