Author Topic: Arduino Calculator  (Read 20773 times)

0 Members and 1 Guest are viewing this topic.

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Arduino Calculator
« on: August 31, 2016, 01:53:59 am »
I want to build a arduino calculator(http://www.instructables.com/id/Arduino-Calculator/) oh btw, i'm not going to make the case, i will just use the circuit. so, heres the scematic(http://www.instructables.com/files/orig/FCD/XDN2/HXII577Q/FCDXDN2HXII577Q.ino) i want this to make a beep every time that any button is pressed.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Arduino Calculator
« Reply #1 on: August 31, 2016, 02:56:05 am »
I want to build a arduino calculator(http://www.instructables.com/id/Arduino-Calculator/) oh btw, i'm not going to make the case, i will just use the circuit. so, heres the scematic(http://www.instructables.com/files/orig/FCD/XDN2/HXII577Q/FCDXDN2HXII577Q.ino) i want this to make a beep every time that any button is pressed.

Show and tell is all well and good, but did you have a question?
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #2 on: August 31, 2016, 04:21:38 am »
I want to build a arduino calculator(http://www.instructables.com/id/Arduino-Calculator/) oh btw, i'm not going to make the case, i will just use the circuit. so, heres the scematic(http://www.instructables.com/files/orig/FCD/XDN2/HXII577Q/FCDXDN2HXII577Q.ino) i want this to make a beep every time that any button is pressed.

Show and tell is all well and good, but did you have a question?
i want this to make a beep every time i press any button
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Arduino Calculator
« Reply #3 on: August 31, 2016, 04:35:32 am »
Ok, so what have you tried.

You need

   1. To decide how you will make the sound, will you use a passive piezo, an active buzzer, a speaker, an MP3 player, a servo dinging a bell...
   2. How you will drive that thing that makes the sound, do you need a waveform, can you just set a pin high/low
   3. Locate the place in the code that the keypad is being read and insert code to accomplish 2.

it's not a complex problem, if people were to just tell you "put code X on line 98 and connect device Y to pin N" you would not learn anything.
 
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 

Offline jeroen79

  • Frequent Contributor
  • **
  • Posts: 529
Re: Arduino Calculator
« Reply #4 on: August 31, 2016, 04:39:30 am »
i want this to make a beep every time i press any button
You're still not asking a question, you just state what you want. ;)
Try formulating it like "How can I..." and add a ? at the end.

I'm not just trying to make fun of you.
If you want help then you will get it quicker if you put some effort in communicating what exactly it is you need.
For example, do you need help creating a beep?
Or with handling the buttom presses?
What do you have so far?
 
The following users thanked this post: tooki

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #5 on: August 31, 2016, 05:18:47 am »
ok sorry about not explaining it properly. so how can i make a piezo buzzer to make a beep every time i press a button? what part of the code do i need to change?
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #6 on: August 31, 2016, 05:22:55 am »
BTW, is it possible to use a I2C LCD? It can decrease the mess of wires.
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3024
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: Arduino Calculator
« Reply #7 on: August 31, 2016, 05:27:16 am »
ok sorry about not explaining it properly. so how can i make a piezo buzzer to make a beep every time i press a button? what part of the code do i need to change?

How about you start by making a piezo buzzer buzz using your Arduino.  The tone() Arduino function can accomplish this for you. 

~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 
The following users thanked this post: BillyD

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #8 on: August 31, 2016, 05:44:28 am »
ok sorry about not explaining it properly. so how can i make a piezo buzzer to make a beep every time i press a button? what part of the code do i need to change?

How about you start by making a piezo buzzer buzz using your Arduino.  The tone() Arduino function can accomplish this for you.
No offence but you can be very infuriating.
 

Offline george.b

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: br
Re: Arduino Calculator
« Reply #9 on: August 31, 2016, 05:52:32 am »
No offence but you can be very infuriating.

You seem pretty lazy. No offense, of course.

:popcorn:
 
The following users thanked this post: ludzinc

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #10 on: August 31, 2016, 05:57:03 am »
Ok so i have tried to connect to a I2C LCD. Here's the code. The two middle rows of the keypad won't work. Any idea why? also, disregard the info on how to connect the lcd to arduino. (sorry for any non professionalism)
 
The following users thanked this post: ludzinc

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #11 on: August 31, 2016, 05:58:17 am »
And please don't judge my ability in writing code,  :( i am terrible at it.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #12 on: August 31, 2016, 06:07:35 am »
ok sorry about not explaining it properly. so how can i make a piezo buzzer to make a beep every time i press a button? what part of the code do i need to change?

How about you start by making a piezo buzzer buzz using your Arduino.  The tone() Arduino function can accomplish this for you.
So the thing is, i can make a buzzer buzz, i just don't know where to put that piece of code. the code for the calculator is complicated, so where do i actually put the buzzer code?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #13 on: August 31, 2016, 06:16:13 am »
Did you try reading the code?
Hint: there is a line commented // read keypad

Follow Sleemanj's advice, but beware: If no key is pressed,  you must avoid triggering the buzzer after a keypad read!
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #14 on: August 31, 2016, 06:29:18 am »
Did you try reading the code?
Hint: there is a line commented // read keypad

Follow Sleemanj's advice, but beware: If no key is pressed,  you must avoid triggering the buzzer after a keypad read!
??? i tried that, here's the code
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #15 on: August 31, 2016, 06:55:30 am »
Presumably you intended to start the buzzer with line 148:
Code: [Select]
    digitalWrite(8, LOW);and stop it at line 195 with:
Code: [Select]
    digitalWrite(8, HIGH);but line 195 is deep within a set of nested if() statements handling the 'D' key, so I suspect your buzzer is jamming on.

The end of the if(key != NO_KEY) block is actually at line 278:
Code: [Select]
          ++length;
        }
      }
   }  // << HERE (278)
}

/////////////////////Function Returns Modulo Even for Negative Numbers//////////////////////////
and that is where you'd want to either stop buzzing after a timer delay, or simply stop buzzing using an else for no key pressed.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #16 on: August 31, 2016, 07:03:14 am »
umm not sure what you mean...
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #17 on: August 31, 2016, 07:20:32 am »
In that case, you need to learn how to program properly in C.  A copy of K&R and some practice writing console programs using a PC C compiler, will help considerably.  Technically Arduino code is written in C++, but most usrr programs stick to the 'vanilla' C subset of C++ and C is a lot simpler to learn than C++.

You'll also probably want to use a better editor than the Arduino IDE, as its brace matching is buggy and it doesn't support code folding so its a PITA to work with poorly structured programs with lots of multi-page flow control structures.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #18 on: August 31, 2016, 07:37:17 am »
ok, i am in the process of learning the c language already. but please can someone stop making this like a puzzle and actually tell me what i have to do??? |O |O if you don't want to come out and actually tell me what to do, don't reply to this post. >:( :horse:
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Arduino Calculator
« Reply #19 on: August 31, 2016, 07:54:46 am »
just read that piece of code you posted. this is very flat and basic C, it is very easy to read and could be a good starting point for your learning curve. You cannot expect to get an answer what to type where here, because the reason of most if not all people being here is the curiosity of how things are made up and tied together.
We Are The Watt - Resistance Is Futile!
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #20 on: August 31, 2016, 08:02:47 am »
just read that piece of code you posted. this is very flat and basic C, it is very easy to read and could be a good starting point for your learning curve. You cannot expect to get an answer what to type where here, because the reason of most if not all people being here is the curiosity of how things are made up and tied together.
first of all, easy for you to say, you probably studied c in univirsity or something. secondly, r u saying people dont know the answer to my question? cause it seems like people like you know it pretty well. as i said, if you dont want to give an answer, then leave my thread.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: Arduino Calculator
« Reply #21 on: August 31, 2016, 08:07:55 am »
ok, i am in the process of learning the c language already. but please can someone stop making this like a puzzle and actually tell me what i have to do??? |O |O if you don't want to come out and actually tell me what to do, don't reply to this post. >:( :horse:
Solving puzzles is the whole point of programming. If you just want a calculator and don't want to figure it out then why not just go and buy one?

just read that piece of code you posted. this is very flat and basic C, it is very easy to read and could be a good starting point for your learning curve. You cannot expect to get an answer what to type where here, because the reason of most if not all people being here is the curiosity of how things are made up and tied together.
first of all, easy for you to say, you probably studied c in univirsity or something. secondly, r u saying people dont know the answer to my question? cause it seems like people like you know it pretty well. as i said, if you dont want to give an answer, then leave my thread.
The purpose of this forum is not to simply give out answers (although people often just do that) but to help you figure it out for yourself.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #22 on: August 31, 2016, 08:18:12 am »
ok, its clear that no one is willing to properly help me. does anyone know a different forum where i can actually get some solid answers?
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Arduino Calculator
« Reply #23 on: August 31, 2016, 08:41:35 am »
you probably studied c in univirsity or something.
Not exactly. Started this on my own in 1984 aged 15, using books and magazines that I bought from my pocket money. By the way, neither the internet nor eevblog existed then.
We Are The Watt - Resistance Is Futile!
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #24 on: August 31, 2016, 08:42:36 am »
I also taught myself C, from the original K&R book back in '85, entering my code on an 8 bit home computer and compiling from tape using an integer only compiler.  Back then, unless you were studying computer science, you'd most likely be taught FORTRAN for a programming component of an engineering degree, and needing to pass a course for your grades is normally a very poor motivation for learning a programming language properly.

I pointed out what I believe to be the problem with your code and suggested where to turn the buzzer off to fix it.  As you haven't given a better description of the problems you are having other than 'don't understand' and 'doesn't work', there is little more we can do other than refer you to:

How To Ask Questions The Smart Way - Catb.org

Don't expect anything except total scorn from any programmers' forums if you cant frame your questions intelligently, and aren't prepared to dig into the code, manually trace its flow and hand annotate a listing of it till you understand it.  If you just want someone to code it for you, there are numerous sites that let you commission coding projects for money - if you don't mind a 3 or 4 figure USD bill.
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Arduino Calculator
« Reply #25 on: August 31, 2016, 08:47:46 am »
We Are The Watt - Resistance Is Futile!
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Arduino Calculator
« Reply #26 on: August 31, 2016, 08:49:36 am »
back in '85, entering my code on an 8 bit home computer and compiling from tape
[shake hands smiley missing]was that by incident the same computer as mine -> C64?
We Are The Watt - Resistance Is Futile!
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #27 on: August 31, 2016, 08:50:19 am »
ok, caus some people dont understand :-- :-- :--: i want a buzzer to beep when a button on the keypad is presssed, and i want to use a i2c lcd instead of a normal one.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #28 on: August 31, 2016, 08:52:24 am »
u guys are impossible, you like keeping me in the dark?
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Arduino Calculator
« Reply #29 on: August 31, 2016, 08:53:54 am »
Just a warning - if you take this problem and attitude to the Arduino forum, you'll be in tears by the morning.

Perhaps a better approach, if you 'want it now', would be to offer a $reward and take the conversation offline...
Don't ask a question if you aren't willing to listen to the answer.
 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Arduino Calculator
« Reply #30 on: August 31, 2016, 08:58:40 am »
u guys are impossible, you like keeping me in the dark?
we like helping you help yourself.
We Are The Watt - Resistance Is Futile!
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: Arduino Calculator
« Reply #31 on: August 31, 2016, 08:59:20 am »
ok, its clear that no one is willing to properly help me. does anyone know a different forum where i can actually get some solid answers?
Go to electro-tech-online. These sort of questions seem to be the norm there.
http://www.electro-tech-online.com/
 
The following users thanked this post: skillz21

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #32 on: August 31, 2016, 09:01:20 am »
u guys are impossible, you like keeping me in the dark?
we like helping you help yourself.
i noticed
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #33 on: August 31, 2016, 09:07:00 am »
Just a warning - if you take this problem and attitude to the Arduino forum, you'll be in tears by the morning.

Perhaps a better approach, if you 'want it now', would be to offer a $reward and take the conversation offline...
are u asking for money?
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #34 on: August 31, 2016, 09:40:24 am »
 :-\ can someone please tell me how i can make it beep and how i can use the i2c protocol? i have no idea how to do it :-//.
« Last Edit: August 31, 2016, 09:57:00 am by skillz21 »
 

Online EEVblog

  • Administrator
  • *****
  • Posts: 37740
  • Country: au
    • EEVblog
Re: Arduino Calculator
« Reply #35 on: August 31, 2016, 11:00:43 am »
:-\ can someone please tell me how i can make it beep and how i can use the i2c protocol? i have no idea how to do it :-//.

1) Get one of these:
http://www.jaycar.com.au/pc-mount-buzzer-3-30v/p/AB3458

2) Hook it up to a spare pin on the Arduino

