Following my previous topic Cannot Read/Write to an 24LC256 EEPROM chip - Storage - Arduino Forum i tried adding to my project that has an lcd display of 20 columns and 4 rows the external EERPOM and read/write some data on it. More specifically i want (for starters) to have a value stored at the EEPROM (in my case it is 100) that will be used to dim the lcd display and later on i can change this value and store it at the external EEPROM. Even though the read/write code works as intended at the provided link, when i initialize the wire.h library the code freezes and the display shows 3 ' ' ' ' and it continues with garbage characters. I checked this by using only the command Wire.begin(); and the program froze as i mentioned before, when the Wire.begin(); is removed the program i have works as intended (without any option to read/write at the EEPROM)
The following code is part of the starting code i have along with the setup function and the read function for the EEPROM. i do not include the loop function since the problem is located at the setup function. The board i use is the Leonardo
Any help is much appreciated
#include <LiquidCrystal.h> //LCD Library
#include <MenuBackend.h> //MenuBackend library - copyright by Alexander Brevig
#include <OneWire.h> //Onewire Library
#include <DallasTemperature.h> // Dallas library
#include <Wire.h> //I2C Library for external EEPROM
#include "DHT.h" // DHT Library
#define DHTPIN 8 // DHT sensor pin on arduino
#define DHTTYPE DHT22 // DHT22 sensor
#define ONE_WIRE_BUS 12 //pin where one bus sensor is connected
#define EEPROM_ADDRESS 0x50 //address for external EEPROM
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); //Pass oneWire reference to Dallas Temperature.
DeviceAddress HeaterTemp = {
0x28, 0x57, 0xFF, 0x08, 0x04, 0x00, 0x00, 0x0FE }; //Dallas sensor address
DHT dht(DHTPIN, DHTTYPE); //define the dht instance
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //LCD pins
boolean ButtonPushed = 0;
float temperature = 0;
int humidity = 0;
float dew = 0;
float ota = 0;
int read_button = 0;
boolean menus = 0; //case for menus
byte lcd_brightness; //starting amount of brightness for lcd the will be read form EEPROM
int fadeAmount = 5; //amount of lcd fading
int reading = 0; //initial reading for analog buttons
const int HeaterPin = 10; //FET pin No.
const int Buzzer = 11; //buzzer pin
const int backlightPin = 13; //LCD backlight dim pin
byte newChar[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000};
void setup(){
Serial.begin(9600); //used for debugging
//while(!Serial); //whether it is in comment brackets or active this command does nothing
Wire.begin(); //initialize I2C bus
delay(15); //delay to make sure the EEPROM is initialized
pinMode(HeaterPin, OUTPUT); //mode of FET pin
pinMode(Buzzer, OUTPUT); // Mode of buzzer pin
pinMode(backlightPin, OUTPUT); // pinmode for lcd pin
lcd_brightness=(eepromRead(0,0),DEC); //read value from EEPROM
// Serial.println(lcd_brightness);
lcd.begin(20, 4); //initialize 20 char 4 line lcd
lcd.createChar(0, newChar);
lcd.setCursor(0,0);
//---opening test text---
analogWrite(backlightPin, lcd_brightness);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Kostas Dew Buster");
lcd.setCursor(0,1);
lcd.print("Version 0.15");
lcd.setCursor(0,2);
lcd.print("Test Build 0.5");
lcd.setCursor(0,3);
lcd.print("====================");
delay(5000);
lcd.clear();
//---initialize sensors---
dht.begin();
sensors.begin();
sensors.setResolution(HeaterTemp, 9); //set resolution of Dallas sensor to 9 bits i.e. 0,5C
}
byte eepromRead(byte highAddress, byte lowAddress)
{
Wire.beginTransmission(EEPROM_ADDRESS);
Wire.write(highAddress);
Wire.write(lowAddress);
Wire.endTransmission();
Wire.requestFrom(EEPROM_ADDRESS,1); //request one byte of data from eeprom at address 0x50
while(!Wire.available())
{
}
return Wire.read();
}