Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: RF24 Library Multi Node Communication Problem on: March 30, 2013, 03:37:30 pm
Using RF24Network library would require Atmega16 at least. So using RF24 alone.

Could there be a synchronization problem?
If so how can I solve it?
2  Using Arduino / Networking, Protocols, and Devices / Re: RF24 Library Multi Node Communication Problem on: March 28, 2013, 10:55:14 am
Could somebody please help me with this problem?

I even tried ACK payload option to no advantage.
Tried including delay but still no use.

P.S: Please comment if this is the wrong section to post this question. I felt it is the appropriate section.
3  Using Arduino / Networking, Protocols, and Devices / RF24 Library Multi Node Communication Problem on: March 24, 2013, 11:52:27 am
Hello

I am trying to send and receive the data to/from two different nodes to/from the central MCU. The procedure that I am using is as follows:

The central node writes the control information to the panel1, in return panel1 sends the ADC values read and status values to the central node. Then it does the same with panel2.

The code I am using on the central node is

Code:
#include<SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"

RF24 radio(9,10);


const uint64_t w_pipe[2] = { 0xA0A0A0A0BBLL, 0xA0A0A0A0CCLL };                         
const uint64_t r_pipe[2] = { 0xF0F0F0A077LL, 0xF0F0F0A055LL };


struct PICO
{
  int power1, power2;
  boolean sh1,sh2,sh3,sh4,ma;
};


struct POCI
{
  int power1,power2;
  boolean ss1,ss2,ss3,ss4,ma;
 
};

byte sz=sizeof(POCI);


  PICO c1,c2;
  POCI p1,p2;

void setup()
{
 

  pinMode(8,OUTPUT);
  //digitalWrite(8,HIGH);
  Serial.begin(9600);
  Serial.println("\n This is the Central Node \n");
 
 
  Serial.flush();
 
  //Setting up the nRF24L01 chip
  radio.begin();
 
  radio.setRetries(15,15);
 
  radio.setPayloadSize(sz);
 
 
  c1.power1=1000;c1.power2=500;c1.sh1=HIGH;c1.sh2=HIGH;c1.sh3=HIGH;c1.sh4=LOW;
  c2.power1=1000;c2.power2=500;c2.sh1=HIGH;c2.sh2=LOW;c2.sh3=HIGH;c2.sh4=HIGH;
 
 
}

void loop()
{
   
 
  //open the pipe to write to Panel1 controller
  radio.openWritingPipe(w_pipe[0]);
 

  radio.write(&c1,sz);
 
  radio.openReadingPipe(1,r_pipe[0]);
 
  //Finish writing and start listening for the reply 
 
  radio.startListening();
 
  //wait for reply, i.e data to be available
  while(!radio.available());
  digitalWrite(8,HIGH);

  radio.read(&p1,sz);
 
  radio.stopListening();
  //digitalWrite(8,LOW);

  //delay(500);
  radio.openWritingPipe(w_pipe[1]);
 
 
  radio.write(&c2,sz);
 
  radio.openReadingPipe(2,r_pipe[1]);
 
  //Finish writing and start listening for the reply
  radio.startListening();
 
  //wait for reply, i.e data to be available
  while(!radio.available());
 

  radio.read(&p2,sz);
 
  //stop listening to any replies
  radio.stopListening();
  //digitalWrite(8,HIGH);

  Serial.print("Panel 1 " );
  Serial.print("P1 ");
  serial_withz(p1.power1);
  Serial.print(" P2 ");
  serial_withz(p1.power2 );
  Serial.print(" ");
  Serial.print(p1.ss1);
  //Serial.print("\t");
  Serial.print(p1.ss2);
  //Serial.print("\t");
  Serial.print(p1.ss3);
  //Serial.print("\t");
  Serial.print(p1.ss4);
  Serial.print("\n");
  Serial.print(" Panel 2=" );
  Serial.print("P1 ");
  serial_withz(p2.power1);
  Serial.print(" P2 ");
  serial_withz(p2.power2 );
  Serial.print(" ");
  Serial.print(p2.ss1);
  //Serial.print("\t");
  Serial.print(p2.ss2);
  //Serial.print("\t");
  Serial.print(p2.ss3);
  //Serial.print("\t");
  Serial.print(p2.ss4);
  digitalWrite(8,LOW);
  delay(100);
}

