HOWTO: odroid-c1 FM recorder via I2C FM board

Post Reply
mlinuxguy
Posts: 793
Joined: Thu Feb 28, 2013 10:28 am
languages_spoken: english
ODROIDs: X, X2, XU, XU3, XU4, C1, C1+, C2, N1, USB-IO
Contact:

HOWTO: odroid-c1 FM recorder via I2C FM board

Unread post by mlinuxguy » Sun Aug 09, 2015 12:41 pm

This is a quick howto on making your own FM recorder on the Odroid-C1
NOTE: This setup will only record mono, which is fine for public radio talk programs

Parts needed
Odroid-c1
USB External Sound Card:Vista,7,8,XP,Mac,Linux (found on ebay, use the mic input)
TEA5767 FM Stereo Radio Module for Arduino 76-108MHZ With Free Cable Antenna (found on ebay)

Plug USB sound card in and identify what card it appears as

Code: Select all

# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: ODROIDHDMI [ODROID-HDMI], device 0: SPDIF PCM dit-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: Set [C-Media USB Headphone Set], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
As you see mine is at card 1, we will need that later for the record command

Setup I2C on the Odroid-c1

Code: Select all

# cat /etc/modules
i2c-dev
aml_i2c
These are the 2 we care about, just make sure you add them into the file
reboot, or modprobe those drivers to load them

wire up the FM radio board
Assuming you get the same board as me the pins are:
Odroid pin1 == 3.3v VCC <--> Power FM
Odroid pin3 == SDA1 <--> SDA FM
Odroid pin5 == SCL1 <--> SCL FM
Odroid pin6 == GND <--> GND FM

Install the needed software
# apt-get install libav-tools i2c-tools

Use my fmwrite.c program to set the radio station

Code: Select all

# cat fmwrite.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#include <stdlib.h>

#define I2C_ADDR 0x60

int main (int argc, char *argv[] ) {
char buffer[10];
int  fd;
int freq;
float fvalue;

if ( argc != 2 )
{
        fvalue = 105.7;
        freq = 4 * (fvalue * 1000000 + 225000) / 32768;
} else {
        fvalue = atof(argv[1]);
        if (fvalue <= 0) {
                printf("Unable to convert string to float: %s\n", argv[1]);
                exit(-1);
        }
        printf("entered value: %f\n",fvalue);
        freq = 4 * (fvalue * 1000000 + 225000) / 32768;
}

fd = open("/dev/i2c-1", O_RDWR);

if (fd < 0) {
        printf("Error opening file: %s\n", strerror(errno));
        return 1;
}

if (ioctl(fd, I2C_SLAVE, I2C_ADDR) < 0) {
        printf("ioctl error: %s\n", strerror(errno));
        return 1;
}
buffer[0]=freq >> 8;
buffer[1]=freq & 0xff;
buffer[2]=0xb0;
buffer[3]=0x10;
buffer[4]=0x00;
write(fd,buffer,5);
}
Note: the arg is the radio station call number
Note: the I2C address is 0x60 for the fm radio board

Verify FM board is working
Use fmwrite to set a local radio station, plug headset in to verify it set the radio station, you will hear the station on your headset.
example: # ./fmwrite 91.7

Plug din plug from USB mic in to headset output on the FM radio board
Verify you can create a MP3 of that radio station you previously tuned:
# avconv -ac 1 -f alsa -i hw:1,0 -t "01:00:00" -acodec libmp3lame -b:a 64k test_radio.mp3 2>/dev/null
copy test_radio.mp3 to a device capable of playing MP3's and verify

Setup a script to record your public radio station

Code: Select all

# cat scifri.sh
#!/bin/bash
# this records science friday on 105.7 Friday 1-2 and 2-3
# the show is 60 minutes long, so duration is 60 * 60 = 3600 seconds
kjou="105.7"
prog="sci_fri_"
dire="/home/odroid/sshare/"
now=$(date +"%m_%d_%y_%H%M")
/root/fmrec/fmwrite $kjou
/root/fmrec/mount_sshare.sh
avconv -ac 1 -f alsa -i hw:1,0 -t "01:00:00" -acodec libmp3lame -b:a 64k $dire$prog$now.mp3 2>/dev/null
umount /home/odroid/sshare
Note: -i hw:1,0 is the address of my USB sound card, change it if yours differs

use cron to run that script when the radio station program airs
Note: you can mount a Samba share or NFS if you wish to save that off box, my script: mount_sshare.sh

Code: Select all

# cat mount_sshare.sh
#!/bin/bash
mount 192.168.1.51:/shares/SimplePool/sshare /home/odroid/sshare/
Notes: 2>/dev/null is so I don't record all the avconv error messages in cron

theBOSS
Posts: 75
Joined: Sat Jan 17, 2015 2:06 am
languages_spoken: spanish, english
ODROIDs: C1
Contact:

Re: HOWTO: odroid-c1 FM recorder via I2C FM board

Unread post by theBOSS » Wed Aug 12, 2015 3:48 am

Thanks for your hard work @mlinuxguy

It´s nice

Best regards!
http://lordpedal.ddns.net... la culminación de un fin es el comienzo de una realidad.

Post Reply

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 3 guests