Go Down

Topic: FONA808 and nRF52 Feather (Read 157 times) previous topic - next topic

dicobraz

Hi all,

I have a problem running Adafruit FONA808 breakout with Adafruit nRF52840 Feather without a USB connection (with USB all works as intended). All running on arduino sketch based on the examples provided by adafruit.

I have tried a few things, with running a SoftwareSerial communication through connecting RX/TX pins of FONA to A0/A1.

The last thing I have tries is to run through HardwareSerial connecting RX/TX pins of FONA to physical RX/TX pins of nRF52840 Feather.

No luck so far... Seems like no communication. I will post the code that runs in this situation, please advise what could be done, I hit the wall.

Code: [Select]
#include <Adafruit_FONA.h>
#include <ArduinoJson.h>
#include <bluefruit.h>

// #define FONA_RX A0
// #define FONA_TX A1
#define FONA_RST 9

// this is a large buffer for replies
char replybuffer[255];

// software serial to communicate with FONA
// #include <SoftwareSerial.h>
// SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
// SoftwareSerial *fonaSerial = &fonaSS;

HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

uint8_t type;

void setup() {
  // put your setup code here, to run once:
 
  while ( !Serial ) delay(10);
  Serial.begin(115200);
  fonaSerial->begin(4800);
  type = fona.type();
  fona.enableGPS(true);
  fona.enableGPRS(true);
}

void loop() {

  delay(10000);

  if (fona.getNetworkStatus() ==1 ) {
    char gpsdata[120];
    int8_t stat;
    uint8_t fr = fona.getRSSI();
    int8_t r;
    uint16_t vbat;
    uint16_t percbat;

    if (fr == 0) r = -115;
    if (fr == 1) r = -111;
    if (fr == 31) r = -52;
    if ((fr >= 2) && (fr <= 30)) {
      r = map(fr, 2, 30, -110, -54);
    }
   
    stat = fona.GPSstatus();
    if (stat > 1) {
      fona.getGPS(0, gpsdata, 120);
      fona.getBattVoltage(&vbat);
      fona.getBattPercent(&percbat);

      //Post data HTTP
      uint16_t statuscode;
      int16_t length;
      char c;
      char url[80] = "someurl.com";
      char data[300];

      const size_t capacity = JSON_OBJECT_SIZE(20);
      DynamicJsonDocument doc(capacity);

      doc["vbat"] = vbat;
      doc["percbat"] = percbat;
      doc["r"] = r;
      doc["stat"] = stat;
      doc["gpsdata"] = gpsdata;

      serializeJson(doc, data);
      fona.HTTP_POST_start(url, F("text/plain"), (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length);

      while (length > 0) {
        a = length;
        while (fona.available()) {
          c = fona.read();

#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
          loop_until_bit_is_set(UCSR0A, UDRE0); /* Wait until data register empty. */
          UDR0 = c;
#else
          //Serial.write(c);
#endif
          length--;
            if (! length) break;
          }
      }

      fona.HTTP_POST_end();
     
    } else {
      // TO DO
      //Serial.println("No FIX");
    }
   
  } else {
    // TO DO
    fona.enableGPRS(false);
    delay(60000);
    fona.enableGPRS(true);
  }
}

Go Up