Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- This is an example for our Monochrome OLEDs based on SSD1306 drivers
- Pick one up today in the adafruit shop!
- ------> http://www.adafruit.com/category/63_98
- This example is for a 128x64 size display using SPI to communicate
- 4 or 5 pins are required to interface
- Adafruit invests time and resources providing this open source code,
- please support Adafruit and open-source hardware by purchasing
- products from Adafruit!
- Written by Limor Fried/Ladyada for Adafruit Industries.
- BSD license, check license.txt for more information
- All text above, and the splash screen must be included in any redistribution
- *********************************************************************/
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- //Adafruit Default If using software SPI (the default case):
- //#define OLED_MOSI 9
- //#define OLED_CLK 10
- //#define OLED_DC 11
- //#define OLED_CS 12
- //#define OLED_RESET 13
- //Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- //My Arduino Nano Test Board
- //#define OLED_DC 4
- //#define OLED_CS 5
- //#define OLED_CLK 2
- //#define OLED_MOSI 3
- //#define OLED_RESET 6
- //Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
- //* Uncomment this block to use hardware SPI
- #define OLED_DC 4
- #define OLED_CS 17 //NEW D17
- #define OLED_RESET 12
- Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
- //*/
- #define NUMFLAKES 10
- #define XPOS 0
- #define YPOS 1
- #define DELTAY 2
- #define LOGO16_GLCD_HEIGHT 16
- #define LOGO16_GLCD_WIDTH 16
- #if (SSD1306_LCDHEIGHT != 64)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- const int up_btn = 6;
- const int lt_btn = 8;
- const int dn_btn = 9;
- const int rt_btn = 5;
- const int ok_btn = 3;
- const int back_btn = 2;
- String inputString = ""; // a string to hold incoming data
- boolean stringComplete = false; // whether the string is complete
- String inputString2 = ""; // a string to hold incoming data
- boolean stringComplete2 = false; // whether the string is complete
- int rxlen = 0;
- boolean isDone = false;
- char menuSelection = 0;
- int lineCount = 0;
- void setup() {
- Serial.begin(9600);
- Serial1.begin(9600);
- pinMode(up_btn, INPUT);
- pinMode(dn_btn, INPUT);
- pinMode(lt_btn, INPUT);
- pinMode(rt_btn, INPUT);
- pinMode(back_btn, INPUT);
- // reserve 200 bytes for the inputString:
- inputString.reserve(400);
- inputString2.reserve(200);
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- display.begin(SSD1306_SWITCHCAPVCC);
- // init done
- // Clear the buffer.
- display.clearDisplay();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0,0);
- display.println("AtomSoftTech");
- display.setCursor(0,20);
- display.println("Mike Rankin");
- display.setCursor(0,50);
- display.println("EPS8266 Mini Terminal");
- display.display();
- delay(3000);
- display.clearDisplay();
- display.display();
- display.setCursor(0,0);
- }
- void MainMenu()
- {
- char menuItem = 0;
- boolean isenter = false;
- boolean isnew = false;
- while(isenter == false)
- {
- display.clearDisplay();
- display.setCursor(0,0);
- display.println("Select Function\n");
- isnew = false;
- if(menuItem == 0)
- {
- display.println(">UART Terminal");
- display.println(" ESP8266 Control");
- }
- else
- {
- display.println(" UART Terminal");
- display.println(">ESP8266 Control");
- }
- display.display();
- delay(200);
- while(isnew == false)
- {
- if(digitalRead(dn_btn) == HIGH)
- {
- if(menuItem<1)
- menuItem++;
- isnew = true;
- }
- if(digitalRead(up_btn) == HIGH)
- {
- if(menuItem>0)
- menuItem--;
- isnew = true;
- }
- if(digitalRead(ok_btn) == HIGH)
- {
- isnew = true;
- isenter = true;
- menuSelection = menuItem+1;
- delay(500);
- }
- }
- }
- }
- void loop() {
- MainMenu();
- switch(menuSelection)
- {
- case 1:
- UartTerminal();
- break;
- case 2:
- ESPTerminal();
- break;
- default:
- break;
- }
- }
- void ESPTerminal ()
- {
- char menuItem = 0;
- boolean isenter = false;
- boolean isnew = false;
- int x;
- char inChar;
- char rxc = 0;
- char myItems[4][25] = {
- " Connect WiFi\0",
- " Status \0",
- " Function 3\0",
- " Function 4\0"
- };
- while(1)
- {
- display.clearDisplay();
- display.setCursor(0,0);
- display.println("ESP8266 Commands\n");
- isnew = false;
- for(x=0;x<4;x++)
- {
- if(menuItem == x)
- myItems[x][0] = '>';
- else
- myItems[x][0] = ' ';
- display.println(myItems[x]);
- }
- display.display();
- delay(200);
- isnew = false;
- while(isnew == false)
- {
- if(digitalRead(dn_btn) == HIGH)
- {
- if(menuItem<3)
- menuItem++;
- isnew = true;
- }
- if(digitalRead(up_btn) == HIGH)
- {
- if(menuItem>0)
- menuItem--;
- isnew = true;
- }
- if(digitalRead(ok_btn) == HIGH)
- {
- isenter = true;
- switch(menuItem)
- {
- case 0:
- connectWiFi();
- break;
- case 1:
- Serial1.println("AT+CIPSTATUS");
- break;
- case 2:
- break;
- case 3:
- break;
- default:
- break;
- }
- delay(300);
- display.clearDisplay();
- display.setCursor(0,0);
- isDone = false;
- while(digitalRead(ok_btn) == LOW)
- {
- while(Serial1.available()==0)
- {
- if(digitalRead(ok_btn) == HIGH)
- {
- isDone = true;
- break;
- }
- }
- rxlen = Serial1.available();
- if(isDone == false)
- {
- inputString = "";
- while(rxlen--)
- {
- inChar = (char)Serial1.read();
- inputString+= inChar;
- rxc++;
- if ((inChar == '\n') || (rxc == 20)) {
- lineCount++;
- rxc = 0;
- if(lineCount ==9)
- {
- lineCount = 0;
- display.setCursor(0,0);
- display.clearDisplay();
- }
- }
- }
- Serial.print(inputString);
- display.print(inputString);
- display.display();
- }
- }
- isDone = false;
- isnew = true;
- }//END of OK
- if(digitalRead(lt_btn) == HIGH)
- {
- menuSelection = 0;
- return;
- }
- }
- }
- }
- void connectWiFi()
- {
- int x;
- Serial1.println("AT+RST"); //Reset wifi
- display.clearDisplay();
- display.setCursor(0,0);
- display.display();
- delay(1500); //1 sec is good
- if(Serial1.find("eady"))
- {
- Serial.println("Module Found!");
- display.println("Module Found!");
- display.display();
- Serial.println("Trying to Set up Wifi");
- display.println("Trying to connect");
- display.display();
- Serial1.println("AT+CWMODE=3"); //mode 1 gives error
- delay(2000);
- Serial.println("Trying to set Mode 3");
- display.println("Trying to set Mode 3");
- display.display();
- char cmd[40] = "AT+CWJAP=\"AtomSoft\",\"PASS\"\r\n\0";
- Serial.print(cmd);
- Serial1.print(cmd);
- for(x=1;x<16;x++)
- {
- delay(1000);
- if(Serial1.find("OK"))
- {
- Serial.println("Wifi Connected");
- display.println("Wifi Connected");
- x = 15;
- }else
- {
- Serial.print("Time: ");
- Serial.print(x);
- Serial.println(" sec(s)");
- if((x==6)||(x==14))
- {
- display.clearDisplay();
- display.setCursor(0,0);
- }
- display.print("Time: ");
- display.print(x);
- display.println(" sec(s)");
- if(x == 15)
- {
- Serial.println("Connect Failed!");
- display.println("Connect Failed!");
- }
- display.display();
- }
- }
- // String cmd = "AT+CWJAP=\"MANUALSSID\",\"MANUALPASS\"";
- }
- else
- {
- Serial.println("Module Not Found!");
- display.println("Module Not Found!");
- display.display();
- }
- }
- void UartTerminal()
- {
- display.clearDisplay();
- display.setCursor(0,0);
- display.println("UART Terminal");
- display.display();
- while(isDone == false)
- {
- if(digitalRead(lt_btn) == HIGH)
- {
- menuSelection = 0;
- isDone = true;
- }
- CheckSerial();
- if (stringComplete2) {
- Serial1.println(inputString2);
- inputString2 = "";
- stringComplete2 = false;
- }
- if (stringComplete) {
- Serial.println(inputString);
- display.println(inputString);
- display.display();
- // clear the string:
- inputString = "";
- stringComplete = false;
- }
- }
- }
- void CheckSerial() {
- while (Serial1.available()) {
- // get the new byte:
- char inChar = (char)Serial1.read();
- // add it to the inputString:
- inputString += inChar;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar == '\n') {
- stringComplete = true;
- lineCount++;
- if(lineCount ==9)
- {
- lineCount = 0;
- display.setCursor(0,0);
- display.clearDisplay();
- }
- }
- }
- while (Serial.available()) {
- // get the new byte:
- char inChar2 = (char)Serial.read();
- // add it to the inputString:
- inputString2 += inChar2;
- // if the incoming character is a newline, set a flag
- // so the main loop can do something about it:
- if (inChar2 == '\n') {
- stringComplete2 = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement