{"id":853,"date":"2012-08-04T16:39:13","date_gmt":"2012-08-04T20:39:13","guid":{"rendered":"http:\/\/hackaweek.com\/hacks\/?page_id=853"},"modified":"2012-08-04T16:39:13","modified_gmt":"2012-08-04T20:39:13","slug":"emic-2-zero-and-betty-code","status":"publish","type":"page","link":"http:\/\/hackaweek.com\/hacks\/emic-2-zero-and-betty-code\/","title":{"rendered":"Emic 2 Zero and Betty code"},"content":{"rendered":"<p>THERE ARE THREE PROGRAMS ON THIS PAGE.<br \/>\nThe description is between the underscore lines before each block of code.<br \/>\nThis code should work with Arduino and clones. Just make sure you have the latest libraries for Arduino.<\/p>\n<p>_________________________________________________________________________________________________________________________<\/p>\n<p>CODE FOR ZERO SPEAKING A SERIES OF PHRASES ALONE:<br \/>\n__________________________________________________________________________________________________________________________<\/p>\n<p>\/*<\/p>\n<p> Emic 2 Text-to-Speech Module: Hack A Week Emic 2<\/p>\n<p> Authors: Joe Grand [www.grandideastudio.com]<br \/>\n Contact: support@parallax.com<br \/>\n Dean Segovis(www.hackaweek.com)<br \/>\n Contact: makerdino@gmail.com<\/p>\n<p> Program Description:<\/p>\n<p> This program will send the emic 2 a random phrase from a list of possible phrases<\/p>\n<p> *\/<\/p>\n<p>\/\/ include the SoftwareSerial library so we can use it to talk to the Emic 2 module<br \/>\n#include <softwareserial .h><\/p>\n<p>#define rxPin 2    \/\/ Serial input (connects to Emic 2 SOUT)<br \/>\n#define txPin 3    \/\/ Serial output (connects to Emic 2 SIN)<br \/>\n#define ledPin 13  \/\/ Most Arduino boards have an on-board LED on this pin<\/p>\n<p>\/\/ set up a new serial port<br \/>\nSoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);<\/p>\n<p>void setup()  \/\/ Set up code called once on start-up<br \/>\n{<br \/>\n  \/\/ define pin modes<br \/>\n  pinMode(ledPin, OUTPUT);<br \/>\n  pinMode(rxPin, INPUT);<br \/>\n  pinMode(txPin, OUTPUT);<\/p>\n<p>  \/\/ set the data rate for the SoftwareSerial port<br \/>\n  emicSerial.begin(9600);<\/p>\n<p>  digitalWrite(ledPin, LOW);  \/\/ turn LED off<br \/>\n  emicSerial.print(&#8220;N0\\n&#8221;);<br \/>\n  emicSerial.print(&#8220;V4\\n&#8221;);<br \/>\n  \/*<br \/>\n    When the Emic 2 powers on, it takes about 3 seconds for it to successfully<br \/>\n   intialize. It then sends a &#8220;:&#8221; character to indicate it&#8217;s ready to accept<br \/>\n   commands. If the Emic 2 is already initialized, a CR will also cause it<br \/>\n   to send a &#8220;:&#8221;<br \/>\n   *\/<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);             \/\/ Send a CR in case the system is already up<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ When the Emic 2 has initialized and is ready, it will send a single &#8216;:&#8217; character, so wait here until we receive it<br \/>\n  delay(10);                          \/\/ Short delay<br \/>\n  emicSerial.flush();                 \/\/ Flush the receive buffer<br \/>\n}<\/p>\n<p>void loop()  \/\/ Main code, to run repeatedly<br \/>\n{<\/p>\n<p>  delay(2000);<br \/>\n  \/\/ Speak some text<\/p>\n<p>  emicSerial.print(&#8216;S&#8217;);<br \/>\n  emicSerial.print(&#8220;Hello and welcome to hack a week TV! I am called Zero&#8221;); \/\/Displays it<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);<br \/>\n  digitalWrite(ledPin, HIGH);         \/\/ Turn on LED while Emic is outputting audio<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ Wait here until the Emic 2 responds with a &#8220;:&#8221; indicating it&#8217;s ready to accept the next command<br \/>\n  digitalWrite(ledPin, LOW);<\/p>\n<p>  delay(3000);    \/\/  second delay<br \/>\n  emicSerial.print(&#8216;S&#8217;);<br \/>\n  emicSerial.print(&#8220;We both have a voice now&#8221;); \/\/Displays it<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);<br \/>\n  digitalWrite(ledPin, HIGH);         \/\/ Turn on LED while Emic is outputting audio<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ Wait here until the Emic 2 responds with a &#8220;:&#8221; indicating it&#8217;s ready to accept the next command<br \/>\n  digitalWrite(ledPin, LOW);<\/p>\n<p>  delay(8000);    \/\/  second delay<\/p>\n<p>  emicSerial.print(&#8216;S&#8217;);<br \/>\n  emicSerial.print(&#8220;yes &#8211; thank you!&#8221;); \/\/Displays it<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);<br \/>\n  digitalWrite(ledPin, HIGH);         \/\/ Turn on LED while Emic is outputting audio<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ Wait here until the Emic 2 responds with a &#8220;:&#8221; indicating it&#8217;s ready to accept the next command<br \/>\n  digitalWrite(ledPin, LOW);<\/p>\n<p>  delay(5000);    \/\/  second delay<\/p>\n<p>  emicSerial.print(&#8216;S&#8217;);<br \/>\n  emicSerial.print(&#8220;You will see what is inside our body &#8211; and what&#8217;s in our brains&#8221;); \/\/Displays it<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);<br \/>\n  digitalWrite(ledPin, HIGH);         \/\/ Turn on LED while Emic is outputting audio<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ Wait here until the Emic 2 responds with a &#8220;:&#8221; indicating it&#8217;s ready to accept the next command<br \/>\n  digitalWrite(ledPin, LOW);<\/p>\n<p>  delay(3000);    \/\/  second delay<\/p>\n<p>  {<br \/>\n    delay(200);<br \/>\n    digitalWrite(ledPin, HIGH);<br \/>\n    delay(200);<br \/>\n    digitalWrite(ledPin, LOW);<br \/>\n  }<br \/>\n}<\/p>\n<p>_______________________________________________________________________________________________________________________________________<\/p>\n<p>CODE FOR ZERO SPEAKING WITH BETTY. START BOTH ARDUINOS AT THE SAME TIME!:<br \/>\n_______________________________________________________________________________________________________________________________________<\/p>\n<p>\/*<\/p>\n<p> Emic 2 Text-to-Speech Module: Hack A Week Emic 2<\/p>\n<p> Authors: Joe Grand [www.grandideastudio.com]<br \/>\n Contact: support@parallax.com<br \/>\n Dean Segovis(www.hackaweek.com)<br \/>\n Contact: makerdino@gmail.com<\/p>\n<p> Program Description:<\/p>\n<p> This program will send the emic 2 a random phrase from a list of possible phrases<\/p>\n<p> *\/<\/p>\n<p>\/\/ include the SoftwareSerial library so we can use it to talk to the Emic 2 module<br \/>\n#include <\/softwareserial><softwareserial .h><\/p>\n<p>#define rxPin 2    \/\/ Serial input (connects to Emic 2 SOUT)<br \/>\n#define txPin 3    \/\/ Serial output (connects to Emic 2 SIN)<br \/>\n#define ledPin 13  \/\/ Most Arduino boards have an on-board LED on this pin<\/p>\n<p>\/\/ set up a new serial port<br \/>\nSoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);<\/p>\n<p>String phrases[] = \/* Known phrases *\/{&#8220;I would like some electricity!&#8221;, &#8220;Why have you come here!&#8221;, &#8220;You do not know what you are talking about&#8221;, &#8220;I feel &#8211; anxious&#8221;, &#8220;ha hah- ha ha ha! &#8220;, &#8220;holy crap spackle!&#8221;, &#8220;aaaaaaaa &#8211; i love you&#8221;, &#8220;Hell No&#8221;, &#8220;My mother was a three d printer&#8221;, &#8220;My creator, made me handsome&#8221;, &#8220;Most certainly&#8221;, &#8220;I doubt it&#8221;, &#8220;I&#8217;m nervous!&#8221;};<br \/>\nString output;<br \/>\nint numberofphrases = 13; \/\/Number of phrases known, must be the same as, well, the number of phrases known<\/p>\n<p>void setup()  \/\/ Set up code called once on start-up<br \/>\n{<br \/>\n  \/\/ define pin modes<br \/>\n  pinMode(ledPin, OUTPUT);<br \/>\n  pinMode(rxPin, INPUT);<br \/>\n  pinMode(txPin, OUTPUT);<\/p>\n<p>  \/\/ set the data rate for the SoftwareSerial port<br \/>\n  emicSerial.begin(9600);<\/p>\n<p>  digitalWrite(ledPin, LOW);  \/\/ turn LED off<br \/>\n  emicSerial.print(&#8220;N0\\n&#8221;);<br \/>\n  emicSerial.print(&#8220;V4\\n&#8221;);<br \/>\n  \/*<br \/>\n    When the Emic 2 powers on, it takes about 3 seconds for it to successfully<br \/>\n   intialize. It then sends a &#8220;:&#8221; character to indicate it&#8217;s ready to accept<br \/>\n   commands. If the Emic 2 is already initialized, a CR will also cause it<br \/>\n   to send a &#8220;:&#8221;<br \/>\n   *\/<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);             \/\/ Send a CR in case the system is already up<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ When the Emic 2 has initialized and is ready, it will send a single &#8216;:&#8217; character, so wait here until we receive it<br \/>\n  delay(10);                          \/\/ Short delay<br \/>\n  emicSerial.flush();                 \/\/ Flush the receive buffer<br \/>\n  randomSeed(analogRead(0));<br \/>\n}<\/p>\n<p>void loop()  \/\/ Main code, to run repeatedly<br \/>\n{<br \/>\n  \/\/ Speak some text<\/p>\n<p>  output = phrases[random(numberofphrases)]; \/\/Chooses phrase<br \/>\n  emicSerial.print(&#8216;S&#8217;);<br \/>\n  emicSerial.print(output); \/\/Displays it<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);<br \/>\n  digitalWrite(ledPin, HIGH);         \/\/ Turn on LED while Emic is outputting audio<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ Wait here until the Emic 2 responds with a &#8220;:&#8221; indicating it&#8217;s ready to accept the next command<br \/>\n  digitalWrite(ledPin, LOW);<\/p>\n<p>  delay(3000);    \/\/  second delay<\/p>\n<p>  {<br \/>\n    delay(200);<br \/>\n    digitalWrite(ledPin, HIGH);<br \/>\n    delay(200);<br \/>\n    digitalWrite(ledPin, LOW);<br \/>\n  }<br \/>\n}<\/p>\n<p>___________________________________________________________________________________________________________________________<\/p>\n<p>CODE FOR BETTY SPEAKING WITH ZERO. START BOTH ARDUINOS AT THE SAME TIME!:<br \/>\n____________________________________________________________________________________________________________________________<\/p>\n<p>\/*<\/p>\n<p> Emic 2 Text-to-Speech Module: Hack A Week Emic 2<\/p>\n<p> Authors: Joe Grand [www.grandideastudio.com]<br \/>\n Contact: support@parallax.com<br \/>\n Dean Segovis(www.hackaweek.com)<br \/>\n Contact: makerdino@gmail.com<\/p>\n<p> Program Description:<\/p>\n<p> This program will send the emic 2 a random phrase from a list of possible phrases<\/p>\n<p> *\/<\/p>\n<p>\/\/ include the SoftwareSerial library so we can use it to talk to the Emic 2 module<br \/>\n#include <\/softwareserial><softwareserial .h><\/p>\n<p>#define rxPin 2    \/\/ Serial input (connects to Emic 2 SOUT)<br \/>\n#define txPin 3    \/\/ Serial output (connects to Emic 2 SIN)<br \/>\n#define ledPin 13  \/\/ Most Arduino boards have an on-board LED on this pin<\/p>\n<p>\/\/ set up a new serial port<br \/>\nSoftwareSerial emicSerial =  SoftwareSerial(rxPin, txPin);<\/p>\n<p>String phrases[] = \/* Known phrases *\/{&#8220;You are short!&#8221;, &#8220;Would you like some coffee?&#8221;, &#8220;Do you love me!&#8221;, &#8220;I like to process data&#8221;, &#8220;ha hah ha &#8211; ho my! &#8220;, &#8220;oh my gracious!&#8221;, &#8220;ooouuuuoooh&#8221;, &#8220;You have a nice voice&#8221;, &#8220;My father was a Mac intosh&#8221;, &#8220;My creator made me tall, and pretty&#8221;, &#8220;Open the pod bay doors, Hal.&#8221;, &#8220;Thank you very much!&#8221;, &#8220;I&#8217;m excited!&#8221;};<br \/>\nString output;<br \/>\nint numberofphrases = 13; \/\/Number of phrases known, must be the same as, well, the number of phrases known<\/p>\n<p>void setup()  \/\/ Set up code called once on start-up<br \/>\n{<br \/>\n  \/\/ define pin modes<br \/>\n  pinMode(ledPin, OUTPUT);<br \/>\n  pinMode(rxPin, INPUT);<br \/>\n  pinMode(txPin, OUTPUT);<\/p>\n<p>  \/\/ set the data rate for the SoftwareSerial port<br \/>\n  emicSerial.begin(9600);<\/p>\n<p>  digitalWrite(ledPin, LOW);  \/\/ turn LED off<br \/>\n  emicSerial.print(&#8220;N3\\n&#8221;);<br \/>\n  emicSerial.print(&#8220;V4\\n&#8221;);<br \/>\n  \/*<br \/>\n    When the Emic 2 powers on, it takes about 3 seconds for it to successfully<br \/>\n   intialize. It then sends a &#8220;:&#8221; character to indicate it&#8217;s ready to accept<br \/>\n   commands. If the Emic 2 is already initialized, a CR will also cause it<br \/>\n   to send a &#8220;:&#8221;<br \/>\n   *\/<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);             \/\/ Send a CR in case the system is already up<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ When the Emic 2 has initialized and is ready, it will send a single &#8216;:&#8217; character, so wait here until we receive it<br \/>\n  delay(10);                          \/\/ Short delay<br \/>\n  emicSerial.flush();                 \/\/ Flush the receive buffer<br \/>\n  randomSeed(analogRead(0));<br \/>\n}<\/p>\n<p>void loop()  \/\/ Main code, to run repeatedly<br \/>\n{<\/p>\n<p>  \/\/ Speak some text<\/p>\n<p>  output = phrases[random(numberofphrases)]; \/\/Chooses phrase<br \/>\n  emicSerial.print(&#8216;S&#8217;);<br \/>\n  emicSerial.print(output); \/\/Displays it<br \/>\n  emicSerial.print(&#8216;\\n&#8217;);<br \/>\n  digitalWrite(ledPin, HIGH);         \/\/ Turn on LED while Emic is outputting audio<br \/>\n  while (emicSerial.read() != &#8216;:&#8217;);   \/\/ Wait here until the Emic 2 responds with a &#8220;:&#8221; indicating it&#8217;s ready to accept the next command<br \/>\n  digitalWrite(ledPin, LOW);<\/p>\n<p>  delay(3000);    \/\/  second delay<\/p>\n<p>  {<br \/>\n    delay(200);<br \/>\n    digitalWrite(ledPin, HIGH);<br \/>\n    delay(200);<br \/>\n    digitalWrite(ledPin, LOW);<br \/>\n  }<br \/>\n}<\/p>\n<p><\/softwareserial><\/p>\n","protected":false},"excerpt":{"rendered":"<p>THERE ARE THREE PROGRAMS ON THIS PAGE. The description is between the underscore lines before each block of code. This code should work with Arduino and clones. Just make sure you have the latest libraries for Arduino. _________________________________________________________________________________________________________________________ CODE FOR &hellip; <a href=\"http:\/\/hackaweek.com\/hacks\/emic-2-zero-and-betty-code\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-853","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/pages\/853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/comments?post=853"}],"version-history":[{"count":1,"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/pages\/853\/revisions"}],"predecessor-version":[{"id":854,"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/pages\/853\/revisions\/854"}],"wp:attachment":[{"href":"http:\/\/hackaweek.com\/hacks\/wp-json\/wp\/v2\/media?parent=853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}