Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Adafruit Feather 32u4 Freezing
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit Feather 32u4 Freezing

by jackbarber on Fri Jul 24, 2020 9:17 am

Hi

I've been building a remote control system using a pair of Adafruit Feather 32u4 Radio with RFM69HCW Modules. The transmitter works fine - consistently sending out commands.

However, the receiver seems to work for a while, processing a lot of commands successfully over a period of time, then becomes unresponsive. I've stripped down my code to make it as simple and minimal as possible (attempting to save resources on the board), but the problem persists. I wonder if anyone can spot any problems with the code below? Anything I can do to work out why it freezes?

Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include <RH_RF69.h>

#define RF69_FREQ 433.0

#define A_UP          13
#define A_DOWN        12
#define B_UP          11
#define B_DOWN        10
#define D_DOWN        18
#define E_UP          9
#define E_DOWN        6
#define F_UP          5
#define F_DOWN        19

#define C_1           20
#define C_2           21
#define C_3           22

#define RFM69_CS      8
#define RFM69_INT     7
#define RFM69_RST     4

RH_RF69 rf69(RFM69_CS, RFM69_INT);

int16_t packetnum = 0;

void setup()
{
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, LOW);
 
  if (!rf69.init()) {
    while (1);
  }

  rf69.setTxPower(20, true);
 
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
 
  pinMode(A_UP, OUTPUT);
  pinMode(A_DOWN, OUTPUT);
  pinMode(B_UP, OUTPUT);
  pinMode(B_DOWN, OUTPUT);
  pinMode(D_DOWN, OUTPUT);
  pinMode(E_UP, OUTPUT);
  pinMode(E_DOWN, OUTPUT);
  pinMode(F_UP, OUTPUT);
  pinMode(F_DOWN, OUTPUT);

  pinMode(C_1, OUTPUT);
  pinMode(C_2, OUTPUT);
  pinMode(C_3, OUTPUT);

  digitalWrite(A_UP,HIGH);
  digitalWrite(A_DOWN,HIGH);
  digitalWrite(B_UP,HIGH);
  digitalWrite(B_DOWN,HIGH);
  digitalWrite(D_DOWN,HIGH);
  digitalWrite(E_UP,HIGH);
  digitalWrite(E_DOWN,HIGH);
  digitalWrite(F_UP,HIGH);
  digitalWrite(F_DOWN,HIGH);

  digitalWrite(C_1,HIGH);
  digitalWrite(C_2,HIGH);
  digitalWrite(C_3,HIGH);
}


void loop() {
 if (rf69.available()) {
    static uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf69.recv(buf, &len)) {
      if (!len) return;
      buf[len] = 0;
      if (strstr((char *)buf, "A UP ON")) {
        digitalWrite(A_UP,LOW);
      }else if (strstr((char *)buf, "A UP OFF")) {
        digitalWrite(A_UP,HIGH);
      }else if (strstr((char *)buf, "A DOWN ON")) {
        digitalWrite(A_DOWN,LOW);
      }else if (strstr((char *)buf, "A DOWN OFF")) {
        digitalWrite(A_DOWN,HIGH);
      }else if (strstr((char *)buf, "B UP ON")) {
        digitalWrite(B_UP,LOW);
      }else if (strstr((char *)buf, "B UP OFF")) {
        digitalWrite(B_UP,HIGH);
      }else if (strstr((char *)buf, "B DOWN ON")) {
        digitalWrite(B_DOWN,LOW);
      }else if (strstr((char *)buf, "B DOWN OFF")) {
        digitalWrite(B_DOWN,HIGH);
      }else if (strstr((char *)buf, "D ON")) {
        digitalWrite(D_DOWN,LOW);
      }else if (strstr((char *)buf, "D OFF")) {
        digitalWrite(D_DOWN,HIGH);
      }else if (strstr((char *)buf, "E UP ON")) {
        digitalWrite(E_DOWN,HIGH);
        digitalWrite(E_UP,LOW);
        delay(3000);
        digitalWrite(E_UP,HIGH);
      }else if (strstr((char *)buf, "E UP OFF")) {
        digitalWrite(E_UP,HIGH);
      }else if (strstr((char *)buf, "E DOWN ON")) {
        digitalWrite(E_UP,HIGH);
        digitalWrite(E_DOWN,LOW);
        delay(3000);
        digitalWrite(E_DOWN,HIGH);
      }else if (strstr((char *)buf, "E DOWN OFF")) {
        digitalWrite(E_DOWN,HIGH);
      }else if (strstr((char *)buf, "F UP ON")) {
        digitalWrite(F_UP,LOW);
      }else if (strstr((char *)buf, "F UP OFF")) {
        digitalWrite(F_UP,HIGH);
      }else if (strstr((char *)buf, "F DOWN ON")) {
        digitalWrite(F_DOWN,LOW);
      }else if (strstr((char *)buf, "F DOWN OFF")) {
        digitalWrite(F_DOWN,HIGH);
      }else if (strstr((char *)buf, "SPEED 0")) {
        digitalWrite(C_1,HIGH);
        digitalWrite(C_2,HIGH);
        digitalWrite(C_3,HIGH);
      }else if (strstr((char *)buf, "SPEED 1")) {
        digitalWrite(C_1,LOW);
        digitalWrite(C_2,HIGH);
        digitalWrite(C_3,HIGH);
      }else if (strstr((char *)buf, "SPEED 2")) {
        digitalWrite(C_1,LOW);
        digitalWrite(C_2,LOW);
        digitalWrite(C_3,HIGH);
      }else if (strstr((char *)buf, "SPEED 3")) {
        digitalWrite(C_1,LOW);
        digitalWrite(C_2,HIGH);
        digitalWrite(C_3,LOW);
      }else if (strstr((char *)buf, "SPEED 4")) {
        digitalWrite(C_1,LOW);
        digitalWrite(C_2,LOW);
        digitalWrite(C_3,LOW);
      }
    }
  }
}

jackbarber
 
Posts: 1
Joined: Fri Jul 24, 2020 9:10 am

Re: Adafruit Feather 32u4 Freezing

by adafruit_support_mike on Sun Jul 26, 2020 3:43 am

Try adding a condition to your loop that does something like print a dot if the call to rf69.available() returns false. That will give you a little more information about what the code sees.

adafruit_support_mike
 
Posts: 61422
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.