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

Re: New pigpio Python module

Sun Jun 05, 2016 1:17 pm

PlanB wrote:So 25000 steps at 10kHz. Does that mean my PID loop should increment the duty cycle in blocks of 40 between 0 & 1000000?

Code: Select all

dc=dc+40
pi.hardware_PWM(18, 10000, dc)
I wouldn't bother. I'd just apply the PID and if it results in no change in duty cycle then so be it.

PlanB
Posts: 69
Joined: Tue Oct 28, 2014 6:44 am

Re: New pigpio Python module

Tue Jun 07, 2016 1:19 am

I tried just ramping the 10kHz duty cycle in steps of 40 for starters Joan but the CRO trace is all broken up, 30-40ms of 10kHz separated by similar intervals of gpio18 at 3.3v. Is this normal? I thought DMA based pwm ensured a steady stream uninterrupted by the OS like the software based versions?

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

Re: New pigpio Python module

Tue Jun 07, 2016 7:50 am

PlanB wrote:I tried just ramping the 10kHz duty cycle in steps of 40 for starters Joan but the CRO trace is all broken up, 30-40ms of 10kHz separated by similar intervals of gpio18 at 3.3v. Is this normal? I thought DMA based pwm ensured a steady stream uninterrupted by the OS like the software based versions?
No, that isn't normal. I suspect a dodgy connection on your CRO or an error in your script.

PlanB
Posts: 69
Joined: Tue Oct 28, 2014 6:44 am

Re: New pigpio Python module

Tue Jun 07, 2016 11:29 pm

Absolutely right, some weird aliasing effect on the digital CRO triggering, tried an old analog oscilloscope & it vanished like the phantom it was. Feeding that rock solid 10kHz pwm into a 100k/100nf RC now for some smoothing makes for a nice agile control loop, very nice. Thnx for the hand holding Joan.

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

Re: New pigpio Python module

Thu Jun 16, 2016 6:55 pm

hello Joan,
i have a script that creates and cancels callback on single gpio in a "strange" way, so i'd have some problems saving the callback var for each gpio.
Is there a way to cancell "all callbacks" from a GPIO without knowing the name of the previous callback created?

I mean, if i create a callback like this:

pi.callback(22, pigpio.EITHER_EDGE, cbf)

how can i cancel the callback from gpio 22?

thanks :)

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

Re: New pigpio Python module

Thu Jun 16, 2016 7:07 pm

Massi wrote:hello Joan,
i have a script that creates and cancels callback on single gpio in a "strange" way, so i'd have some problems saving the callback var for each gpio.
Is there a way to cancell "all callbacks" from a GPIO without knowing the name of the previous callback created?

I mean, if i create a callback like this:

pi.callback(22, pigpio.EITHER_EDGE, cbf)

how can i cancel the callback from gpio 22?

thanks :)
You can't.

You have to do the following.

cbid = pi.callback(22, pigpio.EITHER_EDGE, cbf)
...
cbid.cancel()

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

Re: New pigpio Python module

Thu Jun 16, 2016 7:10 pm

joan wrote:You can't.

You have to do the following.

cbid = pi.callback(22, pigpio.EITHER_EDGE, cbf)
...
cbid.cancel()
sad.
and atm i can't send on a websocket connection from a callback
it's gonna be an hard time for me :)

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

Re: New pigpio Python module

Thu Jun 16, 2016 7:26 pm

You could raise a github issue if you think it might be a common problem (or even if you think it'll be of no use to anyone but you).

https://github.com/joan2937/pigpio/issues

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

Re: New pigpio Python module

Fri Jun 17, 2016 7:41 am

joan wrote:You could raise a github issue if you think it might be a common problem (or even if you think it'll be of no use to anyone but you).

https://github.com/joan2937/pigpio/issues
this is not an issue at all :)
i'm trying to build a websocket app (in python) where the client asks the server for specific GPIOs to monitor, so the server has to set up callbacks on GPIOs when they are requested.
Obviously, when the last client requesting a specific GPIO disconnects, the server has to cancel the callback on that gpio.
It was easier for me to work only on gpio number. But i'll keep an array of vars for gpio's callbacks..
it can be done :)
thanks as always

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

Re: New pigpio Python module

Fri Jun 17, 2016 7:55 am

Massi wrote: ...
i'm trying to build a websocket app (in python) where the client asks the server for specific GPIOs to monitor, so the server has to set up callbacks on GPIOs when they are requested.
Obviously, when the last client requesting a specific GPIO disconnected, the server has to cancel the callback on that gpio.
It was easier for me to work only on gpio number. But i'll keep an array of vars for gpio's callbacks..
it can be done :)
...
It may be possible to do what I do in piscope, the Python module, and the pigpiod C I/F.

I set up a socket dedicated to notifications (PI_CMD_NOIB) and use the notification commands (on another "command" socket) to update the GPIO of interest. When the socket is closed all the notifications are purged.

KennyHD
Posts: 2
Joined: Tue Jun 21, 2016 6:24 pm

Re: New pigpio Python module

Tue Jun 21, 2016 6:27 pm

Hello,

is it possible to send two wave_chains simultaneously on two different pins? I need this to drive two steppers with the A4988-driver board. As soon as the second chain is created the first one stops to send pulses to the first pin.

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

Re: New pigpio Python module

Wed Jun 22, 2016 8:46 am

[ot] [definitely we need a section of the forum dedicated to pigpio :)]
Joan do you remember in which file is defined the list of user accessable gpios for each PI model?
yesterday i was playing with my old B rev2 and i expected an error trying to set the gpio 16 (like i got for gpio 26) - and this is also specified on your site ( http://abyz.co.uk/rpi/pigpio/index.html#Type_2 ), while i got no error (but the gpio wasn't set)

i wanted to check in source files on github, but i did not understand how you use bitmask to set gpio access, so.. sorry :)
Last edited by Massi on Wed Jun 22, 2016 9:02 am, edited 1 time in total.

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

Re: New pigpio Python module

Wed Jun 22, 2016 8:51 am

Sorry again, maybe i got it :)

Bitmask for model b rev 2

Code: Select all

1111 1011 1100 0111 1100 1111 1001 1100
User gpio allowed:
User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31
From the right..

Theres an error on gpio 16 :)

So i think it should be 0xFBC6CF9C in place of 0xFBC7CF9C

or probably i'm wrong :(

Edit to add:
line 5214 of pigpio.h

Code: Select all

#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
i've never used github, should i make a pull request? (i've always dreamt to say that :lol: )

B.Goode
Posts: 3971
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: New pigpio Python module

Fri Jun 24, 2016 11:28 am

[Not strictly related to the Python module, but this seemed like the best long-running threaad for comments about pigpio... ]

I'd like to take the opportunity to thank @joan for pigpio and related tools and utilities.

I've been aware of it and played with it for a year or more. Yesterday piscope really solved a problem for me.

I was working, for the first time, with an spi device - an mcp3008 adc chip.

It didn't work. I assumed it was my understanding of the software and libraries I was using. Tried several different approaches - still getting '0' returned on all channels, even thought some were hardwired to 3.3v.

Finally fired up piscope to look at the 4 logic lines related to SPI. Clock, Chip Select, and Data Out all OK. No data on the Data In line!

Continuity-checked path from relevant pin on mcp3008 to the header on the RPi: no connection.

Examined the PCB with a magnifier, and found that the related track had a tiny break.

I might have resolved this eventually by more continuity-testing, but I hadn't really expected a hardware fault - my mindset was that I didn't understand this new (to me) software technology. Piscope really helped me take a short-cut to the underlying problem. If I had to fire up a 'real' oscilloscope to do this I might not have bothered with the test.

Thanks @joan!

User avatar
elParaguayo
Posts: 1838
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: New pigpio Python module

Fri Jun 24, 2016 11:34 am

I'd second this. Very impressed with pigpio but piscope really helped me with an issue that was driving me mad.

Thank you for all your work.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

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

Re: New pigpio Python module

Fri Jun 24, 2016 11:44 am

Time to compile it for windows! :lol: :lol:

:roll:

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

Re: New pigpio Python module

Fri Jun 24, 2016 12:29 pm

Massi wrote:Sorry again, maybe i got it :)

Bitmask for model b rev 2

Code: Select all

1111 1011 1100 0111 1100 1111 1001 1100
User gpio allowed:
User GPIO 2-4, 7-11, 14-15, 17-18, 22-25, 27-31
From the right..

Theres an error on gpio 16 :)

So i think it should be 0xFBC6CF9C in place of 0xFBC7CF9C

or probably i'm wrong :(

Edit to add:
line 5214 of pigpio.h

Code: Select all

#define PI_DEFAULT_UPDATE_MASK_A_B2        0xFBC7CF9C
i've never used github, should i make a pull request? (i've always dreamt to say that :lol: )
It works on my Rev.2 B (/proc/cpuinfo revision 000f).

Is 16 inverse logic?

I just did a pigs pfs 16 0 p 16 128 and the LED flashes okay.

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

Re: New pigpio Python module

Fri Jun 24, 2016 12:31 pm

@B.Goode
@elParaguayo

Thanks.

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

Re: New pigpio Python module

Fri Jun 24, 2016 12:41 pm

joan wrote: It works on my Rev.2 B (/proc/cpuinfo revision 000f).
Wait, what do you mean with "works"?
isn't gpio 16 out of rev2 B headers? isn't it "not allowed"?
(as reported above, from your page 16 is out of user gpio list)
Is 16 inverse logic?
i don't know (but this would be the first time to hear this :))
i could pi.write() to it, but could not get correct levels.
I'll give it another try tonight..
I just did a pigs pfs 16 0 p 16 128 and the LED flashes okay.
wait again, what led?
where did you connect the led? :)

i fear i missed something :(


Edit: i did. GPIO 16 is the onboard led. Ok i need to give it another try (sorry).

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

Re: New pigpio Python module

Fri Jun 24, 2016 1:22 pm

Some Pi model exceptions are made to which GPIO may be written. See Exceptions in http://abyz.co.uk/rpi/pigpio/pigpiod.html

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

Re: New pigpio Python module

Fri Jun 24, 2016 1:32 pm

joan wrote:Some Pi model exceptions are made to which GPIO may be written. See Exceptions in http://abyz.co.uk/rpi/pigpio/pigpiod.html
damn.. sorry..

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

Re: New pigpio Python module

Fri Jun 24, 2016 2:03 pm

Massi wrote:
joan wrote:Some Pi model exceptions are made to which GPIO may be written. See Exceptions in http://abyz.co.uk/rpi/pigpio/pigpiod.html
damn.. sorry..
I have made several errors in this area which people have pointed out to me, you could just as easily have been right.

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

Re: New pigpio Python module

Mon Jul 11, 2016 10:58 am

I have made a new release, V55, http://abyz.co.uk/rpi/pigpio/download.html

The following features are added
http://abyz.co.uk/rpi/pigpio/examples.h ... 18B20-1_py is an example of using the file functions to read the DS18B20 temperature sensor.

braddo
Posts: 9
Joined: Wed May 06, 2015 2:20 am

Re: New pigpio Python module

Wed Aug 03, 2016 10:25 pm

Hey, I've been using pigpio now and it's working great for controlling both a servo motor and a brushless fan.

A couple of issues thought. The fan needs a relatively high PWM frequency - it's recommended to do 25khz in order to avoid the audible spectrum - indeed, if I set the frequency to 20k I can hear a nasty squeal from the fan motor. It's quiet at 40k but then the poor Pi Zero (which also has to run and paint the NodeRed dashboard, seems to lag.

I would have thought that if I set a lower sample rate I could get a freq somewhere in the middle, but it seems that all of the sample rates ahve overlapping frequencies rather than "alternating" so that somewhere lower in the sample rate support I could get say 25k

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

Re: New pigpio Python module

Thu Aug 04, 2016 6:40 am

braddo wrote:Hey, I've been using pigpio now and it's working great for controlling both a servo motor and a brushless fan.

A couple of issues thought. The fan needs a relatively high PWM frequency - it's recommended to do 25khz in order to avoid the audible spectrum - indeed, if I set the frequency to 20k I can hear a nasty squeal from the fan motor. It's quiet at 40k but then the poor Pi Zero (which also has to run and paint the NodeRed dashboard, seems to lag.

I would have thought that if I set a lower sample rate I could get a freq somewhere in the middle, but it seems that all of the sample rates ahve overlapping frequencies rather than "alternating" so that somewhere lower in the sample rate support I could get say 25k
Try to use one of the hardware PWM GPIO, see http://abyz.co.uk/rpi/pigpio/python.html#hardware_PWM

Return to “Python”

Who is online

Users browsing this forum: No registered users and 10 guests