Errata

Arduino Cookbook

Errata for Arduino Cookbook

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page 18
Sample code comments

The abbreviation "LED" is lower case in the comment, "enable output on the led pin." This is repeated in all sketches on pages 18-20.

Deane Simpson  Apr 02, 2016 
Printed Page 20
Sample code comments

The Blink sketch was modified for a speaker connected to an output pin, but the comments still refer to an LED (i.e., enable output to the led pin, set the LED on, set the LED off).

Deane Simpson  Apr 02, 2016 
Printed Page 27
2.3

The sketch float value have compiling problems. The function almostEqual is declared not in this scope. Such is the advise of compiler. I seem that the same problems as been found by others customer.

Franco  Feb 16, 2018 
Printed Page 27
2.3 Solution

Repeat of earlier post noting same problem:

The sketch float value have compiling problems. The function almostEqual is declared not in this scope. Such is the advise of compiler. I seem that the same problems as been found by others customer.

Mark  Sep 30, 2018 
Printed Page 46
Code for blink2

Code for blink2 example sketch calls variable "count", but never defines it. I'm a rote beginner, so I'm not entirely sure how to fix it, but I'm happy that I noticed this while reading the book (and then confirmed it by programming it as written to be sure). Awesome book regardless!

Dave J  Oct 17, 2014 
Printed Page 47
3rd paragraph

The sketch provided did not stop led from flashing, when switch is pressed.
I did small modification to make it work as shown below:

const int ledPin = 13; // output pin for the LED
const int inputPin = 2; // input pin for the switch

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
digitalWrite(inputPin,HIGH); // use internal pull-up resistor (Recipe 5.2)
Serial.begin(9600);
}

void loop(){
Serial.println("Press and hold the switch to stop blinking");
int count = blink3(250); // blink the LED 250ms on and 250ms off
Serial.print("The number of times the switch blinked was ");
Serial.println(count);
}

// blink an LED using the given delay period
// return the number of times the LED flashed
int blink3(int period)
{
int result = 0;
int switchVal; //with pull-ups, this will be high when switch is up
switchVal = digitalRead(inputPin);
while(switchVal == HIGH) // repeat this loop until switch is pressed
// (it will go low when pressed)
{
digitalWrite(13,HIGH);
delay(period);
digitalWrite(13,LOW);
delay(period);
result = result + 1; // increment the count
switchVal = digitalRead(inputPin); // read input value
Serial.print("switchVal is ");
Serial.println(switchVal);
Serial.println("Press and hold the switch to stop blinking");
if(switchVal==LOW)
digitalWrite(13,LOW);

}

// here when switchVal is no longer HIGH because the switch is pressed
return result; // this value will be returned
}

franklin viloria  Jan 14, 2019 
Printed Page 65
Discussion paragraph

Comments in code example read:

"// blink of both pins are HIGH"

Should be, blink IF both pins are high.

This error is repeated in other codes snippets on the same page.

Anonymous  Jun 27, 2014 
Printed Page 66
United Kingdom

Line above Discussion.

~intVal (1) equals 11111111111111111111111111111110

int is a 16 bit number so possibly should read

~intVal (1) equals 1111111111111110

page 67 describes output as 15 ones followed by a zero

Phil Slater  Jul 12, 2014 
Printed Page 67
2nd to last paragraph

In previous example on page 66, a intVal of 1 (which should be 0000000000000001 in 16-bit binary) is inverted and displayed in it's binary form.

The output however is 11111111111111111111111111111110 which is 32-bits.

The author writes on page 67:

"The int value has 16 bits, so when each is flipped, the result is 15 ones followed by a single zero"

This is what you would expect, but what confuses me is the discrepancy between these, because even when I typed in the code myself, it also returned a 32-bit answer.

How can this be if and int value can only have 16 bits????

JohnBen Lacy  Jun 27, 2014 
Printed Page 77
3rd para

I think that:

else
result = ceil(num - 0.5);

should read

else
result = ceil(floatValue - 0.5);

Typo error I think num was used inadvertently instead of floatValue

Anonymous  Feb 20, 2015 
Printed Page 98
mid-page

The code use Serial.println on several lines, but the output shown would be generated only with Serial.print, using Serial.Println only on the last field of the print.

ron ginger  Feb 09, 2015 
Printed, PDF, ePub, Mobi Page 116
line 6

int longValue = 1000;

Is it should be

long longValue = 1000;

Anonymous  Feb 05, 2014 
Printed, Other Digital Version Page 120
United States

