示例#1
0
 def __init__(self, col, row):
     #self.i2c=i2c
     self._row = row
     self._col = col
     print("LCD _row=%d _col=%d" % (self._row, self._col))
     self.LCD = wiringpi.wiringPiI2CSetup(LCD_ADDRESS)
     self.RGB = wiringpi.wiringPiI2CSetup(RGB_ADDRESS)
     self._showfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS
     self.begin(self._row, self._col)
示例#2
0
    def initInterface(self):
        wpi = self.wpi
        self.file_descriptor_mpu = wpi.wiringPiI2CSetup(self.ADDRESS_I2C_MPU)
        #self.wpi.wiringPiI2CWriteReg8(self.file_descriptor_mpu,self.REGISTER_PWR_MGMT_1, 0x00)  # turn sleep mode off
        #time.sleep(0.2)
        self.wpi.wiringPiI2CWriteReg8(self.file_descriptor_mpu,
                                      self.REGISTER_INT_PIN_CFG, 0x02)
        #self.wpi.wiringPiI2CWriteReg8(self.file_descriptor_mpu,self.REGISTER_INT_ENABLE, 0x01)
        time.sleep(0.1)
        #without setting the bypass, the magnetometer appears to not exists
        # ... because reasons ...

        file_descriptor_ak = wpi.wiringPiI2CSetup(self.ADDRESS_I2C_AK)
        return file_descriptor_ak
示例#3
0
    def init(self):

        global b
        b = wpi.wiringPiI2CSetup(0x1c)

        self.mode_configuration()
        self.data_configuration()
示例#4
0
    def __init__(self):

        global a

        a = wpi.wiringPiI2CSetup(0x1e)

        #set range

        wpi.wiringPiI2CWriteReg8(a, 0x01, 0b001 << 5)

        #setMeasurementMode

        value = wpi.wiringPiI2CReadReg8(a, 0x02)
        value &= 0b11111100
        value |= 0b00

        wpi.wiringPiI2CWriteReg8(a, 0x02, value)

        #setDataRate

        value = wpi.wiringPiI2CReadReg8(a, 0x00)
        value &= 0b11100011
        value |= (0b101 << 2)

        wpi.wiringPiI2CWriteReg8(a, 0x00, value)

        #setSamples

        value = wpi.wiringPiI2CReadReg8(a, 0x00)
        value &= 0b10011111
        value |= (0b11 << 5)

        wpi.wiringPiI2CWriteReg8(a, 0x00, value)
示例#5
0
def start_pwm_driver(pwm_addr):

    global PWM_ON_ADDR_LOW
    global PWM_ON_ADDR_HIGH

    pwm_id = wiringpi.wiringPiI2CSetup(pwm_addr)
    time.sleep(0.001)

    # OSCILLATOR = ON
    wiringpi.wiringPiI2CWriteReg8(pwm_id, mode_1_reg_address, mode_1_reg_value)

    # FREQ = 200Hz
    wiringpi.wiringPiI2CWriteReg8(pwm_id, 0xFE, 0x1E)

    # SET MOTORS ENABLE DELAY TIME = 100
    for a in range(0, 6):

        PWM_MSB, PWM_LSB = divmod(100, 1 << 8)

        byte_low = PWM_ON_ADDR_LOW[a]
        byte_high = PWM_ON_ADDR_HIGH[a]

        wiringpi.wiringPiI2CWriteReg8(pwm_id, byte_low, PWM_LSB)
        wiringpi.wiringPiI2CWriteReg8(pwm_id, byte_high, PWM_MSB)

    return pwm_id
示例#6
0
def mlx_init():
    ret = wpi.wiringPiSetup()  # wPi
    if ret:
        log(logging.ERROR, "设备初始化失败")
        raise WiringPiSetupError("主设备初始化失败!")
    bus_fd = wpi.wiringPiI2CSetup(settings.SMBus)  # I2C初始化
    return bus_fd
