Help finding example code for LCD display.

Hi all.

I'm trying to make an ultrasonic sensor display to an LCD screen (well more complicated than that, but I should be able to handle the rest).

I've got this display:
https://www.ebay.com.au/itm/2-4-inch-Screen-6-Digit-7-Segment-LCD-Display-Module-White-Backlit-for-Arduino/132418597568?_trkparms=aid%3D111001%26algo%3DREC.SEED%26ao%3D1%26asc%3D20160908105057%26meid%3D97fa0dd7b6594c82b54b789c98663568%26pid%3D100675%26rk%3D1%26rkt%3D15%26sd%3D132418597568&_trksid=p2481888.c100675.m4236&_trkparms=pageci%253A037394ad-fc32-11e7-8649-74dbd1808732%257Cparentrq%253A089998fe1610ab6ad325111affe82133%257Ciid%253A1

But the pin readouts don't match up with most of the tutorials I can find.

I found a really confusing example from google fu, and combined it with my ultrasonic sketch:

//Demo for 2.4in 6-digit Segment LCD display module
//by Open-Smart Team and Catalex Team
//catalex_inc@163.com
//Store: http://www.aliexpress.com/store/1199788
// http://dx.com
//Demo Function:
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;

#define CS 13 //Pin 13 as chip selection output
#define WR 12 //Pin 12 as read clock output
#define DATA 7 //Pin 7 as Serial data output

#define CS1 digitalWrite(CS, HIGH)
#define CS0 digitalWrite(CS, LOW)
#define WR1 digitalWrite(WR, HIGH)
#define WR0 digitalWrite(WR, LOW)
#define DATA1 digitalWrite(DATA, HIGH)
#define DATA0 digitalWrite(DATA, LOW)

#define sbi(x, y) (x |= (1 << y)) /��λ����x�ĵ�yλ/
#define cbi(x, y) (x &= ~(1 <<y )) /�������x�ĵ�yλ/
#define uchar unsigned char
#define uint unsigned int

//����HT1621������
#define ComMode 0x52 //4COM,1/3bias 1000 010 1001 0
#define RCosc 0x30 //�ڲ�RC����(�ϵ�Ĭ��)1000 0011 0000
#define LCD_on 0x06 //��LCD ƫѹ������1000 0000 0 11 0
#define LCD_off 0x04 //�ر�LCD��ʾ
#define Sys_en 0x02 //ϵͳ������ 1000 0000 0010
#define CTRl_cmd 0x80 //�������
#define Data_cmd 0xa0 //�������

/0,1,2,3,4,5,6,7,8,9,A,b,C,c,d,E,F,H,h,L,n,N,o,P,r,t,U,-, ,/
const char num[]={0x7D,0x60,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B,0x77,0x4F,0x1D,0x0E,0x6E,0x1F,0x17,0x67,0x47,0x0D,0x46,0x75,0x37,0x06,0x0F,0x6D,0x02,0x00,};
//0 1 2 3 4 5 6 7 8 9
char dispnum[6]={0x00,0x00,0x00,0x00,0x00,0x00};

void SendBit_1621(uchar sdata,uchar cnt)//�����ݳ���
{
//data �ĸ�cnt λд��HT1621����λ��ǰ
uchar i;
for(i=0;i<cnt;i++)
{
WR0;
if(sdata&0x80) DATA1;
else DATA0;
WR1;
sdata<<=1;
}
}

void SendCmd_1621(uchar command) //������
{
CS0;
SendBit_1621(0x80,4); //д���־�롰100����9 λcommand �������
SendBit_1621(command,8); //û��ʹ�е�����ʱ����������Ϊ�˱�̷���
CS1; //ֱ�ӽ�command �����λд��0��
}

void Write_1621(uchar addr,uchar sdata) //�����ݺ��������
{
addr<<=2;
CS0;
SendBit_1621(0xa0,3); //д���־�롰101��
SendBit_1621(addr,6); //д��addr �ĸ�6λ
SendBit_1621(sdata,8); //д��data ��8λ
CS1;
}

void HT1621_all_off(uchar num) //ȫ��Ϩ��1621
{
uchar i;
uchar addr=0;
for(i=0;i<num;i++)
{
Write_1621(addr,0x00);
addr+=2;
}
}

void HT1621_all_on(uchar num) //ȫ������1621
{
uchar i;
uchar addr=0;
for(i=0;i<num;i++)
{
Write_1621(addr,0xff);
addr+=2;
}
}

void Init_1621(void)//��ʼ��1621
{
SendCmd_1621(Sys_en);
SendCmd_1621(RCosc);
SendCmd_1621(ComMode);
SendCmd_1621(LCD_on);
}

void displaydata(int p) //��ʾ��������pΪС����λ��
{
uchar i=0;
switch(p)
{
case 1:
sbi(dispnum[0],7);
break;
case 2:
sbi(dispnum[1],7);
break;
case 3:
sbi(dispnum[2],7);
break;
default:break;
}
for(i=0;i<=5;i++)
{
Write_1621(i2,dispnum);*

  • }*
    }
    void setup()
    {
    pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
    pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    Serial.begin(9600); // Starts the serial communication

  • pinMode(CS, OUTPUT); //*

  • pinMode(WR, OUTPUT); //*

  • pinMode(DATA, OUTPUT); //*

  • CS1;*

  • DATA1;*

  • WR1;*

  • delay(50);*

  • Init_1621();*

  • HT1621_all_on(16); //ȫ������1621*

  • delay(1000);*

  • HT1621_all_off(16); //ȫ��Ϩ��1621 *

  • delay(1000);*

  • displaydata(1);//light on the first decimal point starting from the right side*

  • dispnum[5]=num[5];*

  • dispnum[4]=num[4];*

  • dispnum[3]=num[3];*

  • dispnum[2]=num[2];*

  • dispnum[1]=num[1];*

  • dispnum[0]=num[0];*

  • sbi(dispnum[5],7); //��ʾ���ͼ�궥��*

  • //cbi(dispnum[5],7); //������ͼ�궥��*

  • sbi(dispnum[4],7); //��ʾ���ͼ���в�*

  • //cbi(dispnum[4],7); //������ͼ���в�*

  • sbi(dispnum[3],7); //��ʾ���ͼ��ײ�*

  • //cbi(dispnum[3],7); //������ͼ��ײ�*

  • //Write_1621(0,num[0]); //��1λ��ʾ0*

  • //Write_1621(2,num[28]); //��2λ��ʾ' '*

  • //Write_1621(4,num[2]); //��3λ��ʾ2*

  • //Write_1621(6,num[28]); //��4λ��ʾ' '*

  • //Write_1621(8,num[4]); //��5λ��ʾ4*

  • //Write_1621(10,num[5]); //��6λ��ʾ5*
    }
    void loop() {

  • // put your main code here, to run repeatedly:*
    {
    // Clears the trigPin
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
    duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
    distance= duration*0.034/2;
    // Prints the distance on the Serial Monitor
    Serial.print("Distance: ");
    Serial.println(distance);
    }
    }[/quote]
    I'd think I'd need to add:
    > if (Serial.available()) {
    > // wait a bit for the entire message to arrive
    > delay(100);
    > // clear the screen
    > lcd.clear();
    > // read all the available characters
    > while (Serial.available() > 0) {
    > // display each character to the LCD
    > lcd.write(Serial.read());
    But there isn't a library used which sets up 'lcd', and I couldn't find an equivalent in the sketch, unless I'm blind.
    Anybody have a better sketch example that'd work on my display, or point me in the direction of what I'm doing wrong?
    Thanks in advance.

I've got this display

I know that e-bay did not make that display. You will HAVE to find a link to the manufacturer's site.

I'd think I'd need to add:

That first comment is complete nonsense. There are far better ways to deal with incoming serial data than burying your head in the sand for a while, emerging just KNOWING that the complete message has arrived (which you have no way of knowing before you read it).

I found a really confusing example from google fu, and combined it with my ultrasonic sketch:

Why? The FIRST thing to do is to make the device display KNOWN data.

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

The sketch seems to contain everything you need. Libraries are there for convenience; feel free to create one yourself.

If you leave loop() empty and remove everything after the second delay from setup(), I would expect that all segments (and decimal dots?) light up for one second. Does that indeed happen? Leave the rest of the code as as.

Next you can start working through the code and try to display a letter or number; maybe use the commented last lines in setup() for that (the KNOWN data that PaulS mentions).

Here it is on dealextreme 2.4'' 6-Digit 7 Segment LCD Display Module White Backlit for Arduino - Free shipping - DealExtreme

On that page there is an address for a download but I did not go any further

Thanks for the replies everybody.

It was through DX that I found the initial example:(using code [] now).

//Demo for 2.4in 6-digit Segment LCD display module
//by Open-Smart Team and Catalex Team
//catalex_inc@163.com
//Store: http://www.aliexpress.com/store/1199788
//      http://dx.com
//Demo Function: 



#define CS	 13  //Pin 13 as chip selection output
#define WR	 12  //Pin 12 as read clock	output
#define DATA 7	//Pin 7 as Serial data output

#define CS1    digitalWrite(CS, HIGH) 
#define CS0    digitalWrite(CS, LOW)
#define WR1    digitalWrite(WR, HIGH) 
#define WR0    digitalWrite(WR, LOW)
#define DATA1  digitalWrite(DATA, HIGH) 
#define DATA0  digitalWrite(DATA, LOW)


#define sbi(x, y)  (x |= (1 << y))   /*��λ����x�ĵ�yλ*/
#define cbi(x, y)  (x &= ~(1 <<y ))  /*�������x�ĵ�yλ*/       
#define uchar   unsigned char 
#define uint   unsigned int 

//����HT1621������ 
#define  ComMode    0x52  //4COM,1/3bias  1000    010 1001  0  
#define  RCosc      0x30  //�ڲ�RC����(�ϵ�Ĭ��)1000 0011 0000 
#define  LCD_on     0x06  //��LCD ƫѹ������1000     0000 0 11 0 
#define  LCD_off    0x04  //�ر�LCD��ʾ 
#define  Sys_en     0x02  //ϵͳ������ 1000   0000 0010 
#define  CTRl_cmd   0x80  //д�������� 
#define  Data_cmd   0xa0  //д��������   


/*0,1,2,3,4,5,6,7,8,9,A,b,C,c,d,E,F,H,h,L,n,N,o,P,r,t,U,-, ,*/
const char num[]={0x7D,0x60,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B,0x77,0x4F,0x1D,0x0E,0x6E,0x1F,0x17,0x67,0x47,0x0D,0x46,0x75,0x37,0x06,0x0F,0x6D,0x02,0x00,};
                 //0      1      2      3        4      5      6       7       8       9
char dispnum[6]={0x00,0x00,0x00,0x00,0x00,0x00};



void SendBit_1621(uchar sdata,uchar cnt)//�����ݳ���  
{ 
	//data �ĸ�cnt λд��HT1621����λ��ǰ
	uchar i; 
	for(i=0;i<cnt;i++) 
	{ 
		WR0;
		if(sdata&0x80) DATA1; 
		else DATA0;
		WR1;
		sdata<<=1; 
	} 
}

void SendCmd_1621(uchar command) //������
{ 
	CS0; 
	SendBit_1621(0x80,4);    //д���־�롰100����9 λcommand ������� 
	SendBit_1621(command,8); //û��ʹ�е�����ʱ����������Ϊ�˱�̷��� 
	CS1;                     //ֱ�ӽ�command �����λд��0�� 
}

void Write_1621(uchar addr,uchar sdata) //�����ݺ��������
{ 
	addr<<=2; 
	CS0; 
	SendBit_1621(0xa0,3);     //д���־�롰101�� 
	SendBit_1621(addr,6);     //д��addr �ĸ�6λ 
	SendBit_1621(sdata,8);    //д��data ��8λ 
	CS1; 
} 

void HT1621_all_off(uchar num) //ȫ��Ϩ��1621
{
	uchar i; 
	uchar addr=0; 
	for(i=0;i<num;i++) 
	{ 
		Write_1621(addr,0x00); 
		addr+=2; 
	} 
}

void HT1621_all_on(uchar num) //ȫ������1621
{
	uchar i; 
	uchar addr=0; 
	for(i=0;i<num;i++) 
	{
		Write_1621(addr,0xff); 
		addr+=2; 
	} 
}

void Init_1621(void)//��ʼ��1621 
{
	SendCmd_1621(Sys_en);
	SendCmd_1621(RCosc);    
	SendCmd_1621(ComMode);  
	SendCmd_1621(LCD_on);
}    

void displaydata(int p) //��ʾ��������pΪС����λ��
{
	uchar i=0;
	switch(p)
	{
		case 1:
		sbi(dispnum[0],7);
		break;
		case 2:
		sbi(dispnum[1],7);
		break;
		case 3:
		sbi(dispnum[2],7);
		break;
		default:break;
	}
	for(i=0;i<=5;i++) 
	{
		Write_1621(i*2,dispnum[i]);
	}
}



void setup() 
{


  pinMode(CS, OUTPUT); // 
  pinMode(WR, OUTPUT); // 
  pinMode(DATA, OUTPUT); //
  CS1;
  DATA1;
  WR1;
  delay(50);
  Init_1621();
  HT1621_all_on(16); //ȫ������1621
  delay(1000);
  HT1621_all_off(16); //ȫ��Ϩ��1621  
  delay(1000);

  displaydata(1);//light on the first decimal point starting from the right side
  dispnum[5]=num[5];
  dispnum[4]=num[4];
  dispnum[3]=num[3];
  dispnum[2]=num[2];
  dispnum[1]=num[1];
  dispnum[0]=num[0];
  
  sbi(dispnum[5],7);   //��ʾ���ͼ�궥��
  //cbi(dispnum[5],7); //������ͼ�궥��
  sbi(dispnum[4],7);   //��ʾ���ͼ���в�
  //cbi(dispnum[4],7); //������ͼ���в�
  sbi(dispnum[3],7);   //��ʾ���ͼ��ײ�
  //cbi(dispnum[3],7); //������ͼ��ײ�
  
  
  
  //Write_1621(0,num[0]);  //��1λ��ʾ0
  //Write_1621(2,num[28]);	//��2λ��ʾ' '
  //Write_1621(4,num[2]);  //��3λ��ʾ2
  //Write_1621(6,num[28]);	//��4λ��ʾ' '
  //Write_1621(8,num[4]);  //��5λ��ʾ4
  //Write_1621(10,num[5]); //��6λ��ʾ5

}

void loop() {
  // put your main code here, to run repeatedly:


}

I'm still very much a beginner with the code side of things. The code seems to work, the decimal point displays after a minute, I'm just having trouble figuring out how to make the ultrasonic sensor display. I usually hack together different sketches until I have something that works, or read the // next to the example to see what I need to change around to make work, but I think it's in chinese or something.

Some more fiddling:

 Write_1621(0,num[0]);  //��1λ��ʾ0
  Write_1621(2,num[2]);	//��2λ��ʾ' '
  Write_1621(4,num[2]);  //��3λ��ʾ2
  Write_1621(6,num[2]);	//��4λ��ʾ' '
  Write_1621(8,num[4]);  //��5λ��ʾ4
  Write_1621(10,num[5]); //��6λ��ʾ5

That code changes what displays on the display (once I took away the comment //). So if I change any of the numbers, it changes the display. So now I need to figure out how to make it display the "distance" value that's uploading the the serial monitor.

Will continue my fiddle (I learn as I fiddle usually, then get stuck and swear.).