def __init__(self, оctoliner_address=OCTOLINER_DEFAULT_I2C_ADDRESS):
     # Setup I2C interface for accelerometer and magnetometer.
     wp.wiringPiSetup()
     self._i2c = wp.I2C()
     self._io = self._i2c.setupInterface(
         '/dev/i2c-' + str(getPiI2CBusNumber()), оctoliner_address)
     self._i2c.write(self._io, OCTOLINER_RESET)
    def __init__(self, gpioexp_address=GPIO_EXPANDER_DEFAULT_I2C_ADDRESS):

        # Setup I2C interface for accelerometer and magnetometer.
        wp.wiringPiSetup()
        self._i2c = wp.I2C()
        self._io = self._i2c.setupInterface(
            '/dev/i2c-' + str(getPiI2CBusNumber()), gpioexp_address)
    def __init__(self):
        gpio.setmode(gpio.BOARD)
        gpio.setup(READY_PIN_ID, gpio.IN)

        wiringpi.wiringPiSetupSys()
        self.i2c = wiringpi.I2C()
        self.bus = self.i2c.setup(SHT31_ADDRESS)
        time.sleep(0.03)
示例#4
0
    def __init__(self, addr, rdyPin):
        wiringpi.wiringPiSetup() #setup wiringpi

        self.i2c = wiringpi.I2C() #get I2C
        self.dev = self.i2c.setup(addr) #setup I2C device
        self.rdy = rdyPin

        wiringpi.pinMode(self.rdy, 0) # set ready pin to INPUT

        self.i2c.writeReg16(self.dev, 0x02, 0x0000) # Config reg を設定 MODE=0 温度、湿度をそれぞれ取り込む
示例#5
0
    def __init__(self, addr=ADC_ADR):
        self.NAME = DATANAME
        self.i2c = wiringpi.I2C()  # Ready to start using the I2C
        self.devADC = self.i2c.setup(
            addr)  # To setup with any address as (0x48 - PFC8591)
        pwrup = self.i2c.read(self.devADC)  #flush powerup value

        if DEBUG == True and pwrup != -1:
            print("ADC Ready")

        self.i2c.read(self.devADC)  #flush first value
        time.sleep(BUS_GAP)
        self.i2c.write(self.devADC, ADC_CYCLE)
        time.sleep(BUS_GAP)
        self.i2c.read(self.devADC)  #flush first value
示例#6
0
 def __init__(self,
              address=0x3E,
              interruptPin=None,
              resetPin=None,
              oscillatorPin=None):
     self.address = address
     self.interruptPin = interruptPin
     self.resetPin = resetPin
     self.oscillatorPin = oscillatorPin
     wiringpi.wiringPiSetupSys()
     self.i2c = wiringpi.I2C()
     self.device = self.i2c.setup(self.address)
     data = [0x00, 0x00]
     data[0] = self.i2c.readReg8(self.device, self.REGISTERS['CHECK'])
     data[1] = self.i2c.readReg8(self.device, self.REGISTERS['CHECK'] + 1)
     if data[0] != 0xFF or data[1] != 0x00:
         raise Error('SX1509 not detected!')
     self.reset(False)
示例#7
0
def LED_put(shape_tmp):
    i2c = pi.I2C()  # I2Cの準備

    shape = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]  #16bit
    ht16k33 = i2c.setup(0x70)  #通信準備
    i2c.writeReg8(ht16k33, 0x21, 0x01)  #ドライバー準備
    i2c.writeReg8(ht16k33, 0x81, 0x01)  #出力準備

    for j in range(len(shape_tmp) - 2 * 8):
        for i in range(8):
            z = j // 8
            shape[i] = (shape_tmp[i + (z) * 8] |
                        (shape_tmp[i + (z + 1) * 8] << 8)) << 8 * z
            i2c.writeReg8(ht16k33, i * 2, shape[i] >> j)
            shape[i] = (shape_tmp[i + (z + 1) * 8] |
                        (shape_tmp[i + (z + 2) * 8] << 8)) << 8 * z
            i2c.writeReg8(ht16k33, i * 2 + 1, shape[i] >> j)
        time.sleep(0.03)

    i2c.writeReg8(ht16k33, 0x80, 0x01)  #出力停止
    i2c.writeReg8(ht16k33, 0x20, 0x01)  #ドライバー停止
