User avatar
DavidS
Posts: 3009
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

WiringPi works with FreeBASIC.

Sat Mar 18, 2017 1:48 am

As if all goes to plan I will be going off line sometime tommorrow, I hope someone else finds this helpful.

Having already the option of using BBC BASIC for an interpreted language with GPIO, I decided to give FreeBASIC a try with WiringPi so I have a non-C compiled option, the trouble is that wiringPi.bi is not included.

I found where to download wiringPi.bi, it is here:
http://ops.deltalabs.de/code?id=310

And it works. For the most part everything is the same as in C, just look at the wiringPi.bi file to see what had to be renamed to prevent conflicts with FreeBASIC keywords (eg INPUT became MODE_INPUT). I hope people find this helpful :) .
ARM BASIC: For the love of Simplicity, Fast Interpreted BASIC, and Assembly Language.
Always KISS Keep It Simple Silly.

User avatar
DavidS
Posts: 3009
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
Contact: Website

Re: WiringPi works with FreeBASIC.

Sat Mar 18, 2017 3:12 am

Ok here is a quick example, it is a quick and dirty translation from my C version of a simple stepper speed control, that I use as part of a filament winder.

Code: Select all


#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

'┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
'│                                                   TERMS OF USE: MIT License                                                  │                                                            
'├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
'│Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation    │ 
'│files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,    │
'│modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
'│is furnished to do so, subject to the following conditions:                                                                   │
'│                                                                                                                              │
'│The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
'│                                                                                                                              │
'│THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE          │
'│WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR         │
'│COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,   │
'│ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                         │
'└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘


ARM BASIC: For the love of Simplicity, Fast Interpreted BASIC, and Assembly Language.
Always KISS Keep It Simple Silly.

ias
Posts: 1
Joined: Thu Sep 07, 2017 9:59 pm

Re: WiringPi works with FreeBASIC.

Thu Sep 07, 2017 10:05 pm

Hi,

I've downloaded the wiringPi.bi include from http://ops.deltalabs.de/code?id=310 and writed this minimal FreeBASIC test:

Code: Select all

#include "wiringPi.bi"

wiringPiSetup()
when I try to compile it, I got:

Code: Select all

test_gpio.o: In function `main':
test_gpio.c:(.text+0x2c): undefined reference to `wiringPiSetup'
suggestions on what I missed?

Return to “Other languages”

Who is online

Users browsing this forum: No registered users and 8 guests