3) Insert a few lines of code into the routine that reads the keypad so it drives that pin high for short while and then back low.
https://startingelectronics.org/articles/arduino/connecting-buzzer-arduino-uno/
 

Offline Electro Fan

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino Calculator
« Reply #36 on: August 31, 2016, 11:01:48 am »
Ok, I think you just want "the answer" which is a reasonable thing to want from your standpoint but no one that is here so far* seems likely to give it to you - at least not under your current approach.  I don't know if the approach I suggest here will work but you might give it a try.

Edit:  *while I was drafting Dave just posted a pretty direct suggestion, so there's something good to go on

When you make your next post try giving at least as much information as you are asking for.  For example, you could say "I am trying to accomplish specifically X and I have done 1, 2, 3, and 4.  And since 1 and 2 enabled me to do 3 and 4 I can't see why X isn't happening.  I tried using both "" around each line like it says in the the Programmming Bible by Nobel Prize Winner Johnson and I also tried () around each line, and neither helped.  Does anyone know if the problem is with the characters I'm using to enclose each line, or if I should be looking at some other possible cause?  Thanks!"  Or something like that. 

The idea here is to show that 1 you have done some work, 2 you have done some research and you tried to make your work consistent with some principle you learned somewhere, 3 you have made at least one hypothesis about what has gone wrong and you tested the hypothesis, 4 you are confused by some logic that indicates your approach should work, 5 you have tried to narrow down the possible solution to this or that, 6 you are willing to do some more work if someone would kindly point you in a good direction, and 7 say thanks.

You might not need all 7 steps but if you give this a try you might get enough assistance that you will be able to solve your problem and learn something along the way.

Having said all that I realize that you are probably saying to yourself "if someone would just give me the answer (any answer that works) I could apply the answer, see it work, and then by seeing it work I will likely learn what went wrong and therefore understand and learn something new simply from observing the fix being put in place".  This might be true but unless you managed to get the "here it is answer" from someone fairly early on in the thread you might be stuck because the crowd dynamic has shifted from talking tech to making a point about who has power. (People might not acknowledge that it has anything to do with power; most will insist it is all about being Socratic or intellectual or educational, etc - and it probably is in many if not most cases, but some of it is ego and some of it is occasionally just the power to make people grovel.)

The vast majority of folks here are kind and helpful but once in awhile some may come across as slightly strident or rigid.  As a result, sometimes it's just a matter of how the first post in a thread comes across, how the first reply sets a tone in response to the OP, and then how the mood of the crowd starts out on a thread - and then it evolves from there.  My observation is that when it comes to EE-related topics EEVblog probably has as many helpful and friendly and smart people as you will find anywhere on the Internet, so I think you are in a very good place to learn and exchange ideas about EE overall.  And generally the Beginners forum is an easy place to get help but for some reason when the questions are about code the approach to Q&A stiffens a bit vs other topics.  My theory on this is that coders tend to think of coding as being more about logic being developed and applied and extended, and less about the underlying facts that simply yield a result. I'm sure coders often enjoy the destination but I think they often want to ensure other (especially new) coders fully experience and appreciate the journey.  I could be wrong about this theory (I'm sure we'll hear about it here shortly) but it's a guess.  It might partially explain why someone earlier in this thread said something to the effect of "if you think it's tough here, wait 'til you try the coding forum".

Anyway, don't get too frustrated, don't take things too personally, stay persistent but flexible enough to adapt, and hopefully something in here will help you get the answer to your current question(s) and maybe help you with more questions and projects down the road.
« Last Edit: August 31, 2016, 11:45:24 am by Electro Fan »
 
The following users thanked this post: janoc, edy

Online EEVblog

  • Administrator
  • *****
  • Posts: 37740
  • Country: au
    • EEVblog
Re: Arduino Calculator
« Reply #37 on: August 31, 2016, 11:05:02 am »
as i said, if you dont want to give an answer, then leave my thread.

It's not "your thread". People are trying to help you in their own way, be nice to them and it will reap benefits.
 

Offline Electro Fan

  • Super Contributor
  • ***
  • Posts: 3199
Re: Arduino Calculator
« Reply #38 on: August 31, 2016, 11:57:05 am »
more ideas - less theoretical, more direct, but probably still require some study

Beep

http://www.hobbytronics.co.uk/arduino-tutorial7-piezo-beep

I2C





Buzzer and I2C

Overview | Arduino Lesson 10. Making Sounds | Adafruit Learning System
https://learn.adafruit.com › overview
Dec 12, 2012 - In this lesson, you will learn how to make sounds with your Arduino. First you will ... Piezo Buzzer ... This stackable design is easy to use and requires only 2 I2C pins on any Arduino.
Arduino sound effects need assistance - Stack Overflow
Stack Overflow › questions › arduino-so...
Apr 11, 2014 - Arduino sound effects need assistance ... if there are any ways to put them inside arduino and play them in a buzzer. ... How can I initiate I2C transmission on the same Arduino board?
« Last Edit: August 31, 2016, 12:13:03 pm by Electro Fan »
 

