To connect arduino and LCD Keypad shield with Pololu A4988 s


I am using Arduino 1 microcontroller connected with the LCD Keypad shield and I would like to connect this complex (arduino1 and LCD Keypad shield) with the A4988 stepper motor driver carrier to control Sanyo Pancake Stepper Motor ( Bipolar 200 Steps/Rev, 42x18.6mm, 5.4V, 1000mA). I would like to use the LCD Keypad shield as a potentiometer .LCD Keypad shield is developed for Arduino compatible boards, to provide a user-friendly interface that allows users to go through the menu, make selections etc. It consists of a 1602 white character blue backlight LCD. The keypad consists of 5 keys — select, up, right, down and left. To save the digital IO pins, the keypad interface uses only one ADC channel. The key value is read through a 5 stage voltage divider (I attach the figure and diagram of the shield) . I have consulted both the file named PololuPres_V3 and the minimal wiring diagram for connecting a microcontroller to an A4988 stepper motor driver carrier (full-step mode), but I have difficult to connect LCD Keypad shield with A4988 stepper motor driver carrier.
I know that :

  1. The driver requires a logic supply voltage (3 – 5.5 V) to be connected across the VDD and GND pins and a motor supply voltage (8 – 35 V) to be connected across VMOT and GND;
  2. The driver is connected with the motor across 2B ( The motor’s 2nd coil’s B terminal),2A ( The motor’s 2nd coil’s A terminal),1A ( The motor’s 1st coil’s A terminal) and 1B ( The motor’s 1st coil’s B terminal).
    Since the Pins 4, 5, 6, 7, 8, 9 and 10 are used to interface with the LCD. I should use other digital pins while connecting to the A4988 stepper motor driver.

My problem is to connect LCD Keypad shield with the following terminals:

  • ENABLE ( I should connect this with GND digital pins)

  • MS1(What is its function in full step modality ? )

  • MS2 (What is its function in full step modality ? )

  • MS3 (What is its function in full step modality ? )

-RST & SLP (I should connect both RST and SLT .What is the pin to connect with LCD Keypad ?)
-STEP & DIR ( I should connect these with 2 digital pins. What are these pins to connect with LCD Keypad ?).

I attach an image of my components

Please , help me.
Thank you

Hello.

I recommend looking into the datasheet of the LCD Keypad Shield to see which digital pins are available for interfacing with the A4988 stepper motor driver carrier (if a pin is used by the LCD, you cannot use it to control the A4988). If you are trying to use full step mode on the A4988 stepper motor driver, you can leave MS1, MS2 and MS3 floating. Also, you could keep ENABLE floating because it is pulled LOW on the board.

I recommend you first start by getting the A4988 working without the LCD in the system.

- Jeremy

Dear Jeremy,

Excuse me for my dalay in reply , but I have any problem with my PC .

I have looked into the datasheet of the LCD Keypad Shield.
The pins used by the LCD are the following : 8, 9, 4, 5, 6 and 7.
I have the following problem: " I want control my stepper motor with Buttons of the LCD Keypad Shield , thus I have necessity to connect LCD Keypad Shield with A4988 "
I want use the motor to operate in not only one direction , but in alternating directions .
I don’t know if I have to connect the GND of LCD keypad shield with ENABLE.
I don’t know if I have to connect RST and SLP buttons.
I don’t know if I have to tie DIR directly to VCC or in contrast to GND.

Can you tell to me the solution at my problems?
Thanks
Falcon

Hi

Dont share any pins with the A4988 and the LCD keypad.
You say the pins used by the LCD are: 8, 9, 4, 5, 6 and 7.
Then you use other I/O pins for the A4988.
If you look at the datasheet for the A4988 you see that you dont have to connect MS1,MS2 & MS3 at all if you are using full step, witch is good to start with atleast.
Enable you also can leave unconnected as JeremyT sais.
Reset pin and sleep pin are tied to VDD by a resistor internaly so these you dont have to connect if you dont want use these functions.
STEP pin you need to connect to an free I/O pin on the aurdino.
same with the DIR pin.
The DIR pin is controlling the direction of the stepmotor as HIGH=CW and LOW=CCW (or other way around depending on how you view it).
The STEP pin needs to be pulsed (go first HIGH then LOW) each time your stepmotor should take a step.
If you want to get the buttons from the LCD Shield to preform some action on the motor you program this in the arduino program.
I dont know if this helped you but by reading the datasheets and looking at stuff that others have done who is similar helps alot.

