LCD03

Motor, Servo, Speech etc.

Moderator: chris

LCD03

Postby HiQ » Sun Oct 02, 2011 6:45 pm

Hi all

I have been pondering over the lcd 03. using C#2010 pro I am trying and have been for 2 weeks to make a bar graph showing current (Live) cpu status.

here is my code...
private void button13_Click(object sender, EventArgs e)
{
string cpu = "CPU:";
// byte user_char = 255;
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 4;
SerBuf[4] = 12;
SerBuf[5] = 03;
SerBuf[6] = 2;
SerBuf[7] = 1;
Write(8);
Read(1);
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = (byte)cpu.Length;
byte[] TempBuf1 = Encoding.ASCII.GetBytes(cpu);

for (int x = 0; x < cpu.Length; x++) SerBuf[x + 4] = TempBuf1[x];

Write(cpu.Length + 4);
Read(1);
int bars;
int balance;
int bargraph;
int percent;
int i;
int bwidth = 16;
int maxbar = bwidth * 3;

int a = 1;

while (a < 1000)
{

a++;

bargraph = (int)(performanceCounter1.NextValue());
percent = (bargraph / 3);
bars = percent /3;
balance = percent % 3;
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 3;
SerBuf[4] = 03;
SerBuf[5] = 2;
SerBuf[6] = 5;
Write(7);
Read(1);

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 255;

for (i = 0; i < bars; i++) ;

Write(5);
Read(1);

switch (balance)
{
case 0:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 17;
Write(5);
Read(1);
break;

case 1:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 255;

Write(5);
Read(1);
break;

case 2:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 255;

Write(5);
Read(1);
break;

}
Thread.Sleep(100);
}

I have it running but it does not update any more than 2 Cells of the LCD and not 1 - 16 as required. I have gone "Code Blind" from staring at it for so long. Any help would be appreciated.

I have seen that some LCD's are smart and have graphicg capabilities, does this one? Thanks again Chris
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Mon Oct 03, 2011 5:44 pm

You really need a few more comments so everyone can see what you are trying to achieve with each section, I have a couple of questions:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 255;

255 (oxff) is a space in ascii, did you want a solid shape 254 (0xfe)?

What does (int)(performanceCounter1.NextValue()); typically return? A great debug is to use MessageBox.Show(performanceCounter1.NextValue().tostring());
This will put a popup on screen with the captured value so you can examine retrieved values at any point, or you could use a breakpoint and examine the registers.
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: LCD03

Postby HiQ » Mon Oct 03, 2011 7:05 pm

Hi again

I have commented my code which is below. I have had to use ASC 255 which i know is a space on the PC but on the LCD (which was bought from yourselves adn I queried the ASCII codes previously) it is the Block character.

(int)(performanceCounter1.NextValue()); it is a WMI whichy returns an Integer value of the current CPU usage. I already have a debug box on the program further up which opens a seperate window for debugging and making sure that the values are returned properly. the above statement does return the correct values (or as near as damn it!) for what I want. The bar graph only has to be a rough representation at this point in time really just to get the thing working. I have added code which does something more, actually moves the cursor block as I wanted but not completely in the fashion that I want it.

any help would be useful.. If you don't understand the code clip then I could send you the complete program (for what it is at the moment) or you could just tell me how to program a barcode using these LCD screens and the USB ISS.

many many thanks in advance... Chris

private void button13_Click(object sender, EventArgs e) // bargraph to show CPU usage
{
string cpu = "CPU%:[ ]"; // default screen and brackets to house the Bar Graph
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 4;
SerBuf[4] = 12; // clear screen
SerBuf[5] = 03; // screen pos ident
SerBuf[6] = 4; // line 4 of 4 lines
SerBuf[7] = 1; // char pos 1 of 20
Write(8);
Read(1);

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = (byte)cpu.Length;
byte[] TempBuf1 = Encoding.ASCII.GetBytes(cpu);
for (int x = 0; x < cpu.Length; x++) SerBuf[x + 4] = TempBuf1[x];

Write(cpu.Length + 4);
Read(1);


// init
int bars;
int balance;
int bargraph;
int percent;
int bwidth = 10;
int maxbar = bwidth * 3;
int a = 1;

// loop
while (a < 3000)
{

Application.DoEvents(); // while running, allow other events
a++;

// performance counter is a read only CPU (all cores all threads) meter value 0 to 100 %
// on my laptop this reads as between 17 and 40 % so the graph would show a bargraph of 15 - 40%
bargraph = (int)(performanceCounter1.NextValue());
percent = (bargraph / 3);
bars = percent / 3;
balance = percent % 3;

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 3;
SerBuf[4] = 3;
SerBuf[5] = 4;
SerBuf[6] = (byte)(bars + 7); // place the bars which are written below, between the 2 brackets
Write(7);
Read(1);

// this section of code writes the char 255 to the lcd in the bar graph.
switch (balance)
{
case 0:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 255;
Write(5);
Read(1);

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 32;
Write(5);
Read(1);

break;

case 1:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 17;
Write(5);
Read(1);

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 17;
Write(5);
Read(1);

break;

case 2:

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 255;
Write(5);
Read(1);

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 32;
Write(5);
Read(1);

break;

}

// thread sleep (75 miliseconds)
Thread.Sleep(75);
}
}
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Tue Oct 04, 2011 10:22 am

I think you are trying to do something like:

string cpu;
byte bars;
int x;

REPLACE xxxxxxxxxxxxxx FROM LINE BELOW WITH SPACES, THE FORUM REMOVES IT!!
cpu = "CPU%:[xxxxxxxxxxxxxx"; // declare string and set it empty
bars = (byte) (performanceCounter1.NextValue() / 7.6); //100/7.6 = 13 (maximum number of bars between brackets)
for (x = 1; x < bars; x++) cpu[x + 5] = 254; // add blocks to string
cpu[bars+6] = ']' // finish with close bracket

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = (byte)cpu.Length;
for (x = 0; x < cpu.Length; x++) SerBuf[x + 4] = cpu[x];

Write(cpu.Length + 4);
Read(1);
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: LCD03

Postby HiQ » Tue Oct 04, 2011 11:36 am

Hi,

Im not sure of your code?? I have entered it but it comes up with the following error's

Property or indexer 'string.this[int]' cannot be assigned to -- it is read only
Constant value 254 cannot be converted to a char
for (x = 1; x < bars; x++) cpu[x + 5] = 254; // add blocks to string

property or indexer 'string.this[int]' cannot be assigned to -- it is read only
cpu[bars + 6] = ']';// finish with close bracket

cannot implicityly convert type 'char' to 'byte'. an explicit conversion exists (are you missing a cast?)
for (x = 0; x < cpu.Length; x++) SerBuf[x + 4] = cpu[x];

:oops: Im not experianced enough to resolve this please can you help, I am not really sure that you know what I want. I need a bar graph (moving) to display current <<total CPU activity>> which is measured 0 - 100 so the input from cpu at this second is 10% relevant number of bars should appear in brackets. Next second input from cpu is 30% bars update to show relevant bars within the brackets, update frequency is every second which is handled by a system timer to reduce the the programs process time. Program is then able to reduce to system tray while LCD continues to display relevant info.

That about sums it up really. There is one other thing. I have a data file which is about 300 chars long but the LCD buffer accepts no more than 60 chars including spaces and then displays nothing. Is there a way around this? I have tried but have not been successful.

I have only been using C# for 4 months there about so I apologise for my incompetence.
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Tue Oct 04, 2011 12:28 pm

Ok, try this:

string cpu;
byte bars;
int x;

cpu = "CPU%:["; // declare string and set start text
bars = (byte) (performanceCounter1.NextValue() / 7.6); //100/7.6 = 13 (maximum number of bars between brackets)
for (x = 1; x < bars; x++) cpu += char.ConvertFromUtf32(255); // add blocks to string
while(cpu.length < 19) cpu += ' ';
cpu += ']' // finish with close bracket

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = (byte)cpu.Length;
for (x = 0; x < cpu.Length; x++) SerBuf[x + 4] = (byte) cpu[x];

Write(24);
Read(1);
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: LCD03

Postby HiQ » Tue Oct 04, 2011 1:16 pm

:P Yes thanks that works.
Thank you very much...

As I mentioned in my previos post what is the best way display text from a text file in a continuous stream on one line on the display?

I have tried but I just cannot see it.

Again Thanks in advance
Chris
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Tue Oct 04, 2011 2:21 pm

You will need to use a pointer into the array and increment it each time.

I.E

// global variables:
int x = 0;
string file;

// in the function:
string line;

if(x+20 < file.length) line = file.substring(x,20); // print up 20 characters of data
else{ // theres not 20 characters left!
line = file.substring(x,file.length-x); //print up remainder of text
while(line.length < 19) line += ' '; //fill any remaining characters with space
x++; // increment pointer
}
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: LCD03

Postby HiQ » Tue Oct 04, 2011 2:36 pm

Thank you very much, this solves 3 problems in one...


Thank you, :D , you have made my month...

In case I forgot to say it, thanks again Chris
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby HiQ » Tue Oct 04, 2011 3:55 pm

:roll:
Hi Chris - Again

I have tries to implement your code but Blank LCD

Any chance of a quick view???

:Code:

private void button15_Click(object sender, EventArgs e)
{
int xy = 0;

// nonsence text instead of file on this instance
string file = "That is the way the cookie crumbles, said the little old lady to the little old man who had shandy in the street after eating a lolly";

// Clear the screen
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 12;
Write(5);
Read(1);

// in the function:
string line;
int loopy;

SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = (byte)file.Length;

for (loopy = 0; loopy < file.Length; loopy++)
{
if (xy + 20 < file.Length)
{
line = file.Substring(xy, 20); // print up 20 characters of data
byte[] TempBuf1 = Encoding.ASCII.GetBytes(file);
for (int x = 0; x < loopy; x++) SerBuf[x + 4] = TempBuf1[loopy + x];
Write(file.Length + 4);
Read(1);
Thread.Sleep(500);
}
else
{ // theres not 20 characters left!
line = file.Substring(xy, file.Length - xy); //print up remainder of text
while (line.Length < 19) line += ' '; //fill any remaining characters with space
xy++; // increment pointer
}
}



}

I see what you are saying but I cannot get any display...

Thanks
Chris
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Wed Oct 05, 2011 9:55 am

I think you missed the point of the substring, you are still thinking of passing the complete file length!
Try:

private void button15_Click(object sender, EventArgs e)
{
// nonsence text instead of file on this instance
string file = "That is the way the cookie crumbles, said the little old lady to the little old man who had shandy in the street after eating a lolly";

// Clear the screen
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 1;
SerBuf[4] = 12;
Write(5);
Read(1);

// in the function:
string line;
int loopy;

for (loopy = 0; loopy < file.Length; loopy++)
{
wait_for_buffer_space();
if (loopy + 20 < file.Length) line = file.Substring(loopy, 20); // print up 20 characters of data
else
{ // theres not 20 characters left!
line = file.Substring(loopy, file.Length - loopy); //print up remainder of text
while (line.Length < 21) line += ' '; //fill any remaining characters with space
}
byte[] TempBuf1 = Encoding.ASCII.GetBytes(line);
for (int x = 0; x < 20; x++) SerBuf[x + 4] = TempBuf1[x];
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = 20; //always a text string length of 20!

Write(24);
Read(1);
Thread.Sleep(500);
}
}

private void wait_for_buffer_space() // wait for 20 bytes free in buffer
{
SerBuf[0] = 0;
while(SerBuf[0] < 20){
SerBuf[0] = 0x55;
SerBuf[1] = 0xC7;
SerBuf[2] = 0;
SerBuf[3] = 1;

Write(4);
Read(1);
Thread.Sleep(2);
}
}

I am writing this off the cuff so you may need to debug
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: LCD03

Postby HiQ » Wed Oct 05, 2011 10:38 am

:oops:

Ok I mis understood.

Thank you very much, it has opened my eyes a little bit more.

So the text file can be unlimited size but does it require a special EOF marker. I don't think so as I think VS2010 will handle the file.

Merci beaucoupe

Chris
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Wed Oct 05, 2011 10:51 am

Its nothing to do with VS2010 not being able to handle it, it's the LCD03 screen width is 20 bytes. the frame you were passing included:
Code: Select all
SerBuf[0] = 0x55;
SerBuf[1] = 0xC6;
SerBuf[2] = 0;
SerBuf[3] = (byte)file.Length;   


file.length was about 300 chars long in your earlier post!
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Re: LCD03

Postby HiQ » Fri Oct 07, 2011 10:57 am

8)
all is clear now... Everything works but one last question on the subject, on my Bar Graph I have a char which quickly grows and shrinks smoothly depending on the % input, well it should do and on your bar graph it displays the amount of % then clears the line then reprints the (new) %. Is there a way to get a pure smooth shrink and grow bar graph. I have trawled the c# forums and even quized microsoft technet; but they say it is down to the LCD display its self. My code at the top of this thread is supposed to draw the display, if the next refresh value is more it draws some more blocks and if the value is less i draws blanks from the right hand side of the screen.

Some LCD's I have seen (US Crystal Displays) have a very unique display where each of the segments can be used to indicate a more accurate representation of your input. I have looked at one of these displays closely and I come to the conclusion that it can only be down to programming. Don't get me wrong, if I wanted an easy life I could have bought a Crystal display and used something like LCD smartie, and never have learned to annoy people like you with questions, but seriously;

Do you have any suggestions?

Here is another example of what I have seen which convinced me: http://www.devx.com/dotnet/Article/32067/1954

Thanks for all of your help
Chris
HiQ
 
Posts: 22
Joined: Tue Mar 01, 2011 6:41 pm

Re: LCD03

Postby chris » Fri Oct 07, 2011 11:18 am

Rather than redrawing a complete line on the bar graph you should just set or clear the applicable blocks that have changed on the bar graph.
User avatar
chris
 
Posts: 172
Joined: Wed Nov 08, 2006 3:13 pm
Location: Norfolk, England

Next

Return to Drivers

Who is online

Users browsing this forum: No registered users and 0 guests