# Facing issue in UART Communication on Raspberry Pi

**URL:** <https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419>\
**Category:** balenaOS\
**Created:** [June 15, 2019, 11:57am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419 "2019-06-15T11:57:10Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 15, 2019, 11:57am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/1 "2019-06-15T11:57:10Z")

</div>

Hello

I am using Raspberry Pi and I have downloaded the Raspberry Pi Host OS from BalenaOS download page.

Raspberry Pi Version =\>  
`BalenaOS 2.36.0+rev2`

I have to set up communication between External hardware with Raspberry Pi using the UART interface.

For that I have done the following settings in config.txt =\>

```
enable_uart=1
core_freq=250
dtoverlay=pi3-miniuart-bt
dtoverlay=uart-ctsrts

```

using `Balena Cli env add` command

I am using `pi3-miniuart-bt` for switching the Port for swapping `ttyAMA0` and `ttyS0`

`uart-ctsrts` are used to enable Hardware flow control.

I have copied `miniuart-ctsrts.dtbo` and `uart-ctsrts.dtbo` in the `/mnt/boot/overlays` directory.

I have enabled the UART and wrote a sample code for send and receiving the bytes over receiving.

Send function works properly But receiving function blocks after 2 to 3 seconds.

```auto
#!/usr/bin/env python
import time
import serial

ser = serial.Serial(
    
    port='/dev/serial0',
    baudrate = 9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)
counter=0

while 1:
    print "I am reading"
    x=ser.readline()
    print "I am after reading"
    print(x)

```

```auto
#!/usr/bin/env python
import time
import serial

ser = serial.Serial(
    
    port='/dev/serial0',
    baudrate = 9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
)
counter=0

while 1:
    print "I am here"
    ser.write('Write counter: %d \n'%(counter))
    time.sleep(10)
    counter += 1

```

---

<div class="post-metadata">

**Author:** ![gelbal](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gelbal/32/1109_2.png) [@gelbal](https://forums.balena.io/u/gelbal)\
**Post date:** [June 17, 2019, 9:07am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/2 "2019-06-17T09:07:41Z")

</div>

Hi @Sharvin26,

Thank you for sharing so much context. Could you try out the steps explained in this thread?

> [@Disable console over Serial in Dev on RPi3?](https://forums.balena.io/t/disable-console-over-serial-in-dev-on-rpi3/1412/20):
>
> Is it possible something installed in the Docker image influence what’s happening on the host ? So far I thought the only interactions where : volumes (containers writing datas visible by host in volume directories) ports (you set a port mapping so each listening container port corresponds to a listening host port). Are there low level interactions which would allow some process running in the container to write on /dev/ttyAMA0 from the container ? UPDATE : one thing I’ve just learnt is the…

I see that this user had similar issues and following these steps helped him.

If that doesn’t work, could you as well try using a production image?

Please let us know how it goes.

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 18, 2019, 1:21pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/6 "2019-06-18T13:21:43Z")

</div>

@gelbal  
Thanks for the Solution.  
It’s working now but now I want to enable the Hardware flow control ( CTS/RTS ) pins for UART communication. How can I achieve this?

**Note**

- I have added the `dtoverlay=uart-ctsrts` in config.txt in /mnt/boot/config.txt

- Also I have added the `uart-ctsrts.dtbo` file at /mnt/boot/overlays directory.  
Ref =\> [https://github.com/HiassofT/AtariSIO/tree/master/contrib/rpi](https://github.com/HiassofT/AtariSIO/tree/master/contrib/rpi)

---

<div class="post-metadata">

**Author:** ![zubairlk](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/zubairlk/32/954_2.png) [@zubairlk](https://forums.balena.io/u/zubairlk)\
**Post date:** [June 19, 2019, 12:20pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/9 "2019-06-19T12:20:17Z")

</div>

> [@Sharvin26](#):
>
> dtoverlay=uart-ctsrts

Hi,

You should add that via environment variables (`RESIN_HOST_CONFIG_dtoverlay` I think) in the balenaCloud dashboard so that the supervisor can write that file.  
Otherwise the supervisor checks config.txt and things there is an extra parameter that it removes. Because it isn’t aware of the existence of this one.

Regards  
ZubairLK

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 19, 2019, 1:10pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/11 "2019-06-19T13:10:26Z")

</div>

I am using open balena and I have added the `RESIN_HOST_CONFIG_dtoverlay` using the command `balena add env` command.

```auto
dtoverlay=pi3-miniuart-bt
dtoverlay_1=uart-ctsrts

```

One thing I doubt that is affecting is dtoverlay\_1 naming ( please correct me if I am wrong ) It should be `dtoverlay` for `uart-ctsrts` also.

But I had to add `dtoverlay_1` via Environment variable for `uart-ctsrts` as it was not taking `dtoverlay` as it was already assigned to `pi3-miniuart-bt`.

---

<div class="post-metadata">

**Author:** ![zvin](https://avatars.discourse-cdn.com/v4/letter/z/a5b964/32.png) [@zvin](https://forums.balena.io/u/zvin)\
**Post date:** [June 19, 2019, 2:07pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/12 "2019-06-19T14:07:10Z")

</div>

Hello @sharvin26 you need to use `RESIN_HOST_CONFIG_dtoverlay` and set it to `"pi3-miniuart-bt","uart-ctsrts"` (including the double quotes), see [https://www.balena.io/docs/reference/OS/advanced/#setting-device-tree-overlays-dtoverlay-and-parameters-dtparam](https://www.balena.io/docs/reference/OS/advanced/#setting-device-tree-overlays-dtoverlay-and-parameters-dtparam)

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 20, 2019, 6:50am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/16 "2019-06-20T06:50:49Z")

</div>

Hello,

I have configured as you mentioned in the above thread.

`➜ balena env add BALENA_HOST_CONFIG_dtoverlay "pi3-miniuart-bt","uart-ctsrts" -a MyApp`

After that, I rebooted the raspberry pi.

```auto
root@a2ae423:/mnt/boot# cat config.txt
core_freq=250
dtoverlay=pi3-miniuart-bt,uart-ctsrts
enable_uart=1
dtoverlay_1=uart-ctsrts
disable_splash=1
dtparam=i2c_arm=on
dtparam=spi=on
dtparam=audio=on
gpu_mem=16

```

```auto
➜ balena envs -a MyApp --config
ID NAME VALUE
13 BALENA_HOST_CONFIG_core_freq 250
10 BALENA_HOST_CONFIG_dtoverlay pi3-miniuart-bt,uart-ctsrts
9 BALENA_HOST_CONFIG_dtoverlay_2 i2c-rtc,ds1307
14 BALENA_HOST_CONFIG_enable_uart 1
3 BALENA_SUPERVISOR_LOCAL_MODE 1
4 RESIN_HOST_CONFIG_dtoverlay pi3-miniuart-bt,uart-ctsrts
7 RESIN_HOST_CONFIG_dtoverlay_1 uart-ctsrts

```

But I am still unable to enable the Hardware flow control. I also tried to remove this  
`dtoverlay_1=uart-ctsrts` using command `balena env rm 7 --yes` It didn’t give any error but it didn’t remove.

**Note:** I am using OpenBalena.

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [June 20, 2019, 11:50am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/17 "2019-06-20T11:50:27Z")

</div>

Can you please start fresh on a new application and set the vars again? Might worth trying on balenaCloud as well in order to use the Dashboard.

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 20, 2019, 11:52am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/19 "2019-06-20T11:52:44Z")

</div>

For that I need to remove the device from existing application and reregister to new application right ( Right now I would like to test it on openbalena. )

Can you share the commands for this purpose?

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [June 20, 2019, 11:55am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/20 "2019-06-20T11:55:21Z")

</div>

Is the device present locally with you? You can follow the Getting Started guide from here: [https://www.balena.io/docs/learn/getting-started/raspberrypi3/nodejs/](https://www.balena.io/docs/learn/getting-started/raspberrypi3/nodejs/)

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 20, 2019, 11:56am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/22 "2019-06-20T11:56:21Z")

</div>

yes, the device is present locally. The doc you shared is for BalenaCloud. Can you share a command line option?

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [June 20, 2019, 11:59am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/23 "2019-06-20T11:59:37Z")

</div>

Please use balenaCloud and the Dashboard to rule out a certain set of potential issues. (balenaCloud is free, but does require signup, obviously)

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 20, 2019, 1:30pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/25 "2019-06-20T13:30:33Z")

</div>

Actually right now I don’t want to move my device and application to BalenaCloud ( May be in the future ) I want to test it using OpenBalena. Can you please give a solution for this issue in terms of OpenBalena?

Thanks

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [June 20, 2019, 2:40pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/26 "2019-06-20T14:40:32Z")

</div>

OK. The Getting Started guide of openBalena explains how to create an app, push code and provision a device in detail.

---

<div class="post-metadata">

**Author:** ![Sharvin26](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Sharvin26](https://forums.balena.io/u/Sharvin26)\
**Post date:** [June 21, 2019, 5:15am UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/28 "2019-06-21T05:15:48Z")

</div>

Yes, I have configured the device using OpenBalena and for that, I have followed that guide.

My Question is How can I achieve this with OpenBalena.

> [@dfunckt](#):
>
> Can you please start fresh on a new application and set the vars again

Are there sets of command available for this purpose?

Thanks

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [June 21, 2019, 2:48pm UTC](https://forums.balena.io/t/facing-issue-in-uart-communication-on-raspberry-pi/15419/30 "2019-06-21T14:48:40Z")

</div>

I think my last comment above answers your question perfectly. The Getting Started guide has detailed instructions on how to create a new app and add a device. Which part is not clear and you need help with?
