当前位置: 首页>>代码示例>>Python>>正文


Python PyMata.i2c_read方法代码示例

本文整理汇总了Python中PyMata.pymata.PyMata.i2c_read方法的典型用法代码示例。如果您正苦于以下问题:Python PyMata.i2c_read方法的具体用法?Python PyMata.i2c_read怎么用?Python PyMata.i2c_read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyMata.pymata.PyMata的用法示例。


在下文中一共展示了PyMata.i2c_read方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]
from PyMata.pymata import PyMata



# The PyMata constructor will print status to the console and will return
# when PyMata is ready to accept commands or will exit if unsuccessful
firmata = PyMata("/dev/ttyACM0")

#configure the I2C pins. This code is for the UNO

firmata.i2c_config(0, firmata.ANALOG, 4, 5)

# read i2c device at address 0x48, with no register specified. Expect 2 bytes to be returned
# and the operation is a single shot read
firmata.i2c_read(0x48, 0, 2, firmata.I2C_READ)

# give the serial interface time to send a read, for the device to execute the read
# and to get things back across the interface
time.sleep(3)

# retrieve the data sent from device
data = firmata.i2c_get_read_data(0x48)

# do some calculations on the raw data returned
TemperatureSum = (data[1] << 8 | data[2]) >> 4

celsius = TemperatureSum * 0.0625
print celsius

fahrenheit = (1.8 * celsius) + 32
开发者ID:Haobot,项目名称:PyMata,代码行数:32,代码来源:pymata_i2c_read.py

示例2: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]
import time
from PyMata.pymata import PyMata

addr = 0x48
# Initialize Arduino using port name
port = PyMata("/dev/cu.usbmodem621")

# Configure I2C pin
port.i2c_config(0, port.ANALOG, 4, 5)

# one shot read asking peripheral to send 2 bytes
port.i2c_read(addr, 0, 2, port.I2C_READ)

# Wait for peripheral to send the data
time.sleep(3)

# Read from the peripheral
data = port.i2c_get_read_data(addr)

# Obtain temperature from received data
TemperatureSum = (data[1] << 8 | data[2]) >> 4

celsius = TemperatureSum * 0.0625
print celsius

fahrenheit = (1.8 * celsius) + 32
print fahrenheit

firmata.close()
开发者ID:httran13,项目名称:ArduinoPythonProject,代码行数:31,代码来源:TMP102.py

示例3: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]

# create a PyMata instance
board = PyMata("/dev/ttyACM0")


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# configure firmata for i2c on an UNO
board.i2c_config(0, board.ANALOG, 4, 5)

# configure the I2C pins. This code is for the Leonardo
# board.i2c_config(0, board.DIGITAL, 3, 2)

# read i2c device at address 0x48, with no register specified. Expect 2 bytes to be returned
# and the operation is a single shot read
board.i2c_read(0x48, 0, 2, board.I2C_READ, temp_callback)

# give the serial interface time to send a read, for the device to execute the read
# and to get things back across the interface
time.sleep(2)

board.close()
开发者ID:MrYsLab,项目名称:PyMata,代码行数:31,代码来源:i2c_read_callback.py

示例4: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]
# This code is supporting material for the book
# Python Programming for Arduino
# by Pratik Desai
# published by PACKT Publishing

import time
from PyMata.pymata import PyMata

#Initializing Arduino using PyFirmata constructor
port = PyMata("COM5")

#Configure I2C pin
port.i2c_config(0, port.ANALOG, 4, 5)

# One shot read asking peripheral to send 2 bytes
port.i2c_read(0x23, 0, 2, port.I2C_READ)
# Wait for peripheral to send the data
time.sleep(3)

# Read from the peripheral
data = port.i2c_get_read_data(0x23)

# Obtain lux values from received data
LuxSum = (data[1] << 8 | data[2]) >> 4

lux = LuxSum/1.2
print str(lux) + ' lux'

port.close()
开发者ID:HanBinTsao,项目名称:python-x-arduino-book,代码行数:31,代码来源:PyMata_Example_BH1750.py

示例5: signal_handler

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]
# for uno
# board.i2c_config(0, board.ANALOG, 4, 5)

def signal_handler(sig, frame):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)


def lux_callback(data):
    datax = data[2]
    print('Got read data: %s' % data)
    lux = (datax[1] << 8 | datax[2]) >> 4
    lux /= 1.2
    print(str(lux) + ' lux')


while True:
    try:
        board.i2c_write(0x23, board.I2C_READ_CONTINUOUSLY)  # same results with board.I2C_READ
        time.sleep(.3)
        board.i2c_read(0x23, 0, 2, board.I2C_READ, lux_callback)  # same results with board.I2C_READ_CONTINUOUSLY
        time.sleep(.3)
    except KeyboardInterrupt:
        board.close()
开发者ID:MrYsLab,项目名称:PyMata,代码行数:31,代码来源:bh1750_callback.py

示例6:

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

# configure firmata for i2c on an UNO
board.i2c_config(0, board.ANALOG, 4, 5)

# configure the I2C pins. This code is for the Leonardo
# board.i2c_config(0, board.DIGITAL, 3, 2)

# read i2c device at address 0x48, with no register specified. Expect 2 bytes to be returned
# and the operation is a single shot read
board.i2c_read(0x48, 0, 2, board.I2C_READ)

# give the serial interface time to send a read, for the device to execute the read
# and to get things back across the interface
time.sleep(3)

# retrieve the data sent from device
data = board.i2c_get_read_data(0x48)

# do some calculations on the raw data returned
TemperatureSum = (data[1] << 8 | data[2]) >> 4

celsius = TemperatureSum * 0.0625
print(celsius)

fahrenheit = (1.8 * celsius) + 32
开发者ID:MrYsLab,项目名称:PyMata,代码行数:33,代码来源:i2c_read_polled.py

示例7: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import i2c_read [as 别名]
# This code is supporting material for the book
# Python Programming for Arduino
# by Pratik Desai
# published by PACKT Publishing

import time
from PyMata.pymata import PyMata

#Initialize Arduino using port name
port = PyMata("COM5")

#Configure I2C pin
port.i2c_config(0, port.ANALOG, 4, 5)

# One shot read asking peripheral to send 2 bytes
port.i2c_read(0x48, 0, 2, port.I2C_READ)
# Wait for peripheral to send the data
time.sleep(3)

# Read from the peripheral
data = port.i2c_get_read_data(0x48)

# Obtain temperature from received data
TemperatureSum = (data[1] << 8 | data[2]) >> 4

celsius = TemperatureSum * 0.0625
print celsius

fahrenheit = (1.8 * celsius) + 32
print fahrenheit
开发者ID:HanBinTsao,项目名称:python-x-arduino-book,代码行数:32,代码来源:PyMata_Example_TMP102.py


注:本文中的PyMata.pymata.PyMata.i2c_read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。