python - OpwenWrt - 使用 Python 从 SPI 读取字节
问题描述
我想从 spi 总线读取字节。写入一个字节很简单,只需使用
file = open("/dev/spidev1.0", 'wb')
file.write('#')
我尝试使用 read(1) 命令,但这使得 spi 时钟比仅仅一个字节长。
例子:
file = open("/dev/spidev1.0", 'rb')
file.read(1)
有谁知道为什么当我尝试读取一个字节时它只是时钟 8 次?
(顺便说一下,我使用的是 Carambola2 和 spi over gpio)
解决方案
我自己解决了这个问题。您必须使用 os 库
例子:
import os
file = os.open('filename', os.O_RDWR)
#Write byte 0x1 to SPI Bus
os.write(file, chr(0x1))
#Read one byte from SPI Bus
print(str(ord(os.read(file, 1))))
推荐阅读
- java - 问题: curl: (7) 无法连接到 localhost 端口 1080: Connection refused
- javascript - Tensorflow Square 函数不精确
- javascript - 通过相同的 JS 代码提交多个表单时不支持 POST 方法。(405)
- pandas - 签名为结尾时将字符串格式的负数转换为数字
- opencl - 如何将 cl2.hpp 与 AMD GPU 和 rocm 一起使用
- javascript - 如何在数组中查找对象的出现
- bash - 将 CSV 文件转换为多行文本文件
- javascript - 在javascript数组上使用find时如何检查未定义
- css - 如何将文本与图像对齐
- git - git clone 斜杠