示例#8
0
    def __init__(self, sampling_time, mpu9250_address, ak8963_address):
        self.sampling_time = sampling_time
        self.mpu9250_address = mpu9250_address  # ジャイロ、加速度のアドレス
        self.ak8963_address = ak8963_address  # コンパスのアドレス

        wi.wiringPiSetup()
        self.i2c = wi.I2C()

        self.mpu9250 = self.i2c.setup(mpu9250_address)
        self.ak8963 = self.i2c.setup(ak8963_address)

        # センサ初期化
        self.reset_register()
        self.power_wake_up()

        # センシングされたdecimal値をdpsに変換する係数
        self.gyro_coefficient = self.gyro_range / float(0x8000)
        # センシングされたdecimal値をgに変換する係数
        self.accel_coefficient = self.accel_range / float(0x8000)
        # センシングされたdecimal値をuTに変換する係数(16bit)
        self.mag_coefficient_16 = self.mag_range / 32760.0
        # センシングされたdecimal値をuTに変換する係数(14bit)
        self.mag_coefficient_14 = self.mag_range / 8190.0
示例#9
0
 def __init__(self):
     wiringpi.wiringPiSetup()
     self.i2c = wiringpi.I2C()
     self.dev = self.i2c.setup(0x40)
示例#10
0
 def __init__(self, i2c_addr=I2C_ADDR_THERMO):
     self.i2c = wp.I2C()
     self.fd = self.i2c.setup(i2c_addr)
     # 分解能を16ビットに設定
     self._write(0x003, 0x80)
# pi@raspberrypi ~ $ sudo chown  pi bme280_logs.csv
#データ計測時間は SAMPLING_TIME x TIMES
############################################################

import sys  #sysモジュールの呼び出し
import wiringpi as wi  #wiringPiモジュールの呼び出し
import time  #timeライブラリの呼び出し
import datetime  #datetimeモジュールの呼び出し
import os

#データ計測時間は SAMPLING_TIME x TIMES
SAMPLING_TIME = 0.1  #データ取得の時間間隔[sec]
TIMES = 100  #データの計測回数

wi.wiringPiSetup()  #wiringPiの初期化
i2c = wi.I2C()  #i2cの初期化

i2c_address = 0x76  # #I2Cアドレス SDO=GND
#i2c_address = 0x77 # #I2Cアドレス SDO=VCC
bme280 = i2c.setup(
    i2c_address)  #i2cアドレス0x76番地をbme280として設定(アドレスは$sudo i2cdetect 1で見られる)

digT = []  #配列を準備
digP = []  #配列を準備
digH = []  #配列を準備

