RiscOS and GPIO for dummies ...


49 posts   Page 1 of 2   1, 2
by MegaGumbo » Tue Nov 06, 2012 7:24 pm
This is a quick start guide for people like me who have never used RiscOS before and are interested in setting up GPIO for RiscOS. It's the procedure I followed after reading a few posts on this topic here in this forum. I hope that RiscOS veterans will forgive me for the amature nature of this guide.

Download the GPIO Module for RiscOS Pi from here: http://www.tankstage.co.uk/software.html - if you click on the first link on the page (the link is to a file named GPIO.zip) a download dialog window will pop up. In the window you will see a folder icon being displayed. Drag and drop the folder icon from the download dialog window to the SD card icon in the lower left corner of the RiscOS panel. RiscOS makes intense use of drag and drop, one of the things that are different from Windows or Linux.

Click on the sdcard icon mentioned above and a folder window will pop up containing more folders ('directories'). One of these is called GPIO. Double click on the GPIO folder and another folder window pops up. It contains two programs: !GPIOConfig and !PiLed as well as other files and folders. One of the files is called GPIO and its icon tells us that this is a 'module' file.

Now, to load the module in order to let RiscOS know about the RPi's GPIO hardware, we need to run a 'TaskWindow'. This is a command line tool that we need to load the module. So press ctrl+F12 and a new TaskWindow will open. The asterisk displayed is the prompt. Now we need to load the GPIO module for RiscOS and this is done with the RMLoad command. The example below assumes you have placed the GPIO folder you downloaded before in the top directory of your sdcard.

Code: Select all
RMLoad SDFS::RISCOSpi.$.GPIO.GPIO


This will load the module file GPIO from the location SDFS::RISCOSpi.$.GPIO which is the GPIO folder on the sdcard. There should be no error messages after you entered the RMLoad command.

To see if the module has been loaded and is working, open the GPIO folder you downloaded (the one on your sdcard) and run the !PiLed demo. A task window opens up and informs you about the selected GPIO pin mode. Press space to turn the activity (hdd status) LED of your Pi on, hit space again to turn it off.

To see BASIC code of the !PiLed program, hold down shift and left click the program icon and the application folder pops up. There is a BASIC file there called !RunImage. Again hold down shift and left click on the !RunImage file. This will open up an editor with the BASIC code. Enjoy reading.
Posts: 84
Joined: Mon Feb 13, 2012 4:45 pm
by tank » Tue Nov 06, 2012 7:37 pm
I'm happy to try and help if anyone needs it as well.
Posts: 57
Joined: Thu Dec 15, 2011 5:51 pm
by pygmy_giant » Tue Nov 06, 2012 8:08 pm
shouldnt that be:

Code: Select all
RMLoad SDFS::RISCOSpi.$.GPIO/zip.GPIO


?

Great demo otherwise though - enjoying learning BASIC - thanks :D
Last edited by pygmy_giant on Tue Nov 06, 2012 8:12 pm, edited 2 times in total.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by stylx » Tue Nov 06, 2012 8:10 pm
Hats off to the both of you, we might get the following risc os deserves I only been using risc os for about 2 weeks and already I seeing the best and worst that programmers have to offer.!
Posts: 30
Joined: Thu Oct 25, 2012 10:06 pm
by MegaGumbo » Tue Nov 06, 2012 8:19 pm
pygmy_giant wrote:shouldnt that be:

Code: Select all
RMLoad SDFS::RISCOSpi.$.GPIO/zip.GPIO


?


Er, just went through the instructions to check and you're right: it is still a .zip file but at least from what I can say, RMLoad seems to be able to resolve the 'path' without the filetype. In fact, Filer tells me that this is 'Dir.GPIO' so I asummed it was a directory. Now here's my newbie question: how to I unzip this file? :oops:
Posts: 84
Joined: Mon Feb 13, 2012 4:45 pm
by pygmy_giant » Tue Nov 06, 2012 8:24 pm
I get an error on my pi if I dont include the /zip
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by tank » Tue Nov 06, 2012 8:34 pm
MegaGumbo wrote:
pygmy_giant wrote:shouldnt that be:

Code: Select all
RMLoad SDFS::RISCOSpi.$.GPIO/zip.GPIO


?


Er, just went through the instructions to check and you're right: it is still a .zip file but at least from what I can say, RMLoad seems to be able to resolve the 'path' without the filetype. In fact, Filer tells me that this is 'Dir.GPIO' so I asummed it was a directory. Now here's my newbie question: how to I unzip this file? :oops:


