[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Electronics
. -> [Folder]  Microprocessors
. . -> [Subject]  Before posting a programming question on the Arduino site, read this!
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Before posting a programming question on the Arduino site, read this!

Postings by administrators only.

[Refresh] Refresh page


Posted by Nick Gammon   Australia  (21,607 posts)  [Biography] bio   Forum Administrator
Date Mon 26 Mar 2012 03:28 AM (UTC)
Message
Arduino programming language


The Arduino basically uses the industry-standard C++ language, implemented by the Gnu g++ compiler.

For information on basic things like loops, strings, functions, data types, and so on try consulting one of the many online C++ references. Hint: Google "C++ tutorial".


Version 1.0 of the IDE


A few things were changed in the 1.0 release version of the IDE*. In particular some older examples and libraries may have this at the start:


 #include "WProgram.h"


If you get errors try locating such places and changing that line to:


#include "Arduino.h"


* IDE = Integrated Development Environment


Libraries


Many useful features are implemented by libraries. These are basically xxx.cpp and xxx.h files collected together into a library folder. Some come with the IDE. See here for how to add additional libraries:

http://arduino.cc/it/Reference/Libraries

(It is easy enough to write your own, they are basically just C++ source code).


Reference page


Many functions specific to the Arduino (like activating pins, reading analog input etc.) are documented on the reference page:

http://arduino.cc/en/Reference/HomePage


Examples


Before rushing on to the forum saying you don't understand how to make something work, try working your way through the examples (File Menu -> Examples in the IDE). A few examples under the belt make everything else much easier.


Getting help on the forum


There are quite a few experienced people on the forum anxious to help you, and help you get as much as you can out of your Arduino. You can help them do that by making helpful posts:


  • Make an informative subject description, not "help me, I'm a noob", nor something in all capitals. Try to avoid saying "urgent". That's your problem, not ours.

  • Describe your problem in detail.

  • If it relates to an electronics part (chip or board), give the exact part number and preferably a link to the data sheet.

  • Describe how you have connected things like switches. Are they wired to ground? Or +5V? Are there pull-up or pull-down resistors? Post a circuit if there is doubt.

  • Post your code! If you don't you waste time while people ask you to do that.

  • When you post your code put it between [code] ... [/code] tags. You can do that by hitting the # button above the posting area.

  • If you get an error, post the error (copy and paste). Not just "I got an error".

  • If you have debugging information in your sketch, post what you get.

  • Describe what you expected to happen, and what actually happened. Not just "it doesn't work".

  • If possible, describe what you are really trying to do, not what you think might work. For example "I am trying to turn on an aquarium heater and pump at the same time", not "how do I break out of an interrupt?".



Debugging


If you have puzzling behaviour, it is frequently helpful to put "debugging prints" inside your code. For example, initialize the serial port inside the setup function:


void setup ()
  {
  Serial.begin (115200);  // initialize serial comms at 115200 baud
  //  ... other setup here
  }  // end of setup


Later on you can print things of interest, eg.


  Serial.println ("Button 5 pressed.");


(Check you have set your Serial Monitor to 115200 baud, or you may see gibberish characters).

Some other ways of doing debugging described here:

http://www.gammon.com.au/forum/?id=11329

Memory usage


Microcontrollers like the Arduino have much less memory than you would be used to on a Mac, Windows or Linux. For example the Atmega328 processor (used on the Uno, Fio, Nano, Duemilanove boards, and others) has 32 Kb of Program Memory (for your code), 2 Kb of SRAM* (for your variables), and 1 Kb of EEPROM (for saving data when powered off).

Typically programs that reset unexpectedly, or hang, have run out of SRAM. Note that the number reported by the compiler when you compile your program is program memory, not SRAM.

Even a simple array like the one below uses 2000 bytes of memory. This line alone would almost certainly make your program crash:


int myData [20] [50];


Hint: The String class tends to gobble up memory. Try to avoid using that, especially in larger programs.

* SRAM = Static Random Access Memory


Reading serial data


Serial data arrives asynchronously, that is, a byte at a time at no particular rate between bytes. To read things longer than a byte it is helpful to collect incoming data into a suitable size buffer, and when all has arrived, process that. Typically you know it has all arrived when a special character, such a newline character, is received.

Some examples here:

http://gammon.com.au/serial

Try things!


Read this:

http://mattgemmell.com/2008/12/08/what-have-you-tried/

You will get more help if you try something and describe what happened, rather than posting "I wonder if X will work".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


3,103 views.

Postings by administrators only.

[Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]