ESP32 S2 TFT Wi-Fi problem

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
rrvogel4
 
Posts: 24
Joined: Wed Aug 12, 2020 12:43 am

ESP32 S2 TFT Wi-Fi problem

Post by rrvogel4 »

I have a question about the ESP32-S2 TFT. I have a RF95 lora Featherwing and an Adalogger on a tripler board with it. This is receiving lora data from 4 moisture sensors at 30 minute intervals or more. The ESP32 reboots after my lora featherwing receives a transmission and then attempts a Wi-Fi connection to Adafruit IO. When I disable the Wi-Fi I have no trouble receiving data and logging it using pins 5,6, and 9 for the lora. I was also using pin 10 for the SD_CS but the problem remains even after I cut the trace.
I also changed the lora featherwing"s pins to 5, 11 and A5 after seeing something in the config file about the Wi-Fi using pins 10, 9 and 6, but it made no difference. After looking at the datasheet it says that there are 4 SPI busses and SPI2 and SPI3 are for general use. SPI2 can have up to 6 CS pins and SPI3 can only have 3 and I don't know if the Wi-Fi uses any of them and which is set by default. I'm just a learning hobbyist and this is my first program I have written for ESP32 so I'm not sure how to address the SPI issues if that is causing this.
I think I am using the Adafruit IO examples correctly. I tried using WipperSnapper and was able to send data to AIO so the Wi-Fi works, but that won't work with my project.
I can't find an example that connects to AIO to update the feeds when my data comes in and then disconnects when done.
Please help.

User avatar
neradoc
 
Posts: 542
Joined: Wed Apr 27, 2016 2:38 pm

Re: ESP32 S2 TFT Wi-Fi problem

Post by neradoc »

rrvogel4 wrote:When I disable the Wi-Fi I have no trouble receiving data and logging it using pins 5,6, and 9 for the lora.
Hi, what issues are you encountering with the wifi ? Is the code crashing ? What language are you developing in ?
You can share your code - being careful not to share any login or personal information - and we can have a look at it.
rrvogel4 wrote:seeing something in the config file about the Wi-Fi using pins 10, 9 and 6
The wifi doesn't use any pin, or SPI, it's built into the chip. It's the airlift wifi breakouts that use SPI.
Have you looked at the Adafruit IO examples in the Feather ESP32-S2 guide ?

User avatar
rrvogel4
 
Posts: 24
Joined: Wed Aug 12, 2020 12:43 am

Re: ESP32 S2 TFT Wi-Fi problem

Post by rrvogel4 »

I was able to get the button example to work by it self, but it wouldn't compile with the config file. I put the proper #defines and #include "AdafruitIO_WiFi.h" along with the
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); command in the main body of the program and then it would compile.
However, I still have the same problem with the board rebooting whenever a node sends data to the lora.
here is the code:

Code: Select all

#include <SPI.h>
#include <Wire.h>
#include <SX127XLT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SD.h>
#include <RTClib.h>
#include <Adafruit_GFX.h>
#include "AdafruitIO_WiFi.h"

#define SD_CS 10
#define DIO0 5
#define LORA_RST A5
#define LORA_CS 11
#define LORA_DEVICE  DEVICE_SX1276
#define TXpower 10
#define LORA_SYNCWORD 0xFF
#define ACKdelay 100
#define RXtimeout 200

#define IO_USERNAME "my_username"
#define IO_KEY "my_key"
#define WIFI_SSID "my_ssid"
#define WIFI_PASS "my_password"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);

int NewData[6][7];
float TempC;
uint16_t Bat;
float TempF;
uint8_t Humid;
uint16_t Moisture;
uint8_t Tries;
int16_t PacketRSSI;
uint8_t RXPacketL;
uint8_t RXPayloadL;
uint8_t PacketOK;
uint16_t LocalPayloadCRC;
uint16_t RXPayloadCRC;
const uint16_t NetworkID = 0x1111;
uint8_t startaddr = 0;
const uint16_t thisNode = 999;
uint16_t NodeID;
uint16_t destinationNode;

AdafruitIO_Feed *tempF = io.feed("tempF");
AdafruitIO_Feed *humid = io.feed("humid");
AdafruitIO_Feed *moisture = io.feed("moisture");
AdafruitIO_Feed *nodeID = io.feed("nodeID");

RTC_PCF8523 rtc;
DateTime now;
SX127XLT LT;
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
File logFile;

