├── .gitignore ├── Build instructions for the Tiny Spectrum Analyzer.pdf ├── LICENSE ├── README.md ├── Windows ├── tinySA.cfg └── tinySA.zip ├── tinySA schematic RF part.pdf ├── tinySA.ino ├── tinySA.jpg └── tinySA_measurement.png /.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 | -------------------------------------------------------------------------------- /Build instructions for the Tiny Spectrum Analyzer.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exDB2OO/tinySA/61eff853795308a67d39402dc19d761c2ab2680b/Build instructions for the Tiny Spectrum Analyzer.pdf -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tinySA 2 | A very small, cheap and easy to build spectrum analyzer and signal generator with remarkable performance. 3 | 4 | - Spectrum analyzer span 0-250MHz 5 | - RBW switchable between 3kHz, 10kHz, 30kHz, 100kHz, 300kHz and 600kHz 6 | - IIP3 +7dBm 7 | - Noise level below -100dBm with RBW of 10kHz 8 | - Output of signal generator: 0-250MHz at -3dBm till -33dBm 9 | - Optional 0-30dBm switchable input attenuator 10 | - Optional calibration output 11 | 12 | 13 | ![Example tinySA build](https://github.com/erikkaashoek/tinySA/blob/master/tinySA.jpg) 14 | 15 | Measurement exeample 16 | 17 | ![Example tinySA measurement](https://github.com/erikkaashoek/tinySA/blob/master/tinySA_measurement.png) 18 | -------------------------------------------------------------------------------- /Windows/tinySA.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exDB2OO/tinySA/61eff853795308a67d39402dc19d761c2ab2680b/Windows/tinySA.cfg -------------------------------------------------------------------------------- /Windows/tinySA.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exDB2OO/tinySA/61eff853795308a67d39402dc19d761c2ab2680b/Windows/tinySA.zip -------------------------------------------------------------------------------- /tinySA schematic RF part.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exDB2OO/tinySA/61eff853795308a67d39402dc19d761c2ab2680b/tinySA schematic RF part.pdf -------------------------------------------------------------------------------- /tinySA.ino: -------------------------------------------------------------------------------- 1 | /* tinySA.ino - Si4432 Spectrum analyzer 2 | * 3 | * Copyright (c) 2017 Erik Kaashoek 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining 6 | * a copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sublicense, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject 11 | * to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be 14 | * included in all copies or substantial portions of the Software. 15 | * 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 19 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 20 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #if defined(ARDUINO_ARCH_SAMD) 30 | #define Serial SerialUSB 31 | #endif 32 | 33 | // Comment out below line if you do not want a local user interface 34 | #define USE_ROTARY 1 35 | #define USE_DISPLAY 1 36 | // #define USE_SSD1306 1 37 | #define USE_ILI9341 1 38 | // #define USE_SI4463 1 39 | 40 | #ifdef USE_SI4463 41 | #include "./Si446x.h" 42 | #endif 43 | 44 | 45 | //------------------------------------------ Display ------------------------------------ 46 | #ifdef USE_SSD1306 47 | #include 48 | #include 49 | 50 | //#define SCREEN_WIDTH 128 // OLED display width, in pixels 51 | //#define SCREEN_HEIGHT 64 // OLED display height, in pixels 52 | 53 | // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) 54 | #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin) 55 | Adafruit_SSD1306 tft(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); 56 | 57 | #define DISPLAY_POINTS 100 58 | #endif 59 | 60 | 61 | 62 | #ifdef USE_ILI9341 63 | #include "SPI.h" 64 | #include "Adafruit_GFX.h" 65 | #include "Adafruit_ILI9341.h" 66 | 67 | // For the Adafruit shield, these are the default. 68 | #define TFT_DC A5 69 | #define TFT_CS A4 70 | 71 | // Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC 72 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC); 73 | 74 | #define DISPLAY_POINTS 300 75 | 76 | #endif 77 | 78 | //#define SCREEN_WIDTH 320 // OLED display width, in pixels 79 | //#define SCREEN_HEIGHT 240 // OLED display height, in pixels 80 | 81 | // The onboard led is blinked during serial transfer 82 | #define tinySA_led 13 83 | 84 | #ifndef DISPLAY_POINTS 85 | #define DISPLAY_POINTS 100 86 | #endif 87 | 88 | //--------------------- Generic display --------------- 89 | 90 | void clearDisplay() 91 | { 92 | #ifdef USE_SSD1306 93 | tft.clearDisplay(); 94 | #endif 95 | #ifdef USE_ILI9341 96 | tft.fillScreen(ILI9341_BLACK); 97 | #endif 98 | } 99 | 100 | void textWhite() 101 | { 102 | #ifdef USE_SSD1306 103 | tft.setTextSize(1); 104 | tft.setTextColor(SSD1306_WHITE); // Draw white text 105 | #define DISPLAY_WHITE SSD1306_WHITE 106 | #define DISPLAY_BLACK SSD1306_BLACK 107 | #define DISPLAY_GRAY SSD1306_WHITE 108 | #define DISPLAY_YELLOW SSD1306_WHITE 109 | #define DISPLAY_INVERSE SSD1306_INVERSE 110 | #endif 111 | #ifdef USE_ILI9341 112 | tft.setTextColor(ILI9341_WHITE); 113 | #define DISPLAY_WHITE ILI9341_WHITE 114 | #define DISPLAY_BLACK ILI9341_BLACK 115 | #define DISPLAY_GRAY ILI9341_WHITE 116 | #define DISPLAY_YELLOW ILI9341_YELLOW 117 | #define DISPLAY_INVERSE ILI9341_WHITE 118 | #define SCREEN_WIDTH tft.width() 119 | #endif 120 | } 121 | 122 | void sendDisplay() 123 | { 124 | #ifdef USE_SSD1306 125 | tft.display(); 126 | #endif 127 | #ifdef USE_ILI9341 128 | yield(); 129 | #endif 130 | } 131 | 132 | //---------------- Drawing ------------------ 133 | 134 | #ifdef USE_ILI9341 135 | 136 | const int dX = 30 ; 137 | const int dY = 24 ; 138 | const int oX = 20 ; 139 | const int oY = 24 ; 140 | const int DOTS = 10 * dX - 2 ; // FOR ADAFRUIT RA8875 141 | 142 | 143 | void DrawCheckerBoard() 144 | { 145 | // VERTICAL 146 | for (int y=0; y<9; y++) 147 | { 148 | // HORIZONTAL 149 | for (int x=0; x<10; x++) 150 | { 151 | tft.drawRect(oX + x*dX, y*dY+oY, dX, dY, ILI9341_DARKGREY); 152 | tft.fillRect(oX + x*dX+1, y*dY+1+oY, dX-2, dY-2, DISPLAY_BLACK); 153 | } 154 | tft.drawRect(oX, oY, 10 * dX, 9 * dY, ILI9341_DARKGREY); 155 | } 156 | tft.drawRect(oX, oY, 10 * dX, 9 * dY, ILI9341_DARKGREY); 157 | } 158 | 159 | 160 | void DrawRectangleMenue() 161 | { 162 | // VERTICAL 163 | for (int y=0; y<9; y++) 164 | { 165 | // HORIZONTAL 166 | for (int x=0; x<10; x++) 167 | { 168 | tft.drawRect(oX, oY, 10 * dX, 9 * dY, DISPLAY_WHITE); 169 | tft.fillRect(oX+1, oY+1, 10 * dX - 2, 9 * dY - 2, DISPLAY_BLACK); 170 | } 171 | } 172 | } 173 | 174 | /* 175 | void ShowVerticalScale() 176 | { 177 | // CLEAR TEXTAREA 178 | tft.fillRect(0, 0, oX-2, 420, DISPLAY_BLACK); 179 | // NOW WRITE NEW VALUES 180 | // tft.textMode(); 181 | tft.textEnlarge(0); 182 | char string[6]; 183 | int level ; 184 | int Top ; 185 | if (AttSet == 0) Top = (int)( ThruLoss + MaxIFLevel ); 186 | if (AttSet == 1) Top = (int)( ThruLoss + MaxIFLevel + AttLoss ); 187 | 188 | for (int y=0; y<=9; y++) 189 | { 190 | tft.textSetCursor(0, y * dY); 191 | tft.textTransparent(DISPLAY_WHITE); 192 | level = Top - y * 10 ; 193 | itoa(level,string,10); 194 | if (level == 0) 195 | { 196 | for (int z=6; z>0; z--) string[z] = string[z-1] ; 197 | string[0] = 32 ; // space 198 | } 199 | if (level >= 0) 200 | { 201 | for (int z=6; z>0; z--) string[z] = string[z-1] ; 202 | } 203 | if (level > 0) string[0] = 43 ; // plus 204 | if (abs(level) < 100) 205 | { 206 | for (int z=6; z>0; z--) string[z] = string[z-1] ; 207 | string[0] = 32 ; // space 208 | } 209 | 210 | tft.textWrite(string); 211 | } 212 | } 213 | 214 | 215 | void DrawLine() 216 | { 217 | long Y1, Y2 ; 218 | if (AttSet == 0) TopLevel = MaxIFLevel + ThruLoss ; 219 | if (AttSet == 1) TopLevel = MaxIFLevel + AttLoss + ThruLoss ; 220 | // HORIZONTAL 221 | for (int x=0; x < DOTS-2 ; x+=1) 222 | { 223 | if (Sample[x] >= TopLevel) Sample[x] = TopLevel - 0.5 ; 224 | if (Sample[x+1] >= TopLevel) Sample[x+1] = TopLevel - 0.5 ; 225 | if (Sample[x] <= (TopLevel - 90.0)) Sample[x] = TopLevel - 89.5 ; 226 | if (Sample[x+1] <= (TopLevel - 90.0)) Sample[x+1] = TopLevel - 89.5 ; 227 | Y1 = (int)(dY * abs((TopLevel - Sample[x]) * 0.1 )); 228 | Y2 = (int)(dY * abs((TopLevel - Sample[x+1]) * 0.1 )); 229 | tft.drawLine(x+oX+2, Y1+oY, x+oX+3, Y2+oY, DISPLAY_YELLOW); 230 | tft.drawLine(x+oX+2, Y1+oY+1, x+oX+3, Y2+oY+1, DISPLAY_YELLOW); 231 | } 232 | } 233 | 234 | */ 235 | 236 | #endif 237 | 238 | // -------------------- Rotary ------------------------------------------- 239 | #ifdef USE_ROTARY 240 | 241 | 242 | // Encode input pins, these should be interrupt enabled inputs 243 | int R_pinEncA=7; 244 | int R_pinEncB=6; 245 | 246 | volatile int R_counter = 0; 247 | static int R_counter_oud = 0; 248 | static byte R_abOld = 0; 249 | 250 | void R_setup() { 251 | pinMode(R_pinEncA, INPUT_PULLUP); 252 | pinMode(R_pinEncB, INPUT_PULLUP); 253 | 254 | attachInterrupt(R_pinEncA, R_pinAction, CHANGE); 255 | attachInterrupt(R_pinEncB, R_pinAction, CHANGE); 256 | } 257 | 258 | 259 | int R_delta() { 260 | int c = R_counter - R_counter_oud; 261 | R_counter_oud = R_counter; 262 | static int old_pins = 0; 263 | int new_pins = (digitalRead(R_pinEncB) << 1) | digitalRead(R_pinEncA); 264 | if (new_pins != old_pins) { 265 | old_pins = new_pins; 266 | /* 267 | 268 | Serial.print ("Rotary = "); 269 | Serial.print (digitalRead(R_pinEncA)); 270 | Serial.print (":"); 271 | Serial.print (digitalRead(R_pinEncB)); 272 | Serial.print (" = "); 273 | Serial.println (c); 274 | Serial.print (" Rotary2 = "); 275 | Serial.print (digitalRead(R_pinEncA)); 276 | Serial.print (":"); 277 | Serial.println (digitalRead(R_pinEncB)); 278 | */ 279 | } 280 | return (c); 281 | } 282 | 283 | int R_count() { 284 | R_counter_oud = R_counter; 285 | return (R_counter); 286 | } 287 | 288 | #define DIR_CCW 0x10 289 | #define DIR_CW 0x20 290 | 291 | 292 | #define R_START 0x0 293 | 294 | #define ENABLE_HALF_STEP 295 | #ifdef ENABLE_HALF_STEP 296 | // Use the half-step state table (emits a code at 00 and 11) 297 | #define R_CCW_BEGIN 0x1 298 | #define R_CW_BEGIN 0x2 299 | #define R_START_M 0x3 300 | #define R_CW_BEGIN_M 0x4 301 | #define R_CCW_BEGIN_M 0x5 302 | 303 | const unsigned char ttable[][4] = 304 | { 305 | // 00 01 10 11 306 | {R_START_M, R_CW_BEGIN, R_CCW_BEGIN, R_START}, // R_START (00) 307 | {R_START_M | DIR_CCW, R_START, R_CCW_BEGIN, R_START}, // R_CCW_BEGIN 308 | {R_START_M | DIR_CW, R_CW_BEGIN, R_START, R_START}, // R_CW_BEGIN 309 | {R_START_M, R_CCW_BEGIN_M, R_CW_BEGIN_M, R_START}, // R_START_M (11) 310 | {R_START_M, R_START_M, R_CW_BEGIN_M, R_START | DIR_CW}, // R_CW_BEGIN_M 311 | {R_START_M, R_CCW_BEGIN_M, R_START_M, R_START | DIR_CCW} // R_CCW_BEGIN_M 312 | }; 313 | #else 314 | // Use the full-step state table (emits a code at 00 only) 315 | #define R_CW_FINAL 0x1 316 | #define R_CW_BEGIN 0x2 317 | #define R_CW_NEXT 0x3 318 | #define R_CCW_BEGIN 0x4 319 | #define R_CCW_FINAL 0x5 320 | #define R_CCW_NEXT 0x6 321 | 322 | const unsigned char ttable[7][4] = 323 | { 324 | // 00 01 10 11 325 | {R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START}, // R_START 326 | {R_CW_NEXT, R_START, R_CW_FINAL, R_START | DIR_CW}, // R_CW_FINAL 327 | {R_CW_NEXT, R_CW_BEGIN, R_START, R_START}, // R_CW_BEGIN 328 | {R_CW_NEXT, R_CW_BEGIN, R_CW_FINAL, R_START}, // R_CW_NEXT 329 | {R_CCW_NEXT, R_START, R_CCW_BEGIN, R_START}, // R_CCW_BEGIN 330 | {R_CCW_NEXT, R_CCW_FINAL, R_START, R_START | DIR_CCW}, // R_CCW_FINAL 331 | {R_CCW_NEXT, R_CCW_FINAL, R_CCW_BEGIN, R_START} // R_CCW_NEXT 332 | }; 333 | #endif 334 | 335 | 336 | 337 | 338 | 339 | volatile unsigned char R_state = 0; 340 | 341 | 342 | void R_pinAction() { 343 | unsigned char pinstate = (digitalRead(R_pinEncB) << 1) | digitalRead(R_pinEncA); 344 | unsigned char pinstate_t = (digitalRead(R_pinEncB) << 1) | digitalRead(R_pinEncA); 345 | while (pinstate != pinstate_t) { 346 | pinstate = pinstate_t; 347 | pinstate_t = (digitalRead(R_pinEncB) << 1) | digitalRead(R_pinEncA); 348 | } 349 | R_state = ttable[R_state & 0xf][pinstate]; 350 | // Serial.print("pinstate = "); 351 | // Serial.print(pinstate); 352 | // Serial.print(" R_state = "); 353 | // Serial.println(R_state); 354 | if (R_state & 0x30) { 355 | if ((R_state & 0x30) == DIR_CCW) 356 | R_counter++; 357 | else 358 | R_counter--; 359 | // Serial.print("r_counter = "); 360 | // Serial.println(R_counter); 361 | } 362 | return; 363 | } 364 | 365 | #endif 366 | 367 | ///-------------------------------------------------------- SI4432 start ---------------------------------------------- 368 | 369 | // PINS SI4432, you can change these to any pin you want 370 | 371 | const int SI_nSEL[4] = { 0,5, 11, 12 }; // #4 is dummy!!!!!! 372 | const int SI_SCLK = 1 ; 373 | const int SI_SDI = 2 ; 374 | const int SI_SDO = 3 ; 375 | 376 | // Use this to tune the xtal oscilators on the SI4432 modules to the exact frquency 377 | #define V0_XTAL_CAPACITANCE 0x64 378 | #define V1_XTAL_CAPACITANCE 0x64 379 | 380 | 381 | byte SI4432REG[129] ; 382 | float bandwidth = 34.6 ; 383 | 384 | // currently selectd SI4432 385 | int SI4432_Sel = 0; 386 | 387 | void SI4432_Write_Byte(byte ADR, byte DATA ) 388 | { 389 | ADR |= 0x80 ; // RW = 1 390 | digitalWrite(SI_SCLK, LOW); 391 | digitalWrite(SI_nSEL[SI4432_Sel], LOW); 392 | shiftOut(SI_SDI , SI_SCLK , MSBFIRST , ADR ); 393 | shiftOut(SI_SDI , SI_SCLK , MSBFIRST , DATA ); 394 | digitalWrite(SI_nSEL[SI4432_Sel], HIGH); 395 | } 396 | 397 | byte SI4432_Read_Byte( byte ADR ) 398 | { 399 | byte DATA ; 400 | digitalWrite(SI_SCLK, LOW); 401 | digitalWrite(SI_nSEL[SI4432_Sel], LOW); 402 | shiftOut(SI_SDI , SI_SCLK , MSBFIRST , ADR ); 403 | DATA = shiftIn(SI_SDO , SI_SCLK , MSBFIRST ); 404 | digitalWrite(SI_nSEL[SI4432_Sel], HIGH); 405 | return DATA ; 406 | } 407 | 408 | void SI4432_Reset() 409 | { 410 | int count = 0; 411 | // always perform a system reset (don't send 0x87) 412 | SI4432_Write_Byte( 0x07, 0x80); 413 | delay(10); 414 | // wait for chiprdy bit 415 | while (count++ < 100 && ( SI4432_Read_Byte ( 0x04 ) & 0x02 ) == 0) { 416 | delay(10); 417 | Serial.print("Waiting for SI4432 "); 418 | Serial.println(SI4432_Sel); 419 | } 420 | } 421 | 422 | #if 0 423 | float SI4432_SET_RBW(float WISH) 424 | { 425 | procedure SI4432_Set_BW_FSK ( dword in BW_Hz ) is 426 | var byte IF_filset [] = { 427 | 1,2,3,4,5,6,7,1,2,3, 428 | 4,5,6,7,1,2,3,4,5,6, 429 | 7,1,2,3,4,5,6,7,1,2, 430 | 3,4,5,6,7,1,2,3,4,5, 431 | 6,7,4,5,9,15,1,2,3,4, 432 | 8,9,10,11,12,13,14 } 433 | 434 | -- set the largest bandwidth (used if no valid value is found) 435 | var byte Index = count ( IF_Bandwidth ) - 1 436 | 437 | -- loop until a bandwidth larger or equal to the desired bandwidth is found 438 | for count ( IF_Bandwidth ) using i loop 439 | if IF_Bandwidth [i] >= WISH then 440 | -- if found, remember the index and leave the loop 441 | Index = i 442 | exit loop 443 | end if 444 | end loop 445 | 446 | -- get the parts from the different lookup tables 447 | ndec_exp = IF_ndec_exp [ Index ] 448 | dwn3_bypass = IF_dwn3_bypass [ Index ] 449 | filset = IF_filset [ Index ] 450 | 451 | -- merge the parts and write them to the bandwidth register 452 | var byte Value = (dwn3_bypass << 7) | (ndec_exp << 4) | filset 453 | SI4432_Write ( 0x1C, Value ) 454 | } 455 | #else 456 | float SI4432_SET_RBW(float WISH) 457 | { 458 | byte ndec = 5 ; 459 | byte dwn3 = 0 ; 460 | byte fils = 1 ; 461 | float rxosr = 12.5 ; 462 | float REAL = 2.6 ; // AS CLOSE AS POSSIBLE TO "WISH" :-) 463 | // YES, WE KNOW THIS IS SLOW 464 | #if 0 // Too many resolutions, not needed 465 | if (WISH > 2.6) { 466 | ndec = 5 ; 467 | fils = 2 ; 468 | REAL = 2.8 ; 469 | } 470 | #endif 471 | if (WISH > 2.8) { 472 | ndec = 5 ; 473 | fils = 3 ; 474 | REAL = 3.1 ; 475 | } 476 | #if 0 // Too many resolutions, not needed 477 | if (WISH > 3.1) { 478 | ndec = 5 ; 479 | fils = 4 ; 480 | REAL = 3.2 ; 481 | } 482 | if (WISH > 3.2) { 483 | ndec = 5 ; 484 | fils = 5 ; 485 | REAL = 3.7 ; 486 | } 487 | if (WISH > 3.7) { 488 | ndec = 5 ; 489 | fils = 6 ; 490 | REAL = 4.2 ; 491 | } 492 | if (WISH > 4.2) { 493 | ndec = 5 ; 494 | fils = 7 ; 495 | REAL = 4.5 ; 496 | } 497 | if (WISH > 4.5) { 498 | ndec = 4 ; 499 | fils = 1 ; 500 | REAL = 4.9 ; 501 | } 502 | if (WISH > 4.9) { 503 | ndec = 4 ; 504 | fils = 2 ; 505 | REAL = 5.4 ; 506 | } 507 | if (WISH > 5.4) { 508 | ndec = 4 ; 509 | fils = 3 ; 510 | REAL = 5.9 ; 511 | } 512 | if (WISH > 5.9) { 513 | ndec = 4 ; 514 | fils = 4 ; 515 | REAL = 6.1 ; 516 | } 517 | if (WISH > 6.1) { 518 | ndec = 4 ; 519 | fils = 5 ; 520 | REAL = 7.2 ; 521 | } 522 | if (WISH > 7.2) { 523 | ndec = 4 ; 524 | fils = 6 ; 525 | REAL = 8.2 ; 526 | } 527 | if (WISH > 8.2) { 528 | ndec = 4 ; 529 | fils = 7 ; 530 | REAL = 8.8 ; 531 | } 532 | if (WISH > 8.8) { 533 | ndec = 3 ; 534 | fils = 1 ; 535 | REAL = 9.5 ; 536 | } 537 | #endif 538 | if (WISH > 9.5) { 539 | ndec = 3 ; 540 | fils = 2 ; 541 | REAL = 10.6 ; 542 | } 543 | #if 0 // Too many resolutions, not needed 544 | if (WISH > 10.6) { 545 | ndec = 3 ; 546 | fils = 3 ; 547 | REAL = 11.5 ; 548 | } 549 | if (WISH > 11.5) { 550 | ndec = 3 ; 551 | fils = 4 ; 552 | REAL = 12.1 ; 553 | } 554 | if (WISH > 12.1) { 555 | ndec = 3 ; 556 | fils = 5 ; 557 | REAL = 14.2 ; 558 | } 559 | if (WISH > 14.2) { 560 | ndec = 3 ; 561 | fils = 6 ; 562 | REAL = 16.2 ; 563 | } 564 | if (WISH > 16.2) { 565 | ndec = 3 ; 566 | fils = 7 ; 567 | REAL = 17.5 ; 568 | } 569 | if (WISH > 17.5) { 570 | ndec = 2 ; 571 | fils = 1 ; 572 | REAL = 18.9 ; 573 | } 574 | if (WISH > 18.9) { 575 | ndec = 2 ; 576 | fils = 2 ; 577 | REAL = 21.0 ; 578 | } 579 | if (WISH > 21.0) { 580 | ndec = 2 ; 581 | fils = 3 ; 582 | REAL = 22.7 ; 583 | } 584 | if (WISH > 22.7) { 585 | ndec = 2 ; 586 | fils = 4 ; 587 | REAL = 24.0 ; 588 | } 589 | if (WISH > 24.0) { 590 | ndec = 2 ; 591 | fils = 5 ; 592 | REAL = 28.2 ; 593 | } 594 | #endif 595 | if (WISH > 28.2) { 596 | ndec = 2 ; 597 | fils = 6 ; 598 | REAL = 32.2 ; 599 | } 600 | #if 0 // Too many resolutions, not needed 601 | if (WISH > 32.2) { 602 | ndec = 2 ; 603 | fils = 7 ; 604 | REAL = 34.7 ; 605 | } 606 | if (WISH > 34.7) { 607 | ndec = 1 ; 608 | fils = 1 ; 609 | REAL = 37.7 ; 610 | } 611 | if (WISH > 37.7) { 612 | ndec = 1 ; 613 | fils = 2 ; 614 | REAL = 41.7 ; 615 | } 616 | if (WISH > 41.7) { 617 | ndec = 1 ; 618 | fils = 3 ; 619 | REAL = 45.2 ; 620 | } 621 | if (WISH > 45.2) { 622 | ndec = 1 ; 623 | fils = 4 ; 624 | REAL = 47.9 ; 625 | } 626 | if (WISH > 47.9) { 627 | ndec = 1 ; 628 | fils = 5 ; 629 | REAL = 56.2 ; 630 | } 631 | if (WISH > 56.2) { 632 | ndec = 1 ; 633 | fils = 6 ; 634 | REAL = 64.1 ; 635 | } 636 | if (WISH > 64.1) { 637 | ndec = 1 ; 638 | fils = 7 ; 639 | REAL = 69.2 ; 640 | } 641 | if (WISH > 69.2) { 642 | ndec = 0 ; 643 | fils = 1 ; 644 | REAL = 75.2 ; 645 | } 646 | if (WISH > 75.2) { 647 | ndec = 0 ; 648 | fils = 2 ; 649 | REAL = 83.2 ; 650 | } 651 | if (WISH > 83.2) { 652 | ndec = 0 ; 653 | fils = 3 ; 654 | REAL = 90.0 ; 655 | } 656 | if (WISH > 90.0) { 657 | ndec = 0 ; 658 | fils = 4 ; 659 | REAL = 95.3 ; 660 | } 661 | #endif 662 | if (WISH > 95.3) { 663 | ndec = 0 ; 664 | fils = 5 ; 665 | REAL = 112.1 ; 666 | } 667 | #if 0 // Too many resolutions, not needed 668 | if (WISH > 112.1) { 669 | ndec = 0 ; 670 | fils = 6 ; 671 | REAL = 127.9 ; 672 | } 673 | if (WISH > 127.9) { 674 | ndec = 0 ; 675 | fils = 7 ; 676 | REAL = 137.9 ; 677 | } 678 | if (WISH > 137.9) { 679 | ndec = 1 ; 680 | fils = 4 ; 681 | REAL = 142.8 ; 682 | } 683 | if (WISH > 142.8) { 684 | ndec = 1 ; 685 | fils = 5 ; 686 | REAL = 167.8 ; 687 | } 688 | if (WISH > 167.8) { 689 | ndec = 1 ; 690 | fils = 9 ; 691 | REAL = 181.1 ; 692 | } 693 | if (WISH > 181.1) { 694 | ndec = 0 ; 695 | fils = 15 ; 696 | REAL = 191.5 ; 697 | } 698 | if (WISH > 191.5) { 699 | ndec = 0 ; 700 | fils = 1 ; 701 | REAL = 225.1 ; 702 | } 703 | if (WISH > 225.1) { 704 | ndec = 0 ; 705 | fils = 2 ; 706 | REAL = 248.8 ; 707 | } 708 | if (WISH > 248.8) { 709 | ndec = 0 ; 710 | fils = 3 ; 711 | REAL = 269.3 ; 712 | } 713 | if (WISH > 269.3) { 714 | ndec = 0 ; 715 | fils = 4 ; 716 | REAL = 284.9 ; 717 | } 718 | #endif 719 | if (WISH > 284.9) { 720 | ndec = 0 ; 721 | fils = 8 ; 722 | REAL = 335.5 ; 723 | } 724 | #if 0 // Too many resolutions, not needed 725 | if (WISH > 335.5) { 726 | ndec = 0 ; 727 | fils = 9 ; 728 | REAL = 361.8 ; 729 | } 730 | if (WISH > 361.8) { 731 | ndec = 0 ; 732 | fils = 10 ; 733 | REAL = 420.2 ; 734 | } 735 | if (WISH > 420.2) { 736 | ndec = 0 ; 737 | fils = 11 ; 738 | REAL = 468.4 ; 739 | } 740 | if (WISH > 468.4) { 741 | ndec = 0 ; 742 | fils = 12 ; 743 | REAL = 518.8 ; 744 | } 745 | if (WISH > 518.8) { 746 | ndec = 0 ; 747 | fils = 13 ; 748 | REAL = 577.0 ; 749 | } 750 | #endif 751 | if (WISH > 577.0) { 752 | ndec = 0 ; 753 | fils = 14 ; 754 | REAL = 620.7 ; 755 | } 756 | 757 | if (WISH > 137.9) dwn3 = 1 ; 758 | 759 | byte BW = (dwn3 << 7) | (ndec << 4) | fils ; 760 | 761 | SI4432_Write_Byte(0x1C , BW ) ; 762 | 763 | rxosr = 500.0 * ( 1.0 + 2.0 * dwn3 ) / ( pow(2.0, (ndec-3.0)) * REAL ); 764 | 765 | byte integer = (int)rxosr ; 766 | byte fractio = (int)((rxosr - integer) * 8 ) ; 767 | byte memory = (integer << 3) | (0x07 & fractio) ; 768 | 769 | SI4432_Write_Byte(0x20 , memory ) ; 770 | return REAL ; 771 | } 772 | 773 | #endif 774 | 775 | void SI4432_Set_Frequency ( long Freq ) { 776 | int hbsel; 777 | long Carrier; 778 | if (Freq >= 480000000) { 779 | hbsel = 1; 780 | Freq = Freq / 2; 781 | } else { 782 | hbsel = 0; 783 | } 784 | int sbsel = 1; 785 | int N = Freq / 10000000; 786 | Carrier = ( 4 * ( Freq - N * 10000000 )) / 625; 787 | int Freq_Band = ( N - 24 ) | ( hbsel << 5 ) | ( sbsel << 6 ); 788 | SI4432_Write_Byte ( 0x75, Freq_Band ); 789 | SI4432_Write_Byte ( 0x76, (Carrier>>8) & 0xFF ); 790 | SI4432_Write_Byte ( 0x77, Carrier & 0xFF ); 791 | delay(2); 792 | } 793 | 794 | int SI4432_RSSI() 795 | { 796 | int RSSI_RAW; 797 | // SEE DATASHEET PAGE 61 798 | #ifdef USE_SI4463 799 | if (SI4432_Sel == 2) { 800 | RSSI_RAW = Si446x_getRSSI(); 801 | } else 802 | #endif 803 | RSSI_RAW = (unsigned char)SI4432_Read_Byte( 0x26 ) ; 804 | // float dBm = 0.5 * RSSI_RAW - 120.0 ; 805 | // Serial.println(dBm,2); 806 | return RSSI_RAW ; 807 | } 808 | 809 | 810 | void SI4432_Sub_Init() 811 | { 812 | SI4432_Reset(); 813 | 814 | #if 0 815 | 816 | SI4432_Write_Byte(0x75, 0x53); 817 | SI4432_Write_Byte(0x76, 0x62); 818 | SI4432_Write_Byte(0x77, 0x00); 819 | 820 | SI4432_Write_Byte(0x6E, 0x19); 821 | SI4432_Write_Byte(0x6F, 0x9A); 822 | SI4432_Write_Byte(0x70, 0x04); 823 | SI4432_Write_Byte(0x58, 0xC0); 824 | 825 | SI4432_Write_Byte(0x1C, 0x81); 826 | SI4432_Write_Byte(0x20, 0x78); 827 | SI4432_Write_Byte(0x21, 0x01); 828 | SI4432_Write_Byte(0x22, 0x11); 829 | SI4432_Write_Byte(0x23, 0x11); 830 | SI4432_Write_Byte(0x24, 0x01); 831 | SI4432_Write_Byte(0x25, 0x13); 832 | SI4432_Write_Byte(0x2C, 0x28); 833 | SI4432_Write_Byte(0x2D, 0x0C); 834 | SI4432_Write_Byte(0x2E, 0x28); 835 | SI4432_Write_Byte(0x1F, 0x03); 836 | SI4432_Write_Byte(0x69, 0x60); 837 | 838 | // disable all interrupts 839 | SI4432_Write_Byte ( 0x06, 0x00 ); 840 | 841 | // Set the sytem in Ready mode. PLL on, RX manual receive 842 | SI4432_Write_Byte ( 0x07, 0x07 ); 843 | 844 | #else 845 | // Enable receiver chain 846 | // SI4432_Write_Byte(0x07, 0x05); 847 | // Clock Recovery Gearshift Value 848 | SI4432_Write_Byte(0x1F, 0x00); 849 | // IF Filter Bandwidth 850 | bandwidth = SI4432_SET_RBW(bandwidth) ; 851 | // REG 0x20 is updated with the IF Filter bandwidth 852 | // Register 0x75 Frequency Band Select 853 | byte sbsel = 1 ; // recommended setting 854 | byte hbsel = 0 ; // low bands 855 | byte fb = 19 ; // 430–439.9 MHz 856 | byte FBS = (sbsel << 6 ) | (hbsel << 5 ) | fb ; 857 | // SI4432_Write_Byte(0x75, FBS) ; 858 | SI4432_Write_Byte(0x75, 0x46) ; 859 | // Register 0x76 Nominal Carrier Frequency 860 | // WE USE 433.92 MHz 861 | // Si443x-Register-Settings_RevB1.xls 862 | // SI4432_Write_Byte(0x76, 0x62) ; 863 | SI4432_Write_Byte(0x76, 0x00) ; 864 | // Register 0x77 Nominal Carrier Frequency 865 | SI4432_Write_Byte(0x77, 0x00) ; 866 | // RX MODEM SETTINGS 867 | SI4432_Write_Byte(0x1C, 0x81) ; 868 | SI4432_Write_Byte(0x1D, 0x3C) ; 869 | SI4432_Write_Byte(0x1E, 0x02) ; 870 | SI4432_Write_Byte(0x1F, 0x03) ; 871 | // SI4432_Write_Byte(0x20, 0x78) ; 872 | SI4432_Write_Byte(0x21, 0x01) ; 873 | SI4432_Write_Byte(0x22, 0x11) ; 874 | SI4432_Write_Byte(0x23, 0x11) ; 875 | SI4432_Write_Byte(0x24, 0x01) ; 876 | SI4432_Write_Byte(0x25, 0x13) ; 877 | SI4432_Write_Byte(0x2A, 0xFF) ; 878 | SI4432_Write_Byte(0x2C, 0x28) ; 879 | SI4432_Write_Byte(0x2D, 0x0C) ; 880 | SI4432_Write_Byte(0x2E, 0x28) ; 881 | 882 | 883 | SI4432_Write_Byte(0x69, 0x10); // No AGC, max LNA of 20dB 884 | SI4432_Write_Byte(0x69, 0x60); // No AGC, max LNA of 20dB 885 | 886 | #endif 887 | 888 | // GPIO automatic antenna switching 889 | SI4432_Write_Byte(0x0B, 0x12) ; 890 | SI4432_Write_Byte(0x0C, 0x15) ; 891 | } 892 | 893 | void SI4432_Init() 894 | { 895 | pinMode(SI_nSEL[0], OUTPUT); 896 | pinMode(SI_nSEL[1], OUTPUT); 897 | pinMode(SI_SCLK, OUTPUT); 898 | pinMode(SI_SDI, OUTPUT); 899 | pinMode(SI_SDO, INPUT_PULLUP); 900 | 901 | digitalWrite(SI_SCLK, LOW); 902 | digitalWrite(SI_SDI, LOW); 903 | 904 | digitalWrite(SI_nSEL[0], HIGH); 905 | digitalWrite(SI_nSEL[1], HIGH); 906 | 907 | SI4432_Reset(); 908 | //DebugLine("IO set"); 909 | SI4432_Sel = 0; 910 | SI4432_Sub_Init(); 911 | 912 | SI4432_Sel = 1; 913 | SI4432_Sub_Init(); 914 | //DebugLine("1 init done"); 915 | 916 | 917 | SI4432_Sel = 0; 918 | SI4432_Write_Byte(0x07, 0x07);// Enable receiver chain 919 | SI4432_Write_Byte(0x09, V0_XTAL_CAPACITANCE);// Tune the crystal 920 | SI4432_Set_Frequency(433920000); 921 | SI4432_Write_Byte(0x0D, 0x1F) ; // Set GPIO2 output to ground 922 | 923 | 924 | SI4432_Sel = 1; 925 | SI4432_Write_Byte(0x7, 0x0B); // start TX 926 | SI4432_Write_Byte(0x09, V1_XTAL_CAPACITANCE);// Tune the crystal 927 | SI4432_Set_Frequency(443920000); 928 | SI4432_Write_Byte(0x6D, 0x1F);//Set full power 929 | 930 | SI4432_Write_Byte(0x0D, 0xC0) ; // Set GPIO2 maximumdrive and clock output 931 | SI4432_Write_Byte(0x0A, 0x02) ; // Set 10MHz output 932 | } 933 | 934 | void SetPowerReference(int freq) 935 | { 936 | SI4432_Sel = 1; //Select Lo module 937 | if (freq < 0 || freq > 7 ) { 938 | SI4432_Write_Byte(0x0D, 0x1F) ; // Set GPIO2 to GND 939 | } else { 940 | SI4432_Write_Byte(0x0D, 0xC0) ; // Set GPIO2 maximumdrive and clock output 941 | SI4432_Write_Byte(0x0A, freq & 0x07) ; // Set GPIO2 frequency 942 | } 943 | } 944 | 945 | //------------PE4302 ----------------------------------------------- 946 | 947 | // Comment out this define to use parallel mode PE4302 948 | #define PE4302_serial 949 | 950 | #ifdef PE4302_serial 951 | // Clock and data pints are shared with SI4432 952 | // Serial mode LE pin 953 | #define PE4302_en 10 954 | #else 955 | //Parallel mode bit 0 pin number, according below line the PE4302 is connected to lines A0,A1,A2,A3,A4,A5 956 | #define PE4302_pinbase A0 957 | #endif 958 | 959 | void PE4302_init() { 960 | #ifdef PE4302_serial 961 | pinMode(PE4302_en, OUTPUT); 962 | digitalWrite(PE4302_en, LOW); 963 | #else 964 | for (int i=0; i<6; i++) pinMode(i+PE4302_pinbase, OUTPUT); // Setup attenuator at D6 - D11 965 | #endif 966 | } 967 | 968 | void PE4302_Write_Byte(byte DATA ) 969 | { 970 | #ifdef PE4302_serial 971 | //Serial mode output 972 | digitalWrite(SI_SCLK, LOW); 973 | shiftOut(SI_SDI , SI_SCLK , MSBFIRST , DATA ); 974 | digitalWrite(PE4302_en, HIGH); 975 | digitalWrite(PE4302_en, LOW); 976 | #else 977 | // Parallel mode output 978 | for (int i=0; i<6;i++) { 979 | digitalWrite(i+PE4302_pinbase, p & (1<0) 1022 | { 1023 | if (digit == 6) { 1024 | t[i++] = '.'; 1025 | leading = 0; 1026 | } 1027 | if (digit == incrBaseDigit) 1028 | t[i++] = '['; 1029 | if (f / divider > 0) 1030 | leading = 0; 1031 | t[i++] = ((int) (f / divider)) + '0'; 1032 | f %= divider; 1033 | if (digit == incrBaseDigit) 1034 | t[i++] = ']'; 1035 | divider /= 10; 1036 | digit -= 1; 1037 | } 1038 | t[i++] = 0; 1039 | // Serial.println(t); 1040 | #ifdef USE_DISPLAY 1041 | tft.fillRect(0, 0, tft.width(), oY-2, DISPLAY_BLACK); 1042 | // clearDisplay(); 1043 | textWhite(); // Draw white text 1044 | tft.setCursor(0, 1); 1045 | tft.print(t); 1046 | sendDisplay(); 1047 | #endif 1048 | } 1049 | 1050 | void ChangeFrequency(long v[]) 1051 | { 1052 | static long old_time; 1053 | if (buttonState == buttonLongDown) 1054 | { 1055 | if (buttonEvent == buttonRotateUp) { 1056 | if (incrBase > 10) { 1057 | incrBase /= 10; 1058 | incrBaseDigit--; 1059 | } 1060 | } else if ( buttonEvent == buttonRotateDown){ 1061 | if (incrBase < 100000000) { 1062 | incrBase *= 10; 1063 | incrBaseDigit++; 1064 | } 1065 | } 1066 | showFreq(v[dataIndex]); // to update selected digit 1067 | Serial.print(incrBase); 1068 | Serial.println(F(": incrbase set")); 1069 | } 1070 | else if ( buttonEvent == buttonRotateDown || buttonEvent == buttonRotateUp){ 1071 | // incr = 1; 1072 | v[dataIndex] = (v[dataIndex] / incrBase) * incrBase; // round to incrBase 1073 | if (buttonEvent == buttonRotateUp) { 1074 | v[dataIndex] += incr*incrBase; 1075 | if (v[dataIndex] > 440000000) 1076 | v[dataIndex] = 440000000; 1077 | } else { 1078 | v[dataIndex] -= incr*incrBase; 1079 | if (v[dataIndex] < 0) 1080 | v[dataIndex] = 0; 1081 | } 1082 | showFreq(v[dataIndex]); // to show updated freq 1083 | Serial.print(v[dataIndex]); 1084 | Serial.println(F(": value set")); 1085 | // showFreq(v[dataIndex]); 1086 | //setFreq(v[dataIndex], (int)dataIndex, true); 1087 | //Serial.println(v[dataIndex]); 1088 | } 1089 | } 1090 | 1091 | //---------------- menu system ----------------------- 1092 | 1093 | int settingMax = 0; 1094 | int settingMin = -100; 1095 | int settingAttenuate = 0; 1096 | int settingGenerate = 0; 1097 | int settingBandwidth = 600; 1098 | int settingLevelCal = 0; 1099 | int settingPowerCal = 1; 1100 | 1101 | 1102 | 1103 | #ifdef USE_ROTARY 1104 | 1105 | const char T_off[] PROGMEM = "Off"; 1106 | const char T_on[] PROGMEM = "On"; 1107 | 1108 | const char* const toggleText[] PROGMEM = { 1109 | T_off, //0 1110 | T_on 1111 | }; 1112 | 1113 | 1114 | #define MA_CC 1 1115 | #define MA_CZ 2 1116 | #define MA_IC 3 1117 | #define MA_IZ 4 1118 | #define MA_FR 5 1119 | 1120 | #define menuItem 1 1121 | #define menuAction 2 1122 | #define menuValue 3 1123 | #define menuToggle 4 1124 | 1125 | typedef struct { 1126 | const char kind; 1127 | const char prev; 1128 | const char next; 1129 | const char up; 1130 | const char menuMin; 1131 | const char menuMax; 1132 | const PROGMEM char itemText[10]; 1133 | } menuType; 1134 | 1135 | 1136 | const menuType menu[] PROGMEM = { 1137 | #define MainMenu 1 1138 | // 0 1139 | { menuItem, 0, 0, 0, MainMenu, 0, "Main"}, 1140 | // 1 1141 | { menuAction,MainMenu + 6, MainMenu + 1, 0, MA_FR, 0, "From",}, 1142 | { menuAction,MainMenu + 0, MainMenu + 2, 0, MA_FR, 1, "To",}, 1143 | { menuValue, MainMenu + 1, MainMenu + 3, 0, (char)-120, 20, "Max"}, 1144 | { menuValue, MainMenu + 2, MainMenu + 4, 0, (char)-120, 20, "Min"}, 1145 | { menuValue, MainMenu + 3, MainMenu + 5, 0, (char)-30, 0, "Attenuate"}, 1146 | { menuToggle,MainMenu + 4, MainMenu + 6, 0, 0, 1, "Generate"}, 1147 | { menuAction,MainMenu + 5, MainMenu + 7, 0, MA_FR, 2, "IF",}, 1148 | { menuValue, MainMenu + 6, MainMenu + 8, 0, (char)-50, +50, "LevelCal",}, 1149 | { menuValue, MainMenu + 7, MainMenu + 0, 0, (char)-1, 8, "PowerCal",}, 1150 | #if 0 1151 | #endif 1152 | }; 1153 | 1154 | 1155 | int currentMenu; 1156 | int menuActive; 1157 | //int dataIndex; 1158 | int dirty; 1159 | int stateChange; 1160 | int menuOpen; 1161 | 1162 | void ProcessMenu(int *v = NULL); 1163 | 1164 | void HandleMenu() 1165 | { 1166 | switch (currentMenu) { 1167 | case 3: ProcessMenu (&settingMax); break; 1168 | case 4: ProcessMenu (&settingMin); break; 1169 | case 5: ProcessMenu (&settingAttenuate); 1170 | // Serial.print(F("Attenuate = ")); 1171 | // Serial.println(settingAttenuate); 1172 | break; 1173 | case 6: ProcessMenu (&settingGenerate); break; 1174 | case 8: ProcessMenu (&settingLevelCal); break; 1175 | case 9: ProcessMenu (&settingPowerCal); break; 1176 | default:if (menuActive && stateChange) showFreq(lFreq[dataIndex]); ProcessMenu ((int *)lFreq); break; 1177 | } 1178 | buttonEvent = 0; 1179 | } 1180 | 1181 | void InitMenu() 1182 | { 1183 | currentMenu = 1; 1184 | menuActive = false; 1185 | dataIndex = 0; 1186 | dirty = false; 1187 | stateChange = true; 1188 | menuOpen = false; 1189 | } 1190 | char buffer[16]; 1191 | 1192 | void ProcessMenu(int *v) 1193 | { 1194 | int kind; int n; int p; int u; int mi; 1195 | int ma; 1196 | 1197 | update: 1198 | 1199 | kind = pgm_read_byte(&(menu[currentMenu].kind)); 1200 | n = pgm_read_byte(&(menu[currentMenu].next)); 1201 | p = pgm_read_byte(&(menu[currentMenu].prev)); 1202 | u = pgm_read_byte(&(menu[currentMenu].up)); 1203 | mi = (char) pgm_read_byte(&(menu[currentMenu].menuMin)); if (mi > 127) mi -= 256; 1204 | ma = (char) pgm_read_byte(&(menu[currentMenu].menuMax)); if (ma > 127) ma -= 256; 1205 | 1206 | if (stateChange || dirty) { 1207 | /* 1208 | if (menuOpen) 1209 | Serial.print(F("Open ")); 1210 | if (menuActive) 1211 | Serial.print(F("Active ")); 1212 | if (dirty) 1213 | Serial.print(F("Dirty ")); 1214 | if (stateChange) 1215 | Serial.print(F("stateChange ")); 1216 | Serial.print(u); 1217 | Serial.print(F(":[")); 1218 | Serial.print(p); 1219 | Serial.print(F(":")); 1220 | Serial.print(n); 1221 | Serial.print(F("]{min=")); 1222 | Serial.print(mi); 1223 | Serial.print(F(",max=")); 1224 | Serial.print(ma); 1225 | Serial.print(F("}:")); 1226 | Serial.print(currentMenu); 1227 | Serial.println(F(": Menu entered")); 1228 | */ 1229 | } 1230 | 1231 | //#endif 1232 | 1233 | #ifdef USE_DISPLAY 1234 | __FlashStringHelper *ut; 1235 | ut = ( __FlashStringHelper *) &(menu[u].itemText[0]); 1236 | __FlashStringHelper *t; 1237 | t = ( __FlashStringHelper *) &(menu[currentMenu].itemText[0]); 1238 | 1239 | if (stateChange || dirty) { 1240 | tft.fillRect(0, 0, tft.width(), oY-2, DISPLAY_BLACK); 1241 | // clearDisplay(); 1242 | textWhite(); // Draw white text 1243 | tft.setCursor(0, 0); 1244 | if (!menuActive) { 1245 | tft.print(ut); 1246 | tft.print(':'); 1247 | tft.print(t); // Show menu text 1248 | } else { 1249 | tft.print(t); 1250 | tft.print(':'); 1251 | // tft.setCursor(8, 0); 1252 | if (kind == menuToggle) { 1253 | strcpy_P(buffer, (char*)pgm_read_word(&(toggleText[(v[dataIndex]) + mi]))); // Toggle text 1254 | tft.print(buffer); 1255 | } else if (kind == menuValue) { 1256 | tft.print(v[dataIndex]); // Value 1257 | } else if (kind == menuAction) { 1258 | // tft.print((const __FlashStringHelper*)&(v[5])); // Nothing to show 1259 | } 1260 | // else do not show anything 1261 | } 1262 | sendDisplay(); 1263 | stateChange = false; 1264 | dirty = false; 1265 | // if (buttonEvent == 0) 1266 | // return; 1267 | } 1268 | #endif 1269 | // buttonUp, buttonDown, buttonLongDown, buttonBack, buttonRotateUp, buttonRotateDown 1270 | 1271 | //#ifdef USE_ROTARY 1272 | 1273 | if (!menuActive) { 1274 | if (buttonEvent == buttonRotateUp) { 1275 | currentMenu = n; 1276 | stateChange = true; 1277 | } else if (buttonEvent == buttonRotateDown) { 1278 | currentMenu = p; 1279 | stateChange = true; 1280 | } else if (buttonEvent == shortBackClickRelease) { 1281 | if (u != 0) { 1282 | currentMenu = u + dataIndex; 1283 | dataIndex = 0; 1284 | stateChange = true; 1285 | } 1286 | } else if (buttonEvent == shortClickRelease) { // Single click 1287 | if (kind == menuItem) { 1288 | currentMenu = mi; 1289 | dataIndex = ma; 1290 | } else { 1291 | if (kind == menuAction) 1292 | dataIndex = ma; 1293 | menuActive = true; 1294 | // Serial.print(currentMenu); 1295 | // Serial.println(F(": Menu activated")); 1296 | } 1297 | stateChange = true; 1298 | } 1299 | buttonEvent = 0; 1300 | } else { // Menu is active 1301 | if (buttonEvent == shortClickRelease) { // Single click 1302 | menuActive = false; 1303 | stateChange = true; 1304 | // Serial.print(currentMenu); 1305 | // Serial.println(F(": Menu deactivated")); 1306 | buttonEvent = 0; 1307 | // Serial.println(F("Menu Closed")); 1308 | menuOpen = false; // Stop displaying menu 1309 | } else 1310 | if (kind == menuToggle || kind == menuValue) { 1311 | if (buttonEvent == buttonRotateDown && v[dataIndex] > mi) { 1312 | v[dataIndex] -= (kind == menuToggle? 1 : 1); 1313 | dirty = true; 1314 | } else if (buttonEvent == buttonRotateUp && v[dataIndex] < ma) { 1315 | v[dataIndex] += (kind == menuToggle? 1 : 1); 1316 | dirty = true; 1317 | } 1318 | if (buttonEvent) { 1319 | // Serial.print(v[dataIndex]); 1320 | // Serial.println(F(": Value changed")); 1321 | } 1322 | buttonEvent = 0; 1323 | } else if (kind == menuAction) { 1324 | ChangeFrequency((long int *)v); 1325 | buttonEvent = 0; 1326 | } 1327 | } 1328 | //#endif 1329 | } 1330 | 1331 | 1332 | #endif 1333 | //------------------------------------------ 1334 | 1335 | 1336 | int debug = 0; 1337 | 1338 | 1339 | #define DebugLine(X) { if (debug) Serial.println(X); } 1340 | #define Debug(X) { if (debug) Serial.print(X); } 1341 | 1342 | 1343 | int inData = 0; 1344 | long steps = DISPLAY_POINTS; 1345 | unsigned long startFreq = 250000000; 1346 | unsigned long stopFreq = 300000000; 1347 | unsigned long lastFreq[6] = { 300000000, 300000000,0,0,0,0}; 1348 | int lastParameter[10]; 1349 | int parameter; 1350 | int VFO = 0; 1351 | int RX = 2; 1352 | int extraVFO=-1; 1353 | int extraVFO2 = -1; 1354 | unsigned long reg = 0; 1355 | long offset=0; 1356 | long offset2=0; 1357 | static unsigned int spacing = 10000; 1358 | double delta=0.0; 1359 | int phase=0; 1360 | int deltaPhase; 1361 | int delaytime = 50; 1362 | int drive = 6; 1363 | unsigned int sensor; 1364 | int hardware = 0; 1365 | 1366 | 1367 | // A Arduino zero benefits from a large serial buffer, for a nano you can reduce the buffer size such as 64 1368 | #define BUFFERSIZE 256 1369 | uint8_t serialBuff[BUFFERSIZE]; 1370 | volatile int serialIndex=0; 1371 | //#define HIGHPOINT (BUFFERSIZE - 20) 1372 | #define HIGHPOINT (0) 1373 | 1374 | void serialFlushIf(int amount) 1375 | { 1376 | if (serialIndex > amount) 1377 | { 1378 | pinMode(tinySA_led, OUTPUT); // Flash led if serial data is being send 1379 | digitalWrite(tinySA_led, HIGH); 1380 | Serial.write(serialBuff, serialIndex); 1381 | digitalWrite(tinySA_led, LOW); 1382 | serialIndex = 0; 1383 | } 1384 | } 1385 | 1386 | 1387 | 1388 | 1389 | void info() 1390 | { 1391 | Serial.println("SI4432 Sweeper"); 1392 | Serial.print("A = Start frequency, currently "); 1393 | Serial.println(startFreq); 1394 | Serial.print("B = Stop frequency, currently "); 1395 | Serial.println(stopFreq); 1396 | Serial.print("S = Steps, currently "); 1397 | Serial.println(steps); 1398 | Serial.println("M = Single sweep"); 1399 | Serial.println("C = Continious sweep until Q"); 1400 | Serial.println("H = show menu"); 1401 | Serial.print("T = Timestep in ms, currently "); 1402 | Serial.println(delaytime); 1403 | Serial.print("O = Output frequency, currently "); 1404 | Serial.println(lastFreq[VFO]); 1405 | // Serial.print("D = Drive[2,4,6,8], currently "); 1406 | // Serial.println(drive); 1407 | Serial.print("V = VFO[0,1,2], currently "); 1408 | Serial.println(VFO); 1409 | // Serial.print("G = spacing, currently "); 1410 | // Serial.println(spacing); 1411 | // Serial.print("E = extra VFO and Offset, currently "); 1412 | // Serial.print(extraVFO); 1413 | // Serial.print("="); 1414 | // Serial.print(offset); 1415 | // Serial.print(", "); 1416 | // Serial.print(extraVFO2); 1417 | // Serial.print("="); 1418 | // Serial.println(offset2); 1419 | // Serial.print("F = Perform VNA scan: mode, startFreq, steps, freqStep, stepTime, IF, HW"); 1420 | Serial.print("X = read write hex register, last written 0x"); 1421 | Serial.println(reg, HEX); 1422 | // Serial.print("Y = write stepper(+,-,/,* or delta), delta="); 1423 | // Serial.println(delta); 1424 | Serial.print("W = Set Bandwidth, currently "); 1425 | Serial.println(bandwidth); 1426 | Serial.print("? = Debug level "); 1427 | Serial.println(debug); 1428 | // Serial.println("R = Reset"); 1429 | } 1430 | 1431 | 1432 | unsigned char myData[DISPLAY_POINTS+1]; 1433 | int peakLevel; 1434 | double peakFreq; 1435 | 1436 | #define BARSTART 24 1437 | 1438 | #ifdef USE_DISPLAY 1439 | 1440 | void displayHisto () 1441 | { 1442 | // clearDisplay(); 1443 | DrawCheckerBoard(); 1444 | //int settingMax = 0; 1445 | //int settingMin = -120; 1446 | int delta=settingMax - settingMin; 1447 | 1448 | // Display levels 1449 | tft.fillRect(0, 0, oX-2, tft.height(), DISPLAY_BLACK); 1450 | textWhite(); 1451 | tft.setCursor(0,oY); // Start at top-left corner 1452 | tft.println(settingMax); 1453 | tft.setCursor(0,tft.height() - 8); 1454 | tft.println(settingMin); 1455 | 1456 | // Dsiplay frequencies 1457 | tft.fillRect(0, 0, tft.width(), oY-2, DISPLAY_BLACK); 1458 | tft.setTextColor(DISPLAY_INVERSE); // Draw white text 1459 | tft.setCursor(oX+2,0); // Start at top-left corner 1460 | double f = (((double)(startFreq - lastFreq[0]))/ 1000000.0); 1461 | tft.println(f); 1462 | tft.setCursor(tft.width() - 36,0); 1463 | f = (((double)(stopFreq - lastFreq[0]))/ 1000000.0); 1464 | tft.println(f); 1465 | 1466 | if (peakLevel > -150) { 1467 | tft.setCursor(0,tft.height()/2); // Start at top-left corner 1468 | tft.println((int)((peakLevel/ 2.0 - settingAttenuate) - 120.0)+settingLevelCal); 1469 | tft.setCursor(oX+2,8); 1470 | tft.println(peakFreq/ 1000000.0); 1471 | } 1472 | 1473 | 1474 | #define Y_GRIDS 9 1475 | for (int i=0; i= Y_GRIDS * dY) f = Y_GRIDS * dY-1; 1479 | if (f < 0) f = 0; 1480 | double f2 = ((myData[i+1] / 2.0 - settingAttenuate) - 120.0); 1481 | f2 = (f2 - settingMin) * Y_GRIDS * dY / delta; 1482 | if (f2 >= Y_GRIDS * dY) f2 = Y_GRIDS * dY-1; 1483 | if (f2 < 0) f2 = 0; 1484 | int x = i; 1485 | int Y1 = Y_GRIDS * dY - 1 - (int)f; 1486 | int Y2 = Y_GRIDS * dY - 1 - (int)f2; 1487 | tft.drawLine(x+oX, oY+Y1, x+oX+1, oY+Y2, DISPLAY_YELLOW); 1488 | tft.drawLine(x+oX, oY+Y1+1, x+oX+1, oY+Y2+1, DISPLAY_YELLOW); 1489 | } 1490 | 1491 | 1492 | 1493 | sendDisplay(); 1494 | } 1495 | #endif 1496 | 1497 | void setup() 1498 | { 1499 | 1500 | Serial.begin(115200); // 115200 1501 | #if defined(ARDUINO_ARCH_SAMD) 1502 | // while(!SerialUSB); // Uncomment this line if you want the Arduino to wait with starting till the serial monitor is activated, usefull when debugging 1503 | #endif 1504 | //return; 1505 | #if defined(ARDUINO_ARCH_SAMD) 1506 | Wire.setClock(800000); 1507 | #endif 1508 | 1509 | //SPISettings(12000000, MSBFIRST, SPI_MODE0) 1510 | //SPI.beginTransaction(); 1511 | 1512 | Serial.println("Starting"); 1513 | SI4432_Init(); 1514 | Serial.println("Init done"); 1515 | 1516 | info(); 1517 | 1518 | #ifdef USE_SSD1306 1519 | if(!tft.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 1520 | Serial.println(F("SSD1306 allocation failed")); 1521 | 1522 | } 1523 | #endif 1524 | #ifdef USE_ILI9341 1525 | tft.begin(); 1526 | tft.setRotation(1); 1527 | 1528 | #endif 1529 | // Show initial display buffer contents on the screen -- 1530 | // the library initializes this with an Adafruit splash screen. 1531 | // sendDisplay(); 1532 | // displayHisto(); 1533 | #ifdef USE_ROTARY 1534 | R_setup(); 1535 | #define ENABLE_PULLUPS 1 1536 | pinMode(buttonPin, (ENABLE_PULLUPS ? INPUT_PULLUP : INPUT)); 1537 | pinMode(backButtonPin, (ENABLE_PULLUPS ? INPUT_PULLUP : INPUT)); 1538 | InitMenu(); 1539 | #endif 1540 | PE4302_init(); 1541 | PE4302_Write_Byte(0); 1542 | #ifdef USE_SI4463 1543 | Si446x_init(); 1544 | Si446x_RX ((uint8_t)70); 1545 | #endif 1546 | } 1547 | 1548 | 1549 | 1550 | void histo(int lev) 1551 | { 1552 | Serial.print(lev); 1553 | // Serial.print(": "); 1554 | // while (lev > 80) lev = lev / 2; 1555 | // while (lev--) 1556 | // Serial.print("*"); 1557 | Serial.println(""); 1558 | } 1559 | 1560 | long old_time = 0; 1561 | 1562 | void setFreq(int V, unsigned long freq) 1563 | { 1564 | if (V>=0) { 1565 | SI4432_Sel = V; 1566 | #ifdef USE_SI4463 1567 | if (SI4432_Sel == 2) { 1568 | freq = freq - 433000000; 1569 | freq = freq / 10000; //convert to 10kHz channel starting with 433MHz 1570 | // Serial.print("Set frequency Si4463 = "); 1571 | // Serial.println(freq); 1572 | Si446x_RX ((uint8_t)freq); 1573 | } 1574 | else 1575 | #endif 1576 | SI4432_Set_Frequency(freq); 1577 | } 1578 | } 1579 | 1580 | int autoSweepStep = 0; 1581 | long autoSweepFreq = 0; 1582 | long autoSweepFreqStep = 0; 1583 | int standalone = true; 1584 | 1585 | void loop() 1586 | { 1587 | 1588 | #ifdef USE_ROTARY 1589 | 1590 | if( /*standalone && */ Serial.available() == 0) // Serial has priority 1591 | { 1592 | //-------------------button handling -------------------- 1593 | int x = R_delta(); 1594 | int reading = digitalRead(buttonPin); 1595 | int reading2 = digitalRead(backButtonPin); 1596 | if (reading != lastButtonRead || reading2 != lastBackButtonRead ) { 1597 | lastDebounceTime = millis(); 1598 | } 1599 | lastButtonRead = reading; 1600 | lastBackButtonRead = reading2; 1601 | 1602 | buttonEvent = 0; 1603 | if ((millis() - lastDebounceTime) > debounceDelay) { 1604 | switch(buttonState) { 1605 | case buttonUp: 1606 | if (reading == LOW) 1607 | { 1608 | buttonState = buttonDown; 1609 | } 1610 | break; 1611 | case buttonDown: 1612 | if (reading == HIGH) 1613 | { 1614 | buttonState = buttonUp; 1615 | buttonEvent = shortClickRelease; 1616 | } 1617 | if ((millis() - lastDebounceTime) > longPressDelay) 1618 | { 1619 | buttonState = buttonLongDown; 1620 | buttonEvent = longClick; 1621 | } 1622 | break; 1623 | case buttonLongDown: 1624 | if (reading == HIGH) 1625 | { 1626 | buttonState = buttonUp; 1627 | buttonEvent = longClickRelease; 1628 | } 1629 | break; 1630 | 1631 | } 1632 | switch(backButtonState) { 1633 | case buttonUp: 1634 | if (reading2 == LOW) 1635 | { 1636 | backButtonState = buttonDown; 1637 | } 1638 | break; 1639 | case buttonDown: 1640 | if (reading2 == HIGH) 1641 | { 1642 | backButtonState = buttonUp; 1643 | buttonEvent = shortBackClickRelease; 1644 | } 1645 | if ((millis() - lastDebounceTime) > longPressDelay) 1646 | { 1647 | backButtonState = buttonLongDown; 1648 | buttonEvent = longBackClick; 1649 | } 1650 | break; 1651 | case buttonLongDown: 1652 | if (reading2 == HIGH) 1653 | { 1654 | backButtonState = buttonUp; 1655 | buttonEvent = longBackClickRelease; 1656 | } 1657 | break; 1658 | 1659 | } 1660 | } 1661 | if (x) 1662 | { 1663 | Serial.print("Rotaryevent: "); 1664 | Serial.println(x); 1665 | long new_time = millis(); 1666 | if (new_time - old_time > 50) 1667 | incr = 1; 1668 | else if (new_time - old_time > 20) 1669 | incr = 5; 1670 | else 1671 | incr = 20; 1672 | old_time = new_time; 1673 | if (x > 0) 1674 | buttonEvent = buttonRotateUp; 1675 | else 1676 | buttonEvent = buttonRotateDown; 1677 | } 1678 | if (buttonEvent != 0) { 1679 | // Serial.print("Buttonevent: "); 1680 | // Serial.println(buttonEvent); 1681 | } 1682 | if (buttonEvent || stateChange|| dirty) { 1683 | if (buttonEvent && !menuOpen) { 1684 | menuOpen = true; 1685 | buttonEvent = 0; 1686 | menuActive = false; 1687 | dataIndex = 0; 1688 | dirty = true; 1689 | stateChange = true; 1690 | // Serial.println(F("Menu open")); 1691 | } 1692 | HandleMenu(); 1693 | } 1694 | 1695 | if (!menuOpen && standalone) { 1696 | // Serial.print("AutoSweepStep: "); 1697 | // Serial.println(autoSweepStep); 1698 | if (autoSweepStep == 0) { 1699 | autoSweepFreq = lFreq[0]; 1700 | autoSweepFreqStep = (lFreq[1] - lFreq[0])/DISPLAY_POINTS; 1701 | setFreq (0, lFreq[2]); 1702 | lastFreq[0] = lFreq[2]; 1703 | startFreq = lFreq[0] + lFreq[2]; 1704 | stopFreq = lFreq[1] + lFreq[2]; 1705 | int p = - settingAttenuate * 2; 1706 | PE4302_Write_Byte(p); 1707 | SetPowerReference(settingPowerCal); 1708 | settingBandwidth = ((float)(lFreq[1] - lFreq[0]))/DISPLAY_POINTS/1000.0; 1709 | SI4432_Sel = 0; 1710 | SI4432_SET_RBW(settingBandwidth); 1711 | SI4432_Sel = 1; 1712 | SI4432_Write_Byte(0x6D, 0x1C + (drive - 2 )/2);//Set full power 1713 | 1714 | peakLevel = -150; 1715 | peakFreq = -1.0; 1716 | } 1717 | SI4432_Sel=1; 1718 | setFreq (1, lFreq[2] + autoSweepFreq); 1719 | SI4432_Sel=0; 1720 | myData[autoSweepStep] = SI4432_RSSI(); 1721 | if (settingBandwidth > 500) { 1722 | int subSteps = (settingBandwidth / 500) - 1; 1723 | while (subSteps > 0) { 1724 | //Serial.print("substeps = "); 1725 | //Serial.println(subSteps); 1726 | SI4432_Sel=1; 1727 | setFreq (1, lFreq[2] + autoSweepFreq + subSteps * 500000); 1728 | //Serial.print("Freq = "); 1729 | //Serial.println(lFreq[2] + autoSweepFreq + subSteps * 500000); 1730 | SI4432_Sel=0; 1731 | int subRSSI = SI4432_RSSI(); 1732 | if (myData[autoSweepStep] < subRSSI) 1733 | myData[autoSweepStep] = subRSSI; 1734 | subSteps--; 1735 | } 1736 | } 1737 | 1738 | if (autoSweepFreq > 1000000) { 1739 | if (peakLevel < myData[autoSweepStep]) { 1740 | peakLevel = myData[autoSweepStep]; 1741 | peakFreq = autoSweepFreq; 1742 | } 1743 | } 1744 | 1745 | if (myData[autoSweepStep] == 0) { 1746 | SI4432_Init(); 1747 | } 1748 | autoSweepStep++; 1749 | autoSweepFreq += (lFreq[1] - lFreq[0])/DISPLAY_POINTS; 1750 | if (autoSweepStep >= DISPLAY_POINTS) { 1751 | autoSweepStep = 0; 1752 | #if USE_DISPLAY 1753 | displayHisto(); 1754 | #endif 1755 | } 1756 | } 1757 | } 1758 | #endif 1759 | //-------------------------------- 1760 | inData = 0; 1761 | 1762 | // if (!Serial) NVIC_SystemReset(); 1763 | if(Serial.available() > 0) // see if incoming serial data: 1764 | { 1765 | inData = Serial.read(); // read oldest byte in serial buffer: 1766 | // Serial.println(inData); 1767 | 1768 | if(inData == 'M' || inData == 'm' || inData == 'L' || inData == 'l') 1769 | { 1770 | standalone = false; 1771 | double oldfreq, freq; 1772 | int isLogSweep = false; 1773 | double freqstep = (stopFreq - startFreq) / steps; 1774 | double freqmult = pow(10.0, log10(stopFreq/startFreq)/steps); 1775 | unsigned long old_micros, start_micros; 1776 | unsigned long old_millis; 1777 | 1778 | if(inData == 'L' || inData == 'l') 1779 | isLogSweep = true; 1780 | inData = 0; 1781 | SI4432_Sel=RX; 1782 | if (SI4432_RSSI() == 0) { 1783 | // Serial.println("Init done"); 1784 | SI4432_Init(); 1785 | } 1786 | 1787 | delay(10); 1788 | freq = startFreq; 1789 | Serial.println("{"); 1790 | old_millis = millis(); 1791 | for(int i = 0; i < steps; i++ ) 1792 | { 1793 | unsigned long modfreq = freq; 1794 | serialFlushIf(HIGHPOINT); 1795 | old_micros = micros(); 1796 | if (extraVFO>=0) { 1797 | setFreq(extraVFO,modfreq-offset); 1798 | lastFreq[extraVFO] = modfreq-offset; 1799 | } 1800 | if (extraVFO2>=0) { 1801 | setFreq(extraVFO2,modfreq-offset2); 1802 | lastFreq[extraVFO2] = modfreq-offset2; 1803 | } 1804 | setFreq (VFO, modfreq); 1805 | lastFreq[VFO] = freq; 1806 | if (i>0) { 1807 | serialBuff[serialIndex++] = 'x'; 1808 | serialBuff[serialIndex++] = ((byte) (sensor)); 1809 | serialBuff[serialIndex++] = ((byte) (sensor>>8)); 1810 | serialFlushIf(0); ///TEMP ----------------------------------------------- 1811 | 1812 | if (i < 128){ 1813 | myData[i] = sensor; 1814 | } 1815 | 1816 | } 1817 | #if 1 1818 | while (micros() - old_micros < (delaytime * 100L)*2/3 ) { 1819 | delayMicroseconds(100); 1820 | } 1821 | 1822 | #endif 1823 | oldfreq = freq; 1824 | if (isLogSweep) 1825 | freq = freq * freqmult; 1826 | else 1827 | freq = freq + freqstep; 1828 | // if (bandwidth>0) { 1829 | // sensor = (int)(millis() - old_millis); 1830 | // } else { 1831 | SI4432_Sel=RX; 1832 | sensor = SI4432_RSSI(); 1833 | // } 1834 | } 1835 | serialBuff[serialIndex++] = 'x'; 1836 | serialBuff[serialIndex++] = ((byte) (sensor)); 1837 | serialBuff[serialIndex++] = ((byte) (sensor>>8)); 1838 | // displayHisto(); 1839 | serialFlushIf(0); 1840 | Serial.println("}"); 1841 | //standalone = true; 1842 | } 1843 | 1844 | if(inData == 'S' || inData == 's') 1845 | { 1846 | steps = Serial.parseInt(); 1847 | Serial.print("Steps: "); 1848 | Serial.println(steps); 1849 | } 1850 | 1851 | if(inData == 'H' || inData == 'h') 1852 | { 1853 | info(); 1854 | } 1855 | 1856 | if(inData == 'X' || inData == 'x') 1857 | { 1858 | char t[40]; 1859 | int i = 0; 1860 | int reg; 1861 | int addr; 1862 | char c = 0; 1863 | delay(1); 1864 | while (Serial.available() > 0 && c != ' ') { 1865 | delay(1); 1866 | c = Serial.read(); //gets one byte from serial buffer 1867 | t[i++] = c; //makes the string readString 1868 | } 1869 | t[i++] = 0; 1870 | addr = strtoul(t, NULL, 16); 1871 | i = 0; 1872 | while (Serial.available() > 0) { 1873 | delay(1); 1874 | c = Serial.read(); //gets one byte from serial buffer 1875 | t[i++] = c; //makes the string readString 1876 | } 1877 | t[i++] = 0; 1878 | SI4432_Sel = VFO; 1879 | if (i == 1) { 1880 | Serial.print("Reg["); 1881 | Serial.print(addr, HEX); 1882 | Serial.print("] : "); 1883 | Serial.println(SI4432_Read_Byte(addr), HEX); 1884 | } else { 1885 | reg = strtoul(t, NULL, 16); 1886 | Serial.print("Reg["); 1887 | Serial.print(addr, HEX); 1888 | Serial.print("] = "); 1889 | Serial.println(reg, HEX); 1890 | SI4432_Write_Byte(addr, reg); 1891 | } 1892 | inData = 0; 1893 | } 1894 | 1895 | 1896 | if(inData == '?') 1897 | { 1898 | debug = !debug; 1899 | Serial.print("Debug level "); 1900 | Serial.println(debug); 1901 | } 1902 | 1903 | if(inData == 'T' || inData == 't') 1904 | { 1905 | delaytime = Serial.parseInt(); 1906 | Serial.print("time pr step: "); 1907 | Serial.println(delaytime); 1908 | inData = 0; 1909 | } 1910 | 1911 | if(inData == 'A' || inData == 'a') 1912 | { 1913 | startFreq = Serial.parseInt(); 1914 | Serial.print("Start: "); 1915 | Serial.println(startFreq); 1916 | inData = 0; 1917 | } 1918 | 1919 | if(inData == 'B' || inData == 'b') 1920 | { 1921 | stopFreq = Serial.parseInt(); 1922 | Serial.print("Stop: "); 1923 | Serial.println(stopFreq); 1924 | inData = 0; 1925 | } 1926 | 1927 | if(inData == 'O' || inData == 'o') 1928 | { 1929 | lastFreq[VFO] = Serial.parseInt(); 1930 | unsigned long modfreq = lastFreq[VFO]; 1931 | setFreq(VFO,modfreq); 1932 | if (extraVFO>=0) { 1933 | setFreq(extraVFO,modfreq-offset); 1934 | } 1935 | if (extraVFO2>=0) { 1936 | setFreq(extraVFO2,modfreq-offset2); 1937 | } 1938 | Serial.print("Output frequency: "); 1939 | Serial.println(modfreq); 1940 | inData = 0; 1941 | } 1942 | 1943 | if(inData == 'Y' || inData == 'y') 1944 | { 1945 | if(Serial.available() > 0) // see if incoming serial data: 1946 | { 1947 | inData = Serial.read(); // read oldest byte in serial buffer: 1948 | 1949 | if (inData == '+') { 1950 | lastFreq[VFO] += delta; 1951 | } else 1952 | if (inData == '-') { 1953 | lastFreq[VFO] -= delta; 1954 | } else 1955 | if (inData == '*') { 1956 | lastFreq[VFO] *= delta; 1957 | } else 1958 | if (inData == '/') { 1959 | lastFreq[VFO] /= delta; 1960 | } else { 1961 | delta = Serial.parseFloat(); 1962 | } 1963 | unsigned long modfreq = lastFreq[VFO]; 1964 | setFreq(VFO,modfreq); 1965 | if (extraVFO>=0) { 1966 | setFreq(extraVFO,modfreq-offset); 1967 | } 1968 | if (extraVFO2>=0) { 1969 | setFreq(extraVFO2,modfreq-offset2); 1970 | } 1971 | // Serial.print("Output frequency: "); 1972 | // Serial.println(modfreq); 1973 | inData = 0; 1974 | } 1975 | 1976 | } 1977 | if(inData == 'E' || inData == 'e') 1978 | { 1979 | if(Serial.available()) { 1980 | extraVFO = Serial.parseInt(); 1981 | Serial.print("Extra VFO: "); 1982 | Serial.println(extraVFO); 1983 | if (extraVFO>=0) { 1984 | offset = Serial.parseInt(); 1985 | Serial.print("Offset: "); 1986 | Serial.println(offset); 1987 | if(Serial.available()) { 1988 | extraVFO2 = Serial.parseInt(); 1989 | Serial.print("Extra VFO2: "); 1990 | Serial.println(extraVFO2); 1991 | if (extraVFO2>=0) { 1992 | offset2 = Serial.parseInt(); 1993 | Serial.print("Offset2: "); 1994 | Serial.println(offset2); 1995 | } 1996 | } 1997 | else 1998 | { 1999 | extraVFO2 = -1; 2000 | } 2001 | } 2002 | } 2003 | else{ 2004 | extraVFO=-1; 2005 | extraVFO2=-1; 2006 | } 2007 | inData = 0; 2008 | } 2009 | 2010 | if(inData == 'D' || inData == 'd') 2011 | { 2012 | drive = Serial.parseInt(); 2013 | Serial.print("Drive: "); 2014 | Serial.println(drive); 2015 | inData = 0; 2016 | } 2017 | if(inData == 'V' || inData == 'v') 2018 | { 2019 | VFO = Serial.parseInt(); 2020 | Serial.print("VFO: "); 2021 | Serial.println(VFO); 2022 | inData = 0; 2023 | } 2024 | if(inData == 'G' || inData == 'g') 2025 | { 2026 | spacing = Serial.parseInt(); 2027 | Serial.print("Spacing: "); 2028 | Serial.println(spacing); 2029 | inData = 0; 2030 | } 2031 | if(inData == 'W' || inData == 'w') 2032 | { 2033 | if(Serial.available()) { 2034 | bandwidth = Serial.parseFloat(); 2035 | settingBandwidth = (int)bandwidth; 2036 | Serial.print("Width: "); 2037 | Serial.println(spacing); 2038 | } else 2039 | bandwidth = 300.0; 2040 | SI4432_Sel = RX; 2041 | SI4432_SET_RBW(bandwidth); 2042 | inData = 0; 2043 | } 2044 | if(inData == 'N' || inData == 'n') 2045 | { 2046 | bandwidth = 30.0; 2047 | SI4432_Sel = RX; 2048 | SI4432_SET_RBW(bandwidth); 2049 | inData = 0; 2050 | } 2051 | if(inData == 'P' || inData == 'p') 2052 | { 2053 | if(Serial.available()) { 2054 | parameter = Serial.parseInt(); 2055 | if(Serial.available()) { 2056 | lastParameter[parameter] = Serial.parseInt(); 2057 | 2058 | if (parameter == 0) { 2059 | // ADF4351_spur_mode(lastParameter[0]); 2060 | // ADF4351_Set(VFO); 2061 | } else if (parameter == 1) { 2062 | SetPowerReference(lastParameter[1]); 2063 | #if 0 2064 | SI4432_Sel = 1; //Select Lo module 2065 | if (lastParameter[1] < 0 || lastParameter[1] > 7 ) { 2066 | SI4432_Write_Byte(0x0D, 0x1F) ; // Set GPIO2 to GND 2067 | } else { 2068 | SI4432_Write_Byte(0x0D, 0xC0) ; // Set GPIO2 maximumdrive and clock output 2069 | SI4432_Write_Byte(0x0A, lastParameter[1] & 0x07) ; // Set GPIO2 frequency 2070 | } 2071 | #endif 2072 | // ADF4351_R_counter(lastParameter[1]); 2073 | // ADF4351_Set(VFO); 2074 | } else if (parameter == 2) { 2075 | // ADF4351_channel_spacing(lastParameter[2]); 2076 | // ADF4351_Set(VFO); 2077 | } else if (parameter == 3) { 2078 | // ADF4351_CP(lastParameter[3]); 2079 | // ADF4351_Set(VFO); 2080 | } else if (parameter == 4) { 2081 | // ADF4351_level(lastParameter[4]); 2082 | // ADF4351_Set(VFO); 2083 | } else if (parameter == 5) { 2084 | settingAttenuate = lastParameter[5]; 2085 | int p = - settingAttenuate * 2; 2086 | PE4302_Write_Byte(p); 2087 | } else if (parameter == 6) { 2088 | RX = lastParameter[6]; 2089 | 2090 | if (RX == 3) { //Both on RX 2091 | SI4432_Sel = 0; 2092 | SI4432_Write_Byte(0x7, 0x0B); // start TX 2093 | SI4432_Write_Byte(0x6D, 0x1F);//Set low power 2094 | SI4432_Sel = 1; 2095 | SI4432_Write_Byte(0x7, 0x0B); // start TX 2096 | SI4432_Write_Byte(0x6D, 0x1F);//Set full power 2097 | } else { 2098 | if (RX == 0) { 2099 | SI4432_Sel = 0; 2100 | SI4432_Write_Byte(0x07, 0x07);// Enable receiver chain 2101 | 2102 | SI4432_Sel = 1; 2103 | SI4432_Write_Byte(0x7, 0x0B); // start TX 2104 | SI4432_Write_Byte(0x6D, 0x1C + (drive - 2 )/2);//Set full power 2105 | 2106 | } else if (RX == 1) { 2107 | SI4432_Sel = 0; // both as receiver to avoid spurs 2108 | SI4432_Write_Byte(0x07, 0x07);// Enable receiver chain 2109 | 2110 | SI4432_Sel = 1; 2111 | SI4432_Write_Byte(0x07, 0x07);// Enable receiver chain 2112 | 2113 | } else if (RX == 2) { // SI4463 as receiver 2114 | SI4432_Sel = 0; 2115 | SI4432_Write_Byte(0x07, 0x07);// Enable receiver chain 2116 | 2117 | SI4432_Sel = 1; 2118 | SI4432_Write_Byte(0x7, 0x0B); // start TX 2119 | SI4432_Write_Byte(0x6D, 0x1C + (drive - 2 )/2);//Set full power 2120 | } 2121 | #if 0 // compact 2122 | SI4432_Sel = (RX ? 1 : 0); 2123 | SI4432_Write_Byte(0x07, 0x07);// Enable receiver chain 2124 | 2125 | SI4432_Sel = (RX ? 0 : 1); 2126 | SI4432_Write_Byte(0x7, 0x0B); // start TX 2127 | SI4432_Write_Byte(0x6D, 0x1C + (drive - 2 )/2);//Set full power 2128 | #endif 2129 | } 2130 | } 2131 | } 2132 | Serial.print("Parameter "); 2133 | Serial.print(parameter); 2134 | Serial.print(" = "); 2135 | Serial.println(lastParameter[parameter]); 2136 | 2137 | } 2138 | else{ 2139 | parameter=-1; 2140 | } 2141 | inData = 0; 2142 | } 2143 | 2144 | if(inData == 'R' || inData == 'r') 2145 | { 2146 | int cont = 1; 2147 | while (cont) { 2148 | float rssi = SI4432_RSSI(); 2149 | Serial.println(rssi, DEC); 2150 | if (Serial.available() > 0) { 2151 | inData = Serial.read(); // read oldest byte in serial buffer: 2152 | if (inData == 'q') 2153 | cont = 0; 2154 | } 2155 | } 2156 | Serial.println("Stopped"); // Home 2157 | } 2158 | } 2159 | } 2160 | -------------------------------------------------------------------------------- /tinySA.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exDB2OO/tinySA/61eff853795308a67d39402dc19d761c2ab2680b/tinySA.jpg -------------------------------------------------------------------------------- /tinySA_measurement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/exDB2OO/tinySA/61eff853795308a67d39402dc19d761c2ab2680b/tinySA_measurement.png --------------------------------------------------------------------------------