Chat freely about anything...

User avatar
By Aurélien DM
#68562 Hi, I am using a Huzzah Feather ESP8826 from Adafruit plugged into a TFT FeatherWing screen.
I have connected an IMU BNO055 and a Neo-6M GPS module (from Adafruit too).
The TFT works well when only the IMU is called by the sketch, or only the GPS, but not both at the same time (the outputs then are zero or wrong). It bugs right after the setup(void), before entering the loop(void).
Could it be a matter of ressources? I tried to reduce the pace at which my ESP harvests the data, and put some yield() here and there, but it doesn’t seem to be of any help... :cry:
I am using SoftwareSerial() and Wire.pins(), maybe some weird conflict between them?

Ever heard of this kind of problem?
Here is the code – I deleted some functions not necessary to understand the problem, to make it more readable, so it might not work if you run it.

Cheers



Code: Select all
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_BNO055.h>


#define STMPE_CS 16
#define TFT_CS   0
#define TFT_DC   15
#define BNO055_SAMPLERATE_DELAY_MS (100)
#define rx_pin 12
#define tx_pin 14

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_BNO055 bno = Adafruit_BNO055();

TinyGPS gps;
SoftwareSerial rxtx = SoftwareSerial(rx_pin, tx_pin);

struct timelatilongi {
  int annee;
  byte mois, jour, heure, minuttte, seconde, centieme;   
  float lati, longi;

// ------------------------------ Setup & loop ------------------------------



void setup(void) {

  wdt_enable(WDTO_1S);
  wdt_reset();
  pinMode(rxx, INPUT);
  pinMode(txx, OUTPUT);
  Serial.begin(115200);
  yield();
  tft.begin();
  yield();
  Serial.begin(115200);
  yield();
  starting_bno();
  yield();

}


void loop(void) {
 
  wdt_enable(WDTO_1S);
  wdt_reset();
  timelatilongi position=search_gps();
  yield();
  float latitude=position.lati, longitude=position.longi;
  float heading=direction();
  tft_display(latitude, longitude, heading); 

}


// ------------------------------ Functions ------------------------------



void starting_bno() {
  if(!bno.begin())  {
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }
  delay(1000);
  bno.setExtCrystalUse(true);
  displaySensorDetails();
}


struct timelatilongi search_gps() { 
  int year;
  byte month, day, hour, minute, second, hundr;
  bool newData = false;
  unsigned long chars; unsigned short sentences, failed;
  float flat; float flon; unsigned long age;
  struct timelatilongi coord;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;) {
    while (rxtx.available()) {
      char c = rxtx.read();
      if (gps.encode(c))
        newData = true;
    }
  }
  if (newData) {
    gps.f_get_position(&flat, &flon, &age);
    gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundr);
    coord.lati=flat;
    coord.longi=flon;
    return coord;
  }
  gps.stats(&chars, &sentences, &failed);
  if (chars == 0) { Serial.println(F("** No characters received from GPS: check wiring **")); }
  delay(1000); 
}


float direction() {
  sensors_event_t event;
  bno.getEvent(&event);
  yield();
  float cap=event.orientation.x;
  return(cap);
}


void tft_display(float head, ) {
  tft.fillScreen(ILI9341_WHITE);
  tft.setTextColor(ILI9341_BLACK);
  tft.print("Latitude : ");  tft.println(latitude,6);
  tft.print("Longitude : ");  tft.println(longitude,6);
  tft.print("Heading : ");  tft.println(heading,0);
}