|
| 1 | +# **Lab 14 ADC with LCD** |
| 2 | + |
| 3 | +## **Objective:** |
| 4 | +* The objective of this lab is to utilize the `ADC peripheral` alongside the `LCD driver` to create a `digital multimeter (DMM)`. The LCD driver was provided by the main author of this documentation, [`Jesus Minjares`](https://github.com/jminjares4), the driver can be found here: [`LCD Driver`](https://github.com/jminjares4/ESP32-LCD-1602-Driver). |
| 5 | +## **Bonus** |
| 6 | +- ***Undergrad Bonus:*** |
| 7 | + * Use the `digital multimeter` to read a simple voltage-divider circuit. |
| 8 | +- ***Grad Bonus:*** |
| 9 | + * Using the ADC readings control the `sweeper function` from previous labs. Use up to 6 LEDs to demonstrate it. When the ADC reads the lowest value the one LED must be on and when the ADC reads the highest value the all LEDs must turn on. |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## **ESP32 Pinout** |
| 14 | +~~~ |
| 15 | + +-----------------------+ |
| 16 | + | O | USB | O | |
| 17 | + | ------- | |
| 18 | + 3V3 | [ ] [ ] | VIN |
| 19 | + GND | [ ] [ ] | GND |
| 20 | + Touch3 / HSPI_CS0 / ADC2_3 / GPIO15 | [ ] [ ] | GPIO13 / ADC2_4 / HSPI_ID / Touch4 |
| 21 | + CS / Touch2 / HSPI_WP / ADC2_2 / GPIO2 | [ ] [ ] | GPIO12 / ADC2_5 / HSPI_Q / Touch5 |
| 22 | + Touch0 / HSPI_HD / ADC2_0 / GPIO4 | [ ] [ ] | GPIO14 / ADC2_6 / HSPI_CLK / Touch6 |
| 23 | + U2_RXD / GPIO16 | [ ] [ ] | GPIO27 / ADC2_7 / Touch7 |
| 24 | + U2_TXD / GPIO17 | [ ] [ ] | GPIO26 / ADC2_9 / DAC2 |
| 25 | + V_SPI_CS0 / GPIO5 | [ ] ___________ [ ] | GPIO25 / ADC2_8 / DAC1 |
| 26 | + SCK / V_SPI_CLK / GPIO18 | [ ] | | [ ] | GPIO33 / ADC1_5 / Touch8 / XTAL32 |
| 27 | + U0_CTS / MSIO / V_SPI_Q / GPIO19 | [ ] | | [ ] | GPIO32 / ADC1_4 / Touch9 / XTAL32 |
| 28 | + SDA / V_SPI_HD / GPIO21 | [ ] | | [ ] | GPIO35 / ADC1_7 |
| 29 | + CLK2 / U0_RXD / GPIO3 | [ ] | | [ ] | GPIO34 / ADC1_6 |
| 30 | + CLK3 / U0_TXD / GPIO1 | [ ] | | [ ] | GPIO39 / ADC1_3 / SensVN |
| 31 | + SCL / U0_RTS / V_SPI_WP / GPIO22 | [ ] | | [ ] | GPIO36 / ADC1_0 / SensVP |
| 32 | + MOSI / V_SPI_WP / GPIO23 | [ ] |___________| [ ] | EN |
| 33 | + | | |
| 34 | + | | | ____ ____ | | |
| 35 | + | | | | | | | | | |
| 36 | + | |__|__| |__| |__| | |
| 37 | + | O O | |
| 38 | + +-----------------------+ |
| 39 | +~~~ |
| 40 | + |
| 41 | +## **LCD Example Code** |
| 42 | +This is an example code that demostrates how to utilize the LCD driver. |
| 43 | +~~~c |
| 44 | +#include <stdio.h> |
| 45 | +#include "freertos/FreeRTOS.h" |
| 46 | +#include "freertos/task.h" |
| 47 | +#include "driver/esp_lcd.h" |
| 48 | +/* LCD task */ |
| 49 | +void lcd_task(void *pvParameters){ |
| 50 | + /* Create LCD object */ |
| 51 | + lcd_t lcd; |
| 52 | + /* Set LCD to default pins */ |
| 53 | + lcdDefault(&lcd); |
| 54 | + /* Initialize LCD object */ |
| 55 | + lcdInit(&lcd); |
| 56 | + /* Clear previous data on LCD */ |
| 57 | + lcdClear(&lcd); |
| 58 | + |
| 59 | + while(1){ |
| 60 | + /* Display Text */ |
| 61 | + lcdSetText(&lcd, "Hello World!", 0, 0); |
| 62 | + /* 1 second delay */ |
| 63 | + vTaskDelay(1000 / portTICK_PERIOD_MS); |
| 64 | + } |
| 65 | +} |
| 66 | +void app_main(void){ |
| 67 | + /* Create LCD Task */ |
| 68 | + xTaskCreate(lcd_task, "LCD Task", 2048, NULL, 4, NULL); |
| 69 | +} |
| 70 | + |
| 71 | +~~~ |
| 72 | +
|
| 73 | +# **Lab Template** |
| 74 | +~~~c |
| 75 | +#include <stdio.h> |
| 76 | +#include "freertos/FreeRTOS.h" |
| 77 | +#include "freertos/task.h" |
| 78 | +#include "driver/esp_lcd.h" |
| 79 | +/* Create Function to covert ADC Value to Voltage */ |
| 80 | +
|
| 81 | +/* Create Function for ADC initialization */ |
| 82 | +void ADC_setup(void){ |
| 83 | +
|
| 84 | +} |
| 85 | +/* Function for sweeper */ |
| 86 | +void sweeper_function(uint32_t val){ |
| 87 | +
|
| 88 | +} |
| 89 | +/* LCD task */ |
| 90 | +void lcd_task(void *pvParameters){ |
| 91 | + /* Setup LCD */ |
| 92 | + |
| 93 | + while(1){ |
| 94 | + /* Get ADC Raw Readings */ |
| 95 | +
|
| 96 | + /* Get Conversion */ |
| 97 | +
|
| 98 | + /* Display Voltage onto LCD */ |
| 99 | +
|
| 100 | + /* Change PWM output to match ADC readings */ |
| 101 | +
|
| 102 | + } |
| 103 | +} |
| 104 | +void app_main(void){ |
| 105 | + /* Create LCD Task */ |
| 106 | + |
| 107 | +} |
| 108 | +
|
| 109 | +~~~ |
| 110 | + |
| 111 | +## **Warning** |
| 112 | +Before anything you must add the library for the LCD driver onto the `CMakeLists.txt` which is found in the lab's main folder. |
| 113 | +This would be how to add it: |
| 114 | +~~~c |
| 115 | +idf_component_register(SRCS "main.c" |
| 116 | + "driver/esp_lcd.c" |
| 117 | + INCLUDE_DIRS ".") |
| 118 | +~~~ |
| 119 | +
|
| 120 | +## **Author:** |
| 121 | +* [**Jorge Minjares** :zap:](https://github.com/JorgeMinjares)<br> |
| 122 | + * Bachelor of Science in Electrical Engineering<br> |
| 123 | +[](mailto:jminjares5@miners.utep.edu) |
| 124 | +[](https://www.linkedin.com/in/jorge-minjares/) [](https://github.com/JorgeMinjares) |
0 commit comments