class Relay(): global bus def __init__(self): self.DEVICE_ADDRESS = 0x20 #7 bit address (will be left shifted to add the read write bit) self.DEVICE_REG_MODE1 = 0x06 self.DEVICE_REG_DATA = 0xff bus.write_byte_data(self.DEVICE_ADDRESS, self.DEVICE_REG_MODE1, self.DEVICE_REG_DATA) def ON_1(self): print 'ON_1...' self.DEVICE_REG_DATA &= ~(0x1<<0) bus.write_byte_data(self.DEVICE_ADDRESS, self.DEVICE_REG_MODE1, self.DEVICE_REG_DATA) #### #!/usr/bin/perl use strict; use Device::SMBus; use Data::Dumper; my $dev = Device::SMBus->new( I2CBusDevicePath => '/dev/i2c-1', I2CDeviceAddress => 0x20, ); $dev->writeByteData(0x06,0x1<<0); print Dumper $dev