Arduino Cookbook (part 2) – What was left out and other information from the preface

Let’s continue going through the Arduino Cookbook by Michael Margolis.  (see the first article about the book.)

The book doesn’t cover much electronics theory and practice, but provides some basic guidance.  If you want some more background in this area, then these books are recommended:

• Make: Electronics by Charles Platt (O’Reilly)
• Getting Started in Electronics by Forrest Mims (Master Publishing)
• Physical Computing by Dan O’Sullivan and Tom Igoe (Cengage)
• Practical Electronics for Inventors by Paul Scherz (McGraw-Hill)

These all look like good books to go through, and we might have future series going through these books.  I recognized the Getting Started in Electronics by Forrest Mims.  I had bought it nearly 25 years ago!!  And I still have that copy.  I was going through it with my children (ages 8 and 12) this summer.  It has some wonderful illustrations in it.  Here are some pictures to give you a sense:

IMG_9283 IMG_9282

The Arduino Cookbook explains code to do very specific things.  The author recommends the following books to give you more information on programming in general and C in particular:

• Practical C Programming by Steve Oualline (O’Reilly)
• A Book on C by Al Kelley and Ira Pohl (Addison-Wesley)

The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie(Prentice Hall)

The code in the Arduino Cookbook has been tested with release versions 0018 through 0020.  It was written before v1.0 was finalized.  There might be small changes required to make the code work, and we are directed to this website:

www.oreilly.com/catalog/9780596802479/

So, if you have doubled checked, and tripled checked something from the book, and it does not work as expected, then check the link above to see if there are some changes required.  There is also an Appendix on troubleshooting, and more help can always be found from: www.arduino.cc

In the section “Using Code Examples” it says:

This book is here to help you make things with Arduino. In general, you may use the code in this book in your programs and documentation. You do not need to contact
us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from this book does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Arduino Cookbook by Michael Margolis
with Nick Weldin (O’Reilly). Copyright 2011 Michael Margolis and Nicholas Weldin, 9780596802479.”

If you feel your use of code examples falls outside fair use or the permission given here, feel free to contact us at permissions@oreilly.com.

In this set of blog posts, I will be going through the book, page by page, but we will not be putting the information in the book on this page.  Instead I will be providing some feedback, additional information, and my own personal experiments related to the information in the book.  Therefore, you will want to get the book in order to make best use of these blog posts.  Please use the link below so that we can get a small commission from Amazon to help support this site and the buying of all the Arduino related materials that we need to keep experimenting:

Arduino Cookbook

If you like online versions of things, then you should check out Safari Books Online:

my.safaribooksonline.com.

This is actually how I am reading the book, free through a service provided by my local library (www.hcpl.net/).  It is a great way to get technical books, that are searchable, without having to find a place to store them.    It can be great when doing some of the examples having the ability to copy and paste from the electronic book to the code editor without having to type it in, or try to find an alternate resource to get it from.

The Acknowledgments section can sometimes be very useful to read.  There are several people that Michael thanks:

Nick Weldin

Simon St. Laurent – editor at O’Reilley

Brian Jepson (twitter)– helped to provide the Xbee content in chapter 14

Audrey Doyle – fixed typos and grammatical errors

Philip Lindsay – chapter 15 help – how to make Ethernet more understandable

Mikal Hart – GPS recipes and software serial

Core Arduino development team: Massimo Banzi, David Cuartielles (twitter), Tom Igoe, Gianluca Martino, and David Mellis

Alexandra Deschamps-Sonsino, CEO of Tinker London (has workshops for the Arduino)

Peter Knight

SparkFun

Maker Store

Gravitech

NKC Electronics

Modern Device

Liquidware

Adafruit

Makerbot Industries

Mindkits

Oomlout

SK Pang

Brock Craft

Daneil Soltis

(families of the writers)

Joshua Nobel for his book Programming Interactivity:  A Designer’s Guide to Processing, Arduino, and Openframeworks (published July 28, 2009)  (This looks like a good book for us to go through too)

