我是覆盆子Pi的GPIO部分的新手.当我需要引脚时,我通常只使用Arduino.但是如果可能的话,我真的希望将这个项目合并到一个平台上,我想在PI上完成所有这些工作.
所以我有三(3)个MAX31855板和K型热电偶.我只是不知道在哪里连接其他两个.我不知道我是否可以使用任何其他引脚(电源和接地引脚除外)用于MISO,CSO和SCLK引脚.这可能听起来像一个菜鸟问题,但就像我说我习惯使用arduino这个东西.任何输入都表示赞赏.提前致谢.
我正在使用https://github.com/Tuckie/max31855中的代码
from max31855 import MAX31855, MAX31855Error
cs_pin=24
clock_pin=23
data_pin=22
unit="f"
thermocouple1=MAX31855(cs_pin, clock_pin, data_pin, units)
print(thermocouple.get())
thermocouple.cleanup()
Run Code Online (Sandbox Code Playgroud) 我们通过 Raspberry Pi 和 Python 的串口从 Arduino 应变仪获取数据。我们拥有它,因此它将读取所有数据进行必要的计算,并将打印到文本文件,但是如果出现电源故障,收集的数据就会丢失。这就是我们正在试图找出如何解决或避免发生的问题。
import serial
ardserial = serial.Serial('/dev/ttyACM0',9600)
counter = 1
def strain():
a=int(adserial.readlines())
b=(str(a*(5/16)/166))
c=float(b)
with open('textfile1.txt','a+') as text_file:
text_file.write('Strain Value: ' + str(c) + '\n')
while counter > 0:
strain()
Run Code Online (Sandbox Code Playgroud)
我们拥有它,因此它会正确写入 txt 文件,并且如果我们终止程序,它将保存所有数据,但我们也希望它在 Raspberry Pi 通电时保存所有数据。它不这样做。
我几乎 100% 确信我过去曾这样做过,如果电源被切断,它会保存保存的数据,但我一辈子都无法弄清楚。任何帮助都会……嗯……有帮助,谢谢。
我正在使用 python 3.5、python-docx 和 TKinter。有没有办法能够在输入框中输入 .txt 文件名,并让 python 将该 .txt 文件的内容插入到 docx 中的特定位置?我知道如何从 tkinter 中的输入框获取信息以及如何将它们转换为字符串。
我希望能够在输入框中输入某人的姓名(这也是文本文件的名称),并让 python 插入 .txt 文件的内容。
谢谢
这里更新是我正在尝试的代码
from tkinter import *
from tkinter import ttk
import tkinter as tk
from docx import Document
root=Tk()
def make_document():
testbox=ProjectEngineerEntry.get()
TestBox=str(testbox)
def projectengineer():
with open(+TestBox+'.txt') as f:
for line in f:
document.add_paragraph(line)
document=Document()
h1=document.add_heading('engineer test',level=1)
h1a=document.add_heading('Project Engineer',level=2)
projectengineer()
document.save('test.docx')
notebook=ttk.Notebook()
notebook.pack(fill=BOTH)
frame1=ttk.Frame(notebook)
notebook.add(frame1,text='Tester',sticky=W)
tester1=Label(frame1,text='Test1')
ProjectEngineerEntry=Entry(frame1)
tester1.pack()
ProjectEngineerEntry.pack()
save=Button(frame1,text='Save',command=make_document).pack()
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我试图从输入框中获取信息,将其转换为字符串,然后使用该字符串打开具有该特定名称的文本文件。然而我不断得到
TypeError:一元 + 的操作数类型错误:'str'
我不明白这是怎么回事。在实际文档中,我在保存文件时使用了 ++ 方法(将其另存为当前日期和时间)。
python ×3
python-3.x ×2
raspberry-pi ×2
gpio ×1
python-3.5 ×1
python-docx ×1
temperature ×1
tkinter ×1