Sorry to bother you again, but I'm at my wits end.
I had the home-switches working yesterday, but I had an afterthought:
I had put the code for the homing sequence all the way at the end of the stepper setup. So, if the motors would be put in continuous mode, they would also try to home. Ofcourse, that wouldn't be desireable behaivior.
So I put the homing code after the part where the motors are set to 8 bit or 16 bit. That way, only the motors that are set to be in "perform" mode, would home. I tried it this morning and it worked perfectly.
Then I started to experiment a bit with the homing speed.
I don't know what happened, but at some point the homing stopped working.
I've tried everything I could think of.
I uploaded a fresh 1.0.1 code that I downloaded through the link in this thread and inserted the stepper setup code that I posted earlier (with the zeroswitches defined as a table, like Jaques posted). I'm 100% sure that was the code that worked yesterday. But I can't get it to work anymore.
When I power on the board, the motor makes a sound like it wants to start rotating, but then the DMX led comes on and the motor reacts to the DMX signal, like there was no code for homing at all.
But when I disconnect the DMX signal and power up (or reset) the board, the motor starts rotating and does one turn (that's what I have it set to in the configuration page. So actually it does 27 turns, because I have a 27:1 reduction). It doesn't react to the input of the home switch at all.
I tried putting the homing code in several different places, but to no avail.
I also tried connecting the motor to Port B and the switch to Port A (ofcourse I also configured Port A to be inactive and Port B for steppers and changed the inputs for the endswitches to Arp0, Arp1, Arp2 and Arp3), just to be sure I hadn't blown the inputs to the microcontroller.
But every time I get the same behaviour.
Could you please have a look at the code and see if Ithere's something wrong that I'm just not seeing?
Code : Tout sélectionner
void Port:: stepper_setup()
{
uint8_t zeroSwitch[4]{Arp8,Arp9,Arp10,Arp11};
for (int i=0; i < 4; ++i)
{
(zeroSwitch[i], INPUT_PULLUP);
}
Serial.println(" : Stepper");
uint16_t defaultSPR = 800;
uint16_t defaultMin = 4;
uint16_t defaultMax = 200;
float defaultRevol = 12;
bool defaultAction = 0; //perform by default
m_stepper = new ArpStepper[4];
m_nbDmxChannels = 8;
uint8_t startPin= (m_port_name=='A') ? 0 : 8;
for(int i=0;i<4;i++)
{
String num(i);
String str = num+"stpActive";
const char * word = str.c_str();
m_stp_active[i]= load(word,true);
Serial.print("stepper "); Serial.print(i);
if(m_stp_active[i])
{
str = num+"stpPerRevol";
word = str.c_str();
uint16_t stepPerRevolution = load(word,defaultSPR);
//uint8_t output=i+startPin;
m_stepper[i].attach(Arp[i*2+1+startPin],Arp[i*2+startPin],stepPerRevolution);
Serial.print(" steps per revolution : "); Serial.print(stepPerRevolution); Serial.print("; ");
////////////////////////////////////////////////////////////////////
str = num+"_rpm_min";
word = str.c_str();
uint16_t rpmMin = load(word,defaultMin);
Serial.print(" rpmmin : "); Serial.print(rpmMin); Serial.print("; ");
str = num+"_rpm_max";
word = str.c_str();
uint16_t rpmMax = load(word,defaultMax);
Serial.print(" max : "); Serial.print(rpmMax); Serial.print("; ");
str = num+"_revol";
word = str.c_str();
float revol = load(word,defaultRevol);
Serial.print(" revolutions : "); Serial.print(revol); Serial.print("; ");
str = num+"stpAction";
word = str.c_str();
m_action[i] = load(word,defaultAction);
Serial.print(" action : ");
uint16_t dmxRes = _8bits;
if(m_action[i]==0)
{
Serial.print("perform"); Serial.print("; ");
Serial.print(" DMX resolution : ");
str = num+"stp_dmxRes";
word = str.c_str();
//Serial.print("((word : ");Serial.print(word);Serial.print(" ))");//////////debug////////
m_stp_dmxRes[i]=load(word,false);
//Serial.print("((16bits : ");Serial.print(m_stp_dmxRes[i]);Serial.print(" ))");//////////debug////////
if(m_stp_dmxRes[i]==true)
{
dmxRes = _16bits;
Serial.print("16bits");
m_nbDmxChannels++;
}
else
{
Serial.print("8bits");
}
Serial.print("; ");
Serial.println("Homing ...");
m_stepper[i].refresh(255, 10);//we define a direction of rotation (255, to go in the other direction : 0), and a speed (here 30 for a slow speed)
while (digitalRead(zeroSwitch[i]))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior)
{
m_stepper[i].continuous();//turn !
}
Serial.println("end of homing!");
}
else
{
Serial.print("continuous; ") ;
}
m_stepper[i].init(rpmMin, rpmMax, revol, dmxRes);
//Serial.println();Serial.print(" rpmMin (2): ");Serial.println(rpmMin);
str = num+"stpInverted";
word = str.c_str();
bool inverted = load(word,false);
if(inverted)
{
m_stepper[i].invert_rotation(true);
Serial.println(" inverted; ");
}
Serial.println();
}
else Serial.println(" inactive");
}
Serial.println();
}