LCD only display the 1st time , doesn't changes


hi , i'm using arduino uno r3 , cytron's smk53 gps shield , dfrobot's l298p shield v1.2 project . both original written code can found at   http://tutorial.cytron.com.my/2015/03/11/using-cytron-skm53-gps-shield-with-ct-uno/   and   https://www.dfrobot.com/wiki/index.php?title=arduino_motor_shield_(l298n)_(sku:dri0009)

i had slight idea pwm , i'm have no clue pll motor shield part after reading wiki . , on mini project i'm using pll .

code: [select]

#include <liquidcrystal.h>
#include <softwareserial.h>
#include <tinygps.h>

liquidcrystal lcd(8,9,13,12,11,10); //pin initialization lcd
softwareserial ss(2,3); //software serial pin skm53 shield
tinygps gps;

//const int buttonkey=a0; //button pin lcd keypad shield
boolean newdata=false;
boolean state=0;
float flat;
float flon;
float initiallatitude=3.0635199546; //latitude (horizontal line) above (north side;+ve) equator
float initiallongitude=101.61813354; //longitde (vertical line) right (east side;+ve) of prime meridian

int e1=6; //direction control motor 1
int e2=5; //direction control motor 2
int m1=7; //enable control motor 1
int m2=4; //enable control motor 2
string incomingcommand ;

void setup(){
  //pinmode(buttonkey,input);
  lcd.begin(16,2);
  lcd.print("acquiring gps ......");
  ss.begin(9600);
  //serial.begin(9600);
  pinmode(e1,output);
  pinmode(e2,output);
  pinmode(m1,output);
  pinmode(m2,output);
}

void loop(){
  getgpsposition();
  printpositiononlcd();
  eastsidegliding();
  westsidegliding();
}

void getgpsposition(){
  while(ss.available()){
    char c=ss.read();

    if(gps.encode(c)){
      newdata=true;
      gps.f_get_position(&flat,&flon);
    }
  }
}

void printpositiononlcd(){
  if(newdata){
    lcd.clear();

    if(state==0){
      lcd.setcursor(0,0);
      lcd.print("lat ");
      lcd.setcursor(4,0); //print position (x,y)
      lcd.print(flat,10); //(......,precision)
 
      lcd.setcursor(0,1);
      lcd.print("lon ");
      lcd.setcursor(4,1);
      lcd.print(flon,10);
    }

    //newdata=false;
    delay(1000); //refresh time
  }
}

//set parachute glide east side
void eastsidegliding(){
  if(newdata){
    if(flon<initiallongitude){
      int i=1;
   
      while(flon<initiallongitude){
        digitalwrite(m1,low);
        digitalwrite(m2,high);
        analogwrite(e2,255);
        delay(3000);
        digitalwrite(m2,low);
        i=i+1;
   
        delay(10000); //let parachute glide 10s
 
        getgpsposition();
        printpositiononlcd();

        newdata=false;
       
        if(flon==initiallongitude){
          digitalwrite(m1,low);
          digitalwrite(m2,high);
          analogwrite(e2,0);
          delay(i*3000);
          digitalwrite(m2,low);
          break;
        }
      }
    }
  }
}

//set parachute glide west side
void westsidegliding(){
  if(newdata){
    if(flon>initiallongitude){
      int i=1;
   
      while(flon>initiallongitude){
        digitalwrite(m1,high);
        digitalwrite(m2,low);
        analogwrite(e1,255);
        delay(3000);
        digitalwrite(m1,low);
        i=i+1;
   
        delay(10000); //let parachute glide 10s
 
        getgpsposition();
        printpositiononlcd();

        newdata=false;
       
        if(flon==initiallongitude){
          digitalwrite(m1,high);
          digitalwrite(m2,low);
          analogwrite(e1,0);
          delay(i*3000);
          digitalwrite(m1,low);
          break;
        }
      }
    }
  }
}

/*
void commandfromserialmonitortomotor(){
  while(serial.available()==0){
  }

  incomingcommand=serial.readstring();

  //forward movement both motors
  if(incomingcommand=="q"){
    digitalwrite(m1,high);
    digitalwrite(m2,high);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }
  else if(incomingcommand=="w"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }

  //backward movement both motors
  if(incomingcommand=="a"){
    digitalwrite(m1,high);
    digitalwrite(m2,high);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  else if(incomingcommand=="s"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }

  //forward movement motor 1
  if(incomingcommand=="e"){
    digitalwrite(m1,high);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }
  else if(incomingcommand=="r"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }

  //backward movement motor 1
  if(incomingcommand=="d"){
    digitalwrite(m1,high);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  else if(incomingcommand=="f"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }

  //forward movement motor 2
  if(incomingcommand=="t"){
    digitalwrite(m1,low);
    digitalwrite(m2,high);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }
  else if(incomingcommand=="y"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }

  //backward movement motor 2
  if(incomingcommand=="g"){
    digitalwrite(m1,low);
    digitalwrite(m2,high);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  else if(incomingcommand=="h"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
}
*/


this code modified . , i'm working on longitude part 1 tamiya gearbox (my mini project have 2 tamiya gearbox 2 motors in 1 gearbox operating on latitude part , 2 more motors in gearbox operating on longitude part , i'm still in testing phase .)

from original codes , understand motor shield 1 not gps shield 1 include library file i'm not familiar . , of gps code followed original 1 .

the overall of written code (or @ least planned this) . firstly , latitude , longitude position @ standing position . , show latitude , longitude data on lcd current position . if gps position present , motor move (for on longitude side) base on  detected position , initial position .

i still can't tell whether motor rotated correctly based on code data gps position shows 1st detected position on lcd . after , though placed when in getgpsposition() , printpositiononlcd() functions inside while loop , doesn't overwrite 1st data latest 1 .

i think there error around here still couldn't figure , how fix . newdata variable smells fishy me .
code: [select]

//set parachute glide east side
void eastsidegliding(){
  if(newdata){
    if(flon<initiallongitude){
      int i=1;
   
      while(flon<initiallongitude){
        digitalwrite(m1,low);
        digitalwrite(m2,high);
        analogwrite(e2,255);
        delay(3000);
        digitalwrite(m2,low);
        i=i+1;
   
        delay(10000); //let parachute glide 10s
 
        getgpsposition();
        printpositiononlcd();

        newdata=false;
       


help appreciated :) . thank !

use attached modified code - added serial , serial.println - , post exact serial monitor output


code: [select]
[code]

#include <liquidcrystal.h>
#include <softwareserial.h>
#include <tinygps.h>

liquidcrystal lcd(8, 9, 13, 12, 11, 10); //pin initialization lcd
softwareserial ss(2, 3); //software serial pin skm53 shield
tinygps gps;

//const int buttonkey=a0; //button pin lcd keypad shield
boolean newdata = false;
boolean state = 0;
float flat;
float flon;
float initiallatitude = 3.0635199546; //latitude (horizontal line) above (north side;+ve) equator
float initiallongitude = 101.61813354; //longitde (vertical line) right (east side;+ve) of prime meridian

int e1 = 6; //direction control motor 1
int e2 = 5; //direction control motor 2
int m1 = 7; //enable control motor 1
int m2 = 4; //enable control motor 2
string incomingcommand ;

void setup() {
serial.println(__func__);
  //pinmode(buttonkey,input);
  lcd.begin(16, 2);
  lcd.print("acquiring gps ......");
  ss.begin(9600);
  serial.begin(9600);
  pinmode(e1, output);
  pinmode(e2, output);
  pinmode(m1, output);
  pinmode(m2, output);
serial.println(__func__);
}

void loop() {
serial.println(__func__);
  getgpsposition();
  serial.println("getgpsposition();");
  printpositiononlcd();
  serial.println("printpositiononlcd();");
  eastsidegliding();
  serial.println("eastsidegliding();");
  westsidegliding();
  serial.println("westsidegliding();");
  delay(5000);
serial.println(__func__);
}

void getgpsposition() {
serial.println(__func__);
  while (ss.available()) {
    char c = ss.read();
    if (gps.encode(c)) {
      newdata = true;
      gps.f_get_position(&flat, &flon);
    }
  }
serial.println(__func__);
}

void printpositiononlcd() {
serial.println(__func__);

  if (newdata) {
    lcd.clear();
    if (state == 0) {
      lcd.setcursor(0, 0);
      lcd.print("lat ");
      lcd.setcursor(4, 0); //print position (x,y)
      lcd.print(flat, 10); //(......,precision)
      lcd.setcursor(0, 1);
      lcd.print("lon ");
      lcd.setcursor(4, 1);
      lcd.print(flon, 10);
    }
    //newdata=false;
    delay(1000); //refresh time
  }
serial.println(__func__);
}

//set parachute glide east side
void eastsidegliding() {
serial.println(__func__);
  if (newdata) {
    if (flon < initiallongitude) {
      int = 1;
      while (flon < initiallongitude) {
        digitalwrite(m1, low);
        digitalwrite(m2, high);
        analogwrite(e2, 255);
        delay(3000);
        digitalwrite(m2, low);
        = + 1;
        delay(10000); //let parachute glide 10s
        getgpsposition();
        printpositiononlcd();
        newdata = false;
        if (flon == initiallongitude) {
          digitalwrite(m1, low);
          digitalwrite(m2, high);
          analogwrite(e2, 0);
          delay(i * 3000);
          digitalwrite(m2, low);
          break;
        }
      }
    }
  }
serial.println(__func__);
}

//set parachute glide west side
void westsidegliding() {
serial.println(__func__);
  if (newdata) {
    if (flon > initiallongitude) {
      int = 1;
      while (flon > initiallongitude) {
        digitalwrite(m1, high);
        digitalwrite(m2, low);
        analogwrite(e1, 255);
        delay(3000);
        digitalwrite(m1, low);
        = + 1;
        delay(10000); //let parachute glide 10s
        getgpsposition();
        printpositiononlcd();
        newdata = false;
        if (flon == initiallongitude) {
          digitalwrite(m1, high);
          digitalwrite(m2, low);
          analogwrite(e1, 0);
          delay(i * 3000);
          digitalwrite(m1, low);
          break;
        }
      }
    }
  }
serial.println(__func__);
}

/*
  void commandfromserialmonitortomotor(){
  while(serial.available()==0){
  }

  incomingcommand=serial.readstring();

  //forward movement both motors
  if(incomingcommand=="q"){
    digitalwrite(m1,high);
    digitalwrite(m2,high);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }
  else if(incomingcommand=="w"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }

  //backward movement both motors
  if(incomingcommand=="a"){
    digitalwrite(m1,high);
    digitalwrite(m2,high);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  else if(incomingcommand=="s"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }

  //forward movement motor 1
  if(incomingcommand=="e"){
    digitalwrite(m1,high);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }
  else if(incomingcommand=="r"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }

  //backward movement motor 1
  if(incomingcommand=="d"){
    digitalwrite(m1,high);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  else if(incomingcommand=="f"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }

  //forward movement motor 2
  if(incomingcommand=="t"){
    digitalwrite(m1,low);
    digitalwrite(m2,high);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }
  else if(incomingcommand=="y"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,255);
    analogwrite(e2,255);
  }

  //backward movement motor 2
  if(incomingcommand=="g"){
    digitalwrite(m1,low);
    digitalwrite(m2,high);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  else if(incomingcommand=="h"){
    digitalwrite(m1,low);
    digitalwrite(m2,low);
    analogwrite(e1,0);
    analogwrite(e2,0);
  }
  }
*/

[/code]


Arduino Forum > Using Arduino > Programming Questions > LCD only display the 1st time , doesn't changes


arduino

Comments