Using Nano in place of Uno

The included code works ok (plays the files on the SD card) when I connect the DFRobotDFPlayer to a UNO but will not work when I connect the player to a Nano.
I am using the same pin designations on the Uno and the Nano.
Obviously I have either missed something or there is a subtle difference between the Nano and the Uno that I am not aware of.
Hope someone can help me.
The code uploads without any problems.

/*
The sound effects were recorded from YouTube videos using Audacity.
My sketch plays old time radio music, looping until a trigger event, 
from a switch or motion sensor that starts the sequence.
Music continues for a while, then white and blue LED's flicker to simulate arc welding, 
and the arc welding sound file plays for a random time.
When the welding stops, the red LED comes on and fades to simulate the hot metal 
afterglow, no sound. This time is enough for the welder to pick up his hammer.
Next the slag chipping sound file plays, stops, and plays again.
Then the wire brush sound file plays to simulate cleaning up the slag, and stops.
After time enough for the guy to put down the wire brush and pick up the grinder, 
the 2 yellow LED's start to flicker grinder sparks, 
and the grinder sound file plays for a random time.
The whole sequence repeats once more, then stops, and everything goes silent.
After a short time, the old time radio music starts playing again, 
and loops until the next trigger event.
Script for Full Featured Welding Simulator w/Sound:
MP3 File 5 for 41 seconds of old time radio music after trigger event
Welding (white and blue leds flashing with MP3 File 1 welding sounds)
Hot Metal Afterglow (red led fading no sound)
MP3 File 2 slag chipping 2 times
MP3 File 3 wire brushing 1 time
Grinding the weld smooth (2 yellow leds flashing with MP3 File 4 grinding sounds)
XX seconds after cycles is shutdown, the MP3 File 5 loops 41 seconds until next trigger

Interrupt driven sensor should only play on a RISING edge single. 
I.E, when a light sensor is covered.
Adapted from code by Ben (thewag on Trainboard) pieced together from multiple sources,
including Toms Trains and Things, original idea by fernpoint on Model Railroad Hobbiest, 
and suggestions from Marc, an actual career professional welder. Thanks to you all!
Last Modified 04/27/2020, needs comments for each line so I can understand 
what is happening
*/

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
//Digital Pins
int TRIGGER = 2; // Interrupt 0 -- Sensor
int RLED = 3; // 330 Ohm / Red LED for slag glow on pin D3 PWM
int BLED = 4; // 330 Ohm / Blue LED for arc strike on pin D4
int WLED = 5; // 330 Ohm / White LED for welder flash on pin D5
int ALED = 6; // 330 Ohm / Amber LED for grinder sparks on pin D6
int YLED = 7; // 330 Ohm / Yellow LED for grinder sparks on pin D7
int PLAYER_RX = 10; // Player Receive pin D10.
int PLAYER_TX = 11; // Player Transmit pin D11.
int PLAYER_BUSY = 12; // MP3 player status pin. LOW means busy playing.
int RUN = 0; // Running status                                                                                  
int CYCLE_COUNT = 2; // Cycles to run the welder per trigger event
int SHUTDOWN_SOUND_TRACK_NUMBER = 5;
SoftwareSerial mySoftwareSerial(PLAYER_RX, PLAYER_TX);
DFRobotDFPlayerMini MP3;

void setup() {
attachInterrupt(digitalPinToInterrupt(TRIGGER), sensorTiggered, RISING); //May be RISING, FALLING, or CHANGE
pinMode (PLAYER_BUSY, INPUT);
pinMode (WLED, OUTPUT);
pinMode (BLED, OUTPUT);
pinMode (RLED, OUTPUT);
pinMode (ALED, OUTPUT);
pinMode (YLED, OUTPUT);
//test flash RLED
digitalWrite(RLED, HIGH);
delay(500);
digitalWrite(RLED, LOW);

mySoftwareSerial.begin(9600);
//see if Player begins
if (!MP3.begin(mySoftwareSerial, true, true)){
  // flash white LED if MP3 not started
  digitalWrite(WLED, HIGH);
  delay(500);
  digitalWrite(WLED, LOW);
  delay(500);
  digitalWrite(WLED, HIGH);
  delay(500);
  digitalWrite(WLED, LOW);
} else{   //flash blue LED if MP3 started
  digitalWrite(BLED, HIGH);
  delay(500);
  digitalWrite(BLED, LOW);
  delay(500);
  digitalWrite(BLED, HIGH);
  delay(500);
  digitalWrite(BLED, LOW);
}

//MP3.begin(mySoftwareSerial);
MP3.setTimeOut(500);
MP3.volume(25);
MP3.EQ(DFPLAYER_EQ_BASS);
MP3.outputDevice(DFPLAYER_DEVICE_SD);
}

void loop() {
MP3.play(5);
delay(10000);
// Test condition again to start the weld procedure
if (RUN) {
for (int x = 1; x <= CYCLE_COUNT; x++) {
welder(); // White/Blue flicker and MP3 track 1
afterglow(); // Red weld afterglow 2 to 3 seconds, no sound
grinder();
}
}
RUN = 0; //After CycleCount reaches limit
shut_down(); //Sets all LED's off
}

void sensorTiggered()
{
RUN = 1;
}

