Notifications
Clear all

Need help with nrf24L01

69 Posts
10 Users
12 Likes
5,368 Views
(@gkar2287)
Member
Joined: 2 years ago
Posts: 19
Topic starter  

@eliza I have controlled the lights and also relays and as far as the joysticks that's a little harder my machine has a device known as a digi-sensor it mounts the same way as a potentiometer but it has a one wire output. When for example you push the control forward it lights up an led on the digi-sensor in the direction that your pushing and when you push it in the opposite way the other led lights up. I tested this with my oscilloscope and I found that this was just a pwm signal with one way making it longer and one shorter. I have set up the arduino to run a test basically turning on two leds from two different outputs and one input this should mimic the digi-sensor. I can't hook it up to the machine easily yet and if I can get the radio's to work I could test it that way. I've already got the terminal blocks to transform the control box as well as led's to visually see what's on and off I also bought a good label maker to make the heat shrink tubing for labeling the new wiring and since I'm just using the same wiring I'm going to just have to add a single shamanic to my other one's dictating the changes for the arduinos. And as I said I would like to have 3-4 arduino boards one board be the master in the box controlling the starting and running of the machine two of the other boards one board in the basket giving the pwm commands to the base and the other board taking those commands and controlling the solenoids to operate slowly in either direction. And finely the last board which could act as a basket control from the ground. The only difference between basket and ground controls are that the ground control is on-off switches you operate the switch the ram go's in or out at full speed the basket control adds the pwm function to slow the speeds down and you can only drive the machine in the basket. I'm also including a few pictures of the controls in the machine hopefully it will help in understanding me better.

20210503 120256
20210504 131749
20210504 131923

 


   
ReplyQuote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1122
 

@gkar2287

If you eventually proceed to to make some sort of operational apparatus with your arduinos' you will then need to put in 10 times as much code, and indeed thought, into making sure its safe to operate.  

Say you wireless give your boom the command to rise up and you intend for it to stop just short of your overhanging roof.  Something goes wrong and the wireless command is not received, or one of your boards goes wobbly and chooses that moment to magic smoke, maybe even a programming bug.   The boom continues to rise, it hits the overhanging roof, and your roof parts company with your house.  Hopefully someone is not in the booms basket to be squashed to a jelly like pulp.  

There's a good deal of expertise needed for these industrial controls and you should be afraid, very afraid.

 

 

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@byron @gkar2287 That is very true. Many moons ago a buddy of mine decided to go on his own and start his own elevator maintenance and construction company. He invited ma in to help him desig the new elevator controls. We both had backgrounds in electronics and I can tell you that for every one line of operational code there was 10 or 20 lines of safety code. Same thing with relays, sensors, etc.

I haven't gone back and read all the posts, but I am assuming this is NOT a commercial venture otherwise there are a ton of regulations, inspections etc etc etc, also lawyer heaven.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@gkar2287 Thanks for this reply. I always use LEDs as a sanity check. You say, "When for example you push the control forward it lights up an led on the digi-sensor in the direction that your pushing and when you push it in the opposite way the other led lights up." is this with an arduino or with the existing boom controller?

Have you been able to isolate the wiring to any of the micro switches you want to control such that you can connect them to a relay? Are these simple on/off switches? 

For PWM the arduino typically uses the analogWrite() function. You can send a value from 0 to 255. 

Here is the arduino intro to PWM.

https://create.arduino.cc/projecthub/muhammad-aqib/arduino-pwm-tutorial-ae9d71

Here is the important info:

The Arduino IDE has a built in function “analogWrite()” which can be used to generate a PWM signal. The frequency of this generated signal for most pins will be about 490Hz and we can give the value from 0-255 using this function.

analogWrite(0) means a signal of 0% duty cycle.

analogWrite(127) means a signal of 50% duty cycle.

analogWrite(255) means a signal of 100% duty cycle.

On Arduino Uno, the PWM pins are 3, 5, 6, 9, 10 and 11. The frequency of PWM signal on pins 5 and 6 will be about 980Hz and on other pins will be 490Hz. The PWM pins are labeled with ~ sign.

You say this, "my machine has a device known as a digi-sensor it mounts the same way as a potentiometer but it has a one wire output." Is this the existing boom controller? Would this "digi-sensor" work properly if it received a signal coming from arduino pins as described above?

I think that byron's comment above is vitally important. You'll want to create a virtual system that you can test before you control the actual boom. In other words, you have an arduino that produces "poor man's debugging statements" to the serial monitor such as:

"Received PWM signal 33"

"Entering boom up mode"

"Raising boom for 1/10th second."

"Checking for new PWM signal"

"Received PWM signal 0"

"Exiting boom up mode"

Does this make sense? You can also create a breadboard "control dashboard" with rows of LEDS.  Green LED in row 1 means "radio communication confirmed" Red LED in row 1 means "radio communication failed"  Blue LED in row 2 means "lifting boom now" Yellow LED in row 2 means "lowering boom now"

I always combine text output and LED signals to monitor the program. For my 2  NRF24 radios talking projects I print "radio init OK" "sending value 3 to receiver" type messages to the serial monitor and also turn LEDs on and off. After I get it working I remove the serial print statements, but keep the "sanity check" LEDs.

Hope this helps. We are in a good starting place now. Think about what you want the first step to be. Control an action on the boom with arduino first? or get 2 arduinos to communicate via radio?

If you choose control an action on the boom then plan to do that with a dedicated arduino. If you choose radio communication then we can get 2 arduinos talking without anything connected to the boom.

 


   
Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

@gkar2287, As I've been monitoring this post, I have to say that the comments from @byron, @zander, and @eliza are all well founded in the realm of SAFETY! As someone who spent over 40 years in the industrial arena, I can assure you that if anything can go wrong, it surely will, with more than devastating consequences! The safe route is to proof test every thing BEFORE attempting to hook up to a working boom lift..Remember that the forces involved here are in tons of pound force ..(pressure x area = force) and in particular, hydraulics and pneumatics, where the pressures are several hundred to several thousand PSI.

This means that even a small actuator with say, a 2" bore diameter and a 500 psi hydraulic pressure,  can generate a force of 1570 lbf (pound force) .. enough to seriously damage external things that might be in the way, and to injure, or even kill you! I don't say this as hyperbole, as I seen this many times in my long career as a instrumentation/electrical tech, and know from experience, not hearsay, or off-hand. Please be mindful of the safety aspects of your project, because the life you might save may not just be yours, but someone else's that's just in the wrong place at the wrong time.. other that that, I wish you much success on your project, and if their is anything I can help you with, please feel free to ask..process controls are something I'm very familiar with, especially PIT ( powered industrial truck, fork lifts, aerial platforms), and many different types of actuation's, hydraulic, pneumatic,  and motor driven.

regards,

LouisR

LouisR


   
Ron reacted
ReplyQuote
(@eliza)
Member
Joined: 2 years ago
Posts: 81
 

@gkar2287 Hi again, here is code for a 2 radio system that will work with 2 arduino megas.

You can wire up some LEDs according to the pin out in the code if you want. There are print statements to show what is happening. Run these on 2 different computers with their serial monitors running and you'll have your first step for NRF24 radio communication.

Connect the NRF24 pins according to the code (#define statements)

/*****************************************
* nRF24Lo1 boom controller Receiver SANDBOX

 https://create.arduino.cc/projecthub/muhammad-aqib/nrf24l01-interfacing-with-arduino-wireless-communication-0c13d4 
******************************************/

#include 
#include 
#include 

#define CE 8
#define CSN 53
#define MOSI 51
#define MISO 50
#define SCK 52

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Radio driver constructor
RH_NRF24 radioDriver(CE, CSN); // CE chip enable, CSN chip select)
// construct a reliable data gram object
RHReliableDatagram radioManager(radioDriver, SERVER_ADDRESS);

uint8_t returnMessage[] = "Message Received";
uint8_t globalTextIn[RH_NRF24_MAX_MESSAGE_LEN] = {0};
uint8_t bufferLength = sizeof(globalTextIn);
uint8_t from;

int greenLed = 2;
int redLed = 3;
int blueLed = 6;
int switchPin = 5;
boolean commOk = false;

//boolean debug = false;
boolean debug = true;

////////////////////////////////////////////////////////////////////
void setup() {

Serial.begin(9600);
Serial.println("Enter setup boom receiver build 4.27.22.1");


pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
pinMode(switchPin, INPUT);

for(int i=0; i < 2; i++) {
blinkLed(redLed,500);
blinkLed(greenLed,500);
blinkLed(blueLed,500);
}


if (radioManager.init()) {
ledOn(greenLed);
Serial.println("radioManager.init OK");
while (!commOk){
if (radioManager.available()) {
Serial.println("Setup: radioManager.available OK for dummy data");
// Wait for a message addressed to us from the client
if (radioManager.recvfromAck(globalTextIn, &bufferLength, &from)) {
if(debug){
Serial.print("Got data from : ");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)globalTextIn);
Serial.print("Setup: Received data from transmitter: ");

}
if (!radioManager.sendtoWait(returnMessage, sizeof(returnMessage), from))
Serial.println("sendtoWait failed");
commOk = true;
} // if radioManager.recfromAck
} // if radioManager.available
else
delay(1000); // wait 1 second for a transmission
Serial.println("Data not available. Rechecking");
} // while not comm Ok

} // if radioManager.init ok
else {
Serial.println("radioManager.init failed");
ledOn(redLed);
}

Serial.println("Exiting setup");

} // setup

////////////////////////////////////////////////////////////////////
void loop() {
 // nothing here, everything in setup
} // main loop

////////////////////////////////////////////////////////////////////
void ledOn( int ledPin) {
digitalWrite(ledPin, HIGH);
}

////////////////////////////////////////////////////////////////////
void ledOff( int ledPin) {
digitalWrite(ledPin, LOW);
}

////////////////////////////////////////////////////////////////////
void blinkLed( int ledPin, int delayMillis) {
ledOn(ledPin);
delay(delayMillis);
ledOff(ledPin);
delay(delayMillis);
}

Here is the code for the transmitter, pins the same:

Note:  The code below, to the end of this post, was inserted as a correction by an Admin at the request of Eliza, when it became clear that the original posted code was truncated at the very end.

/*****************************************
* NRF24L01 boom transmitter SANDBOX
* this sketch is for the mega
* ATTENTION this sketch uses pins 9 & 53 on the nRF24L01
* NOT pins 7 & 8 !!!!!!!!!!!!!!!!!!!!!!!!
* this one uses the 16 key keypad
*
 https://create.arduino.cc/projecthub/muhammad-aqib/nrf24l01-interfacing-with-arduino-wireless-communication-0c13d4 
// to recheck radio communication use reset buttons and wait for green lights
**************************************** */

#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>

#define CE 8
#define CSN 53
#define MOSI 51
#define MISO 50
#define SCK 52

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Create an instance of the radio driver
RH_NRF24 RadioDriver(CE, CSN);
RHReliableDatagram radioManager(RadioDriver, CLIENT_ADDRESS);

uint8_t outputData[] = "Hello boom from the mega.";

uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

//boolean debug = false;
boolean debug = true;

/////////////////////////////////////////////////////////////////
void setup() {

boolean transmissionConfirmed = false;
boolean radioInitOk = false;
Serial.begin(9600);
Serial.println("Enter setup boom controller transmitter build 4.27.22.1 ");

while (!radioInitOk){
if (radioManager.init()) {
radioInitOk = true;
Serial.println("radio init OK");
} // if radioInit OK
else {
Serial.println("radioManager.init failed");
} // else
delay(2000); // try the radio again in 2 seconds
}

while (! transmissionConfirmed ) {
// Send default message to radioManager
Serial.println("Attempting transmission to server");
if (radioManager.sendtoWait(outputData, sizeof(outputData), SERVER_ADDRESS)) {
Serial.println("Waiting for reply");
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (radioManager.recvfromAckTimeout(buf, &len, 2000, &from)) {
transmissionConfirmed = true;
Serial.print("got reply from: ");
Serial.print(from, HEX);
Serial.print(" : ");
Serial.println((char*)buf);
}
else {
Serial.println("No reply, is nrf24_reliable_datagram_server running?");
} // else not radioManager.recvfromAck
} // radioManager.sendtoWait
else
Serial.println("radioManager.sendtoWait failed");
delay(1000); // retry after 1 second
} // while not transmission confirmed

Serial.println("Exiting setup.");
} // setup

