moononournation / Arduino_GFX

Arduino GFX developing for various color displays and various data bus interfaces
Other
794 stars 157 forks source link

fillRect didn't finish #326

Closed andreamarz closed 1 year ago

andreamarz commented 1 year ago

Hello, when i start my code the "gfx->fillRect(0, 0, w, h, BLACK);" on setup didn't finish the render, only first 10/15 row was colored and same thing when i redraw the rect inside my loop. Sometimes also "gfx->println(String(tempdate.substring(0, 25)));" that print a date crate some glitch.

I use new Arduino R4 Wifi, and this is my code:

#include "WiFiS3.h"
#include "WiFiSSLClient.h"
#include "IPAddress.h"
#include <ArduinoJson.h>
#include <Arduino_GFX_Library.h>

char ssid[] = "myssid";
char pass[] = "mywifipasswd";

int status = WL_IDLE_STATUS;
char server[] = "myserver";

WiFiSSLClient client;
unsigned long lastConnectionTime = 0;
const unsigned long postingInterval = 15L * 1000L;
int16_t w, h;

#define GFX_BL DF_GFX_BL
Arduino_DataBus *bus = new Arduino_UNOPAR8(A2, A3, A1, A0);
Arduino_GFX *gfx = new Arduino_ILI9486(bus, A4, 1);

void setup() {
  Serial.begin(115200);
  while (!Serial) { ; }

  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    while (true);
  }

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(1000);
  }
  printWifiStatus();

  #ifdef GFX_EXTRA_PRE_INIT
    GFX_EXTRA_PRE_INIT();
  #endif
  if (!gfx->begin()) { Serial.println("gfx->begin() failed!"); }

  w = gfx->width();
  h = gfx->height();

  gfx->fillRect(0, 0, w, h, BLACK);
  gfx->setTextColor(WHITE);
  gfx->setTextSize(3);
  gfx->setCursor(20, 50);
  gfx->print("dbp1");
  gfx->setCursor(20, 100);
  gfx->print("dbp2");
  gfx->setCursor(20, 150);
  gfx->print("dbp3");
  gfx->setCursor(20, 200);
  gfx->print("dbp4");

  delay(5000);
}

String message = "";

void reset2Defaults() {
  message = "";
}

void read_response() {
  while (client.available()) {
    char c = client.read();
    message.concat(c);
  }
}

void loop() {
  read_response();

  if (message != ""){
    int jsonexist = message.indexOf("{\"code\":");

    if (jsonexist > -1){
      delay(1000);
      String tempStr = message.substring(jsonexist);

      int str_len = tempStr.length() + 1;
      char char_array[str_len];
      tempStr.toCharArray(char_array, str_len);
      DynamicJsonDocument doc(5000);
      deserializeJson(doc, tempStr);

      const int code = doc["code"];
      int datestart = message.indexOf("Date:") + 6;
      String tempdate = message.substring(datestart);
      int dateend = tempdate.indexOf("\n");

      gfx->setCursor(10, 10);
      gfx->println(String(tempdate.substring(0, 25)));
      gfx->fillRect(100, 40, 70, 30, RED);
      gfx->fillRect(100, 90, 70, 30, RED);
      gfx->fillRect(100, 140, 70, 30, RED);
      gfx->fillRect(100, 190, 70, 30, RED);

      delay(1000);
      reset2Defaults();
    }
  }

  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();
  }
}

void httpRequest() {
  client.stop();

  if (client.connect(server, 3100)) {
    Serial.println("connected to server");
    client.println("GET / HTTP/1.1");
    client.println("Accept: */*");
    client.println("Host: myserver");
    client.println();
    lastConnectionTime = millis();
  } else {
    Serial.println("connection failed");
  }
}

void printWifiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
moononournation commented 1 year ago

what is Arduino_UNOPAR8?

andreamarz commented 1 year ago

Oh sorry it's a fork: https://github.com/ZinggJM/Arduino_GFX

My mistake, I have implemented this fork because the original one send me a lot of error as explicated here: https://forum.arduino.cc/t/uno-r4-wifi-with-3-5-tft-lcd-not-compiling/1150403/7