Not responding to software

Using an Arduino Pro Mini ---
I have a 4 position dip switch to set the node ID. It is connected to pins 4, 5, 6, and 7.
4PosDIPSwitch

Here is the Code:

// numeric switch pins
pinMode (7, INPUT_PULLUP); // +1
pinMode (6, INPUT_PULLUP); // +2
pinMode (5, INPUT_PULLUP); // +4
pinMode (4, INPUT_PULLUP); // +8

// Set the node ID
if (digitalRead (7) == LOW) {thisNodeID = thisNodeID +1;}
if (digitalRead (6) == LOW) {thisNodeID = thisNodeID +2;}
if (digitalRead (5) == LOW) {thisNodeID = thisNodeID +4;}
if (digitalRead (4) == LOW) {thisNodeID = thisNodeID +8;}

While this code is working on other minis, It will not work on one.

What might I look for?

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Please post your full sketch and schematic of the project. A 'photo of a pencil and paper drawing is good enough

Looks plausible. But without all the code and a description of how it isn't working for you, it is hard to help.

Do you, for example, ever set thisNodeID to zero?

Post the code. Describe the behaviour and what it is doing that it shouldn't, or not doing what it should.

a7

Bad wiring on the one that doesn't work. A short between two pins could do it.

Thanks. Just looking for ballpark guesses right now.

Yes, just doing it on one. Others running same code are ok. If I hard set the node ID like:

thisNodeID = 6;

It runs just fine.

I'll keep hunting for the moment.

Good thought. Thanks. Yes, I am setting the node ID to zero.

We would have known that if you had posted your whole sketch


#include <RFM69.h>
//#include <SPI.h>
#include <LowPower.h>

// RFM69 frequency, uncomment the frequency of your module:
//#define FREQUENCY   RF69_433MHZ
#define FREQUENCY     RF69_915MHZ

// AES encryption (or not):
#define ENCRYPT       true // Set to "true" to use encryption
//#define ENCRYPT       false // Set to "true" to use encryption
#define ENCRYPTKEY    "MYPASSWORDXXXXXX" // Use the same 16-byte key on all nodes

// Use ACKnowledge when sending messages (or not):
#define USEACK        true // Request ACKs or not

//#define ILED          true
//#define SERIAL        true
//#define RESET         true

// Create a library object for our RFM69HCW module:
RFM69 radio;

//----------------------------------------------------------------
const byte interruptPin = 3;

// Addresses for this node. CHANGE THESE FOR EACH NODE!
int networkID = 144;  // Must be the same for all nodes
int thisNodeID = 0;  // This node ID - Set in setup
int toNodeID = 250;  // Destination node ID

byte ledPin = 9;

// 'X' is replaced in setup with node number
char switchStateOPEN[] = "144-X-SO";
char switchStateCLOSED[] = "144-X-SC";

char thisNodeChar[] = "0123456789ABCDE"; 

volatile bool interruptReceived = false;

byte sensorMode = LOW;


void setup ()
{
  pinMode (interruptPin, INPUT_PULLUP);
  attachInterrupt (digitalPinToInterrupt(interruptPin), handleInterrupt, CHANGE );  
  
  pinMode (ledPin, OUTPUT);  

  if (digitalRead(interruptPin) == LOW)
  {
    digitalWrite (ledPin, LOW);
  }
  else
  {
    digitalWrite (ledPin, HIGH);
  }

  // numeric switch pins
  pinMode (7, INPUT_PULLUP);  // +1
  pinMode (6, INPUT_PULLUP);  // +2
  pinMode (5, INPUT_PULLUP);  // +4
  pinMode (4, INPUT_PULLUP);  // +8

  //  Set the node ID
  if (digitalRead (7) == LOW) {thisNodeID = thisNodeID +1;}
  if (digitalRead (6) == LOW) {thisNodeID = thisNodeID +2;}
  if (digitalRead (5) == LOW) {thisNodeID = thisNodeID +4;}
  if (digitalRead (4) == LOW) {thisNodeID = thisNodeID +8;}
  
  switchStateOPEN[4] = thisNodeChar[thisNodeID];
  switchStateCLOSED[4] = thisNodeChar[thisNodeID];

  // Switch Mode Pin
  pinMode (8, INPUT_PULLUP);
  if (digitalRead (8) == LOW)
  {
    // swap sensor action
     sensorMode = HIGH;
  }
    
  // Initialize the RFM69HCW:
  radio.initialize(FREQUENCY, thisNodeID, networkID);
  //radio.initialize(FREQUENCY, myNodeID, NETWORKID);
  radio.setHighPower(); // Always use this for RFM69HCW
  // Turn on encryption if desired:
  if (ENCRYPT) radio.encrypt(ENCRYPTKEY);

}  //End setup()


void loop ()
{
  if (interruptReceived == true)
  {
    sendSwitchState();
    interruptReceived == false;
  }

  // start added code for bug
  delay (1000);

  if (interruptReceived == true)
  {
    sendSwitchState();
    interruptReceived == false;
  }
  // end added code
  
  radio.sleep();  
  //LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  // do nothing
}

void handleInterrupt ()
{
  interruptReceived = true;
}

void sendSwitchState()
{
  if (digitalRead(interruptPin) == sensorMode)
  //if (digitalRead(interruptPin) == LOW)
  {
    // Switch Closed
    digitalWrite(ledPin,LOW);
    if (radio.sendWithRetry(toNodeID, switchStateCLOSED, strlen(switchStateCLOSED)+1))    
    {  }  // ACK received!          
    else
    {  }  // No ACK received          
  }
  else
  {
    // Switch Open
    digitalWrite(ledPin,HIGH);
    if (radio.sendWithRetry(toNodeID, switchStateOPEN, strlen(switchStateOPEN)+1))
    {  }  // ACK received!        
    else
    {  }  // No ACK received        
  }  
}  // End void sendSwitchState()type or paste code here
  interruptReceived == false;

Whoops !

Wouldn't this pretty much give the answer? If it works on other controllers, but this one, that seems to lead to a hardware failure, and lead away from a code problem. I'd have a go at troubleshooting/testing each pin in both input and output modes to determine where the issue lies.

Thanks.

Yes. I suspect a hardware failure too. It is a brand new board.
I will be doing the testing you suggest.
Thanks.

Indeed.

@jack0987 are you saying the faulty code you posted works on some other hardware?

a7

Yes. On four other nodes and two additional ones not deployed yet.

I am surprised the compiler did not pick up on that.

Working on other things right now and will not get back to this problem for a couple of days, but will definitely fix my code error.

It's not an error. Welcome to C/C++, all you need to shoot yourself in the foot while it watches.

But not necessarily silently:

Go to the Preferences panel in the IDE and adjust the compilers settings so it will provide warnings about questionable code - legal but perhaps not what you want.

Then read all the warnings and make a goal of compiling without getting any. Warnings.

a7

Did you fix it ?

Working Now.

After testing, pins 4-7 were not being pulled down when the DIP switches were set on.
The most likely fault for this is a bad ground and that appears to be the problem.
I resoldered all the ground connections and as an added measure connected all the
circuit grounds together.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.