Sending Struct Package over LoRa - When Sensor Value Changes, Transmit Stops

27 Views Asked by At

I can send my data values over my LoRa module when I'm not moving the card. But when sensor value changes, data transmission stops.

I tried to increase delay sizes but it didn't change anything. This is the code that's working right now (I know it is bad code :( )

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <LoRa_E22.h>

#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)

uint16_t BNO055_SAMPLERATE_DELAY_MS = 100;
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28, &Wire1);
Adafruit_BMP280 bmp;
TinyGPSPlus gps;

typedef struct {
  byte baslangic = 0xff;
  float enlem;
  float boylam;
  float irtifa;
  float gpsirtifa;
  float gyrox;
  float gyroy;
  float gyroz;
  float accelx;
  float accely;
  float accelz;
  float rotx;
  float roty;
  float rotz;
  byte CRC;
  byte paketNo;
  byte son = 0xff;
} veriPaketi;

veriPaketi paket;

float gyroX, gyroY, gyroZ, accelX, accelY, accelZ, rotX, rotY, rotZ;
float enleM, boylaM, gpsirtifA;
float baslangicBasinc, irtifA;

bool bnoCheck, bmpCheck;

void setup() {
  Serial.begin(115200);
  Serial1.begin(9600);
  Serial2.setTX(8);
  Serial2.setRX(9);
  Serial2.begin(115200);

  if (!bno.begin()) {
    bnoCheck = false;
  } else {
    bnoCheck = true;
  }
  if (!bmp.begin()) {
    bmpCheck = false;
  } else {
    bmpCheck = true;
  }
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
  baslangicBasinc = bmp.readPressure() / 100;
}

void loop() {
  veriGuncelle();
  paketle();
  Serial2.write((byte)0x00); //Alıcı Adresi HIGH
  Serial2.write(31);       //Alıcı Adresi LOW
  Serial2.write(50);       //Alıcı Kanalı =0x17=23    (410M+23=433 MHz)
  Serial2.write((byte *)&paket, sizeof(veriPaketi));
  smartDelay(300);
  delay(200);
}

void veriGuncelle() {
  imu::Vector<3> accel = bno.getVector(Adafruit_BNO055::VECTOR_ACCELEROMETER);
  imu::Vector<3> gyro = bno.getVector(Adafruit_BNO055::VECTOR_GYROSCOPE);
  imu::Vector<3> orient = bno.getVector(Adafruit_BNO055::VECTOR_EULER);

  accelX = accel.x();
  accelY = accel.y();
  accelZ = accel.z();

  gyroX = gyro.x();
  gyroY = gyro.y();
  gyroZ = gyro.z();

  rotX = orient.x();
  rotY = orient.y();
  rotZ = orient.z();
  //////////////////////
  irtifA = bmp.readAltitude(baslangicBasinc);
  //////////////////////
  if (gps.altitude.isValid()) {
    gpsirtifA = gps.altitude.meters();
  } else {
    gpsirtifA = 0;
  }
  if (gps.location.isValid()) {
    enleM = gps.location.lat();   
    boylaM = gps.location.lng(); 
  } else {
    enleM = 0;
    boylaM = 0;
  }
}

void paketle() {
  paket.enlem = enleM;
  paket.boylam = boylaM;
  paket.gyrox = gyroX;
  paket.gyroy = gyroY;
  paket.gyroz = gyroZ;
  paket.accelx = accelX;
  paket.accely = accelY;
  paket.accelz = accelZ;
  paket.rotx = rotX;
  paket.roty = rotY;
  paket.rotz = rotZ;
  paket.gpsirtifa = gpsirtifA;
  paket.irtifa = irtifA;
}

static void smartDelay(unsigned long ms) {
  unsigned long start = millis();
  do {
    while (Serial1.available()) {
      gps.encode(Serial1.read());
    }
  } while (millis() - start < ms);
}

I'm using an RP2040 Zero for my microcontroller so Ilit is not a problem to use 2 serials at the same time. I just want the transmission not to stop when sensor values change. (Serial1 = AdaFruit Ultimate GPS - Serial2 = E22-900T30D LoRa module).

0

There are 0 best solutions below