Sure here is the two interesting part:
void setup() {
if (ENABLE_SERIAL) {
Serial.begin(115200);
}
delay(5000 + randr(0, APP_TX_DUTYCYCLE_RND));
pinMode(PIN_STEPPER_CLOSE, OUTPUT);
pinMode(PIN_STEPPER_OPEN, OUTPUT);
digitalWrite(PIN_STEPPER_CLOSE, HIGH);
digitalWrite(PIN_STEPPER_OPEN, HIGH);
deviceState = DEVICE_STATE_INIT;
LoRaWAN.ifskipjoin();
}
And when I actually made the change:
#define PIN_STEPPER_OPEN GPIO1
#define PIN_STEPPER_CLOSE GPIO2
void makeStepAction(int seconds, int pin) {
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
delay(seconds * 1000);
digitalWrite(pin, HIGH);
}
void handleChangeStep(const uint8_t *payload) {
int newStep = payload[0];
int seconds = 0;
EEPROM.begin(512);
delay(1000);
latestStepValue = (int) EEPROM.read(eepromAddress);
if (ENABLE_SERIAL) {
Serial.println();
Serial.print("New step saving:");
Serial.println(newStep);
}
EEPROM.write(eepromAddress, newStep);
EEPROM.commit();
EEPROM.end();
// Do close/open
if (newStep == 0 || newStep == 5) {
makeStepAction(STEPPER_FULL_RANGE_SEC, newStep == 0 ? PIN_STEPPER_CLOSE : PIN_STEPPER_OPEN);
return;
}
// Do partial close
if (newStep < latestStepValue) {
if (ENABLE_SERIAL) {
Serial.print("New step seconds CLOSE:");
Serial.println(seconds);
}
makeStepAction(StepperSecTable[latestStepValue] - StepperSecTable[newStep], PIN_STEPPER_CLOSE);
return;
}
// Do partial open
if (newStep > latestStepValue) {
if (ENABLE_SERIAL) {
Serial.print("New step seconds OPEN:");
Serial.println(seconds);
}
makeStepAction(StepperSecTable[newStep] - StepperSecTable[latestStepValue], PIN_STEPPER_OPEN);
return;
}
}
I want to point out that I can make the relay work with one diode in between the Cubecell PIN and the relay input.
I’ve got also another problem:
when in JOINING mode seems like the GPIO1 and GPIO2 are powered with voltage and that just triggers the relay to turn on and off when the board sends the join message.
For what I can see the GPIOx pins of the Cubecell are NEVER with voltage at 0 and that is causing problems with the relay handling.