├── .gitignore
├── LICENSE
├── README.md
├── examples
├── debug
│ └── debug.ino
└── scan
│ └── scan.ino
├── extra
├── DRA818U.pdf
└── DRA818V.pdf
├── library.properties
└── src
├── DRA818.cpp
└── DRA818.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | # Vim
35 | [._]*.s[a-v][a-z]
36 | [._]*.sw[a-p]
37 | [._]s[a-v][a-z]
38 | [._]sw[a-p]
39 | Session.vim
40 | .netrwhist
41 | *~
42 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER 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 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # arduino_dra818
2 | Arduino library for DRA818 VHF/UHF Band Voice Transceiver.
3 |
4 | Don't bother with the DRA818 API, just plug the RX/TX pin to the arduino, include and you're good to go. You can use either the builtin UART [HardwareSoftware](https://www.arduino.cc/en/Reference/HardwareSoftware) or two digital pins of your choice and the [SoftwareSerial](https://www.arduino.cc/en/Reference/SoftwareSerial) library.
5 |
6 | ## Installation
7 | Download the last release and in arduino IDE, in the menu, select `Sketch` / `Include Library` / `Add .ZIP Library` and choose the downloaded file. You should see DRA sample files.
8 |
9 | ## Usage
10 | :warning: The DRA818 module is powered with 3.3v and use 3.3v TTL. If a 5v arduino is used, you should convert the 5v TX pin of the arduino to the 3.3v RX pin of the DRA818. The arduino RX will be able to detect correct TTL sent as-is (3.3v) from the TX pin of the DRA818.
11 |
12 | You can use this library in the *object style* or with a simple configuration call. Here is a sample code snippet with both usage:
13 | ```
14 | #include
15 | #include
16 |
17 | dra_serial *SoftwareSerial;
18 | dra *DRA818;
19 |
20 | void setup() {
21 | dra_serial = new SoftwareSerial(3, 4); // use pin 3 and 4 for serial communication to DRA818
22 |
23 | // all in one configuration
24 | dra = DRA818::configure(dra_serial, DRA818_VHF, 145.500, 145.500, 4, 8, 0, 0, DRA818_12K5, true, true, true);
25 |
26 | // object-style configuration
27 | dra = new DRA818(dra_serial, DRA818_VHF);
28 | dra->handshake();
29 | dra->group(DRA818_12K5, 145.500, 145.500, 0, 4, 0);
30 | dra->volume(8);
31 | dra->filters(true, true, true);
32 | }
33 | void loop() {
34 | }
35 | ```
36 |
37 | ## API
38 | ### Constructor
39 | #### HardwareSerial
40 | Must be called when a HardwareSerial connection to the DRA818 is used (aka when using the builtin arduino UART).
41 |
42 | ```DRA818(HardwareSerial *serial, uint8_t type);```
43 | * **serial** must be a HardwareSerial object.
44 | * **type** must be the DRA818 version used. Must be any of the following values:
45 | * ```DRA818_VHF```
46 | * ```DRA818_UHF```
47 | #### SoftwareSerial
48 | Must be called when a SoftwareSerial connection to the DRA818 is used (aka when not using the builtin arduino UART but using digital pins).
49 |
50 | ```DRA818(SoftwareSerial *serial, uint8_t type);```
51 | * **serial** must be a SoftwareSerial object.
52 | * **type** must be the DRA818 version used. Must be any of the following values:
53 | * ```DRA818_VHF```
54 | * ```DRA818_UHF```
55 | ### Low level API functions that interact directly with the DRA818 chip
56 | The following functions are simple mappings from the DRA818 protocol.
57 | #### Handshake
58 | It is used to check if the module works normally. DRA818V module will send back response information when it receives this command from the host. It's sent 3 times with a timeout of 2s because the module needs time to start.
59 |
60 | ```int DRA818::handshake();```
61 |
62 | **return value**: 1 on success, 0 otherwise
63 | #### Group
64 | This command is used to configure a group of module parameters. This is the main configuration routine.
65 |
66 | ```int DRA818::group(uint8_t bandwidth, float freq_tx, float freq_rx, uint8_t ctcss_tx, uint8_t squelch, uint8_t ctcss_rx);```
67 | * **bandwidth**
68 | * **freq_tx** is a float that represents the TX frequency. If the value is beyond the module limit (134-174 MHz for VHF and 400-470 MHz for UHF), the value is automaticaly bound to the correct range.
69 | * **freq_rx** is a float that represents the RX frequency. Same rules apply with **freq_tx**
70 | * **ctcss_tx** is the CTCSS TX value. Its value is bounded to the range [0000,0038]
71 | * **squelch** is the squelch of the receiver and it is bounded to the range [0,8]
72 | * **ctcss_rx** is the CTCSS RX value. Its value is bounded to the range [0000,0038]
73 |
74 | **return value**: 1 on success, 0 otherwise
75 | #### Volume
76 | This command is used to adjust the volume of module.
77 |
78 | ** return value**: 1 on success, 0 otherwise
79 |
80 | ```int DRA818::volume(uint8_t volume);```
81 | * **volume** is bounded to the range [1,8]
82 |
83 | **return value**: 1 on success, 0 otherwise
84 | #### Filters
85 | This command is used to turn on/off Pre/de-emphasis, Highpass, Lowpass filter.
86 |
87 | ```int DRA818::filters(bool pre, bool high, bool low);```
88 | * **pre**(true or false) to enable/disable the Pre/de-emphasis filter
89 | * **high**(true or false) to enable/disable the Highpass filter
90 | * **low**(true or false) to enable/disable the Lowpass filter
91 |
92 | **return value**: 1 on success, 0 otherwise
93 | #### Scan
94 | It scans the wanted frequency.
95 |
96 | ```int DRA818::scan(float freq);```
97 | * **freq** is the frequency to scan
98 |
99 | **return value**: 1 if the scanned frequency is active, 0 otherwise
100 | ### All-in-one configuration routine
101 | The static ```configuration``` function can be called to setup the DRA818 all in once without calling different low level API functions without passing with constructor and low level API calls.
102 | #### HardwareSerial
103 | Must be called when a HardwareSerial connection to the DRA818 is used (aka when using the builtin arduino UART).
104 |
105 | ```static DRA818* DRA818::configure(HardwareSerial *serial, uint8_t type, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low);```
106 | * **serial** must be a HardwareSerial object.
107 | * **type** must be the DRA818 version used. Must be any of the following values:
108 | * ```DRA818_VHF```
109 | * ```DRA818_UHF```
110 | * **freq_rx** is a float that represents the RX frequency. Same rules apply with **freq_tx**
111 | * **freq_tx** is a float that represents the TX frequency. If the value is beyond the module limit (134-174 MHz for VHF and 400-470 MHz for UHF), the value is automaticaly bound to the correct range.
112 | * **squelch** is the squelch of the receiver and it is bounded to the range [0,8]
113 | * **volume** is bounded to the range [1,8]
114 | * **ctcss_rx** is the CTCSS RX value. Its value is bounded to the range [0000,0038]
115 | * **ctcss_tx** is the CTCSS TX value. Its value is bounded to the range [0000,0038]
116 | * **bandwidth**
117 | * **pre**(true or false) to enable/disable the Pre/de-emphasis filter
118 | * **high**(true or false) to enable/disable the Highpass filter
119 | * **low**(true or false) to enable/disable the Lowpass filter
120 |
121 | **return value**: a pointer to the generated DRA818 object.
122 | #### SoftwareSerial
123 | Must be called when a SoftwareSerial connection to the DRA818 is used (aka when not using the builtin arduino UART but using digital pins). It's the same call than the previous call with a different serial type (SoftwareSerial instead of HardwareSerial)
124 |
125 | ```static DRA818* DRA818::configure(SoftwareSerial *stream, uint8_t type, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low);```
126 |
127 | ## Debug
128 | Debugging the communication with the DRA818 module is included in the code. It can be used to debug the communication between the arduino and the DRA818 module.
129 |
130 | First, enable debuging in the library by defining `DRA818_DEBUG` in `DRA818.h`. Then the DRA818 class exposes a `set_log(Stream *)` function and the `configure()` function takes another argument (`Stream *log`).
131 | ```
132 | dra = DRA818::configure(dra_serial, DRA818_VHF, 145.500, 145.500, 4, 8, 0, 0, DRA818_12K5, true, true, true, &Serial);
133 | ```
134 | `&Serial` is a pointer to the builtin UART. The DRA818 library will send debug messages. See examples/debug.
135 |
136 | ## Thanks
137 | * [darksidelemm](https://github.com/darksidelemm) for its original module that gave me inspiration for the rewrite of the module: https://github.com/darksidelemm/dra818
138 | * [f4goh](https://github.com/f4goh) for its project and ideas from its code: https://github.com/f4goh/DRAPRS
139 |
140 | ## License
141 |
142 | Copyright (c) Arduino LLC. All right reserved.
143 |
144 | This library is free software; you can redistribute it and/or
145 | modify it under the terms of the GNU Lesser General Public
146 | License as published by the Free Software Foundation; either
147 | version 2.1 of the License, or (at your option) any later version.
148 |
149 | This library is distributed in the hope that it will be useful,
150 | but WITHOUT ANY WARRANTY; without even the implied warranty of
151 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
152 | Lesser General Public License for more details.
153 |
154 | You should have received a copy of the GNU Lesser General Public
155 | License along with this library; if not, write to the Free Software
156 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
157 |
--------------------------------------------------------------------------------
/examples/debug/debug.ino:
--------------------------------------------------------------------------------
1 | /*
2 | debug.ino
3 |
4 | A simple sketch that configure a DRA818V and scan all the frequencies in the
5 | range 134-174 MHz with a step of 12.5 kHz. 3 pins of the arduino are
6 | used (PD, RX and TX) (CAUTION the DRA818 runs @3.3v). Configure the 3 macros
7 | and customize the DRA818::configure(...) call to your needs.
8 |
9 | Define the macro DRA818_DEBUG in DRA818.h and recompile to activate the
10 | debug functions of the library.
11 |
12 | Here is a sample output from the serial connection:
13 |
14 | Booting ...
15 | initializing I/O ... done
16 | initializing DRA818 ... DRA818: log serial connection active
17 | DRA818::handshake
18 | -> AT+DMOCONNECT
19 | <- +DMOCONNECT:0
20 | Returned value=1
21 | DRA818::group
22 | -> AT+DMOSETGROUP=0,145.5000,145.5000,0000,4,0000
23 | <- +DMOSETGROUP:0
24 | Returned value=1
25 | DRA818::volume
26 | -> AT+DMOSETVOLUME=8
27 | <- +DMOSETVOLUME:0
28 | Returned value=1
29 | DRA818::filters
30 | -> AT+SETFILTER=1,1,1
31 | <- +DMOSETFILTER:0
32 | Returned value=1
33 | done
34 | Starting ...
35 | Scanning frequency 134.0000 kHz ...DRA818::scan
36 | -> S+134.0000
37 | <- S=1
38 | Returned value=0
39 |
40 | Scanning frequency 134.0125 kHz ...DRA818::scan
41 | -> S+134.0125
42 | <- S=1
43 | Returned value=0
44 |
45 | I'm using a digital pin (D10) to crontrol the PD pin of the DRA818.
46 | It's not mandatory, you can just let the PD pin of the DRA818
47 | to HIGH and free an arduino digital pin.
48 |
49 |
50 | Copyright (c) 2017, Jerome LOYET
51 |
52 | This library is free software; you can redistribute it and/or
53 | modify it under the terms of the GNU Lesser General Public
54 | License as published by the Free Software Foundation; either
55 | version 2.1 of the License, or (at your option) any later version.
56 |
57 | This library is distributed in the hope that it will be useful,
58 | but WITHOUT ANY WARRANTY; without even the implied warranty of
59 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60 | Lesser General Public License for more details.
61 |
62 | You should have received a copy of the GNU Lesser General Public
63 | License along with this library; if not, write to the Free Software
64 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
65 | */
66 |
67 | #include
68 | #include
69 | #include "DRA818.h" // uncomment the following line in DRA818.h (#define DRA818_DEBUG)
70 |
71 | /* Used Pins */
72 | #define PD 10 // to the DRA818 PD pin
73 | #define RX 3 // arduino serial RX pin to the DRA818 TX pin
74 | #define TX 4 // arduino serial TX pin to the DRA818 RX pin
75 |
76 | SoftwareSerial *dra_serial; // Serial connection to DRA818
77 | DRA818 *dra; // the DRA object once instanciated
78 | float freq; // the next frequency to scan
79 |
80 | void setup(){
81 | Serial.begin(9600); // for logging
82 |
83 | Serial.println("Booting ...");
84 |
85 | Serial.print("initializing I/O ... ");
86 | dra_serial = new SoftwareSerial(RX, TX); // Instantiate the Software Serial Object.
87 | pinMode(PD, OUTPUT); // Power control of the DRA818
88 | digitalWrite(PD,HIGH); // start at low power
89 | Serial.println("done");
90 |
91 | Serial.print("initializing DRA818 ... ");
92 | /*
93 | * Configure DRA818V using 145.500 MHz, squelch 4, volume 8, no ctcss, 12.5 kHz bandwidth, all filters activated
94 | * We add the &Serial parameter to tell the DRA object where to log its debug information (to the builtin serial)
95 | *
96 | * Alternative call:
97 | * dra = new DRA818(dra_serial, DRA818_VHF);
98 | * dra->set_log(&Serial);
99 | * dra->handshake();
100 | * dra->group(DRA818_12K5, 145.500, 145.500, 0, 4, 0);
101 | * dra->volume(8);
102 | * dra->filters(true, true, true);
103 | */
104 | dra = DRA818::configure(dra_serial, DRA818_VHF, 145.500, 145.500, 4, 8, 0, 0, DRA818_12K5, true, true, true, &Serial);
105 | if (!dra) {
106 | Serial.println("\nError while configuring DRA818");
107 | }
108 | freq = DRA818_VHF_MIN;
109 |
110 | Serial.println("done");
111 |
112 | Serial.println("Starting ... ");
113 | }
114 |
115 | void loop(){
116 | char buf[9];
117 |
118 | if (!dra) return; // do nothing if DRA configuration failed
119 |
120 | dtostrf(freq, 8, 4, buf); // convert frequency to string with right precision
121 | Serial.print(String("Scanning frequency ") + String(buf) + String(" kHz ..."));
122 | /* scan the frequency */
123 | if (dra->scan(freq)) Serial.print("Found");
124 | Serial.println("");
125 |
126 | freq += 0.0125; //12.5kHz step
127 | if (freq > DRA818_VHF_MAX) freq = DRA818_VHF_MIN; // when DRA818_VHF_MAX (174.0) is reached, start over at DRA818_VHF_MIN (134.0)
128 | }
129 |
--------------------------------------------------------------------------------
/examples/scan/scan.ino:
--------------------------------------------------------------------------------
1 | /*
2 | scan.ino
3 |
4 | A simple sketch that configure a DRA818V and scan all the frequencies in the
5 | range 134-174 MHz with a step of 12.5 kHz. 3 pins of the arduino are
6 | used (PD, RX and TX) (CAUTION the DRA818 runs @3.3v). Configure the 3 macros
7 | and customize the DRA818::configure(...) call to your needs.
8 |
9 | Here is a sample output from the serial connection:
10 |
11 | Booting ...
12 | initializing I/O ... done
13 | initializing DRA818 ... done
14 | Starting ...
15 | Scanning frequency 134.0000 kHz ...
16 | Scanning frequency 134.0125 kHz ...
17 | Scanning frequency 134.0250 kHz ...
18 | Scanning frequency 134.0375 kHz ...
19 | Scanning frequency 134.0500 kHz ...
20 | Scanning frequency 134.0625 kHz ...
21 | Scanning frequency 134.0750 kHz ...
22 |
23 | I'm using a digital pin (D10) to crontrol the PD pin of the DRA818.
24 | It's not mandatory, you can just let the PD pin of the DRA818
25 | to HIGH and free an arduino digital pin.
26 |
27 |
28 | Copyright (c) 2017, Jerome LOYET
29 |
30 | This library is free software; you can redistribute it and/or
31 | modify it under the terms of the GNU Lesser General Public
32 | License as published by the Free Software Foundation; either
33 | version 2.1 of the License, or (at your option) any later version.
34 |
35 | This library is distributed in the hope that it will be useful,
36 | but WITHOUT ANY WARRANTY; without even the implied warranty of
37 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38 | Lesser General Public License for more details.
39 |
40 | You should have received a copy of the GNU Lesser General Public
41 | License along with this library; if not, write to the Free Software
42 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
43 | */
44 |
45 | #include
46 | #include
47 | #include "DRA818.h"
48 |
49 | /* Used Pins */
50 | #define PD 10 // to the DRA818 PD pin
51 | #define RX 3 // arduino serial RX pin to the DRA818 TX pin
52 | #define TX 4 // arduino serial TX pin to the DRA818 RX pin
53 |
54 | SoftwareSerial *dra_serial; // Serial connection to DRA818
55 | DRA818 *dra; // the DRA object once instanciated
56 | float freq; // the next frequency to scan
57 |
58 | void setup(){
59 | Serial.begin(9600); // for logging
60 |
61 | Serial.println("Booting ...");
62 |
63 | Serial.print("initializing I/O ... ");
64 | dra_serial = new SoftwareSerial(RX, TX); // Instantiate the Software Serial Object.
65 | pinMode(PD, OUTPUT); // Power control of the DRA818
66 | digitalWrite(PD,HIGH); // start at low power
67 | Serial.println("done");
68 |
69 | Serial.print("initializing DRA818 ... ");
70 | /*
71 | * Configure DRA818V using 145.500 MHz, squelch 4, volume 8, no ctcss, 12.5 kHz bandwidth, all filters activated
72 | *
73 | * Alternative call:
74 | * dra = new DRA818(dra_serial, DRA818_VHF);
75 | * dra->handshake();
76 | * dra->group(DRA818_12K5, 145.500, 145.500, 0, 4, 0);
77 | * dra->volume(8);
78 | * dra->filters(true, true, true);
79 | */
80 | dra = DRA818::configure(dra_serial, DRA818_VHF, 145.500, 145.500, 4, 8, 0, 0, DRA818_12K5, true, true, true);
81 | if (!dra) {
82 | Serial.println("\nError while configuring DRA818");
83 | }
84 | freq = DRA818_VHF_MIN;
85 |
86 | Serial.println("done");
87 |
88 | Serial.println("Starting ... ");
89 | }
90 |
91 | void loop(){
92 | char buf[9];
93 |
94 | if (!dra) return; // do nothing if DRA configuration failed
95 |
96 | dtostrf(freq, 8, 4, buf); // convert frequency to string with right precision
97 | Serial.print(String("Scanning frequency ") + String(buf) + String(" kHz ..."));
98 | /* scan the frequency */
99 | if (dra->scan(freq)) Serial.print("Found");
100 | Serial.println("");
101 |
102 | freq += 0.0125; //12.5kHz step
103 | if (freq > DRA818_VHF_MAX) freq = DRA818_VHF_MIN; // when DRA818_VHF_MAX (174.0) is reached, start over at DRA818_VHF_MIN (134.0)
104 | }
105 |
--------------------------------------------------------------------------------
/extra/DRA818U.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fatpat/arduino-dra818/89582e3ef7bf3f31f1af149e32cec16c4b9e4cf2/extra/DRA818U.pdf
--------------------------------------------------------------------------------
/extra/DRA818V.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fatpat/arduino-dra818/89582e3ef7bf3f31f1af149e32cec16c4b9e4cf2/extra/DRA818V.pdf
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=DRA818
2 | version=1.0.0
3 | author=Jerome LOYET
4 | maintainer=Jerome LOYET
5 | sentence=Configure and communicate with FM module DRA818.
6 | paragraph=Hardware or Software Serial can be used to Scan and set parameters.
7 | category=Communication
8 | url=https://github.com/fatpat/arduino_dra818
9 | architectures=*
10 |
--------------------------------------------------------------------------------
/src/DRA818.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | DRA818.cpp
3 |
4 | Copyright (c) 2017, Jerome LOYET
5 |
6 | This library is free software; you can redistribute it and/or
7 | modify it under the terms of the GNU Lesser General Public
8 | License as published by the Free Software Foundation; either
9 | version 2.1 of the License, or (at your option) any later version.
10 |
11 | This library is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | Lesser General Public License for more details.
15 |
16 | You should have received a copy of the GNU Lesser General Public
17 | License along with this library; if not, write to the Free Software
18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #include "Arduino.h"
22 | #include "DRA818.h"
23 | #include
24 | #include
25 | #include
26 | #if !defined (ESP32)
27 | #include
28 | #endif
29 |
30 | #define CTCSS_MAX 38
31 | #define SQUELCH_MAX 8
32 | #define VOLUME_MAX 8
33 | #define VOLUME_MIN 1
34 | #define TIMEOUT 2000
35 | #define HANDSHAKE_REPEAT 3
36 | #define SERIAL_SPEED 9600
37 | #define SERIAL_CONFIG SERIAL_8N1
38 |
39 | #define CHECK(a, op, b) if (a op b) a = b
40 |
41 | #ifdef DRA818_DEBUG
42 | #define LOG(action, msg) if (this->log) this->log->action(msg)
43 | #define SEND(msg) do { \
44 | this->serial->write(msg); \
45 | if (this->log) this->log->write(msg); \
46 | } while(0)
47 | #else
48 | #define LOG(action, msg)
49 | #define SEND(msg) this->serial->write(msg)
50 | #endif
51 |
52 | DRA818::DRA818(HardwareSerial *serial, uint8_t type) {
53 | serial->begin(SERIAL_SPEED, SERIAL_CONFIG);
54 | this->init((Stream *)serial, type);
55 | }
56 |
57 | #if !defined (ESP32)
58 | DRA818::DRA818(SoftwareSerial *serial, uint8_t type) {
59 | serial->begin(SERIAL_SPEED); // We can't configure bits/parity for SoftwareSerial, it's 8N1 as the DRA818
60 | this->init((Stream *)serial, type);
61 | }
62 | #endif
63 |
64 | void DRA818::init(Stream *serial, uint8_t type) {
65 | this->serial = serial;
66 | #ifdef DRA818_DEBUG
67 | this->log = NULL;
68 | #endif
69 | this->type = type;
70 | }
71 |
72 | #ifdef DRA818_DEBUG
73 | void DRA818::set_log(Stream *log) {
74 | this->log = log;
75 | LOG(println, F("DRA818: log serial connection active"));
76 | }
77 | #endif
78 |
79 | int DRA818::read_response() {
80 | char ack[3];
81 | ack[0] = ack[1] = ack[2] = '\0'; // Just to quiet some warnings.
82 |
83 | LOG(print, F("<- "));
84 |
85 | ack[2]=0;
86 | long start = millis();
87 | do {
88 | if (this->serial->available()) {
89 | ack[0] = ack[1];
90 | ack[1] = ack[2];
91 | ack[2] = this->serial->read();
92 | LOG(write, ack[2]);
93 | }
94 | } while (ack[2] != 0xa && (millis() - start) < TIMEOUT);
95 | #ifdef DRA818_DEBUG
96 | if (ack[2] != 0xa) LOG(write, F("\r\n"));
97 | #endif
98 | LOG(print, F("Returned value="));
99 | LOG(println, ack[0] == '0' );
100 |
101 | return (ack[0] == '0');
102 | }
103 |
104 |
105 | int DRA818::group(uint8_t bw, float freq_tx, float freq_rx, uint8_t ctcss_tx, uint8_t squelch, uint8_t ctcss_rx) {
106 | char buffer[49];
107 | char buf_rx[9];
108 | char buf_tx[9];
109 |
110 | CHECK(bw, <, DRA818_12K5);
111 | CHECK(bw, >, DRA818_25K);
112 |
113 | CHECK(freq_rx, <, ((this->type & DRA818_BAND_FLAG) == DRA818_VHF ? DRA818_VHF_MIN : DRA818_UHF_MIN));
114 | CHECK(freq_tx, <, ((this->type & DRA818_BAND_FLAG) == DRA818_VHF ? DRA818_VHF_MIN : DRA818_UHF_MIN));
115 |
116 | CHECK(freq_rx, >, ((this->type & DRA818_BAND_FLAG) == DRA818_VHF ? DRA818_VHF_MAX : ((this->type & SA_MODEL_FLAG) == SA_MODEL_FLAG ? SA8X8_UHF_MAX : DRA818_UHF_MAX)));
117 | CHECK(freq_tx, >, ((this->type & DRA818_BAND_FLAG) == DRA818_VHF ? DRA818_VHF_MAX : ((this->type & SA_MODEL_FLAG) == SA_MODEL_FLAG ? SA8X8_UHF_MAX : DRA818_UHF_MAX)));
118 |
119 | CHECK(ctcss_rx, >, CTCSS_MAX);
120 | CHECK(ctcss_tx, >, CTCSS_MAX);
121 |
122 | CHECK(squelch, >, SQUELCH_MAX);
123 |
124 | dtostrf(freq_tx, 8, 4, buf_tx);
125 | dtostrf(freq_rx, 8, 4, buf_rx);
126 |
127 | sprintf(buffer, "AT+DMOSETGROUP=%01d,%s,%s,%04d,%c,%04d\r\n", bw, buf_tx, buf_rx, ctcss_tx, squelch + '0', ctcss_rx);
128 |
129 | LOG(println, F("DRA818::group"));
130 | LOG(print, F("-> "));
131 | SEND(buffer);
132 |
133 | return this->read_response();
134 | }
135 |
136 | int DRA818::handshake() {
137 | char i = HANDSHAKE_REPEAT;
138 |
139 |
140 | while (i-- > 0) {
141 | LOG(println, F("DRA818::handshake"));
142 | LOG(print, F("-> "));
143 |
144 | SEND("AT+DMOCONNECT\r\n");
145 | if (this->read_response()) {
146 | return true;
147 | }
148 | }
149 |
150 | return false;
151 | }
152 |
153 | int DRA818::scan(float freq) {
154 | char buf[9];
155 |
156 | dtostrf(freq, 8, 4, buf);
157 |
158 | LOG(println, F("DRA818::scan"));
159 | LOG(print, F("-> "));
160 |
161 | SEND("S+");
162 | SEND(buf);
163 | SEND("\r\n");
164 |
165 | return read_response();
166 | }
167 |
168 | int DRA818::rssi() {
169 | if ((this->type & SA_MODEL_FLAG) == 0){
170 | LOG(println, F("WARNING: DRA818::rssi() only supported by SA818/SA868, not by DRA818."));
171 | LOG(println, F("Construct your DRA818 object with `type = SA[818]868_[VU]HF` to enable rssi()."));
172 | return -1;
173 | }
174 | LOG(println, F("DRA818::rssi"));
175 | LOG(print, F("-> "));
176 |
177 | SEND("RSSI?");
178 |
179 | return read_response();
180 | }
181 |
182 | int DRA818::volume(uint8_t volume) {
183 | CHECK(volume, >, VOLUME_MAX);
184 | CHECK(volume, <, VOLUME_MIN);
185 |
186 | LOG(println, F("DRA818::volume"));
187 | LOG(print, F("-> "));
188 |
189 | SEND("AT+DMOSETVOLUME=");
190 | SEND(volume + '0');
191 | SEND("\r\n");
192 |
193 | return read_response();
194 | }
195 |
196 | int DRA818::filters(bool pre, bool high, bool low) {
197 | LOG(println, F("DRA818::filters"));
198 | LOG(print, F("-> "));
199 |
200 | SEND("AT+SETFILTER=");
201 | SEND('0' + (char)(pre ? false: true)); // or !pre
202 | SEND(",");
203 | SEND('0' + (char)(high ? false: true)); // or !high
204 | SEND(",");
205 | SEND('0' + (char)(low ? false: true)); // or !low
206 | SEND("\r\n");
207 |
208 | return read_response(); // SCAN function return 0 if there is a signal, 1 otherwise
209 | }
210 |
211 | #if !defined (ESP32)
212 | DRA818* DRA818::configure(SoftwareSerial *stream, uint8_t type, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low, Stream *log) {
213 | DRA818 *dra = new DRA818(stream, type);
214 | return DRA818::configure(dra, freq_rx, freq_tx, squelch, volume, ctcss_rx, ctcss_tx, bandwidth, pre, high, low, log);
215 | }
216 | #endif
217 |
218 | DRA818* DRA818::configure(HardwareSerial *stream, uint8_t type, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low, Stream *log) {
219 | DRA818 *dra = new DRA818(stream, type);
220 | return DRA818::configure(dra, freq_rx, freq_tx, squelch, volume, ctcss_rx, ctcss_tx, bandwidth, pre, high, low, log);
221 | }
222 |
223 | DRA818* DRA818::configure(DRA818 *dra, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low, Stream *log) {
224 | int ret;
225 | #ifdef DRA818_DEBUG
226 | dra->set_log(log);
227 | #endif
228 | delay(TIMEOUT);
229 | dra->handshake();
230 | ret = dra->group(bandwidth, freq_tx, freq_rx, ctcss_tx, squelch, ctcss_tx);
231 | if (ret) ret = dra->volume(volume);
232 | if (ret) ret = dra->filters(pre, high, low);
233 |
234 | return ret ? dra : NULL;
235 | }
236 |
--------------------------------------------------------------------------------
/src/DRA818.h:
--------------------------------------------------------------------------------
1 | /*
2 | DRA818.h
3 |
4 | Copyright (c) 2017, Jerome LOYET
5 |
6 | This library is free software; you can redistribute it and/or
7 | modify it under the terms of the GNU Lesser General Public
8 | License as published by the Free Software Foundation; either
9 | version 2.1 of the License, or (at your option) any later version.
10 |
11 | This library is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | Lesser General Public License for more details.
15 |
16 | You should have received a copy of the GNU Lesser General Public
17 | License along with this library; if not, write to the Free Software
18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifndef DRA818_h
22 | #define DRA818_h
23 |
24 | #include
25 | #include
26 | #if !defined (ESP32)
27 | #include
28 | #endif
29 |
30 | // Which bit of `type` to look at to determine the band
31 | #define DRA818_BAND_FLAG 0x1
32 | // Which bit of `type` to look at to determin whether it's an 818 or an 868
33 | #define DRA868_FLAG 0x2
34 | // Which bit of `type` to look at to determin whether it's a DRA (Dorji) or an SA (NiceRF) model
35 | #define SA_MODEL_FLAG 0x4
36 |
37 | #define DRA818_VHF 0x0
38 | #define DRA818_UHF 0x1
39 | #define DRA868_VHF (DRA818_VHF | DRA868_FLAG) // Not sure this model actually exist, leave it here for backward compatibility
40 | #define DRA868_UHF (DRA818_UHF | DRA868_FLAG) // Not sure this model actually exist, leave it here for backward compatibility
41 | #define SA818_VHF (DRA818_VHF | SA_MODEL_FLAG)
42 | #define SA818_UHF (DRA818_UHF | SA_MODEL_FLAG)
43 | #define SA868_VHF (SA818_VHF | DRA868_FLAG)
44 | #define SA868_UHF (SA818_UHF | DRA868_FLAG)
45 |
46 | #define DRA818_VHF_MIN 134.0
47 | #define DRA818_VHF_MAX 174.0
48 | #define DRA818_UHF_MIN 400.0
49 | #define DRA818_UHF_MAX 470.0
50 | #define SA8X8_UHF_MAX 480.0
51 | #define DRA818_12K5 0x0
52 | #define DRA818_25K 0x1
53 | //#define DRA818_DEBUG
54 |
55 | class DRA818 {
56 | public:
57 | // Constructors
58 | DRA818(HardwareSerial *serial, uint8_t type);
59 | #if !defined (ESP32)
60 | DRA818(SoftwareSerial *serial, uint8_t type);
61 | #endif
62 | void init(Stream *serial, uint8_t type);
63 |
64 | // low level DRA818 function
65 | int group(uint8_t bandwidth, float freq_tx, float freq_rx, uint8_t ctcss_tx, uint8_t squelch, uint8_t ctcss_rx);
66 | int handshake();
67 | int scan(float freq);
68 | int volume(uint8_t volume);
69 | int filters(bool pre, bool high, bool low);
70 | int rssi();
71 |
72 |
73 | // serial connection to DRA818
74 | Stream *serial;
75 |
76 | #ifdef DRA818_DEBUG
77 | // log Serial interface
78 | void set_log(Stream *log);
79 | Stream *log;
80 | #endif
81 |
82 | // all-in-one configuration functions
83 | #if !defined (ESP32)
84 | static DRA818* configure(SoftwareSerial *stream, uint8_t type, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low, Stream *log = NULL);
85 | #endif
86 | static DRA818* configure(HardwareSerial *stream, uint8_t type, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low, Stream *log = NULL);
87 |
88 | private:
89 | uint8_t type;
90 |
91 | int read_response();
92 |
93 | static DRA818* configure(DRA818 *dra, float freq_rx, float freq_tx, uint8_t squelch, uint8_t volume, uint8_t ctcss_rx, uint8_t ctcss_tx, uint8_t bandwidth, bool pre, bool high, bool low, Stream *log = NULL);
94 | };
95 | #endif
96 |
--------------------------------------------------------------------------------