├── LICENSE
├── PCB
├── Gerber_PCB_Arduino_transmitter_V0.9_2022-01-06.zip
└── Readme.md
├── PPMtoCRSF
├── PPMtoCRSF.ino
└── Readme.md
├── README.md
├── STL
├── Front_Shell_REV-A_M7_kkbin_modify.stl
├── Front_Shell_REV-A_M7_kkbin_modify_gimbal Cover v2.stl
├── Readme.md
├── SimpleTX_Battery_Bay v15.stl
├── SimpleTX_Buttom Frsky_X9Lite_S.stl
├── SimpleTX_Buttom v15.stl
├── SimpleTX_Top_Frsky_X9Lite_S.stl
├── SimpleTX_Top_v15.stl
├── SimpleTX_V2_Back.stl
├── SimpleTX_V2_Battery_Cover.stl
└── SimpleTX_V2_Front.stl
└── SimpleTX
├── .vscode
├── arduino.json
└── c_cpp_properties.json
├── NonBlockingRtttl.cpp
├── NonBlockingRtttl.h
├── SimpleTX.ino
├── config.h
├── crsf.cpp
├── crsf.h
├── led.h
└── tone.h
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/PCB/Gerber_PCB_Arduino_transmitter_V0.9_2022-01-06.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/PCB/Gerber_PCB_Arduino_transmitter_V0.9_2022-01-06.zip
--------------------------------------------------------------------------------
/PCB/Readme.md:
--------------------------------------------------------------------------------
1 | Add PCB V0.9
2 |
3 | BOM :
4 | 1. Frsky M7 Gimbal *2
5 | 2. Arduino Nano
6 | 3. XH2.54 3P *6
7 | 4. PH2.0 2P
8 | 5. 1.25 6P
9 | 6. 2 Position Switch *5
10 | 7. LED *1
11 | 8. 100 ohm resister
12 | 9. 10K 0805 resister
13 | 10. 20K 0805 resister
14 | 11. UFL to SMA connector
15 | 12. 2.4G SMA antenna
16 | 13. ExpressLRS 2.4G TX module
17 | 14. 2S battery
18 | 15. PCB https://oshwlab.com/kkbinmail/arduino_transmitter
19 |
20 | Build order:
21 |
22 | 1. Print shell from:https://github.com/cruwaller/elrs_handset/tree/master/revision_A/shell
23 | 2. Order PCB from JLB PCB
24 | 3. Sold 10K and 20K resiter to PCB
25 | 4. Sold 1.25 6P male header
26 | 5. Sold Arduino Nano
27 | 6. Sold XH2.45 (Double check the pole of the battery header, make sure ground is to ground)
28 | 7. Sold PH2.0
29 | 8. Down load firmware
30 | 9. Build and Flash to Arduino Nano with IDE
31 | 10. Flash TX module use ExpressLRS un-check UART_INVERTOR & OpenTX_SYNC
32 | 11. Assemble switch to shell
33 | 12. Assemble M7 Gimbal
34 | 13. Assemble SMA connector
35 | 14. Connect everything
36 |
37 |
38 |
39 |
40 |
41 | 
42 |
43 | 
44 |
--------------------------------------------------------------------------------
/PPMtoCRSF/PPMtoCRSF.ino:
--------------------------------------------------------------------------------
1 | /*
2 | -------------------------------------------------------------------------
3 | Simple Arduino trasmisster (PPM to ELRS)
4 | Decode PPM to CRSF protocol
5 | Arduino Nano
6 | ELRS 2.4G TX moduel
7 | Custom PCB from JLCPCB
8 | https://github.com/kkbin505/Arduino-Transmitter-for-ELRS
9 | * This file is part of Simple TX
10 | *
11 | * Simple TX is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * Simple TX is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with Cleanflight. If not, see .
23 | */
24 |
25 | //Use this lib https://github.com/DzikuVx/PPMReader
26 | #include "PPMReader.h"
27 | //Setup ppm read on pin 2,
28 |
29 | PPMReader ppmReader(2, 0, false);
30 |
31 | byte channelAmount = 8;
32 |
33 | //default channel order is AETR
34 | #define TAER
35 |
36 | #define RADIO_ADDRESS 0xEA
37 | #define ADDR_MODULE 0xEE // Crossfire transmitter
38 | #define TYPE_CHANNELS 0x16
39 |
40 | // internal crsf variables
41 | #define CRSF_CHANNEL_MIN 172
42 | #define CRSF_CHANNEL_MID 991
43 | #define CRSF_CHANNEL_MAX 1811
44 | #define CRSF_TIME_NEEDED_PER_FRAME_US 1100 // 700 ms + 400 ms for potential ad-hoc request
45 | #define CRSF_TIME_BETWEEN_FRAMES_US 4000 // 4 ms 250Hz
46 | #define CRSF_PAYLOAD_OFFSET offsetof(crsfFrameDef_t, type)
47 | #define CRSF_MAX_CHANNEL 16
48 | #define CRSF_FRAME_SIZE_MAX 64
49 | #define SERIAL_BAUDRATE 400000
50 | #define CRSF_MSP_RX_BUF_SIZE 128
51 | #define CRSF_MSP_TX_BUF_SIZE 128
52 | #define CRSF_PAYLOAD_SIZE_MAX 60
53 | #define CRSF_PACKET_LENGTH 22
54 | #define CRSF_PACKET_SIZE 26
55 | #define CRSF_FRAME_LENGTH 24; // length of type + payload + crc
56 |
57 | uint8_t crsfPacket[CRSF_PACKET_SIZE];
58 | int rcChannels[CRSF_MAX_CHANNEL];
59 | uint32_t crsfTime = 0;
60 |
61 | #ifdef TAER
62 | enum chan_order{
63 | THROTTLE,
64 | AILERON,
65 | ELEVATOR,
66 | RUDDER,
67 | AUX1, // (CH5) ARM switch for Expresslrs
68 | AUX2, // (CH6) angel / airmode change
69 | AUX3, // (CH7) flip after crash
70 | AUX4, // (CH8)
71 | AUX5, // (CH9)
72 | AUX6, // (CH10)
73 | AUX7, // (CH11)
74 | AUX8, // (CH12)
75 | };
76 | #else
77 | enum chan_order{
78 | AILERON,
79 | ELEVATOR,
80 | THROTTLE,
81 | RUDDER,
82 | AUX1, // (CH5) ARM switch for Expresslrs
83 | AUX2, // (CH6) angel / airmode change
84 | AUX3, // (CH7) flip after crash
85 | AUX4, // (CH8)
86 | AUX5, // (CH9)
87 | AUX6, // (CH10)
88 | AUX7, // (CH11)
89 | AUX8, // (CH12)
90 | };
91 | #endif
92 |
93 | void setup()
94 | {
95 | /*
96 | TCCR1A = 0; //reset timer1
97 | TCCR1B = 0;
98 | TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us or 1us on 8MHz
99 | */
100 | for (uint8_t i = 0; i < CRSF_MAX_CHANNEL; i++) {
101 | rcChannels[i] = CRSF_CHANNEL_MID;
102 | }
103 | rcChannels[THROTTLE] = CRSF_CHANNEL_MIN; // Throttle
104 |
105 | delay(1000);
106 | Serial.begin(SERIAL_BAUDRATE);
107 |
108 | //Serial.begin(115200);
109 | //Serial.println("ready");
110 | }
111 |
112 | void loop()
113 | {
114 | uint32_t currentMicros = micros();
115 |
116 | if(ppmReader.isReceiving()==true){
117 | int count;
118 | while(ppmReader.get(count) != 0){ //print out the servo values
119 | int value = ppmReader.get(count);;
120 | rcChannels[count]=map(value,1000,2000,CRSF_CHANNEL_MIN,CRSF_CHANNEL_MAX);
121 | //Serial.print(ppmReader.get(count));
122 | //Serial.print(" ");
123 | count++;
124 | }
125 | }
126 | //set fail safe value
127 | else{
128 | rcChannels[THROTTLE] = CRSF_CHANNEL_MIN; //
129 | rcChannels[AILERON] = CRSF_CHANNEL_MID; //
130 | rcChannels[ELEVATOR] = CRSF_CHANNEL_MID; //
131 | rcChannels[RUDDER] = CRSF_CHANNEL_MID; //
132 | rcChannels[AUX1] = CRSF_CHANNEL_MIN; // ARM Low
133 | }
134 |
135 | if (currentMicros > crsfTime) {
136 | crsfPreparePacket(crsfPacket, rcChannels);
137 | Serial.write(crsfPacket, CRSF_PACKET_SIZE);
138 | crsfTime = currentMicros + CRSF_TIME_BETWEEN_FRAMES_US;
139 | }
140 |
141 | }
142 |
143 | // crc implementation from CRSF protocol document rev7
144 | static u8 crsf_crc8tab[256] = {
145 | 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
146 | 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
147 | 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
148 | 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
149 | 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
150 | 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
151 | 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
152 | 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
153 | 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
154 | 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
155 | 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
156 | 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
157 | 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
158 | 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
159 | 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
160 | 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9};
161 |
162 | u8 crsf_crc8(const u8 *ptr, u8 len) {
163 | u8 crc = 0;
164 | for (u8 i=0; i < len; i++) {
165 | crc = crsf_crc8tab[crc ^ *ptr++];
166 | }
167 | return crc;
168 | }
169 |
170 | void crsfPreparePacket(uint8_t packet[], int channels[]){
171 |
172 | static int output[CRSF_MAX_CHANNEL] = {0};
173 | const uint8_t crc = crsf_crc8(&packet[2], CRSF_PACKET_SIZE-3);
174 | /*
175 | * Map 1000-2000 with middle at 1500 chanel values to
176 | * 173-1811 with middle at 992 S.BUS protocol requires
177 | */
178 | for (uint8_t i = 0; i < CRSF_MAX_CHANNEL; i++) {
179 | output[i] = channels[i];
180 | }
181 | /*
182 | Serial.print("crsf ");
183 | Serial.print(output[0]);
184 | Serial.print(" i");
185 | Serial.print(output[1]);
186 | Serial.print(" i");
187 | Serial.print(output[2]);
188 | Serial.print(" i");
189 | Serial.print(output[3]);
190 | Serial.println(); */
191 |
192 | // packet[0] = UART_SYNC; //Header
193 | packet[0] = ADDR_MODULE; //Header
194 | packet[1] = 24; // length of type (24) + payload + crc
195 | packet[2] = TYPE_CHANNELS;
196 | packet[3] = (uint8_t) (channels[0] & 0x07FF);
197 | packet[4] = (uint8_t) ((channels[0] & 0x07FF)>>8 | (channels[1] & 0x07FF)<<3);
198 | packet[5] = (uint8_t) ((channels[1] & 0x07FF)>>5 | (channels[2] & 0x07FF)<<6);
199 | packet[6] = (uint8_t) ((channels[2] & 0x07FF)>>2);
200 | packet[7] = (uint8_t) ((channels[2] & 0x07FF)>>10 | (channels[3] & 0x07FF)<<1);
201 | packet[8] = (uint8_t) ((channels[3] & 0x07FF)>>7 | (channels[4] & 0x07FF)<<4);
202 | packet[9] = (uint8_t) ((channels[4] & 0x07FF)>>4 | (channels[5] & 0x07FF)<<7);
203 | packet[10] = (uint8_t) ((channels[5] & 0x07FF)>>1);
204 | packet[11] = (uint8_t) ((channels[5] & 0x07FF)>>9 | (channels[6] & 0x07FF)<<2);
205 | packet[12] = (uint8_t) ((channels[6] & 0x07FF)>>6 | (channels[7] & 0x07FF)<<5);
206 | packet[13] = (uint8_t) ((channels[7] & 0x07FF)>>3);
207 | packet[14] = (uint8_t) ((channels[8] & 0x07FF));
208 | packet[15] = (uint8_t) ((channels[8] & 0x07FF)>>8 | (channels[9] & 0x07FF)<<3);
209 | packet[16] = (uint8_t) ((channels[9] & 0x07FF)>>5 | (channels[10] & 0x07FF)<<6);
210 | packet[17] = (uint8_t) ((channels[10] & 0x07FF)>>2);
211 | packet[18] = (uint8_t) ((channels[10] & 0x07FF)>>10 | (channels[11] & 0x07FF)<<1);
212 | packet[19] = (uint8_t) ((channels[11] & 0x07FF)>>7 | (channels[12] & 0x07FF)<<4);
213 | packet[20] = (uint8_t) ((channels[12] & 0x07FF)>>4 | (channels[13] & 0x07FF)<<7);
214 | packet[21] = (uint8_t) ((channels[13] & 0x07FF)>>1);
215 | packet[22] = (uint8_t) ((channels[13] & 0x07FF)>>9 | (channels[14] & 0x07FF)<<2);
216 | packet[23] = (uint8_t) ((channels[14] & 0x07FF)>>6 | (channels[15] & 0x07FF)<<5);
217 | packet[24] = (uint8_t) ((channels[15] & 0x07FF)>>3);
218 |
219 | packet[25] = crsf_crc8(&packet[2], CRSF_PACKET_SIZE-3); //CRC
220 |
221 |
222 | }
223 |
--------------------------------------------------------------------------------
/PPMtoCRSF/Readme.md:
--------------------------------------------------------------------------------
1 | PPM to ELRS conveter
2 |
3 | Use simpleTX PCB to make a ppm to ELRS converter
4 |
5 | Plug PPM to D2 (switch 4 in pcb) and GND
6 |
7 | This code is highly expermental, and unstable.
8 |
9 | Make sure your transmitter output ppm correctly, otherwise the TX will receive noise singal, and transmit unexpected singal.
10 |
11 | Use this arduino library:
12 |
13 | https://github.com/DzikuVx/PPMReader
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Simple TX
2 |
3 | 现已增加中文介绍,详情请看Wiki页面
4 |
5 | This is an Arduino based RC transmitter TX. I want to design a RC transmitter (soft and hardware) that is simple to build, and use arduino board wich I am familler with, and it should supoort ELRS.
6 |
7 | 
8 |
9 |
10 | video:
11 |
12 | https://www.youtube.com/watch?v=BPLFkZUoV28
13 |
14 | # Features:
15 | - Support ExpressLRS 2.4G external TX module
16 | - Up to 500Hz packet rate
17 | - 4 analog channel
18 | - 4 AUX channel
19 |
20 | This project includes code, stl file for transmitter shell and pcb board, you can easily diy your own rc transmitter from arduino development board in a very simple way.
21 |
22 | I have tested for 6 month since the first prototype (mod from an old Devo7), it works pretty well.
23 |
24 | * Simple TX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
25 |
26 | I use superslim module in the shell, but any esp32 based tx module should be working.
27 |
28 | It was tested for ELRS 1.0 and 2.0.
29 |
30 | ### Update:
31 |
32 | ### 2025/03/07 Update STL file to V2
33 |
34 | 1. Redesign battery bay
35 |
36 | 2. Add 2 additional switch postion, now support up to 10 channels (The firmware is under test)
37 |
38 | 3. Add buzzer hold
39 |
40 | This version is slight thicker then V1, because I enlarged the battery tray to support bigger batteries. And I redesigned the battery tray cover, now it is clip on.
41 |
42 | 
43 |
44 | 
45 |
46 | 
47 |
48 | 
49 |
50 |
51 |
52 | ### 2025/03/04 Release ELRS 3.0 support
53 |
54 | Merge 3.0 support to main
55 |
56 | Fix buzzer issue
57 |
58 | Change channel 6 to 3 postion AUX
59 |
60 |
61 |
62 | ### 2025/2/12 Add support for ELRS 3.0
63 | Thanks to the great work doing by dbloemhard now the SimpleTX support 3.0, I merged the update into the main branch.
64 | You can change pocket rate, power and tune on/off dynamic power by gesutre.
65 | His repo:
66 | https://github.com/dbloemhard/Arduino-Transmitter-for-ELRS3.x
67 |
68 |
69 | ### 2022/11/5 Move IDE to VSCODE and Arduino Extension
70 |
71 | Add buzzer support on pin 6
72 |
73 | The PIO becomes unusable dude to unstalbe network, so I switch back to arduino extension, still in VSCODE, because the original Arduino IDE is low efficient.
74 |
75 | The code still works in Arduino IDE, you can compile in both enviroment
76 |
77 | The PIO will be saved in a seprate branch and will unliked be updated
78 |
79 | ### 2022/6/3 Optimize Calibration
80 |
81 | 1. Add center stick calibration
82 | 2. Optimze channel reverse
83 | use 4 values to handdle reverse in config.h
84 |
85 | // Define Reverse 1 = reverse, 0 = normal
86 |
87 | Is_Aileron_Reverse =1;
88 |
89 | Is_Elevator_Reverse =1;
90 |
91 | Is_Throttle_Reverse =0;
92 |
93 | Is_Rudder_Reverse =0;
94 |
95 | ### 2022/5/29 Calibration added
96 |
97 | Calibration function added by erstec in Platformio_test_branch, thanks
98 |
99 | 1. enter debug mode by uncomment #define DEBUG
100 | 2. flash firmware to arduino nano
101 | 4. open serial monitor at 115200 baud, center stick and keep for 5 seconds
102 | 5. move stick full range within 20 seconds untill you see "Calibration Done"
103 | 6. comment //#define DEBUG and flash firmware to arduino nano
104 | 7. test in bf configurator
105 | 8. done
106 |
107 | ### 2022/4/6 Test branch
108 |
109 | platformio
110 |
111 |
112 | ### Update Log 2022/4/3
113 |
114 | Add Test branch for ppm output
115 |
116 |
117 | ### Update Log 2022/3/26
118 |
119 | Update STL File:
120 |
121 | Solve gimbal & switch interference
122 |
123 | Add battery tray
124 |
125 | 
126 |
127 |
128 |
129 | ### Update Log 2022/3/20
130 |
131 |
132 |
133 | Update PPM to ELRS library, siginal is more stable, still need more test
134 |
135 |
136 | https://github.com/kkbin505/Arduino-Transmitter-for-ELRS/tree/main/PPMtoCRSF
137 |
138 |
139 |
140 | ### Update Log V0.9.3
141 | Increase baud rate to 400K
142 |
143 | *** In 400k baud, theoretical maxmum packet rate is 500Hz (400000/320bit per second, 1.6ms per frame). RC data pcket is 32byte=320bit(plus 1 start bit and 1 end bit).
144 |
145 | Now simpleTX is supporting 500Hz
146 |
147 | Add 3rd pre seeting for 500Hz 25mW
148 |
149 | Gestrue:
150 | Hold AILERON left and ELEVATOR up at power up.
151 |
152 | ### Update Log V0.9.2
153 | Update cmd to elrs 2.0 (power setting commond of 2.0 is different from 1.0)
154 |
155 | Re write gimbal calibation method, add center stick offset in config file
156 |
157 |
158 | ### Update Log V0.9.1
159 | Add 2 pre settings for power and package rate:
160 |
161 |
162 | Now you can enter setting 1 and 2 by gesutre:
163 |
164 | Setting 1:
165 | //250Hz 25mW
166 |
167 | Hold AILERON left and ELEVATOR down at power up.
168 |
169 | Setting 2:
170 | //150Hz 100mW
171 |
172 | Hold AILERON right and ELEVATOR up at power up.
173 |
174 | Center stick will keep your previous setting.
175 |
176 |
177 | Due to the hardware limitation of the ATMega328p, the follow functions are not supported:
178 |
179 | * The 328p do not support inverted UART (which OpenTX use), there are 2 options:
180 | 1. Tun UART_INVERTED off.
181 | 2. Adding a digital invert IC (I tested with SN74LS06N)
182 |
183 | ** Telemetray is off, 328p do not support half duplex.
184 |
185 |
186 |
187 | The uart logic voltage of ESP32 is 3.3V, my ATMega328p is 5V. However mine TX work fine, it seems ESP32 UART is 5V tolerance.
188 |
189 | #### Tips
190 | Default RC channel order is AETR, you can change channel order whatever you like, by changing the RC channel order.
191 | Current gimbal calibratin method is complex (but you need to do only once):
192 | - Enter debug mode by delete "//" before #define DEBUG
193 | - Flash with arduino IDE
194 | - Open serialmonitor change baud rate to 115200
195 | - Record max and min RC channel value and write in map() function (reverse order if neede)
196 | example:map(Aileron_value,893,223,RC_CHANNEL_MIN,RC_CHANNEL_MAX)
197 | - Add "//" back before #define DEBUG
198 | - Flash with arduino IDE
199 |
200 | There are many amazing Expreslrs handset. But I want a simple arduino based transmitter for my DIY 2.4G external TX module.
201 |
202 | https://youtu.be/PrfSfnqcBgk
203 |
204 | ### Add PCB V0.9
205 |
206 |
207 | I replace the control board with my PCB and system.
208 |
209 |
210 | 
211 |
212 |
213 | ### 1. Project Intro:
214 |
215 | ### 1.1 Hardware (PCB)
216 |
217 | In PCB folder, you can find the PCB and BOM, the PCB is designed in Easyeda and files in Gerber type. I orderd my PCB use the Gerber file from JLCpcb.
218 |
219 | 
220 |
221 | The PCB is v0.9 means it is not complete, but it works well at least for me.
222 |
223 | The version includes 4 digital switch, but I forget to wire out the LED pint, so I use one channel for LED only 3 digital available.
224 |
225 | The analogy channel support 3.3v gimbal (hall and poentional meter both works), the pin use 1.25 6p plug, it is the same pin order as most frsky gimbal (M7 for example). If you use orther gimbal pay attention to the pin order. I find jumper gimbal reversed GND(red) and 3.3V(black).
226 |
227 | I powered my board with 2S battery, the arduino nano have a decent LDO (ASM1117), and the ELRS module also powerd from 2S.
228 |
229 | ### 1.2 Firmware
230 |
231 | All source codes are in SimpleTX folder.
232 |
233 | It is writen in arduino frame use VScode, but arduino IDE should also work.
234 |
235 | ### 1.3 CAD-Model
236 |
237 | 3 versions of transmitter shell are available.
238 |
239 | 1 is a remix from https://github.com/cruwaller/elrs_handset
240 |
241 | 
242 |
243 | I removed 2 switch, and modify switch in front side from Switches to Tango2 like switch
244 |
245 | 
246 |
247 | Front_Shell_REV-A_M7_kkbin_modify.stl
248 |
249 | 2 is my design, it is compatibal with jumper TX 12 hall gimbal, very compact.
250 |
251 | 
252 |
253 |
254 | SimpleTX_Top_v15.stl
255 |
256 | 3 is for X9 lite gimbal, it feels too big for me.
257 |
258 |
259 | !!! Do not solder the buzzer, need to add triode in next version, I burned my board.
260 | 
261 |
262 |
263 | This Transmitter is inspired by cruwallero:
264 | https://github.com/cruwaller/elrs_handset
265 |
266 | Some code are based on Pawel's amazing work on SBUS generate code.
267 |
268 | https://quadmeup.com/generate-s-bus-with-arduino-in-a-simple-way/
269 |
--------------------------------------------------------------------------------
/STL/Front_Shell_REV-A_M7_kkbin_modify.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/Front_Shell_REV-A_M7_kkbin_modify.stl
--------------------------------------------------------------------------------
/STL/Front_Shell_REV-A_M7_kkbin_modify_gimbal Cover v2.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/Front_Shell_REV-A_M7_kkbin_modify_gimbal Cover v2.stl
--------------------------------------------------------------------------------
/STL/Readme.md:
--------------------------------------------------------------------------------
1 | Add STL file for print
2 |
3 | 
4 |
5 |
6 | 
7 |
8 |
9 | Add a modify file from: https://github.com/cruwaller/elrs_handset/tree/master/revision_A/shell
10 |
11 | Delete 2 top side switchs, modify front side switch to rectangle 19*7mm switch, give this design more tango2 kind of taste
12 |
13 | Add gimbal protect for M7, print in TPU 20%
14 |
15 | Add a open on the lower side for usb
16 |
17 |
--------------------------------------------------------------------------------
/STL/SimpleTX_Battery_Bay v15.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/SimpleTX_Battery_Bay v15.stl
--------------------------------------------------------------------------------
/STL/SimpleTX_Buttom v15.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/SimpleTX_Buttom v15.stl
--------------------------------------------------------------------------------
/STL/SimpleTX_Top_v15.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/SimpleTX_Top_v15.stl
--------------------------------------------------------------------------------
/STL/SimpleTX_V2_Back.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/SimpleTX_V2_Back.stl
--------------------------------------------------------------------------------
/STL/SimpleTX_V2_Battery_Cover.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/SimpleTX_V2_Battery_Cover.stl
--------------------------------------------------------------------------------
/STL/SimpleTX_V2_Front.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kkbin505/Arduino-Transmitter-for-ELRS/6c4cbdd912e15320894de9e5d142b5f3c9b14724/STL/SimpleTX_V2_Front.stl
--------------------------------------------------------------------------------
/SimpleTX/.vscode/arduino.json:
--------------------------------------------------------------------------------
1 | {
2 | "board": "arduino:avr:nano",
3 | "port": "COM4",
4 | "sketch": "SimpleTX.ino"
5 | }
--------------------------------------------------------------------------------
/SimpleTX/.vscode/c_cpp_properties.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 4,
3 | "configurations": [
4 | {
5 | "name": "Arduino",
6 | "compilerPath": "C:\\Program Files (x86)\\Arduino\\hardware\\tools\\avr\\bin\\avr-g++",
7 | "compilerArgs": [
8 | "-w",
9 | "-std=gnu++11",
10 | "-fpermissive",
11 | "-fno-exceptions",
12 | "-ffunction-sections",
13 | "-fdata-sections",
14 | "-fno-threadsafe-statics"
15 | ],
16 | "intelliSenseMode": "gcc-x64",
17 | "includePath": [
18 | "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino",
19 | "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\variants\\eightanaloginputs",
20 | "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\libraries\\EEPROM\\src",
21 | "c:\\program files (x86)\\arduino\\hardware\\tools\\avr\\lib\\gcc\\avr\\4.9.2\\include",
22 | "c:\\program files (x86)\\arduino\\hardware\\tools\\avr\\lib\\gcc\\avr\\4.9.2\\include-fixed",
23 | "c:\\program files (x86)\\arduino\\hardware\\tools\\avr\\avr\\include"
24 | ],
25 | "forcedInclude": [
26 | "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
27 | ],
28 | "cStandard": "c11",
29 | "cppStandard": "c++11",
30 | "defines": [
31 | "F_CPU=16000000L",
32 | "ARDUINO=10800",
33 | "ARDUINO_AVR_NANO",
34 | "ARDUINO_ARCH_AVR",
35 | "__DBL_MIN_EXP__=(-125)",
36 | "__HQ_FBIT__=15",
37 | "__UINT_LEAST16_MAX__=65535U",
38 | "__ATOMIC_ACQUIRE=2",
39 | "__SFRACT_IBIT__=0",
40 | "__FLT_MIN__=1.17549435e-38F",
41 | "__GCC_IEC_559_COMPLEX=0",
42 | "__BUILTIN_AVR_SLEEP=1",
43 | "__BUILTIN_AVR_COUNTLSULLK=1",
44 | "__BUILTIN_AVR_COUNTLSULLR=1",
45 | "__UFRACT_MAX__=0XFFFFP-16UR",
46 | "__UINT_LEAST8_TYPE__=unsigned char",
47 | "__DQ_FBIT__=63",
48 | "__INTMAX_C(c)=c ## LL",
49 | "__ULFRACT_FBIT__=32",
50 | "__SACCUM_EPSILON__=0x1P-7HK",
51 | "__CHAR_BIT__=8",
52 | "__USQ_IBIT__=0",
53 | "__UINT8_MAX__=255",
54 | "__ACCUM_FBIT__=15",
55 | "__WINT_MAX__=32767",
56 | "__USFRACT_FBIT__=8",
57 | "__ORDER_LITTLE_ENDIAN__=1234",
58 | "__SIZE_MAX__=65535U",
59 | "__WCHAR_MAX__=32767",
60 | "__LACCUM_IBIT__=32",
61 | "__DBL_DENORM_MIN__=double(1.40129846e-45L)",
62 | "__GCC_ATOMIC_CHAR_LOCK_FREE=1",
63 | "__GCC_IEC_559=0",
64 | "__FLT_EVAL_METHOD__=0",
65 | "__BUILTIN_AVR_LLKBITS=1",
66 | "__cpp_binary_literals=201304",
67 | "__LLACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-47LLK",
68 | "__GCC_ATOMIC_CHAR32_T_LOCK_FREE=1",
69 | "__BUILTIN_AVR_HKBITS=1",
70 | "__BUILTIN_AVR_BITSLLK=1",
71 | "__FRACT_FBIT__=15",
72 | "__BUILTIN_AVR_BITSLLR=1",
73 | "__UINT_FAST64_MAX__=18446744073709551615ULL",
74 | "__SIG_ATOMIC_TYPE__=char",
75 | "__BUILTIN_AVR_UHKBITS=1",
76 | "__UACCUM_FBIT__=16",
77 | "__DBL_MIN_10_EXP__=(-37)",
78 | "__FINITE_MATH_ONLY__=0",
79 | "__LFRACT_IBIT__=0",
80 | "__GNUC_PATCHLEVEL__=2",
81 | "__LFRACT_MAX__=0X7FFFFFFFP-31LR",
82 | "__UINT_FAST8_MAX__=255",
83 | "__has_include(STR)=__has_include__(STR)",
84 | "__DEC64_MAX_EXP__=385",
85 | "__INT8_C(c)=c",
86 | "__UINT_LEAST64_MAX__=18446744073709551615ULL",
87 | "__SA_FBIT__=15",
88 | "__SHRT_MAX__=32767",
89 | "__LDBL_MAX__=3.40282347e+38L",
90 | "__FRACT_MAX__=0X7FFFP-15R",
91 | "__UFRACT_FBIT__=16",
92 | "__UFRACT_MIN__=0.0UR",
93 | "__UINT_LEAST8_MAX__=255",
94 | "__GCC_ATOMIC_BOOL_LOCK_FREE=1",
95 | "__UINTMAX_TYPE__=long long unsigned int",
96 | "__LLFRACT_EPSILON__=0x1P-63LLR",
97 | "__BUILTIN_AVR_DELAY_CYCLES=1",
98 | "__DEC32_EPSILON__=1E-6DF",
99 | "__UINT32_MAX__=4294967295UL",
100 | "__ULFRACT_MAX__=0XFFFFFFFFP-32ULR",
101 | "__TA_IBIT__=16",
102 | "__LDBL_MAX_EXP__=128",
103 | "__WINT_MIN__=(-__WINT_MAX__ - 1)",
104 | "__ULLFRACT_MIN__=0.0ULLR",
105 | "__SCHAR_MAX__=127",
106 | "__WCHAR_MIN__=(-__WCHAR_MAX__ - 1)",
107 | "__INT64_C(c)=c ## LL",
108 | "__DBL_DIG__=6",
109 | "__GCC_ATOMIC_POINTER_LOCK_FREE=1",
110 | "__AVR_HAVE_SPH__=1",
111 | "__LLACCUM_MIN__=(-0X1P15LLK-0X1P15LLK)",
112 | "__BUILTIN_AVR_KBITS=1",
113 | "__BUILTIN_AVR_ABSK=1",
114 | "__BUILTIN_AVR_ABSR=1",
115 | "__SIZEOF_INT__=2",
116 | "__SIZEOF_POINTER__=2",
117 | "__GCC_ATOMIC_CHAR16_T_LOCK_FREE=1",
118 | "__USACCUM_IBIT__=8",
119 | "__USER_LABEL_PREFIX__",
120 | "__STDC_HOSTED__=1",
121 | "__LDBL_HAS_INFINITY__=1",
122 | "__LFRACT_MIN__=(-0.5LR-0.5LR)",
123 | "__HA_IBIT__=8",
124 | "__TQ_IBIT__=0",
125 | "__FLT_EPSILON__=1.19209290e-7F",
126 | "__GXX_WEAK__=1",
127 | "__USFRACT_IBIT__=0",
128 | "__LDBL_MIN__=1.17549435e-38L",
129 | "__FRACT_MIN__=(-0.5R-0.5R)",
130 | "__AVR_SFR_OFFSET__=0x20",
131 | "__DEC32_MAX__=9.999999E96DF",
132 | "__DA_IBIT__=32",
133 | "__INT32_MAX__=2147483647L",
134 | "__UQQ_FBIT__=8",
135 | "__SIZEOF_LONG__=4",
136 | "__UACCUM_MAX__=0XFFFFFFFFP-16UK",
137 | "__UINT16_C(c)=c ## U",
138 | "__DECIMAL_DIG__=9",
139 | "__LFRACT_EPSILON__=0x1P-31LR",
140 | "__AVR_2_BYTE_PC__=1",
141 | "__ULFRACT_MIN__=0.0ULR",
142 | "__has_include_next(STR)=__has_include_next__(STR)",
143 | "__BUILTIN_AVR_ULLRBITS=1",
144 | "__LDBL_HAS_QUIET_NAN__=1",
145 | "__ULACCUM_IBIT__=32",
146 | "__UACCUM_EPSILON__=0x1P-16UK",
147 | "__BUILTIN_AVR_SEI=1",
148 | "__GNUC__=4",
149 | "__ULLACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-48ULLK",
150 | "__HQ_IBIT__=0",
151 | "__BUILTIN_AVR_SWAP=1",
152 | "__FLT_HAS_DENORM__=1",
153 | "__SIZEOF_LONG_DOUBLE__=4",
154 | "__BIGGEST_ALIGNMENT__=1",
155 | "__UINT24_MAX__=16777215UL",
156 | "__BUILTIN_AVR_NOP=1",
157 | "__DQ_IBIT__=0",
158 | "__DBL_MAX__=double(3.40282347e+38L)",
159 | "__ULFRACT_IBIT__=0",
160 | "__INT_FAST32_MAX__=2147483647L",
161 | "__DBL_HAS_INFINITY__=1",
162 | "__INT64_MAX__=9223372036854775807LL",
163 | "__ACCUM_IBIT__=16",
164 | "__DEC32_MIN_EXP__=(-94)",
165 | "__BUILTIN_AVR_UKBITS=1",
166 | "__BUILTIN_AVR_FMULSU=1",
167 | "__LACCUM_MAX__=0X7FFFFFFFFFFFFFFFP-31LK",
168 | "__INT_FAST16_TYPE__=int",
169 | "__LDBL_HAS_DENORM__=1",
170 | "__BUILTIN_AVR_BITSK=1",
171 | "__BUILTIN_AVR_BITSR=1",
172 | "__cplusplus=199711L",
173 | "__DEC128_MAX__=9.999999999999999999999999999999999E6144DL",
174 | "__INT_LEAST32_MAX__=2147483647L",
175 | "__USING_SJLJ_EXCEPTIONS__=1",
176 | "__DEC32_MIN__=1E-95DF",
177 | "__ACCUM_MAX__=0X7FFFFFFFP-15K",
178 | "__DEPRECATED=1",
179 | "__DBL_MAX_EXP__=128",
180 | "__USACCUM_EPSILON__=0x1P-8UHK",
181 | "__DEC128_EPSILON__=1E-33DL",
182 | "__SFRACT_MAX__=0X7FP-7HR",
183 | "__FRACT_IBIT__=0",
184 | "__PTRDIFF_MAX__=32767",
185 | "__UACCUM_MIN__=0.0UK",
186 | "__UACCUM_IBIT__=16",
187 | "__BUILTIN_AVR_WDR=1",
188 | "__GNUG__=4",
189 | "__LONG_LONG_MAX__=9223372036854775807LL",
190 | "__SIZEOF_SIZE_T__=2",
191 | "__ULACCUM_MAX__=0XFFFFFFFFFFFFFFFFP-32ULK",
192 | "__SIZEOF_WINT_T__=2",
193 | "__SA_IBIT__=16",
194 | "__ULLACCUM_MIN__=0.0ULLK",
195 | "__BUILTIN_AVR_ROUNDUHK=1",
196 | "__BUILTIN_AVR_ROUNDUHR=1",
197 | "__GXX_ABI_VERSION=1002",
198 | "__INT24_MAX__=8388607L",
199 | "__UTA_FBIT__=48",
200 | "__FLT_MIN_EXP__=(-125)",
201 | "__USFRACT_MAX__=0XFFP-8UHR",
202 | "__UFRACT_IBIT__=0",
203 | "__BUILTIN_AVR_ROUNDFX=1",
204 | "__BUILTIN_AVR_ROUNDULK=1",
205 | "__BUILTIN_AVR_ROUNDULR=1",
206 | "__BUILTIN_AVR_COUNTLSLLK=1",
207 | "__BUILTIN_AVR_COUNTLSLLR=1",
208 | "__BUILTIN_AVR_ROUNDHK=1",
209 | "__INT_FAST64_TYPE__=long long int",
210 | "__BUILTIN_AVR_ROUNDHR=1",
211 | "__DBL_MIN__=double(1.17549435e-38L)",
212 | "__BUILTIN_AVR_COUNTLSK=1",
213 | "__BUILTIN_AVR_ROUNDLK=1",
214 | "__BUILTIN_AVR_COUNTLSR=1",
215 | "__BUILTIN_AVR_ROUNDLR=1",
216 | "__FLT_MIN_10_EXP__=(-37)",
217 | "__LACCUM_MIN__=(-0X1P31LK-0X1P31LK)",
218 | "__ULLACCUM_FBIT__=48",
219 | "__BUILTIN_AVR_LKBITS=1",
220 | "__ULLFRACT_EPSILON__=0x1P-64ULLR",
221 | "__DEC128_MIN__=1E-6143DL",
222 | "__REGISTER_PREFIX__",
223 | "__UINT16_MAX__=65535U",
224 | "__DBL_HAS_DENORM__=1",
225 | "__BUILTIN_AVR_ULKBITS=1",
226 | "__ACCUM_MIN__=(-0X1P15K-0X1P15K)",
227 | "__AVR_ARCH__=2",
228 | "__SQ_IBIT__=0",
229 | "__UINT8_TYPE__=unsigned char",
230 | "__BUILTIN_AVR_ROUNDUK=1",
231 | "__BUILTIN_AVR_ROUNDUR=1",
232 | "__UHA_FBIT__=8",
233 | "__NO_INLINE__=1",
234 | "__SFRACT_MIN__=(-0.5HR-0.5HR)",
235 | "__UTQ_FBIT__=128",
236 | "__FLT_MANT_DIG__=24",
237 | "__VERSION__=\"4.9.2\"",
238 | "__UINT64_C(c)=c ## ULL",
239 | "__ULLFRACT_FBIT__=64",
240 | "__FRACT_EPSILON__=0x1P-15R",
241 | "__ULACCUM_MIN__=0.0ULK",
242 | "__UDA_FBIT__=32",
243 | "__LLACCUM_EPSILON__=0x1P-47LLK",
244 | "__GCC_ATOMIC_INT_LOCK_FREE=1",
245 | "__BUILTIN_AVR_BITSUHK=1",
246 | "__BUILTIN_AVR_BITSUHR=1",
247 | "__FLOAT_WORD_ORDER__=__ORDER_LITTLE_ENDIAN__",
248 | "__USFRACT_MIN__=0.0UHR",
249 | "__BUILTIN_AVR_BITSULK=1",
250 | "__ULLACCUM_IBIT__=16",
251 | "__BUILTIN_AVR_BITSULR=1",
252 | "__UQQ_IBIT__=0",
253 | "__BUILTIN_AVR_LLRBITS=1",
254 | "__BUILTIN_AVR_BITSULLK=1",
255 | "__BUILTIN_AVR_BITSULLR=1",
256 | "__INT32_C(c)=c ## L",
257 | "__DEC64_EPSILON__=1E-15DD",
258 | "__ORDER_PDP_ENDIAN__=3412",
259 | "__DEC128_MIN_EXP__=(-6142)",
260 | "__UHQ_FBIT__=16",
261 | "__LLACCUM_FBIT__=47",
262 | "__BUILTIN_AVR_ROUNDULLK=1",
263 | "__BUILTIN_AVR_ROUNDULLR=1",
264 | "__INT_FAST32_TYPE__=long int",
265 | "__BUILTIN_AVR_HRBITS=1",
266 | "__UINT_LEAST16_TYPE__=unsigned int",
267 | "__BUILTIN_AVR_UHRBITS=1",
268 | "__INT16_MAX__=32767",
269 | "__SIZE_TYPE__=unsigned int",
270 | "__UINT64_MAX__=18446744073709551615ULL",
271 | "__UDQ_FBIT__=64",
272 | "__INT8_TYPE__=signed char",
273 | "__ELF__=1",
274 | "__ULFRACT_EPSILON__=0x1P-32ULR",
275 | "__LLFRACT_FBIT__=63",
276 | "__FLT_RADIX__=2",
277 | "__INT_LEAST16_TYPE__=int",
278 | "__BUILTIN_AVR_ABSFX=1",
279 | "__LDBL_EPSILON__=1.19209290e-7L",
280 | "__UINTMAX_C(c)=c ## ULL",
281 | "__INT24_MIN__=(-__INT24_MAX__-1)",
282 | "__SACCUM_MAX__=0X7FFFP-7HK",
283 | "__BUILTIN_AVR_ABSHR=1",
284 | "__SIG_ATOMIC_MAX__=127",
285 | "__GCC_ATOMIC_WCHAR_T_LOCK_FREE=1",
286 | "__SIZEOF_PTRDIFF_T__=2",
287 | "__AVR=1",
288 | "__BUILTIN_AVR_ABSLK=1",
289 | "__BUILTIN_AVR_ABSLR=1",
290 | "__LACCUM_EPSILON__=0x1P-31LK",
291 | "__DEC32_SUBNORMAL_MIN__=0.000001E-95DF",
292 | "__INT_FAST16_MAX__=32767",
293 | "__UINT_FAST32_MAX__=4294967295UL",
294 | "__UINT_LEAST64_TYPE__=long long unsigned int",
295 | "__USACCUM_MAX__=0XFFFFP-8UHK",
296 | "__SFRACT_EPSILON__=0x1P-7HR",
297 | "__FLT_HAS_QUIET_NAN__=1",
298 | "__FLT_MAX_10_EXP__=38",
299 | "__LONG_MAX__=2147483647L",
300 | "__DEC128_SUBNORMAL_MIN__=0.000000000000000000000000000000001E-6143DL",
301 | "__FLT_HAS_INFINITY__=1",
302 | "__USA_FBIT__=16",
303 | "__UINT_FAST16_TYPE__=unsigned int",
304 | "__DEC64_MAX__=9.999999999999999E384DD",
305 | "__BUILTIN_AVR_RBITS=1",
306 | "__CHAR16_TYPE__=unsigned int",
307 | "__PRAGMA_REDEFINE_EXTNAME=1",
308 | "__INT_LEAST16_MAX__=32767",
309 | "__DEC64_MANT_DIG__=16",
310 | "__UINT_LEAST32_MAX__=4294967295UL",
311 | "__SACCUM_FBIT__=7",
312 | "__GCC_ATOMIC_LONG_LOCK_FREE=1",
313 | "__INT_LEAST64_TYPE__=long long int",
314 | "__INT16_TYPE__=int",
315 | "__INT_LEAST8_TYPE__=signed char",
316 | "__SQ_FBIT__=31",
317 | "__DEC32_MAX_EXP__=97",
318 | "__INT_FAST8_MAX__=127",
319 | "__INTPTR_MAX__=32767",
320 | "__QQ_FBIT__=7",
321 | "__UTA_IBIT__=16",
322 | "__AVR_ERRATA_SKIP__=1",
323 | "__LDBL_MANT_DIG__=24",
324 | "__SFRACT_FBIT__=7",
325 | "__SACCUM_MIN__=(-0X1P7HK-0X1P7HK)",
326 | "__DBL_HAS_QUIET_NAN__=1",
327 | "__SIG_ATOMIC_MIN__=(-__SIG_ATOMIC_MAX__ - 1)",
328 | "AVR=1",
329 | "__BUILTIN_AVR_FMULS=1",
330 | "__INTPTR_TYPE__=int",
331 | "__UINT16_TYPE__=unsigned int",
332 | "__WCHAR_TYPE__=int",
333 | "__SIZEOF_FLOAT__=4",
334 | "__AVR__=1",
335 | "__BUILTIN_AVR_INSERT_BITS=1",
336 | "__USQ_FBIT__=32",
337 | "__UINTPTR_MAX__=65535U",
338 | "__DEC64_MIN_EXP__=(-382)",
339 | "__INT_FAST64_MAX__=9223372036854775807LL",
340 | "__GCC_ATOMIC_TEST_AND_SET_TRUEVAL=1",
341 | "__FLT_DIG__=6",
342 | "__UINT_FAST64_TYPE__=long long unsigned int",
343 | "__BUILTIN_AVR_BITSHK=1",
344 | "__BUILTIN_AVR_BITSHR=1",
345 | "__INT_MAX__=32767",
346 | "__LACCUM_FBIT__=31",
347 | "__USACCUM_MIN__=0.0UHK",
348 | "__UHA_IBIT__=8",
349 | "__INT64_TYPE__=long long int",
350 | "__BUILTIN_AVR_BITSLK=1",
351 | "__BUILTIN_AVR_BITSLR=1",
352 | "__FLT_MAX_EXP__=128",
353 | "__UTQ_IBIT__=0",
354 | "__DBL_MANT_DIG__=24",
355 | "__BUILTIN_AVR_ULLKBITS=1",
356 | "__INT_LEAST64_MAX__=9223372036854775807LL",
357 | "__DEC64_MIN__=1E-383DD",
358 | "__WINT_TYPE__=int",
359 | "__UINT_LEAST32_TYPE__=long unsigned int",
360 | "__SIZEOF_SHORT__=2",
361 | "__ULLFRACT_IBIT__=0",
362 | "__LDBL_MIN_EXP__=(-125)",
363 | "__UDA_IBIT__=32",
364 | "__INT_LEAST8_MAX__=127",
365 | "__LFRACT_FBIT__=31",
366 | "__LDBL_MAX_10_EXP__=38",
367 | "__ATOMIC_RELAXED=0",
368 | "__DBL_EPSILON__=double(1.19209290e-7L)",
369 | "__BUILTIN_AVR_BITSUK=1",
370 | "__BUILTIN_AVR_BITSUR=1",
371 | "__UINT8_C(c)=c",
372 | "__INT_LEAST32_TYPE__=long int",
373 | "__BUILTIN_AVR_URBITS=1",
374 | "__SIZEOF_WCHAR_T__=2",
375 | "__UINT64_TYPE__=long long unsigned int",
376 | "__LLFRACT_MAX__=0X7FFFFFFFFFFFFFFFP-63LLR",
377 | "__TQ_FBIT__=127",
378 | "__INT_FAST8_TYPE__=signed char",
379 | "__ULLACCUM_EPSILON__=0x1P-48ULLK",
380 | "__BUILTIN_AVR_ROUNDK=1",
381 | "__BUILTIN_AVR_ROUNDR=1",
382 | "__UHQ_IBIT__=0",
383 | "__LLACCUM_IBIT__=16",
384 | "__DBL_DECIMAL_DIG__=9",
385 | "__DEC_EVAL_METHOD__=2",
386 | "__TA_FBIT__=47",
387 | "__UDQ_IBIT__=0",
388 | "__ORDER_BIG_ENDIAN__=4321",
389 | "__WITH_AVRLIBC__=1",
390 | "__ACCUM_EPSILON__=0x1P-15K",
391 | "__UINT32_C(c)=c ## UL",
392 | "__BUILTIN_AVR_COUNTLSUHK=1",
393 | "__INTMAX_MAX__=9223372036854775807LL",
394 | "__BUILTIN_AVR_COUNTLSUHR=1",
395 | "__BYTE_ORDER__=__ORDER_LITTLE_ENDIAN__",
396 | "__FLT_DENORM_MIN__=1.40129846e-45F",
397 | "__LLFRACT_IBIT__=0",
398 | "__INT8_MAX__=127",
399 | "__UINT_FAST32_TYPE__=long unsigned int",
400 | "__CHAR32_TYPE__=long unsigned int",
401 | "__BUILTIN_AVR_COUNTLSULK=1",
402 | "__BUILTIN_AVR_COUNTLSULR=1",
403 | "__FLT_MAX__=3.40282347e+38F",
404 | "__USACCUM_FBIT__=8",
405 | "__BUILTIN_AVR_COUNTLSFX=1",
406 | "__INT32_TYPE__=long int",
407 | "__SIZEOF_DOUBLE__=4",
408 | "__UFRACT_EPSILON__=0x1P-16UR",
409 | "__BUILTIN_AVR_COUNTLSHK=1",
410 | "__BUILTIN_AVR_COUNTLSHR=1",
411 | "__INTMAX_TYPE__=long long int",
412 | "__BUILTIN_AVR_ABSLLK=1",
413 | "__BUILTIN_AVR_ABSLLR=1",
414 | "__DEC128_MAX_EXP__=6145",
415 | "__AVR_HAVE_16BIT_SP__=1",
416 | "__ATOMIC_CONSUME=1",
417 | "__GNUC_MINOR__=9",
418 | "__UINTMAX_MAX__=18446744073709551615ULL",
419 | "__DEC32_MANT_DIG__=7",
420 | "__HA_FBIT__=7",
421 | "__BUILTIN_AVR_COUNTLSLK=1",
422 | "__BUILTIN_AVR_COUNTLSLR=1",
423 | "__BUILTIN_AVR_CLI=1",
424 | "__DBL_MAX_10_EXP__=38",
425 | "__LDBL_DENORM_MIN__=1.40129846e-45L",
426 | "__INT16_C(c)=c",
427 | "__STDC__=1",
428 | "__PTRDIFF_TYPE__=int",
429 | "__LLFRACT_MIN__=(-0.5LLR-0.5LLR)",
430 | "__BUILTIN_AVR_LRBITS=1",
431 | "__ATOMIC_SEQ_CST=5",
432 | "__DA_FBIT__=31",
433 | "__UINT32_TYPE__=long unsigned int",
434 | "__BUILTIN_AVR_ROUNDLLK=1",
435 | "__UINTPTR_TYPE__=unsigned int",
436 | "__BUILTIN_AVR_ROUNDLLR=1",
437 | "__USA_IBIT__=16",
438 | "__BUILTIN_AVR_ULRBITS=1",
439 | "__DEC64_SUBNORMAL_MIN__=0.000000000000001E-383DD",
440 | "__DEC128_MANT_DIG__=34",
441 | "__LDBL_MIN_10_EXP__=(-37)",
442 | "__BUILTIN_AVR_COUNTLSUK=1",
443 | "__BUILTIN_AVR_COUNTLSUR=1",
444 | "__SIZEOF_LONG_LONG__=8",
445 | "__ULACCUM_EPSILON__=0x1P-32ULK",
446 | "__SACCUM_IBIT__=8",
447 | "__GCC_ATOMIC_LLONG_LOCK_FREE=1",
448 | "__LDBL_DIG__=6",
449 | "__FLT_DECIMAL_DIG__=9",
450 | "__UINT_FAST16_MAX__=65535U",
451 | "__GNUC_GNU_INLINE__=1",
452 | "__GCC_ATOMIC_SHORT_LOCK_FREE=1",
453 | "__BUILTIN_AVR_ABSHK=1",
454 | "__BUILTIN_AVR_FLASH_SEGMENT=1",
455 | "__ULLFRACT_MAX__=0XFFFFFFFFFFFFFFFFP-64ULLR",
456 | "__UINT_FAST8_TYPE__=unsigned char",
457 | "__USFRACT_EPSILON__=0x1P-8UHR",
458 | "__ULACCUM_FBIT__=32",
459 | "__QQ_IBIT__=0",
460 | "__ATOMIC_ACQ_REL=4",
461 | "__ATOMIC_RELEASE=3",
462 | "__BUILTIN_AVR_FMUL=1",
463 | "USBCON"
464 | ]
465 | }
466 | ]
467 | }
--------------------------------------------------------------------------------
/SimpleTX/NonBlockingRtttl.cpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------------
2 | // Created by Antoine Beauchamp based on the code from the ToneLibrary
3 | //
4 | // See "NonBlockingRtttl.h" for purpose, syntax, version history, links, and more.
5 | // ---------------------------------------------------------------------------
6 |
7 | #include "Arduino.h"
8 | #include "NonBlockingRtttl.h"
9 |
10 | /*********************************************************
11 | * RTTTL Library data
12 | *********************************************************/
13 |
14 | namespace rtttl
15 | {
16 |
17 | const int notes[] = { 0,
18 | NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4,
19 | NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5,
20 | NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6,
21 | NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7
22 | };
23 |
24 | //#define isdigit(n) (n >= '0' && n <= '9')
25 | #define OCTAVE_OFFSET 0
26 |
27 | const char * buffer = "";
28 | int bufferIndex = -32760;
29 | byte default_dur = 4;
30 | byte default_oct = 5;
31 | int bpm = 63;
32 | long wholenote;
33 | byte pin = -1;
34 | unsigned long noteDelay = 0; //m will always be after which means the last note is done playing
35 | bool playing = false;
36 |
37 | //pre-declaration
38 | void nextnote();
39 |
40 | // tone() and noTone() are not implemented for Arduino core for the ESP32
41 | // See https://github.com/espressif/arduino-esp32/issues/980
42 | // and https://github.com/espressif/arduino-esp32/issues/1720
43 | #if defined(ESP32)
44 | void noTone(){
45 | ledcWrite(0, 0); // channel, volume
46 | }
47 |
48 | void noTone(int pin){
49 | noTone();
50 | }
51 |
52 | void tone(int frq) {
53 | ledcWriteTone(0, frq); // channel, freq
54 | ledcWrite(0, 255); // channel, volume
55 | }
56 |
57 | void tone(int pin, int frq, int duration){
58 | tone(frq);
59 | }
60 | #endif
61 |
62 | void begin(byte iPin, const char * iSongBuffer)
63 | {
64 | #ifdef RTTTL_NONBLOCKING_DEBUG
65 | Serial.print("playing: ");
66 | Serial.println(iSongBuffer);
67 | #endif
68 |
69 | //init values
70 | pin = iPin;
71 | #if defined(ESP32)
72 | ledcSetup(0, 1000, 10); // resolution always seems to be 10bit, no matter what is given
73 | ledcAttachPin(pin, 0);
74 | #endif
75 | buffer = iSongBuffer;
76 | bufferIndex = 0;
77 | default_dur = 4;
78 | default_oct = 6;
79 | bpm=63;
80 | playing = true;
81 | noteDelay = 0;
82 | #ifdef RTTTL_NONBLOCKING_DEBUG
83 | Serial.print("noteDelay=");
84 | Serial.println(noteDelay);
85 | #endif
86 |
87 | //stop current note
88 | noTone(pin);
89 |
90 | //read buffer until first note
91 | int num;
92 |
93 | // format: d=N,o=N,b=NNN:
94 | // find the start (skip name, etc)
95 |
96 | while(*buffer != ':') buffer++; // ignore name
97 | buffer++; // skip ':'
98 |
99 | // get default duration
100 | if(*buffer == 'd')
101 | {
102 | buffer++; buffer++; // skip "d="
103 | num = 0;
104 | while(isdigit(*buffer))
105 | {
106 | num = (num * 10) + (*buffer++ - '0');
107 | }
108 | if(num > 0) default_dur = num;
109 | buffer++; // skip comma
110 | }
111 |
112 | #ifdef RTTTL_NONBLOCKING_INFO
113 | Serial.print("ddur: "); Serial.println(default_dur, 10);
114 | #endif
115 |
116 | // get default octave
117 | if(*buffer == 'o')
118 | {
119 | buffer++; buffer++; // skip "o="
120 | num = *buffer++ - '0';
121 | if(num >= 3 && num <=7) default_oct = num;
122 | buffer++; // skip comma
123 | }
124 |
125 | #ifdef RTTTL_NONBLOCKING_INFO
126 | Serial.print("doct: "); Serial.println(default_oct, 10);
127 | #endif
128 |
129 | // get BPM
130 | if(*buffer == 'b')
131 | {
132 | buffer++; buffer++; // skip "b="
133 | num = 0;
134 | while(isdigit(*buffer))
135 | {
136 | num = (num * 10) + (*buffer++ - '0');
137 | }
138 | bpm = num;
139 | buffer++; // skip colon
140 | }
141 |
142 | #ifdef RTTTL_NONBLOCKING_INFO
143 | Serial.print("bpm: "); Serial.println(bpm, 10);
144 | #endif
145 |
146 | // BPM usually expresses the number of quarter notes per minute
147 | wholenote = (60 * 1000L / bpm) * 4; // this is the time for whole note (in milliseconds)
148 |
149 | #ifdef RTTTL_NONBLOCKING_INFO
150 | Serial.print("wn: "); Serial.println(wholenote, 10);
151 | #endif
152 | }
153 |
154 | void nextnote()
155 | {
156 | long duration;
157 | byte note;
158 | byte scale;
159 |
160 | //stop current note
161 | noTone(pin);
162 |
163 | // first, get note duration, if available
164 | int num = 0;
165 | while(isdigit(*buffer))
166 | {
167 | num = (num * 10) + (*buffer++ - '0');
168 | }
169 |
170 | if(num) duration = wholenote / num;
171 | else duration = wholenote / default_dur; // we will need to check if we are a dotted note after
172 |
173 | // now get the note
174 | note = 0;
175 |
176 | switch(*buffer)
177 | {
178 | case 'c':
179 | note = 1;
180 | break;
181 | case 'd':
182 | note = 3;
183 | break;
184 | case 'e':
185 | note = 5;
186 | break;
187 | case 'f':
188 | note = 6;
189 | break;
190 | case 'g':
191 | note = 8;
192 | break;
193 | case 'a':
194 | note = 10;
195 | break;
196 | case 'b':
197 | note = 12;
198 | break;
199 | case 'p':
200 | default:
201 | note = 0;
202 | }
203 | buffer++;
204 |
205 | // now, get optional '#' sharp
206 | if(*buffer == '#')
207 | {
208 | note++;
209 | buffer++;
210 | }
211 |
212 | // now, get optional '.' dotted note
213 | if(*buffer == '.')
214 | {
215 | duration += duration/2;
216 | buffer++;
217 | }
218 |
219 | // now, get scale
220 | if(isdigit(*buffer))
221 | {
222 | scale = *buffer - '0';
223 | buffer++;
224 | }
225 | else
226 | {
227 | scale = default_oct;
228 | }
229 |
230 | scale += OCTAVE_OFFSET;
231 |
232 | // now, get optional '.' dotted note again.
233 | // A dot /after/ the octave is allowed too, depending on which
234 | // RTTTL specification you read.
235 | // See https://github.com/end2endzone/NonBlockingRTTTL/issues/10
236 | if(*buffer == '.')
237 | {
238 | duration += duration/2;
239 | buffer++;
240 | }
241 |
242 | if(*buffer == ',')
243 | buffer++; // skip comma for next note (or we may be at the end)
244 |
245 | // now play the note
246 |
247 | if(note)
248 | {
249 | #ifdef RTTTL_NONBLOCKING_INFO
250 | Serial.print("Playing: ");
251 | Serial.print(scale, 10); Serial.print(' ');
252 | Serial.print(note, 10); Serial.print(" (");
253 | Serial.print(notes[(scale - 4) * 12 + note], 10);
254 | Serial.print(") ");
255 | Serial.println(duration, 10);
256 | #endif
257 |
258 | tone(pin, notes[(scale - 4) * 12 + note], duration);
259 |
260 | noteDelay = millis() + (duration+1);
261 | }
262 | else
263 | {
264 | #ifdef RTTTL_NONBLOCKING_INFO
265 | Serial.print("Pausing: ");
266 | Serial.println(duration, 10);
267 | #endif
268 |
269 | noteDelay = millis() + (duration);
270 | }
271 | }
272 |
273 | void play()
274 | {
275 | //if done playing the song, return
276 | if (!playing)
277 | {
278 | #ifdef RTTTL_NONBLOCKING_DEBUG
279 | Serial.println("done playing...");
280 | #endif
281 |
282 | return;
283 | }
284 |
285 | //are we still playing a note ?
286 | unsigned long m = millis();
287 | if (m < noteDelay)
288 | {
289 | #ifdef RTTTL_NONBLOCKING_DEBUG
290 | Serial.println("still playing a note...");
291 | #endif
292 |
293 | //wait until the note is completed
294 | return;
295 | }
296 |
297 | //ready to play the next note
298 | if (*buffer == '\0')
299 | {
300 | //no more notes. Reached the end of the last note
301 |
302 | #ifdef RTTTL_NONBLOCKING_DEBUG
303 | Serial.println("end of note...");
304 | #endif
305 |
306 | //issue #6: Bug for ESP8266 environment - noTone() not called at end of sound.
307 | //disable sound at the end of a normal playback.
308 | stop();
309 |
310 | return; //end of the song
311 | }
312 | else
313 | {
314 | //more notes to play...
315 |
316 | #ifdef RTTTL_NONBLOCKING_DEBUG
317 | Serial.println("next note...");
318 | #endif
319 |
320 | nextnote();
321 | }
322 | }
323 |
324 | void stop()
325 | {
326 | if (playing)
327 | {
328 | //increase song buffer until the end
329 | while (*buffer != '\0')
330 | {
331 | buffer++;
332 | }
333 |
334 | //issue #6: Bug for ESP8266 environment - noTone() not called at end of sound.
335 | //disable sound if one abort playback using the stop() command.
336 | noTone(pin);
337 |
338 | playing = false;
339 | }
340 | }
341 |
342 | bool done()
343 | {
344 | return !playing;
345 | }
346 |
347 | bool isPlaying()
348 | {
349 | return playing;
350 | }
351 |
352 | }; //namespace
353 |
--------------------------------------------------------------------------------
/SimpleTX/NonBlockingRtttl.h:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------------
2 | // AUTHOR/LICENSE:
3 | // The following code was written by Antoine Beauchamp. For other authors, see AUTHORS file.
4 | // The code & updates for the library can be found at http://github.com/end2endzone/NonBlockingRTTTL
5 | // Original source code for the RTTL player: https://code.google.com/archive/p/rogue-code/wikis/ToneLibraryDocumentation.wiki
6 | // MIT License: http://www.opensource.org/licenses/mit-license.php
7 | // ---------------------------------------------------------------------------
8 |
9 | #ifndef NonBlockingRtttl_h
10 | #define NonBlockingRtttl_h
11 |
12 | #define NONBLOCKINGRTTTL_VERSION 1.3.0
13 |
14 | #include "Arduino.h"
15 |
16 | //if notes are not already defined
17 | #ifndef NOTE_B0
18 |
19 | #define NOTE_H 0
20 | #define NOTE_B0 31
21 | #define NOTE_C1 33
22 | #define NOTE_CS1 35
23 | #define NOTE_D1 37
24 | #define NOTE_DS1 39
25 | #define NOTE_E1 41
26 | #define NOTE_F1 44
27 | #define NOTE_FS1 46
28 | #define NOTE_G1 49
29 | #define NOTE_GS1 52
30 | #define NOTE_A1 55
31 | #define NOTE_AS1 58
32 | #define NOTE_B1 62
33 | #define NOTE_C2 65
34 | #define NOTE_CS2 69
35 | #define NOTE_D2 73
36 | #define NOTE_DS2 78
37 | #define NOTE_E2 82
38 | #define NOTE_F2 87
39 | #define NOTE_FS2 93
40 | #define NOTE_G2 98
41 | #define NOTE_GS2 104
42 | #define NOTE_A2 110
43 | #define NOTE_AS2 117
44 | #define NOTE_B2 123
45 | #define NOTE_C3 131
46 | #define NOTE_CS3 139
47 | #define NOTE_D3 147
48 | #define NOTE_DS3 156
49 | #define NOTE_E3 165
50 | #define NOTE_F3 175
51 | #define NOTE_FS3 185
52 | #define NOTE_G3 196
53 | #define NOTE_GS3 208
54 | #define NOTE_A3 220
55 | #define NOTE_AS3 233
56 | #define NOTE_B3 247
57 | #define NOTE_C4 262
58 | #define NOTE_CS4 277
59 | #define NOTE_D4 294
60 | #define NOTE_DS4 311
61 | #define NOTE_E4 330
62 | #define NOTE_F4 349
63 | #define NOTE_FS4 370
64 | #define NOTE_G4 392
65 | #define NOTE_GS4 415
66 | #define NOTE_A4 440
67 | #define NOTE_AS4 466
68 | #define NOTE_B4 494
69 | #define NOTE_C5 523
70 | #define NOTE_CS5 554
71 | #define NOTE_D5 587
72 | #define NOTE_DS5 622
73 | #define NOTE_E5 659
74 | #define NOTE_F5 698
75 | #define NOTE_FS5 740
76 | #define NOTE_G5 784
77 | #define NOTE_GS5 831
78 | #define NOTE_A5 880
79 | #define NOTE_AS5 932
80 | #define NOTE_B5 988
81 | #define NOTE_C6 1047
82 | #define NOTE_CS6 1109
83 | #define NOTE_D6 1175
84 | #define NOTE_DS6 1245
85 | #define NOTE_E6 1319
86 | #define NOTE_F6 1397
87 | #define NOTE_FS6 1480
88 | #define NOTE_G6 1568
89 | #define NOTE_GS6 1661
90 | #define NOTE_A6 1760
91 | #define NOTE_AS6 1865
92 | #define NOTE_B6 1976
93 | #define NOTE_C7 2093
94 | #define NOTE_CS7 2217
95 | #define NOTE_D7 2349
96 | #define NOTE_DS7 2489
97 | #define NOTE_E7 2637
98 | #define NOTE_F7 2794
99 | #define NOTE_FS7 2960
100 | #define NOTE_G7 3136
101 | #define NOTE_GS7 3322
102 | #define NOTE_A7 3520
103 | #define NOTE_AS7 3729
104 | #define NOTE_B7 3951
105 | #define NOTE_C8 4186
106 | #define NOTE_CS8 4435
107 | #define NOTE_D8 4699
108 | #define NOTE_DS8 4978
109 |
110 | //if notes are not already defined
111 | #endif
112 |
113 | //#define RTTTL_NONBLOCKING_DEBUG
114 | //#define RTTTL_NONBLOCKING_INFO
115 |
116 | namespace rtttl
117 | {
118 |
119 | /****************************************************************************
120 | * Description:
121 | * begin() setups the NON-BLOCKING RTTTL library for
122 | * decoding a new RTTTL song.
123 | * Parameters:
124 | * iPin: The pin which is connected to the piezo buffer.
125 | * iSongBuffer: The string buffer of the RTTTL song.
126 | ****************************************************************************/
127 | void begin(byte iPin, const char * iSongBuffer);
128 |
129 | /****************************************************************************
130 | * Description:
131 | * play() automatically plays a new note when required.
132 | * This function must constantly be called within the loop() function.
133 | * Warning: inserting too long delays within the loop function may
134 | * disrupt the NON-BLOCKING RTTTL library from playing properly.
135 | ****************************************************************************/
136 | void play();
137 |
138 | /****************************************************************************
139 | * Description:
140 | * stop() stops playing the current song.
141 | ****************************************************************************/
142 | void stop();
143 |
144 | /****************************************************************************
145 | * Description:
146 | * isPlaying() return true when the library is playing
147 | * the given RTTTL song.
148 | ****************************************************************************/
149 | bool isPlaying();
150 |
151 | /****************************************************************************
152 | * Description:
153 | * done() return true when the library is done playing
154 | * the given RTTTL song.
155 | ****************************************************************************/
156 | bool done();
157 |
158 | }; //namespace
159 |
160 | //NonBlockingRtttl_h
161 | #endif
162 |
--------------------------------------------------------------------------------
/SimpleTX/SimpleTX.ino:
--------------------------------------------------------------------------------
1 | /*
2 | // Simple Arduino trasmisster
3 | // Arduino Nano
4 | // ELRS 2.4G TX moduel
5 | // Custom PCB from JLCPCB
6 | // const float codeVersion = 0.92; // Software revision
7 | // https://github.com/kkbin505/Arduino-Transmitter-for-ELRS
8 |
9 | * This file is part of Simple TX
10 | *
11 | * Simple TX is free software: you can redistribute it and/or modify
12 | * it under the terms of the GNU General Public License as published by
13 | * the Free Software Foundation, either version 3 of the License, or
14 | * (at your option) any later version.
15 | *
16 | * Simple TX is distributed in the hope that it will be useful,
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 | * GNU General Public License for more details.
20 | *
21 | * You should have received a copy of the GNU General Public License
22 | * along with Cleanflight. If not, see .
23 | */
24 |
25 | #include
26 | #include "NonBlockingRtttl.h"
27 | #include "EEPROM.h"
28 | #include "config.h"
29 | #include "crsf.h"
30 | #include "led.h"
31 | #include "tone.h"
32 |
33 | //#define DEBUG // if not commented out, Serial.print() is active! For debugging only!!
34 | //#define GIMBAL_CALIBRATION // if not commented out, Serial.print() is active! For debugging only!!
35 |
36 | int Aileron_value = 0; // values read from the pot
37 | int Elevator_value = 0;
38 | int Throttle_value = 0;
39 | int Rudder_value = 0;
40 | int previous_throttle = 191;
41 |
42 | int loopCount = 0; // for ELRS seeting
43 |
44 | int AUX1_Arm = 0; // switch values read from the digital pin
45 | #ifdef USE_3POS_SWITCH_AS_CHANNEL_6
46 | int AUX2_value_HIGH= 0;
47 | int AUX2_value_LOW = 0;
48 | #else
49 | int AUX2_value_LOW = 0;
50 | #endif
51 | int AUX2_value = 0;
52 | int AUX3_value = 0;
53 | int AUX4_value = 0;
54 |
55 | float batteryVoltage;
56 |
57 | int currentPktRate = 0;
58 | int currentPower = 0;
59 | int currentDynamic = 0;
60 | int currentSetting = 0;
61 | int stickMoved = 0;
62 | int stickInt = 0;
63 | uint32_t stickMovedMillis = 0;
64 |
65 | uint32_t currentMillis = 0;
66 |
67 | uint8_t crsfPacket[CRSF_PACKET_SIZE];
68 | uint8_t crsfCmdPacket[CRSF_CMD_PACKET_SIZE];
69 | int16_t rcChannels[CRSF_MAX_CHANNEL];
70 | uint32_t crsfTime = 0;
71 |
72 | CRSF crsfClass;
73 |
74 | bool calStatus=false;
75 |
76 | // -----------------------------------------------------------------------------------------------------
77 | // Calibration
78 |
79 | #define CALIB_MARK 0x55
80 | #define CALIB_MARK_ADDR 0x00
81 | #define CALIB_VAL_ADDR CALIB_MARK_ADDR + 1
82 |
83 | #define CALIB_CNT 5 // times of switch on/off
84 | #define CALIB_CENT_TMO 5000 //ms
85 | #define CALIB_TMO 20000 // ms
86 | int cal_reset = 0 ;
87 |
88 | struct CalibValues {
89 | int aileronMin;
90 | int aileronMax;
91 | int aileronCenter;
92 | int elevatorMin;
93 | int elevatorMax;
94 | int elevatorCenter;
95 | int thrMin;
96 | int thrMax;
97 | int rudderMin;
98 | int rudderMax;
99 | int rudderCenter;
100 | };
101 |
102 | CalibValues calValues;
103 |
104 | bool calibrationPresent() {
105 | return EEPROM.read(CALIB_MARK_ADDR) == CALIB_MARK;
106 | }
107 |
108 | void calibrationSave() {
109 | EEPROM.update(CALIB_MARK_ADDR, CALIB_MARK);
110 | EEPROM.put(CALIB_VAL_ADDR, calValues);
111 | }
112 |
113 | void calibrationLoad() {
114 | EEPROM.get(CALIB_VAL_ADDR, calValues);
115 | }
116 |
117 | void calibrationReset() {
118 | EEPROM.put(CALIB_MARK_ADDR, (uint8_t)0xFF);
119 | calValues = {
120 | .aileronMin = ANALOG_CUTOFF,
121 | .aileronMax = 1023 - ANALOG_CUTOFF,
122 | .aileronCenter = 988,
123 | .elevatorMin = ANALOG_CUTOFF,
124 | .elevatorMax = 1023 - ANALOG_CUTOFF,
125 | .elevatorCenter = 988,
126 | .thrMin = ANALOG_CUTOFF,
127 | .thrMax = 1023 - ANALOG_CUTOFF,
128 | .rudderMin = ANALOG_CUTOFF,
129 | .rudderMax = 1023 - ANALOG_CUTOFF,
130 | .rudderCenter = 988,
131 | };
132 | EEPROM.put(CALIB_VAL_ADDR, calValues);
133 | }
134 |
135 | uint8_t aux2cnt = 0;
136 |
137 | unsigned long calibrationTimerStart;
138 |
139 | //Flash LED and beep for (times)
140 | void calibrationChirp(uint8_t times) {
141 |
142 | digitalWrite(DIGITAL_PIN_LED, HIGH);
143 | delay(1000);
144 | digitalWrite(DIGITAL_PIN_LED, LOW);
145 | delay(1000);
146 |
147 | for (uint8_t i = 0; i < times; i++) {
148 | #ifdef ACTIVE_BUZZER
149 | digitalWrite(DIGITAL_PIN_BUZZER, HIGH);
150 | #else
151 | tone(DIGITAL_PIN_BUZZER,5000,100);
152 | #endif
153 | digitalWrite(DIGITAL_PIN_LED, HIGH);
154 | delay(100);
155 | #ifdef ACTIVE_BUZZER
156 | digitalWrite(DIGITAL_PIN_BUZZER, LOW);
157 | #endif
158 | digitalWrite(DIGITAL_PIN_LED, LOW);
159 | delay(100);
160 | }
161 | digitalWrite(DIGITAL_PIN_LED, LOW);
162 | }
163 |
164 | void calibrationCount(int aux1, int aux2) {
165 | static uint8_t preAux2 = 0;
166 |
167 | // Don't do anything if ARMED
168 | if (aux1 != 0) {
169 | aux2cnt = 0;
170 | preAux2 = 0;
171 | return;
172 | }
173 |
174 | else{
175 | // Start timer window // Arm = DISARMED
176 | if (aux2cnt == 0) {
177 | calibrationTimerStart = millis();
178 | }
179 |
180 | // Timeout
181 | if (calibrationTimerStart + CALIB_TMO > millis()) {
182 | aux2cnt = 0;
183 | preAux2 = 0;
184 | return;
185 | }
186 |
187 | // Analyze AUX2 switch, count only one side of the switch
188 | if (aux2 == 1 && preAux2 == 0) {
189 | aux2cnt++;
190 | preAux2 = 1;
191 | } else if (aux2 == 0 && preAux2 == 1) {
192 | preAux2 = 0;
193 | }
194 | }
195 | }
196 |
197 | bool calibrationRequested() {
198 | //return aux2cnt > CALIB_CNT;
199 | return calStatus;
200 | }
201 |
202 | bool calibrationProcess() {
203 | aux2cnt = 0;
204 |
205 | //calibrationChirp(2); // start calibration
206 |
207 | // Reset variables to "centers"
208 |
209 | while(cal_reset<1){
210 | const int centerValue = (1023 - ANALOG_CUTOFF - ANALOG_CUTOFF) / 2;
211 | calValues.aileronMin = centerValue;
212 | calValues.aileronMax = centerValue;
213 | calValues.aileronCenter = centerValue;
214 | calValues.elevatorMin = centerValue;
215 | calValues.elevatorMax = centerValue;
216 | calValues.elevatorCenter = centerValue;
217 | calValues.thrMin = centerValue;
218 | calValues.thrMax = centerValue;
219 | calValues.rudderMin = centerValue;
220 | calValues.rudderMax = centerValue;
221 | calValues.rudderCenter = centerValue;
222 | cal_reset++;
223 | }
224 |
225 | currentMillis = millis();
226 |
227 | if (currentMillis CALIB_CENT_TMO && currentMillis < CALIB_TMO){
252 | //while ((calibrationTimerStart + CALIB_TMO ) < millis()) {
253 | // A Min-Max
254 | int val = analogRead(analogInPinAileron);
255 | if (val < calValues.aileronMin) {
256 | calValues.aileronMin = val;
257 | }
258 | if (val > calValues.aileronMax) {
259 | calValues.aileronMax = val;
260 | }
261 | // E Min-Max
262 | val = analogRead(analogInPinElevator);
263 | if (val < calValues.elevatorMin) {
264 | calValues.elevatorMin = val;
265 | }
266 | if (val > calValues.elevatorMax) {
267 | calValues.elevatorMax = val;
268 | }
269 |
270 | // T Min-Max
271 | val = analogRead(analogInPinThrottle);
272 | if (val < calValues.thrMin) {
273 | calValues.thrMin = val;
274 | }
275 | if (val > calValues.thrMax) {
276 | calValues.thrMax = val;
277 | }
278 |
279 | // R Min-Max
280 | val = analogRead(analogInPinRudder);
281 | if (val < calValues.rudderMin) {
282 | calValues.rudderMin = val;
283 | }
284 | if (val > calValues.rudderMax) {
285 | calValues.rudderMax = val;
286 | }
287 |
288 | // Double beep and blink every 500ms
289 | if (millis() % 500 == 0) {
290 | // calibrationChirp(2);
291 | }
292 | Serial.print("Mover stick full range: Aileron_Min:");
293 | Serial.print(calValues.aileronMin);
294 | Serial.print(" Max:");
295 | Serial.print(calValues.aileronMax);
296 | Serial.print(" ElevatorMin:");
297 | Serial.print(calValues.elevatorMin);
298 | Serial.print(" Max:");
299 | Serial.print(calValues.elevatorMax);
300 | Serial.print(" RudderMin:");
301 | Serial.print(calValues.rudderMin);
302 | Serial.print(" Max:");
303 | Serial.print(calValues.rudderMax);
304 | Serial.print(" ThrottleMin:");
305 | Serial.print(calValues.thrMin);
306 | Serial.print(" Max:");
307 | Serial.print(calValues.thrMax);
308 | Serial.println();
309 |
310 |
311 | }
312 | else {
313 | Serial.println("Calibration Done");
314 | calibrationSave();
315 | calStatus = false;
316 | }
317 | return true;
318 |
319 | }
320 |
321 | void calibrationRun(int aux1, int aux2) {
322 | if (calibrationRequested()) {
323 | //calibrationReset();
324 | if (calibrationProcess()) {
325 | //calibrationSave();
326 | //calibrationChirp(3); // ok
327 | // Serial.println("Calibration OK");
328 | } else {
329 | //calibrationReset();
330 | // calibrationChirp(10); // error
331 | Serial.println("Calibration error!");
332 | }
333 | } else {
334 | calibrationCount(aux1, aux2);
335 | }
336 | }
337 |
338 | // -----------------------------------------------------------------------------------------------------
339 |
340 | void selectSetting() {
341 | // startup stick commands (rate/power selection / initiate bind / turn on tx module wifi)
342 | // Right stick:
343 | // Up Left - Rate/Power setting 1 (250hz / 100mw / Dynamic)
344 | // Up Right - Rate/Power setting 2 (50hz / 100mw)
345 | // Down Left - Start TX bind (for 3.4.2 it is now possible to bind to RX easily). Power cycle after binding
346 | // Down Right - Start TX module wifi (for firmware update etc)
347 |
348 | if (rcChannels[AILERON] < RC_MIN_COMMAND && rcChannels[ELEVATOR] > RC_MAX_COMMAND) { // Elevator up + aileron left
349 | currentPktRate = SETTING_1_PktRate;
350 | currentPower = SETTING_1_Power;
351 | currentDynamic = SETTING_1_Dynamic;
352 | currentSetting = 1;
353 | } else if (rcChannels[AILERON] > RC_MAX_COMMAND && rcChannels[ELEVATOR] > RC_MAX_COMMAND) { // Elevator up + aileron right
354 | currentPktRate = SETTING_2_PktRate;
355 | currentPower = SETTING_2_Power;
356 | currentDynamic = SETTING_2_Dynamic;
357 | currentSetting = 2;
358 | } else if (rcChannels[AILERON] < RC_MIN_COMMAND && rcChannels[ELEVATOR] < RC_MIN_COMMAND) { // Elevator down + aileron left
359 | currentSetting = 3; // Bind
360 | } else if (rcChannels[AILERON] > RC_MAX_COMMAND && rcChannels[ELEVATOR] < RC_MIN_COMMAND) { // Elevator down + aileron right
361 | currentSetting = 4; // TX Wifi
362 | } else {
363 | currentSetting = 0;
364 | }
365 | }
366 |
367 | bool checkStickMove(){
368 | // check if stick moved, warring after 10 minutes
369 | if(abs(previous_throttle - rcChannels[THROTTLE]) < 30){
370 | stickMoved = 0;
371 | //Serial.println(abs(previous_throttle - rcChannels[THROTTLE]));
372 | }else{
373 | previous_throttle = rcChannels[THROTTLE];
374 | stickMovedMillis = millis();
375 | stickMoved = 1;
376 | }
377 |
378 | if (millis() - stickMovedMillis > STICK_ALARM_TIME){
379 | // Serial.println((millis() - stickMovedMillis));
380 | return true;
381 | }else{
382 | return false;
383 | }
384 | }
385 |
386 | void setup()
387 | {
388 | // inialize rc data
389 | for (uint8_t i = 0; i < CRSF_MAX_CHANNEL; i++) {
390 | rcChannels[i] = CRSF_DIGITAL_CHANNEL_MIN;
391 | }
392 |
393 | analogReference(EXTERNAL);
394 | pinMode(DIGITAL_PIN_SWITCH_ARM, INPUT_PULLUP);
395 | #ifdef USE_3POS_SWITCH_AS_CHANNEL_6
396 | pinMode(DIGITAL_PIN_SWITCH_AUX2_HIGH, INPUT_PULLUP);
397 | pinMode(DIGITAL_PIN_SWITCH_AUX2_LOW, INPUT_PULLUP);
398 | #else
399 | pinMode(DIGITAL_PIN_SWITCH_AUX2, INPUT_PULLUP);
400 | #endif
401 | pinMode(DIGITAL_PIN_SWITCH_AUX3, INPUT_PULLUP);
402 | if (DIGITAL_PIN_SWITCH_AUX4 != 0){
403 | pinMode(DIGITAL_PIN_SWITCH_AUX4, INPUT_PULLUP);
404 | }
405 | pinMode(DIGITAL_PIN_LED, OUTPUT); // LED
406 | pinMode(DIGITAL_PIN_BUZZER, OUTPUT); // BUZZER
407 | #ifdef PASSIVE_BUZZER
408 | digitalWrite(DIGITAL_PIN_BUZZER, LOW); // BUZZER OFF
409 | if(STARTUP_MELODY!=""){
410 | rtttl::begin(DIGITAL_PIN_BUZZER, STARTUP_MELODY);
411 | }
412 | #endif
413 | // inialize voltage:
414 | batteryVoltage = 0.0;
415 | #ifdef PPMOUTPUT
416 | pinMode(ppmPin, OUTPUT);
417 | digitalWrite(ppmPin, !onState); // set the PPM signal pin to the default state (off)
418 | cli();
419 | TCCR1A = 0; // set entire TCCR1 register to 0
420 | TCCR1B = 0;
421 | OCR1A = 100; // compare match register, change this
422 | TCCR1B |= (1 << WGM12); // turn on CTC mode
423 | TCCR1B |= (1 << CS11); // 8 prescaler: 0,5 microseconds at 16mhz
424 | TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
425 | sei();
426 | #endif
427 |
428 | #ifdef PASSIVE_BUZZER
429 | if(STARTUP_MELODY!="") {
430 | while( !rtttl::done() ) {
431 | rtttl::play();
432 | }
433 | }
434 | else {
435 | delay(2000); // Give enough time for uploading firmware (2 seconds)
436 | }
437 | #else
438 | digitalWrite(DIGITAL_PIN_BUZZER, LOW); //BUZZER ON
439 | delay(100); // beep
440 | digitalWrite(DIGITAL_PIN_BUZZER, HIGH); //BUZZER OFF
441 | delay(200);
442 | digitalWrite(DIGITAL_PIN_BUZZER, LOW); //BUZZER ON
443 | delay(100); // beep
444 | digitalWrite(DIGITAL_PIN_BUZZER, HIGH); //BUZZER OFF
445 | delay(200);
446 | digitalWrite(DIGITAL_PIN_BUZZER, LOW); //BUZZER ON
447 | delay(200); // beep
448 | digitalWrite(DIGITAL_PIN_BUZZER, HIGH); //BUZZER OFF
449 | delay(2000); // Give enough time for uploading firmware (2 seconds)
450 | #endif
451 |
452 | #ifdef DEBUG
453 | Serial.begin(115200);
454 |
455 | #else
456 | crsfClass.begin();
457 | #endif
458 |
459 | #ifdef GIMBAL_CALIBRATION
460 | Serial.begin(115200);
461 | //calibrationReset();
462 | calStatus = true;
463 | Serial.println("Start Calibration");
464 | #endif
465 |
466 | digitalWrite(DIGITAL_PIN_LED, HIGH); // LED ON
467 |
468 | //calibrationReset();
469 | calibrationLoad();
470 | }
471 |
472 | void loop()
473 | {
474 | // melody player needs to be first in the loop in order to play correctly.
475 | rtttl::play();
476 |
477 | #ifdef GIMBAL_CALIBRATION
478 | if(calStatus ){
479 | calibrationRun(AUX1_Arm, AUX2_value);
480 | }
481 | #endif
482 | uint32_t currentMicros = micros();
483 |
484 | // Read Voltage
485 | batteryVoltage = analogRead(VOLTAGE_READ_PIN) / VOLTAGE_SCALE; //98.5
486 | #ifdef DEBUG
487 | Serial.print("batteryVoltage:");
488 | Serial.print(batteryVoltage);
489 | Serial.print("v ");
490 | #endif
491 | if (batteryVoltage < WARNING_VOLTAGE && batteryVoltage >= BEEPING_VOLTAGE) {
492 | blinkLED(DIGITAL_PIN_LED, 1000);
493 | }else if(batteryVoltage < BEEPING_VOLTAGE && batteryVoltage >= ON_USB){
494 | blinkLED(DIGITAL_PIN_LED, 250);
495 | playingTones(2);
496 | }else if(currentSetting == 3){
497 | blinkLED(DIGITAL_PIN_LED, 100); // Bind (fast flash)
498 | }else if(currentSetting == 4){
499 | blinkLED(DIGITAL_PIN_LED, 1000); // Wifi (slow flash)
500 | }
501 |
502 | if (checkStickMove() == true){
503 | blinkLED(DIGITAL_PIN_LED, 100);
504 | playingTones(5);
505 | }
506 | #ifdef PASSIVE_BUZZER
507 | else { // Stop the stick warning tone if you move the sticks
508 | if ( rtttl::isPlaying() ) {
509 | rtttl::stop();
510 | }
511 | }
512 | #endif
513 |
514 | /*
515 | * Handle analog input
516 | */
517 | // constrain to avoid overflow
518 | int analogVal = analogRead(analogInPinAileron);
519 | if (analogVal <= calValues.aileronCenter){
520 | Aileron_value = map(analogVal,calValues.aileronMin, calValues.aileronCenter, ADC_MIN, ADC_MID);
521 | }
522 | else{
523 | Aileron_value = map(analogVal,calValues.aileronCenter, calValues.aileronMax, ADC_MID+1, ADC_MAX);
524 | }
525 |
526 | analogVal = analogRead(analogInPinElevator);
527 | if (analogVal <= calValues.elevatorCenter){
528 | Elevator_value = map(analogVal,calValues.elevatorMin, calValues.elevatorCenter, ADC_MIN, ADC_MID);
529 | }
530 | else{
531 | Elevator_value = map(analogVal,calValues.elevatorCenter, calValues.elevatorMax, ADC_MID+1, ADC_MAX);
532 | }
533 |
534 | analogVal = analogRead(analogInPinThrottle);
535 | Throttle_value = map(analogVal, calValues.thrMax, calValues.thrMin, ADC_MIN, ADC_MAX);
536 |
537 | analogVal = analogRead(analogInPinRudder);
538 | if (analogVal <= calValues.rudderCenter){
539 | Rudder_value = map(analogVal,calValues.rudderMin, calValues.rudderCenter, ADC_MIN, ADC_MID);
540 | }
541 | else{
542 | Rudder_value = map(analogVal,calValues.rudderCenter, calValues.rudderMax, ADC_MID+1, ADC_MAX);
543 | }
544 |
545 | //Constrain value to avoid overflow
546 | Aileron_value = constrain(Aileron_value, ADC_MIN, ADC_MAX);
547 | Elevator_value = constrain(Elevator_value, ADC_MIN, ADC_MAX);
548 | Throttle_value = constrain(Throttle_value, ADC_MIN, ADC_MAX);
549 | Rudder_value = constrain(Rudder_value, ADC_MIN, ADC_MAX);
550 |
551 | //Handdle reverse
552 | if (Is_Aileron_Reverse == 1){
553 | Aileron_value = 1023-Aileron_value;
554 | }
555 | if (Is_Elevator_Reverse == 1){
556 | Elevator_value = 1023-Elevator_value;
557 | }
558 | if (Is_Throttle_Reverse == 1){
559 | Throttle_value = 1023-Throttle_value;
560 | }
561 | if (Is_Rudder_Reverse == 1){
562 | Rudder_value = 1023-Rudder_value;
563 | }
564 | // rcChannels[AILERON] = map(Aileron_value, 1023 - ANALOG_CUTOFF, ANALOG_CUTOFF, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); // reverse
565 | // rcChannels[ELEVATOR] = map(Elevator_value, 1023 - ANALOG_CUTOFF, ANALOG_CUTOFF, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); // reverse
566 | // rcChannels[THROTTLE] = map(Throttle_value, 1023 - ANALOG_CUTOFF, ANALOG_CUTOFF, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX); // reverse
567 | // rcChannels[RUDDER] = map(Rudder_value, ANALOG_CUTOFF, 1023 - ANALOG_CUTOFF, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX);
568 | rcChannels[AILERON] = map(Aileron_value, ADC_MIN, ADC_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX);
569 | rcChannels[ELEVATOR] = map(Elevator_value, ADC_MIN, ADC_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX);
570 | rcChannels[THROTTLE] = map(Throttle_value, ADC_MIN, ADC_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX);
571 | rcChannels[RUDDER] = map(Rudder_value, ADC_MIN, ADC_MAX, CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX);
572 |
573 | /*
574 | * Handel digital input
575 | */
576 | AUX1_Arm = digitalRead(DIGITAL_PIN_SWITCH_ARM);
577 | #ifdef USE_3POS_SWITCH_AS_CHANNEL_6
578 | AUX2_value_HIGH= digitalRead(DIGITAL_PIN_SWITCH_AUX2_HIGH);
579 | AUX2_value_LOW = digitalRead(DIGITAL_PIN_SWITCH_AUX2_LOW);
580 | #else
581 | AUX2_value = digitalRead(DIGITAL_PIN_SWITCH_AUX2);
582 | #endif
583 | AUX3_value = digitalRead(DIGITAL_PIN_SWITCH_AUX3);
584 | if (DIGITAL_PIN_SWITCH_AUX4 != 0){
585 | AUX4_value = digitalRead(DIGITAL_PIN_SWITCH_AUX4);
586 | }else {
587 | AUX4_value = 0;
588 | }
589 |
590 | // Aux Channels
591 | rcChannels[AUX1] = (AUX1_Arm == 1) ? CRSF_DIGITAL_CHANNEL_MIN : CRSF_DIGITAL_CHANNEL_MAX;
592 | #ifdef USE_3POS_SWITCH_AS_CHANNEL_6
593 | rcChannels[AUX2] = (AUX2_value_HIGH == 0) ? CRSF_DIGITAL_CHANNEL_MAX :
594 | (AUX2_value_LOW == 0) ? CRSF_DIGITAL_CHANNEL_MIN :
595 | CRSF_DIGITAL_CHANNEL_MID;
596 | #else
597 | rcChannels[AUX2] = (AUX2_value == 1) ? CRSF_DIGITAL_CHANNEL_MIN : CRSF_DIGITAL_CHANNEL_MAX;
598 | #endif
599 | rcChannels[AUX3] = (AUX3_value == 1) ? CRSF_DIGITAL_CHANNEL_MIN : CRSF_DIGITAL_CHANNEL_MAX;
600 | if (DIGITAL_PIN_SWITCH_AUX4 != 0){
601 | rcChannels[AUX4] = (AUX4_value == 1) ? CRSF_DIGITAL_CHANNEL_MIN : CRSF_DIGITAL_CHANNEL_MAX;
602 | }
603 | if(stickInt=0){
604 | previous_throttle=rcChannels[THROTTLE];
605 | stickInt=1;
606 | }
607 | if (loopCount == 0) {
608 | // Check if sticks are held in specific position on startup (bind/wifi/packet rate select)
609 | selectSetting();
610 | }
611 |
612 | if (currentMicros > crsfTime) {
613 | #ifdef DEBUG
614 | //Serial.println("DEBUG");
615 | Serial.print(" AILERON:");
616 | Serial.print(rcChannels[AILERON]);
617 | Serial.print(" ELEVATOR:");
618 | Serial.print(rcChannels[ELEVATOR] );
619 | Serial.print(" THROTTLE:");
620 | Serial.print(rcChannels[THROTTLE]);
621 | Serial.print(" RUDDER:");
622 | Serial.print(rcChannels[RUDDER] );
623 | Serial.print(" stickstatus:");
624 | Serial.print(stickMoved);
625 | Serial.print(" previous_throttle:");
626 | Serial.print(previous_throttle);
627 | Serial.println();
628 | #else
629 | if (loopCount <= 500) { // repeat 500 packets to build connection to TX module
630 | // Build commond packet
631 | crsfClass.crsfPrepareDataPacket(crsfPacket, rcChannels);
632 | crsfClass.CrsfWritePacket(crsfPacket, CRSF_PACKET_SIZE);
633 | loopCount++;
634 | }
635 |
636 | if (loopCount > 500 && loopCount <= 505) { // repeat 5 packets to avoid bad packet, change rate setting
637 | // Build commond packet
638 | if (currentSetting == 1 || currentSetting == 2) {
639 | crsfClass.crsfPrepareCmdPacket(crsfCmdPacket, ELRS_PKT_RATE_COMMAND, currentPktRate);
640 | crsfClass.CrsfWritePacket(crsfCmdPacket, CRSF_CMD_PACKET_SIZE);
641 | } else if (currentSetting == 3) {
642 | crsfClass.crsfPrepareCmdPacket(crsfCmdPacket, ELRS_BIND_COMMAND, ELRS_START_COMMAND);
643 | crsfClass.CrsfWritePacket(crsfCmdPacket, CRSF_CMD_PACKET_SIZE);
644 | } else if (currentSetting == 4) {
645 | crsfClass.crsfPrepareCmdPacket(crsfCmdPacket, ELRS_WIFI_COMMAND, ELRS_START_COMMAND);
646 | crsfClass.CrsfWritePacket(crsfCmdPacket, CRSF_CMD_PACKET_SIZE);
647 | }
648 | loopCount++;
649 | } else if (loopCount > 505 && loopCount <= 510) { // repeat 5 packets to avoid bad packet, change TX power level
650 | if (currentSetting == 1 || currentSetting == 2) {
651 | crsfClass.crsfPrepareCmdPacket(crsfCmdPacket, ELRS_POWER_COMMAND, currentPower);
652 | crsfClass.CrsfWritePacket(crsfCmdPacket, CRSF_CMD_PACKET_SIZE);
653 | }
654 | loopCount++;
655 | } else if (loopCount > 510 && loopCount <= 515) { // repeat 5 packets to avoid bad packet, change TX dynamic power setting
656 | if (currentSetting == 1 || currentSetting == 2) {
657 | crsfClass.crsfPrepareCmdPacket(crsfCmdPacket, ELRS_DYNAMIC_POWER_COMMAND, currentDynamic);
658 | crsfClass.CrsfWritePacket(crsfCmdPacket, CRSF_CMD_PACKET_SIZE);
659 | }
660 | loopCount++;
661 | } else {
662 | crsfClass.crsfPrepareDataPacket(crsfPacket, rcChannels);
663 | crsfClass.CrsfWritePacket(crsfPacket, CRSF_PACKET_SIZE);
664 | }
665 |
666 | #endif
667 | crsfTime = currentMicros + CRSF_TIME_BETWEEN_FRAMES_US;
668 | }
669 | }
670 |
671 | ISR(TIMER1_COMPA_vect) { // leave this alone
672 | static boolean state = true;
673 |
674 | TCNT1 = 0;
675 |
676 | if (state) { // start pulse
677 | digitalWrite(ppmPin, onState);
678 | OCR1A = PULSE_LENGTH * 2;
679 | state = false;
680 | } else { // end pulse and calculate when to start the next pulse
681 | static byte cur_chan_numb;
682 | static unsigned int calc_rest;
683 |
684 | digitalWrite(ppmPin, !onState);
685 | state = true;
686 |
687 | if (cur_chan_numb >= CHANNEL_NUMBER) {
688 | cur_chan_numb = 0;
689 | calc_rest = calc_rest + PULSE_LENGTH; //
690 | OCR1A = (FRAME_LENGTH - calc_rest) * 2;
691 | calc_rest = 0;
692 | } else {
693 | OCR1A = (map(rcChannels[cur_chan_numb], CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX, 1000, 2000) - PULSE_LENGTH) * 2;
694 | calc_rest = calc_rest + map(rcChannels[cur_chan_numb], CRSF_DIGITAL_CHANNEL_MIN, CRSF_DIGITAL_CHANNEL_MAX, 1000, 2000);
695 | cur_chan_numb++;
696 | }
697 | }
698 | }
699 |
--------------------------------------------------------------------------------
/SimpleTX/config.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Simple TX
3 | *
4 | * Simple TX is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Simple TX is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Cleanflight. If not, see .
16 | */
17 |
18 | //#define USE_M7
19 |
20 | /*
21 | =======================================================================================================
22 | Simple TX CONFIG OPTIONS (comment out unneeded options)
23 | =======================================================================================================
24 | */
25 | // Define analogy input limite
26 |
27 | #define ADC_MIN 0
28 | #define ADC_MID 511
29 | #define ADC_MAX 1023
30 |
31 | #define USE_3POS_SWITCH_AS_CHANNEL_6
32 |
33 | #define ANALOG_CUTOFF 150 // cut off lower and upper end to avoid un-symmetric joystick range in trade off resolution
34 |
35 | // Define RC input Offset
36 | #ifdef USE_M7
37 | // M7
38 | int Aileron_OFFSET = -46;
39 | int Elevator_OFFSET = 57;
40 | int Throttle_OFFSET = 0;
41 | int Rudder_OFFSET = -18;
42 | #else
43 | // stat war
44 | int Aileron_OFFSET = 0;
45 | int Elevator_OFFSET = 0;
46 | int Throttle_OFFSET = 0;
47 | int Rudder_OFFSET = 0;
48 | #endif
49 |
50 | // Define Reverse 1=reverse
51 | int Is_Aileron_Reverse =1;
52 | int Is_Elevator_Reverse =0;
53 | int Is_Throttle_Reverse =0;
54 | int Is_Rudder_Reverse =0;
55 | int Is_Arm_Reverse =0;
56 |
57 | // IO setup
58 | // pins that used for the Joystick
59 | const int analogInPinAileron = A4;
60 | const int analogInPinElevator = A3;
61 | const int analogInPinThrottle = A2;
62 | const int analogInPinRudder = A1;
63 | const int VOLTAGE_READ_PIN = A0;
64 |
65 | // pins that used for the switch
66 | const int DIGITAL_PIN_SWITCH_ARM = 4; // Arm switch
67 | #ifdef USE_3POS_SWITCH_AS_CHANNEL_6
68 | const int DIGITAL_PIN_SWITCH_AUX2_HIGH = 3; // 3 stage switch for mode setup
69 | const int DIGITAL_PIN_SWITCH_AUX2_LOW = 8; //
70 | #else
71 | const int DIGITAL_PIN_SWITCH_AUX2 = 3;
72 | #endif
73 | const int DIGITAL_PIN_SWITCH_AUX3 = 2; //
74 | // If the following line is uncommented, the 3 position switch will send low/mid/high on channel 6
75 | // Alternatively it will send one position as Ch6 high, middle as nothing, 3rd position as ch7 high
76 | const int DIGITAL_PIN_SWITCH_AUX4 = 5; //set to 0 if not use AUX4
77 |
78 | // pins that used for output
79 | const int DIGITAL_PIN_LED = 7;
80 |
81 | // pins that used for buzzer
82 | // Active buzzer only plays one tone (often used on Flight controllers as a beeper)
83 | #define ACTIVE_BUZZER
84 | //#define PASSIVE_BUZZER
85 | const int DIGITAL_PIN_BUZZER = 6;
86 |
87 | // If using a passive buzzer, you can enjoy an RTTTL melody on startup (set to "" to disable)
88 | // if using other melodies from bluejay etc. note that the first three parameters need to be in this order:
89 | // d=,o=,b= (bluejay melodies are often in different order)
90 | #ifdef PASSIVE_BUZZER
91 | const char * STARTUP_MELODY = "Melody:d=32,o=4,b=570:4b,p,4e5,p,4b,p,4f#5,2p,4e5,2b5,8b5,1p,8e4,2p,8f#5";
92 | const char * STICK_MOVE_WARNING ="tetris:d=4,o=5,b=160:e6,8b,8c6,8d6,16e6,16d6,8c6,8b,a,8a,8c6,e6,8d6,8c6,b,8b,8c6,d6,e6,c6,a,2a,8p,d6,8f6,a6,8g6,8f6,e6,8e6,8c6,e6,8d6,8c6,b,8b,8c6,d6,e6,c6,a,a";
93 | #endif
94 | //----- Voltage monitoring -------------------------
95 | // Define battery warning voltage
96 | const float VOLTAGE_SCALE = 103.0;
97 | const float WARNING_VOLTAGE = 7.4; // 2S Lipo 3.7v per cell
98 | const float BEEPING_VOLTAGE = 7.0; // 2S Lipo 3.5v per cell
99 | const float ON_USB = 5.2; // On USB power / no battery
100 |
101 | // Define Commond for start Up Setting
102 | #define RC_MIN_COMMAND 600
103 | #define RC_MAX_COMMAND 1400
104 |
105 | // Define stick unmove alarm time
106 | #define STICK_ALARM_TIME 300000 // 300s or 5 minutes
107 |
108 | // ELRS 3.x (ESP8266 based TX module): with thanks to r-u-t-r-A (https://github.com/r-u-t-r-A/STM32-ELRS-Handset/tree/v4.5)
109 | // 1 : Set Lua [Packet Rate]= 0 - 50Hz / 1 - 100Hz Full / 2- 150Hz / 3 - 250Hz / 4 - 333Hz Full / 5 - 500Hz
110 | // 2 : Set Lua [Telem Ratio]= 0 - Std / 1 - Off / 2 - 1:128 / 3 - 1:64 / 4 - 1:32 / 5 - 1:16 / 6 - 1:8 / 7 - 1:4 / 8 - 1:2 / 9 - Race
111 | // 3 : Set Lua [Switch Mode]=0 -> Hybrid;Wide
112 | // 4 : Set Lua [Model Match]=0 -> Off;On
113 | // 5 : Set Lua [TX Power]=0 Submenu
114 | // 6 : Set Lua [Max Power]=0 - 10mW / 1 - 25mW / 2 - 50mW /3 - 100mW/4 - 250mW // dont force to change, but change after reboot if last power was greater
115 | // 7 : Set Lua [Dynamic]=0 - Off / 1 - Dyn / 2 - AUX9 / 3 - AUX10 / 4 - AUX11 / 5 - AUX12
116 | // 8 : Set Lua [VTX Administrator]=0 Submenu
117 | // 9 : Set Lua [Band]=0 -> Off;A;B;E;F;R;L
118 | // 10: Set Lua [Channel]=0 -> 1;2;3;4;5;6;7;8
119 | // 11 : Set Lua [Pwr Lvl]=0 -> -;1;2;3;4;5;6;7;8
120 | // 12 : Set Lua [Pitmode]=0 -> Off;On
121 | // 13 : Set Lua [Send VTx]=0 sending response for [Send VTx] chunk=0 step=2
122 | // 14 : Set Lua [WiFi Connectivity]=0 Submenu
123 | // 15 : Set Lua [Enable WiFi]=0 sending response for [Enable WiFi] chunk=0 step=0
124 | // 16 : Set Lua [Enable Rx WiFi]=0 sending response for [Enable Rx WiFi] chunk=0 step=2
125 | // //17 : Set Lua [BLE Joystick]=0 sending response for [BLE Joystick] chunk=0 step=0 // not on ESP8266??
126 | // // Set Lua [BLE Joystick]=1 sending response for [BLE Joystick] chunk=0 step=3
127 | // // Set Lua [BLE Joystick]=2 sending response for [BLE Joystick] chunk=0 step=3
128 | // 17: Set Lua [Bind]=0 ->
129 |
130 | // 3 Default Settings
131 | #define SETTING_1_PktRate 3 // 250Hz (-108dB)
132 | #define SETTING_1_Power 1 // 25mW
133 | #define SETTING_1_Dynamic 1 // Dynamic power on
134 |
135 | #define SETTING_2_PktRate 0 // 50Hz (-115dB)
136 | #define SETTING_2_Power 3 // 100mW
137 | #define SETTING_2_Dynamic 0 // Dynamic power off
138 |
139 | enum chan_order
140 | {
141 | AILERON,
142 | ELEVATOR,
143 | THROTTLE,
144 | RUDDER,
145 | AUX1, // (CH5) ARM switch for Expresslrs
146 | AUX2, // (CH6) angel / airmode change
147 | AUX3, // (CH7) flip after crash
148 | AUX4, // (CH8)
149 | AUX5, // (CH9)
150 | AUX6, // (CH10)
151 | AUX7, // (CH11)
152 | AUX8, // (CH12)
153 | };
154 |
155 | //#define PPMOUTPUT
156 | //-------------------- PPM Config-------------------------
157 | #define CHANNEL_NUMBER 12 // set the number of chanels
158 | #define CHANNEL_DEFAULT_VALUE 1500 // set the default servo value
159 | #define FRAME_LENGTH 22500 // set the PPM frame length in microseconds (1ms = 1000µs)
160 | #define PULSE_LENGTH 300 // set the pulse length
161 | #define onState 1 // set polarity of the pulses: 1 is positive, 0 is negative
162 | #define ppmPin 2 // set PPM signal output pin on the arduino
163 |
--------------------------------------------------------------------------------
/SimpleTX/crsf.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Simple TX
3 | *
4 | * Simple TX is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Simple TX is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Cleanflight. If not, see .
16 | */
17 | /*
18 | =======================================================================================================
19 | * CRSF protocol
20 | *
21 | * CRSF protocol uses a single wire half duplex uart connection.
22 | * The master sends one frame every 4ms and the slave replies between two frames from the master.
23 | *
24 | * 420000 baud
25 | * not inverted
26 | * 8 Bit
27 | * 1 Stop bit
28 | * Big endian
29 | * ELRS uses crossfire protocol at many different baud rates supported by EdgeTX i.e. 115k, 400k, 921k, 1.87M, 3.75M
30 | * 115000 bit/s = 14400 byte/s
31 | * 420000 bit/s = 46667 byte/s (including stop bit) = 21.43us per byte
32 | * Max frame size is 64 bytes
33 | * A 64 byte frame plus 1 sync byte can be transmitted in 1393 microseconds.
34 | *
35 | * CRSF_TIME_NEEDED_PER_FRAME_US is set conservatively at 1500 microseconds
36 | *
37 | * Every frame has the structure:
38 | *
39 | *
40 | * Device address: (uint8_t)
41 | * Frame length: length in bytes including Type (uint8_t)
42 | * Type: (uint8_t)
43 | * CRC: (uint8_t)
44 | *
45 | */
46 |
47 | #include "crsf.h"
48 |
49 | // crc implementation from CRSF protocol document rev7
50 | static uint8_t crsf_crc8tab[256] = {
51 | 0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54, 0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
52 | 0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06, 0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
53 | 0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0, 0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
54 | 0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2, 0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
55 | 0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9, 0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
56 | 0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B, 0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
57 | 0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D, 0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
58 | 0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F, 0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
59 | 0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB, 0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
60 | 0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9, 0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
61 | 0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F, 0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
62 | 0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D, 0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
63 | 0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26, 0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
64 | 0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74, 0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
65 | 0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82, 0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
66 | 0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0, 0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9};
67 |
68 | uint8_t crsf_crc8(const uint8_t *ptr, uint8_t len) {
69 | uint8_t crc = 0;
70 | for (uint8_t i = 0; i < len; i++){
71 | crc = crsf_crc8tab[crc ^ *ptr++];
72 | }
73 | return crc;
74 | }
75 |
76 | // Serial begin
77 | void CRSF::begin() {
78 | port.begin(SERIAL_BAUDRATE);
79 | }
80 |
81 | // prepare data packet
82 | void CRSF::crsfPrepareDataPacket(uint8_t packet[], int16_t channels[]) {
83 |
84 | // const uint8_t crc = crsf_crc8(&packet[2], CRSF_PACKET_SIZE-3);
85 | /*
86 | * Map 1000-2000 with middle at 1500 chanel values to
87 | * 173-1811 with middle at 992 S.BUS protocol requires
88 | */
89 |
90 | // packet[0] = UART_SYNC; //Header
91 | packet[0] = ELRS_ADDRESS; // Header
92 | packet[1] = 24; // length of type (24) + payload + crc
93 | packet[2] = TYPE_CHANNELS;
94 | packet[3] = (uint8_t)(channels[0] & 0x07FF);
95 | packet[4] = (uint8_t)((channels[0] & 0x07FF) >> 8 | (channels[1] & 0x07FF) << 3);
96 | packet[5] = (uint8_t)((channels[1] & 0x07FF) >> 5 | (channels[2] & 0x07FF) << 6);
97 | packet[6] = (uint8_t)((channels[2] & 0x07FF) >> 2);
98 | packet[7] = (uint8_t)((channels[2] & 0x07FF) >> 10 | (channels[3] & 0x07FF) << 1);
99 | packet[8] = (uint8_t)((channels[3] & 0x07FF) >> 7 | (channels[4] & 0x07FF) << 4);
100 | packet[9] = (uint8_t)((channels[4] & 0x07FF) >> 4 | (channels[5] & 0x07FF) << 7);
101 | packet[10] = (uint8_t)((channels[5] & 0x07FF) >> 1);
102 | packet[11] = (uint8_t)((channels[5] & 0x07FF) >> 9 | (channels[6] & 0x07FF) << 2);
103 | packet[12] = (uint8_t)((channels[6] & 0x07FF) >> 6 | (channels[7] & 0x07FF) << 5);
104 | packet[13] = (uint8_t)((channels[7] & 0x07FF) >> 3);
105 | packet[14] = (uint8_t)((channels[8] & 0x07FF));
106 | packet[15] = (uint8_t)((channels[8] & 0x07FF) >> 8 | (channels[9] & 0x07FF) << 3);
107 | packet[16] = (uint8_t)((channels[9] & 0x07FF) >> 5 | (channels[10] & 0x07FF) << 6);
108 | packet[17] = (uint8_t)((channels[10] & 0x07FF) >> 2);
109 | packet[18] = (uint8_t)((channels[10] & 0x07FF) >> 10 | (channels[11] & 0x07FF) << 1);
110 | packet[19] = (uint8_t)((channels[11] & 0x07FF) >> 7 | (channels[12] & 0x07FF) << 4);
111 | packet[20] = (uint8_t)((channels[12] & 0x07FF) >> 4 | (channels[13] & 0x07FF) << 7);
112 | packet[21] = (uint8_t)((channels[13] & 0x07FF) >> 1);
113 | packet[22] = (uint8_t)((channels[13] & 0x07FF) >> 9 | (channels[14] & 0x07FF) << 2);
114 | packet[23] = (uint8_t)((channels[14] & 0x07FF) >> 6 | (channels[15] & 0x07FF) << 5);
115 | packet[24] = (uint8_t)((channels[15] & 0x07FF) >> 3);
116 |
117 | packet[25] = crsf_crc8(&packet[2], packet[1] - 1); // CRC
118 | }
119 |
120 | // prepare elrs setup packet (power, packet rate...)
121 | void CRSF::crsfPrepareCmdPacket(uint8_t packetCmd[], uint8_t command, uint8_t value) {
122 | packetCmd[0] = ELRS_ADDRESS;
123 | packetCmd[1] = 6; // length of Command (4) + payload + crc
124 | packetCmd[2] = TYPE_SETTINGS_WRITE;
125 | packetCmd[3] = ELRS_ADDRESS;
126 | packetCmd[4] = ADDR_RADIO;
127 | packetCmd[5] = command;
128 | packetCmd[6] = value;
129 | packetCmd[7] = crsf_crc8(&packetCmd[2], packetCmd[1] - 1); // CRC
130 | }
131 |
132 | void CRSF::CrsfWritePacket(uint8_t packet[], uint8_t packetLength) {
133 | port.write(packet, packetLength);
134 | }
135 |
--------------------------------------------------------------------------------
/SimpleTX/crsf.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | /*
5 | * This file is part of Simple TX
6 | *
7 | * Simple TX is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * Simple TX is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with Cleanflight. If not, see .
19 | */
20 |
21 | // Basic setup
22 | #define CRSF_MAX_CHANNEL 16
23 | #define CRSF_FRAME_SIZE_MAX 64
24 | // Device address & type
25 | #define RADIO_ADDRESS 0xEA
26 | // #define ADDR_MODULE 0xEE // Crossfire transmitter
27 | #define TYPE_CHANNELS 0x16
28 |
29 | // Define AUX channel input limite
30 | #define CRSF_DIGITAL_CHANNEL_MIN 172
31 | #define CRSF_DIGITAL_CHANNEL_MAX 1811
32 | #define CRSF_DIGITAL_CHANNEL_MID 992
33 |
34 | // internal crsf variables
35 | #define CRSF_TIME_NEEDED_PER_FRAME_US 1100 // 700 ms + 400 ms for potential ad-hoc request
36 | //#define SERIAL_BAUDRATE 115200 //low baud for Arduino Nano , the TX module will auto detect baud. 115200/400000
37 | //#define CRSF_TIME_BETWEEN_FRAMES_US 4000 // 4 ms 250Hz
38 | #define SERIAL_BAUDRATE 400000
39 | #define CRSF_TIME_BETWEEN_FRAMES_US 1666 // 1.6 ms up to 500Hz
40 | #define CRSF_PAYLOAD_OFFSET offsetof(crsfFrameDef_t, type)
41 | #define CRSF_MSP_RX_BUF_SIZE 128
42 | #define CRSF_MSP_TX_BUF_SIZE 128
43 | #define CRSF_PAYLOAD_SIZE_MAX 60
44 | #define CRSF_PACKET_LENGTH 22
45 | #define CRSF_PACKET_SIZE 26
46 | #define CRSF_FRAME_LENGTH 24 // length of type + payload + crc
47 | #define CRSF_CMD_PACKET_SIZE 8
48 |
49 | // ELRS command
50 | #define ELRS_ADDRESS 0xEE
51 | #define ELRS_PKT_RATE_COMMAND 0x01
52 | #define ELRS_TLM_RATIO_COMMAND 0x02
53 | #define ELRS_SWITCH_MODE_COMMAND 0x03
54 | #define ELRS_MODEL_MATCH_COMMAND 0x04
55 | #define ELRS_POWER_COMMAND 0x06
56 | #define ELRS_DYNAMIC_POWER_COMMAND 0x07
57 | #define ELRS_BLE_JOYSTIC_COMMAND 0x11
58 | #define ELRS_WIFI_COMMAND 0x0F
59 | #define ELRS_BIND_COMMAND 0x11
60 | #define ELRS_START_COMMAND 0x04
61 | #define TYPE_SETTINGS_WRITE 0x2D
62 | #define ADDR_RADIO 0xEA // Radio Transmitter
63 | #define port Serial
64 |
65 | class CRSF {
66 | public:
67 | void begin(void);
68 | void crsfPrepareDataPacket(uint8_t packet[], int16_t channels[]);
69 | void crsfPrepareCmdPacket(uint8_t packetCmd[], uint8_t command, uint8_t value);
70 | void CrsfWritePacket(uint8_t packet[], uint8_t packetLength);
71 | };
72 |
73 | /* ESP32 Team900
74 | https://github.com/danxdz/simpleTx_esp32/blob/master/src/Simple_TX.cpp
75 |
76 | // buildElrsPacket(crsfCmdPacket,X,3);
77 | // 0 : ELRS status request => ??
78 | // 1 : Set Lua [Packet Rate]= 0 - 25Hz / 1 - 50Hz / 2 - 100Hz / 3 - 200Hz
79 | // 2 : Set Lua [Telem Ratio]= 0 - off / 1 - 1:128 / 2 - 1:64 / 3 - 1:32 / 4 - 1:16 / 5 - 1:8 / 6 - 1:4 / 7 - 1:2
80 | // 3 : Set Lua [Switch Mode]=0 -> Hybrid;Wide
81 | // 4 : Set Lua [Model Match]=0 -> Off;On
82 | // 5 : Set Lua [TX Power]=0 - 10mW / 1 - 25mW
83 | // 6 : Set Lua [Max Power]=0 - 10mW / 1 - 25mW *dont force to change, but change after reboot if last power was greater
84 | // 7 : Set Lua [Dynamic]=0 -> Off;On;AUX9;AUX10;AUX11;AUX12 -> * @ ttgo screen
85 | // 8 : Set Lua [VTX Administrator]=0
86 | // 9 : Set Lua [Band]=0 -> Off;A;B;E;F;R;L
87 | // 10: Set Lua [Channel]=0 -> 1;2;3;4;5;6;7;8
88 | // 11: Set Lua [Pwr Lvl]=0 -> -;1;2;3;4;5;6;7;8
89 | // 12: Set Lua [Pitmode]=0 -> Off;On
90 | // 13: Set Lua [Send VTx]=0 sending response for [Send VTx] chunk=0 step=2
91 | // 14: Set Lua [WiFi Connectivity]=0
92 | // 15: Set Lua [Enable WiFi]=0 sending response for [Enable WiFi] chunk=0 step=0
93 | // 16: Set Lua [Enable Rx WiFi]=0 sending response for [Enable Rx WiFi] chunk=0 step=2
94 | // 17: Set Lua [BLE Joystick]=0 sending response for [BLE Joystick] chunk=0 step=0
95 | // Set Lua [BLE Joystick]=1 sending response for [BLE Joystick] chunk=0 step=3
96 | // Set Lua [BLE Joystick]=2 sending response for [BLE Joystick] chunk=0 step=3
97 | // Set Lua [BLE Joystick]=3 sending response for [BLE Joystick] chunk=0 step=3
98 | // Set Lua [BLE Joystick]=4 to enable
99 | // hwTimer stop
100 | // Set Lua [TX Power]=0
101 | // hwTimer interval: 5000
102 | // Adjusted max packet size 22-22
103 | // Starting BLE Joystick!
104 | // 19: Set Lua [Bad/Good]=0
105 | // 20: Set Lua [2.1.0 EU868]=0 =1 ?? get
106 |
107 | 0:Packet Rate:0:9:0:4:4;25Hz(-123dBm):50Hz(-120dBm):100Hz(-117dBm):100Hz Full(-112dBm):200Hz(-112dBm): :: OPT
108 | 1:Telem Ratio:0:9:0:9:0;Std:Off:1:128:1:64:1:32:1:16:1:8:1:4:1:2:Race: :: OPT
109 | 2:Switch Mode:0:9:0:1:0;Wide:Hybrid: :: OPT
110 | 3:Model Match:0:9:0:1:0;Off:On: :: OPT
111 | 4:TX Power (50mW):0:11:0:0:0 :: MainMenuItem
112 | 5:Max Power:5:9:0:2:2;10:25:50: :: OPT
113 | 6:Dynamic:5:9:0:5:0;Off:Dyn:AUX9:AUX10:AUX11:AUX12: :: OPT
114 | 7:VTX Administrator:0:11:0:0:0 :: MainMenuItem
115 | 8:Band:8:9:0:6:0;Off:A:B:E:F:R:L: :: OPT
116 | 9:Channel:8:9:0:7:0;1:2:3:4:5:6:7:8: :: OPT
117 | 10:Pwr Lvl:8:9:0:8:0;-:1:2:3:4:5:6:7:8: :: OPT
118 | 11:Pitmode:8:9:0:8:79;Off:On:AUX1�:AUX1�:AUX2�:AUX2�:AUX3�:AUX3�:AUX Pitmode: :: OPT
119 | 12:Send VTx:8:13:0:0:0 :: CMD
120 | 13:WiFi Connectivity:0:11:0:0:0 :: MainMenuItem
121 | 14:Enable WiFi:14:13:0:0:0 :: CMD
122 | 15:Enable Rx WiFi:14:13:0:0:0 :: CMD
123 | 16:BLE Joystick:0:13:0:0:0 :: CMD
124 | 17:Bind:0:13:0:0:0 :: CMD
125 | 18:Bad/Good:0:12:0:0:0 :: INFO
126 | 19:3.1.2 EU868:0:12:0:0:0 :: INFO
127 |
128 | as menu:
129 |
130 | Main Menu
131 | |- Packet Rate (OPT)
132 | |- 25Hz(-123dBm)
133 | |- 50Hz(-120dBm)
134 | |- 100Hz(-117dBm)
135 | |- 100Hz Full(-112dBm)
136 | |- 200Hz(-112dBm)
137 | |- Telem Ratio (OPT)
138 | |- Std
139 | |- Off
140 | |- 1:128
141 | |- 1:64
142 | |- 1:32
143 | |- 1:16
144 | |- 1:8
145 | |- 1:4
146 | |- 1:2
147 | |- Race
148 | |- Switch Mode (OPT)
149 | |- Wide
150 | |- Hybrid
151 | |- Model Match (OPT)
152 | |- Off
153 | |- On
154 | |- TX Power (50mW)
155 | | |- Max Power (OPT)
156 | | |- 10
157 | | |- 25
158 | | |- 50
159 | |- Dynamic (OPT)
160 | | |- Off
161 | | |- Dyn
162 | | |- AUX9
163 | | |- AUX10
164 | | |- AUX11
165 | | |- AUX12
166 | |- VTX Administrator
167 | | |- Band (OPT)
168 | | |- Off
169 | | |- A
170 | | |- B
171 | | |- E
172 | | |- F
173 | | |- R
174 | | |- L
175 | |- Channel (OPT)
176 | | |- 1
177 | | |- 2
178 | | |- 3
179 | | |- 4
180 | | |- 5
181 | | |- 6
182 | | |- 7
183 | | |- 8
184 | |- Pwr Lvl (OPT)
185 | | |- -
186 | | |- 1
187 | | |- 2
188 | | |- 3
189 | | |- 4
190 | | |- 5
191 | | |- 6
192 | | |- 7
193 | | |- 8
194 | |- Pitmode (OPT)
195 | |- Off
196 | |- On
197 | |- Send VTx
198 | |- WiFi Connectivity
199 | | |- Enable WiFi
200 | |- Enable Rx WiFi
201 | |- BLE Joystick
202 | |- Bind
203 | |- Bad/Good
204 | |- 3.1.2 EU868
205 |
206 |
207 |
208 | */
209 |
--------------------------------------------------------------------------------
/SimpleTX/led.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Simple TX
3 | *
4 | * Simple TX is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Simple TX is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Cleanflight. If not, see .
16 | */
17 |
18 | uint8_t ledState = LOW;
19 | unsigned long previousMillis = 0;
20 |
21 | void blinkLED(int ledPin, uint16_t blinkRate) {
22 | unsigned long currentMillis = millis();
23 |
24 | if (currentMillis - previousMillis >= blinkRate) {
25 | previousMillis = currentMillis; // save the last time you blinked the LED
26 | ledState ^= 1; // if the LED is off turn it on and vice-versa
27 | digitalWrite(ledPin, ledState);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/SimpleTX/tone.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of Simple TX
3 | *
4 | * Simple TX is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * Simple TX is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with Cleanflight. If not, see .
16 | */
17 | //----- global variables for tones generation --------------
18 | unsigned long previousToneMillis = 0;
19 | bool started=false;
20 |
21 | // ----------------------------------------------------------------------------
22 | void playingTones(uint8_t timeSeconde) {
23 | unsigned long currentMillis = millis();
24 |
25 | #ifdef ACTIVE_BUZZER
26 | if (currentMillis - previousToneMillis <= timeSeconde*100) {
27 | digitalWrite(DIGITAL_PIN_BUZZER, LOW);
28 | }else if(currentMillis - previousToneMillis > timeSeconde*100 && currentMillis - previousToneMillis <= timeSeconde*200){
29 | digitalWrite(DIGITAL_PIN_BUZZER, HIGH);
30 | }else if(currentMillis - previousToneMillis > timeSeconde*200 && currentMillis - previousToneMillis <= timeSeconde*300){
31 | digitalWrite(DIGITAL_PIN_BUZZER, LOW);
32 | }else if(currentMillis - previousToneMillis > timeSeconde*300 && currentMillis - previousToneMillis <= 5000){
33 | digitalWrite(DIGITAL_PIN_BUZZER, HIGH);
34 | }else{
35 | previousToneMillis = currentMillis; // save the last time buzzer play tone
36 | digitalWrite(DIGITAL_PIN_BUZZER, 0);
37 | }
38 | #endif
39 |
40 | #ifdef PASSIVE_BUZZER
41 | if ( !rtttl::isPlaying()) {
42 | if ( !started ) { //
43 | if (timeSeconde == 2) { // Low Battery
44 | // The following two tones mimick the old Nokia 3310 battery warning
45 | if (currentMillis - previousToneMillis <= 100) {
46 | tone(DIGITAL_PIN_BUZZER,1568,100);
47 | }else if(currentMillis - previousToneMillis > 100 && currentMillis - previousToneMillis <= 300){
48 | tone(DIGITAL_PIN_BUZZER,784,100);
49 | }else if(currentMillis - previousToneMillis > 300 && currentMillis - previousToneMillis <= 5000){
50 | noTone(DIGITAL_PIN_BUZZER);
51 | }else{
52 | previousToneMillis = currentMillis; // save the last time buzzer play tone
53 | noTone(DIGITAL_PIN_BUZZER);
54 | }
55 | // Tones did not work for the low battery warning
56 | // const char * LOW_BATT_WARNING = "nokia:d=4,o=5,b=140:16g6,8g,16p,16g6,8g,16p,16g6,8g";
57 | // rtttl::begin(DIGITAL_PIN_BUZZER, LOW_BATT_WARNING);
58 | }
59 | else if (timeSeconde == 5) { // Stick move timeout
60 | rtttl::begin(DIGITAL_PIN_BUZZER, STICK_MOVE_WARNING);
61 | started = true;
62 | previousToneMillis = currentMillis; // save the last time buzzer play tone
63 | }
64 | }
65 | else {
66 | if (currentMillis - previousToneMillis > 5000) {
67 | started = false;
68 | }
69 | }
70 | }
71 | #endif
72 |
73 | }
74 |
75 |
--------------------------------------------------------------------------------