Çözüldü292 görüntülenmeLoragps Lora
0

gps modülümüz ile lora modülümüz aynı anda çalıştırıldığında gps verilerini diğer lora’ya veri aktarımı yapılamıyor.

#include <TinyGPS++.h><br />#include <MPU9255.h><br />#include <SoftwareSerial.h><br />#include "LoRa_E22.h"<br />// #include <SimpleKalmanFilter.h><br />#include<Servo.h><br />#include <Wire.h><br />#include <SPI.h><br />#include <Adafruit_BMP280.h><br />SoftwareSerial mySerial(10, 11);<br />int servo_port = 9;<br />#define SERIAL_BAUD 9600<br />#define BMP_SCK  (13)<br />#define BMP_MISO (12)<br />#define BMP_MOSI (11)<br />#define BMP_CS   (10)<br />#define g 9.81<br /> /*SimpleKalmanFilter irtifaKalmanFilter(1, 540, 0.01);<br />SimpleKalmanFilter axKalmanFilter(1, 1, 0.01);<br />SimpleKalmanFilter ayKalmanFilter(1, 1, 0.01);<br />SimpleKalmanFilter azKalmanFilter(1, 1, 0.01);<br />SimpleKalmanFilter gxKalmanFilter(1, 1, 0.01);<br />SimpleKalmanFilter gyKalmanFilter(1, 1, 0.01);<br />SimpleKalmanFilter gzKalmanFilter(1, 1, 0.01);*/<br />LoRa_E22 E22(&mySerial);<br />Adafruit_BMP280 bmp;<br />MPU9255 mpu;<br />TinyGPSPlus gps;<br />Servo servom;<br />int pos = 90; <br />struct Signal {<br />  char type[15] = "Urfa63";<br />  float irtifa;<br />  float sicaklik;<br />  float gps_1;<br />  float gps_2;<br />  float ax[3];<br />  float gx[3];<br />  float ldr;<br />} data;<br /> #define M0 7<br />#define M1 6<br />#define BTN 2<br />#define LED 9<br />   static const int RXPin = 4, TXPin = 3;// Here we make pin 4 as RX of arduino & pin 3 as TX of arduino <br />static const uint32_t GPSBaud = 9600;<br /> SoftwareSerial ss(RXPin, TXPin);<br />float gps_1 = 0,gps_2 = 0;<br /> float ax[3] = {0.0,0.0,0.0};<br />float gx[3] = {0.0,0.0,0.0};<br /> float first_pres = 0,h = 0,irtifa = 0,max_irtifa = 0,min_irtifa = 0,sicaklik = 0,isik = 0;<br />bool aviyonik_durum = false;<br />  double process_acceleration(int input, scales sensor_scale )<br />{<br />  /*<br />  To get acceleration in 'g', each reading has to be divided by :<br />   -> 16384 for +- 2g scale (default scale)<br />   -> 8192  for +- 4g scale<br />   -> 4096  for +- 8g scale<br />   -> 2048  for +- 16g scale<br />  */<br />  double output = 1;<br />  //for +- 2g<br />   if(sensor_scale == scale_2g)<br />  {<br />    output = input;<br />    output = output/16384;<br />    output = output*g;<br />  }<br />   //for +- 4g<br />  if(sensor_scale == scale_4g)<br />  {<br />    output = input;<br />    output = output/8192;<br />    output = output*g;<br />  }<br />   //for +- 8g<br />  if(sensor_scale == scale_8g)<br />  {<br />    output = input;<br />    output = output/4096;<br />    output = output*g;<br />  }<br />   //for +-16g<br />  if(sensor_scale == scale_16g)<br />  {<br />    output = input;<br />    output = output/2048;<br />    output = output*g;<br />  }<br />   return output;<br />}<br />  double process_angular_velocity(int16_t input, scales sensor_scale )<br />{<br />  /*<br />  To get rotation velocity in dps (degrees per second), each reading has to be divided by :<br />   -> 131   for +- 250  dps scale (default value)<br />   -> 65.5  for +- 500  dps scale<br />   -> 32.8  for +- 1000 dps scale<br />   -> 16.4  for +- 2000 dps scale<br />  */<br />   //for +- 250 dps<br />  if(sensor_scale == scale_250dps)<br />  {<br />    return input/131;<br />  }<br />   //for +- 500 dps<br />  if(sensor_scale == scale_500dps)<br />  {<br />    return input/65.5;<br />  }<br />   //for +- 1000 dps<br />  if(sensor_scale == scale_1000dps)<br />  {<br />    return input/32.8;<br />  }<br />   //for +- 2000 dps<br />  if(sensor_scale == scale_2000dps)<br />  {<br />    return input/16.4;<br />  }<br />   return 0;<br />}<br /> void setup()<br />{<br />  pinMode(8,OUTPUT);<br />  Serial.begin(SERIAL_BAUD);<br />  ss.listen();<br />  ss.begin(GPSBaud);<br />  while(!Serial) {} // Wait<br />  Wire.begin();<br />  pinMode(M0, OUTPUT);<br />  pinMode(M1, OUTPUT);<br />  digitalWrite(M0, LOW);<br />  digitalWrite(M1, LOW);<br />  E22.begin();<br />  mySerial.listen();<br />  char* source = "urfa başlat";<br />  strcpy(data.type, source);<br />   ResponseStatus rs = E22.sendFixedMessage(0, 46, 18, &data, sizeof(Signal));<br />    if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {<br />  if (!bmp.begin()) {<br />    Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "<br />                      "try a different address!"));<br />  }<br />   /* Default settings from datasheet. */<br />  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */<br />                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */<br />                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */<br />                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */<br />                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */<br />}<br />    if(mpu.init())<br />  {<br />  Serial.println("MPU9255 çalıştırılamadı");<br />  }<br />  else<br />  {<br />  Serial.println("MPU9255 çalıştırıldı");<br />  }<br />  digitalWrite(8,HIGH);<br />  delay(1500);<br />  digitalWrite(8,LOW);<br />  isik = analogRead(A3);<br />}<br /> //////////////////////////////////////////////////////////////////<br />void loop()<br />{<br />  mpu.read_acc();<br />  mpu.read_gyro();<br />    Serial.print("GPS: ");<br />    Serial.print(gps_1, 6);<br />    Serial.print(F(" , "));<br />    Serial.print(gps_2, 6);<br />    Serial.print("   ");<br />   while (ss.available() > 0)<br />    if (gps.encode(ss.read()))<br />      displayInfo();<br />   if (millis() > 5000 && gps.charsProcessed() < 10)<br />  {<br />  } <br />   printMPU9255();<br />   printBME280();<br />       if (avyonik(irtifa) == true && aviyonik_durum == false){<br />    aviyonik_durum = true;<br />    Serial.print("irtifaya ulaşıldı");<br />    digitalWrite(8,HIGH);<br />    servom.write(pos);<br />    pos = 0;<br />    delay(1000);<br />    digitalWrite(8,LOW);<br />    }<br />         lora();<br />     delay(50);<br />}<br /> void printMPU9255(){<br />  ax[0] = process_acceleration(mpu.ax,scale_2g);<br />  //ax[0] = axKalmanFilter.updateEstimate(ax[0]);<br />  ax[1] = process_acceleration(mpu.ay,scale_2g);<br />  //ax[1] = ayKalmanFilter.updateEstimate(ax[1]);<br />  ax[2] = process_acceleration(mpu.az,scale_2g);<br />  //ax[2] = azKalmanFilter.updateEstimate(ax[2]);<br />   gx[0] = process_angular_velocity(mpu.gx,scale_250dps);<br />  //gx[0] = gxKalmanFilter.updateEstimate(gx[0]);<br />  gx[1] = process_angular_velocity(mpu.gy,scale_250dps);<br />  //gx[1] = gyKalmanFilter.updateEstimate(gx[1]);<br />  gx[2] = process_angular_velocity(mpu.gz,scale_250dps);<br />  //gx[2] = gzKalmanFilter.updateEstimate(gx[2]);<br />     Serial.print(" AX: ");<br />  Serial.print(ax[0]);<br />   //Y axis<br />  Serial.print(" AY: ");<br />  Serial.print(ax[1]);<br />   //Z axis<br />  Serial.print(" AZ: ");<br />  Serial.print(ax[2]);<br />   ////process and print gyroscope data////<br />  //X axis<br />  Serial.print("   GX: ");<br />  Serial.print(gx[0]);<br />   //Y axis<br />  Serial.print(" GY: ");<br />  Serial.print(gx[1]);<br />   //Z axis<br />  Serial.print(" GZ: ");<br />  Serial.print(gx[2]);<br />}<br />  //////////////////////////////////////////////////////////////////<br />void printBME280()<br />{<br />    irtifa = bmp.readAltitude(1013.25);<br />    //irtifa = irtifaKalmanFilter.updateEstimate(irtifa);<br />    sicaklik = bmp.readTemperature();<br />    Serial.print(F("   Sicaklik: "));<br />    Serial.print(sicaklik);<br />    Serial.print(" *C");<br />    Serial.print(F("   İrtifa: "));<br />    Serial.print(irtifa);<br />    Serial.print(" m    ");<br />    Serial.println(analogRead(A3));<br />}<br /> void displayInfo()<br />{<br />  ss.listen();<br />  if (gps.location.isValid())<br />  {<br />    gps_1 = gps.location.lat();<br />    gps_2 = gps.location.lng();<br />  }<br />  else<br />  {<br />    //Serial.print(F("VERİ ALİNAMADİ "));<br />  }<br />}<br />bool avyonik(float irtifas){<br />  if (max_irtifa - irtifas >= 0.15 && ax[1] > -2.3 && analogRead(A3) <= isik+150){<br />    return true;   <br />   }else if (irtifas > max_irtifa){<br />    max_irtifa = irtifas;<br />    return false;<br />    }else{<br />        return false;<br />    }<br />}<br />void lora(){<br />  mySerial.listen();<br />       if (E22.available()  > 1) {<br />    // Gelen mesaj okunuyor<br />    ResponseStructContainer rsc = E22.receiveMessage(sizeof(Signal));<br />    struct Signal data = *(Signal*) rsc.data;<br />    rsc.close();<br />     char* source = "maraşa selam";<br />    strcpy(data.type, source);<br />    data.irtifa = irtifa;<br />    data.sicaklik=sicaklik;<br />    data.gps_1 = gps_1;<br />    data.gps_2 = gps_2;<br />    data.ax[0] = ax[0];<br />    data.ax[1] = ax[1];<br />    data.ax[2] = ax[2];<br />    data.gx[0] = gx[0];<br />    data.gx[1] = gx[1];<br />    data.gx[2] = gx[2];<br />    data.ldr = analogRead(A3);<br />    ResponseStatus rs = E22.sendFixedMessage(0, 46, 18, &data, sizeof(Signal));<br />  }<br />  }

Soru yeni cevaplara kapalıdır.
Mehmet En iyi cevap olarak seçildi Haziran 1, 2022
Whatsapp'tan Yaz
1
Ürün Danışmanı Burada!
fixaj.com Ürün Danışmanı
Merhaba,

Ben sadece "Satın Alma" konularında ürün teknik bilgisinde destek vermekteyim.

Kodlama yardımı, haberleşme hataları, bağlantı şemaları vb. konularla ilgili "Soru&Cevap" sayfamızı ziyaret edebilirsiniz.