pyserial

Wait on Arduino auto-reset using pySerial

一个人想着一个人 提交于 2019-12-03 12:20:15
I'm trying to read lines from an Arduino board with a very simple code (for the sake of showcasing the problem) on Linux. Python code: # arduino.py import serial arduino = serial.Serial('/dev/ttyACM0') with arduino: while True: print(arduino.readline()) Arduino code: // simpleWrite.ino long ii = 0; void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); } void loop() { Serial.println(ii); ii++; } As the board auto-resets when the serial connection is opened, the first bytes are likely garbage. After a second or two everything works fine. This is a typical output: $

Can I use the xmodem protocol with PySerial?

我是研究僧i 提交于 2019-12-03 09:54:19
I have a working connection with my serial device via PySerial, but I also want to transfer files via the xmodem protocol as part of my program. Which would be the most platform-neutral way to do this? Worst case, I could close() my serial.Serial object in Python and use subprocess to call upon /usr/bin/sb , but that seems inelegant. I'm currently on Ubuntu 9.10 and am using a USB-TTY adapter. Any ideas? There is xmodem module on PyPi. It takes two functions in constructor for reading and writing data, implement them to work with your opened serial port. Below is simple sample of its usage:

Reading real time values with pySerial while plotting

浪子不回头ぞ 提交于 2019-12-03 09:48:53
So here is the deal, I have a module which sends out data over the serial port at 9600 baud and I am using the matplotlib to plot that data in real time. I wrote this code #! python ############ import section ################### import serial import struct import numpy as np import matplotlib.pyplot as plt ############################################### ############ Serial Configuration ############# com = serial.Serial(14,9600) print ("Successfully opened " + com.portstr) ############################################### def get_new_values(): s = com.read(20) raw_data = struct.unpack('

pySerial write() works fine in Python interpreter, but not Python script

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Recently, I am trying to make sort of "light control" on Arduino. I use Raspberry Pi to send the control message via serial port (USB cable).Here is the Arduino code : int redled = 12; int whiteled = 48; void setup() { Serial.begin(9600); pinMode(redled,OUTPUT); pinMode(whiteled,OUTPUT); } void loop() { if(Serial.available()) { char cmd = Serial.read(); switch(cmd) { case'r': digitalWrite(redled,HIGH); delay(2000); digitalWrite(redled,LOW); break; case'w': digitalWrite(whiteled,HIGH); delay(2000); digitalWrite(whiteled,LOW); break; } } else

pyserial for Python 2.7.2

假如想象 提交于 2019-12-03 08:39:43
问题 I'm new to Python. According to the internets I was looking for the module pyserial after receiving this error: ImportError: No module named serial I first tried to install pywin32, it went well. But it seems not to contain pyserial. :-( Then I found a single module installer for pyserial, I was not able to install it, it says it did not found the path to python in the registry. :-( After that I found this module on python.org, but I don't know what to do, it does not come with an installer.

No module named serial

匿名 (未验证) 提交于 2019-12-03 08:33:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: and I got a question when I run my Python code. I installed Python 2.7 on Windows 7, bit 64. I got an error "No module named serial" when I compiled my code: import serial ser = serial.Serial("COM5", 9600) ser.write("Hello world") x = ser.readline() print(x) I tried many ways to crack this problem, such as installed Canopy to setup virtual environment, make sure 'pip' is there, no Python v 3.x installed. But still cannot get it out. Any advice would be appreciated. 回答1: Serial is not included with Python. It is a package that you'll need to

How to send a value from Arduino to Python and then use that value

五迷三道 提交于 2019-12-03 08:14:52
I am in the process of building a robot that is remote controlled using Python to send control messages via the Internet through a simple GUI. I have gotten part of my code working pretty well, the GUI and control systems, but I am stuck. I am trying to use a parallax ping sensor to get distance to objects information from an Arduino Mega , and send that value to my Python control script to be displayed on the remote GUI. The main problem that I am having is how to integrate Python code that will use the already established COM port with the Arduino and send a message to tell the Arduino to

How can I improve PySerial read speed

筅森魡賤 提交于 2019-12-03 08:02:49
I'm currently building a machine that uses an Arduino Mega2560 as its main controller. The Arduino is connected to over serial, gets a command, executes it and spits out a bunch of measurement data every 1ms. I have a Raspberry Pi running Python to give the user a nice GUI to send the command, and to present the data in a readable form. The problem I face: the Arduino is able to spit out 15 byte of data each millisecond (so that's only 15kbyte/s), but the code I'm running can only cope with about 15 byte each 10 milliseconds, so 1.5kB/s. When I run cat /dev/ttyACM0 > somefile , I nicely see

How to expand input buffer size of pyserial

只谈情不闲聊 提交于 2019-12-03 07:01:09
I want to communicate with the phone via serial port. After writing some command to phone, I used ser.read(ser.inWaiting()) to get its return value, but I always got total 1020 bytes of characters, and actually, the desired returns is supposed to be over 50KB . I have tried to set ser.read(50000) , but the interpreter will hang on. How would I expand the input buffer to get all of the returns at once? I have had exactly the same problem, including the 1020 byte buffer size and haven't found a way to change this. My solution has been to implement a loop like: in_buff='' while mbed.inWaiting():

Efficient and fast Python While loop while using sleep()

南笙酒味 提交于 2019-12-03 04:46:38
问题 I am attempting to communicate with a device over serial using Pyserial. As commands need to be continually sent, they have to be placed in a while loop in Python. I am currently using this code, and have taken a look at python process takes 100% CPU: while True: #do some serial sending here time.sleep(0.2) This code works. However, the sending speed is slow. I tried to make it faster by decreasing the sleep interval, but it seems to load the CPU a bit too much. In short, is there a any way