User Tools

Site Tools


No ACL setup yet! Denying access to everyone.
en:edu:zmitac:macro:embedeed:lab:esp

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:edu:zmitac:macro:embedeed:lab:esp [2020/11/25 12:41] – [Scenario 1: Basic operations on the 4x20 LCD screen] pczekalskien:edu:zmitac:macro:embedeed:lab:esp [2021/12/21 14:33] (current) – [Connecting to the nodes] pczekalski
Line 10: Line 10:
 You can book for use nodes 1 through 4 and 8 through 11 at the moment. You can book for use nodes 1 through 4 and 8 through 11 at the moment.
  
-Every node contains sensors and actuators. Every node has 4x20 (4 lines, 20 characters) LCD display, you can observe via web camera, and also at least a DHT (temperature + humidity) sensor.+Every node contains sensors and actuators. Every node has a 4x20 (4 lines, 20 characters) LCD display, which you can observe via web camera, and also at least a DHT (temperature + humidity) sensor.
  
 <note important>The 4x20 LCD display is connected via I2C bus to the ESP microcontroller and its address varies, depending on the node, see the documentation below.</note>  <note important>The 4x20 LCD display is connected via I2C bus to the ESP microcontroller and its address varies, depending on the node, see the documentation below.</note> 
  
-<note important>The DHT sensor is connected to the ESP microcontroller using single GPIO and there are two types of them! Please see the documentation below.</note>+
  
 ==== Actuators ==== ==== Actuators ====
Line 25: Line 25:
   * Nodes 10 and 11 use 0x27;   * Nodes 10 and 11 use 0x27;
  
-You need to provide appropriate initialisation in the software library that controls LCD regarding the note you've booked.+You need to provide appropriate initialisation in the software library that controls the LCD regarding the note you've booked.
  
 ==== Sensors ==== ==== Sensors ====
 In the following scenarios, you will use a DHT, integrated temperature-humidity sensor. \\ In the following scenarios, you will use a DHT, integrated temperature-humidity sensor. \\
-Sensor types vary between nodes (Figure {{ref>dhtsensors}}): 
-  * Nodes 1 through 4 all use DHT 22 (white sensor);  
-  * Nodes 8 through 11 all use DHT 11 (a blue one); 
  
 <figure dhtsensors> <figure dhtsensors>
Line 38: Line 35:
 </figure> </figure>
  
-You need to initiate related software library with appropriate sensor type, depending on the laboratory node you use.\\ In general, those sensors differ with accuracy; thus for raw experimentation, it is meaningless, whichever node you book to use.+All of our laboratory nodes use DHT11 sensors(blue one on the Figure {{ref>dhtsensors}}). \\ In general, DHT11 and DHT22 sensors differ with accuracy.
  
 Regarding DHTs, all nodes share the same configuration on the connection level: your DHT is always connected to the D4/GPIO2 pin of the ESP microcontroller. Regarding DHTs, all nodes share the same configuration on the connection level: your DHT is always connected to the D4/GPIO2 pin of the ESP microcontroller.
  
-<note important>Warning: sending continuous requests, without a delay, to the DHT sensors is a really bad idea as you will frequently get NaN (not a number) results. Consider introducing some at least 200ms delay between consecutive reads.</note>+<note important>Warning: sending continuous requests, without a delay, to the DHT sensors is a really bad idea as you will frequently get NaN (not a number) results or zero values. Consider introducing some at least 5s delay between consecutive reads.</note>
  
 ===== Connecting to the nodes ===== ===== Connecting to the nodes =====
Line 49: Line 46:
 Please follow instructions and remember to fix your theme for Revolution! Your environment should look like in Figure {{ref>vrellab}}.\\ Please follow instructions and remember to fix your theme for Revolution! Your environment should look like in Figure {{ref>vrellab}}.\\
  
