Setup constantly loops?


so have problems setup keeps running every time, have uploaded picture of both. before setup kecpt looping meaning didnt run loop b4. atm serial monitor of reciever stuck...what problem guys?

the mega have: link

uno have: link


transmitter code: no strange problem
code: [select]
#include <spi.h>                        //listing libraries needed communicate other arduino
#include <rf24.h>
#include <nrf24l01.h>
#include <printf.h>
#include <rf24_config.h>

#define lstick_x    a0          //left joystik, x axis             
#define rstick_y    a2          //right joystick y axis
                     
#define ce_pin      9
#define csn_pin     53
rf24 radio(ce_pin, csn_pin);
const uint64_t pipe = 0xe8e8f0f0e1ll;    //communication pipe madeup address
   
struct positiondata             //make sturcture package b sent reciever
{                                 
  byte laxis_x;
  byte raxis_y;         
};positiondata data;                                   

void setup()
{
  serial.begin(9600);
  serial.println("starting setup");
  radio.begin();                            //link 2 radios, set speed , set if gana b set reading or writing arduino
  radio.setpalevel(rf24_pa_max);               
  radio.setdatarate(rf24_250kbps);             
  radio.openwritingpipe(pipe);             
}
void loop()
{
  int laxis_x = analogread(lstick_x); 
  int raxis_y = analogread(rstick_y);
  data.laxis_x = map(laxis_x,0,1023,0,180);             //remap servo positions , ready b sent out
  data.raxis_y = map(raxis_y,0,1023,0,180);                           
  serial.print("lxaxis: ");              serial.print(data.laxis_x);
  serial.print("    ryaxis: ");          serial.println(data.raxis_y);
  radio.write( &data, sizeof(unsigned long) );         //send reciever
}




 





reciever code: (this 1 have strange problem
code: [select]
//reciever
#include <spi.h>
#include <rf24.h>
#include <nrf24l01.h>
#include <printf.h>
#include <rf24_config.h>

#define ce_pin   7
#define csn_pin  8
rf24 radio(ce_pin, csn_pin); 
const uint64_t pipe = 0xe8e8f0f0e1ll;       

struct positiondata{                       
  byte laxis_x;
  byte raxis_y;       
};positiondata data;

void setup(){           
  serial.begin(115200);
  serial.println("starting setup");                 //it keeps running this
  radio.begin();                                    //link radio
  radio.setpalevel(rf24_pa_max);
  radio.setdatarate(rf24_250kbps);
  radio.openreadingpipe(1,pipe);           
  radio.startlistening();               
}


void loop() {
  serial.println("starting loop");
  if ( radio.available() )
  {                                   
    radio.read( &data, sizeof(unsigned long) );             
    float right_y = data.raxis_y;
    float left_x = data.laxis_x;
    serial.print("    leftservo: ");
    serial.print(left_x);        //will in servo value, need change since, out motor 97 102 neutral
    serial.print("    rightservo: ");
    serial.print(right_y);        //will in servo value, need change since, out motor 97 102 neutral           
  }
  else{serial.print("no data"); }




see if stops problem:
added spam timer serial.print() crash uno if called quickly

code: [select]
//reciever
#include <spi.h>
#include <rf24.h>
#include <nrf24l01.h>
#include <printf.h>
#include <rf24_config.h>

#define ce_pin   7
#define csn_pin  8
rf24 radio(ce_pin, csn_pin);  
const uint64_t pipe = 0xe8e8f0f0e1ll;      

struct positiondata {
                         
   byte laxis_x;
   byte raxis_y;        
}; positiondata data;

void setup() {
           
   serial.begin(115200);
   serial.println("starting setup");                 //it keeps running this
   radio.begin();                                    //link radio
   radio.setpalevel(rf24_pa_max);
   radio.setdatarate(rf24_250kbps);
   radio.openreadingpipe(1, pipe);            
   radio.startlistening();                
}


void loop() {
  static unsigned long spamtimer;
  if ( (unsigned long)(millis() - spamtimer) >= (100)) {
    spamtimer = millis();

     serial.println("starting loop");
     if ( radio.available() )
        {                                    
              radio.read( &data, sizeof(unsigned long) );              
              float right_y = data.raxis_y;
              float left_x = data.laxis_x;
              serial.print("    leftservo: ");
              serial.print(left_x);        //will in servo value, need change since, out motor 97 102 neutral
              serial.print("    rightservo: ");
              serial.print(right_y);        //will in servo value, need change since, out motor 97 102 neutral          
            
         }
       else {
        serial.print("no data");
      }
  }


Arduino Forum > Using Arduino > Programming Questions > Setup constantly loops?


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor