Check the '/boot/config.txt' file for UART commands with:
This command should return one line: "enable_uart=1"
If it returns more then one line, or returns any other UART commands, or returns a line with spaces in the command, use a text editor to comment out or delete these commands. '/boot/config.txt' should contain just one instance of "enable_uart=1" (note no spaces) to get the Serial Port working on all Pi models.
Use a text editor to examine the '/boot/cmdline.txt' file. If you find an entry "console=ttyAMA0,115200" or "console=serial0,115200", remove them. Be carefull when editing this file, do not split the line in the file when editing, the file must only contain 1 line. The file normally contains an entry "console=tty1", this is normal, leave it alone. This action prevents Raspbian from sending boot messages to the Serial Port, and expecting a log-in from the Serial Port.
The 'raspi-config' utility makes changes to the above mentioned files, so do not use it to change the Serial Port settings after making the above checks.
Reboot your Pi.
You should refer to your Serial Port as "/dev/serial0", not "/dev/ttyAMA0". This will ensure that your code will work in all models of the Pi, and will work with future updates to Raspbian. That's serialZero, not serialOh.
I don't have minicom, but you can check that your Serial port is working by joining the Tx and Rx pins together (power off first!) and running this Python script:
Code: Select all
# Will also work on Python3.
# Serial port testing for a RaspberryPi.
from __future__ import print_function
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", "/dev/serial1", "/dev/ttyS0"]
for port in port_list:
serialPort = serial.Serial(port, 9600, timeout = 2)
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")
print ("Received incorrect data", loopback, "over Serial port", port, "loopback\n")
print ("Failed at", port, "\n")
On a RaspberryPi B+, it should pass on 'serial0' and 'ttyAMA0', and fail on 'serial1' and 'ttyS0'.
I'm not sure if the 'python-serial' module is part of Jessie Lite, if you get an error about no module named serial, install it with:
Code: Select all
sudo apt-get update
sudo apt-get install python-serial