1. Trang chủ
  2. » Công Nghệ Thông Tin

Practical Arduino Cool Projects for Open Source Hardware- P44 potx

10 301 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 359,17 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

After each one, add a single tab not spaces and specify whether it is a class KEYWORD1 or method KEYWORD2.. In our case, we have just one class and one public method, so the end result l

Trang 1

CHAPTER 16 „ RESOURCES

409

Add a file called keywords.txt to your library directory and list the class and functions in it After

each one, add a single tab (not spaces) and specify whether it is a class (KEYWORD1) or method

(KEYWORD2) In our case, we have just one class and one public method, so the end result looks like

this:

TouchScreen KEYWORD1

read KEYWORD2

If our class happened to have more methods in, it they would also be labeled with KEYWORD2 The IDE will then highlight anything labeled KEYWORD1 in orange and anything labeled KEYWORD2 in

brown

Restart your IDE, open the example ReadTouchscreen program again, and you should see that the syntax highlighting is now correct

The complete TouchScreen library is available for download from GitHub, so if you want to see the end result and how it all fits together you can grab it from github.com/practicalarduino/TouchScreen

Platform-Specific Variations

Most of the time you can write a library that will run perfectly well on just about any Arduino, from a

Mini to a Mega, with no changes required Sometimes, though, there are differences between the various Arduino models that can cause problems, and the TouchScreen library we used in this example is one of them The code as described here will work perfectly well on almost all Arduino models, but will break

on a Mega because it has a different system for numbering its analog and digital pins On most Arduino models analog pins 0 through 5 can also be referenced as digital pins 14 through 19, and we do that in

the library by simply adding 14 to the analog pin number to derive the digital pin number

But the Mega has far more I/O pins, so rather than starting the analog pins at number 14, it starts

them at number 54 The result is that the code we’ve created here will appear to compile cleanly on a

Mega, but will totally fail to work because it will be referencing the wrong pins

Luckily, this problem is made very easy to solve because we used a #define to specify the value for

DIGITAL_OFFSET, and we can use special values set in the build environment to make decisions about how the library should be compiled and then build it differently in different circumstances Doing an

explicit check for the ATMega1280 CPU used in the Arduino Mega, we can change the original single

#define entry so that it instead defines one value for the Mega and a different value for anything else

#if defined( AVR_ATmega1280 )

#define DIGITAL_OFFSET 54

#else

#define DIGITAL_OFFSET 14

#endif

The library will then work interchangeably on normal Arduino models and also on the Mega

Summary

The Arduino is an incredibly useful platform, capable of controlling both practical projects and fun

gadgets It also has a very strong and enthusiastic community of developers and gadgeteers, and we

hope you will enjoy becoming part of that community

Trang 3

411

Index

Symbols and

Numerics

#define, 251, 342

1.5V batteries, 10

1/4W resistors, 14

1K resistor, 86−87, 90, 246

1N4004 diodes, 24

22uF electrolytic capacitor, 276

3D cube program, 129

433MHz re ceiver module, 243

433MHz re ceiver modules, 240

47uF electrolytic capacitor, 321−322

4-bit mode, 169

4K7 EOL resistors, 86

4K7 pull-up resistor, 86−87

4K7 pull-up resistors, 90

6-pin mini-DIN panel sockets, 67−69

6-pin mini-DIN sockets, 66

6V battery, 10

74HC4094, 169

78xx series regulators, 383 −384

9V batteries, 10

A

accu_ trip() function, 356

ADC, 194−197

division factor, 196

prescaler bits, 196

ADC clock rate , 196

ADR79/01, 296

Aiko application framework, 45 −46

alarm sensor shield, 87−92

alarm systems See security systems

alligator clip, 194 Allophone Speech Processor, 139 allophone-based speech synthesis, 142 allophones, 142, 157, 160

Allophones, 154 allowedTags array, 290 ambient atmospheric pressure, 209 amperes (A), 2

amplifier for speech synthesizer, 149−151 analog circuits , 392

analog voltage converting to digital value, 194−197 analogRead() function, 99, 229

analog-to-digital converters (ADCs), 186 analyse_cmd(), 110

analyse_cmd() function, 113 appliance remote control instructions

