merkzilla:
and it registers both buttons being HIGH but wont send the first data it its pressed
You have not explained what you want to happen.
Your code suggests that you want to send one value if one switch is pressed and a different value if the other switch is pressed.
However if you want to send both values then you also need something to send when a switch is not pressed - perhaps send "<0,0>" when no switch is pressed and "<111,0>" when only the first switch is pressed, etc.
Have a look at serial input basics which shows how to receive data - and, obviously, you have to send data in a matching style.
now it seems on my receaving side it prints all data but only follows through with the left and right turn
#include <MotorDriver.h>
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
// Hardware configuration
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(48, 49);
// Single radio pipe address for the 2 nodes to communicate.
const uint64_t pipe = 0xE8E8F0F0E1LL;
//
uint8_t received_data[2];
uint8_t num_received_data = sizeof(received_data);
const int rx_led = 42;
void setup(void)
{
motordriver.init();
motordriver.setSpeed(200, MOTORB);
motordriver.setSpeed(200, MOTORA);
pinMode(rx_led, OUTPUT);
digitalWrite(rx_led, LOW);
delay(3000); //wait until the esc starts in case of Arduino got power first
Serial.begin(57600);
printf_begin();
printf("\n\rRF24/Reciever/\n\r");
radio.begin(); //Begin operation of the chip.
// This simple sketch opens a single pipes for these two nodes to communicate
// back and forth. One listens on it, the other talks to it.
radio.openReadingPipe(1, pipe);
radio.startListening();
//
radio.printDetails();
}
void loop(void)
{
delay(100);
// if there is data ready
if ( radio.available() )
{
bool done = false;
while (!done)
{
// Fetch the payload, and see if this was the last one.
done = radio.read( received_data, num_received_data );
}
//direction
if (received_data[0] == 111)
{
digitalWrite(rx_led, HIGH);
motordriver.goForward();
}
else if (received_data[0] == 122)
{
digitalWrite(rx_led, HIGH);
motordriver.goBackward();
}
else if (received_data[0] == 10)
{
digitalWrite(rx_led, LOW);
motordriver.stop();
}
Serial.println(received_data[0]);
//steering
if (received_data[1] == 200)
{
digitalWrite(rx_led, HIGH);
motordriver.goLeft();
}
else if (received_data[1] == 222)
{
digitalWrite(rx_led, HIGH);
motordriver.goRight();
}
else if (received_data[1] == 10)
{
digitalWrite(rx_led, LOW);
motordriver.stop();
}
Serial.println(received_data[0]);
Serial.println(received_data[1]);
}
}
It's printing the values that I send 111,122,200,222,10 when I push the buttons on the transmitter (well 10 is when nothing is pushed) 111 is forward 122 revers 200 left 222 right and 10 is for all stop. after adding the left and right to the receiver code it seems to only do those functions. But yet it still receives all values I send
Yes... I have a Arduino micro I'm using as a controller with 4 push buttons currently forward,backward,left, and right. When I push a button it sends a value to the Arduino mega that will be the remote car.the values are data[o] 111 and 122 also data[1] 200 and 222 in serial monitor all values are being sent and received but the corresponding function only works for left right unless I remove those then the reverse and forward work. I did observe that the receive led is very dim and I hear the motor trying to work but doesn't when unless again I take out the left right functions then it works fine
Could you point me to a good resource for this? I understand my project might be a little too ambitious for a beginner but this project is the reason I'm doing i got into Arduino and I appreciate all the help I'm trying to complete this fairly quickly In between work and my kids
merkzilla:
Yes... I have a Arduino micro I'm using as a controller with 4 push buttons currently forward,backward,left, and right. When I push a button it sends a value to the Arduino mega that will be the remote car.the values are data[o] 111 and 122 also data[1] 200 and 222
That is better, but it is still not completely clear.
If you only need to send one value at any one time why are you thinking of having data[ 0 ] and data[ 1 ]
Knock THAT crap off. Nothing is pushed most of the time, so you are spamming the receiver. You should ONLY send data when there is MEANINGFUL data to send. 10 is NOT meaningful data.
I would like to steer while moving so I thought I might need two sets of data for that...? I have everything working although it's in the same set of data so I can only do one function at a time
I removed the data being sent when no button is pushed code works fine on the remote side but on receive side it just wants to continually put out whatever was received last so I think I need to put something if no data is received
merkzilla:
I removed the data being sent when no button is pushed code works fine on the remote side but on receive side it just wants to continually put out whatever was received last so I think I need to put something if no data is received
If the sender says "Go forward", why would you want to stop?
If the device is supposed to go forward only while the forward switch is being pressed, you are going about this all wrong.
Look at the state change detection example. Send one bit of data when the switch BECOMES pressed. Send another bit of data when the switch BECOMES released. Do NOT spam the receiver.
On the receiver, you deal with left and right only if forward, backwards, and stop have NOT been received.
While forward, backward, and stop are mutually exclusive, forward and left are not.
Dealing with left and right are NOT as else clauses under the of forward statement.
for example this would be better to have another set of data for turn left and forward
if ( digitalRead(SW1) == HIGH && digitalRead(SW2)== HIGH)
{
data[0] = 1;
Serial.println("MoveTurnLeft");
}
im still having trouble seeing how i would just send data once if button is high then again when low would i have to open and close radio Write for each