Joy-it RB-JOYPI User guide

3
Joy-Pi
Publ ished: 20 .02.2019 Copyright by Joy-IT 2
Joy-Pi
1. Overview
2. Details
3. Changing modules and using the GPIOs
4. Using Python and Linux
5. Lessons
5.1 Lesson 1: Using the buzzer for warning sounds
5.2 Lesson 2: Controlling the buzzer with key inputs
5.3 Lesson 3: How a relay works and how to control it
5.4 Lesson 4: Sending a vibraon signal
5.5 Lesson 5: Detecng noises with the sound sensor
5.6 Lesson 6: Detecng brightness with the light sensor
5.7 Lesson 7: Detecng the temperature and the humidity
5.8 Lesson 8: Detecng movements
5.9 Lesson 9: Measuring distances with the ultrasonic sensor
5.10 Lesson 10: Controlling the LCD display
5.11 Lesson 11: Reading and wring RFID cards
5.12 Lesson 12: Using stepper motors
5.13 Lesson 13: Controlling servo motors
5.14 Lesson 14: Controlling the 8x8 LED matrix
5.15 Lesson 15: Controlling the 7-Segment display
5.16 Lesson 16: Recognizing touches
5.17 Lesson 17: Detecng lts with the lt sensor
5.18 Lesson 18: Using the buon matrix
5.19 Lesson19: Controlling and using the IR sensor
5.20 Lesson 20: Own circuits with the breadboard
5.21 Lesson 21: Photographing with the Raspberry Pi camera
6. Informaon and take-back obligaons
7. Copyright informaons
8. Support
TABLE OF CONTENTS
Publ ished: 20 .02.2019 Copyright by Joy-IT 3
Joy-Pi
Dear customer, Thank you very much for choosing our product. In the following we will show you what has to be observed during commissioning and use. Should you encounter any unexpected problems during use, please feel free to contact us.
The following lessons are designed so that, regardless of how much prior knowledge you already have, you can complete all lessons without any problems. For the dierent lessons you have to download sample les and run them on the Joy-Pi. How to do this can also be found in this manual.
But these tutorials are only the beginning.
We look forward to seeing what you will do with our Joy-Pi.
1. OVERVIEW
2. DETAILS
The login data is:
Username: pi
Password: 12345
Publ ished: 20 .02.2019 Copyright by Joy-IT 4
Joy-Pi
1 Raspberry Pi 2 GPIO LED Display 3 Breadboard - for creang custom curciuts with external modules 4 16x2 LCD Module (MCP23008) 5 Power supply 6 8x8 LED Matrix (MAX7219) 7 7 Segment LED display (HT16K33) 8 Vibraon module
9 Light sensor - to measure the light intensity (BH1750) 10 Buzzer - to generate alarm tones 11 Sound sensor 12 Moon sensor (LH1778) 13 Ultrasonic sensor - Used for distance measurement
14 / 15 Servo interfaces - for connecng servo motors
16 Stepper motor interface 17 Tilt sensor (SW-200D) 18 Infrared sensor 19 Touch sensor 20 DHT11 Sensor - for measuring humidity and temperature 21 Relay - for opening and closing electronic circuits 22 Key matrix 23 Independent keys 24 RFID module - for reading and wring data via RFID/NFC (MFRC522) 25 Switch - for switching between sensors and modules
Publ ished: 20 .02.2019 Copyright by Joy-IT 5
Joy-Pi
CHANGING MODULES
The Joy-Pi board contains 2 switching units. Each unit contains 8 switches. The switches make it possible to switch between the use of sensors and modules. Since the Raspberry Pi has only a limited number of GPIO pins, we need the switches to be able to use more sensors.
3. CHANGING MODULES AND USING THE GPIOS
Sensors / Modules Switching Unit Switches
Key array Le 1 - 8
Buon matrix Le 1 - 8
Vibraon module Right 1
Tilt sensor Right 2
Stepper motor Right 3, 4, 5, 6
Servomotor Right 7, 8
Publ ished: 20 .02.2019 Copyright by Joy-IT 6
Joy-Pi
USING THE GPIOS
In the following we will explain in more detail what GPIO's are, how they work and how they are controlled.
GPIO stands for: "General-purpose input / output" (universal input / output). GPIO pins have no specic purpose. They can be congured as either input or output and have a general purpose. This depends on what you want to achieve.
Input pin example: Buon If the Buon is pressed, the Signal will transfered through the input pin to the RaspberryPi
Output pin example: Buzzer Send a signal through the output pin to control the buzzer.
The GPIO pins are located on the right side of the Raspberry Pi board if you start from the Joy-Pi perspecve.
Publ ished: 20 .02.2019 Copyright by Joy-IT 7
Joy-Pi
There are 2 possible Raspberry Pi GPIO schemes: GPIO-BOARD and GPIO-BCM The GPIO-BOARD opon indicates that you are referring to the pins by the pin number. This means that the pin numbers listed below will be used.
The GPIO.BCM opon means that you refer to the pins of the "Broadcom SOC Channel". These are the numbers aer "GPIO" .
1 3.3V DC
3 GPIO 2 (SDA1, I2C)
5 GPIO 3 (SCL1, I2C)
7 GPIO 4
9 Ground
11 GPIO 17
13 GPIO 27
15 GPIO 22
17 3.3V
19 GPIO 10 (SPI, MOSI)
21 GPIO 9 (SPI, MISO)
23 GPIO 11 (SPI, CLK)
25 Ground
27 ID_SD (I2C, EEPROM)
29 GPIO 5
31 GPIO 6
33 GPIO 13
35 GPIO 19
37 GPIO 26
39 Ground
2 5V DC
4 5V DC
6 Ground
8 GPIO 14 (TXD0)
10 GPIO 15 (RXD0)
12 GPIO 18
14 Ground
16 GPIO 23
18 GPIO 24
20 Ground
22 GPIO 25
24 GPIO 8 (SPI)
26 GPIO 7 (SPI)
28 ID_SC
30 Ground
32 GPIO 12
34 Ground
36 GPIO 16
38 GPIO 20
40 GPIO 21
GPIO-Board
Number:
GPIO-Board
Number:
Publ ished: 20 .02.2019 Copyright by Joy-IT 8
Joy-Pi
GPIO-Board Number:
Used sensors and modules:
1 3.3V 2 5.0V 3 I2C, SDA1 (Licht Sensor, LCD Display, 7 Segment Display) 4 5.0V 5 I2C, SCL1 (Light Sensor, LCD Display, 7 Segment Display) 6 Ground 7 DHT11 Sensor
8 TXD0
9 Ground 10 RXD0 11 Touch Sensor 12 Buzzer 13 Buon matrix (ROW1), Vibraon motor 14 Ground 15 Buon matrix (ROW2), Tilt sensor 16 Moon sensor
17 3.3V
18 Sonic sensor 19 SPI 20 Ground 21 SPI 22 Servo2, Buon matrix (COL1), Le Buon 23 SPI 24 RFID Modul 25 Ground 26 LED-MATRIX 27 ID_SD (I2C, EEPROM(Electrically Erasable Programmable Read-only Memory)) 28 ID_SC 29 Stepper Motor (STEP1), Buon matrix (ROW3) 30 Ground 31 Stepper Motor (STEP2), Buon matrix (ROW4) 32 Ultrasonic sensor (Echo) 33 Stepper Motor (STEP3), Buonmatrix (COL4), Down Buon 34 Ground 35 Stepper Motor (STEP4), Buonmatrix (COL3), Right Buon
36 Ultrasonic sensor (TRIG)
37 Servo1, Buon matrix (COL2), Up Buon 38 Infrared sensor 39 Ground 40 Relais
ASSIGNMENT OF THE GPIO PINS ACCORDING TO GPIO.BOARD SCHEME
Publ ished: 20 .02.2019 Copyright by Joy-IT 9
Joy-Pi
In our examples we use Python language to control the GPIO pins. In Python there is a library called "RPi.GPIO". This is a library that helps to control the pins programmacally with Python.
Take a look at the following example and the comments in the code to beer understand how it works.
The rst step will be to import the library by typing the command "RPi.GPIO as GPIO", then the "me" library comes with the command "import me". Then we set the GPIO mode to GPIO.BOARD. We declare the input pin as pin number 11 for our example and the output pin as pin 12 (the input is the touch sensor and the output is the buzzer). We send a signal to the output pin, wait 1 second and then turn it o. Then, to conrm the input, we go through a loop unl the GPIO.input input signal is received. We print "Input Given" to make sure that the click was conrmed, clean up the GPIO with GPIO.cleanup () and nish the script.
To learn more about the purpose and use of GPIO, we recommend that you read the ocial documentaon on the topic of GPIO pins wrien by the Raspberry Pi foundaon.
hps://www.raspberrypi.org/documentaon/usage/gpio/
import RPi.GPIO as GPIO import time #import lybraries import signal
TOUCH = 11 #Declaring variables BUZZER = 12 #and connecting pins
def setup_gpio(): #Definition of in and outputs
GPIO.setmode(GPIO.BOARD) GPIO.setup(TOUCH, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(BUZZER, GPIO.OUT)
def do_smt(channel): #class for buzzer output and
print("Touch detected") #detected touch GPIO.output(BUZZER, GPIO.HIGH) #Signal output time.sleep (1) #Wait 1 second GPIO.output(BUZZER, GPIO.LOW) #Stop signal Output
def main():
setup_gpio() try: #Checking if touch is detected
GPIO.add_event_detect(TOUCH, GPIO.FALLING, callback=do_smt, bouncetime=200)
signal.pause() except KeyboardInterrupt: #CTRL+C is closing the script pass finally: GPIO.cleanup()
if __name__ == '__main__':
main()
Publ ished: 20 .02.2019 Copyright by Joy-IT 10
Joy-Pi
GETTING THE PREINSTALLED OPERATING SYSTEM
For the First Step you have to Download the image le with the Joy-Pi operang system. You can nd the le on our website at hps://joy-pi.net/downloads/.
1. Load the .Zip le onto your computer and unzip it to any folder you like. You should receive a .ISO le
2. Connect a MicroSD card to your computer with the aached MicroSD card reader.
3. Now format the MicroSD card with the program SD Formaer
4. Start the Program Win32DiskImagerand choose the unziped .Iso le, then click on the Write buon to copy the image onto your MicroSD card.
5. Now the MicroSD card is ready for use, you can put it in your Raspberry Pi now.
Publ ished: 20 .02.2019 Copyright by Joy-IT 11
Joy-Pi
This step is oponal, but makes it easier to execute scripts without having to create them individually.
The scripts used in this guide can be downloaded directly from a package. Simply follow the instrucons below:
1. Open the "Terminal". We use this to run most of our Python scripts and download extensions and
scripts.
4. USE OF PYTHON AND LINUX
Publ ished: 20 .02.2019 Copyright by Joy-IT 12
Joy-Pi
2. Aer successfully opening the terminal, we need to download the script archive to the desktop with the following commands:
3. Press "Enter" on your keyboard. Now all you have to do is unpack the archive:
4. Press "Enter" and wait unl the process is completed.
5. With the command "cd" we change to the correct directory so that we can use the scripts that are in it:
cd Desktop/ wget http://anleitung.joy-it.net/wp-content/uploads/2019/01/Joy-Pi.zip
unzip JoyPi.zip
cd Joy-Pi
Attention! Every time you restart your terminal, you have to repeat the steps of
changing the directory.
Publ ished: 20 .02.2019 Copyright by Joy-IT 13
Joy-Pi
EXECUTING PYTHON SCRIPTS
Aer we successfully downloaded our script, we would like to execute it. Open the terminal again and follow the instrucons below to run the script:
Write the command "sudo python <script name>" to execute a Python script. For example:
The sudo command gives us root permissions (admin permissions), which are later required by the GPIO library. We write "python" to tell the system that we want to execute the command with Python. At the end, we write the script name as we put it on the desktop. Make sure to always be in the right folder when you execute the command.
sudo python buzzer.py
Publ ished: 20 .02.2019 Copyright by Joy-IT 14
Joy-Pi
5.1 LESSON 1: USING THE BUZZER FOR WARNING SOUNDS
In the previous explanaon, we learned how to use the GPIO pin both as output and input. To test this now, we go ahead with a real example and apply our knowledge from the previous lesson. The module we will use is the "Buzzer".
We will use the GPIO output to send a signal to the buzzer and close the circuit to generate a loud buzz. Then we will send another signal to turn it o.
The buzzer is located on the right side of the Joy-Pi-Board and is easily recognized by the loud noise that it will make when acvated. When you use your Raspberry Pi for the rst me, the buzzer may have a protecve scker on it. Make sure this scker has been removed before using the Buzzer.
Just like in the previous example, we have prepared a special script with detailed comments that will explain how the whole buzzer process works, and how we can control the buzzer with the GPIOs.
First we import the RPi.GPIO library and the me library. Then we congure the buzzer. At pin 12 we set
the GPIO mode to GPIO BOARD and the pin as OUTPUT.
We output a signal for 0.5 seconds and then turn it o.
5. LESSONS
Publ ished: 20 .02.2019 Copyright by Joy-IT 15
Joy-Pi
Buzzer code example:
Execute the following commands and try it yourself:
#!/usr/bin/python # -*- coding: utf-8 -*-
import RPi.GPIO as GPIO #import librarys import time
buzzer_pin = 12 #define buzzer pin
GPIO.setmode(GPIO.BOARD) GPIO.setup(buzzer_pin, GPIO.OUT)
# Make buzzer sound
GPIO.output(buzzer_pin, GPIO.HIGH)
#wait 0.5 seconds
time.sleep(0.5)
# Stop buzzer sound
GPIO.output(buzzer_pin, GPIO.LOW)
GPIO.cleanup()
sudo python buzzer.py
cd /home/pi/Desktop/Joy-Pi/
Publ ished: 20 .02.2019 Copyright by Joy-IT 16
Joy-Pi
5.2 LESSON 2: CONTROLLING THE BUZZER WITH KEY INPUTS
Aer successfully demonstrang how to turn the buzzer on and o, it's me to make things a lile more excing. In this lesson, we'll combine a buon with the buzzer so that the buzzer is only turned on by pressing the buon.
This me we will use 2 GPIO setups. One will be the GPIO.INPUT, which takes the buon as an input, another will be the GPIO.OUTPUT, which sends a signal to the buzzer to output a sound.
In our example we use the upper of the 4 keys on the lower le side. Theorecally, however, any of the 4
keys can be used. If you sll want to use another key, you have to change the pin assignment accordingly.
Attention! For this example you have to switch between the modules. Turn switch number 5, 6, 7 and 8 on the left switching unit ON. All the other switches should be turned OFF.
GPIO37 Upper buon GPIO27 Lower buon GPIO22 Le buon GPIO35 Right buon
Publ ished: 20 .02.2019 Copyright by Joy-IT 17
Joy-Pi
For this part of our tutorial we need to use 2 GPIO sengs. One input and one output. The GPIO input is used to determine when a key was pressed and the GPIO output is used to acvate the buzzer when that key is pressed.
As you can see in the example below, we have dened 2 pins called buzzer_pin and buon_pin. The program runs unl CTRL + C is pressed.
When you press the key on your Joy-Pi, the buzzer does a sound! Release the key and the Buzzer stops.
Example code:
Execute the following commands and try it yourself:
#!/usr/bin/python # -*- coding: utf-8 -*-
import RPi.GPIO as GPIO import time
# configure both button and buzzer pins
button_pin = 37 buzzer_pin = 12
# set board mode to GPIO.BOARD
GPIO.setmode(GPIO.BOARD)
# setup button pin as input and buzzer pin as output
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(buzzer_pin, GPIO.OUT)
try:
while True: # check if button pressed if(GPIO.input(button_pin) == 0):
# set buzzer on
GPIO.output(buzzer_pin, GPIO.HIGH) else: # it's not pressed, set button off GPIO.output(buzzer_pin, GPIO.LOW)
except KeyboardInterrupt:
GPIO.cleanup()
sudo python button_buzzer.py
cd /home/pi/Desktop/Joy-Pi/
Publ ished: 20 .02.2019 Copyright by Joy-IT 18
Joy-Pi
5.3 LESSON 3: HOW A RELAY WORKS AND HOW TO CONTROL IT
Now that we know everything we need to know about the buzzer, it's me for the next lesson. Now we'll learn how to use the relay, what the funcon of the relay is and how to control it.
Relays are used to control a circuit by a separate low power signal, or when several circuits need to be controlled by one signal. If you connect you wires to NCand COMand you send a GPIO.HIGH signal the relay will close and deacvate your custom circuit. If you stop the signal the relay will open and will acvate your custom circuit.
The relay is located in the middle, lower part of the board, next to the key matrix. It has 3 inputs of which we will use 2 in this example. NCmeans normally closed“, „NOmeans normally openand COMmeans commom“. Common in this case means common ground. When the common circuit is de-energised (GPIO.LOW) the NCcircuit is closed. When the common circuit gets energized (GPIO.HIGH) the relay will close the circuit for NO“. When using NOand COMeverything is reversed.
When COMis o (GPIO.LOW) the relay circuit is open.
When COMis on (GPIO.High) the relay circuit is closed.
Attention! It is very important not to try to connect high voltage devices to the relay (e.g. table lamp, coffee machine etc.). This could result in electric shock and serious injury.
Publ ished: 20 .02.2019 Copyright by Joy-IT 19
Joy-Pi
Now that we have understood what a relay is and how it works, we take a look at the code:
Execute the following commands and try it for yourself:
#!/usr/bin/python # -*- coding: utf-8 -*-
import RPi.GPIO as GPIO import time
# define relay pin
relay_pin = 40
# set GPIO mode as GPIO.BOARD
GPIO.setmode(GPIO.BOARD)
# setup relay pin as OUTPUT
GPIO.setup(relay_pin, GPIO.OUT)
# Open Relay
GPIO.output(relay_pin, GPIO.LOW)
# Wait half a second
time.sleep(0.5)
# Close Relay
GPIO.output(relay_pin, GPIO.HIGH)
GPIO.cleanup()
sudo python relay.py
cd /home/pi/Desktop/Joy-Pi/
Publ ished: 20 .02.2019 Copyright by Joy-IT 20
Joy-Pi
5.4 LESSON 4: SENDING A VIBRATION SIGNAL
Have you ever wondered how your phone vibrates when someone calls you or when you receive a messa­ge? We built exactly the same module into our Joy-Pi and now we will learn how to use it.
The vibraon module is located on the right side of the LED matrix and below the segment LED. When it is on, it is dicult to tell where the vibraon is coming from because it feels like the whole Joy-Pi board is
vibrang.
The vibraon module uses a GPIO.OUTPUT-signal just like the Buzzer and other modules previously used. When sending an output signal the module will start vibrang. When you stop the signal with GPIO.LOW the vibraon will stop.
You can adjust the vibraon length with dierent me.sleep() intervals.
For this example you have to switch between the modules. Set switch number 1 of the right­hand switching unit to ON. All the other switches should be turned OFF.
Publ ished: 20 .02.2019 Copyright by Joy-IT 21
Joy-Pi
Execute the following commands and try it yourself:
#!/usr/bin/python # -*- coding: utf-8 -*-
import RPi.GPIO as GPIO import time
# define vibration pin
vibration_pin = 13
# Set board mode to GPIO.BOARD
GPIO.setmode(GPIO.BOARD)
# Setup vibration pin to OUTPUT
GPIO.setup(vibration_pin, GPIO.OUT)
# turn on vibration
GPIO.output(vibration_pin, GPIO.HIGH)
# wait 4 seconds
time.sleep(4)
# turn off vibration
GPIO.output(vibration_pin, GPIO.LOW)
# cleanup GPIO
GPIO.cleanup()
sudo python vibration.py
cd /home/pi/Desktop/Joy-Pi/
Publ ished: 20 .02.2019 Copyright by Joy-IT 22
Joy-Pi
5.5 LESSON 5: DETECTING NOISES WITH THE SOUND SENSOR
In this lesson, we will learn how to use the sound sensor to make inputs, detect loud noises and react accordingly. So you can build your own alarm system that detects loud noises or turn on an LED by clapping!
The sound sensor consists of two parts: a blue potenometer, which regulates the sensivity, and the sensor itself, which detects the input of sounds. The sound sensor can be easily recognized by the blue potenometer and the sensor itself is located on the right under the buzzer.
With the help of the potenometer we can regulate the sensivity of the sensor. For our script to work, we must rst learn how to control the sensivity. To adjust the sensivity you have to turn the small screw on the potenometer with a screwdriver to the le or right. The best way to test the sensivity is to run the script. Clap your hands and see if the device is receiving a signal. If no signal is received this means that the sensivity of the sensor is not set high enough. This can be easily corrected by turning the potenometer.
#!/usr/bin/python # -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time
# define sound pin
sound_pin = 18
# set GPIO mode to GPIO.BOARD
GPIO.setmode(GPIO.BOARD)
# setup pin as INPUT
GPIO.setup(sound_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
while True: # check if sound detected or not
if(GPIO.input(sound_pin)==GPIO.LOW):
print('Sound Detected') time.sleep(0.1)
except KeyboardInterrupt:
# CTRL+C detected, cleaning and quitting the script GPIO.cleanup()
Publ ished: 20 .02.2019 Copyright by Joy-IT 23
Joy-Pi
Execute the following commands and try it yourself:
First we dene our pin, GPIO18. Then we set a while loop to run this script permanently. We check if we have received an input from the sound sensor indicang that loud noises have been detected and then we print "Sound Detected".
If Ctrl + C is pressed, the program is quit.
5.6 LESSON 6: DETECTING BRIGHTNESS WITH THE LIGHT SENSOR
The light sensor is one of our favorites. It is extremely useful in many projects and situaons, e.g. with lamps that switch on automacally as soon as it gets dark. With the light sensor we can see how bright the module surface is.
The light sensor is dicult to detect because it consists of very small parts. The sensor is to the le of the buzzer. If you cover it with your nger, the output of the light sensor should be close to zero, as no light can reach it.
sudo python sound.py
cd /home/pi/Desktop/Joy-Pi/
Loading...
+ 53 hidden pages