From Scribby Hamster, 1 Year ago, written in Plain Text.
Embed
  1. /*
  2. NodeMCU ESP8266 12x6 I2C display example
  3. Will scan for wifi networks and display them on a attached LCD
  4.  
  5. Connections:
  6. LCD           NodeMCU
  7. GND   <-->    G
  8. VCC   <-->    VV
  9. SDA   <-->    D2  
  10. SCL   <-->    D1
  11.  
  12. You must also install the LiquidCrystal_I2C library in your Arduino IDE:
  13. 1. Click on 'Sketch' > 'Include Library' > 'Manage Libraries'
  14. 2. Click the search bar and enter 'LiquidCrystal_I2C' do no install the one that starts with 'jm_'
  15. 3. Click 'Install' and select latest version
  16.  
  17. */
  18.  
  19. #include "ESP8266WiFi.h"
  20. #include <Wire.h>
  21. #include <LiquidCrystal_I2C.h>
  22.  
  23. LiquidCrystal_I2C lcd(0x27,16,2);  
  24.  
  25. void setup() {
  26.   Serial.begin(115200);
  27.   // Set WiFi to station mode and disconnect from an AP if it was previously connected
  28.   WiFi.mode(WIFI_STA);
  29.   WiFi.disconnect();
  30.   delay(2000);
  31.   Serial.println("Setup done");
  32.  
  33.   lcd.init();  // initialize the lcd
  34.   lcd.backlight(); // turn on backlight
  35. }
  36.  
  37. void loop() {
  38.   Serial.println("scan start");
  39.   lcd.clear();
  40.   lcd.setCursor(2,0); // (char 2, line 0)
  41.   lcd.print("Scanning...");
  42.  
  43.  
  44.   int n = WiFi.scanNetworks();// WiFi.scanNetworks will return the number of networks found
  45.   Serial.println("scan done");
  46.   if (n == 0){
  47.     Serial.println("no networks found");
  48.  
  49.     // print to LCD screen:
  50.     lcd.clear();
  51.     lcd.setCursor(2,0); // (char 2, line 0)
  52.     lcd.print("No networks");
  53.   }
  54.   else
  55.   {
  56.     Serial.print(n);
  57.     Serial.println(" Networks found");
  58.  
  59.     lcd.clear();
  60.     lcd.setCursor(0,0); // (char 0, line 0);
  61.     lcd.print(String(n) + " Networks found");
  62.     delay(1000);
  63.    
  64.     for (int i = 0; i < n; ++i)
  65.     {
  66.       // Print SSID and RSSI for each network found
  67.       Serial.print(i + 1);
  68.       Serial.print(": ");
  69.       Serial.print(WiFi.SSID(i));
  70.       Serial.print(" (");
  71.       Serial.print(WiFi.RSSI(i));
  72.       Serial.print(")");
  73.       Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
  74.  
  75.       lcd.clear();
  76.       lcd.setCursor(0,0);
  77.       lcd.print(WiFi.SSID(i));
  78.       lcd.setCursor(0,1);
  79.       lcd.print("RSSI: " + String(WiFi.RSSI(i)));
  80.       delay(1500);
  81.     }
  82.   }
  83.   Serial.println("");
  84.  
  85.   // Wait a bit before scanning again
  86.   delay(3000);
  87. }

Replies to Untitled rss

Title Name Language When
Re: Untitled Sweltering Parrot c 1 Year ago.