code enhancement

I’m trying send measured resistance values through nRF24L01. Using ADA4522-2 need only one channel. Any suggestions highly appreciated.

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

RF24 radio(9, 8); // CE, CSN

const byte rxAddr[6] = "00001";

#define NUM_CHANNELS  1

typedef struct {
  long int td;               //4 bytes
  int data[ NUM_CHANNELS ];  //2 x 6 = 12 bytes
} 
SRF24_Data;
SRF24_Data  RData;
SRF24_Data* pSRData = &RData;



void setup()
{
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();
}

void loop()
{
  
//  radio.write(&text, sizeof(text));
pSRData->td = millis();
pSRData->data[0]=analogRead(A0);
pSRData->data[1]=analogRead(A1);
pSRData->data[2]=analogRead(A2);
pSRData->data[3]=analogRead(A3);
pSRData->data[4]=analogRead(A4);
pSRData->data[5]=analogRead(A5);
pSRData->data[6]=analogRead(A6);
pSRData->data[7]=analogRead(A7);

  //long int t = millis();
  radio.write(pSRData, sizeof(SRF24_Data));
  delay(100);
}

Check your NUM_CHANNELS, you're overwriting memory.

ADA4522-2 supports maximum two channels.

Hemanth03:
ADA4522-2 supports maximum two channels.

Yes so:-

Check your NUM_CHANNELS,

in what way does "data[ 7 ]" fit with

int data[ NUM_CHANNELS ];

or to put it another way

int data[ 1 ];

In addition to the above comments about the size of your array have a look at this Simple nRF24L01+ Tutorial.

...R

I got it I had overwritten the number of channels…I have changed the code. I’m not sure to what extent its correct. What i want it to do is read the values and transmit it to the receiver. And display on the serial monitor…

// The modified code (transmitter)…//

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

const int SensorPin = A0;//Analog Input pin that senses vout
int SensorValue = 0;//sensorpn default value
float Vin = 5;//input vloltage 
float Vout = 0;//Vout default value
float Rref = 18000;//reference resistors value in ohms
float R = 0;//tested resistor's default value 

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

#define NUM_CHANNELS 1
typedef struct
{
  //long int td;
  int data [ NUM_CHANNELS ];
}
SRF24_Data;
SRF24_Data RData;
SRF424_Data*pSRData = &RData;

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();
}

void loop()
{
  SensorValue = analogRead(SensorPin);//read vout on analog Input pin A0(arduino can sense from 0-1023, 1023 is 5v)
  
Vout = (Vin* SensorValue)/1023; //convert Vout to volts
  R = Rref* (1/((Vin/Vout)-1));//formula to calculate tested resistors value//
  Serial.print("\nR: ");
  Serial.print(R);
  
  
    const char text[] = "R ";
  //const char text[1] = "HEYMANN";
  radio.write(&text, sizeof(text));

  
  //long int t = millis();
  radio.write(pSRData, sizeof(SRF24_Data));
  
  delay(1000);
}

//I'm getting the following error//

[[
Arduino: 1.8.6 (Windows 10), TD: 1.43, Board: "Arduino/Genuino Uno"

sketch_sep28tr:24:1: error: 'SRF424_Data' does not name a type

 SRF424_Data*pSRData = &RData;

 ^

C:\Users\Hemanth Kumar\Desktop\Project\examples\sketch_sep28tr\sketch_sep28tr.ino: In function 'void loop()':

sketch_sep28tr:51:15: error: 'pSRData' was not declared in this scope

   radio.write(pSRData, sizeof(SRF24_Data));

               ^

Multiple libraries were found for "nRF24L01.h"
 Used: C:\Users\Hemanth Kumar\Documents\Arduino\libraries\RF24-master
 Not used: C:\Users\Hemanth Kumar\Documents\Arduino\libraries\RF24
 Not used: C:\Users\Hemanth Kumar\Documents\Arduino\libraries\RF24
 Not used: C:\Users\Hemanth Kumar\Documents\Arduino\libraries\RF24
 Not used: C:\Users\Hemanth Kumar\Documents\Arduino\libraries\RF24
exit status 1
'SRF424_Data' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
]]

Hemanth03:
Any suggestions highly appreciated.

Is that a real circuit, your are really using two AA Duracells to power a Teensy ?

Hemanth03:
I got it I had overwritten the number of channels..I have changed the code. I'm not sure to what extent its correct. What i want it to do is read the values and transmit it to the receiver. And display on the serial monitor..

What program is that paired with? It is pointless considering one wireless program on its own.

What happens when you run the program?

Have you been successful in getting any communication between the nRF24s?

...R

