Go Down

Topic: Arduino Programming error? (Read 2 times) previous topic - next topic

Grootvalk

Hello,

I have made program which should show me 255 codes on a LCD display of 40*2

After programming them with my code the most weird text is showing up. when making the code smaller: up to 180 codes, it suddenly works fine...

Can some1 help me with this problem?

Code up to 180 codes:
http://www.text-upload.com/read.php?id=71938&c=3854221

Code up to 250 codes
http://www.text-upload.com/read.php?id=71941&c=5388691



AWOL

You must really, really like typing.
Code: [Select]
// Print error Code 20
if ( B == 20){
lcd.setCursor (0 , 0 );
lcd.print("Error 01");
lcd.setCursor (0 , 1 );
lcd.print("Code 020");
C = 20;}

// error Code 20 Printed

// Print error Code 21
if ( B == 21){
lcd.setCursor (0 , 0 );
lcd.print("Error 01");
lcd.setCursor (0 , 1 );
lcd.print("Code 021");
C = 21;}
// error Code 21 Printed
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Nick Gammon

Quote
Code: [Select]
while(A == 5 ){

// about 1500 lines of mumbo-jumbo which does not change A

A = 10;

} // End A == 5


This is a joke, right?

What is the purpose of it?
http://www.gammon.com.au/electronics

AWOL

Do you think this would make your sketch any shorter?
Code: [Select]
  int hundreds = B / 100;
  int tens     = (B % 100) / 10;
  int units    = B % 10;
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grootvalk

Well i learned to write HTML and JAVA so the code just pops out.

Its for a error display on my installation.

The loop works fine, but the text on the display with the 255 codes is showing:

226
227

Which never get defined.

Nick Gammon

Let's hope your code doesn't have to do much else than display error messages:

Code: [Select]
Binary sketch size: 27450 bytes (of a 32256 byte maximum)

That's 85% of your program memory gone already.
http://www.gammon.com.au/electronics

Nick Gammon


The loop works fine, but the text on the display with the 255 codes is showing:

226
227

Which never get defined.


I didn't understand that bit.
http://www.gammon.com.au/electronics

Nick Gammon


... when making the code smaller: up to 180 codes, it suddenly works fine...


Yes, well make the code smaller. Here's a tip ... You have this 255 times:

Code: [Select]
if ( B == XXXX){
lcd.setCursor (0 , 0 );
lcd.print("Error 01");
lcd.setCursor (0 , 1 );
lcd.print("Code XXXX");
C = XXXX;}


Do you think you might be able to reduce that to doing that part once?
http://www.gammon.com.au/electronics

Grootvalk

It acts like a converter of my PLC which sends a byte to my Arduino Nano, Which will be converted from 24V to 5V using 78L05Z and a optocoupler.

The remaining program memory is for editing the text to be shown.

when uploading the 255 code viewer i get:

Upperline 226
Lowerline 227

And when throwing Bit 0 tot he ground 227 = 227 + 1
And when throwing Bit 1 tot he ground 227 = 227 + 2
And 226 just stands there... but there should always stand "error 01"

The code cant get smaller because my HTML script is able to change "lcd.setcursor( 0,0 ) to the range of 0-1,0-39


Let's hope your code doesn't have to do much else than display error messages:

Code: [Select]
Binary sketch size: 27450 bytes (of a 32256 byte maximum)

That's 85% of your program memory gone already.

AWOL

Quote
The code cant get smaller because my HTML script is able to change "lcd.setcursor( 0,0 ) to the range of 0-1,0-39

It can get a lot smaller.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Grootvalk


Quote
The code cant get smaller because my HTML script is able to change "lcd.setcursor( 0,0 ) to the range of 0-1,0-39

It can get a lot smaller.


only the set.cursor for the upperline when not defined, but it wont need to get smaller, it just needs to work..
Its strange that up to 180 it works great and any higher and it fails..

Grootvalk



... when making the code smaller: up to 180 codes, it suddenly works fine...


Yes, well make the code smaller. Here's a tip ... You have this 255 times:

Code: [Select]
if ( B == XXXX){
lcd.setCursor (0 , 0 );
lcd.print("Error 01");
lcd.setCursor (0 , 1 );
lcd.print("Code XXXX");
C = XXXX;}


Do you think you might be able to reduce that to doing that part once?


i can not do this part once, because they can all be different.
And a HTML form creates everything for me.
cant this problem be fixed?

Nick Gammon

You seriously, seriously need to revisit how variables work. The places you used them, like here:

Code: [Select]
while(A == 5 ){

...

A = 10;

} // End A == 5


... don't make any sense. That "loop" will only execute once. Why have the "while"?

And what the heck are A, B, C? How about names that give a clue as to their purpose?

And then when you could use a variable to reduce 1500 lines of code to 10 you say you can't do it.

Quote
The code cant get smaller because my HTML script is able to change "lcd.setcursor( 0,0 ) to the range of 0-1,0-39


Do you mean, the HTML script is going to change the Arduino sketch, and then re-upload the changed sketch, on-the-fly in some bizarre way?

Quote
And a HTML form creates everything for me.


Hmm, I think you do mean that.
http://www.gammon.com.au/electronics

Nick Gammon


The code cant get smaller because my HTML script is able to change "lcd.setcursor( 0,0 ) to the range of 0-1,0-39


It could still output: lcd.setcursor( x,y )

or does each error message appear in a different location?
http://www.gammon.com.au/electronics

Grootvalk


You seriously, seriously need to revisit how variables work. The places you used them, like here:

Code: [Select]
while(A == 5 ){

...

A = 10;

} // End A == 5


... don't make any sense. That "loop" will only execute once. Why have the "while"?

And what the heck are A, B, C? How about names that give a clue as to their purpose?

And then when you could use a variable to reduce 1500 lines of code to 10 you say you can't do it.

Quote
The code cant get smaller because my HTML script is able to change "lcd.setcursor( 0,0 ) to the range of 0-1,0-39


Do you mean, the HTML script is going to change the Arduino sketch, and then re-upload the changed sketch, on-the-fly in some bizarre way?

Quote
And a HTML form creates everything for me.


Hmm, I think you do mean that.


The HTML thing is for real. check http://img39.imageshack.us/i/wwwud.jpg/

A = Meant for the steps, Convert the Inputs to 0-255, which gets to "B"
When the error code for B is printed B = C

When B != C a new message gets printed on the LCD

and afterwards a LED wil flash which is currently removed.

and the text will get centered in the midle of the LCD, so it gets different yes.

Go Up