Si4703 FM Tuner Question

If we look at this code:

#include <SparkFunSi4703.h>
#include <Wire.h>

int resetPin = 2;
int SDIO = A4;
int SCLK = A5;
int STC = 3;

Si4703_Breakout radio(resetPin, SDIO, SCLK, STC);
int channel;
int volume;
char rdsBuffer[10];

void setup()
{
  Serial.begin(9600);
  Serial.println("\n\nSi4703_Breakout Test Sketch");
  Serial.println("===========================");  
  Serial.println("a b     Favourite stations");
  Serial.println("+ -     Volume (max 15)");
  Serial.println("u d     Seek up / down");
  Serial.println("r       Listen for RDS Data (15 sec timeout)");
  Serial.println("Send me a command letter.");
  

  radio.powerOn();
  radio.setVolume(0);
}

void loop()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    if (ch == 'u') 
    {
      channel = radio.seekUp();
      displayInfo();
    } 
    else if (ch == 'd') 
    {
      channel = radio.seekDown();
      displayInfo();
    } 
    else if (ch == '+') 
    {
      volume ++;
      if (volume == 16) volume = 15;
      radio.setVolume(volume);
      displayInfo();
    } 
    else if (ch == '-') 
    {
      volume --;
      if (volume < 0) volume = 0;
      radio.setVolume(volume);
      displayInfo();
    } 
    else if (ch == 'a')
    {
      channel = 930; // Rock FM
      radio.setChannel(channel);
      displayInfo();
    }
    else if (ch == 'b')
    {
      channel = 974; // BBC R4
      radio.setChannel(channel);
      displayInfo();
    }
    else if (ch == 'r')
    {
      Serial.println("RDS listening");
      radio.readRDS(rdsBuffer, 15000);
      Serial.print("RDS heard:");
      Serial.println(rdsBuffer);      
    }
  }
}

void displayInfo()
{
   Serial.print("Channel:"); Serial.print(channel); 
   Serial.print(" Volume:"); Serial.println(volume); 
}

We see the line radio.readRDS(rdsBuffer, 15000);, however, this is blocking. The 15000 is how long (milliseconds) it will listen before timing out. Does anyone one know if there is a way to make it non blocking, so it can listen in the background while I do other things (like change volume etc)?

ChatGPT thinks this will fix it, maybe give it a try:

#include <SparkFunSi4703.h>

#include <Wire.h>

int resetPin = 2;

int SDIO = A4;

int SCLK = A5;

int STC = 3;

Si4703_Breakout radio(resetPin, SDIO, SCLK, STC);

int channel;

int volume;

char rdsBuffer[10];

unsigned long rdsStartTime = 0; // Variable to store the start time for RDS listening

unsigned long rdsTimeout = 15000; // RDS listening timeout in milliseconds

void setup()

{

Serial.begin(9600);

Serial.println(“\n\nSi4703_Breakout Test Sketch”);

Serial.println(“===========================”);

Serial.println(“a b Favourite stations”);

Serial.println(“+ - Volume (max 15)”);

Serial.println(“u d Seek up / down”);

Serial.println(“r Listen for RDS Data (15 sec timeout)”);

Serial.println(“Send me a command letter.”);

radio.powerOn();

radio.setVolume(0);

}

void loop()

{

if (Serial.available())

{

char ch = Serial.read();

if (ch == ‘u’)

{

channel = radio.seekUp();

displayInfo();

}

else if (ch == ‘d’)

{

channel = radio.seekDown();

displayInfo();

}

else if (ch == ‘+’)

{

volume++;

if (volume == 16) volume = 15;

radio.setVolume(volume);

displayInfo();

}

else if (ch == ‘-’)

{

volume–;

if (volume < 0) volume = 0;

radio.setVolume(volume);

displayInfo();

}

else if (ch == ‘a’)

{

channel = 930; // Rock FM

radio.setChannel(channel);

displayInfo();

}

else if (ch == ‘b’)

{

channel = 974; // BBC R4

radio.setChannel(channel);

displayInfo();

}

else if (ch == ‘r’)

{

Serial.println(“RDS listening started”);

rdsStartTime = millis(); // Store the current time as the start time

}

}

// Check if the RDS listening timeout has elapsed

if (rdsStartTime > 0 && millis() - rdsStartTime >= rdsTimeout)

{

Serial.println(“RDS listening timeout”);

rdsStartTime = 0; // Reset the start time

}

else if (rdsStartTime > 0)

{

// Continue to listen for RDS data

radio.readRDS(rdsBuffer, rdsTimeout - (millis() - rdsStartTime));

Serial.print(“RDS heard:”);

Serial.println(rdsBuffer);

rdsStartTime = 0; // Reset the start time

}

}

void displayInfo()

{

Serial.print("Channel: ");

Serial.print(channel);

Serial.print(" Volume: ");

Serial.println(volume);

}

Not at all. It’s a problem in the library, not the code. I’ve already tried ChatGPT, but no success

Darn it…it might need something changed in the core library or maybe you can find another code/project with a solution