Hi guys,
I have a simple program that should send a msg to another arduino when something happens.
Worked perfectly for a few weeks, but suddenly it resets during setup().
Here's the code:
/*
Arduino NANO + NRF24L01
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24Network.h>
#define CE 9
#define CSN 10
#define SENSOR_1 3
RF24 radio(CE, CSN); // Create a Radio
RF24Network network(radio);
const uint16_t this_node = 02;
const uint16_t master00 = 00;
char dataToSend[4] = "Pos2";
bool jam = false;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int threshold = 150;
int flag = 0;
unsigned long startTime;
unsigned long stopTime;
unsigned long elapsedTime;
unsigned long interval = 5000; // how long in ms should the sensor be active to detect a jam
void setup() {
Serial.begin(9600);
Serial.println("Tx Starting");
SPI.begin();
radio.begin();
network.begin(90, this_node);
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3, 5); // delay, count
digitalWrite(SENSOR_1, LOW); //change to analog with light barriers
}
//====================
void loop() {
network.update();
val1 = digitalRead(SENSOR_1);
if (val1 == HIGH) {
jam = true;
}
//===== Sending =====//
if (jam) { // If a jam is detected, send a message!
Serial.println("Jam detected");
RF24NetworkHeader header(master00, '2'); // (Address where the data is going)
network.write(header, &dataToSend, sizeof(dataToSend)); // Send the data
Serial.println(dataToSend);
delay (1000);
jam = false;
}
}
The serial monitor just gives me this repeatedly:
Tx St⸮Tx St⸮Tx St⸮Tx St⸮Tx St⸮Tx St⸮
I should mention that I have another Nano with the same code on it, using the same wireless module and it still works perfectly.
Is this Nano fried or am I missing something?