└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # CH340/341 UART Driver for Raspberry Pi 2 | 3 | A pre-compiled binary for CH340/341 (HL340/341) USB-to-Serial UART Driver for Raspberry Pi. This is a very common chip, especially in those millions of esp8266-based dev boards (also often referred to as NodeMCU). Raspberry Pi doesn't have an out of the box driver for it, so plugging your device into RPI's USB won't do much other than power it. I found it surprisingly difficult to locate working instructions and binaries, hence this repository came to life. 4 | 5 | The driver will work both for CH340 & CH341 chips. Sometimes you will see the HL340/HL341 designation, it's just different names for the same hardware. 6 | 7 | # 1-Minute How-To 8 | ## Download the `ch34x.ko` onto the Raspberry Pi. See the **Releases** tab above. E.g. 9 | ``` 10 | wget https://github.com/aperepel/raspberrypi-ch340-driver/releases/download/4.4.11-v7/ch34x.ko 11 | ``` 12 | ## Install the kernel module: 13 | ``` 14 | sudo insmod ch34x.ko 15 | ``` 16 | 17 | ## Verify it's showing up in the kernel. You should see the **ch341** listed: 18 | ``` 19 | $ lsmod 20 | Module Size Used by 21 | bnep 10340 2 22 | hci_uart 17943 1 23 | btbcm 5929 1 hci_uart 24 | bluetooth 326105 22 bnep,btbcm,hci_uart 25 | brcmfmac 186599 0 26 | brcmutil 5661 1 brcmfmac 27 | cfg80211 427855 1 brcmfmac 28 | rfkill 16037 4 cfg80211,bluetooth 29 | snd_bcm2835 20511 0 30 | snd_pcm 75698 1 snd_bcm2835 31 | snd_timer 19160 1 snd_pcm 32 | snd 51844 3 snd_bcm2835,snd_timer,snd_pcm 33 | i2c_bcm2708 4770 0 34 | bcm2835_gpiomem 3040 0 35 | bcm2835_wdt 3225 0 36 | ch341 4932 0 37 | usbserial 22115 1 ch341 38 | uio_pdrv_genirq 3164 0 39 | uio 8000 1 uio_pdrv_genirq 40 | i2c_dev 5859 0 41 | ipv6 347530 30 42 | ``` 43 | 44 | ## Verify the module has been installed (so it's picked up on reboot). You should see the **ch34x.ko** file listed: 45 | ``` 46 | ls /lib/modules/$(uname -r)/kernel/drivers/usb/serial 47 | ``` 48 | If not, try running 49 | ``` 50 | sudo depmod -a 51 | ``` 52 | 53 | ## Plug In ESP8266 54 | Plug in your dev board into any of the Raspberry Pi's USB port. A few things should happen. Again, look for the **340** strings: 55 | ``` 56 | $ lsmod 57 | [ 65.597856] usbcore: registered new interface driver ch34x 58 | [ 65.598537] usbserial: USB Serial support registered for ch34x 59 | 60 | $ lsusb 61 | Bus 001 Device 004: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter 62 | Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter 63 | Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 64 | Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 65 | ``` 66 | 67 | At this point you're all set. Upload the new firmware to esp8266 and, given it prints output to Serial at 115200 baud rate, this should print stuff: 68 | ``` 69 | cat /dev/ttyUSB0 70 | ``` 71 | 72 | # Compilation Instructions 73 | Normally isn't required, but if for some reason you need to compile it for a different kernel version of Raspberry Pi, here it goes. 74 | 75 | ## Download the CH34x Driver Sources 76 | On the Raspberry Pi, go to http://www.wch.cn/download/CH341SER_LINUX_ZIP.html and click that big blue **Download** button. This is the manufacturer's website, but it's all in Chinese. 77 | 78 | ## Prepare the Kernel Build Environment 79 | ``` 80 | sudo apt-get -y install linux-headers-rpi 81 | sudo apt-get install rpi-update 82 | sudo rpi-update 83 | 84 | # reboot here, you're on the latest kernel 85 | 86 | sudo wget https://raw.githubusercontent.com/notro/rpi-source/master/rpi-source -O /usr/bin/rpi-source && sudo chmod +x /usr/bin/rpi-source && /usr/bin/rpi-source -q --tag-update 87 | 88 | sudo apt-get install bc 89 | sudo apt-get install libncurses5-dev 90 | rpi-source 91 | ``` 92 | 93 | ## Build the Driver Module 94 | ``` 95 | # unzip the driver sources archive 96 | # cd into the new directory 97 | make 98 | ``` 99 | This will produce the `ch34x.ko` file, which you can install as described above. 100 | --------------------------------------------------------------------------------