I am trying to make a macadam wheel robot that is controlled via the x and y values on a joystick, the push button on the joystick, and another push button. I have been scavenging the internet for days now on how to send these values and have reached the end of google results on multiple searches. Can anybody tell me how to send these values through a NRFL01 radio and how to receive this data so I can use it on the receiving end? (preferably with code pictures)
Have You managed to send any kind of data, and receiving them?
Those values will always be two integers. You send them both and receive them both and do whatever you want to with them. Best of all, YOU write the code, of course you can.
My 2 partners have, but they have run into issues too. this forced them to switch to IR remotes but that's only temporary. Even the IR remotes are having problems.
How do I send and receive them though? I do have some receiving code.
#define VRX 1
#define VRY 2
#define joyPush 3
#define leftPush 4
#include <Servo.h>
Servo rs; //pin6
Servo qs; //pin5
Servo ss; //pin10
Servo us; //pin11
int q; // TOP RIGHT
int r; // TOP LEFT
int u; // BOTTOM RIGHT
int s; //BOTTOM LEFT
int y;
int x;
int speed;
int slow = 100;
int boost = 200;
void setup() {
Serial.begin(9600) ;
pinMode (joyPush, INPUT);
pinMode (leftPush, INPUT);
rs.attach(6, 500, 2500);
qs.attach(5, 500, 2500);
ss.attach(10, 500, 2500);
us.attach(11, 500, 2500);
}
void loop() {
x = analogRead(VRX);
y = analogRead(VRY);
if (digitalRead (joyPush) ==1) {
speed=boost;
}
else {
speed=slow;
}
if (digitalRead (leftPush) ==1) {
u=q;
r=-q;
r=s;
}
else if (120<y<200) {
q=s;
q=-r;
r=u;
}
else if (120<x<200) {
q=s;
s=-r;
r=u;
}
else if (((y>200)&&(x>200))||((y<120)&&(x<120))) {
r=u;
q=s;
s=0;
}
else {
q=s;
r=u;
u=0;
}
if (digitalRead (leftPush) ==1) {
u=speed; //PINPOINT TURN
}
else if ((120<y<200)&&(x>200)) {
r=speed; //RIGHT
}
else if ((120<y<200)&&(x<120)) {
r=-speed; //LEFT
}
else if ((120<x<200)&&(y>200)) {
q=speed; //FORWARD
}
else if ((120<x<200)&&(y<120)) {
q=-speed; //BACKWARD
}
else if ((y<120)&&(x>200)) {
q=-speed; //down right
}
else if ((y<120)&&(x<120)) {
r=-speed; //down left
}
else if ((y>200)&&(x<120)) {
q=speed; //up left
}
else if ((y>200)&&(x>200)) {
r=speed; //up right
}
else {
q=0; //STOP
}
}
@Railroader's question was, I think, meant to imply that there is nothing special about sending any particular kind of data. As was @Paul_KD7HB 's more pointy point.
To succeed in steps, first get any kind of data at all to go from one place to the other.
Often with radio sets it is advised to slavishly follow a known good example. Do not alter the code, do follow all recommendations for powering the radios, attaching them to the Arduino and keeping the two units a good distance from each other - too very close on the workbench may swamp the receivers and interfere with transmission. Ten feet should be more than enough.
Once you can send numbers, then worry about what those numbers mean and how they might need to be handled differently to your working code. Like if you had to send more bytes, or different data types or whatever.
a7
Do you have any suggestions on places to look for examples?
This is a good place to start
google and you will find several similar full tutorials. I suggest reading them to see where they agree and where they may do things in what each author thinks is better, or easier or whatever.
a7
Sorry but it tells nothing useful.
Confusing.
Use serial.println, and serial monitor, to show and debug what's going on during the execution.
sorry about the lack of information. The problem the IR remote runs into is after every other input, the robot freezes. My partners working on the IR are currently fixing up any wiring issues and taking 777's advice on moving the transmitter and receiver further apart. I'm currently working on the NRF24L01 code
Okey. Do as suggested, use serial.println of the data transmitted to make sure the proper data are sent. Then do the same to the receiver to check what data looks like. If any data is corrupted the poor robot will not do what You want.
Post an example of the values you want to send.
Joystick values: VRX (x-value/ "VRX"), VRY (y-value/ "VRY"), SW (joystick push/ "joyPush")
Push-button Value: pushed/not pushed.
Sorry for the late reply
I hear you're stuck sending joystick data to your robot with the NRF24L01 module. Don't worry, it's achievable! Here's the gist:
1- Libraries: You'll need libraries like "RF24" or "Mirf" to talk to the NRF24L01. These libraries handle the communication details.
2- Data Packing: On the transmitter (joystick side), use the library functions to read joystick X, Y values (usually analog) and button presses (digital). Pack this data into a single byte array.
3- Transmission: Use the library functions again to send this data packet through the NRF24L01. Make sure both transmitter and receiver are on the same channel.
4- Receiving: On the receiver (robot side), the library will receive the data packet. Unpack the byte array to get individual joystick values and button states.
5- Control: Finally, use these received values to control your robot's movement (e.g., motor speeds) based on joystick position and button presses.
Search online for code examples using your chosen library. They'll often include comments explaining each step, making it easier to understand. Happy robot building!