I'm troubleshooting an arduino nano that I want to use to communicate with another device using the 0 and 1 pins. I've already verified that the other device (a gsm module) is working correctly using a usb to ttl converter. When I connect this same converter to the nano with the simple test sketch uploaded below, I get the characters generated by the sketch printed back in the serial monitor correctly, but anything I send to it to have it echo back gets returned as backwards question marks.
So something like:
starting echo with count
1
2
⸮⸮3
⸮⸮⸮⸮⸮4
5
6
etc...
So the arduino seems to be transmitting correctly but not receiving correctly. This happens at every baud up to 9600. I didn't test any higher.
Does anyone have any ideas what could be causing this?
unsigned long timer;
unsigned long currentTime;
int count = 0;
char c;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("starting echo with count");
}
void loop() {
// put your main code here, to run repeatedly:
//should simply echo the commands
currentTime = millis();
if(Serial.available()){
c = Serial.read();
Serial.print(c);
}
if (currentTime - timer > 1000){
Serial.println(count);
timer = millis();
count++;
}
}`
You do know that println() appends the line ending characters…
if you send unwanted text to the GPS, there’s every chance the command will fail, or return nonsense.m
For clarity, I inserted a couple of words in this quote:
Refer to the schematic of the Nano. As you described it, the TX pin of the Nano is directly wired to the TX pin of the GSM module. This is not correct, and potentially will damage either the GSM or the Nano.
First, are you using a classic Nano, with an atmega328, or one of the over Arduino boards with Nano in the name (Nano Every, Nano 33 series, etc)?
The classic Nano already has a USB to serial converter connected to pins 0 and 1, with inline 1K ohm resistors. This allows you to safely connect another device to pins 0 and 1, while allowing the external device to override the TX line from the on-board USB to serial converter. If the USB to ttl converter that you are using has any resistance in-line with the signal lines that can cause problems.
Do you have a common ground connected between the USB to ttl converter and the Nano?
Upon connecting usb to ttl ground to arduino nano ground, the correct characters are returned. Thanks.
The gsm module can use either voltage, and that is selected via a V_MCU pin which I have connected to the 5V pin on the nano. I've actually reused the code on this project from another uno based project, changing from software serial to hardware serial on the nano, so I'm not sure what's wrong yet...
I've got the RX of the gsm module wired directly to the TX of the arduino nano. Same as I do with the usb to ttl I'm using for troubleshooting in this example. I don't have both simultaneously wired to the arduino.
Are you suggesting that I can have both a usb to ttl converter and a separate uart device hooked up to the same TX and RX pins for debugging? I thought that wasn't possible without extra hardware?
What specific problem are you having with the Nano/GSM? There does need to be a common ground between the two, and if you are using the serial monitor in the IDE you will only be able to see what the Arduino is transmitting, you will not be able to send anything from the serial monitor to the Arduino. Also, you will not be able to send debugging messages from the Arduino to the serial monitor, because those would also be sent to the GSM.
Alright, I finally had time to do some more troubleshooting. I uploaded a sketch for communicating through the nano. When I have the devices hooked up like this:
USB-TTL to hardware serial, GSM module to software serial it works as expected. However, when I reverse the hardware and software serial connections (GSM to hardware serial, USB-TTL to software serial), it does not work at all. Nothing is received in the serial monitor.
Is there something else with hardware serial I need to consider?
#include <SoftwareSerial.h>
#define softRX 2
#define softTX 7
#define pwr_en 9
SoftwareSerial softSerial(softRX, softTX);
void setup() {
// put your setup code here, to run once:
pinMode(pwr_en,OUTPUT);
digitalWrite(pwr_en,HIGH);
delay(3000);
digitalWrite(pwr_en,LOW);
delay(3000);
Serial.begin(9600);
softSerial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
delay(10);
softSerial.write(Serial.read());
}
if(softSerial.available()){
delay(10);
Serial.write(softSerial.read());
}
}
Do you own a pen, a piece of paper, and a camera that can provide an image of a hand-drawn schematic to show us your connections? I don't intend to try to decipher word salad, however simple you may think the connection is. See post #11.
Thank you in advance.
Why do you think you can connect another serial to the Nano serial? They're connected to the onboard USB serial chip. See the schematic Arduino has thoughtfully posted on their website for more details.
You can connect another device to the hardware Serial pins, because of the 1K ohm resistors between the USB-to-serial chip and the Nano. This prevents reception of anything from the USB-to-serial chip on the Nano (the external device's Tx line overrides the USB-to-serial chip's Tx), and both the USB-to-serial and the external device will receive anything sent by the Nano. Note that you will need to disconnect the Tx line from the external device in order to upload code to the Nano.
Before you open the serial monitor, are you changing Tools > Port in the IDE to the USB port for the USB-TTL device?
If for some reason you are trying to see what is transmitted from the GSM in the serial monitor, via the Nano's onboard USB-to-serial chip, that will not work. The Tx of the GSM is connected to the Rx of the Nano, and to the Tx of the USB-to-serial chip through the 1K resistor. The only thing you will see in the serial monitor is what is being sent from the Nano.