Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iot:labs:06 [2015/07/21 11:02]
ioana_maria.culic [What you need]
iot:labs:06 [2017/09/11 09:39] (current)
alexandru.radovici created
Line 1: Line 1:
-===== Lab 06.Connect and use an LCD =====+====== Lab 6: Connect and use an LCD ======
  
 In this project you are going to connect an LCD to your board and write a short message on it. In this project you are going to connect an LCD to your board and write a short message on it.
-==== What you need ====+===== What you need =====
  
-  *  One Edison ​connected to Wyliodrin;+  *  One Raspberry Pi connected to Wyliodrin ​STUDIO;
   *  One 16x2 LCD;   *  One 16x2 LCD;
   *  One breadboard;   *  One breadboard;
-  *  ​Sixteen male-male jumper ​wires; +  * Jumper ​wires;
-  *  One potentiometer.+
  
-==== The Setup ==== +===== The Setup ===== 
-The LCD has parallel interfacemeaning that the board has to manage several interface ​pins at once to control ​the display+{{ :​iot:​labs:​lcd-expander.jpg?​500 |}} 
 +The LCD in the kit is connected to port expander (MCP23008). This allows the LCD to be controlled via the I2C protocolthus reducing ​the number of pins you need to connect the LCD to. In this case, you just need to connect the expander to GND, 5V, SCL and SDA pins, according ​to the indicators on the expander. You can find the appropriate pins in the **Pin Layout** tab. You just need to connect the SDA port on the port expander with the SDA pin on the board and so on. 
 +===== The Code ===== 
 +{{ :​iot:​labs:​lcd-simple-example.png?​600 |}} 
 +You go to the Wyliodrin Applications page and create a new application. You name it and select Streams as programming language. Once created, you click on the new application'​s name to open it.
  
-The first pin is the //​RS//​(Register Select) that controls where exactly in the LCD's memory ​you are writing data to. +First of all, you need to initialise ​the LCD. For this, you drag the **run** node and select **Fire once at start** so you make sure that once you run the application ​first message is sentThis is only required ​to trigger ​the **init ​LCD** nodeso you can assure ​there is no other message being sent againFor this, drag the **trigger** node and double ​click on it.
- +
-There is an //Enable// pin that enables writing ​to the registers. +
- +
-The third one is the //​R/​W//​(Read/​Write) pin that selects from reading or writing mode.  +
- +
-The LCD also has //8 data// pins (D0 -D7)The states of these pins (high or low) are the bits that you're reading to a register when you reador the values ​you are writing when you write. +
- +
-There are also power supply pins (5V and GND) for powering ​the LCD, LED Backlight (Bklt- ​and Bklt+) pins that you can use to turn off and on the LED backlight and display contrast pin (Vo) to control the display contrast. +
- +
-What does 16x2 LCD mean? It means that the LCD has 16 columns and 2 rows. You place the LCD on the breadboard and connect it to the board as follows. +
- +
-The first two pins on the right are used to power up the LCD. The next four pinsthe ones with green cables, are the data pins. They allow the LCD to communicate with the board. The next two pins connected by yellow cables are the control pins. There are also three pins used for contrast. Two of them are used to power on the backlight and there is one more pin directly connected to the potentiometerThis way you can control ​the contrast just by rotating it. +
-{{ :​iot:​labs:​lcdstreams_bb.png?​500 |}} +
- +
-==== The Code ==== +
-You go to the Wyliodrin Applications page and create a new application. You name it and select Streams as programming language. Once created, you click on the new application'​s name to open it+
-{{ :​iot:​labs:​lcdtemp.png?​300 |}} +
-Start as usual with the //run// node. +
-To read the value from the temperature sensor through the analog pin. Next, you need the conversion from 0-1024 values to degrees. It is the same function from the project where you first used the temperature sensor+
  
-Now you have the temperature,​ what do you do with it? Let's write it on the LCD. +{{ :​iot:​labs:​trigger-block.png?400 |}}
-HowUse the simple way of Visual Programming Blocks. ​+
  
