Example #1
0
def main():

    address = int(sys.argv[1])
    relayno = int(sys.argv[2])
    status = int(sys.argv[3])
    dev = easyi2c.IIC(address, 1)
    # click relays in turn one after the other
    print "Relay ", relayno
    dev.i2c([relayno, status, 0, 1], 0)  # on
    sleep(0.2)
    dev.close()
Example #2
0
    def __init__(self, easybus=None):
        if easybus:
            self.easyi2c = easybus
            return

        DEVICE_ADDRESS = 0x27      #7 bit address (will be left shifted to add the read write bit)
        # Figure out which bus to use by seeing what devices are present
        import os
        if os.path.exists("/dev/i2c-0"):
            I2C_BUS = 0
        elif os.path.exists("/dev/i2c-1"):
            I2C_BUS = 1
        else:
            raise Exception("HIH6130: can't access the I2C bus on either '/dev/i2c-0' or '/dev/i2c-1'. Have you enabled I2C in the kernel?")

        self.easyi2c = easyi2c.IIC(DEVICE_ADDRESS, I2C_BUS)
Example #3
0
income_data_led = []

flag = 0

servo_up_limit = 2300
servo_down_limit = 1300

#i2c address
address0 = 0x04  #motor0
address1 = 0x08  #motor1
address2 = 0x16  #motor2
address3 = 0x20  #motor3
address4 = 0x30  #servos
address5 = 0x77  #LEDs

bus0 = easyi2c.IIC(address0, 1)
bus1 = easyi2c.IIC(address1, 1)
bus2 = easyi2c.IIC(address2, 1)
bus3 = easyi2c.IIC(address3, 1)
bus4 = easyi2c.IIC(address4, 1)
bus5 = easyi2c.IIC(address5, 1)

out = motors_feedback()

pub = rospy.Publisher('motors_feedback', motors_feedback, queue_size=10)


def l2dig(n):  #function taking last 2 digits of number
    return int(str(n)[-3:]) if '.' in str(n)[-2:] else int(str(n)[-2:])

Example #4
0
import smbus
import time
import easyi2c

# Define the SMBus interface
bus = smbus.SMBus(1)
DEVICE_ADDRESS = 0x6F      #7 bit address (will be left shifted to add the read write bit)
myDevice= easyi2c.IIC(DEVICE_ADDRESS, 1) #address and bus
#DEVICE_REG_MODE1 = 0x00
#DEVICE_REG_LEDOUT0 = 0x1d

#Write a single register
#bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x80)

#Write an array of registers
#ledout_values = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
#bus.write_i2c_block_data(DEVICE_ADDRESS, DEVICE_REG_LEDOUT0, ledout_values)

###THIS WORKS
#easyi2c
#myData=myDevice.i2c([0x00,0x3F],1)
#for iChar in myData:
#	print hex(iChar)

###THIS WORKS
#SMBus
#bus.write_byte_data(DEVICE_ADDRESS, 0x00, 0x30) # the 0x00, 0x00 is the '16 bit' address split into 2 bytes
#myData = bus.read_byte(DEVICE_ADDRESS) # this will read at the current address pointer, which we on the previous line
#print hex(myData)

#Check status