Offline Rick Law

  • Super Contributor
  • ***
  • Posts: 3441
  • Country: us
Re: Arduino Calculator
« Reply #39 on: August 31, 2016, 04:46:13 pm »
ok, caus some people dont understand :-- :-- :--: i want a buzzer to beep when a button on the keypad is presssed, and i want to use a i2c lcd instead of a normal one.

Skillz21,  what is your background?

Don't let coding intimidate you.  C is not so difficult to self-taught.  Like learning the piano, it doesn't take so long to play a tune - it does take a long time to get to the point of being of "Concert-Quality".

Folk here seem to be more the "man vs machine" kind - you know, want to control the machine.  To do that, you need to know how the machine works.  Folks here are not trying to be frustrating to you -- rather they are trying to push you towards the way that works in our collective experiences.  Most here are very helpful, but very few (if any) are aspiring teachers.  Collectively, we are not so patient to do step-by-step teaching in an arena such as a forum.

If you are just trying to make it beep, it doesn't take "concert quality".  You merely need to "poke around" the piano key board (the codes), see what it does and learn from it.

If I may suggest, start with looking at the Arduino IDE's examples.  The simple ones link "blink" - look up digitalWrite() and see what it is suppose to do, look up the delay() and see what it does, so forth.  Look up general C syntax.  As you come across keywords such as the -for- or the -int-, you can again look it up and see what it is suppose to do.

In my view, it is so darn satisfying once you got it figured out and get it to do what you want to do.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #40 on: August 31, 2016, 04:53:03 pm »
just read that piece of code you posted. this is very flat and basic C, it is very easy to read and could be a good starting point for your learning curve. You cannot expect to get an answer what to type where here, because the reason of most if not all people being here is the curiosity of how things are made up and tied together.
first of all, easy for you to say, you probably studied c in univirsity or something. secondly, r u saying people dont know the answer to my question? cause it seems like people like you know it pretty well. as i said, if you dont want to give an answer, then leave my thread.

OK, I would put the entire buzz code right after the key is first detected and before it is processed.

