Raspberry Pi3 pin control

Discussions related to network, internet and socket programming; also to serial, parallel, Bluetooth, USB etc.
mikeg
Posts: 101
Joined: Sat 23 Jun 2018, 19:52

Raspberry Pi3 pin control

Post by mikeg »

I have created this program to diagnose the function of all the commands in the GIPO library
The end game of this program is to be able to set my pin to HIGH so it can run my relay, which requires a HIGH pin and well, be able to set my pin to low when shutting off the relay.
( Richard could you help please?)

to operate the relay ( for solar/ battery powered glow plug water heating timer project)

The relay is a 5 volt relay, but the 5 volt is a supply off your Rpi3 5 volt and ground and the relay has a COM connection that gets the signal from your pin for on/off control.

I want to make a few videos showing BBC Basic running my hardware for 93 people in the Programming tools group.

( I had to edit this post to explain what I was trying to ask)
* I was hoping Richard that you might be able to explain how I can get my pin to HIGH state to run my relay and LOW state to disable the relay.

And thank you Richard for your time.

Code: Select all

INSTALL @lib$+"gpiolib.bbc"
LET active%=FN_gpio_setup
REM Lets give a pin a purpose
REM Lets tell PIN GIPO 5 that it is a output
REM I am not sure why the library says to use PROC_gio_inp() first. Maybe initialization?
LET pv%=FN_gpio_get(5,6)
PRINT "The current state of pin 5 is : "pv%
PROC_gpio_clr(5,0):REM clear pin 5?
PROC_gpio_inp(5,6)
PROC_gpio_out(5,6) :REM one way or another we are safe, as 5 and 6 are free to use
REM now lets find out what the value of pin 5
LET pv%=FN_gpio_get(5,6)
PRINT "The current state of pin 5 is : "pv%
REM next statement (pin,state) state- 0 neutral,2 pull up, 1 down
PROC_gpio_pull(5,1):REM this should make pin 5 down (active?)
REM now lets see the value of pin 5
LET pv%=FN_gpio_get(5,6)
PRINT "The current state of pin 5 is : "pv%
REM hmm still 0. Lets try set
PROC_gpio_set(5,31) :REM hi?
REM now does it have a value?
LET pv%=FN_gpio_get(5,0)
PRINT "The current state of pin 5 is : "pv%


END
Focus is on code subject. Feel free to judge the quality of my work.

RichardRussell

Re: Raspberry Pi3 pin control

Post by RichardRussell »

mikeg wrote:
Sun 23 Feb 2020, 03:27
I have created this program to diagnose the function of all the commands in the GIPO library
I'm afraid the code you posted makes little sense, I don't think you've grasped how the library works (for example that the value returned from FN_gpio_setup must be passed as the first parameter to all the other functions). I would suggest that you start from known, working, code such as my 'cycling LEDs' demo that I published some time ago at the Raspberry Pi and Stardot forums:

Image

Code: Select all

      REM Initialise GPIO:
      INSTALL @lib$ + "gpiolib"
      GPIO% = FN_gpio_setup

      REM Pin numbers to activate, in sequence:
      DATA 17, 23, 25, 12, 16, 26

      REM Set to input first:
      RESTORE
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_inp(GPIO%, pin%)
      NEXT

      REM Set pins to output:
      RESTORE
      FOR I% = 1 TO 6
        READ pin%
        PROC_gpio_out(GPIO%, pin%)
      NEXT

      REM Cycle LEDs in sequence:
      REPEAT
        RESTORE
        FOR I% = 1 TO 6
          READ pin%
          PROC_gpio_set(GPIO%, 1 << pin%)
          WAIT 20
          PROC_gpio_clr(GPIO%, 1 << pin%)
        NEXT
      UNTIL FALSE
      END