Differences

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

Link to this comparison view

Next revision
Previous revision
en:iot-open:practical:hardware:sut:esp32:iot_1 [2024/03/26 18:04] – created pczekalskien:iot-open:practical:hardware:sut:esp32:iot_1 [2024/03/26 18:21] (current) – [Result validation] pczekalski
Line 19: Line 19:
  
 ==== Task to be implemented ==== ==== Task to be implemented ====
-Draw "Hello World" in the upper line of the LCD and "Hello IoT" in the lower one.+Present a MAC address on the selected display. The steps below present only the reading part, not a display. Handling a display is presented in the EMBx scenarios, as listed above.
  
 ==== Start ==== ==== Start ====
Line 28: Line 28:
  
 === Step 1 === === Step 1 ===
-Include the library in your source code:+Include the WiFi management library in your source code:
 <code c> <code c>
-#include <Adafruit_LiquidCrystal.h>+#include <WiFi.h>
 </code> </code>
 +The WiFi library automatically initialises a singleton class ''WiFi'' that you can use to set up working mode, read MAC, and perform many other operations.
  
 === Step 2 === === Step 2 ===
-Declare GPIOs controlling the LCD, according to the hardware reference:+Reading the MAC as a ''String'' is as easy as simply calling:
 <code c> <code c>
-#define LCD_RS 2 +  WiFi.macAddress();
-#define LCD_ENABLE 1 +
-#define LCD_D4 39 +
-#define LCD_D5 40 +
-#define LCD_D6 41 +
-#define LCD_D7 42+
 </code> </code>
  
-=== Step 3 === +==== Result validation ==== 
-Declare a static instance of the LCD controller class and preconfigure it with appropriate control GPIOs:+Using another node should change the MAC read. Book another device and discover its MAC. 
 + 
 +===== FAQ ===== 
 +**Can I change MAC?**: Actually, yes, you can. It is not advised, however, because you may accidentally generate an overlapping address that will collide with another device in the same network. You must first explicitly configure the ESP32 chip to work as an AP (Access Point, Server) or STA (WiFi Client) to do it. Sample stub code (for STA) may look as follows:
 <code c> <code c>
-static Adafruit_LiquidCrystal lcd(LCD_RS, LCD_ENABLE, LCD_D4, LCD_D5, LCD_D6, LCD_D7); +#include <WiFi.h> 
-</code>+#include <esp_wifi.h>
  
-=== Step 4 === +uint8_t newMAC[] {0xDE0xAD0xBE, 0xEF, 0xCA, 0xFE}; //Array of bytes with new MAC 
-Initialise class with display area configuration (number of columnshere 16 and rowshere 2): +void setup(
-<code c> +{ 
-lcd.begin(16,2); +  WiFi.mode(WIFI_STA); 
 +  esp_wifi_set_mac(WIFI_IF_STA&newMAC[0]); 
 +}
 </code> </code>
- 
-=== Step 5 === 
-Implement your algorithm. The most common class methods that will help you are listed below: 
-  * ''.clear()'' - clears all content; 
-  * ''.setCursor(x,y)'' - set cursor, writing will start there; 
-  * ''.print(contents)'' - prints text in the cursor location; note there are many overloaded functions, accepting various arguments, including numerical. 
- 
-==== Result validation ==== 
-You should be able to see "Hello World" and "Hello IoT" on the LCD now. 
  
 <WRAP noprint> <WRAP noprint>
en/iot-open/practical/hardware/sut/esp32/iot_1.1711476245.txt.gz · Last modified: 2024/03/26 18:04 by pczekalski
CC Attribution-Share Alike 4.0 International
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