So, right after:
  if (key != NO_KEY)
  {

Exactly where you put:
    digitalWrite(8, LOW);


Do the entire beep right there.  Maybe put a delay(25) between turning the beep on and turning it off.

Here is a page describing how to get a beep out of a piezo, if that is what you are using:
http://www.hobbytronics.co.uk/arduino-tutorial7-piezo-beep

For a piezo, there's a little more to it than just setting a pin low and then setting it high.  If you are using a buzzer then then turn it on, delay(25) and turn it off.
« Last Edit: August 31, 2016, 05:09:52 pm by rstofer »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #41 on: August 31, 2016, 05:08:47 pm »
I2C is hard, a lot harder than any other protocol.  So, Google around for projects and copy whatever you can find.  The Arduino site itself has a discussion about I2C and LCD displays:

http://playground.arduino.cc/Code/LCD
or
https://www.arduino.cc/en/Reference/Wire

There is example code in the Arduino IDE at File -> Examples -> Wire -> master-writer.

If the code you have works with the display you have and you aren't running out of pins, I would pass on using I2C and build up some confidence first.  I would rather use SPI or parallel than try to get I2C working.

Always try Google first!  You will not be the first person on the planet with a particular problem and all of human knowledge is accessible from Google. Seriously!  I always look there first.  I don't always use the proper search terms and it sometimes takes a bit of rewording but, sooner or later, the answer shows right up.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #42 on: August 31, 2016, 05:12:52 pm »
If you wonder why I point you in a direction rather than write some code, it's simple.  I can't test it!  I won't put code out there that I have personally tested.
 
The following users thanked this post: Ian.M

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino Calculator
« Reply #43 on: August 31, 2016, 08:01:54 pm »
 Seems to me most everyone here IS trying to help in teh best possible way. Hints but not the complete solution. If someone jsut posts some code and says "put these lines HERE int eh calculator program" then when you go to make your next project that also has some button inputs and you want a beep on keypress, you'll have to ask someone for the exact code again. If you poke around a little and discover the solution on your own, next time you will find it faster. And the next time after that - even faster.
 When I was in university, they taught us FORTRAN. Every other language I ever learned, I did so on my own. Usually starting with the available tutorials (and there are TONS of them for Arduino) and then taking the tutorial example and adding extra stuff to it to see what happened. That's how you learn No one is being a smartass about this, they speak the truth.
 I recently got an I2C LCD to use with Arduino. I downloaded the library and for a first step tried one of the examples that came with the library. It displayed garbage, not the pattern that was expected. Had to poke through the code to see what was different about what it was configured to use and how I connected my LCD, but I found it and made it work. Then I added he important parts of that code to my own project for which I needed a display, and added the appropriate code to display the text I needed on selection of each of my options (the selection part was working, evidenced by the LED connected in place of the relays I was waiting for lighting up for each selection - I just wanted to add a text display instead of just light up an LED, plus the second line of the display functions as a menu for the input pushbuttons). Now I know how to do this for other projects as well. For the most part you aren't going to damage anything if your code is not right the first time, but by seeing that B happens when you intended for A to happen will guide you tot he line fo code where the mistake is. Look up the keywords and verify that you have the right parameters, int eh right order, and you haven't made dumb typos like I do, putting , when you need . or vice versa. And it's C++ - make sure you have the ; at the end of each line. This is all part of the learning process. No, your first working example won't be the most ideal code, but after it works successfully is when you go back and look at the little tricks for optimizing things to see if you can get the same job done with fewer lines, and faster.
 Now, if you post a 5 line segment of code and someone responds with "you suck, everyone knows you can do this with one line" then I'd argue that that person is being an unhelpful jackass. The RIGHT approach, knowing your skill level, would be to say something like "that's great, but if you use <feature or capability X> you can reduce your code to fewer lines - give it a try". That's not being unhelpful, that's trying to help you out and increase your knowledge of the programming language.

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #44 on: August 31, 2016, 09:53:06 pm »
There's nearly 500 lines of code in that file.  It's too long to read through and 99% of it is irrelevant to the problem at hand.  All those calculations and stuff just obscure what is really the issue.

As a recommendation, post the fewest possible lines of code to demonstrate the problem.  Nobody really cares what happens after the key is identified, the beep function needs to occur right as the key is being read.

When it comes time to rewrite that code, consider a switch() statement like:

Code: [Select]
switch(key) {
  case 'a' : do something;
                break;
  case 'b' : do something else;
                break;
  default  : there is probably an error;
                break;
}

I wouldn't prefer the string of if statements.  It takes compute cycles to evaluate all of the possibilities on the way down the chain.
 

Offline SL4P

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
  • There's more value if you figure it out yourself!
Re: Arduino Calculator
« Reply #45 on: August 31, 2016, 10:19:33 pm »
Not sure if OP is still lurking around, but even blindly trying things would have realised some sort of result by now...

Given that many here could have 'solved' this in minutes, the OP has spent 24 hours feeling hard done by, when he could have solved his initial problem - and - learned something.

BTW, no- I wasn't looking for money previously, but that's often the case when you walk unknown into a group and ask a room full of strangers to do something for you on 'their' time...  try that in a bar!
If you ask "where's the men's room"... that's free!
Don't ask a question if you aren't willing to listen to the answer.
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Arduino Calculator
« Reply #46 on: August 31, 2016, 10:37:42 pm »
Always fun to see my Keypad library in the wild!
You've got some pointers now skillz21 and the suggestion made by rstoffer is the solution you will most likely want to follow.

I wish you good luck on your programming! We've all been beginners at some point, but the only way to advance from that is to take each challenge as an opportunity to learn :)
 

Offline obiwanjacobi

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Arduino Calculator
« Reply #47 on: September 01, 2016, 10:31:44 am »
"Don't copy code you don't understand."
Now you know why.

But -in the OPs defence- the code is not written very clear. It's a typical flat C approach that you see so often.

OP: You could refactor the code (change its strucutre) by trying to decipher parts of the loop function (where I would start) and move that to other functions that get a name that describes its purpose/function. That way you'll end up with a loop function that reads like a script and only has some flow control in there. If you want to know about a piece, just look at the function that is being called. You can do this until all code is located in (a very short) function that tells you exactly what it does.

It would be most benificial if you would have some sort of Unit test in place. But embedded software usually does not have that. These Unit tests would verify if the units of the software (keypad, calculator, display etc) are still functioning correctly. That way you would know instantly if your refactorings broke something that worked before...

Do worry about the overhead - the compiler should be able to generate adequate assembly for your c code.

Good luck.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #48 on: September 01, 2016, 10:50:52 am »
just read that piece of code you posted. this is very flat and basic C, it is very easy to read and could be a good starting point for your learning curve. You cannot expect to get an answer what to type where here, because the reason of most if not all people being here is the curiosity of how things are made up and tied together.
first of all, easy for you to say, you probably studied c in univirsity or something. secondly, r u saying people dont know the answer to my question? cause it seems like people like you know it pretty well. as i said, if you dont want to give an answer, then leave my thread.

OK, I would put the entire buzz code right after the key is first detected and before it is processed.

So, right after:
  if (key != NO_KEY)
  {

Exactly where you put:
    digitalWrite(8, LOW);


Do the entire beep right there.  Maybe put a delay(25) between turning the beep on and turning it off.

Here is a page describing how to get a beep out of a piezo, if that is what you are using:
http://www.hobbytronics.co.uk/arduino-tutorial7-piezo-beep

For a piezo, there's a little more to it than just setting a pin low and then setting it high.  If you are using a buzzer then then turn it on, delay(25) and turn it off.
finally a solid answer, thank you so much. I will try it out. Thanks once more! :)
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1611
  • Country: gb
Re: Arduino Calculator
« Reply #49 on: September 01, 2016, 12:26:49 pm »
skillz21, 

I just read the entire thread, you had many people running around after you until one held your hand and told you exactly what you need to do.  This is all well and good if you're not an engineer, have no interest in how things work, and just want something done for you.  I don't think anyone has 'intentionally kept you in the dark', they have simply not spent their valuable time explaining everything in fine detail.. although a couple actually did and that seemed to anger you.

Many people post here with problems they have, or questions about things they don't fully understand after thinking about it and googling for some time.  A quick google would have provided all the answers you needed, as long as you actually thought about the problem, which I'm not sure you did.

Picking a project that involves something you cannot do is a great way to learn, but we don't just sit staring at a blank page, then write code (ok, some of us do..) you think about what needs to be done, and ways to achieve it, breaking it down into smaller problems that you can work through, testing it as you go.  Posting on a forum then throwing your toys out of your pram when someone doesn't say exactly what you want to hear isn't a great way to elicit assistance.  You have to remember that in many forums, people have read thousands of 'I want x' posts from people who just post a pseudo-question before they've even tried to do anything, then never return.  Often they don't even know what they want to achieve, but find comfort in posting a question because it makes them feel like they're getting something done. It gets very frustrating for those who have taken the time to try to help, to see beginners cobbling bits of code together, that they haven't even bothered to think about.
 

Offline BillyD

  • Regular Contributor
  • *
  • Posts: 218
  • Country: ie
Re: Arduino Calculator
« Reply #50 on: September 01, 2016, 01:12:46 pm »
just read that piece of code you posted. this is very flat and basic C, it is very easy to read and could be a good starting point for your learning curve. You cannot expect to get an answer what to type where here, because the reason of most if not all people being here is the curiosity of how things are made up and tied together.
first of all, easy for you to say, you probably studied c in univirsity or something. secondly, r u saying people dont know the answer to my question? cause it seems like people like you know it pretty well. as i said, if you dont want to give an answer, then leave my thread.

OK, I would put the entire buzz code right after the key is first detected and before it is processed.

So, right after:
  if (key != NO_KEY)
  {

Exactly where you put:
    digitalWrite(8, LOW);


Do the entire beep right there.  Maybe put a delay(25) between turning the beep on and turning it off.

Here is a page describing how to get a beep out of a piezo, if that is what you are using:
http://www.hobbytronics.co.uk/arduino-tutorial7-piezo-beep

For a piezo, there's a little more to it than just setting a pin low and then setting it high.  If you are using a buzzer then then turn it on, delay(25) and turn it off.
finally a solid answer, thank you so much. I will try it out. Thanks once more! :)

With respect, there were quite a few solid answers before this one which you chose to ignore and, in at least one case, direct an insult at the person who helped you.

This might be enough to get you through this assignment but in the longer term you might want to rethink the way in which you approach problem solving and dealing with people.

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #51 on: September 01, 2016, 04:10:49 pm »
Here's a suggestion:  If you think the beep idea I mentioned above is worthwhile for your project, try it out on a 10 line program.  Don't try it out on a 500 line program.  I always write my code in bits and pieces and string them together later on when I understand how the components will work.

I would get the beep working.  Then I would get the LCD working, separately.  Then I would look around for other chunks and get them working.  Finally, I would stitch them together.  And I would save the sample bits, they will  come in handy in the future.

Overall, the process is know as Top Down Design (start with the big idea at the top) and Bottom Up Coding (write the device drivers first).  Build up from the foundation.  There is also a process known as 'step-wise refinement' (Niklaus Wirth).  Get something working, improve it and try again.

True story:  When I first learned FORTRAN back in '70, I had a fellow trying to help me get started.  I knew what I wanted to do but I had no idea how to do it.  I had seen the computer but I hadn't dared touch it!  He mentioned vectors and arrays and I felt like the stupid step-child.  He might as well have been on a different planet.  I simply didn't have the background, at that particular moment, to understand what he was saying.

So, he stuck with me for another hour or so and I finally caught on.  First you crawl, then you walk and finally you run!  And I bought some books...  Still have them, 46 years later!  Once the light comes on, all this stuff becomes clear.

 

Offline edy

  • Super Contributor
  • ***
  • Posts: 2385
  • Country: ca
    • DevHackMod Channel
Re: Arduino Calculator
« Reply #52 on: September 01, 2016, 06:51:06 pm »
I read through the whole thread as well. I agree with some of the comments regarding posts that ask for answers that otherwise seem apparent. I guess the main issue is the OP admits to not having much coding experience, and thus getting over their head with a project that requires coding experience to debug (in case anything goes wrong) and not showing that they even attempted to solve the problem.

As far as the code goes, I would just look a bit into the main loop where it says under "//read keypad" there is a line that says "if (key != NO_KEY)". I would simply add ANOTHER line just before that which handles the beep:

if (key != NO_KEY) then BEEP!!!!

So if there is NOT a NO_KEY press (double negative meaning something *IS* pressed) then just do your beeping there. The program then continues on to the remaining code and asks the question again (the if NO_KEY thing) and handles whatever it needs to handle.

Of course, the BEEP sub-routine will have to be figured out. You need to make a small test program to see how you are going to implement it, on what pins, and how.

This calculator program is not hard, but if you know little about coding then it will look like a daunting task. First step is to make SMALL PROGRAMS to blink LED's, accept button inputs, make buzzers work, etcetera. Then do keypad reading (this Calculator seems to be using a matrix-style approach to figure out the rows and columns to read in the keys, with a loop).

Like a previous post mentioned, without us having the same setup as you, and spending the time to configure it all the same, we would not know if our solution even is correct or if there is another bug somewhere. You would be running in circles if you are just looking for answers. For any such problem you need to be able to debug and work on it independently quite a bit and learn along the way, for your own good.

YouTube: www.devhackmod.com LBRY: https://lbry.tv/@winegaming:b Bandcamp Music Link
"Ye cannae change the laws of physics, captain" - Scotty
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #53 on: September 01, 2016, 09:11:39 pm »

This calculator program is not hard, but if you know little about coding then it will look like a daunting task. First step is to make SMALL PROGRAMS to blink LED's, accept button inputs, make buzzers work, etcetera. Then do keypad reading (this Calculator seems to be using a matrix-style approach to figure out the rows and columns to read in the keys, with a loop).

Like a previous post mentioned, without us having the same setup as you, and spending the time to configure it all the same, we would not know if our solution even is correct or if there is another bug somewhere. You would be running in circles if you are just looking for answers. For any such problem you need to be able to debug and work on it independently quite a bit and learn along the way, for your own good.

And there is no way in the world a newcomer is capable of working on a 500 line chunk of code.  That was my point with the FORTRAN story.  It might as well come from an another planet!

It's sometimes too easy for those of us who have written tens or hundreds of thousands of lines of code to remember where we began.  My first experience was humiliating!  I remember it vividly!

If there is going to be a beep() function, the call might as well come right after the existing IF statement.  Whether buzzer or piezo, a function is the way to go but that implies a little more coding skill.  Not a lot and there are certainly examples but when you start from nothing, everything is a challenge.

 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino Calculator
« Reply #54 on: September 02, 2016, 12:53:59 am »
 I said much the same in my reply. Start small, add on. Build a program that makes the beeper sound, Then make it make the beeper sound when a button is pushed. Try the examples that comes with various libraries, like the one for the I2C LCD. That's how I figured out how to use an I2C LCD. Then take each of those small known to work bits and start combining to build up the final project.
 You are absolutely right, a rank beginner is going to look at a 500 line program and just glass over. If you don't know the basics, you can't see how all that code works together. Byte sized (ha!) chunks is the way to go. It's the way the tutorials are set up even, and every book I ever learned from, going back to when I first learned BASIC on the TRS-80 Model 1, my first experience at programming. And I'm always learning - I'm relatively new to Arduino. C, I taught myself a long time ago, but rarely ever used it, so this is like a whole new thing. Granted, once you know another language or two, adding more is much easier than the initial learning of the first one, but it's not like I opened the box and started creating 500-100 line projects. I'm building up to the final products I want to make with Arduinos, not trying to solve world peace on my first day.

 

Offline tatus1969

  • Super Contributor
  • ***
  • Posts: 1273
  • Country: de
  • Resistance is futile - We Are The Watt.
    • keenlab
Re: Arduino Calculator
« Reply #55 on: September 02, 2016, 09:17:28 am »
I agree to the point that it is difficulty to start learning a programming language with a piece of code that had not been made for educational purposes, and is neither very structured nor heavily commented. But I am convinced that this is not the road block that the OP is facing here, because of several reasons:

- one of my sons, aged 13, is very (too) much computer affine, but has no experience in any programming language. I would say he has learned most about computers playing Minecraft, going into the deepest depth of redstone magic. But he wants to learn a programming languague, and about three weeks ago I showed him how to start with Visual C++. That ended with a small console program that would print out something, but only if the right key is entered. Pretty close to the beep problem here  ;) I showed the 'calculator.txt' file to him. After skipping a few pages on the screen, he immediately identified that 'if (key != NO_KEY)' as the place to start.

