• <small id='ns9xT'></small><noframes id='ns9xT'>

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

      <legend id='ns9xT'><style id='ns9xT'><dir id='ns9xT'><q id='ns9xT'></q></dir></style></legend>
        <bdo id='ns9xT'></bdo><ul id='ns9xT'></ul>

      1. 从 Raspberry pi 发送串行通信

        Sending serial communication from Raspberry pi(从 Raspberry pi 发送串行通信)
          <bdo id='NiwSh'></bdo><ul id='NiwSh'></ul>
        • <legend id='NiwSh'><style id='NiwSh'><dir id='NiwSh'><q id='NiwSh'></q></dir></style></legend>

              <tfoot id='NiwSh'></tfoot>
                • <small id='NiwSh'></small><noframes id='NiwSh'>

                    <tbody id='NiwSh'></tbody>
                  <i id='NiwSh'><tr id='NiwSh'><dt id='NiwSh'><q id='NiwSh'><span id='NiwSh'><b id='NiwSh'><form id='NiwSh'><ins id='NiwSh'></ins><ul id='NiwSh'></ul><sub id='NiwSh'></sub></form><legend id='NiwSh'></legend><bdo id='NiwSh'><pre id='NiwSh'><center id='NiwSh'></center></pre></bdo></b><th id='NiwSh'></th></span></q></dt></tr></i><div id='NiwSh'><tfoot id='NiwSh'></tfoot><dl id='NiwSh'><fieldset id='NiwSh'></fieldset></dl></div>
                  本文介绍了从 Raspberry pi 发送串行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Python 程序将串行数据从 Raspberry Pi 发送到 Arduino.我正在运行 Python 2.7.3.程序是:

                  I am sending serial data from a Raspberry Pi to an Arduino using a Python program. I am running Python 2.7.3. The program is:

                  import serial
                  
                  ser = serial.Serial('/dev/ttyACM0', 115200)
                  
                  ser.write(b'x4cxffx46')
                  

                  问题是如果这三行在程序中运行,它们似乎没有发送任何内容.但是,如果我在 Python shell 中逐行运行它们,它们就可以正常工作.

                  The problem is that nothing seems to be sent by these three lines if they are run in a program. But if I run them line by line in a Python shell, they work fine.

                  另外,如果我打开了 Arduino 串行监视器,程序也可以正常工作,而无需在 shell 中逐行运行.

                  Also, if I have the Arduino Serial Monitor open, the program works fine as well, without running the lines one by one in the shell.

                  编辑添加:

                  发送到 Arduino 似乎有一些延迟.因此,当我在解释模式下运行代码时,它可以工作,但如果作为程序,它就不行.我认为这是因为我在 Windows 机器上尝试了相同的程序.

                  It seems that there is some delay in sending to the Arduino. So when I run the code in interpretive mode, it works, but if as a program, it doesn't. I think that because I tried the same program on a Windows machine.

                  import serial
                  
                  ser = serial.Serial('COM8', 115200)
                  
                  ser.write(b'x4cx20x46')
                  

                  如果我在解释模式下运行程序,甚至在调试模式下使用 ser.write 命令上的断点,它都可以工作.但如果作为程序运行则不会.

                  If I run the program in interpretive mode, or even in debugging mode with a breakpoint on the ser.write command, it works. But not if run as a program.

                  编辑添加更多内容:

                  事实证明,Arduino 具有必须禁用的串行通信自动重置功能:

                  It turns out that the Arduino has an auto-reset on serial communications that has to be disabled:

                  http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection#.UwP_wfldV8E

                  http://forum.arduino.cc/index.php/topic,28723.0.html

                  我在 RESET 引脚和地之间使用了一个 220 uF 的电容器.这样可行.

                  I used a 220 uF capacitor between the RESET pin and ground. That works.

                  很难被这样的虫子咬!它仍然很聪明.

                  Tough to be bitten by a bug like that! It still smarts.

                  推荐答案

                  试试这个.如果您无法在空闲等下运行它,请通过键入 python name.py 尝试终端.我还建议您使用 putty 检查来自/写入 Rpi 的数据以确保.

                  Try this. If you can't run it under idle or etc, try terminal by typing python name.py. I also suggest you to check the data coming or written from/to Rpi with putty to be sure.

                  import serial
                  import time
                  
                  
                  def readlineCR(port):
                      rv = ""
                      while True:
                      ch = port.read()
                      rv += ch
                      if ch == '
                  ' or ch == '':
                           return rv
                  
                  
                  port = serial.Serial("/dev/ttyAMA0", baudrate = 7200, timeout = 2)
                  
                  while True: 
                       rcv = readlineCR(port)
                       port.write("I typed: " + repr(rcv))
                       print(rcv)
                  

                  这篇关于从 Raspberry pi 发送串行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='2zR7B'></tfoot>

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

                              <tbody id='2zR7B'></tbody>

                            <small id='2zR7B'></small><noframes id='2zR7B'>

                          1. <legend id='2zR7B'><style id='2zR7B'><dir id='2zR7B'><q id='2zR7B'></q></dir></style></legend>