/Mateo

Thank you very much.
Now, I can connect my arduino 1 with my step motor.
I’m writing the sketch to control of the motor, using the LCD keypad shield as reostat.
If I have have any problems with the sketch , can you help me?
Sincerely
Falcon

I might not be able to offer much help, but I would at least be happy to take a look at your code.

- Jeremy

I’m sorry for delay in reply.

Thank you very much for your disponibility.

My idea is to control both the speed and verse of rotation of my stepper motor .
I don’t know if my code is capable to control the stepper motor , because I have combined 2 codes , but,unfortunately today, I have not still used the code.
What is you opinion about my code? :question:
This is the code.

// ===================================================================
// Example for LCD Keypad Shield from  http://www.nuelectronics.com/
// -------------------------------------------------------------------
// * Modified to use a patched LiquidCrystal library 
// * Alternative routine to detect keys
// ===================================================================
#include <stdio.h>
#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// ===================================================================
// hardware settings: define some values used by the panel and buttons
#define rightKey  0
#define upKey     1
#define downKey   2
#define leftKey   3
#define selectKey 4
#define NUM_KEYS  5
// ===================================================================
// Program parameters
// definisci, per l'opzione 1,il  minimo  valore numerico che apparirà sul display
#define minOpt1   1
// definisci, per l'opzione 1,il  massimo di valore numerico che apparirà sul display
#define maxOpt1 20
int valueOpt1 = 1;
// definisci, per l'opzione 2,il minimo di valore numerico che apparirà sul display
#define minOpt2   1
// definisci, per l'opzione 2,il massimo di valore numerico che apparirà sul display
#define maxOpt2  20
int valueOpt2 = 1;

// definisci i pin collegati ai pulsanti come da schema rightKey=0, upKey= 1,downKey = 2 leleftKey = 3

int motorPinx[] = {0, 1, 2, 3};
// definisci, per l'opzione 1 ovvero 2,il numero e la sequenza dei valori numerici che apparirà sul display
int sequenza[] = {1,2,3,4,5,6.7,8,9,10,11,12,13,14,15,16,17,18,19,20};
int countX  = 0;
int count2X = 0;
//definisci due variabili di tipo  integer rispettivamente per memorizzare il valore letto sul pin 0 e sul pin 1;
int  ora = 0;
int  ant = 0;
int delayTime = 100;
int pinPot = 0;
// definisci i pin collegati ai pulsanti come da schema, pin 0 al senso orario e pin 1 al senso antiorario (verso orario = programMode1 digital ,verso antiorario = programMode2)

#define programMode1 0
#define programMode2 1
int programMode    =  programMode1;
boolean inMainProgram  =  false;

int programmSequence = 0;
#define sequenceModeSelect  0
#define sequenceModeOption  1
#define sequenceModeProgram 2

// first menu line - description of menu level
char sequenceHeader[3][17]  = {"Mode select     ", "Option select   ", "Program start   "};

// second menu line - mode select
char sequenceModes[3][17]   = {"  Mode 1       >", "< Mode 2       >",};
// second menu line - options settings
char sequenceOptions[3][17] = {"Option 1:  ", "Option 2:   "};

void setup() 
{ 
    // initial lcd display while initialize and pc detection
     lcd.begin(16, 2);              // start the library
     lcd.setCursor(0,0);
     lcd.print(" Hello word         ");// print a simple message
  
    pinMode(programMode1, INPUT);
    pinMode(programMode2, INPUT);
    for (countX=0; countX<4; countX++)
  {
    pinMode(motorPinx[countX], OUTPUT);
  }
  pinMode(pinPot, INPUT);
    
    programmSequence = sequenceModeSelect;
    inMainProgram = false;
    
    delay(2000);
    updateScreen();
}

