{"id":190,"date":"2017-03-03T19:08:56","date_gmt":"2017-03-03T19:08:56","guid":{"rendered":"http:\/\/ulm.taddug.com\/?p=190"},"modified":"2017-03-13T20:26:25","modified_gmt":"2017-03-13T20:26:25","slug":"arduino-sketch-for-detecting-baud","status":"publish","type":"post","link":"https:\/\/ulm.taddug.com\/index.php\/2017\/03\/03\/arduino-sketch-for-detecting-baud\/","title":{"rendered":"Arduino Sketch for detecting BAUD"},"content":{"rendered":"<p>\/\/name<br \/>\nchar NAME[21] = &#8220;MYPANEL&#8221;;<\/p>\n<p>\/\/ 4 num \u00a0bt code<br \/>\nchar PIN[5] = &#8220;1234&#8221;;<\/p>\n<p>\/*<br \/>\ncodes for BAUD<br \/>\n1 for 1200 bps<br \/>\n2 2400 bps<br \/>\n3 4800 bps<br \/>\n4 9600 bps<br \/>\n5 19200 bps<br \/>\n6 38400 bps<br \/>\n7 57600 bps<br \/>\n8 115200 bps<br \/>\n9 230400 bps<br \/>\nA 460800 bps<br \/>\nB 921600 bps<br \/>\nC 1382400 bps<br \/>\n*\/<br \/>\nchar BAUD=&#8217;7&#8242;;<\/p>\n<p>char response[21]; \/\/ char array<br \/>\nint rv=0; \/\/ return value<br \/>\nint found=0; \/\/ module found<\/p>\n<p>void setup() {<br \/>\nSerial.begin(9600);<br \/>\nSerial.print(&#8220;Setting up BT&#8221;);<\/p>\n<p>\/\/ Search on each of the baud rates<br \/>\nlong baud[12] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400}; \/\/init it<br \/>\nfor(int a = 0; a &lt; 12; a++)<br \/>\n{<br \/>\nSerial.begin(baud[a]);<br \/>\nSerial.write(&#8220;AT&#8221;); \/\/ should get back an &#8220;OK&#8221;<br \/>\nwhile(Serial.available() &lt; 0);<br \/>\nSerial.readBytes(response, 2);<br \/>\nif (strncmp(response, &#8220;OK&#8221;, 2) == 0)<br \/>\n{<br \/>\nSerial.print(&#8220;\\nIt was at \u00a0BAUD: &#8220;);<br \/>\nSerial.println(baud[a]);<br \/>\nfound=1;<br \/>\nbreak;<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nSerial.print(&#8220;.&#8221;);<br \/>\n\/\/Serial.println(baud[a]);<br \/>\n}<br \/>\n}<br \/>\nif (found==0)<br \/>\n{<br \/>\nSerial.println(&#8220;\\nERROR: Blueooth Module not found!&#8221;);<br \/>\nSerial.println(&#8220;BT must NOT be enabled, try again&#8221;);<br \/>\nwhile(1);<br \/>\n}<br \/>\ndelay(100);<br \/>\n\/*<br \/>\nSerial1.write(&#8220;AT+VERSION&#8221;); \/\/ Check the firmware version, because we can<br \/>\nwhile(Serial1.available() &lt; 0);<br \/>\nSerial1.readBytes(response,2);<br \/>\nif (strncmp(response, &#8220;OK&#8221;, 2)==0)<br \/>\n{<br \/>\nrv = Serial1.readBytes(response, 20);<br \/>\nresponse[rv] = 0;<br \/>\nSerial.print(&#8220;BT Module Firmware Version: &#8220;);<br \/>\nSerial.println(response);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nSerial.println(&#8220;Error checking BT Version&#8221;);<br \/>\n}<br \/>\ndelay(100);<\/p>\n<p>Serial1.write(&#8220;AT+NAME&#8221;); \/\/ Set the bluetooth device name<br \/>\nSerial1.write(NAME);<br \/>\nwhile(Serial1.available() &lt; 0);<br \/>\nSerial1.readBytes(response,9);<br \/>\nif (strncmp(response, &#8220;OKsetname&#8221;, 9)==0)<br \/>\n{<br \/>\nSerial.print(&#8220;Setting Name: &#8220;);<br \/>\nSerial.println(NAME);<br \/>\n}<br \/>\nelse<br \/>\n{<br \/>\nSerial.println(&#8220;Error Setting Bluetooth Name&#8221;);<br \/>\n}<br \/>\ndelay(100); \/\/give us time to check all BAUD rates until we find the right one<\/p>\n<p>void loop() {<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/name char NAME[21] = &#8220;MYPANEL&#8221;; \/\/ 4 num \u00a0bt code char PIN[5] = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":262,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-190","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts\/190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/comments?post=190"}],"version-history":[{"count":1,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts\/190\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/posts\/190\/revisions\/191"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/media\/262"}],"wp:attachment":[{"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/media?parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/categories?post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ulm.taddug.com\/index.php\/wp-json\/wp\/v2\/tags?post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}