Freenove 4WD Smart Car Board for Raspberry Pi Manual

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

Advertisement

Quick Links

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 ......................................6 Self-prepared Parts .................................. 6 Preface ........................................
  • Page 5: Welcome

    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

    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

    DC speed reduction motor x4 Motor bracket package Coupling & screw for mecanum Caution: Do not remove the cable tie from wheel x4 the motor; otherwise, the motor cable may become detached. Acrylic Parts For Pan Tilt Need support?  support.freenove.com...
  • Page 8: Electronic Parts

    5, Version 2 is expected to be phased out. If you want to achieve the function of V2, you can connect GPIO10 to GPIO18 with a jumper wire, as shown below. Need support?  support.freenove.com...
  • Page 9 Jumper Wire F/F(4) x1 XH-2.54-5Pin cable x1 FPC soft line x1 FPC soft line x1 Please note that this cable only come with the purchase of the Raspberry Pi 5 version. Need support?  support.freenove.com...
  • Page 10: Tools

    Tools Cross screwdriver (3mm) x1 Black tape x1 Cable Tidy x25cm Self-prepared Parts Please refer to About_Battery.pdf in unzipped folder. Raspberry Pi (Recommended model: Raspberry 5 / 4B / 3B+) x1 Need support?  support.freenove.com...
  • Page 11: 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 12: Raspberry Pi Introduction

    Below are the raspberry pi pictures and model pictures supported by this product. They have 40 pins. Practicality picture of Raspberry Pi 5: Model diagram of Raspberry Pi 5: Need support?  support.freenove.com...
  • Page 13 Actual image of Raspberry Pi 4 Model B: CAD image of Raspberry Pi 4 Model B: Actual image of Raspberry Pi 3 Model B+: CAD image of Raspberry Pi 3 Model B+: Need support?  support.freenove.com...
  • Page 14 Actual image of Raspberry Pi 3 Model B: CAD image of Raspberry Pi 3 Model B: Actual image of Raspberry Pi 2 Model B: CAD image of Raspberry Pi 2 Model B: Need support?  support.freenove.com...
  • Page 15 Actual image of Raspberry Pi 1 Model B+: CAD image of Raspberry Pi 1 Model B+: Actual image of Raspberry Pi 3 Model A+: CAD image of Raspberry Pi 3 Model A+: Need support?  support.freenove.com...
  • Page 16 Actual image of Raspberry Pi 1 Model A+: CAD image of Raspberry Pi 1 Model A+: Actual image of Raspberry Pi Zero W: CAD image of Raspberry Pi Zero W: Actual image of Raspberry Pi Zero: CAD image of Raspberry Pi Zero: Need support?  support.freenove.com...
  • Page 17 Below are the raspberry pi pictures and model pictures supported by this product. They have 40 pins. Hardware interface diagram of RPi 5 is shown below: Hardware interface diagram of RPi 4B is shown below: Need support?  support.freenove.com...
  • Page 18 Hardware interface diagram of RPi 3B+/3B/2B/1B+: Hardware interface diagram of RPi 3A+/A+: Hardware interface diagram of RPi Zero/Zero W: Need support?  support.freenove.com...
  • Page 19 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 20 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 21 You can also use the following command to view their correspondence. gpio readall For more details about wiringPi, please refer to https://github.com/WiringPi/WiringPi Need support?  support.freenove.com...
  • Page 22: Introduction To Mecanum Wheel

    Y-axis, allowing us to better comprehend its motion characteristics. Therefore, we can also consider that when the A-type mecanum wheel rotates forward, it generates a forward and rightward velocity. Conversely, when it rotates backward, it generates a backward and leftward velocity. Need support?  support.freenove.com...
  • Page 23 Y-axis, and rotates around its geometric center. By simple addition, we can then compute the speed of the four wheels required for the composite motion of "translation + rotation" achieved by combining these three simple movements. Need support?  support.freenove.com...
  • Page 24 When the car moves along the Y axis, it can be seen that the speed of each wheel is equal to the translation speed, that is V(FR) = V(Y) V(FL) = V(Y) V(BL) = V(Y) V(BR) = V(Y) When the car moves along the X axis, V(FR) = -V(X) V(FL) = +V(X) V(BL) = -V(X) V(BR) =+V(X) Need support?  support.freenove.com...
  • Page 25 V(BL) = V(Y) -V(X) -V(ω) V(BR) = V(Y) +V(X) +V(ω) Note: When the car rotation is not considered, only the Y-axis velocity and X-axis velocity need to be retained, and the angular velocity ω can be removed. Need support?  support.freenove.com...
  • Page 26: 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 27 The Raspberry Pi 5 provides 1.6A of power to downstream USB peripherals when connected to a power supply capable of 5A at +5V (25W). When connected to any other compatible power supply, the Raspberry Pi 5 restricts downstream USB devices to 600mA of power. Need support?  support.freenove.com...
  • Page 28 Cable Micro-USB USB-A Adapter & Cable (Micro USB OTG Cable) USB HUB USB to Ethernet Internal select one from optional Interface Integration two or select Internal Integration USB Wi-Fi Receiver Internal two from two optional Integration Need support?  support.freenove.com...
  • Page 29 Raspberry Pi through SSH, and then open the VNC or RDP service. This requires the following accessories. Pi Zero Pi Zero W Pi A+ Pi 3A+ Pi B+/2B Pi 3B/3B+/4B/5 Micro-USB to USB-A Adapter & Cable (Micro Cable) USB to Ethernet interface Need support?  support.freenove.com...
  • Page 30 In this way, the system will be downloaded automatically via the application. Manually Method After installing the Imager Tool in the link above. You can also download the system manually first. Visit https://www.raspberrypi.org/downloads/ Please download the latest system image. And then the zip file is downloaded. Need support?  support.freenove.com...
  • Page 31 First, put your Micro SD card into card reader and connect it to USB port of PC. Then open imager toll. Clicked Choose Device. Select a Raspberry PI Device based on your Raspberry PI version. It will help us filter out the right version of the system for the Raspberry PI. Need support?  support.freenove.com...
  • Page 32 Clicked Operating System. Choose system that you just downloaded in Use custom. Need support?  support.freenove.com...
  • Page 33 Choose the SD card. Then click “Next”. You can configure the Raspberry PI according to your needs. Need support?  support.freenove.com...
  • Page 34 Enable ssh and configure WiFi On the GENERAL screen, configure your information based on your actual situation. Click Save, in the new screen, click Yes, wait for SD to brush into the Raspberry system. Need support?  support.freenove.com...
  • Page 35 Insert SD card Then remove SD card from card reader and insert it into Raspberry Pi. Connect to the power supply and wait for the Raspberry PI to turn on. Need support?  support.freenove.com...
  • Page 36: Getting Started With Raspberry Pi

    Raspberry Pi 5, 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 Set Resolution You can also set other resolutions. Need support?  support.freenove.com...
  • Page 38 If you don't know what resolution to set properly, you can try 1920x1080. 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 39 Here, you have logged in to Raspberry Pi successfully by using VNC Viewer and operated proper setting. Raspberry Pi 5/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 40 Open the terminal and type following command. If this command doesn’t work, please move to next page. ssh pi@raspberrypi.local The password is raspberry by default, case sensitive. You may need to type yes during the process. Need support?  support.freenove.com...
  • Page 41 “192.168.1.95". Open the terminal and type following command. ssh pi@192.168.1.95 When you see pi@raspberrypi:~ $, you have logged in Pi successfully. Then you can skip to next section. Then you can skip to VNC Viewer. Need support?  support.freenove.com...
  • Page 42 Then 192.168.1.95 is my Raspberry Pi IP. Or enter router client to inquiry IP address named “raspberrypi”. For example, I have inquired to my RPi IP address, and it is “192.168.1.95". ssh pi@xxxxxxxxxxx(IP address) Enter the following command: ssh pi@192.168.1.95 Need support?  support.freenove.com...
  • Page 43 Enable VNC Viewer Type the following command. And select Interface Options→P5 VNC → Enter→Yes→OK. Here Raspberry Pi may need be restarted, and choose ok. Then open VNC interface. sudo raspi-config Need support?  support.freenove.com...
  • Page 44 Then download and install VNC Viewer according to your computer system by click following link: https://www.realvnc.com/en/connect/download/viewer/ After installation is completed, open VNC Viewer. And click File → New Connection. Then the interface is shown below. Enter ip address of your Raspberry Pi and fill in a name. Then click OK. Need support?  support.freenove.com...
  • Page 45 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. Here, you have logged in to Raspberry Pi successfully by using VNC Viewer Need support?  support.freenove.com...
  • Page 46: 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 --depth 1 https://github.com/Freenove/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi Need support?  support.freenove.com...
  • Page 47 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 48 “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 49: Step 2 Configuration

    The I2C interface Raspberry Pi is disabled by default. You need to open it manually. Note that if your connector version is V2.0, remember to turn on the SPI feature. If your connector version is V1.0, turn off the SPI feature. Need support?  support.freenove.com...
  • Page 50 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 51 # 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 52: Step 3 Run The Libraries Installation Program

    If your Rpi is a Pi 5, it will ask you which camera interface to use. You can type in cam0 or cam1 based on the interface you want to use. Note: Make sure you connect the camera cable to the corresponding interface. If it is not Raspberry Pi, this setting is not needed, as there is only camera interface available. Need support?  support.freenove.com...
  • Page 53 The reboot of the pi takes some time, please wait with patience. 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 54: 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: Need support?  support.freenove.com...
  • Page 55 You can also attach this bracket to motor first. Step 2 Install motor to bracket with M3*30 screw and M3 Nut. Caution: Do not remove the cable tie from the motor; otherwise, the motor cable may become detached. Need support?  support.freenove.com...
  • Page 56 Based on the introduction to the mecanum wheels, assemble them following the sequence of A-B-A-B from M1 to M4. Slide the mecanum wheel coupling onto the motor's transmission rod. Attach the wheel to the coupling. Finally, use the provided screws to tighten the connection securely. Need support?  support.freenove.com...
  • Page 57 Note: Improper installation of the four wheels can lead to issues that prevent the car from functioning correctly. It is essential to strictly adhere to the installation method shown in the diagram to ensure proper functioning and smooth operation of the mecanum wheel-based car. Need support?  support.freenove.com...
  • Page 58 Step 1 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 Connect line tracking module to smart car board with XH-2.54-5Pin cable. Need support?  support.freenove.com...
  • Page 59 Raspberry Pi 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 60 We have two types of connection boards, but they are installed in the same way. here for more information. Connection board (PCB_V1.0) Connection board (PCB_V2.0) Step 2 If you have any concerns, please feel free to contact us via support@freenove.com Need support?  support.freenove.com...
  • Page 61 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 62 Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8: Step 9 Now please refer to Wiring Section to wring ultrasonic sensor and camera frist. Step 10 Step 11 After finished Need support?  support.freenove.com...
  • Page 63 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. Need support?  support.freenove.com...
  • Page 64 Step 3 Pay attention to servo wiring. (Note: wiring about the ultrasonic and camera module will be introduced later. ) Need support?  support.freenove.com...
  • Page 65 You need shut 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 66 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 67 Camera for Pi5 You need shut down Raspberry Pi when wire camera. Step 1 Step 2 Connect one end of cable to camera. Please note the front and back of the cable. Need support?  support.freenove.com...
  • Page 68 Step 3 Step 4 Connect another end of cable to Raspberry Pi. Please note the front and back of the cable. Need support?  support.freenove.com...
  • Page 69 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 70: 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 71 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. set_motor_model(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 72 On one side of the car, two wheels generate a forward and a backward velocity, effectively canceling each other out. However, this results in a solitary leftward velocity component. The leftward velocities from both sides combine, thus moving the car laterally to the left. Need support?  support.freenove.com...
  • Page 73 Data1 Data2 Date3 Data4 Movements of the Car Forward Backward Turn left Turn right Move left Move right Left and forward Right and backward Right and forward Left and backward Stop Need support?  support.freenove.com...
  • Page 74 2. Open “Motor.py” with nano editing tool. sudo nano car.py 3. Modify the value of “time_propotion”,do not make significant increases or decreases at once; keep the changes within a range of tenths place (one decimal point). Need support?  support.freenove.com...
  • Page 75 5°. Additionally, the delay function includes a simple voltage linear compensation. You have the option to modify the proportion value "time_proportion" to achieve the best forward rotation effect, tailoring it to your specific requirements. Need support?  support.freenove.com...
  • Page 76 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 77 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 78 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 79 != ir2_value != ir3_value == 1: print ('Right') elif ir1_value == ir2_value != ir3_value != 1: print ('Left') except KeyboardInterrupt: # Close the Infrared object and print a message when interrupted infrared.close() print("\nEnd of program") Need support?  support.freenove.com...
  • Page 80 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 If you are using the Led feature for the first time, it will ask for the PCB version of the connection board. Need support?  support.freenove.com...
  • Page 81 255, #Red led.ledIndex(0x02, 255, 125, #orange led.ledIndex(0x04, 255, 255, #yellow led.ledIndex(0x08, 0, 255, #green led.ledIndex(0x10, 0, 255, 255) #cyan-blue led.ledIndex(0x20, 0, 255) #blue led.ledIndex(0x40, 128, 0, 128) #purple Need support?  support.freenove.com...
  • Page 82 When the state is 0, the lights will be turned off. When state is 1, the red, green, and blue colors are displayed in a non-blocking loop. wait_ms Indicates the time interval. The default value is 300ms. Need support?  support.freenove.com...
  • Page 83 + C" to end the program. The code is as below: test_Buzzer(): import time from buzzer import Buzzer buzzer = Buzzer() try: print ("Program is starting ...") buzzer.set_state(True) time.sleep(1) print ("1S") time.sleep(1) print ("2S") time.sleep(1) print ("3S") buzzer.set_state(False) Need support?  support.freenove.com...
  • Page 84 ("\nEnd of program") Reference buzzer. (bool) set_state This function has one input parameter. If the input is true, the buzzer will be turned on. If the input is false, the buzzer will be turned off. Need support?  support.freenove.com...
  • Page 85 You can press “Ctrl + C” to end the program. The code is as below: test_Servo(): import time from servo import Servo servo = Servo() try: print ("Program is starting ...") while True: range(50,110,1): servo.set_servo_pwm('0',i) time.sleep(0.01) range(110,50,-1): servo.set_servo_pwm('0',i) time.sleep(0.01) range(80,150,1): servo.set_servo_pwm('1',i) time.sleep(0.01) range(150,80,-1): servo.set_servo_pwm('1',i) Need support?  support.freenove.com...
  • Page 86 There are 2 parameters. The first one is related to servo index. The second one is related to the angle of servos. For example, set_servo_pwm(‘0’,20) makes servo0 rotate to 20°. set_servo_pwm(‘1’,90) makes servo1 rotate to 90°. Need support?  support.freenove.com...
  • Page 87 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 88 # Handle keyboard interrupt (Ctrl+C) ultrasonic.close() finally: print("\nEnd of program") # Print an end message 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 89 Camera for Pi3/4 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 90 RPi USB port. Connect another end of cable to Raspberry Pi. Please note the front and back of the cable. Camera for Pi5 You need shut down Raspberry Pi when wire camera. Step 1 Need support?  support.freenove.com...
  • Page 91 Step 2 Connect one end of cable to camera. Please note the front and back of the cable. Step 3 Need support?  support.freenove.com...
  • Page 92 If you are not a Raspberry PI 5, add the following command. dtoverlay = ov5647 3. Save the file and exit, then restart the Raspberry PI. Run program 1. execute the cd command: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2. Execute the following command: python camera.py Need support?  support.freenove.com...
  • Page 93 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 94: Chapter 4 Light Tracing Car

    Light The code is below: from ultrasonic import Ultrasonic from motor import Ordinary_Car from servo import Servo from infrared import Infrared from import import time import math class Car: … mode_light(self): (time.time() - self.car_record_time) > 0.2: Need support?  support.freenove.com...
  • Page 95 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 96: Chapter 5 Ultrasonic Obstacle Avoidance Car

    Infrared from import import time import math class Car: … run_motor_ultrasonic(self, distance): (distance[0] < distance[1] < distance[2] <30) distance[1] < self.motor.set_motor_model(-1450,-1450,-1450,-1450) time.sleep(0.1) distance[0] < distance[2]: self.motor.set_motor_model(1450,1450,-1450,-1450) else self.motor.set_motor_model(-1450,-1450,1450,1450) elif distance[0] < distance[1] < 30: self.motor.set_motor_model(1500,1500,-1500,-1500) Need support?  support.freenove.com...
  • Page 97 = elif self.car_sonic_servo_angle >= 150: self.car_sonic_servo_dir = self.car_sonic_servo_dir == 1: self.car_sonic_servo_angle += elif self.car_sonic_servo_dir == 0: self.car_sonic_servo_angle -= test_car_sonic(): car = Car() try: while True: car.mode_ultrasonic() except KeyboardInterrupt: car.close() print("\nEnd of program") __name__ == '__main__': import Need support?  support.freenove.com...
  • Page 98 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 99: Chapter 6 Infrared Line Tracking Car

    If there are issues with the test, the infrared device may need to be adjusted. The adjustment screw is on top of the sensor. The code is as below: from ultrasonic import Ultrasonic from motor import Ordinary_Car from servo import Servo from infrared import Infrared from import import time import math class Car: … mode_infrared(self): Need support?  support.freenove.com...
  • Page 100 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 101: Chapter 7 Smart Video Car

    The smart video car integrates the previous functions of light tracing, obstacle avoidance, line tracing, video transmission, face detection, LED and so on. And it is built with a server and a client, so it can be controlled remotely. Need support?  support.freenove.com...
  • Page 102: Server

    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 103 If the resolution ratio is not great or there is just a little window, you can set a proper resolution ratio via steps below. sudo raspi-config Select Screen Configuration. Select the appropriate resolution in the new window. Click Apply. Need support?  support.freenove.com...
  • Page 104 Need support?  support.freenove.com...
  • Page 105 If you are using remote desktop mode to login Raspberry Pi, you need use viewer. Enter the following command in the terminal. 1. Use cd command to enter directory where main.py is located: cd ~/Freenove_4WD_Smart_Car_Kit_for_Raspberry_Pi/Code/Server 2. Run main.py: sudo python main.py The interface is as below: Need support?  support.freenove.com...
  • Page 106 “start.desktop” file sudo nano .config/autostart/start.desktop Add the following content to “start.desktop” file. [Desktop Entry] Type=Application Name=start NoDisplay=true Exec=/home/pi/start.sh Press Ctrl + O and then press Enter to save it. Press Ctrl+X to exit. Need support?  support.freenove.com...
  • Page 107 +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. cd ~ sudo rm start.sh sudo rm .config/autostart/start.desktop Need support?  support.freenove.com...
  • Page 108: 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 109 = 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 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 60 to modify the code. Need support?  support.freenove.com...
  • Page 111 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 112 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 113 Here, my install location is D. You can also choose other location. Then click “Install”. Wait installing. Need support?  support.freenove.com...
  • Page 114 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 115 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 116 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 117 SliderBar. Other control information: Control Function IP address Edit box Enter IP address of Raspberry Pi Power box Show power level R,G,B Edit box Control the color of LED selected. Need support?  support.freenove.com...
  • Page 118 2. Modify IP address to IP address of your Raspberry Pi. For example, my rpi IP is 192.168.1.126. After modification, it should be as below: self.IP.setText(_translate("Client", "192.168.1.126", None)) Then save and close. And then restart your client. You can see it is modified successfully. Need support?  support.freenove.com...
  • Page 119 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 120 At bottom of the page, click macOS 64-bit installer and download installation package. Click Continue. Need support?  support.freenove.com...
  • Page 121 Click Continue Click Agree. Need support?  support.freenove.com...
  • Page 122 Click Install. If your computer has a password, enter the password and Install Software. Need support?  support.freenove.com...
  • Page 123 Now the installation succeeds. You can find it in Aapplications. Need support?  support.freenove.com...
  • Page 124 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 125 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 126 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 127 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 128 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 129: Communication Command

    The speed range for each motor is from -4056 to 4056. App command Action CMD_MOTOR#1500#1500#1500#1500\n Forward CMD_MOTOR#-1500#-1500#-1500#-1500\n Backward CMD_MOTOR#-1500#-1500#1500#1500\n Turn Left CMD_MOTOR#1500#1500#-1500#-1500\n Turn Right CMD_MOTOR#0#0#0#0\n Stop CMD_ M_MOTOR Need support?  support.freenove.com...
  • Page 130 The extent of rotation is contingent upon the angle specified in the third parameter, offering precise control over the direction of rotation for the car. App command Action CMD_CAR_ROTATE#0#0#0#0\n Rotate forward CMD_CAR_ROTATE #0#0#0#0\n Rotate backward CMD_CAR_ROTATE #0#0#0#0\n Stop CMD_CAR_ROTATE #90#1500#0#0\n Rotate to the left Need support?  support.freenove.com...
  • Page 131: Android And Ios App

    CMD_MODE #0 Control mode CMD_MODE #1 Light-tracing mode CMD_MODE #2 Line-tracking mode CMD_MODE #3 Obstacle avoidance mode Android and iOS app You can download and install the Freenove Android app from below: On Google play: https://play.google.com/store/apps/details?id=com.freenove.suhayl.Freenovez Need support?  support.freenove.com...
  • Page 132 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 133 When the "Spin Mode" is activated, it controls the angle at which the car rotates while moving forward. In spin mode, keep the joystick pressed; releasing it will stop the car. Need support?  support.freenove.com...
  • Page 134: 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 135 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 136 Run Thonny Python IDE Need support?  support.freenove.com...
  • Page 137 Click Save and save it into the Test folder, with name: test_Code. Need support?  support.freenove.com...
  • Page 138 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 139 ("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 140 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 141: 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