pyserial

How to get data from I2C device BH1750 over USB-I2C module in Python3?

大兔子大兔子 提交于 2020-07-30 12:36:03
问题 I am Linux user and I have those devices: USB-I2C convertor: https://www.robot-electronics.co.uk/htm/usb_i2c_tech.htm GY-30 I2C module: https://5.imimg.com/data5/TY/AK/MY-1833510/gy-30-bh1750-intensity-digital-light-sensor-module.pdf And GY-30 is with BH1750 Ambient light sensor: https://www.mylms.cz/wp-content/uploads/2017/07/bh1750-datasheet.pdf I need to read Luxs from BH1750 over virtual serial port in Python3, but I am not sure how to do it. I ended with something like this: import

using pyserial flush method

懵懂的女人 提交于 2020-06-27 12:19:17
问题 I've read somewhere that the use of flush is necessary to reduce lag. Is this true? I'm not really sure about using it. Please help me understand what it does exactly. I've checked pyserial docs but it didnt give me much information. All it said was: flush() Flush of file like objects. It’s a no-op in this class, may be overridden. 回答1: Information you're sending/writing may be temporarily stored in a buffer, so that a larger chunk can be written in one go. So, if you do: f = open("test.txt",

Using pySerialTransfer over bluetooth sockets

旧巷老猫 提交于 2020-06-17 09:59:11
问题 I have working code that sends a struct from a Raspberry Pi to an Arduino using pySerialTransfer when the devices are connected via a USB cable. I'd like to do that over bluetooth instead of with a USB cable, however. Independently, using separate python code and a separate Arduino sketch, I've been able to get the Raspberry Pi & Arduino to communicate over bluetooth via a continuous stream of text or binary data. My issue is that I don't see how to combine the two approaches - i.e.: if I

Pyserial when should I use flush?

女生的网名这么多〃 提交于 2020-06-17 02:08:07
问题 I'am working with pyserial and trying to write and read data to and from an arduino board. I saw several examples showing that flush should be used while reading and writing. I couldn't understand what is the role of flush even after reading the pyserial documentation. I also noticed that there is: flushInput() flushOutput() flush() What is the role of each one, why and when should I use it. I'd appreciate the explanation. 回答1: [Quotes from pySerial API documentation] flushInput() "Deprecated

Python Convert String to Byte

谁都会走 提交于 2020-05-30 08:06:36
问题 I am trying to do some serial input and output operations, and one of those is to send an 8x8 array to an external device (Arduino). The pySerial library requires that the information that I send be a byte. However, in my python code, the 8x8 matrix is made up of types <class 'str'> . Here's my sending function: import serial import Matrix width = 8 height = 8 portName = 'COM3' def sendMatrix(matrix): try: port = serial.Serial(portName, 9600, timeout = 1000000) port.setDTR(0) print("Opened

Python Convert String to Byte

℡╲_俬逩灬. 提交于 2020-05-30 08:06:31
问题 I am trying to do some serial input and output operations, and one of those is to send an 8x8 array to an external device (Arduino). The pySerial library requires that the information that I send be a byte. However, in my python code, the 8x8 matrix is made up of types <class 'str'> . Here's my sending function: import serial import Matrix width = 8 height = 8 portName = 'COM3' def sendMatrix(matrix): try: port = serial.Serial(portName, 9600, timeout = 1000000) port.setDTR(0) print("Opened

Connect to serial from a PyQt GUI

痴心易碎 提交于 2020-05-09 17:27:18
问题 I write a program to that send and recive data from serial, but I have a problem, I want to create a function "connect()" or a class, and when I press a button, the function is executed, but if I create this function in "MainWindow" class, variable "ser" from "TestThread" class become uninitialized, can you help me? import sys import serial from PyQt5.QtWidgets import QMainWindow, QApplication from PyQt5.QtCore import QThread, pyqtSignal from PyQt5.uic import loadUi ser = serial.Serial('/dev

21.python通过pyserial读写串口--2013-06-02

拟墨画扇 提交于 2020-04-14 04:42:17
【今日推荐】:为什么一到面试就懵逼!>>> 因为有个需要用有源RFID搞资产管理的项目,需要用python读取读卡器的串口内容。于是装了pyserial模块,用了下很方便,整理下常用功能 一、 为了使用python操作串口,首先需要下载相关模块: 1. pyserial ( http://pyserial.wiki.sourceforge.net/pySerial ) 2. pywin32 ( http://sourceforge.net/projects/pywin32/ ) 2,十六进制显示 十六进制显示的实质是把接收到的字符诸葛转换成其对应的ASCII码,然后将ASCII码值再转换成十六进制数显示出来,这样就可以显示特殊字符了。 在这里定义了一个函数,如hexShow(argv),代码如下: [python] view plain copy import serial def hexShow(argv): result = '' hLen = len(argv) for i in xrange(hLen): hvol = ord(argv[i]) hhex = '%02x' %hvol result += hhex+ ' ' print 'hexShow:' ,result t = serial.Serial( 'com12' , 9600 ) print t.portstr

温度传感器+I2C+串口+PC上位机(pyserial)例子

情到浓时终转凉″ 提交于 2020-04-14 04:23:09
【今日推荐】:为什么一到面试就懵逼!>>> 温度传感器+I2C+串口+PC上位机(pyserial)例子 例子写的有点乱,主要是学习: 温度传感器DS18b20,E2PROM,I2C, 串口读写,PC上位机(pyserial)数据显示 SerialPort.py PC串口上位机程序,可以设定上限报警温度 需要安装Python3以上,pyserial库,例子在Python3.4下写的。 上位机传给单片机上限报警温度后,单片机存入E2PROM, 单片机断电重启后,从E2PROM读取报警值。 i2c.h I2C总线读写和设定 lcd1602.h lcd1602的读写和设定 temp_ds18b20.h DS18b20的读写和设定 #define AT24C02 0xa0 // AT24C02 写数据的设备地址 #define MAX_TEMP_E2PROM_FLAG 0xff // 上限报警温度的存储器数据标志,存在说明存储器有数据 sbit power_port = P2^3; // 报警端口 int max_temp = 340; // 报警上限温度,默认340 int max_temp_buf = 0; // 报警上限温度缓存,用于串口 int sp_read_count = 0; // 串口数据,读取的字节计数 bit sp_read_flag = 0; // 串口读取标志

how to make python awaitable object

 ̄綄美尐妖づ 提交于 2020-03-18 03:51:57
问题 In python 3.5.1 one can make use of await/async, however, to use it (as I undestand), you need to have awaitable object . An awaitable object is an object that defines __await__() method returning an iterator. More info here. But I can not google out any example of having this, since most examples have some sort of asyncio.sleep(x) to mimic awaitable object. My ultimate goal is to make simple websocket serial server, however, I can't pass this first step. This is my (non working code). import