Go Down

Topic: RF24 nRF24L01 Serial Chat example (Read 32227 times) previous topic - next topic

debkalpa

Hi Stanley,

Thanks a lot for the code.
I got this code running on two NRF24L01+ 's on Arduino Uno's; and it worked like a charm.
However, now I would like to run these using ATtiny84's, and just cannot get the code to compile. (serial was not declared in this scope).

What am I missing here?

Thanks!

HuCG1804

Hi. Im new in all this stuff so Im having problems with your sketch, when I verify the code I got an error:
"fatal error: printf.h: No such file or directory
compilation terminated."

So, it seems I need a printf.h library? If thats the case I cant find anything but information about being obsolete, so I need to use something different, the answer is what?

Thanks.

Whandall

printf.h
Code: [Select]
/*
 Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>

 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.
 */
 /*  Galileo support from spaniakos <spaniakos@gmail.com> */

/**
 * @file printf.h
 *
 * Setup necessary to direct stdout to the Arduino Serial library, which
 * enables 'printf'
 */

#ifndef __PRINTF_H__
#define __PRINTF_H__

#if defined (ARDUINO) && !defined (__arm__) && !defined(__ARDUINO_X86__)

int serial_putc( char c, FILE * )
{
  Serial.write( c );

  return c;
}

void printf_begin(void)
{
  fdevopen( &serial_putc, 0 );
}

#elif defined (__arm__)

void printf_begin(void){}

#elif defined(__ARDUINO_X86__)
int serial_putc( char c, FILE * )
{
  Serial.write( c );

  return c;
}

void printf_begin(void)
{
  //JESUS - For reddirect stdout to /dev/ttyGS0 (Serial Monitor port)
  stdout = freopen("/dev/ttyGS0","w",stdout);
  delay(500);
  printf("redirecting to Serial...");
 
  //JESUS -----------------------------------------------------------
}
#else
#error This example is only for use on Arduino.
#endif // ARDUINO

#endif // __PRINTF_H__
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

vagulus

Stanley

I just copied and pasted your sketch from the original post  On compiling I get these errors
Code: [Select]
D:\Arduino\serialChat\serialChat.ino: In function 'void nRF_receive()':

serialChat:111: error: void value not ignored as it ought to be

         done = radio.read(&RecvPayload,len);

              ^

D:\Arduino\serialChat\serialChat.ino: In function 'void serial_receive()':

D:\Arduino\serialChat\serialChat.ino:137:14: warning: unused variable 'ok' [-Wunused-variable]

         bool ok = radio.write(&SendPayload,strlen(SendPayload));

              ^


I can see what the second one (ok) is about but I can make neither head nor tail of the first one (done).
I am using Arduino 1.6.13 which may make a difference.

However, I am reluctant to start fiddling with the code if there's a simple answer (which you might see being the author).  Can you suggest the solutions?

BTW: there is some really clever programming in this.  Thanks
"Answers are easy;
               it's asking the right questions
                                                      which is hard."
 The Doctor (Dr Who: The Face of Evil (1977))

darjiaus7

I found out, that I am getting ACK from nowhere. I turned off RPI3 and I still getting ACK messages. I have line
if (radio.available()) {

}
So I am having available data from somewhere?

So how I am getting ACK messages from nowhere? Maybe Aliens wants to contact with me? :D

SuperFatUnicorn

I tried the code shown here and on your github page, I even used 1.6, as it was the latest released build by 2015. I'm wondering if the reason it doesn't work is that I'm using an arduino leonardo. Could that be the case? And if so, how could I rewrite the code to use it on the arduino leonardo?

Robin2

Two or three hours spent thinking and reading documentation solves most programming problems.

haamidrezzaa

hi

when i was try  to  cmpil your cod (serial chat )  i take this err (void value not ignored as it ought to be)



at this line  (&&&)


void nRF_receive(void) {
 int len = 0;
 if ( radio.available() ) {
     bool done = false;
     while ( !done ) {
       len = radio.getDynamicPayloadSize();
       done = radio.read(&RecvPayload,len);..................>>>&&&
       delay(5);
     }


some help plz

Robin2

when i was try  to  cmpil your cod (serial chat )  i take this err (void value not ignored as it ought to be)
Post the complete programs that YOU have uploaded to your Arduinos.

Are you using the ManiacBug or the newer TMRh20 version of the RF24 library?

Have you tried the examples in my tutorial?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

zencakd

It works perfectly on my end but ok status always returns false even if the message is sent. How is that possible? It really bothers me because I need to test if the message was really sent. Thank you!

Code: [Select]


        bool ok = radio.write(&SendPayload,strlen(SendPayload));
   


zencakd

To everybody that has a compilation error, use this instead:


Code: [Select]

while (radio.available()) {
        len = radio.getDynamicPayloadSize();
        radio.read(&RecvPayload,len);
        delay(5);
      }




Robin2

It works perfectly on my end but ok status always returns false even if the message is sent.
How do you know it is working perfectly?

You need to post the two programs that are talking to each other.

Have a look at the examples in this Simple nRF24L01+ Tutorial

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Robin2

To everybody that has a compilation error, use this instead:
Code: [Select]

while (radio.available()) {
        len = radio.getDynamicPayloadSize();
        radio.read(&RecvPayload,len);
        delay(5);
      }

What compilation error did you have that was solved with your code snippet? And what was the code that was causing the error?

There is no need to use while (radio.available()) with an nRF24 because if any of the message is available all of it will be available. It is not like Serial.read() where each character arrives one by one.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

zencakd

How do you know it is working perfectly?

You need to post the two programs that are talking to each other.
This part of code returns false:

Code: [Select]
bool ok = radio.write(&SendPayload,strlen(SendPayload));

But I always receive a message on other device correctly (I am sending current temperate from the probe and I see correct updated temp on receiver's display). Any idea?


zencakd

hi

when i was try  to  cmpil your cod (serial chat )  i take this err (void value not ignored as it ought to be)



at this line  (&&&)


void nRF_receive(void) {
 int len = 0;
 if ( radio.available() ) {
     bool done = false;
     while ( !done ) {
       len = radio.getDynamicPayloadSize();
       done = radio.read(&RecvPayload,len);..................>>>&&&
       delay(5);
     }


some help plz
I responded to error people are experiencing with the original code. Radio.read returns void. So, compiler issues the error here. The solution is to easy only to call radio.read(&RecvPayload,len);.

Go Up