{"id":555,"date":"2016-03-27T18:44:35","date_gmt":"2016-03-27T23:44:35","guid":{"rendered":"http:\/\/adaming.com\/blog\/?p=555"},"modified":"2016-03-27T18:44:35","modified_gmt":"2016-03-27T23:44:35","slug":"power-upgrade","status":"publish","type":"post","link":"http:\/\/adaming.com\/blog\/index.php\/archive\/power-upgrade\/","title":{"rendered":"Power Upgrade"},"content":{"rendered":"<p>Who wants to drive a slow car? \u00a0Lets soop it up.<\/p>\n<p>To do before buying anything:<\/p>\n<ul>\n<li>Maximum voltage and current for the\u00a0Ardumoto shield\n<ul>\n<li>Based on <a href=\"https:\/\/www.sparkfun.com\/datasheets\/DevTools\/Arduino\/Ardumoto_v13.pdf\">this schematic<\/a>, max voltage is 18V<\/li>\n<li>Recommended voltage is 7-12V, otherwise the voltage regulator could overheat<\/li>\n<\/ul>\n<\/li>\n<li>Power requirements for the motors:\n<ul>\n<li>4.5V and 2A max<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Now buying the batteries:<\/p>\n<ul>\n<li>I wanted to go with 18650 Lithium Phosphate cells because they can deliver a lot of power (20A continuous), are relatively high capacity (2600mAh), come with built-in protection (safer!) and many off the shelf cylindrical battery chargers\u00a0will accept them.\n<ul>\n<li>Looking around, amazon was selling <a href=\"http:\/\/www.amazon.com\/gp\/product\/B00MJ8FFD8?psc=1&amp;redirect=true&amp;ref_=ox_sc_act_title_5&amp;smid=A3S875TZ0N68KJ\">LG cells<\/a> (yay LG). \u00a0Since I spend my days watching videos of LG cells go through a battery of tests (&#8230;ha!), I know these are some of the safest cells on the market. \u00a0Since I&#8217;m not using any sort of battery management system (yet), safety could be a concern.<\/li>\n<li>I noticed there are\u00a0some battery manufacturers which are getting ripped off by Chinese counterfeiters. \u00a0This guy actually <a href=\"http:\/\/www.ebay.com\/gds\/18650-Battery-Buying-Guide-test-on-all-from-eBay-below-3-\/10000000178020340\/g.html\">tested the capacity of the cells<\/a>\u00a0against their claims and rated them in terms of warranty. \u00a0LG cells were the only ones who passed.<\/li>\n<\/ul>\n<\/li>\n<li>Picked up a <a href=\"http:\/\/www.amazon.com\/gp\/product\/B00KBFZDI8?psc=1&amp;redirect=true&amp;ref_=ox_sc_act_title_4&amp;smid=A2WTIW0LCXYF60\">battery charger<\/a> as well. \u00a0It accepts almost all cylindrical format consumer battery cell.<\/li>\n<li>Of course I needed a <a href=\"http:\/\/www.amazon.com\/gp\/product\/B00CQKB5P6?psc=1&amp;redirect=true&amp;ref_=ox_sc_act_title_3&amp;smid=A1V3K7OI49CJC5\">battery holder<\/a>\u00a0to connect these cells in series. \u00a0I&#8217;ll have 1 extra cell just in case.<\/li>\n<li>And finally I&#8217;ll need a power jack so I can plug into the Arduino. \u00a0Surprisingly this took me the longest to choose. \u00a0I was originally was going to go with <a href=\"http:\/\/www.amazon.com\/gp\/product\/B00R1XZ09K?psc=1&amp;redirect=true&amp;ref_=ox_sc_act_title_2&amp;smid=A2TWRNEH2276JE\">something similar<\/a> to what I have, but figured modularity is always best so I went with<a href=\"http:\/\/www.amazon.com\/gp\/product\/B00XJ23U3A?psc=1&amp;redirect=true&amp;ref_=ox_sc_act_title_1&amp;smid=A8GRJU0V6WTPX\">\u00a0cheaper screw terminals<\/a> instead.<\/li>\n<li>In total this cost me $50. \u00a0This is becoming an expensive hobby&#8230;<\/li>\n<\/ul>\n<h2>Power Upgrade Time!<\/h2>\n<p>The batteries came individually packed in the mail. \u00a0They look about the size of shotgun shells.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-559\" src=\"http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160327_172911-300x225.jpg\" alt=\"IMG_20160327_172911\" width=\"300\" height=\"225\" srcset=\"http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160327_172911-300x225.jpg 300w, http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160327_172911-768x576.jpg 768w, http:\/\/adaming.com\/blog\/wp-content\/uploads\/2016\/03\/IMG_20160327_172911-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>I loaded 3 of these in series into a battery holder, and attached the screw terminals. \u00a0After plugging it into the Arduino power sound, I added some new code (see bottom) which I modified to be a more WASD friendly. \u00a0Here is the work in process.<\/p>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/osPRBLmxE5k\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<blockquote><p>&nbsp;<\/p>\n<p>#include<br \/>\nSoftwareSerial BT(4, 5);<br \/>\n\/\/ creates a &#8220;virtual&#8221; serial port\/UART<br \/>\n\/\/ connect BT module TX to D4<br \/>\n\/\/ connect BT module RX to D5<br \/>\n\/\/ connect BT Vcc to 5V, GND to GND<\/p>\n<p>\/\/ Clockwise and counter-clockwise definitions.<br \/>\n\/\/ Depending on how you wired your motors, you may need to swap.<br \/>\n#define CW 0<br \/>\n#define CCW 1<\/p>\n<p>\/\/ Motor definitions to make life easier:<br \/>\n#define MOTOR_A 0<br \/>\n#define MOTOR_B 1<\/p>\n<p>\/\/ Pin Assignments \/\/<br \/>\n\/\/ Don&#8217;t change these! These pins are statically defined by shield layout<br \/>\nconst byte PWMA = 3; \/\/ PWM control (speed) for motor A<br \/>\nconst byte PWMB = 11; \/\/ PWM control (speed) for motor B<br \/>\nconst byte DIRA = 12; \/\/ Direction control for motor A<br \/>\nconst byte DIRB = 13; \/\/ Direction control for motor B<\/p>\n<p>void setup()<br \/>\n{<br \/>\nsetupArdumoto(); \/\/ Set all pins as outputs<\/p>\n<p>\/\/ set digital pin to control as an output<br \/>\npinMode(13, OUTPUT);<br \/>\n\/\/ set the data rate for the SoftwareSerial port<br \/>\nBT.begin(9600);<br \/>\n\/\/ Send test message to other device<br \/>\nBT.println(&#8220;Serial is working correctly&#8221;);<br \/>\n}<\/p>\n<p>char a; \/\/ stores incoming character from other device<br \/>\nint setspeed; \/\/1-255 charecter defining the motor speed<\/p>\n<p>void loop()<br \/>\n{<\/p>\n<p>if (BT.available())<br \/>\n\/\/ if text arrived in from BT serial&#8230;<br \/>\n{<br \/>\na=(BT.read());<br \/>\nBT.println(a);<br \/>\nif (a==&#8217;1&#8242;)<br \/>\n{<br \/>\ndigitalWrite(13, HIGH);<br \/>\nBT.println(&#8220;LED on&#8221;);<br \/>\n}<br \/>\nif (a==&#8217;2&#8242;)<br \/>\n{<br \/>\ndigitalWrite(13, LOW);<br \/>\nBT.println(&#8220;LED off&#8221;);<br \/>\n}<br \/>\nif (a==&#8217;?&#8217;)<br \/>\n{<br \/>\nBT.println(&#8220;Send &#8216;1&#8217; to turn LED on&#8221;);<br \/>\nBT.println(&#8220;Send &#8216;2&#8217; to turn LED on&#8221;);<br \/>\n}<br \/>\n\/\/ you can add more &#8220;if&#8221; statements with other characters to add more commands<\/p>\n<p>if (a==&#8217;w&#8217;) \/\/ FORWARD<br \/>\n{<br \/>\nBT.println(&#8220;FORWARD&#8221;);<br \/>\ndriveArdumoto(MOTOR_A, CCW, 255); \/\/ Motor A at max speed.<br \/>\ndriveArdumoto(MOTOR_B, CCW, 255); \/\/ Motor B at max speed.<br \/>\ndelay(200); \/\/ Drive forward for a second<br \/>\nstopArdumoto(MOTOR_A); \/\/ STOP motor A<br \/>\nstopArdumoto(MOTOR_B); \/\/ STOP motor B<br \/>\n}<\/p>\n<p>if (a==&#8217;s&#8217;) \/\/ BACKWARD<br \/>\n{<br \/>\nBT.println(&#8220;BACKWARD&#8221;);<br \/>\ndriveArdumoto(MOTOR_A, CW, 255); \/\/ Motor A at max speed.<br \/>\ndriveArdumoto(MOTOR_B, CW, 255); \/\/ Motor B at max speed.<br \/>\ndelay(200); \/\/ Drive forward for a second<br \/>\nstopArdumoto(MOTOR_A); \/\/ STOP motor A<br \/>\nstopArdumoto(MOTOR_B); \/\/ STOP motor B<br \/>\n}<\/p>\n<p>if (a==&#8217;a&#8217;) \/\/ RIGHT<br \/>\n{<br \/>\nBT.println(&#8220;RIGHT&#8221;);<br \/>\ndriveArdumoto(MOTOR_B, CCW, 255); \/\/ Set motor B to CCW at max<br \/>\ndelay(200); \/\/ Motor B will spin as set for 1 second<br \/>\nstopArdumoto(MOTOR_B); \/\/ STOP motor B<br \/>\n}<\/p>\n<p>if (a==&#8217;d&#8217;) \/\/ LEFT<br \/>\n{<br \/>\nBT.println(&#8220;LEFT&#8221;);<br \/>\ndriveArdumoto(MOTOR_A, CCW, 255); \/\/ Set motor A to CCW at max<br \/>\ndelay(200); \/\/ Motor A will spin as set for 1 second<br \/>\nstopArdumoto(MOTOR_A); \/\/ STOP motor A<br \/>\n}<\/p>\n<p>}<br \/>\n}<\/p>\n<p>\/\/ driveArdumoto drives &#8216;motor&#8217; in &#8216;dir&#8217; direction at &#8216;spd&#8217; speed<br \/>\nvoid driveArdumoto(byte motor, byte dir, byte spd)<br \/>\n{<br \/>\nif (motor == MOTOR_A)<br \/>\n{<br \/>\ndigitalWrite(DIRA, dir);<br \/>\nanalogWrite(PWMA, spd);<br \/>\n}<br \/>\nelse if (motor == MOTOR_B)<br \/>\n{<br \/>\ndigitalWrite(DIRB, dir);<br \/>\nanalogWrite(PWMB, spd);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ stopArdumoto makes a motor stop<br \/>\nvoid stopArdumoto(byte motor)<br \/>\n{<br \/>\ndriveArdumoto(motor, 0, 0);<br \/>\n}<\/p>\n<p>\/\/ setupArdumoto initialize all pins<br \/>\nvoid setupArdumoto()<br \/>\n{<br \/>\n\/\/ All pins should be setup as outputs:<br \/>\npinMode(PWMA, OUTPUT);<br \/>\npinMode(PWMB, OUTPUT);<br \/>\npinMode(DIRA, OUTPUT);<br \/>\npinMode(DIRB, OUTPUT);<\/p>\n<p>\/\/ Initialize all pins as low:<br \/>\ndigitalWrite(PWMA, LOW);<br \/>\ndigitalWrite(PWMB, LOW);<br \/>\ndigitalWrite(DIRA, LOW);<br \/>\ndigitalWrite(DIRB, LOW);<br \/>\n}<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Who wants to drive a slow car? \u00a0Lets soop it up. To do before buying anything: Maximum voltage and current for the\u00a0Ardumoto shield Based on this schematic, max voltage is 18V Recommended voltage is 7-12V, otherwise the voltage regulator could overheat Power requirements for the motors: 4.5V and 2A max Now buying the batteries: I &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/adaming.com\/blog\/index.php\/archive\/power-upgrade\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Power Upgrade&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/555"}],"collection":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=555"}],"version-history":[{"count":3,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/555\/revisions"}],"predecessor-version":[{"id":560,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/555\/revisions\/560"}],"wp:attachment":[{"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=555"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/adaming.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}