H-Bridge

The project I’m working on window blind tilt control over Wifi. My automation control will issue HTTP commands to the Imp to open or close the blinds. I’m interesting in controlling a small hobby motor attached to an H-Bridge. I want to control forward and reverse through HTTP string along with detect position using a hall sensor. Anyone have any suggestions how I can get started with the code; I’m new to Squirrel and the Imp.

Thanks!

Are you using one of these for motor control?

I’m thinking the command to ‘move to a specific’ position of the motor can be HTTP, but the actual moving to position and feedback needs to be on the control board itself. Using HTTP to act as a PID loop will be too slow. There can be feedback using HTTP, but it would not be reporting back the exact position until the motor is stopped.

Is ‘command’, ‘move to position’, ‘report feedback’ going to require “real-time” accuracy by using HTTP?

I’m using this motor control from adafruit (http://adafruit.com/products/807).

I have a solution prototyped using an Arduino and RF module. I’ve had good luck setting the motor runtime in code and using the hall sensor to check the blind position. The HTTP string will simply issue the open or close function. I thought about using an absolute encoder; however, setting runtime and using an if statement to check position has seems to be working reliably.

With switching to the Imp to leverage connectivity and processing, I think this will simplify the build and adding additional feedback to the automation control (e.g. position, temp, light, etc.).

Thanks for the help!

This is what I did… copied from elsewhere.

and then used HTTP in node in the planner. I know next to zero about web programming but I guess you have that part. The HTTP in node will provide a URL if you doubl-click the thing in the top right corner of it.

`
//Provides some rudimentary control from the web: code copied from someone… who?
class inputHTTP extends InputPort {

function set(httpVal) { 
    
    //erver.log((httpVal));
	
	switch (httpVal){
	
		
		case 20:
			server.log("FAN OFF" + httpVal);
			fanOFF();
		
			break;
		
		case 21:
		
			server.log("FAN ON" + httpVal);
			fanON();
			break;
			
		
			
		case 50:
			
            server.log("Planner Process Logging off");
            PlannerLogRate = 0;
			
			break;
		
		case 51:
			
            server.log("Planner Process Logging ON");
            PlannerLogRate = 1;
			
			break;
		case 60:
			
            server.log("Planner ERROR Logging off");
            ErrorLoggingOn = 0;
			
			break;
		
		case 61:
			
            server.log("Planner ERROR Logging ON");
            ErrorLoggingOn = 1;
			
			break;
            
		default:
		
			//
			
			
		
		break;
	}
	
    server.log(httpVal);
    
}

}

imp.configure(“name of my imp thing”, [inputHTTP()], []);

`

My project has a motor that is turned on and off with a SSR.

Do you have a website where you can create a web page and use PHP scripting? You really don’t need PHP, maybe just an HTML form the does a POST to your imp server key. That key (the link to post to) is found when you create an HTTP IN node. The node gives you the URL to use.

I mention using PHP because it opens things up to automated processes that don’t require human intervention (like an HTML form).

If you don’t have a web page, I would be willing to create a test page for you on my website where it has two buttons (OPEN and CLOSE). I only need to know what the URL is for your HTTP IN node. The buttons will POST a ‘C’ or ‘O’ to the HTTP IN node. Let me know. If you decide you need a test page, private message me in a conversation. You don’t want everyone going to the webpage and opening and closing your blinds.

I am using a VeraLite from MiCasaVerde to handle the HTTP and automation. I was able to get things working using the below code and using two HTTP In node like in the Coffee Time example. Next I will add the hall sensor(s) to update the position of the blinds. If anyone has any suggestion please let me know. The hardest part of this project it seems is working through the mechanical aspect (needed torque, motor blind coupler, etc.). I will try to post the wiring and updated code as I finish it. Thanks for all the suggestions.

`
// Auto Blind by Dominick C. Watts
//dominickwatts.wordpress.com
// Adapted from code written by Don Kitchen, Hardware end by Matt (Zanderx) Everts- Coffee Time
// Tilt open and close window blinds based on HTML IN data received from web

// input class for Open control channel (from HTML IN)
class open_input extends InputPort
{
name = "Tilt Open"
type = “number”

function set(value)
{
// update the display
server.show(“Tilt Open”);
server.log(“Tilt Open”);

    //set H-Bridge pins for correct direction
    hardware.pin9.write(0);
    hardware.pin8.write(1);
    
    // Sleep for 1000ms, allow time for blinds to open- maybe better way??
    imp.sleep(1.00);
    
    //Turn off H-Bridge
    hardware.pin8.write(0);  //make sure output pins are all low
    hardware.pin9.write(0); //make sure output pins are all low

}
}
// input class for Close control channel (from other HTML IN)
class close_input extends InputPort
{
name = "Tilt Close"
type = “number”

function set(value)
{
// update the display
server.show(“Tilt Close”);
server.log(“Tilt Close”);

    //set H-Bridge pins for correct direction 
    hardware.pin8.write(0);
    hardware.pin9.write(1);
    
    // Sleep for 1000ms, allow time for blinds to close- maybe better way??
    imp.sleep(1.00);
    
    //Turn off H-Bridge
    hardware.pin8.write(0);  //make sure output pins are all low
    hardware.pin9.write(0); //make sure output pins are all low

}
}
// Configure pin 8 & 9 as digital outputs
hardware.pin8.configure(DIGITAL_OUT);
hardware.pin9.configure(DIGITAL_OUT);

// Register with the server , passing our two inputs as an array
imp.configure(“AUTO BLINDS”, [open_input(), close_input()], []);

// End of code.
`