Differences

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

Link to this comparison view

iot:labs:05 [2015/07/17 15:08]
madalina.tanea
iot:labs:05 [2017/09/11 09:35] (current)
alexandru.radovici created
Line 1: Line 1:
-===== Lab 05.Connect ​and use an LCD =====+====== Lab 5: Sensors ​and Dashboard====== 
 + 
 +For the following applications,​ you will read data coming from sensors, which means that you will also need to use the Arduino board. As the Raspberry Pi has no ADCs, you cannot read values coming from analog sensors.  
 +===== Arduino Setup =====
  
-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 board connected to Wyliodrin ​STUDIO
-  *  One 16x2 LCD+  * One Arduino board
-  *  One breadboard; +  * One USB cable. 
-  ​* ​ Sixteen male-male jumper wires; +==== The setup ==== 
-  *  One potentiometer.+As previously stated, the classical Arduino board is basically a micro-controller, which is capable of running one piece of software at once and that has little processing power and no network connectivity. So you will use the board to gather data from the environment and then pass it on to the Raspberry Pi.  
  
-==== The Setup ==== +The Raspberry Pi is computer that is capable of processing data and communicating with other smart devices. For instanceyou could visualise ​the temperature on your smart phone.
-The LCD has parallel interfacemeaning that the board has to manage several interface pins at once to control ​the display+
  
-The first pin is the //​RS//​(Register Select) that controls where exactly ​in the LCD's memory you are writing ​data to.+The two boards need to be connected ​in order to send data between them. You can connect them via the USB cable and a serial connection will be established between the two. Once this is done, they can exchange ​data and the Arduino board can be controlled via the Raspberry Pi. This is done by the **firmata** protocol. The protocol allows the Raspberry Pi to send the Arduino messages in which it requests for a certain action or information and the Arduino will respond accordingly.
  
-There is an //Enable// pin that enables writing ​to the registers.+In order to implement ​the protocol, you need to flash the Arduino with the **StandardFirmata** firmware.
  
-The third one is the //​R/​W//​(Read/​Write) pin that selects from reading or writing mode+In the Wyliodrin STUDIO interface you have two tabs referring to **SOFTWARE** and **FIRMWARE**. So far, you used only the **SOFTWARE** tab, as you wrote applications for the Raspberry Pi solely. Now, select the **FIRMARE** tab and there is where you can write code which will be run on the Arduino. In this case, you will import an existing project.
  
-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 read, or the values you are writing when you write.+{{ :​iot:​labs:​select-firmata.png?300 |}}
  
-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 a display contrast pin (Vo) to control ​the display contrast.+Hit the **Show examples** button ​and select **Arduino**. Then **use** the **Firmata/​StandardFirmata** example. Now that you have the software ​to run on the Arduino, once you hit the **run** button, you will be asked the tyype of the Arduino board and if you want to flash it or not. Select the board you are using and **RUN AND FLASH**. The **StandardFirmata** firmware will be deployed on the Arduino.
  
-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.+As you know, any micro-controller,​ including ​the Arduino, once flashed, runs the same firmware until another one is uploaded ​on the board. Thus, you don't have to flash the board each time you run a new Raspberry Pi applicationIf you are confident that the Arduino is running **StandardFirmata**,​ you can skip this step. 
 +{{ :​iot:​labs:​flash-arduino.png?​300 |}}
  
