Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should definitely check the suggestions from the comments:</p> <ul> <li>make the program simpler so that it always sends values without "flow control" (using the "1" byte you send),</li> <li>use a serial monitor to check the output.</li> </ul> <p>First, you shall check if you add a <code>s.flush()</code> before and after your <code>s.write('1')</code> helps. Then you may want to add <code>flush()</code> in your arduino code too.</p> <p>To me it really looks like a starving issue at the initialization of your "flow control" algorithm. On the paper it looks good, but in real life, it may not. Very often, the Arduino sends a lot of garbage when it starts filling up the host serial port's buffer. And the other way around may be true. So instead of having a <code>1</code> on the arduino side, you may get a <code>!@#$@#%@#%!@#$</code> that's totally useless.</p> <p>So on either side, before getting in the loops, you should add an init protocol. The arduino sends <code>READY</code>, the host sends <code>READY</code>, you flush out everything until you get <code>READY</code> on both sides. Something that would look like:</p> <pre><code>void setup() { Serial.begin(9600); Serial.println('READY'); Serial.flush(); char ch1 = 0, ch2 = 0; char incomingByte = 0; while (ch1 != 'O' &amp;&amp; ch2 != 'K') { ch1 = Serial.read(); if (ch1 == 'O' &amp;&amp; ch2 == 'K') break; ch2 = Serial.read(); } } </code></pre> <p>and on the python side:</p> <pre><code>with serial.Serial('/dev/tty.usbserial-AH01LLHS',9600) as s: s.flush() ready = "" while ready != "READY": ready = s.readline() s.flush() while True: # ... you stuff </code></pre> <p>of course that's only an idea of what you may do. You can make it more sophisticated, or way more simple. But before making such flow control, you really need to create a meeting point.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload