New pigpio Python module


189 posts   Page 7 of 8   1 ... 4, 5, 6, 7, 8
by paijo » Wed Aug 24, 2016 9:04 am
Dear,
Would you like give me the example pigpio with gambas program?
Thank you very much
regards
Posts: 2
Joined: Tue Aug 23, 2016 12:11 am
by joan » Wed Aug 24, 2016 10:55 am
paijo wrote:Dear,
Would you like give me the example pigpio with gambas program?
Thank you very much
regards

I can't help with that. I have never used Gambas.
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Dusan » Mon Sep 26, 2016 11:59 am
Hi joan,

Thank you for your effort to make this working.
I have question about interrupt driven GPIO pins.
I want to connect RFID reader to the RPi2 GPIO pins and I have concern about speed of the interrupts. Reader will send 26 or 34 bits (wiegand standard) on every 2ms when card is near the reader. Assume that system have LCD display and some more stuff to do beside reading cards. Can I achieve this interrupt speed without issues?

Best regards,
Dusan
Posts: 1
Joined: Mon Sep 26, 2016 11:52 am
by joan » Mon Sep 26, 2016 12:43 pm
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by federico.human » Sun Oct 02, 2016 3:44 pm
I need your help. I installed the library in Raspbian:
Code: Select all
sudo apt-get install pigpio python-pigpio python3-pigpio

And when I try to use it I get an error on the line:
Code: Select all
pi = pigpio.pi()

pigpio.pi()
AttributeError: 'module' object has no attribute 'pi'

This does not happen when I run python and then manually load the library and start it.
User avatar
Posts: 11
Joined: Wed Jul 15, 2015 8:41 pm
by joan » Sun Oct 02, 2016 3:50 pm
Where is the line pi = pigpio.pi()? In a script, on the command line, typed into IDLE?

Could you cut&paste the context from a screen shot?
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by federico.human » Sun Oct 02, 2016 5:55 pm
On a python file:

Code: Select all
#!/usr/bin/python

import time
import pigpio

RX = 3

pi = pigpio.pi()
pi.set_mode(RX, pigpio.INPUT)
pi.bb_serial_read_open(RX, 9600, 8)

while True:
      (count, data) = pi.bb_serial_read(RX)
      if count:
            print data
      time.sleep(1)


Which I run from the console:

Code: Select all
sudo python pigpio.py



Edit: I realised it is not working because I named the file the same as the library :? :shock: :o
User avatar
Posts: 11
Joined: Wed Jul 15, 2015 8:41 pm
by joan » Sun Oct 02, 2016 7:00 pm
Good spot.

By the way you don't need to run a pigpio script with sudo (only the daemon needs sudo).
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Massi » Mon Oct 03, 2016 2:09 pm
hello Joan,
i have a question :)

if i set up different callbacks on the same GPIO in different python scripts, if i cancel one of those, do the others remain valid?

The manual says:
A GPIO may have multiple callbacks (although I can't think of a reason to do so).


so i'd expect the single callback of the single script can remain active, but this is just to be sure..

(don't ask me the reason, it's a debugging problem..)
Posts: 1554
Joined: Fri May 02, 2014 1:52 pm
Location: Italy
by joan » Mon Oct 03, 2016 2:23 pm
Each script you start will be a separate process and will have its own socket interface to the pigpio daemon. Switching off a callback in one script will have no effect on the callbacks of another process.

As an aside I ran up Windows a few days ago and it was quite easy to get piscope to display on the Windows box using putty. You just need to run a local X server on your Windows box. I downloaded xming. I very rarely use Windows so I may just have discovered something which everyone else has known for years. Anyhow, I updated the details at http://abyz.co.uk/rpi/pigpio/piscope.html
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Massi » Wed Oct 19, 2016 2:15 pm
joan wrote:As an aside I ran up Windows a few days ago and it was quite easy to get piscope to display on the Windows box using putty. You just need to run a local X server on your Windows box. I downloaded xming. I very rarely use Windows so I may just have discovered something which everyone else has known for years. Anyhow, I updated the details at http://abyz.co.uk/rpi/pigpio/piscope.html


sorry, i've never given this a try :)
can i use this also with raspbian lite or do i need the x server even on the remote PI?

as always thanks :)
Posts: 1554
Joined: Fri May 02, 2014 1:52 pm
Location: Italy
by joan » Wed Oct 19, 2016 2:21 pm
Massi wrote:
joan wrote:As an aside I ran up Windows a few days ago and it was quite easy to get piscope to display on the Windows box using putty. You just need to run a local X server on your Windows box. I downloaded xming. I very rarely use Windows so I may just have discovered something which everyone else has known for years. Anyhow, I updated the details at http://abyz.co.uk/rpi/pigpio/piscope.html


sorry, i've never given this a try :)
can i use this also with raspbian lite or do i need the x server even on the remote PI?

as always thanks :)

I don't know. I suspect it should work as all the X stuff will be done by your Windows box. Give it a go.
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Massi » Mon Feb 13, 2017 9:36 pm
hello joan,

i'd like to recreate a wave with these timings (it's a sort of OOK)

#T0H 0 code high voltage time 0.35us ±150ns
#T1H 1 code high voltage time 0.7us ±150ns
#T0L 0 code low voltage time 0.8us ±150ns
#T1L 1 code low voltage time 0.6us ±150ns

should i give up knowing that the minimum delay i can use in the pigpio.pulse function is 1 us?

thanks :)
Posts: 1554
Joined: Fri May 02, 2014 1:52 pm
Location: Italy
by joan » Mon Feb 13, 2017 9:48 pm
Massi wrote:hello joan,

i'd like to recreate a wave with these timings (it's a sort of OOK)

#T0H 0 code high voltage time 0.35us ±150ns
#T1H 1 code high voltage time 0.7us ±150ns
#T0L 0 code low voltage time 0.8us ±150ns
#T1L 1 code low voltage time 0.6us ±150ns

should i give up knowing that the minimum delay i can use in the pigpio.pulse function is 1 us?

thanks :)

pigpio is at best 1µs resolution so can't help with those signals.

I would look at using SPI if you only need one GPIO. If you run a clock at about 8MHz you could probably generate the needed signals on MOSI. You would have to take account of the 1.5 bit times between each octet (but you could make that less time by raising the bit rate).
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Massi » Mon Feb 13, 2017 10:15 pm
well not clean, but it seems it can work..

https://ca.rstenpresser.de/blag/2016/02 ... using-spi/

do you think i will be able to manage this in python?
Posts: 1554
Joined: Fri May 02, 2014 1:52 pm
Location: Italy
by joan » Mon Feb 13, 2017 10:43 pm
I don't see why not. I'd have tried myself if I had that sort of LED strip. I'm fairly sure I posted some code or some logic some time ago to use SPI for WS2812 based LEDs.

If it is a long strip you would be better off using spidev rather than the pigpio driver (unless you give pigpio real-time priority). spidev would have a better chance of keeping the SPI FIFO filled (needed for the tight timings).
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by davef21370 » Tue Feb 14, 2017 5:46 pm
Install went okay but I'm getting...
Traceback (most recent call last):
File "pigtest.py", line 3, in <module>
pigpio.start()
AttributeError: 'module' object has no attribute 'start'


Any ideas?

Regards.
Dave.
Please feel free to tap into my abundant lack of knowledge.
When you're dead you don't know you're dead. It's the same as being stupid.
Apple say. Monkey do.
User avatar
Posts: 821
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded
by joan » Tue Feb 14, 2017 6:18 pm
davef21370 wrote:Install went okay but I'm getting...
Traceback (most recent call last):
File "pigtest.py", line 3, in <module>
pigpio.start()
AttributeError: 'module' object has no attribute 'start'

...

pigpio.start() was deprecated when I decided to allow the control of multiple Pi from one script.

The style to use now is
Code: Select all
#!/usr/bin/env python

import pigpio

pi1 = pigpio.pi()       # pi1 accesses the local Pi's GPIO
if not pi1.connected:
   exit()

pi2 = pigpio.pi('tom')  # pi2 accesses tom's GPIO
if not pi2.connected:
   p1.stop()
   exit()

pi3 = pigpio.pi('dick') # pi3 accesses dick's GPIO
if not pi3.connected:
   p1.stop()
   p2.stop()
   exit()

pi1.write(4, 0) # set local Pi's GPIO 4 low
pi2.write(4, 1) # set tom's GPIO 4 to high
pi3.read(4)     # get level of dick's GPIO 4