-__**Do not book a device for more than 30 minutes in a row (Figure {{ref>vrelbooking}}): respect other students!**__ You can continue working with devices out of regular working hours, see supervisor's guidance on lab availability.+__**Do not book a device for more than 30 minutes in a row (Figure {{ref>vrelbooking}}): respect other students!**__ \\ 
 +You can continue working with devices out of regular working hours, see the supervisor's guidance on lab availability.
  
-The URL for accessing VREL lab is: [[[[http://distance.roboticlab.eu]].+The URL for accessing the VREL lab is: [[http://distance.roboticlab.eu]].
  
 <figure registeraccount> <figure registeraccount>
Line 95: Line 93:
 board = d1_mini board = d1_mini
 framework = arduino framework = arduino
-lib_deps = Wire, 1574, PubSubClient, DHT sensor library@1.3.5, CoAP simple library, 31@1.0.3, 528@1.0.4, Adafruit Unified Sensor+lib_ldf_mode = deep+ 
 +lib_deps = Wire, 1574, PubSubClient, DHT sensor library@1.3.5, 31@1.0.3, 528@1.0.4, Adafruit Unified Sensor
 </code> </code>
 Obviously, this contains all hardware and software libraries, even more than is necessary to use in case of the following two scenarios, but you will have it ready for future experimentation. Obviously, this contains all hardware and software libraries, even more than is necessary to use in case of the following two scenarios, but you will have it ready for future experimentation.
 +
 +<note warning>Remember to remove other content than presented above. Wrong development environment configuration can cause the inability to compile and run your code!</note>
 +
 +<note important>Note, sometime when you copy-paste content from this PDF file, there may be some extra characters included (i.e. text formatting), that are not visible on the screen, but they do exist and they may cause errors during compilation. To avoid, use copying through a proxy, dummy text editor, i.e. Notepad or Notepad++. First copy from PDF to Notepad then from Notepad to the web browser. 
 +
 +**Remember to save the file!**</note>
 ==== Software libraries ==== ==== Software libraries ====
 In general, you need to use two software libraries: for DHT and LCD.\\ In general, you need to use two software libraries: for DHT and LCD.\\
 The LCD library is [[https://github.com/tonykambo/LiquidCrystal_I2C|LiquidCrystal_I2C]] one while using DHT requires two libraries from Adafruit: Adafruit_Sensor and DHT. The LCD library is [[https://github.com/tonykambo/LiquidCrystal_I2C|LiquidCrystal_I2C]] one while using DHT requires two libraries from Adafruit: Adafruit_Sensor and DHT.
  
-And obviously, if you use some preconfigured values (i.e. as when you refer to the D1 and D0 when initialising I2C communication library), you need to include the ''Arduino'' library that contains declarations of the constants and some useful functions, i.e. ''delay(xxx)''.+And obviously, if you use some preconfigured values (i.e. as when you refer to the D1 and D0 when initialising the I2C communication library), you need to include the ''Arduino'' library that contains declarations of the constants and some useful functions, i.e. ''delay(xxx)''.
  
 <code c> <code c>
Line 118: Line 123:
  
 ==== Scenario 1: Basic operations on the 4x20 LCD screen ==== ==== Scenario 1: Basic operations on the 4x20 LCD screen ====
-Whatever you do, you expect to have some output of the system. Sometimes there is a blinking LED, sometimes information about connected/disconnected network and some other time simply trace algorithm progress. In laboratories where you have physically connected MCU to your programming device (i.e. computer), you usually would choose ''Serial'' port to report about what is going on. However here all you have is access via the video stream. Perhaps those are reasons you will use this LCD display in your every lab work.+Whatever you do, you expect to have some output of the system. Sometimes there is a blinking LED, sometimes information about connected/disconnected network and some other time simply trace algorithm progress. In laboratories where you have physically connected MCU to your programming device (i.e. computer), you usually would choose the ''Serial'' port to report what is going on. However here all you have is access via the video stream. Perhaps those are reasons you will use this LCD display in your every lab work.
  
 <note important>Note, the video stream from the camera is limited in bandwidth and presents some 5-10fps maximum (usually around 1 fps) so you shouldn't change display content nor LED state faster than once every 2 seconds, to let you notice any change!</note> <note important>Note, the video stream from the camera is limited in bandwidth and presents some 5-10fps maximum (usually around 1 fps) so you shouldn't change display content nor LED state faster than once every 2 seconds, to let you notice any change!</note>
  
 === Prerequisites === === Prerequisites ===
-There are no other prerequisites than LCD I2C library. Mind, LCD is controlled via the I2C bus. LCD Display is 4×20 characters. LCD is controlled via I2C extender: +There are no other prerequisites than the LCD I2C library. Mind, LCD is controlled via the I2C bus. LCD Display is 4×20 characters. LCD is controlled via an I2C extender: 
 PCF8574.  PCF8574. 
  
Line 132: Line 137:
  
 === Scenario === === Scenario ===
-Initialize LCD screen, clear it then write some fancy text on it, i.e. "Hello IOT!" in the first line then your first name in the second line and the name of the city you're in, in the third. In the fourth line, print right-aligned number of ''loop'' iterations (delay it for 1 second between updates - to observe video stream lag and delays). Note, delays are provided in ms, not in s.+Initialize the LCD screen, clear it, then write some fancy text on it, i.e. "Hello SMIW!" in the first line. Then your first name in the second line and the name of the city you're in, in the third. Note, out of the box, the LCD screen does not contain polish special characters like //śćżółńź//, so do not include them unless you re-define character definitions (advanced). In the fourth line, print the right-aligned number of ''loop'' iterations (delay it for 1 second between updates - to observe video stream lag and delays). Note, delays are provided in ms, not in s.
  
 === Result === === Result ===
Line 149: Line 154:
 </code> </code>
 == Step 2 == == Step 2 ==
-Instantiate software controler component for the LCD display:+Instantiate software controller component for the LCD display:
 <code c> <code c>
 LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x3F for nodes 1 through 5, 8 and 9 LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x3F for nodes 1 through 5, 8 and 9
Line 177: Line 182:
   lcd.home();   lcd.home();
   lcd.print("Hello World!");   lcd.print("Hello World!");
-  lcd.setCursor(0, 1); 
-  lcd.print("James Bond here"); 
-  lcd.setCursor(0,2); 
-  lcd.print("London"); 
 ... ...
 </code> </code>
 +
 +The ''setCursor(x,y);'' function will help you to a position in the place you want the text to be rendered:
 +<code c>
 +...
 +    lcd.setCursor(0, 1);
 +...
 +</code>
 +
 +Indexing is zero-based and the upper left corner is (0,0).
 == Step 5 == == Step 5 ==
 Implement ''loop()'' to draw number of loop executions: Implement ''loop()'' to draw number of loop executions:
Line 197: Line 207:
  
 === Result validation === === Result validation ===
-Observe text, its position and counter ticking in lower, right corner.+Observe text, its position and counter ticking in the lower, right corner.
  
 ==== Scenario 2: Presenting temperature and humidity on the LCD ==== ==== Scenario 2: Presenting temperature and humidity on the LCD ====
-In this scenario, you will present temperature and humidity as read by the attached DHT22/DHT11 sensor, on the LCD screen.+In this scenario, you will present temperature and humidity as read by the attached DHT11 sensor, on the LCD screen.
  
 === Prerequisites === === Prerequisites ===
Line 209: Line 219:
 #include <LiquidCrystal_I2C.h> #include <LiquidCrystal_I2C.h>
 </code> </code>
-The temperature and humidity sensor is all-in-one, DHT22 sensor (white) or DHT11 (blue), connected to the pin D4. Observe your camera to check which sensor is equipped with your lab and consult node documentation.\\+The temperature and humidity sensor is all-in-one, DHT11 (blue), connected to the pin D4. Observe your camera to check which sensor is equipped with your lab and consult node documentation.\\
 To read data you may use a dedicated library (libraries): To read data you may use a dedicated library (libraries):
 <code c> <code c>
Line 242: Line 252:
  
 == Step 2 == == Step 2 ==
-Instantiate software controler components for the LCD display and DHT sensor:+Instantiate software controller components for the LCD display and DHT sensor:
 <code c> <code c>
 LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x3F for nodes 1 through 5, 8 and 9 LiquidCrystal_I2C lcd(0x3F,20,4);  // set the LCD address to 0x3F for nodes 1 through 5, 8 and 9
 //LiquidCrystal_I2C lcd(0x27,20,4); // for nodes 10 and 11 only! //LiquidCrystal_I2C lcd(0x27,20,4); // for nodes 10 and 11 only!
                                    // for a 20 chars and 4 line display                                    // for a 20 chars and 4 line display
-DHT dht(DHTpin,DHT22,50); //for nodes 1 through 4 +DHT dht(DHTpin,DHT11,50);
-//DHT dht(DHTpin,DHT11,50); //for nodes 8 through 11+
 </code> </code>
 == Step 3 == == Step 3 ==
Line 287: Line 296:
 ... ...
 </code> </code>
-<note tip>''sprintf'' uses number of wildcards that are rendered with data. Refer to the c/c++ documentation on ''sprintf''. Here <code c>%2.1f</code> means: having float number render it to string using two digits before decimal point and one after. Temperature in our lab is always above 10C. <code c>%%</code> is an escape character to print a <code c>%</code> (percent) symbol.\\''delay(time)'' is measured in milliseconds.</note>+<note tip>''sprintf'' uses number of wildcards that are rendered with data. Refer to the c/c++ documentation on ''sprintf''. Here <code c>%2.1f</code> means: having float number render it to string using two digits before decimal point and one after. Temperature in our lab is always above 10C. <code c>%%</code> is an escape character to print a <code c>%</code> (percent) symbol. ''delay(time)'' is measured in milliseconds.</note>
  
 === Result validation === === Result validation ===
 Observe temperature and humidity readings on the LCD. The temperature in our lab usually ranges between 20-30C (not, we observed over 30C during really hot summer!) while humidity is usually between 35-60%Rh. Observe temperature and humidity readings on the LCD. The temperature in our lab usually ranges between 20-30C (not, we observed over 30C during really hot summer!) while humidity is usually between 35-60%Rh.
  
 +===== FAQ =====
 +**Q: Help, my LCD seems to be frozen!**\\
  
 +A1: Check the I2C address is correct, regarding the laboratory node you're using. Consult details in the hardware section, as above.\\
  
 +A2: Still not working? And you're sure the I2C address is correct so ... It is rare, but may happen that the I2C bus becomes in an inconsistent state. In such case run the following program (in the separate source file, eventually merge with your code):
 +<code c>
 +#include <Arduino.h>
 +#include <LiquidCrystal_I2C.h>
  
 +LiquidCrystal_I2C lcd(0x3F,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
 +
 +void setup()
 +{
 +  pinMode(4,OUTPUT);
 +  pinMode(5, OUTPUT);
 +  digitalWrite(4,LOW);
 +  digitalWrite(5,LOW);
 +  delay(2000);
 +  pinMode(5, INPUT); // reset pin
 +  pinMode(4, INPUT);
 +  delay(50);
 +  delay(2000);
 +  lcd.init(D2,D1);
 +  lcd.backlight();
 +  lcd.home();
 +  lcd.print("Hello world...");
 +}
 +
 +void loop()
 +{
 +
 +} 
 +</code>
  
en/edu/zmitac/macro/embedeed/lab/esp.1606304478.txt.gz · Last modified: by pczekalski