User Tools

Site Tools



XTension Multipurpose GPIO Kit

NOTE: These instructions are preliminary for those testing the beta units. This is not complete nor final at this time.

The XTension GPIO module is available as a kit or as a pre-assembled and tested device. It is based on an ESP32 processor and can be reprogrammed by the Arduino IDE if you wish to use the hardware without the built in firmware. The device requires 2.4ghz WiFi to be available and an XTension instance running or other software that can connect to it.

XTension Setup:

An instance of XTension running on the same subnet as the device is required. Only one instance of the XTension Kits Plugin needs to be setup to support any number of XTension kit devices on the same subnet.

In XTension visit the Interface Status window and click the New Interface button in the toolbar. Select “XTension Kits” from the plugin/Device popup. Give the interface a descriptive name and save it. Now back in the Interface Status window check the enabled checkbox next to the new entry you just created.

WiFi Setup:

When the device is powered up for the first time, the Setup button is pressed or there are no wifi networks configured, it will start it’s configuration access point. When in Setup Mode the LED will flash quickly twice every second. See the “Status LED Patterns” section below for more info on the status LED. From your mobile device or with a laptop join this wifi network. A captive portal will display with a subset of settings for the device. From here you can enter up to 3 wifi networks to connect to. The device will chose the one with the best signal strength. Here you should also give the device a better name and bonjour/mDNS name than the defaults. If you wish you can also set a static IP address or change other networking parameters at this point. Click the save and restart button to make your changes live. The device will restart and if it connects properly to wifi the captive portal will disappear and your device will reconnect to the previously selected WiFi network.

GPIO Web Interface:

Once the device has joined your WiFi you can access it’s built in configuration web pages from any browser. Use the Bonjour/mDNS name or the static IP address that you entered during the WiFi Setup step above.

Main Web Page:

When visiting the built in web server you will first see this page. When first started up no GPIO is configured so the page will show only the toolbar of links to other config pages and the block with the CPU temperature and WiFi signal strength. If you have GPIO configured as outputs, 1-wire devices or DHT-22 sensors attached their current status will be displayed on this page as well.

Device Settings Page:

Most device settings including WiFi can be set from this page:

  • Device Name: The name of this specific device which will be used when creating units in XTension and displayed on the web pages. This should be descriptive but not too long as it is limited to 30 characters. Once you enable the XTension connection in the next step any units created will have this name prepended to their function or other names. You can change the name of the device after the initial creation of units in XTension but the name change will not be forced to already existing units. Therefore it makes sense to set the name to something more useful first. Once the units are created you can edit their name to be anything that is more useful or descriptive to you. The name from the device is just the startup default when creating them so that they are more easily identified.
  • XTension Connection: It is possible to use the device or just setup the device without connecting to XTension. This way you can delay the creation of units until you have setup the various inputs and outputs or if you don’t have an XTension instance to talk to yet. This does limit the functionality of the device.
  • XTension Device ID: Each GPIO or other board has a unique ID that is created from the MAC address of the WiFi. This is used when creating units associated with this board in XTension. It is editable so that if you need to replace one board with another you can just set it’s ID to be the same as the old board and therefore all the units in XTension will pick up the new board as if nothing had changed. If you are not replacing a board you probably do not want to change this. It must be 6 characters in length but could be changed to something descriptive if you wish to be able to see the unit addresses and know immediately which device they are attached to without looking at their names.
  • mDNS/Bonjour Name: The .local address the device will create on the network. This should be changed to something useful and much be changed if you have more than one device on the network as they must be unique.
  • AP Name in Setup Mode: The name of the WiFi access point that will be created when in setup mode. Generally you won’t need to change this, but if for some reason you want to have multiple devices in setup mode at the same time then this will allow you to tell them apart when connecting to it.
  • Check For Updates: Once a week the device will request a small json file from the server checking to see if a firmware update is available for it. If so it will write a note to the XTension log that you should log in and update it. No device info other than the device type and board revision are sent to the server, no data is colected on the server apart from the standard apache logs that would show the IP address the request originated from. If you do not wish to have the device make this check, or if you are setup where there is no internet connection you may wish to turn this off.
  • Web Server Port: The port the web server should run on. Defaults to 80 and really no reason to change it unless you are dealing with routers or wifi devices with very strange limitations.
  • Web Server Security: uses basic authentication for controlling and configuring the device. You should never expose the built in web server to the internet as a whole and even if you turn this on it will not make things that much more secure. Generally you would not need this on a local network unless you suspect guests might find it and mess with it and yet are incapable of capturing the plain text sending of the password when you log in.
  • WiFi Settings: Here you can enter up to 3 WiFi SSID’s and passwords for networks that the device should connect to. It will do a scan for available networks upon startup and anytime the wifi connection is dropped and will connect to the network that has the best signal strength of any that are found.
  • Network Settings: In general I would recommend setting up a static IP address for any such devices, but it is not strictly necessary with the XTension connection being stateless and the availability of the Bonjour name on the network. If you do wish to set it up as such the settings are in this section.
  • One Wire Settings: The device supports up to 16 one wire temperature sensors connected to the 1-wire interface which is on the terminal block next to the barrel jack power connector.
  • Enable One Wire: Check this box to enable the one wire subsystem to startup and start looking for devices. Note that after a restart it may take a few moments for the 1-wire devices to be found and send a first update. Any one wire devices found will have units in XTension automatically created and the values will show on the main web interface page.
  • Read Interval: How often should the 1-wire bus be read. The minimum is every 5 seconds but that will result in a rather chatty network connection as the devices tend to fluxuate in the range of a tenth of a degree fairly often.
  • Temp Format: Self Explanatory.
  • Device Status Units: by default the device will send it’s signal strength and CPU temperature to units in XTension. These can be helpful or just interesting to see how well the device is working but if they create too much noise or you simply don’t care to see those values you can turn them off here and then delete the units from XTension.
  • Status LED: See below for status LED patters that can tell you what the device is doing. These settings further control how the Status LED is handled.
    • In Proper Connected and Operating State… When connected and working properly you can set the LED to be dimly lit indicating visually that everything is OK and power is on, or if having the LED visible is not desirable you can have it turn off in this state.
    • Led Dim/Bright Level: The LED dim and bright levels can be configured so that they are visible or not too bright. If you set the bright and dim too similarly to each other however you won’t be able to see when the LED is flashing information at you.
    • Echo Status LED: (Beta: this is unimplemented for the GPIO but will eventually echo the status LED pwm on the first GPIO pin so that an LED external to the enclosure could be setup to show the state. This is implemented for the PWM dinner devices and will use PWM channel 1 as the LED output for this purpose)
    • Turn On Find Me Mode: this causes the LED to flash between the bright and dim levels very quickly so that the physical device you are talking to can be identified when you might have several together. It does not require a save and restart. The find me mode can be turned on and off in real time.

After making any changes you must click the Save and Restart button to make them live. If you navigate to another page of the interface after making changes they will not be saved.

GPIO Settings Page:

To setup the GPIO or configure the expansion module you have installed click the link in the navigation toolbar labeled “GPIO.”

Expander Module Settings:

If you have installed an expansion module you need to select it’s type from the popup list on this page. Once selected the appropriate interface for that module will be displayed. See the individual sections below for more info on available expander modules.

GPIO Settings:

Below the Expander settings there is an entry for each of the GPIO pins. There are 8 gpio pins brought out to the removable screw terminals on the top of the board and 11 more available through the expander connection. See the section below about GPIO Ratings and Safe Usage for more information. GPIO capabilities are different for each pin, some supporting higher level functions and more interesting connections. See the table below for more info and also the user interface on the web page though that is incomplete as of this beta version.

GPIO Function Description:

  • Unused: If set to Unused the GPIO will not be shown in any interfaces and no unit will be created for it in XTension.
  • In Use By Expander: Expander cards will make use of some or all of the GPIO available on the GPIO Expander port. In some cases they may also use GPIO 5 and 7 from the main board which are also available on the expander port. When an expander is selected on the interface the GPIO that is used by the expander card are displayed as In Use By Expander and you cannot make changes to them or use them for anything else.
  • Input Pullup: A pullup resistor to the 3.3v is used and you should connect the pin to the board GND to switch the state. Like an alarm system the unit will be ON when the connection is broken and off or safe when connected to GND.
  • Input Pulldown: A pulldown resistor to GND is used and you should connect the pin to the 3.3v rail on the board to switch the state. In this case the input will show as off when disconnected and on when connected to 3.3v. Note that connecting this to a voltage higher than 3,3v or any other source may damage the board. Use the 3.3v source outputs on the first group of removable headers. You may also wish to use a current limiting resistor inline to reduce the risk of damage to the device should you short the connection to ground while setting up wires and such. Recommend that you use the pullup under normal circumstances.
  • Analog Voltage Input: GPIOs 7, 8, 16, 17, 18 and 19 support analog voltage inputs in the range of 0 to 3.3v. In order to sense the voltage the power supplies of the board and whatever is creating the input must share a ground. The numerical output is not completely linear and so cannot be converted to an exact voltage but some simple math will get you approximately there. See the ESP32 analog input specs for more information. While the input is protected against over voltage it is still possible to damage or destroy the board by attaching higher than 3.3v to this input.
  • Button To Gnd: Like the input pullup this is a specific input for a button that connects to GND when pushed. It is different from the Input Pullup in that it includes some debouncing to keep it from firing many times while you’re pressing. The output is an On event when the button is pushed and no event when the button is released except in the case of a Hold action. (BETA: the interface contains interface elements from the PWM device that are not valid for the GPIO only device. The multi-tap and hold actions may not yet be sent to XTension or other sources.)
  • Button To V+: Same as Button To Gnd except that the connection should be to the 3.3v rail on the board.
  • Touch Button: GPIOs 1, 2, 4 and 8 support touch sensing and translating that to the on/off state of a button in XTension. Since every sensor you might connect this too will have a different untouched capacitance a “Touch Threshold” will need to be set. (BETA: There is not yet a simple way of displaying the current capacitance value so setting the threshold may require some experimentation. You can also set the input to the Touch Capacitance type and watch the value in XTension as you touch the sensor and release it then change it back to Touch Button entering a decent value you discovered in the other test.)
  • Touch Capacitance: Instead of a button with a threshold as the Touch Button this creates an analog unit in XTension that will display the current value as sensed. Might be useful for other kinds of detection or proximity or some such.
  • Switch To Gnd: A switch connected from the GPIO to GND. Same debouncing as the Button above but will send an off or on depending on the state of the switch.
  • Switch to V+: Same as the Switch To Gnd but for when you need to use the 3.3v output as the other side of the switch.
  • Counter, Sensor To GND: A counter input when the sensor will make connection to GND for the count. You can set the input to increment the counter on the rising, falling or both edges of the input. The count, if any, will be reported after the reporting interval that is set in seconds in the interface. This is useful for things like flow sensors or electricity sensors that output a pulse.
  • Counter, Sensor To V+: Same as the Counter to GND above but expects the sensor to switch to 3.3v instead of GND. (BETA: The web interface for setting the edge detection and interval does not properly display for this selection. If you need to set this up, set it up as a counter to gnd setting the needed values there and save the settings. Then change the settings to Counter to V+ and save again. The previous settings will be preserved.)
  • DHT-22 Temp/Humidity Sensor: Any of the first 8 GPIO can have a DHT-22 or similar style temperature/humidity device connected to it. They should be powered from the 3.3v and gnd available on the board and have their data line connected to the GPIO input. A Temperature and Humidiy unit will be created in XTension and will show on the main page interface. If you are using a board mounted sensor no other hardware is required. If you are using a bare DHT device it may be necessary to add a pullup or pulldown resistor to the data line in order for it to work properly. See the DHT data sheets for using this. I do not recommend using the cheaper DHT-11 sensors they have horrible stability and accuracy and are not worth saving a few bucks there. Get the better DHT-22 or AM2302 which are basically the same devices.
  • Radio Receiver: a 433mhz or 315mhz receiver device can be connected to any of the first 8 GPIO pins. Note that only a single radio is supported per board so you cannot have both types on the same GPIO board. For better reception, reception indication and transmission capabilities please consider using the radio expansion card. This input type is excellent at receiving many of the 433mhz alarm and remote control devices out there. The transmission capability is more limited. (BETA: transmission is not yet enabled for the expander card) Any device that is received will cause a unit in XTension to be created for it’s ID number and you can attach logic and actions there. If the device is a simple button or event like motion sensing you can use the unit as it is after changing it’s name. If the device has on and off like some remotes or a door/window sensor then you should trigger both and let XTension create the 2 units. Then change the address of the ON unit to be the address of the ON unit, a colon and the address of the off unit. Like “12345:67890” or whatever the address of the 2 units are. Then delete the unit that was created for the OFF event. That single unit will now turn on and off with the reception of the 2 commands. I fund the range of most such devices to be quite excellent but you can add any number of additional GPIO devices with a radio to your network as needed to cover the entire area. If a transmitter is received by more than one of the physical GPIO radios only the single unit will be created and it can increase the reliability of the reception. In other words, it will not create a unit for the GPIO receiver in the living room and another for the receiver in the bedroom. There will be only one unit with those ID numbers and whichever receiver receives it first will trigger the change. Unfortunately there is no information about where the low battery bit is in the devices that support that so when the low battery happens the unit will stop receiving it’s updates as the address will have changed. To work around this XTension radio button units have a low battery address field that you can also fill in with the on and off values when the battery is low. If those are received then the device will continue to function but set the low batt flag. The only way to discover this is to run the device on low batteries or to run it from a bench supply and crank the voltage down until the low batt detector is triggered. Not all devices will even check for low battery so some experimentation here may be necessary. When choosing devices keep in mind that devices that are advertised as “learning” may not work unless you can program them with some other 433 transmitter. They will not transmit a unique ID number necessary until they learn one from another device. Just about any non-learning remote or alarm device on 433mhz work great. Note also that there are so many of these devices and they vary so much from device to device that some may have better range than others and some may not work at all. I recommend ordering a single device to test and not a case of something first in case it turns out not to be supported.
  • IR Receiver: An IR receiver device (not just a simple phototransistor) can be connected to any of the first 8 GPIO inputs. Powered from the 3.3v and gnd rail on the device with the data output connected to the GPIO pin. (more info on this as well as an Expander card to support multiple inputs and even outputs is in the works) When you point a remote at it and press a button a unit in XTension will be created with the code of the button as it’s address and will receive an ON event whenever the same code is received again. Not all remotes may be supported but only those with the most common modulation rates and such but is a way to get a remote output from a remote to do some other action in XTension.
  • Servo: A servo control output on any of the first 8 GPIO pins. The hertz of the output as well as the max and minimum position outputs are configurable in the interface once selecting this. Most servos are 5v and so must have their own power supply to power them. This will also better serve to isolate the noise generated by the motors. When powering one via an external power supply the gnd side of that power supply must be connected to the gnd output of the GPIO card so that the 2 devices can send data to each other. Otherwise it will not see the control pulses. The ground to the board power supply and the data connection from the GPIO pin to the pwm input on the servo is all that is required. The device in XTension will have a min/max value of what you set in the interface and controlling it will set the location of the servo. (BETA: as of this moment there is no rate control, the servo will change immediately and as fast as it can from the one position to the other. Future builds will have the ability to set a rate and possibly a curve for the change so that it can be more smooth.) This PWM could also be used to control brushless motor speed via a proper ESC using the output from the card as the input to the ESC. (BETA: As of the current beta this is totally untested, I have yet to get to the part on the list where I even connect one to the board, but the software is as complete as it can be without testing)
  • Output (LOW at power on): GPIO output with the value set to LOW at startup. See limitations on output current and voltage above. At startup the output will be connected to GND. Additionally there is a “reverse logic” button that will reverse how the interface and XTension show and control the output. It will still startup as LOW however, the interface will just show the output as ON if that is selected.
  • Output (HIGH at power on): Same as the above except that the output will be HIGH or connected to 3.3v at startup.
  • Output Return To Previous State: Same as the above but the output will return to it’s last controlled state when the device is powered on. Note that when starting from a power off state there may be some uncertainty of the output state until the firmware has loaded. If you need to make sure that an output is on or off when powered down please use an external pull up and pull down resistor in addition to the setting to make sure there are no quick changes when powering on. When rebooting via the web interface while changing values the state is preserved and no flickering should occur.
  • Output Analog Voltage: GPIO 5 and 7 support outputting an analog voltage between 0 and 3.3v. Make sure you properly limit the current output from this. The unit in XTension will let you set the level. See the ESP32 DAC documentation for more info on what is possible and how to properly use it.
  • Encoder Lines: 2 optical encoders can be connected to the GPIO pins. Each one will require 2 inputs an A and a B with the common attached to the 3.3v rail. (BETA: in the PWM device these can be used to directly control the level of outputs, they serve no function yet in the GPIO board but will eventually be able to create a unit in XTension for them or to directly control a separate PWM dimmer device.) Most encoders also have a push button output which could be connected to another GPIO pin to get that input into XTension.

