is there a guide or example someone could show me please?
i cant seem to find anything relating to bbc basic on the pi
thanks!

I know you are asking principally about RISC OS, but for completeness the Raspberry Pi edition of BBC BASIC for SDL 2.0 (which runs under Raspbian, on a RPi 3 or 4) supports controlling the GPIO via the supplied library 'gpiolib.bbc'. Here is a demonstration of it in action, with the program listed below:
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
Richard Russell wrote: ↑Mon Dec 23, 2019 10:11 pmI know you are asking principally about RISC OS, but for completeness the Raspberry Pi edition of BBC BASIC for SDL 2.0 (which runs under Raspbian, on a RPi 3 or 4) supports controlling the GPIO via the supplied library 'gpiolib.bbc'. Here is a demonstration of it in action, with the program listed below:
rpigpio.gifCode: 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%, 2^pin%) WAIT 20 PROC_gpio_clr(GPIO%, 2^pin%) NEXT UNTIL FALSE END
I said the program was for BBC BASIC for SDL 2.0 running under Raspbian, so it was never going to work under RISC OS.
If it's a RPi 3 or 4 that should work fine. BBC BASIC for SDL 2.0 will run on a RPi 2 but it's too slow to be 'comfortable' (especially the IDE).
No, it's what is sometimes called a 'handle' or a 'pointer'; really you don't need to know what it actually is, you treat it as an 'opaque' value that you simply store in a variable and pass to the other functions as required. This is a very common technique.
I don't know why you have to set the pins to input first either, you just do. Sometimes it's better not to ask too many questions!set to input
set to output, why do you do this? i cant work that out either
As I explained above, GPIO% is just the value returned from FN_gpio_setup. If you know anything about code libraries you'll know that it's bad practice for them to use global variables. I won't bore you with the details, but one way of avoiding global variables can be for the 'calling' program to act as a go-between, and pass a value from one library function to another. That's what's happening here.then you set the pins and clear the pins. (GPIO,2^pin%) .. what does the gpio bit do
It's a bit-mask. You can set or clear more than one GPIO pin at a time, by passing a 32-bit mask in which each '1' bit causes the relevant action (setting or clearing) to happen to that specific pin, and each '0' bit means that the pin should be ignored (left in its current state). In the specific code you are referring to just a single pin is set or cleared at a time, so the bit-mask corresponds to a single bit being '1' and the other 31 bits being '0'. This is the simplest case but it may occasionally be useful to set or clear multiple pins at the same time.and what is the 2^pin% part?
I'm actually not sure why I wrote 2^pin% when 1<<pin% is directly equivalent, easier to understand, and probably faster.
2^10, 1<<10 and %10000000000 are all equivalent, and will work equally well. You could also use &400 or 1024 which have the same numeric value, but don't indicate the pin number as clearly.So for my program i can set the pins up like you did, and i can then use 2^10 if i want to set pin 10
Yes, that should work.in assembler, i would read the location, compare the location with how i want to change it with bit masking?
FNs return a value, PROCs don't. This is an oversimplification but it's the way they are usually distinguished. I could go on about how FN is the only polymorphic function in BBC BASIC (it can return either a numeric or a string, possibly determined at run time) and how a PROC can return values using the RETURN keyword, but they are more advanced topics!i cant work out the difference between def FN.... and a normal proc?
The GPIO expansion options that I know of rely on I²C communication, and I don't know how difficult it would be to support that from BBC BASIC. There is a WiringPi library that does it; I would need to study that to work out what is involved. I'm not keen on adding hardware to my RPi 4, so are there any built-in I²C peripherals that could be used for testing?
That's very good news. Did you need to run your program 'as root' for it to work?
According to the documentation I can find, ioctl returns an 'int' (signed 32-bit value) so, by rights, it should be straightforward:I should be able to get a return value from SYS "ioctl",F%,I2C_SLAVE,adr but have not found out how to do it.
Code: Select all
SYS "ioctl",F%,I2C_SLAVE,adr TO ret%
That's good, isn't it? The returned value is defined thus: "Upon successful completion, ioctl() shall return a value other than -1" so returning zero presumably implies that the call succeeded. Since the purpose of the call is to set an address, I assume no other returned value is expected.
well, ive modded your code a little for 3 leds, ive got a ULN2803A 8 Darlington Array connected to the pi, and its now flashing 3 leds.Richard Russell wrote: ↑Mon Dec 23, 2019 10:11 pm
I know you are asking principally about RISC OS, but for completeness the Raspberry Pi edition of BBC BASIC for SDL 2.0 (which runs under Raspbian, on a RPi 3 or 4) supports controlling the GPIO via the supplied library 'gpiolib.bbc'. Here is a demonstration of it in action, with the program listed below:
You don't really mean 50 MHz, surely? In the context of a stepper motor, do you mean 50 Hz?
50 Hz is probably within the range you could achieve in 'pure software' with care (certainly if you are prepared to use assembly language), but I'm unsure about the PWM aspect. Stepper motors I've encountered (and that's years ago) didn't use PWM, they were fed with two signals in quadrature, with the direction determined by the relative phase.
Sorry about that, it's because the auto-key-repeat is filling the keyboard buffer faster than the program editor is able to process those delete commands. The Raspberry Pi (particularly the RPi 3) is a very slow machine compared with most platforms on which BBC BASIC for SDL 2.0 runs; more typically the deletions can keep up with the key repeat rate.