I am using a GeeeTech voice recognition module, I have recorded my voices using CoolTerm, and imported these voice commands in my sketch. However, when I plug in that voice recognition module, an error gets thrown: avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
; otherwise, it uploads normally. How can the computer and the Arduino lose connection when the voice recognition module gets plugged in? . I have checked my com ports, and checked the everything that it is connected to is correct.
#include <avr/sleep.h>
#include <avr/power.h>
//#include "math.h"
//This sketch is a metronome, in which each led pin shows one beat.
/**************************************/
const int speaker = 13;//speaker at pin 13
int ts = 6;//highest led pin
int count = 3;//"beat 1 pin"
const int keyPin = 11;//button to change time signature
const int keyPinR = 10;//button to change rhythm
const int keySwitch = 2;//sleep mode/wake up button
//All pins below use a pull-up resistor, so the states are inverted
int buttonState = LOW;
int buttonState2 = LOW;
int switchState = LOW;
int silentState = LOW;
int bpm = 120;//you do not need to know this,
//it's just a variable for the potentialmeter to change the tempo
int comdata;
int rthm = 1;//rhythm
int pressed = 0;//
long silent = 0;
byte com = 0; //reply from voice module
/**************************************/
void setup()
{
Serial.begin(9600);
for(int thisPin = 3;thisPin <= ts;thisPin++)
{
pinMode(thisPin,OUTPUT); //initialize thisPin as an output
pinMode(12, INPUT); //potentialmeter for changing tempo
//Pin 9 to 11, along with pin 2, are all push buttons with pull-up resistors
for(int i = 9; i<=11; i++)
{
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
pinMode(2, INPUT);
digitalWrite(2,HIGH);
}
delay(2000);
//imported voice commands
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);
Serial.print("Type in beats per minute");
}
/****************************************/
void loop()
{
turnOn();
getTS();
getVoiceCommand();
}
void turnOn()
{
buttonState = digitalRead(keyPin);//key for
buttonState2 = digitalRead(keyPinR);
switchState = digitalRead(keySwitch);
silentState = digitalRead(9);
if(switchState==LOW) pressed++;
if(pressed!=0)
{
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
attachInterrupt(0, interrupt, LOW);
sleep_cpu();
}
else{
//The beat starts at pin 3, runs in consecutive pins, and ends at pin 8 at maximum
if(buttonState==LOW){//changing time signature - up to 5 beats
ts++;
if(ts==8) ts = 3; //8 - 3 = 5 beats max
}
if(buttonState2==LOW){//changing rhythm - quarter note to eighth, then
//triplets and sixteenths, back to quarter notes
rthm++;
if(rthm==5) rthm = 1;
}
if(silentState==LOW) silent++; //if silent key pressed, go to silence (only LED's showing)
runMetronome();//Run the metronome
}
}
void runMetronome(){
for(int thisPin = 3;thisPin <= ts;thisPin++)
//LED's blinking beats (thisPin - LED pin (beat number + 2))
{
for(int r = 1; r<=rthm; r++){//nested loop for the rhythm
bpm = pulseIn(12, HIGH);//pin 12 - tempo potentialmeter
digitalWrite(thisPin,HIGH);//each LED blinks
pinMode(13,OUTPUT); //pin 13 - speaker
silent%2==0 ? noTone(13) : (count==3 && r==1 ? tone(13,4400,80) :
r==1 ? tone(13,2500,80) : tone(13,2200,60));
delay((bpm-52)/rthm);
digitalWrite(thisPin,LOW);//turn each off as we proceed to the next beat (LED)
pinMode(13,INPUT);//speaker input
}
count++;//beat++
if(count>ts) count = 3; //go back to beat 1
}
}
void interrupt() {
sleep_disable();
detachInterrupt(0);
}
void getTS(){
if(Serial.available()>0){
comdata = Serial.read();
switch (comdata){
case '1': ts = 3; break;
case '2': ts = 4; break;
case '3': ts = 5; break;
case '4': ts = 6; break;
case '5': ts = 7; break;
}
}
}
void getVoiceCommand(){
while(Serial.available()){
com = Serial.read();
switch(com){
case 0x11: ts = 3; break;
case 0x12: ts = 4; break;
case 0x13: ts = 5; break;
case 0x14: ts = 6; break;
case 0x15: ts = 7; break;
}
}
}