lcd created random caracters

hi,
we have a problem with the LCD screen. after the program runs, in a random time the comunication between the screen and the arduino is lost. the program in the arduino is running corectly but the screen is down.
as you can see in the photo, arduino takes power from usb form a mobilepfone charger. for the motors we have a 29A switching power supply and the max current of the robot is 2A.
can you help us?
this is the robot arm working.

robot.jpg

Where is your code? Post it in FULL

Your wire up is too messy, you need to move communication cables far from things that can cause any interference, such as motors.

for the LCD driver i use the code from the example. we dont use any spesial funcions or any interupts.

for the LCD driver i use the code from the example. we dont use any spesial funcions or any interupts.

"Where is your code? Post it in FULL"

Which part of this are you having trouble understanding?

Don

here is the code: in 2 messages.

#include <Servo.h>
#include <LiquidCrystal.h>
#include <Button.h>

Servo myservo0; // create servo object to control a servo
Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int eftase =0;
int x=0;
int oldx=0;

int servonum=0;

LiquidCrystal lcd(13, 12, 8, 7, 4, 2);

Button BPano = Button(A4,PULLUP);
Button BKato = Button(A5,PULLUP);
Button BSin = Button(A3,PULLUP);
Button BMion = Button(A1,PULLUP);
Button BEnter = Button(A2,PULLUP);
Button BPlay = Button(A0,PULLUP);
Button Fast = Button(1,PULLUP);

char* Menou[6]={"0 peristrofi basis ",
"1 1 joint ",
"2 2 joint ",
"3 karpos ",
"4 peristrofi karpou ",
"5 dagkana "};

int Oria[2][6]={{85,21,21,21,0,40},
{95,156,156,156,179,179}};

int RenewScreen=1;
int programma[21][6]={
{87,90,90,90,90,178},
{91,90,130,90,90,90},
{91,90,130,50,0,90},
{91,90,130,50,0,179},
{91,156,130,50,150,179},
{91,130,156,21,150,179},
{91,130,156,21,150,40},
{92,120,60,150,90,40},
{92,120,60,21,150,40},
{90,156,156,21,150,40},
{90,156,156,21,150,150},
{91,156,156,21,150,150},
{91,156,90,100,90,150},
{91,21,156,100,179,150},
{91,21,156,50,179,40},
{91,90,100,50,90,40},
{92,156,156,50,179,40},
{92,156,156,159,179,40},
{92,156,21,159,90,179},
{92,156,90,90,90,179},
{90,90,90,90,90,90},

};

int SeiraProgrammatos=0;
int aferesi[6]={0,0,0,0,0,0};
int parousathesi[6]={0,0,0,0,0,0};
float imitono=0;

int MenouNum=0;

void setup() {

lcd.begin(20, 4);

Serial.begin(9600);
myservo0.attach(3,800,2200);// basi
myservo1.attach(5,700,2300);//j1 basis
myservo2.attach(6,700,2300);//j2 askonas oxi
myservo3.attach(9,700,2300);//j3 karpos
myservo4.attach(10,850,2150);//j4 peristrofi
myservo5.attach(11,850,2150);//gripper
}

void loop() {

Buttons();
ScreenView();

myservo0.write(programma[SeiraProgrammatos][0]);
myservo1.write(programma[SeiraProgrammatos][1]);
myservo2.write(programma[SeiraProgrammatos][2]);
myservo3.write(programma[SeiraProgrammatos][3]);
myservo4.write(programma[SeiraProgrammatos][4]);
myservo5.write(programma[SeiraProgrammatos][5]);

}

screen.ino (1.27 KB)

motor_euresi_thesis.ino (2.22 KB)

Buttons_testing.ino (6.65 KB)

