Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 05:08 19 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : MMB4L: MMBasic for Linux alpha release

     Page 2 of 11    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 11:42am 24 Sep 2021
Copy link to clipboard 
Print this post

  thwill said  I can't reproduce that on my Ubuntu build, what is the program that you are running ?


Running and editing and rerunning the program listed above for flashing LEDs. It always works, but the extra characters appear on the prompt line.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 11:46am 24 Sep 2021
Copy link to clipboard 
Print this post

  lizby said  
  thwill said  I can't reproduce that on my Ubuntu build, what is the program that you are running ?


Running and editing and rerunning the program listed above for flashing LEDs. It always works, but the extra characters appear on the prompt line.


Thanks, I'll try and take a look over the weekend once I dust off a Pi Zero.
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 11:47am 24 Sep 2021
Copy link to clipboard 
Print this post

32-bit i686 build:

   https://github.com/thwill1000/MMB4L/blob/main/binaries/mmb4l-2021.01.00-a1-i686-glibc-2.17.tgz

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 12:30pm 24 Sep 2021
Copy link to clipboard 
Print this post

Notes: in the .nanorc file, before the "include" statement, I put "set constantshow" so that the line number you are on in nano will be displayed. "set linenumbers" would number each line, but I haven't done that.

I was very hopeful with
> OPEN "COM1: baud=9600" AS #5
>

but then:
> PRINT #5, "Hello, MMB4L"
Error: File number is not open

That leads to the question, what is on your todo list?

For better or worse, we have become accustomed to mmbasic developers not having other computing projects (or jobs) that might take away from developing toys for us greedy users. ;-}

Personally, I'd like to see 1) serial comms; 2) JSON$; 3) the big one: HDMI output on the pi (which makes it a less generic Linux).

This would enable such things as GPS, Lew's weather station, ESP-01 functions, and Tinine's (serial) bluetooth controllers, and serial communications to other 'mites. Some of that can probably be done now using the SYSTEM command and the ability to read and write files.

Then all the other I/O goodies.

All in all, great job, Tom. Thanks.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 12:37pm 24 Sep 2021
Copy link to clipboard 
Print this post

TODO

In no particular order within each section - and unfortunately I do have a "real" job that I have been neglecting and need to get back to.

Required for version 1 release

Add option to PAUSE controlling whether it nanosleeps or not
- or an OPTION to MMBasic controlling all sleep behaviour
Implement SEARCH PATH
Implement command-line RUN shortcut '*'
Ensure all Peter's "preprocessor tricks" implemented in programs and at command-line
Allow program to be specified on Linux command-line when MMBasic is launched
Implement variable/sub/function hash tables
Make output from LS more like that of CMM2
Have another look at the other settings recommended for raw console mode
Make all function keys reprogrammable
Implement OPTION persistence
Work through CMM2 manual implementing missing commands/functions
Review all uses of void*
Implement safety checks on PEEK/POKE calls
- should these be optional ?
- should address alignment of PEEK/POKE be optional ?
Implement serial I/O
Implement command-line shortcut for SYSTEM command, e.g. '!ls'
Implement command-line path completion
Implement support for ~ at start of paths
Implement MM.INFO(EXITSTATUS) to retrieve exit code from SYSTEM command

To infinity and beyond

Build on macOS
Rewrite pre-processor
Implement SWAP - not difficult, just not urgent and not compatible with other MMs
Integrate 'pigpio' with Raspberry Pi build
High resolution graphics

Best wishes,

Tom
Edited 2021-09-24 22:38 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Rado
Regular Member

Joined: 27/11/2020
Location: Croatia
Posts: 59
Posted: 02:47pm 24 Sep 2021
Copy link to clipboard 
Print this post

How do you intend to use PEEK/POKE? If you run them in user space, they are fun, but can't do much. If you allow them in elevated privileges account, they might be really dangerous to use - crash the machine, steal other user's data, etc.

There might be a better use for them to control /proc - and that would be fun, too. And dangerous with elevated privileges, too. :)
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 03:05pm 24 Sep 2021
Copy link to clipboard 
Print this post

  Rado said  How do you intend to use PEEK/POKE? If you run them in user space, they are fun, but can't do much. If you allow them in elevated privileges account, they might be really dangerous to use - crash the machine, steal other user's data, etc.

There might be a better use for them to control /proc - and that would be fun, too. And dangerous with elevated privileges, too. :)


They will only work within the virtual address space of the MMB4L process, I'm not sure how you would do otherwise without explicit use of shared memory, and in any case it's not something that I consider sane. If you want to go crazy then there is the SYSTEM command.

There will be a pair of options "OPTION PEEK UNSAFE" and "OPTION POKE UNSAFE" both by default "OFF". If these are OFF then PEEK/POKE will report an error when used outside of the areas of memory that MMB4L has allocated for variable storage and the BASIC heap.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 03:39pm 24 Sep 2021
Copy link to clipboard 
Print this post

This is a really cool project, Tom. :)
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 03:39pm 24 Sep 2021
Copy link to clipboard 
Print this post

Digital input and output on the Pi Zero W with MMB4L

Youtube video: MMB4L digital input and output

The code activates weak pullups. Pressing a button on the 4-button module pulls the pin low. The LEDs reflect the pin state.


' pin.bas -- 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$="sudo 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$="sudo 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$="sudo 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$="sudo echo '"+str$(pinno)+"' > /sys/class/gpio/export 2>/dev/null"
'    print cmd$
   system(cmd$)
 endif
 if pinmode then
   cmd$="sudo echo 'out' > "+dirname$+"/direction"
 else
   cmd$="sudo echo 'in' > "+dirname$+"/direction"
 endif
 system(cmd$)
