![]() |
Forum Index : Microcontroller and PC projects : MMB4L: MMBasic for Linux alpha release
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Good question, but since without leaving MMB4L and immediately re-running the program, it moved on to the next pin, it would appear that despite complaining that the "direction" file didn't exist, it created it (and there's nothing else in the .bas program which would have done it). I've certainly never said or implied that I thought there was anything wrong with Linux, and I personally have no problem with having to use "sudo mmbasic" to use the gpio pins. I've just been following suggestions people have made to resolve the issue (+issue+, not +problem+). I posted the program I was using above. I've slightly modified it to follow the suggestions, so here it is again. (Start with "mmbasic" from the Linux prompt, and at the mmb4l prompt enter 'load "pinpi.bas"' and then 'run'--if you start with "sudo mmbasic" it will run without falling over.) ' pinpi.bas performs digital I/O with MMB4L ' dim integer i,j,k,p(4)=(0,12,16,20,21) dim integer pState(16) dim integer q(4)=(0,25,8,7,1), dout=1, din=0 for i=1 to 4 setpin p(i),dout cmd$="echo '1' > /sys/class/gpio/gpio"+str$(p(i))+"/value" system(cmd$) pause 500 next for i=1 to 4 setpin q(i),din cmd$="echo '0' > /sys/class/gpio/gpio"+str$(p(i))+"/value" system(cmd$) pause 500 next do for i=1 to 4 open "/sys/class/gpio/gpio"+str$(q(i))+"/value" for input as #1 a$=input$(1,#1): close #1 ' 0 or 1 cmd$="echo '"+a$+"' > /sys/class/gpio/gpio"+str$(p(i))+"/value" ' print cmd$ system(cmd$) next i pause 2000 loop sub setpin(pinno as integer, pinmode as integer) local string dirname$, cmd$ dirname$="/sys/class/gpio/gpio"+str$(pinno) if not MM.INFO(EXISTS DIR dirname$) then cmd$="echo '"+str$(pinno)+"' > /sys/class/gpio/export 2>/dev/null" ' print cmd$ system(cmd$) endif dirname$=dirname$+"/direction" if pinmode then cmd$="echo 'out' > "+dirname$ else cmd$="echo 'in' > "+dirname$ system(cmd$) cmd$="gpio -g mode "+str$(pinno)+" up" ' set weak pullup endif ?pinno,cmd$ system(cmd$) end sub PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7503 |
I believe that on the Pi there is a problem getting user access to the GPIO pins because you are attempting to access registers on the SOC. Those registers are only accessible to root as changing them can crash the system. Having said that, there is apparently a special way to give access to just the GPIO registers while locking out the other registers. The question is, does that system actually work correctly? This problem doesn't occur with a "normal" linux but probably does if it runs on any SOC where the GPIO pins are in SOC registers. Edited 2021-09-28 03:40 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
Obviously I don't know what you have done up to that point but if you're doing the above as non-root you appear to be trying to create and/or write to a file/path in a part of the file system where you don't have create and/or write permission. Thus the error. You may get clues from ls -l /sys/class/gpio/gpio12 and (if it's a directory) from ls -l /sys/class/gpio/gpio12/direction If any of those are links (symbolic or otherwise) then ls -l on their destination or try -L (capital l) as well as -l. It's probably due to running some commands as root (sudo mmbasic etc) and some not. John |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
Perhaps that is part of it, but the Pi does appear to be quirky and apocraphally GPIO seems to be in a constant state of flux, with different people (I'm not talking about the denziens of TBS) reporting different things on different versions and then writing incoherent solutions that looks like they've done a lot of random sh*t and then guessed what fixed their problem ... or maybe that is just me. No, I think it's them (random and incoherent stuff etc). I very much doubt it. Best wishes, Tom Oh ye gods. Best forgotten. (I bailed before the end.) John |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
I've certainly never said or implied that I thought there was anything wrong with Linux That's OK, I never said (or at least I didn't mean to if I did!) you thought that. John |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
ls -l /sys/class/gpio/gpio12 and (if it's a directory) from ls -l /sys/class/gpio/gpio12/direction Upon power-up, the directory /sys/class/gpio/gpio12 doesn't exist (and therefor the file, "direction" doesn't either). What the program does is create that directory and that file. It does so successfully when run with "sudo mmbasic", but not with "mmbasic" (unless you run it 9 times successively--which results in the 8 files having been created somehow despite the program erroring out). As I said, I have no problem with running "sudo mmbasic", but if others have suggestions about how it can be run successfully without the "sudo", I'll be happy to try them. I should note also as I said in my first post about this method of digital I/O to pins in Tom's alpha release of MMB4L that this technique is "a hack". It uses system calls to access the pins, and is not the method which would/will be used when the function is incorporated into the firmware. Whether and where the eventual method used will require "sudo" I don't know. Edited 2021-09-28 07:42 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
I'm wondering if the export takes longer than the program takes to move on to the next system command. That would mean the setpin sub may need a delay (or something else which allows the OS in). Maybe add a system("sleep 1") which I think would cover both ideas. John |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
That would mean the setpin sub may need a delay (or something else which allows the OS in). Maybe add a system("sleep 1") which I think would cover both ideas. Bingo! Adding PAUSE 500 after each system call makes it work. Thanks. For that matter, it works with PAUSE 100. Edited 2021-09-28 07:52 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
Hooray - thanks for trying it! John |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
Now we know some time is needed properly to populate the file system when changes are made, it explains why it would progress a bit further on each run. It also fits with some comments about gpio access via the file system in that manner being slow. John |
||||
tgerbic Regular Member ![]() Joined: 25/07/2019 Location: United StatesPosts: 57 |
I tried it out on my Fedora 34 linux workstation (AMD x86-64 5.13.19 kernel) and it works fine. I used the mmb4l-2021.01.00-a1-x86_64.tgz version and loaded nano 5.8. Set the environment variable for working directory. Works fine as a non-root user. Runs like lightning. Tried a couple of simple programs and it worked ok. Tried a couple of complex ones and hit a lot of expected function related errors. Should be better as the application progresses. Seems to work fine otherwise. Will play with it a bit more tomorrow. Regards Tony |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
For that matter, it works with PAUSE 100. Does this mean it now works without "sudo", just requiring the user to be a member of the "gpio" group, or is the problem that has been solved something else ? Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Hi Tony, Thanks for giving it a spin. That is quite the cutting-edge Linux. Future releases will be built on a pair of Xubuntu 18 VMs (32 & 64 bit) which should ensure they don't depend on unnecessarily late versions of GLIBC and thus don't require the most recent Linux distros. My development environment will still be Ubuntu 20. The "root user" business which is filling this thread is very specific to using the GPIO on the Raspberry Pi build. TBH what @lizby has achieved on the Raspberry Pi using the SYSTEM command is just an interesting diversion, it didn't figure in the original MMB4L concept and now that GPIO support does seem to be on the MMB4L roadmap it is unlikely to be done via directly talking to the "file system". I should hope so too on an x86-64 rather than a 32-bit microcontroller with delusions of grandeur. Should get a little bit faster still when I port @matherp's hash-based variable/sub/function lookup code from the CMM2. I'd appreciate hearing about stuff that didn't work; provided it wasn't related to high-resolution graphics, sound or GPIO. Perhaps it is something I thought did work but have no unit-test for, or perhaps it is low-hanging fruit that could be implemented (a.k.a. copied from @matherp's code) in the next alpha. 20+ years in commercial software development tells me that continuous improvement is "not a done deal" ![]() Best wishes, Tom Edited 2021-09-28 19:48 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7503 |
The RPi isn't a "standard" platform for linux by any means. It doesn't matter how you look at it, it's a SOC that those who haven't signed a NDA have restricted access to. You talk to the GPIO on their terms! Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Hi folks, As an experiment and in a possibly vain attempt to maintain focus I've spun out a new MMB4L: The Raspberry Pi GPIO thread for discussion of Raspberry Pi GPIO with MMB4L and lamentation of the death of the PiCRomite. Any discussion of other aspects of MMB4L alpha are welcome here ![]() Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
For that matter, it works with PAUSE 100. Does this mean it now works without "sudo", just requiring the user to be a member of the "gpio" group, or is the problem that has been solved something else ? Best wishes, Tom I don't know if anyone will want to fine tune the delays. It's handy to have a short test program, regardless of delay length. John |
||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2399 |
for many folks, just being able to set a few pins high/low or read a few switch inputs would likely suffice. there is also a serial port on a couple of the pins, which would then open up the opportunity to connect a slave mx170 (itself running mmbasic) to use as an 'intelligent peripheral'. cheers, rob :-) Edited 2021-09-28 23:50 by robert.rozee |
||||
Volhout Guru ![]() Joined: 05/03/2018 Location: NetherlandsPosts: 4854 |
Tom, My personal preference would be that MMB4L supports serial port (USB serial port) as it is the only non-protocol I/O that still exists in the PC world. Other interfaces (ethernet, wifi, bluetooth) require drivers and protocols that in many cases are supported by Linux, but these API's may be diverse and difficult to support. Especially from an interpreter running at user level in a multitasking system. It could end up in endless MMB4L versions to keep it running on the variety of systems end expectations out in the field. Volhout PicomiteVGA PETSCII ROBOTS |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7503 |
I suppose the beauty of serial is that it's more or less platform independent. Serial to/from anything else can be left up to external hardware. It's a matter of keeping the speed high enough. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6220 |
Back before Peter's RPI basic had serial port support, I experimented with treating the serial as a file. OPEN "/dev/ttyUSB0" FOR RANDOM AS #5 ' open the serial port PRINT #5, "HELLO!!! Is anyone out there?" DO ' one way to receive serial data which might not be there! k$ = INPUT$(1,#5) IF k$="" THEN nodata=nodata+1 ELSE result$=result$+k$ PRINT result$ nodata=0 ENDIF PAUSE 20 LOOP UNTIL k$=CHR$(10)OR nodata=50 ' 50*20ms = 1 second timeout CLOSE #5 Not sure if the same code works on Tom's code. I am not in a position to play with Linux at the moment. Jim VK7JH MMedit |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |