Difference between revisions of "GPIO"

From Let's Control It
Jump to navigation Jump to search
Line 69: Line 69:
 
'''<nowiki>http://<ESP IP address>/control?cmd=Servo,2,2,45</nowiki>'''
 
'''<nowiki>http://<ESP IP address>/control?cmd=Servo,2,2,45</nowiki>'''
  
== Tones ==
+
== Tones, melodies and ringtones ==
  
From ESPEasy v2.0.0-dev6 (in the testing plugin set) its also possible to play a tone on a pin, via a speaker or piezo element:
+
For using tone and rtttl commands you should head over to the [[Buzzer (RTTTL)]] section.
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=tone,14,1300,200</nowiki>'''
 
 
 
Plays a 1300 hz tone for 200 ms on gpio-14h
 
 
 
== Melodies and ringtones ==
 
 
 
From ESPEasy v2.0.0-dev6 (in the testing plugin set) its also possible to play melodies via [[https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language#Technical_specification RTTTL]]
 
 
 
(dont forget to remove the spaces)
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=rtttl,14:d=8,o=5,b=180,c6,b,c6,p,g,g-,p,f,b,c6,p,d6,p,g,p,c6,b,c6,p,d6,p,f,g,g-,4p,g,f,4d-</nowiki>'''
 
 
 
 
 
This plays a melody on pin 14.
 
 
 
You can also use these from rules. We use it to let our alarm system give feedback to the user via a piezo speaker.
 
 
 
To make a boot-sound on startup, create a rule like this:
 
On System#Boot do
 
  rtttl,14:d=10,o=6,b=180,c,e,g
 
endon
 

Revision as of 19:39, 22 October 2017

Introduction

The ESP module can control things with it's build-in GPIO output pins. We can turn these on or off or we can set these pins to a special Pulse modulated value (PWM output). And it's also possible to send short pulses (single puls) to one of these pins to control specific devices that are switched with a single short high or low signal.

Hardware

It's best to connect a LED to the GPIO to test your setup. You could dim this LED with the PWM mode commands. Be aware that the ESP8266 only supplys 3,3v at a max current of only ~10mA.


LED.png


ESP Easy

You dont need a Device definition (task) to control basic GPIO output. You can always control all the pins by HTTP.

Commands

Command GPIO Value Information HTTP example MQTT example
(topic: <MQTT subscribe template>/cmd)
GPIO,<gpio>,<value> 12...16 1 (HIGH)
or
0 (LOW)
Basic on/off. We can control a pin with simple http url commands. To change the pin to high or low steady output http://<espeasyip>/control?cmd=GPIO,12,1
http://<espeasyip>/control?cmd=GPIO,12,0
GPIO,12,1
GPIO,12,0
PWM,<GPIO>,<value> 12...16 0...1023 To set a certain PWM level. If you have set a certain GPIO to a PWM level and want to use it as a regular HIGH/LOW pin you need to reset by setting the PWM level to 0. http://<espeasyip>/control?cmd=PWM,13,500
http://<espeasyip>/control?cmd=PWM,13,0
PWM,13,500
PWM,13,0

Short pulses

To send a pulse to a certain pin:

http://<ESP IP address>/control?cmd=Pulse,<pin>,<state>,<duration>

Example to send an active high pulse on GPIO 2 for 500 mSeconds:

http://<ESP IP address>/control?cmd=Pulse,2,1,500

Long pulses

A long pulse is basically the same as the plain pulse. The only difference is the time base in seconds rather than in milliseconds. So it's more suiteable for longer durations. To send a long pulse to a certain pin:

http://<ESP IP address>/control?cmd=LongPulse,<pin>,<state>,<duration>

Example to send an active high pulse on GPIO 2 for 10 minutes:

http://<ESP IP address>/control?cmd=LongPulse,2,1,600

Servo motor control

To control a Servo Motor:

http://<ESP IP address>/control?cmd=Servo,<servo nr>,<pin>,<position>

We currently support a maximum of two servo motors so you can build a pan & tilt device if you like.

Example to set servo 1 on gpio-0 to a 90 degree position and servo 2 on gpio-2 to a 45 degree position:

http://<ESP IP address>/control?cmd=Servo,1,0,90 http://<ESP IP address>/control?cmd=Servo,2,2,45

Tones, melodies and ringtones

For using tone and rtttl commands you should head over to the Buzzer (RTTTL) section.