Çözüldü1.63K 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
0

kodu tekrar yorum olarak eklermisin bu şekl anlaşılmıyor.

şurda da aynı soruyu dün başka bir arkadaş sordu. alttaki 2 kod alıcı ve verici kısımları.

https://fixaj.com/SoruCevap/gps-ve-lora-ile-3-boyutlu-konum-yollama/

Mehmet En iyi cevap olarak seçildi Haziran 1, 2022
0

#include <TinyGPS++.h>
#include <MPU9255.h>
#include <SoftwareSerial.h>
#include “LoRa_E22.h”
// #include <SimpleKalmanFilter.h>
#include<Servo.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
SoftwareSerial mySerial(10, 11);
int servo_port = 9;
#define SERIAL_BAUD 9600
#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)
#define g 9.81

/*SimpleKalmanFilter irtifaKalmanFilter(1, 540, 0.01);
SimpleKalmanFilter axKalmanFilter(1, 1, 0.01);
SimpleKalmanFilter ayKalmanFilter(1, 1, 0.01);
SimpleKalmanFilter azKalmanFilter(1, 1, 0.01);
SimpleKalmanFilter gxKalmanFilter(1, 1, 0.01);
SimpleKalmanFilter gyKalmanFilter(1, 1, 0.01);
SimpleKalmanFilter gzKalmanFilter(1, 1, 0.01);*/
LoRa_E22 E22(&mySerial);
Adafruit_BMP280 bmp;
MPU9255 mpu;
TinyGPSPlus gps;
Servo servom;
int pos = 90;
struct Signal {
char type[15] = “Urfa63”;
float irtifa;
float sicaklik;
float gps_1;
float gps_2;
float ax[3];
float gx[3];
float ldr;
} data;

#define M0 7
#define M1 6
#define BTN 2
#define LED 9

static const int RXPin = 4, TXPin = 3;// Here we make pin 4 as RX of arduino & pin 3 as TX of arduino
static const uint32_t GPSBaud = 9600;

SoftwareSerial ss(RXPin, TXPin);
float gps_1 = 0,gps_2 = 0;

float ax[3] = {0.0,0.0,0.0};
float gx[3] = {0.0,0.0,0.0};

float first_pres = 0,h = 0,irtifa = 0,max_irtifa = 0,min_irtifa = 0,sicaklik = 0,isik = 0;
bool aviyonik_durum = false;

double process_acceleration(int input, scales sensor_scale )
{
/*
To get acceleration in ‘g’, each reading has to be divided by :
-> 16384 for +- 2g scale (default scale)
-> 8192 for +- 4g scale
-> 4096 for +- 8g scale
-> 2048 for +- 16g scale
*/
double output = 1;
//for +- 2g

if(sensor_scale == scale_2g)
{
output = input;
output = output/16384;
output = output*g;
}

//for +- 4g
if(sensor_scale == scale_4g)
{
output = input;
output = output/8192;
output = output*g;
}

//for +- 8g
if(sensor_scale == scale_8g)
{
output = input;
output = output/4096;
output = output*g;
}

//for +-16g
if(sensor_scale == scale_16g)
{
output = input;
output = output/2048;
output = output*g;
}

return output;
}

double process_angular_velocity(int16_t input, scales sensor_scale )
{
/*
To get rotation velocity in dps (degrees per second), each reading has to be divided by :
-> 131 for +- 250 dps scale (default value)
-> 65.5 for +- 500 dps scale
-> 32.8 for +- 1000 dps scale
-> 16.4 for +- 2000 dps scale
*/

//for +- 250 dps
if(sensor_scale == scale_250dps)
{
return input/131;
}

//for +- 500 dps
if(sensor_scale == scale_500dps)
{
return input/65.5;
}

//for +- 1000 dps
if(sensor_scale == scale_1000dps)
{
return input/32.8;
}

//for +- 2000 dps
if(sensor_scale == scale_2000dps)
{
return input/16.4;
}

return 0;
}

void setup()
{
pinMode(8,OUTPUT);
Serial.begin(SERIAL_BAUD);
servom.attach(9);
ss.listen();
ss.begin(GPSBaud);
while(!Serial) {} // Wait
Wire.begin();
pinMode(M0, OUTPUT);
pinMode(M1, OUTPUT);
digitalWrite(M0, LOW);
digitalWrite(M1, LOW);
E22.begin();
mySerial.listen();
char* source = “urfa başlat”;
strcpy(data.type, source);

ResponseStatus rs = E22.sendFixedMessage(0, 46, 18, &data, sizeof(Signal));

if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
if (!bmp.begin()) {
Serial.println(F(“Could not find a valid BMP280 sensor, check wiring or ”
“try a different address!”));
}

/* Default settings from datasheet. */
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. */
}

if(mpu.init())
{
Serial.println(“MPU9255 çalıştırılamadı”);
}
else
{
Serial.println(“MPU9255 çalıştırıldı”);
}
digitalWrite(8,HIGH);
delay(1500);
digitalWrite(8,LOW);
isik = analogRead(A3);
}

//////////////////////////////////////////////////////////////////
void loop()
{
mpu.read_acc();
mpu.read_gyro();
Serial.print(“GPS: “);
Serial.print(gps_1, 6);
Serial.print(F(” , “));
Serial.print(gps_2, 6);
Serial.print(” “);
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayInfo();

if (millis() > 5000 && gps.charsProcessed() < 10)
{
}
printMPU9255();
printBME280();

if (avyonik(irtifa) == true && aviyonik_durum == false){
aviyonik_durum = true;
Serial.print(“irtifaya ulaşıldı”);
digitalWrite(8,HIGH);
servom.write(pos);
pos = 0;
delay(1000);
digitalWrite(8,LOW);
}

lora();

delay(50);
}

void printMPU9255(){
ax[0] = process_acceleration(mpu.ax,scale_2g);
//ax[0] = axKalmanFilter.updateEstimate(ax[0]);
ax[1] = process_acceleration(mpu.ay,scale_2g);
//ax[1] = ayKalmanFilter.updateEstimate(ax[1]);
ax[2] = process_acceleration(mpu.az,scale_2g);
//ax[2] = azKalmanFilter.updateEstimate(ax[2]);

gx[0] = process_angular_velocity(mpu.gx,scale_250dps);
//gx[0] = gxKalmanFilter.updateEstimate(gx[0]);
gx[1] = process_angular_velocity(mpu.gy,scale_250dps);
//gx[1] = gyKalmanFilter.updateEstimate(gx[1]);
gx[2] = process_angular_velocity(mpu.gz,scale_250dps);
//gx[2] = gzKalmanFilter.updateEstimate(gx[2]);

Serial.print(” AX: “);
Serial.print(ax[0]);

//Y axis
Serial.print(” AY: “);
Serial.print(ax[1]);

//Z axis
Serial.print(” AZ: “);
Serial.print(ax[2]);

////process and print gyroscope data////
//X axis
Serial.print(” GX: “);
Serial.print(gx[0]);

//Y axis
Serial.print(” GY: “);
Serial.print(gx[1]);

//Z axis
Serial.print(” GZ: “);
Serial.print(gx[2]);
}

//////////////////////////////////////////////////////////////////
void printBME280()
{
irtifa = bmp.readAltitude(1013.25);
//irtifa = irtifaKalmanFilter.updateEstimate(irtifa);
sicaklik = bmp.readTemperature();
Serial.print(F(” Sicaklik: “));
Serial.print(sicaklik);
Serial.print(” *C”);
Serial.print(F(” İrtifa: “));
Serial.print(irtifa);
Serial.print(” m “);
Serial.println(analogRead(A3));
}

void displayInfo()
{
ss.listen();
if (gps.location.isValid())
{
gps_1 = gps.location.lat();
gps_2 = gps.location.lng();
}
else
{
//Serial.print(F(“VERİ ALİNAMADİ “));
}
}
bool avyonik(float irtifas){
if (max_irtifa – irtifas >= 0.15 && ax[1] > -2.3 && analogRead(A3) <= isik+150){
return true;
}else if (irtifas > max_irtifa){
max_irtifa = irtifas;
return false;
}else{
return false;
}
}
void lora(){
mySerial.listen();
if (E22.available() > 1) {
// Gelen mesaj okunuyor
ResponseStructContainer rsc = E22.receiveMessage(sizeof(Signal));
struct Signal data = *(Signal*) rsc.data;
rsc.close();

char* source = “maraşa selam”;
strcpy(data.type, source);
data.irtifa = irtifa;
data.sicaklik=sicaklik;
data.gps_1 = gps_1;
data.gps_2 = gps_2;
data.ax[0] = ax[0];
data.ax[1] = ax[1];
data.ax[2] = ax[2];
data.gx[0] = gx[0];
data.gx[1] = gx[1];
data.gx[2] = gx[2];
data.ldr = analogRead(A3);
ResponseStatus rs = E22.sendFixedMessage(0, 46, 18, &data, sizeof(Signal));
}
}

emre kamber Cevaplanan soru Mayıs 12, 2022
Whatsapp'tan Yaz
1
Ürün Danışmanı Burada!
fixaj.com Ürün Danışmanı
Merhaba,

Ben sadece "Satın Alma" konularında destek vermekteyim.

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