temp = 0
humi = 0
press = 0
t_fine = 0.0
示例#12
0
class MPU9250(object):
    wi.wiringPiSetup()
    i2c = wi.I2C()

    _address = 0x68  # addresses of gyroscope and accelerometer
    _addr_AK8963 = 0x0C  # a address of magnetometer (self.AK8963)
    # sensor constant
    _REG_PWR_MGMT_1 = 0x6B
    _REG_INT_PIN_CFG = 0x37
    _REG_ACCEL_CONFIG1 = 0x1C
    _REG_ACCEL_CONFIG2 = 0x1D
    _REG_GYRO_CONFIG = 0x1B

    _MAG_MODE_POWERDOWN = 0  # 磁気センサpower down
    _MAG_MODE_SERIAL_1 = 1  # 磁気センサ8Hz連続測定モード
    _MAG_MODE_SERIAL_2 = 2  # 磁気センサ100Hz連続測定モード
    _MAG_MODE_SINGLE = 3  # 磁気センサ単発測定モード
    _MAG_MODE_EX_TRIGER = 4  # 磁気センサ外部トリガ測定モード
    _MAG_MODE_SELF_TEST = 5  # 磁気センサセルフテストモード
    _MAG_ACCESS = False  # 磁気センサへのアクセス可否
    _MAG_MODE = 0  # 磁気センサモード
    _MAG_BIT = 16  # 磁気センサが出力するbit数
    _gyro_range = 1000  # 250, 500, 1000, 2000 'dps'から選択
    _accel_range = 8  # +-2, +-4, +-8, +-16 'g'から選択
    _mag_range = 4912  # 'μT'

    mpu9250 = i2c.setup(
        _address)  # i2cアドレス0x68番地をmpu9250として設定(アドレスは$sudo i2cdetect 1で見られる)
    AK8963 = i2c.setup(_addr_AK8963)

    # 加速度の測定レンジを設定
    _val = 8  # val = 16, 8, 4, 2(default)

    def __init__(self):
        # オフセット用変数
        self._offset_gyro_x = 0
        self._offset_gyro_y = 0
        self._offset_gyro_z = 0
        self._offset_accel_x = 0
        self._offset_accel_y = 0
        self._offset_accel_z = 0
        self._offset_mag_x = -7.497336140
        self._offset_mag_y = -57.461323250
        self._offset_mag_z = 63.096101850

        self._reset_register()
        self._power_wakeup()
        self._gyro_coefficient = self._gyro_range / float(
            0x8000)  # coefficient : sensed decimal val to dps val.
        self._accel_coefficient = self._accel_range / float(
            0x8000)  # coefficient : sensed decimal val to g val
        self._mag_coefficient_16 = self._mag_range / 32760.0  # coefficient : sensed decimal val to μT val (16bit)
        self._mag_coefficient_14 = self._mag_range / 8190.0  # coefficient : sensed decimal val to μT val (14bit)
        self._set_accel_range(val=self._accel_range, _calibration=True)
        self._set_gyro_range(val=self._gyro_range, _calibration=True)
        # self._set_accel_range(val=self._accel_range, _calibration=False)
        # setself._gyro_range(val=self._gyro_range, _calibration=False)
        self._set_mag_register('100Hz', '16bit')

    # レジスタを初期設定に戻す。
    def _reset_register(self):
        if self._MAG_ACCESS is True:
            self.i2c.writeReg8(self.AK8963, 0x0B, 0x01)
        self.i2c.writeReg8(self.mpu9250, 0x6B, 0x80)
        self._MAG_ACCESS = False
        time.sleep(0.1)

    # センシング可能な状態にする。
    def _power_wakeup(self):
        # PWR_MGMT_1をクリア
        self.i2c.writeReg8(self.mpu9250, self._REG_PWR_MGMT_1, 0x00)
        time.sleep(0.1)
        # I2Cで磁気センサ機能(self.AK8963)へアクセスできるようにする(BYPASS_EN=1)
        self.i2c.writeReg8(self.mpu9250, self._REG_INT_PIN_CFG, 0x02)
        self._MAG_ACCESS = True
        time.sleep(0.1)

    def _set_accel_range(self, val, _calibration=False):
        # +-2g (00), +-4g (01), +-8g (10), +-16g (11)
        if val == 16:
            _accel_range = 16
            _data = 0x18
        elif val == 8:
            _accel_range = 8
            _data = 0x10
        elif val == 4:
            _accel_range = 4
            _data = 0x08
        else:
            _accel_range = 2
            _data = 0x00
        print("set _accel_range=%d [g]" % _accel_range)
        self.i2c.writeReg8(self.mpu9250, self._REG_ACCEL_CONFIG1, _data)
        self._accel_coefficient = _accel_range / float(0x8000)
        time.sleep(0.1)

        # Calibration
        if _calibration is True:
            self._calib_accel(1000)
        return

    # ジャイロの測定レンジを設定します。
    # val= 2000, 1000, 500, 250(default)
    def _set_gyro_range(self, val, _calibration=False):
        if val == 2000:
            _gyro_range = 2000
            _data = 0x18
        elif val == 1000:
            _gyro_range = 1000
            _data = 0x10
        elif val == 500:
            _gyro_range = 500
            _data = 0x08
        else:
            _gyro_range = 250
            _data = 0x00
        print("set _gyro_range=%d [dps]" % _gyro_range)
        self.i2c.writeReg8(self.mpu9250, self._REG_GYRO_CONFIG, _data)
        self._gyro_coefficient = _gyro_range / float(0x8000)
        time.sleep(0.1)

        # Calibration
        if _calibration is True:
            self._calib_gyro(1000)
        return

    # 磁気センサのレジスタを設定する
    def _set_mag_register(self, _mode, _bit, _calibration=False):
        if self._MAG_ACCESS is False:
            # 磁気センサへのアクセスが有効になっていない場合は例外
            raise Exception('001 Access to a sensor is invalid.')

        _writeData = 0x00
        # 測定モードの設定
        if _mode == '8Hz':  # Continuous measurement mode 1
            _writeData = 0x02
            self._MAG_MODE = self._MAG_MODE_SERIAL_1
        elif _mode == '100Hz':  # Continuous measurement mode 2
            _writeData = 0x06
            self._MAG_MODE = self._MAG_MODE_SERIAL_2
        elif _mode == 'POWER_DOWN':  # Power down mode
            _writeData = 0x00
            self._MAG_MODE = self._MAG_MODE_POWERDOWN
        elif _mode == 'EX_TRIGER':  # Trigger measurement mode
            _writeData = 0x04
            self._MAG_MODE = self._MAG_MODE_EX_TRIGER
        elif _mode == 'SELF_TEST':  # self test mode
            _writeData = 0x08
            self._MAG_MODE = self._MAG_MODE_SELF_TEST
        else:  # _mode='SINGLE'    # single measurment mode
            _writeData = 0x01
            self._MAG_MODE = self._MAG_MODE_SINGLE

        # 出力するbit数
        if _bit == '14bit':  # output 14bit
            _writeData = _writeData | 0x00
            self._MAG_BIT = 14
        else:  # _bit='16bit'      # output 16bit
            _writeData = _writeData | 0x10
            self._MAG_BIT = 16
        print("set self._MAG_MODE=%s, %d bit" % (_mode, self._MAG_BIT))
        self.i2c.writeReg8(self.AK8963, 0x0A, _writeData)
        time.sleep(0.1)

        # Calibration
        if _calibration is True:
            self._calib_mag(3000)
        return

    # センサからのデータはそのまま使おうとするとunsignedとして扱われるため、signedに変換(16ビット限定)
    def _u2s(self, unsigneddata):
        if unsigneddata & (0x01 << 15):
            return -1 * ((unsigneddata ^ 0xffff) + 1)
        return unsigneddata

    # 加速度値を取得
    def get_accel(self):
        mpu9250 = self.mpu9250
        i2c = self.i2c
        ACCEL_XOUT_H = i2c.readReg8(mpu9250, 0x3B)
        ACCEL_XOUT_L = i2c.readReg8(mpu9250, 0x3C)
        ACCEL_YOUT_H = i2c.readReg8(mpu9250, 0x3D)
        ACCEL_YOUT_L = i2c.readReg8(mpu9250, 0x3E)
        ACCEL_ZOUT_H = i2c.readReg8(mpu9250, 0x3F)
        ACCEL_ZOUT_L = i2c.readReg8(mpu9250, 0x40)
        raw_x = self._accel_coefficient * self._u2s(
            ACCEL_XOUT_H << 8 | ACCEL_XOUT_L) + self._offset_accel_x
        raw_y = self._accel_coefficient * self._u2s(
            ACCEL_YOUT_H << 8 | ACCEL_YOUT_L) + self._offset_accel_y
        raw_z = self._accel_coefficient * self._u2s(
            ACCEL_ZOUT_H << 8 | ACCEL_ZOUT_L) + self._offset_accel_z
        return raw_x, raw_y, raw_z

    # ジャイロ値を取得
    def get_gyro(self):
        mpu9250 = self.mpu9250
        i2c = self.i2c
        GYRO_XOUT_H = i2c.readReg8(mpu9250, 0x43)
        GYRO_XOUT_L = i2c.readReg8(mpu9250, 0x44)
        GYRO_YOUT_H = i2c.readReg8(mpu9250, 0x45)
        GYRO_YOUT_L = i2c.readReg8(mpu9250, 0x46)
        GYRO_ZOUT_H = i2c.readReg8(mpu9250, 0x47)
        GYRO_ZOUT_L = i2c.readReg8(mpu9250, 0x48)
        raw_x = self._gyro_coefficient * self._u2s(
            GYRO_XOUT_H << 8 | GYRO_XOUT_L) + self._offset_gyro_x
        raw_y = self._gyro_coefficient * self._u2s(
            GYRO_YOUT_H << 8 | GYRO_YOUT_L) + self._offset_gyro_y
        raw_z = self._gyro_coefficient * self._u2s(
            GYRO_ZOUT_H << 8 | GYRO_ZOUT_L) + self._offset_gyro_z
        return raw_x, raw_y, raw_z

    # 磁気値を取得
    def get_mag(self):
        AK8963 = self.AK8963
        i2c = self.i2c

        if self._MAG_ACCESS is False:
            # 磁気センサへのアクセスが有効になっていない場合は例外
            raise Exception('002 Access to a sensor is invalid.')

        # 事前処理
        if self._MAG_MODE == self._MAG_MODE_SINGLE:
            # 単発測定モードは測定終了と同時にPower Downになるので、もう一度モードを変更する
            if self._MAG_BIT == 14:  # output 14bit
                _writeData = 0x01
            else:  # output 16bit
                _writeData = 0x11
            self.i2c.writeReg8(self.AK8963, 0x0A, _writeData)
            time.sleep(0.01)

        elif self._MAG_MODE == self._MAG_MODE_SERIAL_1 or self._MAG_MODE == self._MAG_MODE_SERIAL_2:
            status = self.i2c.readReg8(self.AK8963, 0x02)
            if (status & 0x02) == 0x02:
                # if (status[0] & 0x02) == 0x02:
                # データオーバーランがあるので再度センシング
                self.i2c.readReg8(self.AK8963, 0x09)

        elif self._MAG_MODE == self._MAG_MODE_EX_TRIGER:
            # 未実装
            return

        elif self._MAG_MODE == self._MAG_MODE_POWERDOWN:
            raise Exception('003 Mag sensor power down')

        # ST1レジスタを確認してデータ読み出しが可能か確認する
        status = i2c.readReg8(AK8963, 0x02)
        while (status & 0x01) != 0x01:
            # while (status[0] & 0x01) != 0x01:
            # Wait until data ready state.
            # time.sleep(0.01)
            status = self.i2c.readReg8(self.AK8963, 0x02)

        # データ読み出し
        MAG_XOUT_L = i2c.readReg8(AK8963, 0x03)
        MAG_XOUT_H = i2c.readReg8(AK8963, 0x04)
        MAG_YOUT_L = i2c.readReg8(AK8963, 0x05)
        MAG_YOUT_H = i2c.readReg8(AK8963, 0x06)
        MAG_ZOUT_L = i2c.readReg8(AK8963, 0x07)
        MAG_ZOUT_H = i2c.readReg8(AK8963, 0x08)
        MAG_OF = i2c.readReg8(AK8963, 0x09)
        raw_x = self._u2s(MAG_XOUT_H << 8 | MAG_XOUT_L)
        raw_y = self._u2s(MAG_YOUT_H << 8 | MAG_YOUT_L)
        raw_z = self._u2s(MAG_ZOUT_H << 8 | MAG_ZOUT_L)
        st2 = MAG_OF
        # data    = self.i2c.readReg8(addrAK8963, 0x03 ,7)
        # raw_x    = u2s(data[1] << 8 | data[0])  # Lower bit is ahead.
        # raw_y    = u2s(data[3] << 8 | data[2])  # Lower bit is ahead.
        # raw_z    = u2s(data[5] << 8 | data[4])  # Lower bit is ahead.
        # st2     = data[6]

        # オーバーフローチェック
        if (st2 & 0x08) == 0x08:
            # オーバーフローのため正しい値が得られていない
            raise Exception('004 Mag sensor over flow')

        # μTへの変換
        if self._MAG_BIT == 16:  # output 16bit
            raw_x = raw_x * self._mag_coefficient_16
            raw_y = raw_y * self._mag_coefficient_16
            raw_z = raw_z * self._mag_coefficient_16
        else:  # output 14bit
            raw_x = raw_x * self._mag_coefficient_14
            raw_y = raw_y * self._mag_coefficient_14
            raw_z = raw_z * self._mag_coefficient_14

        # ---- offset by myself ----
        # raw_x -= 7.49733614
        # raw_y -= 57.46132325
        # raw_z -= -63.09610185
        # ---- offset by myself ----

        raw_x += self._offset_mag_x
        raw_y += self._offset_mag_y
        raw_z += self._offset_mag_z

        return raw_x, raw_y, raw_z

    # 加速度センサを較正する
    # 本当は緯度、高度、地形なども考慮する必要があるとは思うが、簡略で。
    # z軸方向に正しく重力がかかっており、重力以外の加速度が発生していない前提
    def _calib_accel(self, _count=1000):
        print("Accel calibration start")
        _sum = [0, 0, 0]

        # データのサンプルを取る
        for _ in range(_count):
            _data = self.get_accel()
            _sum[0] += _data[0]
            _sum[1] += _data[1]
            _sum[2] += _data[2]

        # 平均値をオフセットにする
        self._offset_accel_x = -1.0 * _sum[0] / _count
        self._offset_accel_y = -1.0 * _sum[1] / _count
        # self._offset_accel_z = -1.0 * _sum[2] / _count
        self._offset_accel_z = -1.0 * ((_sum[2] / _count) - 1.0)  # 重力分を差し引く

        # I want to register an offset value in a register. But I do not know the behavior, so I will put it on hold.
        print("Accel calibration complete")
        print(
            f'Accel error X: {self._offset_accel_x:.2f}  Y: {self._offset_accel_y:.2f}  Z: {self._offset_accel_z:.2f}'
        )

    # ジャイロセンサを較正する
    # 各軸に回転が発生していない前提
    def _calib_gyro(self, _count=1000):
        print("Gyro calibration start")
        _sum = [0, 0, 0]

        # データのサンプルを取る
        for _i in range(_count):
            _data = self.get_gyro()
            _sum[0] += _data[0]
            _sum[1] += _data[1]
            _sum[2] += _data[2]

        # 平均値をオフセットにする
        self._offset_gyro_x = -1.0 * _sum[0] / _count
        self._offset_gyro_y = -1.0 * _sum[1] / _count
        self._offset_gyro_z = -1.0 * _sum[2] / _count

        # I want to register an offset value in a register. But I do not know the behavior, so I will put it on hold.
        print("Gyro calibration complete")
        print(
            f'Gyro error X: {self._offset_gyro_x:.2f}  Y: {self._offset_gyro_y:.2f}  Z: {self._offset_gyro_z:.2f}'
        )
示例#13
0
def readData(address, channel):
    i2c = wiringpi.I2C()
    file = i2c.setupInterface("/dev/i2c-1", address)
    return i2c.readReg8(file, 0x40 + channel)
示例#14
0
def writeData(address, value):
    i2c = wiringpi.I2C()
    file = i2c.setupInterface("/dev/i2c-1", address)
    i2c.writeReg8(file, 0x40, value)
    return
示例#15
0
# -*- coding: utf-8 -*-
import wiringpi
import os
import struct
from time import sleep
#import sqlite3
#import sys
#import time

wiringpi.wiringPiSetup()  #setup wiringpi
i2c = wiringpi.I2C()  #get I2C
dev = i2c.setup(0x40)  #setup I2C device
i2c.write(dev, 0x02)  #HDC1000 CONFIGURATION POINTER
i2c.write(dev, 0x10)  #send 1byte
i2c.write(dev, 0x00)  #send 1byte
sleep((6350.0 + 6500.0 + 500.0) / 1000000.0)
dataAry = struct.unpack("BBBB", os.read(dev, 4))
os.close(dev)
temp = (dataAry[0] << 8) | (dataAry[1])
hudi = (dataAry[2] << 8) | (dataAry[3])
temp = ((temp / 65535.0) * 165 - 40)
hudi = ((hudi / 65535.0) * 100)
#print "Humidity %.2f" % hudi
#print "Temperature %.2f" % temp
print temp, hudi

