Go Down

Topic: HELP NEEDED - Keyboard Instrument (from project book) (Read 1 time) previous topic - next topic

ryanhughes

Hello,

Just started using Arduino his week and so I am working through the project book which came with my starter kit (http://www.arduino.org/products/6-arduino-kits/arduino-starter-kit) .

I followed the schematic and am sure everything's in the right place on the breadboard, my codes looking good and has uploaded to the Arduino.

Here's my problem - only 3 of my 4 buttons are responding. Does anybody know this project? Any advice?

Thanks

tmd3

Because no sketch or schematic is offered, I presume that you've tried to implement this project exactly as the manual describes it.  Is that right?

The link you provided leads, eventually, to this sketch: http://labs.arduino.org/STARTER+KIT+-+KEYBOARD+INSTRUMENT.  Is that exactly the code that you're using?

I can't find a schematic from the link you provided.  I think the schematic looks like this one: http://forum.arduino.cc/index.php?action=dlattach;topic=272327.0;attach=99512.  Is that the schematic that you used?  Please inspect it carefully to verify that it's exactly what you have.

If all that's correct, then the serial monitor should print continuously.  What value does it print when you depress the non-working key?

ryanhughes

Thanks for your help, and yes, I'm trying to run it exactly as in the manual.

The code I'm using is as follows below:

int buttons[0];
int notes[] = {262,294,330,349};
void setup(){
Serial.begin(9600);
}
void loop(){
int keyVal = analogRead(A0);
Serial.println(keyVal);
if (keyVal == 1023){
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010){
tone(8, notes [1]);
}
else if(keyVal >= 505 && keyVal <= 515){
tone(8, notes [2]);
}
else if(keyVal >= 150 && keyVal <= 250){
tone(8, notes [3]);
}
else{
noTone(8);
}
}

You'll notice that it is slightly different to the code you sent but when I tried that it fed back this error message:

avrdude: ser_open(): can't open device "/dev/tty.usbmodem411": No such file or directory
ioctl("TIOCMGET"): Inappropriate ioctl for device
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

The schematic you found is the correct one and I have followed it correctly.

When I depress the non-working key it prints 970 in the serial monitor but I'm afraid that I don't have the skills to interpret what that means!

Thank you again

ryanhughes

Also - sorry, that emoji which has appeared in my code is actually meant to read:

(8);

jurs

Also - sorry, that emoji which has appeared in my code is actually meant to read:

(8);
Learn how to post code within "code tags"!

It is described in the posting "How to use this forum - please read." which is a sticky posting at the top of this forum.

Besides of that: Write down all the 4 values that each button is printing when pressed. I'm no mind reader and cannot guess which one is not working with your code.

ryanhughes

Sorry, I will learn how to post code properly, I will fully read that post now. As I pointed out in my initial post in this feed I've been using Arduino for all of a few days.

The values being printed are:

1023 (working)
1002 (working)
510 (working)
970 (not working)

I wasn't aware they were all relevant as tmd3 had only asked for the non-working one. Afraid I have no idea what any of the info being printed means or refers to though, I guess that the last number should be lower than the one above it, is that right?
 

tmd3

... I'm afraid that I don't have the skills to interpret what that means!
That's great, because this is your chance to acquire those skills.  If you're willing to put in the effort, I'm willing to help.  If you want someone to figure it out for you, then somebody else will help you.

Here's your assignment:
  • Tell us where the value of variable keyVal comes from.
  • Go to the Reference page, here - https://www.arduino.cc/en/Reference/HomePage - and find the function that establishes that value, and read about it.
  • Take one of the values that you find on the serial monitor for a working button, and determine which of the tests in the sketch that it satisfies.  What tone would you expect to hear when that key is depressed?
  • Take the non-working value, and determine which if the tests it satisfies.  Tell us what you find, and what it means.
After that, we'll take a look at how those values are generated by the circuit.

jurs

The values being printed are:

1023 (working)
1002 (working)
510 (working)
970 (not working)
So I suppose this code is working:
Code: [Select]

if (keyVal == 1023){
tone(8, notes[0]);
}
else if(keyVal >= 990 && keyVal <= 1010){
tone(8, notes [1]);
}
else if(keyVal >= 505 && keyVal <= 515){
tone(8, notes [2]);
}


And this code is not working:
Code: [Select]
else if(keyVal >= 150 && keyVal <= 250){
tone(8, notes [3]);
}

because there is no value in the range >=150 and <=250

So what do you think about a change of that to:
Code: [Select]
else if(keyVal >= 960 && keyVal <= 980){
tone(8, notes [3]);
}

to make the value 970 play a tone?

ryanhughes

Thanks so much for your responses both! I'm super busy this week but will get to my assignment ASAP, I'm looking forward to working through your suggestions and solving my keyboard issues.

I'll let you both know how I get on!

ryanhughes

Thanks for referring me to the reference page - I now have a much better understanding of analogRead and the values that it generates.

So when I make the change to the code which jurs suggested the key works and gives the value of 970 which falls between the 2 variables mentioned in that line of code!

Looking at how those values are generated by the circuit would be very useful for future reference.

Go Up