end sub

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 04:18pm 24 Sep 2021
Copy link to clipboard 
Print this post

  lizby said  

   open "/sys/class/gpio/gpio"+str$(q(i))+"/value" for input as #1
   a$=input$(1,#1): close #1 ' 0 or 1


The fact that that works is somewhat unexpected - I guess a side-effect of everything being a file.

Innovative work @lizby,

Tom.
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 04:33pm 24 Sep 2021
Copy link to clipboard 
Print this post

Thanks. I had to check these things out with
pi@raspberrypi:~ $ cat /sys/class/gpio/gpio12/direction
in
pi@raspberrypi:~ $ cat /sys/class/gpio/gpio12/value
0
pi@raspberrypi:~ $ echo "out" > /sys/class/gpio/gpio12/direction
pi@raspberrypi:~ $ cat /sys/class/gpio/gpio12/direction
out


I forgot to mention that in order to get the "gpio" command (used for setting the weak pullup), I had to install WiringPi (sudo apt-get update; sudo apt-get install wiringpi).

~
Edited 2021-09-25 02:38 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 04:46pm 24 Sep 2021
Copy link to clipboard 
Print this post

  Mixtel90 said  This is a really cool project, Tom. :)


Thanks Mick. I rearranged the score but Geoff and Peter were the composers and it looks like Lance is making it dance.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 12:49am 25 Sep 2021
Copy link to clipboard 
Print this post

When I tried to run the program I posted above after power-cycling, it failed. I realized that I had run it after getting equivalent code to run in a bash script. That had apparently initialized some things. I also realized that I had forgotten to put the weak pullup line into the MMB4L code.

After inserting that line and fiddling, I realized that it had to run as root for the setup of the gpio to work.

So, after starting with "sudo mmbasic", this now works:

' Pin.bas performs digital I/O with linux4MMB
'
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$="sudo 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$="sudo 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$="sudo 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$="sudo echo '"+str$(pinno)+"' > /sys/class/gpio/export 2>/dev/null"
'    print cmd$
   system(cmd$)
 endif
 dirname$=dirname$+"/direction"
 if pinmode then
   cmd$="sudo echo 'out' > "+dirname$
 else
   cmd$="sudo echo 'in' > "+dirname$
   system(cmd$)
   cmd$="gpio -g mode "+str$(pinno)+" up" ' set weak pullup
 endif
'  ?pinno,cmd$
 system(cmd$)
end sub


~
Edited 2021-09-25 12:06 by lizby
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2285
Posted: 03:58am 25 Sep 2021
Copy link to clipboard 
Print this post

  lizby said  After inserting that line and fiddling, I realized that it had to run as root for the setup of the gpio to work


hi,
   have you tried:
sudo adduser $USER gpio

(from: https://raspberrypi.stackexchange.com/questions/40105/access-gpio-pins-without-root-no-access-to-dev-mem-try-running-as-root

no guarantees, i don't have a RPi here to check the above, but it looks hopeful.


cheers,
rob   :-)
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3649
Posted: 07:56am 25 Sep 2021
Copy link to clipboard 
Print this post

  lizby said  I realized that it had to run as root for the setup of the gpio to work.
Classic sign that the permissions are set to stop users doing potentially dangerous/naughty things (as you'd expect, that's the default).

Rob's idea looks good, but if it doesn't work look at the owner of the gpio ports.

John
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 11:26am 25 Sep 2021
Copy link to clipboard 
Print this post

  robert.rozee said  have you tried:
sudo adduser $USER gpio


no guarantees, i don't have a RPi here to check the above, but it looks hopeful.

pi@raspberrypi:~ $ sudo adduser $USER gpio
The user `pi' is already a member of `gpio'.

So no joy there.

  JohnS said  Rob's idea looks good, but if it doesn't work look at the owner of the gpio ports.


Thanks. How do I do that?

I thought it might have been the "sudo"s in the code. Removing them all got further in the program, but it again died with a "permission" error. Oddly, if I reran, it got further, and after doing that 8 times, it ran fine.

Running with "sudo mmbasic" also works fine with the "sudo"s in the code removed.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 11:45am 25 Sep 2021
Copy link to clipboard 
Print this post

It's not good to have to run MMBasic as root - even with sudo. There's no control over what might be connected to ports etc.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3008
Posted: 12:06pm 25 Sep 2021
Copy link to clipboard 
Print this post

  Mixtel90 said  It's not good to have to run MMBasic as root - even with sudo. There's no control over what might be connected to ports etc.


Pi-Cromite always ran with "sudo mmbasic". No problems detected by me, and none that I know of reported.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 5705
Posted: 12:25pm 25 Sep 2021
Copy link to clipboard 
Print this post

Tut Tut! The user should *never* need root access to run anything under linux. That's what it has a permissions system for. ;)  It's why, on the RPi, the root account is disabled by default and you are pushed towards using sudo for the odd occasions where you need root access.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 12:31pm 25 Sep 2021
Copy link to clipboard 
Print this post

  Mixtel90 said  Tut Tut! The user should *never* need root access to run anything under linux. That's what it has a permissions system for. ;)  It's why, on the RPi, the root account is disabled by default and you are pushed towards using sudo for the odd occasions where you need root access.


It's not my area, but I've had the briefest of looks and it appears you are expected to have sudo priviliges to access the GPIO on the Pi. One possibility is to configure the pigpio daemon to run on startup with the necessary privileges and then communicate with the daemon as a normal user ... I'll leave that as an exercise for the reader. Possibly WiringPi has some similar workflow available.

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
     Page 2 of 11    
Print this page
© JAQ Software 2024