Differences

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

Link to this comparison view

iot:courses:04 [2015/07/24 19:12]
alexandru.radovici
iot:courses:04 [2019/09/16 07:47] (current)
alexandru.radovici
Line 1: Line 1:
-====== ​Course ​4Sensors and peripherals ​======+====== ​Lecture ​Sensors and Peripherals ​======
  
 <​html>​ <​html>​
-<​center>​ +  ​<​center>​ 
-<iframe width="​640" height="​360" src="​https://​www.youtube-nocookie.com/​embed/​7UZdECEYnBs"​ frameborder="​0"​ allowfullscreen></​iframe>​ +    <iframe width="​560" height="​315" src="​https://​www.youtube.com/​embed/​7UZdECEYnBs"​ frameborder="​0" allow="​accelerometer;​ autoplay; encrypted-media;​ gyroscope; picture-in-picture" allowfullscreen></​iframe>​ 
-</​center>​+  </​center>​
 </​html>​ </​html>​
-Slides are available from the [[link]] 
- 
 <​html>​ <​html>​
-<iframe src="//​www.slideshare.net/​slideshow/​embed_code/​key/​6OQHm40yB7ljLw" width="​425" height="​355" frameborder="​0"​ marginwidth="​0"​ marginheight="​0"​ scrolling="​no"​ style="​border:​1px solid #CCC; border-width:​1px;​ margin-bottom:​5px;​ max-width: 100%;" allowfullscreen>​ </​iframe>​ <div style="​margin-bottom:​5px">​ <​strong>​ <a href="//​www.slideshare.net/​alexandruradovici/​iot-4-49837669" title="​Sensors and Peripherals"​ target="​_blank">​Sensors and Peripherals</​a>​ </​strong>​ from <​strong><​a href="//​www.slideshare.net/​alexandruradovici"​ target="​_blank">​Alexandru Radovici</​a></​strong>​ </​div>​+<iframe src="//​www.slideshare.net/​slideshow/​embed_code/​key/​zWZZTiorwoJoT5" width="​595" height="​485" frameborder="​0"​ marginwidth="​0"​ marginheight="​0"​ scrolling="​no"​ style="​border:​1px solid #CCC; border-width:​1px;​ margin-bottom:​5px;​ max-width: 100%;" allowfullscreen>​ </​iframe>​ <div style="​margin-bottom:​5px">​ <​strong>​ <a href="//​www.slideshare.net/​alexandruradovici/​lecture-4-sensors-and-peripherals" title="​Lecture 4 - Sensors and Peripherals"​ target="​_blank">​Lecture 4 - Sensors and Peripherals</​a>​ </​strong>​ from <​strong><​a href="https://​www.slideshare.net/​alexandruradovici"​ target="​_blank">​Alexandru Radovici</​a></​strong>​ </​div>​
 </​html>​ </​html>​
