User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Thu Jun 13, 2019 4:10 pm

Most of the snapshot samples I get with the BitStreamRead C function are repairable with a bit of AI magic. I would like to focus on working together to establish a better sampling routine.

User avatar
RichardRussell
Posts: 527
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Thu Jun 13, 2019 4:27 pm

hippy wrote:
Thu Jun 13, 2019 3:54 pm
It was more how to deal with hardware which needs more than just sampling, needs reasonable timing accuracy on sending for example.
The significant latency and jitter between what's seen at /dev/gpiomem and the actual GPIO pins (which I assume affects both directions) probably rules out sending, if timing accuracy in the region of a few microseconds is required (not to mention context switches which could contribute much larger delays).

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Thu Jun 13, 2019 5:17 pm

My samples look pretty consistant with 1/0 pulse widths if no delays beyond my control happen. What bad data looks like to me is late start and shortened pulse widths.

hippy
Posts: 5360
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Thu Jun 13, 2019 7:33 pm

I have got a proof of concept libgpiod version running. First the bad news; it is unsurprisingly slower than direct access. But the good news is it's not too much slower and it's fairly easy to use.

The fastest I got Python 2.7 polling was every 1.6us. That's with a parameterless call to read a pin which had previously been specified for using.

With libgpiod that's twice as slow at 3.2us.

For ScriptBasic it is 4.9us.

Those are all fast enough for sampling a DHT11 and similar bit-streams.

Rather worse news is it doesn't seem that libgpiod is that well integrated into Raspbian as it stands. Not so much that the library and userland binaries aren't installed by default, but that the pins are all "unnamed", all GPIO pins report themselves as unused, and input, even when they are not currently set-up that way. Basically 'gpioinfo' does not report the same info as the existing 'gpio allreadall' does.

I also couldn't figure out how one would change the Alt-Function of a pin, or determine how that is currently set.

That may be because I am not familiar with how libgpiod is or it's more generic being cross-platform so no one thought of platform specific issues. Hopefully with the RPF and library authors supporting such things, they'll provide some capabilities to do what libraries currently allow, maybe even feed that upto the mainline.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Thu Jun 13, 2019 8:04 pm

For ScriptBasic it is 4.9us.


I'm using a 5us delay between pin reads using the BitStreamRead C function I created. I'm using your pulse detection routine as well.

User avatar
RichardRussell
Posts: 527
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Fri Jun 14, 2019 9:32 am

ScriptBasic wrote:
Thu Jun 13, 2019 5:17 pm
My samples look pretty consistant with 1/0 pulse widths if no delays beyond my control happen. What bad data looks like to me is late start and shortened pulse widths.
Here's a graphical plot of what I am getting. The most notable features are the occasional capture at 1.2 GHz clock rather than 600 MHz (causing everything to be stretched x2) and the rather variable time to the initial transition.

Image
Last edited by RichardRussell on Fri Jun 14, 2019 9:48 am, edited 1 time in total.

User avatar
PeterO
Posts: 4727
Joined: Sun Jul 22, 2012 4:14 pm

Re: ScriptBasic

Fri Jun 14, 2019 9:47 am

RichardRussell wrote:
Fri Jun 14, 2019 9:32 am
Here's a graphical plot of what I am getting. The most notable features are the occasional capture at 600 MHz clock rather than 1.2 GHz (causing everything to be stretched x2) and the rather variable time to the initial transition.
Is that the right way round ? Sampling at the lower rate should compress not stretch the samples, or have I missed something ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
RichardRussell
Posts: 527
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Fri Jun 14, 2019 9:50 am

PeterO wrote:
Fri Jun 14, 2019 9:47 am
Is that the right way round ? Sampling at the lower rate should compress not stretch the samples, or have I missed something ?
You're right, I spotted that before you posted and have corrected the text.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Fri Jun 14, 2019 4:52 pm

Is seems 5 microsecond sampling of the pin is the sweet spot. Anything shorter just increase the time parsing the palse data with no additional benefit.

User avatar
RichardRussell
Posts: 527
Joined: Thu Jun 21, 2012 10:48 am

Re: ScriptBasic

Fri Jun 14, 2019 5:24 pm

ScriptBasic wrote:
Fri Jun 14, 2019 4:52 pm
Is seems 5 microsecond sampling of the pin is the sweet spot. Anything shorter just increase the time parsing the palse data with no additional benefit.
Personally I'd rather sample as fast as I can, even if there's no great benefit it certainly can't make anything worse. It might make the difference between a 'shortened' pulse (and there are some in my plots) being detected and not being detected at all. Even in interpreted BASIC parsing the data doesn't take a significant time compared with the unavoidable 23 milliseconds per poll.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Fri Jun 14, 2019 6:23 pm

I'm surprised @hippy was able to get ScriptBasic polling native at 5 us. I went ahead and created the C BitStreamRead function when I was told SB was too slow to sample data.

I'm going to try again as an argumentless call.

hippy
Posts: 5360
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sat Jun 15, 2019 12:14 pm

ScriptBasic wrote:
Fri Jun 14, 2019 6:23 pm
I'm surprised @hippy was able to get ScriptBasic polling native at 5 us. I went ahead and created the C BitStreamRead function when I was told SB was too slow to sample data.
At the time no one knew what ScriptBasic was capable of, could only judge by what results you were getting.

This is the result using libgpiod; the direct memory access method is faster.

But that's the maximum rate for reading a pin then discarding the result. Storing into an array or poking through a pointer will add additional time.

I'm sure all this was discussed in a previous post.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sat Jun 15, 2019 7:19 pm

Hippy,

How close are you to releasing the code for your GPIO interface? I would like to give it a try on ScriptBasic.

Heater
Posts: 12672
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Sun Jun 16, 2019 9:38 am

ScriptBasic,

Can you tell me (again) how to install ScriptBasic?

Here is what I have done so far:

1) Grabbed the "clean up" branch of sb-dev from here: https://sandbox.allbasic.info:8181/scriptbasic/sb-dev which I notice has a new GMP2 directory in the extensions directory.

2) Unpacked it and changed into it's directory

3) Run "./setup"

4) Against my better judgement run "sudo ./install.sh"

5) Check that it runs by typing just "scriba". Seems to work.

6) In a different directory created a fibo.sb file with the fibo code you posted recently in the Fibonacci thread.

7) Try to run it. It fails with an obtuse missing header error:

Code: Select all

$ cat fibo.sb
IMPORT gmp2.bas

count = 4784969

a = 1
b = 0
p = 0
q = 1

WHILE count > 0
    IF (count % 2) = 0 THEN
        psq   = gmp2::mul(p, p)
        qsq   = gmp2::mul(q, q)
        twopq = gmp2::mul(p, q)
        twopq = gmp2::mul_si(twopq, 2)
        p     = gmp2::add(psq, qsq)
        q     = gmp2::add(twopq, qsq)
        count = count / 2
    ELSE
        bq    = gmp2::mul(b, q)
        aq    = gmp2::mul(a, q)
        ap    = gmp2::mul(a, p)
        bp    = gmp2::mul(b, p)
        a     = gmp2::add(bq, aq)
        a     = gmp2::add(a, ap)
        b     = gmp2::add(bp, aq)
        count = count - 1
    END IF
WEND
PRINT b,"\n"

$ scriba fibo.sb
fibo.sb(1): error &H3e:Include file is not found
$
This is all on my Debian running PC.

What to do?

hippy
Posts: 5360
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Jun 16, 2019 12:44 pm

Don't know if this helps, but on my Pi, with an extension created as "~/sb-dev-cleanup/extensions/gmp2", this is what I have to build it and then make that library available for scriba to use -

Code: Select all

cd ~/sb-dev-cleanup
./setup --module=gmp2
cp ./bin/mod/dll/gmp2.so /usr/local/lib/scriba/gmp2.so
cp ./extensions/gmp2/gmp2.bas /usr/local/include/scriba/gmp2.bas

hippy
Posts: 5360
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Jun 16, 2019 1:14 pm

ScriptBasic wrote:
Sat Jun 15, 2019 7:19 pm
Hippy,

How close are you to releasing the code for your GPIO interface? I would like to give it a try on ScriptBasic.
My latest version is attached.
sb-gpio.tar.gz
(13.27 KiB) Downloaded 23 times

hippy
Posts: 5360
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Jun 16, 2019 2:18 pm

In my "gpio.bas" extension I have ...

Code: Select all

GLOBAL CONST ALT_OUTPUT = 1
But when I run ...

Code: Select all

IMPORT gpio.bas
PRINT gpio::ALT_OUTPUT, "\n"
That reports it as an "undef".

