MicroPython TPYBoard v102 wireless infrared remote steering gear (Infrared Solutions / coding module)

Reproduced please specify the source of the article, more tutorials can self-refer docs.tpyboard.com, QQ technical exchange group: 157 816 561, the public number: MicroPython player sinks

IR decoding / encoding module Introduction

Equipped with a infrared receiver, an infrared transmitter, and the encoding chip module. The main function:

1, with the infrared transmitter function.

2, with infrared encoding.

3, with the first infrared transmitter expansion interface.

4, includes a serial communication function, the communication levels are TTL.

5, the device can control the infrared format, including a television, fans and other electrical and electronic equipment.

6, support for encoding chips

7, can be used as an infrared wireless data communication, data transmission, control and other functions IR

The module is very simple to use, only need to have basic knowledge of microcontroller TTL serial communication can be. The serial port module and Development Board, and controls the transmission module transmits instruction through the specified serial port; infrared decoding operation through the serial port receive mode, the remote control acquires the encoded information.

decoding

Need to send any instruction decoding, only the remote control receiver need to pick up the alignment module a key is pressed, then the output of the infrared serial port module will encode the key value to the boards, the boards just read in the serial port take data for analysis which will come to a pressed key.

Encoding (transmitting)

Needs to be transmitted according to a certain encoding format instructions, transmits five-byte instruction via the serial port, it may correspond to coded infrared signal transmitted. This transceiver functions use infrared, we can do infrared data transmission and control, using two transceivers can complete the operation.

IR decoding / encoding module relevant information download 


This tutorial only to learn decoding. Development board to write a program to read the serial port, after the first look at the remote control is pressed, we can receive in the end what kind of data. Here, we choose boards UART3 (TX-Y9, RX-Y10).

Wiring Diagram

TPYBoard v102 Infrared Solutions / coding module
WINE 5V
Y10 TXD
Y9 RXD
GND GND

 

 

 

 

 

 

 

from pyb import UART

uart = UART(3,9600,timeout=50)

while True:
    if uart.any() > 0:
        print(uart.read())

 

Run the program to save, open PuTTY tool, the first key press CH- upper left corner of the remote control.

PuTTY print:

b'\x00\xffE'

When micropython for serial read, return type is bytes, an immutable sequence, with a similar string. Returned 3 bytes of content, more than a few keys you will find, in front of two bytes of user code is fixed, which means that as long as we judge the first three bytes can find the corresponding key. bytes can be obtained directly through the index elements, and also supports index negative. For example, -1 is the first from the right to left, and so on. It should be noted that, when acquiring an element, he returns the corresponding decimal value.

E.g:

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

 

Huh? Why the last element E is 69 it? This is because the original is stored in bytes bytes (in binary format) data, it will convert some of the values ​​for the corresponding hexadecimal ascii characters. E corresponding decimal ascii uppercase is 69. If you take infrared codec module with a computer, serial debugging should be 00 FF 45 assistant in print.

Based on the above experience, summed up the key correspondence table, you can directly get with the program.

 Next, in conjunction with the steering gear to be examples. On the remote control with | << fast-forward key and the rewind key >> |, servo control is rotated forward and reverse direction. micropython the Servo class Reference  Click here 

TPYBoard v102 Steering gear
WINE The positive power supply (red line)
X1

A signal line (orange line)

GND Negative power supply (brown lines)

 

 

 

 

 

 

First, the steering angle is set to the state 0 by a program easy to see the placement of a small rotation of the sub-fin effect.

from PYB Import Servo 

# servo signal line connected X1, you can be created Servo 4, respectively from 1 to 4, corresponding pins - X4 is the X1 
S1 = Servo (1 )
 # to adjust the servo position rotated to an angle of 0 
s1. angle (0)

Analyzing the program of keys on increasing, each time the rotation of 15 degrees, the entire code is as follows.

from PYB Import the UART, Servo 

# servo signal line connected X1, can be created Servo 4, respectively from 1 to 4, corresponding pins - X4 is the X1 
S1 = Servo (1 )
 # to adjust the servo position rotated to an angle 0 
s1.angle (0) 

UART = the UART (3,9600, timeout = 10 ) 

DEF setServoTurn (In Flag): 
    turn_angle = s1.angle ()
     IF In Flag:
         # counter 90 increments the value of the maximum 
        turn_angle + 15 = # per press a 15 degrees turn 
        IF turn_angle <= 90 : 
            s1.angle (turn_angle) 
    the else :
         # clockwise minimum value of -90 degrees down 
        turn_angle - 15 = 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)

Download Source

 

Guess you like

Origin www.cnblogs.com/xiaowuyi/p/11491656.html
Recommended