sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

How to connect RPI to TTL micro-controller without USB convertor

Sat Apr 21, 2018 12:48 pm

Hi All,
I have a micro-controller with TTL 3.3v pins. I want RPI to control it. However, I have no idea how to achieve this. Here is the details.I searched a lot via google. I saw all use RPI 3 for tutorials and they all talking about USB-TTL, but situation for mine is TTL-TTL without any converter I think.
1. Raspberry Pi B , OS:raspbian squeeze. I turned off the tty console via rasp-config. Power with USB.
2. UHF RFID controller, with 4 pins, vcc, gnd, tx, rx. (3.3v). Power with USB.
I connected GND-GND, TX-RX, RX-TX. Only 3 lines being used to connect each other.
My question:
1. Am I right to connect them as that?
2. I didn't see any /dev/ttyS* was created or any other new port was created. I saw /dev/ttyAMA0 exists in my RPI B although all internet articles are talking about RPI 3 will have that port. And I tried to use minicom on that port and showed me 'offline'. Am I correct for the testing? How can I ensure the micro-controller has been detected by my RPI?(I tried dmesg | grep tty or grep uart, all shows me same message and no diff before and after I connect TTL)
3. Any suggestion for what I do?
Thank you all.

drgeoff
Posts: 10829
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sat Apr 21, 2018 2:21 pm

1. dmesg and similar will never show when something has been connected or disconnected from a UART.

2. Disconnect the other item and connect together the Tx and Rx pins of the RPi. Until you get a terminal echoing back through that loop what you type, it is pointless going further.
Quis custodiet ipsos custodes?

sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sat Apr 21, 2018 3:47 pm

drgeoff wrote:
Sat Apr 21, 2018 2:21 pm
1. dmesg and similar will never show when something has been connected or disconnected from a UART.

2. Disconnect the other item and connect together the Tx and Rx pins of the RPi. Until you get a terminal echoing back through that loop what you type, it is pointless going further.
Thanks for help.
I did below steps.
1. Disconnect all peripherals from my RPi and boot. Wired TX to RX of RPi.
2. Issue below commands to test if echo backing from the loop.
terminal 1 : read X < /dev/ttyAMA0
terminal 2 : echo "hello" > /dev/ttyAMA0

However, my terminal 1 keep reading.

Tried programming way still no lucky -- wrote without any echo from read.
File : read.py

Code: Select all

#!/usr/bin/env python
import serial
with serial.Serial('/dev/ttyAMA0',timeout=10) as ser:
    line = ser.readline()
    print(line)
File : write.py

Code: Select all

#!/usr/bin/env python
import serial
ser = serial.Serial('/dev/ttyAMA0')
ser.write(b'hello\n')
ser.close()

Does it mean my RPi have issue with TX or RX pins(I have two RPis and got same failed result)? Or my test steps are wrong? Tks.
Last edited by sowhong on Sun Apr 22, 2018 11:31 am, edited 1 time in total.

User avatar
thagrol
Posts: 3178
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: How to connect RPI to TTL micro-controller without USB convertor

Sat Apr 21, 2018 6:18 pm

drgeoff wrote:
Sat Apr 21, 2018 2:21 pm
1. dmesg and similar will never show when something has been connected or disconnected from a UART.

2. Disconnect the other item and connect together the Tx and Rx pins of the RPi. Until you get a terminal echoing back through that loop what you type, it is pointless going further.
You need to connect grounds too
Arguing with strangers on the internet since 1993.

drgeoff
Posts: 10829
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sat Apr 21, 2018 8:22 pm

thagrol wrote:
Sat Apr 21, 2018 6:18 pm
drgeoff wrote:
Sat Apr 21, 2018 2:21 pm
1. dmesg and similar will never show when something has been connected or disconnected from a UART.

2. Disconnect the other item and connect together the Tx and Rx pins of the RPi. Until you get a terminal echoing back through that loop what you type, it is pointless going further.
You need to connect grounds too
No you don't. These are the Tx and Rx pins on a single RPi.
Quis custodiet ipsos custodes?

drgeoff
Posts: 10829
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sat Apr 21, 2018 8:23 pm

sowhong wrote:
Sat Apr 21, 2018 3:47 pm
drgeoff wrote:
Sat Apr 21, 2018 2:21 pm
1. dmesg and similar will never show when something has been connected or disconnected from a UART.

2. Disconnect the other item and connect together the Tx and Rx pins of the RPi. Until you get a terminal echoing back through that loop what you type, it is pointless going further.
Thanks for help.
I did below steps.
1. Disconnect all peripherals from my RPi and boot. Wired TX to RX of RPi.
2. Issue below commands to test if echo backing from the loop.
terminal 1 : read X < /dev/ttyAMA0
terminal 2 : echo "hello" > /dev/ttyAMA0
Use only one terminal program.
Quis custodiet ipsos custodes?

sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sun Apr 22, 2018 11:30 am

drgeoff wrote:
Sat Apr 21, 2018 8:23 pm
sowhong wrote:
Sat Apr 21, 2018 3:47 pm
drgeoff wrote:
Sat Apr 21, 2018 2:21 pm
1. dmesg and similar will never show when something has been connected or disconnected from a UART.

2. Disconnect the other item and connect together the Tx and Rx pins of the RPi. Until you get a terminal echoing back through that loop what you type, it is pointless going further.
Thanks for help.
I did below steps.
1. Disconnect all peripherals from my RPi and boot. Wired TX to RX of RPi.
2. Issue below commands to test if echo backing from the loop.
terminal 1 : read X < /dev/ttyAMA0
terminal 2 : echo "hello" > /dev/ttyAMA0
Use only one terminal program.
test with echo & read got blank line for read X variable

Code: Select all

root@raspberrypi:/home/pi#  echo "hello" > /dev/ttyAMA0
root@raspberrypi:/home/pi# read X < /dev/ttyAMA0 
root@raspberrypi:/home/pi# echo $X

root@raspberrypi:/home/pi#
with python script above the read.py will pending reading.
but with below test.py will get result : Received incorrect data b'' over Serial port /dev/ttyAMA0 loopback

Code: Select all

#!/usr/bin/env python3

from __future__ import print_function
import serial

test_string = "Testing 1 2 3 4".encode('utf-8')
#test_string = b"Testing 1 2 3 4" ### Will also work

port_list = ["/dev/serial0", "/dev/ttyAMA0"]

for port in port_list:

    try:
        serialPort = serial.Serial(port, 115200, timeout = 2)
        serialPort.flushOutput()
        serialPort.flushInput() # Syntax may change in new version of python3-serial
        print("Opened port", port, "for testing:")
        bytes_sent = serialPort.write(test_string)
        print ("Sent", bytes_sent, "bytes")
        loopback = serialPort.read(bytes_sent)
        if loopback == test_string:
            print ("Received", len(loopback), "valid bytes, Serial port", port, "working \n")
        else:
            print ("Received incorrect data", loopback, "over Serial port", port, "loopback\n")
        serialPort.close()
    except:
        #except IOError:
        print ("Failed at", port, "\n")

sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sun Apr 22, 2018 6:01 pm

Tried thread viewtopic.php?t=56576 got http://www.raspberry-projects.com/pi/pr ... g-the-uart and http://www.raspberry-projects.com/pi/pi ... /uart-pins

I did a lsof /dev/ttyAMA0. minicom can attach it. so ttyAMA0 should be released from raspbian system. It just not working for either loop back test or micro controller test( I am sure micro controller is well as I tested via usb - ttl in these 2 RPis).

I suspected something wrong in my raspbian system for config RPI B(although I tried jessie & stretch in my two same RPis without any lucky, too ).

Code: Select all

uname -a
Linux raspberrypi 3.18.11+ #781 PREEMPT Tue Apr 21 18:02:18 BST 2015 armv6l GNU/Linux

cat /etc/*release*
PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
NAME="Raspbian GNU/Linux"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=raspbian
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
PRETTY_NAME="Debian #OSNAME# 7 (wheezy)"
NAME="Debian #OSNAME#"
VERSION_ID="7"
VERSION="7 (wheezy)"
ID=debian
ANSI_COLOR="1;31"
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support/"
BUG_REPORT_URL="http://bugs.debian.org/"

drgeoff
Posts: 10829
Joined: Wed Jan 25, 2012 6:39 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sun Apr 22, 2018 6:08 pm

Section "Using minicom on the UART" at http://www.raspberry-projects.com/pi/pr ... g-the-uart

Does that work for you?
Quis custodiet ipsos custodes?

sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sun Apr 22, 2018 8:23 pm

drgeoff wrote:
Sun Apr 22, 2018 6:08 pm
Section "Using minicom on the UART" at http://www.raspberry-projects.com/pi/pr ... g-the-uart

Does that work for you?
Nope, minicom always hang can't type anything. I even tried low baud rate 9600, still not working. If I use echo or python serial script I can write something to /ttyAMA0 at least just can't read or read wrong result. Seems my RPi RX is broken, however, I tried another same RPi same results with same SD-CARD. My RPi is Raspberry Pi B quite old, Lol.

Oh, the RPi have 26 pins for GPIO. I suppose the printout here https://pinout.xyz/ indicated pin 6, 8, 10 is correct for my case?

sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Sun Apr 22, 2018 8:34 pm

hmm...http://www.raspberry-projects.com/pi/pi ... -b-io-pins seems my connection has no issue. Don't know what happened.

sowhong
Posts: 7
Joined: Sat Apr 21, 2018 12:30 pm

Re: How to connect RPI to TTL micro-controller without USB convertor

Mon Apr 23, 2018 2:38 am

hmm... got it.
Thanks @drgeoff
The step http://www.raspberry-projects.com/pi/pi ... /uart-pins and minicom test is correct way to setup UART and test loop back. Just echo won't work for me and minicom works.

I was unlucky one RPi failed because RX short out with other pins on the board. So GPIO damaged.
And other RPi, always got failed result is because bad contact of RX line!!!! Now it works.

Thank you all!

Return to “General discussion”