How do I export a named constant out of an extension ?

Solved: Don't include the GLOBAL. If one does it becomes available in the main program without the module:: prefix which is a nightmare if one has two modules with the same constant name but different values.

And those CONST have to be within the MODULE ... END MODULE block.
Last edited by hippy on Sun Jun 16, 2019 2:47 pm, edited 2 times in total.

Heater
Posts: 12672
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Sun Jun 16, 2019 2:26 pm

hippy,

Thanks.

Somehow I knew this was going to be a world of pain:

Code: Select all

$ ./setup --module=gmp2
This is unix cwd=/mnt/c/Users/heater/Documents/fibo_4784969/BASIC/scriptbasic/sb-dev-cleanup/sb-dev-cleanup/
executing headerer for the C files
 extracting header from interface.c
creating the module object directory
Processing jamal files creating makefile
Module was compiled fine
$ cp ./bin/mod/dll/gmp2.so /usr/local/lib/scriba/gmp2.so
cp: cannot create regular file '/usr/local/lib/scriba/gmp2.so': Permission denied
$ sudo cp ./bin/mod/dll/gmp2.so /usr/local/li
b/scriba/gmp2.so
[sudo] password for heater:
$ sudo cp ./extensions/gmp2/gmp2.bas /usr/local/include/scriba/gmp2.bas
cp: cannot create regular file '/usr/local/include/scriba/gmp2.bas': No such file or directory
$ find -name "gmp2.bas"
./extensions/gmp2/gmp2.bas
$ sudo cp ./extensions/gmp2/gmp2.bas /usr/loc
al/include/scriba/gmp2.bas
cp: cannot create regular file '/usr/local/include/scriba/gmp2.bas': No such file or directory
$ file ./extensions/gmp2/gmp2.bas
./extensions/gmp2/gmp2.bas: ASCII text
$ vim  ./extensions/gmp2/gmp2.bas
$ mkdir /usr/local/include/scriba
mkdir: cannot create directory ‘/usr/local/include/scriba’: Permission denied
$ sudo mkdir /usr/local/include/scriba
$ sudo cp ./extensions/gmp2/gmp2.bas /usr/local/include/scriba/gmp2.bas
$ cd ..
$ cd ..
$ pwd
/mnt/c/Users/heater/Documents/fibo_4784969/BASIC/scriptbasic
$ scriba fibo.sb
fibo.sb(1): error &H3e:Include file is not found
Not working yet.

What to do?

We are far away from an out of the box experience here...

hippy
Posts: 5360
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: ScriptBasic

Sun Jun 16, 2019 3:26 pm

Heater wrote:
Sun Jun 16, 2019 2:26 pm
Somehow I knew this was going to be a world of pain:
That about sums up ScriptBasic.
Heater wrote:
Sun Jun 16, 2019 2:26 pm
What to do?
No idea. I'm not a Linux or ScriptBasic expert.
Heater wrote:
Sun Jun 16, 2019 2:26 pm
We are far away from an out of the box experience here...
This works 'out of the box' for me on my Pi, and, yes I know there's probably a better way to do the wget -

Code: Select all

cd ~/sb-dev-cleanup/extensions
ls
mkdir gpio
cd gpio
ls -l
wget https://www.raspberrypi.org/forums/download/file.php?id=30332
tar -xvzf file.php\?id\=30332
ls
cd ..
cd ..
./setup --module=gpio
cp ./bin/mod/dll/gpio.so /usr/local/lib/scriba/gpio.so
cp ./extensions/gpio/gpio.bas /usr/local/include/scriba/gpio.bas
cd ~
scriba test-sb-gpio.sb
And this is it in action ...

Code: Select all