GPIO Ratings and Safe Usage:

The pins brought out to the screw terminals have extra protection to try to protect the CPU from excessive voltage or spikes from static but it is still definitely possible to damage or destroy the CPU by using these improperly. The aux GPIO on the expander connector may have other limitations and not support all the functionality. (BETA: As of this beta version the capabilities of these are not limited in the UI so you can select functions they won’t support.) The maximum current output per GPIO pin should be limited to 12ma and the total output from all the GPIO pins should be limited to 40ma. In reality the ESP32 seems to support quite a bit more than this without damage but if you do that you are taking your fate into your own hands. If you need to run more than a 5mm led from a GPIO pin directly you should use the GPIO to turn on a transistor or mosfet. There are many diagrams and tutorials available for safely connecting such things to an esp32 or arduino. In the case of an NPN channel mosfet no other hardware is required, in the case of a transistor a 1k or so resistor in between the GPIO output and the transistors gate is required or the transistor will burn itself out fairly quickly.

Controlling Relays:

A more common use of the GPIO may be controlling relays. Please do not connect a relay directly to a GPIO pin as it will draw too much current and the back EMF pulses from the coil will eventually destroy the ESP32 chip. A transistor or mosfet control as well as a snubber circuit is absolutely required to control such a thing from a GPIO output. There are many inexpensive logic level relay boards available on the internet that are optically isolated and can be used directly from the GPIO pins. A 3.3v relay board can be powered from the 3.3v output on the board itself as long as the entire current usage with all the relays on doesn’t exceed an amp. The GPIO output can be used to control a 3.3v board of this type as well as a 5v board of this type, but if a separate power supply is needed the grounds must be connected to the ground on the GPIO board or they cannot talk to each other. 12 volt relays can probably be used also and possibly powered from the same 12v power supply that is used to power the GPIO board. The boards I have tested with however have not been activated by the level of output possible at 3.3v that is output from the GPIO. I have had success by removing the jumper on the boards that connect the relay power with the logic power and powering the logic on the board from the 3.3v supply and the relay power directly from the 12v supply. This has let me use several 12v relay modules successfully here, but there are so many out there that your experience may be different. I will create a page with details on how to separate the 2 power sections on most of the relay boards at some point or drop me a note if you need that sooner.

