* 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
This commit is contained in:
Jim Bennett 2021-06-03 15:55:39 -07:00 коммит произвёл GitHub
Родитель fa04074faf
Коммит 64f1cfc03d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
22 изменённых файлов: 89 добавлений и 103 удалений

Просмотреть файл

@ -1,20 +0,0 @@
from counterfit_shims_grove.counterfit_connection import CounterFitConnection
import time
from counterfit_shims_grove.grove_light_sensor_v1_2 import GroveLightSensor
from counterfit_shims_grove.grove_led import GroveLed
CounterFitConnection.init('127.0.0.1', 5000)
light_sensor = GroveLightSensor(0)
led = GroveLed(5)
while True:
light = light_sensor.light
print('Light level:', light)
if light < 200:
led.on()
else:
led.off()
time.sleep(1)

Просмотреть файл

@ -12,7 +12,7 @@ If you are using a Raspberry Pi as your IoT hardware, you have two choices - you
Before you begin, you also need to connect the Grove Base Hat to your Pi.
### Task
### Task - setup
Install the Grove base hat on your Pi and configure the Pi
@ -29,7 +29,7 @@ Install the Grove base hat on your Pi and configure the Pi
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.
#### Task
#### Task - work directly on your Pi
Set up your Pi for development.
@ -79,7 +79,7 @@ Rather than coding directly on the Pi, it can run 'headless', that is not connec
To code remotely, the Pi OS needs to be installed on an SD Card.
##### Task
##### Task - set up the Pi OS
Set up the headless Pi OS.
@ -115,7 +115,7 @@ The OS will be written to the SD card, and once compete the card will be ejected
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.
##### Task
##### Task - connect to the Pi
Remotely access the Pi.
@ -147,7 +147,7 @@ Remotely access the Pi.
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.
##### Task
##### Task - configure software on the Pi
Configure the installed Pi software and install the Grove libraries.
@ -179,7 +179,7 @@ Configure the installed Pi software and install the Grove libraries.
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.
##### Task
##### Task - configure VS Code for remote access
Install the required software and connect remotely to your Pi.
@ -199,7 +199,7 @@ The Hello World app for the Pi will ensure that you have Python and Visual Studi
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.
### Task
### Task - hello world
Create the Hello World app.

Просмотреть файл

