TEA5767 Fm Radio Spirit Box

Hey,

I have a question, i'm new to all this arduino thing at least i have not much experience at all yet.
I sure made some first experiments with blinking leds and potentiometers etc and though its a lot of fun.

But now i need your help, i got stuck completly and tried everything i have learned so far but it wont work as i was expecting.

I have an arduino uno and hooked up a TEA5767 radio. Everything works, no problems so far. But i want to build a "spirit box" out of it.
Basicly its pretty simple to do and works already, the radio simply scrolls thouh the frequencies without stopping.

But i want to add two switches to change the direction and another to make the frequencies a bit randomized.
Instead of scolling 99.1 99.2 99.3.... by flicking a switch it should now count randomized 99.1 105.4 101.3.... Another switch should simply invert the frequency counting.
The problem is that this fm radio chips work with this bit code thing, that probably most of you know, but for me, i'm completely lost as they have no single input where i could patch another output onto it. Maybe somebody can help me, i bet for some of you this is a 20second job.... Well i took over two days now without progress...

Thanks for the help!

Post the code that you have that scrolls through the frequencies

// SpiritBox vers. 1.01 by Mancave Effects
#include <TEA5767.h>
#include <TM1637Display.h>
#include <Wire.h>
#include <TEA5767Radio.h>


int buttonState = 0;         
const int buttonPin = 0;     
const int CLK = 9; 
const int DIO = 8; 

TEA5767Radio radio = TEA5767Radio();

TM1637Display display(CLK, DIO);  //set up the 4-Digit Display.

  



void setup()
{ 
   Serial.begin(9600);
   unsigned char buf[5];
   Wire.begin();
   display.setBrightness(0x0a);  //set the diplay to maximum brightness
 }