The code for panel1

Code:
#include<SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"

RF24 radio(9,10);


const uint64_t w_pipe[2] = { 0xA0A0A0A0BBLL, 0xA0A0A0A0CCLL };                         
const uint64_t r_pipe[2] = { 0xF0F0F0A077LL, 0xF0F0F0A055LL };


struct PICO
{
  int power1, power2;
  boolean sh1,sh2,sh3,sh4,ma;
};


struct POCI
{
  int power1,power2;
  boolean ss1,ss2,ss3,ss4,ma;
 
};

byte sz=sizeof(POCI);

PICO c1;
POCI p1;
int panelpower;
 
void setup()
{
 
 
 
  pinMode(2,OUTPUT);
  digitalWrite(2,LOW);
  //Serial.begin(9600);
  //Serial.println(" This is the  Panel1 \n");

 
  //Serial.flush();
 
 
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
 
 
  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);
  digitalWrite(8,LOW);
 
  //Setting up the nRF24L01 chip
  radio.begin();
 
  radio.setRetries(15,15);
 
  radio.setPayloadSize(sz);
 
  //Writing pipe 1 for central node is reading pipe for Panel 1
  radio.openReadingPipe(1,w_pipe[0]);
 
  //Open the Central node reading pipe 1 for the Panel 1 to write the data to central node
  radio.openWritingPipe(r_pipe[0]);

 
 
 
}

void loop()
{
 
 
 
  //Temporaryly reading analog values
  p1.power1=analogRead(A0);
  p1.power2=analogRead(A1);
 
  panelpower=p1.power1+p1.power2;
 
 
  p1.ss1=digitalRead(5);
  p1.ss2=digitalRead(6);
  p1.ss3=digitalRead(7);
  p1.ss4=digitalRead(8);
 
  //Start listening on the opened reading pipe for Central Node to send information
  radio.startListening();
  digitalWrite(2,HIGH);
  //Wait for the data to be available
  while(!radio.available());
 
  //Read the dat sent from Central Node into c1
  radio.read(&c1,sz);
 
  //Stop listening to get ready to write back to central node
  radio.stopListening();
 
  digitalWrite(2,LOW);
 
 
 
  //Write the data available with Panel 1 to Central Node
  radio.write(&p1,sz);
 
}

The code for panel2

Code:
#include<SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
//#include "printf.h"

RF24 radio(9,10);


const uint64_t w_pipe[2] = { 0xA0A0A0A0BBLL, 0xA0A0A0A0CCLL };                         
const uint64_t r_pipe[2] = { 0xF0F0F0A077LL, 0xF0F0F0A055LL };


struct PICO
{
  int power1, power2;
  boolean sh1,sh2,sh3,sh4,ma;
};


struct POCI
{
  int power1,power2;
  boolean ss1,ss2,ss3,ss4,ma;
 
};

  PICO c2;
  POCI p2;
  int panelpower;


 byte sz=sizeof(POCI);



void setup()
{
 
 
  //Serial.begin(9600);
  //Serial.println(" This is the Panel 2 \n");
 
 
  //Serial.flush();
  pinMode(2,OUTPUT);
  digitalWrite(2,HIGH);

  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
 

  digitalWrite(5,LOW);
  digitalWrite(6,LOW);
  digitalWrite(7,LOW);
  digitalWrite(8,LOW);
 
  //Setting up the nRF24L01 chip
  radio.begin();
 
  radio.setRetries(15,15);
 
  radio.setPayloadSize(sz);
 

}

