I'm generating a high rate of errors 10-20% when sending messages out via xbee connected to UART but only when I use PWM at the same time. I'm using UART2 and I've tested this behavior using all of the other available PWM pins. Below is a piece of simplified code that has a high error rate. When I comment out the section that turns the PWM signal on, the UART/xbee sends messages pretty much faultlessly.
What is the fix to eliminate the high error rate?
import Adafruit_BBIO.UART as UART
import Adafruit_BBIO.PWM as PWM
import serial
from time import sleep
ser = serial.Serial(port = "/dev/ttyO2", baudrate = 9600)
ser.close()
for i in range(30):
message = "hello world"
ser.open()
if ser.isOpen():
ser.write(message)
else:
print('message unsent - serial port could not be opened')
ser.close()
sleep(0.1)
ser.write()? I don't think you should be opening and closing the serial
port every time you want to write to it---is there a reason to do it that I
fail to see?
On Thu, 31 Aug 2017 05:55:11 -0700 (PDT),
ojc234@gmail.com declaimed the following:
I'm generating a high rate of errors 10-20% when sending messages out via xbee connected to UART but only when I use PWM at the same time. I'm using UART2 and I've tested this behavior using all of the other available PWM pins. Below is a piece of simplified code that has a high error rate. When I comment out the section that turns the PWM signal on, the UART/xbee sends messages pretty much faultlessly.
What type of error? The "unable to open" message in your code (and why
are you constantly opening/closing the serial port?). Garbage characters on
the receiver side?
How close is the xBee antenna to whatever wiring is linked to the PWM
line? Possible cross-talk affecting the transmitted signal. Power-draw for
attached equipment maybe causing xBee drop-outs?
What are the errors? : When receiving the message (xbee connected to PC in API mode) it is commonly scrambled by random characters - often one or two characters per message often.
Why am I opening and closing the serial connection? : There was a reference on Google that told me to do that for connections that could last a long time (but now I can't find it). If it's advisable I'll leave it open the whole time. But regardless the high error rate problem seems to be dependent only on whether PWM is running or not.
Errors : yes garbage characters on the receiver side
Cross-talk : so I have had a servo motor (powered from it's own ubec) plugged in, however I thought that the ubec noise might be interfering, so I tried running the PWM signal without any device attached (no servo ubec running) and no pwm wire plugged into the beaglebone. But still had the same issue.
Errors : yes garbage characters on the receiver side
Cross-talk : so I have had a servo motor (powered from it's own ubec)
plugged in, however I thought that the ubec noise might be interfering, so
I tried running the PWM signal without any device attached (no servo ubec
running) and no pwm wire plugged into the beaglebone. But still had the
same issue.
OK--so now can you test by losing the open/close ,disconnecting the XBee
and jumpering TX and RX and writing some simple text out and checking that
you receive it back correctly, while running PWM. If you see errors, then
maybe beaglebone is sensitive to crosstalk; if you don't then the crosstalk
must be in the XBee. BTW, suppying the servo from a separate power supply
might not fully prevent interference--it could be kickback from driving the
servo.
The servo power supply is a QM12V5A but as seen below - even when this is not active, there is still a high error rate.
Also, I am not opening and closing the serial port now - it stays open throughout each test. I sent 100 messages for each test. Error rates are an approximate guess.
PWM running Servo & Servo Power Supply Active Message Mode Error Rate
Yes Yes RX-TX on loopback 0% - all good
Yes No RX-TX on loopback 0% - all good
No No RX-TX on loopback 0% - all good
Yes Yes BBB to PC via xbee 10 - 50% - no good
Yes No BBB to PC via xbee 10 - 50% - no good
No No BBB to PC via xbee 0% - all good
I don’t really know what to make of it except that the problem seems to be somewhere either in the xbee?
The xbee is connected with a 0.1uF decoupling capacitor between +3.3V and GND close to the xbee (~25mm length from xbee GND pin thru 0.1uF Cap to xbee +3.3V pin)
I see some people recommend a 1uF decoupling capacitor on the xbee - maybe I’ll try adding one of those in parallel with the 0.1uF cap.
On Fri, 1 Sep 2017 14:54:20 -0700 (PDT),
ojc234@gmail.com declaimed the following:
PWM running Servo & Servo Power Supply Active Message Mode
Error Rate
Yes Yes
RX-TX on loopback 0% - all good
Yes No
RX-TX on loopback 0% - all good
No No
RX-TX on loopback 0% - all good
Yes Yes
BBB to PC via xbee 10 - 50% - no good
Yes No
BBB to PC via xbee 10 - 50% - no good
No No
BBB to PC via xbee 0% - all good
I'd try to configure a test using hardware serial from BBB to computer
(likely that would need a 3.3V serial-USB adapter connected to RX/TX/GND,
maybe jumpers for RTS/CTS and/or/ DTR/DSR)
If you get garbage with that, the problem may be on the computer end...
I don't really know what to make of it except that the problem seems to be
somewhere either in the xbee?
How far away from the xBee connections are the PWM connections?
Could you post a picture or drawing of your physical layout? I think the evidence points to interference from the PWM circuit into the XBee. HOw close physically are they?
See the two pictures below - I have tried to simplify things a few times - but nothing seems to change the high error rate, although it might have decreased a bit - a few times it has been ~50% (That was when I was trying to run my Power HD MG1235 servo on a 7.2V UBEC)
The Xbee and PWM are on different sides of the BBB the only thing in common as per the picture below is the GND.
The code below shows the computer side of things to get you an idea of what is going on there - I’ve posted the contents of xbee_tools.py below - not that I think there’s an issue there - just as FYI.
from xbee import XBee
import serial
import cPickle
class xbee_connection:
def init(self, port, baudrate):
Start the serial connection
try:
self.ser = serial.Serial(port, baudrate)
except serial.serialutil.SerialException:
self.ser.close()
print(“Could not start serial connection, ensure that Xbee is connected to COM4 port”)
On Mon, 4 Sep 2017 04:30:07 -0700 (PDT),
ojc234@gmail.com declaimed the following:
See the two pictures below - I have tried to simplify things a few times -
but nothing seems to change the high error rate, although it might have
decreased a bit - a few times it has been ~50% (That was when I was trying
to run my Power HD MG1235 servo on a 7.2V UBEC)
You're using USB power for the BBB? Have you tried with a stand-alone
wall-wart supply?
Shorten the GND wire between the BBB and the GND common point. The BBB GND plane must be the reference point and in your picture, you now have a second GND reference point with a long wire connecting the two. This creates a GND bounce on your second GND reference point and is probably responsible the the noise you are seeing.
Thank you thank you thank You!
You are right. There are 8 ground terminals on the GPIO - they seem to be there for a reason - when I plug the xbee GND directly into one of those (make the path to the BBB short) I get ~zero errors in communication.
When I create a secondary Ground reference plane from one of the BBB GND pins, things go bad and I get a high error rate.
All is good again.
One interesting point to note - if only the xbee is connected to the BBB (no wire connection to the PWM pin) there are similar errors. As soon as the servo is plugged into the PWM pin / GND the error rate goes to ~nil again.