#include <LiquidCrystal.h>
#include <Wire.h>
LiquidCrystal lcd1(13,12,11,10,9,8);
char key;
int shut=0;
int scrmod=0;
int modcanrole=0;
int role=0;
int x=0;
int y=0;
int temp=20;
int hum=60;
char k;
void setup()
{
lcd1.begin(16,2);
lcd1.clear();
Serial.begin(9600);
pinMode(4,INPUT);
pinMode(2,OUTPUT);
pinMode(A2,INPUT);
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);
}
void loop()
{
delay(100);
}
void receiveEvent(int howMany)
{
char c= Wire.read(); // receive byte as a character
k=c;
lcd1.setCursor(0,0);
lcd1.write(k);
lcd1.write("hi");
lcd1.write(k);
//master, receiver
}
This is the code on Receiver UNO ( ignore extra variables, pinMode statements)
[code]
// 4x4 keypad hooking
//
#include <Keypad.h>
#include <Wire.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
}
;int aut=1;
int mod=0;
byte rowPins[ROWS] = {12, 11, 10, 9};
byte colPins[COLS] = {7, 6, 5, 4};
//
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(2,OUTPUT);
Wire.begin();
}
void loop(){
Wire.beginTransmission(4);
char key = keypad.getKey();// Read the key
Wire.write(key);
Wire.endTransmission();
// key hooking done
delay(100);
}
And this be the code on Master UNO
And this is the picture presenting the wiring ( two UNOs' are communicating , on the left side is Receiver, when Master sends the char byte once receiver hears it then corresponding LCD tells it )
After I push the button(- pick, 1st row, 4th col), Master sends the corresponding byte data(- say 'A'), Receiver gets it (- 'A' on Serial monitor)
LCD manages to show "AhiA" on it's screen, on the (0,0)th point
- but with weired 'dots' on (0,0)th and (3,0)th point; on "h" "i" be clearly nothing
(*though they are not randomly placed; for each points dots make identical pattern)
thus I end up seeing some glitchy "AhiA" shaped thing on the monitor.
(for other cases gives the same result)
I have checked that either of LCD itself, wiring, codes and I2C communication are on-tight.
What could cause such events?