- the OP seemed to get upset immediately after the first posters suggested to gain more programming and Arduino knowledge that would help him find the solution himself.

- he apparently has put that hardware project together, connected the additional buzzer, and figured out that 'digitalWrite(8, ..);' manipulates it. He talks about having tried out things, so he will also have the toolchain up and running. So he had already put quite some things together, facing the effort and showing the ability to learn there.

He also seems to have left this thread after he got the answer he expected, which text to put into which line.
We Are The Watt - Resistance Is Futile!
 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Arduino Calculator
« Reply #56 on: September 02, 2016, 07:32:08 pm »
 Perhaps true, but some people have the logical organization to immediately pick up on programming type problems and some do not. The first group is like your son, and somewhat myself. The second group - they aren't going to figure out anything staring at a complex program but that doesn't mean they can't learn to program. They just need to go about it differently.
 There seems to be a high correlation between musical ability and mathematical ability - makes sense since music is highly mathematical - well, I'm one of the exceptions. As long as a piece is not too complex, I can read sheet music, but actually tell you what it means? Or listen to a key being struck on a piano and tell you what note? Or that this note is exactly 1 octave higher than that note? Not a clue. I can use CAD or various hand tools and draw schematics, scientific diagrams, or mechanical drawings, but I couldn't draw a picture of a cat if my life depended on it.

 No, based on another thread the OP started, I think he was looking for someone to do his homework for him. Thus the rejection of all hints without giving the exact answer as people being harsh and unhelpful. Back in college I tutored for the FORTRAN class all engineers had to take back then. It was pretty easy to tell who was coming because they actually wanted to learn how to do the work and who just wanted to be shown the answer. I've carried that through in other forums I participate in, I tend to not immediately post just the answer, but as simple an explanation as I can come up with on how to derive the answer. A good example, it's fairly common in model railroading when using DCC control to use white LEDs for headlights and so forth, and with standard DCC voltages the correct value for a current limiting resistor is 1K. Unless you need to dim the LED down for some reason, 1K is pretty much always the answer - you net about 9ma through a 20ma peak LED< perfectly in the safe zone. But when someone posts the question of what resistor do I need, I don't just reply with 1K - I put in a short explanation of Ohms Law and how you GET 1K as an answer. Hopefully the poster learns something and when they need to use the same LED but with a 5V power supply they can figure out that 1K is too much and calculate a correct value.

 
 