Repeat! Do NOT just connect the coil of a relay to a GPIO output. It will damage or destroy the ESP32.

Firmware Page:

You can manually upload firmware update files, or start an over the internet update from the firmware update page. When you load the page the current firmware version, current web interface version and the hardware revision of your board are displayed. A check for update is started and if there is firmware available for your specific device and hardware revision it will be displayed here and a button will show to let you start that update automatically over the internet.

Note that when doing an update over the internet the device may restart twice as the web interface and firmware are loaded in separate steps.

Most software updates will include both a Firmware file, The file name will end in .bin and include somewhere in the name the hardware revision. For example a firmware update for the initial unit with a hardware revision of “GPIO2” will be named something like “gpio firmware.134.GPIO2.bin. The web firmware will also include the hardware revision but will end in “.spiffs”

Unless an update has specific instructions to the contrary you should load the firmware file first, and then the web interface file.

Once a file is uploaded the hardware revision is validated and if it matches the software is loaded. Upon success the device will reboot and the page will reload showing the new firmware version. If you have a second web interface file load it at this time.

Status LED Patterns:

The GPIO device has a status LED that will flash different patterns depending on the connection state. During startup the LED will do a quick breathing animation to let you know that the hardware and firmware has loaded.

Setup Mode:

If the device has no WiFi networks configured or at any time if you press the setup button it will go into setup mode and advertise it’s own configuration wifi access point for you to conenct to. When in Setup Mode the Status led will flash twice quikly every second.

Connecting To Wifi:

During the connection to WiFi the status LED will flash 1 second on and 1 second off. Normally it takes about 15 seconds or less to connect to the network. If this continues for much more than that you should check the SSID and password you entered and that the WiFi is within range. You can press the setup button during this process to skip the connection and restart the Setup access point.

No XTension Connection:

If the wifi has connected but no XTension has found the device the status LED will quickly flash once a second. This is also displayed if the XTension connection checkbox on the device settings web page is turned off.

Normal Operation:

In normal operation with a valid XTension connection the LED will be dimly lit to indicate that everything is working properly. You can configure the brightness of the LED or even set it to 0 if you do not wish the LED to be lit all the time. This setting is available on the settings web page. If the wifi drops or the connection to XTension is lost the LED will change to the appropriate state to indicate that.

kits/gpio.txt · Last modified: 2021/10/31 16:12 by James Sentman