# Modbus RTU using ch340 ttl to usb on pi 4

**URL:** <https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188>\
**Category:** General\
**Tags:** modbus\
**Created:** [31 July 2023 13:26 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188 "2023-07-31T13:26:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 13:26 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/1 "2023-07-31T13:26:47Z")

</div>

I NEED SOME help on my raspberry pi 4 i use ch340 ttl to usb to get string from a flowmeter via rs485 . wenne i l put the ch340 to my windows10 node red i get the data but when i put it in pi 4 with the same flow i get northing . note : in my windows flow on node modbus-read i use config Serial port COM47 . Serial type :RTU-BUFFERD  
Baud rate : 9600

at do the same in my pi 4 but i change the serial port to /dev/ttyUSB0 . it the anythink  
should i active or any advise

---

<div class="post-metadata">

**Author:** ![meeki007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/meeki007/32/12499_2.png) [@meeki007](https://discourse.nodered.org/u/meeki007)\
**Post date:** [31 July 2023 13:39 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/2 "2023-07-31T13:39:08Z")

</div>

I've had issues with drivers on raspberry pi's before. Works on windows, mac, linux(64), but raspberry NO-GO.

Check out this post on pi drivers for the ch240  
[https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/linux](https://learn.sparkfun.com/tutorials/how-to-install-ch340-drivers/linux)

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 14:04 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/3 "2023-07-31T14:04:10Z")

</div>

i installed drivers and the modbus-read node show connect but when i inject it . it reconnecting without any out put

---

<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:** [31 July 2023 14:13 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/4 "2023-07-31T14:13:46Z")

</div>

What does this command show?  
`ls -l /dev/serial/by-id`

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 14:43 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/5 "2023-07-31T14:43:53Z")

</div>

leopard@raspberrypi:~ $ ls -l /dev/serial/by-id  
ls: cannot access '/dev/serial/by-id': No such file or directory

leopard@raspberrypi:~ $ ls -l /dev/serial\*  
lrwxrwxrwx 1 root root 5 Jul 10 02:17 /dev/serial0 -\> ttyS0  
lrwxrwxrwx 1 root root 7 Jul 10 02:17 /dev/serial1 -\> ttyAMA0

/dev/serial:  
total 0  
drwxr-xr-x 2 root root 60 Jul 31 15:40 by-path

leopard@raspberrypi:~ $ ls /dev/ttyUSB\*  
/dev/ttyUSB0

leopard@raspberrypi:~ $ lsusb  
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub  
Bus 001 Device 007: ID 1a86:7523 QinHeng Electronics CH340 serial converter  
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub  
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 14:53 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/6 "2023-07-31T14:53:14Z")

</div>

node i m using modbus-read \* ;

node-red-contrib-modbus  
v5.25.0

the config is totally correct in this nodes . the problem i think is in the server i use maybe /dev/ttyUSB0 ?

```auto
[
    {
        "id": "384f10890cc6f831",
        "type": "modbus-read",
        "z": "4c0d8eb2f4e52850",
        "name": "",
        "topic": "",
        "showStatusActivities": false,
        "logIOActivities": false,
        "showErrors": false,
        "showWarnings": false,
        "unitid": "1",
        "dataType": "HoldingRegister",
        "adr": "4112",
        "quantity": "4",
        "rate": "10",
        "rateUnit": "s",
        "delayOnStart": false,
        "startDelayTime": "0",
        "server": "4412ae43.cdf648",
        "useIOFile": false,
        "ioFile": "",
        "useIOForPayload": false,
        "emptyMsgOnFail": false,
        "x": 230,
        "y": 140,
        "wires": [
            [
                "6cf7a26b9fbe62ab",
                "dcbeb403db420b52"
            ],
            []
        ]
    },
    {
        "id": "6cf7a26b9fbe62ab",
        "type": "modbus-response",
        "z": "4c0d8eb2f4e52850",
        "name": "modbus 1 Débit",
        "registerShowMax": "20",
        "x": 520,
        "y": 120,
        "wires": []
    },
    {
        "id": "dcbeb403db420b52",
        "type": "debug",
        "z": "4c0d8eb2f4e52850",
        "name": "debug 2355",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 530,
        "y": 180,
        "wires": []
    },
    {
        "id": "4412ae43.cdf648",
        "type": "modbus-client",
        "name": "",
        "clienttype": "simpleser",
        "bufferCommands": true,
        "stateLogEnabled": false,
        "queueLogEnabled": false,
        "failureLogEnabled": false,
        "tcpHost": "127.0.0.1",
        "tcpPort": "502",
        "tcpType": "DEFAULT",
        "serialPort": "/dev/ttyUSB0",
        "serialType": "RTU",
        "serialBaudrate": "9600",
        "serialDatabits": "8",
        "serialStopbits": "1",
        "serialParity": "even",
        "serialConnectionDelay": "100",
        "serialAsciiResponseStartDelimiter": "",
        "unit_id": 1,
        "commandDelay": 1,
        "clientTimeout": 1000,
        "reconnectOnTimeout": true,
        "reconnectTimeout": 2000,
        "parallelUnitIdsAllowed": false
    }
]

```

---

<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:** [31 July 2023 14:57 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/7 "2023-07-31T14:57:11Z")

</div>

> [@issambfs1](#):
>
> leopard@raspberrypi:~ $ ls -l /dev/serial/by-id  
> ls: cannot access '/dev/serial/by-id': No such file or directory

Well that is odd. Are you running the standard pi OS?

Unplug the adaptor, reboot, and run  
`tail -f /var/log/syslog`  
if necessary wait for a gap then hit return a couple of times to give a couple of blank lines, then plug in the adaptor. Post what you see in the log.

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 15:01 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/8 "2023-07-31T15:01:34Z")

</div>

raspberry pi os full ( 32bit )

```auto

leopard@raspberrypi:~ $ tail -f /var/log/syslog
Jul 31 16:04:45 raspberrypi Node-RED[386]: Your flow credentials file is encrypted using a system-generated key.
Jul 31 16:04:45 raspberrypi Node-RED[386]: If the system-generated key is lost for any reason, your credentials
Jul 31 16:04:45 raspberrypi Node-RED[386]: file will not be recoverable, you will have to delete it and re-enter
Jul 31 16:04:45 raspberrypi Node-RED[386]: your credentials.
Jul 31 16:04:45 raspberrypi Node-RED[386]: You should set your own key using the 'credentialSecret' option in
Jul 31 16:04:45 raspberrypi Node-RED[386]: your settings file. Node-RED will then re-encrypt your credentials
Jul 31 16:04:45 raspberrypi Node-RED[386]: file using your chosen key the next time you deploy a change.
Jul 31 16:04:45 raspberrypi Node-RED[386]: ---------------------------------------------------------------------
Jul 31 16:04:45 raspberrypi Node-RED[386]: 31 Jul 16:04:45 - [info] Starting flows
Jul 31 16:04:45 raspberrypi Node-RED[386]: 31 Jul 16:04:45 - [info] Started flows

```

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 15:06 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/9 "2023-07-31T15:06:22Z")

</div>

Unplug the adaptor in this last

---

<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:** [31 July 2023 15:17 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/10 "2023-07-31T15:17:50Z")

</div>

I don't understand, what I want you to do is to unplug the adaptor, reboot, run tail and then plug the adaptor in to the USB port on the pi. You should see the OS registering it as a serial device. If it doesn't log anything when you plug it in then it is not working.

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 15:20 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/11 "2023-07-31T15:20:45Z")

</div>

leopard@raspberrypi:~ $ tail -f /var/log/syslog  
Jul 31 16:20:06 raspberrypi kernel: [974.513653] usbcore: registered new interface driver usbserial\_generic  
Jul 31 16:20:06 raspberrypi kernel: [974.513723] usbserial: USB Serial support registered for generic  
Jul 31 16:20:06 raspberrypi kernel: [974.517645] usbcore: registered new interface driver ch341  
Jul 31 16:20:06 raspberrypi kernel: [974.517722] usbserial: USB Serial support registered for ch341-uart  
Jul 31 16:20:06 raspberrypi kernel: [974.517815] ch341 1-1.2:1.0: ch341-uart converter detected  
Jul 31 16:20:06 raspberrypi kernel: [974.523355] ch341-uart ttyUSB0: break control not supported, using simulated break  
Jul 31 16:20:06 raspberrypi kernel: [974.524649] usb 1-1.2: ch341-uart converter now attached to ttyUSB0  
Jul 31 16:20:06 raspberrypi mtp-probe: checking bus 1, device 3: "/sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2"  
Jul 31 16:20:06 raspberrypi mtp-probe: bus: 1, device: 3 was not an MTP device  
Jul 31 16:20:09 raspberrypi ModemManager[614]: [base-manager] couldn't check support for device '/sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2': not supported by any plugin

---

<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:** [31 July 2023 15:32 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/12 "2023-07-31T15:32:21Z")

</div>

> [@issambfs1](#):
>
> Jul 31 16:20:06 raspberrypi kernel: [974.524649] usb 1-1.2: ch341-uart converter now attached to ttyUSB0

That looks ok. Does `ls -l /dev/serial/by-id` still show nothing?

I understood from the previous post that you had unplugged the adaptor and saw nothing in the log. If you now unplug it do you see a disconnected message?

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 15:34 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/13 "2023-07-31T15:34:15Z")

</div>

leopard@raspberrypi:~ $ ls -l /dev/serial/by-id  
ls: cannot access '/dev/serial/by-id': No such file or directory

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 15:39 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/14 "2023-07-31T15:39:05Z")

</div>

i can see if the ch340 are plugin and unplug in the node-red at node modbus-red and also in msg lsusb !

my problem is when i inject the node are give me northing in the output . but in my laptop it give me the buffer at com47 or com28 .

---

<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:** [31 July 2023 15:40 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/15 "2023-07-31T15:40:28Z")

</div>

Sorry, I don't know what else to suggest.

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 15:44 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/16 "2023-07-31T15:44:42Z")

</div>

no problem . is the any Permissions can i give to set ch340 on the /dev/ttyUSB0

any ideas

---

<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:** [31 July 2023 15:51 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/17 "2023-07-31T15:51:55Z")

</div>

You said it is initially showing connected in node-red, which means that there should not be a permissions issue.  
Do you see anything relevant in syslog if you reboot, tail syslog, and then try to use the port in node-red?

I presume the system is up to date, if not then run  
`sudo apt update && sudo apt full-upgrade`  
watch for any errors.

If that does not help then stop node red and start it again using

```auto
node-red-stop
node-red-start

```

Then try to make the comms work, and post the full startup log here.

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 16:01 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/18 "2023-07-31T16:01:25Z")

</div>

To find more nodes and example flows - go to [http://flows.nodered.org](http://flows.nodered.org)

# Starting as a systemd service. 31 Jul 17:00:10 - [info] Welcome to Node-RED

## 31 Jul 17:00:10 - [info] Node-RED version: v3.0.2 31 Jul 17:00:10 - [info] Node.js version: v18.17.0 31 Jul 17:00:10 - [info] Linux 6.1.21-v8+ arm LE 31 Jul 17:00:11 - [info] Loading palette nodes rpi\_ads1115\_s32.node driver V2.0.2 (c) Ocean [iiot2k@gmail.com](mailto:iiot2k@gmail.com) 31 Jul 17:00:15 - [info] Dashboard version 3.5.0 started at /ui 31 Jul 17:00:15 - [info] Settings file : /home/leopard/.node-red/settings.js 31 Jul 17:00:15 - [info] Context store : 'default' [module=memory] 31 Jul 17:00:15 - [info] User directory : /home/leopard/.node-red 31 Jul 17:00:15 - [warn] Projects disabled : editorTheme.projects.enabled=false 31 Jul 17:00:15 - [info] Flows file : /home/leopard/.node-red/flows.json 31 Jul 17:00:15 - [info] Server now running at [http://127.0.0.1:1880/](http://127.0.0.1:1880/) 31 Jul 17:00:15 - [warn]

## Your flow credentials file is encrypted using a system-generated key. If the system-generated key is lost for any reason, your credentials file will not be recoverable, you will have to delete it and re-enter your credentials. You should set your own key using the 'credentialSecret' option in your settings file. Node-RED will then re-encrypt your credentials file using your chosen key the next time you deploy a change.

31 Jul 17:00:15 - [info] Starting flows  
31 Jul 17:00:15 - [info] Started flows

31 Jul 17:00:44 - [info] Stopping flows  
31 Jul 17:00:44 - [info] Stopped flows  
31 Jul 17:00:44 - [info] Updated flows  
31 Jul 17:00:44 - [info] Starting flows  
31 Jul 17:00:44 - [info] Started flows

---

<div class="post-metadata">

**Author:** ![issambfs1](https://avatars.discourse-cdn.com/v4/letter/i/ea666f/32.png) [@issambfs1](https://discourse.nodered.org/u/issambfs1)\
**Post date:** [31 July 2023 16:06 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/19 "2023-07-31T16:06:03Z")

</div>

i think i will try to use an other node-red version like 2.2.3

---

<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:** [31 July 2023 16:14 UTC](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188/20 "2023-07-31T16:14:01Z")

</div>

Did you run the update and full-upgrade?

> [@Colin](#):
>
> Do you see anything relevant in syslog if you reboot, tail syslog, and then try to use the port in node-red?

You didn't answer that question

I don't think the node-red version will make a difference.

What _exactly_ do you see with the status text under the modbus node?

What does the command  
`groups` show when you are logged in as leopard?

[Next page](https://discourse.nodered.org/t/modbus-rtu-using-ch340-ttl-to-usb-on-pi-4/80188.md?page=2)
