/ch340g-bitbanging

WinChipHead (WCH) ch340g USB-serial adaptor bitbanging and LED blinking

Primary LanguagePython

noswpatv3 CH340G bitbanging

I just wanted to set a pin low or high on a USB-serial adaptor.

This could be used to:

  • blink a LED
  • power on/off a relay
  • bitbanging a protocol over several pins (avrdude)

Picture

WinChipHead CH340G usb-serial adaptor

Pinout

The RTS pin14, the pin1 is marked with the little round on the top head corner.

The usable pins are:

  • RTS = pin14
  • DTR = pin13

We note that the Avrdude flasher mentioned below uses the following four pins:

  • RTS (RESET)
  • DTR (SCK)
  • TXD (MOSI)
  • CTS (MISO)

WinChipHead CH340G pinout

Price

You can get those adaptors by a pack of 10 for 10EUR via Aliexpress.com. Standalone you can find them at 0.88EUR, or just the chip in SOP16 format at around 0.44EUR.

Usage

You can set the RTS pin of the CH340G low (0V) or high (3.7V) with this simple script.

In the future, those CTS/RTS/DCD/CI pins could be used as GPIOs in sysfs or via libusb, which pyserial probably uses.

Speed

When I set 100K permutations, the execution time is around 35secs:

root@sabayon /home/zoobab/soft/ch340g-bitbanging [9]# time ./ch340g-rts.py
real    0m35.066s
user    0m4.004s
sys     0m2.354s

root@sabayon /home/zoobab/soft/ch340g-bitbanging [10]# python
Python 2.7.9 (default, Dec 29 2014, 06:44:46) 
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 100000.0/35.0
2857.1428571428573

Which makes a speed of about 2.8KHz, which is very similar to the RaspberryPi sysfs shell speed.

CP2102 dongle

I also have a CP2102 dongle, and the nice feature with this one is that the DTR pin is available on the header:

Silabs CP2102 usb-serial adaptor breakout

The DTR voltage is different from the CH340G, as it has precise 3.3V or 0V values.

I tried the same on the RTS pin (you need to solder a pin on the nicely exposed hole), and it also has 0V or 3.3V.

Silabs CP2102 blinking a LED with the DTR pin

FTDI UMFT230XB dongle

This dongle has a nice 10 pins female header:

FTDI UMFT230XB dongle FTDI UMFT230XB blinking a LED with the RTS pin

TODO

  • Rewrite the whole thing in C with libusb in order to remove python dependencies.

Links