/*************************************************************************************
Sergey dROb, Oct 2014,
This program will test ESC+motor (or servo), sending range of valid PPM signals to the output pin at "servoPin"
Primarily, this is used to detect sync issues, happening when Motor is quickly accelerating from low to high speed.
If LCD display is connected - it displays number of test and Start-End microseconds of PPM signal (you can then record, which scenario is problem for your motor)
Connection: Plug the LCD Keypad to the Arduino. Output PPM will be on servoPin. Conect GND and servoPin to ESC.
Discussion:
**************************************************************************************/
#include <LiquidCrystal.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel
int servoPin = 22;
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
void setup(){
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Starting motor");
lcd.setCursor(0,1);
lcd.print("In 3 seconds..");
myservo.attach(servoPin);
myservo.writeMicroseconds(950); // Init ESC
delay(3000); // Waiting 3 seconds to avoid chopping of user hands
myservo.writeMicroseconds(1250); // Start motor on low speed
}
void loop(){
int test_no=1;
int start_uS;
int end_uS;
int tact_delay=1000;
lcd.clear();
lcd.print("No: Start: End:");
// Main cycle - start series of cycles, when motor jumps from set of speeds to higher set of speeds.
for (start_uS=1100; start_uS<=1900; start_uS+=100){ // Start PPM from which motor will jump to End PPM
servoOutput(start_uS);
delay(tact_delay);
for (end_uS=start_uS+100; end_uS<=1900; end_uS+=100){ // End PPM of the current cycle
displayData(test_no, start_uS, end_uS);
servoOutput(end_uS);
tact_delay=end_uS - start_uS; if (tact_delay<400) tact_delay=400;// Intellectual delay. Pause will be bigger if motor have to change the speed a lot. But not less 0.4 sec
delay(tact_delay);
servoOutput(start_uS);
delay(tact_delay);
test_no++;
}
}
lcd.setCursor(0,1);
lcd_key = read_LCD_buttons();
dispatch_keys(lcd_key);
}
void servoOutput(int uS){
myservo.writeMicroseconds(uS);
}
void displayData(int test_no, int s_uS, int e_uS){
lcd.setCursor(1,1);
lcd.print(test_no);
lcd.setCursor(5,1);
lcd.print(s_uS);
lcd.setCursor(11,1);
lcd.print(e_uS);
lcd.print(" ");
}
//////////////////////////////////////////////////////////////////////////////
// This is actually not really used. Added to be able to get Keypad presses //
//////////////////////////////////////////////////////////////////////////////
int read_LCD_buttons(){ // read the buttons
adc_key_in = analogRead(0); // read the value from the sensor
if (adc_key_in > 1000) return btnNONE;
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this.
}
void dispatch_keys(int key){
switch (key){
case btnRIGHT:{
break;
}
case btnLEFT:{
break;
}
case btnUP:{
lcd.print("UP ");
break;
}
case btnDOWN:{
lcd.print("DOWN ");
break;
}
case btnSELECT:{
lcd.print("SELECT");
break;
setup();
}
case btnNONE:{
("NONE ");
break;
}
}
}
{"assets_hash":"a8b26fa7f6e768b07a72c8c9aadb9422","page_data":{"users":{"4741bd143df955007777fc51":{"_id":"4741bd143df955007777fc51","hid":29285,"name":"dROb","nick":"dROb","avatar_id":null,"css":""}},"settings":{"blogs_can_create":false,"blogs_mod_can_delete":false,"blogs_mod_can_hard_delete":false,"blogs_mod_can_add_infractions":false,"can_report_abuse":false,"can_vote":false,"can_see_ip":false,"blogs_edit_comments_max_time":30,"blogs_show_ignored":false,"blogs_reply_old_comment_threshold":30,"votes_add_max_time":168},"entry":{"_id":"543270ce9970730077110c05","hid":19509,"title":"Тестирование моторов+ESC на предрасположенность к потере синхронизации","html":"<p>Код для ардуино. Пояснения и результаты чуть позже.<br>\nОбсуждение: <a href=\"https://rcopen.com/forum/f123/topic380040\" class=\"link link-int link-auto\" data-nd-link-type=\"autolink\" data-nd-link-orig=\"https://rcopen.com/forum/f123/topic380040\">rcopen.com/forum/f123/topic380040</a></p>\n<!--cut-->\n<pre class=\"hljs\"><code>/*************************************************************************************\n Sergey dROb, Oct 2014, \n\n This program will test ESC+motor (or servo), sending range of valid PPM signals to the output pin at "servoPin"\n Primarily, this is used to detect sync issues, happening when Motor is quickly accelerating from low to high speed.\n\n If LCD display is connected - it displays number of test and Start-End microseconds of PPM signal (you can then record, which scenario is problem for your motor)\n\n Connection: Plug the LCD Keypad to the Arduino. Output PPM will be on servoPin. Conect GND and servoPin to ESC.\n Discussion: \n**************************************************************************************/\n\n#include <LiquidCrystal.h>\n#include <Servo.h>\n\nServo myservo; // create servo object to control a servo\n\nLiquidCrystal lcd(8, 9, 4, 5, 6, 7); // select the pins used on the LCD panel\n\nint servoPin = 22;\n\nint lcd_key = 0;\nint adc_key_in = 0;\n\n#define btnRIGHT 0\n#define btnUP 1\n#define btnDOWN 2\n#define btnLEFT 3\n#define btnSELECT 4\n#define btnNONE 5\n\n\nvoid setup(){\n lcd.begin(16, 2);\n lcd.setCursor(0,0);\n lcd.print("Starting motor");\n\n lcd.setCursor(0,1);\n lcd.print("In 3 seconds..");\n myservo.attach(servoPin);\n\n myservo.writeMicroseconds(950); // Init ESC\n\n delay(3000); // Waiting 3 seconds to avoid chopping of user hands\n\n myservo.writeMicroseconds(1250); // Start motor on low speed\n}\n\n\nvoid loop(){\n\n int test_no=1;\n int start_uS;\n int end_uS;\n int tact_delay=1000;\n\n lcd.clear();\n lcd.print("No: Start: End:");\n\n\n // Main cycle - start series of cycles, when motor jumps from set of speeds to higher set of speeds.\n for (start_uS=1100; start_uS<=1900; start_uS+=100){ // Start PPM from which motor will jump to End PPM\n servoOutput(start_uS);\n delay(tact_delay);\n for (end_uS=start_uS+100; end_uS<=1900; end_uS+=100){ // End PPM of the current cycle\n displayData(test_no, start_uS, end_uS);\n\n servoOutput(end_uS);\n tact_delay=end_uS - start_uS; if (tact_delay<400) tact_delay=400;// Intellectual delay. Pause will be bigger if motor have to change the speed a lot. But not less 0.4 sec\n delay(tact_delay);\n servoOutput(start_uS);\n delay(tact_delay);\n test_no++;\n }\n }\n\n lcd.setCursor(0,1);\n\n lcd_key = read_LCD_buttons();\n dispatch_keys(lcd_key);\n}\n\n\nvoid servoOutput(int uS){\n myservo.writeMicroseconds(uS);\n}\n\nvoid displayData(int test_no, int s_uS, int e_uS){\n lcd.setCursor(1,1);\n lcd.print(test_no);\n lcd.setCursor(5,1);\n lcd.print(s_uS);\n lcd.setCursor(11,1);\n lcd.print(e_uS);\n lcd.print(" ");\n}\n\n//////////////////////////////////////////////////////////////////////////////\n// This is actually not really used. Added to be able to get Keypad presses //\n//////////////////////////////////////////////////////////////////////////////\n\nint read_LCD_buttons(){ // read the buttons\n adc_key_in = analogRead(0); // read the value from the sensor\n\n if (adc_key_in > 1000) return btnNONE;\n\n if (adc_key_in < 50) return btnRIGHT;\n if (adc_key_in < 250) return btnUP;\n if (adc_key_in < 450) return btnDOWN;\n if (adc_key_in < 650) return btnLEFT;\n if (adc_key_in < 850) return btnSELECT;\n\n return btnNONE; // when all others fail, return this.\n}\n\n\n\n\nvoid dispatch_keys(int key){\n switch (key){\n\n case btnRIGHT:{\n break;\n }\n case btnLEFT:{\n break;\n }\n case btnUP:{\n lcd.print("UP ");\n break;\n }\n case btnDOWN:{\n lcd.print("DOWN ");\n break;\n }\n case btnSELECT:{\n lcd.print("SELECT");\n break;\n setup();\n }\n case btnNONE:{\n ("NONE ");\n break;\n }\n }\n\n}\n</code></pre>\n","user":"4741bd143df955007777fc51","ts":"2014-10-06T10:37:02.000Z","st":1,"cache":{"comment_count":0},"views":965,"bookmarks":0,"votes":0},"subscription":null},"locale":"en-US","user_id":"000000000000000000000000","user_hid":0,"user_name":"","user_nick":"","user_avatar":null,"is_member":false,"settings":{"can_access_acp":false,"can_use_dialogs":false,"hide_heavy_content":false},"unread_dialogs":false,"footer":{"rules":{"to":"common.rules"},"contacts":{"to":"rco-nodeca.contacts"}},"navbar":{"tracker":{"to":"users.tracker","autoselect":false,"priority":10},"forum":{"to":"forum.index"},"blogs":{"to":"blogs.index"},"clubs":{"to":"clubs.index"},"market":{"to":"market.index.buy"}},"recaptcha":{"public_key":"6LcyTs0dAAAAADW_1wxPfl0IHuXxBG7vMSSX26Z4"},"layout":"common.layout"}