-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.1
176 lines (144 loc) · 4.55 KB
/
serial.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
.TH serial 1 "Dec 30, 2018"
.
.
.
.SH NAME
serial \- emit remote infrared codes from a serial port adapter
.
.
.
.SH SYNOPSIS
.TP
.B serial
[\fI-d device\fP]
[\fI-a\fP]
[\fI-h\fP]
\fIprotocol\fP
\fIdevice\fP
\fIsubdevice\fP
\fIfunction\fP
[\fItimes\fP [\fIrepetitions\fP]]
.
.
.
.SH DESCRIPTION
Send infrared codes using an adapter connected to a serial port. The adapter is
made by a infrared LED, a 0.1microfarad capacitor and a 100ohm resistor,
connected between 3.3volt and TXD.
.nf
3.3volt ------ 100 ohm --+
|
|
TXD ---+-- - LED + --+
+- - 0.1uF + -+
.fi
.
.
.
.SH OPTIONS
.TP
.BI -d " device
the serial port, by default \fI/dev/ttyUSB0\fP
.TP
.B -a
allow the device to be a regular file; the default is to only accept devices
and fifos
.TP
.B -h
inline help
.TP
.B protocol
currently supported are: nec, nec2, sharp, sony20 and rc5
.TP
.B device subdevice function
the code to send; subdevice may be \fInone\fP
.TP
.B times repetitions
how many times the code is sent and then repeated (some protocols send
different signals when the key is held down, rather than raised and pressed
again); default is 0 and 1; some protocols (sony20 and rc5) require a minimum
of repetitions, but these are already done without specifying them
.
.
.
.SH SIGNAL AND TIMINGS
Each period of the carrier is generated by a serial output byte. Since the
LED is connected between Vcc and TXD (not between TXD and ground), it is on
when TXD is low. Byte 0xE0 = 11100000 produces a 50% duty cycle:
.nf
---+ +---+---+---+---+---+---+
| 0 0 0 0 0 | 1 1 1 |
+---+---+---+---+---+---+ +---
start lsb msb par stop stop
.fi
The carrier is not turned off by just not transmitting, since serial port
inactivity cannot be timed. Instead, byte 0xFF = 11111111 is sent for the
appropriate number of times:
.nf
---+ +---+---+---+---+---+---+---+---+---+---+---+
| | 1 1 1 1 1 1 1 1 |
+---+ +---
start lsb msb par stop stop
.fi
The led is on only during the start bit. The capacitor is chosen so that it
does not charge quickly enough during this isolated start bit to let the LED
start, but it does for the longer burst above.
.
.
.
.SS TIMINGS
The 38000Hz carrier frequency is obtained by 12 bits at 460800:
.IP " -" 4
period, at 38000Hz = 26.3157 microseconds
.IP " -"
baud 460800 = bit length 2.1701 microseconds
.IP " -"
12 serial bits (start+8data+parity+2stop) = 26.0412 miscroseconds
.
.
.
.SS RESISTOR AND CAPACITANCE
The 100ohm value of the resistor is calculated assuming a 3.3volt power supply,
a transmission line minimum voltage of 0volt, a LED voltage of 1.2volt and LED
current of 20mA. In order to obtain a 20mA current accross a voltage difference
of 3.3-1.2-0, the resistor value is (3.3-1.2-0)/0.020 = 105ohm.
The optimal value of the capacitance is obtained from the two following two
formulae, where Q=charge, C=capacitance, V=voltage, I=current:
.PD 0
.IP " " 4
Q = CV
.IP " "
Q = IT
.PD
.P
The voltage should go from 0volt to 1.2volt in about 3microseconds (just enough
to suppress an isolated start bit), with an average current of 27mA (using the
average is incorrect in general, but works in this case because the voltage
difference 1.2volt is small compared to the 3.3volt supply). The result is
66nF.
.SS POWER SUPPLY AND LED CHARACTERISTICS
The resistor and capacitance values are calculated based on a 3.3volt power
supply, a TXD voltage of either 3.3volt or 0volt, a 20mA LED current and a
1.2volt voltage.
The 3.3volt and 0volt voltages are typical for the power supply and the
transmission line in adapters from usb to ttl-levels uart. Other values may be
used, such as 5volt and 0volt, or 15volt and -15volt, with different values for
the resistor and capacitor. Also, a different LED current may be used.
.SH TESTING
To test the codes emitted via a serial port, \fBserial2sound\fP converts a
serial output to sound, which can be fed to \fBremote\fP(\fI1\fP):
.nf
serial2sound - | sox - -r 44100 -b 16 -t au - | remote -
serial ttySS0 # in another terminal
.fi
The argument of \fBserial2sound\fP is the sound output file, by default
\fIoutput.au\fP. This file can be converted and visualized with
\fBsox\fP(\fI1\fP) and \fBsignal2pbm\fP(\fI1\fP):
.nf
serial2sound
serial ttySS0 # in another terminal
killall serial2sound
sox output.au -r 44100 resampled.au
signal2pbm -t 4 -e 2 -i 20 -p resampled.au ; fbi output.png
remote resampled.au
.fi