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

What is the method of MicroPython infrared decoding / coding module?

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

Share

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

This article mainly introduces "what is the method of MicroPython infrared solution / coding module". In daily operation, I believe that many people have doubts about the method of MicroPython infrared solution / coding module. I have consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "what is the method of MicroPython infrared solution / coding module". Next, please follow the editor to study!

Introduction of Infrared Decoding / coding Module

The module is equipped with infrared receiver head, infrared transmitter and coding chip. Main functions:

1. It has the function of infrared emission.

2. it has the function of infrared coding.

3. Extend the interface with infrared transmitter.

4. It has serial communication function, and the communication level is TTL.

5. Controllable infrared format equipment, including televisions, fans and other electronic and electrical equipment.

6. Support coding chip

7. it can be used as infrared wireless data communication, data transmission, infrared control and other functions.

The use of this module is very simple, only need to master the basic knowledge of single-chip microcomputer TTL serial communication. The module is connected with the development board through the serial port, and the specified instructions are sent through the serial port to control the module to transmit; the infrared decoding operation is carried out through the serial port receiving mode to obtain the remote control coding information.

Decode

There is no need to send any instructions when decoding, just pick up the receiver head of the remote control and press a key, then the serial port of the module will output the infrared coding value of the key to the development board, as long as the development board reads the data from the serial port. the analysis will tell which key is pressed.

Code (transmit)

When coding, you need to send instructions according to a certain format, and send 5-byte instructions through the serial port, then the corresponding coded infrared signal can be sent out. Using this infrared transceiver function, we can do infrared data transmission and control, using 2 can complete the transceiver operation.

Download related materials of infrared decoding / coding module

Development board to write a serial port to read the program, first to see what kind of data we can receive after pressing the remote control. Here, we select the development board UART3 (TX-Y9,RX-Y10).

Wiring diagram

TPYBoard v102 Infrared Decoding / Encoding Module VIN5VY10TXDY9RXDGNDGNDfrom pyb import UARTuart = UART (3Yue9600 timeoutlining 50) while True: if uart.any () > 0: print (uart.read ())

After the program is saved, open the PuTTY tool and press the first key CH- in the upper left corner of the remote control.

PuTTY printing:

B'\ X00\ xffE'

When micropython reads the serial port, it returns the bytes type, which is an immutable sequence, similar to a string. Returned 3 bytes of content, press a few more keys, you will find that the first 2 bytes are fixed user code, that is, we only need to judge the third byte to find the corresponding key. Elements can be obtained directly through indexes in bytes, and indexes with negative numbers are also supported. For example,-1 is the first number from right to left, and so on. It is important to note here that when you get an element, it returns the corresponding decimal value.

For example:

> b = b'\ x00\ xffE' > b [1] 255 > b [- 1] 69

Huh? Why is the last element E 69? This is because what is saved in bytes is the original byte (binary format) data, which converts some hexadecimal values into corresponding ascii characters. The decimal corresponding to the uppercase E in ascii is 69. If you connect the infrared decode module with your computer, the serial port debugging assistant should print 00 FF 45.

According to the above experience, summed up the key-value correspondence table, we can directly get the program to use.

Next, combined with the steering gear to do an example. Use the "|" on the remote control to control the steering gear to rotate in the positive and negative direction. Click to view the Servo class in micropython using the reference

TPYBoard v102 steering gear VIN power supply positive (red wire) X1

Signal line (orange line)

Negative electrode of GND power supply (brown wire)

First of all, the steering gear is set to an angle of 0 through the program, and a small fin is installed to facilitate the viewing of the rotation effect.

The from pyb import Servo# steering gear signal line is connected to X1, and four Servo can be created, respectively. The corresponding pin is X1~X4s1 = Servo (1) # adjust the position of the steering gear to 0 angle s1.angle (0)

The program increases the judgment of the key, each time it rotates 15 degrees, the overall code is as follows.

From pyb import UART,Servo# steering gear signal is connected to X1, and four Servo can be created, which are 1x 4 respectively. The corresponding pin is X1~X4s1 = Servo (1) # adjust the steering gear rotation to 0 angle position s1.angle (0) uart = UART (3jing9600 Timeout=10) def setServoTurn (flag): turn_angle = s1.angle () if flag: # maximum counterclockwise increment 90 degrees turn_angle + = 15 # 15 degrees per press if turn_angle =-90: s1.angle (turn_angle) while True: if uart.any () > 0: val = uart.read () [- 1] if val = 68: setServoTurn (True) elif val = = 64: setServoTurn (False) so far The study on "what is the method of MicroPython infrared solution / coding module" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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