0

BBIO UART Question
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BBIO UART Question

by smbrandonjr on Mon Dec 31, 2018 11:35 am

To preface, I wrote a python app to communicate via serial with a TFT board. I am using pyserial in my program. When I was writing and testing out the program, I was doing so in Windows using a USB-to-Serial adapter. My ultimate goal is to run my app from a BeagleBone, but I knew I could work through the logic of the app quicker in my Windows environment and then worry about the BeagleBone serial later.

So now I am trying to run my app from my BeagleBone. I am using P9.11 and P9.13 (UART4). As soon as I configure P9.13 (TX pin) for UART, my TFT display goes blank and my program does not work as it did when I was interfacing with Windows via the hardware adapter.

Are there some hardware design elements I need to take into account here? I did monitor the serial line when setting the pins to UART mode, and did not see anything coming across.

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by smbrandonjr on Mon Dec 31, 2018 11:40 am

Do I need to add a MAX232 chip to my design?

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by smbrandonjr on Mon Dec 31, 2018 3:40 pm

Happened to have a MAX3232 on hand and the answer to my question is "Yes". Lol

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by drewfustini on Wed Jan 02, 2019 8:30 am

Are you still having issues after adding the MAX232 to the design?

drewfustini
 
Posts: 890
Joined: Sat Dec 26, 2015 1:19 pm

Re: BBIO UART Question

by smbrandonjr on Wed Jan 02, 2019 10:14 am

The max3232 was definitely required and allowed me to communicate with my program. The only issue I am running into with the beagle bone that I don't run into with Windows is that after my program executes and finishes, I can't run it again successfully.

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by drewfustini on Wed Jan 02, 2019 2:50 pm

smbrandonjr wrote:The max3232 was definitely required and allowed me to communicate with my program. The only issue I am running into with the beagle bone that I don't run into with Windows is that after my program executes and finishes, I can't run it again successfully.


Do you get an error message when your program does not run successfully?

If so, could you please paste the exact error message or a screenshot.

drewfustini
 
Posts: 890
Joined: Sat Dec 26, 2015 1:19 pm

Re: BBIO UART Question

by smbrandonjr on Wed Jan 02, 2019 3:21 pm

Unfortunately I do not get a specific error. I am having a hard time debugging on my beaglebone.

Essentially what my program does is:

1) Open serial port -- pyserial and BBIO UART
2) Send a specific write to the serial port
3) Read serial port and if read data matches something specific continue on with the program, else exit

When I my application in windows it works fine. When I run in Beaglebone it works the first time, but subsequent attempts to run the program fail as if the data read in step 3 is wrong.

The main difference between the Windows run and the Beaglebone run, other than the obvious, is the hardware connection.

If you have any advice on how I can further debug this on the BeagleBone, I'd gladly give it a shot...I am closing the serial port and doing UART.cleanup() at the end of the application. (This issue occurred prior to using UART.cleanup()...I wasn't sure if UART.cleanup() was actually functional so in the beginning I left it out of my code.)

I have also tried reconfiguring the pins I am using prior to subsequent runs...

config-pin P9.11 default
config-pin P9.13 default
config-pin P9.11 uart
config-pin P9.13 uart

Mike

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by drewfustini on Wed Jan 02, 2019 3:23 pm

Could you please post the source code for your program so I could try replicating the issue?

drewfustini
 
Posts: 890
Joined: Sat Dec 26, 2015 1:19 pm

Re: BBIO UART Question

by smbrandonjr on Wed Jan 02, 2019 3:38 pm

Only if you promise not to laugh!

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by smbrandonjr on Wed Jan 02, 2019 4:19 pm

Below is the code that applies to the serial connection and usage...I have stripped out a lot of stuff that happens after the point where I am currently exiting with this issue I am encountering on the beaglebone.

Code: Select all | TOGGLE FULL SIZE
import Adafruit_BBIO.UART as UART
import serial
import time

write_command = ';R000F1\r'
erase_command = ';E99EA\r'
erase_confirm = ':RFFFF\r'
read_erase = ':E\r'

# serial work
UART.setup("UART4")
ser = serial.Serial()
ser.port = "/dev/ttyO4"
ser.baudrate = 115200
ser.bytesize = serial.EIGHTBITS  # number of bits per bytes
ser.parity = serial.PARITY_NONE  # set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE  # number of stop bits
ser.timeout = None
ser.xonxoff = False  # disable software flow control
ser.rtscts = False  # disable hardware (RTS/CTS) flow control
ser.dsrdtr = False  # disable hardware (DSR/DTR) flow control
ser.writeTimeout = 180  # timeout for write

try:
    ser.open()
    print "Serial port opened on " + ser.port + "\n"
except Exception, e:
    print "Error opening serial port: \n\n" + str(e)
    exit()

#from here to line 52 is my attempt to catch if there is an issue communicating with the serial device.
tries = 10
try_count = 0
if ser.isOpen():
    while try_count <= tries:
        ser.flushInput()
        ser.flushOutput()
        ser.write(write_command)
        time.sleep(.5)
        while ser.inWaiting() > 0:
            read_data = ''
            read_data += ser.read(131)
            if ':R99' in read_data or ':RFFFF' in read_data:
                try_count = 11
            else:
                ser.flushInput()
        if try_count == 9: #I am getting here on subsequent application runs only when executed from BeagleBone.
            print 'Serial application is not communicating properly. Check your connection.'
         ser.close()
         UART.cleanup()
            exit()
        try_count += 1
            
    ser.write(write_command)
    time.sleep(.5)

   #serial device is communicating as expected, so lets continue
    # read response fromw rite_command and erase
    while ser.inWaiting() > 0:
        read_data += ser.read(131)
        if ':R99' in read_data or ':RFFFF' in read_data:
            ser.write(erase_command)
            time.sleep(1)

            while ser.inWaiting() > 0:
                read_data = ''
                read_data += ser.read(3)
                if read_data == read_erase:
                    ser.write(write_command)
                    time.sleep(1)

                    while ser.inWaiting() > 0:
                        read_data = ''
                        read_data += ser.read(131)
                        if read_data == erase_confirm:
                            pass
                            try:
                               
                        #here I do a lot of file specific stuff that i have stripped out as i am not having issues here with the beaglebone

                                print 'Success...Done!'

                            except IOError:
                                print 'Error...File_List.txt not found! Please upload!'
                        else:
                            print 'Error...Unable to confirm erase!'
                else:
                    print 'Error...read data was not :E'
        else:
            print 'Error...read data is not as expected'
ser.close()
UART.cleanup()


I didn't supply the full code as there are external files that get read in further into the application as well as the fact that they are specific to communicating with a PIC24FJ256DA210 running some custom firmware that I don't have access to. I just happen to have one of the configured units that is running it.

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Re: BBIO UART Question

by smbrandonjr on Sat Jan 05, 2019 8:20 pm

My issue may have been related to my MAX3232 chip I was using.

I have obtained another one and in testing so far, am not encountering the problematic behavior.

smbrandonjr
 
Posts: 27
Joined: Thu Oct 11, 2018 12:44 am

Please be positive and constructive with your questions and comments.