Hello,
I bought a
"LCD Display USB (Edition 1)". I can use this very simple device over USB.
Linux says me, that the device is a "cp210x" usb2serial-device. That's ok. "cp210x" creates me the device "/dev/ttyUSB0". This device, i think, should be used to program the LCD.
I searched and i searched, but i didn't find a needable software to program the device. May the communication is no standart? But, no problem, there are only a few commands. They're descripted in a pdf:
http://www.sure-electronics.net/down..._Ver1.0_EN.pdf
For example:
0xFE 0x46 Should turn the backlight off.
0xFE 0x42 0x00 Should turn the backlight on.
0xFE 0x98 0x[01-FE] Should define the the brightness of the LCD.
There are a few other commands. But the only one that works for me is the command to turn the backlight off. Why?
All the other commands do nothing... May be i make something wrong. Or there's a software for this board?
I use this code to configure the LCD:
Code:
//
//DislayTest.cpp
//
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include <sys/types.h>
#define BAUDRATE B9600
#define device "/dev/ttyUSB0"
unsigned char ClearScreen[] = {254,88};
unsigned char backoff[] = { 0xFE, 0x46
//'a', 'b', 'c', 'd',
//'e', 'f', 'g', 'h',
//'i', 'j', 'k', 'l'
};
unsigned char WelcomeMessage[] = {'H','e','l','l','o',' ','W','o','r','l','d','!'};
int main(int argc, char *argv[])
{
struct termios term;
//Open the serial port
int lcd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
//handle errors
if (lcd < 0)
{
printf("Error opening serial port %s\n",device);
return -1;
}
//Setup the serial port 8 data bits, no parity ,1 stopbit, no flow control
term.c_cflag = BAUDRATE | CS8 | CSTOPB | CLOCAL | CREAD;
term.c_iflag = 0;
term.c_oflag = 0;
term.c_lflag = 0;
tcflush(lcd, TCIFLUSH);
tcsetattr(lcd,TCSANOW,&term);
//Write Welcome Message to the display
//write(lcd,ClearScreen,sizeof(ClearScreen));
//write(lcd,WelcomeMessage,sizeof(WelcomeMessage));
write(lcd, backoff, sizeof(backoff));
//Close the display
close(lcd);
return 0;
}
Thanks,
best regards
toredo
-edit-
I listend on my windows machine with the tool portmon the serial port with the device. Then i used LCD Smartie to work with the device. The communication looks ok.
After this i tried to write a c#-tool for the device:
Code:
SerialPort sp = new SerialPort("COM24");
sp.BaudRate = 9600;
sp.StopBits = StopBits.One;
sp.DataBits = 8;
sp.Open();
foreach (int n in Enumerable.Range(1, 254))
{
sp.Write(new byte[] { 0xFE, 0x98, (byte)n }, 0, 3);
Thread.Sleep(10);
}
sp.Close();
It works perfeclty! It's very simple and stupid. It makes the background light in litle steps haler. all other commands work too.
But, i tried this to write in Perl or C. but it never worked? As base i used to C-Code upside. For Perl i used Device::SerialPort.
May my parameters are bad?
Has anyone an idea?
best regards
toredo