This is my first post here and am relatively new to the RPi, I am currently doing a college project and i need to be able to communicate between my RPi 3 and a dsPIC30F4011 microcontroller and have been trying all sorts to get this working, currently i am just trying to get the most basic communication going and have followed a code written on by someone else on this site, basically a loopback code to make sure that the RPi is actually working but i seem to be having problems with this!
I have carried out the following:
Code: Select all
sudo nano /boot/config.txt
enable_uart=1
dtoverlay=pi3-miniuart-bt
I then done:
Code: Select all
sudo nano /boot/cmdline.txt
console=ttyAMA0,115200
Then:
Code: Select all
sudo systemctl disable hciuart
Code: Select all
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# serial_port_loopback3.py
# Will also work on Python2.
# Serial port testing on a RaspberryPi 3B with Bluetooth disabled.
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")
# That's it!
Failed at /dev/serial0
Failed at /dev/ttyAMA0
Failed at /dev/serial0
Failed at /dev/ttyAMA0
Hardware wise i just have TXD (pin8) and RXD (pin10) shorted out.
Can anyone tell me if i have done anything wrong or if this should be working for me?
Any help would be greatly appreciated.