sparkfun / SparkFun_Swarm_Satellite_Arduino_Library

An Arduino library to enable communications with the Swarm M138 satellite modem
Other
28 stars 11 forks source link

what is the dependency Wire.h? #35

Closed wstack-dev closed 1 year ago

wstack-dev commented 1 year ago

Hi guys. Query what is the dependency Wire.h?. I got this when compiling. Added AceWire but it didn't recognize wire.h

platform = espressif32 board = esp32doit-devkit-v1 framework = arduino monitor_speed = 115200 lib_deps = bxparks/AceWire@^0.4.1 sparkfun/SparkFun Swarm Satellite Arduino Library@^1.1.10

Captura de pantalla de 2023-02-20 17-18-52

Good day

wstack-dev commented 1 year ago

I changed these lines and got the missing library. I need a coffee. ha ha ha

[env:nodemcu-32s] platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = sparkfun/SparkFun Swarm Satellite Arduino Library@^1.1.10 plerup/EspSoftwareSerial@^7.0.0

Captura de pantalla de 2023-02-20 17-44-27

Now I have a communication error with the modem. To the delay of the code I increased it to 10 seconds

Captura de pantalla de 2023-02-20 17-47-42

-softwareSerial Captura de pantalla de 2023-02-20 18-00-57

It is expected to be able to connect. There will be some kind of issue with this since I am connecting to an EVAL KIT by JTAG headers

Captura de pantalla de 2023-02-20 00-28-40

https://swarm.space/product/swarm-eval-kit/

Abrazos para todos

PaulZC commented 1 year ago

Hi,

I think you are having problems because you are not defining your serial pins or port correctly? Or perhaps the pins are being allocated to two Serial ports?

Looking at the code you posted on the Swarm repo, please try:

#include <HardwareSerial.h>

#define RXD2 16
#define TXD2 17

#include <SparkFun_Swarm_Satellite_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_Swarm_Satellite

SWARM_M138 mySwarm;

#define swarmSerial Serial2

void setup() {

Serial.begin(115200);

Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);

mySwarm.begin(swarmSerial);

PIns 16 and 17 are usually used for Serial1 not Serial2... There may be a conflict?

This forum issue may help:

https://forum.sparkfun.com/viewtopic.php?p=237503#p237503

We included Wire.h and I2C communication for a possible future product - "Qwiic Swarm" like our Qwiic Iridium product.

I hope this helps, Paul

wstack-dev commented 1 year ago

Pablo, thank you for your response and guidance. I followed your advice without success and I followed the advice given in the thread sent without success.

1- hwAvail return 0 forever. 2- hwAvail which corresponds to the Available() of hardwareSerial. But I have another simple connection code and the Available() returns 1 3-Increase the wait rate by 10000 after the command is sent. and i have no success 4-the number 3 in the capt. corresponds to the error that in this case is due to timeout

Paul's suggestion Captura de pantalla de 2023-02-21 13-40-01

simple code but enter available() Captura de pantalla de 2023-02-21 13-50-08

I think I have problems with the Rx, but run some code to validate Rx and Tx by sending a message and connecting both pins and everything works great. I should mention that I am connected by FTDI (Rx, TX and GND)

Thank you very much for the guidance and help

PaulZC commented 1 year ago

Please share "Paul's Suggestion" line 40 onwards. I can't see if you are initializing swarmSerial correctly.

wstack-dev commented 1 year ago

Thanks Paul for the prompt response. My mistake for not posting the complete code.

I share