pi1.stop()
pi2.stop()
pi3.stop()
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by davef21370 » Tue Feb 14, 2017 6:27 pm
That works. Ta.
Please feel free to tap into my abundant lack of knowledge.
When you're dead you don't know you're dead. It's the same as being stupid.
Apple say. Monkey do.
User avatar
Posts: 821
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded
by Massi » Wed Feb 15, 2017 1:49 pm
joan wrote:I don't see why not. I'd have tried myself if I had that sort of LED strip. I'm fairly sure I posted some code or some logic some time ago to use SPI for WS2812 based LEDs.
If it is a long strip you would be better off using spidev rather than the pigpio driver (unless you give pigpio real-time priority). spidev would have a better chance of keeping the SPI FIFO filled (needed for the tight timings).


no, it is not.
i bought a couple of "single led board" just because i wanted some fun with your waves, then yesterday (i'm still waiting them to arrive from china..) i realized the timing was some orders of magnitude lower LOL

i'm not able to find your code (i admin i was quite sure of that, lol), but i'll look deeper asap..

Thanks!
Posts: 1554
Joined: Fri May 02, 2014 1:52 pm
Location: Italy
by joan » Wed Feb 15, 2017 3:01 pm
Massi wrote:...
i'm not able to find your code (i admin i was quite sure of that, lol), but i'll look deeper asap..
...

This is the thread/post I was thinking of.

https://www.raspberrypi.org/forums/view ... 46#p619946
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by Massi » Wed Feb 15, 2017 3:30 pm
amazing! i'll try as soon as the leds arrive..
Posts: 1554
Joined: Fri May 02, 2014 1:52 pm
Location: Italy
by bcbrown » Sun Apr 02, 2017 3:04 pm
Hi! I'm just getting involved with small micro controllers like this I'm more familiar with large products such as the NI RoboRio for FRC use. I have had a Pi for a while but I want to put it to good use. In order to set up the PiGPIO do I need some type of OS already like raspbian? It says add the line of code to the console to install it but i'm not sure what console to add it to. If you could redirect me to more forum better suiting my questions or give me instructions please do. Thanks!
Posts: 3
Joined: Sun Apr 02, 2017 2:54 pm
by joan » Sun Apr 02, 2017 10:10 pm
bcbrown wrote:Hi! I'm just getting involved with small micro controllers like this I'm more familiar with large products such as the NI RoboRio for FRC use. I have had a Pi for a while but I want to put it to good use. In order to set up the PiGPIO do I need some type of OS already like raspbian? It says add the line of code to the console to install it but i'm not sure what console to add it to. If you could redirect me to more forum better suiting my questions or give me instructions please do. Thanks!

It may be pre-installed in Raspbian.

If the command pigpiod -v works it means it is installed.

Otherwise follow the instructions at http://abyz.co.uk/rpi/pigpio/download.html
User avatar
Posts: 12629
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by r3bpy » Thu Apr 06, 2017 9:07 pm
Hello Joan,

Being a full time programmer myself I think I can see how much time and efforts you have put in the development of this wonderful library. The idea to have a daemon running on Pi and the client application running on a different machine makes really a huge difference.
I am a Wing (a python IDE) user and like it very much for its remote debugging capabilities. So to learn more about the communication between pigpio and a sensor I had to build a remote Wing debugger for Pi (a Wing feature) and was able to debug one of your examples on my Windows dev. machine while running the client application (basically one of your examples) on Pi. But even then while I could debug the example I could not go/follow the execution flow into the libraries etc - no matter how this debugging technique is good, it still has its own limitations and that's sad.
And then I read about running the client application on a different computer and simply letting the pigpio know the host name of Pi and tried it (one can always change his "host" file and assign a known IP address to a name and use it later in the pigpio initialization call). That is brilliant, because now no matter what Python IDE you use (too be precise - it still has to have some sort of debugger) you can debug your locally running code (On Windows, etc) while the code itself communicates with Pi / pigpio daemon and controls Pi GPIO.
Honestly, I don't know how you came to this implementation but thank you very much for this wonderful library, you have done a great job!

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?

Thanks!
Posts: 2
Joined: Thu Apr 06, 2017 9:52 am