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

Re: ScriptBasic

Mon Jun 10, 2019 4:43 pm

But I wouldn't let anyone's lack of interest in ScriptBasic itself put you off
With almost 1000 posts and over 23K views, it's a hard call to determine if I'm wasting my time here or not.

Keep in mind when you install ScriptBasic, it becomes as much your BASIC as it is mine.

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

Re: ScriptBasic

Mon Jun 10, 2019 8:36 pm

I see no no reason not to make ScriptBasic announcements here. No reason not to discuss Raspi related developments of ScriptBasic, or projects using it with the Raspi. And so on.
Last edited by Heater on Mon Jun 10, 2019 9:48 pm, edited 1 time in total.

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

Re: ScriptBasic

Mon Jun 10, 2019 9:25 pm

I have no problem someone posting a Python or whatever example showing how they would solve a ScriptBasic issue. (like @hippy's Python pulse interrogator)

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

Re: ScriptBasic

Tue Jun 11, 2019 4:42 am

I'm currently using @hippy's pulse detection with the static data I present it. I have taken a couple stabs at trying to come up with a better pulse width to binary routine. You can use my posted raw reads to play with if you want to try and find a better way. Extra points if you find a way to do data correction.

I might add a 4th argument if TRUE, the returned bit string will be the parsed binary result ready for the bin2int function.

Here is my current time for a call to the DHT11 native function. I'm not using the priority function and do it as a standard call.

Code: Select all

IMPORT wpi.bas

ret = WPI::DHT11(7, humidity, temperature)
PRINT FORMAT("[%d] Humidity: %.1f %%  - Temperature: %.1f C\n", ret, humidity, temperature)


pi@RPi3B:~/sbrpi/examples $ time scriba dht11.sb
[0] Humidity: 54.0 %  - Temperature: 25.1 C

real	0m0.168s
user	0m0.127s
sys	0m0.012s
pi@RPi3B:~/sbrpi/examples $ 

I have update the WPI extension module source and binary runtime on the RaspberryBASIC.org forum.

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

Re: ScriptBasic

Tue Jun 11, 2019 8:27 am

ScriptBasic wrote:
Tue Jun 11, 2019 4:42 am
You can use my posted raw reads to play with if you want to try and find a better way. Extra points if you find a way to do data correction.
Are you already taking advantage of the redundancy in the DHT11's data, as my BBC BASIC code does? This is "data correction" in a sense because you can derive effectively three sets of data from the raw read (two of which are independent) and use the checksum to determine which is right if they differ.

Of course this assumes that the total number of transitions is correct; if it's not my code attempts to replace the 'missing' pulse(s). The two strategies together approximately halved the overall error rate here. Not perfect but worthwhile.

I'm certainly not going to translate my BBC BASIC code to ScriptBasic but the dialects are sufficiently similar that if you want to try these techniques it should be easy enough to adapt (these processing steps happen after the data are in a conventional array, so no indirection or other BBC BASIC-specific code is involved).

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

Re: ScriptBasic

Tue Jun 11, 2019 5:15 pm

Thanks Richard!

I'll take a peek at your pulse translator and see if it helps with ScriptBasic. For the most part I'm seeing a result on the first sampling.
Are you already taking advantage of the redundancy in the DHT11's data, as my BBC BASIC code does? This is "data correction" in a sense because you can derive effectively three sets of data from the raw read (two of which are independent) and use the checksum to determine which is right if they differ.
My sampling gets 40 bits of binary data after it's done parsing the raw data with @hippy's routine.

Are you saying you do 3 samples then return a binary result for integer building?

What I'm seeing causing most of the sample errors is data pulses that are shortened but not less then the number of high transition pulses. Shortened low pluses should always be considered as valid. It's the high pulse and transition pulses that needs a magic routine for. Late start samples can be corrected as well in most cases.

Valid binary data starts with a "1" before data bits are presented.

User avatar
bensimmo
Posts: 4065
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: ScriptBasic

Wed Jun 12, 2019 2:21 pm

If people use or don't use ScriptBasic, there are probably a few reading this thread and learning things they never knew.
There are probably people contributing that are doing the same.

RaspberryPi Foundation isn't all about the Pi Computer.

As long as you're having fun and enjoying it along along the way, why worry.
I'm pretty sure you've learnt a lot of things along the way. I certainly have, but then you're a far better programmer than me.
I just happen to know where a few documents and things are from helping and reading other threads that are of interest.

Among the About Us, go along with this.
We provide low-cost, high-performance computers that people use to learn, solve problems and have fun.
https://www.raspberrypi.org/about/

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

Re: ScriptBasic

Wed Jun 12, 2019 2:52 pm

What bothers me most is people refer to ScriptBasic as my BASIC. I didn't write it or have I contributed to Linux if the truth were known.

I started off with BASIC and have continued using it over the years. BASIC is about minimizing the steps to resolving any task before claiming it's a statement.

User avatar
bensimmo
Posts: 4065
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: ScriptBasic

Wed Jun 12, 2019 3:55 pm

From my point of view, I just see you as making it useful on the Pi, for whoever wishes to use it.

One though, if you use WiringPi, does that make it easier to port to Arduino type devices (that's an open question to anyone that knows).
I don't know what its benefits are over pigpio.

User avatar
rpdom
Posts: 14427
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: ScriptBasic

Wed Jun 12, 2019 4:01 pm

ScriptBasic wrote:
Wed Jun 12, 2019 2:52 pm
What bothers me most is people refer to ScriptBasic as my BASIC. I didn't write it or have I contributed to Linux if the truth were known.
Why is it named after you then?

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

Re: ScriptBasic

Wed Jun 12, 2019 4:31 pm

I'm just the ScriptBasic project manager / facilitator and someone to notify if things don't work as intended.

My name is John Spikowski not ScriptBasic. Feel free to address me by my first name here on the forum.

ejolson
Posts: 3039
Joined: Tue Mar 18, 2014 11:47 am

Re: ScriptBasic

Wed Jun 12, 2019 7:10 pm

ScriptBasic wrote:
Wed Jun 12, 2019 4:31 pm
My name is John Spikowski not ScriptBasic. Feel free to address me by my first name here on the forum.
With the permission of the forum moderators, it would be much clearer if you created a personal account such as "jspikowsky" and reserved ScriptBasic only for announcements of major new releases of that programming language.

As long as you don't carry on a conversation with yourself as two different people sock-puppet style, I suspect creating a personal account would be fine.

If a moderator doesn't comment here, maybe you could give them a heads-up when you create the personal account so there are no misunderstandings.

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

Re: ScriptBasic

Thu Jun 13, 2019 12:10 am

Or people can call me John if they wish to refer to me instead of ScriptBasic.

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

Re: ScriptBasic

Thu Jun 13, 2019 8:11 am

ScriptBasic wrote:
Thu Jun 13, 2019 12:10 am
Or people can call me John if they wish to refer to me instead of ScriptBasic.
I always have.

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

Re: ScriptBasic

Thu Jun 13, 2019 12:17 pm

As an aside, and the view from the BBC BASIC world would be interesting to hear -

WiringPi seems to use an on-chip timer peripheral for generating accurate microsecond timings below 100us, which is fair enough, but to access those timer peripherals one needs to use /dev/mem rather than just /dev/gpiomem, and that requires sudo. But no one is talking about using sudo.

So how are accurate short microsecond delays being achieved ?

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

Re: ScriptBasic

Thu Jun 13, 2019 12:43 pm

hippy wrote:
Thu Jun 13, 2019 12:17 pm
So how are accurate short microsecond delays being achieved ?
In the case of BBC BASIC, and I think of some other languages, simply through instruction timings. Accuracy isn't essential (my code, and some Python code I've seen, is 'self calibrating' in that it doesn't rely on any absolute delays). Consistency is quite important however and the RPi's habit of switching between 600 MHz and 1.2 GHz clocks is far from helpful! Boosting the thread's priority assists somewhat; locking the thread to a specific core probably would too but although I know how to do that in Windows I don't in Linux.

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

Re: ScriptBasic

Thu Jun 13, 2019 1:09 pm

Instruction timing was what I was thinking would be easiest.And I expect it would be possible to calibrate 'how many nops' during the 18ms reset period for DHT11, and explicitly for other cases, keep fingers crossed that timing holds true through the full sampling period.

I sill keep getting pulled towards running VPU/Scaler code on the VideoCore for better timing, and it may be enough just to do timing that way. But I guess grabbing samples into shared memory wouldn't actually be that much harder once one had it figured out.

The big unknown is whether /dev/gpiomem will continue to exist in the future, whether direct memory access will be disallowed, and everything has to be done through libgpiod. I am still in the early stages of investigating libgpiod because it will no doubt have implications with GPIO use and particularly timing.

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

Re: ScriptBasic

Thu Jun 13, 2019 1:26 pm

hippy wrote:
Thu Jun 13, 2019 12:17 pm
WiringPi seems to use an on-chip timer peripheral for generating accurate microsecond timings below 100us
I have just realised it's not quite that clear-cut. At -

https://projects.drogon.net/accurate-de ... spberry-pi

the use of the timer peripheral is described but, at line 2101 in what seems to be the actual code, that's not used -

https://github.com/WiringPi/WiringPi/bl ... wiringPi.c

Also, it seems, as there's no 'use peripheral polling or don't' test, it does peripheral polling regardless. I would have expected that to crash with a segfault if it wasn't run with sudo.

So, if anyone is calling WiringPi without using sudo, is invoking delayMicroseconds for less than 100us delays and it doesn't crash; it suggests it must be using a non-sudo means to do its timing.

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

Re: ScriptBasic

Thu Jun 13, 2019 1:54 pm

hippy wrote:
Thu Jun 13, 2019 1:09 pm
Instruction timing was what I was thinking would be easiest.And I expect it would be possible to calibrate 'how many nops' during the 18ms reset period for DHT11, and explicitly for other cases, keep fingers crossed that timing holds true through the full sampling period.
Rather than do that, my timing 'reference' is derived from the total 'low' time (in arbitrary units) of the DHT11's returned data (after the initial 80 μs). All the lows are the same length (nominally 50 μs) and there are exactly 41 of them, so dividing the total low time by 41 gives me the duration with which I compare the 'high' pulses (or twice that value when measuring between edges in the same direction). There should be less chance of the CPU clock switching frequency during the 5 ms data stream than the 18 + 5 ms total sampling period.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 22697
Joined: Sat Jul 30, 2011 7:41 pm

Re: ScriptBasic

Thu Jun 13, 2019 2:37 pm

hippy wrote:
Thu Jun 13, 2019 1:09 pm
The big unknown is whether /dev/gpiomem will continue to exist in the future, whether direct memory access will be disallowed, and everything has to be done through libgpiod. I am still in the early stages of investigating libgpiod because it will no doubt have implications with GPIO use and particularly timing.
Libraries that we ship rely on gpiomem. It's not going anywhere for the foreseeable future.

However, gpiolib is a better option.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

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

Re: ScriptBasic

Thu Jun 13, 2019 3:11 pm

So, if anyone is calling WiringPi without using sudo, is invoking delayMicroseconds for less than 100us delays and it doesn't crash; it suggests it must be using a non-sudo means to do its timing.
If ScriptBasic is installed in its traditional way, scriba is in /usr/local/bin with root privileges. Like Peal, Python, ... scripting engines.

User avatar
rpdom
Posts: 14427
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: ScriptBasic

Thu Jun 13, 2019 3:31 pm

ScriptBasic wrote:
Thu Jun 13, 2019 3:11 pm
If ScriptBasic is installed in its traditional way, scriba is in /usr/local/bin with root privileges. Like Peal, Python, ... scripting engines.
Python and (I assume you mean) Perl etc. are usually installed in /usr/bin and although owned by root, don't have any special privileges.

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

Re: ScriptBasic

Thu Jun 13, 2019 3:42 pm

ScriptBasic wrote:
Thu Jun 13, 2019 3:11 pm
If ScriptBasic is installed in its traditional way, scriba is in /usr/local/bin with root privileges. Like Peal, Python, ... scripting engines.
That had me worried for a moment but it seems I am safe -

Code: Select all

pi@Pi3B:~ $ ls -l /usr/local/bin/scriba
-rwxr-xr-x 1 pi pi 637104 Mar 30 20:56 /usr/local/bin/scriba
Python, and I would guess Perl or any other interpreters, do not, would not, have root privileges.

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

Re: ScriptBasic

Thu Jun 13, 2019 3:49 pm

jamesh wrote:
Thu Jun 13, 2019 2:37 pm
Libraries that we ship rely on gpiomem. It's not going anywhere for the foreseeable future.
I would expect that; it was more what happens beyond the "foreseeable", how far that extends to. But I wouldn't expect to be told anything other than as you have. It's good to know anyway.

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

Re: ScriptBasic

Thu Jun 13, 2019 3:54 pm

RichardRussell wrote:
Thu Jun 13, 2019 1:54 pm
Rather than do that, my timing 'reference' is derived from the total 'low' time (in arbitrary units) of the DHT11's returned data (after the initial 80 μs)
Yes, 'any timing as long as quick enough' will do for the DHT11, we can determine what the timing was from the samples. It was more how to deal with hardware which needs more than just sampling, needs reasonable timing accuracy on sending for example.

Return to “Other programming languages”