User avatar
joan
Posts: 13294
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: 1677
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: 13294
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: 1677
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: 13294
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: 1677
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: 13294
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: 13294
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: 1677
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: 13294
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: 1677
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: 13294
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: 1677
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: 1677
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!

Massi
Posts: 1677
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Sun Mar 04, 2018 12:25 pm

Dear Joan,
probably i'm wrong, but i'm seeing a problem with your python module in a specific case.

Pigpio version: 64 (the last on repositories for jessie)

I'm driving a stepper motor with a test code, trying to reset gpio to low on exit (on keyboard interrupt)

Here is the code

Code: Select all

#!/usr/bin/python
import time
import pigpio

pi = pigpio.pi()

# Define GPIO signals to use
StepPins = [18,17,27,22]
# Set all pins as output and low
for pin in StepPins:
	pi.set_mode(pin, pigpio.OUTPUT)
	pi.write(pin,0)
 
# Define advanced sequence
# as shown in manufacturers datasheet
Seq = [[1,0,0,1],
       [1,0,0,0],
       [1,1,0,0],
       [0,1,0,0],
       [0,1,1,0],
       [0,0,1,0],
       [0,0,1,1],
       [0,0,0,1]]
        
StepCount = len(Seq)
StepDir = 1 # Set to 1 or 2 for clockwise
            # Set to -1 or -2 for anti-clockwise
  
# Initialise variables
StepCounter = 0
 
# Start main loop
try:
	while True:
		for pin in range(0,4):
			xpin=StepPins[pin]# Get GPIO
			pi.write(xpin, Seq[StepCounter][pin])
		StepCounter += StepDir

		# If we reach the end of the sequence
		# start again
		if (StepCounter>=StepCount):
			StepCounter = 0
		if (StepCounter<0):
			StepCounter = StepCount+StepDir
		
		# Wait before moving on
		#time.sleep(0.1/1000)
	
except (KeyboardInterrupt, SystemExit) as e:
	for pin in StepPins:
		print("Turning off pin {}".format(pin))
		pi.write(pin,0)
except Exception as e:
	print(e)
finally:
	pi.stop()
As you can see, i put in the except for keyboard interrupt the modification to outputut and in the finally the connection closing to pigpiod.
Well, this code is not working, given that 99% of times my keyboard interrupt is hanging the script in the "turning off pin.." part.

BUT

if i close the connection to pigpio and re-open it, all works. here is the part of code modified:

Code: Select all

except (KeyboardInterrupt, SystemExit) as e:
	pi.stop()
	pi = pigpio.pi()
	for pin in StepPins:
		print("Turning off pin {}".format(pin))
		pi.write(pin,0)
my idea is that if i ctrl+C the code while it is executing a pi.write() command, the connection to pigpiod is in some way interrupted.
Indeed, if i add a sleep in the code and i ctrl-C the code in that point, the except code works correctly.

what else can it be?

PS: do you think i could have any advantage in timings using the get_bank, set_bank and clear_bank functions to set more GPIOs at the same time?

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

Re: New pigpio Python module

Sun Mar 04, 2018 12:33 pm

@Massi

I'll run the original code later to see if I can reproduce the problem. Using the bank calls would be quicker for
multiple GPIO.

Massi
Posts: 1677
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Sun Mar 04, 2018 12:57 pm

joan wrote:
Sun Mar 04, 2018 12:33 pm
@Massi

I'll run the original code later to see if I can reproduce the problem. Using the bank calls would be quicker for
multiple GPIO.
as usual, thank you a lot :)
it's also happening with the stepper code you linked on your site:

Code: Select all

#!/usr/bin/env python3
#coding=utf-8

import pigpio
from time import sleep
from collections import deque

fullStepSequence = (
	(1, 0, 0, 0),
	(0, 1, 0, 0),
	(0, 0, 1, 0),
	(0, 0, 0, 1)
)

