Estoy desesperado...
Busco y no encuentro la respuesta, pero me parece recordar alguna vez algo en alguna parte que no encuentro....
Problema Nuevo !!!
A la placa antigua le he intentado conectar el wiichuck (I2c) (A4,A5,+3.3v y GND). La controla un Nano y tb lleva conectado un Joystick en A6 y A7. los DRV van conectados a los pines 9,10,11 y 12 (Step y DIR) más los digitales 3y4 para microstep.
Pues bien... cuando activo los comandos de la wiichuck (en el void loop), los steppers empiezan a hacer un silbido y casi que no funcionan.
OJO ! El problema NO está relacionado con el hardware (ocurre lo mismo si está enchufado el wiichuck o desconectado). Tampoco influye que estén cargadas las librerías "Wire" y "wiichuck"..
En cuanto desactivo el código de control del wiichuck del Void Loop se acaba el problema !!.
Pregunto....
Es posible que al recibir por I2C esté interfiriendo con pines digitales de los DRV´s ??
El ruido es como si el Nano no acertara a controlar los pines Step o Dir.....es parecido a cuando conectas mal los steppers al driver..
Puede afectar el recibir señal I2C a algún reloj interno en los digitales ???
Es lo único que se me ocurre.....
//ACORDE A LA PLACA Telescopecontrol 1
#include <Wire.h>
#include <Wiichuck.h>
#define Xdir_pin 9 // Pin 9 connected to Direction pin on DRV-X
#define Xstep_pin 10 // Pin 10 connected to Steps pin on DRV-X
#define Ydir_pin 11 // Pin 11 connected to Direction pin on DRV-Y
#define Ystep_pin 12 // Pin 12 connected to Steps pin on on DRV-Y
#define X_pin A7 // Pin A2 connected to joystick X axis
#define Y_pin A6 // Pin A1 connected to joystick Y axis
Wiichuck chuck;
boolean WiiChuckPresent;
int X;
int Y;
int PosStepX=0; // Facing North
int PosStepY=DEC_90; // Facing Up (+90Deg)
// Posicion inicial Destino en Pasos
int TargetX=0;
int TargetY=0;
bool Move_e,Move_w,Move_u,Move_d;
bool TelescopeisTracking=false;
bool TelescopeisSlewing=false;
bool SilentMode = false ;
int errX = 0 ; // To measure align errors
int errY = 0 ;
unsigned int OrigenX = 0 ;
unsigned int OrigenY = 0 ;
bool GD_Request=false ;
bool GR_Request=false ;
bool JoyStickPresent=true;
void setup() {
Serial.begin(9600);
SinLat = sin (OBSERVATION_LATTITUDE/Rad);
CosLat = cos (OBSERVATION_LATTITUDE/Rad);
// CONTROL DE DRV´S
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(Xdir_pin, OUTPUT);
pinMode(Xstep_pin, OUTPUT);
pinMode(Ydir_pin, OUTPUT);
pinMode(Ystep_pin, OUTPUT);
digitalWrite(2,LOW ); // STEPMODE 1/4 MICROSTEPS AT START UP
digitalWrite(3,HIGH );
//Wiichuck
chuck.init();
delay(5);
chuck.calibrate();
delay(10);
WiiChuckPresent=true;
//joystick
// pinMode(X_pin, INPUT);
// pinMode(Y_pin, INPUT);
JoyStickPresent=true;
// Ponemos a false todos los Movimientos
Move_e = false;
Move_w = false;
Move_u = false;
Move_d = false;
}
// ============================================= LOOP==========================
void loop() {
// COMANDOS DE STELLARIUM
if (Serial.available()>0){
BT_COMMAND_STR = Serial.readStringUntil('#');
Comunicaciones();
}
// MOVIMIENTO MANUAL
if ((JoyStickPresent==true) ) {
JoyControl();
JoyStick();
MoverTelescopio();
}
//============== PROBLEMA AL ACTIVAR ESTE CODIGO ===============
/* if (chuck.poll()){
if ((chuck.joyX()<90) || (chuck.joyX()>180) || (chuck.joyY()<90) || (chuck.joyY()>180)) { // If Wiichuck is Moved
WiiChuck();
MoverTelescopio();
}
// if ((chuck.buttonC() != 0) ) {
// TelescopeisTracking = false;
// }
}*/
// MOVIMIENTO AUTOMATICO POR STELLARIUM
if ( (TelescopeisTracking==true) && (((PosStepX + errX) != TargetX) || ((PosStepY + errY) != TargetY)) ) {
MoverTelescopio();
}
// ENCUENTRA OBJETIVO
if ((TelescopeisTracking == true) && ((PosStepX + errX) == TargetX) && ((PosStepY + errY) == TargetY)) {
SilentMode = true;
OrigenX = 0 ;
OrigenY = 0 ;
TelescopeisTracking == false;
JoyControl();
MoverTelescopio();
}
}
//================================ END LOOP ====================================
void JoyControl () {
X=analogRead (X_pin);
delay(5);
Y=analogRead(Y_pin);
delay(5);
if ((X > 900) || (X < 200) || (Y > 900) || (Y < 200)){ // If joystick is moved
}
}
void JoyStick(){
if (X > 900) { // If joystick is moved Left
Move_e=true;
}
if (X < 200) { // If joystick is moved right
Move_w=true;
}
if (Y > 900) { // If joystick is moved DOWN
Move_d=true;
}
if (Y < 200) { // If joystick is moved UP
Move_u=true;
}
return;
}
void WiiChuck(){
if (chuck.joyX()<90) { // If joystick is moved Left
Move_e=true;
}
if (chuck.joyX()>180) { // If joystick is moved right
Move_w=true;
}
if (chuck.joyY()>180) { // If joystick is moved DOWN
Move_d=true;
}
if (chuck.joyY()<90) { // If joystick is moved UP
Move_u=true;
}
return;
}
void MoverTelescopio(){
if (Move_e==true) { // If Target is Left ( Target < Pos)
digitalWrite(Xdir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(Xstep_pin, HIGH);
digitalWrite(Xstep_pin, LOW);
Move_e=false;
SilentMode ? errX-- : PosStepX = PosStepX - ( 1* RA_mode_steps );
delay(10);
}
if (Move_w==true) { // If Target is right (Target>Pos)
digitalWrite(Xdir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)PORQUE TIENE 1 REDUCCION iso 2
digitalWrite(Xstep_pin, HIGH);
digitalWrite(Xstep_pin, LOW);
Move_w=false;
SilentMode ? errX++ : PosStepX = PosStepX + ( 1 * RA_mode_steps );
delay(10);
}
if (Move_d==true) { // If Target is DOWN (Target<Pos)
digitalWrite(Ydir_pin, LOW); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(Ystep_pin, HIGH);
digitalWrite(Ystep_pin, LOW);
SilentMode ? errY-- : PosStepY = PosStepY - ( 1* DEC_mode_steps );
Move_d=false;
delay(10);
}
if (Move_u==true) { // If Target is UP (Target>Pos)
digitalWrite(Ydir_pin, HIGH); // (HIGH = anti-clockwise / LOW = clockwise)
digitalWrite(Ystep_pin, HIGH);
digitalWrite(Ystep_pin, LOW);
SilentMode ? errY++ : PosStepY = PosStepY + ( 1* DEC_mode_steps );
Move_u=false;
delay(10);
}
return;
}