master
nerdyscout 3 months ago
commit 3221338fa7
  1. 5
      .gitignore
  2. 19
      platformio.ini
  3. 138
      src/main.cpp
  4. 3
      src/main.h

5
.gitignore vendored

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

@ -0,0 +1,19 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:m5stack-core-esp32]
platform = espressif32
board = m5stack-core-esp32
framework = arduino
upload_protocol = esptool
lib_deps =
adafruit/Adafruit GFX Library@^1.11.3
sandeepmistry/LoRa@^0.8.0
upload_port=/dev/ttyACM0

@ -0,0 +1,138 @@
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Wire.h>
#include <SPI.h>
#include <LoRa.h>
#include "main.h"
#define RE 8
#define DE 7
// const byte code[]= {0x01, 0x03, 0x00, 0x1e, 0x00, 0x03, 0x65, 0xCD};
const byte nitro[] = {0x01, 0x03, 0x00, 0x1e, 0x00, 0x01, 0xe4, 0x0c};
const byte phos[] = {0x01, 0x03, 0x00, 0x1f, 0x00, 0x01, 0xb5, 0xcc};
const byte pota[] = {0x01, 0x03, 0x00, 0x20, 0x00, 0x01, 0x85, 0xc0};
byte values[11];
void setup()
{
Serial.begin(9600);
while (!Serial)
;
Serial.println("LoRa Gönderen");
Serial.println();
if (!LoRa.begin(433E6))
{
Serial.println("LoRa'yı başlatamadım");
while (1)
;
}
LoRa.setTxPower(20);
Serial.begin(9600);
Serial2.begin(9600);
pinMode(RE, OUTPUT);
pinMode(DE, OUTPUT);
}
void loop()
{
byte val1, val2, val3;
val1 = nitrogen();
delay(250);
val2 = phosphorous();
delay(250);
val3 = potassium();
delay(250);
Serial.print("Nitrogen: ");
Serial.print(val1);
Serial.println(" mg/kg");
Serial.print("Phosphorous: ");
Serial.print(val2);
Serial.println(" mg/kg");
Serial.print("Potassium: ");
Serial.print(val3);
Serial.println(" mg/kg");
delay(2000);
LoRa.beginPacket();
LoRa.println("LoRa Alıcı");
LoRa.println();
LoRa.print("Nitrogen ");
LoRa.print(val1);
LoRa.println(" mg/kg");
LoRa.print("Phosphorous ");
LoRa.print(val2);
LoRa.println(" mg/kg");
LoRa.print("Potassium ");
LoRa.print(val3);
LoRa.println(" mg/kg");
LoRa.endPacket();
delay(1000);
}
byte nitrogen()
{
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (Serial2.write(nitro, sizeof(nitro)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 7; i++)
{
// Serial.print(Serial2.read(),HEX);
values[i] = Serial2.read();
// Serial.print(values[i],HEX);
}
Serial.println();
}
return values[4];
}
byte phosphorous()
{
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (Serial2.write(phos, sizeof(phos)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 7; i++)
{
// Serial.print(Serial2.read(),HEX);
values[i] = Serial2.read();
// Serial.print(values[i],HEX);
}
Serial.println();
}
return values[4];
}
byte potassium()
{
digitalWrite(DE, HIGH);
digitalWrite(RE, HIGH);
delay(10);
if (Serial2.write(pota, sizeof(pota)) == 8)
{
digitalWrite(DE, LOW);
digitalWrite(RE, LOW);
for (byte i = 0; i < 7; i++)
{
// Serial.print(Serial2.read(),HEX);
values[i] = Serial2.read();
// Serial.print(values[i],HEX);
}
Serial.println();
}
return values[4];
}

@ -0,0 +1,3 @@
byte nitrogen();
byte phosphorous();
byte potassium();
Loading…
Cancel
Save