LeoWhite
Posts: 131
Joined: Mon Apr 08, 2013 9:20 am
Contact: Website

PiGlow and BBC Basic

Tue Nov 19, 2013 8:31 am

Hiya,

For those that attended the RISC OS London show last month you may have seen me with a PiGlow running under RISCOS. I've now given the BBC Basic code a bit of a tidy (Switching from using IIC_Control to OS_IICOp being the main change) and I've now made it available on my website if anyone is interested in seeing/using it. Might be helpful if you are trying to work out how to use I2C from Basic (Took me a few attempts to get it working).

Code can be found at http://www.mybigideas.co.uk/RPi/PiGlow/.

Leo

colin B
Posts: 119
Joined: Sun Mar 04, 2012 12:23 pm
Contact: Website

Re: PiGlow and BBC Basic

Tue Nov 19, 2013 12:18 pm

May I suggest adding some notes explaining the hex codes, some people may want to see how you use the I2C but not have either a PiGlow or looked at the Python script.

Thank you for posting your code though.

Colin
On a clear disk one can seek forever

LeoWhite
Posts: 131
Joined: Mon Apr 08, 2013 9:20 am
Contact: Website

Re: PiGlow and BBC Basic

Tue Nov 19, 2013 12:26 pm

colin B wrote:May I suggest adding some notes explaining the hex codes, some people may want to see how you use the I2C but not have either a PiGlow or looked at the Python script.
Oops, I 'defined' some of the HEX codes at the top of the file and then don't actually use them later in the file, but instead use the hard-coded numbers! I'll look at updating that so its a bit more readable.

Thanks for the feedback!

Leo

LeoWhite
Posts: 131
Joined: Mon Apr 08, 2013 9:20 am
Contact: Website

Re: PiGlow and BBC Basic

Tue Nov 19, 2013 9:21 pm

Okay, I've now update the code to have a few more comments and updated some of the register names to match those defined in the data sheets. I've also added a couple of links to where the OS_IICOp calls are documented, and where to find the original python example.

I've also added a SetLED call so you no longer need to update all 18 in one go.

Leo

riscosdave
Posts: 6
Joined: Tue Oct 25, 2011 4:43 pm

Re: PiGlow and BBC Basic

Mon Dec 30, 2013 8:26 pm

Hi Leo.
My Son bought me a PiGlow for Christmas. So I have to show him I can use it!
I have played around with your BASIC program and so to some observations.
The procedure, StopPiGlow, is not called as far as I can see. The main REPEAT loop doesn't terminate as UNTIL FALSE never holds.
As far as I can see, the procedure, SetLED, is not called anywhere.

LeoWhite
Posts: 131
Joined: Mon Apr 08, 2013 9:20 am
Contact: Website

Re: PiGlow and BBC Basic

Mon Dec 30, 2013 11:07 pm

riscosdave wrote:Hi Leo.
Hiya!
riscosdave wrote: My Son bought me a PiGlow for Christmas. So I have to show him I can use it!
I have played around with your BASIC program and so to some observations.
The procedure, StopPiGlow, is not called as far as I can see. The main REPEAT loop doesn't terminate as UNTIL FALSE never holds.
Yes, this particular example loops forever. In theory I could call it from the error handler to ensure the PiGlow gets turned off when 'Escape' is pressed or similar. In reality I just had a different BASIC file that turned the PiGlow off, so I was using that during development!

riscosdave wrote: As far as I can see, the procedure, SetLED, is not called anywhere.
That's true. Its something I added in the second revision of the code after reviewing the data sheet for the chip. Its not used by the main code itself, but I included it as an example of how a single LED can be set without affecting any of the others in case people took and modified the code. So in theory you could write a BASIC program that sets the red LEDs if you have new mails or your internet connection is down etc.

Leo

riscosdave
Posts: 6
Joined: Tue Oct 25, 2011 4:43 pm

Re: PiGlow and BBC Basic

Wed Jan 01, 2014 12:49 am

Thanks for the explanation. I had already written a 'StopPiGlow' program - cheating, actually, by using some of your code including PROCStopPiGlow. In similar vein I have got a few other programs. It was good enough to impress my Son and a few other family members this Christmas and New Year! May be I'll have a go at Python now.

LeoWhite
Posts: 131
Joined: Mon Apr 08, 2013 9:20 am
Contact: Website

Re: PiGlow and BBC Basic

Wed Jan 01, 2014 4:15 pm

riscosdave wrote:Thanks for the explanation. I had already written a 'StopPiGlow' program - cheating, actually, by using some of your code including PROCStopPiGlow.
That's what the code is there for... Feel free to re-use it (I really should get around to putting an appropriate licence at the top.

riscosdave wrote: In similar vein I have got a few other programs. It was good enough to impress my Son and a few other family members this Christmas and New Year! May be I'll have a go at Python now.
Glad to hear you got it working! Did any one comment on how bright it gets? When I was showing it at the RISC OS London show I had to reduce the max brightness by half to stop blinding people!

Return to “RISCOS”