`#include

define RXD2 16

define TXD2 17

include

SWARM_M138 mySwarm; // HardwareSerial swarmSerial; // #define swarmSerial Serial1 HardwareSerial swarmSerial(2);

void printGeospatial(const Swarm_M138_GeospatialData_t *info) { Serial.print(F("New geospatial information received: Lat: ")); Serial.print(info->lat, 4); Serial.print(F(" Lon: ")); Serial.print(info->lon, 4); Serial.print(F(" Alt: ")); Serial.print(info->alt, 2); Serial.print(F(" Course: ")); Serial.print(info->course, 2); Serial.print(F(" Speed: ")); Serial.println(info->speed, 2); }

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void setup() { // Swarm Satellite Transceiver MicroMod Function Board PWR_EN

ifdef swarmPowerEnablePin

pinMode(swarmPowerEnablePin, OUTPUT); // Enable modem power digitalWrite(swarmPowerEnablePin, HIGH);

endif

delay(10000);

Serial.begin(115200); while (!Serial) ; // Wait for the user to open the Serial console Serial.println(F("Swarm Satellite example")); Serial.println(); swarmSerial.begin(115200, SERIAL_8N1, RXD2, TXD2); //swarmSerial.setRxTimeout(30);

//mySwarm.enableDebugging(); // Uncomment this line to enable debug messages on Serial // Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);

bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem

while (!modemBegun) // If the begin failed, keep trying to begin communication with the modem { Serial.println(F("Could not communicate with the modem. It may still be booting...")); delay(10000); modemBegun = mySwarm.begin(swarmSerial); }

// Just to prove it works, call getGeospatialInfo to request the most recent geospatial information Swarm_M138_GeospatialData_t *info = new Swarm_M138_GeospatialData_t; // Allocate memory for the information

Swarm_M138_Error_e err = mySwarm.getGeospatialInfo(info);

while (err != SWARM_M138_SUCCESS) { Serial.print(F("Swarm communication error: ")); Serial.print((int)err); Serial.print(F(" : ")); Serial.println(mySwarm.modemErrorString(err)); // Convert the error into printable text Serial.println(F("The modem may not have acquired a valid GPS fix...")); delay(10000); err = mySwarm.getGeospatialInfo(info); }

Serial.print(F("getGeospatialInfo returned: ")); Serial.print(info->lat, 4); Serial.print(F(",")); Serial.print(info->lon, 4); Serial.print(F(",")); Serial.print(info->alt); Serial.print(F(",")); Serial.print(info->course); Serial.print(F(",")); Serial.println(info->speed); delete info; // Free the memory

// Set up the callback for the geospatial information message. Call printGeospatial when a new $GN message arrives mySwarm.setGeospatialInfoCallback(&printGeospatial);

// Set the $GN message rate: send the message every 2 seconds err = mySwarm.setGeospatialInfoRate(2);

if (err == SWARM_M138_SUCCESS) { Serial.println(F("setGeospatialInfoRate was successful")); } else { Serial.print(F("Swarm communication error: ")); Serial.print((int)err); Serial.print(F(" : ")); Serial.print(mySwarm.modemErrorString(err)); // Convert the error into printable text if (err == SWARM_M138_ERROR_ERR) // If we received a command error (ERR), print it { Serial.print(F(" : ")); Serial.print(mySwarm.commandError); Serial.print(F(" : ")); Serial.println(mySwarm.commandErrorString((const char *)mySwarm.commandError)); } else Serial.println(); }

// Just to prove it works, call getGeospatialInfoRate to check the message rate uint32_t rate;

mySwarm.getGeospatialInfoRate(&rate);

Serial.print(F("Message rate is ")); Serial.println(rate); }

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void loop() { mySwarm.checkUnsolicitedMsg(); }`

a hug

PaulZC commented 1 year ago

Hi @wstack-dev ,

OK - thanks. I can't see why it's not working... Unless there is a conflict between Serial1 and Serial2? (Pins 16 and 17 are usually used for Serial1.)

I am away from home for a few days - and I don't have access to a Swarm modem. I will try and replicate your issue when I'm back at home. I will try and reply again on Monday at the latest.

Until then, Paul

PaulZC commented 1 year ago

Just a note that another user was having the same issue with pins 16 and 17:

https://forum.sparkfun.com/viewtopic.php?p=237503#p237503

PaulZC commented 1 year ago

Hi @wstack-dev ,

Looking at the output from your esp32swarm.test, you see the "RT RSSI" messages. That means your RX pin is working. You are receiving data from the modem. But it does not prove that your TX pin is working. If you saw any GN position data in your received data, that would prove TX is working.

I suspect it is a pin/port conflict which is preventing the TX data from being transmitted. You could try a simple loop-back test to make sure. Disconnect the modem. Use a jumper wire to connect 16 to 17. Repeat your esp32swarm.test. Do you see the GN message echoed back?

Best wishes, Paul

PaulZC commented 1 year ago

Ah. Sorry. Looking again at your esp32swarm.test output. It looks like you have connected 16 to 17, and also to the modem? Otherwise I cannot explain how you are seeing $GN @*69 in the serial console. That is not a good test. The ESP and Modem TX pins will conflict - perhaps preventing the modem from receiving any data.

Also, I do not understand how you are using an FTDI cable/board?

Can you please post a photo of your set-up - and a wiring diagram too if possible.

Thanks, Paul

PaulZC commented 1 year ago

I have access to my Swarm modem again. I'm going to document this in real time as I test the Serial configurations, so there will be several updates over the next hour or so...

My set-up:

First Test - Run Example1 UNMODIFIED

This test confirms that the Thing Plus C supports Serial1 correctly on pins 16 and 17

Success:

image

