#!/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...