halfStepSequence = (
	(1, 0, 0, 0),
	(1, 1, 0, 0),
	(0, 1, 0, 0),
	(0, 1, 1, 0),
	(0, 0, 1, 0),
	(0, 0, 1, 1),
	(0, 0, 0, 1),
	(1, 0, 0, 1)
)

class StepperMotor:
	def __init__(self, pin1, pin2, pin3, pin4, sequence = fullStepSequence, delayAfterStep = 0):
		self.pi = pigpio.pi()
		self.pi.set_mode(pin1, pigpio.OUTPUT)
		self.pi.set_mode(pin2, pigpio.OUTPUT)
		self.pi.set_mode(pin3, pigpio.OUTPUT)
		self.pi.set_mode(pin4, pigpio.OUTPUT)
		self.pin1 = pin1
		self.pin2 = pin2
		self.pin3 = pin3
		self.pin4 = pin4
		self.delayAfterStep = delayAfterStep
		self.deque = deque(sequence)

	def doCounterclockwiseStep(self):
		self.deque.rotate(-1)
		self.doStepAndDelay(self.deque[0])
	
	def doClockwiseStep(self):
		self.deque.rotate(1)
		self.doStepAndDelay(self.deque[0])

	def doStepAndDelay(self, step):
		self.pi.write(self.pin1, step[0])
		self.pi.write(self.pin2, step[1])
		self.pi.write(self.pin3, step[2])
		self.pi.write(self.pin4, step[3])
		sleep(self.delayAfterStep)
	
	def doPause(self):
		self.pi.write(self.pin1, 0)
		self.pi.write(self.pin2, 0)
		self.pi.write(self.pin3, 0)
		self.pi.write(self.pin4, 0)
	
	def close(self):
		self.pi.stop()

		
if __name__ == "__main__":
	stepper = StepperMotor(18,17,27,22)
	try:
		for i in range(1024):
			stepper.doClockwiseStep()
		for i in range(1024):
			stepper.doCounterclockwiseStep()
	finally:
		stepper.doPause()
		stepper.close()
just slightly modified to remove the delay

Edit to add: well, probably i should say my test PI is a first version Pi model B, given we are talking about timings :)

fishwolf
Posts: 39
Joined: Fri Sep 13, 2013 8:33 am

Re: New pigpio Python module

Wed Mar 14, 2018 6:25 pm

Hi,

when i use the hardware pwd on all 3 pwn pins, the audio output play a continuos beep sound.

i have read the 3 post, but is it possible remove this sound?

thanks

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

Re: New pigpio Python module

Wed Mar 14, 2018 6:41 pm

fishwolf wrote:
Wed Mar 14, 2018 6:25 pm
Hi,

when i use the hardware pwd on all 3 pwn pins, the audio output play a continuos beep sound.

i have read the 3 post, but is it possible remove this sound?

thanks
I am not sure which pins you mean. If you use the hardware PWM GPIO (i.e. 12/13/18/19) that will affect audio which uses PWM.

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

Re: New pigpio Python module

Wed Mar 14, 2018 6:43 pm

@Massi

I have not forgotten your issue. It is a problem. I will see if I can find a reasonable solution.

Massi
Posts: 1677
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

Re: New pigpio Python module

Wed Mar 14, 2018 8:42 pm

i'm sorry i always carry bad news :)
can i help you in any way?
thanks!

Edit to add: i can't remember if i told you that the same problem is happening using the "bank approach" in place of the "single gpio approach"..

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

Re: New pigpio Python module

Wed Mar 14, 2018 9:27 pm

Massi wrote:
Wed Mar 14, 2018 8:42 pm
i'm sorry i always carry bad news :)
can i help you in any way?
thanks!

Edit to add: i can't remember if i told you that the same problem is happening using the "bank approach" in place of the "single gpio approach"..
Bugs are always good news. :D

I think the problem is the interrupted system call (a read/write on the command socket) which destroys the socket. It would be easy if I could disable the keyboard interrupt during the call but you can't in Python. I haven't started looking for a practical solution. I'll start looking tomorrow.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 6 guests