below my two programs
- first is interfacing lcd and keypad
- second is mqtt client server concept using enc28j60
both the programs run independently good.but when i merge this 2 programs my lcd is not working.i dont know how to configure.please help me for this
// first program
//Hello, This is the code to use a 4x4 keypad matrix with and Arduino and show the result on an LCD screen
//You should wire you keypad from 8to1 (keypad pins) to 9to2 Arduino digital pins
//SurtrTech
#include <Keypad.h> //The keypad and LCD i2c libraries
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
char Data[100];
byte data_count = 0, master_count = 0;
#define I2C_ADDR 0x27 //try with 0x3f if not works
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin, BACKLIGHT_PIN, POSITIVE);
const byte numRows = 3; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad
//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numCols][numRows] =
{
{'1', '4', '7'},
{'*', '3', '6'},
{'9', '#', '2'},
{'5', '8', '0'}
};
byte rowPins[numRows] = {9, 8, 7}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols] = {2, 3, 4,5 }; //Columns 0 to 3
//initializes an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup()
{
lcd.begin(16, 2);
//Power on the back light
//lcd.backlight(); Power off the back light
}
void loop()
{
lcd.setCursor(0, 0);
lcd.print("Enter any key");
char keypressed = myKeypad.getKey();
if (keypressed ){
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(10);
digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
Data[data_count] = keypressed ;
lcd.setCursor(data_count,1);
data_count++;
lcd.print(keypressed);
Serial.println(keypressed);
}
}
//second program
#include <avr/dtostrf.h>
#include <UIPEthernet.h>
#include <PubSubClient.h>
#include "DHT.h"
#define CLIENT_ID "ArduinoMQTT"
#define TOPIC "temp"
#define PUBLISH_DELAY 5000
#define DHTPIN 3
#define DHTTYPE DHT11
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
IPAddress mqttServer(192,168,0,112);
EthernetClient ethClient;
PubSubClient mqttClient;
DHT dht(DHTPIN, DHTTYPE);
long previousMillis;
void setup() {
// setup serial communication
Serial.begin(9600);
while(!Serial) {};
Serial.println(F("MQTT Arduino Demo"));
Serial.println();
// setup ethernet communication using DHCP
if(Ethernet.begin(mac) == 0) {
Serial.println(F("Unable to configure Ethernet using DHCP"));
for(;;);
}
Serial.println(F("Ethernet configured via DHCP"));
Serial.print("IP address: ");
Serial.println(Ethernet.localIP());
Serial.println();
// setup mqtt client
mqttClient.setClient(ethClient);
mqttClient.setServer(mqttServer, 1883);
Serial.println(F("MQTT client configured"));
// setup DHT sensor
dht.begin();
Serial.println(F("DHT sensor initialized"));
Serial.println();
Serial.println(F("Ready to send data"));
previousMillis = millis();
}
void loop() {
// it's time to send new data?
if(millis() - previousMillis > PUBLISH_DELAY) {
sendData();
previousMillis = millis();
}
mqttClient.loop();
}
void sendData() {
char msgBuffer[20];
float t = 21.555;//dht.readTemperature();
Serial.print("Temperature: ");
Serial.println(t);
if(mqttClient.connect(CLIENT_ID)) {
mqttClient.publish(TOPIC, dtostrf(t, 6, 2, msgBuffer));
}
}
please help global