assemble reed relay shield, 21−25 connect reed relay shield to remote control, 25

create reed relay control program, 27−28, 30−32

test and investigate appliance remote, 19−21

parts required, 17 −18 schematic, 18

test reed relay shield, 32−33 variations

automatic trigger, 34 socket conne ctions , 35

Trang 4

412

wireless link, 34

appliance remote control, 17, 35

Appliance RemoteControl, 27−28, 30

Appliance RemoteControlCompact, 27,

30−32 Arduino

connecting keyboard to, 63, 80

connecting mouse to , 63, 76 −78

mounting, 137

Arduino community

sharing work with, 1

Arduino Duemilanove See Duemilanove

pin-change interrupts for, 345

Arduino library

writing, 401, 404 −406, 408

develop functionality, 402 −403

encapsulation of, 403−405

example sketch, 407 −408

library class file, 405−407

library header file, 403−405

platform-specific variations , 409

supporting files, 408−409

Arduino Mega, 175, 184, 189

pin-change interrupts for, 346

Arduino Pro Mini, 189

Arduinoscope, 204 −205

arrays

multidimensional, 253

ASCIINUMBASE, 251

AT keyboard, 63−64

ATDPN (ATtentionCOL Des cribe Protocol

by Number) command, 353 ATMega chip, 13

ATMega chips, 139

ATMega CPU, 166−167, 190

ATMega1280 CPU, 296

attachInterrupt() function, 179

B

back-EMF , 24

BAP tags, 270

barcode reader, 79

batteries, 10

battery-assisted passive (BAP) tags, 270 bidirectional interfaces, 168

bipolar transistors, 15

bipolar transitors, 391 −392 bit banging, 116 , 296 blinkLed() function, 47 Buffer Half Full signal, 161 button de-bouncing, 180 buttonState variable, 342

C

C++ methods, 406 C++ objects, 403 camera shutter release camera modification for, 43 infrared remote control, 42, 43 remote release connector, 40 −42 Canon cameras , 41−42

capacitance (C), 11-13 capacitors, 11 −13, 15 carAlarmScreen option, 340, 381 Cat5 network cabling, 8

cathod-ray oscilloscopes (CRO), 186 cbi() function, 199

charlieplexing, 387 −388 check_mil_code() function, 359 −360 checkSensor() function, 96−97 checksum calculation function, 259 chording keyboard, 61

clamping, 55 CLOCK pin connection, 74, 76 config parame ters, 363 config_menu() function, 363 constrain() function, 137, 229 contras t adjustment trimpot, 169 Controller-Area Ne twork (CAN) , 302 CPU RAM allocation, 365

Creative Commons licenses, 1 current, 2, 388

current limiting, 7−8 current-limiting resistors, 245 custom input devices, 51

Trang 5

413

D

DATA pin connection, 74, 76

DB9 socke t, 333−334

DB9 to OBD-II cable, 313

DC plugpacks, 11

DEBUG option, 339

decoupling capacitor, 244

defines, 251−252

delay loops, 45

delay() function, 45

delayMs() function, 57

detachInterrupt(), 181

diagnostic trouble codes (DTCs), 357 −361

digital input/output e xpansion, 393 −396

digitalWrite(), 331

diodes, 8−9, 15

reverse biased, 24

display() function, 353, 356−357

displayAlarmScreen() function, 381

DIY shields, 72, 73

double end-of-line resistors, 86

draw(), 129

dropout voltage, 384

DS18B20 temperature sensors, 103, 107,

108, 118

Duemilanove, 189

E

ECU polling, 340

ECUs (electronic control units), 352

EEPROM (Electrically Erasable

Programmable Read-Only

Memory), 324

eeprom_read_word() function, 363

eeprom_write_block() function, 363

efficiency

of voltage regulators, 384

electro-me chanical relays

operation of, 24

electronic circuits

debugging, 185

electronics

basics, 1−13 capacitance and capacitors , 11−13 choosing wire, 8

current limiting, 7−8 current, voltage, and power, 2 diodes, 8−9

ESD precautions, 13 mains voltages, 2−3 Ohm's law, 7−8 power supplies, 9−11 resistance, 6 −8 resistors, 6−7 schematics, 3−5 electrostatic discharge (ESD), 13 elm_compact_response() function, 351,

354 elm_read() function, 351 ELM327

initializing serial connection to , 352 reading from, 351−352

ELM327 adapter, 321 ELM327 chip, 302−303, 308−311 ELM327 OBD-II adapter, 333 ENABLE_GPS option, 339 ENABLE_VDIP option, 339 encapsulation, 404

endKeyStroke() function, 58 end-of-line (EOL) resistors, 84−85, 92,

94−95 engine-management system, 295−296 EOBD (European OBD) standard, 296 erproxy, 265

Etherne t adapters , 103 Etherne t shields, 184, 265 etherShield library, 103, 108 external devices, 388

F

farads (F), 11 field effect transistors (FETs), 392 flash memory chips, 324

Flash movies, 233 floating-point (decimal) numbers , 178

Trang 6

414

floatToString() helper function, 342

flow gauges, 163, See also water flow gauge

four-channel alarm sensor shield, 87−88,

90−92 FTDI chip, 310

G

get_pid() function, 353−356

getPid() function, 348

GGA sentence format, 318−319

global variables, 177

Google Earth, 295, 380

GPS module, 314, 316 −319, 337

GPS serial connection, 323

GPS.pde, 370

gpsdump() function, 370

H

Hall-effect devices, 174

Hall-effect flow sensor, 166, 173, 178

Hall-effect sensors, 163,178

hardware interrupts , 175−176, 347

HD44780 displays, 169

HD44780 interface, 168

HD44780 LCD module, 329−330

HD44780-compatible displays, 168

HD44780-compatible interfaces, 328

heap pointer, 365

heck_supported_pids() function , 347

hex values, 305

high-frequency (HF) RFID tags, 270

home security system, 99

hooked wire, 8

Host.pde , 372−375

Human Interface Device (HID), 59

I

I2C, 324

ickel-cadmium ( NiCd) cells, 10

ID-12 reader module, 287

ID-12 RFID reader modules, 282 −284 IFF systems, 270

image processing Linux, 48 Macintosh, 49 Windows, 48 image tags, 234 impplantable RFID tags , 271 include guard, 403

indicator LEDs, 280−282 Init_RF_Interpreters function, 259−260 initGps() function, 370

initialize() method, 76 initVdip() function, 374 Input Capture Pin (ICP), 253 input conditioning, 396−399 isolated, 398

nonisolated, 396−397 input voltage prescaler, 205−206 input voltages, 396

input/output (I/O) expansion digital, 393−396

interrupt flags, 177 Interrupt Service Routine (ISR), 175, 177 ,

260−261 interrupts disabling, 181

IR (internal resistance) loss, 8 ISO 14230 KWP2000, 302 isolation, 388

ISR (interrupt service routine), 331

K

keyboard software, 73−76 keyboard.read() method, 75

L

lastLogWrite variable, 350 LCD module, 168 −171 for vehicle telemetry platform, 328 −331

Trang 7

415

mounting , 171−172

LCD pin assignments, 340

LCD.pde, 366 −367, 369− 370

lcd_commandWrite() function , 369

lcd_commandWriteSet() function, 368

lcd_gotoXY() function, 367

lcd_init() function, 368

lcd_tickleEnable() function, 368

LEDs, 14

about, 384 −385

charlieplexing, 387−388

current limiting resistors with, 245

driving, 384−385, 387−388

indicator, 280−282

multiplexing, 385−387

status, 90−92

library class file, 405−407

library header file, 403−405

light-dependent resistors (LDRs), 49

linear regulator circuits, 384

line-level output cable, 148−149

line-level signals, 147

Linux

image processing, 48

LiquidCrystal library, 178, 328, 366

lithium polymer (LiPo) batteries, 11

LM2940CT-5 linear voltage regulator, 320

LM386-based audio amplifier, 150

LM7805 voltage regulator , 320−321

load dump, 320

Locosys LS20031 module, 314 −318

logActive flag, 340, 348, 372

logging control button, 331 −332

logic analyzers

about, 186

cost of, 187

logPid byte array, 344

loop() function, 46

