[Detailed examples] Micropython plug-in programming combat: DIY A thinking of the barrier car

Source: Internet
Author: User

(please indicate the source of the article, more tutorials can self-reference Www.tpyboard.com,QQ Technology Exchange Group: 157816561, public number: Micropython player)

In daily life, people will often see a variety of remote control cars, it needs our artificial operation, control its forward, backward and turn. Today, we will take you to a different new friend-the "thinking car that can be considered." "Can think of the obstacle-avoidance car" and our usual remote control car The main difference is the intelligent, it can not need us to control, we can walk. It also detects if there are any obstructions in front of you and whether you want to move forward or turn. See here, is not already eager to do it. Speak not more, move your hands!


first, the required equipment:

1, Turnipbit Development Board 1 (TB can buy)
2. Download Data cable 1
3, Intelligent Car Kit 1 sets (chassis, wheels, motors, etc.)
4, Ultrasonic module (HC-SR04) 1 (used as a car "eyes")
5, l298n Motor Drive module One
6, Internet access to the computer 1 (recommended to use Google Chome or Firefox browser)

Second, the Assembly of the wall barrier car

The first step, the car bottom, fasteners, the code plate of the yellow protective paper torn off, and then the fastener into the car floor.



The second step is to install the code tray and secure the motor to the baseplate. The large side of the plate axis is small and the large side is inserted into the motor shaft (note: The motor leads the copper sheet toward the inside, that is, one end of the code tray).

In the third step, insert the screw, fasten the motor to the bottom of the trolley and tighten the nut.

Fourth step, insert the screws and secure the battery compartment. This step of the experiment can be omitted, we use the charger to power.

Fifth step, put the copper pillar, tighten the 8 screws to fix the universal wheel, hand hold the motor (protect the fastener), and insert the wheel inside, assembly completed.

Finally, let's take a look at the finished assembly.

Three, motor drive and ultrasonic installation

The connection of the hardware is mainly the connection between each pin. For details (see table below): The ultrasonic module has a total of 4 pins, VCC, GND, Trig, and Echo respectively. The VCC pin of the Turnipbit expansion board is connected to the GND pin of the Turnipbit expansion board, and the Trig trigger pin is connected to the P5,echo backhaul pin P8. l298n Motor Drive Module The left OUT3 and OUT4 terminals correspond to the lower side of the revolver motor, the upper side of the copper plate, and the right side. l298n input IN1, IN2, IN3, IN4 respectively access the expansion board P19, P13, P12, P11. Finally, the experiment uses the charging treasure to power supply, simply connect the charging board via USB cable to the microUSB port of the Turnipbit Development Board.


four, plug programming


Step 1: Because P11 and P12 control a wheel, P13 and P19 control a wheel, only need to give the corresponding wheel P12 and P19 high level, the other two pins low gaoping, obstacle avoidance car two wheels will turn, if the rotation direction two wheels are different or backward, Note that you do not pay attention to the connection of the l298n pin, only need to switch, the car will move forward, such as.



Step 2: Add a dead loop to keep the program running.



Step 3: Next you need to complete the detection of obstacles, which requires the ultrasonic module to achieve. We need to add the content of the obstacle detection in the dead loop, so that the obstacle-avoidance vehicle constantly detects the distance from the front obstacle.


Step 4: For a simpler, easier and faster implementation of the function, we use a count of the way to measure a approximate distance, and then to determine whether to avoid the barrier. The attentive classmate may find that we have defined a num variable at the beginning of the program, and we use NUM to count it. When Pin 8 is high, the echo of the ultrasonic module is entered in the receiving mode, we constantly let num self-add 1, until the ultrasonic module received the return signal, that is, pin 8 is low, stop counting. Num here can reflect the current distance between the car and the obstacle. This test is conducted at a safe distance of 25 centimeters, and the number of NUM is found to be 8. As a result, if the distance between the car and the obstacle is less than 25 cm, Num is less than 8. Therefore, the program determines that if Num's value is less than or equal to 8 o'clock, it will be turned to avoid obstacles.


Step 5: To this, the thinking of the disabled car has been completed. In order to make the car more cool, we can use the LED screen to dynamically display the direction of the current obstacle-avoidance vehicle driving. The method is to use the arrows to show the direction of the steering before making the steering movement, then do the action.

Step 6: Change the program name to Turnipbit-car and click the "Download Hex" button to save the program to your computer. Drag the saved Turnipbit-car.hex file into the turnipbit disk and we'll see the lights on the Turnipbit board flashing, indicating that they are being downloaded to the dashboard. After the download is successful, insert the turnipbit into the Turnipbit expansion board slot and start the barrier-free car.


(please indicate the source of the article, more tutorials can self-reference Www.tpyboard.com,QQ Technology Exchange Group: 157816561, public number: Micropython player)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.