srnet:
Is that a real circuit, your are really using two AA Duracells to power a Teensy ?

I'm planning to use teensy for both(tx, rx), but as of now i'm using uno for transmitter part and teensy for receiver part. I'll not be using exact same cells instead a 5v power supply that is to power up my analog front end(AFE), which consists of voltage divider and opamp(ADA4522-2).

Robin2:
What program is that paired with? It is pointless considering one wireless program on its own.

What happens when you run the program?

Have you been successful in getting any communication between the nRF24s?

...R

It is paired with a receiver program. which displays resistance values in serial monitor.

I'm getting the error posted above.

I have tried for a simple communication code to check the nRF modules and its working. Now trying to send resistance values.

Hemanth03:
I'm planning to use teensy for both(tx, rx), but as of now i'm using uno for transmitter part and teensy for receiver part. I'll not be using exact same cells instead a 5v power supply that is to power up my analog front end(AFE), which consists of voltage divider and opamp(ADA4522-2).

So its not a real depiction of how you have everything connected up ?

srnet:
So its not a real depiction of how you have everything connected up ?

It is same except for the power supply and the microcontroller. I’ll change the microcontroller once I get it that wont be a problem. I wasn’t getting the exact power supply component in fritzing while perparing the circuit hence that battery cells.

I wasn't getting the exact power supply component in fritzing

That is one of the reasons we hate fritzing here. There are ways of drawing your own symbols but this is beyond the skill of the people who this hateful package is aimed at.

Hemanth03:
It is paired with a receiver program. which displays resistance values in serial monitor.

I sort-of guessed that.

I had hoped you would take the hint and post the receiver program.

…R

Robin2:
I sort-of guessed that.

I had hoped you would take the hint and post the receiver program.

…R

// The receiver code//

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

RF24 radio(8, 7);

const byte rxAddr[6] = “00001”;

void setup()
{
while (!Serial);
Serial.begin(9600);

radio.begin();
radio.openReadingPipe(0, rxAddr);

radio.startListening();
}

void loop()
{
if (radio.available())
{
char text[32] = {0};
radio.read(&text, sizeof(text));

Serial.println(text);
}
}

Hemanth03:
It is same except for the power supply and the microcontroller.

How the parts are actually connected up is important, so if you dont use a schematic drawing program, just draw the actual real circuit on paper and take a picture.

And if your not posting the real circuit, at least tell people.

Not in relation to the circuit diagram I have mentioned in the earlier.

Now I’m just trying to measure an unknown resistor with a simple voltage divider and communicating between two nRF24L01. I’m receiving some junk value…

//Transmitter CODE//

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

const int SensorPin = A0;//Analog Input pin that senses vout
int SensorValue = 0;//sensorpn default value
float Vin = 5;//input vloltage 
float Vout = 0;//Vout default value
float Rref = 1800;//reference resistors value in ohms
float R = 0;//tested resistor's default value 

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

#define NUM_CHANNELS 1
typedef struct
{
  long int td;
  int data [ NUM_CHANNELS ];
}
SRF24_Data;
SRF24_Data RData;
SRF24_Data *pSRData = &RData;

void setup()
{
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.openWritingPipe(rxAddr);
  
  radio.stopListening();
}

void loop()
{
  SensorValue = analogRead(SensorPin);//read vout on analog Input pin A0(arduino can sense from 0-1023, 1023 is 5v)
  Vout = (Vin* SensorValue)/1023; //convert Vout to volts
  R = Rref* (1/((Vin/Vout)-1));//formula to calculate tested resistors value//
  Serial.print("\nR: ");
  Serial.print(R);
  
  
   const char text[] = "0";
  //const char text[] = "HEMANTH";
  radio.write(&text, sizeof(text));

  
  //long int t = millis();
  radio.write(pSRData, sizeof(SRF24_Data));
  
  delay(1000);
}
[CODE]

//Receive code//

[CODE]
 #include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(7, 8);

const byte rxAddr[6] = "00001";

void setup()
{
  while (!Serial);
  Serial.begin(9600);
  
  radio.begin();
  radio.openReadingPipe(0, rxAddr);
  
  radio.startListening();
}

void loop()
{
  if (radio.available())
  {
    char text[] = {0};
    radio.read(&text, sizeof(text));
    
    Serial.println(text);
  }
}
[CODE]

[/code]
[/code]

I'm not familiar with the library, but int data and float resistance do not fit together.

Hemanth03:
// The receiver code//

The receiver program should use an identical struct to the transmitting program. That’s why you should ALWAYS post both programs.

And please use the code button </> when posting code.

Have you tried any of the examples in my Tutorial - don’t try to move forward until you get one of them working.

…R