Start Using the Heltec ESP32 OLED Wi-Fi Kit
This video shows how to start using the Heltec ESP32 WiFi OLED Bluetooth microcontroller board. The code below is the default factory demo code for the V2 or 2022 production version.
242-Start using Heltec ESP32 OLED Wi-Fi Kit
语言: C++
/*
Watch full video and demonstration of code https://youtu.be/dk-01OpKYuQ
* HelTec Automation(TM) WIFI_Kit_32 factory test code, which includes
* the following functions:
*
* - Basic OLED function test;
*
* - Basic serial port test (in baud rate 115200);
*
* - LED blink test;
*
* - WIFI join and scan test;
*
* - Timer test and some other Arduino basic functions.
*
* by Aaron.Lee from HelTec Automation, Chengdu, China
*
* www.heltec.cn
*
* This project is also released on GitHub:
* https://github.com/HelTecAutomation/Heltec_ESP32
*/
#include "heltec.h"
#include "WiFi.h"
#include "images.h"
void logo(){
Heltec.display -> clear();
Heltec.display -> drawXbm(0,5,logo_width,logo_height,(const unsigned char *)logo_bits);
Heltec.display -> display();
}
void WIFISetUp(void)
{
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.disconnect(true);
delay(1000);
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
WiFi.begin("Robojax","4YouTubeESP32-hGT5R");
delay(100);
byte count = 0;
while(WiFi.status() != WL_CONNECTED && count < 10)
{
count ++;
delay(500);
Heltec.display -> drawString(0, 0, "Connecting...");
Heltec.display -> display();
}
Heltec.display -> clear();
if(WiFi.status() == WL_CONNECTED)
{
Heltec.display -> drawString(0, 0, "Connecting...OK.");
Heltec.display -> display();
// delay(500);
}
else
{
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, "Connecting...Failed");
Heltec.display -> display();
while(1);
}
Heltec.display -> drawString(0, 10, "WIFI Setup done");
Heltec.display -> display();
delay(500);
}
void WIFIScan(void)
{
Heltec.display -> drawString(0, 20, "Scan start...");
Heltec.display -> display();
int n = WiFi.scanNetworks();
Heltec.display -> drawString(0, 30, "Scan done");
Heltec.display -> display();
delay(500);
Heltec.display -> clear();
if (n == 0)
{
Heltec.display -> clear();
Heltec.display -> drawString(0, 0, "no network found");
Heltec.display -> display();
while(1);
}
else
{
Heltec.display -> drawString(0, 0, (String)n);
Heltec.display -> drawString(14, 0, "networks found:");
Heltec.display -> display();
delay(500);
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Heltec.display -> drawString(0, (i+1)*9,(String)(i + 1));
Heltec.display -> drawString(6, (i+1)*9, ":");
Heltec.display -> drawString(12,(i+1)*9, (String)(WiFi.SSID(i)));
Heltec.display -> drawString(90,(i+1)*9, " (");
Heltec.display -> drawString(98,(i+1)*9, (String)(WiFi.RSSI(i)));
Heltec.display -> drawString(114,(i+1)*9, ")");
// display.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
delay(10);
}
}
Heltec.display -> display();
delay(800);
Heltec.display -> clear();
}
void setup()
{
pinMode(LED,OUTPUT);
digitalWrite(LED,HIGH);
Heltec.begin(true /*DisplayEnable Enable*/, false /*LoRa Enable*/, true /*Serial Enable*/);
logo();
delay(300);
Heltec.display->clear();
WIFISetUp();
}
void loop()
{
WIFIScan();
delay(2000);
}
资源与参考
-
外部Heltec WiFi Kit 32 网站链接heltec.org
-
外部下载 Heltec 板的代码示例github.com
文件📁
没有可用的文件。