Project car lights stage 2

Some off you read my post on wiring a relay to a nano some time back. Now I am back with phase two of my project which involves finer control over the car lights as well as bi-directional communication with an android app over BLE, and remote garage door opening using relays and radios.

In this phase I will connect a BlueBear BLE Arduino to an 8 relay block as well as a radio transmitter in a box which will sit under the hood of the car. From the cab, the box will be controller via an android app over BLE. The box will run the program that triggers the alert pattern on the high beams and fog lights to signal oncoming traffic. While doing so the relay will power down the daytime running lights so the effect is not lost due to them being on.

Since each light will be controlled independently, a start up pattern will be created when the vehicle is powered on. A horn pattern (beep beep beep) might also be incorporated into the program's logic.

Additionally, through the android app as well, the garage doors will open (left and right) through the transmitters and $5 nanos.

Attached is a diagram outlining the components in this application with some basic connectivity wirings explaining their relationship to one another.

Please enjoy.

I couldn't find the question in your post, so it's pretty hard to help.
What is the nature of the problem that you need help with?

OldSteve:
I couldn't find the question in your post, so it's pretty hard to help.
What is the nature of the problem that you need help with?

I didnt have a question but since you asked, I am running the transceivers on two nanos. The first nano sends a code to the second to turn on a pin and then that one in return replies whether the pin is on or off. That entire chat is one transaction. When I first power up the nanos everything works, then after a while of receiving codes and turning leds on and off it freezes - the led no longer comes on or goes off, just either stays on or off. The sender is still attempting to send codes to the receiver however, and if I reset the receiver the codes begin to flow and the light begins to toggle. Why is this?

I'm using a modified version of this: GitHub - liamjack/Arduino-NRF24L01-Thermometer: Sending the temperature via NRF24L01 between two Arduino Nanos.

Is this a known issue?

dhtmldude:
I didnt have a question

I only asked because this is the "Project Guidance" section, intended for asking questions or for guidance on a project, so I assumed that you must have had a question.
If you just wanted to highlight/show your project, the "Exhibition / Gallery" section might have been more appropriate.

but since you asked, I am running the transceivers on two nanos. The first nano sends a code to the second to turn on a pin and then that one in return replies whether the pin is on or off. That entire chat is one transaction. When I first power up the nanos everything works, then after a while of receiving codes and turning leds on and off it freezes - the led no longer comes on or goes off, just either stays on or off. The sender is still attempting to send codes to the receiver however, and if I reset the receiver the codes begin to flow and the light begins to toggle. Why is this?
I'm using a modified version of this: GitHub - liamjack/Arduino-NRF24L01-Thermometer: Sending the temperature via NRF24L01 between two Arduino Nanos.
Is this a known issue?

I've never used those transceivers, but perhaps posting your code would help. (Between code tags, of course.)

Thanks will do. I didn't realize i hadn't posted a question. Originally I just wanted to highlight my project diagram.

OldSteve:
I've never used those transceivers, but perhaps posting your code would help. (Between code tags, of course.)

Here is the code in the receiver, the one that stops blinking.

/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.

Hack.lenotta.com
Modified code of Getting Started RF24 Library
It will switch a relay on if receive a message with text 1, 
turn it off otherwise.
Edo
*/

#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"

int deviceNumber = 1;
int relay = 8;

//
// Hardware conf
//

// Set up nRF24L01 radio on SPI bus plus pins 9 & 10 
RF24 radio(9,10);

//
// Topology
//

// Radio pipe addresses for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };


char * convertNumberIntoArray(unsigned short number, unsigned short length) {
    char * arr = (char *) malloc(length * sizeof(char)), * curr = arr;
    
    do {
        *curr++ = number % 10;
      number /= 10;
    } while (number != 0);
    
    return arr;
}

unsigned short getId(char * rawMessage, unsigned short length){
    unsigned short i = 0;
    unsigned short id = 0;
    for( i=1; i< length; i++){
        id += rawMessage[i]*pow( 10, i-1 );
    }
    return id;
}
unsigned short getMessage( char * rawMessage){
    unsigned short message = rawMessage[0];
    return (unsigned short)message;
}
unsigned short getLength( unsigned int rudeMessage){
    unsigned short length = (unsigned short)(log10((float)rudeMessage)) + 1;
    return length;
}

/*
class Message
{
    private:
      int deviceId = 0;
      int state = 0;
      int pin = 0;

    public:
      //AMLed(uint8_t pin);
      void setDeviceId(int deviceId);
      void setState(int state);
      void setPin(int pin);
};

void Message::setDeviceId(int deviceId)
{
  this->deviceId = deviceId;
}
void Message::setState(int state)
{
  this->state = state;
}
void Message::setPin(int pin)
{
  this->pin = pin;
}

Message getMessage(char *  rawMessage){ 

  Message *m = new Message();

  int i = 0;
  char * pch;
  pch = strtok (rawMessage," ,.:-");
  while (pch != NULL)
  {
    if (i==0) m->setDeviceId(pch);
    if (i==1) m->setState(pch);
    if (i==2) m->setPin(pch);
    
    pch = strtok (NULL, " ,.:-");
    i++;
  }

  return *m;
  
}
*/

void setup(void)
{
  Serial.begin(57600);
  pinMode(relay, OUTPUT);
  digitalWrite(relay, LOW);
  printf_begin();
  printf("\nRemote Switch Arduino\n\r");

  radio.begin();
  //radio.setAutoAck(1);                    // Ensure autoACK is enabled
  radio.setRetries(15,15);

  radio.openWritingPipe(pipes[1]);
  radio.openReadingPipe(1,pipes[0]);
  radio.startListening();
  radio.printDetails();
}

int getState(unsigned short pin){
  boolean state = digitalRead(pin);
  return state == true ? 1 : 0;
}

void doAction(unsigned short id, unsigned short action){
    if( action == 1 ){
        digitalWrite(id, HIGH);
    }else{
        digitalWrite(id, LOW);
    }
}
void sendCallback(unsigned short callback){
  // First, stop listening so we can talk
  radio.stopListening();
  
  // Send the final one back.
  radio.write( &callback, sizeof(unsigned short) );
  printf("Sent response: %d.\n\r", &callback);
  
  // Now, resume listening so we catch the next packets.
  radio.startListening();
}

void performAction(unsigned short rawMessage){
  unsigned short action, id, length, callback;
  char * castedMessage;
  
  length = getLength(rawMessage);
  castedMessage = convertNumberIntoArray(rawMessage, length);
  action = getMessage(castedMessage);
  id = getId(castedMessage, length);

  if (action == 0 || action == 1){
      callback = action;
      doAction(id, action);
  }else if(action == 2){
      callback = getState(id);
  }
  
  sendCallback(callback);
}
void loop(void)
{
  // if there is data ready
  if ( radio.available() )
  {
    
    //Dump the payloads until we've gotten everything
    unsigned short message;
    unsigned short rawMessage; 
    bool done;
    done = false;
    
    while ( radio.availablehg4() )
    {
      //Fetch the payload, and see if this was the last one.
      radio.read( &rawMessage, sizeof(unsigned long) );
      
      //Spew it
      printf("Got message %d...", rawMessage); 
      performAction(rawMessage);
      delay(10);
    }
  }
}

saw this in the serial monitor when it stopped working properly. it was scrolling by real fast. had to stop autoscroll.

The junk in the attachment is what happens when the problem occurs. The light still turns on and off but this junk fills the console (serial monitor) very fast, over and over the same junk.

 if ( radio.available() )
  {
}

if radio.available() could be the culprit, signaling that there is data to process. Then is it the receiver or the sender?

junk.png

dhtmldude:
if radio.available() could be the culprit, signaling that there is data to process. Then is it the receiver or the sender?

As mentioned, I haven't used the nRF24L01 modules yet, although I have some on the way, so I'm not really qualified to help with this. I've been sitting back hoping that someone who has experience would have some suggestions.