Пример #1
0
        :param float  timeout: How long to wait for the device
        :return: True if device is ready, False otherwise
        """
        t = I2CTransaction()
        t.s().a(self.chip_write_address).p()
        deadline = time() + timeout
        while time() < deadline:
            r = self.device.i2c_run(t)
            if r.ack(1):
                return True
        return False

if __name__ == "__main__":

    # This example works with any device supporint I2CHelper API.
    dev = ArduinoUnoTwi('COM7')
    eeprom = Eeprom24lc32(dev)
    dev.connect()

    dev.i2c_enable = True

    # You can experiment with higher speeds, but it can fail ACK if you
    # use longer wires or inadequate pull-up resistors. 25kHz is a safe bet.
    dev.i2c_clock = ArduinoUnoTwi.I2CClock.F25k

    message = b'A secret message'

    print('Message size: %s' % len(message))

    print('Writing: %s...' % message, end='')
    eeprom.write(0, message)
        """

        # The code below is equivalent to the following transaction
        # t = I2CTransaction()
        # t.s().a(self.write_address).w(self.CMD_START_CONVERT).p()
        # r = self.device.i2c_run(t)

        self.device.i2c_start()
        self.device.i2c_address(self.write_address)
        self.device.i2c_write(self.CMD_START_CONVERT)
        self.device.i2c_stop()


if __name__ == "__main__":

    arduino = ArduinoUnoTwi('/dev/ttyACM0')
    #arduino = ArduinoLeonardo('/dev/ttyACM0')

    arduino.connect()
    arduino.i2c_enable = True
    arduino.i2c_verbose = False  # True will dump every I2C transaction to console

    dev = Ds1721(arduino, chip_address=0b111)

    print('*** Configure DS1721')
    dev.configure()

    print('*** Start conversion - it should take ~750ms')
    dev.start_conversion()

    while True: