The TEA5767 radio and clock can't work together?

Hi all.
The TFT_eSPI.h Clock example works well;
The TEA5767 fm Radio module with ESP32 works well;
I'd like to put them together and listen to radio and watch clock, with two button control the shift.
failed of Radio, clock run well, why?
Thanks
Adam

TEA5767 Radio:

#include <Wire.h>
#include <TEA5767Radio.h>

//TEA5767Radio radio = TEA5767Radio();

#include <TEA5767.h>
TEA5767 radio = TEA5767();

float FrequencyA[14] = {88.1, 88.9, 89.5, 90.3, 91.1, 91.9, 92.5, 94.1, 96.3, 98.7, 99.1, 101.3, 102.4, 104.5};  /// 14
long FrequencyI;
int frequencySelctB = 25;   // 13 
int StratRadioMarker = 0; 
int frequencySelctBmark = 0;
int count = 0;


void setup()
{
  Serial.begin(115200);
  Wire.begin();
  pinMode(frequencySelctB, INPUT);
 // pinMode(BTradioStart, INPUT);

  // radio.setFrequency(FrequencyI); // pick your own frequency
for(int i =0; i<14;i++){
Serial.print("33FrequencyA[3]=");  
Serial.println(FrequencyA[i]);  
}

}

void loop() {
  if (!digitalRead(frequencySelctB)) {
    frequencySelctBmark = 1;
    count++;


    Serial.print("42 count=");
    Serial.println(count);
    if (count > 13) {
      count = 0;

    }
    Serial.print("49 count=");
    Serial.println(count);

  }

  if (frequencySelctBmark == 1) {
    radio.setFrequency(FrequencyA[count]); // pick your own frequency

    Serial.print("56 FrequencyA[count]=");
    Serial.println(FrequencyA[count]);
    frequencySelctBmark = 0;
  }

}

void printStation() {
  Serial.print("Frequency:   ");
  Serial.println(radio.getFrequency()); //Print current Frequency
  Serial.print("Signallevel: ");
  Serial.println(radio.getSignalLevel()); //Print current Signal Level (0-15)
  Serial.println();
}

combined code:

/*
  An example analogue clock using a TFT LCD screen to show the time
  use of some of the drawing commands with the library.

  For a more accurate clock, it would be better to use the RTClib library.
  But this is just a demo.

  This sketch uses font 4 only.

  Make sure all the display driver and pin connections are correct by
  editing the User_Setup.h file in the TFT_eSPI library folder.

  #########################################################################
  ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
  #########################################################################

  Based on a sketch by Gilchrist 6/2/2014 1.0
*/

#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

#include "TEA5767radio.h "


#define TFT_GREY 0x5AEB

TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0;    // Saved H, M, S x & y multipliers
float sdeg = 0, mdeg = 0, hdeg = 0;
uint16_t osx = 120, osy = 120, omx = 120, omy = 120, ohx = 120, ohy = 120; // Saved H, M, S x & y coords
uint16_t x0 = 0, x1 = 0, yy0 = 0, yy1 = 0;
uint32_t targetTime = 0;                    // for next 1 second timeout

static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x
uint8_t hh = conv2d(__TIME__), mm = conv2d(__TIME__ + 3), ss = conv2d(__TIME__ + 6); // Get H, M, S from compile time

bool initial = 1;

#include <Wire.h>
#include <TEA5767Radio.h>

//TEA5767Radio radio = TEA5767Radio();

#include <TEA5767.h>
TEA5767 radio = TEA5767();

float FrequencyA[14] = {88.1, 88.9, 89.5, 90.3, 91.1, 91.9, 92.5, 94.1, 96.3, 98.7, 99.1, 101.3, 102.4, 104.5};  /// 14
long FrequencyI;
int frequencySelctB = 33;   // 13
int StratRadioMarker = 0;
int frequencySelctBmark = 0;
int count = 0;

int CLOCKstart = 13;
int CLOCKstartMarker = 0;
int TEAstart = 25;
int TEAstartMarker = 0;


void setup(void) {

  Serial.begin(115200);

  for (int i = 0; i < 14; i++) {
    Serial.print("33FrequencyA[3]=");
    Serial.println(FrequencyA[i]);
  }

  tft.init();
  tft.setRotation(0);

  pinMode(CLOCKstart, INPUT);
  pinMode(TEAstart, INPUT);
  pinMode(frequencySelctB, INPUT);

  //tft.fillScreen(TFT_BLACK);
  //tft.fillScreen(TFT_RED);
  //tft.fillScreen(TFT_GREEN);
  //tft.fillScreen(TFT_BLUE);
  //tft.fillScreen(TFT_BLACK);
  tft.fillScreen(TFT_GREY);

  tft.setTextColor(TFT_WHITE, TFT_GREY);  // Adding a background colour erases previous text automatically

  // Draw clock face
  tft.fillCircle(120, 120, 118, TFT_GREEN);
  tft.fillCircle(120, 120, 110, TFT_BLACK);

  // Draw 12 lines
  for (int i = 0; i < 360; i += 30) {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 114 + 120;
    yy0 = sy * 114 + 120;
    x1 = sx * 100 + 120;
    yy1 = sy * 100 + 120;

    tft.drawLine(x0, yy0, x1, yy1, TFT_GREEN);
  }

  // Draw 60 dots
  for (int i = 0; i < 360; i += 6) {
    sx = cos((i - 90) * 0.0174532925);
    sy = sin((i - 90) * 0.0174532925);
    x0 = sx * 102 + 120;
    yy0 = sy * 102 + 120;
    // Draw minute markers
    tft.drawPixel(x0, yy0, TFT_WHITE);

    // Draw main quadrant dots
    if (i == 0 || i == 180) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
    if (i == 90 || i == 270) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
  }

  tft.fillCircle(120, 121, 3, TFT_WHITE);

  // Draw text at position 120,260 using fonts 4
  // Only font numbers 2,4,6,7 are valid. Font 6 only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - a p m
  // Font 7 is a 7 segment font and only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : .
  tft.drawCentreString("Time flies", 120, 260, 4);

  targetTime = millis() + 1000;
}


void loop() {

  if (!digitalRead(CLOCKstart)) {
    TEAstartMarker = 0;
    CLOCKstartMarker = 1;

    Serial.print("86 digitalRead(CLOCKstart)=");
    Serial.println(digitalRead(CLOCKstart));
  }

  if (CLOCKstartMarker == 1) {
    TFT_CLOCK_loop();

    Serial.println("TFT_CLOCK_loop--Start");
  }

  if (!digitalRead(TEAstart)) {
    CLOCKstartMarker = 0;

    tft.fillScreen(TFT_BLACK);
    TEAstartMarker = 1;

    Serial.print("86 digitalRead(TEAstart)=");
    Serial.println(digitalRead(TEAstart));
  }

  if (TEAstartMarker == 1) {

    TEA5767_loop();
    Serial.println("TEA5767_loop()--Start");
  }

}


void TFT_CLOCK_loop() {
  if (targetTime < millis()) {
    targetTime += 1000;
    ss++;              // Advance second
    if (ss == 60) {
      ss = 0;
      mm++;            // Advance minute
      if (mm > 59) {
        mm = 0;
        hh++;          // Advance hour
        if (hh > 23) {
          hh = 0;
        }
      }
    }

    // Pre-compute hand degrees, x & y coords for a fast screen update
    sdeg = ss * 6;                // 0-59 -> 0-354
    mdeg = mm * 6 + sdeg * 0.01666667; // 0-59 -> 0-360 - includes seconds
    hdeg = hh * 30 + mdeg * 0.0833333; // 0-11 -> 0-360 - includes minutes and seconds
    hx = cos((hdeg - 90) * 0.0174532925);
    hy = sin((hdeg - 90) * 0.0174532925);
    mx = cos((mdeg - 90) * 0.0174532925);
    my = sin((mdeg - 90) * 0.0174532925);
    sx = cos((sdeg - 90) * 0.0174532925);
    sy = sin((sdeg - 90) * 0.0174532925);

    if (ss == 0 || initial) {
      initial = 0;
      // Erase hour and minute hand positions every minute
      tft.drawLine(ohx, ohy, 120, 121, TFT_BLACK);
      ohx = hx * 62 + 121;
      ohy = hy * 62 + 121;
      tft.drawLine(omx, omy, 120, 121, TFT_BLACK);
      omx = mx * 84 + 120;
      omy = my * 84 + 121;
    }

    // Redraw new hand positions, hour and minute hands not erased here to avoid flicker
    tft.drawLine(osx, osy, 120, 121, TFT_BLACK);
    osx = sx * 90 + 121;
    osy = sy * 90 + 121;
    tft.drawLine(osx, osy, 120, 121, TFT_RED);
    tft.drawLine(ohx, ohy, 120, 121, TFT_WHITE);
    tft.drawLine(omx, omy, 120, 121, TFT_WHITE);
    tft.drawLine(osx, osy, 120, 121, TFT_RED);

    tft.fillCircle(120, 121, 3, TFT_RED);
  }
}

static uint8_t conv2d(const char* p) {
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9')
    v = *p - '0';
  return 10 * v + *++p - '0';
}



void TEA5767_loop() {
  if (!digitalRead(frequencySelctB)) {
    frequencySelctBmark = 1;
    count++;


    Serial.print("42 count=");
    Serial.println(count);
    if (count > 13) {
      count = 0;

    }
    Serial.print("49 count=");
    Serial.println(count);

  }

  if (frequencySelctBmark == 1) {
    radio.setFrequency(FrequencyA[count]); // pick your own frequency

    Serial.print("56 FrequencyA[count]=");
    Serial.println(FrequencyA[count]);
    frequencySelctBmark = 0;
  }

}

void printStation() {
  Serial.print("Frequency:   ");
  Serial.println(radio.getFrequency()); //Print current Frequency
  Serial.print("Signallevel: ");
  Serial.println(radio.getSignalLevel()); //Print current Signal Level (0-15)
  Serial.println();
}



Can you post an annotated schematic showing how you wired it, be sure to include all connections and power sources.

1 Like

Thanks.
The ESP32 DEV + ILI9341 wired:

ILI9341 ESP32

#define SPI_MISO            19
#define SPI_MOSI            23
#define SPI_SCLK            18
//........................
#define TFT_MISO           SPI_MISO
#define TFT_MOSI           SPI_MOSI
#define TFT_SCLK            SPI_SCLK
#define TFT_CS                 05     // Chip select control pin
#define TFT_DC                04      // Data Command control pin
#define TFT_RST               32   // was: 22 , change to 32 for save I2C pin; 

#define TOUCH_MISO     SPI_MISO
#define TOUCH_MOSI     SPI_MOSI
#define TOUCH_SCLK      SPI_SCLK
#define TOUCH_CS          15      // TouchScreen Chip Select
#define TIRQ_PIN             2   // was: 21 , change to 2 for save I2C pin;

and TEA5767 goes: SDA 21 SCL 22
5V battery bank go: VIN of ESP32 and PC USB to ESP32 USB.

Try reversing these two connections.

1 Like

Thanks.
not luck.
do you have idea why the TEA5767 got noise if ESP32 doing anything when Radio on?

Not really but I will take a SWAG. It probably comes down to lead dress and shielding. Everything you have has a clock and clocks will radiate RF. The ESP has a fast clock that will have harmonics that will cross the AM and FM bands. If the software is working as indicated it will become a mechanical layout problem. Twisting wires with a ground always helps but be sure all grounds connect at only one point if possible.

1 Like

I made the TEA works now, and into sleep mode every 5 seconds.
The clock just can show the panel without H/M/S fingers, Too late to show the time?



#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library

#include <Wire.h>
#include <TEA5767Radio.h>

//TEA5767Radio radio = TEA5767Radio();

#include <TEA5767.h>
TEA5767 radio = TEA5767();

float FrequencyA[14] = {88.1, 88.9, 89.5, 90.3, 91.1, 91.9, 92.5, 94.1, 96.3, 98.7, 99.1, 101.3, 102.4, 104.5};  /// 14
long FrequencyI;
int frequencySelctB = 33;   // 13 
int StratRadioMarker = 0; 
int frequencySelctBmark = 0;
int count = 0;


#define TFT_GREY 0x5AEB

TFT_eSPI tft = TFT_eSPI();       // Invoke custom library

float sx = 0, sy = 1, mx = 1, my = 0, hx = -1, hy = 0;    // Saved H, M, S x & y multipliers
float sdeg=0, mdeg=0, hdeg=0;
uint16_t osx=120, osy=120, omx=120, omy=120, ohx=120, ohy=120;  // Saved H, M, S x & y coords
uint16_t x0=0, x1=0, yy0=0, yy1=0;
uint32_t targetTime = 0;                    // for next 1 second timeout

static uint8_t conv2d(const char* p); // Forward declaration needed for IDE 1.6.x
uint8_t hh=conv2d(__TIME__), mm=conv2d(__TIME__+3), ss=conv2d(__TIME__+6);  // Get H, M, S from compile time

bool initial = 1;

int CLOCKstart = 34;
int CLOCKsetupMarker = 0;
int CLOCKstartMarker = 0;
int TEAstart = 25;
int TEAstartMarker = 0; 
int TEAsetupMarker = 0; 
int PADstart = 13;
int PADstartMarker = 0; 
int PADsetupMarker = 0;

//......................................................Rui_ESP32_Timer_Wake_Up_from_Deep_Sleep_gd
#define uS_TO_S_FACTOR 1000000  /* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP  5        /* Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int bootCount = 0;

void setup() {

  SerialSetting();
  TFTsetting();

  pinMode(frequencySelctB, INPUT);
  pinMode(PADstart, INPUT);
  pinMode(TEAstart, INPUT);
  pinMode(CLOCKstart, INPUT);

  TFT_Clock_setup();
   TEA5767_setup();

   sleep_loop();

   //...........................................................................
  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("53 Boot number: " + String(bootCount));

  esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
  Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
                 " Seconds");

  Serial.println("71 Going to sleep now");
  delay(1000);
  Serial.flush();
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop() {
  //sleep_loop();
}

void sleep_loop() {
  TFT_Clock_loop();
  TEA5767_loop();
}

void SerialSetting()
{
  Serial.begin(115200);
  //  while (!Serial) ; // Needed for Leonardo only
  Serial.print("File   : "), Serial.println(__FILE__);
  const char compile_date[] = __DATE__ " " __TIME__;
  Serial.print("Compile timestamp: ");
  Serial.println(compile_date);
}

void TFTsetting()
{
  tft.init();
  tft.setRotation(0);
  tft.setTextSize(1);
  tft.fillScreen(TFT_BLACK);
  tft.setCursor(0, 0);
  tft.setTextColor(TFT_GREEN);
  tft.print("ADAM-DIY");
  delay(2000);
  //  tft.fillScreen(TFT_BLACK);

  // Initialise the TFT
  //  tft.begin();
  tft.setTextColor(0xFFFF, 0x0000);
  //  tft.fillScreen(TFT_BLACK);
  tft.setSwapBytes(true); // We need to swap the colour bytes (endianess)

}


void TFT_Clock_setup() {
  tft.init();
  tft.setRotation(0);
  tft.fillScreen(TFT_GREY);
  
  tft.setTextColor(TFT_WHITE, TFT_GREY);  // Adding a background colour erases previous text automatically
  
  // Draw clock face
  tft.fillCircle(120, 120, 118, TFT_GREEN);
  tft.fillCircle(120, 120, 110, TFT_BLACK);

  // Draw 12 lines
  for(int i = 0; i<360; i+= 30) {
    sx = cos((i-90)*0.0174532925);
    sy = sin((i-90)*0.0174532925);
    x0 = sx*114+120;
    yy0 = sy*114+120;
    x1 = sx*100+120;
    yy1 = sy*100+120;

    tft.drawLine(x0, yy0, x1, yy1, TFT_GREEN);
  }

  // Draw 60 dots
  for(int i = 0; i<360; i+= 6) {
    sx = cos((i-90)*0.0174532925);
    sy = sin((i-90)*0.0174532925);
    x0 = sx*102+120;
    yy0 = sy*102+120;
    // Draw minute markers
    tft.drawPixel(x0, yy0, TFT_WHITE);
    
    // Draw main quadrant dots
    if(i==0 || i==180) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
    if(i==90 || i==270) tft.fillCircle(x0, yy0, 2, TFT_WHITE);
  }

  tft.fillCircle(120, 121, 3, TFT_WHITE);

  tft.drawCentreString("Time flies",120,260,4);

  targetTime = millis() + 1000; 
}

void TFT_Clock_loop() {
  if (targetTime < millis()) {
    targetTime += 1000;
    ss++;              // Advance second
    if (ss==60) {
      ss=0;
      mm++;            // Advance minute
      if(mm>59) {
        mm=0;
        hh++;          // Advance hour
        if (hh>23) {
          hh=0;
        }
      }
    }

    // Pre-compute hand degrees, x & y coords for a fast screen update
    sdeg = ss*6;                  // 0-59 -> 0-354
    mdeg = mm*6+sdeg*0.01666667;  // 0-59 -> 0-360 - includes seconds
    hdeg = hh*30+mdeg*0.0833333;  // 0-11 -> 0-360 - includes minutes and seconds
    hx = cos((hdeg-90)*0.0174532925);    
    hy = sin((hdeg-90)*0.0174532925);
    mx = cos((mdeg-90)*0.0174532925);    
    my = sin((mdeg-90)*0.0174532925);
    sx = cos((sdeg-90)*0.0174532925);    
    sy = sin((sdeg-90)*0.0174532925);

    if (ss==0 || initial) {
      initial = 0;
      // Erase hour and minute hand positions every minute
      tft.drawLine(ohx, ohy, 120, 121, TFT_BLACK);
      ohx = hx*62+121;    
      ohy = hy*62+121;
      tft.drawLine(omx, omy, 120, 121, TFT_BLACK);
      omx = mx*84+120;    
      omy = my*84+121;
    }

      // Redraw new hand positions, hour and minute hands not erased here to avoid flicker
      tft.drawLine(osx, osy, 120, 121, TFT_BLACK);
      osx = sx*90+121;    
      osy = sy*90+121;
      tft.drawLine(osx, osy, 120, 121, TFT_RED);
      tft.drawLine(ohx, ohy, 120, 121, TFT_WHITE);
      tft.drawLine(omx, omy, 120, 121, TFT_WHITE);
      tft.drawLine(osx, osy, 120, 121, TFT_RED);

    tft.fillCircle(120, 121, 3, TFT_RED);
  }
}

static uint8_t conv2d(const char* p) {
  uint8_t v = 0;
  if ('0' <= *p && *p <= '9')
    v = *p - '0';
  return 10 * v + *++p - '0';
}

void TEA5767_setup()
{
//  Serial.begin(115200);
  Wire.begin();
 
  // radio.setFrequency(FrequencyI); // pick your own frequency
  for (int i = 0; i < 14; i++) {
    Serial.print("33FrequencyA[3]=");
    Serial.println(FrequencyA[i]);
  }
}

void TEA5767_loop() {
  if (!digitalRead(frequencySelctB)) {
    frequencySelctBmark = 1;
    count++;
    Serial.print("42 count=");
    Serial.println(count);
    if (count > 13) {
      count = 0;

    }
    Serial.print("49 count=");
    Serial.println(count);

  }

  if (frequencySelctBmark == 1) {
    radio.setFrequency(FrequencyA[count]); // pick your own frequency

    Serial.print("56 FrequencyA[count]=");
    Serial.println(FrequencyA[count]);
    frequencySelctBmark = 0;
  }

}

void printStation() {
  Serial.print("Frequency:   ");
  Serial.println(radio.getFrequency()); //Print current Frequency
  Serial.print("Signallevel: ");
  Serial.println(radio.getSignalLevel()); //Print current Signal Level (0-15)
  Serial.println();
}

1 Like

Great, you can mark this solved.

seems not likely.
the clock still not yet work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.