#datetime = "%s" % (time.strftime("%Y/%m/%d %H:%M:%S"))

#dbname = sys.argv[1]
#conn = sqlite3.connect(dbname)
#cursor = conn.cursor()
示例#16
0
文件: oled.py 项目: ugcgeta/dev
        i2c.writeReg8(oled_i2c, 0x00, 0x21)  # set column addres
        i2c.writeReg8(oled_i2c, 0x00, 0x00 + x)  # start column addres
        i2c.writeReg8(oled_i2c, 0x00, 0x7F)  # stop column addres

        startPos = 0 + fontSize * line
        endPos = fontSize + fontSize * line
        for i in range(startPos, endPos):
            i2c.writeReg8(oled_i2c, 0x40, fontX2[i])
    #print(fontX2)
    return x + fontSize


################################################################
if __name__ == '__main__':

    wiringpi.wiringPiSetup()

    i2c = wiringpi.I2C()

    Oled_init(i2c)

    #Oled_putCharX2(i2c,0,0,[0, 192, 56, 6, 56, 192, 0, 0, 60, 3, 2, 2, 2, 3, 60, 0])
    #Oled_putChar(i2c,1,1,(0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf))

    Oled_putStringX2(
        i2c, 0, 1,
        [[0, 192, 56, 6, 56, 192, 0, 0, 60, 3, 2, 2, 2, 3, 60, 0],
         [254, 130, 130, 130, 196, 56, 0, 0, 63, 32, 32, 32, 32, 17, 14, 0],
         [240, 12, 2, 2, 2, 4, 8, 0, 7, 24, 32, 32, 32, 16, 8, 0]])
    #Oled_putString(i2c,2,1,[[0, 192, 56, 6, 56, 192, 0, 0, 60, 3, 2, 2, 2, 3, 60, 0], [254, 130, 130, 130, 196, 56, 0, 0, 63, 32, 32, 32, 32, 17, 14, 0], [240, 12, 2, 2, 2, 4, 8, 0, 7, 24, 32, 32, 32, 16, 8, 0]])
