Arduino Programming in 24 Hours Richard Blum pdf download






















Using the Windows Installer File When you run the Windows installer file, a wizard utility starts up, guiding you through the software installation, as shown in Figure 2. The wizard guides you through the steps for installing the Arduino IDE software.

You can accept the default folder location to install the Arduino software or change it if you prefer to store the program files in another location. After the software installs, the wizard installs the Arduino software drivers necessary for Windows to interface with your Arduino. Just follow the prompts in the wizard to complete the software and driver installation. Using the Windows Zip File If you choose to download the Windows zip file version of the software, youll find the installation a bit more complicated.

The zip file contains all the same files as the Windows installer version, but it doesnt automatically install them. To run the Arduino IDE, just extract the zip file contents into a folder and look for the arduino. You can create a shortcut to this file on your desktop for easy access.

The following steps walk through how to do that. After unzipping the Windows zip file to a folder, plug your Arduino unit into the USB port on your workstation. The Windows USB utility will appear, but will complain that it is unable to find the driver for the Arduino unit. Open the Device Manager interface in your Windows workstation, as shown in Figure 2. Double-click the Unknown device entry. Youll need that information later on when you configure the Arduino IDE software.

Double-click the installation file to extract the Arduino IDE application file. Move the Arduino application file to the Applications folder on your Mac. The OS X system will automatically recognize the Arduino as a new network interface, as shown in Figure 2.

Dont worry, the Arduino will work just fine. Installing for Linux The Linux installation provides for two separate zip files: A bit version A bit version Youll need to select the version appropriate for your specific Linux distribution.

Both versions are distributed as a. To extract the tarball into a folder, you use the tar command, and add the -z option to uncompress the tarball as it extracts the files: Click here to view code image. Just create a shortcut on your desktop to the file. There are two packages to install: arduino and arduino-core. When you install these packages, Ubuntu automatically places a link to the Arduino IDE software in the Unity desktop menu. Summary In this hour, you learned how you can write code to program the Arduino.

The core of the Arduino is the ATmega microcontroller, so the code you write must be able to run on that system. The ATmega microcontroller uses machine language code to handle data and interface with the input and output ports.

However, you can use the Atmel C programming language library to make coding easier. Also, the Arduino development team has expanded on the Atmel C language and provided their own programming environment and libraries. This makes creating code for the Arduino much easier. In the next hour, we take a closer look at the Arduino IDE window. Youll learn how to create, edit, compile, debug, and upload your Arduino programs, all from one place!

Which part of the microcontroller performs the addition of two numbers? The ALU B. The registers C. The memory D. SRAM memory stores your program data, even after you turn off the Arduino unit. Why doesnt the Arduino have any analog output ports? The Arduino uses pulse-width modulation PWM to simulate an analog output signal using a digital output port.

That allows you to use the digital output ports to generate either a digital or analog output. Can I write assembly language programs and upload them to the Arduino? Yes, you can write assembly language programs using the Arduino IDE and compile them using the avr-gcc compiler. However, you must be careful when doing that, because you have to keep track of the registers and memory locations in your program!

Hour 3. Using the Arduino IDE. This hour covers the different parts of the Arduino IDE interface and how to use them to create your Arduino programs. Overview of the IDE The Arduino integrated development environment IDE itself is a Java program that creates an editor environment for you to write, compile, and upload your Arduino programs.

Figure 3. The Arduino IDE interface contains five main sections: The menu bar The taskbar The editor window The message area The console window Lets walk through each of these different sections and explain what theyre for and how to use them. From here, you can create a new program, retrieve an existing program, automatically format your code, compile your program, and upload your program to the Arduino unit.

The following sections discuss each of the options youll find in the menu bar. The File Menu The File menu contains all the file-handling options required to load and save sketches, along with a couple of miscellaneous options that dont fit in any other menu bar category. The options available under the File menu are described in the following subsection. New The New option does what youd probably expect it to do: It creates a new Arduino sketch tab in the main window.

When you save the sketch, you can change this sketch name to something that makes more sense. Open The Open option opens an existing sketch using the File Open dialog box of the operating system. The Open dialog box will open in the default sketchbook folder for your Arduino IDE set in the Preferences option, discussed later. The File Open dialog box allows you to navigate to another folder area if youve saved sketches on a removable media device, such as a USB thumb drive.

The 1. Sketchbook The Sketchbook option provides a quick way to open your existing sketches. It lists all the sketches that youve saved in the default sketchbook area in the Arduino IDE. You can select the sketch to load from this listing. Examples The Examples option provides links to lots of different types of example sketches provided by the Arduino developers. The examples are divided into different categories, so you can quickly find an example sketch for whatever type of project youre working on.

