hi everyone, trying get arduino uno send data to esp32 TTGO but wont talk to each over and uno to uno works and esp32 to esp32 works, so not sure whats wrong i guess be coding
arduino sender
#include <LoRa.h>
#include<Arduino.h>
//Lora
// GPIO5 -- SX1278's SCK
// GPIO19 -- SX1278's MISO
// GPIO27 -- SX1278's MOSI
// GPIO18 -- SX1278's CS
// GPIO14 -- SX1278's RESET
// GPIO26 -- SX1278's IRQ(Interrupt Request)
#define SS 10
#define RST 9
#define DI0 2
#define BAND 915E6
#define triggerPIN 6
#define echoPIN 7
int returnCM; // Variable containg processed sounding
int safetyDistance;
int counter = 0;
void setup() {
pinMode(25,OUTPUT); //Send success, LED will bright 1 second
Serial.begin(115200);
while (!Serial); //If just the the basic function, must connect to a computer
LoRa.setPins(SS,RST,DI0);
// Serial.println("LoRa Sender");
if (!LoRa.begin(BAND)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initial OK!");
pinMode(triggerPIN, OUTPUT); // Set the trigPin as an Output (sr04t or v2.0)
// pinMode(echoPIN, INPUT); // Set the echoPin as an Input (sr04t)
pinMode(echoPIN,INPUT_PULLUP); // Set the echoPin as an Input with pullup (sr04t or v2.0)
}
void loop() {
long distanceCM = 0;
unsigned long durationMS = 0;
// Do sounding here
distanceCM = 0;
durationMS = 0;
// Clear the trigger pin
digitalWrite(triggerPIN, LOW);
delayMicroseconds(2);
// Sets the trigger on HIGH state for 10 micro seconds
digitalWrite(triggerPIN, HIGH);
delayMicroseconds(20);
digitalWrite(triggerPIN, LOW);
// wait for the echo
durationMS = pulseIn(echoPIN, HIGH);
// Calculating the distance
distanceCM = (((int) durationMS * 0.034) / 2);
safetyDistance = distanceCM;
// Prints the distance on the Serial Monitor
Serial.println("Watertank 01");
Serial.print("Distance: ");
Serial.println(distanceCM);
// send packet
LoRa.beginPacket();
Serial.print("1");
LoRa.print(counter);
Serial.print("2");
LoRa.print(distanceCM);
Serial.print("3");
LoRa.endPacket();
Serial.print("4");
counter++;
delay(5000);
}
esp32 receiver
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include "SSD1306.h"
#include "images.h"
#define SCK 5 // GPIO5 -- SX1278's SCK
#define MISO 19 // GPIO19 -- SX1278's MISO
#define MOSI 27 // GPIO27 -- SX1278's MOSI
#define SS 18 // GPIO18 -- SX1278's CS
#define RST 14 // GPIO14 -- SX1278's RESET
#define DI0 26 // GPIO26 -- SX1278's IRQ(Interrupt Request)
#define BAND 915E6
SSD1306 display(0x3c, 4, 15);
String rssi = "RSSI --";
String packSize = "--";
String packet ;
void loraData(){
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0 , 15 , "Received "+ packSize + " bytes");
display.drawStringMaxWidth(0 , 26 , 128, packet);
display.drawString(0, 0, rssi);
display.display();
}
void cbk(int packetSize) {
packet ="";
packSize = String(packetSize,DEC);
for (int i = 0; i < packetSize; i++) { packet += (char) LoRa.read(); }
rssi = "RSSI " + String(LoRa.packetRssi(), DEC) ;
loraData();
}
void setup() {
pinMode(16,OUTPUT);
digitalWrite(16, LOW); // set GPIO16 low to reset OLED
delay(50);
digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high、
Serial.begin(9600);
while (!Serial);
Serial.println();
Serial.println("LoRa Receiver Callback");
SPI.begin(SCK,MISO,MOSI,SS);
LoRa.setPins(SS,RST,DI0);
if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
//LoRa.onReceive(cbk);
LoRa.receive();
Serial.println("init ok");
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
delay(20);
}
void loop() {
Serial.println("loop");
int packetSize = LoRa.parsePacket();
if (packetSize) { cbk(packetSize); }
delay(5);
}
i was hoping send water level and water flow and pressure with lora for long distance to be used monitor sheep water supply
cheers