Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - Printable Version +- PINE64 (https://forum.pine64.org) +-- Forum: PINE A64(+) (https://forum.pine64.org/forumdisplay.php?fid=4) +--- Forum: Pine A64 Hardware, Accessories and POT (https://forum.pine64.org/forumdisplay.php?fid=32) +---- Forum: Pi2, Euler and Exp GPIO Ports (https://forum.pine64.org/forumdisplay.php?fid=34) +---- Thread: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus (/showthread.php?tid=1760) |
Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - MarkHaysHarris777 - 07-15-2016 I have reworked my LED lab specifically for the PineA64 board demo codes (uploaded here) which highlight the RPi.GPIO-PineA64 module from github; as well the Sparkfun T cobbler breakout board and 40pin ribbon cable. The LED layout is changed to a row of blue 5mm diodes in a single line; the GPIO pins are GP20 - GP27 (BCM Broadcom numbering) on the PI bus. Three files have been uploaded here for convenience sake; I may put them on github later. They are the following: display8bit.py the main python3 import file using RPi.GPIO-PineA64 dsp_patterns3.sh the main python3 driver GPIO patterns demo script ssendsig.sh the signal generator for controlling dsp_patterns3.sh The display8bit.py file may be imported in the Python3 REPL for manual use. The script dsp_patterns3.sh uses display8bit.py (imports it) and is intended to be run in the background. The script is controlled by the ssendsig.sh script which generates either -SIGHUP, -SIGUSR1, -SIGUSR2, or -SIGINT for controlling the frequency|speed, forward pattern, reverse pattern, or keyboard interrupt respectively. They will be explained in more detain below. Manual Operation of RPi.GPIO-PineA64 (Python3 REPL) The ssendsig.sh script should be located in your path, maybe your ~/bin directory; as long as its in the $PATH. The other two scripts are located in your ~/Python3/ directory; cd into the ~/Python3/ directory. To start the REPL for GPIO use enter: sudo python3 >>> from display8bit import * The display8bit.py file divides the eight (8) LEDs into two groups ( high_pins, and low_pins ) or high-order and low-order binary digits; each 4 bits in length. They may be addressed four or eight at a time. Any of the defined commands in display8bit may be used directly in the REPL main namespace. Several examples are listed below: >>> all_on() >>> all_off() >>> led_on(high_pins[n]) n is binary digit 0-3 >>> led_off(high_pins[n]) n is binary digit 0-3 >>> led_on(low_pins[n]) n is binary digit 0-3 >>> led_off(low_pins[n]) n is binary digit 0-3 >>> bin_display() not intended to be called directly >>> dsp8_INV(0xNN) NN 8 bit hex value low-order high-order >>> dsp8_STD(0xNN) NN 8 bit hex value high-order low-order >>> walking(1, .7, "STD") digits walk right to left >>> walking(1, .7, "INV") digits walk left to right >>> counter_4bit(0x11,low_pins,.7,"STD") >>> counter_4bit(0x11,low_pins,.7,"INV") >>> counter_4bit(0x11,high_pins,.7,"STD") >>> counter_4bit(0x11,high_pins,.7,"INV") >>> counter_8bit(0x101,.250,"STD") >>> counter_8bit(0x101,.250,"INV") >>> end() this command exits the REPL, and cleans up the GPIO Scripted Operation of RPi.GPIO-PineA64 (dsp_patterns3.sh) To start the dsp_patterns3.sh script in the background enter: sudo -b ./dsp_patterns3.sh The main driver script dsp_patterns3.sh imports display8bit.py and uses it to display twelve (12) light patterns on the LED lab breadboard. The patterns are selected by sending the script (running in the background) one of four signals. Signal handlers then modify the operation of the script on the fly. USR1: selects on the forward patterns from an indexed list (see code) USR2: selects on the reverse patterns from an indexed list (see code) HUP: changes the speed of the display INT: similar to ctrl-c on the keyboard... stops the background process The signals may be sent via htop, or the kill command, or from the supplied ssendsig.sh script; examples follow: sudo ~/bin/ssendsig.sh dsp_pattern INT sudo ~/bin/ssendsig.sh dsp_pattern HUP sudo ~/bin/ssendsig.sh dsp_pattern USR1 sudo ~/bin/ssendsig.sh dsp_pattern USR2 The script finds the process number from the process name (dsp_pattern) and then issues the appropriate kill command. The purpose of the demo codes display8bit.py is to highlight the RPi.GPIO-PineA64 module(s) and to document how to use the GPIO of input | output. At this time the module can not be used for i2c, SPI, nor pwm. The purpose of the demo codes dsp_patterns3.sh is to highlight a proper way of coding a Python3 script for accessing the GPIO with a 'try block'; also a way to control a background script with the use of signals and signal handlers. While I hope that these codes will be useful, I do not guarantee that they will be suitable for any purpose what-so-ever; nor do I accept responsibility for their use or subsequent success or failure/ the user herself|himself must bear the responsibility for the use of these codes. If you have questions about these codes, post your comments here, or even better join us on the irc.pine64.xyz:6697 chat for a friendly discussion. You may also PM me, or send me a private message on this forum. marcus edit: PS please notify me asap should you find errors; I will correct them immediately; and thank you ! #***************************************************************** # author: Mark H. Harris # license: GPLv3 # # THIS SOFTWARE IS PROVIDED BY THE COPYLEFT HOLDERS AND # CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MECHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYleft HOLDER OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENCIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # #***************************************************************** Code: ssendsig.sh Code: display8bit.py Code: dsp_patterns3.sh RE: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - MarkHaysHarris777 - 03-24-2017 The above pic is an updated photo of the LED lab ; the white 4bit bus is coming from the euler bus, the blue 8bit bus is coming from the PI bus in a two row configuration. Each pair of blue LED(s) has a common cathode; the resistors drive the anodes across the bread board divide where they meet up with the 8bit bus from the PI-bus. The LED(s) patterns have a different visual effect arranged in two rows of four, rather than a single row of eight(8). RE: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - tllim - 03-30-2017 (03-24-2017, 04:32 PM)MarkHaysHarris777 Wrote: The above pic is an updated photo of the LED lab ; the white 4bit bus is coming from the euler bus, the blue 8bit bus is coming from the PI bus in a two row configuration. Appreciate and thanks on the tutorial RE: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - TeaPack - 09-25-2017 Hi Marcushh =) Do you know, if RPi.GPIO is also working with EulerBus? I was trying to use PB3 and PB8 pins, but their # (35, 40) is not working for me... pin #23 on RPi bus is working correctly... Which version of RPi.GPIO are u using? there are several of them on GitHub, even fork with totally destroyed RPi.GPIO renamed to "brand new" Pine.GPIO :-\ RE: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - MarkHaysHarris777 - 09-26-2017 (09-25-2017, 04:29 PM)TeaPack Wrote: Hi Marcushh =) hi TeaPack, the euler bus gpio(s) do work ; I use them with sysfs, and with C ; but the RPi.GPIO-Pine64 package is designed to mimic the python codes of the RPi3 on the PI-bus; it won't work (out-of-box) because you have to specify either BOARD , or BCM , numbering scheme which does not cover the euler bus. There could of course be a modification ( like EULER ) to provide a numbering scheme that would work; you might make that suggestion on the github site for RPi.GPIO-Pine64. RE: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - MikeA23 - 06-03-2019 Is there a library to use the RPi GPIO in C or C++?? RE: Sample GPIO codes highlighting RPi.GPIO-PineA64 and the PI bus - tllim - 06-07-2019 (06-03-2019, 01:44 PM)MikeA23 Wrote: Is there a library to use the RPi GPIO in C or C++?? Hopefully this doc helps. http://synfare.com/599N105E/hwdocs/pine64/index.html |