// ===================================================================
// main loop with new key detection
int keyEvent  = -1;
int lastEvent = -1;
int countEvent = 0;

//Key message
char msgs[5][3] = {
    "> ", 
    "^ ", 
    "v ", 
    "< ", 
    "* " };

void updateScreen()
{
    lcd.clear();
    lcd.print(sequenceHeader[programmSequence]);
    lcd.setCursor(0,0);
    switch(programmSequence)
    {
        case sequenceModeSelect:
            menuModeSelect( keyEvent );
            break;
        case sequenceModeOption:
            menuOptionSelect( keyEvent );
            break;
        case sequenceModeProgram:
            break;        
    }
}

void loop() 
{     

       int keyEvent = detectKey();
    if (keyEvent >= 0)
    {
        switch (keyEvent)
        {
            case upKey:
                if (!inMainProgram)
                {
                    if (programmSequence > sequenceModeSelect)
                        programmSequence--;
                    updateScreen();
                }
                break;
            case downKey:
                if (!inMainProgram)
                {
                    if (programmSequence < sequenceModeProgram)
                        programmSequence++;
                    updateScreen();
                }
                break;
            case rightKey:
            case leftKey:
                if (!inMainProgram)
                {
                    switch (programmSequence)
                    {
                        case sequenceModeSelect:
                            menuModeSelect( keyEvent );
                            break;
                        case sequenceModeOption:
                            menuOptionSelect( keyEvent );
                            break;
                        case sequenceModeProgram:
                            break;
                    }
                }
                break;
            case selectKey:
                lcd.setCursor(0, 1);
                if (lastEvent != keyEvent)
                {
                    lastEvent = keyEvent;
                    countEvent=0;
                }
                else
                    countEvent++;
                lcd.print(msgs[keyEvent]);
                lcd.print(countEvent);
                break;
        }
    }
}

// ===================================================================
// Menu tools

void menuModeSelect( int keyEvent )
{
    switch (keyEvent)
    {
        case rightKey:
            if (programMode < programMode2)
                programMode++;
            break;
        case leftKey:
            if (programMode > programMode1)
                programMode--;
            break;
    }
       lcd.setCursor(0,1);
    lcd.print( sequenceModes[programMode] );
}
     

void menuOptionSelect( int keyEvent )
{
    char cbuf[4] = "   ";
    lcd.setCursor(0,1);
    lcd.print(sequenceOptions[programMode]);
    switch (keyEvent)
    {
        case rightKey:
            switch (programMode)
            {
                case programMode1:
                    if (valueOpt1 < maxOpt1)
                        valueOpt1++;
                    break;
                case programMode2:
                    if (valueOpt2 < maxOpt2)
                        valueOpt2++;
                    break;
            }
            break;
        case leftKey:
            switch (programMode)
            {
                case programMode1:
                    if (valueOpt1 > minOpt1)
                        valueOpt1--;
                    break;
                case programMode2:
                    if (valueOpt2 > minOpt2)
                        valueOpt2--;
                    break;
            }
            break;
    }
    switch(programMode)
    {
        case programMode1:
            if (valueOpt1 > minOpt1)
                lcd.print("<");
            else
                lcd.print(" ");
            sprintf(cbuf,"%3d",valueOpt1);
            lcd.print(cbuf);
            if (valueOpt1 < maxOpt1)
                lcd.print(">");
            else
                lcd.print(" ");
            break;
        case programMode2:
            if (valueOpt2 > minOpt2)
                lcd.print("<");
            else
                lcd.print(" ");
            sprintf(cbuf,"%2d",valueOpt2);
            lcd.print(cbuf);
            if (valueOpt2 < maxOpt2)
                lcd.print(">");
            else
                lcd.print(" ");
            break;
    }
   
}

// ===================================================================
// Lcd tools

void clearLine(int line)
{
    lcd.setCursor(0,line);
    lcd.print("                ");
    lcd.setCursor(0,line);
}

