Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79001 > unrolled thread
| Started by | martijnperdaan@gmail.com |
|---|---|
| First post | 2014-10-12 07:24 -0700 |
| Last post | 2014-10-12 18:36 +0000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
what is wrong with this script and how do I get the value in a php script martijnperdaan@gmail.com - 2014-10-12 07:24 -0700
Re: what is wrong with this script and how do I get the value in a php script Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-12 12:47 -0400
Re: what is wrong with this script and how do I get the value in a php script Peter Pearson <pkpearson@nowhere.invalid> - 2014-10-12 17:01 +0000
Re: what is wrong with this script and how do I get the value in a php script Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-12 18:36 +0000
| From | martijnperdaan@gmail.com |
|---|---|
| Date | 2014-10-12 07:24 -0700 |
| Subject | what is wrong with this script and how do I get the value in a php script |
| Message-ID | <05f27d81-372d-4242-bc62-e738e23680d4@googlegroups.com> |
what is wrong with this script and how do I get the value Rij1 and Rij2 and Rij3 and Rij4 and Rij5 and Rij6 in a php script
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN)
GPIO.setup(18, GPIO.IN)
GPIO.setup(21, GPIO.IN)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
Rij1 = 0
Rij2 = 0
Rij3 = 0
Rij4 = 0
Rij5 = 0
Rij6 = 0
while True:
PRij1 = GPIO.input(17)
PRij2 = GPIO.input(18)
PRij3 = GPIO.input(21)
PRij4 = GPIO.input(22)
PRij5 = GPIO.input(23)
PRij6 = GPIO.input(24)
if (PRij1 == False):
Rij1 = Rij1 + 1
while PRij1 == False:
PRij1 = GPIO.input(17)
if (PRij2 == False):
Rij2 = Rij2 + 1
while PRij2 == False:
PRij2 = GPIO.input(18)
if (PRij3 == False):
Rij3 = Rij3 + 1
while PRij3 == False:
PRij3 = GPIO.input(21)
if (PRij4 == False):
Rij4 = Rij4 + 1
while PRij4 == False:
PRij4 = GPIO.input(22)
if (PRij5 == False):
Rij5 = Rij5 + 1
while PRij5 == False:
PRij5 = GPIO.input(23)
if (PRij6 == False):
Rij6 = Rij6 + 1
while PRij6 == False:
PRij6 = GPIO.input(24)
Totaal = Rij1 + Rij2 + Rij3 + Rij4 + Rij5 + Rij6
print Totaal
[toc] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-12 12:47 -0400 |
| Message-ID | <mailman.14791.1413132432.18130.python-list@python.org> |
| In reply to | #79001 |
On Sun, 12 Oct 2014 07:24:52 -0700 (PDT), martijnperdaan@gmail.com
declaimed the following:
>what is wrong with this script and how do I get the value Rij1 and Rij2 and Rij3 and Rij4 and Rij5 and Rij6 in a php script
>
Well, I don't see anything that looks like PHP here...
>import RPi.GPIO as GPIO
Presume this means running on a Raspberry PI... There is a newsgroup
just for them; comp.sys.raspberry-pi
>GPIO.setmode(GPIO.BCM)
>
>GPIO.setup(17, GPIO.IN)
>GPIO.setup(18, GPIO.IN)
>GPIO.setup(21, GPIO.IN)
>GPIO.setup(22, GPIO.IN)
>GPIO.setup(23, GPIO.IN)
>GPIO.setup(24, GPIO.IN)
>
>Rij1 = 0
>Rij2 = 0
>Rij3 = 0
>Rij4 = 0
>Rij5 = 0
>Rij6 = 0
>
>
>while True:
> PRij1 = GPIO.input(17)
> PRij2 = GPIO.input(18)
> PRij3 = GPIO.input(21)
> PRij4 = GPIO.input(22)
> PRij5 = GPIO.input(23)
> PRij6 = GPIO.input(24)
>
> if (PRij1 == False):
Over kill or erroneous depending upon what GPIO.input() actually
returns...
if not PRij1:
is sufficient, since Python treats 0, 0.0, False, [], {}, and None as
"FALSE"
> Rij1 = Rij1 + 1
> while PRij1 == False:
> PRij1 = GPIO.input(17)
This loop is going to block the program from doing ANYTHING until that
input changes to true.
>
> if (PRij2 == False):
> Rij2 = Rij2 + 1
> while PRij2 == False:
> PRij2 = GPIO.input(18)
>
Same for this... And all the rest... You are incrementing a counter
that apparently says the input was low, and then waiting for the input to
go high, regardless of any other inputs.
>
> Totaal = Rij1 + Rij2 + Rij3 + Rij4 + Rij5 + Rij6
You will only get here once ALL inputs have gone True. Totaal will then
contain the count of inputs that were not high when you first read the pins
(for the first cycle of the main loop). Subsequent passes of the main loop
will continue to increment the Rijx for those pins that were low at the top
of the loop.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Peter Pearson <pkpearson@nowhere.invalid> |
|---|---|
| Date | 2014-10-12 17:01 +0000 |
| Message-ID | <c9vqfhF7vuqU1@mid.individual.net> |
| In reply to | #79001 |
On Sun, 12 Oct 2014 07:24:52 -0700 (PDT), martijnperdaan@gmail.com wrote: > what is wrong with this script and how do I get the value Rij1 and > Rij2 and Rij3 and Rij4 and Rij5 and Rij6 in a php script > > import RPi.GPIO as GPIO > GPIO.setmode(GPIO.BCM) > > GPIO.setup(17, GPIO.IN) > GPIO.setup(18, GPIO.IN) > GPIO.setup(21, GPIO.IN) > GPIO.setup(22, GPIO.IN) > GPIO.setup(23, GPIO.IN) > GPIO.setup(24, GPIO.IN) > > Rij1 = 0 > Rij2 = 0 > Rij3 = 0 > Rij4 = 0 > Rij5 = 0 > Rij6 = 0 > > > while True: > PRij1 = GPIO.input(17) > PRij2 = GPIO.input(18) > PRij3 = GPIO.input(21) > PRij4 = GPIO.input(22) > PRij5 = GPIO.input(23) > PRij6 = GPIO.input(24) > > if (PRij1 == False): > Rij1 = Rij1 + 1 > while PRij1 == False: > PRij1 = GPIO.input(17) [snip] I regret that I can't solve your problem, but perhaps I can move the conversation in a useful direction. If this is a question about RPi.GPIO, it would be good to phrase it as the simplest possible question about RPi.GPIO. If it's *not* a question about RPi.GPIO, it would be useful to replace the references to RPi.GPIO with some artificial substitute, so that people who don't have RPi.GPIO on their systems can contribute to the discussion. For example, I don't know what type of object is returned by GPIO.input. Your code appears to assume that it's True or False, but I don't know whether that's a valid assumption. When asking why something doesn't work, one greatly improves one's chances of getting a prompt and useful answer if one reveals precisely (1) what one desires, and (2) what one gets. Finally, the code you posted is indented in a way that is not legal Python, leaving people to guess at what you intended to post. And finally finally, why do you call this a PHP script? This is a Python newsgroup. -- To email me, substitute nowhere->runbox, invalid->com.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-10-12 18:36 +0000 |
| Message-ID | <m1ehmo$qr1$3@dont-email.me> |
| In reply to | #79001 |
On Sun, 12 Oct 2014 07:24:52 -0700, martijnperdaan wrote:
> what is wrong with this script and how do I get the value Rij1 and Rij2
> and Rij3 and Rij4 and Rij5 and Rij6 in a php script
I can see several pythonic errors in your script, however as for "what is
wrong", I see no indication from you of what you expect it to do, what
output you expect, what error messages you get when you try and run it
etc.
Perhaps a better subject would have been "how to read gpio on raspberry
pi"
It also helps if you can reduce your code example to the minimum needed
to demonstrate the error. In this case, I would suggest that once you can
read one input correctly, you should be able to expand that code to read
all inputs.
The code below might help (uses 2.x style print):
import RPi.GPIO as GPIO
GPIO.setmode(mode)
GPIO.setup(17, GPIO.IN)
if GPIO.input(17) == GPIO.HIGH:
print True
else:
print False
--
Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web