5 Replies Latest reply on Mar 17, 2020 6:05 AM by eeEn_4618901

    I2C Full Keyboard Sample (CardKb)

    MoTa_728816

      Hi, I feel somewhat guilty about calling this a sample,

      but knowing that we have access to an I2C Full Keyboard may be good!

       

      これをサンプルと言い張るのは少しずうずうしいかもしれませんが、

      I2C で接続できるフルキーボードが安価に入手できるのは良い知らせかも知れません。

       

      In the discussion of Data entry from keyboard  to PSOC

      I encountered M5Stack Official CardKB Mini Keyboard Unit MEGA328P GROVE I2C USB ISP Programmer for ESP32 Arduino Development Board STE…

       

      Data entry from keyboard  to PSOC のスレで、I2C で接続できるミニキーボードを見つけました。

      M5Stack Official CardKB Mini Keyboard Unit MEGA328P GROVE I2C USB ISP Programmer for ESP32 Arduino Development Board STE…

       

      So I ordered a couple of these and they arrived today.

       

      スイッチサイエンスさんのウェブにあったのでポチッたところ、今日到着しました。

      M5Stack用カード型キーボードユニット - スイッチサイエンス

       

      Pins from top to bottom are

      ============

      1 GND

      2 5V

      3 SDA

      4 SCL

      ============

      IMG_4142.JPG

       

      schematic

      001-schematic.JPG

       

      pins

      002-pins.JPG

       

      main.c

      ====================

      #include "project.h"

      #include "stdio.h"

       

      #define CARDKB_I2C_SLAVE_ADDR   0x5F

       

      #define STR_LEN 64

      char str[STR_LEN+1] ;

      void print(char *str)

      {

          UART_PutString(str) ;

      }

       

      void printc(char c)

      {

          UART_PutChar(c) ;

      }

       

      void cls(void)

      {

          print("\033c") ; /* reset */

          CyDelay(20) ;

          print("\033[2J") ; /* clear screen */

          CyDelay(20) ;

      }

       

      void splash(void)

      {

          cls() ;

          print("5LP CardKb Test") ;

          snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;

          print(str) ;

      }

       

      void init_hardware(void)

      {

          CyGlobalIntEnable; /* Enable global interrupts. */

          UART_Start() ;

          splash() ;

         

          I2C_Start() ;

      }

       

      uint8_t myI2C_ReadByte(uint8_t reg_addr)

      {

          uint8_t status ;

          uint8_t value = 0 ;

         

          I2C_MasterClearStatus();

       

          status = I2C_MasterSendStart(CARDKB_I2C_SLAVE_ADDR, I2C_WRITE_XFER_MODE) ;

         

          if (I2C_MSTR_NO_ERROR == status) {

              I2C_MasterWriteByte(reg_addr);

              status = I2C_MasterSendRestart(CARDKB_I2C_SLAVE_ADDR, I2C_READ_XFER_MODE); 

          }

         

          if (I2C_MSTR_NO_ERROR == status) {  

              value = I2C_MasterReadByte(I2C_ACK_DATA);

          }

          I2C_MasterSendStop(); 

         

          return(value) ;

      }

       

      uint8_t read_cardkb(void)

      {

          uint8_t key = 0 ;

          key = myI2C_ReadByte(1) ;

          return( key ) ;

      }

       

      int main(void)

      {

          uint8_t key ;

         

          init_hardware() ;

       

          for(;;)

          {

              key = read_cardkb() ;

              if (key) {

      //            snprintf(str, STR_LEN, "%02X ", key) ;

      //            print(str) ;

                  printc(key) ;

              }

              CyDelay(10) ;

          }

      }

      ====================

       

      Tera Term log

      000-TeraTerm-log.JPG

      moto