void loop ()
{
  radio.setFrequency(75.0); // pick your own frequency
  display.showNumberDec(750);
  radio.setFrequency(75.1); // pick your own frequency
  display.showNumberDec(751);
  radio.setFrequency(75.2); // pick your own frequency
  display.showNumberDec(752);
  radio.setFrequency(75.3); // pick your own frequency
  display.showNumberDec(753);
  radio.setFrequency(75.4); // pick your own frequency
  display.showNumberDec(754);
  radio.setFrequency(75.5); // pick your own frequency
  display.showNumberDec(755);
  radio.setFrequency(75.6); // pick your own frequency
  display.showNumberDec(756);
  radio.setFrequency(75.7); // pick your own frequency
  display.showNumberDec(757);
  radio.setFrequency(75.8); // pick your own frequency
  display.showNumberDec(758);
  radio.setFrequency(759); // pick your own frequency
  display.showNumberDec(759);
  radio.setFrequency(76.0); // pick your own frequency
  display.showNumberDec(760);
  radio.setFrequency(76.1); // pick your own frequency
  display.showNumberDec(761);
  radio.setFrequency(76.2); // pick your own frequency
  display.showNumberDec(762);
  radio.setFrequency(76.3); // pick your own frequency
  display.showNumberDec(763);
  radio.setFrequency(76.4); // pick your own frequency
   display.showNumberDec(764);
  radio.setFrequency(76.5); // pick your own frequency
   display.showNumberDec(765);
  radio.setFrequency(76.6); // pick your own frequency
   display.showNumberDec(766);
  radio.setFrequency(76.7); // pick your own frequency
   display.showNumberDec(767);
  radio.setFrequency(76.8); // pick your own frequency
  display.showNumberDec(768);
  radio.setFrequency(76.9); // pick your own frequency
  display.showNumberDec(769);
  radio.setFrequency(77.0); // pick your own frequency
   display.showNumberDec(770);
  radio.setFrequency(77.1); // pick your own frequency
   display.showNumberDec(771);
  radio.setFrequency(77.2); // pick your own frequency
   display.showNumberDec(772);
  radio.setFrequency(77.3); // pick your own frequency
   display.showNumberDec(773);
  radio.setFrequency(77.4); // pick your own frequency
   display.showNumberDec(774);
  radio.setFrequency(77.5); // pick your own frequency
   display.showNumberDec(775);
  radio.setFrequency(77.6); // pick your own frequency
   display.showNumberDec(776);
  radio.setFrequency(77.7); // pick your own frequency
   display.showNumberDec(777);
  radio.setFrequency(77.8); // pick your own frequency
   display.showNumberDec(778);
  radio.setFrequency(77.9); // pick your own frequency
   display.showNumberDec(779);
  radio.setFrequency(78.0); // pick your own frequency
   display.showNumberDec(780);
  radio.setFrequency(78.1); // pick your own frequency
   display.showNumberDec(781);
  radio.setFrequency(78.2); // pick your own frequency
   display.showNumberDec(782);
  radio.setFrequency(78.3); // pick your own frequency
   display.showNumberDec(783);
  radio.setFrequency(78.4); // pick your own frequency
   display.showNumberDec(784);
  radio.setFrequency(78.5); // pick your own frequency
   display.showNumberDec(785);
  radio.setFrequency(78.6); // pick your own frequency
   display.showNumberDec(786);
  radio.setFrequency(78.7); // pick your own frequency
   display.showNumberDec(787);
  radio.setFrequency(78.8); // pick your own frequency
   display.showNumberDec(788);
  radio.setFrequency(78.9); // pick your own frequency
   display.showNumberDec(789);
  radio.setFrequency(79.0); // pick your own frequency
   display.showNumberDec(790);
  radio.setFrequency(79.1); // pick your own frequency
   display.showNumberDec(791);
  radio.setFrequency(79.2); // pick your own frequency
   display.showNumberDec(792);
  radio.setFrequency(79.3); // pick your own frequency
   display.showNumberDec(793);
  radio.setFrequency(79.4); // pick your own frequency
   display.showNumberDec(794);
  radio.setFrequency(79.5); // pick your own frequency
   display.showNumberDec(795);
  radio.setFrequency(79.6); // pick your own frequency
   display.showNumberDec(796);
  radio.setFrequency(79.7); // pick your own frequency
   display.showNumberDec(797);
  radio.setFrequency(79.8); // pick your own frequency
   display.showNumberDec(798);
  radio.setFrequency(79.9); // pick your own frequency
   display.showNumberDec(799);
  radio.setFrequency(80.0); // pick your own frequency


.....




and so on, i cant paste all the code here as it is to long due to the 9000 letters limit



.......



  display.showNumberDec(1059);
  radio.setFrequency(106.0); // pick your own frequency
  display.showNumberDec(1060);
  radio.setFrequency(106.1); // pick your own frequency
  display.showNumberDec(1061);
  radio.setFrequency(106.2); // pick your own frequency
  display.showNumberDec(1062);
  radio.setFrequency(106.3); // pick your own frequency
  display.showNumberDec(1063);
  radio.setFrequency(106.4); // pick your own frequency
  display.showNumberDec(1064);
  radio.setFrequency(106.5); // pick your own frequency
  display.showNumberDec(1065);
  radio.setFrequency(106.6); // pick your own frequency
  display.showNumberDec(1066);
  radio.setFrequency(106.7); // pick your own frequency
  display.showNumberDec(1067);
  radio.setFrequency(106.8); // pick your own frequency
  display.showNumberDec(1068);
  radio.setFrequency(106.9); // pick your own frequency
  display.showNumberDec(1069);
  radio.setFrequency(107.0); // pick your own frequency
  display.showNumberDec(1070);
  radio.setFrequency(107.1); // pick your own frequency
  display.showNumberDec(1071);
  radio.setFrequency(107.2); // pick your own frequency
  display.showNumberDec(1072);
  radio.setFrequency(107.3); // pick your own frequency
  display.showNumberDec(1073);
  radio.setFrequency(107.4); // pick your own frequency
  display.showNumberDec(1074);
  radio.setFrequency(107.5); // pick your own frequency
  display.showNumberDec(1075);
  radio.setFrequency(107.6); // pick your own frequency
  display.showNumberDec(1076);
  radio.setFrequency(107.7); // pick your own frequency
  display.showNumberDec(1077);
  radio.setFrequency(107.8); // pick your own frequency
  display.showNumberDec(1078);
  radio.setFrequency(107.9); // pick your own frequency
  display.showNumberDec(1079);
  radio.setFrequency(108.0); // pick your own frequency
  display.showNumberDec(1080);
  radio.setFrequency(108.1); // pick your own frequency
  display.showNumberDec(1081);
  radio.setFrequency(108.2); // pick your own frequency
  display.showNumberDec(1082);
  radio.setFrequency(108.3); // pick your own frequency
  display.showNumberDec(1083);
  radio.setFrequency(108.4); // pick your own frequency
  display.showNumberDec(1084);
  radio.setFrequency(108.5); // pick your own frequency
  display.showNumberDec(1085);
  radio.setFrequency(108.6); // pick your own frequency
  display.showNumberDec(1086);
  radio.setFrequency(108.7); // pick your own frequency
  display.showNumberDec(1087);
  radio.setFrequency(108.8); // pick your own frequency
  display.showNumberDec(1088);
  radio.setFrequency(108.9); // pick your own frequency
  display.showNumberDec(1089);
  radio.setFrequency(109.0); // pick your own frequency
  display.showNumberDec(1090);
  radio.setFrequency(109.1); // pick your own frequency
  display.showNumberDec(1091);
  radio.setFrequency(109.2); // pick your own frequency
  display.showNumberDec(1092);
  radio.setFrequency(109.3); // pick your own frequency
  display.showNumberDec(1093);
  radio.setFrequency(109.4); // pick your own frequency
  display.showNumberDec(1094);
  radio.setFrequency(109.5); // pick your own frequency
  display.showNumberDec(1095);
  radio.setFrequency(109.6); // pick your own frequency
  display.showNumberDec(1096);
  radio.setFrequency(109.7); // pick your own frequency
  display.showNumberDec(1097);
  radio.setFrequency(109.8); // pick your own frequency
  display.showNumberDec(1098);
  radio.setFrequency(109.9); // pick your own frequency
  display.showNumberDec(109.9);
  display.showNumberDec(0000);

}

