WIO Issues trying to display tft and sd card

Hi,
I am using some code from the wifi/ble scanner. I am logging the data on the sd card, on the BLE side, Iseem to drop the scan after about 500 records. I can’t seem to get the tft to display/load images that I have on the SD Card or dump the text to the screen. This is a sample of the code I am trying to run.

Preformatted text#

  • List item
include <SPI.h>

#include <Seeed_FS.h>

#include "SD/Seeed_SD.h"

#include "rpcWiFi.h"

#include "rpcBLEDevice.h" //bluetooth library

#include "BLEScan.h" //bluetooth library

#include "BLEAdvertisedDevice.h" //bluetooth library

File myFile;

int scanTime = 2; //scan time for bluetooth

int counter = 1; //start count

BLEScan* pBLEScan; //create buffer to allocate memory

//get MAC addresses of bluetooth devices available

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks{

  void onResult(BLEAdvertisedDevice advertisedDevice){

    Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); //print MAC addresses of bluetooth devices

    myFile.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); //print MAC addresses of bluetooth devices

    myFile.println("");

    }

};

void setup() {

    Serial.begin(115200);

    while(!Serial); // Wait for Serial to be ready

    delay(100);{

    }

    // Set WiFi to station mode and disconnect from an AP if it was previously connected

    WiFi.mode(WIFI_STA); //configure Wi-Fi as Station(STA) Mode

    WiFi.disconnect(); //disconnect from an AP(access point) if it was previously connected

   

      //Bluetooth setup

  BLEDevice::init(""); //initialize bluetooth

  pBLEScan = BLEDevice::getScan(); //create new scan

  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); //set device callbacks

  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster

  pBLEScan->setInterval(100); //scan interval

  pBLEScan->setWindow(99); //less than or equal to setInterval value

    delay(100);

   

// Setup for SD Card  

  Serial.print("Initializing SD card...");

  if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)) {

    Serial.println("initialization failed!");

    while (1);

  }

  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,

  // so you have to close this one before opening another.

  myFile = SD.open("SensorData.txt", FILE_WRITE);

  // if the file opened okay, write to it:

  if (myFile) {

    Serial.print("Writing to SensorData.txt...");

    myFile.println("testing 1, 2, 3.");

    // close the file:

    myFile.close();

    Serial.println("done.");

  } else {

    // if the file didn't open, print an error:

    Serial.println("error opening SensorData.txt");

  }

  // re-open the file for reading:

  myFile = SD.open("SensorData.txt", FILE_READ);

  if (myFile) {

    Serial.println("SensorData.txt:");

    // read from the file until there's nothing else in it:

    while (myFile.available()) {

      Serial.write(myFile.read());

    }

    // close the file:

    myFile.close();

  } else {

    // if the file didn't open, print an error:

    Serial.println("error opening SensorData.txt");

    Serial.println("Setup done");

  }  

 

}  

// Setup done

// Before the loop