-Add a visual ​node and inside ​it do as follows.+You need to set this node to **wait until reset**. This will make the node to send the first message ​and then wait until it receives a message containing the property **reset**, which will never happen.  
 +Next, the **init LCD** node initializes the LCD.
  
-First of all, you need to initialise ​the LCD. For this you select ​the //​Peripherals/​LCD/​Init LCD// block.+First of all, you need to require the **wyliodrin** module, which exposes some simple functions in order to control ​the LCD. Otherwise ​you would need to implement ​the protocol in order to control it
  
 +Once you have the **wyliodrin** variable, call the **LiquidCrystal** constructor in order to obtain a **LiquidCrystal** object. The constructer receives 0 as parameter.
  
-To write something, you will use the //​Perpherals/​LCD/​Print on LCD []// block. you place it below the //Init// block and write the message received ​from the conversion function ​in it.+Why is the value 0 the parameter of the contructor? This type of LCD communicates with the Raspberry Pi board via that I2C protocolTaking into account how the I2C protocol behaves, ​you would need to mention ​the bus specific to the LCD, that usually is 32. However, in order to be able to connect multiple LCDs at once, they have three jumpers which can be connected in order to represent values ​from 0 to 7, thus being able to identify eight different LCDs. This is the value you need to pass to the constructor, ​in this case, no jumper is connected so we passed the value 0.
  
-Once the project runs, you should see the temperature from your room on the LCD, however, the contrast might be high and the text can be difficult to read. In order to modify the contrast, you just turn the rotary angle.+{{ :​iot:​labs:​init-lcd.png?400 |}}
  
-You run the project+What is new at the code presented above is the **context.global.lcd** structure. ​You need to use this because you want the **lcd** variable to be available from other nodes also (Display on LCD node) and **context.global** is a variable accessible to all the nodes, so you just set the lcd property and you will be able to use it from any other node.
  
-{{ :iot:labs:lcdd.png?300 |}}+{{ :iot:labs:display-lcd-simple.png?400 |}}
  
 +The **display LCD** node is another function node which first clears the LCD, then prints a string on it. Notice that the global **lcd** variable is used.
  
 ===== Exercises===== ===== Exercises=====
-  - Connect ​distance ​sensor and show the values ​on an LCD.\\ {{ :​iot:​labs:​parkingscheme.png?​500 |}} The distance sensor in the picture is connected to an Intel Gaileo Gen2 board. The wiring is the same for the Intel Edison. +  - Use temperature ​sensor and display ​the temperature ​on the LCD.
-  - Connect a gas sensor to an analog pin of the board and show the values on an LCD when they go over a set value (use a slider to set it). If the values stay under this value, show a message on the LCD, // There is no gas danger// . +
-  - Add a 7 segment to the  setup. On this display you can choose to display one digit of the value received from a sensor.\\ {{ :​iot:​labs:​7seg.png?​500 |}} \\ ** Hint ** In the example you can see a common anode 7 segment, which means that there is one common VCC for all of the 7 LEDs the display consists of. The segments will be alight when the value on the corresponding pins is 0, as this way the circuit is closed. If it has a common cathode, it will be connected to the ground, and the value which turns on the segments is 1.  +
-  -  Connect 4 LEDs using a 74HC595 shift register and make them blink one by one, in order.\\{{ :​iot:​labs:​595.png?​500 |}} \\ ** Hint ** In the example, there is a 595 shift register used with 8 LEDs. You need only 4, so, when you search for the piece'​s datasheet, look which are the first 4 GPIO pins and use only these, starting with 0. +
-  - Make a setup which works by this rules. You connect a distance sensor, a button, use a ruler and a sheet of paper.\\ At one end of the ruler you put the sensor and, at a certain distance, place the paper. When you press the button, your board should receive the value from the sensor with the distance where it detects the obstacle. Send these values to a chart in the dashboard via a signal. \\When you add the chart, go in its settings and uncheck the //time stamp// field. After doing this, you can master not only the Y axes, but the X as well. In streams you will be able to set each one with the //change// node. On X you put the value of the distance on the ruler. On Y, the values sent by the sensor+
iot/labs/06.1437465723.txt.gz · Last modified: 2015/07/21 11:02 by ioana_maria.culic
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0