This library is intended to provide an easy-to-use interface for controlling the QN8066 FM transceiver and receiver.
The primary goal of this Arduino library project for the QN8066 is to simplify the development of robust applications using this device. I hope that hobbyists, electronics technicians, radio amateurs, and others interested in this work will find success in their projects. All the C/C++ funcions and methods are documented [here].(https://pu2clr.github.io/QN8066/extras/apidoc/html/index.html)
This library can be freely distributed using the MIT Free Software model. By using or installing Library you are agreeing to the terms of the MIT licence.
Copyright (c) 2024 Ricardo Lima Caratti.
Contact: pu2clr@gmail.com.
I hold a Master’s degree in Educational Technology from the Federal University of Ceará, where I delved into the ways technology can enhance learning experiences. My passion for computer science led me to specialize in it, focusing on Distributed Systems Development with an Object-Oriented approach, at the University of Brasília. My academic journey began with a Bachelor’s degree in Information Systems from the União Pioneira de Integração Social (UPIS-Brasília). Outside the classroom, my main hobbies are electronics and Amateur Radio.
This library is continuously evolving, with both corrective and feature updates. While the implemented functions have been tested, it is possible that in certain situations, the library may exhibit unexpected behavior. I encourage users to always utilize the latest release of this library. Should you encounter any issues, please feel free to contact me at pu2clr@gmail.com. I will do my best to address or clarify any problems as quickly as possible. Thank you.
Please, be aware that the use of FM transmitters is regulated by the laws and regulations of each country. It is crucial to ensure that your use of any FM transmitter complies with the applicable legal requirements and does not violate any broadcasting regulations.
By following these guidelines, you can ensure that your use of the FM transmitter respects the laws and regulations of your country and does not result in any legal issues.
There is a Facebook group called QN80XX FM Transmitters & Receivers Enthusiasts where the purpose is exchanging experiences with projects based on Quintic QN80XX IC family. You will be welcome there.
Mr. Grazianny Carvalho Tavares - I would like to thank Mr. Grazianny Carvalho Tavares, PU7MGR, for introducing me to the QN8066 and encouraging me to develop this library. Mr. Grazianny also played a crucial role in helping me understand various concepts about FM modulation, audio quality criteria, as well as in testing the fundamental functions implemented in this library using equipment for precise value measurements.
I would like to thank Mr. Adam Fabio for his article published in the online magazine Hackaday titled Be Your Own DJ With QN8066 And An Arduino Library.
I would like to thank Mr. Gareth Halfacree for his article published in the online magazine hackster.io titled Ricardo Lima Caratti’s Handy Arduino Library Delivers Easy QN8066-Powered FM Radio Projects.
Mr. Elionaldo Gomes da Silva, PY2EGS, to share his board Layout project with Nano and LCD
Technically, no Arduino application strictly requires a library. In some cases, avoiding libraries might even be the right decision. However, there are several compelling reasons to consider using them.
Libraries often simplify the design and maintenance of code, and they can make your projects more portable by implementing the necessary functionality across multiple hardware platforms.
For example, if you want to use an LCD or another display device in a project that monitors temperature and atmospheric pressure, there are many excellent libraries available for Arduino users. These libraries usually include most, if not all, of the features you might need. Re-inventing the wheel by not using a library generally doesn’t make sense—unless you need a feature that no existing library supports. Using a library is often the smarter choice, particularly when it can simplify porting your code to different hardware.
Utilizing a library can reduce programming complexity and enhance the robustness of your application. It simplifies life not only for other developers but also for yourself. You don’t need to be a software engineer to see the value in this. A library is similar to an integrated circuit (IC); while you could manually implement the functionality of many ICs in a circuit, doing so would significantly increase the cost, complexity, size, and potential for failure of your project. Often, it’s better to abstract certain functions inside a ready-made IC. The user only needs to know how to interact with the chip, not how the chip itself is designed.
Finally, if you’re already using libraries to handle the I2C bus (Wire.h), TFT or OLED displays, SPI devices, and Serial UART communication, it makes sense to use a library to manage the QN8066 device as well. The QN8066 Arduino Library can add convenience, development speed, and robustness to your project. Unlike closed-source solutions, this library is open-source, allowing you to learn from and modify the code as needed.
This library uses the I²C communication protocol and implements most of the functions offered by QN8066 IC from QUINTIC. This library also has primitive functions that make it easier for you to implement commands that may not have been implemented yet. As said before, this library is constantly improving. Check the API documentation before implementing a new function. It is likely that your function is already implemented. See the API documentation for this library.
The QN8066 is a highly integrated and versatile receiver/transmitter (RX/TX) device designed for use in FM radio applications. It offers a comprehensive solution for high-quality audio reception and transmission with minimal external components, making it suitable for a wide range of applications, including portable radios, automotive systems, and multimedia devices.
SSOP16 PIN | NAME | DESCRIPTION | |
---|---|---|---|
1 | SCL | Clock for I2C serial bus | |
2 | SDA | Bi-directional data line for I2C serial bus | |
3 | VCC | Voltage supply | |
4 | ALO | Analog audio output – left channel | |
5 | ARO | Analog audio output – right channel | |
6 | GND | Ground | |
7 | RFI | FM Receiver RF input | |
8 | GND | Ground | |
9 | ARI | Right channel audio input | |
10 | ALI | Left channel audio input | |
11 | GND | Ground | |
12 | RFO | Transmitter RF output – connect to matched antenna | |
13 | CEN | Chip enable with internal pull up: Chip power down if less than 0 | 4V and VIO is powered; power up if higher voltage or left floated |
14 | XCLK | External clock input | |
15 | GND Ground | ||
16 | INT | Interrupt output, active low, need pull-up externally |
REGISTER | NAME | USER CONTROL FUNCTIONS | |
---|---|---|---|
00h | SYSTEM1 | Sets device modes | |
01h | SYSTEM2 | Sets external clock type and CCA parameters | |
02h | CCA | Sets CCA parameters | |
03h | SNR | Estimate RF input CNR value | |
04h | RSSISIG | In-band signal RSSI dBµ V value | |
05h | CID1 | Device ID numbers | |
06h | CID2 | Device ID numbers | |
07h | XTAL_DIV0 | Frequency select of reference clock source | |
08h | XTAL_DIV1 | Frequency select of reference clock source | |
09h | XTAL_DIV2 | Frequency select of reference clock source | |
0Ah | STATUS1 | System status | |
0Bh | RX_CH | Lower 8 bit of 10-bit receiver channel index | |
0Ch | CH_START | Lower 8 bits of 10-bit channel scan start channel index | |
0Dh | CH_STOP | Lower 8 bits of 10-bit channel scan stop channel index | |
0Eh | CH_STEP | Channel scan frequency step | Highest 2 bits of receiver channel indexes |
0Fh | RX_RDSD0 | RDS data byte 0 | |
10h | RX_RDSD1 | RDS data byte 1 | |
11h | RX_RDSD2 | RDS data byte 2 | |
12h | RX_RDSD3 | RDS data byte 3 | |
13h | RX_RDSD4 | RDS data byte 4 | |
14h | RX_RDSD5 | RDS data byte 5 | |
15h | RX_RDSD6 | RDS data byte 6 | |
16h | RX_RDSD7 | RDS data byte 7 | |
17h | STATUS2 | Receiver RDS status indicators | |
18h | VOL_CTL | Audio volume control | |
19h | INT_CTRL | Receiver RDS control | |
1Ah | STATUS3 | Receiver audio peak level and AGC status | |
1Bh | TXCH | Lower 8 bit of 10-bit transmitter channel index | |
1Ch | TX_RDSD0 | Transmit RDS data byte0 | |
1Dh | TX_RDSD1 | Transmit RDS data byte1 | |
1Eh | TX_RDSD2 | Transmit RDS data byte2 | |
1Fh | TX_RDSD3 | Transmit RDS data byte3 | |
20h | TX_RDSD4 | Transmit RDS data byte4 | |
21h | TX_RDSD5 | Transmit RDS data byte5 | |
22h | TX_RDSD6 | Transmit RDS data byte6 | |
23h | TX_RDSD7 | Transmit RDS data byte7 | |
24h | PAC | PA output power target control | |
25h | FDEV | Specify total TX frequency deviation | |
26h | RDS | Specify transmit RDS frequency deviation | |
27h | GPLT | Transmitter soft chip threshold, gain of TX pilot | |
28h | REG_VGA | TX AGC gain |
The following figures illustrate a homemade setup with the QN8066. As you can see, only a few components are needed to build an FM transmitter with the QN8066. The key component is the 32.768 kHz active crystal (32,768 Hz). The QN8066 allows for other signal source configurations. As far as I understand, there is no possibility of using passive crystals. The QN8066 requires an active signal source provided by a generator.
Through some functions in the Arduino library, you can configure the active crystal you intend to use. Check the setup and begin functions for more details.
The table below shows some tested sources (active crystal or signal generator) and divider values.
Source (kHz) | Divider |
---|---|
32.768 | 1 |
< 1,310.720 | did not work |
1,310.720 | 40 |
1,638.400 | 50 |
3,276.800 | 100 |
13,107.200 | 400 |
16,384.000 | 500 |
32,768,000 | 1000 |
/**
This sketch works on Arduino Pro Mini, Nano, UNO, or any other board based on the ATMega328.
IMPORTANTE: Refer to the documentation if you are using a 5V microcontroller instead of a 3.3V one.
This sketch illustrates the clock configuration used on the XCLK pin of the QN8066.
Depending on the active crystal or signal generator you are using, it is important
to set the correct frequency and signal waveform type for the QN8066 to function
properly.
IMPORTANT: The QN8066 works with active crystals or signal generators.
Passive crystals will not work with the QN8066.
Author: Ricardo Lima Caratti (PU2CLR) - 2024
*/
#include <QN8066.h>
#define FREQUENCY 1069 // 106.9 MHz
QN8066 tx;
char str[80];
void setup() {
Serial.begin(9600);
while (!Serial) ;
delay(100); // Wait a bit while the system stabilizes.
if (!tx.detectDevice()) {
Serial.println("\nDevice QN8066 not detected");
while (1);
}
// The call to the setup function below illustrates the use of a 32.768 kHz crystal.
// Since the reference clock for the QN8066 is exactly 32.768 kHz, you can provide the
// frequency value of the crystal you are using divided by 32.768.
// For example: if you are using a 32.768 kHz active crystal, then you should provide the
// divisor value of 1. If the signal generator (active crystal) produces a sine wave,
// enter the value 0, and if it is a digital signal, you should enter the value 1. See below.
tx.setup(1, // Divider based on frequency select of reference clock source. The crystal used here is 32.768 kHz
false, // Mono False => TX will start in stereo mode
false, // TX will start in RDS OFF
1, // PreEmphasis = 75
1); // 1 if XCLK pin is receiving a digital clock. set it to 0 if you are using a sine-wave oscillator.
tx.setTX(FREQUENCY); // Chenge the FREQUENCY constant if you want other value
sprintf(str, "\n\nBroadcasting...");
Serial.print(str);
}
void loop() {
sprintf(str,"\nFSM: %d\nAudio Peak: %d mV", tx.getFsmStateCode(), tx.getAudioPeakValue());
Serial.print(str);
tx.resetAudioPeak();
delay(15000);
}
#include <QN8066.h>
#define FREQUENCY 1069 // 106.9 MHz
QN8066 tx;
char str[80];
void setup() {
Serial.begin(9600);
while (!Serial) ;
delay(100); // Wait a bit while the system stabilizes.
if (!tx.detectDevice()) {
Serial.println("\nDevice QN8066 not detected");
while (1);
}
tx.begin();
// Assuming you are using a 32.768 kHz active crystal, a digital signal, and LO<RF,
// the image is on the lower side.
tx.setXtal(1,1,0);
// tx.setXtal(100,1,0); // If you are using 3,768 active crystal
// tx.setXtal(1000,1,0); // If you are using 32,768,000 active crystal
delay(100);
tx.setTX(FREQUENCY); // Chenge the FREQUENCY constant if you want other value
sprintf(str, "\n\nBroadcasting...");
Serial.print(str);
}
void loop() {
sprintf(str,"\nFSM: %d\nAudio Peak: %d mV", tx.getFsmStateCode(), tx.getAudioPeakValue());
Serial.print(str);
tx.resetAudioPeak();
delay(15000);
}
It is possible to find Transceivers based on the QN8066 in kit form. With this library, you will also be able to control this kit, thereby expanding its original functionalities. Check AliExpress and others to check it out.
The images below show the DIY Kit 5W-7W FM Transceiver available on AliExpress.
The code below is a minimalist sketch example of using this library with the DIY Kit 5W-7W FM board.
Anduino Nano or Uno pin | Kit 5W-7W FM |
---|---|
GND | GND |
D9 | PWM (*1) |
A4 | SDA (*2) |
A5 | SCL (*2) |
During experiments, commands sent to the QN8066 via I2C often had no effect, such as switching from “Stereo” to “Mono” or changing the transmission frequency. To resolve this, disable the PWM (0% duty cycle) before sending commands and re-enable it afterward.
#include <QN8066.h>
QN8066 dv;
void setup() {
Serial.begin(9600);
while (!Serial);
pinMode(9, OUTPUT); // Pin use to PWM power control
dv.setup();
Serial.print("\nStarting the system...");
delay(1000);
dv.setTX(1067); // Set the transmitter to 106.9 MHz
dv.setTxStereo(true);
// Now you can start PWM
analogWrite(9, 50); // It is about 1/5 of the max power (5~7W). It is between 1 and 1,4 W
Serial.print("\nBroadcasting...");
// Turning the Stereo OFF
analogWrite(9, 0); // Disable PWM
dv.setTxStereo(false);
analogWrite(9, 50); // Enable PWM
}
void loop() {
}
The “DIY 5~7W FM Transmitter Kit” is designed for 3.3V controllers and has I2C pull-up resistors connected to its 3.3V power supply. However, the Arduino Nano operates at 5V, producing 5V signals on the I2C bus, which can cause communication instability. Additionally, the Nano cannot run stably on a 3.3V supply from the kit.
The simplest, but impractical, solution is to modify the Arduino Nano to run at 3.3V by changing its crystal to 8MHz and updating the bootloader. A better option is to use an Arduino Pro Mini 3.3V for direct compatibility.
In some examples using the Arduino Nano, a 3.3V to 5V voltage converter was added for power, along with two 150-ohm resistors in series with the I2C bus and two 10K resistors as pull-ups. While not ideal, this method works. A more appropriate solution would be to use a bidirectional I2C level shifter for compatibility.
The Arduino Nano is used in some examples in this library because it’s popular among hobbyists, many of whom already have one or an Arduino Uno with the same architecture. Most other examples use 3.3V microcontrollers that do not require any modifications.
See also DIY Kit 5W-7W FM example
The following figure shows the “DIY Kit 5W-7W FM TRANSMITTER” connected to the Arduino Pro Mini. The following link provides more operational details. Click here to watch the video.
Click here to see the source code and schematic
Before presenting some observations that I consider important, it is worth highlighting that the following information may not reflect the reality in other environments or with other kits. The goal here is not to judge the quality of the kit or its architecture. However, these observations may explain some phenomena you might experience during the development of your project and help you mitigate these issues.
Based on several experiments I conducted with this kit, I observed instability in the communication between the microcontroller and the QN8066 via the I2C bus in the following situations:
PWM Line Interference: When the PWM line to control the transmitter’s power is active, communication failures and even unavailability of the QN8066 to respond to new commands are common. One solution to this problem was to disable the PWM signal every time a command is sent to the system and re-enable the PWM signal afterward. It is important to note that this behavior hinders or limits, to some extent, a more dynamic use of RDS services.
High Power Transmission: When the transmitter is configured to transmit at higher power levels, approaching its upper limit of 7W, the communication also becomes unstable, and the QN8066 stops responding to the microcontroller, even though it continues to transmit.
Avoid touching: Touching certain points on the KIT board or the microcontroller with your hands can also cause system instability.
Wire-up organization: Shortening and organizing the I2C bus lines that connect the KIT to the microcontroller significantly improves system stability.
Good grounding: Through good grounding, it was possible to make the system more stable.
System Stability of the KIT Powered via Microcontroller (Tests and Results): Without using the power module, that is, by only powering the QN8066 stage of the board through the interface connector with the microcontroller, the system remains stable. The example sketches provided in this library ran for hours without any instability. The sketch developed for the Arduino Pro Mini and LCD16x2 was subjected to a test lasting over 16 hours without any issues.
Impact of RF Interference on I2C Communication in Power Control Systems: There is another point to consider that might somewhat absolve the issue of power control via I2C. As the bandwidth increases, the transmitter’s power also rises. It’s possible that excessive RF signal in close proximity to the circuit is disrupting the I2C communication. When using a “dummy load,” there is a noticeable reduction in I2C communication errors. This can be demonstrated by eliminating the I2C control and manually controlling it by applying a voltage of 3.3V or lower to the power control line. In my experiments, the I2C communication errors persisted, causing system instability.
Enhancing System Stability Through Shielding and Isolation (Future Testing Considerations): Finally, I believe that good shielding of the KIT in a metal enclosure, as well as isolating the microcontroller from the transmitter (in a separate enclosure), could significantly improve the system. This is something to be tested in the future.
It is important to highlight that this library was not developed exclusively to work with this kit. In fact, it was designed to work with any architecture involving the QN8066 via the I2C protocol. That said, it is crucial for the designer or experimenter to keep in mind the necessary precautions to provide a stable system. There are various literatures that can help follow the best design practices involving I2C communication.
In a new project involving the QN8066, I believe a more stable approach would be not to work with power levels above ½W on the same board. An additional amplification module could be added separately from the QN8066 circuit. The organization of the printed circuit board is also a determining factor in improving the stability of the system. Preferably, the communication circuit of the microcontroller with the QN8066 should be as far away as possible from the RF circuit. The appropriate values for the pull-up resistors for the I2C bus is a variable that deserves attention. These values may depend on the length of the bus and other I2C devices that may be connected to the circuit. In my experiments, I used 10K pull-up resistors. However, lower resistance values can be tested and may further improve the stability of the system. Consider shielding the Display and microcontroller circuit so that unwanted signals and interference do not propagate to the QN8066 circuit.
This library can be useful to develop cross-platform software.
The table below shows the some boards where this library has been successfully compiled.
Board | Need voltage converter | I²C Pins | Used Reset Pin | Features | |
---|---|---|---|---|---|
1 | Arduino Pro Mini 3.3V 8MHz | No | A4 and A5 | 12 | More… |
2 | Mega 2560 Pro | Yes | 20 and 21 | 12 | More… |
3 | ESP WEMOS LOLIN32 | No | GPIO21 and GPIO22 [4] | GPIO25 [5] | More… |
4 | ESP32 Dev Module | No | GPIO21 and GPIO22 [4] | GPIO25 [5] | More… |
5 | ESP32 Wrover Module | No | GPIO21 and GPIO22 [4] | GPIO25 [5] | More… |
6 | ESP8266 | No | GPIO4 and GPIO5 | GPIO2 | More… |
7 | Arduino UNO | Yes | A4 and A5 | 12 | More… |
8 | Arduino NANO ATmega 328 | Yes | A4 and A5 | 12 | More… |
9 | Arduino NANO ATmega 168 | Yes | A4 and A5 | 12 | More… |
10 | Arduino NANO 33 IoT | No [6] | A4 and A5 | 12 | More… |
11 | Arduino Yún / ATmega-32u4 | Yes | 2 and 3 | 12 | More… |
12 | ATtiny84 | No | 7 and 8 | 6 | More… |
13 | ATtiny85 | No | 5 and 7 | 2 (D3) | More… |
14 | Arduino DUE | No | 2 and 3 | 12 | More… |
15 | BlueDuino 3.3V (ATmega-32u4) | No | 2 and 3 | 10 | More… |
16 | Arduino Mini Pro 5V 16Mhz | Yes | 2 and 3 | 10 | More… |
17 | STM32F746G-DISCO | No | - | - | More… |
18 | STM32F103 Series | No | PB6 (SCL) and PB7(SDA) | PA12 | More… |
19 | STM32F411 Series | No | PB6 (SCL) and PB7(SDA) | PA12 | More… |
20 | Raspberry Pi Pico | No | GP0 (0) and GP1 (1) | GP16 (16) | More… |
21 | WeAct Studio RP2040 Pico | No | GP0 (0) and GP1 (1) | GP16 (16) | More… |
22 | Seeeduino XIAO | No | A4 and A5 | 3 | More… |
23 | Teensy 3.1 | No | A4 and A5 | 12 | More… |
24 | Teensy 4.1 | No | A4 and A5 | 12 | More… |
25 | Atmega8 | No | PC4 and PC5 | PD6 | More… |
26 | Atmega32 | No | PC1 and PC0 | PB2 | More… |
27 | Atmega128 | No | PC1 and PC0 | PB2 | More… |
28 | LGT8F328P | No | A4 and A5 | 12 | More… |
29 | LUATOS ESP32C3 | No | GPIO4 and GPIO5 | GPIO8 | More… |
If you find this project useful, consider making a donation so that the author of this library can purchase components and modules for improvements and testing of this library. Click here to donate or use the QR code below.