Jump to content

Serial Communication issues with python (at Mac) and Energia

Recommended Posts

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.

import serial

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

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");
Serial3.println("I am R1");

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...