Difference between revisions of "GPIO"

From Let's Control It
Jump to navigation Jump to search
(Added LongPulse Command)
 
(27 intermediate revisions by 3 users not shown)
Line 3: Line 3:
  
 
== Hardware ==
 
== 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.
+
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.
  
 
----
 
----
Line 9: Line 9:
 
----
 
----
  
= Software =
+
= ESP Easy =
 
 
== Custom Sketch ==
 
 
 
== ESP Easy ==
 
 
You dont need a Device definition (task) to control basic GPIO output. You can always control all the pins by HTTP.
 
You dont need a Device definition (task) to control basic GPIO output. You can always control all the pins by HTTP.
  
=== Basic on/off ===
+
== Commands ==
We can control a pin with simple http url commands. To change the pin to high or low steady output:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=GPIO,<pin>,0</nowiki>'''
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=GPIO,<pin>,1</nowiki>'''
 
 
 
 
 
=== PWM control ===
 
To set a certain PWM level:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=PWM,<pin>,<level></nowiki>'''
 
 
 
 
 
=== Short pulses ===
 
To send a pulse to a certain pin:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=Pulse,<pin>,<state>,<duration></nowiki>'''
 
 
 
Example to send an active high pulse on GPIO 2 for 500 mSeconds:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=Pulse,2,1,500</nowiki>'''
 
 
 
=== Long pulses ===
 
A long puls is basicly the same as the plain pulse. The only difference is the timebase in seconds rather than in milliseconds. So it's more suiteable for longer durations.
 
To send a long pulse to a certain pin:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=LongPulse,<pin>,<state>,<duration></nowiki>'''
 
 
 
Example to send an active high pulse on GPIO 2 for 10 minutes:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=LongPulse,2,1,600</nowiki>'''
 
 
 
=== Servo motor control ===
 
To control a Servo Motor:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=Servo,<servo nr>,<pin>,<position></nowiki>'''
 
 
 
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:
 
 
 
'''<nowiki>http://<ESP IP address>/control?cmd=Servo,1,0,90</nowiki>'''
 
'''<nowiki>http://<ESP IP address>/control?cmd=Servo,2,2,45</nowiki>'''
 
 
 
 
 
=== Tones ===
 
  
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:
+
{| class="wikitable mw-collapsible sortable"
 +
! style="width: 15%|Command
 +
! GPIO
 +
! style="width: 10%|Value
 +
! Information
 +
! style="width: 25%|HTTP example
 +
! style="width: 15%|MQTT example<BR>(topic: <MQTT subscribe template>/cmd)
 +
|-
  
'''<nowiki>http://<ESP IP address>/control?cmd=tone,14,1300,200</nowiki>'''
+
| GPIO,<gpio>,<value>
 +
| 0...16
 +
| 2 (HIGH-Z)<BR>or<BR>1 (HIGH)<BR>or<BR>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. Setting GPIO to "2" means that it will be able to detect low level relays (with high impedance, "Z").
 +
| http://<espeasyip>/control?cmd=GPIO,12,1<BR>http://<espeasyip>/control?cmd=GPIO,12,0
 +
| GPIO,12,1<BR>GPIO,12,0
 +
|-
  
Plays a 1300 hz tone for 200 ms on gpio-14h
+
| PWM,<GPIO>,<state><BR>PWM,<GPIO>,<state>,<duration>
 +
| 0...'''15'''
 +
| 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. You can use the duration (ms) parameter to create a fading.
 +
| http://<espeasyip>/control?cmd=PWM,13,500<BR>http://<espeasyip>/control?cmd=PWM,13,0
 +
| PWM,13,500<BR>PWM,13,0
 +
|-
  
=== Melodies and ringtones ===
+
| 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
 +
|-
  
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]]
+
| 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,1,600
 +
|-
  
(dont forget to remove the spaces)
+
| LongPulse_mS,<GPIO>,<value>
 +
| 0...16
 +
| <state>,<duration>
 +
| '''To send a ''long'' pulse to a certain pin.''' A long pulse (mS) is the same as the regular long pulse. The only difference is the time base in milliseconds rather than in seconds. Example to send an active high (1) pulse on GPIO 15 for 1 second.
 +
| http://<espeasyip>/control?cmd=LongPulse_mS,15,1,1000
 +
| LongPulse_mS,15,1,1000
 +
|-
  
'''<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>'''
+
| Servo,<value1>,<GPIO>,<value2>
 +
| 0...16
 +
| value1: servo number<BR>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<BR>http://<espeasyip>/control?cmd=Servo,2,16,45
 +
| Servo,1,2,90<BR>Servo,2,16,45
 +
|-
 +
|}
  
 +
== Tones, melodies and ringtones ==
  
This plays a melody on pin 14.
+
For using tone and rtttl commands you should head over to the [[Buzzer (RTTTL)]] section.
  
You can also use these from rules. We use it to let our alarm system give feedback to the user via a piezo speaker.
+
== Caveats: User Beware! ==
  
To make a boot-sound on startup, create a rule like this:
+
<div style="border-bottom:1px solid black; background: red; padding:0.4em 1em; font-size:110%; font-weight:bold; font-color: white;"><span style="color:white">There are many pins called GPIO but be aware: These pins differ even they are all called GPIO!</span></div>
On System#Boot do
 
  rtttl,14:d=10,o=6,b=180,c,e,g
 
endon
 
  
== ESP Connexio ==
+
<div style="border-bottom:1px solid red;  background:#F6CECE; padding:0.4em 1em 0.4em;">The ESP8266 is a small chip with a lots of possibilities. The GPIO16 (D0) is a good example: Besides GPIO it is used for waking up from deep sleep. Internally it is connected to a hardware timer and does not have all possibilities of other GPIOs in exchange. This also means that a DS18B20 will not work on GPIO16, neither will any other plugin using interrupts work.
 +
For a full list of GPIO pins and hints what's connected inside the chip see the [[Configuration]] page.</div>

Latest revision as of 22:41, 7 June 2018

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 2 (HIGH-Z)
or
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. Setting GPIO to "2" means that it will be able to detect low level relays (with high impedance, "Z"). http://<espeasyip>/control?cmd=GPIO,12,1
http://<espeasyip>/control?cmd=GPIO,12,0
GPIO,12,1
GPIO,12,0
PWM,<GPIO>,<state>
PWM,<GPIO>,<state>,<duration>
0...15 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. You can use the duration (ms) parameter to create a fading. 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,1,600
LongPulse_mS,<GPIO>,<value> 0...16 <state>,<duration> To send a long pulse to a certain pin. A long pulse (mS) is the same as the regular long pulse. The only difference is the time base in milliseconds rather than in seconds. Example to send an active high (1) pulse on GPIO 15 for 1 second. http://<espeasyip>/control?cmd=LongPulse_mS,15,1,1000 LongPulse_mS,15,1,1000
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.

Caveats: User Beware!

There are many pins called GPIO but be aware: These pins differ even they are all called GPIO!
The ESP8266 is a small chip with a lots of possibilities. The GPIO16 (D0) is a good example: Besides GPIO it is used for waking up from deep sleep. Internally it is connected to a hardware timer and does not have all possibilities of other GPIOs in exchange. This also means that a DS18B20 will not work on GPIO16, neither will any other plugin using interrupts work. For a full list of GPIO pins and hints what's connected inside the chip see the Configuration page.