<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html class="client-nojs" dir="ltr" lang="en"> <head> <meta charset="UTF-8" /> <title>Modules/GPIO - OpenSCADAWiki</title> <meta content="MediaWiki 1.26.4" name="generator" /> <link href="https://www.gnu.org/copyleft/fdl.html" rel="copyright" /> <link href="../files/doc.css" rel="stylesheet" /></head> <body><div class="floatright"><a href="../index.html"><img alt="OpenSCADA" src="../../en/files/index.png" /></a></div><div id="mw_header"> <div class="mw-indicators"> </div> <h1 id="firstHeading" lang="en">Modules/GPIO</h1> </div><div class="mw-content-ltr" dir="ltr" id="mw-content-text" lang="en"><div class="mw-pt-languages" dir="ltr" lang="en"><div class="mw-pt-languages-list autonym"><span class="mw-pt-languages-ui mw-pt-languages-selected mw-pt-progress mw-pt-progress--complete">English</span> • ‎<a class="mw-pt-progress mw-pt-progress--complete" href="../../ru/Modules/GPIO.html" title="Модули/GPIO (100% translated)">mRussian</a> • ‎<a class="mw-pt-progress mw-pt-progress--complete" href="../../uk/Modules/GPIO.html" title="Модулі/GPIO (100% translated)">УкраїнÑька</a></div></div> <table class="wikitable"> <tr> <th> Module </th> <th> Name </th> <th> Version </th> <th> License </th> <th> Source </th> <th> Languages </th> <th> Platforms </th> <th> Type </th> <th> Author </th> <th> Description </th></tr> <tr> <td> <a href="../Modules/GPIO.html" title="Special:MyLanguage/Modules/GPIO">GPIO</a> </td> <td> GPIO </td> <td> 2.1 </td> <td> GPL2 </td> <td> daq_GPIO.so </td> <td> en,uk,ru,de </td> <td> x86,x86_64,ARM </td> <td> DAQ </td> <td> Roman Savochenko </td> <td> GPIO different single board PCs: Broadcom BCM 2835 and more (Raspberry Pi, ...), SUNXI AllWinner H2 and more (Orange Pi Zero, ...). </td></tr></table> <div class="toc" id="toc"><div id="toctitle"><h2>Contents</h2></div> <ul> <li class="toclevel-1 tocsection-1"><a href="#Controller_object"><span class="tocnumber">1</span> <span class="toctext">Controller object</span></a></li> <li class="toclevel-1 tocsection-2"><a href="#Parameters_.28BCM2835.2C_SUNXI.29"><span class="tocnumber">2</span> <span class="toctext">Parameters (BCM2835, SUNXI)</span></a> <ul> <li class="toclevel-2 tocsection-3"><a href="#Function_GPIO:_Mode_.28mode.29"><span class="tocnumber">2.1</span> <span class="toctext">Function GPIO: Mode (mode)</span></a></li> <li class="toclevel-2 tocsection-4"><a href="#Function_GPIO:_Get_.28get.29"><span class="tocnumber">2.2</span> <span class="toctext">Function GPIO: Get (get)</span></a></li> <li class="toclevel-2 tocsection-5"><a href="#Function_GPIO:_Put_.28put.29"><span class="tocnumber">2.3</span> <span class="toctext">Function GPIO: Put (put)</span></a></li> </ul> </li> <li class="toclevel-1 tocsection-6"><a href="#Notes"><span class="tocnumber">3</span> <span class="toctext">Notes</span></a></li> </ul> </div> <p>The module provides OpenSCADA support for General Purpose Inputs/Outputs (GPIOs) based on single-board PCs: </p> <ul><li> BCM2835 and higher — <a class="external text" href="https://www.raspberrypi.org" rel="nofollow noreferrer noopener" target="_blank">Raspberry PI, PI2, PI3</a>;</li> <li> SUNXI AllWinner H2 and higher — <a class="external text" href="http://www.orangepi.org" rel="nofollow noreferrer noopener" target="_blank">Orange Pi, Zero, One, Plus</a>.</li></ul> <p>GPIO on BCM2835 and higher of Raspberry Pi counts 32 pins in maximum, some of them can also performs alternative functions like to: I2C, UART, SPIO. For access to the GPIO there is used the GPIO part of the library <a class="external text" href="http://www.airspayce.com/mikem/bcm2835" rel="nofollow noreferrer noopener" target="_blank">libBCM2835</a>, which are included and building with the module. </p><p>GPIO on SUNXI AllWinner H2 and higher of Orange Pi can have 9 main and 6 additional banks with 32 pins for each one, some of them can also performs alternative functions like to: I2C, UART, SPIO. For access to the GPIO there is used the GPIO part of the library <a class="external text" href="https://github.com/duxingkei33/orangepi_PC_gpio_pyH3" rel="nofollow noreferrer noopener" target="_blank">orangepi_PC_gpio_pyH3</a>, which are included and building with the module. </p> <h2><span class="mw-headline" id="Controller_object"><span class="mw-headline-number">1</span> Controller object</span></h2> <p>GPIO in OpenSCADA is configured by creating a new controller object (Fig.1) and the controller parameter — one GPIO parameter for one card. </p> <div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:682px;"><a class="image" href="http://oscada.org/wiki/File:GPIO_obj_cntr.png"><img class="thumbimage" height="574" src="../files/GPIO_obj_cntr.png" width="680" /></a> <div class="thumbcaption">Fig.1. Configuration tab of a controller object.</div></div></div></div> <p>From this tab you can set: </p> <ul><li> The state of the controller object, as follows: status, "Enabled", "Running" and the database name containing the configuration.</li> <li> Identifier, name and description of the controller.</li> <li> The state "Enabled" and "Running", in which the controller object must be switched at boot.</li> <li> Name of the table to store the controller parameters configuration.</li></ul> <h2><span class="mw-headline" id="Parameters_.28BCM2835.2C_SUNXI.29"><span class="mw-headline-number">2</span> Parameters (BCM2835, SUNXI)</span></h2> <p>The parameter is the direct representative-reflection of the GPIO, which contains a list of attributes of a discrete type in an amount that corresponds to this GPIO type. The parameter configuration tab is shown in Figure 2. The data collection is performed only in synchronous mode since the GPIO should be fast. </p> <div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:682px;"><a class="image" href="http://oscada.org/wiki/File:GPIO_obj_prm.png"><img class="thumbimage" height="574" src="../files/GPIO_obj_prm.png" width="680" /></a> <div class="thumbcaption">Fig.2. Configuration tab of a parameter.</div></div></div></div> <p>With the parameter configuration tab you can set: </p> <ul><li> The state of the parameter: type (BCM2835, SUNXI), "Enabled" and static functions list.</li> <li> Identifier, name and description of the parameter.</li> <li> The state "Enabled", in which the parameter must be translated at start up.</li></ul> <p>The tab "Attributes" of GPIO is shown in Figure 3 for BCM2835, and Figure 4 for SUNXI. For the GPIO, the "Configuration" tab (Fig. 5) is also available with the IO mode and the inversion state. </p> <div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:682px;"><a class="image" href="http://oscada.org/wiki/File:GPIO_obj_prmAttr.png"><img class="thumbimage" height="740" src="../files/GPIO_obj_prmAttr.png" width="680" /></a> <div class="thumbcaption">Fig.3. Tab "Attributes" of a parameter of the "BCM2835".</div></div></div></div> <div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:881px;"><a class="image" href="http://oscada.org/wiki/File:GPIO_obj_prmAttrSUNXI.png"><img class="thumbimage" height="606" src="../files/GPIO_obj_prmAttrSUNXI.png" width="879" /></a> <div class="thumbcaption">Fig.4. Tab "Attributes" of a parameter of the "SUNXI".</div></div></div></div> <div class="center"><div class="thumb tnone"><div class="thumbinner" style="width:706px;"><a class="image" href="http://oscada.org/wiki/File:GPIO_obj_prmCfg.png"><img class="thumbimage" height="650" src="../files/GPIO_obj_prmCfg.png" width="704" /></a> <div class="thumbcaption">Fig.5. Tab "Configuration" of a parameter.</div></div></div></div> <p>For the fastest access to the GPIO, the parameter provides three static functions: "mode", "get" and "put". These functions can be used in the OpenSCADA programming environment for extraordinary interaction algorithms organization. To address the function, you can use the static call of the address <b>GPIO.{cntr}.{prm}.{Func}()</b> or the dynamic <b>SYS.DAQ.GPIO.{cntr}.{prm}["{Func}"].call()</b>. Where: </p> <ul><li> {cntr} — identifier the controller object;</li> <li> {prm} — identifier the parameter object;</li> <li> {Func} — identifier the function.</li></ul> <p>At the moment, it is also possible to dynamically connect the static functions as the fastest and simultaneously flexible solution, for example: </p> <pre style="white-space: pre-wrap;"> function put = addr+".fnc_put"; if(put) { put(D4, vl&0x10); put(D5, vl&0x20); put(D6, vl&0x40); put(D7, vl&0x80); }</pre> <p>And in this configurable way there for now have implemented next templates of the low-level devices: </p> <ul><li> <a href="../Libs_LowLevelDevices.html#DHT" title="Special:MyLanguage/Libs/LowLevelDevices">GPIO: DHT11,22 (AM23XX)</a></li> <li> <a href="../Libs_LowLevelDevices.html#1602A" title="Special:MyLanguage/Libs/LowLevelDevices">GPIO: 1602A(HD44780) (1602A)</a></li></ul> <h3><span class="mw-headline" id="Function_GPIO:_Mode_.28mode.29"><span class="mw-headline-number">2.1</span> Function GPIO: Mode (mode)</span></h3> <p><i>Description</i>: GPIO mode, input or output.<br /> <i>Parameters</i>: </p> <table class="wikitable"> <tr> <th> ID </th> <th> Parameter </th> <th> Type </th> <th> Mode </th> <th> By defaults </th></tr> <tr> <td> rez </td> <td> Result </td> <td> Integer </td> <td> Return </td> <td> </td></tr> <tr> <td> pin </td> <td> Pin </td> <td> Integer </td> <td> Input </td> <td> </td></tr> <tr> <td> set </td> <td> Setting the input mode: 1-Input, 2-Input (pull up), 3-Input (pull down), 4-Output </td> <td> Integer </td> <td> Input </td> <td> 0 </td></tr></table> <h3><span class="mw-headline" id="Function_GPIO:_Get_.28get.29"><span class="mw-headline-number">2.2</span> Function GPIO: Get (get)</span></h3> <p><i>Description</i>: GPIO get pin level.<br /> <i>Parameters</i>: </p> <table class="wikitable"> <tr> <th> ID </th> <th> Parameter </th> <th> Type </th> <th> Mode </th> <th> By defaults </th></tr> <tr> <td> rez</td> <td> Result </td> <td> Bool </td> <td> Return </td> <td> </td></tr> <tr> <td> pin </td> <td> Pin </td> <td> Integer </td> <td> Input </td> <td> </td></tr></table> <h3><span class="mw-headline" id="Function_GPIO:_Put_.28put.29"><span class="mw-headline-number">2.3</span> Function GPIO: Put (put)</span></h3> <p><i>Description</i>: GPIO put pin level.<br /> <i>Parameters</i>: </p> <table class="wikitable"> <tr> <th> ID </th> <th> Parameter </th> <th> Type </th> <th> Mode </th> <th> By defaults </th></tr> <tr> <td> pin </td> <td> Pin </td> <td> Integer </td> <td> Input </td> <td> </td></tr> <tr> <td> val </td> <td> Value </td> <td> Bool </td> <td> Input </td> <td> </td></tr></table> <h2><span class="mw-headline" id="Notes"><span class="mw-headline-number">3</span> Notes</span></h2> <p>The module was tested on the boards <a class="external" href="http://oscada.org/wiki/Special:MyLanguage/Using/Raspberry_Pi" title="Special:MyLanguage/Using/Raspberry Pi">Raspberry Pi 2,3 models B</a> and <a class="external" href="http://oscada.org/wiki/Using/Orange_Pi" title="Using/Orange Pi">Orange Pi Zero</a>. </p><p>Access time to the static functions was measured comparing to the different methods which you can see <a href="../Modules/JavaLikeCalc.html#Productivity" title="Special:MyLanguage/Modules/JavaLikeCalc">here</a> and the overall performance measurement is given in the following table: </p> <table class="wikitable"> <tr> <th> GPIO type </th> <th> get(), us </th> <th> put(), us </th></tr> <tr> <td> Raspberry Pi 3 </td> <td> 0.36 </td> <td> 0.27 </td></tr> <tr> <td> Orange Pi Zero </td> <td> 1.2 </td> <td> 1.2 </td></tr></table> </div><table style="border-top: dotted 2px #999999; margin-top: 20pt; color: gray;" width="100%"><tr><td style="text-align: left;" width="40%"><a href="http://oscada.org/wiki/Modules/GPIO/en">Modules/GPIO/en</a> - <a href="http://oscada.org/en/main/about-the-project/licenses/">GFDL</a></td><td style="text-align: center;">April 2025</td><td style="text-align: right;" width="40%">OpenSCADA 1+r3018</td></tr></table></body> </html>