VT100

The VT100 devices are the most simple to use. Any serial library will do but there is a buffered library that is also used for other BV devices and so for this section that will be used. The most important part to get right is to send byte value 13 to establish the baud rate before sending anything else. This can be done with putch(13).

Just one example is given as all of the devices follow the same protocol. The only difference being is the commands may be different.

Libraries and Resources

ByVac Serial Library - Library file for buffered serial communication
ByVac VT100 - Library that uses Bserial but will also input (receive) easily

Devices that use VT100

BV4308    -    Simple LCD controller for 2 and 4 line displays
BV4511    -    128 x 64 Graphic controller
BV4513    -    192 x 64 Graphic controller
BV4615    -    Zero keypad - IR receiver
BV4168    -    More complex LCD controller with the addition of a 16 way keypad interface
BV4622    -    SD Card subsystem
BV4626    -    Multi-I/O with relays
BV4627    -    8 way relay board
BV4629    -    240 x 320 Colour LCD with touch screen

All of these devices can be controlled from the Arduino using a simple serial interface, they all have TX and RX lines and so can be connected to the Arduino's soft serial port.

BV4308 Example

As this is probably the most simple device a full example will be given. There is no need to download the sketch as the few lines needed will be presented here. The serial library is required though.

Hardware

For this example a UNO will be used connected to a BV4308-4 and a blue 4 line display.

Arduino BV4308
txPin 4 Pin 1 RX
rxPin 5 Pin 2 TX
+5V Pin 3 +V
(no connection) Pin 4
GND Pin 5

All of the devices will have these lines but not necessarily the same pin numbers. The data sheet on the particular device should be consulted for further information. For example the BV46xx normally have a 10 way connector. Pins 4 and 5 on the Arduino have been used but as a software serial library that will be used any digital pins will do.

Software

When the Arduino is connected there will be a sign on message, this will vary from device to device but the BV4108 looks like this:

There are two important things to note:

  1. Most LCD displays will only work on 5V so make sure the Arduino 5V supply is used, if in doubt check it with a meter. The actual voltage measured in this particular set up was 4.91V which is as you can see fine.
  2. The first byte that is sent to a VT100 device must have a value of 13. This is vitally important as it sets the Baud rate any other byte or any errors at this stage and the display is not likely to respond to any commands.

The above is all that s needed to create an "Hello World" program. In this instance BSerial is used as the library so this must be downloaded (top of page) and placed with all the other libraries. In the set up section, after setting the baud rate (which can be up to 19200 for this library - check data sheet first to see if it is on the devices list) byte 13 is sent to the display. This also MUST be followed by a delay as it takes the device some time to decide which rate to use.

Sending commands to the display can be dun by 'puts' (put string), the Arduino compiler will recognise the 'e' as escape and substitute the byte value 0xb1 (27) and so it is very simple to control the device. As an example to place fred on the 3rd line down second column would be this:

puts("e[3;2Hfred");

The data sheet for this device gives row and column positioning as esc[<row>;<col>H which is exactly what has been specified above.

Receiving

In the above example the BV4308 device has very little information to give to the user, unlike a device with input the BV4618 for example and so it doesn't really need the RC line connected. However this device will output the firmware version to the serial port so it may be worth looking at.

The main loop has been expanded. The command esc[9c (puts("e[9c")) will get the firmware version and output it to the serial port. The problem with receiving serial is: how do we know when the information has been sent and complete? In this case the command will output something like "1.4" to indicate the version number which is 3 bytes, but suppose the the firmware changed to say "1.41", that's 4 bytes. The method used by this and most other BV serial devices is to use a unique byte to tell the serial interface that the transmission has ended, this is called an ACK (acknowledge) and can be set to any character, by default it is set to byte value 42 which is the ASCII character '*'.

This is sent when any command is used, to wlak through what is happening start at the delay(200):

delay(200): The purpose of this is to allow the serial interface to receive any ACK characters from previous commands, in this case the clear screen will have generated one.

bv.flush(): This clears out any bytes in the buffer ready for the next command.

bv.puts("e[9c"): When this command is sent to the display the display will respond by sending the firmware version to the serial port, the TX line. This information will be buffered by the serial library as it comes in.

while(timeout){}: This whole loop is responsible for getting bytes from the serial buffer and placing them in the character buffer b[], the timeout variable is used in case something goes wrong and '*' is never received, the count variable keeps track of the number of bytes received and bv.buffer() returns the number of bytes in the buffer. The result of all of this is that b[] will be filled by characters from the serial buffer until '*' is encountered at which point the while loop terminates. An alternative would be to simply use a delay that will be big enough to ensure that all the characters have been received, simple but less efficient.

The last few lines position the text and display it.

There are timing issues with all serial communication, it must be remembered that you are communicating with an external device and this may need time. One of the biggest pitfalls is to assume that bytes will be available immediately. Of course this while loop could be placed in a function say 'gets()' for get string and take care of all the timing issues, the program would wait for 'gets()' to complete.

VT100 Library

This library has a couple of input functions that simply getting bytes out of a VT100 device when using ACK.

This is the same program that will display the firmware version to the display but uses a built in library function. The initialisation is slightly different in that the ACK charater is specified along with the Baud rate, the constructor functions has the following options:

xyz.begin(<Baud rate>,<delay>,<ack byte value>)

In this sketch the delay has been set to 0. If ACK was not available then a larger delay could be used and the alternative constructor could be used:

xyz.begin(<Baud rate>,<delay>)

This display has the ACK switched on by default but some devices are off by default. If this is the case and ACK s used then remember to issue the command that turns on ACK before receiving any bytes. Now instead of the while delay loop as above the xyz.cmds() class is used. The description for this is as follows:

xyz.cmds(<command>,<buffer>,<max>)

This class will send the specified command to the display in the above example that is "e[9c". It will then wait and fill the buffer 'b' with the text that is returned from the device. Max is used to protect the supplied buffer should more characters be received than expected. It should be set to 1 less then the buffer size that is supplied.

There is also a cmd() class:

cmd(<command>)

This class will return an integer and is intended for results that are numerical. It could not be used in the above because the firmware version is not a number but a string.