Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to DIY Bluetooth Intelligent car by python

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you how python DIY Bluetooth smart car related knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

1. Experimental purpose

1. Learn the method of extending the simple Iripple O interface in the PC system.

two。 Further learn the design method of compiling data output program.

3. Learn the wiring method and working principle of Bluetooth module.

4. Learn the wiring method of L298N motor driver board module.

5. Learn the working principle of Bluetooth control car.

two。 Required components

TPYBoard board

One Bluetooth serial port module

One module of L298N motor driver board

An intelligent car chassis.

A data line

Some DuPont lines

3. Principle of Bluetooth Serial Port Module

(1) the lead-out interface includes EN,5V,GND,TX,RX,STATE, and our car only uses four RX,TX,GND,5V pins.

(2) the default baud bit of the module is 9600, the default pairing password is 1234, and the default name bit is HC-06.

(3) led indicates Bluetooth connection status, flashing means there is no Bluetooth connection, always bright means Bluetooth is connected and open port, when we use Android mobile phone software to send instructions, send instructions to TPYBoard through serial port, TPYBoard receives instructions to drive the car forward, backward, left, right or stop through the L298BN module.

In the following figure, 5V connects to VIN of TPYBoard, GND is ground wire, TX connects RX of TPYBoard (this is using TPYBoard serial port 2 Magi X3 Magi X4), that is, X4 Magi RX connects TX with TPYBoard, that is X3.

4. Learn the wiring method of L298N motor driver board module

This module is a 2-way H-bridge drive, so it can drive two motors at the same time. After the ENA ENB is enabled as shown in the figure, the speed and direction of the motor 1 can be driven by the PWM signal input from the IN1 IN2, and the speed and direction of the motor 2 can be driven by the PWM signal from the IN3 IN4. We connect the OUT1 and OUT2 of the motor 1 interface with the positive and negative electrodes of one motor of the car, and connect the OUT3 and OUT2 of the motor 2 interface with the positive and negative electrodes of the other motor of the car. Then connect the terminals on both sides, that is, the power supply positive terminal (the middle terminal is grounded) to the VIN of TPYboard, and the middle terminal is grounded. The GND,In1-In4 connecting TPYBoard is connected to TPYBoard's Y1Magi Y2mY3Magi Y4, which controls the rotation of the motor through the high and low levels of Y1Mague Y2 and Y3Magi Y4, so that the car can move forward, backward, left and right.

After wiring the ok, write main.py, power up the TOYBoard and ok it. Here is the source code.

5. source code

Import pybfrom pyb import UARTfrom pyb import PinM2 = Pin ('X3cycles, Pin.IN) M3 = Pin (' X4legs, Pin.IN) N1 = Pin ('Y1mm, Pin.OUT_PP) N2 = Pin (' Y2cycles, Pin.OUT_PP) N3 = Pin ('Y3cycles, Pin.OUT_PP) N4 = Pin (' Y4miles, Pin.OUT_PP) U2 = UART (2) 9600) while True: pyb.LED (2). On () pyb.LED (3). On () pyb.LED (4). On () _ dataRead=u2.readall () if _ dataReadsheets none: # stop (read the instructions sent by the APP from the phone Different software instructions may be different and can be set by yourself, which is the default here. Same below) if (_ dataRead.find (b'\ xa5Z\ X04\ xb1\ xb5\ xaa') >-1): print ('stop') N1.low () N2.low () N3.low () N4.low () # left elif (_ dataRead.find (b'\ xa5Z\ X04\ xb4\ xb8\ xaa') ) >-1): print ('left') N1.low () N2.high () N3.high () N4.low () # right elif (_ dataRead.find (b'\ xa5Z\ X04\ xb6\ xba\ xaa') >-1): print ('right') N1.high () N2.low () N3.low () N4.high () # back elif (_ dataRead.find (b'\ xa5Z\ X04\ xb5\ xb9\ xaa') >-1): print ('back') N2.high () N1.low () N4.high () N3.low () # forward elif (_ dataRead.find (b'\ xa5Z\ X04\ xb2\ xb6\ xaa') >-1): print ('go') N1.high () N2.low () N3.high () N4.low () above is all the content of the article "python how to DIY Bluetooth Smart car" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report