title: Why does my python serial code not work, while sending the same data from the arduino serial monitor does?
body: <p>I have an arduino that reads in two ints over a serial connection when I send the data from the arduino serial monitor it works as it should, but no matter what I do I can't get it to work when I send the same data from python using pySerial, I have been at this hours and have gotten nowhere </p>
  
  <p>I have tried encoding the data as utf8, different encodings flushing the output buffer and have read too many other similar stackoverflow Q&amp;As to count </p>
  
  <p>I am using python 3.7.1 in Windows 10 but the code will untimately be running on a Rpi</p>
  
  <pre class="lang-py prettyprint-override"><code>import os
  import time
  import serial
  ser = serial.Serial('COM7', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=5)
  print("writting")
  time.sleep(0.5)
  ser.write(b'4,5')
  ser.write(b'\r\n')
  time.sleep(0.5)
  ser.flushOutput()
  ser.close()
  </code></pre>
  
  <pre><code>
  #include &lt;SoftwareSerial.h&gt;
  byte buttonPin = 9;
  const int pin_led = LED_BUILTIN; // Pin for indication LED
  int sensorPin = A0;
  int sensorValue = 0;
  int remotePower = 0;  
  
  SoftwareSerial mySerial(11, 12); // RX, TX
  
  void setup()
  {
    pinMode(pin_led, OUTPUT); // Set LED pin as output
    Serial.begin(9600);
    mySerial.begin(9600);
    pinMode(buttonPin, INPUT_PULLUP);
  }
  
  int oldremotePower = 0; 
  
  void loop()
  {
    // if there's any serial available, read it:
    while (Serial.available() &gt; 0) {
      Serial.println("theres Data");
      // look for the next valid integer in the incoming serial stream:
      int mode = Serial.parseInt();
      // do it again:
      int action = Serial.parseInt();
      // do it again:
      //int blue = Serial.parseInt();
  
      // look for the newline. That's the end of your sentence:
      if (Serial.read() == '\n') {
        // constrain the values to 0 - 255 and invert
        // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
        mode = constrain(mode, 1, 4);
        action =  constrain(action, 0, 100);
  
        mySerial.print(mode);
        mySerial.print(",");
        mySerial.println(action);
      }
    }
  
  
      oldremotePower = remotePower;
      sensorValue = analogRead(sensorPin);
      remotePower = map(sensorValue, 0, 1023, 1, 100);
      if (oldremotePower != remotePower){
        //Serial.println(oldremotePower);
        //Serial.println(remotePower);
          }
  
    if (digitalRead(buttonPin) == LOW) {
      mySerial.println(remotePower);
    }
  }
  </code></pre>
  
  <p>I send "1,100" from the arduino serial monitor and the uno responds with "theres Data" and on the software serial it prints the values it was just sent
  this works but when I try to send "1,100\r" from my python script nothing happens the script runs without error the Rx led on the uno flashes but there is no output on the software serial port It must be something wrong with my python serial code.</p>