void Buttons(){

if(BPano.uniquePress()) {
MenouNum++;
if (MenouNum>5) MenouNum=0;
RenewScreen=1;
}
else
{

}
if(BKato.uniquePress()) {
MenouNum–;
if (MenouNum<0) MenouNum=5;
RenewScreen=1;

}
else
{

}
if(BSin.uniquePress()) {
if (Fast.isPressed()){
programma[SeiraProgrammatos][MenouNum]=programma[SeiraProgrammatos][MenouNum]+10;
}
else
{
programma[SeiraProgrammatos][MenouNum]++;
}
programma[SeiraProgrammatos][MenouNum]=min(programma[SeiraProgrammatos][MenouNum], Oria[1][MenouNum]);
RenewScreen=1;
}
else
{

}
if(BMion.uniquePress()) {
if (Fast.isPressed()){
programma[SeiraProgrammatos][MenouNum]=programma[SeiraProgrammatos][MenouNum]-10;
}
else
{
programma[SeiraProgrammatos][MenouNum]–;
}
programma[SeiraProgrammatos][MenouNum]=max(programma[SeiraProgrammatos][MenouNum], Oria[0][MenouNum]);
RenewScreen=1;
}
else
{

}
if(BEnter.uniquePress()) {

RenewScreen=1;

SeiraProgrammatos++;
// gia na min peidaei
if(SeiraProgrammatos!=0&&eftase==0){

for (int y=0;y<6;y++){

programma[SeiraProgrammatos][y]= programma[(SeiraProgrammatos-1)][y];
}}
if (SeiraProgrammatos>20){
SeiraProgrammatos=0;
eftase =1;
}}

if(BPlay.uniquePress()) {

RenewScreen=1;
Serial.println(“syntetagmenes:”);

for (int y=0;y<20;y++){
for (int x=0;x<5;x++){
Serial.print(programma[y]);
Serial.print(" ");

}
Serial.println(programma[y][5]);

}
Serial.println("");
Serial.println("");

for (int gramikodika=0;gramikodika<20;gramikodika++){ // gia na trezoyn oles oi grammes

for(int moter=0;moter<6;moter++){//gia na treksei 6 fores dld apo 0 eos 5
aferesi[moter] = programma[gramikodika+1][moter]-programma[gramikodika][moter];
parousathesi[moter]=programma[gramikodika][moter];
}

for (int xxx=0;xxx<180;xxx++){
imitono=0.500sin((xxx71/4068.000)+4.6778)+0.500;
for(int parousa=0;parousa<6;parousa++){//gia na treksei 6 fores dld apo 0 eos 5
parousathesi[parousa]=imitono*aferesi[parousa]+programma[gramikodika][parousa];
}

myservo0.write(parousathesi[0]);
myservo1.write(parousathesi[1]);
myservo2.write(parousathesi[2]);
myservo3.write(parousathesi[3]);
myservo4.write(parousathesi[4]);
myservo5.write(parousathesi[5]);
delay(1);

}
delay(200);
}
}

}

void ScreenView(){
if (RenewScreen==1){

RenewScreen=0;

lcd.setCursor(0, 3);
//lcd.print(MenouNum);
lcd.print(" ");
lcd.setCursor(0, 3);
//lcd.print(MenouNum);
lcd.print(Menou[MenouNum]);

lcd.setCursor(0, 0);
//lcd.print(MenouNum);
lcd.print(" ");
lcd.setCursor(0, 0);
delay(1);
lcd.print(Oria[0][MenouNum]);

lcd.setCursor(17, 0);
//lcd.print(MenouNum);
lcd.print(" ");
lcd.setCursor(17, 0);
delay(1);
lcd.print(Oria[1][MenouNum]);

lcd.setCursor(8, 0);
//lcd.print(MenouNum);
lcd.print(" ");
delay(1);
lcd.setCursor(8, 0);
lcd.print(programma[SeiraProgrammatos][MenouNum]);

lcd.setCursor(12, 2);
//lcd.print(MenouNum);
lcd.print("seira:");
delay(1);
lcd.setCursor(18, 2);
lcd.print(SeiraProgrammatos);

lcd.setCursor(0, 1);
//lcd.print(MenouNum);
lcd.print(" ");
delay(1);
lcd.setCursor(0, 1);
lcd.print(programma[SeiraProgrammatos][0]);
lcd.setCursor(3, 1);
lcd.print(programma[SeiraProgrammatos][1]);
lcd.setCursor(7, 1);
lcd.print(programma[SeiraProgrammatos][2]);
lcd.setCursor(10, 1);
lcd.print(programma[SeiraProgrammatos][3]);
lcd.setCursor(14, 1);
lcd.print(programma[SeiraProgrammatos][4]);
lcd.setCursor(17, 1);
lcd.print(programma[SeiraProgrammatos][5]);
}
}

this is my full code. if this can help you.

Aside from your code not in the proper format or tags, this is not how you attach your servos.

Serial.begin(9600);
myservo0.attach(3**,800,2200**);// basi
myservo1.attach(5**,700,2300**);//j1 basis
myservo2.attach(6**,700,2300**);//j2 askonas oxi
myservo3.attach(9**,700,2300**);//j3 karpos
myservo4.attach(10**,850,2150**);//j4 peristrofi
myservo5.attach(11**,850,2150**);//gripper
}

What are all these extra numbers? Look at this example, http://arduino.cc/en/Tutorial/Sweep

all the servos dont have the same parameters.
please see: Servo - Arduino Reference
the meaning of this numders are the servo.attach(pin, min, max)
min (optional): the pulse width, in microseconds, corresponding to the minimum (0-degree) angle on the servo (defaults to 544)
max (optional): the pulse width, in microseconds, corresponding to the maximum (180-degree) angle on the servo (defaults to 2400)

i think that the format is making difficult to read it and doesnt have any effect to the performace. do you have some tips & tricks or general rules for the correct code format?
i am engineer mechanic so, the code is not my best.

Ok, my mistake. Usually the min/max are not used, but ok. As for proper format, Ctrl + T in your arduino software will fix the format, or just go under Edit >> auto format.

Are you using an Arduino Mega or Uno? Judging by the size of your code, you may be running out of memory. If you are using a Uno, I suggest you upgrade to a Mega.

we want maximum acurancy and efficience of the motors, so we are using all the opions we have. (acurancy in hobby servos... :fearful:)
Our code is: 10.318 bytes (at maximum 32.256 byte)
is any way to mesure the free memory? we use uno.