latinet:unicaes:workshops:sensors-23
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
latinet:unicaes:workshops:sensors-23 [2023/08/30 00:01] – jan.sonntag | latinet:unicaes:workshops:sensors-23 [2024/09/13 21:57] (current) – harley.lara | ||
---|---|---|---|
Line 7: | Line 7: | ||
Now, we're stepping into the practical aspect of our workshop, focusing on Pulse Width Modulation (PWM) output with the ESP8266. PWM isn't just about adjusting the brightness of an LED; it's a versatile method of communication. Through this segment, you'll grasp how PWM operates as a form of control, allowing us to transmit information using varying pulse widths. This will come to life as we demonstrate PWM in action, using an attached LED as an illustrative example. | Now, we're stepping into the practical aspect of our workshop, focusing on Pulse Width Modulation (PWM) output with the ESP8266. PWM isn't just about adjusting the brightness of an LED; it's a versatile method of communication. Through this segment, you'll grasp how PWM operates as a form of control, allowing us to transmit information using varying pulse widths. This will come to life as we demonstrate PWM in action, using an attached LED as an illustrative example. | ||
- | < | + | < |
- | < | + | |
+ | \\ | ||
+ | |||
+ | < | ||
===== 2. Libraries ===== | ===== 2. Libraries ===== | ||
Line 16: | Line 19: | ||
Remember, in the Arduino world, libraries are your trusted companions, facilitating smooth communication and opening doors to limitless possibilities. | Remember, in the Arduino world, libraries are your trusted companions, facilitating smooth communication and opening doors to limitless possibilities. | ||
+ | |||
+ | Good-To-Know: | ||
===== 3. Inputs / Protocols ===== | ===== 3. Inputs / Protocols ===== | ||
Line 25: | Line 30: | ||
With these common sensors, we don´t need to reinvent the wheel. There are plenty of good tutorials out there on how to use this sensor. One we link here: [[https:// | With these common sensors, we don´t need to reinvent the wheel. There are plenty of good tutorials out there on how to use this sensor. One we link here: [[https:// | ||
- | < | + | |
- | < | + | < |
+ | < | ||
We also prepared a little sketch for you. Try to understand it. A good way to do so is to look up function documentation in the Arduino Documentation: | We also prepared a little sketch for you. Try to understand it. A good way to do so is to look up function documentation in the Arduino Documentation: | ||
- | <file ino read-analog.ino> | + | <WRAP center round info 40%> |
- | // the setup routine runs once when you press reset: | + | Demo code available in Github [[https://github.com/EOLab-HSRW/intro-to-iot/ |
- | void setup() { | + | </ |
- | | + | |
- | Serial.begin(115200); | + | |
- | } | + | |
- | // the loop routine runs over and over again forever: | ||
- | void loop() { | ||
- | // read the input on analog pin 0: | ||
- | int sensorValue = analogRead(A0); | ||
- | // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 3.2V): | ||
- | float voltage = sensorValue * (3.2 / 1023.0); | ||
- | // print out the value you read: | ||
- | Serial.println(" | ||
- | Serial.println(" | ||
- | | ||
- | delay(1500); | ||
- | } | ||
- | </ | ||
==== 3.2. 1-Wire (ex. temperature sensor) ==== | ==== 3.2. 1-Wire (ex. temperature sensor) ==== | ||
- | One-Wire is a protocol that is heavily used by the company Maxim Integrated. One of the most popular sensors using this protocol is the (deprecated) DS18B20. It is an easy-to-use temperature sensor, that is available in multiple different form factors. In this workshop we use two different variants: | + | One-Wire is a bus protocol that is heavily used by the company Maxim Integrated. One of the most popular sensors using this protocol is the (deprecated) DS18B20. It is an easy-to-use temperature sensor, that is available in multiple different form factors. In this workshop we use two different variants: |
- Water-Proof DS18B20 | - Water-Proof DS18B20 | ||
- DS18B20 on a PCB | - DS18B20 on a PCB | ||
Line 68: | Line 58: | ||
==== 3.3. I2C (ex. ToF sensor) ==== | ==== 3.3. I2C (ex. ToF sensor) ==== | ||
+ | I2C is one of the most common sensor bus interfaces used. It requires 2 cables for communication. One is called SCL and the other is SDA. I2C in general is a serial interface. SCL is the serial clock. This is needed to synchronize the communication between two components. SDA is the actual serial data line. Here is where all the magic is happening. On one I2C bus, 127 slave devices can be attached. Therefore I2C is a master-slave protocol. The master will instantiate communication by calling for a specific address followed by a register it wants to read or write to, followed by some additional data in case of writing to a device. The slave device will give a response depending on the function called. | ||
+ | |||
+ | The sensor used in the sensor is a ToF sensor called VL53L0X, which is able to measure distance pretty accurately. | ||
+ | |||
+ | Have a look at the datasheet and the library: | ||
* [[https:// | * [[https:// | ||
* Here you can find a library for the sensor: [[https:// | * Here you can find a library for the sensor: [[https:// | ||
- | {{ :latinet: | + | < |
+ | Task: Try to get the sensor to work with your microcontroller. | ||
+ | |||
+ | <WRAP center round info 40%> | ||
+ | Demo code available in Github [[https:// | ||
+ | </ | ||
- | ==== 3.3. UART ==== | + | ==== 3.3. Good to know ==== |
+ | Out there are more than just the protocols that we covered today. Here are some more that are worth researching if you are interested: | ||
+ | * SPI | ||
+ | * UART | ||
+ | * Digital Interrupts | ||
===== Recording ===== | ===== Recording ===== | ||
latinet/unicaes/workshops/sensors-23.1693346482.txt.gz · Last modified: 2023/08/30 00:01 by jan.sonntag