{"id":220,"date":"2026-10-01T14:06:24","date_gmt":"2026-10-01T14:06:24","guid":{"rendered":"http:\/\/el-dev.com\/en\/?p=220"},"modified":"2026-10-01T14:11:36","modified_gmt":"2026-10-01T14:11:36","slug":"3d-printed-truck-raspberry-pi-android","status":"publish","type":"post","link":"https:\/\/el-dev.com\/en\/articles\/3d-printed-truck-raspberry-pi-android\/","title":{"rendered":"Project of a truck model printed on a 3D printer"},"content":{"rendered":"\n<div style=\"display:table;\"><div style=\"display:table-cell; width:500px;\"><figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_1.jpg\" alt=\"\" class=\"wp-image-36\" width=\"500\" height=\"274\" style=\"float: left; margin-right: 15px; margin-top:5px;\"><\/figure><\/div>\n\n\n\n<div style=\"display: table-cell; vertical-align:top; padding-left:15px;\">\n\n\n\n<p class=\"wp-block-paragraph\">List of equipment required for the project:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> Raspberry Pi 3 model A+ <\/li><li>Logic level converter from 3.3V to 5V<\/li><li>L298N brushless motor driver<\/li><li>Battery 5V 2700 mAh<\/li><li>MG995 servo<\/li><li>Brushless motor<\/li><\/ul><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we will consider the process of 3D printing and assembling a truck model, analyze the technical aspects and features of connecting devices for controlling electric motors, and also talk about the difficulties encountered during the project implementation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This project is a continuation of a series of articles about remote control of self-propelled platforms using a Raspberry Pi microcomputer. In the previous article, we installed a Raspberry Pi on a Chinese 1:10 scale pickup model and replaced the radio control module with Wi-Fi control.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> In this article, we decided to go further and change the design of our car model. A ready-made truck model project for 3D printing was taken as a basis. The chosen project has a number of advantages. The model provides an independent suspension system, drive is distributed to all 4 wheels, and it is possible to additionally install a differential lock. The size of the truck model allows placing all necessary equipment. <\/p>\n\n\n\n<div style=\"margin:auto; text-align:center;\"><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/JR4DCSf0bqY\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" style=\"margin:auto;\"><\/iframe><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">3D printing and assembly of the truck model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">While wandering through the vast expanses on thingiverse.com, I came across an interesting 3D truck model project by user MrCrankyface. The project immediately interested me with its complexity, many parts for 3D printing, and many additional metal parts that had to be purchased separately. But first things first.<\/p>\n<p>Link to the project on the Thingiverse: <a href=\"https:\/\/www.thingiverse.com\/thing:1755011\" target=\"_blank\">3D printed RC truck<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Printing<\/h3>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_3.jpg', 1024, 720, '')\" onmouseover=\"image_mouseover(2)\" onmouseout=\"image_mouseout(2)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_3.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"281\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_2\"><\/div><\/div><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">During 3D printing, we encountered a standard set of problems: poor adhesion (when parts came unstuck and warped), delamination of printed parts, and a banal mismatch in the dimensions of mating parts (solved by adjusting the 3D model).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We solved the adhesion problem by using the technology of lubricating the printing surface with ABS glue. ABS glue is easy to make by simply dissolving a small amount of ABS plastic with dichloroethane in a glass, well-sealing container. Then, before each print, the glue is applied to the print surface in a thin layer using an ordinary brush (better before heating the bed).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We solved the problem of part delamination simply by increasing the temperature of the printing nozzle, as well as the bed temperature. For our ABS plastic, the suitable printing parameters were 245 degrees nozzle temperature and 100 degrees bed temperature.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Assembly<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For assembling the model, it was necessary to buy additional metal fasteners to connect the printed 3D parts. The full list of required components can be found on the author&#8217;s project page (see note). Some parts were available in local stores (such as M3 and M4 bolts, studs, and nuts), some had to be ordered online (such as ball joints for suspension mounting and bearings for rotating parts).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The model itself consists of a load-bearing central frame measuring 7 cm * 40 cm, to which the suspension and power section are attached, a central differential, axles, a brushed electric motor, and a servo drive acting as a steering motor.<\/p>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" style=\"float:left;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_4_1.jpg', 1024, 574, '')\" onmouseover=\"image_mouseover(3)\" onmouseout=\"image_mouseout(3)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_4_1.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"300\" height=\"168\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_3\"><\/div><\/div><\/div>\n\n\n\n<div class=\"image_zoom_block\" style=\"margin: auto;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_4_2.jpg', 1024, 709, '')\" onmouseover=\"image_mouseover(4)\" onmouseout=\"image_mouseout(4)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_4_2.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"300\" height=\"208\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_4\"><\/div><\/div><\/div>\n\n\n\n<div class=\"image_zoom_block\" style=\"float:right;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_4_3.jpg', 1024, 568, '')\" onmouseover=\"image_mouseover(5)\" onmouseout=\"image_mouseout(5)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_4_3.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"300\" height=\"166\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_5\"><\/div><\/div><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The image above shows the steering mechanism of the front wheels. An M3 stud was bent and used as a steering rack going from the servo to the steering mechanism on the front axle.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The shock absorbers were printed on a 3D printer. This model also provides for the installation of factory air shock absorbers for radio models.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The tires for the wheels were taken from a Chinese radio-controlled model from the <a href=\"https:\/\/el-dev.com\/en\/articles\/raspberry-car-control\/\" target=\"_blank\">previous project<\/a>. The rims were designed in a 3D editor specifically for the size of these tires and the mounts to the truck model axles. The design of the wheels of the legendary Russian Ural truck was taken as the basis for the wheel rim design.<\/p>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_2.jpg', 1024, 599, '')\" onmouseover=\"image_mouseover(1)\" onmouseout=\"image_mouseout(1)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_2.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"234\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_1\"><\/div><\/div><\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Development and 3D printing of a platform for equipment<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To reliably place the equipment on the model body, an additional 3D model of a platform with mounts for installing circuit boards with the Raspberry Pi microcomputer and motor drivers was developed. All dimensions were taken from the specifications for each individual electronic component. Special slots were provided on the platform for routing wires. In the rear part of the body there is a battery block. On the sides, the platform has mounts for installing the body, which will be printed in the following articles.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For convenience of 3D printing, the platform model was divided into two parts. 3D printing of all platform parts took about 7 hours. Printing was done with 100% infill and supports. After printing, the 3D-printed electronics platform was installed and secured to the truck frame. All electronic components were placed in their respective mounting areas.<\/p>\n\n\n\n<div style=\"display:table; margin-left:auto; margin-right:auto;\"><figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/en\/wp-content\/uploads\/2026\/10\/model_with_devices_eng-5.jpg\" alt=\"\" class=\"wp-image-36\" width=\"800\" height=\"521\" style=\"float: left; margin-right: 15px; margin-top:5px;\"><\/figure><\/div>\n\n\n\n<div style=\"display:table; margin-top:20px; margin-left:auto; margin-right:auto;\"><div class=\"image_zoom_block\" style=\"padding-right:60px;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/model_3d_2.jpg', 1294, 843, '')\" onmouseover=\"image_mouseover(6)\" onmouseout=\"image_mouseout(6)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/model_3d_2.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"261\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_6\"><\/div><\/div><\/div>\n\n\n\n<div class=\"image_zoom_block\" style=\"margin-right:50px;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/model_3d_3.jpg', 1294, 843, '')\" onmouseover=\"image_mouseover(7)\" onmouseout=\"image_mouseout(7)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/model_3d_3.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"261\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_7\"><\/div><\/div><\/div><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Installation and connection of equipment<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Equipment composition:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> Raspberry Pi 3 model A+ <\/li><li>Logic level converter from 3.3V to 5V<\/li><li>L298N brushless motor driver<\/li><li>Battery 5V 2700 mAh<\/li><li>MG995 servo<\/li><li>Brushless motor<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">All of the listed equipment can be ordered in any online radio components store. Except for the Raspberry Pi, which sometimes has to be searched for separately.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So let&#8217;s begin; first, it is necessary to place all electronic boards on a special platform located on the frame of our truck. They are fixed using small M1 screws.<\/p>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_5.jpg', 1024, 534, '')\" onmouseover=\"image_mouseover(8)\" onmouseout=\"image_mouseout(8)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/truck_3d_pic_5.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"209\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_8\"><\/div><\/div><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Then, following the diagram shown below, you need to correctly connect all outputs on our devices. All electronic components were connected using 10-pin (F) &#8211; 10-pin (M) jumper wires. First, you will need to twist (or solder) two blanks for branching power from the batteries.<\/p>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/Truck_Connection_Scheme_c.jpg', 696, 1024, 'General electronics connection diagram')\" onmouseover=\"image_mouseover(9)\" onmouseout=\"image_mouseout(9)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/Truck_Connection_Scheme_c.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"589\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_9\"><\/div><\/div><\/div><div class=\"image_description\">General electronics connection diagram<\/div><\/div>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/Connection_example.jpg', 935, 709, 'Wires for branching power from batteries')\" onmouseover=\"image_mouseover(10)\" onmouseout=\"image_mouseout(10)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/Connection_example.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"400\" height=\"303\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_10\"><\/div><\/div><\/div><div class=\"image_description\">Wires for branching power from batteries<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The 5V battery for powering the motors is connected and disconnected using pin connectors. The Raspberry Pi microcomputer is powered separately from an external power bank for mobile devices with a capacity of 9000 mAh, an output voltage of 5V, and a current of 2A.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For further manipulations, it is necessary to check the correctness of the circuit connection. To do this, simply connect the batteries to the motor controllers and the controllers themselves to the Raspberry Pi, connect remotely to the Raspberry via SSH (or connect a monitor for testing), and run a couple of test scripts to check the operation of the servo and brushed motor from the previous articles. If everything works properly, we can move on and start developing a mobile application to control our truck.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Development of a mobile application with a control panel<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To control the motors of the truck model, a mobile Android application with a minimalist design was developed. A new screen was added to the application for controlling the servo; it is available from the menu item \u201cServo control\u201d. In the settings, two new fields appeared, \u201cMotor PWM\u201d and \u201cServo turn\u201d, for specifying the pin numbers for pulse-width modulation (PWM) of the brushed motor, to control smoothness of movement, and for turning the servo, respectively.<\/p>\n\n\n\n<div style=\"text-align:center;\"><div class=\"image_zoom_block\" style=\"float:left;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/android_app_screen_2.jpg', 394, 702, 'Main application screen')\" onmouseover=\"image_mouseover(11)\" onmouseout=\"image_mouseout(11)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/android_app_screen_2.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"300\" height=\"535\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_11\"><\/div><\/div><div class=\"image_description\">Main application screen<\/div><\/div>\n\n\n\n<div class=\"image_zoom_block\" style=\"margin: auto;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/android_app_screen_3.jpg', 396, 702, 'Settings screen')\" onmouseover=\"image_mouseover(12)\" onmouseout=\"image_mouseout(12)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/android_app_screen_3.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"300\" height=\"532\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_12\"><\/div><\/div><div class=\"image_description\">Settings screen<\/div><\/div>\n\n\n\n<div class=\"image_zoom_block\" style=\"float:right;\" onclick=\"image_zoom_onclick('http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/android_app_screen_1_2.jpg', 1024, 508, 'Servo and brushed motor control screen.')\" onmouseover=\"image_mouseover(13)\" onmouseout=\"image_mouseout(13)\"><div class=\"zoom_icon_container\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/android_app_screen_1_2.jpg\" alt=\"\" class=\"wp-image-64\" alt=\"\" class=\"wp-image-64\" width=\"300\" height=\"149\" class=\"image_zoom_block\"\/><div class=\"zoom_icon\" id=\"zoom_icon_13\"><\/div><\/div><div class=\"image_description\">Servo and brushed motor control screen.<\/div><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">On the settings screen in the application, you must specify the address and port for connecting to the Raspberry Pi, as well as the numbers of the Raspberry Pi pins responsible for controlling the motors. We will not need the \u201cGo left\u201d and \u201cGo right\u201d fields, since turning is performed using the servo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a description of the correct field values if connecting according to the diagram presented above:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go forward: 8 (Brushless motor forward movement)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go back: 7 (Brushless motor backward movement)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Motor PWM: 25 (Pulse-width modulation)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Servo turn: 17 (Servo turning)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">After saving the settings, the application will send HTTP requests to the Raspberry Pi to activate the corresponding pins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Mini web server code in Python<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In order for the Raspberry Pi to understand our commands and activate the necessary pins, a small web application written in Python was developed. Before connecting through the mobile application, you must run the Python script with the code specified below. This web server has an open API interface with commands; by calling them, you can control the motors connected to the Raspberry Pi.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;python&quot;,&quot;mime&quot;:&quot;text\/x-python&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;python&quot;}\"> from flask import Flask, json, request\nfrom werkzeug.serving import make_server\nimport RPi.GPIO as GPIO\nimport threading\nimport time\n\napp = Flask(__name__)\n\np_servo = 17  # GPIO num for servo\nfPWM = 50  # Hz (not higher with software PWM)\na = 10\nb = 2\n\nin1 = 23  # GPIO num for motor go forward\nin2 = 24  # GPIO num for motor go backward\np_motor = 18  # GPIO num for PWM control motor\ngo_forward = 1\n\nmin_angle = 30\nmax_angle = 90\ndefault_forward_angle = 60\n\nthrottle_current = 0\n\nis_making_connection = 0\n\nclass ServerThread(threading.Thread):\n\n    def __init__(self, app):\n        threading.Thread.__init__(self)\n        self.srv = make_server('0.0.0.0', 5000, app)\n        self.ctx = app.app_context()\n        self.ctx.push()\n\n    def run(self):\n        print('starting server')\n        try:\n            self.srv.serve_forever()\n        finally:\n            self.srv.server_close()\n\n    def shutdown(self):\n        print('server stopped now !')\n        self.srv.shutdown()\n        self.srv.server_close()\n\n\n@app.route('\/')\ndef hello_world():\n    return 'Hello, from Raspberry Pi!'\n\n@app.route('\/set-servo-angle')\ndef set_servo_angle():\n    servo_angle = request.args.get('servo_angle')\n    if servo_angle != 'None':\n        setDirection(servo_angle)\n        #return '{\"status\":\"ok\"}'\n    #else:\n        #return '{\"status\":\"err\", \"err_msg\":\"empty servo_angle parameter\"}'\n    return 'ok'\n\n\n@app.route('\/set-throttle')\ndef set_throttle():\n    throttle_val = request.args.get('throttle_val')\n    if throttle_val != 'None':\n        setThrottle(int(throttle_val))\n        # return '{\"status\":\"ok\"}'\n    # else:\n    # return '{\"status\":\"err\", \"err_msg\":\"empty throttle_val parameter\"}'\n    return 'ok'\n\n\n@app.route('\/set-go-forward')\ndef set_go_forward():\n    global go_forward\n    go_forward_val = request.args.get('go_forward')\n    if throttle_current == 0 and go_forward_val != 'None':\n        go_forward = int(go_forward_val)\n        return '{\"status\":\"ok\"}'\n    else:\n        return '{\"status\":\"err\", \"err_msg\":\"empty go_forward parameter\"}'\n\n\n@app.route('\/make-connection')\ndef make_connection():\n    pwm_servo = request.args.get('p_servo')\n    pwm_motor = request.args.get('p_motor')\n    inpt1 = request.args.get('in1')\n    inpt2 = request.args.get('in2')\n    if pwm_servo != 'None' and pwm_motor != 'None' and inpt1 != 'None' and inpt2 != 'None':\n        setup(int(pwm_servo), int(pwm_motor), int(inpt1), int(inpt2))\n        return '{\"status\":\"ok\"}'\n    else:\n        return '{\"status\":\"err\", \"err_msg\":\"empty setup GPIO parameters\"}'\n\n\n@app.route('\/exit')\ndef app_exit():\n    setDirection(default_forward_angle)\n    time.sleep(5)\n    GPIO.cleanup()\n    print(\"stopping server\")\n    stop_server()\n    return \"Server closed\"\n\n\ndef setup(pwm_servo_val, pwm_motor_val, inpt1, inpt2):\n    global servo_pwm, motor_pwm, in1, in2, p_servo, p_motor, is_making_connection\n    # global servo_pwm, motor_pwm, is_making_connection\n\n    if is_making_connection == 0:\n        p_servo = pwm_servo_val\n        p_motor = pwm_motor_val\n        in1 = inpt1\n        in2 = inpt2\n\n        print('Setup: p_servo {} | p_motor {} | in1 {} | in2 {}'.format(p_servo, p_motor, in1, in2))\n\n        GPIO.setmode(GPIO.BCM)\n        GPIO.setup(p_servo, GPIO.OUT)\n        GPIO.setup(in1, GPIO.OUT)\n        GPIO.setup(in2, GPIO.OUT)\n        GPIO.setup(p_motor, GPIO.OUT)\n        GPIO.output(in1, GPIO.LOW)\n        GPIO.output(in2, GPIO.LOW)\n        motor_pwm = GPIO.PWM(p_motor, 1000)\n        motor_pwm.start(throttle_current)\n        servo_pwm = GPIO.PWM(p_servo, fPWM)\n        servo_pwm.start(getDutyFromAngle(default_forward_angle))\n        is_making_connection = 1\n\n\ndef getDutyFromAngle(angle):\n    duty = float(angle) \/ (180 \/ (10)) + 2.0\n    duty = round(duty, 2)\n    print(\"getDutyFromAngle: duty = \", duty)\n    return duty\n\n\ndef setDirection(angle):\n    # duty = a \/ 120 * direction + b\n    angle = ((int)(angle))\n    print('setDirection: ', angle)\n\n    if angle >= max_angle:\n        angle = max_angle\n    elif angle <= min_angle:\n        angle = min_angle\n\n    if min_angle <= angle <= max_angle:\n        duty = getDutyFromAngle(angle)\n        servo_pwm.ChangeDutyCycle(duty)\n        print(\"direction =\", angle, \"-> duty =\", duty)\n        # time.sleep(2) # allow to settle\n    return angle\n\n\ndef setThrottle(throttle_val):\n    global throttle_current\n    print('setThrottle: throttle_current {} | throttle_val {}'.format(throttle_current, throttle_val))\n    if throttle_current == 0 and throttle_val > 0:\n        startMotor()\n\n    if 0 <= throttle_val <= 100:\n        throttle_current = throttle_val\n        if throttle_current == 100:\n            GPIO.output(p_motor, GPIO.HIGH)\n            print('set MAX throttle')\n        else:\n            motor_pwm.ChangeDutyCycle(throttle_current)  # change motor PWM to move\n            print(\"setThrottle(): throttle_current = \", throttle_current)\n        if throttle_current == 0:\n            stopMotor()\n\n\ndef startMotor():\n    if go_forward == 1:\n        GPIO.output(in1, GPIO.HIGH)\n        GPIO.output(in2, GPIO.LOW)\n        print('start motor go forward')\n    elif go_forward == 0:\n        GPIO.output(in1, GPIO.LOW)\n        GPIO.output(in2, GPIO.HIGH)\n        print('start motor go backward')\n\n\ndef stopMotor():\n    GPIO.output(in1, GPIO.LOW)\n    GPIO.output(in2, GPIO.LOW)\n    print('stop motor')\n\n\ndef start_server():\n    global server\n    server = ServerThread(app)\n    server.start()\n    print('server started')\n\n\ndef stop_server():\n    global server\n    server.shutdown()\n\n\ndef main():\n    # setup()\n    start_server()\n\n\nif __name__ == '__main__':\n    main()\n<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Launch and testing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting the model, you must connect power from the external battery to the Raspberry Pi. After the Raspberry Pi boots and you successfully connects to it via SSH, you can connect the additional battery to the circuit of our motors. The LEDs on the body of the brushed motor driver should light up.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is worth recalling that the WebIOPi service must be installed and running on the Raspberry Pi (for more details, see the <a href=\"http:\/\/el-dev.com\/en\/articles\/raspberry-car-control\/\">previous article<\/a>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If everything is specified correctly in the application settings, open the \u201cServo Control\u201d screen, the connection status should change to \u201cConnected\u201d, after which you can begin controlling the model\u2019s motors. The detailed process of launching and testing the model can be seen in the video below.<\/p>\n\n\n\n<div style=\"margin:auto; text-align:center;\"><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/JR4DCSf0bqY\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"\" style=\"margin:auto;\"><\/iframe><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"choose-car-model\">Conclusions<\/h3>\n\n\n\nInsufficient battery power for powering the motors. The current power of 4.8V is insufficient to power the servo and the brushless motor. As a result, the rotational force of the brushless motor is barely enough to move the model from its place. In the next article, we will try to connect 4 more GP batteries of 1.2V in series to achieve a full 9V and install a more powerful motor.<\/p>\n\n\n\nIt is necessary to lubricate the rubbing parts. This concerns the plastic gears inside the front and rear axles, the differential, and the gearbox.<\/p>\n\n\n\nIt is necessary to print an external body to protect the electronics from dust. The shape of the body will repeat the form factor of a real truck. We will implement this in the next article.<\/p>\n\n\n\n<div style=\"display:block; height:96px;\"><figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2019\/09\/app_icon.png\" alt=\"\" class=\"wp-image-138\" style=\"float:left; margin-right:15px;\"\/><\/figure>\n\n\n\n<p>1. Android application Car Control:<\/p>\n\n\n\n<p><a href=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/CarControl_v1.1.zip\">Car Control v1.1<\/a><\/p><\/div>\n\n\n\n<div style=\"display:block;\"><p>2. 3D model from Blender and STL files of the <a href=\"http:\/\/el-dev.com\/ru\/wp-content\/uploads\/2022\/10\/3d_frame_for_electronics.zip\">electronics platform<\/a><\/p>\n\n\n\n<p>3. Project with application source code on GitHub: <a href=\"https:\/\/github.com\/NeonBurg\/CarControl\" target=\"_blank\" rel=\"noopener noreferrer\">CarControl<\/a><\/p>\n<p>4. Link to the project on the Thingiverse: <a href=\"https:\/\/www.thingiverse.com\/thing:1755011\" target=\"_blank\">3D printed RC truck<\/a><\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>List of equipment required for the project: Raspberry Pi 3 model A+ Logic level converter from 3.3V to 5VL298N brushless motor driverBattery 5V 2700 mAhMG995 servoBrushless motor In this article, we will consider the process of 3D printing and assembling a truck model, analyze the technical aspects and features of connecting devices for controlling electric [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":236,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,9],"tags":[],"class_list":["post-220","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-robotics"],"_links":{"self":[{"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":12,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":234,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/posts\/220\/revisions\/234"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/media\/236"}],"wp:attachment":[{"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/el-dev.com\/en\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}