0

I would like to add code to a Python program for my Pi (Raspbian Jessie or Stretch) which will do the equivalent of these command line commands:

  • sudo i2cget -y 1 0x6b 0x05
  • sudo i2cset -y 1 0x6b 0x05 0xff

I looked at using SMBUS but the more I read the more I get confused.

Any help or Python code examples would be appreciated.....RDK

EDIT: As per Joan's suggestion I grabbed the bull by the horns and tried the following:

#!/usr/bin/env python
import smbus
# sudo i2cget -y 1 0x6b 0x05
# sudo i2cset -y 1 0x6b 0x05 0xff
# bus number = 1
# Chip_Add = 0x6b
# Data_Add = 0x05

MyBus = smbus.SMBus(1) 

MyBus.write_byte_data(0x6b,0x05,0xfe) 
ReadData = MyBus.read_byte_data(0x6b,0x05)
print ReadData

It seemed to work, although I still not clear on most of the other SMBUS commands. The issue, or maybe my issue with this question was that, while there are lots of web references to SMBUS and to I2C commands, there are none that I found which made a 1:1 connection....

0

It looks like the first is the SMBus read byte data command and the second is the SMBus write byte data command.

In pigpio terms i2c_read_byte_data and i2c_write_byte_data.

  • I guess I did not make myself clear. I know what the commands are and what they do when I issue them from a command line. What I want to do is to code them into a Python 2 program which will run on one of my Pi's (Version 2 or 3, running Jessie or Stretch). Not sure what "pigpio" is. Thanks – RDK Nov 27 '17 at 9:03
  • @RDK There must be 1000s of Raspberry Pi Python SMBus examples. Choose one and if you have a problem add what you have done to your question. – joan Nov 27 '17 at 10:54
  • @Joan...As per your suggestion I have updated my question and perhaps with a solution? – RDK Nov 27 '17 at 17:12
  • Finally and thanks again @Joan, I would welcome any reference which would detail the correspondence between I2C commands and SMBUS commands, – RDK Nov 28 '17 at 5:49
  • Have a look at smbus.org/specs/smbus20.pdf. Personally I think SMBus is an unneeded spec and should have never been introduced. I'm not sure I have ever had to use anything other than standard I2C read/write commands. – joan Nov 28 '17 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.