# micropython machine  uart.write() limit

**URL:** <https://forums.digi.com/t/micropython-machine-uart-write-limit/23245>\
**Category:** XBee Micropython & IDE plugin\
**Tags:** uart, micropython, xbee-cellular, xbee3\
**Created:** [September 28, 2022, 2:04pm UTC](https://forums.digi.com/t/micropython-machine-uart-write-limit/23245 "2022-09-28T14:04:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajsPillar](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ajsPillar](https://forums.digi.com/u/ajsPillar)\
**Post date:** [September 28, 2022, 2:04pm UTC](https://forums.digi.com/t/micropython-machine-uart-write-limit/23245/1 "2022-09-28T14:04:55Z")

</div>

I am using a Xbee3 LTE-m Module with micropython scripts. I am running into a strange issue where I can only send 255 bytes of a 348 byte string through the secondary UART. I have verified with a logic analyzer that only 255 leave the module. I can print the string, and I can also print two halves separately. I also verified that I still have enough RAM available. I am stumped!! Here is an example of what doesn’t work:

Example string:  
TestString = ‘{“a”:“1234563400417E2B63”,  
“b”:“0100FCFFF10000008403010001111100”,  
“c”:“0100020001000200000020C1000020410000C8C20000C8420000  
0100020001000200000020C1000020410000C8C20000C842000001000  
20001000200000020C1000020410000C8C20000C84200000100020001  
000200000020C1000020410000C8C20000C84200FF010002000100020  
0000020C1000020410000C8C20000C8420000”,  
“d”: “2C012C01”}’

Test Code:  
self.secUart = UART(1, 115200)  
self.secUart.init(115200, bits=8, parity=None, stop=1, timeout=1, timeout\_char = 1)  
print("TestString: “,TestString)  
print(” len: ",len(TestString))  
bcount = self.secUart.write(TestString)  
print("bytesSent: ", bcount)  
bcount = self.secUart.write(TestString)  
print("bytesSent: ", bcount)

OUTPUT:

TestString: {“a”:“1234563400417E2B63”,  
“b”:“0100FCFFF10000008403010001111100”,  
“c”:“0100020001000200000020C1000020410000C8C20000C8420000  
0100020001000200000020C1000020410000C8C20000C842000001000  
20001000200000020C1000020410000C8C20000C84200000100020001  
000200000020C1000020410000C8C20000C84200FF010002000100020  
0000020C1000020410000C8C20000C8420000”,  
“d”: “2C012C01”}  
len: 348  
bytesSent: 255  
bytesSent: 0

---

<div class="post-metadata">

**Author:** ![ajsPillar](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@ajsPillar](https://forums.digi.com/u/ajsPillar)\
**Post date:** [September 29, 2022, 8:19am UTC](https://forums.digi.com/t/micropython-machine-uart-write-limit/23245/2 "2022-09-29T08:19:18Z")

</div>

I found a work around, its not great, but works for what i need:

```
def psuedoFlush(self, bytes):
    delayms = int((bytes * 10000)/self.baud) + 1
    utime.sleep_ms(delayms) 

def testPrint(self):
    datalen = len(TestString)
    bcount = 0

    if datalen &gt; 255:           
        bcount += self.secUart.write(TestString[:250])
        self.psuedoFlush(bcount)
        bcount += self.secUart.write(TestString[250:])
    else:
        bcount = self.secUart.write(TestString)

```

PS: for some reason the forum post keeps killing my tabs/spaces