[email protected]:~ $ cd ~/sb-dev-cleanup/
[email protected]:~/sb-dev-cleanup $ cd extensions/
[email protected]:~/sb-dev-cleanup/extensions $ ls
bigint  curl    dyc   ip        mt     nt       rpool.h  slre    trial
cgi     curses  ftpd  json      mxml   odbc     sbt      sqlite  ux
cio     dbg     hash  libgpiod  mysql  rpool.c  sdbg     t       zlib
[email protected]:~/sb-dev-cleanup/extensions $ mkdir gpio
[email protected]:~/sb-dev-cleanup/extensions $ cd gpio
[email protected]:~/sb-dev-cleanup/extensions/gpio $ ls -l
total 0
[email protected]:~/sb-dev-cleanup/extensions/gpio $ wget https://www.raspberrypi.org/forums/download/file.php?id=30332
--2019-06-16 16:10:24--  https://www.raspberrypi.org/forums/download/file.php?id=30332
Resolving www.raspberrypi.org (www.raspberrypi.org)... 104.22.1.43, 104.22.0.43, 2606:4700:10::6816:12b, ...
Connecting to www.raspberrypi.org (www.raspberrypi.org)|104.22.1.43|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13590 (13K) [application/octet-stream]
Saving to: âfile.php?id=30332â

file.php?id=30332   100%[=================>]  13.27K  --.-KB/s    in 0.001s  

2019-06-16 16:10:25 (13.3 MB/s) - âfile.php?id=30332â saved [13590/13590]

[email protected]:~/sb-dev-cleanup/extensions/gpio $ tar -xvzf file.php\?id\=30332
makefile.jam
interface.c
gpio.h
gpio.bas
manual.texi.jam
gpio.c
install.sb
[email protected]:~/sb-dev-cleanup/extensions/gpio $ ls
file.php?id=30332  gpio.c  install.sb   makefile.jam
gpio.bas           gpio.h  interface.c  manual.texi.jam
[email protected]:~/sb-dev-cleanup/extensions/gpio $ cd ..
[email protected]:~/sb-dev-cleanup/extensions $ cd ..
[email protected]:~/sb-dev-cleanup $ ./setup --module=gpio
This is unix cwd=/home/pi/sb-dev-cleanup/
executing headerer for the C files
 extracting header from interface.c
 extracting header from gpio.c