low dropout (LDO) regulators, 384

low-frequency (LF) RFID tags , 270

low-pass filters, 147

LQFP-48 format, 325

M

Macintosh image processing, 49 macros, 252

mains voltages, 2−3 map() function, 136 −137, 230 Mass Air Flow parameter, 355 mass-storage devices

connecting, 324−325, 327 mechanical contacts, 391 mechanical switches, 389 −393 MEGA option, 339

memory limitations, 364 −365 memory-mapped peripheral registers, 176 memoryTest() function, 366

metal-oxide–semiconductor field-effe ct

transistors (MOSFETS), 392 MicroSD flash memory cards , 324 millis() function, 183, 260

Mini GPS program, 316−317 mode 0x03, 357 −361

modeButton() function, 372 modifier keys, 74

motion detectors, 81 passive infrared (PIR), 85 mouse input, 63

mouse software, 76 −78 MPGuino, 297

MPX2010DP, 212 multidimensional array, 253 multimeters , 185

multiplexing, 385−387 multistate voltage divider, 99 multithreaded applications global variables within, 177 multiturn variable resistors, 212

N

negative feedback, 212 network proxies, 265 nickel-metal hydride (NiMH) cells, 10 NMEA 0183 sentences, 318 −319

Trang 8

416

nonpolarized capacitors, 12

normally closed (N.C.) sensors, 85

normally closed outputs, 81

normally open (N.O.) sensors, 84−85

normally-closed (N.C.) sensors, 85

nuElectronics, 108

NuElectronics Ethernet Shield, 103

O

OBD-Codes site, 359

OBD-II, 296

modes and parameters, 304−308

OBD-II adapters , 302

OBD-II cable

assembling, 313−314

OBD-II serial connection, 323

OBD-II standard, 301 −302

OBD-II to DB9 cables, 313

OBD-II to USB adapters, 314

OBDtoKML dire ctory, 380

obd-to-kml.php, 380

OBDuino , 297

OBDuino Mega sketch, 338, 340−347, 349,

351−352, 354−356, 358−365, 368−369, 373−375, 377− 378, 380 GPS.pde, 370

Host.pde , 372−375

LCD.pde, 366 −367, 369−370

OBDuino Mega.pde, 339−342, 344 −354,

356−366 PowerFail.pde, 375

using, 376−380

VDIP.pde , 371, 372

OBDUINO.CSV file, 372

OBDuino Mega.pdf, 339

ohms, 6

Ohm's law, 7−8

on-board amplifier

for speech synthesizer, 149−151

On-Board Diagnostics version 2 (OBD -II),

296 online thermometer

instructions, 103

assemble sensors, 106−108 connect data lines , 105−106 load program, 108−118 mount PCB plugs on shield, 103 parts required, 101

schematic, 102 variations, 119 online thermometer, 101, 119 op-amp circuits

negative feedback on, 212 performance characteris tics , 213 tuning, 212

open source software, 1 optocouplers, 389, 393 Organic LED (OLED) modules, 328 oscilloscope/log analyzer

analog read version, 198−200 digital read version, 200−202 digital read version with optimized communications , 202−203 instructions

connection to circuit under test, 197 install software in Arduino, 198 −203 oscilloscope/logic analyzer

input voltage prescaler, 185, 205−207 instructions, 189

case assembly, 190−192 fit proto typing shield, 193 install Processing, 203−205 make test probes, 194 run visualization program, 203−205 successive approximation ADC, 194−197

parts required, 187 −188 resources, 206

schematic, 189 variations, 205−206

oscilloscopes about, 185 −186 cathode-ray , 186 cost of, 187 output circuitry , 388−393

Trang 9

417

P

Pachube, 184, 236

Panasonic cameras , 40, 41

panel-mount socke ts, 67 −69

parallel interfaces, 168

Parameter IDs (PIDs), 304−308

params_load() function, 363

params_save() function, 348, 363

params_t struct, 344

parts, 14−15

passive infrared (PIR) motion detectors ,

85, 92−93

placement of, 98

soldering EOL resistors onto, 94

trigger-and-hold function, 96

triggering of, 94

warming up, 98

PCB plugs

