Skip to content

Commit

Permalink
Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pu2clr committed Aug 10, 2024
1 parent 0b3db72 commit a1b8fbd
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 33 deletions.
Binary file modified .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ void sendRDS() {
if ((millis() - rdsTimeRT) > RDS_RT_REFRESH_TIME) {
if (idxRdsRT > lastRdsRT) idxRdsRT = 0;
delay(100);
tx.rdsSendRTMessage(rdsRTmsg[idxRdsRT]);
tx.rdsSendRTMessage(rdsRTmsg[idxRdsRT]); // See rdsSendRTMessage in https://pu2clr.github.io/QN8066/extras/apidoc/html/index.html
idxRdsRT++;
rdsTimeRT = millis();
}
Expand Down
76 changes: 76 additions & 0 deletions examples/06_ATTINY85_RDS_OLED/06_ATTINY85_RDS_OLED.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
This sketch is an example of using the QN8066 library for Arduino to run on the ATtiny85 and OLED. Learn more details below.
It is important to highlight some limitations regarding the number of pins available on the ATtiny85. This condition somewhat
restricts the user interface.
ATtiny85, OLED and QN8066 wireup
| Device pin | Attiny85 REF pin | Physical pin |
| ----------------| -----------------| ------------- |
| PUSH BUTTON | | |
| UP | PB1 | 6 |
| DOWN | PB4 | 3 |
| MENU | PB3 | 2 |
| | | |
| QN8066 & OLED | | |
| SDIO / SDA | SDA | 5 |
| SCLK / CLK | SCL | 7 |
Compiling and uploading:
1) Install the ATtiny Core in Arduino IDE - Insert the URL http://drazzy.com/package_drazzy.com_index.json on board manager.
To do that, go to Preferences, enter the above URL in "Additional Boards Manager URLs.
To setup ATtiny85 on Arduino IDE, go to Tools Menu, Board, Board Manager and install
"ATTinyCore by Spence Konde".
2) Setup: Chip: ATtiny85; Clock Source: 1MHz (Internal); LTO Enabled; millis() / macros() Enabled;
ATTENTION: if you select Clock source 8 MHz, for some reason, the system will work very slow. Maybe a bug.
See documentation: https://pu2clr.github.io/QN8066/extras/apidoc/html/index.html
By Ricardo Lima Caratti, 2024.
*/

#include <QN8066.h>
#include <Tiny4kOLED.h>
#include <5x5_font.h>

char ps[] = "QN8066TX";
char rt[] = "PU2CLR QN8066 ARDUINO LIBRARY";

uint16_t currentFrequency = 1069; // 106.9 MHz is the default frequency

QN8066 tx;

void setup() {
oled.begin();
oled.on();
oled.clear();
oled.setFont(FONT6X8);
oled.setCursor(0, 0);
oled.print(F("QN8066-ATTiny85"));
oled.setCursor(0, 2);
oled.print(F(" By PU2CLR "));
delay(2000);
oled.clear();
// End Splash

tx.setup();
tx.setTX(currentFrequency);
tx.setTxMono(false); // Stereo
tx.rdsSetSyncTime(30); // Needed due to the low speed that the Attiny was configured (1MHz clock)
tx.rdsTxEnable(true);
showStatus();
}

// Shows the current status
void showStatus() {
char strFrequency[7];
tx.convertToChar(currentFrequency, strFrequency, 4, 3, ','); // Convert the selected frequency a array of char
oled.clear();
oled.setCursor(0, 0);
oled.print(strFrequency);
}

void loop() {
tx.rdsSendPS(ps,20);
delay(200);
tx.rdsSendRTMessage(rt,30);
delay(800);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
#define CMD_MENU PB3
#define TIME_RDS_ON_DISPLAY 2300

#define CMD_NO_PRESSED 7 // 111
#define CMD_DOWN_PRESSED 6 // 110
#define CMD_UP_PRESSED 5 // 101
#define CMD_MENU_PRESSED 3 // 011

#define CTRL_FREQ 0
#define CTRL_MONO 1
#define CTRL_RDS 2

uint8_t cmdCtrl = 0; // 0 - change frequency; 1 - switch stereo/mono; 2 - switch RDS on/off

#define VALID_DATA 85

char ps[] = "QN8066TX";
Expand All @@ -50,8 +61,10 @@ uint16_t currentFrequency = 1069; // 106.9 MHz is the default frequency
uint8_t currentRDS = 0; // Default no RDS
uint8_t currentMono = 0; // Default Stereo


QN8066 tx;


void setup() {
pinMode(CMD_UP, INPUT_PULLUP);
pinMode(CMD_DOWN, INPUT_PULLUP);
Expand All @@ -68,17 +81,22 @@ void setup() {
delay(2000);
oled.clear();
// End Splash
tx.setup();

tx.setup();
delay(500);
// Restores the latest frequency and audio mute statis saved into the EEPROM
if (EEPROM.read(0) == VALID_DATA) {
readEEPROM();
} else {
writeEEPROM(); // Writes into EEPROM the default values
}
}
tx.setTX(currentFrequency);
tx.rdsTxEnable(currentRDS);
tx.setTxMono(currentMono); // 1 = Mono; 0 = Stereo
// tx.rdsTxEnable(currentRDS);
// tx.setTxMono(currentMono); // 1 = Mono; 0 = Stereo

tx.rdsSetSyncTime(30); // Needed due to the low speed that the Attiny was configured (1MHz clock)
tx.rdsTxEnable(true);
tx.setTxMono(false);

showStatus();
}
Expand Down Expand Up @@ -108,27 +126,44 @@ void showStatus() {
oled.print(strFrequency);
}

/*
Returns:
7 if no key is pressed. - 111 - NO PRESSED
6 if BT_DOWN is pressed - 110 - CMD_UP PRESSED
5 if BT_UP is pressed - 101 - CMD_DOWN PRESSED
3 if BT_MENU is pressed - 011 - CMD_MENU
// TODO - Debounce process
*/
int8_t checkButton() {
uint8_t button;
for (uint8_t i = 0; i < 5; i++) {
// Please... check it out later
button = digitalRead(CMD_MENU) << 2 | digitalRead(CMD_DOWN) << 1 | digitalRead(CMD_UP);
delay(30);
}
return button;
}

void doCtrl( uint8_t cmd) {

// TODO

}

void loop() {
/*
uint8_t bkey;
bkey = ((digitalRead(CMD_UP) << 2) | (digitalRead(CMD_DOWN) << 1)) | digitalRead(CMD_MENU); // 3, 5 or 6 (Pressed = 0 - considering just one button pressed)
if (bkey != 0b111) { // if none of them is pressed (not igual to 0b011, 0b101 or 0b110) then do nothing.
if (bkey == 0b011) // 3
// UP
else if (bkey == 0b101) // 5
// UP
else // 6
// MENU
showStatus();
delay(200);
// Saves the current frequency if it has changed.
currentFrequency = tx.getFrequency();
EEPROM.update(0, VALID_DATA); // Says that a valid frequency will be saved
EEPROM.update(1, currentFrequency >> 8); // stores the current Frequency HIGH byte
EEPROM.update(2, currentFrequency & 0xFF); // stores the current Frequency LOW byte
EEPROM.update(3, tx.isMuted()); // Stores the current audio mute status

uint8_t bkey = checkButton();

if (bkey != CMD_NO_PRESSED) {
// TODO
doCtrl( bkey );
}
*/

delay(5);

delay(800);
tx.rdsSendPS(ps,20);
delay(200);
tx.rdsSendRTMessage(rt,30);


}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=QN8066
version=1.2.6
version=1.2.7
author=Ricardo Lima Caratti, pu2clr@gmail.com
maintainer=Ricardo Lima Caratti
sentence=Control your TX/RX QN8066 device
Expand Down
14 changes: 7 additions & 7 deletions src/QN8066.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ void QN8066::rdsSendGroup(RDS_BLOCK1 block1, RDS_BLOCK2 block2, RDS_BLOCK3 block
// It should not be here. Judiging by the data sheet, the use must
// wait for the RDS_TXUPD before toggling the RDSRDY bit in the SYSTEM2 register.
this->rdsSetTxToggle();
delay(60); // This time is very critical and may need to be tuned
delay(this->rdsSyncTime); // This time is very critical and may need to be tuned. Check the function/method rdsSetSyncTime
// checks for the RDS_TXUPD .
while ( this->rdsGetTxUpdated() == toggle && count < 10) {
delay(1);
Expand All @@ -1354,7 +1354,7 @@ void QN8066::rdsSetStationName(char *stationName) {
* @brief Sends the Program Service Message
* @details Like rdsSendPS this method sends the Station Name or other 8 char message.
* @param ps - String with the name of Station or message limeted to 8 character.
* @param groupTransmissionCoun - number of times the group 2A must be sent to ensure continuous and synchronized transmission (default 4)
* @param groupTransmissionCount - number of times the group 2A must be sent to ensure continuous and synchronized transmission (default 4)
* @details Example
* @code
* #include <QN8066.h>
Expand All @@ -1371,7 +1371,7 @@ void QN8066::rdsSetStationName(char *stationName) {
* }
* @endcode
*/
void QN8066::rdsSendPS(char* ps, uint8_t groupTransmissionCoun) {
void QN8066::rdsSendPS(char* ps, uint8_t groupTransmissionCount) {

RDS_BLOCK1 b1;
RDS_BLOCK2 b2;
Expand All @@ -1398,7 +1398,7 @@ void QN8066::rdsSendPS(char* ps, uint8_t groupTransmissionCoun) {
// It is important to ensure that the 2A or 2B groups are transmitted continuously and in
// sync so that receivers can correctly piece together the parts of the text and display
// them to the listener without interruptions.
for ( uint8_t k = 0; k < groupTransmissionCoun; k++) { // Just a test. To be removed
for ( uint8_t k = 0; k < groupTransmissionCount; k++) { // Just a test. To be removed
for (uint8_t i = 0; i < 8; i+=2) {
b4.byteContent[0] = ps[i];
b4.byteContent[1] = ps[i+1];
Expand All @@ -1414,7 +1414,7 @@ void QN8066::rdsSendPS(char* ps, uint8_t groupTransmissionCoun) {
* @brief Sends RDS Radio Text Message (group 2A)
*
* @param rt - Radio Text (string of 32 character)
* @param groupTransmissionCoun - number of times the group 2A must be sent to ensure continuous and synchronized transmission (default 4)
* @param groupTransmissionCount - number of times the group 2A must be sent to ensure continuous and synchronized transmission (default 4)
*
* @code
* #include <QN8066.h>
Expand All @@ -1431,7 +1431,7 @@ void QN8066::rdsSendPS(char* ps, uint8_t groupTransmissionCoun) {
* }
* @endcode
*/
void QN8066::rdsSendRTMessage(char *rt, uint8_t groupTransmissionCoun) {
void QN8066::rdsSendRTMessage(char *rt, uint8_t groupTransmissionCount) {

// Flushes any previus data
this->rdsSetTxToggle();
Expand All @@ -1458,7 +1458,7 @@ void QN8066::rdsSendRTMessage(char *rt, uint8_t groupTransmissionCoun) {
// It is important to ensure that the 2A or 2B groups are transmitted continuously and in
// sync so that receivers can correctly piece together the parts of the text and display
// them to the listener without interruptions.
for ( uint8_t k = 0; k < groupTransmissionCoun; k++) {
for ( uint8_t k = 0; k < groupTransmissionCount; k++) {
for (uint8_t i = 0; i < numGroups; i++) {
block2.group2Field.address = i;
RDS_BLOCK3 block3;
Expand Down
11 changes: 11 additions & 0 deletions src/QN8066.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@ class QN8066 {
qn8066_vol_ctl vol_ctl;


uint8_t rdsSyncTime = 60; // Time in ms to wait fro send the next group - Default value is 60 ms

char rdsStationName[9] = " QN8066\r";
uint16_t rdsPI = 33179; //!< Default value for piCode (0x819B)
uint8_t rdsPTY = 5; //!< Default program type (PTY) 5 is "Education"
Expand Down Expand Up @@ -1046,6 +1048,15 @@ class QN8066 {
*/
void rdsClearBuffer();


/**
* @ingroup group05 TX RDS
* @brief Sets the wait time for the QN8066 to be available to send the next RDS block.
* @details The default time is 60ms, but depending on the microcontroller you are using, it may be necessary to reduce this time.
* @param syncTime - time in ms
*/
inline void rdsSetSyncTime(uint8_t syncTime) {this->rdsSyncTime = syncTime; };

void resetFsm();
uint8_t getFsmStateCode();

Expand Down

0 comments on commit a1b8fbd

Please sign in to comment.