WTV020SD16P Library Conflicting with Both Hardware and Software Serial Ports

Dear Forum,

I am currently trying to use the BLYNK app (on a smartphone) to wirelessly control an MP3/sdCard module (Wtv020sd16p). There is an excellent tutorial on the Wtv020sd16p here Arduino mp3 module Tutorial - wtv020sd16p: Code, Connect, and Run! - YouTube .

I am using an HM-10 Bluetooth module as the slave. I have written some code to communicate between my phone and serial monitor. I installed the BLE Terminal app on my smartphone and I can confirm that the serial communication works great.

Martyn Currey has an excellent tutorial on this here HM-10 Bluetooth 4 BLE Modules | Martyn Currey . With Martyn's code, I was able to change the HM-10 baud rate...very cool.

I have already tried to increase the baud rate to 57600, but the BLE Terminal app only allows 9600. I have an e-mail into their tech support to figure out how to change the baud rate. This feature is probably available on the purchased version, and I will be happy to purchase the app if I can get this functionality.

The only problem that I seem to be having is when I create an instance of the WTV020SD16P class. This seems to interfere with the both the hardware and software serial ports. I currently have the line commented out.

I looked at the wtv020sd16p.cpp code (WTV020SD16P/WTV020SD16P.cpp at master · theFPVgeek/WTV020SD16P · GitHub ) and the only thing that I can think of is that there is a timing issue. The WTV code has some very small delays on the order of microseconds, and I wonder if this is creating an issue for the serial ports.


#include <stdio.h>
#include <stdint.h>
#include <BlynkSimpleSerialBLE.h>
#include <WTV020SD16P.h>
#include <SoftwareSerial.h>
#define extSpkr    A0 
#define intSpkr    A1
//#define BLYNK_PRINT Serial

char auth[] = "tbd";

int resetPin   = 4;
int clockPin   = 5;
int dataPin    = 6;
int busyPin    = 7;
int track;

//WTV020SD16P wtv020sd16p(resetPin, clockPin, dataPin, busyPin);
SoftwareSerial mySerial(8,9); // RX(8), TX(9) these pins must be for AltSoftSerial

void setup()
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  //Blynk.begin(SerialBLE, auth);
  pinMode(extSpkr, INPUT);
  pinMode(dogSpkr, INPUT);

void loop()
  char c;

  if (Serial.available())
    c = Serial.read();
  if (mySerial.available())
    c = mySerial.read();

I moved the instance declaration

WTV020SD16P wtv020sd16p(resetPin, clockPin, dataPin, busyPin);

...to within the brackets of setup(). Now it works. I am not really sure where I should instantiate: Before setup OR within setup????


As that library is badly written (most of the code in the constructor should be moved to a begin() method) you cannot instantiate the variable outside setup() or loop(). If you want to use the variable in setup() and loop() you must declare a pointer variable to it globally and instantiate it with the new operator.

Dear Shannon,

Can you show me the proper syntax for instantiating WTV020SD16P in setup() and then declaring a pointer variable to it globally?

Thank you.


WTV020SD16P *wtv020sd16p;

void setup() {
  wtv020sd16p = new WTV020SD16P(resetPin, clockPin, dataPin, busyPin);