When you select an example sketch, the sketch code automatically loads into the editor window. You can then verify and upload the example sketch directly, or you can modify the sketch code before compiling and uploading.

Caution: Modifying Example Sketches If you modify the example sketch and try to save it, the Arduino IDE will warn you that the example sketch is saved as a read-only file and not let you update it.

Close The Close option closes out the current sketch editor window and safely closes the sketch file. Closing the sketch will also exit the Arduino IDE interface. Save The Save option allows you to save a previously saved sketch in your sketchbook area using the same filename.

Be careful when using this option, as the Arduino IDE will just overwrite the existing saved sketch and it wont keep any past versions automatically for you.

Save As The Save As option allows you to save a sketch using a new filename. It saves the sketch file using the. Make sure that the Arduino unit is connected to the USB port before you try to upload the sketch. The normal Upload option uploads your sketch to a special location in the flash program memory area on the ATmega microcontroller.

The Upload Using Programmer option writes the program to the start of the flash memory area on the ATmega microcontroller. This requires additional coding in your sketch so that the Arduino can boot from your program.

Tip: The Arduino Bootloader The Arduino system adds a special bootloader program to the start of the microcontrollers flash memory area. The bootloader runs when the Arduino powers on, and automatically jumps to your program code.

It makes formatting and running your Arduino code easier because you dont have to worry about the boot code. However, the Arduino IDE is versatile enough to allow advanced users to upload programs directly to the program area on the microcontroller. When you do this, your program code is responsible for creating a fully operational program. Beginners are best off using the Arduino bootloader format to write the program code.

Not using the bootloader means that you need to include more code in your Arduino program to tell the microcontroller how to handle your program. Page Setup The Page Setup option allows you to define formatting options for printing your sketch on a printer connected to your workstation. Print The Print option allows you to send the sketch text to a printer connected to your workstation.

Editor Language: Sets the default language recognized in the text editor. Editor Font Size: Sets the font size used in the text editor. Show Verbose Output: Displays more output during either compiling or uploading. This proves handy if you run into any problems during either of these processes.

Verify Code After Upload: Verifies the machine code uploaded into the Arduino against the code stored on the workstation. Check for Updates on Startup: Connects to the main Arduino. Automatically Associate. You can change these settings at any time, and they will take effect immediately in the current Arduino IDE window. The Edit Menu The Edit menu contains options for working with the program code text in the editor window. The options available under the Edit menu are: Undo This feature enables you to take back changes that you make to the sketch code.

This returns the code to the original version. Redo This feature enables you to revert back to the changes you made undoes an Undo command. Cut This feature enables you to cut selected text from the sketch code to the system Clipboard.

The selected text disappears from the editor window. Copy This feature allows you to copy selected text from the sketch code to the system Clipboard. With the Copy feature, the selected text remains in place in the sketch code. Copy for Forum This interesting option is for use if you interact in the Arduino community forums. If you post a problem in the forums, members will often ask to see your code.

When you use this feature, the Arduino IDE copies your sketch code to the Clipboard and retains the color formatting that the editor uses to highlight Arduino functions. When you paste the code into your forum message, it retains that formatting, making it easier for other forum members to follow your code.

This option comes in handy if you want to post your sketch code onto a web page to share with others. Paste As you might expect, the Paste option copies any text currently in your system Clipboard into the editor window.

Select All Yet another common editor feature, the Select All option highlights all the text in the editor window to use with the Copy or Cut options. You can highlight a block of code and then select this option to automatically mark the code as commented text. The compiler ignores any commented text in the sketch code.

When you finish troubleshooting, you can highlight the commented code block and select this option to remove the comment tags and make the code active again.

Increase Indent This option helps format your code to make it more readable. It increases the space used to indent code blocks, such as if-then statements, while loops, and for loops. This helps the readability of your code. Decrease Indent This option enables you to reduce the amount of space placed in front of indented code blocks.

Sometimes if code lines run too long, it helps to reduce the indentation spaces so that the code more easily fits within the editor window. Find The Find option provides simple search and replace features in the editor window.

If you just want to find a specific text string in the code, enter it into the Find text box. You can select or deselect the Ignore Case check box as required. The Wrap Around check box helps you find longer text strings that may have wrapped around to the next line in the editor window. If you need to quickly replace text, such as if youre changing a variable name in your sketch code, you can enter the replacement text in the Replace With text box.

You can then replace a single instance of the found text, or click the Replace All button to replace all occurrences of the text with the replacement text. Find Next The Find Next option finds the next occurrence of the previously submitted search text.

Find Previous The Find Previous option finds the previous occurrence of the previously submitted search text. Use Selection for Find This option lets you control just what section of your code the Find feature looks in. Instead of searching an entire code file, you can highlight a section of the code and use this feature to find a text string just within the highlighted section.

