| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2024-10-20 15:02:19 +00:00
										 |  |  |   RadioLib AM-modulated AFSK Example | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 15:02:19 +00:00
										 |  |  |   This example shows hot to send AM-modulated | 
					
						
							|  |  |  |   audio FSK tones using SX1278's OOK modem. | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 15:02:19 +00:00
										 |  |  |   Other modules that can be used for AFSK: | 
					
						
							|  |  |  |   - SX127x/RFM9x | 
					
						
							|  |  |  |   - RF69 | 
					
						
							|  |  |  |   - SX1231 | 
					
						
							|  |  |  |   - CC1101 | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 15:02:19 +00:00
										 |  |  |   For default module settings, see the wiki page | 
					
						
							|  |  |  |   https://github.com/jgromes/RadioLib/wiki/Default-configuration
 | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 15:02:19 +00:00
										 |  |  |   For full API reference, see the GitHub Pages | 
					
						
							|  |  |  |   https://jgromes.github.io/RadioLib/
 | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // include the library
 | 
					
						
							|  |  |  | #include <RadioLib.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // SX1278 has the following connections:
 | 
					
						
							|  |  |  | // NSS pin:   10
 | 
					
						
							|  |  |  | // DIO0 pin:  2
 | 
					
						
							|  |  |  | // RESET pin: 9
 | 
					
						
							|  |  |  | SX1278 radio = new Module(10, 2, 9); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // create AFSK client instance using the FSK module
 | 
					
						
							|  |  |  | // this requires connection to the module direct
 | 
					
						
							|  |  |  | // input pin, here connected to Arduino pin 5
 | 
					
						
							|  |  |  | // SX127x/RFM9x:  DIO2
 | 
					
						
							|  |  |  | // RF69:          DIO2
 | 
					
						
							|  |  |  | // SX1231:        DIO2
 | 
					
						
							|  |  |  | // CC1101:        GDO2
 | 
					
						
							|  |  |  | AFSKClient audio(&radio, 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void setup() { | 
					
						
							|  |  |  |   Serial.begin(9600); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // initialize SX1278 with default settings
 | 
					
						
							|  |  |  |   Serial.print(F("[SX1278] Initializing ... ")); | 
					
						
							|  |  |  |   int state = radio.beginFSK(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // when using one of the non-LoRa modules for AFSK
 | 
					
						
							|  |  |  |   // (RF69, CC1101, Si4432 etc.), use the basic begin() method
 | 
					
						
							|  |  |  |   // int state = radio.begin();
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-14 10:37:49 +00:00
										 |  |  |   if(state == RADIOLIB_ERR_NONE) { | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  |     Serial.println(F("success!")); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Serial.print(F("failed, code ")); | 
					
						
							|  |  |  |     Serial.println(state); | 
					
						
							| 
									
										
										
										
											2024-06-29 16:29:11 +00:00
										 |  |  |     while (true) { delay(10); } | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // initialize AFSK client
 | 
					
						
							|  |  |  |   Serial.print(F("[AFSK] Initializing ... ")); | 
					
						
							|  |  |  |   state = audio.begin(); | 
					
						
							| 
									
										
										
										
											2021-11-14 10:37:49 +00:00
										 |  |  |   if(state == RADIOLIB_ERR_NONE) { | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  |     Serial.println(F("success!")); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Serial.print(F("failed, code ")); | 
					
						
							|  |  |  |     Serial.println(state); | 
					
						
							| 
									
										
										
										
											2024-06-29 16:29:11 +00:00
										 |  |  |     while (true) { delay(10); } | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // after that, set mode to OOK
 | 
					
						
							|  |  |  |   Serial.print(F("[SX1278] Switching to OOK ... ")); | 
					
						
							|  |  |  |   state = radio.setOOK(true); | 
					
						
							| 
									
										
										
										
											2021-11-14 10:37:49 +00:00
										 |  |  |   if(state == RADIOLIB_ERR_NONE) { | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  |     Serial.println(F("success!")); | 
					
						
							|  |  |  |   } else { | 
					
						
							|  |  |  |     Serial.print(F("failed, code ")); | 
					
						
							|  |  |  |     Serial.println(state); | 
					
						
							| 
									
										
										
										
											2024-06-29 16:29:11 +00:00
										 |  |  |     while (true) { delay(10); } | 
					
						
							| 
									
										
										
										
											2021-07-27 16:54:05 +00:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void loop() { | 
					
						
							|  |  |  |   // AFSKClient can be used to transmit tones,
 | 
					
						
							|  |  |  |   // same as Arduino tone() function
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // 400 Hz tone
 | 
					
						
							|  |  |  |   Serial.print(F("[AFSK] 400 Hz tone ... ")); | 
					
						
							|  |  |  |   audio.tone(400); | 
					
						
							|  |  |  |   delay(1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // silence
 | 
					
						
							|  |  |  |   Serial.println(F("done!")); | 
					
						
							|  |  |  |   audio.noTone(); | 
					
						
							|  |  |  |   delay(1000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // AFSKClient can also be used to transmit HAM-friendly
 | 
					
						
							|  |  |  |   // RTTY, Morse code, Hellschreiber, SSTV and AX.25.
 | 
					
						
							|  |  |  |   // Details on how to use AFSK are in the example
 | 
					
						
							|  |  |  |   // folders for each of the above modes.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // CAUTION: Unlike standard AFSK, the result when using OOK
 | 
					
						
							|  |  |  |   // must be demodulated as AM!
 | 
					
						
							|  |  |  | } |