Outils pour utilisateurs

Outils du site


issue111:python

Ceci est une ancienne révision du document !


Last month, we worked with the DS18B20 Temperature Sensor. This month we will start to interface a 16×2 LCD display to show our temperatures. Don’t tear down your setup, but make sure you have enough room to mount the display on your breadboard. You’ll need about 32 pinholes for the length of the device and 16 for the pins to connect to. You will have only three pinholes left if you mount the display at the bottom of the vertical holes, so you will need to use some jumpers to connect the bottom verticals to the top verticals. Of course, the 16×2 display has 16 characters on two rows. The backlight comes in many colours. I chose a blue one. We can address each of the 32 character positions individually, or print pretty much like we do to the regular monitor. We will be making 8 connections to the RPi as well as the three that we used for the temperature sensor last month. You will need the following additional items for this month: • 10K Potentiometer • 16×2 LCD Display • Many breadboard jumpers, Male to Male and 8 Male to Female

Le mois dernier, nous avons travaillé avec le capteur de température DS18B20. Ce mois-ci, nous commencerons par interfacer un afficheur LCD 16×2 pour montrer nos températures. Ne défaites pas votre montage, mais assurez-vous que vous avez assez de place pour monter votre afficheur sur la plaque d'essai. Vous aurez besoin de 32 trous pour la longueur de la pièce et de 16 trous pour connecter les picots. Vous n'aurez que 3 trous de rab si vous montez l'afficheur en bas des trous verticaux ; aussi, vous aurez besoin de quelques cavaliers pour connecter lestrous verticaux du bas à ceux du haut.

By the time you are done, the wiring diagram (and the resulting board) will look like a bit of a rat’s nest, but go slowly – make sure you have the wiring correct. As you can see in the graphic above, it’s pretty crazy, so I’ll lay out all the wiring for you in text. First, you will need to put a jumper between the two horizontal busses on both the top and bottom. That way, you’ll have power and ground on both busses. I chose to do it on the left side, but you can put it anywhere that is convenient for you. The next thing to do is to wire in the potentiometer. One side (it doesn’t matter which) needs to go to ground and the other side to our 5 volt supply. The center contact (the wiper) will wire to pin 3 of the LCD display. This controls the contrast, so you can control how bright the characters appear. You should already have 5 volts to the board, as well as ground, from last month. On the display, connect pin 1 to ground and pin 2 to the +5 volt buss. That makes three connections out of the twelve we need. Pin 6 of the display goes to pin 22 of the RPi. This is the Enable pin. Pin 5 on the display goes to ground, and pin 4 to pin 27 on the RPi. We are up to 6 connections so far. That makes us halfway there. Because we have to use pin 4 for our sensor, we can’t control the backlight.

Now we will work backwards from pin 16. Pin 16 goes to ground, and pin 15 to +5v. Pin 15 is actually the backlight voltage on mine. If you find the display too bright, you could put the wiper of another potentiometer connected between +5v and ground and control the display backlight. Now for the data lines. There are actually 8 data lines, but thankfully, we will be using only 4. Pins 11 to 14 are D4, D5, D6 and D7 (counting from 0). Here is the connection list. Now everything is hooked up, so we will continue with some sample code to test the display. But we need to get the Adafruit python library for LCDs. In a terminal window, type the following… git clone https://github.com/adafruit/Adafruit_Python_CharLCD cd Adafruit_Python_CharLCD sudo python setup.py install cd examples

Now load char_lcd.py into your favorite editor. Or, you could type it in from the previous page. Ignore the backlight messages, but you should see… Hello World! Show Cursor_ Blink Cursor_ Scroll (right and left) Flash backlight in 5 seconds… Goodbye! If everything worked, we are ready to proceed. If not, go back and check your wiring. Here is the modified program from last month that includes snippets from this example (top right) from Adafruit. (New code is in bold.) That’s about it for this month. Next month we will look at changing out our regular 16×2 display for a 16×2 I2C display (which uses only 2 lines for data and all control, and 2 lines for power.) We will also discuss the different ways of using serial communication for interfacing displays and other devices. Until then, have fun!

issue111/python.1471677311.txt.gz · Dernière modification : 2016/08/20 09:15 de d52fr