Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FTPClient javakysSDFileSystem2 WIZnetInterface mbed
Prerequisite
This example is for playing MP3 file stored in SD card on WIZwiki-W7500 and updating MP3 files from server to SD card via FTP protocol.
To implement this function, you need a Platform board, network Interface board, MP3 decoder board and SD card. Below are what we used.
- WIZwiki-W7500 from WIZnet (Platform board and Ethernet I/F board)
- Music shield from Seeed Studio
- SD card
Hardware Configuration
WIZwiki-W7500 Pin map

SPI1 for SD Card
SPI1 on WIZwiki-W7100 is for reading from or writing to SD card and pins for SPI1 are PB_0, PB_1, PB_2 and PB_3.
SPI0 and other control pins for MP3 decoder
WIZwiki-W7500 communicates to MP3 decoder on Music Shield via SPI0 pins of which consists of PC_12, D11, D12 and D13.
And PC_13, PC_14 and PC-15 are used for DCS, DREQ and RST, respectively.
InterruptIn pins for 5-Way Navigation Switch
D3, D4, D5, D6 and D7 are connected to 5 way navigation switch on Music Shield.
When user pushes the switch to one way, a relevant pin is grounded so that he or she should make it set high at the beginning.
Software
SPI Initialization
//Declaration in VS1002.cpp
VS1002::VS1002(PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName dreq, PinName dcs)
: _DREQ(dreq), _RST(rst), _spi(mosi, miso, sck), _CS(cs), _DCS(dcs), _sd(mmosi, mmiso, ssck, ccs, name) {
}
//Initialization in main.cpp
VS1002 mp3(PB_3, PB_2, PB_1, PB_0,"sdc",D11, D12 ,D13, PC_12, PC_15, PC_14, PC_13);
Mapping 5-Way Navigation Switch into InterruptIn pins
main.cpp
InterruptIn K_VU(D3); // Volume UP Key InterruptIn K_VD(D7); // Volume Down Key InterruptIn K_FW(D4); // Foward Key InterruptIn K_BW(D6); // Backward Key InterruptIn K_ONOFF(D5); //Play/Resume or Pause Key
Additional codes due to mbed library bug of WIZwiki-W7500
main.cpp
//Operating Clock Frequency Set *(volatile uint32_t *)(0x41001014) = 0x0060100; //Set all InterruptIn pins to Internal PullUp *(volatile uint32_t *)(0x41003000) = 0x00000002; //D6 *(volatile uint32_t *)(0x41003004) = 0x00000002; //D5 *(volatile uint32_t *)(0x41003008) = 0x00000002; //D4 *(volatile uint32_t *)(0x41003080) = 0x00000002; //D3 *(volatile uint32_t *)(0x41003098) = 0x00000002; //D7
Caution
This example can play only MP3 files with up to 192KHz sample rate//
Diff: SSD1306.h
- Revision:
- 1:fc4e0c572992
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SSD1306.h Thu Mar 30 06:29:49 2017 +0000
@@ -0,0 +1,209 @@
+#include "data.h"
+#define addr (0x78)
+
+#if defined(TARGET_WIZwiki_W7500)
+#define SDA PA_10
+#define SCL PA_9
+#endif
+
+I2C i2c(SDA, SCL);
+
+void send_cmd(uint8_t cmd){
+ char c[2] ={0x00,cmd};
+
+ i2c.write(addr,c,2,1);
+
+}
+
+void send_data(uint8_t data){
+ char c[2] = {0x40,data};
+ i2c.write(addr,c,2,1);
+
+}
+
+void init(void)
+{
+ wait_ms(5); // TBD
+
+ send_cmd(0xae); // display off
+ send_cmd(0xd5); // display divide ratio/osc. freq. ratio
+ send_cmd(0x80);
+ send_cmd(0xa8); // multiplex ation mode: 63
+ send_cmd(0x3f);
+ send_cmd(0xd3); // set display offset
+ send_cmd(0x00);
+ send_cmd(0x40); // set display start line
+ send_cmd(0x8d); // set display offset
+ send_cmd(0x14);
+ send_cmd(0xa1); // segment remap
+ send_cmd(0xc8); // set COM output scan direction
+ send_cmd(0xda); // common pads hardware: alternative
+ send_cmd(0x12);
+ send_cmd(0x81); // contrast control
+ send_cmd(0xcf);
+ send_cmd(0xd9); // set pre-charge period
+ send_cmd(0xf1);
+ send_cmd(0xdb); // VCOM deselect level mode
+ send_cmd(0x40); // set vcomh = 0.83 * VCC
+ send_cmd(0xa4); // set entire display on/off
+ send_cmd(0xa6); // set normal display
+ send_cmd(0xaf); // set display on
+}
+
+// set position (x, 8*y)
+void locate(int x, int y){
+ send_cmd(0xb0+y);
+ send_cmd(((x&0xf0)>>4)|0x10);
+ send_cmd((x&0x0f)|0x01);
+}
+
+void cls(void){
+ int x, y;
+ for(y = 0; y < 8; y++){
+ locate(0, y);
+ for(x = 0; x < 128; x++) send_data(0x00);
+ }
+}
+
+
+
+ void OLED_ShowStr(unsigned char x, unsigned char y, char ch[], unsigned char TextSize)
+{
+ unsigned char c = 0,i = 0,j = 0;
+ switch(TextSize)
+ {
+ case 1:
+ {
+ while(ch[j] != '\0')
+ {
+ c = ch[j] - 32;
+ if(x > 126)
+ {
+ x = 0;
+ y++;
+ }
+ locate(x,y);
+ for(i=0;i<6;i++)
+ send_data(F6x8[c][i]);
+ x += 6;
+ j++;
+ }
+ }break;
+ case 2:
+ {
+ while(ch[j] != '\0')
+ {
+ c = ch[j] - 32;
+ if(x > 120)
+ {
+ x = 0;
+ y++;
+ }
+ locate(x,y);
+ for(i=0;i<8;i++)
+ send_data(F8X16[c*16+i]);
+ locate(x,y+1);
+ for(i=0;i<8;i++)
+ send_data(F8X16[c*16+i+8]);
+ x += 8;
+ j++;
+ }
+ }break;
+ }
+}
+void OLED_DrawBMP(unsigned char x0,
+ unsigned char y0,unsigned char x1,
+ unsigned char y1,unsigned char BMP[])
+{
+ unsigned int j=0;
+ unsigned char x,y;
+
+ if(y1%8==0)
+ y = y1/8;
+ else
+ y = y1/8 + 1;
+ for(y=y0;y<y1;y++)
+ {
+ locate(x0,y);
+ for(x=x0;x<x1;x++)
+ {
+ send_data(BMP[j++]);
+ }
+ }
+}
+//==========================================================//
+// Prints a display big number (96 bytes) in coordinates X Y,
+// being multiples of 8. This means we have 16 COLS (0-15)
+// and 8 ROWS (0-7).
+void printBigNumber(unsigned char s, int x, int y)
+{
+ locate(x,y);
+ int salto=0;
+ for(int i=0; i<96; i++) {
+ if(s == ' ') {
+ send_data(0);
+ } else
+ send_data(bigNumbers[s-0x30][i]);
+
+ if(salto == 23) {
+ salto = 0;
+ x++;
+ locate(x,y);
+ } else {
+ salto++;
+ }
+ }
+}
+void printBigTime(char *s)
+{
+
+ int y=0;
+ int lon = strlen(s);
+ if(lon == 6) {
+ y = 0;
+ } else if (lon == 5) {
+ y = 3;
+ } else if (lon == 4) {
+ y = 6;
+ }
+ else if(lon == 3) {
+ y = 9;
+ } else if (lon == 2) {
+ y = 12;
+ } else if (lon == 1) {
+ y = 15;
+ }
+
+ int x = 2;
+ while(*s) {
+ printBigNumber(*s, x, y);
+
+ y+=3;
+ x=2;
+ locate(x,y);
+ *s++;
+ }
+}
+void LED_P23x32Str(unsigned char x, unsigned char y, char ch[])
+{
+ unsigned char c = 0, i = 0, j = 0, k = 0;
+ while (ch[j] != '\0')
+ {
+ c = ch[j] - '0';
+ if (x > 120) {
+ x = 0;
+ y++;
+ }
+
+ for (k = 0; k < 4; k++) {
+ locate(x, y + k);
+ for (i = 0; i < 23; i++) {
+ send_data(F23x32[c * 23 * 4 + k * 23 + i]);
+ }
+ }
+ x += 25;
+ j++;
+ }
+}
+
+