Help with Arduino..! - Page 1
Forum section: electronics / general

author: Mr1234kaki
author_rank: Contributor
timestamp: September 05, 2012, 07:11:55 am
content: My attempt to build a push button counter with interrupt,It didnt work though, im not good at programming please help me out, =)What im trying to do is , i dsplay the initial value at 25 on the lcd displaythen when i push the interrupt button, i will move to the counter functionthe counter will then calculate how many time i have push the button and add the value to the intial 25, x = pushcounter +25then i will stop the counter function and return to the main loop function and displaying the new value after being added with pushcounter valueswe will have three button for return, interupt, and counterCheers! Thanks in advance

author: shebu18
author_rank: Frequent Contributor
timestamp: September 05, 2012, 07:44:17 am
content: What you are trying to do has a example in the IDE. Search there, using the interrupt is a bit complicated.

author: poorchava
author_rank: Super Contributor
timestamp: September 05, 2012, 08:12:24 am
content: This will sound as an attempt to troll a person (well, it kinda is):Get a real microcontroller. You will not learn programming microcontrollers by using Arduino. When you'll go for a job interview, the recruiter will ask you what programming environments you know and your response will be 'Arduino' the recruiter will most likely perform an action commonly abbreviated as "ROTFL".You learn Arduino - you know ArduinoYou learn C - you can program ANY microcontroller when you get the datasheet (or other corresponding document like 'programming reference')

author: shebu18
author_rank: Frequent Contributor
timestamp: September 05, 2012, 08:45:41 am
content: If you do not have programming courses in school then arduino is a good starting point and a easy way to make contact with the world of uC. After some time you will get curious about the other chips and you will want to learn the rel C.

author: Mr1234kaki
author_rank: Contributor
timestamp: September 05, 2012, 09:02:27 am
content: lol, i learnt C languane and C++, but im not that advance to debug the coding, i did what i know and stuck..im not very good at logic things i guess..

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: September 05, 2012, 09:55:45 am
content: this guy explains how to do ithttp://www.dave-auld.net/index.php?option=com_content&view=article&id=107:arduino-interrupts&catid=53:arduino-input-output-basics&Itemid=107though you seem to have grabbed similar code anyway.Start with his code and gradually adapt it to suit your purposes, on step at a time.Check you have working code at each change.You cant go wrong...

author: Simon
author_rank: Unknown
timestamp: September 05, 2012, 11:43:31 am
content: I believe the arduino will take straight C if you sent it to it. The problem I have with arduino is that it is so similar to C they might as well have made it a C environment instead of reinvent the wheel. If I tried to learn both I'd end up getting confused. I'll learn C, once I know that I'll be in full control. The statements made by the arduino designers is a load of bollocks, if they really wanted a simple environment that even artists can use they would have used basic not C as C is not at all intuitive but basic is very easy to pick up fo simple artistic needs.

author: madires
author_rank: Super Contributor
timestamp: September 05, 2012, 02:00:59 pm
content: Quote from: Simon on September 05, 2012, 11:43:31 amActually it's (nearly) C++ and the wheel wasn't reinvented. The IDE is just a nice GUI for avr-gcc and avrdude including a simple editor. It also includes a lot of libs and convenience stuff to hide some of the hardware in an abstraction layer for the starters. If you wish you can do anything the hardcore way :-) At most schools and universities students start with Pascal or Java as first programming language. C++ isn't far off but still nearer to the hardware. Arduino hides most of C++ in the libs. So the user isn't bothered too much with it, until he starts writing libs. Starting programming with Basic isn't a good idea for most students, since they have to learn C anyway later on. And if they started with Basic they have to dismiss any programming habits to cope with Pascal/Java/C.

author: Simon
author_rank: Unknown
timestamp: September 05, 2012, 03:45:10 pm
content: My Basic comment was for artists wanting to flash a light, basic is far more suitable for them.Everything seems to run on C, The book I read about arduino programing that cwas a rubbish book anyway was essentially teaching some basic c with some of the features hidden.

author: madires
author_rank: Super Contributor
timestamp: September 05, 2012, 09:25:05 pm
content: Quote from: Simon on September 05, 2012, 03:45:10 pmQuick and dirty :-)QuoteYep, C rulez :-) But if someone wants to develop software for MCUs professionally he should study two different MCU architectures incl. programming in assembler at least. Otherwise he doesn't know what could be gained by choosing the appropriate MCU and using different programming techniques. A lot of EEs treat MCUs like black boxes. If one isn't fast enough they throw a more powerful one at the problem. With time and cost contraints it's obviously the "save" way to go, but a faster MCU doesn't help with bad code always.

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 06, 2012, 02:15:57 am
content: if you think you can create a better world with Basic then go for it and prove it, dont mourn about another. there are reasons why C is a buzz and used by many. if Basic is an artist drawing with pencil, C is an artist drawing with colors. thats my 2cnts analogy. and if someone say Arduino IDE is not C then its just plain stupid they should go back and learn more, just as if someone say i'm not writing in english right now (broken or your majesty english is another story). Arduino is C just a poor implementation due to struggle to encapsulate and making it easier... by another artists.

author: westfw
author_rank: Super Contributor
timestamp: September 06, 2012, 04:52:35 am
content: (You'll get more help, less complaining, and less digression; if you ask your question on the Arduino Forums athttp://arduino.cc)I suspect that the LCD functions are not callable from within interrupts. The usual technique would be to have the ISR function read the buttons and update some global variables, and then have the non-ISR loop go and redisplay those values whenever they've changed.

author: Unknown
author_rank: Unknown
timestamp: September 07, 2012, 11:34:50 pm
content: I believe Arduino is both good and bad; good in that they can allow people with limited experience to get-up-and-running very quickly; But they are evil because they abstract too many important fundamentals of the system design process. They're supposed to be aimed at artists - I'm an artist and I find Arduino quite confusing! why do they call source-code a sketch? I don't call my oil paintings software! ;-)

author: Simon
author_rank: Unknown
timestamp: September 08, 2012, 06:19:01 am
content: C is a serious programming language and is not intuitive. If you have no programming knowledge and look at a C program it will mean nothing at all. I find that it is too compact personally as it just makes no sense unless you know what it is and commenting will be very very important. Basic on the other hand can be pretty much understood if you can deal with logic statements but are not knowledgeable of programing. That is much more suited to artists etc who are not interested in programming. If your into programig and making the most of it you'll probably want to do it in C but the mission statement of the arduino completely conflicts with what it is !

author: Rerouter
author_rank: Super Contributor
timestamp: September 08, 2012, 08:14:13 am
content: to me writing arduino code isnt all that different to tying up most of your functions in a library, and as a somewhat begginner at micro code (only had limited understanding of visual basic) i must say it atleast allowed me to start in the right riection, as now i am more and more making direct calls to the hardware while still skipping things it has helped me to better understand it all :/

author: mtkaalund
author_rank: Contributor
timestamp: September 08, 2012, 08:31:23 am
content: The arduino project is a fine attempt to get the masses to do some electronics, but for the arduino framework, in my personally opinion not suitable for development a finished product, but more as a quick 'n' dirty prototyping.When you are finished with the quick 'n' dirty part, you can just reprogram it using C for avr, flash the chip by using avr-dude, then you got a relativity cheap development board, that is as good as the STK-500.As it is, I would not use interrupts in the arduino framework, I would go an use avr-gcc when testing interrupts.

author: Simon
author_rank: Unknown
timestamp: September 09, 2012, 08:50:29 pm
content: Quote from: mtkaalund on September 08, 2012, 08:31:23 ambut it's more about programming and easy lazy programming. like you say it's for the masses, that statement in itself assumes over ease and poor real usability that they will need to see a way out of and into real electronics. Why should I develop my product twice ?

author: Mr1234kaki
author_rank: Contributor
timestamp: September 10, 2012, 04:55:10 am
content: Quote from: westfw on September 06, 2012, 04:52:35 amThank you! i got it now!

author: psycho0815
author_rank: Regular Contributor
timestamp: September 10, 2012, 12:02:38 pm
content: I really don't see why anyone would have a problem with the arduino ide/language.if you don't want to use the shortcuts they provide, you can just feed it straight C.the code is eventually compiled by avr-gcc anyway, so you can just use the basic avr c-lib.You can even skip the whole arduino stuff, alltogether and program the chip via your normal avr-gcc/avrdude toolchain by using the isp-header.You should even be able to upload a .hex file via usb using the arduino bootloader.And if you don't like C at all, i don't see why one couldn't use bascom-avr as a language.So basically the arduino is just a really cheap prototyping board, or at least that's how i view it.However i agree that the way it's marketed for non-electronics-people, it would have made more sense to use something like basic as a language.

author: Simon
author_rank: Unknown
timestamp: September 10, 2012, 12:04:21 pm
content: Quote from: psycho0815 on September 10, 2012, 12:02:38 pmYou basically just agreed with me

author: JuiceKing
author_rank: Regular Contributor
timestamp: September 10, 2012, 02:49:51 pm
content: I got the interrupts to work in a project where I needed to read a keypad. The first key-press would invoke the interrupt handler, which would scan the keyboard for the expected sequence of key presses.Details with code are here:https://www.eevblog.com/forum/projects-designs-and-technical-stuff/arduino-metronome-with-keypad-input/msg133329/#msg133329I don't know how you implemented your button, but make sure that it's not left floating when left open... I pulled mine up and then had the keypad buttons ground the input line, so I tested for a falling edge to invoke the interrupt.- Ken

author: psycho0815
author_rank: Regular Contributor
timestamp: September 10, 2012, 04:24:50 pm
content: Quote from: Simon on September 10, 2012, 12:04:21 pmWell English is not my first language, but i think that's what "i agree" usually means isn't it?

author: Mechatrommer
author_rank: Super Contributor
timestamp: September 10, 2012, 04:54:29 pm
content: Quote from: psycho0815 on September 10, 2012, 04:24:50 pmit means the guy agreed for a moment just before, but now not anymore.

author: Simon
author_rank: Unknown
timestamp: September 10, 2012, 05:13:36 pm
content: Quote from: Mechatrommer on September 10, 2012, 04:54:29 pmOh your giving English lessons now ? God help us.Saying that someone agrees with me is not the same as saying I agree with them. The one agreeing acknowledges that the other holds their view also, having already laid it out on the table.

author: JuiceKing
author_rank: Regular Contributor
timestamp: September 10, 2012, 05:59:16 pm
content: Quote from: madires on September 05, 2012, 02:00:59 pmI'm really glad they did it this way. BASIC is a very poor language in general, and would be especially bad for an embedded controller: no pointer arithmetic, no concept of a stack/scoped variables, no or very weak bitwise operators...I'm surprised, though, that there is no mention of struct or malloc in the Arduino Language Reference, which are very important features of C. Are they allowed by the compiler?

author: innot
author_rank: Newbie
timestamp: September 10, 2012, 08:29:08 pm
content: Quote from: JuiceKing on September 10, 2012, 05:59:16 pmYes, the "Arduino compiler" is just a plain, somewhat older avr-gcc, so it will accept every legal C or C++ code.Actually the only thing the Arduino IDE does with ".ino" sketches is to add an "#include <arduino.h>" at the top of the file and then pass it on to the compiler. The IDE also looks at the other includes to determine which libraries the sketch uses and copies the code for these libraries to the temporary working directory for compiling and linking with the transformed sketch.The Arduino core framework is a static library which gets linked in as well as the normal avr-libc, so all functions of the avr-libc are available.The Arduino core also has the main() function, so the sketches don't need one. But this main() is really simple, basically it just containsCode:main() {init(); // Set up the arduino hardware, mainly the timerssetup(); // call the setup function of the sketchwhile(true) {loop(); // call the loop function of the sketch}}I am just finishing a slightly more complex Arduino project, driving a stepper and a few motors, written in plain C++ and a bit of C, using the Eclipse IDE with the AVR Plugin instead of the overly simplistic Arduino IDE. Other than the lack of the main() function and the use of some Arduino convenience functions (Serial port stuff and the digitalWrite() functions) it should be indistinguishable from any other AVR project. It even uses Timer interrupts which are not supported by the Arduino Framework (which was a bit of a struggle because the Arduino core assumes it has full control over the timers for its PWM stuff).That malloc(), structs and other stuff is not documented in the Arduino Reference Library is probably deliberate. They target beginners and the use of these "advanced" features is bound to cause problems for novices. For my project I had some trouble with dynamically created C++ Objects (the C++ way of mallocing structs) causing memory fragmentation so I removed them and made every Object static, which is much more predictable and deterministic in such a limited environment.