Skip to content

Commit d31d579

Browse files
authored
Merge pull request #43 from Joe7M/master
Update PiGPIO documentation
2 parents 6404867 + a93453e commit d31d579

File tree

3 files changed

+225
-190
lines changed

3 files changed

+225
-190
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,51 @@
11
# smallbasic.github.io
2-
SmallBASIC github pages
2+
3+
SmallBASIC Github pages
4+
5+
## Edit files the easy way
6+
7+
If you want to edit the SmallBASIC website because information is missing, examples
8+
are not clear enough or maybe just to correct a typo, you can do it quite easy.
9+
10+
All website pages are written in Markdown. The files are located in:
11+
12+
- `_build/pages` : Almost all web pages
13+
- `_build/reference`: The command reference
14+
15+
To start editing:
16+
17+
1. Create a Github account.
18+
2. Fork smallbasic.github.io.
19+
3. Change to the forked version in your account.
20+
4. Edit a `.markdown` file directly in Github in your browser.
21+
5. Save the file and let Github make a commit.
22+
6. Start a pull-request.
23+
7. We will merge your changes or give you feedback how to proceed. Please don't
24+
worry. Even if you make a mistake, we will help you. We are happy for everyone
25+
who wants to participate.
26+
27+
## Build instructions for Linux:
28+
29+
- Install SmallBASIC console version (sbasic)
30+
- Optional: Install SmallBASIC web server (sbasicw)
31+
- Install pandoc
32+
- Execute the following commands:
33+
34+
```
35+
git clone https://github.com/smallbasic/smallbasic.github.io.git
36+
git clone https://github.com/smallbasic/smallbasic.samples.git
37+
cd smallbasic.github.io/_build
38+
export SAMPLE = PATH_TO_SMALLBASIC_SAMPLES
39+
make clean
40+
make
41+
```
42+
43+
`PATH_TO_SMALLBASIC_SAMPLES` is the absolute path to the sample
44+
directory, i.e. `/home/userxyz/smallbasic.samples`
45+
46+
The SmallBASIC static website can be found in the root directory of
47+
the smallbasic.github.io folder. To access the website locally
48+
use the SmallBASIC webserver: `sbasicw index.html` (or other
49+
webservers like the python http-server: `python -m http.server 8080`).
50+
In the browser type: `http://127.0.0.1:8080`.
51+

_build/pages/plugins_pigpio.markdown

Lines changed: 96 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,79 @@
22

33
![Logo](https://joe7m.github.io/SmallBasicPIGPIO/images/logo_smallbasicpigpio.png)
44

5-
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)
5+
SmallBASIC-PiGPIO is a plugin for SmallBASIC to use the GPIO connector of a Raspberry Pi.
6+
The following article will give you a short introduction to the plugin. Detailed information
7+
is available on the [project website](https://joe7m.github.io/smallbasic.pigpio2/index.html)
68

79
## Blinking LED
810

9-
In this example we will connect a LED to the Raspberry Pi and let it blink with a short SmallBASIC program.
10-
11+
In this example we will connect a LED to the Raspberry Pi and let it blink with a short#
12+
SmallBASIC program.
1113

1214
### Wiring
1315

1416
The wiring of the LED is shown in the following image
1517

1618
![LED wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/LED_wiring.png)
1719

18-
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.
20+
Depending on the type of the LED you need a certain resistor. When using the LED without
21+
a resistor, you will destroy the LED and maybe even parts of your Raspberry Pi. If you
22+
want to see your LED blinking without studying to much and you don’t expect maximum
23+
brightness, then go for a resistor with 220 Ohms or even (saver) 1000 Ohms.
1924

20-
Connect the resistor to pin 4 and the LED to ground of the Raspberry Pi.
25+
Connect the resistor to pin 7 (GPIO4) and the LED to ground of the Raspberry Pi.
2126

2227
### Software
2328

2429
To let the LED blink the following SmallBASIC program can be used.
2530

2631
```smallbasic
27-
import SmallBasicPIGPIO as gpio
28-
29-
' LED is connected to pin GPIO4
30-
const PIN_GPIO4 = 4
31-
32-
' Set pin as an output
33-
gpio.GPIO_SetOutput(PIN_GPIO4)
34-
35-
for ii = 1 to 5
36-
print(ii)
37-
'Set GPIO pin to high -> 3.3V
38-
gpio.GPIO_Write(PIN_GPIO4, 1)
39-
delay(500)
40-
'Set GPIO pin to low -> ground
41-
gpio.GPIO_Write(PIN_GPIO4, 0)
42-
delay(500)
43-
next
44-
```
45-
46-
The plugin supports Pulse Width Modulation (PWM). Using this technique the intensity of the LED can tuned as shown in the next example.
32+
import gpio
4733
48-
```smallbasic
49-
import SmallBasicPIGPIO as gpio
34+
gpio.Open()
35+
gpio.SetOutput(4)
5036
51-
' LED is connected to pin GPIO4
52-
const PIN_GPIO4 = 4
37+
for ii = 1 to 10
38+
v = !v
39+
gpio.Write(4, v)
40+
delay(100)
41+
next
5342
54-
' Set pin as an output
55-
gpio.GPIO_SetOutput(PIN_GPIO4)
43+
print "done"
44+
```
5645

57-
' Duty cycle is a value between 0 and 255.
58-
' 0 -> LED is off
59-
' 128 -> LED half brightness
60-
' 255 -> LED max. brightness
46+
The plugin supports Pulse Width Modulation (PWM). Using this technique the intensity
47+
of the LED can be tuned as shown in the next example. Connect a LED with a 1 KOhm
48+
resistor to pin 12 (PWM0)
49+
' and pin 6 (GND)
6150

62-
for DutyCycle = 0 to 255 step 20
63-
print(DutyCycle)
64-
gpio.GPIO_Pwm(PIN_GPIO4, DutyCycle)
65-
delay(200)
51+
```smallbasic
52+
import pwm
53+
54+
' Initialize
55+
pwm.open("pwmchip0")
56+
pwm.Period(1000000) ' in ns -> 1kHz
57+
pwm.DutyCycle(0) ' Active time in ns -> 0 = off
58+
pwm.Enable() ' enable pwm0
59+
60+
' Fade from dark to bright
61+
for ii = 1 to 1000000 Step 10000
62+
pwm.DutyCycle(ii)
63+
delay(10)
6664
next
6765
```
6866

6967
## Push Buttons
7068

71-
Reading the state of a push button is for many Raspberry Pi project important and really easy with SmallBASIC PiGPIO.
69+
Reading the state of a push button is for many Raspberry Pi project important and
70+
really easy with SmallBASIC PiGPIO.
7271

7372
### Wiring
7473

75-
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.
74+
In the following image you see the wiring of a push button. When you press the button,
75+
the circuit will be closed, otherwise the circuit is open. The button is connected to
76+
pin 4 and ground of the Raspberry Pi. An internal pullup resistor will be enabled
77+
automatically.
7678

7779
![Button wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/PushButton_wiring.png)
7880

@@ -81,85 +83,84 @@ In the following image you see the wiring of a push button. When you press the b
8183
To read the state of the button, the following example program can be used.
8284

8385
```smallbasic
84-
import SmallBasicPIGPIO as gpio
85-
86-
const PIN_GPIO4 = 4
87-
88-
' Set GPIO pin 4 to INPUT. When a pin is set to input,
89-
' the internal pullup resistor will be enabled automaticly
90-
gpio.GPIO_SetInput(PIN_GPIO4)
91-
92-
repeat
93-
key = inkey()
94-
95-
' Read the state of the pin. It will return 0 or 1.
96-
status = gpio.GPIO_Read(PIN_GPIO4)
97-
locate 1,1: print(status)
98-
99-
showpage()
100-
delay(50)
101-
102-
until key <> ""
86+
import gpio
87+
88+
gpio.Open()
89+
gpio.SetInput(4)
90+
91+
while(1)
92+
print gpio.Read(4)
93+
delay(500)
94+
wend
10395
```
10496

10597
## OLED Display
10698

107-
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).
99+
In case the Raspberry Pi is used without a big screen, it would be great to have a
100+
small display to print information or even show nice graphics. The plugin supports
101+
SSD1306 compatible OLED displays (quite common and really cheap).
108102

109103
### Wiring
110104

111-
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.
105+
For running this example, you need a SSD1306 compatible OLED display. OLEDs with
106+
128x64 or 128x32 pixels are supported. SmallBASIC-PiGPIO is using the I2C-protocol
107+
for communication.
112108

113109
![OLED wiring](https://joe7m.github.io/SmallBasicPIGPIO/images/ssd1306_wiring.png)
114110

115111
### Software
116112

117-
The following example shows how to use basic graphic commands to draw lines or print text.
113+
The following example shows how to use basic graphic commands to draw lines or print
114+
text.
118115

119116
```smallbasic
120-
import SmallBasicPIGPIO as gpio
121-
122-
gpio.OLED1_Open()
123-
124-
gpio.OLED1_SetBrightness(128)
117+
import ssd1306
125118
126-
gpio.OLED1_Cls()
119+
const ADDRESS = 0x3C
127120
128-
gpio.OLED1_Pset(10,0)
129-
gpio.OLED1_Line(0,0,127,63)
130-
gpio.OLED1_RoundRect(54,26,74,38,5)
131-
gpio.OLED1_Circle(118,10,5,1,1) 'Filled with white
132-
gpio.OLED1_Triangle(118,30, 113,45, 123,45, 1, 1) 'Filled with white
133-
134-
gpio.OLED1_At(0,56)
135-
gpio.OLED1_SetTextSize(16)
136-
gpio.OLED1_Print("SmallBASIC")
121+
Print "Connect to SSD1306 OLED display"
122+
ssd1306.Open("/dev/i2c-1", ADDRESS)
123+
Print "Connection established"
137124
138125
delay(2000)
139-
gpio.OLED1_Close()
126+
ssd1306.Cls()
127+
ssd1306.Circle(25, 40, 16, 1, true)
128+
ssd1306.At(50,5): ssd1306.Print("I2C with", 1)
129+
ssd1306.At(50,14): ssd1306.Print("SMALLBASIC", 1)
130+
ssd1306.line(0, 0, 127, 63)
131+
ssd1306.rect(0,0,127,63)
132+
133+
' Transfer framebuffer to display
134+
s = ticks
135+
ssd1306.Display()
136+
print ticks - s
137+
delay(2000)
140138
141-
print("Done")
142-
```
139+
' Set brightness
140+
ssd1306.SetBrightness(20)
141+
delay(1000)
142+
ssd1306.SetBrightness(255)
143+
delay(1000)
143144
144-
# Supported Hardware
145+
' Display on/off
146+
ssd1306.DisplayOff()
147+
delay(1000)
148+
ssd1306.DisplayOn()
149+
delay(1000)
145150
146-
The SmallBASIC-PiGPIO plugin supports the following hardware. Support for more sensors and displays is planned.
151+
' Set inverse
152+
ssd1306.InvertDisplay()
153+
delay(1000)
154+
ssd1306.InvertDisplay()
147155
148-
- LED
149-
- Push Button
150-
- DS18B20 Temperature Sensor
151-
- HD44780 Text LCD Display
152-
- SSD1306 OLED Display
153-
- BH1750 Ambient Light Sensor
154-
- ADS1015 and ADS1115 Voltage Sensor
155-
- SCD30 CO2, Temperature and Humidity Sensor
156+
print "done"
157+
```
156158

157159
# Links
158160

159-
- [SmallBASIC PiGPIO project website](https://joe7m.github.io/SmallBasicPIGPIO/)
160-
- [Github repository](https://github.com/Joe7M/SmallBasicPIGPIO)
161-
- [Feedback and discussion](https://github.com/Joe7M/SmallBasicPIGPIO/discussions)
161+
- [SmallBASIC PiGPIO project website](https://joe7m.github.io/smallbasic.pigpio2/index.html)
162+
- [Github repository](https://github.com/Joe7M/smallbasic.pigpio2)
163+
- [Feedback and discussion](https://smallbasic.discourse.group/)
162164
- [SmallBASIC website](https://smallbasic.github.io/)
163-
- [SmallBASIC forum](https://www.syntaxbomb.com/smallbasic/)
164165

165166

0 commit comments

Comments
 (0)