Go Down

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

AWOL

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

I think you may have got into an HTML, not programming, mindset.
"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 have to make this and it should work!

But i think i got the problem

Arduino Uno
An ATmega328 running at 16 MHz with auto-reset, using the optiboot bootloader (115200 baud, 0.5 KB).

When checking in Bascom AVR what the error rate is.. it is almost 8%.

Can i change it somewhere?

Grootvalk

I do an Electric, Installatin, Designer and construction education.

Now i have to work for my education and get to learn more than i need.

so ive created all this for an easy work and everyone can program.

AWOL

Quote
so ive created all this for an easy work and everyone can program

Imagine how much more work you could get done, if you didn't have to do all that typing.
"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

I only have to change some values in the HTML page and simply press convert and done.

But i cant get it right now, cus it fails.

Nick Gammon


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


Centering text at runtime is pretty trivial stuff.

Quote
When checking in Bascom AVR what the error rate is.. it is almost 8%.

Can i change it somewhere?


Can you quote the documentation on that?

Quote
I only have to change some values in the HTML page and simply press convert and done.


And then what? You deploy these gadgets?

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


I was hoping for a picture of the end-product. Whatever it does.

Quote
I do an Electric, Installatin, Designer and construction education.


That's great that you are doing all this. But if I may humbly suggest, a bit more practice on the programming side before you write HTML code that produces C++ code that runs on a microprocessor.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

Quote
But i cant get it right now, cus it fails

Time for a new approach.
"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



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


Centering text at runtime is pretty trivial stuff.

Quote
When checking in Bascom AVR what the error rate is.. it is almost 8%.

Can i change it somewhere?


Can you quote the documentation on that?

Documentation for Error % can be found at: http://www.wormfood.net/avrbaudcalc.php
BAscom AVR has a built-in error shown, just set it to 16MHZ and baudrate you have an the rror % is shown.



Quote
I only have to change some values in the HTML page and simply press convert and done.


And then what? You deploy these gadgets?

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


I was hoping for a picture of the end-product. Whatever it does.

Quote
I do an Electric, Installatin, Designer and construction education.


That's great that you are doing all this. But if I may humbly suggest, a bit more practice on the programming side before you write HTML code that produces C++ code that runs on a microprocessor.
The HTML form only generates the cade ATM. su copy paste compile and upload.

robtillaart

#23
Apr 18, 2011, 10:49 am Last Edit: Apr 18, 2011, 10:51 am by robtillaart Reason: 1
Hi Grootvalk,

I had a quick look at your code and I think you are running out of variable RAM, an Arduino has only 2K.

You need to use functions to eleminate double typing as Nick said. As I am in a very good mood today I did that for you (also to move the discussion forward). The code below is ~100 lines iso 2000(?), it compiles and as far as I can see it does almost the same as yours (the leading zero's in the display are missing). So try this code and let us know if it works for you.

Succes,
Rob

Code: [Select]


#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd( 7, 6, 5, 4, 3, 2);

int A = 0;
int B = 0;
int C = 1;

void displayError(int code)
{
 lcd.setCursor (0 , 0 );
 lcd.print("Error 01");
 lcd.setCursor (0 , 1 );
 lcd.print("Code    ");
 lcd.print(code);
 C = code;
}

void setup()
{
 // Define Output
 pinMode(13, OUTPUT); // sets the digital pin as output LED
 // Define Input
 pinMode(A0, INPUT); // input A0 - Bit 0
 pinMode(A1, INPUT); // input A1 - Bit 1
 pinMode(A2, INPUT); // input A2 - Bit 2
 pinMode(A3, INPUT); // input A3 - Bit 3
 pinMode(A4, INPUT); // input A4 - Bit 4
 pinMode(A5, INPUT); // input A5 - Bit 5
 pinMode( 8, INPUT); // input D8 - Bit 6
 pinMode( 9, INPUT); // input D9 - Bit 7
 // Pull up Resistors
 digitalWrite(A0, HIGH); // Pull up resistor for A0 - Bit 0
 digitalWrite(A1, HIGH); // Pull up resistor for A1 - Bit 1
 digitalWrite(A2, HIGH); // Pull up resistor for A2 - Bit 2
 digitalWrite(A3, HIGH); // Pull up resistor for A3 - Bit 3
 digitalWrite(A4, HIGH); // Pull up resistor for A4 - Bit 4
 digitalWrite(A5, HIGH); // Pull up resistor for A5 - Bit 5
 digitalWrite( 8, HIGH); // Pull up resistor for D8 - Bit 6
 digitalWrite( 9, HIGH); // Pull up resistor for D9 - Bit 7

 // set up the LCD's & Company Logo:
 lcd.begin(40, 2);
 Serial.begin(9600);
}


void loop()
{
 if (A == 0 )
 {
   B = 0;
   if (digitalRead(14) == LOW){
     B = B + 1;
   }
   if (digitalRead(15) == LOW){
     B = B + 2;
   }
   if (digitalRead(16) == LOW){
     B = B + 4;
   }
   if (digitalRead(17) == LOW){
     B = B + 8;
   }
   if (digitalRead(18) == LOW){
     B = B + 16;
   }
   if (digitalRead(19) == LOW){
     B = B + 32;
   }
   if (digitalRead( 8) == LOW){
     B = B + 64;
   }
   if (digitalRead( 9) == LOW){
     B = B + 128;
   }

   if (B == C)
   {
     A = 10;
   }
   else {
     lcd.clear();
     A = 5;
   }
 } // End A == 0

 if (A == 5 )
 {
   displayError(B);  // call to function above
   A = 10;
 } // End A == 5


 if (A == 10 )
 {
   delay(100);
   Serial.println();
   Serial.println(A);
   Serial.println(B);
   Serial.println(C);
   A = 0;
 } // End A == 10

} // End of Loop

Compiles smoothly => Binary sketch size: 4846 bytes (of a 30720 byte maximum)
Thats far less than the 27K

--- UPDATE ---
If the C++ code is generated from somewhere you must modify the codegenerator accordingly ..

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grootvalk


Hi Grootvalk,

I had a quick look at your code and I think you are running out of variable RAM, an Arduino has only 2K.

You need to use functions to eleminate double typing as Nick said. As I am in a very good mood today I did that for you (also to move the discussion forward). The code below is ~100 lines iso 2000(?), it compiles and as far as I can see it does almost the same as yours (the leading zero's in the display are missing). So try this code and let us know if it works for you.

Succes,
Rob

Code: [Select]



#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd( 7, 6, 5, 4, 3, 2);

int A = 0;
int B = 0;
int C = 1;

void displayError(int code)
{
  lcd.setCursor (0 , 0 );
  lcd.print("Error 01");
  lcd.setCursor (0 , 1 );
  lcd.print("Code    ");
  lcd.print(code);
  C = code;
}

void setup()
{
  // Define Output
  pinMode(13, OUTPUT); // sets the digital pin as output LED
  // Define Input
  pinMode(A0, INPUT); // input A0 - Bit 0
  pinMode(A1, INPUT); // input A1 - Bit 1
  pinMode(A2, INPUT); // input A2 - Bit 2
  pinMode(A3, INPUT); // input A3 - Bit 3
  pinMode(A4, INPUT); // input A4 - Bit 4
  pinMode(A5, INPUT); // input A5 - Bit 5
  pinMode( 8, INPUT); // input D8 - Bit 6
  pinMode( 9, INPUT); // input D9 - Bit 7
  // Pull up Resistors
  digitalWrite(A0, HIGH); // Pull up resistor for A0 - Bit 0
  digitalWrite(A1, HIGH); // Pull up resistor for A1 - Bit 1
  digitalWrite(A2, HIGH); // Pull up resistor for A2 - Bit 2
  digitalWrite(A3, HIGH); // Pull up resistor for A3 - Bit 3
  digitalWrite(A4, HIGH); // Pull up resistor for A4 - Bit 4
  digitalWrite(A5, HIGH); // Pull up resistor for A5 - Bit 5
  digitalWrite( 8, HIGH); // Pull up resistor for D8 - Bit 6
  digitalWrite( 9, HIGH); // Pull up resistor for D9 - Bit 7

  // set up the LCD's & Company Logo:
  lcd.begin(40, 2);
  Serial.begin(9600);
}


void loop()
{
  if (A == 0 )
  {
    B = 0;
    if (digitalRead(14) == LOW){
      B = B + 1;
    }
    if (digitalRead(15) == LOW){
      B = B + 2;
    }
    if (digitalRead(16) == LOW){
      B = B + 4;
    }
    if (digitalRead(17) == LOW){
      B = B + 8;
    }
    if (digitalRead(18) == LOW){
      B = B + 16;
    }
    if (digitalRead(19) == LOW){
      B = B + 32;
    }
    if (digitalRead( 8) == LOW){
      B = B + 64;
    }
    if (digitalRead( 9) == LOW){
      B = B + 128;
    }

    if (B == C)
    {
      A = 10;
    }
    else {
      lcd.clear();
      A = 5;
    }
  } // End A == 0

  if (A == 5 )
  {
    displayError(B);  // call to function above
    A = 10;
  } // End A == 5


  if (A == 10 )
  {
    delay(100);
    Serial.println();
    Serial.println(A);
    Serial.println(B);
    Serial.println(C);
    A = 0;
  } // End A == 10

} // End of Loop

Compiles smoothly => Binary sketch size: 4846 bytes (of a 30720 byte maximum)
Thats far less than the 27K

--- UPDATE ---
If the C++ code is generated from somewhere you must modify the codegenerator accordingly ..






Thanks for that code, but its just without my error code thins which i must have. with yours i can only use 1 error. but checking out the RAM.

Worst case is that i have to send characters manually?

robtillaart

Quote
Thanks for that code, but its just without my error code thins which i must have.


What are thins? (I'm not native English, sorry)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Quote
with yours i can only use 1 error.

No the function displayError() takes care of all your errors defined with the value B (which is set by means of 8 switches)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grootvalk

You mean i must make a lot of Void ?

robtillaart

Quote
Worst case is that i have to send characters manually?

Have you tried running my sample code?
If so where did it go wrong?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

Quote
You mean i must make a lot of Void ?

Don't understand your question.. please rephrase

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up