element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog Using the IO on a Raspberry Pi 3 B+
  • Blog
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Raspberry Pi Projects requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: jc2048
  • Date Created: 16 Mar 2019 11:43 PM Date Created
  • Views 924 views
  • Likes 7 likes
  • Comments 8 comments
  • raspberry pi 3 b+
  • raspberry_pi_projects
Related
Recommended

Using the IO on a Raspberry Pi 3 B+

jc2048
jc2048
16 Mar 2019

In my quest to use a Raspberry Pi 3B+ for creating art, I need to be able to control the GPIO pins. So next step

was to look for some information on doing just that.

 

A quick search of element14 uncovered this blog by shabaz where he illustrates controlling the GPIO lines with

Python. That should get me off to a quick start and Python should be ok to work with, at least for the simpler

art pieces [I haven't done very much with Python and, to be honest, I didn't entirely like it when I did, but it

will do for the moment].

 

Raspberry Pi GPIO Explained

 

To enter the script I'm going to need a text editor that I can run without the desktop. It seems that GNU Nano

is part of the distribution, so I'll start with that. For it to work with PuTTY, I found that local editing

needed to be turned off.

 

Here's the Python code I'm using, as seen in the Nano editor's text-terminal-style 'window', framed in PuTTY's

Windows GUI-style window. The code is one of Shabaz's examples.

 

 

If I give it to the Python interpreter to run and look at the IO pin, it does this on the 'scope

 

 

Success!

 

So, I now have the means to control I/O lines under the control of a Python script and that probably gives me

enough to get me going and produce the first simple piece of art (which I've got to come up with by the end of next

week to stay on schedule). Next blog will be the first proper challenge one and will be in the Picasso Challenge

area.

Anonymous

Top Comments

  • fmilburn
    fmilburn over 3 years ago +4

    Hi Jon,

     

    I have been using Geany as the IDE for Python on the Raspberry Pi.  It has the advantage of highlighting key words, start the code running with a button click, etc.  I have been using it long enough…

  • shabaz
    shabaz over 3 years ago +4

    Hi Jon,

     

    That's awesome, glad the blog was helpful!

    In recent times, another Python API has become available, called "gpiozero".

    The one in that blog still works, but just in case you want to…

  • beacon_dave
    beacon_dave over 3 years ago in reply to jc2048 +4

    "GPIO Zero is installed by default in the Raspbian image, and the Raspberry Pi Desktop image for PC/Mac, both available from raspberrypi.org. Follow these guides to installing on Raspbian Lite and…

Parents
  • shabaz
    shabaz over 3 years ago

    Hi Jon,

     

    That's awesome, glad the blog was helpful!

    In recent times, another Python API has become available, called "gpiozero".

    The one in that blog still works, but just in case you want to examine that other API too, there is some info here:

    https://gpiozero.readthedocs.io/en/stable/migrating_from_rpigpio.html

    The original RPi.GPIO API is similar to how it would be done with any generic microcontroller, i.e. set a port pin to input or output mode, and then read or write it, and let the user code directly call this API and leave the user to optionally write any class to control a pin if desired, whereas gpiozero has ready-made classes for input/output devices, and creating an instance will set the port pin to input or output as part of that ready-made class code, without the user code needing to do that.

    The gpiozero API was not available when that blog was written. I reckon some may still find the original API easier to understand but for others more familiar with classes and objects the gpiozero is probably cleaner. I've been in two minds to update that blog post, since it currently works and isn't broken.

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
  • jc2048
    jc2048 over 3 years ago in reply to shabaz

    That's awesome, glad the blog was helpful!

    It was very useful - much quicker than trying to find all the info myself and sort it all out.

     

    In recent times, another Python API has become available, called "gpiozero".

    I saw the gpiozero stuff on the Raspberry Pi website but got the impression that it wasn't available in the Lite version of Rasbian (I might not have interpreted that correctly), so I thought I'd try your code and just see what happened. I'm much happier with it like this - I've done a lot more assembler programming in my time than anything high level, so this level of control feels quite natural (that's the reason I'm uncomfortable, generally, with a language like Python).

    • Cancel
    • Up +2 Down
    • Reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 3 years ago in reply to jc2048

    "GPIO Zero is installed by default in the Raspbian image, and the Raspberry Pi Desktop image for PC/Mac, both available from raspberrypi.org. Follow these guides to installing on Raspbian Lite and other operating systems, including for PCs using the remote GPIO feature."

    https://gpiozero.readthedocs.io/en/stable/installing.html

     

    There is a MagPi Essentials eBook on using GPIO Zero here:

    https://www.raspberrypi.org/magpi-issues/Essentials_GPIOZero_v1.pdf

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
Comment
  • beacon_dave
    beacon_dave over 3 years ago in reply to jc2048

    "GPIO Zero is installed by default in the Raspbian image, and the Raspberry Pi Desktop image for PC/Mac, both available from raspberrypi.org. Follow these guides to installing on Raspbian Lite and other operating systems, including for PCs using the remote GPIO feature."

    https://gpiozero.readthedocs.io/en/stable/installing.html

     

    There is a MagPi Essentials eBook on using GPIO Zero here:

    https://www.raspberrypi.org/magpi-issues/Essentials_GPIOZero_v1.pdf

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
Children
No Data
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube