Power & Source of Big Ideas

python Pin control for all io pins

Moderators: chensy, FATechsupport

I've just got my NEO AIR and I'm trying to access io. I'm trying to use RPI.GPIO_NP https://github.com/auto3000/RPi.GPIO_NP. But I can't interface with many of my pins. When I deep dive into WiringNP, only some of the I/O are addressed, others just have -1 on them. I can't figure out when they're functional, and when not. I bought the AIR expecting to use all pins.
look at the source here https://github.com/friendlyarm/WiringNP/blob/master/wiringPi/wiringPi.c#L508. When I run

Code: Select all

gpio readall
on my NEO AIR and look at the characteristics of the headers, consider the usb/audio header (pic attached). all except 1 of the pins on this header have no mode, and do not work. So when I run the demo "led.py" assigned to pin 32, which should be an i2c pin, one that I need for my project, python spits a value error that the channel is invalid for RPi. Fine. Then when I run assigned to phys pin 31, i same thing. This made me think it is an "off" problem. But when I run the script assigned to physical pin 16, also an 'off' pin, it works. This doesn't make sense. What am i doing wrong? I need help getting IO access to all of the pins, even ones that are not RPi standard ones.

Thanks,
Darren

Attachments

I'm still having trouble. I need to be able to use these pins: [3, 5, 11, 13, 15, 19, 21, 23, 22, 37, 38] when read under the "physical" numbering of the NEO Air.
Some of them work, but others are in alternative modes. For instance, pin 15, ostensibly in "OUT" mode, does not work.
How can i control whether pins are used in I/O, or some other mode like UART or I2C? I'm starting to get worried. Please help.
Thanks,
Darren



Here is my python script:

Code: Select all

import RPi.GPIO as GPIO
import argparse
import time


def blink(i,t=.1):
    GPIO.output(i, GPIO.HIGH) # Set HIGH
    time.sleep(t)             #Pause
    GPIO.output(i, GPIO.LOW)  # Set LOW
    time.sleep(t)             #Wait

if __name__ == '__main__':

    # parse command line
    parser = argparse.ArgumentParser(description='''
        This script takes a pin number and number of blinks''')
     
    parser.add_argument('-s','--scale', action="store_true", default=False,
                            help='''play a scale of IO pins in sequence''') 
    parser.add_argument('-p','--pin', action="store", type=int, default=5,
                            help='''pick the GPIO pin number for controlling''') 
    parser.add_argument('-b','--blink', action="store", type=int, default=5,
                          help='''how many times to blink''')                         
    args = parser.parse_args()
     
    # SETUP
    GPIO.setmode(GPIO.BOARD)

    # Routine
    if args.scale:
        # run a scale on all of the important IO
        pins = [3, 5, 11, 13, 15, 19, 21, 23, 22, 37, 38]

        GPIO.setup(pins, GPIO.OUT)
        for j in pins:
            print("blink %d" % j)
            blink(j)
       

    else:
        ## pick the blink params
        if args.pin:
            pin_num = args.pin     
        if args.blink:
            num_blink = args.blink
       
        print("pin %d in mode %d" % (pin_num, GPIO.gpio_function(pin_num)))
        GPIO.setup(pin_num, GPIO.OUT)
        print("pin %d in mode %d" % (pin_num, GPIO.gpio_function(pin_num)))
       
        ## run blink loop
        for i in range(0,num_blink):            #loop n times
            print("blink %d of %d times" % (i, num_blink))
            blink(i,1)

        print("terminate in state: %d" % GPIO.LOW) 
        GPIO.output(pin_num, GPIO.LOW)

    GPIO.cleanup()
   

Attachments

I'm all confused. I'm a fairly new linux user, so maybe i'm missing something obvious, but I usually can follow online walk-through posts to solve environment setup type problems.
Anyways, after not getting anywhere with different libs i've found on github, I figure I need to go back to basics and get some CLI control working. In that effort I read different tutorials online which lead me to trying to use libgpiod. But i have trouble installing it. I end up needing the header file gpio.h. see https://forum.armbian.com/topic/6244-how-to-compile-libgpiod/ for discussion. But now i've started to realize i'm not running armbian, i'm running debian. i'm attaching an image of various commands to learn about my distro/kernel/os. Basically I need to figure out how to get the gpio.h for my NEO air. This would be a complete mapping of the 40 or so available pins.
And in that line of thinking, maybe I need help modifying the WiringNP repo https://github.com/friendlyarm/WiringNP. Like, somehow if I could expand the accessible pins in the headers of this repo I could get access to all the pins.

Can someone help?

Attachments

Or maybe I just need hardware level control of which pins can be accessed and controlled by RPi.GPIO_NP
Forum,

I ended up semi-bricking my Air trying to get some more controls. It gets stuck in the "starting kernel" state of uboot. I don't know what to do (help appreciated). but at least I have a backup neo air.

So I started again with a second neo air and this time I can GPIO control all of the pins!!! My guess is that I had a bad soldering on some of the suspect pins.

Hopefully others can benefit from my lesson.

Attachments

Who is online

In total there are 3 users online :: 0 registered, 0 hidden and 3 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 3 guests