title: pyserial 2.7, python 3.3, sending carriage returns
body: <p>I have been attempting to have a Raspberry Pi interface with an embedded circuit using the UART interface. The UART interface on the Pi is in working order and I can receive messages from the circuit, though I am having trouble sending messages to the circuit.</p>
  
  <p>I am using Python 3.3 with Pyserial 2.7. Sample code is available, though it uses Pyserial 2.6. When used with older versions of Python (&lt;2.6), <code>ser.write()</code> accepts strings, but now it only accepts bytearrays.</p>
  
  <p>The problem I am having is in sending carriage returns... The old code supposedly functioned with just:</p>
  
  <p><code>ser.write("L1\r")</code></p>
  
  <p>but now I am using the following:</p>
  
  <p><code>ser.write(bytearray("L1\r", "ascii"))</code></p>
  
  <p>The circuit does not respond to the command. I think the resultant message is sending <code>\r</code> as two individual characters rather than a carriage return. How would I make sure my code is outputting commands appended with carriage returns?</p>
  
  <p>Notes: I can reasonably expect that the circuit is working well and that the Pi's UART interface is functional. The circuit is an Atlas Scientific Dissolved Oxygen Circuit. The circuit's documentation demands that commands be written in the form <code>l1&lt;cr&gt;</code> or <code>L1&lt;CR&gt;</code>.</p>
  
  <p>Relevant links:</p>
  
  <ol>
  <li><p>Old sample code (<a href="https://www.atlas-scientific.com/_files/code/pi_sample_code.pdf" rel="nofollow">https://www.atlas-scientific.com/_files/code/pi_sample_code.pdf</a>) </p></li>
  <li><p>Documentation describing write method (<a href="http://pyserial.sourceforge.net/pyserial_api.html#classes" rel="nofollow">http://pyserial.sourceforge.net/pyserial_api.html#classes</a>)</p></li>
  </ol>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT: Netch makes a strong point: <code>ser.write(b'L1\r')</code> works and is much cleaner. Both methods, however, ARE sending a correct '\r' sequence.. The problem is that the circuit still does not regard <code>L1\r</code> as a valid command. At this point, I think my issue may be some property of my serial port.</p>
  
  <p>My port is declared as such:</p>
  
  <pre><code>ser = serial.Serial(
     port = '/dev/ttyAMA0',
     baudrate = 38400,
     bytesize = serial.EIGHTBITS,
     parity = serial.PARITY_NONE,
     stopbits = serial.STOPBITS_ONE,
     timeout = 1
  )
  </code></pre>
  
  <p>This port declaration is done with accordance to the circuit's datasheet (I can only post two links unfortunately :( Google brings it up easily).</p>