Programming Arduino

[Contents] [Download Code] [Arduino 1.0] [Errata] [Screenshots]

ste 600

This book is all about Programming the Arduino. I wrote it to try and respond to the many problems that come up on the Arduino forums about how to program an Arduino. The book does not assume any prior knowledge about programming or experience of electronics.

Contents:

Chapter 1. This is Arduino. An introduction the Arduino hardware, what it is capable of and the various types of Arduino board that are available.
Chapter 2. Getting Started. First experiments with your Arduino board, installing the software, powering it up and uploading your first sketch.
Chapter 3. C Language Basics. The basics of the C language and for complete programming beginners an introduction to programming in general.
Chapter 4. Functions. This chapter explains the key concept of using and writing functions in Arduino sketches. Demonstrated throughout with runnable code examples.
Chapter 5. Arrays and Strings. How to make and use more advanced data structures than simple integer variables. A Morse Code example project is slowly developed to illustrate the concepts being explained.
Chapter 6. Input and Output. How to use the digital and analog inputs and outputs on the Arduino in your programs. A multimeter will be useful to see what is happening on the Arduino’s input output connections.
Chapter 7. The Standard Arduino Library. Making use of the standard Arduino functions that come in the Arduino’s standard library.
Chapter 8. Data Storage. Writing sketches that can save data in EEPROM memory and make use of the Arduino’s built-in Flash memory.
Chapter 9. LCD Displays. Programming with the LCD Shield library to make a simple USB message board example.
Chapter 10. Arduino Ethernet Programming. Making the Arduino behave like a web server, including a little background on HTML and the HTTP protocol.
Chapter 11. C++ and Libraries. Beyond C, looking at adding object-orientation and writing your own Arduino libraries.

Arduino 1.0:

At the start of December 2011 Arduino 1.0 was released. This changed a few things, that have caused two of the sketches in this book not to work.

If you are using Arduino 1.0 and have not used any previous version of Arduino, you need to:

Download the new versions of sketches 10-01 and 10-02 from the Download Code link at the top of this page. The classes Server and Client have been renamed to EthernetServer and EthernetClient.

If you are using Arduino 1.0 and have used Arduino 023 or earlier, you may need to:

get version 1.6 of the Bounce library from http://www.arduino.cc/playground/Code/Bounce

Errata:

Page 3. Figure 1.1 marks one of the mounting holes as being the reset button. The reset button is actually slightly below it and to the left just above the label ‘Reset’ on the board.
Page 4, 2nd paragraph under Power Connections, 3.5V should be 3.3V in list of power pins.

Page 7, 2nd paragraph under The Origins of Arduino, … such clones often have “*dunino” names should be “*duino” names.

Page 19. I state that the serial port is always COM3. This is not the case – usually it is COM4.

page 33 paragraph 6 last sentence. The value returned to use from the call would be the sin of the angle passed as its argument. Should be: The value returned to use from the call would be the sine of the angle passed as its argument.

 

page 36 last paragraph last sentence int ledPin 13; Should be: int ledPin = 13;

Page 40. I say that to convert C to F you ‘to multiply it by 5, divide by 9, and then add 32′. This is the wrong way around. It should say ‘multiply it by 9, divide by 5, and then add 32′

Page 44. The sentence: ‘We used the symbol <, which means less than’ should read: ‘We used the symbol > which means greater than’.

Page 47. Near the top of the page. ‘less than 100′ should read ‘less than 20′.

Page 61. “-” missing on p61 table 4-1 for “long’ types (2,147,483,648 to 2,147,483,647) also on page 61, last sentence of first paragraph in section Other Data Types: “numbers between -32767 and 32768″ should be “numbers between -32768 and 32767″ so that it agrees with Table 4-1.
Page 69, Figure 5-1, the first 6 lines of the output is shown as 200, while only the first 3 lines should be 200 (should be 3 lines of 200, 3 lines of 500, 3 lines of 200 – 9 total output lines, not 12 output lines).

Pg.75. Table 5-2. “D” is shown as “..” should be “-..”

Page 120. The example code for writing a string in Chapter 8 does not write the terminator. It should look like this:

char *test = “Hello”;
int i = 0;
while (test[i] != ‘\0′)
{
EEPROM.write(i, test[i]);
i++;
}
EEPROM.write(i, ‘\0′);

Page 121. There was a semi-colon missing on line 7 of sketch 08-03. This is fixed in the current download of the sketches.
Page 121. Also in this sketch, for (int i = 0; i < 1023; i++) should be: for (int i = 0; i <= 1023; i++). That is <= rather than <. As it stands the sketch would not clear the last byte.
Page 149, 1st Paragraph, “Type the flowing into the sketch …” should be “Type the following into the sketch …”

Page 121. The sentence at the end of the page that says ints and floats are both 16 bits should say that ints are 16 bits and floats 32 bit.

Screen Shots:

Following problems with legibility of some of the screen shots on some eBook readers, here are the images.

F02-01

F02-01

 

F02-02

F02-02

 

F02-03

F02-03

 

F02-04

F02-04

 

F02-05

F02-05

 

F02-06

F02-06

 

F02-07

F02-07

 

F02-08

F02-08

 

F02-09

F02-09

 

F02-10

F02-10

 

F03-02

F03-02

 

F03-03

F03-03

 

F03-04

F03-04

 

F03-05

F03-05

 

F03-06

F03-06

 

F03-07

F03-07

 

F05-01

F05-01

 

F06-02

F06-02

 

F10-03

F10-03

 

F11-01

F11-01

 

F11-02

F11-02

7 thoughts on “Programming Arduino

  1. Wayne Carr

    programming arduino Ch 3 page 42 says: “The arithmetic operators +, -, *, and / have an order of precedence – that is, multiplications are done first, then divisions, then additions and subtractions” That isn’t correct. Multiplication and division are at the same level of precedence and are performed left to right, so “10 / 2 * 6″ has the division first and then the multiplication, not the multiplication first as in the text. The same is true of + and -, but the text there doesn’t claim one of those always happens before the other. References: Microsoft c operator precedence or c operator precedence

  2. admin Post author

    I stand corrected! I think I already have that errata in the list, but thanks for pointing it out. It all helps to make the next edition better. Si.

  3. Pascal Munerot

    Hello,
    I think there is a mistake p119 in the section “Storing a float in EEPROM (Unions)”. A float uses 4 bytes and not just 2. This is confirmed with your book “Next steps …” p34 (4 bytes). So the example should probably map a float to a long and thus write two series of 2 bytes. Perhaps even better would be to use 2 int. Not sure how the endianess comes into play.

    Other than that, the book is excellent. I am also reading “hacking electronics which is very clear”.

    Regards

  4. admin Post author

    You are quite right. Sorry about that. Also if you are enjoying Hacking Electronics, it may interest you to know that we have a kit to support the book now. Si.

  5. Bill Ward

    Hi Simon-

    Thinking P 63, last word of 3d paragraph should be “valuable” or something similarly positive instead of “difficult,” as ‘it’ refers to “All of this ” (good practice) rather than “someone else’s badly formatted sketches.”

    I am reading this and Next Steps. Love your writing style- I wish it had been my dry C++ textbook in college. It’s every bit as instructive and by combining with the Ardiuino functionality, much more interesting and readable.

    -BW

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>