What can we do with a UC00A besides Serial to USB converter? Let’s start from fulfilling my day dreams. I always wanted to have a device other than mouse and keyboard to control my PC. Okay, it’s not a big deal if we use a microcontroller to commnunicate with the PC through serial interface by using a UC00A. However that’s not what we want to achieve here. We want to do it by using UC00A alone!
If you are familiar with this product, you’ll know that it doesn’t have microcontroller on board. So you may ask how are we going to read input and give output in that case? Looking into the serial communication, besides TXD pin (Transmitter Data – output) and RXD pin (Receiver Data – input), there are also pins like:
- DTR (Data Terminal Ready – output)
- DSR (Data Set Ready – input)
- RTS (Request To Send – output)
- CTS (Clear To Send – input)
If you wish to know more about these pins, please visit this webpage for more information. Thanks to their great description on serial communication!
Actually there is one more input pin that we can use. It is DCD (Data Carrier Detect – input). Since this pin is not extended to UC00A pinout, so I choose to ignore it. So did you see the point now? We’ll make use of the pins which are initially used for serial communication as the input/output.
After we are clear about what are we going to control and manipulate, lets move on to the software portion. Usually I’ll complete the hardware or circuit first before the software. But this time since I’m not sure what functions the developer software can offers, I would like to determine it before I come out with the circuit. I choose to use VB.net for personal preference =p You may download Microsoft Visual Basic 2008 Express Edition here. It’s free!
Thanks to the marvellous assistant functions in VB.net where people like me who lack of PC programming experience can get rid of the difficulty in using syntax and structure in this language. It gives suggestions on the components you may wish to insert into your program after a command is keyed in. However, you may use other languages like C#, Labview, Matlab and etc. to achieve the same goal too. It’s just a matter of language you want to use in order to give commands to the hardware (PC)! =)
MSDN is the user’s manual for everything a developer needs to know in Microsoft programming language (Correct me if I’m wrong. Perhaps it’s true for my level of skill only). Searching for “SerialPort” in MSDN webpage gives you an idea on SerialPort class and the components under this class. Lets declare “SerialPort” object as “ComPort” and configured the necessary components to establish the serial communication (Please refer to the source code attached at the end of this article).
I found that we can read the status of the CTS, DSR and RXD pins by using “SerialPort” class. The output status of DTR, RTS and TXD pins can be controlled too. However, since the state of RXD will be changing over the transmission of data, reading from the pin is not recommended. Same thing goes to TXD pin. However we still use TXD as output just for future testing purpose. That means we’ll have 2 inputs and 3 outputs as our general purpose i/o.
After we have determined the pins, we can start with the circuit design. This is the circuit diagram:
The LEDs are active-low (0) while the switches initial state is high (1). In other word, the PC software needs to give low (0) to on the LEDs and if a low (0) is read from the input pins, corresponding switch is pressed. I’m using the prototyping area provided beside the common 2510 connector on UC00A module .
The completed circuit:
Now lets continue with the coding. The PC software we need is one which can read the status of the DSR and CTS pins and light up LEDs for indication. “PinChanged” event is the solution for monitoring of the input pins continuously. It’s similar to microchip PIC’s interrupt-on-change feature. So whenever the state of those input pins change, it’ll runs the program under the handler function.
After plugging in the UC00A with additional circuit, we can run the software and test it! You will notice that LED2 and LED3 blink for several times upon plugin. It’s because of the establishing of serial connection. This is how my GUI looks like after it’s connected to UC00A:
COM22 shows the virtual COM port created by UC00A. Usually it’s the one with greatest number unless you have more than one UC00A connected to your PC at once. After selected the COM port, click on “Connect” will establish the serial communication between your PC and UC00A.
The correct sequence would be when S1 (DSR) is pressed, LED2 (DTR) lights up, and when i press S2 (CTS), LED3 (RTS) lights up. After confirmed the functionality of the circuit and program, since we have two input, we can add the function to increase and decrease the system volume. So by pressing the switches, the volume of your system can be altered.
Photo below shows all 3 LEDs light up when i press S1 after i modify the source code given. Try it out!
To conclude, UC00A which is actually a USB to Serial Converter, also can be used as a simple yet handy GPIO for your computer. You can write your program in your PC to read 2 inputs (eg: switch, sensor) and control 3 outputs (eg: LEDs, relay, motor). Of course, the current and voltage you may draw from the USB port is definitely insufficient for driving a motor. Additional power supply is needed.
Hope you learn from the sharing and please give your precious comment so that I can improve this article. Thanks!
The source code: http://www.cytron.com.my/suppMaterial/UC00A_blog.zip