示例#17
0
def writePort(address, data):
    i2c = wiringpi.I2C()
    file = i2c.setupInterface("/dev/i2c-1", address)
    i2c.write(file, data)
    return
    def __init__(self, addr):
        wiringpi.wiringPiSetup() #setup wiringpi

        self.i2c = wiringpi.I2C() #get I2C
        self.dev = self.i2c.setup(addr) #setup I2C device
示例#19
0
def readPort(address):
    i2c = wiringpi.I2C()
    file = i2c.setupInterface("/dev/i2c-1", address)
    return i2c.read(file)
示例#20
0
import wiringpi as pi
import time
from lsm9ds1 import lsm9ds1

gyro_addr = 0x6b
magnet_addr = 0x1e

pi.wiringPiSetupGpio()
i2c = pi.I2C()
motion = lsm9ds1(i2c, gyro_addr, magnet_addr)

while True:
    motion.read_sensor()
    (g_x, g_y, g_z) = motion.get_gyro()
    print("Gyro X:", g_x, " Y:", g_y, " Z:", g_z)

    (a_x, a_y, a_z) = motion.get_accel()
    print("Accel X:", a_x, " Y:", a_y, " Z:", a_z)

    (m_x, m_y, m_z) = motion.get_magnet()
    print("Magnet X:", m_x, " Y:", m_y, " Z:", m_z)

    time.sleep(1)
