亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

樹莓派(Raspberry Pi)python smbus 函數(shù)說明

系統(tǒng) 1894 0

剛開始學(xué)習(xí)樹莓派,在使用I2C接口時(shí)遇到了一些問題,比如不了解smbus有那些函數(shù)和這些函數(shù)的使用方法,網(wǎng)上找了很久也沒有找到具體說明smbus函數(shù)的文檔,現(xiàn)將我整理的一些說明資料歸檔如下,一方面便于自己后期學(xué)習(xí),二方面便于剛接觸樹莓派,想要更深入學(xué)習(xí)I2C接口功能的朋友們,希望對(duì)大家有所幫助:

? ? ?? 使用方法:

首先在程序中導(dǎo)入“smbus”模塊,方法如下:

            
              #導(dǎo)入方法一:
import smbus

#導(dǎo)入方法二:
from smbus import SMBus

#創(chuàng)建一個(gè)smbus實(shí)例
b = smbus.SMBus(1)

b = SMBus(1)    # 0 代表 /dev/i2c-0, 1 代表 /dev/i2c-1
                #具體看使用的樹莓派那個(gè)I2C來決定。

#實(shí)例創(chuàng)建好了就可以使用i2c函數(shù)了
b.read_byte_data(0x2f,0x58)

            
          

?

?

function

description

parameters

return value

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? SMBus Access

?

write_quick (addr)

Quick transaction.

int addr

long

?

read_byte (addr)

Read Byte transaction.

int addr

long

?

write_byte (addr, val)

Write Byte transaction.

int addr, char val

long

?

read_byte_data (addr, cmd)

Read Byte Data transaction.

int addr, char cmd

long

?

write_byte_data (addr, cmd, val)

Write Byte Data transaction.

int addr, char cmd, char val

long

?

read_word_data (addr, cmd)

Read Word Data transaction.

int addr, char cmd

long

?

write_word_data (addr, cmd, val)

Write Word Data transaction.

int addr, char cmd, int val

long

?

process_call (addr, cmd, val)

Process Call transaction.

int addr, char cmd, int val

long

?

read_block_data (addr, cmd)

Read Block Data transaction.

int addr, char cmd

long [ ]

?

write_block_data (addr, cmd, vals)

Write Block Data transaction.

int addr, char cmd, long [ ]

None

?

block_process_call (addr, cmd, vals)

Block Process Call transaction.

int addr, char cmd, long [ ]

long [ ]

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?I2C Access

?

read_i2c_block_data (addr, cmd)

Block Read transaction.

int addr, char cmd

long [ ]

?

write_i2c_block_data (addr, cmd, vals)

Block Write transaction.

int addr, char cmd, long [ ]

None

函數(shù)介紹:

Checking For Connected Devices

At the command prompt type one of these depending on whether you are using the I2C0 or I2C1 port:?

            
              sudo i2cdetect -y 0
//or
sudo i2cdetect -y 1

            
          

The 7 bit I2C address of all found devices will be shown (ignoring the R/W bit, so I2C address 0000 0110 is displayed as hex?03).

SMBus (System Management Bus) is a subset from the I2C protocol
When writing a driver for an I2C device try to use the SMBus commands if possible (if the device uses only that subset of the I2C protocol) as it makes it possible to use the device driver on both SMBus adapters and I2C adapters.

Note address is the 7 bit address?excluding the read / write bit (it will be shifted left 1 bit when added to the read/write bit)

            
              # Send only the read / write bit 
long write_quick(int addr)

# Read a single byte from a device, without specifying a device register. 
long read_byte(int addr)

# Send a single byte to a device 
long write_byte(int addr, char val)

# Read Byte Data transaction. 
long read_byte_data(int addr, char cmd)

# Write Byte Data transaction. 
long write_byte_data(int addr, char cmd, char val)

# Read Word Data transaction. 
long read_word_data(int addr, char cmd)

# Write Word Data transaction. 
long write_word_data(int addr, char cmd, int val)

# Process Call transaction. 
long process_call(int addr, char cmd, int val)

#Read Block Data transaction.  
long[] read_block_data(int addr, char cmd)
    
# Write up to 32 bytes to a device.  This fucntion adds an initial byte indicating the 
# length of the vals array before the valls array.  Use write_i2c_block_data instead! 
write_block_data(int addr,char cmd,long vals[])

# Block Process Call transaction.  
long[] block_process_call(int addr, char cmd, long vals[])
 
   
# I2C Access Functions
# Block Read transaction. 
long[] read_i2c_block_data(int addr, char cmd)

#Block Write transaction. 
write_i2c_block_data(int addr, char cmd, long vals[])


#Code Example

#!/usr/bin/python

import smbus

bus = smbus.SMBus(1)    # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)

DEVICE_ADDRESS = 0x15      #7 bit address (will be left shifted to add the read write bit)
DEVICE_REG_MODE1 = 0x00
DEVICE_REG_LEDOUT0 = 0x1d

#Write a single register
bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1, 0x80)

#Write an array of registers
ledout_values = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
bus.write_i2c_block_data(DEVICE_ADDRESS, DEVICE_REG_LEDOUT0, ledout_values)

            
          

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

            
              ?
            
          

?

            
              ?
            
          
            
              ?
            
          

更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦?。?!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 中文字幕一二区 | 俺去也最新网站 | 国产91av视频 | 在线观看日本免费视频大片一区 | 国产在线观看99 | 色视频在线播放 | 国产成人精视频在线观看免费 | 久久香蕉国产线看观看亚洲卡 | 久久99热这里只有精品 | 另类 欧美 视频二区 | 国产精品午夜波多野结衣性色 | 99在线热视频只有精品免费 | 韩国 欧美 日产 国产精品 | 欧美国产高清 | 欧美日本一本线在线观看 | 久久98精品久久久久久婷婷 | 久热在线视频 | 中文国产成人精品久久一区 | 国产欧美自拍 | 久久99久久99精品免观看不卡 | 七月婷婷精品视频在线观看 | 免费在线中文字幕 | 亚欧洲精品bb | 不卡的毛片 | 成年网站视频在线观看 | 国产一区二区三区久久 | 欧美精品国产 | 国产精品久久久久国产精品三级 | 四房激情网 | 日本在线精品 | 中文字幕不卡一区 | 欧美日韩在大午夜爽爽影院 | 97国产成人精品视频 | 欧美一级一极性活片免费观看 | 亚洲精品入口一区二区在线观看 | jiucao在线观看精品 | 久免费视频 | 国产精品久久国产精麻豆99网站 | 最新国产福利片在线观看 | 99久久国产综合精品成人影院 | 911精品国产91久久久久 |