Help porting Arduino code for FM radio module - Page 2 - General Discussion - Netduino Forums
   
Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Help porting Arduino code for FM radio module


  • Please log in to reply
27 replies to this topic

#21 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 11 October 2011 - 08:08 PM

Hey Ken

Try this, it's only a proof of concept I put together in 20 minutes, so it's not good code or even remotely robust, but it'll get you started I hope:

Add "using System.Collections;" to the Si4703 class I uploaded before.

Also add this code to the same class.

public string PrintRadioName()
        {
            int j = 0;
            string token = "";
            string fullRadioName = "";
            while (true && j < 500)
            {
                j++;
                this.ReadRegisters();
                if ((this.Si4703_Registers[Si4703.STATUSRSSI] & (1 << Si4703.RDSR)) > 1)
                {
                    var radioNameSoFar = this.ReadRadioName();
                    if (radioNameSoFar != null)
                    {
                        if (token != (string)radioNameSoFar.Value)
                        {
                            token = (string)radioNameSoFar.Value;
                            fullRadioName += radioNameSoFar.Value;
                        }

                        if (fullRadioName.Length > 16)
                        {
                            return fullRadioName;
                        }
                    }
                }
            }
            return string.Empty;
        }

        public DictionaryEntry ReadRadioName()
        {
            if ((this.Si4703_Registers[RDSB] >> 11) == 0 || (this.Si4703_Registers[RDSB] >> 11) == 1)
            {
                int Dh = (this.Si4703_Registers[RDSD] & 0xFF00) >> 8;
                int Dl = (this.Si4703_Registers[RDSD] & 0x00FF);

                int infoOrder = (this.Si4703_Registers[RDSB] & 0x00FF);

                var radioName = new System.Text.UTF8Encoding();
                byte blockerrors = (byte)((this.Si4703_Registers[STATUSRSSI] & 0x0600) >> 9); //Mask in BLERA

                DictionaryEntry d;

                if (blockerrors == 0)
                {
                    if ((Dh >= 32 && Dh <= 127) && (Dl >= 32 && Dl <= 127))
                    {
                        var radioChars = radioName.GetChars(new byte[] { (byte)Dh, (byte)Dl });
                        d = new DictionaryEntry(infoOrder, "" + radioChars[0] + radioChars[1]);
                        return d;
                    }
                }
            }
            return null;
        }

And call the "PrintRadioName" method after you tune to a radio station with a strong signal. If there's something there, it should return it into a string variable. I was able to get some RDS information with this, so hopefully it'll work in your part of the world too. Anyway, give it a try and let me know what happens.

Jeremy

#22 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 11 October 2011 - 08:49 PM

Hey Ken

Try this, it's only a proof of concept I put together in 20 minutes, so it's not good code or even remotely robust, but it'll get you started I hope:



Thanks Jeremy, It works!

What you are showing here is called "PS" (programme service) and is 8 characters long, Also interesting is "RT" (radio text) 64 characters long. Here is more info: http://en.wikipedia....dio_Data_System

Thanks again, now I have something to play with.


Another thing, do you think it's possible to control two ore more of this FM-board from the one Netduino, with all running and pulling data from each of them?


/Ken

#23 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 11 October 2011 - 09:00 PM

I think I solved the RDS mystery and stereo thing thanks to your new code.

The code I first got from you you cast with byte, that should not be there

before:

            if ((byte)(this.Si4703_Registers[STATUSRSSI] & (1 << STEREO)) > 0)
            {
                status += " (Stereo!)";
            }
            else
            {
                status += " (Mono)";
            }


now, this works:


            if ((this.Si4703_Registers[STATUSRSSI] & (1 << STEREO)) > 0)
            {
                status += " (Stereo!)";
            }
            else
            {
                status += " (Mono)";
            }



#24 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 11 October 2011 - 09:37 PM

Hi Ken - excellent news! I'll update my code here as well, I'm happy you've found how to make it better :D

