0

I have a program that is meant to read data:

import pigpio

pi = pigpio.pi()

if not pi.connected:
    exit()

h = pi.i2c_open(1, 0x5a)





c, data = pi.i2c_read_device(h,0x09)



print(data)




pi.i2c_close(h)

pi.stop()

When I try and run it, I get data but it crashes when it tries to run pi.stop().

The error message is:

Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1106, in run
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 977, in _pigpio_command
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'send'
  • I haven't been able to replicate this behavior. Which version of pigpio are you using (pigs pigpv) ? – joan Feb 16 '18 at 18:15
  • the command returns the number 60 – wye_mine codebase Feb 17 '18 at 8:51
0

Try adding an import time at the top and a time.sleep(0.1) before the pi.stop(). There may be a race condition, although I don't see why there should be.

import time
import pigpio

pi = pigpio.pi()

if not pi.connected:
    exit()

h = pi.i2c_open(1, 0x5a)

c, data = pi.i2c_read_device(h, 0x09)

print(data)

pi.i2c_close(h)

time.sleep(0.1)

pi.stop()
  • I am getting data but I am struggling to interpret it as it has less bytes than it should : (9L, bytearray(b'\x01\xc7\x00\x00\x023\xc1\x00\x7f')) – wye_mine codebase Feb 17 '18 at 10:01
  • also the problem I had earlier seems to be with I2c or smbus as the raw read device works but read block data gives the same impossible data that started this: (9L, bytearray(b'\xb5\x7f\xff\xff\xff\xff\xff\xff\xff')) – wye_mine codebase Feb 17 '18 at 10:02
  • The \x023 is two bytes, it prints hex for non-ASCII characters, so that is hex 02 followed by the character 3 (hex 33). It might be easier if you print data[0], data[1], etc. The device does not seem to support SMBus commands, you will have to use i2c read device. – joan Feb 17 '18 at 11:40
  • the bytearray is all one thing, how do I separate it? it is all in data[1] – wye_mine codebase Feb 17 '18 at 17:14
  • I have fixed it and got reliable and accurate data from my program, many thanks for your kind assistance – wye_mine codebase Feb 17 '18 at 17:28

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.