Click on the SFDS icon in the icon bar to open the filer window.
Click Menu in the window, follow New Directory to the right, type GPIO, press return.
Double click on the new GPIO folder.
Double click on the GPIO/zip icon.
If this errors, double click on the utilities folder and double click on !SparkFS.
Try again.
This should open the GPIO/zip as a filer window.
Drag all the files from this window to the GPIO filer window.
Close the GPIO/zip filer window.
You can now delete the GPIO/ZIP file if you wish (remember there's no Un-Delete)
You should now have a directory called GPIO with the contents of the zip file in it.
Posts: 57
Joined: Thu Dec 15, 2011 5:51 pm
by MegaGumbo » Tue Nov 06, 2012 8:48 pm
tank wrote:Click on the SFDS icon in the icon bar to open the filer window.
Click Menu in the window, follow New Directory to the right, type GPIO, press return.
Double click on the new GPIO folder.
Double click on the GPIO/zip icon.
If this errors, double click on the utilities folder and double click on !SparkFS.
Try again.
This should open the GPIO/zip as a filer window.
Drag all the files from this window to the GPIO filer window.
Close the GPIO/zip filer window.
You can now delete the GPIO/ZIP file if you wish (remember there's no Un-Delete)
You should now have a directory called GPIO with the contents of the zip file in it.


Ah, okay - I thought one would need to install additional packages, but it's just as simple as it is ... ;)
Posts: 84
Joined: Mon Feb 13, 2012 4:45 pm
by tank » Tue Nov 06, 2012 8:54 pm
MegaGumbo wrote:
tank wrote:Click on the SFDS icon in the icon bar to open the filer window.
Click Menu in the window, follow New Directory to the right, type GPIO, press return.
Double click on the new GPIO folder.
Double click on the GPIO/zip icon.
If this errors, double click on the utilities folder and double click on !SparkFS.
Try again.
This should open the GPIO/zip as a filer window.
Drag all the files from this window to the GPIO filer window.
Close the GPIO/zip filer window.
You can now delete the GPIO/ZIP file if you wish (remember there's no Un-Delete)
You should now have a directory called GPIO with the contents of the zip file in it.


Ah, okay - I thought one would need to install additional packages, but it's just as simple as it is ... ;)



That the RISC OS ethic !!
It needs to be simple for some of us....;)
Posts: 57
Joined: Thu Dec 15, 2011 5:51 pm
by MegaGumbo » Tue Nov 06, 2012 8:55 pm
pygmy_giant wrote:I get an error on my pi if I dont include the /zip


Unfortunately, I can't edit my older post so here comes a hint from pygmy_giant regarding the RMLoad command. If it's not possible for RMLoad to access the 'folder' (which, as it turned out, is still a .zip file if you follow my instructions above) then please do the following:

Code: Select all
RMLoad SDFS::RISCOSpi.$.GPIO/zip.GPIO


@pygmy_giant: thanks for the info!
Posts: 84
Joined: Mon Feb 13, 2012 4:45 pm
by SEDev » Tue Nov 06, 2012 11:12 pm
MegaGumbo wrote:Now, to load the module in order to let RiscOS know about the RPi's GPIO hardware, we need to run a 'TaskWindow'. This is a command line tool that we need to load the module.

There's no need to go to the command line to load a module, you can just double-click it.
Posts: 24
Joined: Thu Aug 02, 2012 10:55 pm
by MegaGumbo » Wed Nov 07, 2012 7:44 pm
SEDev wrote:
MegaGumbo wrote:Now, to load the module in order to let RiscOS know about the RPi's GPIO hardware, we need to run a 'TaskWindow'. This is a command line tool that we need to load the module.

There's no need to go to the command line to load a module, you can just double-click it.


Aaah, now that's cool! I didn't know that, thanks! I just picked up the 'RMLoad' command from a previous post and dug around how to use it. At least I learned some more of the basics of RiscOS, which is something I really enjoy.
Posts: 84
Joined: Mon Feb 13, 2012 4:45 pm
by stylx » Sat Nov 10, 2012 3:23 pm
message for tank or anyone who can help
I have written a small assembly language to act as a for next loop to access the GPIO module but it run to fast. can't seem to put number in greater then 6FFFFFFF in to the loop why is this. I tried basic but it doesn't seem fast enough. As I working on Pulse width modulation project
Posts: 30
Joined: Thu Oct 25, 2012 10:06 pm
by tank » Sat Nov 10, 2012 3:56 pm
stylx wrote:message for tank or anyone who can help
I have written a small assembly language to act as a for next loop to access the GPIO module but it run to fast. can't seem to put number in greater then 6FFFFFFF in to the loop why is this. I tried basic but it doesn't seem fast enough. As I working on Pulse width modulation project


In BASIC the following loop will toggle pin 17 at just over 9Khz in a task window.

REPEAT
SYS "GPIO_WriteData" ,17,1
SYS "GPIO_WriteData" ,17,0
UNTIL FALSE

What sort of speeds are you trying to get ?
Posts: 57
Joined: Thu Dec 15, 2011 5:51 pm
by stylx » Sat Nov 10, 2012 4:09 pm
it the cut off point off the leds thats the problem I'm trying to make the led go from off to on like a dimmer switch then off again bit like christmas decorations
Posts: 30
Joined: Thu Oct 25, 2012 10:06 pm
by tank » Sat Nov 10, 2012 4:19 pm
stylx wrote:it the cut off point off the leds thats the problem I'm trying to make the led go from off to on like a dimmer switch then off again bit like christmas decorations


If you want to send me your code, I'll take a look !!
webmaster@tankstage.co.uk
Posts: 57
Joined: Thu Dec 15, 2011 5:51 pm
by stylx » Sat Nov 10, 2012 4:24 pm
it's ok now that I know the operating frequency 9KHz the rest is just simple math thank you it now works in basic. Through I'm still gonna mess around with assembly. it just something to learn
Posts: 30
Joined: Thu Oct 25, 2012 10:06 pm
by stylx » Sat Nov 10, 2012 7:01 pm
does any one know the math to plot a sine way i forgot and left my books at home
Posts: 30
Joined: Thu Oct 25, 2012 10:06 pm
by ukscone » Sat Nov 10, 2012 7:16 pm
User avatar
Forum Moderator
Forum Moderator
Posts: 2581
Joined: Fri Jul 29, 2011 2:51 pm
by Grumpy Mike » Sat Nov 10, 2012 7:41 pm
tank wrote:In BASIC the following loop will toggle pin 17 at just over 9Khz in a task window.

Any idea why it is so slow?
On a RISC PC with only a 80MHz clock you could get 1MHz and that was limited by the PIO chip.
User avatar
Posts: 748
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by neilf » Sun Nov 11, 2012 8:29 am
The following Basic code toggles at 324kHz on my V2 board:

REM R-Pi speed test, V2 board, Risc OS BBC Basic V, 9/11/12
SYS "GPIO_ExpAsGPIO",0
T%=TIME
FORN%=1TO324000:SYS&58F81,24,1:SYS&58F81,24,0:NEXT:S%=TIME-T%
PRINT "Completed in ";S%;" centisecs"
END

See thread at: https://www.riscosopen.org/forum/forums/5/topics/1445
I expect using inline assembler would be about four times that speed. How quick do you need it to be?

-Neil F.
Posts: 63
Joined: Sun Nov 11, 2012 8:14 am
by stylx » Sun Nov 11, 2012 11:41 pm
Does any one known what SWI to use to relate the value held in register. I need it to debug program
Posts: 30
Joined: Thu Oct 25, 2012 10:06 pm
by tank » Mon Nov 12, 2012 6:14 pm
neilf wrote:The following Basic code toggles at 324kHz on my V2 board:
-Neil F.


What speed are you running the CPU/GPU at. On mine it gets about 224Khz (V2 board, 900Mhz CPU, default GPU) with that program, nothing else running... :(
Reading pin with a logic probe.
Posts: 57
Joined: Thu Dec 15, 2011 5:51 pm
by Grumpy Mike » Tue Nov 13, 2012 4:25 pm
stylx wrote:Does any one known what SWI to use to relate the value held in register. I need it to debug program

I don't know what you mean by this, care to expand?
Relate the value to what?
User avatar
Posts: 748
Joined: Sat Sep 10, 2011 7:49 pm
Location: Manchester (England England)
by neilf » Wed Nov 14, 2012 9:21 pm
What speed are you running the CPU/GPU at. On mine it gets about 224Khz (V2 board, 900Mhz CPU, default GPU) with that program, nothing else running... :(
Reading pin with a logic probe.


Hi Tank.

I'm just running a Rev2 card standard, straight out of the box, with the above prog running single-tasking (i.e. not in a task window).

There's no need to test the output with a logic probe as the code is self-timing.
Just tweak the value 324000 in the 4th line until the prog returns 'completed in 100 centisecs' or thereabouts. The 324000 (or whatever) value is the number of times the GPIO line has been toggled in one second.
Posts: 63
Joined: Sun Nov 11, 2012 8:14 am