Displays the WiFi signal strength. Requires Adafruit_mfGFX, Adafruit_ILI9341 and XPT2046 libraries.
Source code at: https://go.particle.io/shared_apps/5a1a42c221b3e8bcb8000571
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_ILI9341.h"
// This #include statement was automatically added by the Particle IDE.
#include "XPT2046.h"
// This #include statement was automatically added by the Particle IDE.
#include
// Screen. See:
// http://nailbuster.com/?page_id=341
// =======================================
// A0 -> SD Card CS (Needs wire + 10k pullup)
// A1 -> Touch CS (Needs Wire + 10k pullup)
// A2 -> TFT CS
// D2 -> TFT DC
// D3 -> TFT RST
// A3 -> SCK
// A4 -> MOSI
// A5 -> MISO
// WKP -> Touch IRQ (with 0R Linker resitor R7)
// Display LED +3v3 needs 0R link resistor
// Dispolay reset needs 10k pullup.
// =======================================
// Display uses ILI9341 - Driver from Adafruit
// Touch uses XPT2046 - Driver from https://github.com/spapadim/XPT2046
int TFT_CS = A2;
int TFT_DC = D2;
int TFT_RESET = D3;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, 0);
// Change from V1.0 PCB, IRQ now on RX not WKP
XPT2046 touch(/*cs=*/ A1, /*irq=*/ RX);
volatile int showTouched = false;
void setup() {
SPI.setClockDividerReference(SPI_CLK_ARDUINO);
SPI.setClockDivider(SPI_CLOCK_DIV32);
tft.begin();
// Display we are using is the 2.8" 240x320
touch.begin(240, 320);
attachInterrupt(WKP, touched, CHANGE); // CHANGE, RISING
tft.setRotation(2);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(3);
tft.setRotation(3);
tft.setTextSize(4);
tft.setCursor(0, 0);
tft.println("WiFi....");
tft.setCursor(0, 65);
tft.println("Signal...");
tft.setCursor(0, 130);
tft.println("Meter......");
Particle.publish("status", "WiFi Display Stick v0.0.3");
delay(2000);
tft.setRotation(3);
}
// ISR for display touch
void touched() {
// If measuring the touch ADC this should be ignored as
// it is taken low!
showTouched = true;
}
int count = 0;
void loop() {
tft.fillScreen(ILI9341_BLACK);
int rssi = WiFi.RSSI();
tft.setCursor(0, 0);
tft.println("RSSI: " + String(rssi, DEC));
String senml = "{'n':'rssi', 'v':" + String(rssi, DEC) + "}";
Particle.publish("senml", "{'e': [ " + senml + "]}");
/*
for(uint8_t rotation=0; rotation<4; rotation++) {
tft.setRotation(rotation);
testText();
delay(10);
}
*/
if (touch.isTouching()) {
uint16_t x, y;
touch.getPosition(x, y);
tft.fillScreen(ILI9341_BLACK);
// Swap Antenna>
//tft.setCursor(0, 0);
//tft.println("x: 0x" + String(x, HEX));
//tft.println("y: 0x" + String(y, HEX));
delay(100);
count++;
}
delay(5000);
}