Working with Electronics: Controlling the Electronic Speed Controller via the Web

The Electronic Speed Controller (ESC) can be controlled in the same way as the servo using the Raspberry Pi’s GPIO pins. The biggest difference is that theCapture pulse widths to control it are different.

To find out what pulses made it do what I decided that it would be easier to set the duty cycle to 10o and then to change the pulse widths based on this. I discovered that then at a pulse width of 15 the ESC made the motor go forwards, and after much trial and error, that a pulse width of 13 made it go backwards.

Control via PHP

PHP runs python scripts on page load, so I needed to have the control buttons link to a page with the python script called on it. I could do this in a similar way to how I did with the servo control and have several different pages that look the same but with different scripts called when they load, however this would leave me with over 10 different pages, and this seems like a lot.

I therefore decided that I would load a page that calls the ‘forwards’ or ‘backwards’ script, then goes back to the page the user was just on. To do this I needed some JavaScript.

<script type=”text/javascript”>

window.setTimeout(‘history.back();’, 1000); // waits a specified number of seconds before going back

</script>

This simple bit of script went into the <head> of my document. By changing the value ‘1000’ to another number you can change the time period that the page waits before going back. I then decided to add a simple message to the page that told the user that their previous command was currently in progress. I decided a .gif would make the page more interesting.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s