示例#7
0
    def __init__(self, address=0x20, config=None):
        """
        Initialize the connection to the chip and set the a configuration if given

        address: int
            integer of the I2C address of the TCA9555 (default is 0x20 e.g. 32)
        config: dict
            dictionary holding register values which should be set
        """

        # I2C-bus address; 0x20 (32 in decimal) if all address pins A0=A1=A2 are low
        self.address = address

        # Setup I2C-bus communication using wiringpi library
        self.device_id = wp.wiringPiI2CSetup(self.address)

        # Quick check; if self.device_id == -1 an error occurred
        if self.device_id == -1:
            raise IOError(
                "Failed to establish connection on I2C-bus address {}".format(
                    hex(self.address)))

        # Flag which indicates writing or reading condition
        self._device_available = Event()
        self._device_available.set()

        if config:
            self.config = config
示例#8
0
    def init(self):

        global a

        a=wpi.wiringPiI2CSetup(0x1e)

            #set range

        wpi.wiringPiI2CWriteReg8(a,0x01, 0b001 << 5);

            #setMeasurementMode

        value = wpi.wiringPiI2CReadReg8(a,0x02);
        value &= 0b11111100;
        value |= 0b00;  

        wpi.wiringPiI2CWriteReg8(a,0x02, value);

            #setDataRate

        value = wpi.wiringPiI2CReadReg8(a,0x00);
        value &= 0b11100011;
        value |= (0b101 << 2);  

        wpi.wiringPiI2CWriteReg8(a,0x00, value);

            #setSamples

        value = wpi.wiringPiI2CReadReg8(a,0x00);
        value &= 0b10011111;
        value |= (0b11 << 5);

        wpi.wiringPiI2CWriteReg8(a,0x00, value);
示例#9
0
    def getHumidity(self):
        with self.busMux.lock:
            self.busMux.setBusMux(self.device_num)
            i2cDev = wiringpi.wiringPiI2CSetup(self.device_id)
            # Read both the humidity and the temperature, one measurement
            reading1 = wiringpi.wiringPiI2CReadReg16(i2cDev, 0xE5) >> 2

        return (125.0 * reading1) / 65536.0 - 6.0
示例#10
0
	def setupCompass(self):
		self.comp=wiringPiI2CSetup(HMC5883)
		if(self.comp == -1):
			print "Error al conectar con HMC5883"
			return -1  
		#Turning on the ADXL345
		wiringPiI2CWriteReg8(self.comp, 0x02, 0x00)      
		return 0
示例#11
0
    def getTemperature(self):
        with self.busMux.lock:
            self.busMux.setBusMux(self.device_num)
            i2cDev = wiringpi.wiringPiI2CSetup(self.device_id)
            # Read both the humidity and the temperature, one measurement
            reading = wiringpi.wiringPiI2CReadReg16(i2cDev, 0xE3) >> 2

        return (175.72 * reading2) / 65536.0 - 46.85
示例#12
0
 def SetUp(self):
     wp.wiringPiSetup()
     self.fd = wp.wiringPiI2CSetup(self.device)
     wp.wiringPiI2CWriteReg8(self.fd, self.register_A, 0x70)
     wp.wiringPiI2CWriteReg8(self.fd, self.register_B, 0x20)
     wp.wiringPiI2CWriteReg8(self.fd, self.register_Mode, 0x00)
     # self.CalibrateMag(self.fd)
     return
示例#13
0
	def setupAcc(self):
		self.acc=wiringPiI2CSetup(ADXL345)
		if(self.acc == -1):
			print "Error al conectar con ADXL345"
			return -1  
		#Turning on the ADXL345
		wiringPiI2CWriteReg8(self.acc, 0x31, 0x01)      
		wiringPiI2CWriteReg8(self.acc, 0x2d, 0x08)
		return 0
示例#14
0
def start_dev(address, adres_rejestru1, adres_rejestru2, bajt_danych1,
              bajt_danych2):

    fd = wiringpi.wiringPiI2CSetup(address)
    time.sleep(0.01)

    wiringpi.wiringPiI2CWriteReg8(fd, adres_rejestru1, bajt_danych1)
    wiringpi.wiringPiI2CWriteReg8(fd, adres_rejestru2, bajt_danych2)

    return fd
示例#15
0
 def writeData(self, address, str):
     str = str + "*"
     bs = str.encode()
     if add_dict[address] is not None:
         bus = add_dict[address]
     else:
         bus = wpi.wiringPiI2CSetup(address)
         add_dict[address] = bus
     for byte in bs:
         wpi.wiringPiI2CWrite(bus, int(byte))
示例#16
0
def get_gyroscope_xyz():
    fd = wiringpi.wiringPiI2CSetup(0x6B)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x20, 15)
    x = twos_complement_combine(wiringpi.wiringPiI2CReadReg8(fd, 0x29),
                                wiringpi.wiringPiI2CReadReg8(
                                    fd, 0x29)) / 32768  # left, right
    y = twos_complement_combine(wiringpi.wiringPiI2CReadReg8(
        fd, 0x2B), wiringpi.wiringPiI2CReadReg8(fd, 0x2A)) / 32768  # up, down
    z = twos_complement_combine(wiringpi.wiringPiI2CReadReg8(
        fd, 0x2D), wiringpi.wiringPiI2CReadReg8(fd, 0x2C)) / 32768  # rotation
    return jsonify({"gyroscope": [str(x), str(y), str(z)]})
 def _initConnection(self):
     try:
         device = wiringpi.wiringPiI2CSetup(self.address)
         print("Successfully conneced to PCA9685 IC Chip.\n")
         return device
     except AttributeError:
         print(
             "Failed to connect to device. Please check the connection.\n")
         print(
             "Tip:\t You may need to initialize the I2C bus using raspi-config.\n"
         )
         exit(0)
def init(address=HT16K33_DEFAULT_ADDRESS):
    """HT16K33初期化処理"""
    # wiringpi.wiringPiSetup() は __init__.py で実行済み
    fd = wiringpi.wiringPiI2CSetup(address)
    if fd == -1:
        print('wiringPiI2CSetup error')
        return -1
    set_ocillator(fd, True)
    set_display(fd, app_display_on, app_blink_rate)
    set_brightness(fd, app_brightness)
    clear()
    return fd
示例#19
0
    def __init__(self,devid=0x76):
        '''Initialze the I2C port with wiringpi and start the BMP280 sensor.
        Arguments: devid = the device ID of the sensor, defaults to 0x76'''

        wp.wiringPiSetupGpio()                 # Use the GPIO numbering scheme.
        self.fh = wp.wiringPiI2CSetup(devid)   # Open com to devide
        dat =  wp.wiringPiI2CReadReg8(self.fh,0xD0) # Check device ID
        if dat != 0x58:
            print('''The device at address 0x{:02x} returned 0x{:02x} instead of 0x58.\n
            Probably this is the wrong device.'''.format(devid,dat))
            return(0)

        wp.wiringPiI2CWriteReg8(self.fh,0xF4,0b00100111) # Set for normal operation, 1x oversampling.
示例#20
0
	def setupGyro(self):
		self.gy=wiringPiI2CSetup(ITG3200)
		if(self.gy == -1):
			print "Error al conectar con ITG3200"
			return -1  
		#Turning on the ITG3200
		wiringPiI2CWriteReg8(self.gy, 0x3e, 0x00)      
		wiringPiI2CWriteReg8(self.gy, 0x15, 0x07)
		wiringPiI2CWriteReg8(self.gy, 0x16, 0x1e)
		wiringPiI2CWriteReg8(self.gy, 0x17, 0x00)

		delay(10)

		self.gyroCalibrate()
示例#21
0
 def __init__(self, address=PCA9685_ADDRESS, i2c=None, **kwargs):
     """Initialize the PCA9685."""
     # private variables of class
     # self.fd
     self.enAPin = 0
     self.en1Pin = 1
     self.en2Pin = 2
     self.enBPin = 5
     self.en3Pin = 3
     self.en4Pin = 4
     self.BuzzPin = 8
     self.fd = wp.wiringPiI2CSetup(0x60);
     self.nSpeed = NOR_SPEED
     self.init_start()
示例#22
0
 def initInterface(self, sampling_freqeuncy_hz):
     wpi = self.wpi
     file_descriptor = wpi.wiringPiI2CSetup(self.I2C_ADDRESS)
     #configure device to use remote register for sampling rate control
     reg_value = 0x08 | (1 << 5)  #0x08 default value
     wpi.wiringPiI2CWriteReg8(file_descriptor,
                              self.I2C_REGISTER_ACQ_CONFIG_REG, reg_value)
     #configure device to capture continuously
     wpi.wiringPiI2CWriteReg8(file_descriptor,
                              self.I2C_REGISTER_TRIGGER_COUNT, 0xFF)
     #configure triggering rate
     wpi.wiringPiI2CWriteReg8(file_descriptor,
                              self.I2C_REGISTER_SAMPLING_DELAY,
                              int(2000 / sampling_freqeuncy_hz))
     return file_descriptor
def init(address=HT16K33_DEFAULT_ADDRESS, font=None):
    global seven_seg_font
    """HT16K33初期化処理"""
    # wiringpi.wiringPiSetup() は __init__.py で実行済み
    fd = wiringpi.wiringPiI2CSetup(address)
    if fd == -1:
        print('wiringPiI2CSetup error')
        return -1
    set_ocillator(fd, True)
    set_display(fd, app_display_on, app_blink_rate)
    set_brightness(fd, app_brightness)
    if font is not None:
        seven_seg_font = font
    clear()
    return fd
示例#24
0
def main():
    #init
    wiringpi.wiringPiSetup()
    fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
    if not fd:
        return False
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa1)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xc8)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x8d)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x14)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xa6)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x21)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x00)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0x7f)
    wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xaf)

    #clear oled
    for a in range(8):
        wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + a)
        for b in range(128):
            wiringpi.wiringPiI2CWriteReg8(fd, 0x40, 0x00)

    while True:
        try:
            #get time
            yi[0] = full_string("++++OrangePi++++")
            #yi[1] = full_string(time.strftime("%m/%d %w"))
            yi[1] = full_string(time.strftime("%m/%d %a"))
            yi[2] = full_string(time.strftime("%H:%M"))
            yi[3] = full_string("SSD1306 I2C OLED")

            #write
            for zt3 in range(4):
                wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + (zt3 * 2))
                for zt4 in range(16):
                    for zt in range(8):
                        wiringpi.wiringPiI2CWriteReg8(
                            fd, 0x40, zi[ord(yi[zt3][zt4]) * 16 + zt])
                wiringpi.wiringPiI2CWriteReg8(fd, 0x00, 0xb0 + (zt3 * 2) + 1)
                for zt4 in range(16):
                    for zt in range(8):
                        wiringpi.wiringPiI2CWriteReg8(
                            fd, 0x40, zi[ord(yi[zt3][zt4]) * 16 + zt + 8])
            time.sleep(1)
        except KeyboardInterrupt:
            print("\nexit")
            sys.exit(0)
示例#25
0
def main():
    wiringpi.wiringPiSetup()
    fd = wiringpi.wiringPiI2CSetup(I2C_ADDR)
    if not fd:
        return False
    while True:
        try:
            # clear RTC Register
            clear_register(fd)
            # set sys time to RTC Register
            sys2rtcSet(fd)
            # read RTC Register
            read_register(fd)
            time.sleep(1)
        except KeyboardInterrupt:
            print("\nexit")
            sys.exit(0)
示例#26
0
def init():
    """   
       BSP initialize function. Must be called before any other BSP related
       functions.
    
    """
    global gI2cFd

    if wiringpi.wiringPiSetup() < 0:
        print "bsp_init: failed to initialize wiringPi"
        return -1
        
    gI2cFd = wiringpi.wiringPiI2CSetup(LM75A_I2C_ADDR)
    
    if gI2cFd < 0:
        print "bsp_init: failed to initialize I2C"
        return -1
    
    if wiringpi.wiringPiSPISetup(0, 1000000) < 0:
        print "bsp_init: failed to initialize SPI"
        return -1
    
    return 0
示例#27
0
文件: KS103.py 项目: KNCheung/rpi-ui
 def __init__(self, addr = 0x75):
     self.addr = addr
     self.fd = wpi.wiringPiI2CSetup(addr)
     self.cmd(0xc1)
     self.cmd(0xc3)
     self.cmd(0x73)
示例#28
0
import wiringpi
import sys

fd = wiringpi.wiringPiI2CSetup(0x04)
if fd == -1:
    print "errno: ", errno
    quit()

var = int(sys.argv[1])
print "Trying to set scoop to: ", var

result = wiringpi.wiringPiI2CWriteReg8(fd, 1, var)
if result == -1:
    print "Error writing. errno: ", result
else:
    print "Scoop set to: ", var
 def __link_to_controllers(self):
     #do initial wiringpi library setup
     self.__wiringpisetup = wiringpi.wiringPiSetup()
     self.__controller1 = wiringpi.wiringPiI2CSetup(0x10)
     self.__controller2 = wiringpi.wiringPiI2CSetup(0x11)
示例#30
0
import wiringpi as wp
import time

i2cHandle = wp.wiringPiI2CSetup(0x68)
#g = 9.81
g = 1
roll = 0
pitch = 0
yaw = 0


def configureIMU(devHandle):

    wp.wiringPiI2CWriteReg8(devHandle, 0x6b, 0x01)
    wp.wiringPiI2CWriteReg8(devHandle, 0x1b, 0x00)
    wp.wiringPiI2CWriteReg8(devHandle, 0x1c, 0x18)


def get2sComplement(val):
    if (val & (1 << (16 - 1))) != 0:
        val = val - (1 << 16)
    return val


if i2cHandle is None:
    print 'there was anerror initializing the i2c interface'
else:
    configureIMU(i2cHandle)

    res = wp.wiringPiI2CReadReg8(i2cHandle, 0x75)
    print 'whoami: ', res
示例#31
0
    reg_name[59]: [0x72, 0x00],  #114PCM512X_
    reg_name[60]: [0x73, 0x00],  #115PCM512X_
    reg_name[61]: [0x76, 0x00],  #118PCM512X_
    reg_name[62]: [0x77, 0x00],  #119PCM512X_GPIN
    reg_name[63]: [0x78, 0x00],  #120PCM512X_DIGITAL_MUTE_DET
    reg_name[64]: [0x79, 0x00],  #121PCM512X_
    reg_name[65]: [0x7a, 0x00],  #122PCM512X_
    reg_name[66]: [0x7b, 0x00],  #123PCM512X_
    reg_name[67]: [0x7c, 0x00],  #124PCM512X_
    reg_name[68]: [0x7d, 0x00]  #125PCM512X_
}
Ch_L = 0
Ch_R = 1
mute = 1
wpi.wiringPiSetup()
fb = wpi.wiringPiI2CSetup(0x4d)


def i2c_write(reg_adress, reg_data):
    wpi.wiringPiI2CWriteReg8(fb, reg_adress, reg_data)


def set_clock_ref():
    'set clock tree'
    #select PLLCKIN source(BCK 2.8224M)
    i2c_write(0x0d, 1 << 4)

    #generate PLLCK = PLLCKIN * J.D * R/P = 90.3168MHz
    #J = 16
    i2c_write(21, 16)
    #D = 0
示例#32
0
 def __init__(self):
     self.fd = wp.wiringPiI2CSetup(I2C)  #初始化I2C总线设备
     #初始化I2C
     pass
示例#33
0
# i2c interface comms

print("Loading WiringPi library")

import wiringpi
import smbus
import time

bus = smbus.SMBus(0)
address = 0x60  # result from running i2cdetect -y 0
pin_base = 65
i2c_addr = 0x20

wiringpi.wiringPiSetupGpio()  # need to run with root privileges
print("PP")
wiringpi.wiringPiI2CSetup(pin_base, i2c_addr)


def write(value):
    bus.write_byte_data(address, 0, value)
    return -1


def read(value):
    var = bus.read_byte_data(address, 1)
    return var


# print("Detecting I2C devices on bus")

# run i2cdetect -y 1 in terminal to detect devices on bus
示例#34
0
import wiringpi as wpi
import math

ACC = wpi.wiringPiI2CSetup(0x18)
wpi.wiringPiI2CWriteReg8(ACC, 0x20, 0x27)

while True:
    ACC_x = wpi.wiringPiI2CReadReg8(ACC, 0x28) << 8 | wpi.wiringPiI2CReadReg8(
        ACC, 0x29)
    #
    ACC_y = wpi.wiringPiI2CReadReg8(ACC, 0x2a) << 8 | wpi.wiringPiI2CReadReg8(
        ACC, 0x2b)
    #
    ACC_z = wpi.wiringPiI2CReadReg8(ACC, 0x2c) << 8 | wpi.wiringPiI2CReadReg8(
        ACC, 0x2d)
    #
    #
    #
    #
    #
    if ACC_x > 32768:
        ACC_x = -(65535 - ACC_x + 1)
#
#
    if ACC_y > 32768:
        ACC_y = -(65535 - ACC_y + 1)
#
#
    if ACC_z > 32768:
        ACC_z = -(65535 - ACC_z + 1)
#