Hey everyone. I'm working on a RC car with Arduino Nano. I'm using the Mega as a receiver, and the dc motor is connected to it. I'm unable to get the dc motor to work, after changing the code around, following YouTube videos, and some articles. Would anyone be of any assistance ?
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(10,8); //nRF24L01 (CE,CSN)
const byte address[][6] = {"00001", "00002"};
const byte motor_A_left = 5; // PWM motor pin IN2 motor A
const byte motor_A_right = 6; // PWM motor pin IN1 motor A
const byte top_Button = 2; // button for counter clockwise motor A
const byte bottom_Button = 3; // button for clockwise motor A
const byte motor_B_left = 9; // PWM motor pin IN2 motor B
const byte motor_B_right = A1; // PWM motor pin IN1 motor B
const byte left_Button = 7; // button for clockwise motor B
const byte right_Button = 4; // button for counter clockwise motor B
const byte PotPin = A0;
const byte MotorB_speed = 30;
int topButton = digitalRead(2);
int bottomButton = digitalRead(3);
int leftButton = digitalRead(7);
int rightButton = digitalRead(4);
void setup() {
// put your setup code here, to run once:
pinMode (10,OUTPUT); pinMode(3,OUTPUT); pinMode(2,OUTPUT);
radio.begin();
radio.openWritingPipe(address[1]);
radio.openReadingPipe(1, address[0]);
radio.setPALevel(RF24_PA_MIN);
Serial.begin(9600);
Serial.println("checking if chip connected");
bool check = radio.isChipConnected();
Serial.print("check-");
Serial.println(check);
radio.setPALevel(RF24_PA_MIN);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(9, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(7, INPUT);
pinMode(4, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
radio.stopListening();
int Pot = analogRead(A0); // Speed from 0 to 255
Pot /= 4;
Serial.println(Pot);
// Motor A:
if (topButton == LOW && bottomButton == HIGH)
{
analogWrite(motor_A_left, Pot);
digitalWrite(motor_A_right, LOW);
}
else if (topButton == HIGH && bottomButton == LOW)
{
digitalWrite(motor_A_left, LOW);
analogWrite(motor_A_right, Pot);
}
else
{
// Brake
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
}
// Motor B
if (leftButton == LOW && rightButton == HIGH)
{
//For Clockwise motion
analogWrite(motor_B_left, MotorB_speed);
digitalWrite(motor_B_right, LOW);
}
else if (leftButton == HIGH && rightButton == LOW)
{
//For Anti-Clockwise motion
digitalWrite(motor_B_left, LOW) ;
analogWrite(motor_B_right,MotorB_speed );
}
else
{
//For brake
digitalWrite(motor_B_left, HIGH) ;
digitalWrite(motor_B_right, HIGH) ;
}
int message[4];
message[0] = digitalRead(topButton);
message[1] = digitalRead(bottomButton);
message[2] = digitalRead(leftButton);
message[3] = digitalRead(rightButton);
//int i;
//for (i = 0; i < 4; i = i + 1) {
// Serial.print(message[i]);
//}
Serial.println("Transmitted");
radio.write(&message,sizeof(message));
delay(100); //You can play with this number
}
All I'm seeing in the serial monitor is "Transmitted, and whatever number I turn my potentiometer to. Also, if I choose Nano on one screen, it automatically makes the other screen Nano, even though it's a Mega.
The transmit and the load led's are communicating on the Nano, I presume from the blinking. I thought maybe the receive would be blinking on the Mega, but it is not.
No. Open 2 separate instances of the Arduino IDE. In each, run the CheckConnection sketch from post #30 (link back in post #6) on both of your boards to make sure that you have the correct values for CE_PIN and CSN_PIN.
Post the output of the IDE serial monitor for both Arduinos if you are not sure if the connection is working.
Then load the example sketches from post #2 (again, link back in post #6). Load SimpleTx into one of your Arduinos (in one IDE instance), and SimpleRx into the other one (in the other IDE instance).
Make any necessary changes for your particular setups for the values of CE_PIN and CSN_PIN in both of the sketches.
The boards can be of the same type or different. By opening a separate instance of the IDE for each you are able to set the COM port and board type for each, if different, which yours are
Remember I said explicitly
Have you got 2 instances, one for the Tx and one for the Rx working now ?
Sorry to respond so late, something happened to my account so I'm a Newbie now . Which limits my replies. I can't make anymore replies for another 4 hours. I think my badge upgraded, so I'm trying with this post now .
Yeah, I can get a Tx, and Rx screen open now for two different Arduinos. However, my Tx, transmission is failing.
I've been browsing some forums, and saw something about a root port usb, so I switched the usb my Mega was on. Once I did that, the receiver started receiving data, but the transmitter continues to fail.
I did the two tests as mentioned, from the tutorial. It's shows the Tx failing. The first only showed the dynpd/feature as 0×00. I thought I saved my draft, before the technicality . It was a diagnosis page for how many 0x00's, and 0xff's I had.
I don't know if you saw my replies on having technicalities with responding . I tried to save my drafts, but they're not coming up. I did those two tests, and the first only had one 0x00, and no 0xff's. The 0x00 was on dynpd/feature. It says 0x00 twice. The second test says Tx failed, and I was able to set a different Arduino for each screen . I wasn't able to when I do my rc car though.