Online Brumby

  • Supporter
  • ****
  • Posts: 12298
  • Country: au
Re: Arduino Calculator
« Reply #57 on: September 03, 2016, 12:57:15 am »
Agreed.

Sometimes giving direct answers without imparting understanding is a bad thing.  The inquirer may take the answer given for a particular set of parameters and then try to apply it in a completely different - and inappropriate - scenario.  This could end up with damaged components or people.

.... and the blame will most probably be laid at our feet - something that tends to go with impatient and demanding attitudes.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #58 on: September 03, 2016, 02:00:06 am »
Ok, i finally got the beep working. so now i have the problem of the two middle rows of the keypad not working. any idea why?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #59 on: September 03, 2016, 02:11:55 am »
I believe you are using a 3rd party keyboard library, so the most likely causes of problems are:
- Your code isn't handling the returned keypress value correctly so some values have no effect
- You've tried to use some I/Os needed for the keypad for other purposes
- your keypad has a hardware fault.

Make a copy of your current code (sketch) and strip out all the calculator stuff.  Replace it with code to simply display the last key pressed.   If that works for all the keypad rows, the bug is in the calculator code, otherwise its hardware or an I/O conflict.  Carefully make a list of what's using each I/O pin of the ATmega328P - Caution: some I/O pins go to more than one pin on the Arduino headers.  If you dont find any conflicts, check that any initialisation code that runs after the keypad initialisation doesn't change any of the keypad pins.
« Last Edit: September 03, 2016, 03:15:42 am by Ian.M »
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #60 on: September 03, 2016, 02:55:28 am »
i changed the code a bit so that i dont have to use the i2c. then i realised if i used the original code, i would not have enough i/o pins for the buzzer. so i changed the code to use less of the pins on the lcd, (using D0, D1, D2, D3 instead of D0, D1, D2, D3, D4, D5, D6, D7) the lcd didnt display anything at all. i tried using this hello world code.
#include <LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 13, 8, 9, 10, 11);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {
  lcd.setCursor(0, 1);
  lcd.print(millis() / 1000);
}
once again, it didn't work, am i just missing something?
oh yeah, with the keyboard, it works perfectly, i tried it with a sketch, and the buzzer beeped every time i pressed a key.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #61 on: September 03, 2016, 03:11:25 am »
I changed the code a bit so that i dont have to use the i2c. then i realised if I used the original code, I would not have enough i/o pins for the buzzer. so I changed the code to use less of the pins on the lcd, (using D0, D1, D2, D3 instead of D0, D1, D2, D3, D4, D5, D6, D7) the lcd didn't display anything at all.
...
Oh yeah, with the keyboard, it works perfectly, I tried it with a sketch, and the buzzer beeped every time I pressed a key.
Hitachi HD44780 compatible LCD 4 bit mode uses D7 - D4, with D3 - D0 left unconnected.