@ -120,7 +120,7 @@ Create a Python application to print `"Hello World"` to the console.
code .
```
> 💁 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.
> 💁 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.
1. When VS Code launches, it will activate the Python virtual environment. You will see this in the bottom status bar:

Просмотреть файл

@ -8,7 +8,7 @@ The [Wio Terminal from Seeed Studios](https://www.seeedstudio.com/Wio-Terminal-p
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.
### Task
### Task - setup
Install the required software and update the firmware.
@ -32,7 +32,7 @@ The Hello World app for the Wio Terminal will ensure that you have Visual Studio
The first step is to create a new project using PlatformIO configured for the Wio Terminal.
#### Task
#### Task - create a PlatformIO project
Create the PlatformIO project.
@ -122,7 +122,7 @@ The VS Code explorer will show a number of files and folders created by the Plat
You're now ready to write the Hello World app.
#### Task
#### Task - write the Hello World app
Write the Hello World app.

Просмотреть файл

@ -1,15 +1,15 @@
import time
from grove.grove_light_sensor_v1_2 import GroveLightSensor
import seeed_si114x
from grove.grove_led import GroveLed
light_sensor = GroveLightSensor(0)
light_sensor = seeed_si114x.grove_si114x()
led = GroveLed(5)
while True:
light = light_sensor.light
light = light_sensor.ReadVisible
print('Light level:', light)
if light < 200:
if light < 300:
led.on()
else:
led.off()

Просмотреть файл

@ -12,7 +12,7 @@ while True:
light = light_sensor.light
print('Light level:', light)
if light < 200:
if light < 300:
led.on()
else:
led.off()

Просмотреть файл

@ -12,7 +12,7 @@ while True:
light = light_sensor.light
print('Light level:', light)
if light < 200:
if light < 300:
led.on()
else:
led.off()

Просмотреть файл

@ -19,7 +19,7 @@ void loop()
Serial.print("Light value: ");
Serial.println(light);
if (light < 200)
if (light < 300)
{
digitalWrite(D0, HIGH);
}

Просмотреть файл

@ -1,10 +1,9 @@
import time
from grove.grove_light_sensor_v1_2 import GroveLightSensor
import seeed_si114x
light_sensor = GroveLightSensor(0)
light_sensor = seeed_si114x.grove_si114x()
while True:
light = light_sensor.light
light = light_sensor.ReadVisible
print('Light level:', light)
time.sleep(1)

Просмотреть файл

@ -12,7 +12,7 @@ while True:
light = light_sensor.light
print('Light level:', light)
if light < 200:
if light < 300:
led.on()
else:
led.off()

Просмотреть файл

@ -12,7 +12,7 @@ The nightlight logic in pseudo-code is:
```output
Check the light level.
If the light is less than 200
If the light is less than 300
Turn the LED on
Otherwise
Turn the LED off
@ -22,7 +22,7 @@ Otherwise
The Grove LED comes as a module with a selection of LEDs, allowing you to chose the color.
#### Task
#### Task - connect the LED
Connect the LED.
@ -44,9 +44,9 @@ Connect the LED.
## Program the nightlight
The nightlight can now be programmed using the Grove light sensor and the Grove LED.
The nightlight can now be programmed using the Grove sunlight sensor and the Grove LED.
### Task
### Task - program the nightlight
Program the nightlight.
@ -70,16 +70,18 @@ Program the nightlight.
The line `led = GroveLed(5)` creates an instance of the `GroveLed` class connecting to pin **D5** - the digital Grove pin that the LED is connected to.
> 💁 All the sockets have unique pin numbers. Pins 0, 2, 4, and 6 are analog pins, pins 5, 16, 18, 22, 24, and 26 are digital pins.
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:
```python
if light < 200:
if light < 300:
led.on()
else:
led.off()
```
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.
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.
> 💁 This code should be indented to the same level as the `print('Light level:', light)` line to be inside the while loop!
@ -103,7 +105,7 @@ Program the nightlight.
Light level: 290
```
1. Cover and uncover the light sensor. Notice how the LED will light up if the light level is 200 or less, and turn off when the light level is greater than 200.
1. Cover and uncover the sunlight sensor. Notice how the LED will light up if the light level is 300 or less, and turn off when the light level is greater than 300.
> 💁 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.

Просмотреть файл

@ -4,31 +4,33 @@ In this part of the lesson, you will add a light sensor to your Raspberry Pi.
## Hardware
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).
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.
The light sensor is an eternal Grove sensor and needs to be connected to the Grove Base hat on the Raspberry Pi.
The sunlight sensor is an eternal Grove sensor and needs to be connected to the Grove Base hat on the Raspberry Pi.
### Connect the light sensor
### Connect the sunlight sensor
The Grove light sensor that is used to detect the light levels needs to be connected to the Raspberry Pi.
The Grove sunlight sensor that is used to detect the light levels needs to be connected to the Raspberry Pi.
#### Task
#### Task - connect the sunlight sensor
Connect the light sensor
Connect the sunlight sensor
![A grove light sensor](../../../images/grove-light-sensor.png)
![A grove sunlight sensor](../../../images/grove-sunlight-sensor.png)
1. Insert one end of a Grove cable into the socket on the light sensor module. It will only go in one way round.
1. Insert one end of a Grove cable into the socket on the sunlight sensor module. It will only go in one way round.
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.
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.
![The grove light sensor connected to socket A0](../../../images/pi-light-sensor.png)
> 💁 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.
## Program the light sensor
![The grove sunlight sensor connected to socket A0](../../../images/pi-sunlight-sensor.png)
The device can now be programmed using the Grove light sensor.
## Program the sunlight sensor
### Task
The device can now be programmed using the Grove sunlight sensor.
### Task - program the sunlight sensor
Program the device.
@ -36,38 +38,44 @@ Program the device.
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.
1. Run the following command to install a pip package for working with the sunlight sensor:
```sh
pip3 install seeed-python-si114x
```
Not all the libraries for the Grove Sensors are installed with the Grove install script you used in an earlier lesson. Some need additional packages.
1. Open the `app.py` file and remove all code from it
1. Add the following code to the `app.py` file to import some required libraries:
```python
import time
from grove.grove_light_sensor_v1_2 import GroveLightSensor
import seeed_si114x
```
The `import time` statement imports the `time` module that will be used later in this assignment.
The `from grove.grove_light_sensor_v1_2 import GroveLightSensor` statement imports the `GroveLightSensor` from the Grove Python libraries. This library has code to interact with a Grove light sensor, and was installed globally during the Pi setup.
The `import seeed_si114x` statement imports the `seeed_si114x` module that has code to interact with the Grove sunlight sensor.
1. Add the following code after the code above to create an instance of the class that manages the light sensor:
```python
light_sensor = GroveLightSensor(0)
light_sensor = seeed_si114x.grove_si114x()
```
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.
> 💁 All the sockets have unique pin numbers. Pins 0, 2, 4, and 6 are analog pins, pins 5, 16, 18, 22, 24, and 26 are digital pins.
The line `light_sensor = seeed_si114x.grove_si114x()` creates an instance of the `grove_si114x` sunlight sensor class.
1. Add an infinite loop after the code above to poll the light sensor value and print it to the console:
```python
while True:
light = light_sensor.light
light = light_sensor.ReadVisible
print('Light level:', light)
```
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.
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.
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.
@ -81,16 +89,16 @@ Program the device.
python3 app.py
```
You should see light values being output to the console. Cover and uncover the light sensor to see the values change:
You should see sunlight values being output to the console. Cover and uncover the sunlight sensor to see the values change:
```output
pi@raspberrypi:~/nightlight $ python3 app.py
Light level: 634
Light level: 634
Light level: 634
Light level: 230
Light level: 104
Light level: 290
Light level: 259
Light level: 265
Light level: 265
Light level: 584
Light level: 550
Light level: 497
```
> 💁 You can find this code in the [code-sensor/pi](code-sensor/pi) folder.

