Différences entre versions de « Pi-WiringPi-Exemple-ShieldRGB »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 2 : Ligne 2 :
  
 
== Intro ==
 
== Intro ==
Le [http://mchobby.be/PrestaShop/product.php?id_product=253 Shield LCD RGB pour Pi d'Adafruit] (aussi appelé ''RGB LCD plate'' et [http://mchobby.be/PrestaShop/product.php?id_product=253 disponible chez MCHobby]) est ... is a nice little display which adds 5 push-buttons to the display board, and sits on-top of the Raspberry Pi. The RGB part refers to the backlight which, as you’ve guessed can be set to various colours by combining the red, green and blue backlights.
+
 
 +
{{bloc-etroit|text=Le [http://mchobby.be/PrestaShop/product.php?id_product=253 Shield LCD RGB pour Pi d'Adafruit] (aussi appelé ''RGB LCD plate'' et [http://mchobby.be/PrestaShop/product.php?id_product=253 disponible chez MCHobby]) est un chouette carte équipé d'un afficheur, de 5 boutons et s'installe sur le GPIO du Raspberry Pi. L'afficheur RGB dispose d'un rétro-éclairage RGB – qui, comme vous pouvez le deviner, permet de combiner plusieurs couleurs de base rouge, vert et bleu pour le rétro-éclairage. }}
  
 
{{ADFImage|RASP-LCD-RGB-Intro-02.jpg|480px}}
 
{{ADFImage|RASP-LCD-RGB-Intro-02.jpg|480px}}

Version du 29 septembre 2013 à 20:30


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Intro

Le Shield LCD RGB pour Pi d'Adafruit (aussi appelé RGB LCD plate et disponible chez MCHobby) est un chouette carte équipé d'un afficheur, de 5 boutons et s'installe sur le GPIO du Raspberry Pi. L'afficheur RGB dispose d'un rétro-éclairage RGB – qui, comme vous pouvez le deviner, permet de combiner plusieurs couleurs de base rouge, vert et bleu pour le rétro-éclairage.

RASP-LCD-RGB-Intro-02.jpg
Crédit: AdaFruit Industries www.adafruit.com

Gordon chose it to use as a bit of a test-bed to make sure that one of the existing devLibs – the LCD character driver should work not only with the Pi’s on-board GPIO, but through a GPIO expander chip – the Adafruit display uses the MCP23017 I2C GPIO expander chip.

Brancher & analyser

It comes as a kit to be soldered and there weren’t any real issues – although the one thing that I find annoying was that the holes in the PCB for the 3 resistors were slightly wider than the resistor with the legs bent close to it – necessitating some small adjustments! A minor niggle though.

So with that in-mind, a quick modification to my existing lcd.c test program and it was running almost immediately without any hitches.

Once I’d soldered it and checked to make sure no solder bridges, etc. I plugged it in and loaded up the I2C driver to see if I could see it:

To see the output of this, you would need to connect a single LED to the GPIO connector of the Raspberry Pi as follows:

gpio load i2c
gpio i2cd

and I saw the MCP23017 at its default address of 0×20. (There are solderable jumpers under the board to change this if required)

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

I consulted the schematic to work out the pin assignments on the device – the display is connected up on 4-bit mode and the display control signals, buttons, and the LED outputs taking up almost all the other 16 GPIO pins.

Some quick testing using the GPIO command to verify I’d interpreted it OK:

gpio -x mcp23017:100:0x20 mode 106 out
gpio -x mcp23017:100:0x20 write 106 0

and the Red backlight LED came on. (It seems the backlight uses negative logic) Similarly for the green and blue:

gpio -x mcp23017:100:0x20 mode 107 out # Green
gpio -x mcp23017:100:0x20 write 107 0
gpio -x mcp23017:100:0x20 mode 108 out # Blue
gpio -x mcp23017:100:0x20 write 108

Next, a quick modification to my existing lcd.c test program and it was running almost immediately without any hitches.

So to make it work with wiringPi v2, it’s just a matter of setting up the mcp23017 as an extension module, then using the new pins defined for the display itself:

// Defines for the Adafruit Pi LCD interface board

#define AF_BASE         100
#define AF_RED          (AF_BASE + 6)
#define AF_GREEN        (AF_BASE + 7)
#define AF_BLUE         (AF_BASE + 8)

#define AF_E            (AF_BASE + 13)
#define AF_RW           (AF_BASE + 14)
#define AF_RS           (AF_BASE + 15)

#define AF_DB4          (AF_BASE + 12)
#define AF_DB5          (AF_BASE + 11)
#define AF_DB6          (AF_BASE + 10)
#define AF_DB7          (AF_BASE +  9)

#define AF_SELECT       (AF_BASE +  0)
#define AF_RIGHT        (AF_BASE +  1)
#define AF_DOWN         (AF_BASE +  2)
#define AF_UP           (AF_BASE +  3)
#define AF_LEFT         (AF_BASE +  4)

Configurer

  mcp23017Setup (AF_BASE, 0x20) ;
  lcd = lcdInit (2, 16, 4, AF_RS, AF_E, AF_DB4,AF_DB5,AF_DB6,AF_DB7, 0,0,0,0) ;

That’s enough to get the display going, but we really need to turn the backlight on and put the button pins into input mode with the internal pull-ups enabled – the buttons short to 0v.

Please do see the program source to see how the backlight is setup and the buttons read, but there is nothing special to reading them – e.g. I modified the code that waits for the Enter key to be pressed in the original to wait for the “Select” button on the display:

static void waitForEnter (void)
{
  printf ("Press SELECT to continue: ") ; fflush (stdout) ;

  while (digitalRead (AF_SELECT) == HIGH)       // Wait for push
    delay (1) ;

  while (digitalRead (AF_SELECT) == LOW)        // Wait for release
    delay (1) ;

  printf ("OK\n") ;
}

(it could probably be done better and with some debouncing, but for this little demo, that’s more than sufficient – demonstrating that a simple digitalRead() function call is all you need to read the button via wiringPi which has the mcp23017 registered with it).

The demo program uses the up/down buttons to cycle through the LED colours – from Off to Red, Green, Yellow, Blue, Purple, Cyan and finally White.

Pi-WiringPi-Exemple-ShieldRgb-01.jpg
Source: wiringPi.com


Source: WiringPi.com. WiringPi est une libraire sous licence GPL écrite par Gordon Henderson. Crédit: wiringpi.com

Traduit de l'anglais par Meurisse D. pour MCHobby.be

Traduit avec l'accord de Gordon Henderson, créateur de wiringPi - Translated with authorization of Gordon Henderson, creator of wiringPi

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.