Nano v3 + JDY31 hw serial - Arduino not receiving

Dear All,
I use Bluetooth to change settings from mobile phone to a Nano controller. It works with SoftwareSerial for years without a problem. In the meantime I deployed my project to places where there is no knowledge or tools to upgrade the software via USB and I can't be everywhere so I thought I would create an own OTA upgrade (from mobile phone upgrade the Nano).

I want to keep the cost low and the BT module is already there so I was thinking

  • instead of SoftwareSerial I can use hardware serial
  • Resetting the board is not a problem as it has reset button on it
  • I could use a mobile app + STK500 protocol. The Arduino reset does not affect the connection between JDY31 and the mobile phone so the app is able to send 0x30 0x20 via the BT and if it gets answer it starts the update process, following the protocol.

At first I created a very basic setup and I already bumped to an issue. I wired up everything (see attachment), on the Nano I have the code above and using Bluetooth terminal software on my Android phone, I thought I can see some conversation back and forth. The communication Nano -> JDY31 -> Phone works, I can see the dots the Nano send (and everything else I tried) while the Nano cannot see the bytes sent from the phone (Serial.available never contains a byte, Serial.read() is always zero).

  • I don't have oscilloscope but I measured the voltage between JDY31 TXD and Nano RX0 with a good multimeter. It's constant 3.2V if no communication and it goes a littlebit lower if I send something from the phone. I evaluated this like in serial communication the idle state is HIGH and if there are more LOWs on the channel (e.g. communication is ongoing), the average voltage drops a little so that's why I think my wiring is fine.
  • I tried it with multiple JDY31 and multiple Nanos, to exclude hardware issue - no luck
  • Of course I don't use USB and to upload the code I removed the wires to RX0 and TX1 ports
char b;

void setup(){
    Serial.begin(9600);
    pinMode(LED_BUILTIN, OUTPUT);
    // To only indicate reset
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
}

void loop(){
    if(Serial.available()){
        b = (char)Serial.read();

        Serial.print(F("Got "));
        Serial.println(b, HEX);
    }else{
        Serial.print(F("."));
    }
    delay(1000);
}

I don't have a clue why the communication goes only one way. Is it a limitation in Nano so this setup never works? I have taken the idea from here (but it's an Uno, not Nano): GitHub - JayLooi/RemoteArduino: Remotely interface with Arduino Uno through ESP8266

Thank you.

A Nano doesn't work correctly with 5V on VIN.

The JDY31 must be powered by 3.3V, the absolute maximum rating is 3.6V. As you're providing 5V to it you may have damaged it already. I didn't find any information if the module is 5V tolerant on the serial pins.

Post a link to the datasheet of the module you're using. Maybe you use a module with a 5V->3.3V voltage regulator on board.

Hello,
thanks for replying. Indeed I forgot to mention, I'm using the breakout board version that tolerates between 3.6V - 6V. I bought it from Ali. I always use the breakout board and they never had an issue with 5V before. Also, if I change the cabling from RX0 and TX1 to A0 and D8 (this is what I use in my project in normal case) and use SoftwareSerial, the communication works back and forth. (But today I'll do another test with it. It's in a breadboard at the moment so it's very easy to change.)

UPDATE:
I tried it out with SoftwareSerial again, it works as expected. The new code is:

#include <SoftwareSerial.h>
char b;
SoftwareSerial btSerial(A0, 8); // RX, TX

void setup(){
    btSerial.begin(9600);
    pinMode(LED_BUILTIN, OUTPUT);
    // To only indicate reset
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
}

void loop(){
    if(btSerial.available()){
        b = (char)btSerial.read();

        btSerial.print(F("Got "));
        btSerial.println(b, HEX);
    }else{
        btSerial.print(F("."));
    }
    delay(1000);
}

The cables were amended accordingly: Nano D8 to voltage divider and finally to RXD at JDY31 breakout board and Nano A0 to TXD at JDY31 breakout board.

It tells me that both Nanov3 and JDY31 works and the voltage divider works, too and baudrate 9600 + default 8N1 terminal settings are OK.

Best regards,

Hello All,
a little update. I tried the original setup (as seen in my first post) but with a bi-directional logic level converter. The effect is quite the same when I measure with the multimeter. In normal case it shows 4.83V and if I start sending from my mobile (via BT Terminal app), temporarily the average drops to 4.78 - 4.80V. No RX led is lit and I don't get a byte at the Arduino side.
Honestly, I'm out of ideas.

You do know that your original code uses the hardware serial interface for the communication to the module and for debugging, don't you?

I'm not sure what do you mean by 'debugging'. I send some dots to the phone and I want to receive some data from the phone at the same time. The JDY-31 module is a 'serial tunnel', so I try to use it accordingly (for serial communication). Could you please give an example how do you mean using the serial interface to "only module communication"? Because that is my goal. I want to communicate with JDY-31, not debugging on USB at the same time (I don't have anything connected to USB).
Thank you,

Oh my God, I managed to solve this strange issue. The solution was to upload an optiboot boot loader from the Minicore version, because the original bootloader is buggy. After I replaced it, the communication started working two-way.
This is only the start of my project but I found the answer to my question. I hope someone else will benefit from it, too.

Please provide more details about where the original optiboot bootloader is buggy.

I wish I could give you more details but I don't have that deep knowledge. I bought a couple of Nano v3 clones, they worked fine but I could not use the hardware serial on pins TX0 and RX1 as I summarized in my first post. When I uploaded sketches to these Nanos, I had to select "ATM328p (Old bootloader)". Using a programmer, I replaced the boot loader from this repo. For me the only change was that I could not use "old bootloader" anymore, I used the other option (without "old bootloader"). After I replaced the bootloader and uploaded the same sketch again (maybe it wasn't necessary) the communication from the JDY31 dongle to RX1 was received by the Serial library (e.g. Serial.available() gave numbers greater than zero and Serial.read() started working).

How the old bootloader code looked like, I don't know - the Nano clones were shipped with that. Also I don't know what is the bootloader does with the Serial communication. Maybe if I'd take a look to the repo where I got the new Minicore bootloader, I could realize it but honestly, I'm satisfied with the fact it's working, I have a lot to do to finally achieve my goal (update sketch via Bluetooth via Android app) so I'm not going to dive deep into the details.

What does upload mean? Did you upload over the serial interface (USB) or always using the ICSP header?

It does initialize the serial hardware but the standard bootloader (optiboot) doesn't do anything the serial library of the IDE doesn't do.
Depending on the upload process you use (see above) the bootloader never runs anyway.

I uploaded via USB (and disconnected the TX0 RX1 while I did it). For the boot loader replacement I used a programmer via the ICSP header. When I had the new bootloader I uploaded the sketch via the ICSP (as it was connected so I thought why not to use). Do you think it is the reason for the difference? I can try to upload via USB again.

So you immediately overwrote it. Upload by programmer deletes a bootloader written before.

That's possible although I cannot see a reason for that at the moment. I can only imagine that other precompiler settings might influence the compiler output but given you used identical board settings and just used the upload by programmer instead of the standard upload, it doesn't make sense.

You must install a bootloader again, first.

Hello,

  1. I have installed the boot loader via asp programmer
  2. I disconnected the cables to RX-TX
  3. I uploaded my sketch
  4. I reconnected the cable
  5. The sketch works exactly as expected. Arduino receives the sent bytes from the phone and can send back feedback to the phone that the Bluetooth serial app shows.

I'm confident that the "old bootloader" had an effect to the serial communication somehow.
Thank you for the kind assistance.

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