Analogwerte zum I2HAA-Modul übertragen
Das Programmbeispiel schreibt auf Tastendruck Analogwerte zur Analog-Ausgabekarte
Programmcode
import tkinter as tk import smbus bus = smbus.SMBus(1) mainWin = tk.Tk() mainWin.title("Analoge Ausgabekarte") def uebertragen1(): val=e1.get() a=int(val) HBy = int(a/256) LBy = int(a-HBy*256) field=[LBy,HBy] print(field) bus.write_i2c_block_data(0x58,0x00,field) def uebertragen2(): val=e2.get() a=int(val) HBy = int(a/256) LBy = int(a-HBy*256) field=[LBy,HBy] print(field) bus.write_i2c_block_data(0x58,0x01,field) def uebertragen3(): val=e3.get() a=int(val) HBy = int(a/256) LBy = int(a-HBy*256) field=[LBy,HBy] print(field) bus.write_i2c_block_data(0x58,0x02,field) def uebertragen4(): val=e4.get() a=int(val) HBy = int(a/256) LBy = int(a-HBy*256) field=[LBy,HBy] print(field) bus.write_i2c_block_data(0x58,0x03,field) #label0 = tk.Label(mainWin, text='Werte 0-1023 = 0-10,23V') e1 = tk.Entry(mainWin,width=7) e1.grid(row=2,column=1) e2 = tk.Entry(mainWin,width=7) e2.grid(row=3,column=1) e3 = tk.Entry(mainWin,width=7) e3.grid(row=4,column=1) e4 = tk.Entry(mainWin,width=7) e4.grid(row=5,column=1) button1t = tk.Button(mainWin,width=7,text='Kanal 1',command=uebertragen1) button1t.grid(row=2,column=2) button2t = tk.Button(mainWin,width=7,text='Kanal 2',command=uebertragen2) button2t.grid(row=3,column=2) button3t = tk.Button(mainWin,width=7,text='Kanal 3',command=uebertragen3) button3t.grid(row=4,column=2) button4t = tk.Button(mainWin,width=7,text='Kanal 4',command=uebertragen4) button4t.grid(row=5,column=2) mainWin.mainloop()