void setup()
{
  SPI.begin();
  Serial.begin(115200);
  rtc.begin();
  LT.begin(LORA_CS, LORA_RST, DIO0, LORA_DEVICE);
  Lora_init();
  // turn on backlite
  pinMode(TFT_BACKLITE, OUTPUT);
  digitalWrite(TFT_BACKLITE, HIGH);
  // turn on the TFT / I2C power supply
  pinMode(TFT_I2C_POWER, OUTPUT);
  digitalWrite(TFT_I2C_POWER, HIGH);
  delay(10);
  // initialize TFT
  tft.init(135, 240); // Init ST7789 240x135
  tft.setRotation(3);
  tft.setTextSize(2);
  tft.setTextWrap(false);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(1, 0);
  tft.setTextColor(ST77XX_ORANGE);
  displayTime();
  if (! rtc.initialized() || rtc.lostPower())
  {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  rtc.start();
  if (SD.begin(SD_CS))
  {
    if (!SD.exists("/LOG.csv"))
  {
    logFile = SD.open("/LOG.csv", FILE_WRITE);
      if (logFile)
      {
        logFile.println("Date,Time,NodeID,Humid,Moisture,BatVolts,TempF,Tries,RSSI");
        logFile.close();
      }
    }
  }
  Serial.print("Connecting to Adafruit IO");
  io.connect();
    // wait for a connection
  while(io.status() < AIO_CONNECTED) 
  {
    Serial.print(".");
    delay(500);
  }
  // we are connected
  Serial.println();
  Serial.println(io.statusText());
}

void loop()
{
  io.run();
  tft.setCursor(1, 0);
  tft.setTextColor(ST77XX_ORANGE);
  displayTime();

  if (LT.receiveSXReliableIRQ(startaddr, NetworkID, RXtimeout, WAIT_RX));
  {
    RXPacketL = LT.readRXPacketL();
    RXPayloadL = RXPacketL - 4;
    PacketRSSI = LT.readPacketRSSI();

    LT.startReadSXBuffer(startaddr);
    NodeID = LT.readUint16();
    destinationNode = LT.readUint16();
    TempC = LT.readFloat();
    Humid = LT.readUint8();
    Moisture = LT.readUint16();
    Bat = LT.readUint16();
    Tries = LT.readUint8();
    RXPayloadL = LT.endReadSXBuffer();
    TempF = TempC * 1.8 + 32;

    if (destinationNode == thisNode)
    {
      now = rtc.now();
      sendACK();
      showData();
      formatData();
      displayData();
      logData();
      feedAIO();
    }
  }

}

void feedAIO()
{
  
  tempF->save(TempF);
  humid->save(Humid);
  moisture->save(Moisture);
  nodeID->save(NodeID);
//  io.wifi_disconnect();
}
void formatData()
{
  for (int i = 6; i > 0; i--) {
    for (int j = 0; j < 7; j++) {
      NewData[i][j] = NewData[i - 1][j];
    }
  }
  NewData[0][0] = NodeID / 100;
  NewData[0][1] = Humid;
  NewData[0][2] = Moisture;
  NewData[0][3] = Bat;
  NewData[0][4] = round (TempF * 10.0);
  NewData[0][5] = now.hour();
  NewData[0][6] = now.minute();

}

void displayData()
{
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(1, 0);
  tft.setTextColor(ST77XX_ORANGE);
  displayTime();
  tft.setTextColor(ST77XX_WHITE);
  tft.setCursor(0, 18);
  tft.print("ID|H2O|Bat| ");
  tft.print((char)247);
  tft.print("F |Time");

  for (int i = 0; i < 6; i++)
  {
    tft.setCursor(0, i * 16 + 35);

    if (NewData[i][0] == 1)
    {
      tft.setTextColor(ST77XX_BLUE);
      printLine(i);
    }
    else if (NewData[i][0] == 2)
    {
      tft.setTextColor(ST77XX_YELLOW);
      printLine(i);
    }
    else if (NewData[i][0] == 3)
    {
      tft.setTextColor(ST77XX_MAGENTA);
      printLine(i);
    }
    else if (NewData[i][0] == 4)
    {
      tft.setTextColor(ST77XX_GREEN);
      printLine(i);
    }
    else return;

  }

}
void printLine(int i)
{
  tft.print(" ");
  tft.print(NewData[i][0]);
  tft.print("|");
  tft.print(NewData[i][2]);
  tft.print("|");
  tft.print((NewData[i][3] / 1000.0), 1);
  tft.print("|");
  tft.print(float(NewData[i][4] / 10.0), 1);
  tft.print("|");
  if (NewData[i][5] < 10) tft.print("0");
  tft.print(NewData[i][5]);
  if (NewData[i][6] < 10) tft.print("0");
  tft.print(NewData[i][6]);
}
void logData()
{
  logFile = SD.open("/LOG.csv", FILE_APPEND);
  logFile.print(now.month(), DEC);
  logFile.print("-");
  logFile.print(now.day(), DEC);
  logFile.print("-");
  logFile.print(now.year(), DEC);
  logFile.print(",");
  logFile.print(now.hour(), DEC);
  logFile.print(":");
  logFile.print(now.minute(), DEC);
  logFile.print(":");
  logFile.print(now.second(), DEC);
  logFile.print(",");
  logFile.print(NodeID / 100);
  logFile.print(",");
  logFile.print(Humid);
  logFile.print(",");
  logFile.print(Moisture);
  logFile.print(",");
  logFile.print(Bat / 1000.0, 2);
  logFile.print(",");
  logFile.print(TempF, 1);
  logFile.print(",");
  logFile.print(Tries);
  logFile.print(",");
  logFile.println(PacketRSSI);
  logFile.close();
}

void sendACK()
{
  LocalPayloadCRC = LT.CRCCCITTReliable(0, RXPayloadL - 1, 0xFFFF);    //calculate payload crc
  delay(ACKdelay);
  LT.sendReliableACK(NetworkID, LocalPayloadCRC, TXpower);
}

void Lora_init()
{
  LT.setMode(MODE_STDBY_RC);
  LT.setPacketType(PACKET_TYPE_LORA);
  LT.setRfFrequency(915E6, 0);
  LT.calibrateImage(0);
  LT.setModulationParams(LORA_SF9, LORA_BW_125, LORA_CR_4_7, LDRO_AUTO);
  LT.setBufferBaseAddress(0x00, 0x00);
  LT.setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL);
  LT.setSyncWord(LORA_SYNCWORD);
  LT.setHighSensitivity();
  LT.setDioIrqParams(IRQ_RADIO_ALL, IRQ_TX_DONE, 0, 0);

}
void displayTime()
{
  now = rtc.now();
  //     tft.setTextSize(1);
  tft.setTextColor(ST77XX_ORANGE, ST77XX_BLACK);
  //  tft.setCursor(1, 0);
  tft.print(now.month(), DEC);
  tft.print("/");
  tft.print(now.day(), DEC);
  tft.print("/");
  tft.print(now.year() - 2000, DEC);
  tft.print(" ");
  if (now.hour() < 10) tft.print("0");
  tft.print(now.hour(), DEC);
  tft.print(":");
  if (now.minute() < 10) tft.print("0");
  tft.print(now.minute(), DEC);
  tft.print(":");
  if (now.second() < 10) tft.print("0");
  tft.print(now.second(), DEC);
  //  if (now.isPM()) tft.print(" PM");
  //  else tft.print(" AM");
}

void showData()
{
  Serial.println("node\tTempF\tTempC\tHumid\tMoist\tBat\tTries");
  Serial.print(NodeID);
  Serial.print("\t");
  Serial.print(TempF);
  Serial.print("\t");
  Serial.print(TempC);
  Serial.print("\t");
  Serial.print(Humid);
  Serial.print("\t");
  Serial.print(Moisture);
  Serial.print("\t");
  Serial.print(Bat);
  Serial.print("\t");
  Serial.println(Tries);
}
Also, is there a command to disconnect from AIO as I only want to connect when data comes in.

User avatar
rrvogel4
 
Posts: 24
Joined: Wed Aug 12, 2020 12:43 am

Re: ESP32 S2 TFT Wi-Fi problem

Post by rrvogel4 »

Just to clarify, in the code that I posted, if I comment out the AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); , the AdafruitIO_Feed definitions, the io.connect portion in the setup. and the io.run and feedAIO function in the loop the sketch runs perfectly.
It receives each nodes data when it comes in, then saves the last 6 sets in an array and displays the time and the last 6 data sets in a different color for each node on the display, then it logs the newest set in the adalogger.
What I want to do is to connect to AIO send the new set of data when it comes in and then disconnect from AIO, which I don't know how to do.
When I run the sketch as written it displays the time until a data transmission comes in, the display blanks and the board leds light up and it reboots to the time until the next one.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”