Glad to hear the keypad's OK.  It sounds like there is either an initialisation conflict or a problem with the calculator key handling code.
« Last Edit: September 03, 2016, 03:14:54 am by Ian.M »
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #62 on: September 03, 2016, 03:38:47 am »
ok it works perfectly now! (without i2c)
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #63 on: September 03, 2016, 04:02:00 am »
On an Arduino Uno R3  the dedicated SDA and SCL pins next to AREF on the top left header are also wired to A4 and A5 on the bottom right header.  If you were attempting to use A4 and A5 for the keypad, hardware I2C using the Wire library would have caused a conflict with the keypad library.
« Last Edit: September 03, 2016, 04:03:58 am by Ian.M »
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #64 on: September 03, 2016, 04:13:49 am »
i was using the dedicated SDA and SCL pins
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #65 on: September 03, 2016, 04:33:36 am »
... but were you also trying to use A4 and A5 as that doesn't work?
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #66 on: September 03, 2016, 05:33:44 am »
... but were you also trying to use A4 and A5 as that doesn't work?
I can't use A4 and A5 as they were being used by the keypad.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #67 on: September 03, 2016, 05:40:44 am »
A4 and A5 are connected to the same ATmega328P pins as SDA and SCL.  If you are using SDA and SCL for I2C, you *C*A*N*N*O*T* use A4 and/or A5 for *A*N*Y*T*H*I*N*G* else!
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #68 on: September 03, 2016, 03:11:07 pm »
So, I went looking for the Uno schematic.  The first I found didn't show the dual use of A4 and A5, it didn't show the I2C connections at all.

This version clearly shows that A4 and A5 are used as SDA and SCL respectively:
http://download.arduino.org/products/UNO/Arduino-UNO-Rev3e-SCH.pdf

When you read a user manual for the chip, you may find these pins referred to by their port/pin as PC4 and PC5.  Just to toss in a little more confusion...
 
The following users thanked this post: Ian.M

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #69 on: September 04, 2016, 04:32:10 am »
A4 and A5 are connected to the same ATmega328P pins as SDA and SCL.  If you are using SDA and SCL for I2C, you *C*A*N*N*O*T* use A4 and/or A5 for *A*N*Y*T*H*I*N*G* else!
Woah... ok, that explains it.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #70 on: September 04, 2016, 04:35:05 am »
Thanks so much guys i finally got the calculator fully working with i2c. one last problem though, the lcd backlight doesn't light up, it lights up with the normal code (without i2c).
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Arduino Calculator
« Reply #71 on: September 04, 2016, 06:45:17 am »
How is the backlight controlled?
Without your current schematic and code we can only guess.  It  could be another conflict like the one between the I2C pins and the keypad middle rows, or maybe, due to the complexity of the calculator code, you've made a mistake and its never reaching the routine that turns the backlight on.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Arduino Calculator
« Reply #72 on: September 04, 2016, 03:06:40 pm »
Check whatever documentation you have for the LCD and see if there is a command sequence required to turn on the backlight.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #73 on: September 05, 2016, 09:38:21 am »
Here's the code i'm currently using. (once again, ignore the info at the top, i am using i2c)
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Arduino Calculator
« Reply #74 on: September 05, 2016, 09:53:15 am »
Rw_pin and rowPins[0] are the same. The same is true for D7_pin and colPins[1] and D6_pin and colPins[2].
Does it currently work?
« Last Edit: September 05, 2016, 09:55:27 am by alexanderbrevig »
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #75 on: September 05, 2016, 10:05:50 am »
Rw_pin and rowPins[0] are the same. The same is true for D7_pin and colPins[1] and D6_pin and colPins[2].
Does it currently work?
So right now, it's working fine. Do those pins actually take up the ones on the Arduino? I thought they might be some sort of virtual pins or something...
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Arduino Calculator
« Reply #76 on: September 05, 2016, 10:10:04 am »
So right now, it's working fine. Do those pins actually take up the ones on the Arduino? I thought they might be some sort of virtual pins or something...
Glad to hear!  :-+

Regarding the pins, I presume you have wired them? :)
They are used to scan the keypad matrix. 8 Pins for 16 keys.
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #77 on: September 07, 2016, 08:24:39 am »
So right now, it's working fine. Do those pins actually take up the ones on the Arduino? I thought they might be some sort of virtual pins or something...
Glad to hear!  :-+

Regarding the pins, I presume you have wired them? :)
They are used to scan the keypad matrix. 8 Pins for 16 keys.
yes i have wired them
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #78 on: September 08, 2016, 07:15:07 am »
any ideas guys?
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Arduino Calculator
« Reply #79 on: September 08, 2016, 01:50:12 pm »
 

Offline skillz21Topic starter

  • Frequent Contributor
  • **
  • Posts: 311
  • Country: au
Re: Arduino Calculator
« Reply #80 on: September 12, 2016, 08:49:55 am »
So right now, it's working fine.
any ideas guys?
Ideas about what exactly?
the backlight, the calculator is working fine, but is there a way to turn on the backlight?
 

Offline alexanderbrevig

  • Frequent Contributor
  • **
  • Posts: 700
  • Country: no
  • Musician, developer and EE hobbyist
    • alexanderbrevig.com
Re: Arduino Calculator
« Reply #81 on: September 12, 2016, 09:45:50 am »
Have you still wired pin 3 to the LCD? :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf