Micropython Tpyboard Control Wireless Acceleration Trolley

Source: Internet
Author: User

Now wireless control has become the mainstream of the field of electronic science, this time to teach you to do a mainstream mainstream-wireless control of the car, first to show you the final product demo Video:

://v.youku.com/v_show/id_xmty2mzazndazng==.html?spm=a2h0k.8191407.0.0&from=s1.8-1-1.2

first, introduce the materials you need to use.:

TPYBoardv102 Development Board two pieces
Car Chassis One
Lora Wireless module two pieces
Rechargeable Treasure One
90,143 Pole Tube Two (why do you use it, back again).

there is one and a speed sensor on the board, and I saw an accelerometer on the board to remember to do it, here we introduce the accelerometer.

an accelerometer, comprising a silicon diaphragm, a top cover, a lower cover, a diaphragm located between the upper cover and the lower cover, is bonded together; one-dimensional or two-dimensional nanomaterials, gold electrodes and lead wires are distributed on the diaphragm, and the wire is drawn by the pressure welding process; the industrial field vibration sensor is mainly piezoelectric accelerometer. Its working principle is mainly advantageous to the piezoelectric sensitive element's piezoelectric effect obtains the charge quantity or the voltage quantity which is proportional to the vibration or the pressure. At present, the industrial field is typical of the Iepe accelerometer, and the built-in IC circuit piezoelectric accelerometer, the sensor output and vibration is directly proportional to the voltage signal, for example: 100mv/g (each acceleration unit output 100mV voltage value. 1G=9.81M/S-2).

Did you not read the introduction? Do not understand also does not matter, that is I refer to the official introduction to write, actually I also can not understand. In fact, in layman's terms, the accelerometer is measured by the acceleration caused by gravity, and you can calculate the tilt angle of the device relative to the horizontal plane. By analyzing the dynamic acceleration, you can analyze how the device moves. Do you still not know how to get this tilted value? That's okay, our Python language has a function to get this tilt value, and it's OK to use it directly. However, it is worth noting that this function returns the gradient is a value, each sensor because of the difference in workmanship, the return value is different, this need to do their own experiments to see.

get the Tilt value, the following work is simple, that is to judge the board in how to tilt, and then the tilt signal out, so OK, properly.

After the introduction of this control, let's talk about how to get the control signal out. Here is the main use of the Lora module, this module is still very popular. I personally went to do a transmission distance experiment, the specific distance I did not test, but I feel at least also have to have a two or three miles, this distance for a car to be done properly enough.

talk about the use of Lora module, Lora module use it, is also very simple, serial communication, wireless transmission. That is to say you use SCM through the serial port to module what, the module will give you to transmit what (fixed point need to bring the address channel), this Lora module description is very detailed. But do you feel that you have to use the serial port, feel good trouble? I also feel the trouble, but the Python language and the function of the Development Board is very powerful, there is a good way to write the use of the serial port, the direct call can be (instantaneous feeling development is simple).

The above describes the control side of the work and principle, the following is said to be controlled (just press on the car).

the control is to use the Development Board to control the car site motor rotation, where I was a pit, I bought this car in a treasure, asked the customer service need not other things, customer service said no. I feel now even the motor drive is not necessary, feel good high-end, but buy back to find still need a l298n drive. Momentary feeling was cheated, but, at the same time, my grief and indignation, my two 9014 played, simply made a transistor switch circuit, the completion of the (albeit slightly slow).

The signal Reception section, which is similar to the control side, uses the Lora module and then makes a judgment on the data received. After judging and then according to their own logic to drive the motor, the car will open up (how to turn the car I do not introduce, online tutorials a lot more).

The above said so much, in fact, is also very abstract, below a gathering elephant,.

Make a simple schematic diagram of your own drawing first.

Controller

controlled End


These two graphs are I draw to help you understand (I do this by the controlled side of the circuit, the speed is slightly slower. We can be in the drive there to make a amplification circuit, speed can go up, but can not back, we can directly use the l298n drive. ), I do when the use of the DuPont line, and no circuit diagram, and then a finished picture to everyone

finished drawings


These are for everyone's reference, when we do more study more to see, firsthand experience can really learn things.

The following procedure for everyone, we can refer to.

Source code of the control terminal:

[Code]import Pyb
Xlights = (Pyb. LED (2), Pyb. LED (3))
Ylights = (Pyb. LED (1), Pyb. LED (4))
From PYB import UART
From PYB import Pin
#from ubinascii Import hexlify
From UBINASCII Import *
Accel = Pyb. Accel ()
U2 = UART (2, 9600)
I=0
K=1

[/code]
******************************* Main program **********************************

[Code] Print (' while ')
while (k>0):
_dataread=u2.readall ()
if (1>0):
x = accel.x ()
Print ("x=")
Print (x)
If x > 10:
Xlights[0].on ()
Xlights[1].off ()
U2.write (' \x00\x05\x18you ')
#pyb. Delay (1000)
Print (' \x00\x01\x18you ')
Elif x <-10:
Xlights[1].on ()
Xlights[0].off ()
U2.write (' \x00\x05\x18zuo ')
Print (' \x00\x01\x18zuo ')
#pyb. Delay (1000)
Else
Xlights[0].off ()
Xlights[1].off ()
y = Accel.y ()
Print ("y=")
Print (y)
If y > 15:
Ylights[0].on ()
Ylights[1].off ()
#u2. Write (' \x00\x05\x18hou ')
#pyb. Delay (1000)
#print (' \x00\x01\x18hou ')
Elif y <-15:
Ylights[1].on ()
Ylights[0].off ()
U2.write (' \x00\x05\x18qian ')
#pyb. Delay (1000)
Print (' \x00\x01\x18qian ')
Else
Ylights[0].off ()
Ylights[1].off ()
Pyb.delay (10)

[/code]
Source code of the controlled side:

[Code]import Pyb
From PYB import UART
From PYB import Pin
From UBINASCII import hexlify
From UBINASCII Import *
M1 = Pin (' X1 ', pin.out_pp)
M3 = Pin (' Y1 ', pin.out_pp)
U2 = UART (2, 9600)
I=0
K=1

[/code]
******************************* Main program **********************************

[Code]print (' while ')
while (k>0):
M1.high ()
Pyb.delay (3)
M3.high ()
if (U2.any () >0):
Print (' 1234 ')
M1.low ()
M3.low ()
Pyb.delay (3)
_dataread=u2.readall ()
Print (' 123 ', _dataread)
if (_dataread.find (b ' QIAN ') >-1):
M1.low ()
M3.low ()
Print (' QIAN ')
Pyb.delay (250)
Elif (_dataread.find (b ' ZUO ') >-1):
M1.low ()
M3.high ()
Print (' ZUO ')
Pyb.delay (250)
Elif (_dataread.find (b ' you ') >-1):
M1.high ()
M3.low ()
Print (' ZUO ')
Pyb.delay (+)

[/code]

Micropython Tpyboard Control wireless Acceleration Trolley

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.