I want to connect to the Serial while an USB cable is connected. I know ESP32 has 3 serial ports. On is used by USB while working on a script and the two others are expected to be free for device connectivity.
I'm not sure what pins to use for Serial1 and Serial2. The pinout cheat shows there is two pins D0/D1 which are expected to be RX0/TX0 thus used by USB.
Reading the Starter page, I see Serial1 is D0/D1 That's a bit surprising as I though it should be Serial. Actually, a script connecting to these pins with Serial1 object does not seems to work when the board is running with no USB cable. Nor with Serial object either.
I read here and there ESP-32 Serial GPIO should be 9-10 (respectively RX/TX) or 16-17. The Nano does not present GPIO 16, so I can't try this one. And I tried using 9-10 with Serial1 with no success.
Here is the initialization code used:
#define RX_PIN 9U // D6
#define TX_PIN 10U // D7
Serial.begin(9600); // Works with USB cable. Otherwise, fails
Serial1.begin(9600): // Fails on D0/D1 and D6/D7
Serial2.begin(9600); // Fails on D0/D1 and D6/D7
Serial.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); // Fails
Serial1.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); // Fails
Serial2.begin(9600, SERIAL_8N1, RX_PIN, TX_PIN); // Fails
I jsut can get a device to discuss with my Nano using Serial for now.
[...] two pins D0/D1 which are expected to be RX0/TX0 thus used by USB.
Actually, the "Serial over USB" device is internal to the CPU, so those pins can be connected to an actual physical UART if you desire. But on the ESP32 you can choose any digital pin to be used as RX or TX for the hardware UARTs.
#define RX_PIN 9U // D6
#define TX_PIN 10U // D7
That is probably the issue. As other Arduino platforms, on the Nano ESP32 pins are referenced by their "digital number" (not by GPIO index, as is common with other ESP32 implementations). Can you try simply with 6 for D6 and 7 for D7?
Yes, it's me again
I though everything worked fine, and it did... But I'm working at night and I was working on two boards: an Arduino Nano ESP32 and a Adafruit HUZZAH32 Feather. And I eventually mixed the two.
The Long Version:
My code and the given solution for the voltage divider worked fine with the Feather and at the time, I thanked you (and J.M.L) as It solved all my problems... But in the morning, I realized it was on the wrong board. No issue here: I just plug one out and placed the other one, check pins and cables (only GND to change and RX/TX) and... Everything went OK BUT the DFPlayer stuff.
I tried again several Serial setings with no luck. Setting back the pins for the Feather and the music plays.
<TL;DR>
9U and 10U are convientions I use when defining stuff to be sure the compiler will get I'm working on unsigned int for later convertion to uint_8. Not a point, I suppose as I had no issue with that for the time I code on Arduino (but, I tried without U and declaring const byte as you suggest, for the Honor and to be sure. I'm never sure of anything for the years I code...)
The code you gave uses ports 16 and 17 but I can't find them on the Nano ESP32.
And yes, I read here and there that any GPIO can be used. And I tried several for sure, but no success. I go back to the root from a post on StackOverflow (arduino - ESP32 - SoftwareSerial Library - Stack Overflow) that seems to know what it talks about. But hey: no success anyway.
At last, My all setup (IR detection, a reed switch, a keypad, a buzzer... A digicode ) works fine with the same code for Huzzah and NanoESP32... But the Huzzah is able to play music where the NanoESP32 does not due to that Serial issue I can't spot.
Thanks for the point. But that is not the case. There is many names for the pins on the board; their little name (Dx/Ax) that can be declared in a .h file regarding your IDE settings and the actual name for the MCU (GPIOx).
For instance, if you use a "generic ESP32", you can see that: (pins_arduino.h)
Here, you have the names and the actual GPIO number. And because the names are dictate by a piece of code, it may be wrong or inconsistent with you actual board and IDE.
This is why I prefer to use GPIO numbers I'm sure of.
And I also sure I'm not wrong in that case: I have four other devices attached to my board and they all respond correctly to the port/pin I assigned them to.
Note I tried the 6 and 7 as you propsed. With no success any
I leave for few days. The world will change by when I'm back online.
I work with PlatformIO which has a very light support for the NanoESP32 and I'm struggling with it (I suppose ArduinoIDE works fine, but I'm not happy with that IDE). For instance, I have to use an other ESP profile for having the board uploading a script, It changes dynamically its com port, I have to manually reset the board for it to run the new script and manually restart the serial monitor, missing all the setup debug stuff...
Eventually, I use a ledstrip for debugging that part
In few weeks I suppose the PlatformIO support for the board will me better. And maybe some new tutorials will be available regarding the serials
They're showing Serial1 in an example where it's all set up to use 0 and 1. Importantly, Serial is still SerialMonitor (like the Leonardo and so on).
Even though I have my Nano32's, I haven't checked to see if they can be configured with the rx/tx assigned to other 'pins'.
Thanks for the check.
That's the first attempt I made, using Serial1 on D0/D1. But no success.
That's why I read more and found the expected other pins.
Hi!
I'm vert happy that works. Well. I'm scratching my head. I known this sketch and I tried it.
I'm away from home, thinking of my life and that circuit... I'll try again when back.
Ok. The DF is powered by the Nano board, Hence you don't need voltage divider. Good. On my side, I notice I've got poor sound when not on 5V. Not an issue.
I'm now considering changing my Dupont cables and breadboard.... Because nothing looks different between your schème and mine. #Arg
Thanks anyway for the confirmation it would work!
More news in few weeks.
Bests regards