# Serialport Node Huge CPU usage

**URL:** <https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532>\
**Category:** Hardware\
**Created:** [30 September 2020 00:07 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532 "2020-09-30T00:07:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [30 September 2020 00:07 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/1 "2020-09-30T00:07:34Z")

</div>

I recently set up a new Raspberry Pi 3 with Node Red V1.1.3. The Raspberry Pi 3 uses Raspberry Pi OS lite 5.4.

I copied the node red flows from one working system to this new system. Everything worked except that I noticed a huge CPU usage jump. The new system uses much less memory and has less apps running than the working system. The working system uses Node Red V1.1.2.

I troubled shoot the problem and found that the Serialport node caused the problem. If I remove the serialport node, then the CPU usage quickly drops down to normal level (2-4% typically). If I add the serialport node back, the CPU usage jumps more than 100% and the board will heat up quickly.

There are only two major differences that I can think of:

1. Raspberry Pi OS (the working system has Desktop, the new system does not). I doubt that this is the problem.
2. The working system uses Node Red v1.1.2. The new system uses Node Red v1.1.3. I doubt that this is the problem either.

What could cause the problem? Thanks for your help.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [30 September 2020 01:43 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/2 "2020-09-30T01:43:21Z")

</div>

Did you happen to copy the whole `.node-red` directory from from the older system? I'm asking as the serialport library has native code bindings and might need to be rebuilt against the libraries of the new installation.

Another thought that occurred is that the serialport build could have failed due to missing tools/libraries during the installation.

This is somewhat of a longshot but just my first thoughts on what I can think of as a potential issue. If you want to try to force a rebuild (noting possible errors), log in to your Raspberry and run:

```auto
cd .node-red
npm rebuild 

```

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [30 September 2020 04:51 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/3 "2020-09-30T04:51:44Z")

</div>

Thank you very much. I did a fresh installation of the .node-red on the new system.

But it might be related to what you suggested. The old system uses USB to serial interface (/dev/ttyACM0). The new system uses UART interface (/dev/ttyAMA0). When I changed the serial interface of the new system to /dev/ttyACM0, then the CPU usage drops back to normal (less than 4%). When I change it back to UART interface, the CPU usage shoots up more than 100% again ☹

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [30 September 2020 06:24 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/4 "2020-09-30T06:24:57Z")

</div>

OK. I changed the serial interface on the old system to /dev/ttyAMA0, the CPU usage on the old system also shoots up more than 100%. Now I am convinced that this problem is due to the /dev/ttyAMA0 port usage with Node Red Serial port node.

Any solutions for it? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [30 September 2020 06:45 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/5 "2020-09-30T06:45:33Z")

</div>

Likely a stupid question but have you enabled serial port with `raspi-config`?

Is there any errors in the logs? If you installed NR with the official install script, you can see them with `node-red-log` (or `-logs`).

Have you tried if the serial connection works with some other way, e.g. a simple Python script:

```auto
import serial

port = serial.Serial("/dev/ttyAMA0", baudrate=115200, timeout=3.0)

while True:
    port.write("\r\nSay something:")
    rcv = port.read(10)
    port.write("\r\nYou sent:" + repr(rcv))

```

Source: [https://www.elinux.org/Serial\_port\_programming](https://www.elinux.org/Serial_port_programming)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 September 2020 07:27 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/6 "2020-09-30T07:27:23Z")

</div>

What happens if you disconnect the output of the serial port node? It may not be the node, it may be what is happening in your flow after the node.

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [30 September 2020 12:03 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/7 "2020-09-30T12:03:27Z")

</div>

Have a look at this.

> **[Configuring The GPIO Serial Port On Raspbian Jessie and Stretch Including Pi...](https://spellfoundry.com/2016/05/29/configuring-gpio-serial-port-raspbian-jessie-including-pi-3-4/)**
>
> The Raspberry Pi GPIO serial port configuration has changed under Jessie / Stretch / Buster and also with the Raspberry PI 3 / 4. How to set it up.

By default /dev/ttyAMA0 is bluetoothport.

---

<div class="post-metadata">

**Author:** ![davidz](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@davidz](https://discourse.nodered.org/u/davidz)\
**Post date:** [30 September 2020 17:23 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/8 "2020-09-30T17:23:12Z")

</div>

Thank you very much ristomatti, Colin and edje11! This forum is amazing.

It turns out that the Bluetooth in Raspberry Pi 3/4 is using the /dev/ttyAMA0 port, which caused the huge CPU spike if I use this port.

So I followed edje11's link and disabled the Bluetooth in Raspberry Pi 3/4, then the CPU usage is back to normal.

Here is what I did and hopefully it can help others in the future:

1. Edit the config.txt file:  
sudo nano /boot/config.txt  
and add the following line to the end of the file to disable Bluetooth:  
dtoverlay=pi3-disable-bt
2. Reboot the Raspberry Pi. Then the /dev/ttyAMA0 port will be available for UART usage.  
Deploy the serialport node will not have the CPU spike.

Cheers

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 October 2020 17:23 UTC](https://discourse.nodered.org/t/serialport-node-huge-cpu-usage/33532/9 "2020-10-14T17:23:17Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
