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

#1 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 04 October 2011 - 11:11 AM

Hi, I have a FM Radio module, that I want to use with Netduino. I found example code for Arduino, but I need help porting it to .NET This is the module and all document are at this page: http://www.sparkfun.com/products/10344 Thanks! Ken

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 04 October 2011 - 11:20 AM

Hi Ken, I read you need help, on which level? How far is your current progress, can you post something about that already? :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 04 October 2011 - 11:36 AM

Hi Ken,

I read you need help, on which level? How far is your current progress, can you post something about that already? :)


To begin, I need help with hook it up to Netduino and get them to "talk", sending the command I can properly figure out. My goal is to tune in a frequency, get signal level and read simple RDS data.

#4 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 04 October 2011 - 12:26 PM

The protocol it's talking is I2C, you can see some example code using I2C linked in http://forums.netdui...-i2cbus-class/.
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#5 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 04 October 2011 - 12:58 PM

Hi Ken, I've done this with the Netduino already - the tricky part is that you need to do a little manipulation with the array you use to read and write to the registers, I think that when you start reading the first word that comes out is at 0x0A rather than 0x00. But porting from Arduino to Netduino is definitely possible. If you're interested I'll try to resurrect the code from my development machine, just let me know. Jeremy

#6 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 04 October 2011 - 01:24 PM

I figure it was I2C. Yes Jeremy, I would love to see and test your code Ken

#7 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 04 October 2011 - 09:48 PM

Hey Ken I've attached the 3 files I think you need to get started - I've tried to keep it close to the Arduino code so it's easy to compare the two. Once you've got the Netduino and Si4703 talking, getting the RDS data is pretty easy. If you hit any problems with that, give me a shout, I've got another class that outputs the channel name and description, but it's seriously not pretty code. I have been using the Sparkfun breakout board, here are the pins I used. Vcc - 3v3 GND - Gnd SDIO - A4 SCLK - A5 !SEN - n/c !RST - D2 GPIO1 - n/c GPIO2 - n/c As with any of these sorts of things, works on my hardware, but use at your own risk...:) Let me know how it works out, Jeremy

Attached Files



#8 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 05 October 2011 - 07:16 AM


I've attached the 3 files I think you need to get started - I've tried to keep it close to the Arduino code so it's easy to


Thanks Jeremy! I give it a try tonight. How come you use Analogue port on Netduino?

/Ken

#9 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 05 October 2011 - 07:41 AM

Hi Ken A4 and A5 are the pins for I2C - there's a great post here http://forums.netdui...5-pinout-cards/ I have the netduino plus card printed out and refer to it pretty much every day :) Jeremy

#10 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 05 October 2011 - 10:46 AM

Hi Ken

A4 and A5 are the pins for I2C - there's a great post here

http://forums.netdui...5-pinout-cards/

I have the netduino plus card printed out and refer to it pretty much every day :)

Jeremy


Yes I got it that A4, A5 is for IC2, just curious if that data is really analogue.

/Ken

#11 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 05 October 2011 - 10:52 AM

Yeah that's a good question, I think that A5 is a clock pulse so it's not analogue. I think the A4 (SDIO) sends logic pulses, rather than a clock signal. But it's completely possible I'm wrong, there's guys like Stefan, CW2 and Mario (and others too!) who know how to explain it much better than me. I'm watching the forum thread below with interest :) It seems to be very relevant to our discussion! http://forums.netdui...64-i2c-voltage/ Jeremy

#12 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 05 October 2011 - 11:11 AM

Yeah that's a good question, I think that A5 is a clock pulse so it's not analogue. I think the A4 (SDIO) sends logic pulses, rather than a clock signal.

A4 and A5 pins have several usage 'modes':

  • When I2C is instantiated, they are physically switched to microcontroller's I2C pins,
  • When passed to AnalogInput, they are A/D converter inputs,
  • When passed to Port-derived class (InputPort, OutputPort, TristatePort, InterruptPort), they are digital I/O.
Switching between analog and digital mode is feature of the microcontroller's I/O controller (most of the I/O pins have multiple functions - one is usually general purpose digital I/O, multiplexed with hardware peripherals, such as A/D converter, UART, SPI, I2C, PWM, CAN, timers etc.), switching between analog an I2C is provided by on-board circuitry designed to maintain compatibility with Arduino shields.

#13 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 05 October 2011 - 12:15 PM

A4 and A5 pins have several usage 'modes':

  • When I2C is instantiated, they are physically switched to microcontroller's I2C pins,
  • When passed to AnalogInput, they are A/D converter inputs,
  • When passed to Port-derived class (InputPort, OutputPort, TristatePort, InterruptPort), they are digital I/O.

Heya! Small question and perhaps a bit offtopic, but I recently read that when switching to I2C it physically switches to +5V tolerant pins. Does the same count for GPIO?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#14 Stefan W.

Stefan W.

    Advanced Member

  • Members
  • PipPipPip
  • 153 posts

Posted 05 October 2011 - 03:47 PM

Hi Stefan, see http://forums.netdui...dpost__p__18103 (yes, they are 5V tolerant unless you do analog input with them, however they are not switched to different pins on the MCU like in the case of I2C). Cheers, Stefan ;)
I believe that no discovery of fact, however trivial, can be wholly useless to the race, and that no trumpeting of falsehood, however virtuous in intent, can be anything but vicious.
-- H.L. Mencken, "What I Believe"

#15 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 06 October 2011 - 09:52 AM

Yeah that's a good question, I think that A5 is a clock pulse so it's not analogue. I think the A4 (SDIO) sends logic pulses,
Jeremy


Hi Jeremy,

I now got the FM module to work, I can set channel and the radio plays. But it report mono and no RDS. I hear stereo in the headphones and I got strong signal (my iPod show RDS)

I try to pull "DisplayStatus()" with a timer, but I get same result only RSSI changes (Received Signal Strength Indicator)

Channel = 1014 (No RDS) (Seek Successful!) (Mono) (RSSI=54 of 75)

Jeremy, do you get RDS and stereo? I not sure if the RDS is enabled.

/Ken

#16 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 06 October 2011 - 10:20 AM

Hey Ken Well done, and 54 out of 75 is higher than anything I got out in the wilds of the countryside! What I found with the RDS was that I had to tell the device to listen for it for a while. I've written some proof of concept code for it, but as I said before it's a bit of a tangled mess, but it definitely gets text out of the signal. I'll look at the code again this weekend and have a go at tidying it up - but as I remember, the process is: 1. Look at the RDS bit after tuning to a strong channel - keep polling until it until it indicates there's RDS data. 2. When it finds there is RDS data, look at the RDSA, RDSB, RDSC and RDSD registers (details are in data sheet). 3. First look at the RDSA register, shift by 11 bits, if it equals 0 or 1 then it's the station name, if it's 5 or 6 then it's the station information. 4. If you're looking at the station information, then look at the values of the RDSD register - split the dataword into two bytes, convert each from a byte to corresponding ascii character. 5. If you're looking at the station information, then look at the values of the RDSC and RDSD register - split the two datawords into four bytes, convert each from a byte to corresponding ascii character. 6. Build up consecutive letters to make up the station name and information. I've found that station name only ever has 8 characters, station information has many more. I imagine you'll actually have it cracked by this weekend anyway, let me know if you do, but if not I'll try to help out. Hope this is helpful, Jeremy

#17 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 06 October 2011 - 10:58 AM


What I found with the RDS was that I had to tell the device to listen for it for a while. I've written some proof of concept code for it, but as I said before it's a bit of a tangled mess, but it definitely gets text out of the signal.


I don't get in so I can read RDS, is my code correct? And why does it say that the station I receive is in "mono"?

this.ReadRegisters();
if((byte)(Si4703_Registers[STATUSRSSI] & (1<<RDSR))>0)
{
  //Read RDS
}


Here is the Ardino code for reading RDS


void readRDS(char* message, long timeout);
// message should be at least 9 chars
// result will be null terminated
// timeout in milliseconds

void Si4703_Breakout::readRDS(char* buffer, long timeout)
{ 
	long endTime = millis() + timeout;
  boolean completed[] = {false, false, false, false};
  int completedCount = 0;
  while(completedCount < 4 && millis() < endTime) {
	readRegisters();
	if(si4703_registers[STATUSRSSI] & (1<<RDSR)){
		// ls 2 bits of B determine the 4 letter pairs
		// once we have a full set return
		// if you get nothing after 20 readings return with empty string
	  uint16_t b = si4703_registers[RDSB];
	  int index = b & 0x03;
	  if (! completed[index] && b < 500)
	  {
		completed[index] = true;
		completedCount ++;
	  	char Dh = (si4703_registers[RDSD] & 0xFF00) >> 8;
      	char Dl = (si4703_registers[RDSD] & 0x00FF);
		buffer[index * 2] = Dh;
		buffer[index * 2 +1] = Dl;
		// Serial.print(si4703_registers[RDSD]); Serial.print(" ");
		// Serial.print(index);Serial.print(" ");
		// Serial.write(Dh);
		// Serial.write(Dl);
		// Serial.println();
      }
      delay(40); //Wait for the RDS bit to clear
	}
	else {
	  delay(30); //From AN230, using the polling method 40ms should be sufficient amount of time between checks
	}
  }
	if (millis() >= endTime) {
		buffer[0] ='\0';
		return;
	}

  buffer[8] = '\0';
}



#18 <Jeremy>

<Jeremy>

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationNorthern Ireland

Posted 06 October 2011 - 12:32 PM

Hi Ken To be honest, everything you've put in the last post pretty much covered I've got at home on RDS. Certainly I think your code looks ok - I've found that some channels initially report 'No RDS', but if I poll for a few seconds like in the Arduino code, the RDS comes up. Have you tried polling, say for 60 seconds to see if anything appears in the RDS registers? Jeremy

#19 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 06 October 2011 - 04:02 PM


Have you tried polling, say for 60 seconds to see if anything appears in the RDS registers?

Jeremy


Hi,

I try pulling for 10 minutes, even on a local transmitter with RDS (RSSI is about 65). I work with broadcast so I put up a small FM transmitter in my lab...

But I question the quality of the FM board, I have one more that I tested with, but that don't even tune in a station... So I ordered one more FM-board to test with that.

/Ken

#20 kenNET

kenNET

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSweden

Posted 11 October 2011 - 07:40 PM

Well I got a new FM board today that works, but I can still not read any RDS (even if a pull data for minutes) and it still reports mono on a good stereo transmission. Jeremy, do you have a working code example that I can try? /Ken




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.