PaulZC commented 1 year ago

Test 2 - Run Example1 with Debug messages enabled

I've uncommented this line so I can see the debug messages:

https://github.com/sparkfun/SparkFun_Swarm_Satellite_Arduino_Library/blob/5d07a8c6d7c1528c131767228cb0bf180716904c/examples/Example1_getConfigurationSettings/Example1_getConfigurationSettings.ino#L60

Output is:

image

The $CS information is requested and sent twice as mySwarm.begin uses $CS to check if the modem is connected.

PaulZC commented 1 year ago

Test 3 - Manually define the pins for Serial1

#include <HardwareSerial.h>

#include <SparkFun_Swarm_Satellite_Arduino_Library.h>

SWARM_M138 mySwarm;

#define RXD_Pin 16
#define TXD_Pin 17

HardwareSerial swarmSerial(1); // Use UART 1

void setup()
{
  delay(1000);

  Serial.begin(115200);
  Serial.println(F("Swarm Satellite example"));
  Serial.println();

  swarmSerial.begin(115200, SERIAL_8N1, RXD_Pin, TXD_Pin);

  mySwarm.enableDebugging(); // Uncomment this line to enable debug messages on Serial

  bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem

  while (!modemBegun) // If the begin failed, keep trying to begin communication with the modem
  {
    Serial.println(F("Could not communicate with the modem. It may still be booting..."));
    delay(2000);
    modemBegun = mySwarm.begin(swarmSerial);
  }

  char configSettings[30]; // Create storage for the configuration settings

  Swarm_M138_Error_e err = mySwarm.getConfigurationSettings(configSettings); // Get the settings

  if (err == SWARM_M138_SUCCESS)
  {
    Serial.print(F("The configuration settings are: "));
    Serial.println(configSettings);
  }
}

void loop()
{
  //Nothing to do here
}

Result:

image

PaulZC commented 1 year ago

OK. So far, so good.

pins_arduino.h for the Thing Plus C does not define pins for Serial2 (UART2). So the next test is to manually define those pins - and move the jumper wires to match.

Test 4 - Manually define the pins for Serial2

I'm using Pin 25 for TX and Pin 26 for RX. The jumper wires are now:

Updated code is:

#include <HardwareSerial.h>

#include <SparkFun_Swarm_Satellite_Arduino_Library.h>

SWARM_M138 mySwarm;

#define RXD_Pin 26
#define TXD_Pin 25

HardwareSerial swarmSerial(2); // Use UART 2

void setup()
{
  delay(1000);

  Serial.begin(115200);
  Serial.println(F("Swarm Satellite example"));
  Serial.println();

  swarmSerial.begin(115200, SERIAL_8N1, RXD_Pin, TXD_Pin);

  mySwarm.enableDebugging(); // Uncomment this line to enable debug messages on Serial

  bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem

  while (!modemBegun) // If the begin failed, keep trying to begin communication with the modem
  {
    Serial.println(F("Could not communicate with the modem. It may still be booting..."));
    delay(2000);
    modemBegun = mySwarm.begin(swarmSerial);
  }

  char configSettings[30]; // Create storage for the configuration settings

  Swarm_M138_Error_e err = mySwarm.getConfigurationSettings(configSettings); // Get the settings

  if (err == SWARM_M138_SUCCESS)
  {
    Serial.print(F("The configuration settings are: "));
    Serial.println(configSettings);
  }
}

void loop()
{
  //Nothing to do here
}

Result is:

image

PaulZC commented 1 year ago

Here's where I think your issue lies, and where I think communication will fail. I am going to attempt to use UART2 - but with pins 16 and 17 which are normally allocated to Serial1.

Test 5 - Use UART2 but with Serial1's Pins 16 and 17

Move the jumper wires back to:

Change the code to:

#include <HardwareSerial.h>

#include <SparkFun_Swarm_Satellite_Arduino_Library.h>

SWARM_M138 mySwarm;

#define RXD_Pin 16
#define TXD_Pin 17

HardwareSerial swarmSerial(2); // Use UART 2 but with Serial1's pins

void setup()
{
  delay(1000);

  Serial.begin(115200);
  Serial.println(F("Swarm Satellite example"));
  Serial.println();

  swarmSerial.begin(115200, SERIAL_8N1, RXD_Pin, TXD_Pin);

  mySwarm.enableDebugging(); // Uncomment this line to enable debug messages on Serial

  bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem

  while (!modemBegun) // If the begin failed, keep trying to begin communication with the modem
  {
    Serial.println(F("Could not communicate with the modem. It may still be booting..."));
    delay(2000);
    modemBegun = mySwarm.begin(swarmSerial);
  }

  char configSettings[30]; // Create storage for the configuration settings

  Swarm_M138_Error_e err = mySwarm.getConfigurationSettings(configSettings); // Get the settings

  if (err == SWARM_M138_SUCCESS)
  {
    Serial.print(F("The configuration settings are: "));
    Serial.println(configSettings);
  }
}