////////////////////////////////////////////////////////////////////
void loop() {

} // main loop

   
ReplyQuote
(@gkar2287)
Member
Joined: 2 years ago
Posts: 19
Topic starter  

I thank you for your concerns and trust me I'm painfully aware of safety. But the fact that the lift is going to be using all the original controls and sensors should not allow for any worries first and foremost will be the kill button. 


   
Ron reacted
ReplyQuote
(@gkar2287)
Member
Joined: 2 years ago
Posts: 19
Topic starter  

@eliza So how the digi-sensor operates is when moving the joy stick in any direction it powers the digi-sensor with 12 volt input then the output is one wire giving either a 12 volt short pulse or long pulse depending on which way its operated down to the lower control board to operate two different solenoids in or out. that's one of the reasons I want to get the antennas working I plan on setting up a mock control system including led's on every function. one of the safety functions is in essence a Deadman's switch which allows the power to be cut from both the board on the basket and the one that the digi-sensors control so if while in the basket you take your foot off the switch it kills the whole control assembly except for the mechanical control switches in the base that are just powered when you operate them manually. As for the led's I was referring to the digi-sensors they are about the size of an potentiometer made of some sort of Bakelite product with two led's encased in it when operating the control one lights up in one direction and the other in the other direction. maybe I'm explaining this wrong the board in the basket has only one function that's sending the digi-sensor signals down to the other board which has one function sending the pwm signals to the solenoids. the third board function is just to monitor the sensors the angle sensor the engine temperature or oil pressure if it detects a sensor being activated it also kills the power to any of the basket controls. I'm utilizing all the safety features in the original controls with the same safety switch's and lock outs. I will try your new program and let you know how I make out thanks again.


   
ReplyQuote
(@gkar2287)
Member
Joined: 2 years ago
Posts: 19
Topic starter  

@inst-tech Thank you for concern and I agree safety is paramount I'm trying to use all of original safety controls in these circuits and since they are basically killing all the power to the controls so even if they go wonky they cant control anything basically making them nonexistent. I'm sure that's why they were designed with 3 independent board each with its own controlling aspect's making sure that one couldn't influence an others commands. thank you for your input and I'll let you know how I progress.


   
Inst-Tech reacted
ReplyQuote
Inst-Tech
(@inst-tech)
Member
Joined: 2 years ago
Posts: 554
 

@gkar2287..your quite welcome, and yes, your correct in assuming that the 3 independent boards were designed that way for safety.. it's called one out 3 voting system architecture, and used in quite a lot of industrial control applications where severe danger of destroying expensive equipment, and/or life threatening injuries are possible. I look forward to seeing your  progress, and eventual completed project. 

regards,

LouisR

LouisR


   
frogandtoad reacted
ReplyQuote
frogandtoad
(@frogandtoad)
Member
Joined: 5 years ago
Posts: 1458
 

@inst-tech

Posted by: @inst-tech

@gkar2287..your quite welcome, and yes, your correct in assuming that the 3 independent boards were designed that way for safety.. it's called one out 3 voting system architecture, and used in quite a lot of industrial control applications where severe danger of destroying expensive equipment, and/or life threatening injuries are possible. I look forward to seeing your  progress, and eventual completed project. 

regards,

LouisR

Coming from both Engineering and IT backgrounds, I agree that safety in such risky circumstances is paramount!

This is what implementing "redundancy" is all about, whether it be engineering or IT.

Cheers


   
Inst-Tech reacted
ReplyQuote
(@gkar2287)
Member
Joined: 2 years ago
Posts: 19
Topic starter  

@eliza Hi Eliza I'm trying to run your program and I'm getting multiple faults when I try to verify it before loading it into the boards? 


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2535
 

@gkar2287 

It would be helpful if you told us which sketch you're running and what errors you're getting. Otherwise it's a pure guessing game 🙂

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@gkar2287 Before going further, make sure you have the right board selected, then do a screen grab of the last few lines in red in the IDE, and like @will said, the name of the sketch posted above.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 7001
 

@gkar2287 I just tried the rcvr code it for the first time, and it compiled ok, but tx is having multiple errors. Looks like part of sketch is missing.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
Page 2 / 5