G+_Jim Hofmann Posted September 28, 2016 Share Posted September 28, 2016 I'm dusting off my Lunchbox and would like to automate it with an Arduino. I was able to control the front wheel servo, fairly basic. However, I cannot figure out what kind of signal to use on the Tamiya TBLE-02 ESC. I know it's PWM but what frequency? How does reverse work? 0-127 forward, 128-255 reverse? So confused. I have used Adafruit Motor Shield V1 which used PWM lines for control with forward/reverse. I can "try" using the Adafruit code and see what happens but ... little concerned about letting the magic blue smoke out. Any web sites or tutorials ld be helpful. Thanks Link to comment Share on other sites More sharing options...
G+_Jim Hofmann Posted September 28, 2016 Author Share Posted September 28, 2016 OK, spent way too many hours looking at the AF Motor Shield. Turns out it takes 2 PWM and a couple control lines which are muxed thru a serial to parallel shift register. Don't think that's the answer. SOoo, I took a chance and hooked it up the ESC to the Arduino with a pot & PWM out. 0 to 127 is 100% to 0% forward. 127 being 0%. So 128 to 255 "SHOULD" be 0% to 100% reverse. OK, so on the tranceiver you have to go reverse, neutral then reverse again to get it to backup. Still no movement. I can go forward really fast. Post if I figure it out. CAn't be that hard ... Rrrrightttt. Link to comment Share on other sites More sharing options...
G+_Jim Hofmann Posted October 18, 2016 Author Share Posted October 18, 2016 OK, figured out most of it. My bad. I started with an example from the Servo library, KNOB.ino . Servo, as in 0 to 180 degree not 0 to 255 count. Know your units. That said, I learned a lot more than if it had worked the first time. LOL. After some searching I found this site: . The guy seems very knowledgeable about R/C shtuff. The big clue was he discussed the PWM being 1,000 to 2,000 microseconds with 1,500 microseconds being center. If 2,000 uS is the max the frequency should be 500 Hz. After reading the Arduino site I found the default frequencies are 490. Although, for pins 3 & 11 it says 980 for the Uno and mixed on other boards. I wrote a small program for the Arduino to read the pulse duration using “pulseIn()”. I wired the Arduino to the R/C receiver and measured the duration. It was in the range of 1,000 to 2,000 (ish). Next I add the pulseIn() to the original code and monitored my durations. I found the following command parms worked, map(val1, 100, 100, 145, 45). I modded the program to use analogWrite() instead of myServo.write(). I measured the duration and found the following works, map(val1, -100, 100, 255, 128). I decided to stay with servo code since it is “supposed” to handle any timing issues (pins 3 & 11). Below is the code; / Controlling a servo position using a potentiometer (variable resistor) by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> modified on 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Knob / #include Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int servopin = 9; // servo pin assigned int val; // variable to read the value from the analog pin int val1; // variable to scale the analog pin as +/ 100 percent int val2; // variable to scale the percent to servo degree, 0-180 // int val2; // variable to scale the percent to PWM count, 0-255 int durapin = 7; // read pin for pulse duration unsigned long duration; void setup() { // initialize the serial communication: Serial.begin(115200); myservo.attach(servopin); // attaches the servo on pin 9 to the servo object pinMode(durapin, INPUT); // assign duration read } void loop() { val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) val1 = map(val, 0, 1023, -100, 100); // scale as percent, -100 to 0 (backwards) 0 to 100 (forward) if (val1 >-10 && val1 < 10) val1 = 0; // center deadband val2 = map(val1, -100, 100, 145, 45); // scale it to use it with the servo (value between 0 and 180) val2 = constrain(val2, 0, 180); // deadband // val2 = map(val1, -100, 100, 255, 128); // scale it to use it with the servo (value between 0 and 255) // val2 = constrain(val2, 0, 255); myservo.write(val2); // sets the servo position according to the scaled value // analogWrite(servopin, val2); // sets the servo position according to the scaled value delay(15); // waits for the servo to get there duration = pulseIn(durapin, HIGH); // read pulse duration Serial.print(val); // print pot count value Serial.print("\t"); Serial.print(val1); // print percent Serial.print("\t"); Serial.print(val2); // print servo count Serial.print("\t"); Serial.println(duration); // print duration } Enjoy, Jim arduino.cc - Arduino - Knob Link to comment Share on other sites More sharing options...
Recommended Posts