jan Posted May 29, 2013 at 09:24 AM Share Posted May 29, 2013 at 09:24 AM http://www.tinkerunity.org/wiki/index.php/I2C_mit_IO16-Bricklet Hab mal meine I2C-Platine von (ganz) früher ausgepackt und mit TF verbunden. Hat geklappt. Wer also auch mal in die Verlegenheit kommt I2C ansteuern zu müssen/wollen, der kann sich gerne am Quelltext bedienen. Fehler, Tipps und Hinweise an mich oder im Wiki bitte ändern. Danke. Quote Link to comment Share on other sites More sharing options...
Nick the Tester Posted June 1, 2023 at 10:49 AM Share Posted June 1, 2023 at 10:49 AM Hallo, ich bin neu bei dieses Forum. Ich habe vor 3-4 Monaten angefangen mit Tinkerforge und Raspi zu arbeiten und möchte ein Sensor Simulator entwickeln als I2C Slave und wäre sehr interessiert an der gelinkte Seite. Leider ist der oben hinzugefügte Thread-link schon gelöscht worden. Kann jemand mir helfen? Quote Link to comment Share on other sites More sharing options...
jan Posted June 1, 2023 at 11:02 AM Author Share Posted June 1, 2023 at 11:02 AM #!/usr/bin/env python # -*- coding: utf-8 -*- HOST = "localhost" PORT = 4223 uid_io16 = 'xxx'; import time from tinkerforge.ip_connection import IPConnection from tinkerforge.bricklet_io16 import IO16 i2c_io16_port='a' #SCL = Port0 scl_port=0 #SDA = Port1 sda_port=1 #Adresse: 01110000 bis 01110111 def PortWert(bitstring=0, port=0): #ermittelt den Wert eines(!) Input-Ports anhand der kompletten Bitmaske wert =bitstring & (1<<port) wert =wert>>port return wert def send_start(): #Start: SDA und SCL = high, SCL geht auf low io.set_port(i2c_io16_port,(1 << scl_port) | (1 << sda_port)) io.set_port(i2c_io16_port,(1 << scl_port) | (0 << sda_port)) io.set_port(i2c_io16_port,(0 << scl_port) | (0 << sda_port)) #Start Ende def send_stop(): #Stop: SDA und SCL = high, SCL geht auf low io.set_port(i2c_io16_port,(1 << scl_port) | (0 << sda_port)) io.set_port(i2c_io16_port,(1 << scl_port) | (1 << sda_port)) #Stop Ende def send_ack(): #Acknowledge io.set_port(i2c_io16_port,(1 << scl_port) | (1 << sda_port)) io.set_port(i2c_io16_port,(0 << scl_port) | (0 << sda_port)) #Acknowledge Ende def send_dat(daten): #Daten for i in range(7,-1,-1): #Bit io.set_port(i2c_io16_port,(1 << scl_port) | (PortWert(daten, i) << sda_port)) io.set_port(i2c_io16_port,(0 << scl_port) | (0 << sda_port)) #Daten Ende send_ack() if __name__ == "__main__": ipcon = IPConnection() # Create IP connection io = IO16(uid_io16, ipcon) # Create device object ipcon.connect(HOST, PORT) # Connect to brickd # Don't use device before it is added to a connection #Ports als Ausgang definieren und erstmal low io.set_port_configuration(i2c_io16_port, (1 << scl_port) | (1 << sda_port), 'o', False) send_start() #Adresse 1110000r/w (r/w=1 für Write) ===> Adresse: 0b11100001 send_dat(0b11100001) #send_dat(0xD9) #TestMode send_dat(0x21) #turn on oscillator send_dat(0x7F) send_dat(0b11101111) #Display volle Helligkeit send_stop() pause=0.05 #time.sleep(pause) ipcon.disconnect() Das ist der Code von damals mit python. SDA und SCL werden einfach als Ausgang am IO bedient. Der Code müsste noch angepasst werden: neues IO-Bricklet, Adresse, etc... Quote Link to comment Share on other sites More sharing options...
Nick the Tester Posted June 7, 2023 at 12:40 PM Share Posted June 7, 2023 at 12:40 PM Dankeschön - ich melde mich bei weitere Fragen :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.