Microsoft.NET Gadgeteer Electronics Projects for Hobbyists and Inventors Simon Taylor Mc Graw Hill New York Lisbon Londi Mill Seoul Sinj
Contents Foreword Acknowledgments Introduction ix xi xii PART I Getting to Know.NET Gadgeteer 1 Introduction to.net Gadgeteer 3.NET Gadgeteer Basics 3 Hardware Interface 3 Firmware 4 Micro Framework and Gadgeteer 4 TinyCLR 5 Base Class Layer 6 Gadgeteer Architecture 6 Hardware Interface 7 Firmware Interface 8 Creating Gadgeteer Applications 8 Serial Camera Module 9 The Application Designer 9 2 Software Development Environment 15 Install Visual C# 2010 Express 15 Install the.net Micro Framework 19 Install the Gadgeteer Core SDK 23 Gadgeteer Documentation 26 Gadgeteer Mainboard and Module Project Templates 26 Install Gadgeteer Mainboard and Modules SDK 28 Tour of the Gadgeteer Development Environment 28 Summary 39 3 Gadgeteer Sockets, Mainboards, and Modules 41 Gadgeteer Sockets 42 Mainboards 45 Modules and Interfaces 47 Module Base Class 48 DaisyLinkModule Base Class 49 DisplayModule Base Class 50 NetworkModule Base Class 51 V
yj Contents Gadgeteer Application 52 Program Base Class 52 Application 54 Gadgeteer Interfaces, Utilities, and Services 56 Interfaces 56 Utilities 56 Services 58 4 Gadgeteer API Interfaces 59 Analog Input and Output 59 Analoglnput Class 59 AnalogOutput Class 60 Digital Input, Output, and Input/Output 61 Digitallnput Interface 61 DigitalOutput Interface 61 Input/Output: DigitallO Interface 61 Interruptlnput Class 62 PWMOutput Class 63 I2CBus Class 64 Serial Class 65 SPI Class 66 5 Gadgeteer Mainboards and Modules 69 Gadgeteer Mainboards 69 GHI Electronics 69 Mountaineer Group 71 Love Electronics 74 Sytech Designs Ltd 75 Gadgeteer Modules 76 Ethernet, WiFi, and SD Cards 76 Graphics Displays 76 I2C and SPI Modules 77 Serial Modules 77 6 Deploying and Debugging 79 TinyCLR and TinyBooter 80 Using MFDeploy 80 MFDeploy Main Screen 81 MFDeploy Functions 83 Deploying and Debugging with Visual Studio 88 Build the Project 89 Set a Breakpoint 91 Immediate Execution 92 Single-Step Through Code and Move the Execution Point 93... More Visual Studio Features 93
Contents vii PART II Projects 7 Writing Gadgeteer Applications 97 Sequential and Event-Driven Applications 97 Sequential vs. Event-Driven Design Basics 98 Adding Battery Power Savings 98 Gadgeteer Application Flow 100 The Gadgeteer Application Template 100 Application Thread 102 Classes and Project Code Files 104 Using Sequential Application Code 107 Summary 110 8 Data Input and Output Projects Ill Create an Empty Solution in Visual Studio Express Ill SPI Display Module Using Project Resources 116 Adding Project Resources 117 I2C Accelerometer and Process Data Threads 121 Gadgeteer DaisyLink 126 A Combined Module Project 129 Create the Project 131 JoyInput Class with Event 133 DemoApp Class 136 Gadgeteer Program.cs 139 Summary 140 9 Serial Communications Projects 141 Building a Serial Comms Project Using a Serial2USB Module 141 Create the New Project 142 Start and Debug the Application 147 Start the Terminal Application 148 Changing Serial Port Physical Settings 151 Serial Message Data Handling 154 10 SD Card and File Projects 159 Mounting and Unmounting Removable Media 159 GHI-Based Mainboard 160 Sytech NANO Mainboard 162 Directory and File Handling 163 Using the StorageDevice Class 163 Save and Restore Setup Data Project 168 Adding Classes to the Project 169 The Program.cs File 173 Micro Framework Extended Weak References 176
vjjj Contents Text and CSV File Projects Simple Text Logger Project CSV File Project Summary 176 176 180 186 11 Ethernet and Web Device Projects 187 Sockets 188 Device Network Configuration 189 TCP/IP Server Project 192 Web-Connected Devices 205 Web Server 205 Web Client 210 Additional Micro Framework Network Support 211 Summary 212 PART III Build Your Own.NET Gadgeteer Hardware 12 Designing Gadgeteer Modules and Mainboards 215 Modules 217 A Simple Custom Prototype Module 217 Using the Module Project Template 218 GadgeteerHardware.XML 221 MSI Generation 222 Mainboards 225 13 Turning Your Gadgeteer Prototype Into a Product 227 Use Modules or Design a Custom Board 227 Packaging Your Prototype 229 A Gadgeteer and Micro Framework 4.2 231 Gadgeteer MF 4.1 and 4.2 Applications 231 MF 4.3 and Visual Studio 2012 232 Index 235