1. <small id='7T13H'></small><noframes id='7T13H'>

    <legend id='7T13H'><style id='7T13H'><dir id='7T13H'><q id='7T13H'></q></dir></style></legend>
      <tfoot id='7T13H'></tfoot>
    1. <i id='7T13H'><tr id='7T13H'><dt id='7T13H'><q id='7T13H'><span id='7T13H'><b id='7T13H'><form id='7T13H'><ins id='7T13H'></ins><ul id='7T13H'></ul><sub id='7T13H'></sub></form><legend id='7T13H'></legend><bdo id='7T13H'><pre id='7T13H'><center id='7T13H'></center></pre></bdo></b><th id='7T13H'></th></span></q></dt></tr></i><div id='7T13H'><tfoot id='7T13H'></tfoot><dl id='7T13H'><fieldset id='7T13H'></fieldset></dl></div>

      • <bdo id='7T13H'></bdo><ul id='7T13H'></ul>

      Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序

      Pyserial problem with Arduino - works with the Python shell but not in a program(Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序)
          <tbody id='2jYEt'></tbody>

          <legend id='2jYEt'><style id='2jYEt'><dir id='2jYEt'><q id='2jYEt'></q></dir></style></legend>

              <bdo id='2jYEt'></bdo><ul id='2jYEt'></ul>

            • <tfoot id='2jYEt'></tfoot>
              <i id='2jYEt'><tr id='2jYEt'><dt id='2jYEt'><q id='2jYEt'><span id='2jYEt'><b id='2jYEt'><form id='2jYEt'><ins id='2jYEt'></ins><ul id='2jYEt'></ul><sub id='2jYEt'></sub></form><legend id='2jYEt'></legend><bdo id='2jYEt'><pre id='2jYEt'><center id='2jYEt'></center></pre></bdo></b><th id='2jYEt'></th></span></q></dt></tr></i><div id='2jYEt'><tfoot id='2jYEt'></tfoot><dl id='2jYEt'><fieldset id='2jYEt'></fieldset></dl></div>

              1. <small id='2jYEt'></small><noframes id='2jYEt'>

                本文介绍了Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                好的,所以我很肯定我的 Arduino 电路和它的代码是正确的.我知道这一点,因为当我使用 Arduino IDE 中内置的串行监视器并发送H"时,LED 会亮起,而当我发送L"时,LED 会关闭.

                All right, so I am positive my Arduino circuit is correct and the code for it. I know this because when I use the serial monitor built into the Arduino IDE and send 'H' an LED lights up, when I send 'L' that LED turns off.

                现在我做了一个 Python 程序

                Now I made a Python program

                import serial
                ser = serial.Serial("COM4",9600)
                ser.write("H")
                

                当我运行代码时,LED 会闪烁一秒钟然后又熄灭.但是,当我在 shell 中分别执行这些行时,它的工作原理就像它应该做的那样.

                When I run the code the LED blinks on for a second then goes back off. However when I do each of these lines separately in the shell it works just like it is supposed to.

                有什么想法吗?

                推荐答案

                当你打开串口时,这会导致 Arduino 重置.由于 Arduino 需要一些时间来启动,所有输入都进入 bitbucket(或者可能进入引导加载程序,上帝知道它会做什么).如果你插入一个睡眠,你等待 Arduino 出现所以你的序列号.这就是它以交互方式工作的原因;您正在等待软件启动所需的 1.5 秒.

                When you open the serial port, this causes the Arduino to reset. Since the Arduino takes some time to bootup, all the input goes to the bitbucket (or probably to the bootloader which does god knows what with it). If you insert a sleep, you wait for the Arduino to come up so your serial code. This is why it works interactively; you were waiting the 1.5 seconds needed for the software to come up.

                我确认打开串口会重置我的Arduino Uno;我闪烁了一个程序,该程序将使 setup() 例程中的 LED 闪烁——调用 open("/dev/ttyACM0") 足以触发重置.恕我直言,这是串行支持中令人困惑且未记录的问题.

                I confirmed that opening the serial port resets my Arduino Uno; I flashed a program which will blink the LED from the setup() routine -- calling open("/dev/ttyACM0") was sufficient to trigger the reset. This is IMHO a confusing and undocumented wrinkle in the serial support.

                这篇关于Arduino 的 Pyserial 问题 - 适用于 Python shell 但不适用于程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                <tfoot id='HYNWy'></tfoot>

                • <legend id='HYNWy'><style id='HYNWy'><dir id='HYNWy'><q id='HYNWy'></q></dir></style></legend>
                  <i id='HYNWy'><tr id='HYNWy'><dt id='HYNWy'><q id='HYNWy'><span id='HYNWy'><b id='HYNWy'><form id='HYNWy'><ins id='HYNWy'></ins><ul id='HYNWy'></ul><sub id='HYNWy'></sub></form><legend id='HYNWy'></legend><bdo id='HYNWy'><pre id='HYNWy'><center id='HYNWy'></center></pre></bdo></b><th id='HYNWy'></th></span></q></dt></tr></i><div id='HYNWy'><tfoot id='HYNWy'></tfoot><dl id='HYNWy'><fieldset id='HYNWy'></fieldset></dl></div>

                  1. <small id='HYNWy'></small><noframes id='HYNWy'>

                        • <bdo id='HYNWy'></bdo><ul id='HYNWy'></ul>
                            <tbody id='HYNWy'></tbody>