Vassilis Serasidis
Published © CC BY-NC-SA

WIZwiki-W7500 WebRadio player (streaming music player)

Listen to your favorite Internet music radio stations with data streaming bit-rate up to 320 kbps !

IntermediateFull instructions provided1,533
WIZwiki-W7500 WebRadio player (streaming music player)

Things used in this project

Hardware components

VS1053 mp3 decoder module
×1
WIZwiki-W7500
WIZnet WIZwiki-W7500
×1

Story

Read more

Schematics

The WebRadio player 2 Connection diagram

Code

The WebRadio player 2 source code (mbed online compiler)

C/C++
/**
 *     WebRadio player 2  (Icecast music streams player)
 *
 *     Listen to your favorite WebRadio music stations up to 320 kbps !
 *
 *     Used components: VS1053 MP3 decoder and WIZ-wiki-W7500 ARM Cortex-M0 board
 *
 *     5 September 2015 by Vassilis Serasidis
 *   
 *     Home: http://www.serasidis.gr
 *     email: avrsite@yahoo.gr
 *
 *     Edit the file "W7500x_toe.cpp" and add the following lines:
 *     
 *       **
 *       * Use only one socket with 16 kBytes of RAM for Tx and 16 kBytes of RAM for Rx 
 *       *
 *       sreg<uint8_t>(0, Sn_RXBUF_SIZE, 16); //Vassilis Serasidis
 *       sreg<uint8_t>(0, Sn_TXBUF_SIZE, 16); //Vassilis Serasidis
 *
 *     -= NOTE =-
 *     This project is provided as-is without any waranty, under the GNU General Public License v3 
 *     ( http://www.gnu.org/licenses/gpl-3.0.en.html )
 * 
 */

#include "mbed.h"
#include "VS1053.h"
#include "EthernetInterface.h"

#define BUFFER_LENGTH    1024
#define BUFFER_LENGTH2     32
#define MAX_RADIO_STATIONS 18 // 18 pre-selected webradio station. You can increase the number if you want.

VS1053 player(D11, D12, D13, D10, D9, D8, D7); // mosi, miso, sck, cs, dcs, dreq, rst
               
char ramBuffer[BUFFER_LENGTH];
int radioStationNumber = 0; //Initial webradio station

Serial com(USBTX, USBRX); //Create a Serial Port instance.

typedef struct station {
    char const * rAddress;
    unsigned int port;
} STATION;

/**
 * 18 pre-selected webradio stations. 
 * You can increase the number of the stations because there is plenty of memory bytes.
 * Syntax: {"WebRadio_station_address", port_number}
 */
const STATION stations[MAX_RADIO_STATIONS] = { 
    {"ks386954.kimsufi.com", 8248},    // <01> La Grosse Radio Metal - Hard Heavy - From Paris ::  48 kbps :: aacp
    {"205.164.62.15",10032},           // <02> 1.FM - GAIA                                     ::  64-kbps :: aacp
    {"205.164.36.153",80},             // <03> BOM PSYTRANCE (1.FM TM)                         ::  64-kbps :: aacp
    {"topfm-st1.kbcnet.rs",80},        // <04> TOP FM Beograd 106,8                            ::  64-kpbs :: mpeg
    {"80.86.82.101",8130},             // <05> Cosmoradio 95.1 - Thessaloniki - Greece         :: 128 kbps :: mpeg
    {"s10.voscast.com",9940},          // <06> Zoo Radio 90.8 Greece                           :: 128 kbps :: mpeg
    {"radio.onweb.gr",8078},           // <07> 1055 ROCK - THESSALONIKI - GREECE               :: 128 kbps :: mpeg
    {"149.255.59.162", 8030},          // <08> ORIGINUK.NET DRUM AND BASS AND OLDSKOOL         :: 128 kbps :: mpeg
    {"uk3.internet-radio.com", 8060},  // <09> Champion 5768 FM - Non Stop Hits From All Eras  :: 128 kbps :: mpeg
    {"46.41.129.195", 8000},           // <10> Trance1.FM                                      :: 128 kbps :: mpeg
    {"uk3.internet-radio.com", 10523}, // <11> Tonik Radio Ireland                             :: 192 kbps :: mpeg
    {"95.141.24.4", 80},               // <12> #MUSIK.CLUB (DANCE) - WWW.RAUTEMUSIK.FM         :: 192 kbps :: mpeg
    {"193.34.51.33", 80},              // <13> WackenRadio.com - Metal Rock Alternative        :: 192 kbps :: mpeg
    {"uk4.internet-radio.com",15938},  // <14> GoHamRadio - Trance Dance Progressive Chillout  :: 256 kbps :: mpeg
    {"206.190.152.194", 8000},         // <15> PARTY VIBE RADIO: Reggae   Roots   Dancehall    :: 256 kbps :: mpeg
    {"213.251.157.145", 8016},         // <16> Audiophile Baroque Clasic Music                 :: 320 kbps :: mpeg
    {"83.137.145.141", 14280},         // <17> Nautic Radio - Beats 'n Breaks - drum and bass  :: 320 kbps :: mpeg
    {"50.7.173.162", 8014}             // <18> Audiophile Jazz                                 :: 320 kbps :: mpeg
};


/*************************************
 *
 *************************************/
int main() {
    
    int i,m;
    
    DigitalIn dreq(D8); //Set DREQ pin as input (D8).
    DigitalIn sw1(D5);  //Next webradio station selection button (D5).
    DigitalIn sw2(D6);  //Previous webradio station selection button (D6).
    
    com.baud(115200);   //Set the Serial port baud rate to 115200 bits/second
    
    com.printf("---------------------------------------\n");
    com.printf("\n          WebRadio player\n");
    com.printf("(c) 05 Sept 2015 by Vassilis Serasidis\n");
    com.printf("      Home: http://www.serasidis.gr\n");
    com.printf("---------------------------------------\n");
    uint8_t mac_addr[6] = {0x00, 0x08, 0xDC, 0x00, 0x01, 0x02}; //Ethernet MAC address
    EthernetInterface eth; 
    com.printf("Getting IP address...\n");
    eth.init(mac_addr); //Use DHCP to get the IP from the ADSL router (from the DHCP server).
    eth.connect();
    printf("Local IP Address: %s\r\n", eth.getIPAddress()); //Print the local IP address.
    TCPSocketConnection client; //Create a client.
    
    player.hardwareReset(); //Do a reset to the VS1053 board.
    player.clockUp();       //Set the VS1053 at faster SPI speed.
    player.modeSwitch();    //Patch the VS1053 board to play MP3 files (very important!).
    player.setVolume(44);   //Set the VS1053 volume. Value 0 is MAX volume, 255 is mute.
    
    while(1){
        com.printf("\n----------------------------------------------\n");
        com.printf("Connecting to [%s] ...\n",stations[radioStationNumber].rAddress);
        
        /* Connect to the Icecast server defined by 'radioStationNumber' variable (1-18) */
        client.connect(stations[radioStationNumber].rAddress, stations[radioStationNumber].port);
        
        /* Check if the client was connected to the server */
        if(client.is_connected()){
            com.printf("Connected!\n\n");    
        }else{
            //com.printf("Is NOT connected. Please try again.\n");
            for(;;); //Stay here for ever.
        }
        
        client.send("GET / HTTP/1.1\r\n",16); //Send the Header to the Server.
        client.send("\r\n",2);
        wait(0.5);
    
        com.printf("Reading Icecast radiostation information...\n");
        /* Read the Icecast server information (station name, bit rate and more)*/
        client.receive(ramBuffer, BUFFER_LENGTH); //Store the received data to the RAM buffer.
        com.printf("Done!\n\n");
        
        com.printf("<%d> ",radioStationNumber + 1); //Print the station number (1-18)
        
        /**
         * From the 1024 received bytes extract only the WebRadio station information.
         * The information data ends with the bytes \r\n\r\n
         * In other words, ends with the four hexadecimal bytes [0x0d 0x0a 0x0d 0x0a] . 
         */
        for(i=0;i<(BUFFER_LENGTH - 4);i++){ 
          if((ramBuffer[i] == 0x0d)&&(ramBuffer[i+1] == 0x0a)&&(ramBuffer[i+2] == 0x0d)&&(ramBuffer[i+3] == 0x0a))
            break; //If you found the end-sequence then break the <for> loop.
          else
            com.putc(ramBuffer[i]);
        }
        com.printf("\n");
        
        
        /* Do that loop forever */  
    
        m = 1;
        
        while(m > 0){ 
            client.receive(ramBuffer, BUFFER_LENGTH2);        
            while(!dreq);
            if(sw1){ //If the NEXT button is pressed,
                if(radioStationNumber < MAX_RADIO_STATIONS - 1 )
                    radioStationNumber++; //select the NEXT webradio station. 
                else
                    radioStationNumber = 0;
                m = 0; //Exit from this loop.
            }
            
            if(sw2){ //If the PREVIOUS button is pressed,
                if(radioStationNumber > 0)
                    radioStationNumber--; //select the PREVIOUS webradio station. 
                else
                    radioStationNumber = MAX_RADIO_STATIONS - 1;
                m = 0; //Exit from this loop. 
            }
            player.sendDataBlock(ramBuffer, BUFFER_LENGTH2);    // and pass the data to the VS1053 MP3 decoder module.
        }
          
    }
}

Credits

Vassilis Serasidis

Vassilis Serasidis

1 project • 0 followers

Comments