I’ve hooked up the 4 motors from the Rover 5 to the motor controller and connected the direction and PWM pins to the red back spider robot controller (that’s a very long name). When you connect the motors to the motor controller take a good look which motor is what number. You don’t want to drive 2 motors on the same side in different directions. For this reason I left the tracks off and put a box under the chassis to easily test my little robot.
I currently use a breadboard with a LM7805 and L1117D, the 7805 provides 5 Volts to the logic terminals of the motor controller and the L1117D gives 3,3V to the Nrf24L01 2,4GHz wireless module. I will make a small PCB with some terminals and the voltage regulators to connect the different voltages. I have already received a 2 cell Lipo battery, the nominal voltage of these batteries is 7,4V. But when fully charged they give 8,4V. The battery will be connected to the robot controller and the motor power terminals on the 4 channel motor controller. I haven’t been able to do this because I don’t have the right connector.
To remote control the Rover 5 I connected my analog joystick and a Nrf24L01 module to my Arduino Uno. I then uploaded the same sketch that I used to remote control my 2 stepper motors. This sketch transmits the analog values from the joystick to the robot controller.
In the sketch for the robot controller the values from the X and Y axis are mapped to PWM values (0-255) to set the speed and the direction is determined by setting the direction outputs high or low. The minimum pins needed to drive the 4 motors are 4 PWM pins and 4 digital output pins. For the Nrf24L01 module you need another 5 pins, 3 for the SPI bus and the CE and CSN pin. Thankfully the Dagu red back spider robot controller is based on the Arduino Mega 1280, which has 54 digital input/outputs (16 are PWM) and 16 analog inputs. So I have a lot of room for expansion 🙂
Here is the sketch I’ve made to remote control the Dagu Rover 5 with an analog joystick connected to another Arduino:
// http://www.bajdi.com // Dagu Rover 5 chassis with 4 motors // Remote control through Nrf24L01 2,4GHz wireless module // µcontroller = Dagu Red back spider, Arduino Mega 1280 compatible // Motor controller = Dagu 4 channel motor controller // Motor 1 and 2 on the left // Motor 3 and 4 on the right #include <SPI.h> #include <Mirf.h> #include <nRF24L01.h> #include <MirfHardwareSpiDriver.h> /* Nrf24L01 pinout 1 GND 2 VCC (3,3V) 3 CE pin 48 on Mega 1280 4 CSN pin 49 on Mega 1280 5 SCK pin 52 on Mega 1280 6 MOSI pin 51 on Mega 1280 7 MISO pin 50 on Mega 1280 8 IRQ (not used) */ int DirM1 = 30; // direction motor 1 int DirM2 = 31; // direction motor 2 int DirM3 = 32; // direction motor 3 int DirM4 = 33; // direction motor 4 int PWMM1 = 3; // pwm motor 1 int PWMM2 = 4; // pwm motor 2 int PWMM3 = 5; // pwm motor 3 int PWMM4 = 6; // pwm motor 4 int fs; // forward speed int bs; // backward speed int ls; // turn left speed int rs; // turn right speed int joystick[3]; // Array with 2 analog values (X,Y-axis) and one digital (Z-axis) from transmitter/joystick void setup() { pinMode(DirM1, OUTPUT); // direction motor 1, left front pinMode(DirM2, OUTPUT); // direction motor 2, left rear pinMode(DirM3, OUTPUT); // direction motor 3, right front pinMode(DirM4, OUTPUT); // direction motor 4, right rear pinMode(PWMM1, OUTPUT); // PWM motor 1 pinMode(PWMM2, OUTPUT); // PWM motor 2 pinMode(PWMM3, OUTPUT); // PWM motor 3 pinMode(PWMM4, OUTPUT); // PWM motor 4 Mirf.cePin = 48; //ce pin Mirf.csnPin = 49; //csn pin Mirf.spi = &MirfHardwareSpi; Mirf.init(); Mirf.setRADDR((byte *)"serv1"); Mirf.payload = sizeof(joystick); Mirf.config(); } void loop() { int X = joystick[0]; // joystick X-axis int Y = joystick[1]; // joystick Y-axis while(!Mirf.dataReady()){ } Mirf.getData((byte *) &joystick); if (X > 500 && X < 540 && Y > 490 && Y < 530 ) // joystick is centered { analogWrite(PWMM1, 0); analogWrite(PWMM2, 0); analogWrite(PWMM3, 0); analogWrite(PWMM4, 0); } if (X <= 500 && Y > 490 && Y < 530) // joystick forward = all motors forward { fs = (map(X, 500, 0, 35, 255)); digitalWrite(DirM1, HIGH); digitalWrite(DirM2, HIGH); digitalWrite(DirM3, HIGH); digitalWrite(DirM4, HIGH); analogWrite(PWMM1, fs); analogWrite(PWMM2, fs); analogWrite(PWMM3, fs); analogWrite(PWMM4, fs); } if (X >= 540 && Y > 490 && Y < 530) // joystick backward = all motors backward { bs = (map(X, 540, 1023, 35, 255)); digitalWrite(DirM1, LOW); digitalWrite(DirM2, LOW); digitalWrite(DirM3, LOW); digitalWrite(DirM4, LOW); analogWrite(PWMM1, bs); analogWrite(PWMM2, bs); analogWrite(PWMM3, bs); analogWrite(PWMM4, bs); } if (Y <= 490 && X > 500 && X < 540) // joystick left = left motors backward && right motors forward { ls = (map(Y, 490, 0, 35, 255)); digitalWrite(DirM1, LOW); digitalWrite(DirM2, LOW); digitalWrite(DirM3, HIGH); digitalWrite(DirM4, HIGH); analogWrite(PWMM1, ls); analogWrite(PWMM2, ls); analogWrite(PWMM3, ls); analogWrite(PWMM4, ls); } if (Y >= 530 && X > 500 && X < 540) // joystick right = left motors forward && right motors backward { rs = (map(Y, 530, 1023, 35, 255)); digitalWrite(DirM1, HIGH); digitalWrite(DirM2, HIGH); digitalWrite(DirM3, LOW); digitalWrite(DirM4, LOW); analogWrite(PWMM1, rs); analogWrite(PWMM2, rs); analogWrite(PWMM3, rs); analogWrite(PWMM4, rs); } }
Hi, Can you provide links to the libraries you used?? I’d like to really work on this…
Regards, Terry King …In The Woods In Vermont
You only need the mirf library for this sketch. You can find it on the Arduino playground: http://arduino.cc/playground/InterfacingWithHardware/Nrf24L01