Arduino Nano + loadcell + ADXL335

Hi, I have problem with my board:
Board 1: Arduino Nano + (loadcell + hx711) + ADXL335 + NRF24L01+ BLUETOOTH HC-05
Board 2: Arduino Nano + (loadcell + hx711) + ADXL335 + NRF24L01
My ideal is measure loadcell and acceleration on board 1 and send data to board 2, board 2 measure the same data then send data from 2 board to my laptop by bluetooth.
Here is my code, but my code have problem**, it can’t send data to each other **

#include "HX711.h"
#include <EEPROM.h>
#include <SPI.h>
#include "printf.h"
#include "RF24.h"

#define DOUT 3
#define CLK  2

const int xpin = A7;                  // x-axis of the accelerometer
const int ypin = A6;                  // y-axis
const int zpin = A5;                  // z-axis (only on 3-axis models)

HX711 scale;

RF24 radio(7, 6); // using pin 7 for the CE pin, and pin 8 for the CSN pin
uint8_t address[][6] = {"1Node", "2Node"};
bool radioNumber = 0; // 0 uses address[0] to transmit, 1 uses address[1] to transmit
bool role = false;  // true = TX role, false = RX role

//float calibration_factor = -7050; //-7050 worked for my 440lb max scale setup
//int peak = 0;
//int timeOut = 0;
float calibration_factor = 2230; // this calibration factor must be adjusted according to your load cell
int units;

int payload = 15;

bool master = true; // true - master-bluetooth, false - client

void setup() {
  Serial.begin(9600);
  Serial.println("HX711 calibration sketch");
  Serial.println("Remove all weight from scale");
  Serial.println("After readings begin, place known weight on scale");
  Serial.println("Press + or a to increase calibration factor");
  Serial.println("Press - or z to decrease calibration factor");
  
  scale.begin(DOUT, CLK);
  scale.set_scale();
  scale.tare(); //Reset the scale to 0
  
  long zero_factor = scale.read_average(); //Get a baseline reading
  Serial.print("Zero factor: "); //This can be used to remove the need to tare the scale. Useful in permanent scale projects.
  Serial.println(zero_factor);

  if (!radio.begin()) {
    Serial.println(F("radio hardware is not responding!!"));
    while (1) {} // hold in infinite loop
  }

  if (master){
     role = false;
  radioNumber = 1;
  
  }
 else {
     role = true;
  radioNumber = 0;

 }
  
  Serial.print(F("radioNumber = "));
  Serial.println((int)radioNumber);

  radio.setPALevel(RF24_PA_LOW);  // RF24_PA_MAX is default.
  radio.setPayloadSize(payload);

  // set the TX address of the RX node into the TX pipe
  radio.openWritingPipe(address[radioNumber]);     // always uses pipe 0

  // set the RX address of the TX node into a RX pipe
  radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1

  // additional setup specific to the node's role
  if (role) {
    radio.stopListening();  // put radio in TX mode
  } else {
    radio.startListening(); // put radio in RX mode
  }
}

void loop() {
  //Serial.print("Reading");
  units = scale.get_units(), 5;
  if (units < 0)
  {
    units = 0.00;
  }
  //Serial.print("Weight: ");
  //Serial.print(units);
  //Serial.print(" grams"); 
  //Serial.println();
  
  //Serial.print(analogRead(xpin));
  // print a tab between values:
  //Serial.print("\t");
  //Serial.print(analogRead(ypin));
  // print a tab between values:
  //Serial.print("\t");
  //Serial.print(analogRead(zpin));
  //Serial.println();
  char myString[20] = "";

  String str1 = String(units);
  int valX = analogRead(xpin);
  int valY = analogRead(ypin);
  int valZ = analogRead(zpin);

  //sprintf(myString,"%d %d %d %d", valX, valY, valZ, units);
  //sprintf(myString,"%d %d %d", valX, valY, valZ);
    sprintf(myString,"%d %d", valX, units);
  Serial.println(myString);
  if (role){
    radio.write(&myString, sizeof(myString)); 
  }
  else{
    uint8_t pipe;
    if (radio.available(&pipe)) {                    // is there a payload? get the pipe number that recieved it
      uint8_t bytes = radio.getDynamicPayloadSize(); // get the size of the payload

      char text[32] = "";                 //Saving the incoming data
      radio.read(&text, bytes); 

      //Serial.println(text);                           // print the size of the payload
      
    }
    //Serial.println(); 
  }
  

  
}

Please help me!!!

Hi, lot of years ago when I was playing with nrf and adxl on same SPI interface I didn’t know about arduino in that time I was programming in atmel studio.... after reading all datasheets -> spi configuration for nrf is different as for adxl, my partial code was working separately so adxl was working and nrf was working but if I wanted to switch the configuration for spi interface during a running program it failed than I connected adxl to I2c and nrf to SPI. but I am not good in programming and this was only my situation and how I fixed that , I am not telling that it is not possible but for me it was’t working and maybe you can try your application only woth adxl than nrf separately than together if it will not work connect your accelerometer to I2c

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.