mounting, on shield, 103, 105

PCB-mount 6-pin mini-DIN so ckets, 66

PCB-mount buttons, 20

PCMSK (pin change mask), 345

phonemes, 142

PhotoLapse, 48

PIDs, 342, 354

Pin Change Interrupt Control Register

(PCICR), 346

Pin Change Interrupt number (PCINT),

346

Pin Change Interrupt Register, 346

pin change interrupts, 346

Pin Change Mask (PCMSK), 346

pin-change interrupts, 345− 346

pinMode() function, 200

plugpacks, 11

polarized capacitors, 12

port-level interrupts , 341, 346

power, 2

power dissipation, 384

power failures, 321

power supplies, 9

batteries, 10

USB power, 9

wall warts/plugpacks , 11

power supply bypass, 13 power supply circuit for vehicle telemetry platform, 319 −323 powerFail() function, 375

PowerFail.pde, 375 pressure transducer, 209, 212 above-tank mount, 216 external mount, 219 in-pipe mount, 218 inside-tank mount, 217 installation methods, 216 −218 installation options, 215 pin assignments, 223 pin numbers and ports for, 222 print() function, 230, 234

print_webpage() function, 110-111 println() function, 230

processGpsBuffer() function , 347, 370 processHostCommands() function, 372 Processing, 128−131, 187

Processing programming language, 98 processVdipBuffer() function, 371 PROGMEM directive, 234

PROGMEM keyword, 343 prototyping shields DIY, 399−400 PS/2 barcode scanner, 79 PS/2 conne ctions , 65 PS/2 extension cable, 69−72 PS/2 keyboard, 63, 80 instructions, 64 6-pin mini-DIN panel sockets, 66−69

keyboard software, 73−76 PS/2 conne ctions , 65 PS/2 extension cable, 69−72 parts required, 63 −64

schematic, 65 variations, 79 PS2Keyboard library, 73−76 PS2Mouse library, 76−78 PString class, 339 PString library, 347 pull-down resistors, 166 pull-up resistors, 166

Trang 10

418

pulseCount variable, 176

pulseOutput function, 31, 32

pulse-width–modulated (PWM) carrier,

144 PWM (pulse-width modulation), 302

Q

QuickTime , 49

R

radio antenna, 249

radio antennas, 249

RCA connectors, 143

RDM360 reader, 284−285

read() method, 406

README file, 408

rechargeable batteries , 10

reed relay shield

assembling, 21−22, 24−25

connecting to remote control, 25

testing, 32−34

reed relays, 21, 389− 390

creating control program, 27 − 28, 30−32

for camera controller, 39

registers

setting, 254

relays, 389

about, 390 −391

reed, 389−390

report() function, 77

resistance, 6, 8

resistive touch screens

workings of, 123−126

resistors, 6−7

light-dependent, 49

resolution, 195

resource consumption, 163

reverse biased diodes, 24

reverse spikes, 24

RF_Interpreter_ WS2355() function, 261

RFID access control system

extensible read head, 292

instructions, 274 assemble prototyping shield, 275 assemble RDM630 reader, 284−285 ID-12 reader module, 282−284 indicator LEDs, 280−282 install Arduino, 292 install reader, 291−292 install strike plate, 291 manual release button, 282 power supply, 275−277 relay output, 278 −280 RFID serial connection, 277 −278 variations, 292−294

intelligent desk pad, 294 parts required, 272 −273 resources, 294

schematic, 274 sketch, 285−290 speech synthesizer feedback, 293 RFID access control system, 269, 294 RFID reader modules, 274−275 RFID systems

archite cture, 269 early, 269 RFID tags, 270 −272 RFID technology, 269−270 rocessVdipBuffer() function, 374 RS-232 adapter, 302−303

RTS (ready to send) pin, 349 RXB1 433MHz receiver module, 243,

246−250

S

SAE J1850 standard, 302 sbi() function, 199 scancodes, 73 −74 schematics defined, 3 reading, 3−5 SDuFAT (SD micro FAT), 324 Sealed lead acid (SLA) batteries, 10 security system sensors

Ngày đăng: 03/07/2014, 20:20

TỪ KHÓA LIÊN QUAN