void welder() {
delay(3000);
MP3.play(1); // Random White/Blue flashing with track 1 playing
int cycle = random(80, 160); // Randomly sets the cycle time of the LEDs
for (int i = 0; i < cycle; i++)
{
delay(1000);  //allow sound to start same as leds
digitalWrite(WLED, HIGH);
delay(random(10));
digitalWrite(WLED, LOW);
delay(random(200));
digitalWrite(BLED, HIGH);
delay(random(10));
digitalWrite(BLED, LOW);
delay(random(100));
if (digitalRead(PLAYER_BUSY) == HIGH) { // HIGH not playing
MP3.play(1); // Restart if sound has stopped
}
}
MP3.stop();
}

void afterglow() { // Weld afterglow starts after weld stops and then dims no sound
for (int j = 80; j > 1; j--) { // Variable int=j sets afterglow intensity, j > 1 sets ending glow, j-- decreases intensity
analogWrite(RLED, j); // Sets RLED to current value of j
delay(80); // Sets delay between each RLED intensity decrease
}
}

void grinder() {
MP3.play(2);
delay(5000);
MP3.play(2);
delay(2000);
MP3.play(3);
delay(12000);
MP3.play(4);
// Randomly sets the cycle time of the LEDs
int cycle = random(100, 200);
for (int i = 0; i < cycle; i++)
{
digitalWrite(ALED, HIGH);
delay(random(20));
digitalWrite(ALED, LOW);
delay(random(200));
digitalWrite(YLED, HIGH);
delay(random(10));
digitalWrite(YLED, LOW);
delay(random(100));
if (digitalRead(PLAYER_BUSY) == HIGH) { // HIGH not playing
// Restart if sound has stopped
MP3.play(4);
}
}
MP3.stop();
}

void shut_down() {
// Turn off all LEDs
digitalWrite(WLED, LOW);
digitalWrite(BLED, LOW);
digitalWrite(RLED, LOW);
digitalWrite(ALED, LOW);
digitalWrite(YLED, LOW);
}

Hello johnhb

Check wiring first.

My first thought would be power. How do you power your setup?

2 Likes

Thanks Paul. The wiring is ok. I have been trying to solve this problem for a week now. Tried two Nano units and have tripled checked the wiring.

Thanks sterretje. The Uno is powered via the DC barrel. Using the Uno the code works fine.
The Nano is powered from the Uno 5v supply connected to the 5v pin. The RLED (test flash RLED in setup) flashes as does the WLED and BLED (white and blue leds), but nothing after that.

Not a good idea.

This is because all the power is passing through the internal regulators of the Arduino, and these are of limited capacity. They will get hot and maybe even burn out.

Better to use a proper 5V regulated supply for your Nano, especially if you need to draw more than a few mA from the Nano.

It is notoriously hard to find your own wiring mistakes.

Essentially an Arduino and Nano are exactly the same processor.

2 Likes

OK, connected separate 5v power supply to the Nano and DFPlayer. Just the same problem as before.
I have re-examined the wiring over several days. I understand that it can be difficult to find one's mistake but I have removed all the jumper wires and reconnected them many times. Also made sure, with continuity test, that each jumper wire di not have an open circuit.

And I assume these two power supplies have a common ground to the Arduino.

We can only know what you tell us and sadly at the moment you are not telling us anything useful to allow us to help you. We need to see a schematic of how you are wiring things up, along with a clear photograph that shows where each wire goes where.

I wish I had $1 for every poster who insisted their wiring was correct, only to find out it wasn't. I would be very rich by now.

1 Like

As Mike says:

OK, point taken. I will draw up a schematic and upload a couple of photos.

1 Like

Hi Grumpy_Mike. Here is a schematic of the wiring of the Uno to the DFPlayer and the Nano to the DFPlayer. I would have included a photo but I have removed the Leds to use them elsewhere temporarily. All connections from the Uno to DFPlayer and Nano to DFPlayer are done on a breadboard.
ArcWelder Pinout.pdf (191.2 KB)

Here is a simpler code. You can try this instead:

#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

int PLAYER_RX = 10;
int PLAYER_TX = 11;

SoftwareSerial mySoftwareSerial(PLAYER_RX, PLAYER_TX);
DFRobotDFPlayerMini MP3;

void setup() {
  mySoftwareSerial.begin(9600);
  Serial.begin(9600);
  if (!MP3.begin(mySoftwareSerial, true, true)) {
    Serial.println("DFPlayer Mini not detected.");
    while (true);
  } else {
    Serial.println("DFPlayer Mini detected.");
  }
  MP3.setTimeOut(500);
  MP3.volume(25);
  MP3.EQ(DFPLAYER_EQ_BASS);
  MP3.outputDevice(DFPLAYER_DEVICE_SD);
}

void loop() {
  MP3.play(1); // Play the first track
  delay(10000); // Wait for 10 seconds
}

No it is not! It is a physical layout diagram.
It doesn't help at all, there is so much missing.

Just to verify, you do have headers soldered onto the nano's?
Did the nano's come with headers, or did you solder them on yourself?

Grumpy_Mike. The diagram I attached is the way the Uno to Player is connected and also the Nano to Player is connected. I don't have any other schematics. All connections are done with wire links on breadboard, I will include photos of both arrangements.

1 Like

I have soldered headers to the Nano so I can plug in to the breadboard. I have done continuity checks from header pins to Nano.

1 Like

Then sorry I can't help.

Thanks aliarifat794, I will give that try to see if it works on both the Uno and Nano.

To me it sure looks like you have your TX RX wires wrongways. Swap them at the Nano side.
RX is 10 and TX is 11. TX should go to the Player's 'rx' (the resistor) - and RX should go to the Player's 'tx'.

image

1 Like

For reference:


To me it looks like the resistor and wire are in different rows (36 vs 37):