New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update add-on boards to use BOARD numbering, close #349 #860
Conversation
Hi, Thank you for this. How do I use this branch? |
Are you asking for the git commands to get this branch? e.g: Or are you seeking clarification about the different pin Pin Numbering schemes? e.g: |
Hi, Thanks, Martyn |
Sorry for the questions, |
There's quite good docs at https://gpiozero.readthedocs.io/en/stable/development.html#development-installation 😉 |
Thanks, EDIT: I may try and follow the instructions to see if it works this afternoon |
Hmm, I tried the first couple of things and then got this: $ git clone https://github.com/RPi-Distro/python-gpiozero.git |
That looks like your internet connection. I've made a release you can try:
|
Thank you, I have to go and teach a lesson now. Will try later. |
@bennuttall - thanks for the pointer (Virgin Media's internet safety feature was blocking git). Okay, I have followed the instructions and installed this branch in a virtual environment and it works perfectly! Thank you. Will this branch be merged into the master in the near future or should I install this branch on my system? Once again, @lurch and @ukBaz thanks for guiding me through the process. |
Good to know it works. @lurch is this what you had in mind? I'll try and check with Dave if he has a mo. Seems like a reasonable approach to take for all physical boards really. |
I can't quite remember, given that I originally opened that issue 4 years ago 😉 But yeah the change here looks reasonable.
Yeah IMHO if you're gonna be doing this it makes sense to do it for all add-on boards (for consistency). |
Well, that was a dull way to spend the last hour. Done! One thing that annoys me is that the way the input/output pins are made available with the new In [1]: from gpiozero import *
In [2]: pb = Pibrella()
In [3]: pb.inputs.a
Out[3]: 'BOARD21' But I guess they still work as intended: In [4]: btn = Button(pb.inputs.a, pull_up=False)
...: led = LED(pb.outputs.e) So it's only really if somebody prints them out that it could confuse people... bit of an edge case though! One question: what does |
gpiozero/boards.py
Outdated
@@ -592,7 +592,7 @@ def pulse(self, fade_in_time=1, fade_out_time=1, n=None, background=True): | |||
on_time, off_time, fade_in_time, fade_out_time, n, background) | |||
|
|||
def _blink_device( | |||
self, on_time, off_time, fade_in_time, fade_out_time, n, fps=25): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh jesus... find and replace 😱
Codecov Report
@@ Coverage Diff @@
## master #860 +/- ##
==========================================
- Coverage 79.58% 79.58% -0.01%
==========================================
Files 23 23
Lines 4517 4516 -1
Branches 656 656
==========================================
- Hits 3595 3594 -1
Misses 866 866
Partials 56 56
Continue to review full report at Codecov.
|
Hmmm, that's a shame - I kinda assumed that specifying a BOARD number when constructing an object would automatically convert it back into the internal GPIO numbers. But thinking about it, perhaps constructing e.g. a Oh... now having looked at the code in more detail 🔍 I see that it's because pb.inputs is just a namedtuple, and a GpioZero object hasn't been created yet. But I think if you printed out btn.pin in your example then you'd see the GPIO number?
Looking at https://github.com/gpiozero/gpiozero/blob/master/gpiozero/pins/data.py#L1272 and https://github.com/gpiozero/gpiozero/blob/master/gpiozero/pins/data.py#L320 I think that 'BOARD2' on a compute module would get converted to 'EMMC DISABLE N' and then "raise PinInvalidPin('%s is not a valid pin spec' % spec)"
Probably not ;-) |
Eugh it seems silly to worry about compute module but if you think about a non-industrial hacker type playing around with one - what would they expect? Wire up e.g. en Energenie using the right BCM pins, they would expect it to work. Let's say we make it possible for that to work - some workaround that we document in the FAQs - what would that look like? My initial thought would be allowing an override to pins in the constructor: class SomeHat(LEDBoard):
def __init__(self, pins=None, pwm=False, pin_factory=None):
if pins is None:
pins = (2, 3, 4, 5)
elif len(pins) != 4:
raise GPIOPinErrorWhatever()
super().__init__(*pins, pwm=pwm, pin_factory=pin_factory) Instead of what this class would look like now: class SomeHat(LEDBoard):
def __init__(self, pwm=False, pin_factory=None):
pins = (2, 3, 4, 5)
super().__init__(*pins, pwm=pwm, pin_factory=pin_factory) An entirely different approach to all of this would be: instead of using BOARD numbers in classes, we call a function that converts physical pin numbers to BCM numbers for the original Pi, but leaves them alone for everything else, e.g: def pin(n):
# where n is the board number
rev = pi_info().revision
if rev == ORIGINAL_PI_REV:
return ORIGINAL_PI_PINS[n]
return n This is ridiculous 😆 |
Although perhaps if a |
It would be better all-round if pwm was keyword-only :) Good point re: BHH In a way, adding What do you think about the other approach? We could do both 😆 |
I think I once remember seeing @waveform80 say that Python3 allows keyword-only arguments (?), but that we couldn't use this yet because GpioZero supports py2 and py3. But if we're going to be dropping py2...
Given how complex this is getting, I think we ought to stick to just one way of doing this 😉
Do you mean checking that the required numbers of |
Yeah, it would be good to enforce keyword-only arguments (where appropriate) post- dropping Python 2.
I see this as two separate things:
I meant where the board is complex enough to have a nested "shape" (i.e.
|
Yeah, I meant that I don't think there's much value in investigating your "instead of using BOARD numbers in classes, we call a function that converts physical pin numbers to BCM numbers for the original Pi, but leaves them alone for everything else" suggestion - IMHO it feels far too special-case and error-prone. (And isn't "a function that converts physical pin numbers to BCM numbers" exactly what BOARD numbering does anyway? 😉 )
Ah, so you're asking whether a board with a "shaped"
(with the JamHat constructor than checking that But perhaps it's worth keeping this PR as just "specifying pins in board definitions so that they work on original pis too" and then creating a separate issue / PR for "allowing people to override pins for boards (for any reason)" ? Hmmmm2, perhaps we could allow a "special value" to be supplied to the P.S. Slightly off-topic question, but is there a reason why edit: fixed the dict syntax |
True. We could use the dict declaration ourselves, so instead of:
we do:
That way we pave the way for copy/paste/edit.
That makes sense :)
I don't know! I'd have to check the PR. Probably a mistake by overthinking it. I know what you're thinking, that sounds really out of character, but I guess sometimes these things happen. |
Nice! Except we'd obviously be using 'BOARD' numbers rather than GPIO numbers in the second line 😉 |
Hi, |
Not sure yet - think it needs a rethink. And we're in the middle of another project at the moment. |
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
-->No problem, thanks for the update. Sent from Mail for Windows 10 From: Ben NuttallSent: 24 June 2020 13:29To: gpiozero/gpiozeroCc: martynwheeler; MentionSubject: Re: [gpiozero/gpiozero] Update add-on boards to use BOARD numbering, close #349 [WIP] (#860) Not sure yet - think it needs a rethink. And we're in the middle of another project at the moment.—You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub, or unsubscribe.
|
gpiozero/boards.py
Outdated
super(PiLiterBarGraph, self).__init__( | ||
*pins, pwm=pwm, initial_value=initial_value, pin_factory=pin_factory | ||
'BOARD7', 'BOARD11', 'BOARD13', 'BOARD12', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These could just go in pins?
Okay, read through the thread: yes, this will break on compute modules (1, 3, and 3+). However, I'm not fussed. Given CM4 is now out and (due to the various needs of the high-speed interfaces) has reverted to a basically "classic" GPIO layout (at least on the dev board), and that CM1/3/3+ users will be a tiny niche of gpiozero users, I'm fine with merging this as is. Any objections @bennuttall ? |
d889897
to
8870e46
Compare
As suggested by @lurch in #349, this branch updates add-on boards to use BOARD numbering so that the right BCM numbers are elected regardless of Pi model.