creating the module object directory
Processing jamal files creating makefile
Module was compiled fine
[email protected]:~/sb-dev-cleanup $ cp ./bin/mod/dll/gpio.so /usr/local/lib/scriba/gpio.so
[email protected]:~/sb-dev-cleanup $ cp ./extensions/gpio/gpio.bas /usr/local/include/scriba/gpio.bas
[email protected]:~/sb-dev-cleanup $ cd ~
[email protected]:~ $ scriba test-sb-gpio.sb
Started
Imported
Version 0.00 (#0139) - 2019-06-16 15:50:42
Running without sudo
Initialised : 0 - Okay
GPIO Address : 1995866112
0 ! 1 Output
1 ! 0 Input
2 = 0 Input
3 = 0 Input
4 = 0 Input
5 = 0 Input
6 = 0 Input
7 = 0 Input
8 ! 1 Output
9 ! 4 SPI0_MISO
10 ! 4 SPI0_MOSI
11 ! 4 SPI0_SCLK
12 = 0 Input
13 ! 4 PWM1
14 ! 2 TXD1
15 ! 2 RXD1
16 = 0 Input
17 = 0 Input
18 = 0 Input
19 ! 1 Output
20 = 0 Input
21 = 0 Input
22 = 0 Input
23 = 0 Input
24 = 0 Input
25 = 0 Input
26 = 0 Input
27 = 0 Input
Pulsing GPIO0
Finished
[email protected]:~ $ 
Maybe replicate doing that on a PI, resolve what issues there are, before moving on to doing something different, on a different platform, different OS.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Jun 16, 2019 3:38 pm

Heater,

Did everything build with. /setup?

If so, run mkdeb.sh to create an install file.

Bottom line is if you want to use extension modules, your basic.conf needs to point where it's located. The install does this for you and makes sure you have the required dependencies.

Don't run that old install script, it's useless.

Following the steps on the resource post on RaspberryBASIC.org should have got you going.

Heater
Posts: 12672
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Sun Jun 16, 2019 4:10 pm

ScriptBasic
Did everything build with. /setup?
Yes, as far as I can tell:

Code: Select all

$ ./setup
This is unix cwd=/mnt/c/Users/michael/Documents/fibo_4784969/BASIC/scriptbasic/sb-dev-cleanup/sb-dev-cleanup/
creating configure.jim
creating subdirectories for compilation output files
compiling Makefile using the Jamal preprocessor
...
...
libscriba library OK
MODULE cgi:      dll OK   lib OK   bas OK
MODULE curl:     dll OK   lib OK   bas OK
MODULE curses:   dll OK   lib OK   bas OK
MODULE dbg:      dll OK   lib OK   bas OK
MODULE gmp2:     dll OK   lib OK   bas OK
MODULE hash:     dll OK   lib OK   bas OK
MODULE ip:       dll OK   lib OK   bas OK
MODULE json:     dll OK   lib OK   bas OK
MODULE mt:       dll OK   lib OK   bas OK
MODULE mxml:     dll OK   lib OK   bas OK
MODULE mysql:    dll OK   lib OK   bas OK
MODULE odbc:     dll OK   lib OK   bas OK
MODULE sbt:      dll OK   lib OK   bas OK
MODULE sdbg:     dll OK   lib OK   bas FAIL
MODULE slre:     dll OK   lib OK   bas OK
MODULE sqlite:   dll OK   lib OK   bas OK
MODULE t:        dll OK   lib OK   bas OK
MODULE trial:    dll OK   lib OK   bas OK
MODULE ux:       dll OK   lib OK   bas OK
MODULE zlib:     dll OK   lib OK   bas OK
If so, run mkdeb.sh to create an install file.
You mean "sudo mkdeb.sh". It won't run without root permissions. This makes me very nervous. I can feel my system getting hosed very soon...

Where is the frikken .deb after that.

Oh, I found it in ./PACKAGES. Grrr...

Code: Select all

$ sudo /usr/bin/dpkg -i ./PACKAGES/scriptbasic-2.1-linux-amd64.deb
Selecting previously unselected package scriptbasic-2.1-linux-amd64.
(Reading database ... 121178 files and directories currently installed.)
Preparing to unpack .../scriptbasic-2.1-linux-amd64.deb ...
Unpacking scriptbasic-2.1-linux-amd64 (2.1-1) ...
dpkg: dependency problems prevent configuration of scriptbasic-2.1-linux-amd64:
 scriptbasic-2.1-linux-amd64 depends on libmysqlclient20; however:
  Package libmysqlclient20 is not installed.
 scriptbasic-2.1-linux-amd64 depends on libssl1.0.0; however:
  Package libssl1.0.0 is not installed.

dpkg: error processing package scriptbasic-2.1-linux-amd64 (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 scriptbasic-2.1-linux-amd64
Hmmm....There is no libssl1.0.0 in Debian stretch. I have the libssl1.0.2 installed.

Hmmm... There is no libmysqlclient20 in Debian stretch. Which I don't want anyway.

Please could you say how to install this from gitlab clone and without needing any root privs?

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Jun 16, 2019 4:28 pm

I don't need root permissions to run mkdeb.sh. Did you install the .deb using apt-get like instructed?

The installed SB files are put in the /usr/local directory structure with user permissions not root.

Heater
Posts: 12672
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Sun Jun 16, 2019 5:09 pm

ScriptBasic,
I don't need root permissions to run mkdeb.sh.

Code: Select all

$ ./mkdeb.sh
dpkg-deb: error: control directory has bad permissions 777 (must be >=0755 and <=0775)
mv: cannot stat '/tmp/tmp.fUwg5elf6Z/scriptbasic-2.1-linux-amd64.deb': No such file or directory
I have no idea where "control directory" is so I can't start to fix that.
Did you install the .deb using apt-get like instructed?
I don't recall anyone mentioning apt-get here.

How would I do that? What is the package name?

I normally install .deb files with dpkg -i

A install that works from the gitlab repo and does not require root privs is what we need.

User avatar
ScriptBasic
Posts: 1254
Joined: Wed Apr 03, 2019 5:53 pm
Location: Anacortes, WA USA
Contact: Website Twitter

Re: ScriptBasic

Sun Jun 16, 2019 5:24 pm

If you would have started HERE in the first place you would be running ScriptBasic long ago.

The first post in this thread points to that page.

Heater
Posts: 12672
Joined: Tue Jul 17, 2012 3:02 pm

Re: ScriptBasic

Sun Jun 16, 2019 5:43 pm

ScriptBasic,
If you would have started HERE in the first place you would be running ScriptBasic long ago.
Not here on my Intel PC I would not. I don't have a Pi to hand to try this on.
The first post in this thread points to that page.
That's great and all but why would I start reading this thread from the beginning when I'm asking here and now.

Where is the amd64 package?

It would be much easier if I could build and install from the git repo.

What's all that AppImage about? Never heard of it before?

Return to “Other programming languages”