Go Down

Topic: Arudino Lcd Shield And Stepper Help (Read 1 time) previous topic - next topic

Trigger80

Now it works fine, BIG THANKS!!


As my prodject is gonna be , stepper,lcd shield,and distance messurment, im almost there now.

I have the lcd shield and distance messurment working in one code.

Then now i have the lcd shield and stepper in on code.

After playing around and try to add this together i find somthing strange.

When i add code for the distance messurment the stepper dont work anymore?:(

Whitout distance messurment:

Code: [Select]
oid loop() {
 
 
  int buttonVal = read_buttons();
  if(buttonVal == btnLEFT)
{
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}

if(buttonVal == btnRIGHT)
{
    digitalWrite(dir_pin, LOW);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);


this works good.

This is whit the distance code, and stops the stepper, "or bottons" so it does not work.

Code: [Select]
void loop() {
 
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance =(((duration/2)/29.4)*2) ;
 
 
  int buttonVal = read_buttons();
  if(buttonVal == btnLEFT)
{
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}

if(buttonVal == btnRIGHT)
{
    digitalWrite(dir_pin, LOW);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);


Im so close to make this work as my very first prodject, any ide of whats goes wrong when i add the distance code?

Thanks

J-M-L

Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

OldSteve

#17
Sep 11, 2016, 04:21 pm Last Edit: Sep 11, 2016, 04:24 pm by OldSteve
Now it works fine, BIG THANKS!!


As my prodject is gonna be , stepper,lcd shield,and distance messurment, im almost there now.

I have the lcd shield and distance messurment working in one code.

Then now i have the lcd shield and stepper in on code.

After playing around and try to add this together i find somthing strange.

When i add code for the distance messurment the stepper dont work anymore?:(

Whitout distance messurment:

Code: [Select]
void loop() {
  
 
  int buttonVal = read_buttons();
  if(buttonVal == btnLEFT)
{
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}

if(buttonVal == btnRIGHT)
{
    digitalWrite(dir_pin, LOW);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}  


this works good.

This is whit the distance code, and stops the stepper, "or bottons" so it does not work.

Code: [Select]
void loop() {
  
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance =(((duration/2)/29.4)*2) ;
  
 
  int buttonVal = read_buttons();
  if(buttonVal == btnLEFT)
{
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}

if(buttonVal == btnRIGHT)
{
    digitalWrite(dir_pin, LOW);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}  


Im so close to make this work as my very first prodject, any ide of whats goes wrong when i add the distance code?

Thanks
Please post all of your code, as it now stands. Edit: Not just 'loop()' It would be good to see your variable definitions, pin allocations etc.

Quote from: J-M-L
what is trigPin and echoPin?
'ping sensor'
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

J-M-L

#18
Sep 11, 2016, 04:24 pm Last Edit: Sep 11, 2016, 04:33 pm by J-M-L
 :)

Being smart OldSteve...

Ok - I mean which pins are they connected to? what are the values of these 2 variables

--> suspecting conflict with LCD pins (and of course would be nice to know they are declared as output and input)

Analog 0   Button (select, up, right, down and left)
Digital 4   DB4
Digital 5   DB5
Digital 6   DB6
Digital 7   DB7
Digital 8   RS (Data or Signal Display Selection)
Digital 9   Enable
Digital 10   Backlit Control

should not mess with those + of course his dir_pin and step_pin, nor D0 and D1 probably for Serial.
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

Trigger80

Here is the complet code, if i remove the parts that is coding the distance sensor the stepper works again.

Code: [Select]
#include <LiquidCrystal.h>
LiquidCrystal LCD(8, 9, 4, 5, 6, 7);

#define step_pin 3    // Define pin 3 as the steps pin
#define dir_pin 2    // Define pin 2 as the direction pin
#define MS1 5     // Define pin 5 as "MS1"
#define MS2 4       // Define pin 4 as "MS2"
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5
#define trigPin 13
#define echoPin 10

int button;
int direction;    // Variable to determine the sense of the motor
int steps = 500;      // Number of steps that you want to execute (for full steps, 200 = 1 turn)

void setup() {
 
   LCD.begin(16,2);
   LCD.setCursor(0,0);
   LCD.print("    Pall 120");
   
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
   
   pinMode(MS1, OUTPUT);     // Configures "MS1" as output
   pinMode(MS2, OUTPUT);     // Configures "MS2" as output
   pinMode(dir_pin, OUTPUT);    // Configures "dir_pin" as output
   pinMode(step_pin, OUTPUT);    // Configures "step_pin" as output
   
   pinMode(btnUP, INPUT_PULLUP);
   pinMode(btnDOWN, INPUT_PULLUP);
   digitalWrite(MS1, LOW);      // Configures the steps division (see above)
   digitalWrite(MS2, LOW);    // Configures the steps division (see above)
   digitalWrite(dir_pin, LOW);   // Sense (HIGH = anti-clockwise / LOW = clockwise) - It can be also changed
   
 
}

void loop() {
 
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance =(((duration/2)/29.4)*2) ;
 
  LCD.setCursor(0,1); 
  LCD.print("                ");
  LCD.setCursor(0,1);   
  LCD.print(distance);
  LCD.print(" cm"); 
  delay(250);
 
  int buttonVal = read_buttons();
  if(buttonVal == btnLEFT)
{
    digitalWrite(dir_pin, HIGH);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);
}

if(buttonVal == btnRIGHT)
{
    digitalWrite(dir_pin, LOW);
    digitalWrite(step_pin, LOW);
    delay(3);
    digitalWrite(step_pin, HIGH);
    delay(3);

 
 

int read_buttons() {
 
 int adc_key_in = analogRead(0);
 
 if (adc_key_in > 1000) return btnNONE;
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;   
}

OldSteve

Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

J-M-L

#21
Sep 11, 2016, 04:36 pm Last Edit: Sep 11, 2016, 04:37 pm by J-M-L
Code: [Select]
#define echoPin 10

pin 10 is the Backlit Control, go for pin 11
Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

Trigger80

all i got left is a1-a5 and tx-rx

OldSteve

#23
Sep 11, 2016, 04:44 pm Last Edit: Sep 11, 2016, 04:46 pm by OldSteve
Get rid of this for starters. what do you think it's doing?:-
Code: [Select]
pinMode(btnUP, INPUT_PULLUP);
pinMode(btnDOWN, INPUT_PULLUP);

Edit: It's almost 1am, so that's my last contribution for the day. Good luck. :)

Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

Trigger80

i used the tx-rx now, but its still not working the stepper, the sensor works, and the lcd works, but not the stepper

And i did remove the pinmode.

J-M-L

Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

Trigger80

on pin 11 i got MS1 from the easy driver

Trigger80

i have the ms1 on pin 12 now and ms2 on pin 13, and i added the right pin in the code, still nothing

so now i got pin 11 pin 10 free

Trigger80

i did mess up the code and the ms1 and ms2. now it works, but the stepper just move smal steps and realy slow::(

J-M-L

Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums
Pas de messages privés SVP

Go Up