Advertisement

About SunFounder
SunFounder is a technology company focused on Raspberry Pi and Arduino open source
community development. Committed to the promotion of open source culture, we strive to
bring the fun of electronics making to people all around the world and enable everyone to
be a maker. Our products include learning kits, development boards, robots, sensor modules
and development tools. In addition to high quality products, SunFounder also offers video
tutorials to help your own project. If you have interest in open source or making something
cool, welcome to join us! Visit
About the Super Kit 3.0
This super kit is suitable for the
model
B+. It includes various components and chips that can show different interesting
phenomena. You can make it happen by following the experiment instructions, and learn
basic knowledge about them. Also you can explore more application after mastering the
principle and code. Now get on the road!
In this book, we will show you circuits with both realistic illustrations and schematic diagrams.
You can go to our official website
clicking
LEARN
-->
Free Support
If you have any TECHNICAL questions, add a topic under
and we'll reply as soon as possible.
For NON-TECH questions like order and shipment issues, please
service@sunfounder.com. You're also welcomed to share your projects on FORUM.
www.sunfounder.com
Raspberry Pi B, model B+, Pi 2 model B, Pi 3 model B and Pi 3
www.sunfounder.com
Get tutorials
and watch related videos by clicking VIDEO.
Preface
for more!
to download the related code by
FORUM
section on our website
send an email to
Reprint 2.0

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Super Kit 3.0 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for SunFounder Super Kit 3.0

  • Page 1 Preface About SunFounder SunFounder is a technology company focused on Raspberry Pi and Arduino open source community development. Committed to the promotion of open source culture, we strive to bring the fun of electronics making to people all around the world and enable everyone to be a maker.
  • Page 2: Table Of Contents

    Contents Components List ........................1 Components Introduction...................... 8 Resistor ................................8 Potentiometer ............................10 LED .................................11 RGB LED ................................12 Jumper Wires ..............................13 Breadboard ..............................13 Get Started .......................... 16 Preparation ..............................16 Access to Raspberry Pi’s Console ......................16 Using Console in GUI (terminal, recommended for beginners) ..........16 Using Console Only ..........................18 Introduction to Raspberry Pi ....................
  • Page 3 Lesson 4 Breathing LED ......................48 Lesson 5 RGB LED ......................... 52 Lesson 6 Buzzer ........................56 Lesson 7 Relay ........................60 Lesson 8 4N35 ........................64 Lesson 9 Ne555 ........................68 Lesson 10 Slide Switch ......................72 Lesson 11 How to Drive a DC Motor ..................76 Lesson 12 Rotary Encoder ....................
  • Page 4: Components List

    Components List Name Quantity Component 555 Timer IC Optocoupler (4N35) Shift Register (74HC595) L293D Accelerometer ADXL345 Rotary Encoder...
  • Page 5 Potentiometer (50k) Resistor (220Ω) (red, red, black, black, brown) Resistor (1kΩ) (brown, black, black, brown, brown) Resistor (10kΩ) (brown, black, black, red, brown) Resistor (100kΩ) (brown, black, black, orange, brown) Resistor (1MΩ) (brown, black, green, gold) Resistor (5.1MΩ) (green, brown, green, gold) Diode Rectifier Switch...
  • Page 6 Button Power Supply Module LCD1602 Dot Matrix Display (8*8) 7-Segment Display DC Motor...
  • Page 7 RGB LED LED (red) LED (white) LED (green) LED (yellow) NPN Transistor (S8050)
  • Page 8 PNP Transistor (S8550) Capacitor Ceramic 100nF Capacitor Ceramic 10nF Breadboard Active Buzzer Relay...
  • Page 9 Male-to-Male Jumper Wire Female-to-Male Dupont Wire 5-Pin Anti-reverse Cable 9V Battery Buckle M3*10 Screw M2.5*6 Screw M3*6 Screw...
  • Page 10 RAB Holder T-Extension Board 40-Pin GPIO Cable Notes: After unpacking, please check that the number of components is correct and that all components are in good condition.
  • Page 11: Components Introduction

    Components Introduction Resistor Resistor is an electronic element that can limit the branch current. A fixed resistor is one whose resistance cannot be changed, when that of a potentiometer or variable resistor can be adjusted. The resistors in this kit are fixed ones. It is essential in the circuit to protect the connected components.
  • Page 12 As shown in the card, each color stands for a number. Black Brown Red Orange Yellow Green Blue Violet Grey White Gold Silver 0.01 The 4- and 5-band resistors are frequently used, on which there are 4 and 5 chromatic bands. Let’s see how to read the resistance value of a 5-band resistor as shown below.
  • Page 13: Potentiometer

    Read the resistance of the above resistor from left to right. The value is 1(brown) 0(block) x 10^5(green)=10x10^5Ω=10^6Ω=1MΩ and the permissible error is ±5%(gold) The resistance value of the resistor below is 5(green) 1(brown) x 10^5(green) = 51 x 10^5 Ω = 5.1 x 10^6 Ω...
  • Page 14: Led

    3. When the potentiometer is used as a rheostat, connect the middle pin and one of the other 2 pins in the circuit. Thus you can get a smoothly and continuously changed resistance value within the travel of the moving contact. 4.
  • Page 15: Rgb Led

    RGB LED An RGB LED is provided in this kit. RGB LEDs emit light in various colors. An RGB LED packages three LEDs of red, green, and blue into a transparent or semitransparent plastic shell. It can display various colors by changing the input voltage of the three pins and superimpose them, which, according to statistics, can create 16,777,216 different colors.
  • Page 16: Jumper Wires

    comes the green and the blue one. Therefore, you may need to add a current limiting resistor with different resistances to the three pins for these colors. Jumper Wires Wires that connect two terminals are called jumper wires. There are various kinds of jumper wires.
  • Page 17 soldering up your circuit. Therefore, in lots of experiments, it is often used as a hub to connect two or more devices. Normally, there are two types of breadboard: full+ and half+. You can tell their difference from the names. A half+ breadboard is half the size of a full+ one and their functions are the same.
  • Page 18 (u) Internal structure of the full+ Now let’s make some simple experiment with the breadboard. Turn on an LED as shown in the figure below. You can have a try and the LED will light up. The breadboard makes it possible for you to plug and pull components at any time without welding, which is very convenient for tests.
  • Page 19: Get Started

    Get Started Preparation 1. Prepare a MicroSD/TF card of no less than 8GB, a 5V 2A DC power adapter with a MicroUSB port, and a network cable (to connect your router and Raspberry Pi, or plug in the USB Wi-Fi adapter directly if you have one). 2.
  • Page 20 Wait for a while and the GUI display will show up as below. Note: The screen monitor shown above is the 10.1 inch one we're using, available on our website www.sunfounder.com and our Amazon store. Check out now and use your Raspberry Pi in a most convenient way.
  • Page 21: Using Console Only

    4. Then a terminal will pop up as follows: Here’s the console we talk about before. Using Console Only There are several ways to use the console only and they can be divided into mainly two ways: using directly and remotely. A.
  • Page 22 Type in ssh pi@<ip_address> – ssh is the tool for remote login; pi, the user name, and <ip_address> as the name suggests, your RPi's IP address. For example: pi@192.168.0.1 Press Enter to confirm. If you get a prompt that no ssh is found, you need to install a ssh tool like Ubuntu and Debian by yourself: sudo apt-get install ssh...
  • Page 23 4. Enter the IP address of the RPi you just got in the textbox under Host Name (or IP address) and 22 under Port (by default it is 22) 5. Click Open. Note that when you first log in to the Raspberry Pi with the IP address, you'll be prompted with a security reminder.
  • Page 24 Note: when you're typing the password in, the window shows nothing just null, but you're in fact is typing things in. So just focus on typing it right and press Enter. After you log in the RPi successfully, the window will display as follows. Now, no matter what method you take, you can get in the console of your Raspberry Pi.
  • Page 25: Introduction To Raspberry Pi

    Introduction to Raspberry Pi RAB Holder RAB Holder is a basic but indispensable component for your experiment. It makes your experiment easier and can be used for fixing a bread board, an Arduino board like Uno board or Mega2560, or a Raspberry Pi board. Before starting the experiment, you need to fix the Raspberry Pi and the breadboard on the RAB Holder first.
  • Page 26 Then place the Raspberry Pi in the holder, fasten it with M2.5x5 screws. Since it may be a little difficult to fasten it, be careful to operate. Pay attention to the direction when plugging in the 40-pin GPIO Cable into the Raspberry Pi pins.
  • Page 27: Raspberry Pi

    Raspberry Pi A Raspberry Pi is an indispensable component for the kit, the control device. But it is not included in the kit and you need to prepare one yourself. Raspberry Pi is a kind of minicomputer for users like amateurs, teachers, students and small businesses, etc.
  • Page 28: Extension Board

    to right. The columns near Physical are the V (voltage), Mode (Input or Output), Name (original name), wPi (wiringPi, C language based on), BCM (Python based on) of the pins. Besides the original name of the pins, there are other three ways of naming including physical, wiringPi and BCM.
  • Page 29 This is our 40-pin GPIO Extension Board and GPIO cable for Raspberry Pi model B+, 2 model B, 3 model B and 3 model B+. For your better understanding of every pins, we have drawn a table for you to know the Name, BCM and wiring pi of each pin.
  • Page 30 Also, we have drawn a table of the corresponding BCM, wiringPi and Name of each pins.
  • Page 31: Gpio Libraries

    GPIO Libraries WiringPi Introduction WiringPi is a GPIO library for C applied to the Raspberry Pi. It complies with GUN Lv3. The functions in wiringPi are similar to those in the wiring system of Arduino. They enable the users familiar with Arduino to use wiringPi more easily. Now the Raspbian system has wiringPi pre-installed, you can use it directly.
  • Page 32: Rpi.gpio

    RPi.GPIO If you are a Python user, you can program GPIOs with API provided by RPi.GPIO and use BCM numbering method to control the GPIOs of Raspberry Pi. Please note that it differs from the way that using wiringPi numbering method to control the GPIO on a Raspberry Pi in C language.
  • Page 33: Download The Code

    Informally, here is to go to the path /home/pi/. Clone the repository from GitHub clone https://github.com/sunfounder/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi.git The advantage of this method is that, you can update the latest code any time you want, using under the folder.
  • Page 34: Lesson 1 Blinking Led

    Lesson 1 Blinking LED Introduction In this lesson, we will learn how to program Raspberry Pi to make an LED blink. You can play numerous tricks with an LED as you want. Now get to start and you will enjoy the fun of DIY at once! Components - 1 * Raspberry Pi...
  • Page 35 For C language users: Step 2: Go to the folder of the code. If you use a monitor, you're recommended to take the following steps. Go to /home/pi/ and find the folder SunFounder_Super_Kit_V3.0_for_Raspberry_Pi Find C in the folder, right-click on it and select Open in Terminal. Then a window will pop up as shown below.
  • Page 36 In either way, you now are in the folder C. The subsequent procedures under the two methods are the same. Let's move on. Step 3: Compile the Code gcc 01_blinkLed.c -o 01_blinkLed -lwiringPi Compiler Collection. Here, it functions like compiling the C language file Note: 01_blinkLed.c and outputting an executable file 01_blinkLed.
  • Page 37 If you want to view the code 01_blinkLed.c, press Ctrl + C to stop running the code. Then type the following command to open it: nano 01_blinkLed.c Note: nano is a text editor tool. The command is to open the code file 01_edblinkLed.c by this tool.
  • Page 38 Code Explanation #include <wiringPi.h>//The hardware drive library designed for the C language of Raspberry Pi. Adding this library is convenient for hardware initialization, I/O ports, PWM outputs, etc. #include <stdio.h>// Standard I/O library. The pintf function used for printing the data displayed on the screen is realized by this library.
  • Page 39 Click Run ->Run Module in the window and the following contents will appear. To stop it from running, just click the X button on the top right to close it and then you'll back to the code details. If you modify the code, before clicking Run Module (F5) you need to save it first.
  • Page 40 Note: nano is a text editor tool. The command is to open the code file 01_blinkLed.c by this tool. Code Explanation #!/usr/bin/env python: When the system detects this, it will search the installation path of python in the env setting, then call the corresponding interpreter to complete the operation. It’s to prevent the user not installing the python onto the /usr/bin default path.
  • Page 41 # delay 0.5 second, which is equals to the delay in C language, using second as the unit, time.sleep(0.5) print 'LED OFF...' # Turn off LED GPIO.output(LedPin, GPIO.HIGH) time.sleep(0.5) # Define a destroy function for clean up everything after the script finished def destroy(): # Turn off LED GPIO.output(LedPin, GPIO.HIGH)
  • Page 42 It will not appear only when you run the make command after having changed the code and saved it. Tips: For any TECHNICAL questions, add a topic under FORUM section on our website www.sunfounder.com and we'll reply as soon as possible.
  • Page 43: Lesson 2 Controlling An Led By A Button

    Lesson 2 Controlling an LED by a Button Introduction In this lesson, we will learn how to turn an LED on or off by a button. Components - 1 * Raspberry Pi - 1 * Breadboard - 1 * LED - 1 * Button - 1 * Resistor (220Ω) - Jumper wires...
  • Page 44 When the button is pressed, the 4 pins are connected, thus closing the circuit. Use a normally open button as the input of Raspberry Pi, the detailed connection is as shown in the schematic diagram below. When the button is pressed, the B18 will turn into low level (0V).
  • Page 45 make 02_buttonControlLed Step 4: Run the executable file above sudo ./02_buttonControlLed Step 5: Check the code nano 02_buttonControlLed.c Code Explanation #define LedPin Pin B17 in the T_Extension Board connects to the GPIO0. GPIO0 corresponds to pin0 in the wiringPi pin figure. So in C program, LedPin is defined as 0. #define ButtonPin 1 Pin B18 in the T_Extension Board connects to the GPIO8.
  • Page 46 /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python Step 3: Run the code sudo python 02_buttonControlLed.py Step 4: Check the code nano 02_buttonControlLed.py Code Explanation LedPin = 17 # Set #17 as LED pin BtnPin = 18 # Set #18 as button pin # Set up a falling detect on BtnPin, and callback function to swled GPIO.add_event_detect(BtnPin, GPIO.FALLING, callback=swLED) # Define a callback function for button callback, execute the function after the callback of the interrupt.
  • Page 47: Lesson 3 Flowing Led Lights

    Lesson 3 Flowing LED Lights Introduction In this lesson, we will learn how to make eight LEDs blink in various effects as you want based on Raspberry Pi. Components - 1 * Raspberry Pi - 1 * Breadboard - 8 * LED - 8 * Resistor (220Ω) - Jumper wires - 1 * T-Extension Board...
  • Page 48 programming, and then LED0-LED7 will light up in turn. You can make eight LEDs blink in different effects by controlling their delay time and the order of lighting up. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Open the code file /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Note: Use the cd command to switch to the code path of this experiment.
  • Page 49 Code Explanation void Led_on(int channel): This is a subfunction with a formal parameter int channel for importing the numbers of the controlled pins. Its function body is digitalWrite(channel, LOW); Set the I/O port of channel as low level(0V), the LED on this port lights up. void led_off(int channel) is to turn off the LED.
  • Page 50 Step 2: Open the code file /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python Step 3: Run sudo python 03_8Led.py Code Explanation LedPins = [17, 18, 27, 22, 23, 24, 25, 4] # The cathodes of the 8 LEDs connect to B17, B18, B27, 22, 23, 24, 25, 4 of the T-shape extension board. In BCM, these pins are corresponding to 17, 18, 27, 22, 23, 24, 25, and 4.
  • Page 51: Lesson 4 Breathing Led

    Lesson 4 Breathing LED Introduction In this lesson, we will try something interesting – gradually increase and decrease the luminance of an LED with PWM, just like breathing. So we give it a magical name - Breathing LED. Components - 1 * Raspberry Pi - 1 * Breadboard - 1 * LED - 1 * Resistor (220Ω)
  • Page 52 In this experiment, we use this technology to make the LED brighten and dim slowly so it looks like our breath. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Open the code file /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C...
  • Page 53 Step 3: Compile the Code make 04_breathLed Step 4: Run the executable file above sudo ./04_breathLed Code Explanation pinMode(LedPin, PWM_OUTPUT); // Set the I/O as pwn output for(i=0;i<1024;i++){ // i,as the value of pwm, increases progressively during 0-1024. pwmWrite(LedPin, i); // Write i into the LEDPin delay(2);...
  • Page 54 pLed.ChangeDutyCycle(dc) # ChangeDutyCycle() function in pLED output pulse width 0~100% according to the variable dc. print " ++ Duty cycle: %s"%dc # print information time.sleep(delay) # it will delay after changing the pulse width for each time, this parameter can be modified to change the LED’s lighting and dimming speed.
  • Page 55: Lesson 5 Rgb Led

    Lesson 5 RGB LED Introduction Previously we've used the PWM technology to control an LED brighten and dim. In this lesson, we will use it to control an RGB LED to flash various kinds of colors. Components - 1 * Raspberry Pi - 1 * Breadboard - 1 * RGB LED - 3 * Resistor (220Ω)
  • Page 56 Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Open the code file /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile the Code make 05_rgb Step 4: Run the executable file above sudo ./05_rgb Code Explanation #include <softPwm.h> // library used for realizing the pwm function of the software. void ledInit(void){ // define function used for initializing I/O port to output for pwm.
  • Page 57 softPwmWrite(LedPinGreen, g_val); softPwmWrite(LedPinBlue, b_val); ledColorSet(0xff,0x00,0x00); // red calls the function defined before. Write oxff into LedPinRed and ox00 into LedPinGreen and LedPinBlue. Only the Red LED lights up after running this code. If you want to light up LEDs in other colors, just modify the parameters.
  • Page 58 B_val = (color & 0x0000FF) >> 0 # assign the last two values to B, please refer to the shift operation of the hexadecimal for details. R_val = MAP(R_val, 0, 255, 0, 100) # use map function to map the R,G,B value among 0~255 into PWM value among 0-100.
  • Page 59: Lesson 6 Buzzer

    Lesson 6 Buzzer Introduction In this lesson, we will learn how to drive an active buzzer to beep with a PNP transistor. Components - 1 * Raspberry Pi - 1 * Breadboard - 1 * Buzzer (Active) - 1 * PNP transistor (8550) - 1 * Resistor (1KΩ) - Jumper wires - 1 * T-Extension Board...
  • Page 60 You can check the pins of the buzzer, the longer one is the anode and the shorter one is the cathode. Please don’t mix them up when connecting, otherwise the buzzer will not make sound. Transistor The transistor is a semiconductor device that controls current by current. It functions by amplifying weak signal to larger amplitude signal and is also used as a non-contact switch.
  • Page 61 The schematic diagram: Principle: In this experiment, an active buzzer, a PNP transistor and a 1k resistor are used between the base of the transistor and GPIO to protect the transistor. When the B17 of Raspberry Pi output is supplied with low level (0V) by programming, transistor will...
  • Page 62 digitalWrite(BeepPin, LOW); // We use an active buzzer in this experiment, so it will make sound automatically when connecting to the direct current. This sketch is to set the I/O port as low level (0V), thus to manage the transistor and make the buzzer beep. digitalWrite(BeepPin, HIGH);...
  • Page 63: Lesson 7 Relay

    Lesson 7 Relay Introduction As we know relay is a device which is used to provide connection between two or more points or device in response to the input signal applied. In another words relay provide isolation between the controller and the device as we know devices may work on AC as well as on DC.
  • Page 64 . Normally close – not connected when the relay is activated, and connected when it is inactive. 5. Molded frame – Relays are covered with plastic for protection. Working of Relay The working principle of relay is simple. When power is supplied to the relay, currents start flowing through the control coil;...
  • Page 65 Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Open the code file /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile the Code make 07_relay Step 4: Run the executable file above sudo ./07_relay Code Explanation digitalWrite(relayPin, LOW); // set the I/O port as low level (0V) to energize the transistor.
  • Page 66 time.sleep(1) # wait for 1 second. Change the switching frequency of the relay by changing this parameter. Note: Relay is a kind of metal dome formed in mechanical structure. So its lifespan will be shortened under high-frequency using. GPIO.output(relayPin, GPIO.HIGH) # Set the pins of the transistor as low level to let the relay open.
  • Page 67: Lesson 8 4N35

    Lesson 8 4N35 Introduction The 4N35 is an optocoupler for general purpose application. It consists of gallium arsenide infrared LED and a silicon NPN phototransistor. When the input signal is applied to the LED in the input terminal, the LED lights up. After receiving the light signal, the light receiver then converts it into electrical signal and outputs the signal directly or after amplifying it into a standard digital level.
  • Page 68 See the internal structure of 4N35 above. Pin 1 and 2 are connected to an infrared LED. When the LED is electrified, it'll emit infrared rays. To protect the LED from burning, usually a resistor (about 1K) is connected to pin 1. Then the NPN phototransistor is power on when receiving the rays.
  • Page 69 For C language users: Step 2: Open the code file /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile the Code make 08_4N35 Step 4: Run the executable file above. sudo ./08_4N35 Code Explanation digitalWrite(_4N35Pin, LOW); // set the I/O port as low level (0V), thus the optocoupler is energized, and the pin connected to LED conducts to the 0V.
  • Page 70 Exploration 4N35 is an optocoupler that usually used for driving relay as well as motor circuits. As there is no direct connection between the input and output, even if a short circuit at the output end occurs, the control board will not be burnt. Have a try!
  • Page 71: Lesson 9 Ne555

    Lesson 9 Ne555 Introduction If you ask anyone in the know to rank the most commonly and widely used IC, the famous 555 time base IC would certainly be at the top of the list. The 555 – a mixed circuit composed of analog and digital circuits –...
  • Page 72 Pin 4 (RESET): output low level when supplied a low one;  Pin 5 (CONTROL VOLTAGE): changing the upper and lower level trigger values;  Pin 6 (THRESHOLD): the input of upper comparator;  Pin 7 (DISCHARGE): having two states of suspension and ground connection also ...
  • Page 73 Step 4: Run the executable file above. sudo ./09_ne555 Code Explanation static volatile int globalCounter = 0 ; // a static integer variable to store the pulse count void exInt0_ISR(void) { //GPIO0 interrupt service routine ++globalCounter; wiringPiISR(Pin0, INT_EDGE_FALLING, &exInt0_ISR); // set an interrupt here and the signal is falling edge for Pin 0.
  • Page 74 Code Explanation g_count = 0 # a global variable used to store the pulse count # Define a function to be run when an interrupt happens def count(ev=None): global g_count # this function will change the value of the global variable g_count, thus here we add global before it.
  • Page 75: Lesson 10 Slide Switch

    Lesson 10 Slide Switch Introduction In this lesson, we will learn how to use a Slide Switch. Usually, the slide switch is soldered on PCB as a power switch, but here we need to insert it into the breadboard, thus it may not be tightened.
  • Page 76 Principle: Connect the middle pin of the Slide Switch to B17, and two LEDs to pin B18 and B27 respectively. Then when you pull the slide, you can see the two LEDs light up alternately. Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Go to the folder of the code.
  • Page 77 sudo ./10_slideSwitch Code Explanation // When the slide is pulled to the left, the middle pin and left one are connected; the Raspberry Pi reads a high level at the middle pin, so the LED1 is on and LED2 off if(digitalRead(slidePin) == 1){ digitalWrite(led1, LOW);...
  • Page 78 Now pull the slide, and you can see the two LEDs light up alternately.
  • Page 79: Lesson 11 How To Drive A Dc Motor

    Lesson 11 How to Drive a DC Motor Introduction In this lesson, we will learn to how to use L293D to drive a DC motor and make it rotate Since the DC Motor needs a larger current, for safety clockwise and counterclockwise. purpose, here we use the Power Supply Module to supply motors.
  • Page 80 the right bottom. When pin EN is High level, if A is High, Y outputs high level; if A is Low, Y outputs Low level. When pin EN is Low level, the L293D does not work. In this experiment, it just needs to drive one motor, so here only half of the L293D will be used. DC Motor This is a 5V DC motor.
  • Page 81 Schematic diagram: Principle: Plug the power supply module in breadboard, and insert the jumper cap to pin of 5V, then it will output voltage of 5V. Connect pin 1 of L293D to B27, and set it as high level. Connect pin2 to B18, and pin7 to B27, then set one pin high, while the other low. Thus you can change the motor’s rotation direction.
  • Page 82 Note: The power module can apply a 9V battery with the 9V Battery Buckle in the kit. Insert the jumper cap of the power module into the 5V bus strips of the breadboard. For C language users: Step 2: Get into the folder of the code /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile make...
  • Page 83 GPIO.setup(MotorPin2, GPIO.OUT) GPIO.setup(MotorEnable, GPIO.OUT) # Set pins for motor’s working condition as output pin GPIO.output(MotorEnable, GPIO.LOW) # Set the motor low level for initial state GPIO.output(MotorEnable, GPIO.HIGH) # Set the motor in high level GPIO.output(MotorPin1, GPIO.HIGH) # Set pin1 in high level and pin2 in low level GPIO.output(MotorPin2, GPIO.LOW) # Make the motor rotate clockwise time.sleep(5)
  • Page 84: Lesson 12 Rotary Encoder

    Lesson 12 Rotary Encoder Introduction A rotary encoder is an electro-mechanical device that converts the angular position or motion of a shaft or axle to analog or digital code. Rotary encoders are usually placed at the side which is perpendicular to the shaft. They act as sensors for detecting angle, speed, length, position, and acceleration in automation field.
  • Page 85 pin 5 generate two-phase square waves whose phase difference is 90° . Usually the two- phase square waves are called channel A and channel B as shown below: We can see from the figure above: If channel A is in low level, and channel B converts from high level to low, it indicates the Rotary Encoder has spun clockwise (CW).
  • Page 86 Experimental Procedures Step 1: Build the circuit For C language users: Step 2: Get into the folder of the code. /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile make 12_rotaryEncoder Step 4: Run the executable file above sudo ./12_rotaryEncoder Code Explanation #define RoAPin // CLK connects to B17, define B17 as 0 in wiring Pi. #define RoBPin // DT connects to GPIO1, define B18 as 1 in wiring Pi.
  • Page 87 if((Last_RoB_Status == 0)&&(Current_RoB_Status == 1)){ // If DT value converts from low to high, the globalCounter adds 1. if((Last_RoB_Status == 1)&&(Current_RoB_Status == 0)){ //If DT value converts from high to low, globalCounter --; // the globalCounter decreases 1. printf("globalCounter : %d\n",globalCounter); // Print the value of globaCounter.
  • Page 88 if (Last_RoB_Status == 0) and (Current_RoB_Status == 1): counter = counter + 1 if (Last_RoB_Status == 1) and (Current_RoB_Status == 0): counter = counter - 1 print 'counter = %d' % counter # Define a callback function on switch, to clean "counter" def clear(ev=None): global counter counter = 0...
  • Page 89: Lesson 13 Driving Leds By 74Hc595

    Lesson 13 Driving LEDs by 74HC595 Introduction In this lesson, we will learn how to use 74HC595 to make eight LEDs blink regularly. Components - 1 * Raspberry Pi - 1 * Breadboard - 1 * 74HC595 - 8 * LED - 8 * Resistor (220Ω) - Jumper wires - 1 * T-Extension Board...
  • Page 90 Q7’: Series output pin, connected to DS of another 74HC595 to connect multiple 74HC595s in series MR: Reset pin, active at low level; here it is directly connected to 5V to keep the chip from resetting. SH_CP: Time sequence input of shift register. On the rising edge, the data in shift register moves successively one bit, i.e.
  • Page 91 Experimental Procedures Step 1: Build the circuit. If you want to take out the chip from the breadboard, DO NOT pull it in one direction forcefully, for fear that the pins on it may be bent and you may get hurt. Try to use a sharp tool to cross the notch of the breadboard to remove the chip.
  • Page 92 AND operation. (0x80 >> i) is to implement the operation from left to right by bit, so each time one of the eight bits in byte (0000 0001). pulse(SRCLK); // the shift register generates a rising edge pulse, and data in DS will shift to the shift register.
  • Page 93 GPIO.output(SDI, 0x80 & (dat << bit)) # Assig·n dat data to SDI pins of HC595 by bits GPIO.output(SRCLK, GPIO.HIGH) # Every SRCLK adds one, the shift register moves one bit. time.sleep(0.001) GPIO.output(SRCLK, GPIO.LOW) GPIO.output(RCLK, GPIO.HIGH) # Everytime RCLK adds one, the HC595 updates output. time.sleep(0.001) GPIO.output(RCLK, GPIO.LOW) leds = ['-', '-', '-', '-', '-', '-', '-', '-']...
  • Page 94: Lesson 14 Driving 7-Segment Display By 74Hc595

    Lesson 14 Driving 7-Segment Display by 74HC595 Introduction Since we've got some knowledge of the 74HC595 in the previous lesson, now let's try to use it and drive a 7-segment display to show a figure from 0 to 9 and A to F. Components - 1 * Raspberry Pi - 1 * Breadboard...
  • Page 95 (CC) and Common Anode (CA). As the name suggests, a CC display has all the cathodes of the 7 LEDs connected when a CA display has all the anodes of the 7 segments connected. Common Cathode 7-Segment Display In a common cathode display, the cathodes of all the LED segments are connected to the logic "0"...
  • Page 96 The schematic diagram is shown as below: Principle: Connect pin ST_CP of 74HC595 to Raspberry Pi B18, SH_CP to B27, DS to B17, parallel output ports to 8 segments of the LED segment display. Input data in DS pin to shift register when SH_CP (the clock input of the shift register) is at the rising edge, and to the memory register when ST_CP (the clock input of the memory) is at the rising edge.
  • Page 97 For C language users: Step 2: Get into the folder of the code. /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile make 14_segment Step 4: Run the executable file above. sudo ./14_segment Code Explanation unsigned char SegCode[17] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80}; // display array from 0 to F. void init(void){} // Initialize the function, set ds, st_cp, sh_cp three pins to low level, and the initial state as 0.
  • Page 98 segCode = [0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71] # Commen anode # segCode = [0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e] # Shift the data to 74HC595 def hc595_shift(dat): for bit in range(0, 8): GPIO.output(SDI, 0x80 & (dat << bit)) GPIO.output(SRCLK, GPIO.HIGH) time.sleep(0.001) GPIO.output(SRCLK, GPIO.LOW) GPIO.output(RCLK, GPIO.HIGH) time.sleep(0.001) GPIO.output(RCLK, GPIO.LOW) for code in segCode: # Input item in segCode list to hc595_shift()function, to display the character.
  • Page 99 You can slightly modify the hardware and software based on this experiment to make a dice. For hardware, add a button to the original board. Build the circuit: Get into the folder of the code. /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Next, Compile the Code make 14_dice sudo...
  • Page 100 together to generate the random number. Thus a random number of 0-6 will be displayed on the 7-segment display. For Python users: Step 2: Get into the folder of the code. /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/Python Step 3: Run sudo python 14_dice.py Code Explanation import random # use this function to generate the random number SegCode = [0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d]...
  • Page 101: Lesson 15 Driving Dot-Matrix By 74Hc595

    Lesson 15 Driving Dot-Matrix by 74HC595 Introduction As the name suggests, an LED dot matrix is a matrix composed of LEDs. The lighting up and dimming of the LEDs formulate different characters and patterns. Components - 1 * Raspberry Pi - 1 * Breadboard - 2 * 74HC595 - 1 * Dot-Matrix...
  • Page 102 Below the figures show their internal structure. You can see in a CA matrix, ROW represents the anode of the LED, and COL is cathode; it's contrary for a CC one. One thing in common: for both types, pin 13, 3, 4, 10, 6, 11, 15, and 16 are all COL, when pin 9, 14, 8, 12, 1, 7, 2, and 5 are all ROW.
  • Page 103 Experimental Procedures Step 1: Build the circuit. Since the wiring is complicated, let's make it step by step. First, inset the T-Cobbler and two 74HC595 chips into breadboard. Connect the 5V and GND of the T- Cobbler to holes on the two sides of the board, then hook up pin16 and 10 of the two 74HC595 chips to VCC and pin 13 respectively, and pin 8 to GND.
  • Page 104 Step 3: Insert the dot matrix onto the breadboard. The 74HC595 on the right side is to control columns of the matrix. See the table below for the mapping. Therefore, Q0-Q7 pins of the 74HC595 are mapped with pin 13, 3, 4, 10, 6, 11, 15, and 16 respectively. Pin No.
  • Page 105 Note: PLEASE connect devices correctly. DO NOT wire up insufficiently. DO NOT connect to the wrong side of the dot matrix. In the Fritzing image above, the side with label is at the bottom. For C language users: Step 2: Get into the folder of code /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile make...
  • Page 106 void hc595_out(){ // Update the output data of the 74HC596 digitalWrite(RCLK, 1); // Everytime RCLK adds 1, the HC595 updates the output. delay(1); digitalWrite(RCLK, 0); while(1){ for(i=0;i<sizeof(code_H);i++){ // The data of ROW and COL table for the matrix adds 1 each time. hc595_in(code_L[i]);...
  • Page 107 # ROW ++++ code_H = [0x01,0xff,0x80,0xff,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0xff,0xff,0xff,0xff,0xff,0x ff,0xff,0xff] # COL ---- code_L = [0x00,0x7f,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xfd,0xfb,0xf7,0xef,0x df,0xbf,0x7f] def get_matrix(row_buffer, col_buffer, max_row=8, max_col=8): # The functions is to print the pattern on the matrix by the 2D array on the command line interface (CLI). matrix_msg = [[0 for i in range(max_row)] for i in range(max_col)] # Initialize a 2D array...
  • Page 108 Through this lesson, you have got the basic principle of LED dot matrix and how to program the Raspberry Pi to drive an LED dot matrix based on 74HC595 cascade. With the knowledge learnt, try more fascinating creations! Further Exploration If you want to display characters on the matrix, please refer to a python code: https://github.com/sunfounder/SunFounder_Dot_Matrix.
  • Page 109: Lesson 16 Lcd1602

    LCD1602 can be categorized into eight-port and four-port connections. If the eight-port connection is used, then all the digital ports of the SunFounder Uno board are almost completely occupied. If you want to connect more sensors, there will be no ports available.
  • Page 110 Pin 6 (E): An enable pin that, when low-level energy is supplied, causes the LCD module to execute relevant instructions Pin 7 (D0-D7): pins that read and write data A and K: controlling LCD backlight; K connects to GND, and A to 3.3V. Turn the backlight on and you can see the characters displayed clear in a dim environment LCD1602 has two operation modes: 4-bit and 8-bit.
  • Page 111 #include <lcd.h> // includes the lcd library, containing some functions for the LCD1602 display for convenient use const unsigned char Buf[] = "---SUNFOUNDER---"; // An array to store the characters to be displayed on the LCD1602 const unsigned char myBuf[] = "...
  • Page 112 // Display the character "Welcom To--->"on the LCD1602 lcdPosition(fd, 0, 1); // Place the cursor at Col 0, Row 0. lcdPuts(fd, " sunfounder.com"); while(1){ lcdClear(fd); for(i=0; i<16; i++){ // i adds one in the loop. i means the number of columns, so i adds to 16 at most.
  • Page 113 # Locate the cursor at character No. i, Row 1 lcd.message(line1[i]) # Display the character on the LCD You should see two lines of characters displayed on the LCD1602: " Welcome to ---> " ," SUNFOUNDER sunfounder.com " and "--- --- ".
  • Page 114 Further Exploration In this experiment, the LCD1602 is driven in the 4-bit mode. You can try programming by yourself to drive it in the 8-bit mode.
  • Page 115: Lesson 17 Adxl345

    Lesson 17 ADXL345 Introduction In this lesson, we will learn how to use the acceleration sensor ADXL345. Components - 1 * Raspberry Pi - 1 * Breadboard - 1 * ADXL345 module - 1 * T-Extension Board - 1 * 40-Pin GPIO Cable - Jumper wires Principle ADXL345...
  • Page 116 increases along the axis direction, so does Y_OUT along the Ay axis. See the picture below. Thus, when you rotate the module, you can see the changes of X_OUT, Y_OUT, and Z_OUT. Relationship between output and gravity direction Pin Function of ADXL345 Module: Name Description Supply Voltage...
  • Page 117 Experimental Procedures Step 1: Build the circuit The I2C interface is used in the following program. Before running the program, please make sure the I2C driver module of Raspberry Pi has loaded normally. For C language users: Step 2: Get into the folder of code /home/pi/SunFounder_Super_Kit_V3.0_for_Raspberry_Pi/C Step 3: Compile the Code make...
  • Page 118 sudo ./17_adxl345 Code Explanation #include <wiringPiI2C.h> // Include functions and method for the IIC protocol #define DevAddr 0x53 // device address struct acc_dat{ // a struct variable to store the value of x,y,and z int x; int y; int z; fd = wiringPiI2CSetup(DevAddr);...
  • Page 119 if(acc_xyz.y > 32767){ // Set the value of y as no more than 0x7FFF acc_xyz.y -= 65536; if(acc_xyz.z > 32767){ acc_xyz.z -= 65536; return acc_xyz; // The function ends, return to the acc_xyz struct acc_xyz = adxl345_read_xyz(fd); // Call the function to read the data collected by the accelerometer module printf("x: %05d y: %05d...
  • Page 120 All contents including but not limited to texts, images, and code in this manual are owned by the SunFounder Company. You should only use it for personal study, investigation, enjoyment, or other non-commercial or nonprofit purposes, under the related regulations and copyrights laws, without infringing the legal rights of the author and relevant right holders.

Table of Contents