The Sketch Menu The Sketch menu provides options for working with the actual sketch code. The following subsections describe the various options available under the Sketch menu. If any errors in the program code generate compiler errors, the errors will appear in the console window. This comes in handy if you have multiple library files stored in the sketch folder. Add File The Add File menu option enables you to add a library file to the sketch folder.

Import Library The Import Library menu option automatically adds a C language include directive related to the specific library that you select. You can then use functions from that library in your program code. The Tools Menu The Tools menu provides some miscellaneous options for your sketch environment, as described in the following subsections. Auto Format The Auto Format option helps tidy up your program code by indenting lines of code contained within a common code block, such as if-then statements, while loops, and for loops.

Using the Auto Format feature helps make your program code more readable, both for you and for anyone else reading your code. Archive Sketch This feature saves the sketch file as an archive file for the operating system platform used.

For Windows, this appears as a compressed folder using the zip format. For Linux, this appears as a. Serial Monitor The Serial Monitor option enables you to interact with the serial interface on the Arduino unit. It produces a separate window dialog box, which displays any output text from the Arduino and allows you to enter text to send to the serial interface on the Arduino.

You must write the code in your programs to send and receive the data using the Arduino USB serial port for this to work. Board The Board option is extremely important. You must set the Board option to the Arduino unit that youre using so that the Arduino IDE compiler can create the proper machine code from your sketch code.

Serial Port The Serial Port option selects the workstation serial port to use to upload the compiled sketch to the Arduino unit. You must select the serial port that the Arduino is plugged into. Programmer The Programmer option is for advanced users to select what version of code to upload to the ATmega microcontroller.

If you use the Arduino bootloader format which is recommended , you dont need to set the Programmer option. Burn Bootloader This option enables you to upload the Arduino bootloader program onto a new ATmega microcontroller.

If you purchase an Arduino unit, this code is already loaded onto the microcontroller installed in your Arduino, so you dont need to use this feature. However, if you have to replace the ATmega microcontroller chip in your Arduino, or if you purchase a new ATmega microcontroller to use in a separate breadboard project, you must burn the bootloader program into the new microcontroller unit before you can use the Arduino IDE program format for your sketches.

Caution: Working with the Bootloader All the current Arduino units load the bootloader program into the ATmega microcontroller program memory by default. If you purchase an Arduino unit, you wont have to worry about using the Burn Bootloader feature. However, if you purchase a new ATmega microcontroller to use outside of your Arduino, you may or may not have to burn the bootloader program.

Some vendors preload the bootloader program for you, others dont. Check with your vendor to find out which option they use. If the bootloader isnt burned onto the microcontroller, your Arduino programs wont work correctly.

Upload the right arrow icon : Uploads the compiled sketch code to the Arduino unit. Open the up arrow icon : Displays the File Open dialog box that allows you to select an existing sketch to load into the editor. Save the down arrow icon : Saves the sketch code into the current sketch filename.

Serial monitor the magnifying glass icon : Opens the serial monitor window to interact with the serial port on the Arduino unit. Now that youve seen the menu bar and toolbar options, the next section walks through the basics of setting up the Arduino IDE to work with your Arduino unit. Exploring the Message Area and Console Window The last two sections of the Arduino IDE are provided to give you some idea of whats going on when you compile or upload your sketch.

The message area is a one-line section of the Arduino IDE interface that displays quick messages about whats happening. For example, as you compile the sketch, it shows a progress bar indicating the progress of the compile process, as shown in Figure 3. The console window often displays informational messages from the last command you entered. For example, after a successful compile, youll see a message showing how large the program is, as shown in Figure 3.

If there are any errors in the compiled sketch code, both the message area and the console window will display messages pointing to the line or lines that contain the errors. However, youll need to check on two main things before you start working with your Arduino unit.

This provides a list of the various Arduino boards available, as shown in Figure 3. Select the board model that youre using to ensure the compiler generates the proper machine code for your Arduino unit. The second thing to check is the serial port. You should see a list of the available serial ports installed on your workstation, as shown in Figure 3. The serial ports listed will depend on your workstation configuration, and what devices you have connected to your workstation. Select the serial port that points to your Arduino IDE.

Tip: Finding Serial Ports in Windows With Windows, it can sometimes be tricky trying to figure out just which serial port the Arduino unit uses.

The easiest way to determine the serial port is to open the Device Manager utility in Windows. From the Device Manager utility, you should see a Ports section. Using the Serial Monitor The serial monitor is a special feature in the Arduino IDE that can come in handy when troubleshooting code running on your Arduino, or just for some simple communication with the program running on the Arduino. The serial monitor acts like a serial terminal, enabling you to send data to the Arduino serial port and receive data back from the Arduino serial port.

