- This topic has 4 replies, 3 voices, and was last updated 5 years, 2 months ago by Jason Franken.
- AuthorPosts
- August 19, 2015 at 7:12 pm #930RC Tractor GuyKeymaster
If you have any questions about my John Deere 8360RT build then this is the place to ask them. You can see it working with the Moneydarragh Farm and Agri Contractors here:
August 19, 2015 at 7:13 pm #931RC Tractor GuyKeymasterHere is the code for the Arduino in the cab of the JD 8360RT
/* Generic RC Tractor Cab Code Version 2.0 This code was written by Oisin O'Conchubhair for the website www.rctractors.net This is the generic code used to control homemade RC Tractors. The code is intended to be used with an Arduino Pro Mini Circuit diagram can be found ar www.rctractors.net Pin Assignment D0 Serial RX D1 Serial TX D2 Right Indicator D3 Work Lights D4 Right Beacon D5 D6 D7 Left Beacon D8 NRF24 CE D9 Left Indicator D10 NRF24 CSN D11 NRF24 MOSI D12 NRF24 MISO D13 NRF24 SCK A0 A1 A2 Not assigned A3 Not assigned A4 Not assigned A5 Not assigned */ // This section describes the vehicle byte ID1 = 0x4A; // Enter a four byte ID for the vehicle byte ID2 = 0x44; // for example F936 for the Fendt 936 model byte ID3 = 0x38; // would be ID1 = 0x46; ID2 = 0x39; ID3 = 0x33; ID4 = 0x36 byte ID4 = 0x33; // because asci character F is 46 in hexidecimal and so on // Variables used in the program int Active = 0; // Variable to determine if the tractor is in active int left_ind = 0; // Variable indicating if the left indicator is currently on or off int right_ind = 0; // Variable indicating if the right indicator is currently on or off int Ind_Timer = 0; // Variable used to record the length of time the indicator is on for int ind_timer2 = 0; // Variable used to record the beacon is on for int beac_on = 0; // Variable indicating if the right indicator is currently on or off int beac_timer = 0; // Variable used to record the length of time the indicator is on for int ind_active = 0; // Variable set to show that indicator code should be running int beacon_active = 0; // Variable set to show that indicator code should be running int spots_on = 0; // Variable to idicate if the large spot lights are on int Last_Data_Timer = 0; int Beacon_Option=2; int Beacon_Timer=0; byte dat1 = 0x00; // Stores received byte byte dat2 = 0x00; // Stores received byte byte dat3 = 0x00; // Stores received byte byte dat4 = 0x00; // Stores received byte byte dat5 = 0x00; // Stores received byte byte dat6 = 0x00; // Stores received byte byte command_val = 0; // Stores the command value byte Data_Val_1 = 0; // Stores the data value byte Data_Val_2 = 0; // Stores the data value byte Data_Val_3 = 0; // Stores the data value byte Data_Val_4 = 0; // Stores the data value byte Data_Val_5 = 0; // Stores the data value byte Data_Val_6 = 0; // Stores the data value byte Data_Val_7 = 0; // Stores the data value byte Data_Val_8 = 0; // Stores the data value byte Data_Val_9 = 0; // Stores the data value byte Data_Val_10 = 0; // Stores the data value byte Data_Val_11 = 0; // Stores the data value byte Data_Val_12 = 0; // Stores the data value byte Old_Data_Val_1 = 0; // Stores the data value byte Old_Data_Val_2 = 0; // Stores the data value byte Old_Data_Val_3 = 0; // Stores the data value byte Old_Data_Val_4 = 0; // Stores the data value byte Old_Data_Val_5 = 0; // Stores the data value byte Old_Data_Val_6 = 0; // Stores the data value byte Old_Data_Val_7 = 0; // Stores the data value byte Old_Data_Val_8 = 0; // Stores the data value int data = 0; // Variable to indicate serial data is available uint8_t buf[16]; #include <SPI.h> #include "RF24.h" RF24 radio(8,10); // Controller Addresses const uint64_t Controller_1 = 0xE8E8F0F0E1LL; const uint64_t Controller_2 = 0xE8E8F0F0E2LL; void setup() { Serial.begin(9600); pinMode(2, OUTPUT); // Right indicator pinMode(3, OUTPUT); // Work lights pinMode(4, OUTPUT); // Right Beacon pinMode(7, OUTPUT); // Left Beacon pinMode(9, OUTPUT); // Left indicator radio.begin(); // Initialize the NRF24 Radio Module radio.openReadingPipe(1,Controller_1); // Set Address of Controller 1 radio.openReadingPipe(2,Controller_2); // Set Address of Controller 2 radio.startListening(); // Start listening for commands from the controllers } void loop() { Data_Check(); Data_Loss_Check(); if(Active==1){ Update_Motors(); LED_Control(); Beacon_Control(); } Ind_Control(); } void Data_Check(){ if (radio.available())radio.read(buf, 16); { // We recieved a string of ten bytes, four ID, one command and six data values but they may not be for this tractor if (buf[0] == ID1 && buf[1] == ID2 && buf[2] == ID3 && buf[3] == ID4){ // Confirm that the correct vehicle ID has been recieved Data_Val_1 = buf[4]; // Store the controller left joystick x value Data_Val_2 = buf[5]; // Store the controller left joystick x value Data_Val_3 = buf[6]; // Store the controller left joystick x value Data_Val_4 = buf[7]; // Store the controller left joystick x value Data_Val_5 = buf[8]; // Store the controller left joystick x value Data_Val_6 = buf[9]; // Store the controller left joystick x value Data_Val_7 = buf[10]; // Store the head lights state Data_Val_8 = buf[11]; // Store the work lights state Data_Val_9 = buf[12]; // Store the indicator state Data_Val_10 = buf[13]; // Store the new data value Data_Val_11 = buf[14]; // Store the new data value Data_Val_12 = buf[15]; // Store the new data value Last_Data_Timer = 10; Active = 1; } } } void Update_Motors(){ if(Data_Val_1!=Old_Data_Val_1){ Serial.write(0x0A); // \n Serial.write(0x01); // \n Serial.write(Data_Val_1); // \n Old_Data_Val_1=Data_Val_1; } if(Data_Val_2!=Old_Data_Val_2){ Serial.write(0x0A); // \n Serial.write(0x02); // \n Serial.write(Data_Val_2); // \n Old_Data_Val_2=Data_Val_2; } if(Data_Val_3!=Old_Data_Val_3){ Serial.write(0x0A); // \n Serial.write(0x03); // \n Serial.write(Data_Val_3); // \n Old_Data_Val_3=Data_Val_3; } if(Data_Val_4!=Old_Data_Val_4){ Serial.write(0x0A); // \n Serial.write(0x04); // \n Serial.write(Data_Val_4); // \n Old_Data_Val_4=Data_Val_4; } if(Data_Val_5!=Old_Data_Val_5){ Serial.write(0x0A); // \n Serial.write(0x05); // \n Serial.write(Data_Val_5); // \n Old_Data_Val_5=Data_Val_5; } if(Data_Val_6!=Old_Data_Val_6){ Serial.write(0x06); // \n Serial.write(0x01); // \n Serial.write(Data_Val_6); // \n Old_Data_Val_6=Data_Val_6; } } void LED_Control(){ if(Data_Val_8!=Old_Data_Val_8){ if(Data_Val_8 == 1){ // Work Lights digitalWrite(3, HIGH); // turn it on Serial.write(0x0A); // \n Serial.write(0x08); // \n Serial.write(0x01); // \n } else{ digitalWrite(3, LOW); // turn it on Serial.write(0x0A); // \n Serial.write(0x08); // \n Serial.write(0x00); // \n } Old_Data_Val_8=Data_Val_8; } if(Data_Val_7!=Old_Data_Val_7){ if(Data_Val_7 == 1){ Serial.write(0x0A); // \n Serial.write(0x07); // \n Serial.write(0x01); // \n } else if(Data_Val_7 == 2){ Serial.write(0x0A); // \n Serial.write(0x07); // \n Serial.write(0x02); // \n } else{ Serial.write(0x0A); // \n Serial.write(0x07); // \n Serial.write(0x00); // \n } Old_Data_Val_7=Data_Val_7; } } void Ind_Control(){ Ind_Timer = Ind_Timer+1; if(Ind_Timer = 2000){ if (Data_Val_9 == 1){ ind_left(); } else if(Data_Val_9 == 2){ ind_right(); } else if(Data_Val_9 == 3){ ind_hazard(); } else{ ind_off(); } Ind_Timer = 0; } } // Indicator control functions void ind_left(){ if (left_ind == 0){ // If left indicator is off digitalWrite(2, HIGH); // turn it on Serial.write(0x0A); // \n Serial.write(0x09); // \n Serial.write(0x02); // \n left_ind = 1; } else{ // If left indicator is on ind_off(); } } void ind_right(){ if (right_ind == 0){ // If right indicator is off digitalWrite(9, HIGH); // turn it on Serial.write(0x0A); // \n Serial.write(0x09); // \n Serial.write(0x01); // \n right_ind = 1; } else{ // If right indicator is on ind_off(); } } void ind_hazard(){ if (left_ind == 0){ // If hazards are off digitalWrite(2, HIGH); // turn them on digitalWrite(9, HIGH); Serial.write(0x0A); // \n Serial.write(0x09); // \n Serial.write(0x03); // \n left_ind = 1; } else{ // If hazards are on ind_off(); } } void ind_off(){ digitalWrite(2, LOW); // turn them off digitalWrite(9, LOW); Serial.write(0x0A); // \n Serial.write(0x09); // \n Serial.write(0x00); // \n left_ind = 0; right_ind = 0; } void Beacon_Control(){ if(Beacon_Option==1){ Beacon_Timer++; if (Beacon_Timer == 4){ digitalWrite(4, LOW); digitalWrite(7, HIGH); } else if (Beacon_Timer == 8){ digitalWrite(4, HIGH); digitalWrite(7, LOW); Beacon_Timer = 0; } } else if(Beacon_Option==2){ Beacon_Timer++; if (Beacon_Timer == 4){ digitalWrite(4, HIGH); } if (Beacon_Timer == 6){ digitalWrite(4, LOW); } if (Beacon_Timer == 8){ digitalWrite(4, HIGH); } if (Beacon_Timer == 10){ digitalWrite(4, LOW); } if (Beacon_Timer == 14){ digitalWrite(7, HIGH); } if (Beacon_Timer == 16){ digitalWrite(7, LOW); } if (Beacon_Timer == 18){ digitalWrite(7, HIGH); } if (Beacon_Timer == 20){ digitalWrite(7, LOW); Beacon_Timer = 0; } } else{ digitalWrite(4, LOW); digitalWrite(7, LOW); } } void Data_Loss_Check(){ if(Last_Data_Timer != 0){ Last_Data_Timer = Last_Data_Timer - 1; } if(Last_Data_Timer == 0 && Active == 1){ Active = 0; Data_Val_9 == 3; Beacon_Option=0; LED_Control(); Beacon_Control(); } }
And the code for the Arduino in the body is:
/* Generic RC Tractor Body Code Version 2.0 This code was written by Oisin O'Conchubhair for the website www.rctractors.net This is the generic code used to control homemade RC Tractors. The code is intended to be used with an Arduino Pro Mini Circuit diagram can be found ar www.rctractors.net Pin Assignment D0 Serial RX D1 Serial TX D2 Left Indicator D3 Head Lights D4 Right Indicator D5 Drive Motor Speed Control D6 Brake Lights D7 Drive Motor Direction Control 1 D8 Drive Motor Direction Control 2 D9 Three-Point Linkage Servo Signal D10 Steering Servo Signal D11 Accessory Servo Signal D12 Accessory Serial TX Signal D13 Spot Lights A0 Beacon 1 A1 Beacon 2 A2 Not assigned A3 Not assigned A4 Not assigned A5 Not assigned */ // This section describes the vehicle byte ID1 = 0x4A; // Enter a four byte ID for the vehicle byte ID2 = 0x44; // for example F936 for the Fendt 936 model byte ID3 = 0x38; // would be ID1 = 0x46; ID2 = 0x39; ID3 = 0x33; ID4 = 0x36 byte ID4 = 0x33; // because asci character F is 46 in hexidecimal and so on byte steering_center = 0x52; // Every model is different so once we have biult the model byte steering_min = 0x40; // we test for the limits of the steering. Servo values must byte steering_max = 0x80; // not exceed 0xB4 as this is 180 degrees, max servo rotation byte drive_center = 128; // The drive is generally going to be the same for all models byte drive_max = 255; // but you can change these values if you need to byte drive_min = 0; byte link_center = 0x5A; // The link values depend your use. If used to control one of byte link_min = 0x40; // the three-point links, adjust the values. If used for an byte link_max = 0x80; // accessory, dont change values and use like external servo byte external_center = 0x5A; // Set a center value for the extra servos, 5A is 90 in Hex byte ex_ser_val = 30; // Variables used in the program int left_ind = 0; // Variable indicating if the left indicator is currently on or off int right_ind = 0; // Variable indicating if the right indicator is currently on or off int ind_timer = 0; // Variable used to record the length of time the indicator is on for int ind_timer2 = 0; // Variable used to record the beacon is on for int beac_on = 0; // Variable indicating if the right indicator is currently on or off int beac_timer = 0; // Variable used to record the length of time the indicator is on for int ind_active = 0; // Variable set to show that indicator code should be running int beacon_active = 0; // Variable set to show that indicator code should be running int dips_on = 0; // Variable to idicate if the dipped headlights are on int heads_on = 0; // Variable to idicate if the full beams are on int spots_on = 0; // Variable to idicate if the large spot lights are on int move1 = 125; // Variable used to determine the motor direction int move2 = 125; byte command_val = 0x00; // Stores the command value byte data_val = 0x00; // Stores the data value byte servo_val = 0x00; // Variable used to ensure data_val is between servo limits byte drive_val = 0x00; byte dat1 = 0x00; // Stores received byte byte dat2 = 0x00; // Stores received byte byte dat3 = 0x00; // Stores received byte byte dat4 = 0x00; // Stores received byte byte dat5 = 0x00; // Stores received byte byte dat6 = 0x00; // Stores received byte byte steering_val = 0x00; int link_ser_val = 127; // Battery Voltage Measurement Code //long readVcc() { // long result; // // Read 1.1V reference against AVcc // ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // delay(2); // Wait for Vref to settle // ADCSRA |= _BV(ADSC); // Convert // while (bit_is_set(ADCSRA,ADSC)); // result = ADCL; // result |= ADCH<<8; // result = 1125300L / result; // Back-calculate AVcc in mV // return result; //} #include <Servo.h> // Include the library for controlling servos #include <SendOnlySoftwareSerial.h> // Include the library for creating additional serial ports SendOnlySoftwareSerial ExternalSerial(12); // Set pin 2 as RX and 7 as TX for the software serial port Servo link_servo; // Create servo object to control the link servo Servo external_servo; // Create servo object to control the external servo int data = 0; // Variable to indicate serial data is available void setup() { Serial.begin(9600); // Initialize main serial communication ExternalSerial.begin(9600); // Initialize additional serial communication // Set pins as outputs pinMode(2, OUTPUT); // Left indicator pinMode(3, OUTPUT); // Head lights pinMode(4, OUTPUT); // Right indicator pinMode(5, OUTPUT); // Drive motor 1 PWM control pin pinMode(6, OUTPUT); // Drive motor 2 PWM control pin pinMode(7, OUTPUT); // Drive motor 1 direction control 1 pinMode(8, OUTPUT); // Drive motor 1 direction control 2 pinMode(10, OUTPUT); // Brake Lights pinMode(13, OUTPUT); // Spot Lights pinMode(A0, OUTPUT); // Drive motor 2 direction control 1 pinMode(A1, OUTPUT); // Drive motor 2 direction control 2 pinMode(A2, OUTPUT); // Not assigned pinMode(A3, OUTPUT); // Not assigned pinMode(A4, OUTPUT); // Not assigned pinMode(A5, OUTPUT); // Not assigned // Set servo pins link_servo.attach(9); // attaches the servo on pin 9 to the link servo object external_servo.attach(11); // attaches the servo on pin 11 to the external servo object // Initialise the servos link_servo.write(link_center); // sets the initial link servo position external_servo.write(external_center); // sets the initial external servo position } // Main loop, this constantly repeats void loop() { if (Serial.available()) { // Check if serial data is available dat1=Serial.read(); // If yes then read it if (dat1 == 0x0A){ // Check for 0A indicating the start of a command string data++; // If 0A recieved then make data = 1 while (data == 1){ // While data = 1 wait for the first command byte if (Serial.available()) { command_val=Serial.read(); // Once receieved store it in dat1 data++; // Increment data variable } } while (data == 2){ // While data = 2 wait for the second command byte if (Serial.available()) { data_val=Serial.read(); // Once receieved store it in dat2 data = 0; // When the final byte is recieved we exit these loops } } } } switch (command_val){ // Perform an action based on the recieved command case 0x00: { // No command exit command selection break; } case 0x01: // Left Joystick X { if(data_val > 0xCC){// && ex_ser_val<255) ex_ser_val = ex_ser_val +1; ExternalSerial.write(0x09); } else if(data_val < 0x40){// && ex_ser_val>0) ex_ser_val = ex_ser_val -1; ExternalSerial.write(0x08); } else{ ExternalSerial.write(0x0A); } external_servo.write(ex_ser_val); // Set the servo position according to the recieved value command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x02: // Left Joystick Y { drive_val = data_val;//drive_min, drive_max); // scale the data value for use with the motor update_motor(); command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x03: // Left Pot { // We will scale this value with the controller so it works for different implements link_servo.write(data_val); // Set the servo position according to the scaled value command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x04: // Right Joystick X { command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x05: // Right Joystick Y { steering_val = data_val; // Scale data_val to between steering_min and steering_max update_motor(); command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x06: // Right Pot { ExternalSerial.write(data_val); // Output serial command to the implement command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x07: // Head Lights { if (data_val == 1) { analogWrite(3, 127); digitalWrite(10, HIGH); } else if (data_val == 2) { analogWrite(3, 255); digitalWrite(10, HIGH); } else { analogWrite(3, 0); digitalWrite(10, LOW); } command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x08: // Left indicator { if (data_val == 1){ // If off turn on digitalWrite(13, HIGH); } else{ digitalWrite(13, LOW); } } case 0x09: // Left indicator { if (data_val == 1){ // If off turn on digitalWrite(2, HIGH); digitalWrite(4, LOW); } else if(data_val == 2){ digitalWrite(2, LOW); digitalWrite(4, HIGH); } else if(data_val == 3){ digitalWrite(2, HIGH); digitalWrite(4, HIGH); } else{ digitalWrite(2, LOW); digitalWrite(4, LOW); } } case 0x0B: // Not Implemented { command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x0C: // Link servo { command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x0D: // Not Implemented { command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x0E: // Not Implemented { command_val = 0x00; // Clear command and data values data_val = 0x00; break; } case 0x0F: // Not Implemented { command_val = 0x00; // Clear command and data values data_val = 0x00; break; } } } void update_motor(){ if (drive_val < 120){ // These if functions leave a buffer zone of 15 bits above and below the drive center value move1 = map(drive_val, 120, 0, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(5,move1); // Set the PWM vlue on pin 5 to move the motor digitalWrite(8, HIGH); // Set the direction with pins 7 and 8 digitalWrite(7, LOW); } else if (drive_val > 135){ move1 = map(drive_val, 135, 255, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(5,move1); // Set the PWM vlue on pin 5 to move the motor digitalWrite(7, HIGH); // Set the direction with pins 7 and 8 digitalWrite(8, LOW); } else{ move1=0; analogWrite(5,move1); // Set the PWM vlue on pin 5 to move the motor digitalWrite(8, LOW); // Set the direction with pins 7 and 8 digitalWrite(7, LOW); } if(steering_val < 120){ move2 = map(steering_val, 128, 0, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(6,move2); // Set the PWM vlue on pin 5 to move the motor digitalWrite(A1, LOW); // Set the direction with pins 7 and 8 digitalWrite(A0, HIGH); } else if(steering_val > 135){ move2 = map(steering_val, 128, 255, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(6,move2); // Set the PWM vlue on pin 5 to move the motor digitalWrite(A0, LOW); // Set the direction with pins 7 and 8 digitalWrite(A1, HIGH); } else{ move2=0; analogWrite(6,move2); // Set the PWM vlue on pin 5 to move the motor digitalWrite(A0, LOW); // Set the direction with pins 7 and 8 digitalWrite(A1, LOW); } } void Battery_Check(){ //Batt_Vol = readVcc(); //if(Batt_Vol<3600){ //shutdown //} }
October 16, 2015 at 4:16 pm #1355sisikarParticipantyes but only control arduino on arduino not serial communication.I build crawler and i like your steering RC John Deere 8360RT.
I have a functional model but need variables code for two motor control. code for Arduino in the control – code for Arduino in the bodyleft-right joystick X, forward-backward joystick Y
_________________________________________________________________
please modify receiver code/* NRF24L01 Module Demo Receiver Code Pin Assignment D0 D1 AIN3 D2 AIN4 D3 PWMB D4 LED Pin D5 PWMA D6 AIN1 D7 AIN2 D8 NRF24 CE D9 nova ledka D10 NRF24 CSN D11 NRF24 MOSI D12 NRF24 MISO D13 NRF24 SCK A0 A1 A2 A3 A4 A5 */ // This section describes the vehicle (this ID is JD83) byte ID1 = 0x4A; // Enter a four byte ID for the vehicle byte ID2 = 0x44; // for example F936 for the Fendt 936 model byte ID3 = 0x38; // would be ID1 = 0x46; ID2 = 0x39; ID3 = 0x33; ID4 = 0x36 byte ID4 = 0x33; // because asci character F is 46 in hexidecimal and so on // Variables used in the program int Move_1 = 125; // Variable used to determine the motor direction int Move_2 = 125; byte Command_Val = 0x00; // Stores the command value byte Data_Val_1 = 0x00; // Stores the data value byte Data_Val_2 = 0x00; // Stores the data value byte Data_Val_3 = 0x00; // Stores the data value byte Data_Val_4 = 0x00; // Stores the data value byte Data_Val_5 = 0x00; // Stores the data value byte Data_Val_6 = 0x00; // Stores the data value byte Data_Val_7 = 0x00; //nova ledka byte Data_Val_8 = 0x00; //Right_Joy_X byte Data_Val_9 = 0x00; //Right_Joy_Y float Value; // Include Libraries #include <SPI.h> #include <RH_NRF24.h> RH_NRF24 nrf24; // Create NRF24 object void setup() { pinMode(4, OUTPUT); // Set digital pin 4 as an output pinMode(3, OUTPUT);// nova ledka Serial.begin(9600); nrf24.init(); // Initiailize NRF24 radio module nrf24.setChannel(1); // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm nrf24.setRF(RH_NRF24::DataRate2Mbps, RH_NRF24::TransmitPower0dBm); } void loop() { if (nrf24.available()) // If the NRF24 has recieved data { uint8_t buf[14]; // Create array to store it in uint8_t len = sizeof(buf); if (nrf24.recv(buf, &len)) // Store the data { // We recieved a string of ten bytes, four ID, one command and six data values but they may not be for this tractor if (buf[0] == ID1 && buf[1] == ID2 && buf[2] == ID3 && buf[3] == ID4){ // ak sedia hodnoty tak je to pravda Command_Val = buf[4]; // Store the new command value Data_Val_1 = buf[5]; // variabilne priradene k setup Data_Val_2 = buf[6]; // Store the new data value Data_Val_3 = buf[7]; // Store the new data value Data_Val_4 = buf[8]; // Left_Joy_X Data_Val_5 = buf[9]; // Left_Joy_Y Data_Val_6 = buf[10]; // Store the new data value Data_Val_7 = buf[11]; // nova ledka Data_Val_8 = buf[12]; //Right_Joy_X Data_Val_9 = buf[13]; //Right_Joy_Y } } // Servo not simple, NRF24 and servo libraries trying to use the same timer // Motor Control // Data recieved is between 0 and 255. The center is 255/2=127.5 and we want a buffer zone around here to stop the tractor from moving unexpectedly. if (Data_Val_5 < 120){ // This if function create a buffer zone of 7.5 bits below 127.5 Move_1 = map(Data_Val_5, 120, 0, 0,255); // PWM is 0% at 0 and 100% at 255 so scale the data value for use with the motor analogWrite(5,Move_1); Serial.print("analog read "); Serial.println(Data_Val_5);// Set the PWM value on pin 5 to move the motor digitalWrite(6, HIGH); // Set the direction with pins 6 and 7 digitalWrite(7, LOW); } else if (Data_Val_5 > 140){ // This if function create a buffer zone of 7.5 bits above 127.5 Move_1 = map(Data_Val_5, 140, 255, 0,255); // PWM is 0% at 0 and 100% at 255 so scale the data value for use with the motor analogWrite(5,Move_1); Serial.print("analog read "); Serial.println(Data_Val_5);// Set the PWM vlue on pin 5 to move the motor digitalWrite(7, HIGH); // Set the direction with pins 6 and 7 digitalWrite(6, LOW); } else{ // Every other value is in the buffer zone Move_1=0; analogWrite(5,Move_1); // Set the PWM to 0% digitalWrite(6, LOW); // Set the direction with pins 6 and 7 but not necessary digitalWrite(7, LOW); } if (Data_Val_9 < 120){ // This if function create a buffer zone of 7.5 bits below 127.5 Move_2 = map(Data_Val_9, 120, 0, 0,255); // PWM is 0% at 0 and 100% at 255 so scale the data value for use with the motor analogWrite(3,Move_2); Serial.print(" analog read "); Serial.println(Data_Val_9);// Set the PWM value on pin 5 to move the motor digitalWrite(4, HIGH); // Set the direction with pins 6 and 7 digitalWrite(2, LOW); } else if (Data_Val_9 > 140){ // This if function create a buffer zone of 7.5 bits above 127.5 Move_2 = map(Data_Val_9, 140, 255, 0,255); // PWM is 0% at 0 and 100% at 255 so scale the data value for use with the motor analogWrite(3,Move_2); digitalWrite(2, HIGH); // Set the direction with pins 6 and 7 digitalWrite(4, LOW); } else{ // Every other value is in the buffer zone Move_2=0; analogWrite(3,Move_2); // Set the PWM to 0% digitalWrite(4, LOW); // Set the direction with pins 6 and 7 but not necessary digitalWrite(2, LOW); } // LED Control if(Data_Val_6==1){ digitalWrite(1, HIGH); // Turn LED on } else { digitalWrite(1, LOW); // Turn LED off } // nova ledka if(Data_Val_7==1){ digitalWrite(9, HIGH); // Turn LED on } else { digitalWrite(9, LOW); // Turn LED off } } }
October 19, 2015 at 10:59 am #1356RC Tractor GuyKeymasterYou just need the piece that controls the motors right? I just use this function to do that, I measure two potentiometer values, send them to the tractor, name the values drive_val_1 and drive_val_2 and then call this function. Does that help?
void update_motor(){ if (drive_val_1 < 120){ // These if functions leave a buffer zone of 15 bits above and below the drive center value move1 = map(drive_val_1, 120, 0, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(5,move1); // Set the PWM vlue on pin 5 to move the motor digitalWrite(8, HIGH); // Set the direction with pins 7 and 8 digitalWrite(7, LOW); } else if (drive_val_1 > 135){ move1 = map(drive_val_1, 135, 255, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(5,move1); // Set the PWM vlue on pin 5 to move the motor digitalWrite(7, HIGH); // Set the direction with pins 7 and 8 digitalWrite(8, LOW); } else{ move1=0; analogWrite(5,move1); // Set the PWM vlue on pin 5 to move the motor digitalWrite(8, LOW); // Set the direction with pins 7 and 8 digitalWrite(7, LOW); } if(drive_val_2 < 120){ move2 = map(drive_val_2, 128, 0, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(6,move2); // Set the PWM vlue on pin 5 to move the motor digitalWrite(A1, LOW); // Set the direction with pins 7 and 8 digitalWrite(A0, HIGH); } else if(drive_val_2 > 135){ move2 = map(drive_val_2, 128, 255, 0,255);//drive_min, drive_max); // scale the data value for use with the motor analogWrite(6,move2); // Set the PWM vlue on pin 5 to move the motor digitalWrite(A0, LOW); // Set the direction with pins 7 and 8 digitalWrite(A1, HIGH); } else{ move2=0; analogWrite(6,move2); // Set the PWM vlue on pin 5 to move the motor digitalWrite(A0, LOW); // Set the direction with pins 7 and 8 digitalWrite(A1, LOW); } }
February 18, 2019 at 8:45 pm #3636Jason FrankenParticipantHi all.
I’m considering alternative drive motors for the RC John Deere 8360RT.How low geared (low rpm) does it need to be since that was an issue with an early attempt?
I can find flipped output 30 rpm n20 motors with threaded shafts or shorter shafts than used in the video, but the only one I see with the same size shaft as in the video is at 35 rpm.The motor at this url might fit without cutting as much away from the tractor body but is 87 rpm (https://www.ebay.com/itm/Micro-7-Type-N20-Full-Metal-Gear-Motor-DC-3V-87RPM-Slow-Speed-Threaded-Shaft-DIY-/113275372699)
Like in video but 35 rpm: (https://www.ebay.com/itm/1pcs-1024-N20-DC1-5V-6V-Flip-Speed-Reduction-Gear-Motor-with-Metal-Gearbox-Wheel-/162792853203?uskus=speed:35R/Min&vauurId=461831340782)
Threaded shaft: (https://www.ebay.com/itm/1024GA20-6-12V-Thread-Flip-N20-Reduction-Geared-Motor-M4-55mm-Shaft-30-200RPM-im-/183356645680?skus=Voltage:6V|Rated%20Speed:30RPM&varId=690668606656)
Shorter shaft: (https://www.ebay.cuom/itm/JGA1024-N20-Micro-DC-Gear-Motors-3V-6V-12V-15rpm-500rpm-For-DIY-Robot-Flip-/153273342268?skus=Voltage%20&%20Speed:6V%20-%2030RPM|Package%20Quantity:1PCS&varId=453150392849)Thanks,
Jason
- AuthorPosts
You must be logged in to reply to this topic.