-The first two pins on the right are the used to power up the LCD. The next four pins, the 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 potentiometer. This way you can control the contrast just by rotating it. +===== Street Lightning =====
-{{ :​iot:​labs:​lcdgalileo1.png?​500 |}}+
  
 +In this application,​ you will build a system to monitor the light level and if there is the case, you will turn on the street lights brighter or dimmer, depending on the amount of light.
 +
 +==== What you need =====
 +  * One Raspberry Pi connect to \Wyliodrin;
 +  * One Arduino connected to the Raspberry Pi;
 +  * One photocell;
 +  * One LED;
 +  * One 220 $\Omega$ resistor;
 +  * One 10 k$\Omega$ resistor;
 +  * Jumper wires. ​
 +
 +==== The Setup ====
 +
 +{{ :​iot:​labs:​light_sensor_schematics.png?​600 |}}
 +
 +The photocell works just like resistor with a variable resistance. Depending on the amount of light it receives, its resistance gets higher or lower. As a result, you can connect it in a voltage divider, as well.
 +
 +The sensor is connected to the 5V via the 10 K Ohms resistor and to the GND pin on the other side. In order to read the sensor'​s value, the yellow jumper wire is connected to the A0 pin of the board. The A0-A5 pins can be used for reading digital values, in this case values ranging from 0 to 1024. 
 +
 +For the photocell, the resistance decreases proportionally with the amount of light, so for this schematics, the brighter the environment,​ the higher is the read value.
 +
 +In addition, the photocell has a resistance varying from hundred of ohms to mega ohms and in order for the voltage divider to work, you should use the sensor as a pull-down resistor, while the actual resistor needs to have a resistance comparable with the sensor'​s,​ otherwise its effect is not visible. This is why you need a 10 k Ohms resistor.
 +
 +The other part of the setup, the LED is connected similar to the previous schematics except that you can notice that its behaviour is controller by pin 3. That pin has a tilde next to it. That means that it is a PWM pin so you can control if the LED should light up brighter or dimmer. You can write values ranging from 0 to 255 on these pins, 0 being the equivalent of digital 0 and 255 the equivalent of digital 1. 
 ==== The Code ==== ==== 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:​street_lights_code.png?400 |}}
-HowUse the simple way of Visual Programming Blocks. ​+
  
-Add a visual ​node and inside ​it do as follows.+First of all, you need to use an **Arduino in** node in order to read the values from the sensor. This node gets triggered each time the value on the pin it reads from changes. To actually configure the node's behavior you need to set its properties
  
-First of all, you need to initialise the LCD. For this you select the //​Peripherals/​LCD/​Init LCD// block.+{{ :​iot:​labs:​arduino_in_properties.png?400 |}}
  
 +The first property allows you to set the Raspberry Pi connection to the Arduino board so the Raspberry Pi knows the port through which it should send the messages. Usually, the port is **/​dev/​ttyACM0**. However, in order to make sure, go to the **Shell** tab and type **dmesg**. There you should see messages stating that an FTDI cable has been connected to the board and the port it is connected to. Concatenate that value to **/dev/** and place the value as the first property of the node.
  
-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.+Further on, you need to specify which pin you want to read from. In this case, the pin is 0 and is an analog pin. Afterwards, you will use a **range** node in order to map the read values to values that should light up the LEDFor this, you need to adapt the system to your environment. Depending on the regular amount of light, usually you will read a value of around 400. So in this case, the range scales values going from 400 to 1024 to 0 to 255. However, if the regular value is different, you will need to scale a different range.
  
-Once the project runs, you should see the temperature from your room on the LCD, however, the contrast might be to high and the text can be difficult to read. In order to modify the contrast, you just roll the rotary angle.+{{ :​iot:​labs:​range-light.png?400 |}}
  
-You run the project+The last node to use is **Arduino out**. This node acts just like the **digital write** node used in the previous chapters. However, you still need to select the port for the Arduino board and you can choose from analog or digital write. As you want to make the LED light up brighter or dimmer, you will set the type to **analog** and the **pin** property has to be 3
  
-{{ :​iot:​labs:​lcdd.png?300 |}}+<​note>​ 
 +If you use more than one Arduino node in the application,​ add a new Raspberry Pi board only for one nodeFor the rest of the nodes, choose the previously added board from the drop-down. 
 +</​note>​
  
 +Now you can run the application and watch how the LED gets brighter as you cover up the sensor. ​
  
 ===== Exercises===== ===== Exercises=====
-  - Connect a distance ​sensor ​and show the values on an LCD.\\ {{ :​iot:​labs:​parkingscheme.png?500 |}}  +  - Display the values coming from the light sensor ​in the dashboard using the **gauge** graph
-  - 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// . +  - Connect ​all the sensors in the kit to the Arduino ​and display ​the values you read in the dashboard. **Note:** Do not connect ​the Hall sensor, which works in a different ​way. 
-  - 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.  +  - Search ​the temperature sensor's datasheet ​online (TMP36) ​and transform ​the read values to celsius degrees. 
-  -  ​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/05.1437134880.txt.gz · Last modified: 2015/07/17 15:08 by madalina.tanea
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