Removing sunlight sensor (#91)

* 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

* Adding lesson 16

* Adding virtual camera

* Adding Wio Terminal camera capture

* Adding wio terminal code

* Adding SBC classification to lesson 16

* Adding challenge, review and assignment

* Adding images and using new Azure icons

* Update README.md

* Update iot-reference-architecture.png

* Adding structure for JulyOT links

* Removing icons

* Sketchnotes!

* Create lesson-1.png

* Starting on lesson 18

* Updated sketch

* Adding virtual distance sensor

* Adding Wio Terminal image classification

* Update README.md

* Adding structure for project 6 and wio terminal distance sensor

* Adding some of the smart timer stuff

* Updating sketchnotes

* Adding virtual device speech to text

* Adding chapter 21

* Language tweaks

* Lesson 22 stuff

* Update en.json

* Bumping seeed libraries

* Adding functions lab to lesson 22

* Almost done with LUIS

* Update README.md

* Reverting sunlight sensor change

Fixes #88
pull/92/head
Jim Bennett 3 years ago committed by GitHub
parent 7ec6d1aa8f
commit 359f2f7447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

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

@ -44,7 +44,7 @@ Connect the LED.
## Program the nightlight ## Program the nightlight
The nightlight can now be programmed using the Grove sunlight sensor and the Grove LED. The nightlight can now be programmed using the Grove light sensor and the Grove LED.
### Task - program the nightlight ### Task - program the nightlight
@ -105,7 +105,7 @@ Program the nightlight.
Light level: 290 Light level: 290
``` ```
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. 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.
> 💁 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. > 💁 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,33 +4,31 @@ In this part of the lesson, you will add a light sensor to your Raspberry Pi.
## Hardware ## Hardware
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 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,000 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 sunlight sensor is an eternal Grove sensor and needs to be connected to the Grove Base hat on the Raspberry Pi. The light sensor is an eternal Grove sensor and needs to be connected to the Grove Base hat on the Raspberry Pi.
### Connect the sunlight sensor ### Connect the light sensor
The Grove sunlight sensor that is used to detect the light levels needs to be connected to the Raspberry Pi. The Grove light sensor that is used to detect the light levels needs to be connected to the Raspberry Pi.
#### Task - connect the sunlight sensor #### Task - connect the light sensor
Connect the sunlight sensor Connect the light sensor
![A grove sunlight sensor](../../../images/grove-sunlight-sensor.png) ![A grove light sensor](../../../images/grove-light-sensor.png)
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. Insert one end of a Grove cable into the socket on the light sensor module. It will only go in one way round.
1.
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 - program the light sensor
The device can now be programmed using the Grove sunlight sensor.
### Task - program the sunlight sensor
Program the device. Program the device.
@ -38,44 +36,36 @@ 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. 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. 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: 1. Add the following code to the `app.py` file to import some required libraries:
```python ```python
import time import time
import seeed_si114x from grove.grove_light_sensor_v1_2 import GroveLightSensor
``` ```
The `import time` statement imports the `time` module that will be used later in this assignment. The `import time` statement imports the `time` module that will be used later in this assignment.
The `import seeed_si114x` statement imports the `seeed_si114x` module that has code to interact with the Grove sunlight sensor. 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.
1. Add the following code after the code above to create an instance of the class that manages the light sensor: 1. Add the following code after the code above to create an instance of the class that manages the light sensor:
```python ```python
light_sensor = seeed_si114x.grove_si114x() light_sensor = GroveLightSensor(0)
``` ```
The line `light_sensor = seeed_si114x.grove_si114x()` creates an instance of the `grove_si114x` sunlight sensor class. 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.
1. Add an infinite loop after the code above to poll the light sensor value and print it to the console: 1. Add an infinite loop after the code above to poll the light sensor value and print it to the console:
```python ```python
while True: while True:
light = light_sensor.ReadVisible light = light_sensor.light
print('Light level:', light) print('Light level:', light)
``` ```
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. 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.
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. 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.
@ -89,16 +79,16 @@ Program the device.
python3 app.py python3 app.py
``` ```
Sunlight values will be output to the console. Cover and uncover the sunlight sensor, and the values will change: Light values will be output to the console. Cover and uncover the light sensor, and the values will change:
```output ```output
pi@raspberrypi:~/nightlight $ python3 app.py pi@raspberrypi:~/nightlight $ python3 app.py
Light level: 259 Light level: 634
Light level: 265 Light level: 634
Light level: 265 Light level: 634
Light level: 584 Light level: 230
Light level: 550 Light level: 104
Light level: 497 Light level: 290
``` ```
> 💁 You can find this code in the [code-sensor/pi](code-sensor/pi) folder. > 💁 You can find this code in the [code-sensor/pi](code-sensor/pi) folder.

@ -57,7 +57,7 @@ These are specific to using the Raspberry Pi, and are not relevant to using the
* Headphones or other speaker with a 3.5mm jack, or a JST speaker such as: * Headphones or other speaker with a 3.5mm jack, or a JST speaker such as:
* [Mono Enclosed Speaker - 2W 6 Ohm](https://www.seeedstudio.com/Mono-Enclosed-Speaker-2W-6-Ohm-p-2832.html) * [Mono Enclosed Speaker - 2W 6 Ohm](https://www.seeedstudio.com/Mono-Enclosed-Speaker-2W-6-Ohm-p-2832.html)
* [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) * [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 Sunlight sensor](https://www.seeedstudio.com/Grove-Sunlight-Sensor.html) * [Grove Light sensor](https://www.seeedstudio.com/Grove-Light-Sensor-v1-2-LS06-S-phototransistor.html)
* [Grove button](https://www.seeedstudio.com/Grove-Button.html) * [Grove button](https://www.seeedstudio.com/Grove-Button.html)
## Sensors and actuators ## Sensors and actuators

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 496 KiB

Loading…
Cancel
Save