Just be aware you are NOT sending integers with your Python code, but are assuming they are integers in your Arduino code. That won't work.
You need to ensure consistency between the two devices. The easiest way is use characters on both ends and then convert them to byte on the Arduino. Also look at the length of the data. You are sending and receiving only a single byte, but integers on the Arduino are two bytes long.
If you want to use serial to do multiple things you should think about implementing a structured serial message format that allows you to send all the forms of commands and data you might need.
Such structures often include "fields" in a serial stream like:
framing bytes/characters (indicates start and end of a message)
command
number of data bytes in message
data (if any)
a checksum term to check the message and framing is valid
For example:
Example serial structure:
SOH ; 0x01 start of header (beginning of data frame)
CMD ; command byte
NDATA ; number of data bytes to follow (if no data, st to 0x00)
DATA0 ; data byte 0
.
.
.
DATAN ; data byte N
CS ; message checksum (LSB of sum of SOH to CS inclusive should be 0x00)
EOT ; 0x04 end of transmission
Examples:
01 26 02 00 01 D6 04
| | | | | | +---------- end of transmission marker
| | | | | +------------- checksum term: 01+26+02+00+01+D6 == 0x0100; & 0xff == 00
| | | | +---------------- state of LED; 00=off, 01=on
| | | +------------------- LED number
| | +---------------------- number of data bytes to follow
| +------------------------- LED control command 0x26
+---------------------------- start of transmission marker
01 13 04 E0 93 04 00 71 04
| | | | | | | | +---- end of transmission marker
| | | | | | | +------- checksum term 01+13+04+E0+93+04+00+71 == 0x0200; & 0xff == 00
| | | +--+--+--+---------- 4-byte uint32_t delay(x) value 0x0493E0 (300000) in little-endian format
| | +---------------------- # of bytes in data field; 4 == sizeof( uint32_t)
| +------------------------- set delay command 0x13
+---------------------------- start of transmission marker
.
.
.
Here is an example of how to change variables from serial monitor. Make sure that the serial baud rate is 115200 and line endings are Both NL&CR. Uses the example #2Receive with an end-marker from the serial input basics and the strtok() function (example #5 of the tutorial). All the information for this example is in the tutorial.
If this is not what you want, you will have to better explain your requirements.
const byte numChars = 12;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
int pin12;
int pin13;
void setup()
{
Serial.begin(115200);
Serial.println("<Arduino is ready>");
Serial.println("make sure line endings set to Both NL & CR");
Serial.println("enter desired pin numbers separated by a comma");
Serial.println("for example: 12,13\n\n");
}
void loop()
{
recvWithEndMarker();
if (newData)
{
//showNewData();
parseData();
}
}
void recvWithEndMarker()
{
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false)
{
rc = Serial.read();
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData()
{
Serial.print("This just in ... ");
Serial.println(receivedChars);
}
void parseData()
{
char *strings[3];
char *ptr = NULL;
byte index = 0;
ptr = strtok(receivedChars, ",");
while (ptr != NULL)
{
strings[index] = ptr;
index++;
ptr = strtok(NULL, ",");
}
pin12 = atoi(strings[0]);
pin13 = atoi(strings[1]);
Serial.print("pin12 = ");
Serial.print(pin12);
Serial.print(" pin13 = ");
Serial.println(pin13);
newData = false;
}