void loop()
{
 
  //Writing pipe 2 for central node is reading pipe for Panel 2
  radio.openReadingPipe(2,w_pipe[1]);
 
  //Open the Central node reading pipe 1 for the Panel 1 to write the data to central node
  radio.openWritingPipe(r_pipe[1]);

 
 

  p2.power1=analogRead(A0);
  p2.power2=analogRead(A1);
 
  panelpower=p2.power1+p2.power2;
 

  p2.ss1=digitalRead(5);
  p2.ss2=digitalRead(6);
  p2.ss3=digitalRead(7);
  p2.ss4=digitalRead(8);
  digitalWrite(2,HIGH);
  //Start listening on the opened reading pipe for Central Node to send information
  radio.startListening();
 
  //Wait for the data to be available
  while(!radio.available());
 
  //Read the data sent from Central Node into c1
  radio.read(&c2,sz);
 
  //Stop listening to get ready to write back to central node
  radio.stopListening();

 
  //Write the data available with Panel 2 to Central Node
  radio.write(&p2,sz);
  digitalWrite(2,LOW);

 
}

The central node is an Arduino UNO clone, and the panels are Atmega8 based homemade Arduino boards.

Now coming to the problem

The code does not work the way I meant it to. When I use the same code on central node with the Panel1 or 2 related code disabled, it works. That is the code works for communication with single panel, when I add the second panel it doesn't work. It only prints "This is the Central Node" and stops working.
I think the homemade boards are fine as I tested all possible single(Central Node-Panel) combinations with all the home made boards and they worked individually.

I used the LED for debugging the found that it was hanging at
Code:
while(!radio.available());

What could be the problem?
4  Using Arduino / Programming Questions / Re: Serial Programming question on: December 08, 2012, 02:55:48 am
I will change that.
Are there any suggestions to reduce the jitter and errors through programming?
5  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 06:27:21 pm
Code:
        while(!Serial1.available());
Serial.available() is not a boolean function. Do not use it like one!
For now it is serving the purpose.
Could you suggest a better alternate instruction to make the arduino wait until the the byte of data is available.
6  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 06:23:20 pm
Now I am trying to read 4bytes of data coming from the ATMega32.
1-sync,2-t,3-h,4-f
 I inserted that while loop after every Serial1.read()
Code:
   if(Serial1.available()>0)
  {
    sync=Serial1.read();
    //delay(500);
   
    if(sync==0xAA)
    {
      Serial.print("Sensor reading \n");
      while(!Serial1.available())
      digitalWrite(13,HIGH);
      //if(Serial1.read()==B00011010) //Address 1=B00011010
      //{
        while(!Serial1.available());
        temp=Serial1.read();
        while(!Serial1.available());
        hu=Serial1.read();
        while(!Serial1.available());
        fcs=Serial1.read();
        digitalWrite(13,LOW);
        if((temp+hu)==fcs)
        {
          Serial.print("Temperature 1 \t");
          Serial.print(temp);
          Serial.print("Humidity 1 \t\n");
          Serial.print(hu);
        }
        else
        Serial.print("Sensor1 Error\n");
      //}
     }
   }

It is very slow(not main problem as the sensor updates the data once every second, but still the data received is lot slower and jitter is also high ) and the error rate is too high. Is there any programming improvement to reduce the errors and jitter(speed is secondary)
7  Using Arduino / Installation & Troubleshooting / Mega 2560 randomly hanging on: December 07, 2012, 04:37:07 pm
My Arduino Mega 2560 is randomly hanging while I try to upload. One the same program is uploaded without any glitches. Other times it just hangs. If I press the upload button again I am getting the error saying the the COM5 port is already in use. I either have to remove the USB and plug it in again(sometimes even this doesn't work I have to restart the PC). Then again it works fine .
8  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 04:22:34 pm

How about some debug prints?

Code:
if(Serial1.available())
  {
    sync=Serial1.read();
    if(sync==0x02)
    {
      ...
    }
    else
    {
      Serial.print("The byte I received was not a sync byte: ");
      Serial.println(sync);
    }
  }

It's also worth noting that Serial.available() doesn't return a boolean, it returns a number of bytes in the buffer. The proper way to write it is:

Code:
if (Serial.available() > 0)
I will remember those pointers next time. I was using LED on 13 for debugging. I will use debug prints next time.

For now this solved the problem
Code:
void setup()
{
  Serial.begin(9600);
  Serial1.begin(300);
}

void loop()
{
  int sync;
  char data,fcs;
  if(Serial1.available())
  {
    sync=Serial1.read();
    //Serial.print(sync);
    if(sync==0xAA)
    {
      while(!Serial1.available());
      data=Serial1.read();
      //fcs=Serial1.read();
      Serial.print(data);
     
    //if((data+fcs)==0)
    //{
     // Serial.print(data);
    //}
    }
   
  }
}

Thank you. I have been struggling with this problem for many hours now. Seeking help here got it solved in minutes

Now I will go on to test the RF receiver and transmitter module
9  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 04:12:45 pm
By looping until data is available.
Code:
  if(Serial1.available())
  {
    sync=Serial1.read();
    //Serial.print(sync);
    if(sync==0x02)
    {
      while(~Serial1.available());
      data=Serial1.read();
      //fcs=Serial1.read();
      Serial.print(data);
     
    //if((data+fcs)==0)
    //{
     // Serial.print(data);
    //}
    }
   
  }
doesn't solve the problem
10  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 04:03:41 pm


You seem to be under the impression that Serial communication is fast; It's not. The second

if(Serial1.available())

will happen eons before the next serial byte is received. You either need to make it blocking, implement a state machine with some sort of end of packet marker and a buffer to store all of the data, or check for more than one byte is available the first time.
So how do I make it wait till the byte after the sync byte arrives?
11  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 03:48:24 pm
yes I am aware. 0xaa is not ASCII 'a'. I tried all the possibilities of using 'a', 0xaa, other formats, on both the ends(atmega and arduino as sync bit).

Code:
  if(Serial1.available())
  {
    sync=Serial1.read();
    //Serial.print(sync);
    if(sync==0xaa)
    {
      if(Serial1.available())
      {
        data=Serial1.read();

I can't see how that code can ever work. As soon as a character is available, you check to see if it is the sync byte. If it is, you check immediately whether another character is available. It won't be, you are sending data at 300 baud so it will take around 33ms for the next character to arrive. You need to wait until each character is available. You'll also need some way of knowing when you have reached the end of the message, so you can go back to waiting for the sync byte.

I thought inserting 
if(Serial1.available()) before data=Serial1.read() would tell arduino to wait until the next byte is available.
12  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 03:29:32 pm
I used "\code" instead of "/code".
13  Using Arduino / Programming Questions / Re: Serial Programming question on: December 07, 2012, 03:25:26 pm
I corrected the format.I got the \ / confused. And that code is working(second part).
14  Using Arduino / Programming Questions / Serial Programming question on: December 07, 2012, 03:04:14 pm
Code:
[code][code]
void setup()
{
  Serial.begin(9600);
  Serial1.begin(300);
}

void loop()
{
  int sync;
  char data,fcs;
  if(Serial1.available())
  {
    sync=Serial1.read();
    //Serial.print(sync);
    if(sync==0xaa)
    {
      if(Serial1.available())
      {
      data=Serial1.read();
      //fcs=Serial1.read();
      Serial.print(data);
      }
    //if((data+fcs)==0)
    //{
     // Serial.print(data);
    //}
    }
   
  }
}

I am trying to establish communication between my ATMega32 and Arduino Mega. My atmega is outputting characters of this format "aAaBaCaD" and repeats it at BAUD 300. What I want my arduino to do, is read the incoming data on Serial1, if it is "a" than read the next byte ie."A" and then only it is printed through Serial port to the computer.
And I am using this code to achieve that


But the out put  "some 2 dots on y character" that is repeating on the serial monitor(gibberish).

So I used this code

Code:
void setup()
{
  Serial.begin(9600);
  Serial1.begin(300);
}
void loop()
{
  char i;
  if(Serial1.available())
  {
    i=Serial1.read();
    Serial.print(i);
    Serial.print("\n");
  }
}


 to test what is being output from the Atmega and I got the format
"a
A
a
B
a
C
a
D
a
A
.
.

What could be wrong with the first code?

P.S: I need the sync byte and fcs(not used, but intend to use ) as I plan to do use 315MHZ RF communication.[/code][/code]
Pages: [1]