- 
- 
-This course will go through both analog and digital sensors, describing how they function and different ways of comnnecting and using them. More than this, it will present some other important peripherals,​ from the basic ones: LEDs to more complicated- shift registers or significant ones- LCDs.  
-===== Sensors ===== 
- 
-Sensors are devices that scan the environment and get data from it. Some examples of sensors are : thermistors , buttons (because they send a value, sensing the environment),​ photo resistors, infra-red sensors, distance sensors. 
- 
-Types of sensors: 
-  * Analog Sensors - send an analog value that **needs to be processed by the ADC** 
-  * Digital Sensors - send a digital value 
- 
- 
-//​Basically,​ all the sensing parts are analog.// 
- 
-For the analog sensor the sensing part is directly connected to a micro controller. They are easy to interface, you only need an ADC to do some computing to find the real value. 
- 
-Digital sensors are more complicated ​ because the micro controller that processes the data is already in the box of the sensor and it sends the data out on a communication channel ​ that  implements some type of  protocol. In order to get the data, the device needs to communicate with the sensor via the protocol. 
- 
-For the analog sensors there are two types: with two or three pins. 
- 
-An analog sensors will most probably be connected as a //voltage divider//. Such a sensor has a variable resistance, according to a specific environment element. Take a //light sensor// as an example: the more light there is, the lower the resistance. For the //​temperature sensor//, the higher the temperature,​ the lower the resistance. You practically measure the voltage drop in the circuit. ​ 
-The 2 leg and 3 leg analog sensors are mentioned above. ​ 
-The sensors that have 3 pins usually have the voltage divider already integrated: one pin goes to VCC, one to the Ground and the third pin goes to the analog input. ​ 
-For the sensors withe 2 legs, you have to build the voltage devider yourself by adding a resistance to the circuit 
- 
-<​note>​ If you switch VCC with ground, some sensors will burn. </​note>​ 
- ​Another particuparity of the sensors is that they will introduce some errors in the measurements,​ depending on the quality of the sensor. These parts usually increase in accuracy if they have the voltage devider inside as they bring some corrections. More to this, the sensors are not linear. 
- 
-One simple way to connect errors in reading or the ones that occurred due to the fact that the circuit is not perfect is to average them (usually using 1000 samples). This works on micro controllers,​ but on computer boards, it might result in reading the same value over and over. 
- 
-==== Button ==== 
- 
-It is one of the simplest sensors that you can connect. It is in fact an analog sensor, but it can only report 2 values : either 1 or 0. If the button is released, the resistance is infinite, if it is pressed, the resistance becomes 0  and  the input will be directly connected to the ground. 
- 
-{{ :​iot:​courses:​pull-up_resistor.png?​300 |}} 
- 
-The button becomes a pull-up resistor because when the button is not pressed it pulls up the voltage up to 5V. You need a really small resistor so that when the button is in the air the voltage drop will be insignificantly low, so that you can still read 5 volts. The problem comes up when you press the button for a longer period of time. In conclusion, you need a resistor sufficiently high that you won't drain the source too fast, but sufficiently low to be able to read the value 1. 
- 
-If R1 is replaced by S1 it will be called a pull-down resistor: it will pull down the voltage from that point to the ground the moment the button is not pressed. When the button is pressed it will stop the current from flowing too fast and having a short circuit. The input will be connected to VCC. 
- 
-=== Button Debounce === 
- 
-This problem is really visible on micro controllers because they sample fast. Buttons are imperfect, so from the moment you start pressing the button, there is a short time when the button'​s connectors start approaching and the distance is really small resulting in an electric discharge. The resistance will be neither 0, nor infinite, so for a short period of time the resistance will vary.  
- 
-{{ :​iot:​courses:​button_debounce.png?​300 |}} 
- 
-With the microelectronics,​ you will see many values of 1 and 0 continuously changing. 
-One way to debounce is to //average the values// and if the result is different from 0 or 1, then to discard the measurement because the button bounced. Another way is to //use a trigger// which, for an amount of time won't read any other value thus not detecting the edges. 
-Expensive microcontrollers have debouncing circuits. 
- 
-==== Potentiometer ==== 
- 
-A potentiometer is a variable resistance, with 3 pins. Usually it is a full resistor and the pin is connected in the middle (it can float around the full resistor and split it into two resistors so it works as a voltage divider). 
-You can connect it in two ways: either by //making a voltage divider//, choose R1 and connect two of the pins in the voltage divider (the middle one and one of the extremities),​ or by //​connecting one pin to VCC, one the Ground and the middle one to the input//. 
-To have a linear function as input from the sensor some computing is requested. 
-==== Thermistor ==== 
-Let's see an example of how an analog sensor can be connected to a board and how an application looks in Visual Programming for the thermistor, for instance. ​ 
-This sensor is still a variable resistor that changes its value with the temperature. You can compute the actual temperature using that value and a formula that takes into account the thermistor`s parameters, among which the resistance at 25 degrees. This kind of sensor has a low accuracy and is used to get a rough idea about the temperature.\\ 
-{{ :​iot:​courses:​termistor.png?​400 |}} 
-{{ :​iot:​courses:​thermistorcode.png?​400 |}} 
-==== Temperature sensor ==== 
- Note that there is a difference between the two sensors, consisting of the fact that the temperature sensor has a linear resistance-temperature characteristic,​ while the thermistor usually has the output voltage as a logarithmic or exponential function. Also the formulas to find the temperature in Celsius degrees are different. ​ 
- 
- 
-==== Light Sensor ==== 
- 
-This is also a resistance that changes its value due to the amount of photons it receives. Measuring the voltage drop on the resistance, you can get an idea about the light intensity. How does it actually work? If there is much light, there will be many photons in the photocell, thus less electrons to stop the electric current, which means the resistance of the sensor is lower. ​ 
- 
-{{ :​iot:​courses:​sezor_lumin.png?​400 |}} 
-{{ :​iot:​courses:​lightvisual.png?​400 |}} 
- 
-==== Gas Sensor ==== 
- 
-This sensor detects CO2. Pay attention that in order to detect gas it uses an exothermic chemical reaction therefore it heats up so don`t touch it while it is connected to the board.\\ 
-More importantly **pay attention that this sensor IS NOT for safety-important applications**. 
- 
- 
-==== Distance Sensor ==== 
-This sensor works like a sonar. It has 4 pins. Two of them are the power pins: GND and VCC, and the other two are the trigger and the echo pins. The trigger ​ will send out an ultrasonic signal and wait for the response. The moment the signal is sent out, the echo pin is 1, when the response comes, this pin turns to 0.  
-The distance is measured by multiplying the time needed for the response to come with the speed of sound. ​ 
- 
-Another type of sensor is an infrared one. It has an ADC inside so computing the distance is after a simple formula. ​ 
- 
-===== Digital sensors ===== 
-Digital sensors work with either of the two protocols: SPI or I2C. 
-===SPI=== 
- This protocol involves several slaves and a master. The communication is always initiated by the master. The pins for such a sensor are SS(slave select}, MISO, MOSI, Clock, each with their role. \\  MOSI stands for master out, slave in, which means that a line is created to send data from the master to the slave. MOSI is the line that facilitates the communication in the opposite direction: the slave writes on the line and the master samples.\\ The master is the one who generated the clock. SS pin will be 0 when the slave is active and conversely 1 when the slave is inactive. In the first case, the slave waits for the clock to transfer data. One master has pins for each slave, but it can't work with more than one slave at a time, since the MISO and MOSI lines would get impossible to use. \\ Communication in this protocol is always an exchange. 
-{{ :​iot:​courses:​spi.png?​400 |}} 
-===I2C===  ​ 
- This protocol works with one master and several slaves as well. This time there is no slave selection, but each slave has a fixed address. \\ It only uses two lines: SDA and SCL: serial data and serial clock line. This protocol is called a half duplex as it only uses one line for communication. The transfer of data goes as follows. The master sends the address. The slave identifies itself, sends out and acknowledgement message, then the master writes or reads the data, all this on the same line. 
-{{ :​iot:​courses:​i2c.png?​500 |}} 
-In general microcontrollers can be masters or slaves, but the computers can only be masters. ​ 
-==== Accelerometer and Gyroscope ==== 
- 
-See below an example of wiring and programming for a digital sensor. ​ 
- 
-Using this sensor you can determine acceleration on all three axis and also the rotation angle. An important note is that it also measures gravitational acceleration so don`t be surprised to get values different from 0 when the sensor is not moving. 
- 
-{{ :​iot:​labs:​accel.png?​500 |}} 
-{{ :​iot:​labs:​acceloblocks.png?​500 |}} 
- 
- 
- 
-===== Peripherals ===== 
-==== LED ==== 
- 
-An LED is a light emitting diode. A diode allows the current to pass only in one direction. Also, it has no resistance, which means it will be in a short circuit once it is wired to a circuit with no resistor. You will see when you look at the LED that it has two legs. One is longer, that one is usually the anode. This one has to be connected to the GPIO pin of the Edison. The shorter leg should to be connected to the resistor and then to the ground pin of the board. ​ 
- 
-Although the position of the resistor is not fixed, it can can either connect the ground to the cathode or the anode to the GPIO pin, the cathode should be connected to the ground to obtain the usually desired behavior. That means that we want the LED to light when the GPIO is set to HIGH and not to light when the GPIO is set to LOW. If you put the legs the other way around, the effect will be the opposite. ​ 
-==== 7 segment display ==== 
-It is an electronic component consisting of 7 LEDs. These have either a common cathode or common anode. In the first case, the LEDs need the value 1 on the pins to be alight, but in the second case, the VCC will be common. The latter situation means that the LEDs are alight when the value on the pins is 0.  
- 
-How do you connect it?  
-{{ :​iot:​courses:​7segsch.png?​400 |}} 
- 
-In visual programming,​ there are special blocks for the piece. All you have to do is to look up your model'​s datasheet AND insert the number of the pins for each segment. ​ 
-{{ :​iot:​courses:​7visual.png?​300 |}} 
-==== Shift register ==== 
-It is a serial to parallel register. Being a register, it is actually a memory. The data stored inside goes from QA to QH. These are the GPIO pins. OE stands for output enable, it is used to disconnect the pins all at once. SER is the serioal input pin, RCLK latch clock, SCLK is the serial clock, SRCLR is the clear pin.  
-The data is easy to read, paralleled, but written by shifting it inside. ​ 
-When the serial clock switches from 0 to 1 the register reads the value in the SER, puts the value from QH into QH, QG into QH and so on until it's QAs turn to go into QB and SER is now stored into QA. You would need 8 cycles to change all the values from a register. The bits can be read all at a time, but not written this way. \\ 
-Two shift registers can be connected together. \\ 
-A shift register offers 8 outputs using only 2 lines: the clock and the SER.  
-When SRCLR is 1, everything is cleared out. 
-The shift register changes the values in the output as others come in, so this can be visible. To avoid this problem, good quality shift registers have a parallel to parallel register. This means that only when a cycle is complete the RCLK will switch and the values are given as output. This is why the latch clock is needed. ​ 
-{{ :​iot:​labs:​595.png?​400 |}}  
-{{ :​iot:​courses:​595int.png?​500 |}} 
-==== LCD ==== 
-An LCD with 16 colons and 2 rows needs 16 pins to be controlled. It can use either a 4 pin protocol or an 8 pin protocol. The former will need 12 pins and the last, all the 16 pins. There are 4 power pins, meaning two groups of GND and VCC, one group being used by the backlights. ​ 
-Any LCD uses a potentiometer to set the contrast. The enable pin of an LCD can be connected to the ground or to a microcontroller. ​ 
-There are also I2C LCDs that work with only 4 pins, have an integrated potentiometer and can be connected in the same circuit only if they have different addresses. \\ 
-{{ :​iot:​labs:​lcdstreams_bb.png?​300|}} 
-{{:​iot:​courses:​lcdvisual.png?​300 |}} 
iot/courses/04.1437754340.txt.gz · Last modified: 2015/07/24 19:12 by alexandru.radovici
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