Freenove 4WD Smart Car Board for Raspberry Pi Manual

Hide thumbs Also See for 4WD Smart Car Board for Raspberry Pi:

Advertisement

Welcome
Thank you for choosing Freenove products!
About Battery
First, read the document
If you did not download the zip file, please download it and unzip it via link below.
https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/archive/master.zip
Get Support and Offer Input
Freenove provides free and responsive product and technical support, including but not limited to:
Product quality issues
Product use and build issues
Questions regarding the technology employed in our products for learning and education
Your input and opinions are always welcome
We also encourage your ideas and suggestions for new products and product improvements
For any of the above, you may send us an email to:
support@freenove.com
Safety and Precautions
Please follow the following safety precautions when using or storing this product:
Keep this product out of the reach of children under 6 years old.
This product should be used only when there is adult supervision present as young children lack necessary
judgment regarding safety and the consequences of product misuse.
This product contains small parts and parts, which are sharp. This product contains electrically conductive
parts. Use caution with electrically conductive parts near or around power supplies, batteries and
powered (live) circuits.
When the product is turned ON, activated or tested, some parts will move or rotate. To avoid injuries to
hands and fingers, keep them away from any moving parts!
It is possible that an improperly connected or shorted circuit may cause overheating. Should this happen,
immediately disconnect the power supply or remove the batteries and do not touch anything until it
cools down! When everything is safe and cool, review the product tutorial to identify the cause.
Only operate the product in accordance with the instructions and guidelines of this tutorial, otherwise
parts may be damaged or you could be injured.
Store the product in a cool dry place and avoid exposing the product to direct sunlight.
After use, always turn the power OFF and remove or unplug the batteries before storing.
About_Battery.pdf
in the unzipped folder.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the 4WD Smart Car Board for Raspberry Pi and is the answer not in the manual?

Questions and answers

