Author Topic: Why is this serial connection not working?  (Read 2449 times)

0 Members and 1 Guest are viewing this topic.

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Why is this serial connection not working?
« on: June 23, 2017, 02:38:07 am »
Hi
I 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: [Select]
#include <LiquidCrystal.h>

#include <Keypad.h>

LiquidCrystal lcd(10, 9, 8, A5, A4, A3);

//4x4 Matrix key pad
const byte ROWS = 4; // Four rows

const byte COLS = 4; // Four columns

// Define the Keymap

char keys[ROWS][COLS] =

{


  {'1', '2', '3', 's'},


  {'4', '5', '6', 'c'},
 

  {'7', '8', '9', 'e'},
 

  {'o', '0', 't', 'p'}

};

byte rowPins[ROWS] = { A1, A0, 7, 6 };

byte colPins[COLS] = { 5, 4, 3, 2 };

// Create the Keypad

Keypad 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 ("");
  }
}


This is my right hand this is my wrong hand
 

Offline welpester

  • Contributor
  • Posts: 37
  • Country: fi
Re: Why is this serial connection not working?
« Reply #1 on: June 23, 2017, 04:22:06 am »
This may be silly question, but i don't see any level converter in serial line?

-welpester
Signature goes here!
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Why is this serial connection not working?
« Reply #2 on: June 23, 2017, 05:29:32 am »
Have you forgotten that TX -> RX and RX -> TX ?
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Online mikerj

  • Super Contributor
  • ***
  • Posts: 3238
  • Country: gb
Re: Why is this serial connection not working?
« Reply #3 on: June 23, 2017, 07:41:02 am »
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.
« Last Edit: June 23, 2017, 07:43:45 am by mikerj »
 

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: Why is this serial connection not working?
« Reply #4 on: June 23, 2017, 11:31:18 am »
This may be silly question, but i don't see any level converter in serial line?
Its not using the full RS232 voltage, just 5V TTL.
This is my right hand this is my wrong hand
 

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: Why is this serial connection not working?
« Reply #5 on: June 23, 2017, 11:33:18 am »
Have you forgotten that TX -> RX and RX -> TX ?
No, I can talk to it it bunt not receive on the PC end, yet the LED flashes both ways and Bluetooth module works fine.
This is my right hand this is my wrong hand
 

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: Why is this serial connection not working?
« Reply #6 on: June 23, 2017, 11:36:14 am »
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.
Yes 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.
This is my right hand this is my wrong hand
 

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: Why is this serial connection not working?
« Reply #7 on: June 23, 2017, 01:18:45 pm »
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. |O |O |O |O |O |O
« Last Edit: June 23, 2017, 01:28:41 pm by abdullahseba »
This is my right hand this is my wrong hand
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2862
  • Country: 00
Re: Why is this serial connection not working?
« Reply #8 on: June 24, 2017, 08:06:52 am »
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.
 
The following users thanked this post: abdullahseba

Offline abdullahsebaTopic starter

  • Frequent Contributor
  • **
  • Posts: 335
  • Country: gb
Re: Why is this serial connection not working?
« Reply #9 on: June 24, 2017, 08:40:41 am »
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.
I'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.
This is my right hand this is my wrong hand
 

Offline alm

  • Super Contributor
  • ***
  • Posts: 2862
  • Country: 00
Re: Why is this serial connection not working?
« Reply #10 on: June 24, 2017, 08:57:28 am »
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.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf