I used arduino mega2560 development board. I want to give number as input by 4*4 keypad. Then in serial communication I want to read that input until specific character.
My Arduino code is already working correctly
This is my Arduino code
#include <Keypad.h>
const byte numRows= 4; //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[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {11,10,9,8}; //Rows 0 to 3
byte colPins[numCols]= {7,6,5,4}; //Columns 0 to 3
//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
int i=0;
int a[20];
int number=0;
int j=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
char keypressed = myKeypad.getKey();
if (keypressed != NO_KEY)
{
i++;
if(keypressed != 'A')
{
a[i]=keypressed-48;
}
else
{
for(int j=1;j<i;j++)
{
Serial.print(a[j]);
}
Serial.print('A');
i=0;
}
}
}
It give these type of serial output
123A (A is my specific number)
then I want to read this serial output within a while loop from python
this is my python code
from __future__ import print_function
import pypyodbc
import serial
import time
import datetime
s = serial.Serial('COM31', 9600)
time.sleep(2)
while (1==1):
code = s.readline()// Read keyboard input
k = str(code)
L= k.index('A')
m= k[:L]
print(m)
But python is not display any thing
Any one know what is the problem here........