GPIO Ports Konfigurieren

  • Hmm und wieso geht das:

    Code
    root@raspberrypi:/var/www# cat /sys/devices/virtual/gpio/gpio1/{direction,value} 
    in
    1
    root@raspberrypi:/var/www# echo 0 >/sys/class/gpio/gpio1/value                   
    -bash: echo: Schreibfehler: Die Operation ist nicht erlaubt.
    root@raspberrypi:/var/www#

    Ist das ein Bug?


    Pin auf "out" gestellt, value auf 1 gesetzt, Pin wieder auf "in" gestellt, value bleibt auf 1

    Bei anderen Pins wird dann Value auch auf 0 gestellt sobald man ihn von "out" auf "in" umstellt:

    Wieso aber nicht bei Pin1 ?


    Was ist an Pin-1 so besonders? :-/

  • Hi Georg,

    neee - da hast Du schon recht ...

    Ich hab da allerdings auch - ehrlich gesagt - keinen Schimmer, wie man die Ports da schalten kann. Das ist für mich eine vollkommen neue Seite - ich seh die Pins aus der C-Api sozusagen immer nur von innen ;) ...

    webiopi und gpio können die Werte ja scheinbar schalten ... ich hab' aber keine Ahnung, wie sie das machen.

    Das, was meigrafd da probierte, klang zunächst mal logisch ... allerdings nach Deiner Erklärung auch nicht mehr so wirklich :)

    Nee, nee ... ich bleib bei C :thumbs1:

    das reimt sich sogar ....

    Danke und schönen Abend noch,
    -ds-

  • Also Pin-0 und Pin-1 vom RaspberryPi rev1 sind anscheint etwas besonderes, da kann man bei direction " in " trotzdem auf Value 1 stellen :s
    (siehe post#21)


    Und wieso geht das nicht:

    Code
    root@raspberrypi:/var/www# gpio -g mode 25 in                            
    root@raspberrypi:/var/www# cat /sys/devices/virtual/gpio/gpio25/{direction,value} 
    out
    0
    root@raspberrypi:/var/www# gpio -1 mode 25 in                                     
    root@raspberrypi:/var/www# gpio mode 25 in   
    root@raspberrypi:/var/www# cat /sys/devices/virtual/gpio/gpio25/{direction,value}
    out
    0
    root@raspberrypi:/var/www#

    ...so langsam bin ich völlig verwirrt :irre: lvmdaalxqry.gif

  • Jooo ... wenn ich mir das so anschaue, was Du da so treibst, dann kann ich das :wallbash: nachvollziehen.

    Aber: ich fürchte, Du fällst gerade auf den Nummerierungs-Wirrwarr rein.

    mach mal nur einen


    25 ist, nach meinem Verständnis der phys. Pin 25 und damit GND.

    cu,
    -ds-

  • Hmmm, sicher? :s

    Spoiler anzeigen

    gpio-rev1-new.pnggpio-rev2-new.png

    Spoiler anzeigen

    gpio mode 0 out
    gpio write 0 1

    The above uses the wiringPi pin numbers to set pin 0 as an output and then sets the pin to a logic 1.

    gpio -g mode 17 out
    gpio -g write 17 1

    This uses the BCM_GPIO pin numbering scheme and performs the same operation as above.

  • Nöö ... ach Mensch ... jetzt peil ich bald gar nichts mehr ... :s

    Nein, nein und nochmals nein ... mit diesem Durcheinander kann und will ich mich nicht anfreunden :no_sad:

    Ich hab' mir genau aus diesem Grund mal eine mapping-Funktion in C geschrieben und kann da blind zwischen den einzelnen Bezeichnungen wechseln. Da muss man ja gaga werden, wenn man dauernd beim umswitchen ist :irre:

    Am besten webiopi nehmen, da hast Du ein Bildchen, da klickst Du drauf und gut ist ;) ...

    cu,
    -ds-

  • Hehe :fies:


    Physikalisch ragen 26 Stifte an dem "P1" raus, abzüglich 3V , 5V, GND und GPIO 14 & 15 (insg. 9) bleiben 17 Pins über ... wiringPi 0 bis 16 ergibt 17 :daumendreh2:

    Also schlussfolger ich das man auf die anderen 9 Pins kein Einfluss nehmen aber auch nicht über gpio ansprechen kann :-/

    Anscheint kann ich mit rev1 auch nicht GPIO-0 und GPIO-1 benutzen, zumindest nicht als Eingang.. Wenn ich die auf "in" stelle ist Value fest auf "1" aber nicht veränderbar


    Aber um die Verwirrung weiter zu führen kann man laut dem Programm https://github.com/adafruit/Adafruit-Retrogame einen beliebigen GPIO pin zu nem GND "umwandeln"

    In den Quellcode bischen rein geguckt und das hier gefunden:

    Code
    if(io[i].key == GND) {
                // Set pin to output, value 0 (ground)
                if(pinConfig(io[i].pin, "direction", "out") ||
                   pinConfig(io[i].pin, "value"    , "0"))
                    err("Pin config failed (GND)");
            }

    Bedeutet das, dass jeder GPIO der als direction = out und value = 0 gesetzt wird ein GND pin wird?

  • Das sieht wohl so aus ...
    Und 14 und 15 sind Rx und Tx ... die kann man, zumindest beim B Rev. 2, schon nutzen. Fällt halt die rs232 flach.

    Aber mal ehrlich ... nachdem ich mir meine Gehirnwindungen mit der wget-Geschichte von jar schon genug verknotet habe, glaubst Du doch nicht ernsthaft, dass ich Dir hier im Moment auch nur annähernd folgen kann ... das muss ich mir mal in Ruhe durch den Kopf gehen lassen.

    Naja, vielleicht ist das alles gar nicht so kompliziert, wenn man das mal genauer beleuchtet.

    Ich hab auch noch einen: Du kannst die Eigenschaften der Pins bezüglich Strom "umprogrammieren" ... hehe :fies:

    Wenn ich dran denke, schick ich dir mal den Link.

    cu,
    -ds-

    hab den Link gefunden ...

    schon krass, was man da alles drehen kann/könnte :fies:

    cheers,
    -ds-

  • Ich hab ein weiteres Script geschrieben um den aktuellen Status der GPIO Pins anzeigen zu lassen...

    Dazu nutze ich quasi AJAX, der Status wird alle 0,5 Sekunden (500 millisec) aktualisiert - das erzeugt allerdings sehr viele Logeinträge in /var/log/apache2/access.log die sich soweit ich weiss nicht unterbinden lassen (es sei dann man schaltet das logging für apache2 allgemein aus), aber da man das Script ja nicht permanent geöffnet hat ist das eigentlich auch nicht weiter tragisch ;)

    Das Script ist komplett standalone, es benötigt also kein wiringPi o.ä. - es ermittelt anhand der /proc/cpuinfo welche Revision genutzt wird und zeigt dementsprechend die GPIO P1 und sofern man rev2 hat auch P5 an.. Da ich aber nur einen rev1 hab weiss ich nicht ob das auch tatsächlich funktioniert :)

    Das sieht dann so aus:

    Es wird also auch angezeigt welche Pin-Nummer das auf der Platine wäre und was auf diesem Pin normalerweise ist (I²C oder SPI usw) mit farblicher Zuteilung der Pins: die grünen Pins können eigentlich unbedenklich genutzt werden

    Bitte mal testen und ggf Bugs reporten - Danke :)


    Es werden 2 Dateien benötigt:

    gpio.php:
    [code=php]
    <?php
    // v0.1

    // update gpio pin stat all ... millisec
    // NOTE: due to using ajax this massivly spams /var/log/apache2/access.log
    $UPDATE = "500";

    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>GPIO PINs Status</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type=text/css>
    .kreis {
    font: 11px Georgia, "Times New Roman", Times, serif; /* Schrift*/
    padding:1px; /*Innerer Abstand*/
    width:2px; /* gleiche Breite wie */
    height:2px; /* Höhe angeben damit es ein Kreis wird */
    text-align:center; /* Text wird zentriert*/
    border-radius:50%; /* Border-Radius auf 50% bedeutet rund*/
    #background:rgba(70,70,70,0.3); /* Hintergrundfarbe */
    border: 7px solid rgba(50,50,50,0.5); /* Rand Stärke und Farbe */
    #box-shadow: 0px 1px 3px rgba(50,50,50,0.2) inset; /* inner Schatten Stärke und Farbe */
    }
    .lpin {
    text-align:right;
    valign:middle;
    }
    .rpin {
    text-align:left;
    valign:middle;
    }
    .lvolt {
    text-align:right;
    valign:middle;
    }
    .rvolt {
    text-align:left;
    valign:middle;
    }
    .lgnd {
    text-align:right;
    valign:middle;
    }
    .rgnd {
    text-align:left;
    valign:middle;
    }
    .value {
    text-align:center;
    valign:middle;
    }
    </style>


    <!-- auto refresh -->
    <script type="text/javascript">
    function getHTTPObject() {
    var http = false;
    // Use IE's ActiveX items to load the file.
    // MS Internet Explorer (ab v6)
    if(typeof ActiveXObject != 'undefined') {
    try {http = new ActiveXObject("MSXML2.XMLHTTP");}
    catch (e) {
    // MS Internet Explorer (ab v5)
    try {http = new ActiveXObject("Microsoft.XMLHTTP");}
    catch (E) {http = false;}
    }
    // If ActiveX is not available, use the XMLHttpRequest of Firefox/Mozilla etc. to load the document.
    // Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
    } else if (XMLHttpRequest) {
    try {http = new XMLHttpRequest();}
    catch (e) {http = false;}
    }
    return http;
    }
    var http = getHTTPObject();
    var ID = "GPIO";
    var url = "status_gpio.php";
    var params = "UPDATE";
    //Call a function when the state changes.
    function handler() {
    if (http.readyState == 4 && http.status == 200) {
    document.getElementById(ID).innerHTML = http.responseText;
    // JavaScript function calls AutoRefresh() every .. milli seconds
    setTimeout('AutoRefresh()',<?php echo $UPDATE; ?>);
    //$("txt").value = http.responseText;
    }
    }
    function AutoRefresh(){
    http.open("GET",url+"?"+params,true);
    http.onreadystatechange = handler;
    http.send(null);
    }
    AutoRefresh();
    </script>

    </head>
    <body>

    <?php

    # Stats of GPIO Pins
    echo "<div id='GPIO'><?php include('status_gpio.php'); ?></div>\n";

    ?>

    </body>
    </html>
    [/php]

    status_gpio.php:
    [code=php]
    <?php

    # RaspberryPI GPIO pin - colors
    /*
    http://www.farb-tabelle.de/de/farbtabelle.htm
    rgb(red, green, blue)
    GND = black
    3V3 = tomato (quasi hell rot)
    5V = red (quasi dunkel rot)
    */
    $GND ='<p class="kreis" style="background:rgb(0,0,0);"></p>';
    $threeVolt = '<p class="kreis" style="background:rgb(255,99,71);"></p>';
    $fiveVolt = '<p class="kreis" style="background:rgb(255,0,0);"></p>';
    #pin: 0,2,1,3
    $blue = '<p class="kreis" style="background:rgb(30,144,255);"></p>';
    #pin: 4,17,21,27,22,18,23,24,25
    $greenpin = '<p class="kreis" style="background:rgb(50,205,50);"></p>';
    #pin: 10,9,11,8,7
    $pinkpin = '<p class="kreis" style="background:rgb(199,21,133);"></p>';
    #pin: 14,15
    $yellowpin = '<p class="kreis" style="background:rgb(238,238,0);"></p>';

    # get RaspberryPI Revision
    if (!file_exists("/tmp/.rpi_rev")) {
    GetRPIrev();
    WriteRPIrev($RPIrevision);
    } else {
    $RPIrevision = file_get_contents("/tmp/.rpi_rev");
    }


    $S="&nbsp;";
    $s=" ";

    echo "<center>\n";
    echo "<font face='Arial' size='3' color=FF0000><b>GPIO pin Status - P1</b></font>\n";
    echo "<table class='GPIOpinTable' border=1 cellpadding=3 cellspacing=0 bordercolorlight>\n";
    echo "<tr> <th>description</th> <th>value</th> <th>pin#</th> <th>".$S."</th> <th>".$S."</th> <th>pin#</th> <th>value</th> <th>description</th> </tr>\n";
    echo "<tr>\n";
    echo "<td class='lvolt'>3.3V</td> <td>".$S."</td> <td class='lpin'>".$S."1</td> <td>".$threeVolt."</td>\n";
    echo "<td class='rvolt'>".$fiveVolt."</td> <td class='rpin'>".$S."2</td> <td>".$S."</td> <td>5V</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    if ($RPIrevision == 1) {
    echo "<td>GPIO 0 (I2C_SDA)</td> <td class='value'><b>".GetGPIOpinValue(0)."</b></td> <td class='lpin'>".$S."3</td> <td>".$blue."</td>\n";
    } else {
    echo "<td>GPIO 2 (I2C_SDA)</td> <td class='value'><b>".GetGPIOpinValue(2)."</b></td> <td class='lpin'>".$S."3</td> <td>".$blue."</td>\n";
    }
    echo "<td class='rvolt'>".$fiveVolt."</td> <td class='rpin'>".$S."4</td> <td>".$S."</td> <td>5V</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    if ($RPIrevision == 1) {
    echo "<td>GPIO 1 (I2C_SCL)</td> <td class='value'><b>".GetGPIOpinValue(1)."</b></td> <td class='lpin'>".$S."5</td> <td>".$blue."</td>\n";
    } else {
    echo "<td>GPIO 3 (I2C_SCL)</td> <td class='value'><b>".GetGPIOpinValue(3)."</b></td> <td class='lpin'>".$S."5</td> <td>".$blue."</td>\n";
    }
    echo "<td class='rgnd'>".$GND."</td> <td class='rpin'>".$S."6</td> <td>".$S."</td> <td>GND</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 4 (GPCLK0)</td> <td class='value'><b>".GetGPIOpinValue(4)."</b></td> <td class='lpin'>".$S."7</td> <td>".$greenpin."</td>\n";
    echo "<td>".$yellowpin."</td> <td class='rpin'>".$S."8</td> <td class='value'><b>".GetGPIOpinValue(14)."</b></td> <td>GPIO 14 (UART_TxD)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td class='lgnd'>GND</td> <td>".$S."</td> <td class='lpin'>".$S."9</td> <td>".$GND."</td>\n";
    echo "<td>".$yellowpin."</td> <td class='rpin'>".$S."10</td> <td class='value'><b>".GetGPIOpinValue(15)."</b></td> <td>GPIO 15 (UART_RxD)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 17</td> <td class='value'><b>".GetGPIOpinValue(17)."</b></td> <td class='lpin'>".$S."11</td> <td>".$greenpin."</td>\n";
    echo "<td>".$greenpin."</td> <td class='rpin'>".$S."12</td> <td class='value'><b>".GetGPIOpinValue(18)."</b></td> <td>GPIO 18 (PCM_CLK)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    if ($RPIrevision == 1) {
    echo "<td>GPIO 21 (PCM_DOUT)</td> <td class='value'><b>".GetGPIOpinValue(21)."</b></td> <td class='lpin'>".$S."13</td> <td>".$blue."</td>\n";
    } else {
    echo "<td>GPIO 27 (PCM_DOUT)</td> <td class='value'><b>".GetGPIOpinValue(27)."</b></td> <td class='lpin'>".$S."13</td> <td>".$blue."</td>\n";
    }
    echo "<td class='rgnd'>".$GND."</td> <td class='rpin'>".$S."14</td> <td>".$S."</td> <td>GND</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 22</td> <td class='value'><b>".GetGPIOpinValue(22)."</b></td> <td class='lpin'>".$S."15</td> <td>".$greenpin."</td>\n";
    echo "<td>".$greenpin."</td> <td class='rpin'>".$S."16</td> <td class='value'><b>".GetGPIOpinValue(23)."</b></td> <td>GPIO 23</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td class='lvolt'>3.3V</td> <td>".$S."</td> <td class='lpin'>".$S."17</td> <td>".$threeVolt."</td>\n";
    echo "<td>".$greenpin."</td> <td class='rpin'>".$S."18</td> <td class='value'><b>".GetGPIOpinValue(24)."</b></td> <td>GPIO 24</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 10 (SPI_MOSI)</td> <td class='value'><b>".GetGPIOpinValue(10)."</b></td> <td class='lpin'>".$S."19</td> <td>".$pinkpin."</td>\n";
    echo "<td class='rgnd'>".$GND."</td> <td class='rpin'>".$S."20</td> <td>".$S."</td> <td>GND</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 9 (SPI_MISO)</td> <td class='value'><b>".GetGPIOpinValue(9)."</b></td> <td class='lpin'>".$S."21</td> <td>".$pinkpin."</td>\n";
    echo "<td>".$greenpin."</td> <td class='rpin'>".$S."22</td> <td class='value'><b>".GetGPIOpinValue(25)."</b></td> <td>GPIO 25</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 11 (SPI_SCLK)</td> <td class='value'><b>".GetGPIOpinValue(11)."</b></td> <td class='lpin'>".$S."23</td> <td>".$pinkpin."</td>\n";
    echo "<td>".$pinkpin."</td> <td class='rpin'>".$S."24</td> <td class='value'><b>".GetGPIOpinValue(8)."</b></td> <td>GPIO 8 (SPI_CE0)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td class='lgnd'>GND</td> <td>".$S."</td> <td class='lpin'>".$S."25</td> <td>".$GND."</td>\n";
    echo "<td>".$pinkpin."</td> <td class='rpin'>".$S."26</td> <td class='value'><b>".GetGPIOpinValue(7)."</b></td> <td>GPIO 7 (SPI_CE1)</td>\n";
    echo "</tr>\n";
    echo "</table>\n";

    # Only RaspberryPI rev2 - P5
    if ($RPIrevision == 2) {
    echo "<font face='Arial' size='3' color=FF0000><b>GPIO pin Status - P5</b></font>\n";
    echo "<table class='GPIOpinTable' border=1 cellpadding=3 cellspacing=0 bordercolorlight>\n";
    echo "<tr> <th>description</th> <th>value</th> <th>pin#</th> <th>".$S."</th> <th>".$S."</th> <th>pin#</th> <th>value</th> <th>description</th> </tr>\n";
    echo "<tr>\n";
    echo "<td>3.3V</td> <td>".$S."</td> <td class='lpin'>".$S."2</td> <td>".$threeVolt."</td>\n";
    echo "<td>".$fiveVolt."</td> <td class='rpin'>".$S."1</td> <td>".$S."</td> <td>5V</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 29 (I2C0_SCL)</td> <td class='value'><b>".GetGPIOpinValue(28)."</b></td> <td class='lpin'>".$S."4</td> <td>".$blue."</td>\n";
    echo "<td>".$blue."</td> <td class='rpin'>".$S."3</td> <td class='value'><b>".GetGPIOpinValue(29)."</b></td> <td>GPIO 28 (I2C0_SDA)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GPIO 31 (UART_RTS)</td> <td class='value'><b>".GetGPIOpinValue(30)."</b></td> <td class='lpin'>".$S."6</td> <td>".$yellowpin."</td>\n";
    echo "<td>".$yellowpin."</td> <td class='rpin'>".$S."5</td> <td class='value'><b>".GetGPIOpinValue(31)."</b></td> <td>GPIO 30 (UART_CTS)</td>\n";
    echo "</tr>\n";
    echo "<tr>\n";
    echo "<td>GND</td> <td>".$S."</td> <td class='lpin'>".$S."8</td> <td>".$GND."</td>\n";
    echo "<td>".$GND."</td> <td class='rpin'>".$S."7</td> <td>".$S."</td> <td>GND</td>\n";
    echo "</tr>\n";
    echo "</table>\n";
    }
    echo "</center>\n";


    ##--- functions

    function GetGPIOpinDirection($PIN) {
    $Direction='';
    if (file_exists("/sys/class/gpio/gpio".$PIN."")) {
    $Direction = trim(file_get_contents("/sys/class/gpio/gpio".$PIN."/direction"));
    }
    return $Direction;
    }
    function GetGPIOpinValue($PIN) {
    $Value='';
    if (file_exists("/sys/class/gpio/gpio".$PIN."")) {
    $Value = trim(file_get_contents("/sys/class/gpio/gpio".$PIN."/value"));
    }
    return $Value;
    }

    function GetRPIrev() {
    global $RPIrevision,$RPIrevinfo,$overvolted;
    $CPUrevision["Beta"] = "1";
    $REVinfos["Beta"] = "Released: Q1 2012, MODEL: B, MEM: 256";
    $CPUrevision["0002"] = "1";
    $REVinfos["0002"] = "Released: Q1 2012, MODEL: B, MEM: 256";
    $CPUrevision["0003"] = "1";
    $REVinfos["0003"] = "Released: Q3 2012, MODEL: B, MEM: 256";
    $CPUrevision["0004"] = "2";
    $REVinfos["0004"] = "Released: Q3 2012, MODEL: B, MEM: 256";
    $CPUrevision["0005"] = "2";
    $REVinfos["0005"] = "Released: Q4 2012, MODEL: B, MEM: 256";
    $CPUrevision["0006"] = "2";
    $REVinfos["0006"] = "Released: Q4 2012, MODEL: B, MEM: 256";
    $CPUrevision["0007"] = "2";
    $REVinfos["0007"] = "Released: Q1 2013, MODEL: A, MEM: 256";
    $CPUrevision["0008"] = "2";
    $REVinfos["0008"] = "Released: Q1 2013, MODEL: A, MEM: 256";
    $CPUrevision["0009"] = "2";
    $REVinfos["0009"] = "Released: Q1 2013, MODEL: A, MEM: 256";
    $CPUrevision["000d"] = "2";
    $REVinfos["000d"] = "Released: Q4 2012, MODEL: B, MEM: 512";
    $CPUrevision["000e"] = "2";
    $REVinfos["000e"] = "Released: Q4 2012, MODEL: B, MEM: 512";
    $CPUrevision["000f"] = "2";
    $REVinfos["000f"] = "Released: Q4 2012, MODEL: B, MEM: 512";
    $cpuinfolines = file("/proc/cpuinfo");
    $FOUND="";
    foreach($cpuinfolines AS $line) {
    if (preg_match("/Revision.*:(.*)/", $line, $find)) {
    foreach($CPUrevision AS $rev => $revision) {
    if (preg_match("/$rev/", $find[1])) {
    $FOUND = $rev;
    if (strlen($find[1]) != 4) { $overvolted = "This Pi has/is overvolted!"; }
    }
    }
    }
    }
    if (!empty($FOUND)) {
    $RPIrevision = $CPUrevision[$FOUND];
    $RPIrevinfo = $REVinfos[$FOUND];
    }
    }

    function WriteRPIrev($RPIrev) {
    if ($fh = fopen("/tmp/.rpi_rev", "w")) {
    fwrite($fh, "$RPIrev");
    fclose($fh);
    }
    }
    ?>

    [/php]

Jetzt mitmachen!

Du hast noch kein Benutzerkonto auf unserer Seite? Registriere dich kostenlos und nimm an unserer Community teil!