Why is this serial connection not working?  - Page 1
Forum section: electronics / beginners

author: abdullahseba
author_rank: Frequent Contributor
timestamp: June 23, 2017, 02:38:07 am
content: HiI have simple circuit based on the Arduino that controls an LCD and a keypad. All it does is send what ever is pressed on the keypad over the serial port and receives from the serial port to the LCD.The circuit runs off 12V but the serial is 5v. When I connect a Bluetooth module to the circuit via a 12v to 5v DC-DC converter it works fine I can receive and send on my PC and phone. But when I connect a USB to serial adapter including ground I can send but receive nothing.The TX LED flashes on the adapter so it gets the signal, but I get nothing on the terminal. When I connect the TX and RX together I get whats on the keypad on the LCD.Why does this not work with the adapter? Is it because they are power separately even tho ground is connected? If so how come I can send to it?Here is my code and circuit.Thanks in advance.Code:#include <LiquidCrystal.h>#include <Keypad.h>LiquidCrystal lcd(10, 9, 8, A5, A4, A3);//4x4 Matrix key padconst byte ROWS = 4; // Four rowsconst byte COLS = 4; // Four columns// Define the Keymapchar keys ={{'1', '2', '3', 's'},{'4', '5', '6', 'c'},{'7', '8', '9', 'e'},{'o', '0', 't', 'p'}};byte rowPins = { A1, A0, 7, 6 };byte colPins = { 5, 4, 3, 2 };// Create the KeypadKeypad kpd = Keypad( makeKeymap(keys), rowPins,colPins, ROWS, COLS );void setup(){Serial.begin(9600);lcd.begin(16, 2);lcd.print("Loading...");}void loop(){char key = kpd.getKey();lcd.setCursor(0, 0);Serial.setTimeout('1');while (Serial.available()) {lcd.clear();lcd.print(Serial.readString());}if (key){// digitalWrite(8, HIGH); // sets the LED on// delay(100); // waits for a second// digitalWrite(8, LOW); // sets the LED off//tone(21, 3000, 100);Serial.print(key);Serial.println ("");}}

author: welpester
author_rank: Contributor
timestamp: June 23, 2017, 04:22:06 am
content: This may be silly question, but i don't see any level converter in serial line?-welpester

author: sleemanj
author_rank: Super Contributor
timestamp: June 23, 2017, 05:29:32 am
content: Have you forgotten that TX -> RX and RX -> TX ?

author: mikerj
author_rank: Super Contributor
timestamp: June 23, 2017, 07:41:02 am
content: If you connect the Rx and Rx of the USB adapter, do you see the terminal correctly echo whatever you type?I'm assuming your USB/Serial adapter has TTL or LVTTL compatible outputs, i.e. you are using one without a built in line driver? The TTL/LVTTL types won't have a 9 way D connector, but the type with the line driver will and these can not be hooked up directly to a micro without using a second line driver.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: June 23, 2017, 11:31:18 am
content: Quote from: welpester on June 23, 2017, 04:22:06 amIts not using the full RS232 voltage, just 5V TTL.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: June 23, 2017, 11:33:18 am
content: Quote from: sleemanj on June 23, 2017, 05:29:32 amNo, I can talk to it it bunt not receive on the PC end, yet the LED flashes both ways and Bluetooth module works fine.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: June 23, 2017, 11:36:14 am
content: Quote from: mikerj on June 23, 2017, 07:41:02 amYes it works fine I tried echoing and a few other things. I even tried connecting it to my Omega2 and again I could only send.And yes its a UART adapter not full RS232.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: June 23, 2017, 01:18:45 pm
content: I dont know if this is supposed to be but both TX and RX have 5V continuously when measured with multimeter.Update: This is super annoying... If I connect it to the arduino TX and RX pins its works fine.

author: alm
author_rank: Super Contributor
timestamp: June 24, 2017, 08:06:52 am
content: I wonder if this is a baud rate accuracy issue. One side has 9600 baud +3%, the other -3%, and you have unreliable / no comms. Most likely when either using a low quality clock source (ceramic resonator or RC oscillator), or if the available division ratio the UART offers is poor (the ATmega datasheet has a table).If possible, try measuring the frequency of a continuous stream of UUUUU with a frequency counter, logic analyzer or scope from both sides.

author: abdullahseba
author_rank: Frequent Contributor
timestamp: June 24, 2017, 08:40:41 am
content: Quote from: alm on June 24, 2017, 08:06:52 amI'll try that, I think my multimeter has a counter function.The oscillator is just to 15pf and a 16MHz crystal form digikey.It also works fine with the Arduino USB2serial.

author: alm
author_rank: Super Contributor
timestamp: June 24, 2017, 08:57:28 am
content: An ATMega with a 16 MHz crystal should be pretty close at 9600 baud (see ATMega datasheet). It is more the other side I would suspect.