No ACL setup yet! Denying access to everyone.
en:edu:zmitac:macro:embedeed:lab:esp-on-site
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:macro:embedeed:lab:esp-on-site [2021/11/02 22:22] – pczekalski | en:edu:zmitac:macro:embedeed:lab:esp-on-site [2023/04/05 12:23] (current) – [Task 1] pczekalski | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| While ESP 8266 (Espressiff) is, in general, a network processor with broad applications in IoT, here we focus on using it as an embedded-class microcontroller.\\ | While ESP 8266 (Espressiff) is, in general, a network processor with broad applications in IoT, here we focus on using it as an embedded-class microcontroller.\\ | ||
| - | ===== Laboratory hardware in details | + | ===== Laboratory hardware in detail |
| Each team is given the following configuration with a pre-built hardware stack. | Each team is given the following configuration with a pre-built hardware stack. | ||
| Line 11: | Line 11: | ||
| < | < | ||
| </ | </ | ||
| - | Note, this microcontroller even if its board reminds Arduino Uno has different logic voltage (here 0..3.3V while Arduino Uno uses classical 0..5V logic) and has different pinout numbering. Detail on the following figure: | + | Note, this microcontroller, even if its board reminds Arduino Uno has a different logic voltage (here 0..3.3V while Arduino Uno uses classical 0..5V logic) and has different pinout numbering. Detail on the following figure: |
| <figure wemosd1r2pinout> | <figure wemosd1r2pinout> | ||
| {{: | {{: | ||
| Line 25: | Line 25: | ||
| </ | </ | ||
| - | <note warning> | + | <note warning> |
| ==== 2x16 LCD display shield ==== | ==== 2x16 LCD display shield ==== | ||
| [[https:// | [[https:// | ||
| Line 34: | Line 34: | ||
| ===== Software ===== | ===== Software ===== | ||
| - | You will be using Visual Studio Code with PlatformIO plugin to author software for the ESP8266. | + | You will be using Visual Studio Code with the PlatformIO plugin to author software for the ESP8266. |
| - | The framework (software stack) is Arduino compatible with the popular source code model: | + | The framework (software stack) is Arduino-compatible with the popular source code model: |
| <code c> | <code c> | ||
| #include < | #include < | ||
| void setup() { | void setup() { | ||
| - | // put your setup code here, to run once: | + | // put your setup code here to run once: |
| } | } | ||
| void loop() { | void loop() { | ||
| - | // put your main code here, to run repeatedly: | + | // put your main code here to run repeatedly: |
| } | } | ||
| </ | </ | ||
| - | Firmware uploading is done via USB cable providing a COM (serial) port to the PC computer, you're developing software on. You can also use the same port to trace (send communicates) from your code to the console. | + | Firmware uploading is done via a USB cable providing a COM (serial) port to the PC computer you're developing software on. You can also use the same port to trace (send communications) from your code to the console |
| - | <note important> | + | <note important> |
| ==== VSCode, PlatformIO and project configuration ==== | ==== VSCode, PlatformIO and project configuration ==== | ||
| - | In any case, creating a new project under PlatformIO should follow | + | In any case, creating a new project under PlatformIO should follow |
| <figure platformionewproject> | <figure platformionewproject> | ||
| {{: | {{: | ||
| Line 66: | Line 66: | ||
| framework = arduino | framework = arduino | ||
| </ | </ | ||
| + | |||
| + | It is also necessary to configure the serial port name that is used for uploading your firmware and monitoring. In the case of this microcontroller, | ||
| + | < | ||
| + | ... | ||
| + | upload_port = COM3 | ||
| + | monitor_port = COM3 | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | <note tip> | ||
| + | |||
| + | === Running your code === | ||
| + | To execute your code you need to compile it and upload it to the microcontroller.\\ | ||
| + | The easiest way to interact with PlatformIO is to use its blue ribbon bar, located at the bottom of the VSCode (image {{ref> | ||
| + | <figure pioribbon> | ||
| + | {{: | ||
| + | < | ||
| + | </ | ||
| + | |||
| === Libraries === | === Libraries === | ||
| Line 88: | Line 107: | ||
| === Hardware-software components and libraries === | === Hardware-software components and libraries === | ||
| Interfacing hardware requires the use of particular GPIOs. Laboratory nodes and hardware used needs specific configuration. Following chunks of code will help to set up proper hardware-software configuration. | Interfacing hardware requires the use of particular GPIOs. Laboratory nodes and hardware used needs specific configuration. Following chunks of code will help to set up proper hardware-software configuration. | ||
| + | |||
| == LCD display == | == LCD display == | ||
| Built-in LED on the microcontroller development board can help to manage simple tracing of the code execution: | Built-in LED on the microcontroller development board can help to manage simple tracing of the code execution: | ||
| Line 109: | Line 129: | ||
| </ | </ | ||
| - | == LCD keypad == | + | It is also necessary |
| - | The LCD shield has 6 buttons. One of them is hard-wired | + | <code c> |
| + | ... | ||
| + | lcd.begin(16,2); | ||
| + | ... | ||
| + | </ | ||
| - | <figure LCD1602buttons> | + | Some useful methods of the '' |
| + | <code c> | ||
| + | ... | ||
| + | lcd.setCursor(x, | ||
| + | ... | ||
| + | lcd.print(...); | ||
| + | ... | ||
| + | </code> | ||
| - | < | + | <note tip>LCD module has a standard ASCII (US) set of characters embedded. It is possible to re-program it, i.e. for Polish-specific letters like ąęółśćżź and virtually any other symbol. If you do not re-program it, pleas use English alphabet only for messaging.</ |
| + | |||
| + | == Keypad == | ||
| + | The LCD shield has six buttons. One of them is hard-wired to the reset function, but other buttons (marked SELECT, UP, DOWN, RIGHT, LEFT) can be read through voltage analysis delivered into the AD0 (Analogue to Digital Converter, Channel 0) existing in the ESP8266 chip. Buttons are connected the way that they short the connection, and every button creates a separate voltage divider between pull-up and respectable resistance, different for each button (see figure {{ref> | ||
| + | |||
| + | <figure LCD1602buttons> | ||
| + | {{: | ||
| + | < | ||
| </ | </ | ||
| - | Note, there is an assumption that you press only one button at a time. If no button is pressed, Vcc goes to the AD0 and you get maximum reading (see note below). | + | Note there is an assumption that you press only one button at a time. If no button is pressed, Vcc goes to the AD0, and you get maximum reading (see schematics on figure {{ref> |
| - | <note warning> | + | <note warning> |
| Reading an AD0 is as simple as: | Reading an AD0 is as simple as: | ||
| Line 128: | Line 166: | ||
| int nAdcReading = 0; | int nAdcReading = 0; | ||
| ... | ... | ||
| - | | + | |
| ... | ... | ||
| </ | </ | ||
| Line 135: | Line 173: | ||
| == Temperature and humidity sensor == | == Temperature and humidity sensor == | ||
| There is a DHT11 (blue) sensor connected to the __GPIO 5__.\\ | There is a DHT11 (blue) sensor connected to the __GPIO 5__.\\ | ||
| - | There are two libraries needed to handle reading from the sensor: a common sensor communication library and a specific for DHT sensors, both by Adafruit, so two more entries are needed in the // | + | There are two libraries needed to handle reading from the sensor: a common sensor communication library and a specific for DHT sensors, both by Adafruit, so two more entries are needed in the // |
| < | < | ||
| lib_deps = | lib_deps = | ||
| + | ... | ||
| adafruit/ | adafruit/ | ||
| adafruit/ | adafruit/ | ||
| Line 146: | Line 185: | ||
| </ | </ | ||
| - | To access sensor readings it is necessary to instantiate a communication class that binds the hardware to the code: | + | To access sensor readings, it is necessary to instantiate a communication class that binds the hardware to the code: |
| <code c> | <code c> | ||
| #define DHTTYPE DHT11 // DHT 11 | #define DHTTYPE DHT11 // DHT 11 | ||
| Line 175: | Line 214: | ||
| </ | </ | ||
| - | To convert float into the string with formatting use '' | + | To convert float into the string with formatting, use '' |
| <code c> | <code c> | ||
| ... | ... | ||
| Line 183: | Line 222: | ||
| ... | ... | ||
| </ | </ | ||
| - | <note tip>'' | + | <note tip>'' |
| <code c> | <code c> | ||
| delay(time) | delay(time) | ||
| </ | </ | ||
| ==== Tracing ==== | ==== Tracing ==== | ||
| - | There is no direct debugging capability in this environment yet it is possible to send log/trace messages to the PC console over a serial (serial over USB) port, the same that is used for flashing. | + | There is no direct debugging capability in this environment, yet it is possible to send log/trace messages to the PC console over a serial (serial over USB) port, the same that is used for flashing. |
| - | To open serial communication, | + | To open serial communication, |
| <code c> | <code c> | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| </ | </ | ||
| - | 9600 is the default speed but you can change it in the // | + | 9600 is the default speed, but you can change it in the // |
| It is possible to send virtually any message to the console (keep in mind, you need explicitly open Serial | It is possible to send virtually any message to the console (keep in mind, you need explicitly open Serial | ||
| <code c> | <code c> | ||
| Line 201: | Line 240: | ||
| Serial.println(...); | Serial.println(...); | ||
| </ | </ | ||
| - | Both functions accept a wide range of argument types with no need to explicitly | + | Both functions accept a wide range of argument types with no need to convert to string |
| ===== Tasks to do during labs ===== | ===== Tasks to do during labs ===== | ||
| ==== Task 1 ==== | ==== Task 1 ==== | ||
| Write on the LCD screen your name (in the first line) and the city name you live in (in the second line). | Write on the LCD screen your name (in the first line) and the city name you live in (in the second line). | ||
| + | === Advanced === | ||
| + | Make it animated (each line) in the loop, towards the left or right. | ||
| + | |||
| ==== Task 2 ==== | ==== Task 2 ==== | ||
| - | Present on the LCD screen current environmental parameters: temperature and humidity, as read from the DHT sensor. In the first line, there should be headers stating: '' | + | Present on the LCD screen |
| Update information at most every 1s, but on the other hand, short enough to notify changes when keeping the sensor in your hand or blowing into it. 5s seems to be a reasonable delay between consecutive readings. | Update information at most every 1s, but on the other hand, short enough to notify changes when keeping the sensor in your hand or blowing into it. 5s seems to be a reasonable delay between consecutive readings. | ||
| ==== Task 3 ==== | ==== Task 3 ==== | ||
| - | Present on the LCD screen the absolute value of the ADC 0 (analogue to digital converter) value and button name that has been pressed. | + | Present on the LCD screen the absolute value of the ADC 0 (analogue to digital converter) value and the button name that has been pressed. |
| - | The Upper LCD screen line should present current AD0 readings and the lower should present decoded button name. Mind, every LCD shield is slightly different, so you may need to run an absolute AD0 value reader to grab values reported when particular buttons are pressed, then update your solution with a decoder function that will return the button name, as detected by the absolute AD0 readings. | + | The Upper LCD screen line should present current AD0 readings, and the lower should present decoded button name. Mind, every LCD shield is slightly different, so you may need to run an absolute AD0 value reader to grab values reported when particular buttons are pressed, then update your solution with a decoder function that will return the button name, as detected by the absolute AD0 readings. |
| - | Note, ESP8266 default AD0 resolution is 10 bits, so AD0 reading can range from 1 to 1024 (or 0 to 1023). | + | Note that ESP8266' |
| + | |||
| + | <note tip>One of the buttons won't work. It is natural to ask the supervisor for details if you're interested in why.</ | ||
| + | <note tip> | ||
en/edu/zmitac/macro/embedeed/lab/esp-on-site.1635888149.txt.gz · Last modified: by pczekalski
