GPIO

From Let's Control It
Jump to: navigation, search

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> 0...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> 0...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
Pulse,<GPIO>,<value> 0...16 <state>,<duration> To send a short pulse to a certain pin. Example to send an active high (1) pulse on GPIO 14 for 500 mSeconds. Pulse duration is in milliseconds. State is 1 or 0. http://<espeasyip>/control?cmd=Pulse,14,1,500 Pulse,14,1,500
LongPulse,<GPIO>,<value> 0...16 <state>,<duration> To send a long pulse to a certain pin. 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 suitable for longer duration. Example to send an active high (1) pulse on GPIO 15 for 10 minutes. http://<espeasyip>/control?cmd=LongPulse,15,1,600 LongPulse,15,600
Servo,<value1>,<GPIO>,<value2> 0...16 value1: servo number
value2: position
To control a Servo Motor. 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 2 to a 90 degree position and servo 2 on GPIO 16 to a 45 degree position. http://<espeasyip>/control?cmd=Servo,1,2,90
http://<espeasyip>/control?cmd=Servo,2,16,45
Servo,1,2,90
Servo,2,16,45

Tones, melodies and ringtones

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