The processing sketch listed under section 4.8 in the printed copy of the second edition as well as the code download from the Oreilly website produce an error(The function readStringUntil(char) does not exist.) when executed. The error occurs on line 24 * String inString = myPort.readStringUntil('\n');.

Andrew Straws  Nov 28, 2014 
Printed, PDF, ePub, Mobi, Other Digital Version Page 130
top in the processing code

the new Versions of processing(v2/3) don't know the commands
Dimension screen=java.awt.toolkit.getDefaultToolkit().getScreensize()
screen.getHeight()
v2 crashes with the first one, v3 with both
so the scetches don't work, i overgone it with simply tipping in the dimension of my screen by hand.

Anonymous  Feb 02, 2017 
Printed Page 139
Figure 4.6

The text on page 139 accompanying Figure 4.6 suggests that the Arduino's digital pin 2 is connected to the serial LCD display's transmit line, but that connection isn't shown in Figure 4.6. Later, on page 141, mention is made of a unidirectional serial device, in terms suggesting that this may be what's shown in Figure 4.6. I'm not suggesting that there's an error in the book but I'm wondering if some form of clarification might be appropriate.

Anonymous  Dec 30, 2013 
Printed Page 149
Figure 5-2

The figure of the Mega board, on the right side, that shows the "digital" section has an error. In the upper right hand corner the figure shows the two pins, above pin 22, to be Gnd.

This pin and the pin to the right of it are actually +5 Volts.

The two pins below pins 52 and 53 are correctly labeled Gnd.

James Gallivan  Aug 31, 2013 
PDF Page 155
Code on top of page

In the void loop() section of the code, you put the following:

digitalWrite(ledPin, HIGH); // turn LED OFF
}
else
{
digitalWrite(ledPin, LOW); // turn LED ON
}

However, it should be:

digitalWrite ledPin, LOW); // turn the LED OFF
}
else
{
digitalWrite(ledPin, HIGH); // turn the LED ON
}

Otherwise, it does the opposite and the light is on until you depress the button, then turns off.

However, I thank you for this mistake as it helped me understand this section better.

xKoldFuzionx  Jun 22, 2013 
Printed, PDF Page 221
sketch

the sketch on this page returns errors that blinkLED is not declared

Anonymous  Dec 02, 2011 
PDF Page 248
Code in the solution

In the solution to adjust the brighness of LEDs, the LEDs are eased in and faded out by writing to the analog pins. However this, solutions contains an 'of by one' error inside the loop. If analogWrite() has a analog value greater than 255, the LEDs go of. This results in a visible flicker because the LEDs are off for 10ms, because the brightness reaches 256 for 10ms.

/*leftout*/

void loop()
{
if ( brightness > 255 )
{
increment = -1;
}
else if ( brightness < 1 )
{
increment = 1;
}
brightness = brightnes + increment; //oops brightness can become 256.

//write the brightness value to the LEDs
analogWrite(firstLed, brigthness);
analogWrite(secondLed, brigthness);
analogWrite(thirdLed, brigthness);

delay(10);
}

I would suggest this fix note the use of 'greater than or equal' comparison operator:
if ( brightness >= 255 )
{
increment = -1;
}

maarten  Jan 16, 2014 
Printed Page 253
function hueToRGB

Colour change of the LEDs is somewhat abrupt, due to (IMO) an error in the conversion function.

segmentOffset = scaledHue - (segment * 256) always yields 0 because segment is defined as scaledHue / 256

Replacing it by segmentOffset = scaledHue % 256 gives a much smoother color change.

Fred Swart  Jun 25, 2012 
Printed Page 273-274
schematic 7-12 on p 273 and 2nd paragraph on p 274

for Common Cathode display not only (as the text indicated) does the line isBitset = ! isBitset; be taken out of the code, but also (and this not mentioned) does the Common needs to be connected to Gnd rather than 5V in schematic Fig 7-12.

Eloy Wouters  Nov 24, 2013 
PDF Page 274
Top

If you use a common cathode diplay, connect the common pin to GND not to +5V.

Richard Frank  Apr 18, 2014 
Printed Page 275
bottom of page showDigit() function

The sketch failed to run properly as all four digits were permanently on and not multiplexing. Adding the line ' digitalWrite( digitPins [digit], LOW ); ' after the line ' delay(5); ' corrected the problem. Final } also missing.

Jim Parish  Dec 06, 2013 
Printed Page 284
Pins connection paragraph concerning daisy-chaining