What might be interesting to you as well is if you want to see the radio text information, you can use

if ((this.Si4703_Registers[RDSB] >> 11) == 4 || (this.Si4703_Registers[RDSB] >> 11) == 5)
            {
                int Ch = (this.Si4703_Registers[RDSC] & 0xFF00) >> 8;
                int Cl = (this.Si4703_Registers[RDSC] & 0x00FF);
                int Dh = (this.Si4703_Registers[RDSD] & 0xFF00) >> 8;
                int Dl = (this.Si4703_Registers[RDSD] & 0x00FF);

... and convert to ascii, and then the rest of the code goes here, with minor modifications :)

That's an interesting question about the two boards from one Netduino. I don't know enough about the I2C protocol right now to answer that unfortunately. If you've got two FM boards (even if the first one is only partially working) you might be able to try it, but I guess you might have to revisit the original code and try to eliminate static variables. I don't know how two devices with the same device identifier on the same I2C pins would work - I'd guess it would conflict, because the netduino can't determine which device to talk to at any one time? But it's just a guess.

Cheers,
Jeremy

#25 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 11 October 2011 - 09:48 PM


That's an interesting question about the two boards from one Netduino. I don't know enough about the I2C protocol right now to answer that unfortunately. If you've got two FM boards (even if the first one is only partially working) you might be able to try it, but I guess you might have to revisit the original code and try to eliminate static variables. I don't know how two devices with the same device identifier on the same I2C pins would work - I'd guess it would conflict, because the netduino can't determine which device to talk to at any one time? But it's just a guess.



I have 3 FM boards, 2 are working fine.

I was thinking of device identifier as they have to share I2C pins, but I'm not sure if that is possible to change device identifier on the board (and store it). If I cound have different ID then I just could make a new instance of the "FM board class"

I have code C# for many years, but bite/byte coding for Netduino is new for me, but I'm learning ;-)

/Ken

#26 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 11 October 2011 - 10:55 PM

You've got me interested in this breakout board again, I think we can improve the Programme Service Name code a little - in the PrintRadioName method, I put the RDSB value and text into a DictionaryEntry object, but I think it would be better to store

( (this.Si4703_Registers[RDSB] & 0x00FF) & 0x3) * 2;

So this time, each of the pairs of letters will be associated with the numbers 0, 2, 4, and 6, and therefore you can determine the correct order of the letters and what letters come first.

Jeremy

#27 CdRsKuLL

CdRsKuLL

    New Member

  • Members
  • Pip
  • 1 posts

Posted 24 August 2012 - 03:12 PM

Hi guys, I was hoping you could help me. I've just purchased one of these little radios in the hope I can couple it with an arduino nano and then write a vb.net frontend so I can use it in my car. I have already wrote a vb.net / flash frontend which I give away free to all car pc geeks (like me :-) just search for 'FreeICE' and wanted to also get a rds fm radio. I've downloaded a Si4703 Lib for the Arduino and managed to get the little device working. I'm just wanting a few extra things. I need to be able to toggle the mute on/off the device and also extend the RDS reader. I would like it to auto-update the RDS by simply sending something like RDSNAME:xxxx / RDSDESC:xxxx down via Serial.println and my VB app would do the rest. Agian the signal strength and mono / stereo indicators would be hand. Either by asking the arduino or just auto receiving them. any help would be most welcome. :-) thanks, Steve

#28 JordiMayor

JordiMayor

    New Member

  • Members
  • Pip
  • 5 posts

Posted 26 June 2013 - 12:18 PM

I'm in a good mess working with Netduino Plus 2 and si4703FM chip from sparkFun. Netduino is running last beta versión, but I've tried connect to my Chip with the original version, but no lucky... :(

I'm able to run my program, but after the si4703.Init(), when try to read the registers all values are set to 0... I cannot hear anything from my si4703.

 

All connections are revised many times, but I cannot find the mistake... Please, any help will be very useful to go on...

 

Thank you very much...  






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.