Page 2
Component List 1x DC Motor 1x Servo 1x L9110 motor driver 1x LCD1602 1x ADC0832 2x 74HC595 1x Dot-matrix Display 1x 7-Segment Display 1x Light Sensor (Photoresistor) 1x 40 pin GPIO Extension Board 1x 40 pin GPIO Cable 1x Breadboard Power Supply Module 1x Active buzzer 1x Tilt Switch 2x Switch...
Page 3
Raspberry Pi. About Adeept Adeept is a technical service team of open source software and hardware. Dedicated to applying the Internet and the latest industrial technology in open source area, we strive to provide best hardware support and software service for general makers and electronic enthusiasts around the world.
Content About the Raspberry Pi ........................ - 1 - Raspberry Pi Pin Numbering Introduction ................... - 2 - Raspberry Pi GPIO Library Introduction ..................- 4 - How to use the wiringPi and the RPi.GPIO ................. - 6 - Lesson 1 Blinking LED......................- 10 - Lesson 2 Buzzer .........................
About the Raspberry Pi The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python.
Raspberry Pi Pin Numbering Introduction There are three methods for numbering Raspberry Pi’s GPIO: 1. Numbering according to the physical location of the pins, from left to right, top to bottom, the left is odd, the right is even. 2. Numbering according the GPIO registers of BCM2835/2836 SOC. 3.
Raspberry Pi GPIO Library Introduction Currently, there are two major GPIO libraries for Raspberry Pi, RPi.GPIO and wiringPi. RPi.GPIO: RPi.GPIO is a python module to control Raspberry Pi GPIO channels. For more information about RPi.GPIO, please visit: https://pypi.python.org/pypi/RPi.GPIO/ For examples and documentation, please visit: http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ The RPi.GPIO module is pre-installed in the official Raspbian operating system, you can use it directly.
Page 9
Next, verify whether the wiringPi is installed successfully or not: wiringPi includes a command-line utility gpio which can be used to program and setup the GPIO pins. You can use this to read and write the pins and even use it to control them from shell scripts. You can verify whether the wiringPi is installed successfully or not by the following commands: $ sudo gpio -v...
How to use the wiringPi and the RPi.GPIO Here we take a blinking LED for example to illustrate how to use the wiringPi C library and the RPi.GPIO Python module. Step 1 : Build the circuit according to the following schematic diagram Note : Resistance=220Ω...
Page 11
Step 4 : Run the program $ sudo python led.py Press Enter, you should see that the LED is blinking. Press ’Ctrl+C’, the program execution will be terminated. For C language user: Step 2 : Create a file named led.c $ sudo touch led.c Step 3 : Open the file led.c with vim or nano - 7 -...
Page 12
$ sudo vim led.c Write down the following source code, then save and exit. Step 4 : Compile the code $ sudo gcc led.c -lwiringPi After executing this command, you'll find a file named a.out appear in the current directory. It is an executable program. Step 5 : Run the program $ sudo ./a.out Press Enter, you should see that the LED is blinking.
Page 13
Before learning the next courses, please copy the source code we provided to your Raspberry Pi's /home/ directory, or you can get the source code directly from our github repository : C Language Source Code : $ git clone https://github.com/adeept/Adeept_Starter_Kit_C_Code_for_RPi.git Python Source Code : $ git clone https://github.com/adeept/Adeept_Starter_Kit_Python_Code_for_RPi.git - 9 -...
Lesson 1 Blinking LED Overview In this tutorial, we will start the journey of learning Raspberry Pi. In the first lesson, we will learn how to control an LED. Requirement - 1* Raspberry Pi - 1* 220Ω Resistor - 1* LED - 1* Breadboard - 2* Jumper Wires Principle...
Page 15
As shown in the schematic diagram above, the anode of LED is connected to VCC(+3.3V), and the cathode of LED is connected to the Raspberry Pi GPIO. When the GPIO output low level, the LED is on; when the GPIO output high level, the LED is off. ②...
Page 16
Writes the value HIGH or LOW (1 or 0) to the given pin which must have been WiringPi previously set as an output. treats any non-zero number as HIGH, however 0 is the only representation of LOW. ● void delay (unsigned int howLong) This causes program execution to pause for at least howLong milliseconds.
Page 17
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/01_blinkingLed/blinkingLed.c) #include <wiringPi.h> #include <stdio.h> #define LedPin main(void) if(wiringPiSetup() == -1){ //when initialize wiringPi failed, print message to screen printf("setup wiringPi failed !\n"); return pinMode(LedPin, OUTPUT);...
Page 18
Note : The parameter ‘-o’ is to specify a file name for the compiled executable program. If you do not use this parameter, the default file name is a.out. 2.3 Run the program $ sudo ./led Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/01_blinkingLed_1.py) #!/usr/bin/env python import...
Lesson 2 Buzzer Overview In this lesson, we will learn how to program the Raspberry Pi to make an active buzzer sound. Requirement - 1* Raspberry Pi - 1* Active buzzer - 1* 1 kΩ Resistor - 1* NPN Transistor (S8050) - 1* Breadboard - Several Jumper wires Principle...
Page 21
below: There are two driving circuit for the buzzer: Figure1 Figure2 Figure 1: Set the Raspberry Pi GPIO as a high level, the transistor S8050 will conduct, and then the buzzer will sound; set the Raspberry Pi GPIO as low level, the transistor S8050 will cut off, then the buzzer will stop.
Page 22
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/02_buzzer/buzzer.c) 2.2 Compile the program $ gcc buzzer.c -o buzzer -lwiringPi 2.3 Run the program $ sudo ./buzzer Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/02_buzzer.py) 2.2 Run the program $ sudo python 02_buzzer.py...
Page 23
Summary By learning this lesson, we have mastered the basic principle of the buzzer and the transistor. We also learned how to program the Raspberry Pi and then control the buzzer. I hope you can use what you have learned in this lesson to do some interesting things.
Lesson 3 Controlling an LED with a button Overview In this lesson, we will learn how to detect the status of a button, and then toggle the status of LED based on the status of the button. Requirement - 1* Raspberry Pi - 1* Button - 1* LED - 1* 220Ω...
Page 25
Each time you press the button, the Raspberry Pi will think you have pressed the button many times due to the jitter of the button. We must to deal with the jitter of buttons before we use the button. We can remove the jitter of buttons through the software programming, besides, we can use a capacitance to remove the jitter of buttons.
Page 26
need to activate a pull-up/pull-down, then you can do it with the gpio program in a script before you start your program. ● int digitalRead (int pin) This function returns the value read at the given pin. It will be HIGH or LOW (1 or 0) depending on the logic level at the pin.
Page 27
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/03_btnAndLed/btnAndLed_2.c) 2.2 Compile the program $ gcc btnAndLed_2.c -o btnAndLed -lwiringPi 2.3 Run the program $ sudo ./btnAndLed Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/03_btnAndLed_1.py) 2.2 Run the program $ sudo python 03_btnAndLed_1.py...
Page 28
Summary Through this lesson, you should have learned how to use the Raspberry Pi detect an external button status, and then toggle the status of LED relying on the status of the button detected before. - 24 -...
Lesson 4 Tilt Switch Overview In this lesson, we will learn how to use the tilt switch and change the status of an LED by changing the angle of tilt switch. Requirement - 1* Raspberry Pi - 1* Tilt switch - 1* LED - 1* 220Ω...
Page 30
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/04_tiltSwitch/tiltSwitch.c) 2.2 Compile the program $ gcc tiltSwitch.c -o tiltSwitch -lwiringPi 2.3 Run the program $ sudo ./tiltSwitch Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/04_tiltSwitch.py) 2.2 Run the program $ sudo python 04_tiltSwitch.py...
Page 31
switch is a very simple electronic component, but simple device can often make something interesting. - 27 -...
Lesson 5 LED Flowing Lights Overview In the first class, we have learned how to make an LED blink by programming the Raspberry Pi. Today, we will use the Raspberry Pi to control 8 LEDs, so that 8 LEDs showing the result of flowing. Requirement - 1* Raspberry Pi - 8* LED...
Page 33
then the condition is tested again. When the condition becomes false, the loop ends. Procedures 1. Build the circuit 2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/05_flowingLed/flowingLed.c) 2.2 Compile the program $ gcc flowingLed.c -o flowingLed -lwiringPi Run the program $ sudo ./flowingLed...
Page 34
Now, you should see 8 LEDs are lit in sequence from the right green one to the left, next from the left to the right one. And then repeat the above phenomenon. Summary Through this simple and fun experiment, we have learned more skilled programming about the Raspberry Pi.
Lesson 6 Breathing LED Overview In this lesson, we will learn how to program the Raspberry Pi to generate PWM signal. And use the PWM square-wave signal control an LED gradually becomes brighter and then gradually becomes dark like the animal's breath. Requirement - 1* Raspberry Pi - 1* LED...
Page 36
Key function: C user: ● pwmWrite(int pin, int value) Writes the value to the PWM register for the given pin. The Raspberry Pi has one on-board PWM pin, pin 1 (BMC_GPIO 18, Phys 12) and the range is 0-1024. Other PWM devices may have other PWM ranges.
Page 37
Procedures 1. Build the circuit 2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/06_breathingLed/breathingLed.c) 2.2 Compile the program $ gcc breathingLed.c -o breathingLed -lwiringPi 2.3 Run the program $ sudo ./breathingLed Python user: 2.1 Edit and save the code with vim or nano.
Page 38
Now, you should see the LED gradually from dark to brighter, and then from brighter to dark, continuing to repeat the process, its rhythm like the animal's breathing. Summary By learning this lesson, I believe that you have understood the basic principles of the PWM, and mastered the PWM programming on the Raspberry Pi platform.
Lesson 7 Controlling a RGB LED with PWM Overview In this lesson, we will program the Raspberry Pi for RGB LED control, and make RGB LED emits a variety of colors of light. Requirement - 1* Raspberry Pi - 1* RGB LED - 3* 220Ω...
Page 40
● void softPwmWrite (int pin, int value) This updates the PWM value on the given pin. The value is checked to be in-range and pins that haven’t previously been initialised via softPwmCreate will be silently ignored. Procedures 1. Build the circuit 2.
Page 41
(Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/07_rgbLed.py) 2.2 Run the program $ sudo python 07_rgbLedLed.py Now, you can see that the RGB LED emitting red, green, blue, yellow, white and purple light, then the RGB LED will be off, each state continues 1s, after repeating the above procedure.
Lesson 8 7-segment display Overview In this lesson, we will program the Raspberry Pi to achieve the controlling of segment display. Requirement - 1* Raspberry Pi - 1* 220Ω Resistor - 1* 7-Segment display - 1* Breadboard - Several Jumper wires Principle The seven-segment display is a form of electronic display device for displaying decimal numerals that is an alternative to the more complex dot matrix displays.
Page 43
A 7-segment display has seven segments for displaying a figure and a segment for displaying a decimal point. If you want to display a number ‘1’, you should only light the segment b and c. Key function: ● void digitalWriteByte (int value) This writes the 8-bit byte supplied to the first 8 GPIO pins.
Page 44
C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/08_segment/segment.c) 2.2 Compile the program $ gcc segment.c -o segment -lwiringPi 2.3 Run the program $ sudo ./segment Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/08_segment.py) 2.2 Run the program $ sudo python 08_segment.py...
Page 45
Through this lesson, we have learned the principle and programming of segment display. I hope you can combine the former course to modify the code we provided in this lesson to achieve cooler originality. - 41 -...
Lesson 9 Dot-matrix display Overview In this lesson, we will program to control a 8*8 dot-matrix display to realize the display of graphical and digital we want. Requirement - 1* Raspberry Pi - 1* 8*8 Dot-matrix display - 2* 74HC595 - 1* Breadboard - Several Jumper wires Principle...
Page 47
A certain drive current is required for the dot-matrix display. In addition, more pins are needed for connecting dot-matrix display with controller. Thus, to save the Raspberry Pi’s GPIO, driver IC 74HC595 is used in this experiment. 2. 74HC595 The 74HC595 is an 8-stage serial shift register with a storage register and 3-state outputs.
Page 48
Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/09_ledMatrix.py) 2.2 Run the program $ sudo python 09_ledMatrix.py Now, you can see a rolling “Adeept” should be displayed on the dot-matrix display. - 44 -...
Page 49
Summary In this experiment, we have not only learned how to operate a dot-matrix display to display numbers and letters, but also learned the basic usage of 74HC595, then you can try operating the dot-matrix display to show other images. - 45 -...
Overview In this lesson, we will learn how to use a character display device—LCD1602 on the Raspberry Pi platform. First, we make the LCD1602 display a string "Hello Geeks!" scrolling, then display“Adeept”and“www.adeept.com”static. Requirement - 1* Raspberry Pi - 1* LCD1602 - 1* 10KΩ...
Page 51
Key function: ● int lcdInit (int rows, int cols, int bits, int rs, int strb, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) This is the main initialisation function and must be called before you use any other LCD functions.
Page 52
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/10_lcd1602/lcd1602_2.c) 2.2 Compile the program $ gcc lcd1602_2.c -o lcd1602_2 -lwiringPi -lwiringPiDev 2.3 Run the program $ sudo ./lcd1602_2 Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/10_lcd1602.py) 2.2 Run the program $ sudo python 10_lcd1602.py...
Page 53
"Adeept" and " www.adeept.com " is displayed on the LCD1602 static. Summary I believe that you have already mastered the driver of LCD1602 through this lesson. I hope you can make something more interesting base on this lesson and the previous lesson learned .
Lesson 11 Photoresistor Overview In this lesson, we will learn how to measure the light intensity by photoresistor and make the measurement result displayed in the screen. Requirement - 1* Raspberry Pi - 1* ADC0832 - 1* Photoresistor - 1* 10KΩ Resistor - 1* Breadboard - Several Jumper wires Principle...
Page 55
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/11_photoresistance/photoresistor.c) 2.2 Compile the program $ gcc photoresistor.c -o photoresistor -lwiringPi 2.3 Run the program $ sudo ./photoresistor Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/11_photoresistor.py) 2.2 Run the program $ sudo python 11_photoresistor.py...
Page 56
Summary By learning this lesson, we have learned how to detect surrounding light intensity with the photoresistor. You can play your own wisdom , and make more originality based on this experiment and the former experiment. - 52 -...
Lesson 12 Controlling an LED through LAN Overview In this lesson, we will introduce TCP and socket, and then programming to control an LED through the local area network(LAN). Requirement - 1* Raspberry Pi - 1* LED - 1* 220Ω Resistor - 1* Breadboard - Several Jumper wires Principle...
Page 58
Control Protocol (TCP) or Stream Control Transmission Protocol (SCTP). 3. Raw sockets (or Raw IP sockets), typically available in routers and other network equipment. Here the transport layer is bypassed, and the packet headers are made accessible to the application. In this experiment, our program is based on stream socket, and the program is divided into two parts, the client and the server.
Page 59
2.4 Compile the program(On Linux PC) $ gcc ledClient.c -o ledClient 2.5 Run the program $ sudo ./ledServer (On Raspberry Pi) $ ./ledClient 192.168.1.188 (On PC, Modify the IP Address to your Raspberry Pi’s IP Address) Now, input “ON” in the terminal and then press Enter, you will find the LED connected to the Raspberry Pi is on, input “OFF”, the LED is off.
Page 60
Summary By learning this lesson, you should have understood the basic principles of inter-computer communication. I hope this lesson will help you open the door to learn IoT(Internet of Things). - 56 -...
Lesson 13 How to control a servo Overview In this lesson, we will introduce a new electronic device (Servo) to you, and tell you how to control it with Raspberry Pi. Requirement - 1* Raspberry Pi - 1* Servo - 1* Breadboard - Several Jumper wires Principle Servo is a type of geared motor that can only rotate 180 degrees.
Page 62
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/13_servo/servo.c) 2.2 Compile the program $ gcc servo.c -o servo -lwiringPi 2.3 Run the program $ sudo ./servo Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/13_servo.py) 2.2 Run the program $ sudo python 13_servo.py...
Lesson 14 A Simple Voltmeter Overview In this lesson, we will make a simple voltmeter with Raspberry Pi and LCD1602, the range of this voltmeter is 0~5V. Then, we will measure the voltage of the potentiometer’s adjustment end with the simple voltmeter and display it on the LCD1602.
Page 65
2. Program 2.1 Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/14_voltage/voltmeter.c) 2.2 Compile the program $ gcc voltmeter.c -o voltmeter -lwiringPi 2.3 Run the program $ sudo ./voltmeter Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/14_voltmeter.py) 2.2 Run the program $ sudo python 14_voltmeter.py...
Page 66
The substance of voltmeter is reading analog voltage which input to ADC. Through this course, I believe that you have mastered how to read analog value and how to make a simple voltmeter with Raspberry Pi. - 62 -...
Lesson 15 DC motor Overview In this comprehensive experiment, we will learn how to control the state of DC motor with Raspberry Pi. The state of DC motor includes its forward, reverse, acceleration, deceleration and stop. Requirement - 1* Raspberry Pi - 1* L9110 DC Motor driver - 1* DC motor - 4* Button...
Page 68
2. L9110 L9110 is a driver chip which is used to control and drive motor. The chip has two TTL/CMOS compatible input terminals, possesses property anti-interference: it has high current driving capability, two output terminals that can directly drive DC motor, each output port can provide 750~800mA dynamic current, and its peak current can reach 1.5~2.0A;...
Page 69
2. Program C user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_C_Code_for_RPi/15_motor/motor.c) 2.2 Compile the program $ gcc motor.c -o motor -lwiringPi 2.3 Run the program $ sudo ./motor Python user: 2.1 Edit and save the code with vim or nano. (Code path: /home/Adeept_Starter_Kit_Python_Code_for_RPi/15_motor.py) 2.2 Run the program $ sudo python 15_motor.py...
Page 70
Summary I think you must have grasped the basic theory and programming of the DC motor after studying this experiment. You not only can forward and reverse it, but also can regulate its speed. Besides, you can do some interesting applications with the combination of this course and your prior knowledge.
Need help?
Do you have a question about the Super Starter and is the answer not in the manual?
Questions and answers