juhasch / pybuspiratelite Goto Github PK
View Code? Open in Web Editor NEWPython library for BusPirate
Home Page: https://pybuspiratelite.readthedocs.io/en/latest/
License: Other
Python library for BusPirate
Home Page: https://pybuspiratelite.readthedocs.io/en/latest/
License: Other
There is a wrong method call in the I2Chigh class. I2Chigh class not unusable at the moment... :-(
>>> i2c.get_byte(addr_I2Cmux,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/pyBusPirateLite/I2Chigh.py", line 53, in get_byte
r = self.read_byte()
AttributeError: 'I2Chigh' object has no attribute 'read_byte
Hi;
I have a python script from 2017 that was working and I decided to pull the latest version which appears to have broken I2C BB Mode.
This is the code that I previously used to initialise and connect, what is the equivalent code now ?
def i2cinit():
global i2c
i2c = I2C("/dev/tty.usbserial-A600aSfe", 115200, 5)
tries=0
## Pullups - disable on sniff.
pups=True;
if(cmd=='sniff'): pups=False
while True:
tries+=1
if(tries>1):
print('Initializing...',tries)
if not i2c.BBmode():
msg="Can't set binmode on Buspirate!"
continue
elif not i2c.enter_I2C():
msg = "Can't set raw mode on Buspirate!"
continue
elif not i2c.set_speed(I2CSpeed._50KHZ):
msg = "Can't set I2C speed on Buspirate!"
continue
elif pups and not i2c.cfg_pins(I2CPins.POWER | I2CPins.PULLUPS):
msg = "Failed to set I2C peripherals."
continue
else:
break
This just fails with:
Traceback (most recent call last):
File "./aibobat.py", line 801, in <module>
i2cinit();
File "./aibobat.py", line 85, in i2cinit
if not i2c.BBmode():
AttributeError: 'I2C' object has no attribute 'BBmode'
Is it possible to easily get my old code to run with the new version without a complete re-write ?
Many Thanks
https://pypi.org/ is the de facto standard for distributing Python package and having this library available on pypi, which make it also supported by PIP, will make it more accessible and easier to include in project.
Adding a project to pypi is easy and free, and doesn't require too much hassle, and I can help if needed.
I cannot get this version of pyBusPirateLite to talk to my Bus Pirate -- the port opens correctly, but any attempt to communicate with the BP (even attempting to put it into bitbang mode) results in a long wait followed by a "bus pirate malfunctioning" error.
This is on Windows 7, Bus Pirate v3a, firmware v6.1.
If I use the version of pyBusPirateLite from the Dangerous Prototypes website (http://code.google.com/p/the-bus-pirate/downloads/detail?name=pyBusPirateLite-r597.zip), the BP works fine.
The following code (Python 3):
from pyBusPirateLite.SPI import *
i2c = I2C(portname='COM8', speed=115200)
i2c.pins = PIN_POWER | PIN_CS
i2c.speed = '400kHz'
... leads to the following error:
ProtocolError Traceback (most recent call last)
<ipython-input-7-74521de54adf> in <module>()
1 i2c.pins = PIN_POWER | PIN_CS
----> 2 i2c.speed = '400kHz'
D:\python\pyBusPirateLite\pyBusPirateLite\I2C.py in speed(self, frequency)
220
221 if self.response(1, True) != 0x01:
--> 222 raise ProtocolError('Could not set IC2 speed')
223 self.i2c_speed = frequency
224
ProtocolError: Could not set IC2 speed
The following code (Python 3):
from pyBusPirateLite.I2Chigh import *
i2c = I2Chigh("COM8", 115200, 5)
... leads to the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-50afcf9735bb> in <module>()
----> 1 from pyBusPirateLite.I2Chigh import *
2 i2c = I2Chigh("COM8", 115200, 5)
D:\python\pyBusPirateLite\pyBusPirateLite\I2Chigh.py in <module>()
21 """
22
---> 23 from .BitBang import BBIO
24 from .I2C import *
25
ImportError: cannot import name 'BBIO'
Hello,
During my evaluation of this library, I believe I came across a bug that was introduced in 913ac51 in BBIO_base.response():
the return value was changed from data
to data.decode()
which will raise a UnicodeDecodeError when reading or writing values greater than 0x7F.
I was testing the SPI bus using Python 3.5.
I apologize for not submitting a pull request but I believe this change in response() behavior affects the other subclasses of BBIO wherever response() is called, and have decided to go with pyBusPirate instead.
Samir
I am unable to get consistent reads using the write_then_read method:
def get_byte_a(addr):
i2c.write_then_read(2,0, [0x16, addr]) ## Write 2, receive none.
r = i2c.write_then_read(1, 1, [0x17]) ## Write 1, receive 1
print(f'VALUE = {hex(r[0])}')
for i in range(10):
get_byte_a(0x10)
time.sleep(0.1)
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0x17
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0x0
VALUE = 0xb8
Or the using transfer and write_then_read method:
def get_byte_b(addr):
i2c.start()
i2c.transfer([0x16, addr]) ## Send Multiple
r = i2c.write_then_read(1, 1, [0x17])
print(f'VALUE = {hex(r[0])}') ## 0xB8 Is Correct Value = 184
for i in range(10):
get_byte_b(0x10)
time.sleep(0.1)
VALUE = 0xb8
VALUE = 0x5c
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xb8
VALUE = 0xdc
VALUE = 0x5c
VALUE = 0xb8
The only way I can get a consistent result is by using I2C.read_byte():
def get_byte(addr):
i2c.start()
stat = i2c.transfer([0x16, addr])
i2c.start()
stat += i2c.transfer([0x16 | 1])
r = i2c.read_byte()
i2c.nack()
i2c.stop()
if stat.find(chr(0x01)) != -1:
raise IOError("I2C command on address 0x%02x not acknowledged!" % (i2caddr))
return ord(r)
And I had to add the read_byte method into I2C.py as it was missing:
def read_byte(self):
self.write(0x04)
return self.response(1, True)
The write_then_read method, which according to my understanding supposed to be the general I2C read/write function implements the I2C wrong. The read supposed to be as follows:
The example in the README does not tell anything about how to issue a repeated start. I've written a code in the spirit of the example in the README:
>>> import pyBusPirateLite
>>> i2c = pyBusPirateLite.I2C()
>>> i2c.speed = '5kHz'
>>> i2c.configure(power=True)
>>> i2c.write_then_read(4,0, [ 0x3e, 0x82, 0xf0, 0xf0 ] )
b''
>>> i2c.write_then_read(2,2, [ 0x3f, 0x01] )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/pyBusPirateLite/I2C.py", line 308, in write_then_read
raise ProtocolError('Error in transmission')
pyBusPirateLite.base.ProtocolError: Error in transmission
Note to the code: The 0x82 command sets among others the 0x01 register, what I want to read out.
The signal waveforms shows that the first part of the transmission is missing (R/Wb=0 & reg address = 0x01)
I could get around with this if I could force a repeated start in the read_then_write's txdata. In its form either the implementation of the code is bad, or something is missing from the description.
This is a very useful library. The documentation could be improved, adding examples:
Does this also work with I2C? Do you have any example code?
Because I cannot find methods like: i2c.write or i2c.readword
Thank you for your work, this seems to be the best buspirate python lib at the moment!
Using latest master. Looks like this requires Python 3, might be worth noting.
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:25:58) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyBusPirateLite.I2C import *
>>> I2C()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyBusPirateLite\I2C.py", line 55, in __init__
super().__init__()
TypeError: super() takes at least 1 argument (0 given)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.