// ===================================================================
// Define a custom char in lcd
int defineCharacter(int ascii, int *data) {
    int baseAddress = (ascii * 8) + 64;  
    // baseAddress = 64 | (ascii << 3);
    lcd.command(baseAddress);
    for (int i = 0; i < 8; i++)
        lcd.write(data[i]);
    lcd.command(128);
    return ascii;
}

// ===================================================================
// Convert ADC value to key number

int adc_key_val[NUM_KEYS] ={ 30, 150, 360, 535, 760 };
int get_key(unsigned int input)
{
    int k;
    for (k = 0; k < NUM_KEYS; k++)
    {
        if (input < adc_key_val[k])
            return k;
    }
    if (k >= NUM_KEYS)
        k = -1; // No valid key pressed
    return k;
}

// ===================================================================
// new key detection routine, without delays!

int     lastKeyEvent = 0;
int     curKeyEvent  = 0;
int     keyToReturn  = 0;
boolean keyToProcess = false;
int     adc_key_in   = 0;

int detectKey()
{
    keyToReturn = -1;
    adc_key_in = analogRead(0);         // read the value from the sensor  
    curKeyEvent = get_key(adc_key_in);      // convert into key press
    if (curKeyEvent != lastKeyEvent)
    {
        if (!keyToProcess) 
        {
            lastKeyEvent = curKeyEvent;
            keyToProcess = true;
        }
        else
        {
            keyToReturn = lastKeyEvent;
            lastKeyEvent = -1;
            keyToProcess = false;
        }
    }
    return keyToReturn;
    
    ora = digitalRead(programMode1);
    ant = digitalRead(programMode2);

    
       int readPot = analogRead( pinPot );
  int delayTime = map(readPot,0,1024,10,1000);

  if (ora == HIGH) {
    orario();
  } 

  if (ant == HIGH) {
    antiorario();
  }
  delay(delayTime);
}

void orario()
{
  int val = LOW;
  for (countX=0; countX<4; countX++)
  {
    if (countX == sequenza[count2X]) val = HIGH;
    else                             val = LOW;

    digitalWrite(motorPinx[countX], val);
  }
  count2X++;
  if (count2X == 4) count2X = 0;
}

void antiorario()
{
  int val = LOW;
  for (countX=3; countX>=0; countX--)
  {
    if (countX == sequenza[count2X]) val = HIGH;
    else                             val = LOW;

    digitalWrite(motorPinx[countX], val);
  }
  count2X--;
  if (count2X < 0) count2X = 3;
}


// ===================================================================

When I said I was happy to take a look at your code, I meant if you had specific problems. I recommend you try the code before posting it on the forum. If you do run into a problem, could you simplify it to a just a few lines that are problematic. Also, when posting code, please use the code brackets so it displays nicely in your post. I have edited your post to include the code brackets.

- Jeremy

Hello.

I am using Arduino UNO interfaced with LCD KEYPAD sheild (same sheild used by Falcon).
The sheild keypad consists of 5 keys — select, up, right, down and left.
I am using 2 DC MOTOR .
FIRST MOTOR : M1 :IF “UP KEY” is pressed M1 should run in forward direction till select key is pressed .
ELSE M1 & M2 no operation i.e stop mode.
IF “DOWN KEY” is pressed M1 should run in REVERSE direction till select key is pressed .
ELSE M1 & M2 no operation i.e stop mode.

Second MOTOR :M2 : :IF “LEFT KEY” is pressed M1 should run in forward direction till select key is pressed .
ELSE M1 & M2 no operation i.e stop mode.
IF “RIGHT KEY” is pressed M1 should run in REVERSE direction till select key is pressed .
ELSE M1 & M2 no operation i.e stop mode.

THE PROBLEM :is that i am not understanding which pins should i use for motor input ,as there are header pins -0 (RX),1(Tx),2,3,4,5,6,7 .
As 4,5,6,7,are already used by LCD.
SO,AVAILABLE header pins (holes)are 0,1,2,3 in my code i used it .

Hello, Sud.

What motor driver are you using?

-Derrill