Concerning the exercise 7.14 TLC5940 example in Edition 2 Daisy-chain discussion.

For the daisy-chained 16 leds to work, more pins must be connected than are listed in the Tlc5940 discussion.

Add into the bottom paragraph:
* Arduino pin 3 to GSclk (pin18) of each TLC


The Daisy Chained TLC also needs the following pins addressed:

Daisy-Chained Vcc (pin 21) to 5v
Daisy-Chained DCprg (pin 19) to 5v.
Daisy-Chained Gnd (pin22) to Gnd

Anonymous  Sep 13, 2016 
Printed Page 342
Code for 9.6 "Controlling MIDI"

(Downloadable code matches printed version)
First line of void loop() is:
if (digitalRead(switchPin == LOW))
This causes the scale to repeatedly play (on OSEPP Uno R3 Plus).
To make the scale play only while button is pressed:
if (digitalRead(switchPin) == LOW)
i.e., The argument for digitalRead should just be (switchPin) rather than (switchPin == LOW)

salsberyfamily  Sep 28, 2015 
Printed Page 399
second to last line of code in sketch

Just before "Serial.println(duration); in void loop() section of recipe 12.2, you redefine a previously created variable "duration".
This causes it to return a zero value.
Delete the "long" from the duration = millis() - startTime; line and it works fine.

Kind of pissed- absolute beginner at arduino and two of two sketches I've tried have bugs- didn't you guys test the code??

Nice that you have an Errata section to post bugs to, but the file is basically unsearchable... just check your f'ing work before you charge $45 for a book.

Dave J  Oct 21, 2014 
Printed Page 416
First line

The sketches in section 12.6 ("Using a Real-Time Clock") make use of the "DS1307RTC" library. However, this library does not appear to be distributed with the current (1.0.1) Arduino IDE. I did, however, find a version of this library (ie, .h and .cpp files, dated 6 Mar 2010) in the Google code repository and tried installing this locally. However, compiling against this library throws up a whole raft of errors, suggesting some incompatibility with the current suite of libraries.

Fred  Mar 24, 2013 
PDF Page 422
Vietnam

In the 3rd row :
... analog pin 4 for SDL... shoulded be changed to:
... analog pin 4 for SDA...

L? Kh?nh  Jun 06, 2014 
Printed, PDF Page 439
United Kingdom

Table 13.2 as written does not give the correct addresses in HEX from the corresponding A0,A1, A2.
e.g. 0x53 and 0x56 are both shown as 5V, 5V, 0V

Phil Slater  Dec 06, 2014 
PDF Page 455
United States

Inside the loop routine for the master arduino, there is no statement to actually read the character that is available from the serial port. The first statement inside the if should be "c = Serial.read();"

jbernardis  Apr 21, 2015 
PDF Page 495
Chapter 15


Dear Mr. Margolis,

I have been studying the Arduino UNO R3 board - out of interest.
I have recently added an Ethernet 2 shield (Arduino.org) and worked thru several sketches after solving several gotchas (both software and router) when connecting the shield to a local/external network.

I read and run all your sample sketches this month from your Arduino Cookbook, 2nd edition Chapter 15. Most of the sketches worked, but several had errors or were no longer possible as the Web site no longer exists.

Since you are writing a third edition, would you be interested in my comments and observations using the Ethernet2 shield - network setup, tools, other useful sketches (e.g ping, using SD card), as well as the errors that I found in the sketches?

If so, send me an email address.

Yours truly,
Rick Isaacs

Rick Isaacs  Mar 26, 2016 
Printed Page 502
In the setup section

The ethernet connection is started with one parameter, signifying a DHCP request. However the comment states "... using mac & IP address".
It should read "... using mac & DHCP".
Since it is only comment, the sketch will work alright, however it is confusing to the readers.

The error appears on pages 502, 504, 506, 507 and 509.

Paul Kroon  Feb 26, 2017 
PDF Page 612
18.4 code line "int duty = map(microseconds, 0,period, 0,1024);"

The very same line in reported as int duty = map(microseconds, 0,period, 1,1023); in the discussion session on p.614 last line just before "See Also" section.

Anonymous  May 06, 2014 
Printed Page 615
60% down the page

The line;

long precision = (F_CPU / 128000) * prescaleValue ;

is wrong in that precision (i.e. time) should be 1/F_CPU * whatever.

It possibly gives the right numerical value (for the 16 M Arduino) only by chance (or deliberate fudging).

Regards JC........

Anonymous  Aug 27, 2016