def __init__(self, name, hostname): ''' ''' self.name = name self.hostname = hostname # topic = 'pump/'+name # client.message_callback_add(topic,self.on_message) # # wiringpi.wiringPiSetupGpio() # # wiringpi.pinMode(PORT,1) # # wiringpi.digitalWrite(PORT,not data['status']) # gpio.init() # gpio.setcfg(port.PA10, gpio.OUTPUT) i2c.init("/dev/i2c-0") #Initialize module to use /dev/i2c-2 i2c.open(0x48) #The slave device address is 0x55 #If we want to write to some register #i2c.write([0xAA, 0x20]) #Write 0x20 to register 0xAA #i2c.write([0xAA, 0x10, 0x11, 0x12]) #Do continuous write with start address 0xAA #If we want to do write and read data = [0x84,0xc2] i2c.write([0x01, 0xc2, 0x85 ]) #Set address at 0xAA register i2c.write([0x00]) threading.Timer(9, publish).start() threading.Timer)
def __init__(self, address=BME280_I2CADDR): i2c.init("/dev/i2c-0") self.address = address # Read calibration values self.dig_t1 = self.read_word(BME280_DIG_T1) # Unsigned self.dig_t2 = self.read_word_sign(BME280_DIG_T2) self.dig_t3 = self.read_word_sign(BME280_DIG_T3) self.dig_p1 = self.read_word(BME280_DIG_P1) # Unsigned self.dig_p2 = self.read_word_sign(BME280_DIG_P2) self.dig_p3 = self.read_word_sign(BME280_DIG_P3) self.dig_p4 = self.read_word_sign(BME280_DIG_P4) self.dig_p5 = self.read_word_sign(BME280_DIG_P5) self.dig_p6 = self.read_word_sign(BME280_DIG_P6) self.dig_p7 = self.read_word_sign(BME280_DIG_P7) self.dig_p8 = self.read_word_sign(BME280_DIG_P8) self.dig_p9 = self.read_word_sign(BME280_DIG_P9) self.dig_h1 = self.read_byte(BME280_DIG_H1) # unsigned char self.dig_h2 = self.read_word_sign(BME280_DIG_H2) self.dig_h3 = self.read_byte(BME280_DIG_H3) # unsigned char self.dig_h4 = (self.read_byte(BME280_DIG_H4) << 24) >> 20 self.dig_h4 = self.dig_h4 | self.read_byte(BME280_DIG_H4+1) & 0x0F self.dig_h5 = (self.read_byte(BME280_DIG_H5+1) << 24) >> 20 self.dig_h5 = self.dig_h5 | (self.read_byte(BME280_DIG_H5) >> 4) & 0x0F self.dig_h6 = self.read_byte(BME280_DIG_H6) # signed char if self.dig_h6 > 127: self.dig_h6 = 127-self.dig_h6 # Set Configuration self.write_byte(BME280_CONFIG, BME280_CONFIG_SET) self.write_byte(BME280_CONTROL_HUM, BME280_CONTROL_HUM_SET) self.write_byte(BME280_CONTROL_MEAS, BME280_CONTROL_MEAS_SET)
def __init__(self, bus): """Instantiates a I2CBus Args: bus: string, path to bus address: integer, generally 0x58, the address where mod-io can be found """ try: i2c.init(bus) except IOError: raise I2CBusNotConfiguredProperly( "could not find files for access to I2C bus," "you need to load the proper modules")
def lcd_init(DispSet, EntryMode): i2c.init("/dev/i2c-0") i2c.open(I2C_ADDR) delay_ms(20) nibble(0x30, CMD) delay_ms(5) nibble(0x30, CMD) delay_us(110) nibble(0x30, CMD) nibble(0x20, CMD) write(DispSet, CMD) write(0x08, CMD) write(0x01, CMD) write(0x06, CMD) write(EntryMode, CMD)
def main(): i2c.init("/dev/i2c-1") (chip_id, chip_version) = readBmp180Id() print "Chip ID :", chip_id print "Version :", chip_version print ( temperature, pressure ) = readBmp180() print print "Temperature : ", temperature, "C" print "Pressure : ", pressure, "mbar" print RESULTS = [ [ "Temperature", "Pressure" ], [ temperature, pressure ] ] with open('some.csv', 'wb') as f: writer = csv.writer( f ) writer.writerows( RESULTS )
def ReadADC(Address, channel, ref): config = 0b1000000111000011 config |= (channel << 12) config |= (ref << 9) lectura = 0 aux = 0x80 configH = (config >> 8) configL = config & 0x00FF i2c.init("/dev/i2c-0") i2c.open(Address) #Open ADC I2C i2c.write([0x01, configH, configL]) #Write to Adddress 1 (config register) i2c.close() while (lectura != aux): i2c.open(Address) high = i2c.read(2) i2c.close() lectura = high[0] & aux i2c.open(Address) i2c.write([0x00]) i2c.close() i2c.open(Address) read = i2c.read(2) i2c.close() value = (read[0] << 8) + read[1] return value
#Author Kaname Aimu #Date 01-17-2017 import time import os import re from pyA20 import i2c #Initialize module to use /dev/i2c-0 # i2c-0 is is the upper i2c port on your orangepi GPIO ports #Physical: # 3 - SDA.0 # 5 - SCL.0 i2c.init("/dev/i2c-0") #the address of PCF8574 i2c.open(0x27) #i2c 1602 module pin defination #LEDK is the K pin for LCD background light LED #PCF8574 LCD1602 #D0 RS #D1 RW #D2 E #D3 LEDK #D4 D4 #D5 D5 #D6 D6 #D7 D7
def __init__(self, device_address, port): i2c.init(device_address) i2c.open(port) self.state = None
#!/usr/bin/env python import rospy import time from std_msgs.msg import Float64, UInt16, Bool from pyA20 import i2c # REGISTERS AND ADRESSES REG_speed = 0x82 # speed register ADR_slave = 0x0f # slave device address #Initialize module to use /dev/i2c-2 i2c.init("/dev/i2c-2") def get_params(): global ramp_min global ramp_max # Get parameters from launch file ramp_min = rospy.get_param('~ramp_min') if rospy.has_param( '~ramp_min') else 10 ramp_max = rospy.get_param('~ramp_max') if rospy.has_param( '~ramp_max') else 100 def print_params(): print(" ----- PARAMETERS -----") print(" - Ramp min : " + str(ramp_min)) print(" - Ramp max : " + str(ramp_max)) print(" ----------------------")
""" from pyA20 import i2c __author__ = "Stefan Mavrodiev" __copyright__ = "Copyright 2014, Olimex LTD" __credits__ = ["Stefan Mavrodiev"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" eeprom_address = 0x50 """Initialize i2c bus""" i2c.init("/dev/i2c-1") i2c.open(eeprom_address) """Set address pointer to the first""" i2c.write([0x00]) print "Dump eeprom:" print "="*24 print " ", for i in xrange(16): print " %x" % i, print "\t", for i in xrange(16): print "%x" % i,
msg = "Could not initialize GPIOs, oven operation will only be simulated!" log.warning(msg) gpio_available = False except RuntimeError: msg = "Could not load RPi.GPIO library, trying OrangePiZero library" log.warning(msg) gpio_available = False try: from pyA20.gpio import gpio from pyA20.gpio import port from pyA20 import i2c log.warning("Hello") i2c.init("/dev/i2c-1") #Initialize module to use /dev/i2c-1 i2c.open(0x68) #The slave device address is 0x68 DS1371 i2c.write([0x04, 0xFF, 0xFF, 0xFF]) #If we want to write to some register i2c.write([0x07, 0x4F]) #Write 0x0E to register 0x07 # INTCN 1 WDALM 0 AIE 1 #Initialise the GPIO output gpio.init() #Initialize module. Always called first # gpio.setcfg(config.gpio_watchdog, gpio.OUTPUT) # Configure the watchdog gpio.setcfg(config.gpio_cool, gpio.OUTPUT) # Configure the cooling output gpio.setcfg(config.gpio_reset, gpio.OUTPUT) # Configure Reset as OUTPUT gpio.output(config.gpio_reset, gpio.HIGH) # Set the i2c GPIO reset line High
The i2c address can be different, but on this specific board is 0x50. The text will be big mess if python3 is used. """ from pyA20 import i2c __author__ = "Stefan Mavrodiev" __copyright__ = "Copyright 2014, Olimex LTD" __credits__ = ["Stefan Mavrodiev"] __license__ = "GPL" __version__ = "2.0" __maintainer__ = __author__ __email__ = "*****@*****.**" eeprom_address = 0x28 """Initialize i2c bus""" i2c.init("/dev/i2c-1") i2c.open(eeprom_address) """while loop between 0 and 255""" n = 255 li = range(1, 255 + 1) + range(n, 0, -1) ti = cycle(li) while True: sleep(0.01) i2c.write([0xAA, next(ti)]) i2c.close()
def init(interface, addr): """ Initalize i2c interface """ i2c.init("/dev/i2c-" + str(interface)) i2c.open(addr)
#!/usr/bin/env python from pyA20 import i2c """Initialize i2c bus""" i2c.init("/dev/i2c-2") i2c.open(0x77) #Slave Device adress """Set address pointer to the first""" i2c.write([0x00]) print "Dump eeprom:" i2c.close()
#!/usr/bin/env python from pyA20 import i2c i2c.init("/dev/i2c-0") #Initialize module to use /dev/i2c-0 res = i2c.open(0x20) #The slave device address is 0x2A i2c.write([0x21]) #Set address at 0x21 ADCL register value = i2c.read(1) #Read 1 byte valueL=[hex(x) for x in value] i2c.write([0x20]) #Set address at 0x20 ADCH register value = i2c.read(1) #Read 1 valueH=[int(x) for x in value] total=int(valueL[0],16)+(valueH[0]<<8) voltage=(total+3.737611)/76.250833 percentage=round((100*(voltage-10.4))/2.2) percentage=100 if percentage>100 else percentage percentage=0 if percentage<0 else percentage print str(percentage) i2c.close() #End communication with slave device