Wiring up my machine

Hi Everyone!

I’ve just put a project on to particle but I need some advice on the wiring for it.

I can’t get my head around where the wires need to go/come from and what else I might need to be able to complete the project. I’ve spent days looking at examples online and I’m still none-the-wiser.

I really appreciate any help that you can give me?

Cheers

Tim

Hmm, you’ve put this project onto Hackster but you don’t know how this works? :confused:
Could you elaborate what exactly you want to wire from where to where?

Wouldn’t you first investigate the how-to, then get it running and then put it up on Hackster?

3 Likes

But what did you get so far? The question (as I read it):“what do I need to do to make my project?” is a bit of a vague question, not to mention the fact that we aren’t supposed to make your project :wink:
If you need help with specific things, then please ask specific questions. “I looked, but haven’t found, what to do?” is not something we can answer here.

Looking at the code (which @ScruffR rightfully dubbed as questionable), it seems there are some things off. Disregarding the fact that you seem to lack a couple of brackets (if cases) that would cause issues, it seems as though you’re using the Servo object even though it was mentioned that that wouldn’t work.

I’m with @ScruffR on this one, Hackster is generally meant to share complete projects, it’s not a troubleshooting site, and really shouldn’t be used as such. If you want to share code and/or get improvements on it, then please place it on Github, or directly on the forums here. Then we can help out, and when you’ve got it working, you can post it on Hackster.

2 Likes

Hi guys,
there is a way to publish a project in Hackster that represents a work in project:

@timtiernan maybe you would like to set it like that while you are working on it, and once finished you change it again (it’s allowed) :wink:
thanks!
Gustavo.

1 Like

Thanks Moors, sorry if I somehow managed to offend anyone. I’m still new at this and haven’t used hackster before. I do have the project hidden unless you have the link and it’s marked as a work in progress. It just looked like a good place to keep everything together.

I took the advice of someone else and swapped out the stepper motors for continuous servos so that I can use the library that’s in-built.

I was just hoping that someone could point me at a guide for doing the hardware elements of this kind of project. Although the manufacture of the solution will be quite complicated, what I’m trying to do from a software, switch and motor control point of view with this project is quite simple.

I’m just looking for someone to point me in the right direction, not do the project for me.

1 Like

Thanks Gustavo… it’s already set like that, and hidden unless you have the link. :wink:

oh yes, I see the “Work in progress” on the side… thanks!

1 Like

Which parts exactly? There are guides for servos, guides for switches, guides for code, there's even a Hackster project doing the same thing you're trying to do.

That’s great, thanks Moors! That really helps. Per your point above, I’ve now added in the brackets to my code… for some reason it validated without them so I assumed that they were unnecessary.

It should compile! There's nothing wrong with the code as you had it. It just wouldn't do what you wanted it to do :wink:

OK, having now put the brackets in… will that now do “what I think it’s going to do?” do you think or have I gone fundamentally wrong?

The thing I struggle with most with these controllers is what the possibilities are for the various pins on the photon (i.e. for a reed switch like this to work, which pins do I need to attach the various legs to?

https://1drv.ms/i/s!Aob0lXeugY43iV0x-T9wcJ1rqlF0 )

Theoretically, it looks alright. Next thing would be to move all that logic out of the function call, place it in the loop, and act on it by toggling a ‘flag’ (boolean value) in the function call. Function calls should be treated as interrupts, and as such be kept as short as possible. Running servos and delays in them is generally not recommended.

The nice thing about those bare-bones reed switches is that you can see they’re literally nothing more than switches. They’re either open, or closed, a boolean state, a digital state. they either allow current to flow, or they don’t, nothing in-between. A digital pin reads exactly that. Now you need to find a way to power it, or don’t power it, depending on the state.
Have a look at pull-up and pull-down resistors, that might give some ideas :wink: https://docs.particle.io/reference/firmware/photon/#pinmode-

This explanation might help as well:

ok, so putting one between D2 and GND should work.

I’m afraid that what you’re talking about with the loop above is a little beyond me. I had never seen this language (is it C#?) before Monday and I’m learning as fast as I can… with limited success, as you can see!

Yup, that should work :smile:

The language is ‘Wiring’, which is basically C/C++ with some extras sprinkled on for these kinds of controllers.

As to the loop part, would this help clarify the idea?

volatile bool doBlink = false;

void setup() {
    Particle.function("blinkLed", blinkLed);
}

void loop() {
    if (doBlink == true){
        //blink LED
        doBlink = false;
    }
}

int blinkLed(String command){
    doBlink = true;
    return 1;
}

Basically, do all the hard work in the loop, and only trigger it from the function call.

feels like it should be helping… :smile:

I think I’ve updated as you’ve suggested, but now I’m getting a bunch of errors (“motor2.cpp:37:33: error: ‘toggleopen’ was not declared in this scope” and similar)… one last hint for old time’s sake?

    // ** NOTES
    // ** posStatus1 -> Reed switch for openServo -> HIGH=DISENGAGED, LOW=ENGAGED
    // ** posStatus2 -> Reed switch for twistServo -> HIGH=DISENGAGED, LOW=ENGAGED
    // ** openServo -> Operates string that moves blinds apart -> HIGH=CLOSED
    // ** twistServo -> Operates beaded cord that turns blinds -> HIGH=FLUSH
    // ** 
    // ** 
    
    #define OPEN_TIME 175
    #define TWIST_TIME 200
    
    int servoPin1 = D0; // ToggleOpen servo
    Servo openServo;
    
    
    int servoPin2 = D1; // ToggleTwist servo
    Servo twistServo;
    
    
    int posDetector1 = D2; // ToggleOpen switch input
    int posDetector2 = D3; // ToggleTwist switch input
    
    
    int servoPos = 0; // Reset servo position
    int posStatus1 = 0; // Position status variable ToggleOpen
    int posStatus2 = 0; // Position status variable ToggleTwist
    
    volatile bool doToggle = false;
    volatile bool doTwist = false;
    
    void setup() {
    
    openServo.write(90);
    twistServo.write(90);
     
    openServo.attach( servoPin1 ); // Attach Toggle servo to D0
    Particle.function("toggleOpen", toggleopen);
    
    
    twistServo.attach( servoPin2 ); // Attach Twist servo to D1
    Particle.function("toggleTwist", toggletwist);
    
    
    pinMode(posDetector1, INPUT_PULLDOWN); // Check status of ToggleOpen switch
    pinMode(posDetector2, INPUT_PULLDOWN); // Check status of ToggleTwist switch
    
    
    Particle.variable("posStatus1", &posStatus1, INT); // Declare status variable to check ToggleOpen position status
    Particle.variable("posStatus2", &posStatus2, INT); // Declare status variable to check ToggleTwist position status
    
    
    }
     
    
    
    //  ToggleOpen blinds open/closed
    
    void loop () {
        
        
        if (doToggle == true) {
        
        posStatus1 = digitalRead(posDetector1); // Status of ToggleOpen switch
        posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
    
     
        if     (posStatus1 == LOW, posStatus2 == LOW) { // If OPEN and NOT FLUSH to window then this closes and aligns them
                openServo.write( 80 ), delay(OPEN_TIME), openServo.write( 90 ),// Pulls curtains together
                delay(500), // Half second pause
                twistServo.write( 80 ), delay(TWIST_TIME), twistServo.write( 90 ) ; // Twists to close flush to window
        }
            
        else if  (posStatus1 == LOW, posStatus2 == HIGH) {// If OPEN and FLUSH to window then this closes them
            openServo.write( 80 ), delay(OPEN_TIME), openServo.write( 90 );
        }// Pulls curtains together
            
            
        else if  (posStatus1 == HIGH, posStatus2 == LOW) {// If CLOSED and NOT FLUSH to the window, this opens them
            openServo.write( 100 ), delay(OPEN_TIME), openServo.write( 90 ); 
        } // Pulls curtains apart
    
    
        else if  (posStatus1 == HIGH, posStatus2 == HIGH) {// If CLOSED and FLUSH to the window, this opens and aligns them
            twistServo.write( 100 ), delay(TWIST_TIME), twistServo.write( 90 ), // Twists to close flush to window
            delay(500), // Half second pause
            openServo.write( 100 ), delay(OPEN_TIME), openServo.write( 90 );// Pulls curtains together
        }
    
    
        
        else return (-1);
    
    
    }
    }
    
        if (doTwist == true) {
        
        
        posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
     
     
        if (posStatus2 == LOW) {// If FLUSH TO WINDOW
            twistServo.write( 100 ), delay(TWIST_TIME), twistServo.write( 90 );
        }
     
            
        else {
            twistServo.write( 80 ), delay(TWIST_TIME), twistServo.write( 90 );
        }   
    
    }
    
    }
    
    int toggleOpen(String command) {
        doToggle = true;
        return 1;
    }
    
    int toggleTwist(String command) {
        doTwist = true;
        return 1;
    }

Mind your caps.
Mind your (amount of) brackets. (proper indentation helps A LOT!)
Mind the ‘unsetting’ of your flags.
Ditch the commas ; it doesn’t work like that && make sure you handle them all :wink:

ok, I think I’m with you… I’ve covered off everything you’ve listed above except the ‘unsetting of flags’ which I have no idea what that means.

Plus side, looks like I’m only getting one error now, around my delays.

motor2.cpp:104:35: error: return-statement with a value, in function returning 'void' [-fpermissive]
                         delay(OPEN_TIME); // X
        // ** NOTES
        // ** posStatus1 -> Reed switch for openServo -> HIGH=DISENGAGED, LOW=ENGAGED
        // ** posStatus2 -> Reed switch for twistServo -> HIGH=DISENGAGED, LOW=ENGAGED
        // ** openServo -> Operates string that moves blinds apart -> HIGH=CLOSED
        // ** twistServo -> Operates beaded cord that turns blinds -> HIGH=FLUSH
        // ** 
        // ** 
        
        #define OPEN_TIME 175
        #define TWIST_TIME 200
        
        int servoPin1 = D0; // ToggleOpen servo
        Servo openServo;
        
        
        int servoPin2 = D1; // ToggleTwist servo
        Servo twistServo;
        
        
        int posDetector1 = D2; // ToggleOpen switch input
        int posDetector2 = D3; // ToggleTwist switch input
        
        
        int servoPos = 0; // Reset servo position
        int posStatus1 = 0; // Position status variable ToggleOpen
        int posStatus2 = 0; // Position status variable ToggleTwist
        
        volatile bool doToggle = false;
        volatile bool doTwist = false;
        
        void setup() {
        
            openServo.write(90);
            twistServo.write(90);
         
            openServo.attach( servoPin1 ); // Attach Toggle servo to D0
            Particle.function("toggleOpen", toggleOpen);
        
        
            twistServo.attach( servoPin2 ); // Attach Twist servo to D1
            Particle.function("toggleTwist", toggleTwist);
        
        
            pinMode(posDetector1, INPUT_PULLDOWN); // Check status of ToggleOpen switch
            pinMode(posDetector2, INPUT_PULLDOWN); // Check status of ToggleTwist switch
        
        
            Particle.variable("posStatus1", &posStatus1, INT); // Declare status variable to check ToggleOpen position status
            Particle.variable("posStatus2", &posStatus2, INT); // Declare status variable to check ToggleTwist position status
        
        
        }
         
        
        
        //  ToggleOpen blinds open/closed
        
    void loop () {
            
            
            if (doToggle == true) {
            
                posStatus1 = digitalRead(posDetector1); // Status of ToggleOpen switch
                posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
        
         
                        if (posStatus1 == LOW && posStatus2 == LOW) { // A If OPEN and NOT FLUSH to window then this closes and aligns them
                            openServo.write( 80 ); // B
                            delay(OPEN_TIME);  // C
                            openServo.write( 90 );// D Pulls curtains together
                            delay( 500 ); // E Half second pause
                            twistServo.write( 80 ); // F 
                            delay(TWIST_TIME); // G
                            twistServo.write( 90 ) ; // H Twists to close flush to window
                        }
                
                        else if (posStatus1 == LOW && posStatus2 == HIGH) {// J I If OPEN and FLUSH to window then this closes them
                            openServo.write( 80 ); // K
                            delay(OPEN_TIME); // L
                            openServo.write( 90 ); // M
                        }// Pulls curtains together
                
                
                        else if  (posStatus1 == HIGH && posStatus2 == LOW) {// N If CLOSED and NOT FLUSH to the window, this opens them
                            openServo.write( 100 ); // O
                            delay(OPEN_TIME); // P
                            openServo.write( 90 ); // Q 
                        } // Pulls curtains apart
        
        
                        else if  (posStatus1 == HIGH && posStatus2 == HIGH) {// R If CLOSED and FLUSH to the window, this opens and aligns them
                            twistServo.write( 100 ); // S
                            delay(TWIST_TIME); // T
                            twistServo.write( 90 ); // U Twists to close flush to window
                            delay( 500 ); // V Half second pause
                            openServo.write( 100 ); //W
                            delay(OPEN_TIME); // X
                            openServo.write( 90 );// Y Pulls curtains together
                        }
        
        
            
                        else { 
                            return (-1); 
            
                        }
        
        
            }
    
        
            if (doTwist == true) {
            
            
                posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
         
         
                    if (posStatus2 == LOW) {// If FLUSH TO WINDOW
                       twistServo.write( 100 ); 
                       delay(TWIST_TIME); 
                       twistServo.write( 90 );
                    }
         
                
                    else {
                        twistServo.write( 80 );
                        delay(TWIST_TIME);
                        twistServo.write( 90 );
                    }   
        
            }  
        
    }
        
    int toggleOpen(String command) {
        doToggle = true;
        return 1;
    }
        
        
    int toggleTwist(String command) {
        doTwist = true;
        return 1;
    }

You set the flag to be 'true' in the function call, after which it stays 'true' indefinitely. Unless you'd like some trippy blinds, I'd do something about that :wink: Have a look at my previous example.

As for the error, it tells you the exact problem. You're returning something inside a function that returns 'void', a.k.a 'nothing'. Long story short, you can't return anything 'out the loop'.

A-Ha! Woo Hoo!

“Code verified - Great work!”

Now I just need to wire it up without blowing it or myself up and see if it works!

Thanks so much for your help! I will get it eventually!

2 Likes

just keep swimming :smile:

2 Likes