void loop() {

   

    myFile = SD.open("SensorData.txt", FILE_APPEND);

    Serial.println("Wi-Fi scan start");

    myFile.println("Wi-Fi scan start");

   

    // WiFi.scanNetworks will return the number of networks found

    int n = WiFi.scanNetworks();  //return the number of Wi-Fi networks found and store in variable

    Serial.println("scan done");

    myFile.println("scan done");

    if (n == 0) {

        Serial.println("no networks found"); //print string if no networks found

        myFile.println("no networks found"); //print string if no networks found

    } else {

       

        Serial.print(n); //print the number of networks found

        myFile.print(n);

        Serial.println(" networks found");

        myFile.println(" Networks Found");

        for (int i = 0; i < n; ++i) {  //iterate the network found in the loop

            // Print SSID and RSSI for each network found

            Serial.print(i + 1); //found network number

            myFile.print(i + 1);

            Serial.print(": ");

            myFile.print(": ");

            Serial.print(WiFi.SSID(i)); //print Wi-Fi name

            myFile.print(WiFi.SSID(i));

            Serial.print(" (");

            myFile.print(" (");

            Serial.print(WiFi.RSSI(i)); //print Wi-Fi signal strength

            myFile.print(WiFi.RSSI(i));

            Serial.print(")");

            myFile.println(")");

            Serial.print((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*"); //print "*" if password protected & print nothing if open

            myFile.print((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");

            delay(10);

        }

                                  

    }

    Serial.println("Wi-Fi scan done!");

    myFile.println("Wi-Fi scan done!");

    Serial.println("");  //print an empty line

    myFile.println("");  //print an empty line

     //Bluetooth scan

  Serial.println("BLE scan start");

  myFile.println("BLE scan start");

   {

    Serial.print("Loop Count: ");

    Serial.println(counter);

    myFile.print("Loop Count: ");

    myFile.println(counter);

    counter++;

     }

  BLEScanResults foundDevices = pBLEScan->start(scanTime, false); //scan for bluetooth devices and print MAC address

  Serial.print(foundDevices.getCount()); //print number of bluetooth devices found

  myFile.print(foundDevices.getCount()); //print number of bluetooth devices found

  Serial.println(" BLE device(s) found");

  myFile.println(" BLE device(s) found");

 

  Serial.println("BLE scan done!");

  myFile.println("BLE scan done!");

  pBLEScan->clearResults(); //delete results from pBLEScan buffer to release memory

  Serial.println("Networks Found");

  myFile.println("Networks Found");

  Serial.println("");

  myFile.println("");

  myFile.close();

    // Wait a bit before scanning again

    delay(500); //wait before scanning again

}

void saveData(){

myFile = SD.open("SensorData.txt",FILE_APPEND);

           

}

After about 92 loops through the BLE it stops, using the above code.

This code runs without using the TFT_eSPI display, when I add the TFT to it, it won’t run. I am sure I am doing something incorrectly, but need some good advice.

Thank you in advance!

Hi there,
What in the SAMHILL is that ? :face_with_peeking_eye:
Can you edit and use the ABOVE preformatted text tags, please! as you can SEE it makes it very difficult to read the flow, fix it and some folks will reply.
You already know , the TFT_eSPI needs specific edits in the selects file. certainly why it’s DOA.
what’s with all the Serial prints and My prints?
I don’t see an PIN define for the CS of the SD card?
are you trying to do wifi scan and BLE scan?
HTH
GL :slight_smile: PJ

You’re close , Mi unit is on Back order until March 4th… Nice little all-in one unit. :heart_eyes: :pinching_hand: :+1:

Hi PJ,
As you can tell I’m new to the Arduino IDE and the posting stuff. I tried cleaning up the formatting of the post, if I missed anything kindly let me know, and thanks for the response and any help you can provide.

1 Like

Hi there,
Nice job…Looks WAAAAY better, Now then :grin: :v:
What Size is the SD card & format ?
So I don’t see where it closes the file on SD card?
and the other questions Please., BTW ,Ok so your code compiled here no issue’s.

FQBN: Seeeduino:samd:seeed_wio_terminal
Using board 'seeed_wio_terminal' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5
Using core 'arduino' from platform in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5
Detecting libraries used...
---edit for brevity ---
Using library SPI at version 1.0 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\libraries\SPI 
Using library Adafruit Zero DMA Library at version 1.0.4 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\libraries\Adafruit_ZeroDMA 
Using library Seeed Arduino FS at version 2.1.1 in folder: D:\Arduino_projects\libraries\Seeed_Arduino_FS 
Using library Seeed Arduino rpcWiFi at version 1.0.7 in folder: D:\Arduino_projects\libraries\Seeed_Arduino_rpcWiFi 
Using library Seeed Arduino rpcUnified at version 2.1.4 in folder: D:\Arduino_projects\libraries\Seeed_Arduino_rpcUnified 
Using library Seeed Arduino FreeRTOS at version 10.4.3 in folder: C:\Users\Dude\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\libraries\Seeed_Arduino_FreeRTOS 
Using library Seeed Arduino rpcBLE at version 1.0.0 in folder: D:\Arduino_projects\libraries\Seeed_Arduino_rpcBLE 
Using library Seeed_Arduino_mbedtls at version 3.0.1 in folder: D:\Arduino_projects\libraries\Seeed_Arduino_mbedtls 
"C:\\Users\\Dude\\AppData\\Local\\Arduino15\\packages\\Seeeduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-size" -A "C:\\Users\\Dude\\AppData\\Local\\Temp\\arduino\\sketches\\0FA98A6111F7ECF1B666FFD73C31D6B5/sketch_feb25c.ino.elf"
Sketch uses 98336 bytes (19%) of program storage space. Maximum is 507904 bytes.

HTH
GL :slight_smile: PJ

some thoughts only 192kRam on that samd51 , kinda light IMHO…

Hi PJ,
Thanks for the response. The SD Card is 16 Gb and fat32. I know the code compiles, but when you run the scan it bombs on the BLE side after about 500 records, it’s like it does not clear the memory, (I think).

I have images stored on the SD Card that I try to display, they are formatted for the rgb565 (16-bit) images, these work on another display .ino that Seeed used as an example but I can’t seem to get this to work when using the scan code from above.
So these are the 2 issues that I need help with,
1- why does the BLE drop after 500 records
2- what do I need to do to get an image to display when running the scan code.

I tried combining the 2 sets of code, but got an error.


# include"TFT_eSPI.h"
# include "Seeed_FS.h" //Including SD card library
# include"RawImage.h"  //Including image processing library
TFT_eSPI tft;

void setup() {
    //Initialise SD card
    if(!SD.begin(SDCARD_SS_PIN, SDCARD_SPI)) {
        while (1);
    }
    tft.begin();
    tft.setRotation(3);

    drawImage<uint16_t>("test.bmp", 0, 0); //Display this 16bit image in sd card from (0, 0)

}

void loop() {
}

``

Hi there,
OK , what edits have you made to the User_Setup_Select.h ?
What pin Defines are you declaring, for the display and SD and I don’t see SPI.h ?
HTH
GL :slight_smile: PJ

Hi PJ,
I don’t think I have made any changes to the setup. I will check it. I have the declaration SPI.h in the original sketch, with the scanner code.

Thank you!

Hi there,
Ok so if you want to use the TFT_eSPI.lib You need to edit the User_Setup_Select.h file and choose your display. the defaults will conflict with other libs. the spi.h is also needed.
in the selects file for the Round display for example the uncommented line is the Seeed Round display
like this


What do you have uncommented for the display?
STart there, we can get it going easy. :+1:
HTH
GL :slight_smile: PJ

Thank you PJ! I will check it, I appreciate all the help.