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

Re: New pigpio Python module

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

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

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: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

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: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

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: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

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: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Sun May 07, 2017 6:34 am

take your time, i can live with that error :)

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

Re: New pigpio Python module

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

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: 12782
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: New pigpio Python module

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

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: 1631
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

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 :)

brehar
Posts: 1
Joined: Tue Aug 22, 2017 5:21 pm

Re: New pigpio Python module

Tue Aug 22, 2017 6:39 pm

I've got a question about the online manual. regarding the glitch and noise filter. I plan to add a device to a one-wire CSMA/CA serial bus at 4,800 bps. Collisions are detected when the own transmit data are simultaneously read back distorted because another device was then transmitting at the same time.
Devices on the bus can send telegrams which are between 11 and 32 bytes long, with each byte being sent as start,8bits,parity,stop. Inter-byte delays are up to one-byte time, i.e. 2.290 ms. A longer pause indicates the end of a telegram which can then be processed..
The shortest pause between telegrams I have observed is 60 ms. Deduction: This is the shortest time any device waits for the bus to remain quiet before it begins a transmission. There is no upper limit for pauses between telegrams. Bus activity during a 60ms wait retriggers the wait period.
I have two scenarios:
1. The receiving code considers a telegram to be complete if sees a pause of longer than 1 character time (~ 3 ms); then it can go and process the receive buffer.
2. The sending code must have seen a quiet bus for at least 60ms before it is allowed to send. Let's disregard an add'l random delay for this discussion.

I am now referring to the Python part of the documentation. The section set_glitch_filter() reads: ".. It does not affect levels read by read, .. etc."
Q1: What does this mean for a receive operation? Can glitch_filter() run unaffected in parallel while bb_serial_read() receives data but triggers as soon as the bus level remains constant for a preset time of , say 3ms? This behavior could detect the end of a telegram ASAP.

Transmit operation: The glitch filter description looks as if this function can also be set up to wait 60ms for a quiet bus (at stop bit level) and then invokes a callback function which sends data.
Q2: Is this feasible?
Q3: Is pigpio thread-safe? Can a receive thread run in parallel to a transmit thread to check if there are bus collisions while the own device is transmitting? The data in the receive thread must be bit for bit identical to those being transmitted. Otherwise another device has impressed its own data onto the bus while the own device was sending. Then both devices revert to a wait status of at least 60 ms + random delay before they attempt to transmit.
============
One hint about the wave_add_serial() function: The documentation says "For bb_bits 9..16 there will be two bytes per character.:" So far, so good. I assumed that those two bytes are simply concatenated like in any 16-bit word and that the MSB bit of the second (lo) byte therefore is where the successive bits of the first (hi) byte continue. No such thing, a 9th parity bit has to be in the LSB position of the second byte, not in the MSB position. Maybe it would help to elaborate HOW more than one byte need to be fit together for 9..32 bits of serial data. I got the parity calculation in my code and, with the help of a scope, subsequently also the correct waveform generation with a data and parity byte done.

WIBNI parity handling could become part of the serial code in pigpio?

jgoglio
Posts: 3
Joined: Fri Feb 10, 2017 3:34 pm

Re: New pigpio Python module

Wed Sep 20, 2017 3:29 pm

Hi everyone,

I'm having an issue with the PIGPIO Python library. Long story short, I need to push 19 bits of data to a chip through SPI interface. I am able to successfully do this in most respects, but I believe there is something wrong with my current method of pushing 3 standard 8-bit words. I am successfully using the auxiliary SPI device (in order to use 3 CS), so I figure why not just change the word length to 19 (using the spi flags mentioned on the PIGPIO website)? However, this is not working for me. When I execute my code, it yells at me because it is expecting a value from 0 to 255 (8 bits) per word.

Has anyone else used this function of the PIGPIO Python library or run into this issue? Would anyone else be able to try this and see if they can get it to work?

Thank you in advance!

Return to “Python”

Who is online

Users browsing this forum: No registered users and 15 guests