Skip to content

Instantly share code, notes, and snippets.

@t413
Last active October 25, 2017 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save t413/0f7fb0e96d288cc0aa54ef5b29a3e6c2 to your computer and use it in GitHub Desktop.
Save t413/0f7fb0e96d288cc0aa54ef5b29a3e6c2 to your computer and use it in GitHub Desktop.
ESP8266 LIPO OLED development board Example Sketch
//compile with SparkFun Thing Dev, upload works great at 921600 Baud!
// backup demo flash first with `esptool.py read_flash 0x00000 0x400000 factory-0-0x400000.bin`
// restore with `esptool.py --baud 921600 write_flash 0x0000 factory-0-0x400000.bin`
// get esptool.py with `pip install esptool`
#include <ESP8266WiFi.h>
#include <U8g2lib.h>
#include <FastLED.h>
// the OLED used
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 5, /* data=*/ 4, /* reset=*/ 16);
#define NUM_LEDS 6
#define LED_PIN 2 //pin 2 == pin labled 'SDA' on the board
CRGB leds[NUM_LEDS];
ADC_MODE(ADC_VCC);
void setup() {
Serial.begin(115200);
Serial.println("Setup hardware");
FastLED.addLeds<NEOPIXEL,LED_PIN>(leds, NUM_LEDS);
LEDS.setBrightness(84);
leds[0] = CRGB::Red;
FastLED.show();
// Set WiFi to station mode and disconnect from an AP if it was previously connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
u8g2.begin();
u8g2.setFont(u8g2_font_profont10_tr);
u8g2.enableUTF8Print();
u8g2.print("ey!");
u8g2.sendBuffer();
Serial.println("Setup done");
}
uint32_t last_scan = millis() + 8000;
int8_t nets_found = 0;
void loop() {
uint32_t current = millis();
uint8_t clk = (current >> 5);
uint8_t clkfast = (current >> 3);
for (uint8_t i=0; i<NUM_LEDS; i++)
leds[i] = CHSV(cubicwave8(clk + i * 4), 255, 255);
FastLED.show();
u8g2.clearBuffer();
const uint8_t wdth = u8g2.getDisplayWidth(), ht = u8g2.getDisplayHeight(), halfh = ht/2;
for (uint8_t c=0; c < wdth; c++) {
int16_t hpos = halfh + ((int16_t)cubicwave8(clkfast - c*8) * ht / 256 - halfh) * cubicwave8(c*2) / 256;
u8g2.drawPixel(c, hpos);
}
u8g2.setCursor(0, 0);
u8g2.setFontPosTop();
u8g2.setFont(u8g2_font_pxplusibmvga9_t_all); //BIG font
u8g2.print(nets_found);
u8g2.setFont(u8g2_font_4x6_mr); //small font
u8g2.print(" networks");
u8g2.setCursor(0, ht);
u8g2.setFontPosBottom();
u8g2.print(ESP.getVcc() / 1024.00f);
u8g2.print("VCC");
u8g2.setFont(u8g2_font_u8glib_4_tr); //4x3 font
u8g2.setFontPosTop();
char buff[32];
for (int i = 0; i < nets_found; ++i) {
if (i * u8g2.getFontAscent() > ht) break;
WiFi.SSID(i).toCharArray(buff,32);
uint8_t w = u8g2.getStrWidth(buff);
u8g2.setCursor(wdth - w, i * u8g2.getFontAscent());
u8g2.print(WiFi.SSID(i));
//u8g2.print((WiFi.encryptionType(i) == ENC_TYPE_NONE)?"☼,":"☂,");
}
// for (int i = 0; i < n; ++i) {
// Serial.print(WiFi.SSID(i));
// Serial.print(WiFi.RSSI(i));
// Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
// }
if (last_scan > 0 && (current - last_scan) > 8000) { //start a scan!
Serial.println("scan async start");
WiFi.scanNetworks(true, false);
last_scan = 0; //scanning happening!
}
if (last_scan == 0 && WiFi.scanComplete() >= 0) { //scan done!
last_scan = current;
nets_found = WiFi.scanComplete();
Serial.println("scan done");
if (nets_found == 0) { Serial.println("no networks found");
} else {
Serial.print(nets_found);
Serial.println(" networks found");
for (int i = 0; i < nets_found; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
}
}
Serial.println("");
}
u8g2.sendBuffer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment