Help with a build and programming

Hi all.

I require help on a build project im doing.

Its basically a copy of a clamshell observatory that someone made in Germany. He has been very helpful in sharing his files and software, but I have run into some issues and the translation process is quite hard between us, so i could use some assistance.

when i run the program it seems a little erratic and not doing what it should be doing.

I have included a picture. i have a video explaing everything, but unsure on how to upload it here to help.

the code is a direct copy from him and his dome works, so unsure where i have gone wrong. 🤔

This is the code iv got if it helps?

p.s. i know i wrote down and previously had the buttons on 5v, that has now been changed to GND.

Drop box link to the video

/*----------------------------------------------------
       Dome Steurung via Button oder RCCIASCOM
       Engelbert Vollmer 
       2025 02 02 nach Anschluss der Motoren 
*/

String serialin;  //incoming serial data
String str;       //store the state of opened/closed/pins

//relays
#define close 2  // PIN_BUTTON_DOWN
#define open 3   // PIN_BUTTON_UP

//input sensors
#define openedUS 4  // roof open sensor     UppSegOpened
#define closedUS 5  // roof closed sensor   UppSegClosed
#define openedLS 7  // roof open sensor     LowSegOpened
#define closedLS 6  // roof closed sensor   LowSegClosed

int motor1pin1 = 10;
int motor1pin2 = 11;
int motor2pin1 = 12;
int motor2pin2 = 13;

String StatusUS;
String StatusLS;

void setup() {

  //Begin Serial Comunication(configured for 9600baud)
  Serial.begin(9600);
  //pin relay as OUTPUT
  pinMode(motor1pin1, OUTPUT);
  pinMode(motor1pin2, OUTPUT);
  pinMode(motor2pin1, OUTPUT);
  pinMode(motor2pin2, OUTPUT);

  //pins as INPUT
  pinMode(open, INPUT_PULLUP);
  pinMode(close, INPUT_PULLUP);
  pinMode(closedUS, INPUT_PULLUP);
  pinMode(openedUS, INPUT_PULLUP);
  pinMode(closedLS, INPUT_PULLUP);
  pinMode(openedLS, INPUT_PULLUP);

  //Initialize Output states
  digitalWrite(open, LOW);
  digitalWrite(close, LOW);
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, LOW);
  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, LOW);

  Serial.write("RRCI#");  //init string
}

void loop() {
  Operate_Dome_By_Button();
  Operate_Dome_by_RCCI();
}

//---------------------------------------------------------------
// Operate by Button
//---------------------------------------------------------------
void Operate_Dome_By_Button() {
  // --------------- Close Dome ----------------
  if (digitalRead(close) == HIGH && digitalRead(open) == LOW) {
    //Both Segments
    while (digitalRead(close) == HIGH && digitalRead(closedUS) == LOW && digitalRead(closedLS) == LOW) {
      digitalWrite(motor1pin1, HIGH);
      digitalWrite(motor1pin2, LOW);
      digitalWrite(motor2pin1, HIGH);
      digitalWrite(motor2pin2, LOW);
    }
    Stopp_Motors();

    //Upper Segment if Lower Segment is closed before
    while (digitalRead(close) == HIGH && digitalRead(closedUS) == LOW) {
      digitalWrite(motor1pin1, HIGH);
      digitalWrite(motor1pin2, LOW);
    }
    Stopp_MotorsUS();

    //Lower Segment if Upper Segment is closed before
    while (digitalRead(close) == HIGH && digitalRead(closedLS) == LOW) {
      digitalWrite(motor2pin1, HIGH);
      digitalWrite(motor2pin2, LOW);
    }
    Stopp_MotorsLS();
  }

  // --------------- Open Dome --------------------------
  if (digitalRead(open) == HIGH && digitalRead(close) == LOW) {

    //Both Segments
    while (digitalRead(open) == HIGH && digitalRead(openedUS) == HIGH && digitalRead(openedLS) == HIGH) {
      digitalWrite(motor1pin1, LOW);
      digitalWrite(motor1pin2, HIGH);
      digitalWrite(motor2pin1, LOW);
      digitalWrite(motor2pin2, HIGH);
    }
    Stopp_Motors();

    //Upper Segment if Lower Segment is opened before
    while (digitalRead(open) == HIGH && digitalRead(openedUS) == HIGH) {
      digitalWrite(motor1pin1, LOW);
      digitalWrite(motor1pin2, HIGH);
    }
    Stopp_MotorsUS();

    //Lower Segment if Upper Segment is opened before
    while (digitalRead(open) == HIGH && digitalRead(openedLS) == HIGH) {
      digitalWrite(motor2pin1, LOW);
      digitalWrite(motor2pin2, HIGH);
    }
    Stopp_MotorsLS();
  }
}
//----------------------------------------------------------------------------
// Operate via ASCOM
//----------------------------------------------------------------------------
void Operate_Dome_by_RCCI() {

  //Verify connection by serial
  while (Serial.available() > 0) {
    //Read Serial data and alocate on serialin
    serialin = Serial.readStringUntil('#');

    if (serialin == "y") {
      Stopp_Motors();
    } else if (serialin == "open") {
      digitalWrite(motor1pin1, LOW);  //Upper Segment
      digitalWrite(motor1pin2, HIGH);
      digitalWrite(motor2pin1, LOW);  // Lower Segmenet
      digitalWrite(motor2pin2, HIGH);
      StatusUS = "opening";
      StatusLS = "opening";
    }
    if (serialin == "y") {
      Stopp_Motors();
    } else if (serialin == "close") {
      digitalWrite(motor1pin1, HIGH);  //Upper Segment
      digitalWrite(motor1pin2, LOW);
      digitalWrite(motor2pin1, HIGH);  // Lower Segmene
      digitalWrite(motor2pin2, LOW);
      StatusUS = "closing";
      StatusLS = "closing";
    }
  }

  if (digitalRead(closedUS) == HIGH && StatusUS == "closing") { Stopp_MotorsUS(); }
  if (digitalRead(closedLS) == HIGH && StatusLS == "closing") { Stopp_MotorsLS(); }

  if (digitalRead(openedUS) == LOW && StatusUS == "opening") { Stopp_MotorsUS(); }
  if (digitalRead(openedLS) == LOW && StatusLS == "opening") { Stopp_MotorsLS(); }

  if (serialin == "Parkstatus") {  // external query command to fetch RRCI data
    Serial.println("0#");
    serialin = "";
  }

  if (serialin == "get") {  // external query command to fetch RRCI data - Two Pipelines(||) to make a boolean OR Comparission

    if ((digitalRead(closedUS) == HIGH && digitalRead(openedUS) == HIGH) && (digitalRead(closedLS) == HIGH && digitalRead(openedLS) == HIGH)) { str += "closed,not_moving_o#"; }
    if ((digitalRead(closedUS) == LOW && digitalRead(openedUS) == LOW) || (digitalRead(closedLS) == LOW && digitalRead(openedLS) == LOW)) { str += "opened,not_moving_c#"; }
    //if ((digitalRead(openedUS) == LOW && digitalRead(closedUS) == LOW) && (digitalRead(openedLS) == LOW && digitalRead(closedLS) == LOW)) {str += "opened,not_moving_c#";}
    // if ((digitalRead(closedUS) == HIGH && digitalRead(openedUS) == HIGH) || (digitalRead(closedLS) == HIGH && digitalRead(openedLS) == HIGH)) {}

    Serial.println(str);  //send serial data
    serialin = "";
    str = "";
  }

  if (serialin == "Status") { Serial.println("RoofOpen#"); }
  serialin = "";
  //str = "";
}

//--------------------------
// Motor stop
//--------------------------
void Stopp_Motors() {
  Stopp_MotorsUS();
  Stopp_MotorsLS();
}

void Stopp_MotorsUS() {
  digitalWrite(motor1pin1, LOW);
  digitalWrite(motor1pin2, LOW);
  StatusUS = "";
}

void Stopp_MotorsLS() {
  digitalWrite(motor2pin1, LOW);
  digitalWrite(motor2pin2, LOW);
  StatusLS = "";
}

//--------------------------
//  Status of Button during tests
//--------------------------

void Print_Schalter_Status() {
  Serial.print("UpSegCl  UpSeg Op  LoSegCl  LoSegOp  ButCl  ButOp...");
  Serial.print(digitalRead(closedUS));
  Serial.print("..");
  Serial.print(digitalRead(openedUS));
  Serial.print("..");
  Serial.print(digitalRead(closedLS));
  Serial.print("..");
  Serial.print(digitalRead(openedLS));
  Serial.print("..");
  Serial.print(digitalRead(close));
  Serial.print("..");
  Serial.println(digitalRead(open));
  delay(5000);
}

So what is it doing? As for the video, can you upload it to dropbox or Youtube and share the link? Make sure it is set to public.

hi. yes iv just uploaded into my dropbox.

How is the motor driver getting its power? From the video, it looks like its coming from the Arduino, is that correct? If so, please remove it as the Arduino is not capable of powering the motor driver and can actual cause damage to the arduino. Please use a separate power supply and make sure they have a common ground wire between the Arduino's gnd pin and the ground of the external power supply.

What does Print_Schalter_Status() output? What does it look like when fully open, partially closed and fully closed?

yes i do have a seperate power spply plugged into the arduino via the jack.

the arduino are linked together via 5v, GND and +v

No, I mean the motor driver and arduino should have separate power supplies with the grounds connected. In the video it looks like the motor driver is getting the 5V from the Arduino's 5v pin. You should not do that, it should be getting 5v from its own power supply.

ah ok. do you mean like this picture?

That turns off the internal pullup, those switches are now INPUT mode. So they need an external resistor, and need to be wired one of two ways.

I'd like to say "probably..." but won't.

You need to know

"What voltage does each Arduino pin see in every mechanically meaningful state?"

or perhaps

"What voltage does each Arduino pin expect in every mechanically meaningful state?"

I'm curious about your difficuties with the language barrier. Are you both using google translate? That is a recipe for time wasting. Presumably the project works for its inventor.

I suggest using translation on steroids, which could be chatGPT. Not to debug or solve anything, but to translate in a rich semantic context which would be provided by giving it the sketch, then asking for a good translation of your questions. Let the German guy write in German, and use the same chatGPT converation to render them his replies for you in English. This will at least relieve the inventor of a burden it might be too much to expect him to remain cheerful bearing.

Aside from the odd switch mode switch, which doesn't look right, it's down to switch sense and wiring.

A mechanical diagram of any kind is going to get more attention than a video where you are talking about contacts opening and closing.

a7

That looks correct. What is your power supply rated for, how many amps?

And this

//input sensors
#define openedUS 4  // roof open sensor     UppSegOpened
#define closedUS 5  // roof closed sensor   UppSegClosed
#define openedLS 7  // roof open sensor     LowSegOpened
#define closedLS 6  // roof closed sensor   LowSegClosed

makes me think there is more going on than just open, closing, closed, and open.

Is there something that happens halfway? Sorry if I missed it in your words (likely) or video (totally possible! that's on me, not my best communication channel).

a7

ok. i can change my power supply to suit that picture instead.

the psu is rated at 5A

no, its litterally 2 buttons on the dome (open and close).

the dome is in 2 segments, lower half and upper half.

there are 2 limit switches for each half(4 in total). 1 switch to sence when the dome half is fully open and 1 switch to know when the dome half is closed. same for the other half.

If you have 5V coming from your motor driver module, it should not be tied to Vin on your arduino. Vin takes 6-9V and feeds that into the arduion's onboard voltage regulator to produce 5V. If your motor driver is supplying the 5V, it should go directly into the 5V pin on the Arduino.

iv not. i have now changed my power supply connections and now have 12v connected inton vin that now splits off into the motor controller and aruino, GND is common between the 2 and 5v is a direct link between the . i also have all the inputs etc that need a GND connection going into the same terminal.

sorry just checked its 2A. assuming this is enough?

Please elaborate.

In particular, do you find that it is consistent?

"Erratic" points our attention to switches not pulled up or down, no matter they be right or wrong, and inadequate power, no matter the motors are turning the wrong directions or whatever.

So those lines that turn off the pull-up makes me ask if the corresponding switches have the (now) required resistor, no matter which way they are interpreted or "normal".

The software also now looks like the motors are driven until one or the other reaches the limit they are being driven towards. Which may or may not be fine. TBH if I didn't say, this sketch could be structured in a totally different way; I appreciate that here you just want help making a project that works for someone else do the same for you without any real programming.

Which shoukd be entirely possible.

@HazardsMind asked

I think at this point that function is never called. But the answer to the question is important, as it isn't yet clear the roll of HIGH and LOW crossed with NC/NO contacts - too many variations for simply testing all theories.

But first the missing pulling resistors.

a7

Ok.

So if i do need resistors, how do i do that? Would that be why it seems erratic in opening and closing? Nothing seems consistent when I press the buttons.

Yes when I press either button, it is meant to open fully, or close fully until it touches the limit switches, telling the motors to stop.

Is there a way in the software to tell me what command / operation is currently being carried out in a "live" View?

Your Facebook video is better. Post a link to that.

It might be better, if you could, to start from scratch with some simple stuff on just turning the motors on and off using the Arduino and then introduce the limit switches.

Alternatively, use one of the AI modes in a search and you might get some useful code.

If the original author assures you that it works with the code they gave you, and you haven't altered the code, then recheck all the wiring.

Is this your first Arduino project?

If i could start from scratch i would, but to be honest , I haven't a clue what im doing and most of this is going over my head :upside_down_face: :see_no_evil_monkey:.

Its easier for me to pay someone to write the code, then tell me what connections I need.

No this is the 2nd project iv done, but the 1st one i did i just copied and pasted the code and everything worked straight away.

It's not as difficult as you think and if you do start from scratch, it puts you in control.
Everyone who writes code does so their own way and using their own logic which can be difficult to get to grips with.
There are quite easy ways to get started, with a starter kit - genuine Arduino advised-and you can soon be up and running.
You probably have managed to load the code via the IDE and that's a start.
Get a copy of Arduino Cookbook, which convers most of what you want.
Good luck