Serialport Node Huge CPU usage

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.

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:

cd .node-red
npm rebuild 

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 :frowning:

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.

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:

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

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.

Have a look at this.

By default /dev/ttyAMA0 is bluetoothport.

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

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