示例#21
0
t0 = time.time()  #基準時

today_date = datetime.date.today()  #ログのセットアップ
filename = 'log' + today_date + '.csv'
f = open(filename, "w")
header = [
    'TIME', 'ACCELERATION', 'ALTITUDE', 'LATITUDE', 'LONGITUDE', 'DISTANCE'
]
writer = csv.writer(f, lineterminator="\n")
writer.writerow(header)

location = gps.gps(BAUD_RATE, TIMEOUT, DISTANCE_LAT, DISTANCE_LNG)  #GPSのセットアップ

pi.wiringPiSetupGpio()  #GPIOピンのセットアップ

i2c = pi.I2C()  #BME280とMPU6050のセットアップ
acc = mpu6050.mpu6050(i2c, mpu6050_addr)
press = bme280.bme280(i2c, bmp280_addr, s_press)
acc.setup()
press.setup()

pi.pinMode(MOTOR_R_1PIN, pi.OUTPUT)  #駆動部のセットアップ
pi.pinMode(MOTOR_R_2PIN, pi.OUTPUT)
pi.pinMode(MOTOR_L_1PIN, pi.OUTPUT)
pi.pinMode(MOTOR_L_2PIN, pi.OUTPUT)
pi.softPwmCreate(MOTOR_R_1PIN, 0, 100)
pi.softPwmCreate(MOTOR_R_2PIN, 0, 100)
pi.softPwmCreate(MOTOR_L_1PIN, 0, 100)
pi.softPwmCreate(MOTOR_L_2PIN, 0, 100)
pi.softPwmWrite(MOTOR_R_1PIN, 0)
pi.softPwmWrite(MOTOR_R_2PIN, 0)