# smbus2 來源:https://smbus2.readthedocs.io/en/latest/?badge=latest github https://github.com/kplindegaard/smbus2 update(change log):https://github.com/kplindegaard/smbus2/blob/master/CHANGELOG.md 持續學習中,如有錯誤歡迎留言賜教 smbus2 is pure Python implementation of of the python-smbus package. It was designed from the ground up with two goals in mind: It should be a drop-in replacement of smbus. The syntax shall be the same. Use the inherent i2c structs and unions to a greater extent than other pure Python implementations like pysmbus does. By doing so, it will be more feature complete and easier to extend. ### wirte: write_byte(I2C_Slave_address[slave_num], value) arduino收到是 資料 故總共有 1 byte數 write_i2c_block_data(I2C_Slave_address[slave_num], 0x00 , data) arduino收到是 起始位址+資料 故總共有 資料長度+1 byte數 write_block_data(I2C_Slave_address[slave_num], 0x08 , data) arduino收到是 起始位址+資料長度+資料 故總長度有 資料長度+2 byte數 write_byte_data(I2C_Slave_address[slave_num], 0x05, value,) arduino收到是 起始位址+資料 故總長度有 2 byte數 write_word_data(I2C_Slave_address[slave_num], 0x05, value,) arduino收到是 起始位址+2byte的整數(0~65535) 故總長度有 3 byte數 P.S. 1word = 2byte ### read: 以write_block_data(I2C_Slave_address[slave_num], 0x05 , data) 寫入 [ 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112],arduino收到後顯示 [ 5 , 8 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112] read_byte(I2C_Slave_address[slave_num]) rpi收到 5 read_byte_data(I2C_Slave_address[slave_num], 0x0a) rpi收到10 arduino資料被改為[ 10 , 8 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112] read_block_data(I2C_Slave_address[slave_num], 0) rpi收到[] read_i2c_block_data(I2C_Slave_address[slave_num], 0 , 16) rpi收到[ 0 , 8 , 105 , 106 , 107 , 108 , 109 , 110 , 111 , 112 , 0 , 0 , 0 , 0 , 0 , 0] 用for 迴圈將資料以Wire.write()分多次丟給rpi