Просмотреть файл

@ -12,17 +12,17 @@ The nightlight logic in pseudo-code is:
```output
Check the light level.
If the light is less than 200
If the light is less than 300
Turn the LED on
Otherwise
Turn the LED off
```
### Add the sensors to CounterFit
### Add the actuator to CounterFit
To use a virtual LED, you need to add it to the CounterFit app
#### Task
#### Task - add the actuator to CounterFit
Add the LED to the CounterFit app.
@ -48,7 +48,7 @@ Add the LED to the CounterFit app.
The nightlight can now be programmed using the CounterFit light sensor and LED.
#### Task
#### Task - program the nightlight
Program the nightlight.
@ -75,13 +75,13 @@ Program the nightlight.
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:
```python
if light < 200:
if light < 300:
led.on()
else:
led.off()
```
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.
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.
> 💁 This code should be indented to the same level as the `print('Light level:', light)` line to be inside the while loop!
@ -101,7 +101,7 @@ Program the nightlight.
Light level: 253
```
1. Change the *Value* or the *Random* settings to vary the light level above and below 200. You will see the LED turn on and off.
1. Change the *Value* or the *Random* settings to vary the light level above and below 300. You will see the LED turn on and off.
![The LED in the CounterFit app turning on and off as the light level changes](../../../images/virtual-device-running-assignment-1-1.gif)

Просмотреть файл

@ -12,7 +12,7 @@ The sensor is a **light sensor**. In a physical IoT device, it would be a [photo
To use a virtual light sensor, you need to add it to the CounterFit app
#### Task
#### Task - add the sensors to CounterFit
Add the light sensor to the CounterFit app.
@ -38,11 +38,10 @@ Add the light sensor to the CounterFit app.
The device can now be programmed to use the built in light sensor.
### Task
### Task - program the light sensor
Program the device.
1. Open the nightlight project in VS Code that you created in the previous part of this assignment. Kill and re-create the terminal to ensure it is running using the virtual environment if necessary.
1. Open the `app.py` file

Просмотреть файл

@ -12,7 +12,7 @@ The nightlight logic in pseudo-code is:
```output
Check the light level.
If the light is less than 200
If the light is less than 300
Turn the LED on
Otherwise
Turn the LED off
@ -22,7 +22,7 @@ Otherwise
The Grove LED comes as a module with a selection of LEDs, allowing you to chose the color.
#### Task
#### Task - connect the LED
Connect the LED.
@ -48,7 +48,7 @@ Connect the LED.
The nightlight can now be programmed using the built in light sensor and the Grove LED.
### Task
### Task - program the nightlight
Program the nightlight.
@ -67,7 +67,7 @@ Program the nightlight.
1. Add the following code immediately before the `delay` in the loop function:
```cpp
if (light < 200)
if (light < 300)
{
digitalWrite(D0, HIGH);
}
@ -77,7 +77,7 @@ Program the nightlight.
}
```
This code checks the `light` value. If this is less than 200 it sends a `HIGH` value to the `D0` digital pin. This `HIGH` is a value of 1, turning on the LED. If the light is greater than or equal to 200, a `LOW` value of 0 is sent to the pin, turning the LED off.
This code checks the `light` value. If this is less than 300 it sends a `HIGH` value to the `D0` digital pin. This `HIGH` is a value of 1, turning on the LED. If the light is greater than or equal to 300, a `LOW` value of 0 is sent to the pin, turning the LED off.
> 💁 When sending digital values to actuators, a LOW value is 0v, and a HIGH value is the max voltage for the device. For the Wio Terminal, the HIGH voltage is 3.3V.
@ -101,7 +101,7 @@ Program the nightlight.
Light value: 344
```
1. Cover and uncover the light sensor. Notice how the LED will light up if the light level is 200 or less, and turn off when the light level is greater than 200.
1. Cover and uncover the light sensor. Notice how the LED will light up if the light level is 300 or less, and turn off when the light level is greater than 300.
![The LED connected to the WIO turning on and off as the light level changes](../../../images/wio-running-assignment-1-1.gif)

Просмотреть файл

@ -372,13 +372,13 @@ The next step for our Internet controlled nightlight is for the server code to s
1. Add the following code to the end of the `handle_telemetry` function:
```python
command = { 'led_on' : payload['light'] < 200 }
command = { 'led_on' : payload['light'] < 300 }
print("Sending message:", command)
client.publish(server_command_topic, json.dumps(command))
```
This sends a JSON message to the command topic with the value of `led_on` set to true or false depending on if the light is less than 200 or not. If the light is less than 200, true is sent to instruct the device to turn the LED on.
This sends a JSON message to the command topic with the value of `led_on` set to true or false depending on if the light is less than 300 or not. If the light is less than 300, true is sent to instruct the device to turn the LED on.
1. Run the code as before

Просмотреть файл

@ -18,7 +18,7 @@ def handle_telemetry(client, userdata, message):
payload = json.loads(message.payload.decode())
print("Message received:", payload)
command = { 'led_on' : payload['light'] < 200 }
command = { 'led_on' : payload['light'] < 300 }
print("Sending message:", command)
client.publish(server_command_topic, json.dumps(command))

Просмотреть файл

@ -21,7 +21,7 @@ while True:
light = light_sensor.light
print('Light level:', light)
if light < 200:
if light < 300:
led.on()
else:
led.off()

Просмотреть файл

@ -24,7 +24,7 @@ while True:
light = light_sensor.light
print('Light level:', light)
if light < 200:
if light < 300:
led.on()
else:
led.off()

Просмотреть файл

@ -23,7 +23,7 @@ All the device code for Arduino is in C++. To complete all the assignments you w
These are specific to using the Wio terminal Arduino device, and are not relevant to using the Raspberry Pi.
* [Grove camera kit](https://www.seeedstudio.com/Grove-Serial-Camera-Kit.html)
* [ArduCam Mini 2MP Plus - OV2640](https://www.arducam.com/product/arducam-2mp-spi-camera-b0067-arduino/)
* [Grove speaker plus](https://www.seeedstudio.com/Grove-Speaker-Plus-p-4592.html)
## Raspberry Pi
@ -48,7 +48,7 @@ These are specific to using the Raspberry Pi, and are not relevant to using the
* Any USB speaker, or speaker with a 3.5mm cable
or
* [USB Speakerphone](https://www.amazon.com/USB-Speakerphone-Conference-Business-Microphones/dp/B07Q3D7F8S/ref=sr_1_1?dchild=1&keywords=m0&qid=1614647389&sr=8-1)
* [Grove Light sensor](https://www.seeedstudio.com/Grove-Light-Sensor-v1-2-LS06-S-phototransistor.html)
* [Grove Sunlight sensor](https://www.seeedstudio.com/Grove-Sunlight-Sensor.html)
## Sensors and actuators
@ -58,8 +58,6 @@ Most of the sensors and actuators needed are used by both the Arduino and Raspbe
* [Grove humidity and temperature sensor](https://www.seeedstudio.com/Grove-Temperature-Humidity-Sensor-DHT11.html)
* [Grove capacitive soil moisture sensor](https://www.seeedstudio.com/Grove-Capacitive-Moisture-Sensor-Corrosion-Resistant.html)
* [Grove relay](https://www.seeedstudio.com/Grove-Relay.html)
* [Grove 125KHz RFID reader](https://www.seeedstudio.com/Grove-125KHz-RFID-Reader.html)
* [RFID tags (125KHz)](https://www.seeedstudio.com/RFID-tag-combo-125khz-5-pcs-p-700.html)
* [Grove GPS (Air530)](https://www.seeedstudio.com/Grove-GPS-Air530-p-4584.html)
* [Grove - Ultrasonic Distance Sensor](https://www.seeedstudio.com/Grove-Ultrasonic-Distance-Sensor.html)

Двоичные данные
images/grove-sunlight-sensor.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 358 KiB

Двоичные данные
images/pi-sunlight-sensor.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 496 KiB