User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Sat Apr 08, 2017 8:00 am

r3bpy wrote: ...
PS: I would like to buy you a beer and was looking at your website for a "donate" link and found nothing. Is there such a thing?
...
No need, I have a surgically implanted syringe to drip feed needed supplies. :D

There is another debugging tool which is sometimes useful.

If you enter the command pigs csi 5 that switches on internal diagnostics up to level 5. If you then cat /dev/pigerr& at a Pi terminal you will see a trace of commands sent to the pigpio daemon.
r3bpy
Posts: 3
Joined: Thu Apr 06, 2017 9:52 am

Re: New pigpio Python module

Postby r3bpy » Tue Apr 11, 2017 8:12 am

joan wrote: No need, I have a surgically implanted syringe to drip feed needed supplies. :D
I hope you are ok as much as one can be in such situation.
joan wrote: There is another debugging tool which is sometimes useful.
Thank you for the valuable advice.

best,
r3bpy
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Tue May 02, 2017 12:16 pm

Hello Joan,
i have a single class (che one reading from an ADS1115 ADC) that now and then returns this kind of error:

Code: Select all

 File "/usr/local/bin/classes/peripheals/ads1115.py", line 84, in __init__
    self.i2c = self.pi.i2c_open(1, self.address, 0)
  File "/usr/lib/python3/dist-packages/pigpio.py", line 2580, in i2c_open
    self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))
  File "/usr/lib/python3/dist-packages/pigpio.py", line 1000, in _pigpio_command_ext
    sl.s.sendall(ext)
AttributeError: 'NoneType' object has no attribute 'sendall'
as far as i can understand, this is not an error related to i2c, but it is related to the connection between python and pigpiod, am i wrong?
how can i debug deeper this?

thanks :)
User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Tue May 02, 2017 12:35 pm

Massi wrote:Hello Joan,
i have a single class (che one reading from an ADS1115 ADC) that now and then returns this kind of error:

Code: Select all

 File "/usr/local/bin/classes/peripheals/ads1115.py", line 84, in __init__
    self.i2c = self.pi.i2c_open(1, self.address, 0)
  File "/usr/lib/python3/dist-packages/pigpio.py", line 2580, in i2c_open
    self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))
  File "/usr/lib/python3/dist-packages/pigpio.py", line 1000, in _pigpio_command_ext
    sl.s.sendall(ext)
AttributeError: 'NoneType' object has no attribute 'sendall'
as far as i can understand, this is not an error related to i2c, but it is related to the connection between python and pigpiod, am i wrong?
how can i debug deeper this?

thanks :)
I think I only see that error when the pigpio connection has never been established (program start) or is being closed down (program exit).

Are either of those scenarios likely? I wouldn't expect the error in the middle of a session.
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Tue May 02, 2017 8:28 pm

joan wrote:I think I only see that error when the pigpio connection has never been established (program start) or is being closed down (program exit).
Are either of those scenarios likely? I wouldn't expect the error in the middle of a session.
well it seems to me there is nothing strange in my code:

Code: Select all

	def __init__(self, address=0x48, debug=False):
		self.pi = pigpio.pi()
		self.address = address
		self.i2c = self.pi.i2c_open(1, self.address, 0)
		loggerInfo.info("ADS1115 initialized at i2c address {0:x}".format(address))
More or less, all my sensor classes are written in this way. And i get that error only for this class.
I'll add the check on pi connection in the middle, but i can't really understand why..
that error means that self.pi has been created and dies before the i2c_open call, am i right?
User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Tue May 02, 2017 8:40 pm

Massi wrote: ...
More or less, all my sensor classes are written in this way. And i get that error only for this class.
I'll add the check on pi connection in the middle, but i can't really understand why..
that error means that self.pi has been created and dies before the i2c_open call, am i right?
Have you a small complete error example you can share? I'll see if I can debug it.
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Thu May 04, 2017 7:56 pm

sorry for the late reply, but i've been trying to reproduce it.
well, today i got an error also from another sensor class so i tried to "stress" a little the pigpio connection.

I understand this is a very "unrealistic" case, but with this code i get the same error:

