I have the Sure Electronics 24x16 (Green) display board working perfectly with an Arduino Duemilanove using the excellent Miles Burton code. The code is made for the red display, and required a small tweak to get the coordinates transposed correctly for the green one to display correctly. If anyone wants the modification, I can post it right away.
My problem is I also have eight 0832's and the demo board, and I wanted to keep the Arduino working with the 24x16. I'm an okay C programmer, but for my life I can't work out why it doesn't want to communicate. This problem's not related to the Arduino, so I plead on the good will of yourself and the admins to hopefully let me post this one, as the manual is no help at all and so are the customer service at Sure.
It works fine with the supplied (but very limited) Java program, but after setting the demo board for 8 displays and opening the serial port /dev/ttyUSB0 for 9600,8,N,1 and then sending it the four-byte string and the 16 characters it wants, I get nothing. If I keep sending it strings, it eventually goes crazy or displays garbled characters. I can post my current broken C source if it helps.
If anyone got it working without the supplied prog, could you please let me know how you did it?
I'll be back to post my final program for everyone on the forums.
Well, I worked it out anyway. Here's the code if anyone does or doesn't want it. The thing is, I can't get it to complete the serial transfer before the file descriptor is closed. I used a usleep as a nasty workaround...
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#define SERIAL_DEVICE_NAME "/dev/ttyUSB0"
int fd;
int ttySwrite(int fd, char *chars) {
if(write(fd, chars, strlen(chars)) < 0)
{
perror("write failed!\n");
return 0;
}
return 1;
}
void ttySinit(int fd) { // Set port for 9600,8,N,1
struct termios opt;
tcgetattr(fd, &opt);
cfsetispeed(&opt, B9600);
cfsetospeed(&opt, B9600);
// opt.c_cflag |= (CLOCAL);
// opt.c_cflag &= ~PARENB;
// opt.c_cflag &= ~CSTOPB;
// opt.c_cflag &= ~CSIZE;
// opt.c_cflag |= CS8;
opt.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
| INLCR | IGNCR | ICRNL | IXON);
opt.c_oflag &= ~OPOST;
opt.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
opt.c_lflag |= FLUSHO;
opt.c_cflag &= ~(CSIZE | PARENB | CSTOPB);
opt.c_cflag |= CS8;
tcsetattr(fd, TCSANOW, &opt);
}
int main(int argc, char **argv) {
if(argc!=3)
{
perror("Usage:\n"
" %s LINE_NUMBER MESSAGE\n"
"where LINE_NUMBER is 1 or 2 and MESSAGE is a string up to 16 characters");
exit(1);
return(1);
}
if((fd = open(SERIAL_DEVICE_NAME, O_WRONLY | O_NOCTTY | O_NDELAY)) == -1)
{
perror("Error opening serial port\n");
exit(1);
return(1);
}
ttySinit(fd);
char sCmd[254] = { 0xFE, 0x47, 0x01, 0x01, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0' };
int j=0;
while((argv[2][j] != '\0') && j<16)
{
sCmd[j+4] = argv[2][j];
j++;
}
sCmd[20] = 0x00; // just in case
sCmd[3] = ( argv[1][0] == '1' ? 0x01 : 0x02 ); // select the line on the LED display
if (!ttySwrite(fd, sCmd))
{
perror("Write failed\n");
close(fd);
exit(1);
return 1;
}
tcdrain(fd); // THIS DOESN'T DO ANYTHING!
usleep(50000); // WE NEED THIS TO MAKE IT WORK INSTEAD
close(fd);
exit(0);
return(0);
}