![]() |
Forum Index : Microcontroller and PC projects : MMB4L: MMBasic for Linux alpha release
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
robert.rozee Guru ![]() Joined: 31/12/2012 Location: New ZealandPosts: 2399 |
sudo is funny like that. once you've done a sudo and supplied the password, it can, for some short length of time thereafter, be run again without requiring the password to be entered. i believe the 'correct' way of doing it from within a script or program is to use pkexec. for example, see the below shell script: #!/bin/bash cmdU="" cmdB="" for port in $(find /sys/bus/pci/drivers/ehci-pci/0000* -maxdepth 1 -type l) do cmdU=$cmdU"echo -n "$(basename "$port")" > $(dirname "$port")/unbind;" cmdB=$cmdB"echo -n "$(basename "$port")" > $(dirname "$port")/bind;" done; for port in $(find /sys/bus/pci/drivers/xhci_hcd/0000* -maxdepth 1 -type l) do cmdU=$cmdU"echo -n "$(basename "$port")" > $(dirname "$port")/unbind;" cmdB=$cmdB"echo -n "$(basename "$port")" > $(dirname "$port")/bind;" done cmdstr="sleep 1;"$cmdU"sleep 3;"$cmdB"sleep 1" echo $cmdstr | sed 's/;/\n/g' pkexec su -c "$cmdstr" if [ $? -eq 0 ] then paplay /usr/share/sounds/LinuxMint/stereo/system-ready.ogg fi this particular script brings the USB subsystem back up once a pico had knocked it over. can be very useful! cheers, rob :-) |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
Something like ls -l /sys/class/gpio/gpio* You probably want to see the group and become a member of it. Commonly you'd have to re-login for an adduser (addgroup etc) to take effect. John |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Right, and I've seen that, but this didn't ask for a password (and I didn't provide one)--it just failed back the the MMB4L prompt. This was in attempting to write "out" or "in" to the direction file., e.g. /sys/class/gpio/gpio12/direction. But apparently it did create the file, because pressing up-arrow and <Enter> to run again moved on to the direction file for the next pin, which failed. When I did this for all 8 pins (4 out and 4 in), it ran successfully. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
ls -l /sys/class/gpio/gpio* pi@raspberrypi:~ $ ls -l /sys/class/gpio/gpio* lrwxrwxrwx 1 root gpio 0 Sep 25 09:17 /sys/class/gpio/gpiochip0 -> ../../devices/platform/soc/20200000.gpio/gpio/gpiochip0 ~ Edited 2021-09-26 00:37 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Right, and I've seen that, but this didn't ask for a password (and I didn't provide one) See https://www.raspberrypi.org/forums/viewtopic.php?t=97334 "The default policy for sudo within Raspbian is not the same as for Ubuntu etc. To change this you need to edit /etc/sudoers using visudo. More details can be found within the man page for sudo and within the file itself. Normally there is no root user and user pi has been given enough privileges to perform essential tasks w/o re-asking for a password." Or to put it another way it appears tha even though Raspbian / Raspberry OS is a *nix it isn't configured/secured out of the box like a typical multi-user *nix system. Regards, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
ls -l /sys/class/gpio/gpio* pi@raspberrypi:~ $ ls -l /sys/class/gpio/gpio* lrwxrwxrwx 1 root gpio 0 Sep 25 09:17 /sys/class/gpio/gpiochip0 -> ../../devices/platform/soc/20200000.gpio/gpio/gpiochip0 ~ OK, so you're either not included in group gpio or need to re-login. You can check with commands such as id or groups John |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
You can check with commands such as id or groups John After power-cycling: pi@raspberrypi:~ $ groups pi pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio pi@raspberrypi:~ $ id uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev), 60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi) pi@raspberrypi:~ $ ~ Edited 2021-09-26 03:52 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
Then I get: > load "pinpi1.bas" > run ==== AUTHENTICATING FOR org.freedesktop.policykit.exec === Authentication is needed to run `/bin/su' as the super user Authenticating as: root Password: Error in line 37: Command could not be run If I run it with sudo mmbasic, I don't get the "AUTHENTICATING" error, but get: pkexec su -c echo '12' > /sys/class/gpio/export 2>/dev/null Error in line 37: Command could not be run PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Error in line 37: Command could not be run I need to include the actual return value from system() in that error message. Bit busy at the moment though, having to rebuild my mum's laptop ![]() Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
scruss Regular Member ![]() Joined: 20/09/2021 Location: CanadaPosts: 88 |
That used to be the case, but in the last couple of years (== aeons in Raspberry Pi time) it hasn't been necessary. Unfortunately, there's no one clear way of doing it: * WiringPi, while still supplied as a system package, is no longer supported. The author walked away from it after a bad experience from Raspberry Pi clone manufacturers. For now, there's some community support, but it may not work on newer machines. * pigpio is well supported and runs on all Raspberry Pis. It has a daemon that runs with root privileges, and user processes talk to that. * the official/"correct" way is the kernel /dev/gpiochip* devices, but support for that is very limited so far. Nice work on this port to all involved, btw. I'm glad it doesn't run a core flat out like the Raspberry pi version used to. |
||||
toml_12953 Guru ![]() Joined: 13/02/2015 Location: United StatesPosts: 390 |
That used to be the case, but in the last couple of years (== aeons in Raspberry Pi time) it hasn't been necessary. Unfortunately, there's no one clear way of doing it: Nice work on this port to all involved, btw. I'm glad it doesn't run a core flat out like the Raspberry pi version used to. It wouldn't hurt to try staring BASIC with sudo just to test it. |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
That's the only thing that has worked for me with this SYSTEM method of reading/setting pins. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
If you want maximum speed then pigpio calls are the way to go but in that case the process must be started with sudo. If you use the pigpio daemon then the process won't need to be run with sudo but there are limitations to what the daemon supports. "File" access to I/O is very slow. I recommend the book "Raspbery PI IOT in C" by Harry Fairhead (ISBN 9781871962468). He explains the various options with lots of code examples |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
Thanks, I'm please some people are having fun with it. The MMB4L process takes brief naps when keyboard input is expected but not available (e.g. whilst waiting at the BASIC prompt) or when processing the PAUSE command (though before anyone shouts it doesn't naively just sleep for the length of the PAUSE). This does make PAUSE less accurate (both by limiting its resolution and I believe by increasing the likelyhood of another process grabbing the CPU). I imagine there will need to be some further titivation of this code but in the end Linux is not an RTOS so even if all the digital I/O is implemented there are many controller tasks for which MMB4L on the Pi (and presumably the PiCRomite) are unsuited. Many thanks for the recommendation Peter, I'll add it to my Christmas list. 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 |
pi@raspberrypi:~ $ groups pi pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio pi@raspberrypi:~ $ id uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev), 60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi) pi@raspberrypi:~ $ ~ Does it now work without needing to be root/sudo? The above looks good. John |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3309 |
No. Still fails at "echo 'out' > /sys/class/gpio/gpio12/direction" with "sh: 1: cannot create /sys/class/gpio/gpio12/direction: Permission denied" But when I immediately run it again, it works for gpio12 and fails at gpio16. If I run it 8 times, it progresses 1 pin further each time, and on the 9th run works. With "sudo mmbasic" it works from the beginning. Puzzling. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
toml_12953 Guru ![]() Joined: 13/02/2015 Location: United StatesPosts: 390 |
No. Still fails at "echo 'out' > /sys/class/gpio/gpio12/direction" with "sh: 1: cannot create /sys/class/gpio/gpio12/direction: Permission denied" But when I immediately run it again, it works for gpio12 and fails at gpio16. If I run it 8 times, it progresses 1 pin further each time, and on the 9th run works. With "sudo mmbasic" it works from the beginning. Puzzling. Puzzling is an understatement! Once all pins work, do they keep working for runs 10 and up? |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10067 |
I wonder why I gave up on the Raspberry Pi ![]() |
||||
JohnS Guru ![]() Joined: 18/11/2011 Location: United KingdomPosts: 3998 |
No. Still fails at "echo 'out' > /sys/class/gpio/gpio12/direction" with "sh: 1: cannot create /sys/class/gpio/gpio12/direction: Permission denied" But when I immediately run it again, it works for gpio12 and fails at gpio16. If I run it 8 times, it progresses 1 pin further each time, and on the 9th run works. With "sudo mmbasic" it works from the beginning. Puzzling. Your previous response showed you had no gpio12 so please explain where it has come from. You look to have left out important information, thus making assistance impossible. Please try to provide the same level of detail that Peter would ask for. BTW, despite Peter's unhelpful snipes (which you would be wise to ignore) I'm afraid it's something you're doing or not doing rather than something wrong with Linux. John Edited 2021-09-28 02:35 by JohnS |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4251 |
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. Is there something that needs to be done with /dev/mem ? https://www.element14.com/community/thread/19995/l/anyone-know-how-to-access-raspi-gpio-without-sudo Best wishes, Tom Edited 2021-09-28 02:47 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |