This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Serial Communication issues with python (at Mac) and TM4C129

Other Parts Discussed in Thread: ENERGIA

I have an XBee (S2C) connected to my Mac and another XBee connected to a TI microcontroller (TIVA-C129) communicating with each other - Mac as a coordinator and TI as a router.

I can communicate between them, but on the TI side, I can't read the exact data that is coming in the serial port.

On the Mac, I am running below python code that reads the incoming serial data through XBee and writes an acknowledgment.

#!/usr/bin/python
import serial

ser = serial.Serial('/dev/tty.usbserial-A104IC2U', 9600)
ack='A'

while True:
incoming = ser.readline().strip()
if incoming != 'A':
print '%s' % incoming
ser.write('%s\n' % ack)

On the TI side, I have below code

int incomingByte = 0;

void setup()
{
Serial3.begin(9600); //UART3 has XBee connection
pinMode(LED, OUTPUT); 
}

void loop()
{
Serial3.println("Sending command to the XBee");
delay(1000);
Serial3.println("I am R1");
delay(1000);

if (Serial3.available() > 0) {
// read the incoming byte from UART3
incomingByte = Serial3.read();

// say what you got, print at the usb serial console
Serial.print("I received: "); 
Serial.println(incomingByte, DEC);

}

}

When I run this, XBee communication stops after printing "I am R1" in the python console. I am sure Serial3.available() > 0 is working as when I replace it with a blink code like below, it works and XBee communication keeps working on.

if (Serial3.available() > 0) {

digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

So looks like the problem is in

incomingByte = Serial3.read();

 

From python, I am sending a string (%s) with ser.write('%s\n' % ack). Is Serial3.read() the right read mechanism for the ack string? Anything else?

 

FYI: I tested the serial.read() only with TI (no python involved) by writing something in the console and serial.read() can read and print it.

  • Hello Lilyhack,

    Unfortunately, we can't really answer this question. This isn't a TI tool so we have no insight into its inner workings. I would recommend you employ some sort of "sniffer" device to receive the Zigbee message where you can look at the physical message that is being sent via a log of the communication stream. TI sells these as USB devices that can then log all observed messages and data. I'm not sure of compatibility with Mac though.
  • I figured out the problem. It is not really in serial read. 

    The problem is happening because I am using a mix of Serial3 and Serial commands. I used the below snippets to see whats really going on

    if (Serial3.available() > 0) {
    // read the incoming byte:
    Serial3.println("got ack");
    delay(1000);
    incomingByte = Serial3.read();
    Serial3.println("read done");
    delay(1000);
    
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
    
    
    Serial3.println("I got");
    delay(1000);
    Serial3.println(incomingByte);
    delay(1000);

    The code gets stuck after sending "read done" to XBee. But it I comment out below lines, the entire code works fine

    // say what you got:
    //Serial.print("I received: ");
    //Serial.println(incomingByte, DEC);

    Any thoughts on how to solve this?

  • lilly hack,

    I really have no idea what your code is doing as it is unrecognizable syntax to me. I am assuming you are either posting your python scripting or this is energia code. Either way, this forum is not the right place to get answers on either one of those environments. So, unless you luck out and one of the many users stumbles upon your post and is also familiar with what you are using based on the syntax and is inclined to invest the time and effort to attempt to dive into your project, I am afraid we won't be able to help.