Summary of Contents for Freenove 4WD Smart Car Board for Raspberry Pi

  • Page 1 If you did not download the zip file, please download it and unzip it via link below. https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/archive/master.zip Get Support and Offer Input Freenove provides free and responsive product and technical support, including but not limited to:  Product quality issues ...
  • Page 2 This means you can use these resource in your own derived works, in part or completely, but NOT for the intent or purpose of commercial use. Freenove brand and logo are copyright of Freenove Creative Technology Co., Ltd. and cannot be used without written permission.
  • Page 3: Table Of Contents

    Contents Welcome ....................................1 Contents....................................1 List ......................................1 4WD Smart Car Board for Raspberry Pi ........................1 Machinery Parts ................................2 Transmission Parts ............................... 3 Acrylic Parts .................................. 3 Electronic Parts ................................4 Tools ....................................4 Self-prepared Parts ..............................5 Preface ....................................
  • Page 5: Welcome

    List █ www.freenove.com List If you have any concerns, please feel free to contact us via support@freenove.com 4WD Smart Car Board for Raspberry Pi Need support?  support.freenove.com...
  • Page 6: Machinery Parts

    List www.freenove.com █ Machinery Parts Note: You may receive M1.4*4 or M1.4*5. Can be used normally Need support?  support.freenove.com...
  • Page 7: Transmission Parts

    List █ www.freenove.com Transmission Parts Servo package x2 Driven wheel x4 DC speed reduction motor x4 Motor bracket package x4 Acrylic Parts For Pan Tilt Need support?  support.freenove.com...
  • Page 8: Electronic Parts

    List www.freenove.com █ Electronic Parts Line tracking module x1 Camera x1 HC-SR04 Ultrasonic Module x1 Connection board Jumper Wire F/F(4) x1 XH-2.54-5Pin cable x1 Tools Cross screwdriver (3mm) x1 Black tape x1 Cable Tidy x25cm Need support?  support.freenove.com...
  • Page 9: Self-Prepared Parts

    List █ www.freenove.com Self-prepared Parts Please refer to About_Battery.pdf in unzipped folder. Raspberry Pi (Recommended model: Raspberry 4B / 3B+ / 3B) x1 Need support?  support.freenove.com...
  • Page 10: Preface

    █ Preface Welcome to use Freenove 4WD Smart Car Kit for Raspberry Pi. Following this tutorial, you can make a very cool smart car with many functions. This kit is based on Pi Raspberry, a popular control panel, so you can share and exchange your experience and design ideas with many enthusiasts all over the world.
  • Page 11: Raspberry Pi Introduction

    Below are the Raspberry Pi pictures and model pictures supported by this product. Practicality picture of Raspberry Pi 4 Model B: Model diagram of Raspberry Pi 4 Model B: Need support?  support.freenove.com...
  • Page 12 Preface www.freenove.com █ Practicality picture of Raspberry Pi 3 Model B+: Model diagram of Raspberry Pi 3 Model B+: Practicality picture of Raspberry Pi 3 Model B: Model diagram of Raspberry Pi 3 Model B: Need support?  support.freenove.com...
  • Page 13 Preface █ www.freenove.com Practicality picture of Raspberry Pi 2 Model B: Model diagram of Raspberry Pi 2 Model B: Practicality picture of Raspberry Pi 1 Model B+: Model diagram of Raspberry Pi 1 Model B+: Need support?  support.freenove.com...
  • Page 14 Preface www.freenove.com █ Practicality picture of Raspberry Pi 3 Model A+: Model diagram of Raspberry Pi 3 Model A+: Practicality picture of Raspberry Pi 1 Model A+: Model diagram of Raspberry Pi 1 Model A+: Need support?  support.freenove.com...
  • Page 15 Preface █ www.freenove.com Practicality picture of Raspberry Pi Zero W: Model diagram of Raspberry Pi Zero W: Practicality picture of Raspberry Pi Zero: Model diagram of Raspberry Pi Zero: Need support?  support.freenove.com...
  • Page 16 Connector x4 Power Connector MINI HDMI Camera Audio Connector x2 Connector Connector Hardware interface diagram of RPi 3B+/3B/2B/1B+ are shown below: GPIO Connector Connector Display Connector Ethernet Power Connector Connector HDMI Camera Audio Connector Connector Connector Need support?  support.freenove.com...
  • Page 17 Hardware interface diagram of RPi 3A+/A+ is shown below: GPIO Connector Connector Display Connector Power Connector HDMI Audio Camera Connector Connector Connector Hardware interface diagram of RPi Zero/Zero W is shown below: GPIO Connector Camera Connector Power HDMI Connector Connector Connector Need support?  support.freenove.com...
  • Page 18 You will need a printed reference or a reference board that fits over the pins. Each pin is defined as below: For more details about pin definition of GPIO, please refer to http://pinout.xyz/ Need support?  support.freenove.com...
  • Page 19 WiringPi was renumbered. Here we have three kinds of GPIO number mode: based on the number of BCM chip, based on the physical sequence number and based on wiringPi. The correspondence between these three GPIO numbers is shown below: (For more details, please refer to https://projects.drogon.net/raspberry-pi/wiringpi/pins/ Need support?  support.freenove.com...
  • Page 20 Preface www.freenove.com █ You can also use the following command to view their correspondence. gpio readall For more details about wiringPi, please refer to http://wiringpi.com/ Need support?  support.freenove.com...
  • Page 21: Chapter 0 Raspberry Pi Preparation

    Camera cable(>25cm) for zero w, 15 Pin 1.0mm Pitch to 22 Pin 0.5mm, OTG cable (USB Type micro B to USB Type A) Raspberry Pi 2 Model B wireless network adapter Raspberry Pi 1 Model A+ wireless network adapter Raspberry Pi 1 Model B+ wireless network adapter Need support?  support.freenove.com...
  • Page 22 5V/2.5A is highly recommend. SD Card Micro (recommended capacity 16GB or more) is a hard drive for RPi, which is used to store the system and personal files. In later projects, the components list with a RPi will contains these required components, using only RPi as a representative rather than presenting details. Need support?  support.freenove.com...
  • Page 23 Raspberry Pi through SSH, then open the VNC or RDP service. So you need the following accessories. Item Pi Zero Pi Zero W Pi A+ Pi 3A+ Pi B+/2B Pi 3B/3B+/4B Micro-USB to USB-A OTG cable USB transferring to Ethernet interface Need support?  support.freenove.com...
  • Page 24 “Raspberry Pi OS”. Raspberry Pi OS supported by RPI is an operating system based on Linux, which contains a number of contents required for RPi. We recommended Raspberry Pi OS to beginners. All projects in this tutorial are operated under the Raspberry Pi OS. https://www.raspberrypi.org/downloads Need support?  support.freenove.com...
  • Page 25 First, put your Micro SD card into card reader and connect it to USB port of PC. Then open "Raspberry Pi Imager", select "Choose OS", select "Use custom" from the bottom of the list, and select the image file that you just downloaded. Need support?  support.freenove.com...
  • Page 26 Chapter 0 Raspberry Pi Preparation www.freenove.com █ Choose the SD card. Then click “WRITE”. Need support?  support.freenove.com...
  • Page 27 After login, you can enter the following interface. Now, you have successfully installed the Raspberry Pi OS for your RPi. Then you can connect WiFi on the right corner. Now you can skip to VNC Viewer. Need support?  support.freenove.com...
  • Page 28: Remote Desktop & Vnc

    Micro SD Card. Configure WiFi wpa_supplicant.conf in boot. Create a file named Open it with notepad. Add WiFi information. Input following content and save. ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=CN network={ ssid="your WiFi name" psk="WiFi password" key_mgmt=WPA-PSK Need support?  support.freenove.com...
  • Page 29 Chapter 0 Raspberry Pi Preparation █ www.freenove.com Insert SD card Then remove SD card from card reader and insert it into Raspberry Pi. Need support?  support.freenove.com...
  • Page 30 RPi IP address, and it is “192.168.1.108". Then open Putty, enter the address, select SSH, and then click "OPEN", as shown below: Step2: Step1: enter Select SSH the IP address Step3: Click “OPEN” There will appear a security warning at first login. Just click “YES”. Need support?  support.freenove.com...
  • Page 31 Chapter 0 Raspberry Pi Preparation █ www.freenove.com Need support?  support.freenove.com...
  • Page 32 This is normal. After the correct input, press “Enter” to confirm. Then enter the command line of RPi, which means that you have successfully login to RPi command line mode. Need support?  support.freenove.com...
  • Page 33 If you want to use built-in Remote Desktop Connection under Windows, you need install xrdp service on Raspberry Pi. Next, install a xrdp service, an open source remote desktop protocol(xrdp) server, for RPi. Type the following command, then press enter to confirm: sudo apt-get install xrdp Later, the installation starts. Need support?  support.freenove.com...
  • Page 34 Chapter 0 Raspberry Pi Preparation www.freenove.com █ Enter "Y", press key “Enter” to confirm. After the installation is completed, you can use Windows remote desktop applications to login to your RPi. Need support?  support.freenove.com...
  • Page 35 Use "WIN+R" or search function, open the remote desktop application "mstsc.exe" under Windows, enter the IP address of RPi and then click “Connect”. Later, there will be xrdp login screen. Enter the user name and password of RPi (RPi default user name: pi; password: raspberry) and click “OK”. Need support?  support.freenove.com...
  • Page 36 Raspberry Pi 4B/3B+/3B integrates a Wi-Fi adaptor. You can use it to connect to your Wi-Fi. Then you can use the wireless remote desktop to control your RPi. This will be helpful for the following work. Raspberry Pi of other models can use wireless remote desktop through accessing an external USB wireless card. Need support?  support.freenove.com...
  • Page 37 You can also use the IP to log in Pi. Enter router client to inquiry IP address named “Raspberry Pi”. For example, I have inquired to my RPi IP address, and it is “192.168.1.131". Open the terminal and type following command. ssh pi@192.168.1.131 Need support?  support.freenove.com...
  • Page 38 Chapter 0 Raspberry Pi Preparation www.freenove.com █ Need support?  support.freenove.com...
  • Page 39 Chapter 0 Raspberry Pi Preparation █ www.freenove.com VNC Viewer & VNC Type the following command. And select 5 Interfacing OptionsP3 VNC YesOKFinish. Here Raspberry Pi may need be restarted, and choose ok. Then open VNC interface. sudo raspi-config Need support?  support.freenove.com...
  • Page 40 Enter ip address of your Raspberry Pi and fill in a Name. And click OK. Then on the VNC Viewer panel, double-click new connection you just created, and the following dialog box pops up. Enter username: pi and Password: raspberry. And click OK. Need support?  support.freenove.com...
  • Page 41 Raspberry Pi. In addition, your VNC Viewer window may zoom your Raspberry Pi desktop. You can change it. On your VNC View control panel, click right key. And select Properties->Options label->Scaling. Then set proper scaling. Need support?  support.freenove.com...
  • Page 42 Here, you have logged in to Raspberry Pi successfully by using VNC Viewer and operated proper setting. Raspberry Pi 4B/3B+/3B integrates a Wi-Fi adaptor.If you did not connect Pi to WiFi. You can connect it to wirelessly control the robot. Need support?  support.freenove.com...
  • Page 43: Chapter 1 Software Installation And Test (Necessary)

    Open the terminal and type the following commands to obtain the car code. And the code will be placed in the directory "Pi". (Note: Here are two commands. Please execute them in order.) git clone https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi Need support?  support.freenove.com...
  • Page 44 █ Downloading takes some time. Please wait with patience. You can also find and download the code by visiting our official website (http://www.freenove.com) or our GitHub repository (https://github.com/freenove). Please note that this tutorial is based on python3. If you want to use python2, please download another version of the tutorial.
  • Page 45 “cd D”, press Tab key, then there is no response. Press Tab key again, then all the files/folders that begin with “D” is listed. Continue to type the character "oc", then press the Tab key, and then “Documents” is completely typed automatically. Need support?  support.freenove.com...
  • Page 46: Step 2 Configuration

    █ Step 2 Configuration Enable I2C and VNC The I2C interface Raspberry Pi is disabled by default. You need to open it manually. For OS earlier than 2021-10-30 For OS 2021-10-30 and later Finally Click OK Need support?  support.freenove.com...
  • Page 47 The smart car board has two chips, PCF8591 and PCA9685. Their I2C addresses are 0X48 and 0X40 respectively. Command “i2cdetect –y 1” can detect whether the board is successfully connected to Raspberry Pi. i2cdetect -y 1 If an I2C device is connected to your RPI, its I2C address will be displayed here. Need support?  support.freenove.com...
  • Page 48  # camera_auto_detect=1 1 Add before  dtoverlay=vc4-fkms-v3d 2 Add dtoverlay=vc4-kms-v3d 3 Add following in the end. start_x=1 gpu_mem=128 4 Add following in the end. hdmi_force_hotplug=1 hdmi_ignore_edid=0xa5000080 hdmi_group=2 hdmi_mode=82 Finally press Ctrl+O, Enter, then Ctrl+X. Need support?  support.freenove.com...
  • Page 49 Chapter 1 Software installation and Test (necessary) █ www.freenove.com Before After Need support?  support.freenove.com...
  • Page 50 # Enable audio (loads snd_bcm2835) # dtparam=audio=on It will take effect after restarting, and you can restart after executing the next section. If you want to restart the audio module, just restore the content modified in the above two steps. Need support?  support.freenove.com...
  • Page 51: Step 3 Run The Libraries Installation Program

    Pi after the installation is completed, as shown below. If the installation fails, please rerun setup.py. After the installation is completed, restart the Raspberry Pi. Most installation failures are caused by network reasons. sudo python setup.py Need support?  support.freenove.com...
  • Page 52: Chapter 2 Assemble Smart Car

    Place the Rocker arm on the smart car board in accordance with its silkscreen printing. Use two M2.5*8 screws to install it to smart car board. There are two servo packages. Each package contains one servo, three rocker arms, one M2*4 screw and two M2.5*8 screws, as shown below: Screw M2.5*8 Rocker arm Need support?  support.freenove.com...
  • Page 53 M3*8 Install motor bracket with M3*8. You can also attach this bracket to motor first. Step 2 Keep the side with wire toward inside. M3*30 Screw Install motor to bracket with M3*30 screw and M3 Nut. Need support?  support.freenove.com...
  • Page 54 The installation of the rest 3 sets of motor is the same. Then connect motor wires to motor ports. If you think the wires are too long, you can tie a knot. Step 4 Install 4 wheels to motor. The mounting hole is not a round hole. Need support?  support.freenove.com...
  • Page 55 Chapter 2 Assemble Smart Car █ www.freenove.com Now, all motors and wheels are installed successfully. Need support?  support.freenove.com...
  • Page 56 First install two M3*30 standoffs on smart car board with M3*6 screws. Then install line tracking module on standoffs with M3*6 screws. Step 2 Cable XH-2.54-5Pin Connect line tracking module to smart car board with XH-2.54-5Pin cable. Need support?  support.freenove.com...
  • Page 57 M2.5*8+6 Standoff X4 First install four M2.5*8+6 standoffs to the nuts on smart car board. And then place the Rapberry Pi on the standoff in accordance with its silkscreen printing, and use four M2.5*4 screws to install it. Need support?  support.freenove.com...
  • Page 58 Raspberry Pi. Step 2 Press it until you can see the pins. × √ If you have any concerns, please feel free to contact us via support@freenove.com We will offer you satisfied solution. Need support?  support.freenove.com...
  • Page 59 If the terminal displays the directory as below (where test.py is located). You can directly execute the servo.py command. 1.If not, execute the cd command: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2.Execute Servo.py command: sudo python servo.py Then servos rotate to a proper angle. Please keep the connection between the servos and the smart car board. Need support?  support.freenove.com...
  • Page 60 Step 7 Step 8: Step 9 M2.5*8 M3*14 M3*14 M3*14 Now please refer to Wiring Section to wring ultrasonic sensor and camera frist. Step 10 Step 11 After finished Keep them vertical M2*4 screw in servo package Need support?  support.freenove.com...
  • Page 61 Keep the pan tilt as shown in the right picture and install servo0 with rocker arm. Step 2 Use a Cross screwdrive to support M2 * 10 screws and M2 nuts to fix the servo 0. Screw M2*10 and Nut M2 Screw M2*10 Nut M2 Screw Need support?  support.freenove.com...
  • Page 62 Chapter 2 Assemble Smart Car www.freenove.com █ Step 3 Servo 1 Servo 0 Pay attention to servo wiring. (Note: wiring about the ultrasonic and camera module will be introduced later. ) Need support?  support.freenove.com...
  • Page 63 You need turn down Raspberry Pi when wire camera. Step 1 Step 2 × √ Blue side of cable should be toward to Servo. Connect one end of cable to camera. Please note the front and back of the cable. Need support?  support.freenove.com...
  • Page 64 █ Step 3 Step 4 √ × Blue side of cable should be toward to RPi USB port. Connect another end of cable to Raspberry Pi. Please note the front and back of the cable. Need support?  support.freenove.com...
  • Page 65 Chapter 2 Assemble Smart Car █ www.freenove.com Ultrasonic Use jumper wires F/F to connect ultrasonic module with pins on smart car board. GND-GND, VCC-5V, ECHO-ECHO, TRIG-TRIG Need support?  support.freenove.com...
  • Page 66: Chapter 3 Module Test (Necessary)

    Next, test RGB LED, motor, ultrasonic module, servo, etc. You can still power Raspberry Pi with a power supply Cable when switches are pressed. If you have never learned python before, you can learn some basic knowledge via the link below: https://python.swaroopch.com/basics.html Need support?  support.freenove.com...
  • Page 67 If the direction is reversed, it moves back then move forward, please follow steps below. 1. Find Motor.py in the following path in your Raspberry Pi: Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server/Motor.py Open Motor.py and add a “–“ before duty1,2,3,4 like below. setMotorModel(self,duty1,duty2,duty3,duty4): duty1,duty2,duty3,duty4=self.duty_range(duty1,duty2,duty3,duty4) self.left_Upper_Wheel(-duty1) self.left_Lower_Wheel(-duty2) self.right_Upper_Wheel(-duty3) self.right_Lower_Wheel(-duty4) Then save the modification and try again. Need support?  support.freenove.com...
  • Page 68 If it is within -4096~0, the motor will rotate reversely. The larger the absolute value is, the faster the motor is. When the input is 0, the motor will stop. If the function is input as follows: setMotorModel(2000,2000, 2000, 2000), four motors will rotate forward and the car will move forward. Data1 Data2 Data4 Data3 Need support?  support.freenove.com...
  • Page 69 Every 1s, the voltage values of the two photoresistors and the battery are output. The value read for the first time is not stable and inaccurate when the chip just starts. It will be stable later. You can press "Ctrl + C" to end program. Need support?  support.freenove.com...
  • Page 70 When the input is 1, the value of this function is the voltage value of the right photoresistor. When the input is 2, the value of this function is the voltage value of each battery. After multiplying by 3, it is the actual battery voltage value Need support?  support.freenove.com...
  • Page 71 When the black line is on the right side of the module, right The LED will light up, the terminal will print “Right”, You can press “Ctrl + C” to end the program. If there are issues with the test, the infrared device may need to be adjusted. The adjustment screw is on top of the sensor. Need support?  support.freenove.com...
  • Page 72 'Left' except KeyboardInterrupt: print "\nEnd of program" Reference GPIO.input(IO) This function has an input parameter. If the IO input is high level, GPIO.input(IO) returns True. If the IO input is low level, GPIO.input(IO) returns False. Need support?  support.freenove.com...
  • Page 73 Enter the following commands to test LEDs. If the terminal displays the directory as below (where test.py is located), you can directly execute the test.py command. 1.If not, execute the cd command: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2.Execute test.py command: sudo python test.py Led Need support?  support.freenove.com...
  • Page 74 "The LED has been lit, the color is red orange yellow green cyan-blue blue white" time.sleep(3) #wait 3s led.colorWipe(led.strip, Color(0,0,0)) #turn off the light print "\nEnd of program" except KeyboardInterrupt: led.colorWipe(led.strip, Color(0,0,0)) #turn off the light print "\nEnd of program" except: pass Need support?  support.freenove.com...
  • Page 75 Neopixel object, color represents the color to be erased, and wait_ms represents the erasure interval. The default is 50ms. For example, colorWipe(strip, Color(255,0,0),20) means that the LED0 is red first, wait for 20ms, and then the LED1 is also red, until all eight LEDs are lit and red. Need support?  support.freenove.com...
  • Page 76 # Define functions which animate LEDs in various ways. class Led: __init__(self): self.ORDER = "GRB" #Control the sending order of color data # Create NeoPixel object with appropriate configuration. self.strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) Need support?  support.freenove.com...
  • Page 77 -= 170 g=pos * 3 b=255 - pos * 3 return self.LED_TYPR(self.ORDER,Color(r,g,b)) rainbow(self,strip, wait_ms=20, iterations=1): """Draw rainbow that fades across all pixels at once.""" j in range(256*iterations): i in range(self.strip.numPixels()): self.strip.setPixelColor(i, self.wheel((i+j) & 255)) self.strip.show() time.sleep(wait_ms/1000.0) Need support?  support.freenove.com...
  • Page 78 LED and it has two input parameters. The first one is the LED number, the second one is used to set the color of the LED. For example, strip.setPixelColor(1,Color(255, 0, 0)), and write strip.show() in the next line, then LED1 will light red. Need support?  support.freenove.com...
  • Page 79 First, make the eight LEDs display one color at the same time and then change the color with intervals of 20ms. And then make the eight LEDs display different colors at the same time, and then change the color to produce another rainbow effect. Need support?  support.freenove.com...
  • Page 80 The buzzer will be turned on and last for 3s. Then the program will automatically end or you can press "Ctrl + C" to end the program. The code is as below: from Buzzer import buzzer=Buzzer() test_Buzzer(): try: buzzer.run(cmd.CMD_START) time.sleep(1) print "1S" time.sleep(1) print "2S" time.sleep(1) print "3S" buzzer.run(cmd.CMD_STOP) Need support?  support.freenove.com...
  • Page 81 KeyboardInterrupt: buzzer.run(cmd.CMD_STOP) print "\nEnd of program" Reference buzzer.run(cmd) This function has one input parameter. If the input is ’1’, the buzzer will be turned on. If the input is ‘0’, the buzzer will be turned off. Need support?  support.freenove.com...
  • Page 82 You can press “Ctrl + C” to end the program. The code is as below: from servo import pwm=Servo() test_Servo(): try: while True: i in range(50,110,1): pwm.setServoPwm('0',i) time.sleep(0.01) i in range(110,50,-1): pwm.setServoPwm('0',i) time.sleep(0.01) i in range(80,150,1): pwm.setServoPwm('1',i) time.sleep(0.01) i in range(150,80,-1): pwm.setServoPwm('1',i) time.sleep(0.01) except KeyboardInterrupt: Need support?  support.freenove.com...
  • Page 83 There are 2 parameters. The first one is related to servo index. The second one is related to the angle of servos. For example, setServoPwm(‘0’,20) makes servo0 rotate to 20°. setServoPwm(‘1’,90) makes servo1 rotate to 90°. Need support?  support.freenove.com...
  • Page 84 If the terminal displays the directory as below (where test.py is located). You can directly execute the test.py command. 1. If not, execute the cd command: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2. Execute test.py command: sudo python test.py Ultrasonic Need support?  support.freenove.com...
  • Page 85 #Get the value print ("Obstacle distance is "+str(data)+"CM") time.sleep(1) except KeyboardInterrupt: print "\nEnd of program" Reference get_distance() This function is used to obtain the distance between ultrasonic module and obstacles in front of it, with unit Need support?  support.freenove.com...
  • Page 86 CSI camera must be connected or disconnected under no power and when Raspberry Pi is shut down, or the camera may be burned.) Step 1 × √ Blue side of cable should be toward to Servo. Connect one end of cable to camera. Please note the front and back of the cable. Need support?  support.freenove.com...
  • Page 87 Connect another end of cable to Raspberry Pi. Please note the front and back of the cable. Run program Detect camera: vcgencmd get_camera 1. execute the cd command: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2. Execute the following command: python camera.py Then please open and check the generated image.jpg under /Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server. Need support?  support.freenove.com...
  • Page 88: Chapter 4 Light Tracing Car

    If the terminal displays the directory as below, you can directly execute the Light.py command. 1. If not, execute the cd command: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2. Run Light.py: sudo python Light.py You can press "Ctrl + C" to end the program. Need support?  support.freenove.com...
  • Page 89 If the left voltage is greater than the right, the car turns left. If the right voltage is greater than the left, the car turns right. You can change the judgment of the program to achieve the result you want, according to the light intensity of the environment. Need support?  support.freenove.com...
  • Page 90: Chapter 5 Ultrasonic Obstacle Avoidance Car

    You can press "Ctrl + C" to end the program. Part of code is as below: run(self): self.PWM=Motor() self.pwm_S=Servo() i in range(30,151,60): self.pwm_S.setServoPwm('0',i) time.sleep(0.2) i==30: L = self.get_distance() elif i==90: M = self.get_distance() else: R = self.get_distance() while True: Need support?  support.freenove.com...
  • Page 91 When distances detected on the left>30cm, middle <30cm, right<30cm. It means that there is an obstacle on the right side of the car, so the car turn left. Need support?  support.freenove.com...
  • Page 92: Chapter 6 Infrared Line Tracking Car

    Line_Tracking.py You can press "Ctrl + C" to end the program. If there are issues with the test, the infrared device may need to be adjusted. The adjustment screw is on top of the sensor. Need support?  support.freenove.com...
  • Page 93 PWM.setMotorModel(4000,4000,-2000,-2000) elif self.LMR==7: pass infrared=Line_Tracking() # Main program logic follows: __name__ == '__main__': print ('Program is starting ... try: infrared.run() except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed. PWM.setMotorModel(0,0,0,0) Need support?  support.freenove.com...
  • Page 94 When the sensor on left: low, middle: high, right: low, the car moves forward straight. When the sensor on left: low, middle: low, right: high, the car turns right lightly. When the sensor on left: low, middle: high, right: high, the car turns right. Need support?  support.freenove.com...
  • Page 95: Chapter 7 Smart Video Car

    LED and so on. And it is built with a server and a client, so it can be controlled remotely. Start Start Open server Open client Wait Connect connection server If success If success Wait Send command command If get If success command Done success keep Execute sending Command Need support?  support.freenove.com...
  • Page 96: Server

    = socket.socket() self.server_socket1.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1) self.server_socket1.bind((HOST, 5000)) self.server_socket1.listen(1) self.server_socket = socket.socket() self.server_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEPORT,1) self.server_socket.bind((HOST, 8000)) self.server_socket.listen(1) print('Server address: '+HOST) StopTcpServer(self): try: self.connection.close() self.connection1.close() except Exception , e: print "No client connection" sendvideo(self): try: self.connection,self.client_address = self.server_socket.accept() self.connection=self.connection.makefile('rb') except: pass Need support?  support.freenove.com...
  • Page 97 'jpeg', use_video_port = True): try: self.connection.flush() stream.seek(0) b = stream.read() lengthBin = struct.pack('L', len(b)) self.connection.write(lengthBin) self.connection.write(b) time.time() - start > 600: break stream.seek(0) stream.truncate() except print "End transmit ... " break except: print "Camera unintall" Need support?  support.freenove.com...
  • Page 98 Enter IP address of your Raspberry Pi and fill in a Name. And click OK. Then on the VNC Viewer panel, double-click new connection you just created, and the following dialog box pops up. Enter username: and Password: raspberry. And click OK. Need support?  support.freenove.com...
  • Page 99 VNC View control panel, click right key. And select Properties->Options label->Scaling. Then set proper scaling. Step 2 Run commands If you are using remote desktop mode to login Raspberry Pi, you need use viewer. Enter the following command in the terminal. Need support?  support.freenove.com...
  • Page 100 “-t” means open TCP communication. “-n“ means don’t show interface. Sever Auto Start Open the terminal and execute the following two commands respectively to create a “start.sh” file. cd ~ sudo touch start.sh Open “start.sh”. sudo nano start.sh Need support?  support.freenove.com...
  • Page 101 Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit. Modify permissions. sudo chmod +x .config/autostart/start.desktop Finally enter the following content to reboot Raspberry Pi. sudo reboot Note: To cancel auto start, please delete the files “start.sh” and “start.desktop” created above. Need support?  support.freenove.com...
  • Page 102: Client

    = socket.socket(socket.AF_INET, socket.SOCK_STREAM) StopTcpcClient(self): try: self.client_socket.shutdown(2) self.client_socket1.shutdown(2) self.client_socket.close() self.client_socket1.close() except: pass IsValidImage4Bytes(self,buf): bValid = True buf[6:10] in (b'JFIF', b'Exif'): not buf.rstrip(b'\0\r\n').endswith(b'\xff\xd9'): bValid = False else: try: Image.open(io.BytesIO(buf)).verify() except: bValid = False return bValid face_detect(self,img): sys.platform.startswith('win'): gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) Need support?  support.freenove.com...
  • Page 103 = b' ' try: self.client_socket.connect((ip, 8000)) self.connection = self.client_socket.makefile('rb') except: #print "command port connect failed" pass while True: try: stream_bytes= self.connection.read(4) leng=struct.unpack('L', stream_bytes[:4]) jpg=self.connection.read(leng[0]) self.IsValidImage4Bytes(jpg): image = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8), cv2.IMREAD_COLOR) self.video_Flag: self.face_detect(image) self.video_Flag=False except: break Need support?  support.freenove.com...
  • Page 104 Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time. If pressing forward but the car moves backward, please refer to page 51 to modify the code. Need support?  support.freenove.com...
  • Page 105 After the installation is completed, you need to open Raspberry Pi and server again. Install python3 Download the installation file: https://www.python.org/downloads/windows/ Click Latest Python 3 Release - Python 3.8.1 Choose and download Windows x86 executable installer. After downloading successfully, install it. Need support?  support.freenove.com...
  • Page 106 Chapter 7 Smart video car www.freenove.com █ Select “Add Python 3.8 to PATH”. You can choose other installation features. Select all options and click “Next”. Need support?  support.freenove.com...
  • Page 107 Chapter 7 Smart video car █ www.freenove.com Here, my install location is D. You can also choose other location. Then click “Install”. Wait installing. Need support?  support.freenove.com...
  • Page 108 2. Enter directory where setup_windows.py is located: (If you put it into E, it should be E:) cd D:\Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi\Code 3. Run setup_windows.py: Python3 setup_windows.py Or enter the unzipped directory Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi\Code\Client. And double-click setup_client.py or open it with python3. Need support?  support.freenove.com...
  • Page 109 2. Enter directory where Main.py is located: cd D:\Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi\Code\Client 3. Run Main.py: python Main.py Or enter the unzipped directory and enter following directory: Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi\Code\Client. And double-click Main.py or open it with python to open the client. Need support?  support.freenove.com...
  • Page 110 Note: when Raspberry Pi is shut down, server will be closed. You need open server again the next time. If pressing forward but the car moves backward, please refer to page 51 to modify the code. Control And you can also control the car with following blue keys. Need support?  support.freenove.com...
  • Page 111 Power box Show power level R,G,B Edit box Control the color of LED selected. Button “Ultrasonic“ Show the distance from obstacle. Button “Light “ Show voltage of two photoresistors. Button “Tracing-On/Off “ Open and close face tracking Need support?  support.freenove.com...
  • Page 112 2. Modify IP address to IP address of your Raspberry Pi. For example, my rpi IP is 192.168.1.116. After modification, it should be as below: self.IP.setText(_translate("Client", "192.168.1.116", None)) Then save and close. And then restart your client. You can see it is modified successfully. Need support?  support.freenove.com...
  • Page 113 Download installation package, link: https://www.python.org/downloads/ If your macOS is 11. Like 11.0, please install python 3.9. If your macOS is NOT 11, like 10.15, please install python 3.8. If you have installed python 3.9. You need uninstall it first. Need support?  support.freenove.com...
  • Page 114 Chapter 7 Smart video car www.freenove.com █ At bottom of the page, click macOS 64-bit installer and download installation package. Click Continue. Need support?  support.freenove.com...
  • Page 115 Chapter 7 Smart video car █ www.freenove.com Click Continue Click Agree. Need support?  support.freenove.com...
  • Page 116 Chapter 7 Smart video car www.freenove.com █ Click Install. If your computer has a password, enter the password and Install Software. Need support?  support.freenove.com...
  • Page 117 Chapter 7 Smart video car █ www.freenove.com Now the installation succeeds. You can find it in Aapplications. Need support?  support.freenove.com...
  • Page 118 Enter “Downloads“, (Where the Car code is located. If your location for it is different, please enter the location in your device.) cd Downloads Enter directory where setup_macos.py is located: cd Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/ Run setup_macos.py: python3 setup_macos.py Need support?  support.freenove.com...
  • Page 119 Most of the installation failures are caused by poor networks. You can check your network before installing. If you are using macOS under 11.0, like 10.15. Just skip to “Open client”. If you are using macOS 11.0 or later version. Please run commands below: pip3 uninstall PyQt5 pip3 install PyQt5 Need support?  support.freenove.com...
  • Page 120 Following the previous step, after the installation is completed, you are now in the directory where setup_macos.py is located. 1.Type following command to enter Client folder. cd Client/ 2.Type following command to run Main.py. python3 Main.py The control way of Raspberry Pi macOS System client is same with Windows (Control). Need support?  support.freenove.com...
  • Page 121 1. Use the cd command to go to the directory where Main.py is located. cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Client 2. Run Main.py: sudo python Main.py The interface is shown below: Please check whether the camera protective film is torn off. Need support?  support.freenove.com...
  • Page 122 The latest Raspberry Pi official system is not stable. It occasionally is stuck. The old version is more stable. If the Raspberry Pi system is stuck for a long time, you need reboot Raspberry Pi. If you have any concerns, please feel free to contact us with pictures: support@freenove.com Need support?  support.freenove.com...
  • Page 123: Android And Ios App

    On GitHub: https://github.com/Freenove/Freenove_App_for_Android In this github repository, you can find the App instruction (Tutorial.pdf). You can download and install the Freenove iPhone ios app by searching freenove in app store. Open the app and select the car. Need support?  support.freenove.com...
  • Page 124 Open the server in Raspberry Pi car first. And enter your Pi IP. RGB led Take photos Raspberry Pi IP Buzzer Connect Control Car moving. Control camera angle and postion. Drag the middle dot to The ring in the middle is use to reset. anywhere in the area. Need support?  support.freenove.com...
  • Page 125: Free Innovation

    If you have never learned python before, you can learn some basic knowledge via the link below: https://python.swaroopch.com/basics.html First, turned on S1 and S2. Then open Raspberry Pi, right click and create a new folder on the desktop: Test Need support?  support.freenove.com...
  • Page 126 Chapter 7 Smart video car www.freenove.com █ Open Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server in your Raspberry Pi and copy the following 8 files into the Test folder we created. Paste them in Test folder. Need support?  support.freenove.com...
  • Page 127 Chapter 7 Smart video car █ www.freenove.com Run Thonny Python IDE Need support?  support.freenove.com...
  • Page 128 Chapter 7 Smart video car www.freenove.com █ Click Save and save it into the Test folder, with name: test_Code. Need support?  support.freenove.com...
  • Page 129 █ www.freenove.com Now you can see the file test_Code.py we created. Then write code in test_Code.py, then click save. Note: the code and library are written by Python 3. You need execute the code with python 3. Need support?  support.freenove.com...
  • Page 130 ("The photoresistor voltage on the left is "+str(Left_IDR)+"V") LED. For more details, please refer to LED. from import #import Led led=Led() #create an object led.ledIndex(0x04,255,255,0) #yellow led.ledIndex(0x80,0,255,0) #green time.sleep(5) #wait 5s led.colorWipe(led.strip, Color(0,0,0)) #turn off Need support?  support.freenove.com...
  • Page 131 Ultrasonic module. For more details, please refer to Ultrasonic module. from Ultrasonic import #import Led ultrasonic=Ultrasonic() #create an object data=ultrasonic.get_distance() #Get the value print ("Obstacle distance is "+str(data)+"CM") These codes can be integrated into one code to achieve your requirement. Need support?  support.freenove.com...
  • Page 132: What's Next

    Freenove electronic modules, or improving the code to achieve different functions. We will also try our best to add more new functions and update the code on our github (https://github.com/freenove). If you want to learn more about Arduino, Raspberry Pi, smart cars, robots and orther interesting products in science and technology, please continue to focus on our website.

Table of Contents

Save PDF