$USD
  • EUR€
  • £GBP
  • $USD
PROJECTS ArduinoBluetooth

How to Make a Bluetooth Music Player

DFRobot Jul 06 2018 1872


Do you become elated when your Mr/Mrs Right agree to go on a date with you?

Then a brighter sunny day begins. While a puzzle comes into my mind that what gift should I bring.

Innovated by the movie Pixels by Sony, I believe Pixel will be a great choice which represents pure and authentic.

Hereby let's expand more on pixels - colors, particles, etc.

Off the top of my head, colors can be represented by the matrix screen (such as 32x16 RGB LED Matrix)

What makes particles? Definitely it is Lego?

In addition, it is a Bluetooth music player with music spectrum.


Component list:

- 32x16 RGB LED Matrix Panel (6mm pitch)

- DFRduino Mega2560 V3.0 controller

- Bluetooth Audio Receiver and Playback Module (Bluetooth 4.0)

- Stereo Enclosed Speaker - 3W 8Ω

- TCS34725 RGB Color Sensor For Arduino (optional)

- Lego bricks (about 40 particles)


Wiring Connection:

The interface of rgb matrix screen has 16 wires (R1.G1.B1 R2.G2.B2 A.B.C CLK LAT OE 4 GNDs); Arduino mega2560 (24.25.26 27.28.29 A4.A1.A2 11 A3 9).

The Bluetooth voice panel includes two small loudspeakers with right and left channels as well as functional buttons such as volume+ and volume-. It can connect several four-foot buttons. In terms of power supply, you can add lithium battery or use external USB and DC plug (as shown in the following picture).


According to what we have understanded, what is music?

Or what is sound? Graphically, it’s a heap of waves running up and down (waves include a lot of information so they look a bit disordered).

A more vivid explanation is that they are music notes on the stave.

Now we know how to express music in a vivid way. Next, let’s start a short study on Fourier transform algorithm (FFT):

The fickle world with flying falling leaves in your eyes is actually a composed movement lying in the arms of God”.

Sorry. It’s not something like chicken soup but a certain formula on the blackboard. Fourier told us that any periodic function can be regarded as the superposition of different amplitudes and sine waves of different phase positions. In the first example, we can interpret it like this: any piece of music can be created by beating different keys with different forces at different points of time.

One of the methods which run through time and frequency domains is the legendary Fourier analysis which can be divided into Fourier Series and Fourier Transformation. Let’s start with the simple one.

Music play scenario: The range display of music at 32 frequency domains.


Audio Codes:

     #define LOG_OUT 1 // use the log output function
#define FFT_N 256 // FFT Samples:16.32.64.128.256
//#define DEBUG
#include  //Fast Fourier Transformer File Declaration
#include    // Core graphics library
#include  // Hardware-specific library
 
#define Cycle 3 //Because there is a lot of noise interference in a single sampling, the method of averaging multiple samples is selected.
#define SIZE_WIDTH 32    //show the rgb width
//#define MAX_SPECTRUM 32 
#define GAIN 2.3
//#define FREQUENCY_INDEX(I) ((I)*3 + 10)
int Spectrum[SIZE_WIDTH];//Array records multiple samples and takes the average at the end
// Similar to F(), but for PROGMEM string pointers rather than literals
//#define F2(progmem_ptr) (const __FlashStringHelper *)progmem_ptr
#define CLK 11 // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A3
#define OE  9
#define A   A4
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
const unsigned char myBitmap [] PROGMEM = {
  // 'Designbolts-Free-Valentine-Heart-Heart, 16x16px
  0x00, 0x00, 0x1c, 0x38, 0x7e, 0x7e, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 0x7f, 0xfe, 
  0x3f, 0xfc, 0x1f, 0xf8, 0x1f, 0xf8, 0x0f, 0xf0, 0x03, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 
};
void setup() {
   Serial.begin(115200); // use the serial port
   TIMSK0 = 0; // turn off timer0 for lower jitter - delay() and millis() killed
   ADCSRA = 0xe5; // set the adc to free running mode
   ADMUX = 0x40; // use adc0
   DIDR0 = 0x01; // turn off the digital input for adc0
 
   matrix.begin();
//           matrix.fillScreen(matrix.Color888(0, 150, 255));
//while(true);
 }
  
void loop() {
  int ave;
//  matrix.fillScreen(0);
  for (int m=0;m26)
        y = 15;
         
        /*if(y<=7){
           
           //y = 0;
           matrix.fillScreen(0);
        }*/
         
       matrix.drawLine(m, 0, m, y, matrix.Color888(0, 150, 255));
       matrix.drawLine(m, y+1, m, 15, matrix.Color888(0, 0, 0));
      }
        }
    
}
  
  


How to create emoticons (graphics)?

Matrix Taking Software:here is the link

Select the graphics we have drawn, and change settings and preview.

Configure data output format and drawing pattern (horizontal or vertical)

The data format usually is in this type:

// 'Designbolts-Free-Valentine-Heart-Heart', 16x16px
const unsigned char myBitmap [] PROGMEM = {
0xff, 0xff, 0xe3, 0xc7, 0x81, 0x81, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 
0xc0, 0x03, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff
};


Emoticon Demonstration

Emotions Code Sample:

#include 
#include 
#include 
#include 
 
// testshapes demo for Adafruit RGBmatrixPanel library.
// Demonstrates the drawing abilities of the RGBmatrixPanel library.
// For 16x32 RGB LED matrix:
// [url=http://www.adafruit.com/products/420]http://www.adafruit.com/products/420[/url]
 
// Written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon
// for Adafruit Industries.
// BSD license, all text above must be included in any redistribution.
 
 
#include  // Hardware-specific library
 
#define CLK 11  // MUST be on PORTB! (Use pin 11 on Mega)
#define LAT A4
#define OE  9
#define A   A0
#define B   A1
#define C   A2
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);
 // 'Designbolts-Free-Valentine-Heart-Heart', 16x16px
const unsigned char myBitmap [] PROGMEM = {
  0xff, 0xff, 0xe3, 0xc7, 0x81, 0x81, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 
  0xc0, 0x03, 0xe0, 0x07, 0xe0, 0x07, 0xf0, 0x0f, 0xfc, 0x3f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff
};
 
void setup() {
 
  matrix.begin();
  matrix.drawBitmap(0,0,myBitmap,16,16,0xff);
   
}
 
void loop() {
  // do nothing
}

You can add color sensor TCS34725 to create more fun.

REVIEW