Arduino Project. - Page 1
Forum section: electronics / projects

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 11, 2013, 08:22:10 pm
content: Hey guys i got my arduino mega today but i have no idea how to write a simple sketch.I just want the arduino to send a 1 on the serial monitor everytime the button is being pressed.I think its very simple but i dont know how to do it.......so i will need a site that has tutorials so that i can get into arduino.... for good.Thank you.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 11, 2013, 08:39:36 pm
content: or...http://arduino.cc/en/Tutorial/ReadASCIIString

author: Chet T16
author_rank: Frequent Contributor
timestamp: February 11, 2013, 08:46:57 pm
content: Quote from: ChrisGreece52 on February 11, 2013, 08:22:10 pmWhat button?

author: johnboxall
author_rank: Unknown
timestamp: February 12, 2013, 04:43:41 am
content: Quote from: ChrisGreece52 on February 11, 2013, 08:22:10 pmhttp://arduino.cc/en/Tutorial/HomePagehttp://tronixstuff.com/tutorialsRemember - you don't learn by asking people to do it for you.

author: smashedProton
author_rank: Frequent Contributor
timestamp: February 12, 2013, 06:09:55 am
content: -jeremy blum tutorials-blink sketch-serial communication-spi-i2cthen start making shit!another cool recourse is the morse code tutorial onlineVery interesting codeAfter you get the basics, try and do something interesting like a Fourier transform?

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 12, 2013, 12:56:59 pm
content: Quote from: tronixstuff on February 12, 2013, 04:43:41 amRight i would like to learn by experimenting my own.Thats why i told my problem and asked for sites that i could learn from.

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 12, 2013, 12:57:42 pm
content: Quote from: smashedProton on February 12, 2013, 06:09:55 amI thought of learning morse code too

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 12, 2013, 05:37:21 pm
content: Hi i tried to follow a tutorial of jeremy blum and i ended up with an error.I dont know why but when i write "else if " and try to upload it i get this errorsketch_feb12a.ino: In function 'void loop()':sketch_feb12a:18: error:'else' without a previous 'if'I had this problem with other projects too help me plz.Here is my code.Code:int ledPin = 13;void setup(){pinMode(ledPin , OUTPUT);Serial.begin(9600);}void loop(){while (Serial.available() == 0);int val = Serial.read() - '0';{if (val == 1)Serial.println("LED IS ON");digitalWrite(ledPin, HIGH);}else if (val == 0){Serial.println("LED IS OFF");digitalWrite(ledPin , LOW);}else {Serial.println("Invalid");}}

author: c4757p
author_rank: Super Contributor
timestamp: February 12, 2013, 05:39:27 pm
content: The problem is exactly what it says. Go through your code and fix the indentation, then read it again.Remember that an "if" only takesone single statementas the code to run conditionally. The {} braces are not actually part of the "if" - they just group multiple statements together into one so that thegroupcan be run conditionally. It's like parentheses in an equation.Code:if (false)a;b;That will skipaand runb.Code:1: if (x)2: a;3: b;4: else5: c;The "if" statement there is just lines 1 and 2. 3 is outside it, so when the compiler gets to 4 ("else"), there is noactive"if" statement for it to attach it to. Proper indentation of that code would be:Code:1: if (x)2: a;3: b;4: else5: c;

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 12, 2013, 05:44:17 pm
content: omg i got it thank you ill never post about coding problems any more it was right in front of me thank you(btw i thought it was the botom else that had the problem.)fixed codeCode:int ledPin = 13;void setup(){pinMode(ledPin , OUTPUT);Serial.begin(9600);}void loop(){while (Serial.available() == 0);int val = Serial.read() - '0';if (val == 1){ Serial.println("LED IS ON");digitalWrite(ledPin, HIGH);}else if (val == 0){Serial.println("LED IS OFF");digitalWrite(ledPin , LOW);}else {Serial.println("Invalid");}}And it is working like a charm thank you.

author: c4757p
author_rank: Super Contributor
timestamp: February 12, 2013, 05:46:27 pm
content: Are you working in the actual Arduino "IDE"? The last time I used it, it messed up line numbers by auto-inserting code before compile and never adjusting the error messages. The line numbers are useless.TBH, I've never understood why the Arduino developers can't just use an "#include <Arduino>" or something at the top of the file to pull in all the "auto-insert" junk. I know they're trying to make it easy to learn, but what good do you do to a beginning programmer by pretending includes don't exist?? Using a proper include directive would allow the compiler to properly manage the line numbers.Of course, I love the Arduino hardware and concept, but the whole idea of the software seems to be to always wrap yourself in a heavy layer of bubble wrap before you ever enter the coding world.

author: c4757p
author_rank: Super Contributor
timestamp: February 12, 2013, 05:48:51 pm
content: Quote from: ChrisGreece52 on February 12, 2013, 05:44:17 pmHuh? Please do! Most code errors are "obvious" - it just takes a second set of eyes to find them sometimes. When you've been staring at the same code for a long time it's easy to overlook something simple.Though you will save yourself a lot of trouble if you always pay careful attention to indentation.

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 12, 2013, 05:51:16 pm
content: Quote from: c4757p on February 12, 2013, 05:46:27 pmShall i use eclipse or something like that kind of software?

author: c4757p
author_rank: Super Contributor
timestamp: February 12, 2013, 05:58:27 pm
content: To be honest I don't really know what I would recommend. If you're really dedicated I'd suggest starting fresh with an AVR tutorial that doesn't use the Arduino software - you can still use all the hardware - but it's a lot of work to get started. I took that route but it took me a long time to get familiar with them. Maybe someone else on this forum has an idea for at least making the Arduino error messages useful?I imagine setting up Eclipse with Arduino would be a massive pain. If youwereto try bare AVR programming, Atmel has their own IDE and it's pretty good. But there's really nothing wrong with Arduino, I just hate the IDE...

author: ChrisGreece52
author_rank: Frequent Contributor
timestamp: February 12, 2013, 07:40:15 pm
content: Thank you for your advise

author: bitwelder
author_rank: Super Contributor
timestamp: February 16, 2013, 08:00:25 am
content: Unless you're doing a quite complex project in Arduino, I don't think you really need a heavy IDE like Eclipse.Rather, I think it would beneficial to just focus on writing clean code, i.e. using adequate indentation, opening a {} block after every loop (even if at beginning that block is just one line), adding comments in the code, etc.If you don't like the built-in editor, there is also the option to use an external editor.

author: Mechatrommer
author_rank: Super Contributor
timestamp: February 16, 2013, 09:57:46 am
content: Quote from: ChrisGreece52 on February 12, 2013, 05:51:16 pmsince Arduino IDE is so broken esp compilation. let me give you my 2cnts..i have no obligation about Eclipse environment as far as the "Programming" is concerned, except its an abomination of the "Inefficient Architectural Design Structure" (NET, Java or Peanut i'm not sure what), butlet me suggest AVR Studio 4, i know its old, but its one of the remaining exampleof an App that is based on properly designed "Lower Level Structure" (from its efficiency experience), you'll get the "true" coding, compiling, debugging and simulating experience.only one quirk, its not designed directly to support Arduino Board (and newer AVR chips), either you need the AVR Programmer (direct ISP programming), or make a DIY script or command line batch for avrdude to upload the hex file. complaints from other users made me not to download the latest version of AVR Studio that is based on NetBeans and Peanut structure (i'm an Old Windows user anyhow).edit: striked portion is... maybe i can make mistake in my claim. i havent used Netbeans extensively.

author: TerminalJack505
author_rank: Super Contributor
timestamp: February 16, 2013, 10:14:39 am
content: I think Eclipse was the best thing to ever happen to Java. (Eclipse is written in Java.) Even still, it doesn't seem like Java is going anywhere--except downhill. It seems likeSun'sOracle's only interest in Java is the money they believe they can make by suing Google. The security issues are really getting out of hand. Facebook developers recently had their laptops compromised thanks to a Java security issue. A lot of developers seem to be dropping Java like a hot rock.I removed Java (and Eclipse) from my system recently. I wouldn't recommend Eclipse as an IDE unless you're willing to take a risk with Java.Edit: I said Sun but meant Oracle. Java probably wouldn't be in this sad state if Sun never got bought-out by Oracle.