OUCH ! That code is painful

The first thing for you to do is to research for loops. You can reduce your existing code by about 90% or more before considering enhancements.

The problem is that as loop it skips frequencies and it sounds weird

The problem is that as loop it skips frequencies and it sounds weird

Do you mean that its skips frequencies as it is now or when you use a for loop ?

The portion of code that you posted seems to increment the frequency by 0.1. Is that always the case in the full code ?

By the way, you could have attached the code if it was too big to post.

Actually the code works great like this. When i use code that came with the FM shield it scrolls though the frequencies and skip's most of them as the radio is looking for the next channel. But this is not what i want, i want it to scan frequency by frequency, what works with my home brew craftet sketch (if only i could use gaffer tape as a solution ;).
The code how it is now scans every 100rds of a frequency what is what i want.
But addiotional to this code i want to add a switch.
Meaning that when
switch is off, the sketch runs as is
when the switch is "on" it searches for frequencies randomly (99.1 108.5 101.3 92.5 ... and so on).

Thats basicly what i want to do for now sure additionally there could be a seperate switch that make the skech run backwards (instead of 97.0-108.9 108.9-97.0).

But for now i would be happy to have a solution for the first challenge ;)....

As has already been pointed out, you could replace all this:

  radio.setFrequency(75.0); // pick your own frequency
  display.showNumberDec(750);
  radio.setFrequency(75.1); // pick your own frequency
  display.showNumberDec(751);
  radio.setFrequency(75.2); // pick your own frequency
  display.showNumberDec(752);
  radio.setFrequency(75.3); // pick your own frequency
  display.showNumberDec(753);
  . . .
  . . .
  radio.setFrequency(109.9); // pick your own frequency
  display.showNumberDec(109.9);

