Software serial not working when most other pins connected

I often use Arduino Nanos with a DF Robot DFR0299 MP3 player, using software serial as the control signal between the Nano and the DFR0299. I have done this literally hundreds of times with one board design, and all is fine. I have another board design which uses the same connections for the DFR (Digital pin 10 for Transmit, 11 for receive, 1K resistor between the TX and RX pin on the DFR), but one that has all of the other pins used for inputs or outputs (with jumpers on D0 and D1 to allow USB programming), including all the analogue pins.

Now, the issue I've got is the arduino won't talk to the DFR using software serial when all of these other pins have connections to them (all the digital pins have mosfets on them to drive LED's). Anyone any idea why this might be? I've checked all the connections over and over again, and built the board twice, and I definitely haven't made a wiring mistake, and the DFR plays if you short the AD key 1 to ground, so that is working and reading the sd card.

Do you think it might help if you posted a schematic of your project and the sketch that does not work

What exactly do you mean by this

Software serial makes fairly heavy use of interrupts, if your other code interferes with that then you will have problems.

Working Schematic

Non Working Schematic

On the non working version, every input/output is as per this

(I haven't uploaded the whole schematic as it's quite big and not a lot of it is relevant).

I found in the past if you have something connected to D0/D1 when trying to upload a sketch, it fails. So, I put a jumper on the pins so they can be used as outputs after the sketch is uploaded. In this particular case, D0 and D1 aren't connected as the jumper is open.

The program doesn't get past the check if it can talk to the DFR. Here is the code

#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"

SoftwareSerial mySoftwareSerial(11, 10); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

const int vrin=A0;
const int Power1 = 13;
const int Power2 = 12;
const int Power3 = 9;
const int Power4 = 8;
const int Power5 = 7;
const int Switch1 = A1;
const int Switch2 = A2;
const int Switch3 = A3;
const int Switch4 = A4;
const int Switch5 = A5;
const int busyPin = A7;


unsigned long start;
int vread = 0;
int vin = 0;
int vcurrent = 0;
int buttonstate1 = 0;
int buttonstate2 = 0;
int buttonstate3 = 0;
int buttonstate4 = 0;
int buttonstate5 = 0;
int busyState=0;

unsigned long ledstart1;
unsigned long ledelapsed1;
unsigned long ledstart2;
unsigned long ledelapsed2;
unsigned long ledstart3;
unsigned long ledelapsed3;
unsigned long ledstart4;
unsigned long ledelapsed4;
unsigned long ledstart5;
unsigned long ledelapsed5;

void setup() {
  pinMode(Power1, OUTPUT);
  digitalWrite(Power1, LOW); // LED 1 - Rocker Switch - Pink Diffuser - S2 4T46 - cable 600mm - 2.2k Pullup
  pinMode(Power2, OUTPUT);
  digitalWrite(Power2, LOW); // LED 2 - Push Switch - Blue Diffuser - S2 7T1F - cable 450mm - 2.2k Pullup
  pinMode(Power3, OUTPUT);
  digitalWrite(Power3, LOW); // LED 3 - Hall Effect - Orange Diffuser  - S2 3T17 - cable 300 mm - 10K pullup
  pinMode(Power4, OUTPUT);
  digitalWrite(Power4, LOW); // LED 4 - Push button 2 - Citrus Yellow Diffuser - S2 2T07 - cable 150mm - 2.2k pullup
  pinMode(Power5, OUTPUT);
  digitalWrite(Power5, LOW); // LED 5 - Toggle Switch - Red Diffuser - S2 3T17 - cable 150mm - 2.2k Pullup (Was pull cord)
  pinMode(busyPin,INPUT_PULLUP);

  pinMode(Switch1, INPUT); 
  pinMode(Switch2, INPUT); 
  pinMode(Switch3, INPUT); 
  pinMode(Switch4, INPUT); 
  pinMode(Switch5, INPUT);

  vread=analogRead(vrin);
  vcurrent=((vread*15)/1015)+15;

mySoftwareSerial.begin(9600);
Serial.begin(9600);
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));
  Serial.println(myDFPlayer.readFileCounts()); //read all file counts in SD card
  myDFPlayer.volume(vcurrent);
}

That should come as no surprise, because pins 0 and 1 are used by the hardware Serial interface of the Nano which in turn is used to upload sketches

Indeed. Hence the jumpers on it. In this particular case, I haven't bridged the jumpers, because I only need 5 outputs, but the board is designed for up to 12. If I need all 12, I'll need to change the program so it doesn't have any serial output, just software serial.

Is your power source sufficient for the MP3 player and all the LEDs?

Yes, there is a 1A regulator which supplies the DFR and gives the logic voltage for the switches, the MOSFET controlled LEDs are all powered by 12V, as is the Nano. The DFR has a max output of 3W, so 5W should more than cover it (and does normally, on the board that works fine I run both the Nano and DFR from an external 1A 5V regulator).

Edit: Also, I can get the DFR to trigger and play a sound, by grounding one of the pins. It just won't talk to the Nano.

What does the compiler show for memory usage?

Sketch uses 6206 bytes (20%) of program storage space. Maximum is 30720 bytes.
Global variables use 449 bytes (21%) of dynamic memory, leaving 1599 bytes for local variables. Maximum is 2048 bytes.

So... @david_2018 mentioned about interrupts. I checked which pins the Nano used for interrupts (D2 and D3), found that whilst I had mosfets connected to those pins (via resistors, of course), they weren't actually then doing anything on this application, so removed the resistor, and hey presto, suddenly it will talk to the DFR.

Certainly a step in the right direction. However, now 2 of the outputs don't illuminate and it completely ignores all of the inputs....

So. I think, "Hey, what if I swap out the two suddenly not working outputs for two spare outputs, and remove those resistors too"...... And it worked!!

So. TLDR, if you are trying to use software serial (on pins 10 and 11), you CANNOT have anything connected to pins 2,3,9 and 12.

As the problem is solved, I only skimmed the thread, so maybe I’ve misunderstood. But that general warning surely cannot be right? I’m certain I’ve used one or more of those pins in my many DFR Player projects, as well as 10/11 for Rx/Tx.

Pin D12 may or may not be relevant tbh, I’ve later realised that I do have that one connected to the busy pin on the dfr299 on other projects. But pin 9 I’m sure is an issue, as the led I had connected as an indicator on that output always had a low glow to it, suggesting it is doing something. I don’t know if I had simply disconnected pin 9 whether pin 12 would have then worked ok, but whilst pin 9 was not floating, pin 12 would not output.

Edit: also, as above if I uploaded a sketch which didn’t use software serial, all inputs and outputs worked perfectly with what was originally connected.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.