In the next post, we will get into Chapter 1 – Getting started…

Arduino Cookbook by Michael Margolis

 

In order to bring some structure to my experiments with the Arduino, and to help me get through the learning curve quicker, I thought it would be good to have a book to guide me.  The book I have selected is the Arduino Cookbook by Michael Margolis.  It is a recent book, published in March 2011.  The first words of the preface say just what I am looking for.  “This book was written to help you explore the amazing things you can do with Arduino.” Yay

Preface

Arduino is a family of microcontrollers (tiny computers).  It can be used for “physical computing”.  Actually responding to and interacting with the “real world”.

This book is aimed at a broad range of people.  There is no assumption about a particular hardware or software background.  But even if you have a microcontroller background or a background in C/C++, you will still find this book very useful.

What does this book cover?

Chapter 1 – Getting Started – (everything you need to get that first program written, that first circuit created, and possibly even that first LED blinking?)

Chapter 2 – Making the Sketch Do Your Bidding.  (“sketches” are what we call the Arduino program)  This chapter covers the key software concepts and task.

Chapter 3 – Using Mathematical Operators

Chapter 4 – Serial Communications – how to connect to the computer and other devices using a serial connection.

Chapter 5 – Simple Digital and Analog Input – how to actually get the data into the arduino

Chapter 6 – Getting Input from Sensors – enable touch, sound, position, heat, and light

Chapter 7 – Visual Output – controlling LEDS (ok, looks like they wait until this chapter to get that first LED blinking?)  Switch on one or many LEDs, controlling brightness and color.  How to create bar graphs, numeric LED displays, create patterns, animations with LED arrays.

Chapter 8 – Physical output .. how to make things move with solenoids (I’ve never quite understood what a solenoid is…)  servo motors (got some of them floating around… will be good to put them to some good use… found some for sale on eBay for just a few cents too.  but possibly will not win those)  Physical output is where the rubber meets the road.  This is where we make things move!  Can’t wait till we get to chapter 8!!!

Chapter 9 – Audio Output – generate sounds by playing wav files and MIDI output.

Chapter 10 – Remotely Controlling External Devices – interact with the TV, cameras, garage doors, appliances, toys. 

Chapter 11 – Using Displays – interfacing with text and graphical LCD displays

Chapter 12 – Using Time and Dates – measuring time; handling time delays (here we will learn what we need to know to develop a clock, timer, and I could create a speech timer for my toastmaster club…)

Chapter 13 – Communicating using I2C and SPI  (I have did one project in the Parallax Basic stamp book using I2C.  I understand it is a protocol to connect things together.  I am completely unfamiliar with SPI…)

Chapter 14 – Wireless Communication – using XBee

Chapter 15 – Ethernet and Networking – hook up things to the Internet.  (I have been playing around with the EtherShield, and got a web page setup to control a little LED.  But I got the cheaper enc28j60 based EtherShield.  Not the newer, expensive one based on the Wiznet chip.  The API calls for the Enc28j60 are a lot more difficult to understand than the newer ones.  The difference in cost though is about 100%.  You can get the Enc28j60 etherShield for about $20.  The Wiznet one will be around $45.  It will be interesting to see which one the book uses… I think we can both already guess 🙂 )

Chapter 16 – Using, Modifying and Creating Libraries (maybe this is where I can learn how to create a easier to use library wrapper for the EtherShield that I have. )

Chapter 17 – Advanced Coding and Memory Handling

Chapter 18 – Using the Controller Chip Hardware – How to access and use hardware functions that are not “fully” exposed through the documented Arduino language… (Sounds interesting and advanced)

I have no idea how long it will take to get through the book.  And I imagine we will be taking a lot of detours on the way to create projects using what we have learned.  But I would recommend that if you are starting with the Arduino that you get the book and come along this journey with me.  I intend to keep you updated on my progress in the book, and I intend to publish the code and projects that I create from the things that I learn from the book, but to fully understand everything, you will need the book.  Please use this link:

Also, if you live in Harris county, then you can access it through the Harris Public County Library who has an arrangement with SafariBooksOnline to make it available.  Your library might have a similar setup.

Follow Me Game – Arduino Based Game

Remember playing MySimon (Simon Says) back in the 1980s?  It was a simple game that could entertain you for hours.  It had 4 buttons, each of a different color.  Turn on the game, and one of the buttons would glow.  Then you had to press that button.  Another button was added to the pattern, and the goal was to get to the longest pattern without messing up.
Here I show a simple Arduino based version of this game.  It is simpler because there are only 3 buttons, but it is completely open for you to build on and learn from.

 

image

See the circuit and files on Fritzing.org

 

Update:  I received an email about a more sophisticated version of Simon.


Arduino SimonGame

More infos at jadiema.blogspot.com/
Arduino Simon Game: Version 3
Initial Release from David M. Auld (19th October 2009): Version 1 & 2
www.dave-auld.net/index.php?option=com_content&view=article&id=96:arduino-project-simon-game&catid=54:arduino-projects&Itemid=107
Added some features by jadiema: Version 3:
NEW: Added EEPROM storage for high score: level and name
NEW: Multilangage selection
You’ll find the code at: code.google.com/p/my-arduino-projects/downloads/detail?name=Arduino_SimonGame_EEPROM_LANGUE_V3_1.pde&can=2&q=#makechanges

Simple Scoreboard using the Arduino processor

The Arduino microcontroller board has got to be one of the coolest things to come along.  If you ever wanted to create simple gadgets and devices without that much hassle, then this the board to get.  You can hook it up to your computer using the USB port, program in a simple C language, download the code, and away you go.  You can use it to create controllers for your games, lights for your Christomas tree, loggers for your garden, monitors for your rooms, and controllers for your robots.  All you need is a little patience and imagination (access to Google helps too 🙂 ).

Today, I want to share with you a little project that we created.  It is a simple scoreboard.  It took us about 20 minutes to put together, but that is because we were just learning and didn’t know much. 

We started out by finding this example on how the LCD panel works: www.arduino.cc/en/Tutorial/LiquidCrystal 

Then we hooked up some buttons, added some variables, created several iterations between our code.

Start off displaying the “Hello World” message in the LCD example.  Then had added a “homeScore” variable and displayed that.  Then added the Home Button.  And tested to see if it was “high”, i.e. “on” in our code.  Our first version of the code did not have the “delay” commands, and pressing the button one time caused the score to increment by 50-120 points.  This was because the loop would have that many cycles before the button was brought back “low”, i.e. “off”.  Adding the “delay” kept this from happening.  Then did the same thing for the visitor button.  Required some experimentation with the lcd.SetCursor command to get the visitor scores to show up in the right place.  Then added the reset button and set the scores to 0 when it was pressed.  Ran into the problem that if the score had become two digit, then the 0 was only over writing part of the digits.  Decided to “clear” the display completely on reset, which resolved the problem.  Then cleaned up the code a little, and this was the results:

 

IMG_8725

image

Code (based on LCD example: www.arduino.cc/en/Tutorial/LiquidCrystal )

/*
Simple Scoreboard

Shows a simple Home/Visitor scoreboard

*/

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int homeScore;
int visitorScore;
const int buttonHomePin = 6;
const int buttonVisitorPin = 7;
const int buttonResetPin = 8;
int buttonState = 0;

void setup() {
  // set up the LCD’s number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  setupScreen(); 
}

void setupScreen()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("home     visitor");
  homeScore = 0;
  visitorScore = 0;
}

void loop() {
  buttonState = digitalRead(buttonHomePin);
  if(buttonState == HIGH)
  {
    homeScore++;
    delay(500);
  }
    buttonState = digitalRead(buttonVisitorPin);
  if(buttonState == HIGH)
  {
    visitorScore++;
    delay(500);
  }

   buttonState = digitalRead(buttonResetPin);
  if(buttonState == HIGH)
  {
    setupScreen();
  }
   lcd.print(homeScore);
   lcd.setCursor(12, 1);
   lcd.print(visitorScore);
}

First Two Weeks of Summer

“Can’t talk now… I’m on a schedule.”  “No, I have no time to meet this week.”  “Really focused, can’t think about that right now.”  If you have talked to me in the past two weeks, you have probably heard something like that.  Also, you may have noticed that I have been a little slow on emails, not attending events that I normally go to (like the cypress coffee club networking meeting and the CyFair Chamber meetings or the Friday night chess meets, toastmasters, etc.)  You may have noticed that the daily learn Hindi show on ISpeakHindi.com has been a little less than daily.  And you might be tempted to ask “Are you OK?”  or perhaps you think I am working on some super secret project.  Well, it is time that I set the record straight.

These past two weeks I have been engaged in something that is best described as “continuous contact parenting”.  In past summers we have sent the kinds off to various camps.  But this summer I am at home and available to spend with them 24/7.  I want to make the most of this time.   Because I know that in less than a decade both of them will out of the house, and I will probably have time for them at that point, but they will probably be too busy with their lives for me.

But how to make the most of the summer?  Should I just sit around and do whatever comes to mind.  Should we just play board game after board game.  Read books.  Watch movies.  What should we do?

I had some very specific ideas on what an ideal summer day might look like.  It should have exercise.  Time for eating.  Piano practice.  Math worksheets.  Piano writing.  But there is one area that I thought we could focus on and have a lot of fun:  Electronics and robotics.  After putting all that together, we came up with a daily schedule that we would try for two weeks:

image

The electronics time was spent learning about voltage, current, resistance, using the multi-meter, understanding the relationship between voltage, current, resistance, soldering, striping wires, reading circuit diagrams, making connections between components on a breadboard, using a Parallax Basic stamp.

Here are some pictures to give you some idea:

IMG_8710

We also put together some kits:

IMG_8708

In fact, we have a “wall of completed projects” where we put a postcard or something to indicate the projects that we have finished:

IMG_8709

We have also programmed Parallax’s scribbler robot. 

 

IMG_8706

During our free time we did end up playing a board game, Settlers of Catan.  My friend, Daniel Parker, in Austin introduced it to us a couple of weeks ago.  Since then we have played dozens of games.

IMG_8671

This is just a small glimpse of the things we have been up to. 

Grab Bag for the day

Theater Camps in North Houston for Cy-Fair Real Estate Blog

Needbase

Needlebase is a project of ITA Software which is in the process of being acquired by Google.

Needlebase allows for you to create online databases and import local data as well as data from websites.  The video above will give you a good idea on the capabilities.  They have some job openings for Semantic Database Curator and Tester

 

New Robotics Merit Badge – BSA

Merit Badge Worksheet: meritbadge.org/wiki/images/7/7a/Robotics.pdf

Chrome Addins

PHP Code Editor

chrome.google.com/webstore/detail/lgglafkdjaokcebgpphkkliojmjbmicm?hl=en-US#

PHP Code Editor is a web based interface to edit your code.
This way you can work on your project now matter where in the world you are, or on wich computer you are sitting at.

image

image 

 

Speed Tracer (by Google)

chrome.google.com/extensions/detail/ognampngfcbddbfemdapefohjiobgbdl

Speed Tracer is a tool to help you identify and fix performance problems in your web applications. It visualizes metrics that are taken from low level instrumentation points inside of the browser and analyzes them as your application runs.

Using Speed Tracer you are able to get a better picture of where time is being spent in your application. This includes problems caused by: 

  * Javascript parsing and execution
  * Layout
  * CSS style recalculation and selector matching
  * DOM Event handling
  * Network resource loading
  * Timer fires
  * XMLHttpRequest callbacks
  * Painting
  * and more ...

image

 

 

 

 

 

 

 

csscan

image

 

chrome.google.com/extensions/detail/nnklpgoldelpoigiacfpnpphpkkmbdkb

nspired by the Firefox Extension CSSViewer, this Chrome extension allows you to easily scan an element's basic CSS properties without having to delve into the inspector window.

The extension adds a button to the toolbar. Clicking this button will enable the extension; you can then continue using the page, with the difference that a quick overview of CSS properties for the element your mouse cursor is hovering is displayed. To disable the CSS scanner, simply click the icon again.

Elements being scanned are highlighted with a red outline so the user can easily see the structure of the page. Most CSS properties are supported; however, feel free to leave a comment if you feel like there's any missing.

NOTE: For some reason the extension does not work on this page (or any other in the chrome extension gallery)! It seems to work fine on any other page.

SeoQuake

chrome.google.com/extensions/detail/akdgnmcogleenhbclghghlkkdndkjdjc

image 
 
 
 
Displays the Google PageRank, Alexa rank and other SEO parameters of any webpage, highlights nofollow links, text density, check and compare urls.

Full list of SEO parameters:

Google PageRank
Google Index
Yahoo links
Yahoo linkdomain
Bing index
Alexa Rank
Webarchive age
Delicious index
Whois link
Page source
SEMRush rank
Nofollow links

Cool Websites

Online web editor

JS Fiddle

site: jsfiddle.net/

blog: blog.jsfiddle.net/

image

Frame Box

framebox.org/

Show what you need in 3 easy steps:

  1. Sketch frame using UI units
  2. Save it and get a link to created frame
  3. Send a link to your companion

image

CSS3 Generator

css3generator.com/

image

Button Maker

css-tricks.com/examples/ButtonMaker/#

image

Acer Iconia display…

Motorla’s Atrix 4G

Thomas Becket

The Wild Soccer Bunch

imageWhile researching camps for my Soccer Camps in Houston for the Cy Fair Real Estate blog, I came across The Wild Soccer Bunch website.  At first I could not tell if the site was promoting a soccer camp, a book on improving soccer, or something else.  One thing that stuck me was the amount of orange on the site, and the coordination of colors on the website and the promotional video (see below).

After looking through it a little more, I discovered the site was about a series of books call The Wild Soccer Bunch which is about “a crew of zany, extraordinary, fun-loving soccer players.”  Looking at the way the book is being promoted alone makes me want to read it.  You can pick up a copy on Amazon.

A free $2 Trillion

“The Fed has kept short-term interest rates near zero since December 2008 and has bought more than $2 trillion in long-term securities to push borrowing costs down further and boost recovery from the 2007-2009 recession.”  (Fed unlikely to extend QE2, officials say by Ann Saphir (Reuters – 03/25/11)

The Federal Reserve was able to buy $2 trillion in long-term securities.  This is amazing consider that GDP is right around $14 trillion (Google) and the 2010 US Federal Government is $2 trillion (wikipedia.org).  Where does the Federal Reserve get that $2 trillion from?  (From what I’ve read, it seems it just gets it out of thin air.) The ability to pump this amount of money into the economy is just extraordinary. 

Winning the Lottery can make you less of what you already are

With just a bit of luck $1 could have become $312 Million in last Friday’s Mega Millions lottery.  Think of it, just pick 6 numbers correctly and all of your financial needs could be met, or could they?

It is my belief that giving people in financial distress a large sum of money actually makes the problem worse.  The distress financial situation is often caused by not matching expectations and expenditures with means and ability to earn.  Many of these situations start out slowly of earning just a little less than one spends, and then as the amount of difference (debt) accumulates, more desperate action is required that exasperates the condition.

A recent news article points to a related trend Why Lottery Winners Go Bankrupt by Jack Hough (Smart Money 3/28/11)

My belief is that if you want to have a happy life, learn how to live within your means.  And constantly push yourself to increase your means.