From 2ace6ddb837ad66912ed7ad6a15e6aad6acce652 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:17:20 +0200 Subject: [PATCH 01/10] Update example according to bug #148 --- _build/pages/features.markdown | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/_build/pages/features.markdown b/_build/pages/features.markdown index e16445af..442a94f6 100644 --- a/_build/pages/features.markdown +++ b/_build/pages/features.markdown @@ -22,22 +22,28 @@ The SDL version now allow the window geometry to be set from your program. User defined structures in SmallBASIC are a form of compound variable allowing individual elements to be referenced. -The following example loads the system password table and prints the contents: +The following example loads the system password table and prints the contents of the first user (works only in Linux): ~~~ tload "/etc/passwd", buffer + +dim users + for row in buffer + split row, ":", fields() - if (len(fields) > 0) then + + if (ubound(fields) > 0) then local user user.name = fields(0) user.passwd = fields(1) user.userId = fields(2) user.groupId = fields(3) - users << user + users << user fi next row -? users + +print users(0) ~~~ ## Associative arrays ## @@ -48,19 +54,26 @@ The following example loads the system password table then prints the groupID va ~~~ tload "/etc/passwd", buffer -dim users + +users = {} + for row in buffer + split row, ":", fields() - if (len(fields) > 0) then + + if (ubound(fields) > 0) then local user user.name = fields(0) user.passwd = fields(1) user.userId = fields(2) user.groupId = fields(3) + users(user.name) = user + fi next row -? users("mail").userId + +print users("mail").userId ~~~ ## Unit name pathing ## From f766a6722f32c74ab77c773016d556dc7add44c3 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:27:28 +0200 Subject: [PATCH 02/10] Update link --- _build/pages/sdl.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_build/pages/sdl.markdown b/_build/pages/sdl.markdown index 44f4ca3a..58977c21 100644 --- a/_build/pages/sdl.markdown +++ b/_build/pages/sdl.markdown @@ -37,7 +37,7 @@ You can now press `F6` to step through program lines, or `F7` to continue. The p 2. Adobe Source Code Pro -- Download +- Download https://www.1001fonts.com/download/source-code-pro.zip - Unzip and copy SourceCodePro-Regular.ttf and SourceCodePro-Bold.ttf into the same folder as sbasicg.exe. From 68215b06c8c480dec3f01d4bd285354cbd0d858a Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:33:40 +0200 Subject: [PATCH 03/10] Add setLocation() --- _build/reference/624-graphics-window.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/_build/reference/624-graphics-window.markdown b/_build/reference/624-graphics-window.markdown index 5323e625..ade66462 100644 --- a/_build/reference/624-graphics-window.markdown +++ b/_build/reference/624-graphics-window.markdown @@ -155,6 +155,16 @@ text "that can save her people and restore" text "freedom to the galaxy...." ``` +### setLocation(x, y) + +Sets the location of the window on the screen. + +``` +w = window() +w.setLocation(100, 100) +``` + + ### setSize(w, h) Sets the width and height of the SmallBASIC window. From 91f1b2c7f52f86adf6778ca048ab810dd2e5df2c Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Fri, 28 Oct 2022 19:37:20 +0200 Subject: [PATCH 04/10] fixed example for in operator --- _build/pages/features.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_build/pages/features.markdown b/_build/pages/features.markdown index 442a94f6..cf4b13a4 100644 --- a/_build/pages/features.markdown +++ b/_build/pages/features.markdown @@ -99,9 +99,9 @@ The unit file would be saved in $UNITPATH/other/something. If not defined, $UNIT When applied to arrays the IN operator now returns the 1 based index position, for example: ~~~ -a << "cat" -a << "dog" -? "dog" in a 'prints 2 +a << "cat" +a << "dog" +print "dog" in a ' prints 2 ~~~ ## Logical expression short-circuit evaluation ## From ceb079901cc455fdd74e8c6664bfcc9483afd3cb Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:27:08 +0100 Subject: [PATCH 05/10] Article for SmallBASIC-PiGPIO plugin --- _build/pages/SmallBASICPiGPIO.markdown | 165 +++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 _build/pages/SmallBASICPiGPIO.markdown diff --git a/_build/pages/SmallBASICPiGPIO.markdown b/_build/pages/SmallBASICPiGPIO.markdown new file mode 100644 index 00000000..60f753ef --- /dev/null +++ b/_build/pages/SmallBASICPiGPIO.markdown @@ -0,0 +1,165 @@ +# SmallBASICPiGPIO - Plugin to use the GPIO pins of a Raspberry Pi + +![Logo](https://joe7m.github.io/SmallBasicPIGPIO/images/logo_smallbasicpigpio.png) + +SmallBASIC-PiGPIO is a plugin for SmallBASIC to use the GPIO connector of a Raspberry Pi. The following article will give you a short introduction of the plugin. Detailed information is available on the [project website](https://joe7m.github.io/SmallBasicPIGPIO) + +## Blinking LED + +In this example we will connect a LED to the Raspberry Pi and let it blink with a short SmallBASIC program. + + +### Wiring + +The wiring of the LED is shown in the following image + +![LED wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/LED_wiring.png) + +Depending on the type of the LED you need a certain resistor. When using the LED without a resistor, you will destroy the LED and maybe even parts of your Raspberry Pi. If you want to see your LED blinking without studying to much and you don’t expect maximum brightness, then go for a resistor with 220 Ohms or even (saver) 1000 Ohms. + +Connect the resistor to pin 4 and the LED to ground of the Raspberry Pi. + +### Software + +To let the LED blink the following SmallBASIC program can be used. + +``` +import SmallBasicPIGPIO as gpio + +' LED is connected to pin GPIO4 +const PIN_GPIO4 = 4 + +' Set pin as an output +gpio.GPIO_SetOutput(PIN_GPIO4) + +for ii = 1 to 5 + print(ii) + 'Set GPIO pin to high -> 3.3V + gpio.GPIO_Write(PIN_GPIO4, 1) + delay(500) + 'Set GPIO pin to low -> ground + gpio.GPIO_Write(PIN_GPIO4, 0) + delay(500) +next +``` + +The plugin supports Pulse Width Modulation (PWM). Using this technique the intensity of the LED can tuned as shown in the next example. + +``` +import SmallBasicPIGPIO as gpio + +' LED is connected to pin GPIO4 +const PIN_GPIO4 = 4 + +' Set pin as an output +gpio.GPIO_SetOutput(PIN_GPIO4) + +' Duty cycle is a value between 0 and 255. +' 0 -> LED is off +' 128 -> LED half brightness +' 255 -> LED max. brightness + +for DutyCycle = 0 to 255 step 20 + print(DutyCycle) + gpio.GPIO_Pwm(PIN_GPIO4, DutyCycle) + delay(200) +next +``` + +## Push Buttons + +Reading the state of a push button is for many Raspberry Pi project important and really easy with SmallBASIC PiGPIO. + +### Wiring + +In the following image you see the wiring of a push button. When you press the button, the circuit will be closed, otherwise the circuit is open. The button is connected to pin 4 and ground of the Raspberry Pi. An internal pullup resistor will be enabled automatically. + +![Button wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/PushButton_wiring.png) + +### Software + +To read the state of the button, the following example program can be used. + +``` +import SmallBasicPIGPIO as gpio + +const PIN_GPIO4 = 4 + +' Set GPIO pin 4 to INPUT. When a pin is set to input, +' the internal pullup resistor will be enabled automaticly +gpio.GPIO_SetInput(PIN_GPIO4) + +repeat + key = inkey() + + ' Read the state of the pin. It will return 0 or 1. + status = gpio.GPIO_Read(PIN_GPIO4) + locate 1,1: print(status) + + showpage() + delay(50) + +until key <> "" +``` + +## OLED Display + +In case the Raspberry Pi is used without a big Screen, it would be great to have a small Display to print information or even show nice graphics. The plugin supports SSD1306 compatible OLED displays (quite common and really cheap). + +### Wiring + +For running this example, you need a SSD1306 compatible OLED display. OLEDs with 128x64 or 128x32 pixels are supported. SmallBASICPiGPIO is using the I2C-protocol for communication. + +![OLED wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/ssd1306_wiring.png) + +### Software + +The following example shows how to use basic graphic commands to draw lines or print text. + +``` +import SmallBasicPIGPIO as gpio + +gpio.OLED1_Open() + +gpio.OLED1_SetBrightness(128) + +gpio.OLED1_Cls() + +gpio.OLED1_Pset(10,0) +gpio.OLED1_Line(0,0,127,63) +gpio.OLED1_RoundRect(54,26,74,38,5) +gpio.OLED1_Circle(118,10,5,1,1) 'Filled with white +gpio.OLED1_Triangle(118,30, 113,45, 123,45, 1, 1) 'Filled with white + +gpio.OLED1_At(0,56) +gpio.OLED1_SetTextSize(16) +gpio.OLED1_Print("SmallBASIC") + +delay(2000) +gpio.OLED1_Close() + +print("Done") +``` + +# Supported Hardware + +The SmallBASIC PiGPIO pluging supports the following hardware. Support for more sensors and displays is planned. + +- LED +- Push Button +- DS18B20 Temperature Sensor +- HD44780 Text LCD Display +- SSD1306 OLED Display +- BH1750 Ambient Light Sensor +- ADS1015 and ADS1115 Voltage Sensor +- SCD30 CO2, Temperature and Humidity Sensor + +# Links + +- [SmallBASIC PiGPIO project website](https://joe7m.github.io/SmallBasicPIGPIO/) +- [Github repository](https://github.com/Joe7M/SmallBasicPIGPIO) +- [Feedback and discussion](https://github.com/Joe7M/SmallBasicPIGPIO/discussions) +- [SmallBASIC website](https://smallbasic.github.io/) +- [SmallBASIC forum](https://www.syntaxbomb.com/smallbasic/) + + From f6927a6f754f0288ad0e97e03e0e27c00b4b10b2 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:45:38 +0100 Subject: [PATCH 06/10] Update SmallBASICPiGPIO.markdown --- _build/pages/SmallBASICPiGPIO.markdown | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/_build/pages/SmallBASICPiGPIO.markdown b/_build/pages/SmallBASICPiGPIO.markdown index 60f753ef..77f0f5ac 100644 --- a/_build/pages/SmallBASICPiGPIO.markdown +++ b/_build/pages/SmallBASICPiGPIO.markdown @@ -1,8 +1,8 @@ -# SmallBASICPiGPIO - Plugin to use the GPIO pins of a Raspberry Pi +# SmallBASIC-PiGPIO - Plugin to use the GPIO pins of a Raspberry Pi ![Logo](https://joe7m.github.io/SmallBasicPIGPIO/images/logo_smallbasicpigpio.png) -SmallBASIC-PiGPIO is a plugin for SmallBASIC to use the GPIO connector of a Raspberry Pi. The following article will give you a short introduction of the plugin. Detailed information is available on the [project website](https://joe7m.github.io/SmallBasicPIGPIO) +SmallBASIC-PiGPIO is a plugin for SmallBASIC to use the GPIO connector of a Raspberry Pi. The following article will give you a short introduction to the plugin. Detailed information is available on the [project website](https://joe7m.github.io/SmallBasicPIGPIO) ## Blinking LED @@ -23,7 +23,7 @@ Connect the resistor to pin 4 and the LED to ground of the Raspberry Pi. To let the LED blink the following SmallBASIC program can be used. -``` +```freebasic import SmallBasicPIGPIO as gpio ' LED is connected to pin GPIO4 @@ -45,7 +45,7 @@ next The plugin supports Pulse Width Modulation (PWM). Using this technique the intensity of the LED can tuned as shown in the next example. -``` +```freebasic import SmallBasicPIGPIO as gpio ' LED is connected to pin GPIO4 @@ -80,7 +80,7 @@ In the following image you see the wiring of a push button. When you press the b To read the state of the button, the following example program can be used. -``` +```freebasic import SmallBasicPIGPIO as gpio const PIN_GPIO4 = 4 @@ -104,11 +104,11 @@ until key <> "" ## OLED Display -In case the Raspberry Pi is used without a big Screen, it would be great to have a small Display to print information or even show nice graphics. The plugin supports SSD1306 compatible OLED displays (quite common and really cheap). +In case the Raspberry Pi is used without a big screen, it would be great to have a small display to print information or even show nice graphics. The plugin supports SSD1306 compatible OLED displays (quite common and really cheap). ### Wiring -For running this example, you need a SSD1306 compatible OLED display. OLEDs with 128x64 or 128x32 pixels are supported. SmallBASICPiGPIO is using the I2C-protocol for communication. +For running this example, you need a SSD1306 compatible OLED display. OLEDs with 128x64 or 128x32 pixels are supported. SmallBASIC-PiGPIO is using the I2C-protocol for communication. ![OLED wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/ssd1306_wiring.png) @@ -116,7 +116,7 @@ For running this example, you need a SSD1306 compatible OLED display. OLEDs with The following example shows how to use basic graphic commands to draw lines or print text. -``` +```freebasic import SmallBasicPIGPIO as gpio gpio.OLED1_Open() @@ -143,7 +143,7 @@ print("Done") # Supported Hardware -The SmallBASIC PiGPIO pluging supports the following hardware. Support for more sensors and displays is planned. +The SmallBASIC-PiGPIO plugin supports the following hardware. Support for more sensors and displays is planned. - LED - Push Button From cf79ce2b2381ef7bf643174c8522e0fa8888989f Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:46:07 +0100 Subject: [PATCH 07/10] Rename SmallBASICPiGPIO.markdown to plugins_pigpio.markdown --- .../pages/{SmallBASICPiGPIO.markdown => plugins_pigpio.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename _build/pages/{SmallBASICPiGPIO.markdown => plugins_pigpio.markdown} (100%) diff --git a/_build/pages/SmallBASICPiGPIO.markdown b/_build/pages/plugins_pigpio.markdown similarity index 100% rename from _build/pages/SmallBASICPiGPIO.markdown rename to _build/pages/plugins_pigpio.markdown From 92056c7dd53f13008b8e4bd9b4f6215ae1099611 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:47:54 +0100 Subject: [PATCH 08/10] Update articles.markdown --- _build/pages/articles.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/_build/pages/articles.markdown b/_build/pages/articles.markdown index f0fc3198..69f2d100 100644 --- a/_build/pages/articles.markdown +++ b/_build/pages/articles.markdown @@ -25,6 +25,7 @@ - [Nuklear: Create your own graphical user interface](/pages/plugins_nuklear.html) - [Clipboard: Copy and paste](/pages/plugins_clipboard.html) - [GIFenc: create animated GIFs](/pages/plugins_gifenc.html) +- [PiGPIO: Use the GPIO pins of a Raspberry Pi](/pages/plugins_pigpio.html) ## Miscellaneous ## From 68ddf11652a402d8cfc3702fbdb6a35c53445e8b Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 6 Nov 2022 22:28:10 +0100 Subject: [PATCH 09/10] Update 768-string-sinput.markdown --- _build/reference/768-string-sinput.markdown | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/_build/reference/768-string-sinput.markdown b/_build/reference/768-string-sinput.markdown index e9887dca..f6095dbc 100644 --- a/_build/reference/768-string-sinput.markdown +++ b/_build/reference/768-string-sinput.markdown @@ -5,9 +5,15 @@ Splits the string 'src' into variables which are separated by delimiters. ``` -SINPUT "if x>1 then y"; vif, " ", vcond, "then", vdo -? vcond, vdo -' result= -' x>1 y +src = "if x>1 then y" +SINPUT src; vif, " ", vcond, "then", vdo +print vif, vcond, vdo ' output: if x>1 y ``` +``` +src = "1456,Peter,8" +SINPUT src; id, ",", name, ",", age +print "ID: " + id +print "Name: " + name +print "Age: " + age +``` From 2a46518fbd0f47d09b74fc46361cf340816eabe6 Mon Sep 17 00:00:00 2001 From: Joerg Siebenmorgen <82510480+Joe7M@users.noreply.github.com> Date: Sun, 6 Nov 2022 22:59:25 +0100 Subject: [PATCH 10/10] Update 769-string-split.markdown --- _build/reference/769-string-split.markdown | 44 ++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/_build/reference/769-string-split.markdown b/_build/reference/769-string-split.markdown index 59f46282..2cf8fd76 100644 --- a/_build/reference/769-string-split.markdown +++ b/_build/reference/769-string-split.markdown @@ -2,23 +2,53 @@ > SPLIT string, delimiters, words() [, pairs] [USE expr] -Returns the words of the specified string into array 'words'. +Splits "string" at the position of the given delimiters and returns the words of the specified string into array 'words'. "pairs" can be used to group words. "Use expr" is applied to every splitted word. ``` s="/etc/temp/filename.ext" -SPLIT s, "/.", v() +SPLIT s, "/.", v() ' Splits the string using the delimiters "/" and "." FOR i=0 TO UBOUND(v) PRINT i;" [";v(i);"]" NEXT + +' displays: +' 0 [] +' 1 [etc] +' 2 [temp] +' 3 [filename] +' 4 [ext] ``` -displays: +Example for using the argument "pairs" ``` +s = "/etc/temp/filename.ext" +SPLIT s, "/", v(), "temp" +FOR i = 0 TO UBOUND(v) + PRINT i;" [";v(i);"]" +NEXT + +' Display 0 [] -1 [etc] -2 [temp] -3 [filename] -4 [ext] +1 [etc/temp] +2 [filename.ext] +``` + +Example for using "USE expr" + +``` +s = "/etc/temp/filename1.ext " ' additional spaces at the end of the string +SPLIT s, "/", v(), "temp" USE TRIM(x) ' trim(x) will remove spaces at the beginning + ' and the end of the splitted strings; + ' try the example without "USE TRIM(x)" +FOR i = 0 TO UBOUND(v) + PRINT i;" [";v(i);"]" +NEXT + +' displays +' 0 [] +' 1 [etc/temp] +' 2 [filename1.ext] ``` +