The serial monitor displays the data it receives on the selected serial port in a pop-up window. Click the serial monitor icon on the toolbar. If youve selected the correct serial port for your Arduino unit, a pop-up window will appear and connect to the serial port to communicate with the Arduino unit serial port using the USB connection.

You can enter text in the top line of the serial monitor interface and then click the Send button to send it to the Arduino unit via the serial port. The serial monitor window also displays any text output from the Arduino unit in a scrollable window area. Three setting options are available at the bottom of the serial monitor window: Autoscroll: Checking this option always displays the last line in the scroll window.

Removing the check freezes the window so that you can manually scroll through the output. Newline: This option controls what type of end-of-line marking the serial monitor sends after the text that you enter. Which you select depends on how you write your Arduino sketch to look for data. Baud Rate: The communications speed that the serial monitor connects to the Arduino serial port.

By default, the serial monitor will detect the baud rate based on the Serial. Caution: Starting the Serial Monitor When you start the serial monitor, it automatically sends a reboot signal to the Arduino unit, causing it to restart the program thats currently loaded into the flash memory.

You learned about each of the menu bar and taskbar options, including how to create, save, compile, and upload your Arduino sketches.

After that, we looked at the serial monitor feature in the Arduino IDE. The serial monitor enables you to send and receive text with the Arduino unit using the USB serial port. This is a handy feature when youre trying to debug Arduino program code.

In the next hour, we create an Arduino program so that you can get a feel for the Arduino IDE and for working with your Arduino unit. Which tool should you use to send data to the Arduino unit? Message area B. Console window C. Serial monitor D. Toolbar 2. The upload icon the right arrow icon on the toolbar will automatically verify and compile the sketch code before uploading it.

The serial monitor enables you to send and receive data from the Arduino unit. Clicking the upload toolbar icon will first verify and compile the sketch code before trying to upload it, even if youve already compiled the code previously. The Arduino unit will appear as an available serial port in the listing. No, the Arduino IDE is written using the Java programming language, and it creates a common window interface on all three operating system platforms.

Can I upload the sketch code to my Arduino unit using a wireless connection? No, at this time you can only upload the sketch code using a serial USB port connection. Will the Arduino IDE editor window point out syntax errors in my sketch code before I try to compile it? The Arduino IDE editor will highlight library function names and text that it thinks is part of a string, but it cant pick up all syntax errors in your code.

Hour 4. Creating an Arduino Program. Now that youve seen what the Arduino is and how to program it using the Arduino IDE, its time to write your first program and watch it work. In this hour, you learn how to use the Arduino IDE software package to create, compile, and upload an Arduino program.

You then learn how to interface your Arduino with external electronic circuits to complete your Arduino projects. Building an Arduino Sketch Once you have your Arduino development environment set up, youre ready to start working on projects.

About Heritage Lincolnshire. Explore with us. Explore Lincolnshire's heritage. Learn with us. Learning resources and courses. Work with us. Services we offer. Support us. Support our work. LibriVox volunteers narrate, proof listen, and upload chapters of books and other textual works in the public domain. These projects are then made available on the Internet for everyone to enjoy, for free.

There are many, many things you can do to help, so please feel free to jump into the Forum and ask what you can do to help! See also: How LibriVox Works. LibriVox volunteers are helpful and friendly, and if you post a question anywhere on the forum you are likely to get an answer from someone, somewhere within an hour or so.

So don't be shy! An innovative data solution providing search and analytics capability right out of the box, it is used by developers to create quick and easy data solutions for a variety of situations easily. A popular non-relational DBMS, it stores data in sectors accessible by a unique key.

Its simple, high speed functionality makes it popular for mobile apps, web apps and e-commerce platforms. Lorem ipsum dolor sit ametsed do tempor aliqua.

Ut enimnisi ut aliquipea. Our innovative 5-step web development process helps us to develop a variety of websites. Ranging in complexity from small static sites to large enterprise solutions, the process below helps us deliver perfection every time. Our developers convert the beautiful website design into a user-friendly custom website, efficiently transforming your business needs into a well-functioning website.

We tweak and optimize the configuration so that you can manage your webpages, automate deployments, scale your website, and most importantly, keep it running perfectly. From simple websites to large scale e-commerce portals, our web developers excel at creating highly efficient websites. These are just a few of the many ways our web development company stands out from the competition. This is what brands expect when they choose us to develop innovative business websites.

Find how our full-cycle website development services help you reach new heights in the industry, precisely by setting you apart from the competitors. Have a look at what our clients have to say about our custom logo design services. Every website we design and develop, whether it is for a small business or a large enterprise, is SEO compliant.

They help you design, develop and maintain a website, a web app or a complete web solution combining the two.



0コメント

  • 1000 / 1000