Menu

rpi gpio freebasic

2018-01-15
2018-01-17
  • stan cartwright

    stan cartwright - 2018-01-15

    My raspberry has lots of gpio but I can't program in python or c. I got pwm on a led to work in python but max was hundreds Hz as interpreted.
    As I like basic I got to make a freebasic for rpi2/3 and it works and want to use gpio so need to use pigpio or wiringpi c with freebasic.
    The idea is to connect with gcb pic/avr ..that's my excuse for posting here.
    Has anyone used freebasic with a raspberry pi for gpio?
    Has anyone used fuze, which has gpio built in it seems?
    I hope this isn't out of place posting, gcb being from freebasic.

     
  • David Stephenson

    I've downloaded FuzeBasic (it was a pain to get installed - as everything in Linux seems to be).
    I have been meaning to get round to using it, but have yet to find a suitable project for my Pi.

     
  • stan cartwright

    stan cartwright - 2018-01-15

    Hi David. I don't like linux as it's all terminal dos/cmd style text and exact with white spaces to do stuff. The fancy gui can't do much.
    I thought using fb, which is compiled, gpio would run faster than python but searching seems gpio includes are slow, that's if they work.
    I have a 32 bit arm arduino but can't do c so waste of time.
    Using fb on rpi is easier for me than python. I never used qbasic so screen and the windows in rpi pixel are new but least I get results. I use geany but fbide would be better. Can geany link the file to fb and compile like gcb syn?
    If this is off topic tell me to..

     
  • Moto Geek

    Moto Geek - 2018-01-16

    Stan, you can have a look at MMBasic running on raspberry Pi. Should let you use GPIO and lots of other stuff. I believe it works on the PiZero also... I am personally not familiar with PIs so give a look here...

    https://www.thebackshed.com/forum/search.asp?KW=picromite&SM=1&SI=PT&FM=16&OB=1&Submit=Start+Search

     
  • stan cartwright

    stan cartwright - 2018-01-16

    Cheers. FB is compiled. I don't know if other basics are.
    I got this to work on but dunno if I'll get anywhere. rpi is complicated.
    Close this topic as inappropriete.

    ''
    ''
    '' wiringPi -- header translated with help of SWIG FB wrapper
    ''
    '' NOTICE: This file is part of the FreeBASIC Compiler package and can't
    ''         be included in other distributions without authorization.
    ''
    ''
    #ifndef __wiringPi_bi__
    #define __wiringPi_bi__
    
    #define NUM_PINS 17
    #define WPI_MODE_PINS 0
    #define WPI_MODE_GPIO 1
    #define WPI_MODE_GPIO_SYS 2
    #define WPI_MODE_PHYS 3
    #define WPI_MODE_PIFACE 4
    #define WPI_MODE_UNINITIALISED -1
    #define MODE_INPUT 0
    #define MODE_OUTPUT 1
    #define PWM_OUTPUT 2
    #define GPIO_CLOCK 3
    #define LOW 0
    #define HIGH 1
    #define PUD_OFF 0
    #define PUD_DOWN 1
    #define PUD_UP 2
    #define PWM_MODE_MS 0
    #define PWM_MODE_BAL 1
    #define INT_EDGE_SETUP 0
    #define INT_EDGE_FALLING 1
    #define INT_EDGE_RISING 2
    #define INT_EDGE_BOTH 3
    
    type wiringPiNodeStruct
        pinBase as integer
        pinMax as integer
        fd as integer
        data0 as uinteger
        data1 as uinteger
        data2 as uinteger
        data3 as uinteger
        pinMode as sub cdecl(byval as wiringPiNodeStruct ptr, byval as integer, byval as integer)
        pullUpDnControl as sub cdecl(byval as wiringPiNodeStruct ptr, byval as integer, byval as integer)
        digitalRead as function cdecl(byval as wiringPiNodeStruct ptr, byval as integer) as integer
        digitalWrite as sub cdecl(byval as wiringPiNodeStruct ptr, byval as integer, byval as integer)
        pwmWrite as sub cdecl(byval as wiringPiNodeStruct ptr, byval as integer, byval as integer)
        analogRead as function cdecl(byval as wiringPiNodeStruct ptr, byval as integer) as integer
        analogWrite as sub cdecl(byval as wiringPiNodeStruct ptr, byval as integer, byval as integer)
        next as wiringPiNodeStruct ptr
    end type
    extern wiringPiNodes alias "wiringPiNodes" as wiringPiNodeStruct ptr
    
    declare function wiringPiFailure cdecl alias "wiringPiFailure" (byval fatal as integer, byval message as zstring ptr, ...) as integer
    declare function wiringPiFindNode cdecl alias "wiringPiFindNode" (byval pin as integer) as wiringPiNodeStruct ptr
    declare function wiringPiNewNode cdecl alias "wiringPiNewNode" (byval pinBase as integer, byval numPins as integer) as wiringPiNodeStruct ptr
    declare function wiringPiSetup cdecl alias "wiringPiSetup" () as integer
    declare function wiringPiSetupSys cdecl alias "wiringPiSetupSys" () as integer
    declare function wiringPiSetupGpio cdecl alias "wiringPiSetupGpio" () as integer
    declare function wiringPiSetupPhys cdecl alias "wiringPiSetupPhys" () as integer
    declare sub pinModeAlt cdecl alias "pinModeAlt" (byval pin as integer, byval mode as integer)
    declare sub pinMode cdecl alias "pinMode" (byval pin as integer, byval mode as integer)
    declare sub pullUpDnControl cdecl alias "pullUpDnControl" (byval pin as integer, byval pud as integer)
    declare function digitalRead cdecl alias "digitalRead" (byval pin as integer) as integer
    declare sub digitalWrite cdecl alias "digitalWrite" (byval pin as integer, byval value as integer)
    declare sub pwmWrite cdecl alias "pwmWrite" (byval pin as integer, byval value as integer)
    declare function analogRead cdecl alias "analogRead" (byval pin as integer) as integer
    declare sub analogWrite cdecl alias "analogWrite" (byval pin as integer, byval value as integer)
    declare function wiringPiSetupPiFace cdecl alias "wiringPiSetupPiFace" () as integer
    declare function wiringPiSetupPiFaceForGpioProg cdecl alias "wiringPiSetupPiFaceForGpioProg" () as integer
    declare function piBoardRev cdecl alias "piBoardRev" () as integer
    declare function wpiPinToGpio cdecl alias "wpiPinToGpio" (byval wpiPin as integer) as integer
    declare function physPinToGpio cdecl alias "physPinToGpio" (byval physPin as integer) as integer
    declare sub setPadDrive cdecl alias "setPadDrive" (byval group as integer, byval value as integer)
    declare function getAlt cdecl alias "getAlt" (byval pin as integer) as integer
    declare sub digitalWriteByte cdecl alias "digitalWriteByte" (byval value as integer)
    declare sub pwmSetMode cdecl alias "pwmSetMode" (byval mode as integer)
    declare sub pwmSetRange cdecl alias "pwmSetRange" (byval range as uinteger)
    declare sub pwmSetClock cdecl alias "pwmSetClock" (byval divisor as integer)
    declare sub gpioClockSet cdecl alias "gpioClockSet" (byval pin as integer, byval freq as integer)
    declare function waitForInterrupt cdecl alias "waitForInterrupt" (byval pin as integer, byval mS as integer) as integer
    declare function wiringPiISR cdecl alias "wiringPiISR" (byval pin as integer, byval mode as integer, byval function as sub cdecl()) as integer
    declare function piThreadCreate cdecl alias "piThreadCreate" (byval fn as sub cdecl(byval as any ptr)) as integer
    declare sub piLock cdecl alias "piLock" (byval key as integer)
    declare sub piUnlock cdecl alias "piUnlock" (byval key as integer)
    declare function piHiPri cdecl alias "piHiPri" (byval pri as integer) as integer
    declare sub delay cdecl alias "delay" (byval howLong as uinteger)
    declare sub delayMicroseconds cdecl alias "delayMicroseconds" (byval howLong as uinteger)
    declare function millis cdecl alias "millis" () as uinteger
    declare function micros cdecl alias "micros" () as uinteger
    
    #
    
     
  • David Stephenson

    I'm impressed I gave up on freebasic many years ago as it seemed to have left it's BASIC roots and made a language all of its own.
    I started up my Pi for the first time in about a year and I was expecting lots of updates, but there were none. Seem like Debian has abandoned older Pi's (mine is a B+) comparison with windows?
    It is rumored that QB64 will run on newer Pi's, the program has some bloat due to a BASIC to C conversion before assembly.

     
  • stan cartwright

    stan cartwright - 2018-01-16

    I've yet to try this but looks simple/familiar.

    #include "wiringPi.bi"
    
    DECLARE SUB PriLoop()
    
    DIM SHARED Steps(0 TO 7) AS INTEGER => {&H09, &H08 ,&H0C, &H04, &H60, &H02, &H03, &H01}
    
    PRINT "STEPPER SPEED CONTROL, ONE DIRECTION."
    
    wiringPiSetup()
    
    'Setup the four pins as outputs.
    pinMode(22,MODE_OUTPUT)
    pinMode(23,MODE_OUTPUT)
    pinMode(24,MODE_OUTPUT)
    pinMode(25,MODE_OUTPUT)
    
    PRINT " +  Increases Speed"
    PRINT " -  Decreases Speed"
    PRINT " q  Quits"
    
    PriLoop()
    
    'Dissable Stepper before we leave.
    digitalWrite(22,LOW)
    digitalWrite(23,LOW)
    digitalWrite(24,LOW)
    digitalWrite(25,LOW)
    
    SYSTEM
    
    SUB PriLoop()
      DIM dly AS INTEGER
      DIM cnt AS INTEGER
      DIM key AS STRING * 1
    
      'Some initialization.
      key = UCASE(INKEY)
      dly = 5
      cnt = 0
    
      WHILE (key <> "Q")                              'Loop until the user presses Q.
        'Move to the next half step, using the values in Steps().
        digitalWrite(22,Steps(cnt) AND 1)
        digitalWrite(23,(Steps(cnt) SHR 1) AND 1)
        digitalWrite(23,(Steps(cnt) SHR 2) AND 1)
        digitalWrite(23,(Steps(cnt) SHR 3) AND 1)
        delay(dly)
    
        'Check for press of + or - and change the value of dly accordingly, also echo status.
        IF key = "+" THEN
          dly = dly - 1
          PRINT "Current Delay is: "; dly
        ELSEIF key = "-" THEN
          dly = dly + 1
          PRINT "Current Delay is: "; dly
        END IF
    
        'We need to stay slow enough for the stepper.
        IF dly <= 2 THEN
          dly = 2
        END IF
    
        'Get next keypress if any, and increse count.
        key = UCASE(INKEY)
        cnt = (cnt + 1) AND 7
      WEND
    END SUB
    
     
  • stan cartwright

    stan cartwright - 2018-01-17

    It's more better to use gcb and a uno rather than a rpi for messing with ports.
    FB on a rpi is like gcb on uno/nano with no c for me... ie I know a bit of basic but c, no.
    My idea of rpi project is continuous looping video of a log fire on a s/h £5 charity shop monitor in a matt black wood box that looks like a cast iron burner. The hdmi is 1080 and streams fine from usb stick.
    I got it working on some old vga lead monitors via hdmi to vga adaptor..except for the fake wood burner to put it in.

     

Log in to post a comment.