You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Adding content
* Update en.json
* Update README.md
* Update TRANSLATIONS.md
* Adding lesson tempolates
* Fixing code files with each others code in
* Update README.md
* Migrating to sunlight sensor at the request of seeed
* More on sunlight sensor
Copy file name to clipboardexpand all lines: 1-getting-started/lessons/1-introduction-to-iot/pi.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ If you are using a Raspberry Pi as your IoT hardware, you have two choices - you
12
12
13
13
Before you begin, you also need to connect the Grove Base Hat to your Pi.
14
14
15
-
### Task
15
+
### Task - setup
16
16
17
17
Install the Grove base hat on your Pi and configure the Pi
18
18
@@ -29,7 +29,7 @@ Install the Grove base hat on your Pi and configure the Pi
29
29
30
30
If you want to work directly on your Pi, you can use the desktop version of Raspberry Pi OS and install all the tools you need.
31
31
32
-
#### Task
32
+
#### Task - work directly on your Pi
33
33
34
34
Set up your Pi for development.
35
35
@@ -79,7 +79,7 @@ Rather than coding directly on the Pi, it can run 'headless', that is not connec
79
79
80
80
To code remotely, the Pi OS needs to be installed on an SD Card.
81
81
82
-
##### Task
82
+
##### Task - set up the Pi OS
83
83
84
84
Set up the headless Pi OS.
85
85
@@ -115,7 +115,7 @@ The OS will be written to the SD card, and once compete the card will be ejected
115
115
116
116
The next step is to remotely access the Pi. You can do this using `ssh`, which is available on macOS, Linux and recent versions of Windows.
117
117
118
-
##### Task
118
+
##### Task - connect to the Pi
119
119
120
120
Remotely access the Pi.
121
121
@@ -147,7 +147,7 @@ Remotely access the Pi.
147
147
148
148
Once you are connected to the Pi, you need to ensure the OS is up to date, and install various libraries and tools that interact with the Grove hardware.
149
149
150
-
##### Task
150
+
##### Task - configure software on the Pi
151
151
152
152
Configure the installed Pi software and install the Grove libraries.
153
153
@@ -179,7 +179,7 @@ Configure the installed Pi software and install the Grove libraries.
179
179
180
180
Once the Pi is configured, you can connect to it using Visual Studio Code (VS Code) from your computer - this is a free developer text editor you will be using to write your device code in Python.
181
181
182
-
##### Task
182
+
##### Task - configure VS Code for remote access
183
183
184
184
Install the required software and connect remotely to your Pi.
185
185
@@ -199,7 +199,7 @@ The Hello World app for the Pi will ensure that you have Python and Visual Studi
199
199
200
200
This app will be in a folder called `nightlight`, and it will be re-used with different code in later parts of this assignment to build the nightlight application.
Copy file name to clipboardexpand all lines: 1-getting-started/lessons/1-introduction-to-iot/virtual-device.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ Create a Python application to print `"Hello World"` to the console.
120
120
code .
121
121
```
122
122
123
-
> 💁 If your terminal returns `command not found` on macOS it means VS Code has not been added to PATH, you can add VS Code to PATH by following the instructions in the [Launching from the command line section of the VS Code documentation](https://code.visualstudio.com/docs/setup/mac?WT.mc_id=academic-17441-jabenn#_launching-from-the-command-line) and run the command afterwards. VS Code is installed to PATH by default on Windows and Linux.
123
+
> 💁 If your terminal returns `command not found` on macOS it means VS Code has not been added to your PATH. You can add VS Code to yout PATH by following the instructions in the [Launching from the command line section of the VS Code documentation](https://code.visualstudio.com/docs/setup/mac?WT.mc_id=academic-17441-jabenn#_launching-from-the-command-line) and run the command afterwards. VS Code is installed to your PATH by default on Windows and Linux.
124
124
125
125
1. When VS Code launches, it will activate the Python virtual environment. You will see this in the bottom status bar:
Copy file name to clipboardexpand all lines: 1-getting-started/lessons/1-introduction-to-iot/wio-terminal.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The [Wio Terminal from Seeed Studios](https://www.seeedstudio.com/Wio-Terminal-p
8
8
9
9
To use your Wio Terminal, you will need to install some free software on your computer. You will also need to update the Wio Terminal firmware before you can connect it to WiFi.
10
10
11
-
### Task
11
+
### Task - setup
12
12
13
13
Install the required software and update the firmware.
14
14
@@ -32,7 +32,7 @@ The Hello World app for the Wio Terminal will ensure that you have Visual Studio
32
32
33
33
The first step is to create a new project using PlatformIO configured for the Wio Terminal.
34
34
35
-
#### Task
35
+
#### Task - create a PlatformIO project
36
36
37
37
Create the PlatformIO project.
38
38
@@ -122,7 +122,7 @@ The VS Code explorer will show a number of files and folders created by the Plat
Copy file name to clipboardexpand all lines: 1-getting-started/lessons/3-sensors-and-actuators/pi-actuator.md
+9-7
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ The nightlight logic in pseudo-code is:
12
12
13
13
```output
14
14
Check the light level.
15
-
If the light is less than 200
15
+
If the light is less than 300
16
16
Turn the LED on
17
17
Otherwise
18
18
Turn the LED off
@@ -22,7 +22,7 @@ Otherwise
22
22
23
23
The Grove LED comes as a module with a selection of LEDs, allowing you to chose the color.
24
24
25
-
#### Task
25
+
#### Task - connect the LED
26
26
27
27
Connect the LED.
28
28
@@ -44,9 +44,9 @@ Connect the LED.
44
44
45
45
## Program the nightlight
46
46
47
-
The nightlight can now be programmed using the Grove light sensor and the Grove LED.
47
+
The nightlight can now be programmed using the Grove sunlight sensor and the Grove LED.
48
48
49
-
### Task
49
+
### Task - program the nightlight
50
50
51
51
Program the nightlight.
52
52
@@ -70,16 +70,18 @@ Program the nightlight.
70
70
71
71
The line `led = GroveLed(5)` creates an instance of the `GroveLed`class connecting to pin **D5**- the digital Grove pin that the LEDis connected to.
72
72
73
+
> 💁 All the sockets have unique pin numbers. Pins 0, 2, 4, and6 are analog pins, pins 5, 16, 18, 22, 24, and26 are digital pins.
74
+
73
75
1. Add a check inside the `while` loop, and before the `time.sleep` to check the light levels and turn the LED on or off:
74
76
75
77
```python
76
-
if light <200:
78
+
if light <300:
77
79
led.on()
78
80
else:
79
81
led.off()
80
82
```
81
83
82
-
This code checks the `light` value. If this is less than 200 it calls the `on` method of the `GroveLed`class which sends a digital value of 1 to the LED, turning it on. If the light value is greater than or equal to 200 it calls the `off` method, sending a digital value of 0 to the LED, turning it off.
84
+
This code checks the `light` value. If this is less than 300 it calls the `on` method of the `GroveLed`class which sends a digital value of 1 to the LED, turning it on. If the light value is greater than or equal to 300 it calls the `off` method, sending a digital value of 0 to the LED, turning it off.
83
85
84
86
> 💁 This code should be indented to the same level as the `print('Light level:', light)` line to be inside the while loop!
85
87
@@ -103,7 +105,7 @@ Program the nightlight.
103
105
Light level: 290
104
106
```
105
107
106
-
1. Cover and uncover the light sensor. Notice how the LED will light up if the light level is200or less, and turn off when the light level is greater than 200.
108
+
1. Cover and uncover the sunlight sensor. Notice how the LED will light up if the light level is300or less, and turn off when the light level is greater than 300.
107
109
108
110
> 💁 If the LED doesn't turn on, make sure it is connected the right way round, and the spin button is set to full on.
Copy file name to clipboardexpand all lines: 1-getting-started/lessons/3-sensors-and-actuators/pi-sensor.md
+36-28
Original file line number
Diff line number
Diff line change
@@ -4,70 +4,78 @@ In this part of the lesson, you will add a light sensor to your Raspberry Pi.
4
4
5
5
## Hardware
6
6
7
-
The sensor for this lesson is a **light sensor** that uses a [photodiode](https://wikipedia.org/wiki/Photodiode) to convert light to an electrical signal. This is an analog sensor that sends an integer value from 0 to 1,023 indicating a relative amount of light that doesn't map to any standard unit of measurement such as [lux](https://wikipedia.org/wiki/Lux).
7
+
The sensor for this lesson is a **sunlight sensor** that uses [photodiodes](https://wikipedia.org/wiki/Photodiode) to convert visible and infrared light to an electrical signal. This is an analog sensor that sends an integer value from 0 to 1,023 indicating a relative amount of light, but this can be used to calculate exact values in [lux](https://wikipedia.org/wiki/Lux) by taking data from the separate infrared and visible light sensors.
8
8
9
-
The light sensor is an eternal Grove sensor and needs to be connected to the Grove Base hat on the Raspberry Pi.
9
+
The sunlight sensor is an eternal Grove sensor and needs to be connected to the Grove Base hat on the Raspberry Pi.
10
10
11
-
### Connect the light sensor
11
+
### Connect the sunlight sensor
12
12
13
-
The Grove light sensor that is used to detect the light levels needs to be connected to the Raspberry Pi.
13
+
The Grove sunlight sensor that is used to detect the light levels needs to be connected to the Raspberry Pi.
14
14
15
-
#### Task
15
+
#### Task - connect the sunlight sensor
16
16
17
-
Connect the light sensor
17
+
Connect the sunlight sensor
18
18
19
-

19
+

20
20
21
-
1. Insert one end of a Grove cable into the socket on the light sensor module. It will only go in one way round.
21
+
1. Insert one end of a Grove cable into the socket on the sunlight sensor module. It will only go in one way round.
22
22
23
-
1. With the Raspberry Pi powered off, connect the other end of the Grove cable to the analog socket marked **A0** on the Grove Base hat attached to the Pi. This socket is the second from the right, on the row of sockets next to the GPIO pins.
23
+
1. With the Raspberry Pi powered off, connect the other end of the Grove cable to one of the three the I<sup>2</sup>C sockets marked **I2C** on the Grove Base hat attached to the Pi. This socket is the second from the right, on the row of sockets next to the GPIO pins.
24
24
25
-

25
+
> 💁 I<sup>2</sup>C is a way sensors and actuators can communicate with an IoT device. It will be covered in more detail in a later lesson.
26
26
27
-
## Program the light sensor
27
+

28
28
29
-
The device can now be programmed using the Grove light sensor.
29
+
## Program the sunlight sensor
30
30
31
-
### Task
31
+
The device can now be programmed using the Grove sunlight sensor.
32
+
33
+
### Task - program the sunlight sensor
32
34
33
35
Program the device.
34
36
35
37
1. Power up the Pi and wait for it to boot
36
38
37
39
1. Open the nightlight project in VS Code that you created in the previous part of this assignment, either running directly on the Pi or connected using the Remote SSH extension.
38
40
41
+
1. Run the following command to install a pip package for working with the sunlight sensor:
42
+
43
+
```sh
44
+
pip3 install seeed-python-si114x
45
+
```
46
+
47
+
Not all the libraries forthe Grove Sensors are installed with the Grove install script you usedin an earlier lesson. Some need additional packages.
48
+
39
49
1. Open the `app.py` file and remove all code from it
40
50
41
51
1. Add the following code to the `app.py` file to import some required libraries:
42
52
43
53
```python
44
54
import time
45
-
from grove.grove_light_sensor_v1_2 importGroveLightSensor
55
+
import seeed_si114x
46
56
```
47
57
48
58
The `import time` statement imports the `time` module that will be used later in this assignment.
49
59
50
-
The `from grove.grove_light_sensor_v1_2 importGroveLightSensor` statement imports the `GroveLightSensor`from the Grove Python libraries. This library has code to interact witha Grove light sensor, and was installed globally during the Pi setup.
60
+
The `import seeed_si114x` statement imports the `seeed_si114x` module that has code to interact with the Grove sunlight sensor.
51
61
52
62
1. Add the following code after the code above to create an instance of the class that manages the light sensor:
53
63
54
64
```python
55
-
light_sensor =GroveLightSensor(0)
65
+
light_sensor = seeed_si114x.grove_si114x()
56
66
```
57
67
58
-
The line `light_sensor = GroveLightSensor(0)` creates an instance of the `GroveLightSensor`class connecting to pin **A0**- the analog Grove pin that the light sensor is connected to.
59
-
60
-
> 💁 All the sockets have unique pin numbers. Pins 0, 2, 4, and6 are analog pins, pins 5, 16, 18, 22, 24, and26 are digital pins.
68
+
The line `light_sensor = seeed_si114x.grove_si114x()` creates an instance of the `grove_si114x` sunlight sensor class.
61
69
62
70
1. Add an infinite loop after the code above to poll the light sensor value and print it to the console:
63
71
64
72
```python
65
73
while True:
66
-
light = light_sensor.light
74
+
light = light_sensor.ReadVisible
67
75
print('Light level:', light)
68
76
```
69
77
70
-
This will read the current light level on a scale of 0-1,023 using the `light`property of the `GroveLightSensor`class. This property reads the analog value from the pin. This value is then printed to the console.
78
+
This will read the current sunlight level on a scale of 0-1,023 using the `ReadVisible` property of the `grove_si114x` class. This value is then printed to the console.
71
79
72
80
1. Add a small sleep of one second at the end of the `loop` as the light levels don't need to be checked continuously. A sleep reduces the power consumption of the device.
73
81
@@ -81,16 +89,16 @@ Program the device.
81
89
python3 app.py
82
90
```
83
91
84
-
You should see light values being output to the console. Cover and uncover the light sensor to see the values change:
92
+
You should see sunlight values being output to the console. Cover and uncover the sunlight sensor to see the values change:
85
93
86
94
```output
87
95
pi@raspberrypi:~/nightlight $ python3 app.py
88
-
Light level: 634
89
-
Light level: 634
90
-
Light level: 634
91
-
Light level: 230
92
-
Light level: 104
93
-
Light level: 290
96
+
Light level: 259
97
+
Light level: 265
98
+
Light level: 265
99
+
Light level: 584
100
+
Light level: 550
101
+
Light level: 497
94
102
```
95
103
96
104
> 💁 You can find this code in the [code-sensor/pi](code-sensor/pi) folder.
0 commit comments