Code: Select all

import pigpio
import threading
import time

def doThings():
	pi = pigpio.pi()
	handle = pi.i2c_open(1,0x20)
	time.sleep(0.1)
	pi.i2c_close(handle)
	pi.stop()
	
for i in range(1000):
	t = threading.Thread(target=doThings)
	t.start()
	time.sleep(0.01)
Error coming from this code is the same as before, but since i'm testing this from the console i also see the error message of the pigpiod

Code: Select all

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Can't connect to pigpio at localhost(8888)

Do you have permission to access the pigpio daemon?
Perhaps it was started with sudo pigpiod -nlocalhost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Exception in thread Thread-1209:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "pigtest.py", line 7, in doThings
    handle = pi.i2c_open(1,0x20)
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 2580, in i2c_open
    self.sl, _PI_CMD_I2CO, i2c_bus, i2c_address, 4, extents))
  File "/usr/lib/python2.7/dist-packages/pigpio.py", line 1000, in _pigpio_command_ext
    sl.s.sendall(ext)
AttributeError: 'NoneType' object has no attribute 'sendall'
Sometimes this returns 1 error
sometimes no errors
sometimes 3 errors
it's random :)

the system has just been dist-upgraded

Indeed, the first time i saw this error was trying to run sensors readings threading the classes..
User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Thu May 04, 2017 8:49 pm

Okay, thanks for that. I can repeat the error.

If I find out what's going wrong I'll let you know!
User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Sat May 06, 2017 10:27 pm

Okay, I think I know what is going wrong. A socket operation I thought was atomic doesn't appear to be atomic after all.

I will correct the fault, but I'm not sure when I'll push out the fix.
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Sun May 07, 2017 6:34 am

take your time, i can live with that error :)
User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Sat May 13, 2017 2:05 pm

Massi wrote:take your time, i can live with that error :)
I have just released V63 which I hope corrects the fault you are seeing. Sockets are atomic after all. That was a red herring.
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Sun May 14, 2017 6:20 am

joan wrote:
Massi wrote:take your time, i can live with that error :)
I have just released V63 which I hope corrects the fault you are seeing. Sockets are atomic after all. That was a red herring.
wow great!
how long do you think it is gonna take to have this in the standard raspbian repositories?

Code: Select all

pi@baguette:~ $ pigs pigpv
60
we are 3 steps late :)

and thanks also for the english course :)
User avatar
joan
Posts: 12702
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

Postby joan » Sun May 14, 2017 7:23 am

Massi wrote: ...
how long do you think it is gonna take to have this in the standard raspbian repositories?
...
I have no idea.

As an aside I don't think it will ever get in the standard Raspbian repository as I think they only accept Debian packages.

The raspberrypi.org image will be fetching it from the separate repository maintained by raspberrypi.org.
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Thu May 18, 2017 11:47 am

well as of today we are still at v60 in the repositories.. i fear i'll have to install it manually..
Massi
Posts: 1567
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Postby Massi » Tue Jul 04, 2017 7:26 pm

hello joan,
i'm playing with i2c bitbanging, but since i can get only "0xff" results from a sensor i can't read in other ways (clock stretching problem..) i'd like to know if i'm missing something :)

Let's say the sensor is at address 0x20
Let's say i'd like to read 1 byte from a register (0x02)

So i'd open the i2c bitbang:

Code: Select all

bb_i2c_open(sdaGpio, sclGpio, i2cSpeed)
then i'd zip this series of command:
4 (set address)
0x20 (7bit i2c address)
2 (start condition)
7 (write)
1 (1 byte)
0x02 (register address)
2 (another start)
6 (read)
1 (1 byte)
3 (stop)
0 (close)

so:

Code: Select all

(count, data) = pi.bb_i2c_zip(sdaGpio, [4, 0x20, 2, 7, 1, 0x02, 2, 6, 1, 3, 0])

print(count)
print(binascii.hexlify(data))
and what i get is.. the number of bytes i choose (any number, also 10..) and a list of "ff"
now, is the sensor working bad or am i missin something?

thanks :)