with something like this and still increment by 0.1 MHz :

for ( int i = 750 ; i < 1100 ; i++ ) {
  float freq = i/10.0 ;
  radio.setFrequency(freq); // pick your own frequency
  display.showNumberDec(i);
  // maybe also you want to wait here for a few ms
}

and to go backwards:

for ( int i = 1100 ; i >= 750 ; i-- ) {
  float freq = i/10.0 ;
  radio.setFrequency(freq); // pick your own frequency
  display.showNumberDec(i);
  // maybe also you want to wait here for a few ms
}

Actually the code works great like this.

I never said that it didn't, just that there was a better way of doing it.

Try the for loop as suggested.

Awesome, it works!

I havent worked with “for” sketches yet so i am lost again adding a switch to it.

Usually i would read the switch state and write it to an output, right?
But in this case there is no output as it writes to the radio shield in serial if i understand right?

#include <TEA5767.h>
#include <TM1637Display.h>
#include <Wire.h>
#include <TEA5767Radio.h>
int buttonState = 0;         
const int buttonPin = 1;     
const int CLK = 9; 
const int DIO = 8; 
TEA5767Radio radio = TEA5767Radio();
TM1637Display display(CLK, DIO);  //set up the 4-Digit Display.

void setup()
{ 
   Serial.begin(9600);
   unsigned char buf[5];
   Wire.begin();
   display.setBrightness(0x0a);  //set the diplay to maximum brightness
}
void loop ()
{
buttonState = digitalRead(buttonPin);
 if (buttonState == HIGH) {
   

for ( int i = 750 ; i < 1100 ; i++ ) {
  float freq1 = i/10.0 ;
  radio.setFrequency(freq1); // pick your own frequency
  display.showNumberDec(i);
  delay(100);

}} else {

for ( int i = 1100 ; i >= 750 ; i-- ) {
  float freq = i/10.0 ;
  radio.setFrequency(freq); // pick your own frequency
  display.showNumberDec(i);
  delay(100);
}}}

It looks OK but:

  1. int buttonState = 0; // should really be bool buttonState = 0;
  2. const int buttonPin = 1; // avoid using pins 0 and 1 because these are used for the serial functions.
  3. There is no pinMode() statement for buttonPin. It will work, however, in your case if there is a 10k pull down resistor on buttonPin. Better is to restructure the code and use the internal pull up resistor on the pin.

Hello,

I'm a first time user of the arduino and have purchased both a UNO and a NANO.

I'm trying to do pretty much the same as the OP and was wondering if the OP had made any progress on this project at all. I've made some progress in getting the TEA5767 working with an adjustable sweep by using a 10k potentiometer. However, like the OP I am a bit stumped how to get a reverse sweep and also a random sweep.

I plan to use an ON-OFF-ON toggle switch for this but unsure of the way to write the code to get it working.

If anyone or even the OP could get back to me as I know this is thread is now a few months old i woukd be very grateful.

Many Thanks.

Without having looked at this particular chip, most FM radio ICs will be set default to take 200kHz steps.
They won’t be set to an even frequency by tuning to something like 104.4 MHz, even if you tell them to
because radio stations in most countries, by law, must be at least 200kHz apart.

You can set the frequency step to 100kHz, or 50kHz though, and then this will work.
A specific example of this is the Silicon Labs Si4703/Si4702.

For these chips the step register is called "SPACE”.

You can change this because in different countries, the laws and channel spacing are different.
200kHz spacing applies to the US and Australia, For Europe you might find 100 kHz spacing,
and 50kHz in parts of Japan.

You might also notice AM radios with digital displays take 9kHz steps for the same reason.