Automated Window Blinds - Spark Core

Yeah, you’re right, @axyr. I reversed them. I’ll correct the diagram. Must be early onset Alzheimer’s! :slightly_smiling:

Just figured something else out. My blinds wouldnt open exactly 100% I needed to do this

def on() {
put’10’
sendEvent(name: ‘switch’, value: ‘on’)
}

However making the change did nothing, then I figured out that it had to do something with the delay. Increasing it 1000 fixed the problem

int setState(String command){
myservo.attach(A4);
myservo.attach(SERVO_PIN);
state = command.toInt();
state = map (state, 0, 99, open, closed);
myservo.write(state);
delay(1000);
analogWrite(A4,255);
return 1;
}

Hello,

So I worked on this pretty extensively over the last week. I took my code back to the original code because I felt it stayed closer to what I wanted. Feel free to modify to your hearts content as axyr did above.

The main bonus of this code is two way communication. I figured out the particle API commands for an httpGet to grab a variable set on particle.

So head on over to github and get the original branch:

@a6pack @keithcroshaw @hawesg @Pete
I know this was something you will be looking for.

The main advantage of this is that now polling and refresh will show status if an outside smart app opens the blinds or if the slider is used… (which is working again)!

Enjoy!
Justin

Oh and on a side note I think this opens the possibility of having a general Spark device type that variables could be setup for the function and particle variable so that they could be entered in the device setup ui and then the particle could work for about any purpose the user wanted and have smart apps call it.

2 Likes

Awesome! Pretty cool. I’ll take a look soon.

This is great! Thank you, @jjhtpc! I’ll take a look tonight in preparation for installation of my 4th Photon blind install tomorrow, so this is just in time!

@jjhtpc - Thanks again! This is great work. I was “close” with my code in trying to retrieve a variable from my Photons, but close only counts in horseshoes and hand grenades as they say.

Before I start modifying my code this morning, I was wondering about your #include statements in the beginning of your Spark Code (in your Original branch). Are are those two, particle-blinds.ccp and particle.blinds.h references part of the public library? I can’t seem to find them. Also, your code in the Original doesn’t seem to require the includes, or am I reading it incorrectly? Sorry for the questions as I am still learning!

1 Like

The .h and .cpp are completely useless. In fact I think they are blank. Particle build just barks at me if I don’t have anything. Let me know if there is anything missing or that needs to be added. Also if you want to setup a separate branch for the photo resistor and actuator that you have setup let me know(I think those are great additions) oh and also the new variable inclusion could be setup to the pull the photo resistor readings back to smartthings. I think there may have been mention of that a few posts back.

Updated github with the servo buzz code. I always forget that servo disconnect code.

Using myservo.detach(); is that the same as analogWrite(A4,255)?

Probably has the same outcome. Really the write(A4,255) will send a pwm, this actually caused an error for me. The attach detach actually cuts power.

I read this thread with massive interest… it’s such a great project and a feature I was always willing to have.
I ordered all the hardware needed on SparkFun, they basically have everything and the shipping cost is very reasonable.

I have a question though, I have 5 windows almost next to each other, and I was thinking I may be able to control them from a single Photon.
I didn’t find how many PWM outputs I can control at the same time on the GPIO interface, and it could also well be that 5 servos at the same time will draw too much current.

I read that @a6pack (hello from DC area as well BTW) did plug 2 servos, has anybody tried more?

Edit I found that: PWM is available on D0, D1, D2, D3, A4, A5, WKP, RX, TX with a caveat: PWM timer peripheral is duplicated on two pins (A5/D2) and (A4/D3) for 7 total independent PWM outputs. For example: PWM may be used on A5 while D2 is used as a GPIO, or D2 as a PWM while A5 is used as an analog input. However A5 and D2 cannot be used as independently controlled PWM outputs at the same time.

Not sure if I would be able to control independently the blinds, but I actually need to have them open or close the same way anyways…

So exited to get my order delivered!

I think using the attach and detach code you could piece together as many servos as possible. (Your hardware limitations document it well). The caveat to that is that you do have to run them sequentially.

Yea I’m doing two at once. For mine. If you can reach a wire. I bought a long length of servo wire. If you look up you can see it but who looks up from where I’m sitting.

@Francky, I started with the idea of independent control of each blind connected to a single Photon, but practically speaking when I have two window next to each other I’m fairly certain that I will only want both blinds at the same angle. In fact, I quickly created groups to control the all of the blinds in large areas of my house instead of trying to control individual windows.
As you pointed out, I’ve only connected a max of two servos to one Photon. I would love to have connected more servos to one Photon, but the wiring would have been problematic. I really didn’t have a good way to run cable from the windows to a central location where the Photon would sit. Short of ripping out the drywall and running the cable, I simply gave up and paired one Photon per window that were adjacent to each other.
I also shared your concern about current draw on greater than two servos/Photon. I was prepared to provide a separate 5V power rail for the servos should I have 3 or more connected. However, as I mentioned, I gave that up given the difficulty in running wires and distance limitations on carrying the voltage over long distances.

Just kind of “officially” released my project. Let me know if you guys want to contribute to or it or have any critical comments. Thanks again to @jjhtpc and even @a6pack for the toggle button idea, I still have to do that. I didn’t solder anything, life’s too short fort that, the blind housing isn’t going to be moving around so the breadboard works.

Thanks for the brainstorming!

5 Likes

Nice work. I had thought about putting this out on hackster myself, but I want to finish up the last few finishing touches which I am doing this weekend. Hiding USB cords required drilling and some keystone plates to make it look nice. I’ll probably post some video this weekend when phase 1 is fully complete.

1 Like

Yeah, I finally received my Photon and 2 Servos along with PSU, coupler, breadboard, cables etc…
I struggled a bit get the right code for the Photon and the Right Device Handler, but eventually it works wonderfully on the bench.

Tomorrow, I’ll try to get a second servo hooked up but modifying the code, that’ll be a great exercise to try to get my head around all those new stuff…
I’ll also try to power these 2 Servos with long 24AWG cable and see if I can still power them.
And I’ll probably try to fit a servo in one of my blinds… headache in perspective but excited!

Though, I did try @jjhtpc latest code, and I can’t get anything working.
First the 2x #Include line at the beginning generates errors, so I tried to rid of them… but that’s probably not I’m supposed to do…lol
You said it’s probably empty, am I supposed to create empty files with those names and upload them in the Library (if this is even possible?)

Yes empty files for those two names. You can try to remove them but particle compile was throwing errors if I didn’t have a .h and .CPP.

1 Like

Thanks @jjhtpc, it worked, but I eventually got rid of the 2 empty files and the reference into your code, no errors anymore.

Loads of progress here! I got everything working :slight_smile:

For the Software part:
I spent a lot of time reverse engineering the code to understand how everything works… and mostly I now get it, so that’s an achievement.

I spent time to modify both Device Handler code and Photon Code to make it how I want it to behave

I even found a way to slow down the Servo, that makes it a tad quieter with a lower pitch.

For the mechanical part:
I also spend time to find a way to fit the servo into the rail, the main problem being having a too short Hex inner rod and the tilt mechanism in the servo’s way.
I was thinking to create crazy stuff to extend the inner rod, or even replace it with a longer one, but I ended up just reversing the inner rod and it gaves me the extra 1/4 inches neeeded.

BUT the big disappointment is when I found the Servo cannot turn the inner rod when the Tilt mechanism is attached to it… even manually it’s tough, it just requires too much torque, so I had to remove it for the tests.
I don’t really like not having a way to change the tilt manually… I don’t know how I could do… need to think about it…
Has anyone of you had to remove it too?

Here is the Servo mounted:

The tilt mechanism on the other end (I had to remove it, add too much torque)

Curious, does the tilt rod still work? I felt like it would add too much load on the servo.

The Tilt on my blind is controlled via 2 cords, one to close up, one to close down (it’s not a rod).
It’s connected to the box where there are 2 gears to transform into a rotation on the inner tilt metal rod.

If both the servo is connected with the tilt mechanism in place, I can still use the cords to control the tilt, it makes the servo turning of course (no sure how’s that good for the servo).
On the other hand, the servo hasn’t enough torque to rotate it (and I have a good torque on this servo), I guess it’s just the way the gear are… not sure if any other blind would allow me rotate the inner rod when the tilt mechanism is still there though…