Skip to content

Instantly share code, notes, and snippets.

@tthtlc
Created January 19, 2020 06:18
Show Gist options
  • Select an option

  • Save tthtlc/b412ce5d2875f04510a3e7d350877519 to your computer and use it in GitHub Desktop.

Select an option

Save tthtlc/b412ce5d2875f04510a3e7d350877519 to your computer and use it in GitHub Desktop.
How to write to the OLED in WiFi Lora V2 kit from Heltec
#include <WiFi.h>
#include <U8x8lib.h>
// #include <LoRa.h>
// the OLED used
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);
int linecounter = 0;
void myu8x8_print(const char *line) {
char myline[30];
sprintf(myline, "%s ", line);
u8x8.drawString(0, linecounter, myline);
linecounter+=1;
if (linecounter>7)
linecounter=0;
}
void setup()
{
Serial.begin(115200);
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
Serial.println("Setup done");
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
myu8x8_print("WiFiScan from Peter Teoh");
}
void loop()
{
Serial.println("scan start");
myu8x8_print("Start");
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
myu8x8_print("Scan done");
if (n == 0) {
Serial.println("no networks found");
myu8x8_print("No network");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
myu8x8_print(WiFi.SSID(i).c_str());
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
delay(10);
}
}
Serial.println("");
// Wait a bit before scanning again
delay(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment