Hello, I’m doing an internship project for greenhouses in my area, I’m somewhat new to programming and automation. My code keeps resetting to setup and I’m not sure why. Also it’s not receiving any messages from my other RFM69 connected to an Arduino Uno, but I’m assuming that’s because it keeps resetting. Any help is appreciated.
ESP32 board is Nose32s in Arduino IDE.
Setup:
Pins:
RFM69: ESP32
Vin: 5V
Mosi: GPIO23 (VPSIMOSI)
Miso: GPIO19 (VSPIMISO)
CS = GPIO5 (VSPI SS)
RST = GPI02
G0/INT = GPI15
SCK/LED = GPI18 (VSPI SCK)
Serial Monitor:
19:15:04.914 -> Feather RFM69 RX Test!
19:15:05.017 -> RFM69 radio init OK!
19:15:05.054 -> RFM69 radio @915 MHz
19:15:05.633 -> .......WiFi connected
19:15:09.739 -> test1 Feather RFM69 RX Test!
19:15:11.028 -> RFM69 radio init OK!
19:15:11.062 -> RFM69 radio @915 MHz
19:15:11.655 -> .WiFi connected
19:15:12.889 -> test1 Feather RFM69 RX Test!
19:15:14.183 -> RFM69 radio init OK!
19:15:14.183 -> RFM69 radio @915 MHz
19:15:14.799 -> .WiFi connected
19:15:15.906 -> test1 Feather RFM69 RX Test!
19:15:17.186 -> RFM69 radio init OK!
19:15:17.220 -> RFM69 radio @915 MHz
19:15:17.804 -> .WiFi connected
19:15:19.039 -> test1 Feather RFM69 RX Test!
19:15:20.334 -> RFM69 radio init OK!
19:15:20.334 -> RFM69 radio @915 MHz
Code:
// rf69 demo tx rx.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF69 class. RH_RF69 class does not provide for addressing or
// reliability, so you should only use RH_RF69 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf69_server.
// Demonstrates the use of AES encryption, setting the frequency and modem
// configuration
#define BLYNK_TEMPLATE_ID "**************"
#define BLYNK_DEVICE_NAME "ESP32"
#define BLYNK_AUTH_TOKEN "*************************"
#include <SPI.h>
#include <RH_RF69.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_AHTX0.h> //for alarm
int i = 0; //for alarm
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***************************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*********";
char pass[] = "**************";
/************ Radio Setup ***************/
// Change to 434.0 or other frequency, must match RX's freq!
#define RF69_FREQ 915.0
//#if defined (Arduino Uno) //Arduino Uno input by Calder
#define RFM69_CS 5
#define RFM69_INT 15
#define RFM69_RST 2
#define LED 19
// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);
int16_t packetnum = 0; // packet counter, we increment per xmission
void setup()
{
Serial.begin(9600);
//while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer
pinMode(33, OUTPUT); //pin for LED
pinMode(32, OUTPUT); //pin for noise maker pin
//Serial.begin(115200);
//while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer
pinMode(LED, OUTPUT);
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, LOW);
Serial.println("Feather RFM69 RX Test!");
// manual reset
digitalWrite(RFM69_RST, HIGH);
delay(10);
digitalWrite(RFM69_RST, LOW);
delay(10);
if (!rf69.init()) {
Serial.println("RFM69 radio init failed");
while (1);
}
Serial.println("RFM69 radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
// No encryption
if (!rf69.setFrequency(RF69_FREQ)) {
Serial.println("setFrequency failed");
}
// If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
// ishighpowermodule flag set like this:
rf69.setTxPower(20, true); // range from 14-20 for power, 2nd arg must be true for 69HCW
// The encryption key has to be the same as the one in the server
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);
pinMode(LED, OUTPUT);
Serial.print("RFM69 radio @"); Serial.print((int)RF69_FREQ); Serial.println(" MHz");
//Wifi code copy pasted
WiFi.begin(ssid, pass);
int wifi_ctr = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Blynk.begin(auth, ssid, pass);
}
void loop() {
//Alarm
Serial.print ("test1 ");
noTone(9); //no noise for buzzer if temp normal
if (rf69.available()) {
// Should be a message for us now
Serial.print ("test2 ");
uint8_t buf[RH_RF69_MAX_MESSAGE_LEN]; //Creates array using buf of the amount of units there are in the string
uint8_t len = sizeof(buf); //len = length of string
if (rf69.recv(buf, &len)) {
Serial.print ("test3 ");
float hhtemp = *((float *)buf);
// if (!len) return;
if (len = 4); //if length is 4 (for temp) then:
if (!len) return;
buf[len] = 0;
Serial.print("Received [");
Serial.print(len); //length of message received
Serial.print("]: ");
Serial.println(hhtemp);
Serial.print("RSSI: "); //RSSI is like the signal strength
Serial.println(rf69.lastRssi(), DEC);
//Send data to Blynk website
Blynk.run();
delay(200);
Blynk.virtualWrite(V1,hhtemp);
//////////// Blynk.virtualWrite(V2,hhhumid);
//Siren Alarm using Buzzer
if (hhtemp > 75) {
for(i=700;i<800;i++){
tone(9,i);
digitalWrite(8, HIGH);
delay(15);
}
for(i=800;i>700;i--){
tone(9,i);
digitalWrite(8, LOW);
delay(15);
}
}
}
} else {
Serial.println("Receive failed");
// set radio to use less power
// it will wake up the next time send() or sendWithRetry() is called
//////////// rf69.sleep(); ///removing to test if doens't work on ESP32
}
Serial.print ("Test4 ");
}


