Buenas, estoy obteniendo un dato de la pantalla TFT de Arduino y transmito esos números a pulsos mandándoselo al motor nema 24 cuyo driver es un TB6600 la pantalla y el motor me andan bien por separado pero cuando lo junto el motor no responde solo hace 3 ruidos fuertes pero no se mueve.
El código se supone que con la pantalla la persona ponga un valor numérico y ese valor es la cantidad de pulsos que recibe el motor para que este se mueva.
Les dejo el cogigo abajo la variable que toma el dato que seleccione la persona es "stLast".
Estoy 100% seguro que el error proviene de esta parte que les dejo abajo además e de decir que en la consola no me aparece ningún error.
Muchísimas gracias por leer mi post.
El código se supone que con la pantalla la persona ponga un valor numérico y ese valor es la cantidad de pulsos que recibe el motor para que este se mueva.
Les dejo el cogigo abajo la variable que toma el dato que seleccione la persona es "stLast".
#include <UTFT.h>
#include <UTouch.h>
// Initialize display
// ------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : <display model>,19,18,17,16
// Standard Arduino Mega/Due shield : <display model>,38,39,40,41
// CTE TFT LCD/SD Shield for Arduino Due : <display model>,25,26,27,28
// Teensy 3.x TFT Test Board : <display model>,23,22, 3, 4
// ElecHouse TFT LCD/SD Shield for Arduino Due : <display model>,22,23,31,33
//
// Remember to change the model parameter to suit your display module!
UTFT myGLCD(ILI9341_16,38,39,40,41);
// Initialize touchscreen
// ----------------------
// Set the pins to the correct ones for your development board
// -----------------------------------------------------------
// Standard Arduino Uno/2009 Shield : 15,10,14, 9, 8
// Standard Arduino Mega/Due shield : 6, 5, 4, 3, 2
// CTE TFT LCD/SD Shield for Arduino Due : 6, 5, 4, 3, 2
// Teensy 3.x TFT Test Board : 26,31,27,28,29
// ElecHouse TFT LCD/SD Shield for Arduino Due : 25,26,27,29,30
//
UTouch myTouch( 6, 5, 4, 3, 2);
// Declare which fonts we will be using
extern uint8_t BigFont[];
int x, y;
char stCurrent[20]="";
int stCurrentLen=0;
char stLast[20]="";
extern uint8_t SevenSegNumFont[];
/*************************
** Custom functions **
*************************/
char dato;
const int dirPin = 8;
const int stepPin = 9;
const int enPin = 10;
void drawButtons()
{
myGLCD.print("M.M", 230, 28);
// Draw the upper row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10+(x*60), 130, 60+(x*60), 180);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10+(x*60), 130, 60+(x*60), 180);
myGLCD.printNumI(x+1, 27+(x*60), 147);
}
// Draw the center row of buttons
for (x=0; x<5; x++)
{
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10+(x*60), 190, 60+(x*60), 235);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10+(x*60), 190, 60+(x*60), 235);
if (x<4)
myGLCD.printNumI(x+6, 27+(x*60), 207); // Imprime los numeros
}
myGLCD.print("0", 267, 87);
// Draw the lower row of buttons
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (10, 70, 150, 120);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (10, 70, 150, 120);
myGLCD.print("Limpiar", 20, 85);
myGLCD.setColor(0, 0, 255);
myGLCD.fillRoundRect (160, 70, 300, 120);
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (160, 70, 300, 120);
myGLCD.print("Aceptar", 170, 85);
myGLCD.setBackColor (0, 0, 0);
}
void updateStr(int val)
{
if (stCurrentLen<7) // Para decir cuantos numeros quieres que aparescarn en el resultado
{
waitForIt(160, 120, 300, 70);
stCurrent[stCurrentLen]=val;
stCurrent[stCurrentLen+1]='\0';
stCurrentLen++;
myGLCD.setColor(244, 244, 244);
myGLCD.setFont(SevenSegNumFont);
myGLCD.print(stCurrent, LEFT, 18); // Numeros en verde los de abajo
}
}
// Draw a red frame while a button is touched
void waitForIt(int x1, int y1, int x2, int y2)
{
myGLCD.setColor(255, 0, 0);
myGLCD.drawRoundRect (x1, y1, x2, y2);
while (myTouch.dataAvailable())
myTouch.read();
myGLCD.setColor(255, 255, 255);
myGLCD.drawRoundRect (x1, y1, x2, y2);
}
/*************************
** Required functions **
*************************/
void setup()
{
// Initial setup
myGLCD.InitLCD();
myGLCD.clrScr();
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.setFont(BigFont);
myGLCD.setBackColor(0, 0, 255);
drawButtons();
Serial.begin(9600);
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
Serial.begin(9600);
pinMode(enPin,OUTPUT);
digitalWrite(enPin,LOW);
}
void loop()
{
while (true)
{
if (myTouch.dataAvailable())
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=60) && (y<=110)) // Upper row
{
if ((x>=10) && (x<=60)) // Button: 1
{
// x1 y1 x2 y2
waitForIt(10, 130, 60, 180);
updateStr('1');
}
if ((x>=70) && (x<=120)) // Button: 2
{
waitForIt(70, 130, 120, 180);
updateStr('2');
}
if ((x>=130) && (x<=180)) // Button: 3
{
waitForIt(130, 130, 180, 180);
updateStr('3');
}
if ((x>=190) && (x<=240)) // Button: 4
{
waitForIt(190, 130, 240, 180);
updateStr('4');
}
if ((x>=250) && (x<=300)) // Button: 5
{
waitForIt(250, 130, 300, 180);
updateStr('5');
}
}
if ((y>=10) && (y<=50)) // Center row
{
if ((x>=10) && (x<=60)) // Button: 6
{
waitForIt(10, 190, 60, 235);
updateStr('6');
}
if ((x>=70) && (x<=120)) // Button: 7
{
waitForIt(70, 190, 120, 235);
updateStr('7');
}
if ((x>=130) && (x<=180)) // Button: 8
{
waitForIt(130, 190, 180, 235);
updateStr('8');
}
if ((x>=190) && (x<=240)) // Button: 9
{
waitForIt(190, 190, 240, 235);
updateStr('9');
}
if ((x>=250) && (x<=300)) // Button: 0
{
waitForIt(250, 190, 300, 235);
updateStr('0');
}
}
if ((y>=130) && (y<=170)) // Upper row ...........................................................................
{
if ((x>=10) && (x<=150)) // Button: Clear
{
waitForIt(10, 120, 150, 70);
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 4, 220, 67); // Borrar
}
if ((x>=160) && (x<=300)) // Button: Enter
{
waitForIt(160, 120, 300, 70);
if (stCurrentLen>0)
{
for (x=0; x<stCurrentLen+1; x++)
{
stLast[x]=stCurrent[x];
}
stCurrent[0]='\0';
stCurrentLen=0;
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 4, 220, 65);
myGLCD.setColor(0, 255, 0);
myGLCD.setFont(SevenSegNumFont);
myGLCD.print(stLast, LEFT, 18); // Numeros aceptados La variable stLast aloja los resultados
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < stLast; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
}
}
}
}
}
}
Estoy 100% seguro que el error proviene de esta parte que les dejo abajo además e de decir que en la consola no me aparece ningún error.
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(0, 4, 220, 65);
myGLCD.setColor(0, 255, 0);
myGLCD.setFont(SevenSegNumFont);
myGLCD.print(stLast, LEFT, 18); // Numeros aceptados La variable stLast aloja los resultados
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making one full cycle rotation
for(int x = 0; x < stLast; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1000); // One second delay
}
}
}
Muchísimas gracias por leer mi post.