void loop()
{
  //Nothing to do here
}

Edit: Sorry! Silly me. I forgot to move the jumper wires! This test does actually work too:

image

PaulZC commented 1 year ago

Edit: Sorry! Forgot to move the jumper wires...

Right now I can't explain the issue you are having. I do still suspect it is some invalid combination of UART and TX/RX pins, but I can't prove it or replicate it.

Can you please post a photo of your set-up - and a wiring diagram too if possible.

Best wishes, Paul

wstack-dev commented 1 year ago

@PaulZC , I appreciate all the help given. I have been following your advice. And in the end the error lay in the jumpers of the antenna's serialBuffer.

I leave my source code running.

#include <iostream>
#include <string>
#include <HardwareSerial.h>
#include <Wire.h>
#include "DFRobot_SHT20.h"

#define RXD2 16
#define TXD2 17

#include <SparkFun_Swarm_Satellite_Arduino_Library.h>

SWARM_M138 mySwarm;

HardwareSerial swarmSerial(2);

unsigned long tiempo1 = 0;
unsigned long tiempo2 = 0;
unsigned long tiempoSegundos = 0;

void printGeospatial(const Swarm_M138_GeospatialData_t *info)
{
  Serial.print(F("New geospatial information received:  Lat: "));
  Serial.print(info->lat, 4);
  Serial.print(F("  Lon: "));
  Serial.print(info->lon, 4);
  Serial.print(F("  Alt: "));
  Serial.print(info->alt, 2);
  Serial.print(F("  Course: "));
  Serial.print(info->course, 2);
  Serial.print(F("  Speed: "));
  Serial.println(info->speed, 2);
}

void printMessageSent(const int16_t *rssi_sat, const int16_t *snr, const int16_t *fdev, const uint64_t *msg_id)
{
  Serial.print(F("New $TD SENT message received:"));
  Serial.print(F("  RSSI = "));
  Serial.print(*rssi_sat);
  Serial.print(F("  SNR = "));
  Serial.print(*snr);
  Serial.print(F("  FDEV = "));
  Serial.print(*fdev);
  Serial.println();
}

DFRobot_SHT20 sht20;
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void setup()
{
  sht20.initSHT20(); // Init SHT20 Sensor
  delay(100);
  sht20.checkSHT20(); // Check SHT20 Sensor
// Swarm Satellite Transceiver MicroMod Function Board PWR_EN
#ifdef swarmPowerEnablePin
  pinMode(swarmPowerEnablePin, OUTPUT); // Enable modem power
  digitalWrite(swarmPowerEnablePin, HIGH);
#endif

  delay(10000);

  Serial.begin(115200);
  while (!Serial)
    ; // Wait for the user to open the Serial console
  Serial.println(F("Swarm Satellite example"));
  Serial.println();
  swarmSerial.begin(115200, SERIAL_8N1, RXD2, TXD2);

  mySwarm.enableDebugging(); // Uncomment this line to enable debug messages on Serial

  bool modemBegun = mySwarm.begin(swarmSerial); // Begin communication with the modem

  while (!modemBegun) // If the begin failed, keep trying to begin communication with the modem
  {
    Serial.println(F("No se pudo comunicar con el módem. Puede que todavía esté arrancando..."));
    delay(10000);
    modemBegun = mySwarm.begin(swarmSerial);
  }

  // Just to prove it works, call getGeospatialInfo to request the most recent geospatial information
  Swarm_M138_GeospatialData_t *info = new Swarm_M138_GeospatialData_t; // Allocate memory for the information

  Swarm_M138_Error_e err = mySwarm.getGeospatialInfo(info);

  while (err != SWARM_M138_SUCCESS)
  {
    Serial.print(F("Swarm communication error: "));
    Serial.print((int)err);
    Serial.print(F(" : "));
    Serial.println(mySwarm.modemErrorString(err)); // Convert the error into printable text
    Serial.println(F("Es posible que el módem no haya adquirido una posición de GPS válida..."));
    delay(10000);
    err = mySwarm.getGeospatialInfo(info);
    // float humd = sht20.readHumidity();
    // float temp = sht20.readTemperature();
    // Serial.print("Temperature:");
    // Serial.print(temp, 1);
    // Serial.print("C");
    // Serial.print(" Humidity:");
    // Serial.print(humd, 1);
    // Serial.print("%");
    // Serial.println();
  }

  Serial.print(F("getGeospatialInfo response: "));
  Serial.print(info->lat, 4);
  Serial.print(F(","));
  Serial.print(info->lon, 4);
  Serial.print(F(","));
  Serial.print(info->alt);
  Serial.print(F(","));
  Serial.print(info->course);
  Serial.print(F(","));
  Serial.println(info->speed);
  delete info; // Free the memory

  // Set up the callback for the geospatial information message. Call printGeospatial when a new $GN message arrives
  mySwarm.setGeospatialInfoCallback(&printGeospatial);

  // Set the $GN message rate: send the message every 2 seconds
  err = mySwarm.setGeospatialInfoRate(2);

  if (err == SWARM_M138_SUCCESS)
  {
    Serial.println(F("setGeospatialInfoRate was successful"));
  }
  else
  {

    Serial.print(F("Swarm communication error: "));
    Serial.print((int)err);
    Serial.print(F(" : "));
    Serial.print(mySwarm.modemErrorString(err)); // Convert the error into printable text
    if (err == SWARM_M138_ERROR_ERR)             // If we received a command error (ERR), print it
    {
      Serial.print(F(" : "));
      Serial.print(mySwarm.commandError);
      Serial.print(F(" : "));
      Serial.println(mySwarm.commandErrorString((const char *)mySwarm.commandError));
    }
    else
      Serial.println();
  }

  // Just to prove it works, call getGeospatialInfoRate to check the message rate
  uint32_t rate;

  mySwarm.getGeospatialInfoRate(&rate);

  Serial.print(F("Respuesta"));
  Serial.println(rate);
  tiempo1 = millis();
}

//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

void loop()
{
  mySwarm.checkUnsolicitedMsg();
}

Anyway, I already have hardwareSerial mastered, I'm using 2 uarts on pins 16/17 and 26/27.

I realized that regardless of the uart to occupy, what is in charge is the definition of ports by the user. I did tests declaring hardwareSerial(1) and assigning 26Rx/28Tx pins and it works great. I also tried hardwareSerial(1) with 16Rx/17Tx pins and no problem. So to reach a happy ending with hardwareSerial independent of the uart to occupy, the important thing is the definition of pins, which I can do in begin() or by editing hardwareSerial.cpp

#ifndef SOC_RX0
#if CONFIG_IDF_TARGET_ESP32
#define SOC_RX0 3
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define SOC_RX0 44
#elif CONFIG_IDF_TARGET_ESP32C3
#define SOC_RX0 20
#endif
#endif

#ifndef SOC_TX0
#if CONFIG_IDF_TARGET_ESP32
#define SOC_TX0 1
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define SOC_TX0 43
#elif CONFIG_IDF_TARGET_ESP32C3
#define SOC_TX0 21
#endif
#endif

void serialEvent(void) __attribute__((weak));
void serialEvent(void) {}

#if SOC_UART_NUM > 1

#ifndef RX1
#if CONFIG_IDF_TARGET_ESP32
#define RX1 9
#elif CONFIG_IDF_TARGET_ESP32S2
#define RX1 18
#elif CONFIG_IDF_TARGET_ESP32C3
#define RX1 18
#elif CONFIG_IDF_TARGET_ESP32S3
#define RX1 15
#endif
#endif

#ifndef TX1
#if CONFIG_IDF_TARGET_ESP32
#define TX1 10
#elif CONFIG_IDF_TARGET_ESP32S2
#define TX1 17
#elif CONFIG_IDF_TARGET_ESP32C3
#define TX1 19
#elif CONFIG_IDF_TARGET_ESP32S3
#define TX1 16
#endif
#endif

void serialEvent1(void) __attribute__((weak));
void serialEvent1(void) {}
#endif /* SOC_UART_NUM > 1 */

#if SOC_UART_NUM > 2
#ifndef RX2
#if CONFIG_IDF_TARGET_ESP32
#define RX2 16
#elif CONFIG_IDF_TARGET_ESP32S3
#define RX2 19 
#endif
#endif

#ifndef TX2
#if CONFIG_IDF_TARGET_ESP32
#define TX2 17
#elif CONFIG_IDF_TARGET_ESP32S3
#define TX2 20
#endif
#endif

Happy ending

Captura de pantalla de 2023-02-24 14-21-11

***I am in the underground but in the open air it works wonderfully

Greetings from Chile

PaulZC commented 1 year ago

Thanks for the update - glad that’s working for you!

Very best wishes, Paul