сопряжение клавиатуры с Arduino с использованием I2C - PullRequest
0 голосов
/ 06 марта 2019

Я подключаю клавиатуру 4 * 4 к I2C, а затем I2C к своему Arduino Uno.Но на серийном мониторе ничего не отображается, когда я нажимаю клавишу с клавиатуры.Это мой код: -

#include <Keypad_I2C.h>
#include <Keypad.h>        // GDY120705
#include <Wire.h>

#define I2CADDR 0x27

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 5, 6, 7}; //connect to the column pinouts of the

//initialize an instance of class NewKeypad
Keypad_I2C customKeypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS, I2CADDR); 

void setup(){
//  Wire.begin( );
  customKeypad.begin( );        // GDY120705
  Serial.begin(9600);
  }

void loop(){
  Serial.print("Key pressed= ");
  char customKey = customKeypad.getKey();

  if (customKey != NO_KEY){
     Serial.println(customKey);
  }
}

Это простой код для отображения нажатой клавиши.

Соединения: - R1, R1, R3, R4 подключен к контакту №.4 (P0), 5 (P1), 6 (P2), 7 (P3) I2C.C1, C2, C3, C4 подключен к контакту №.9 (P4), 10 (P5), 11 (P6), 12 (P7) I2C.PIN-код8 (VSS), 1 (A0), 3 (A2) I2C подключен к земле.PIN-код2 (A1), 16 (VCC) I2C подключен к 5V.PIN-код14 (SCL), 15 (SDA) I2C подключен к SCL и SDA I2C.SDA & SCL I2C подключен к A4, A5 Arduino Uno.ПОЖАЛУЙСТА, ПОМОГИТЕ !!!

...