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

Apress - Smart Home Automation with Linux (2010)- P16 pot

5 278 0

Đ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 5
Dung lượng 397,25 KB

Nội dung

CHAPTER 2 ■ APPLIANCE HACKING 58 Hardware Hacks The hacks in this category will involve changes you can make either to existing hardware or to new hardware you can easily build that controls, or is controlled by, an existing computer. Linksys NSLU2 The existing NSLU2 unit (aka the Slug) requires no hardware hacks to make it run any of the custom Linux firmwares covered earlier. However, you can improve the unit with various hacks. Always On Like most consumer hardware, the Slug has an on/off button. For normal operation, this is fine. But for a home automation system, which is generally intended to work 24/7 (like the rest of the house), this can cause problems whenever there is a brief power outage, since the machine then needs to be manually switched back on. Also, if you are controlling the Slug’s power remotely, maybe through a timed X10 appliance module or stand-alone timer, it won’t fully turn on since it needs the button to be pressed. In the first instance, there are obvious solutions here, such as putting the Slug onto a UPS or keeping it accessible so you can manually control it. However, these negate the benefits of it being cheap, hidden, and (importantly for HA) controllable. You can solve this by invalidating your warranty by performing one of several hardware hacks to ensure the machine always switches on when the power is applied. These vary from using USB Y-cables in various configurations to soldering components to the board. All are detailed, with their relative merits online (www.nslu2-linux.org/wiki/HowTo/ForcePowerAlwaysOn). Overclocking Prior to 2006, all Slugs ran slower than necessary since their CPUs were clocked at 133MHz, despite the chip being designed to run at 266MHz. This technically meant the original versions were underclocked, which means the following hack is known as de-underclocking, rather than overclocking. If you log into your Slug (through telnet or ssh, depending on your firmware) and type the following: cat /proc/cpuinfo you’ll see a BogoMIPS value, indicating the currently speed. If this is within 10 percent of the 133 value, then you can improve the speed by removing the resistor shown in Figure 2-1. CHAPTER 2 ■ APPLIANCE HACKING 59 Figure 2-1. The de-underclocking resistor (second from the bottom in the R84 stack). Image from http://www.nslu2-linux.org/gallery/hardware released under cc-by-sa. You can remove it using nail clippers, a soldering iron, a saw, or any combination of the above. Just be sure to not to damage any other components. Serial Port You can use a standard serial port for two-way communication between many pieces of old technology such as joysticks, along with LCD text displays and other forms of home-brew electronics. It also provides a way of controlling the Slug through getty when other routes, such as the network, are failing. There is already a serial port hidden away at J2 on the Slug motherboard. Alas, its control voltages are 0/+3.3v, and not the +/-12V necessary for the standard RS-232 serial port, which means you’ll require a power-level converter. (However, strictly speaking, the standard requires hardware to differentiate between voltages in the range of +/- 3–15V.) Some converters can be purchased as a single chip (such as the MAX3232) or already included in some mobile phone data cables. You can find full details on the web site (www.nslu2-linux.org/wiki/HowTo/AddASerialPort). There are also circuits available that allow you to connect an LCD character display (such as the HD44780) to the Slug with a minimum of effort, providing a basic (and very low-power) display to report the current media playing or the machine status. However, this also requires opening your Slug to make hardware adjustments. If you’d prefer, the Pertelian 5 plugs into the external USB and achieves the same effect. It is supported through the standard software available in OpenSlug, thereby making this the most effective way of having a display on the Slug available in a silent environment. 5 Being USB, this can also plug into any standard PC, or you could hack a PicoLCD or build one of the many circuits on the Web (such as at http://forums.bit-tech.net/showthread.php?t=115461 or http://spritesmods.com/?art=picframe&page=1, which converts a photo album key ring into a display device). CHAPTER 2 ■ APPLIANCE HACKING 60 LEGO Mindstorms First released in 1998, LEGO Mindstorms was originally known as the Mindstorms Robotics Invention System (RIS) Kit and contained a control brick known as RCX to which you uploaded a program with infrared. The software would then run, control the various motors and sensors connected to the RCX brick, and communicate with others via IR. This naturally had the usual problems associated with IR as covered in Chapter 1 (primarily line of sight). There were two versions of RCX released, and both operated the IR at different carrier frequencies (although both RCX modules can transmit on either frequency) but were functionality identical. The programming could be done in many languages, including cut-down versions of Java, C/C++, Lisp, and Forth, provided it was compiled into suitable code for the internal microcontroller, a Renesas H8/300. Because of its age, it is now available fairly cheaply, although the supplied IR transmitter has no support for any 64-bit operating systems and is losing support for newer 32-bit ones. From RCX, LEGO moved to Mindstorms NXT in 2006. This increased the specification of the main brick by improving the processor (now a 32-bit ARM7/TDMI chip) and communications devices (it now included USB, Bluetooth, and an onboard 100 ×64 pixel LCD matrix). This upgrade in processor has necessitated a change in control software, but that is to be expected, and most of the RIS code has now been ported to NXT. The LEGO components also improved, as shown in Table 2-1. Table 2-1. LEGO Mindstorms Specifications Kit Motors Touch Sensors Light Sensors Ultrasonic Sensors Sound Sensors Color Sensor RIS 2 2 1 NXT 3* 1 1 1 1 NXT 2.0 3* 2 1 1 1 NXT Education 3* 2 1 1 1 * These are servo motors, which internally monitor their position for greater positional accuracy. Since 2009, Mindstorms has been on its third iteration (NXT 2.0) and consists of the same RCX brick as NXT version 1.0, some alternative LEGO Technic bricks, and a change in sensor from sound to color. This was an odd change, since now all NXT 2.0 robots are deaf by default! This might have been a ploy to sell more add-on sensors, however, but for the wily hacker, these can be made much more cheaply using standard electronic components using instructions found on the Web or in various books, such as Extreme NXT. 6 Where LEGO Mindstorms excels is its ability to rapidly prototype hardware that can be controlled by the computer, as well as remote sensors that can relay information back to it. This provides a method 6 Formally called Extreme NXT: Extending the LEGO MINDSTORMS NXT to the Next Level (ISBN 978-1590598184) CHAPTER 2 ■ APPLIANCE HACKING 61 whereby the computer’s state can be demonstrated by something in the real world. Similarly, it allows the real world to be understood, to some degree, by the computer. Home automation is full of ideas, and not all of them have the staying power to enhance your living once their novelty has worn off. This makes LEGO perfect as a means of building proof-of-concept hardware before devoting time and money on PIC chips, motors, and cases that will be used for only one project. Here are some ideas: • Create a robot that waves, or gestures, when an email, private instant message, or phone call is received. • Use the LCD on the NXT processor block to relay information, such as weather. • Create a robot to open the fridge and bring beer into the living room. 7 • Create a Bluetooth gateway for sensors and devices around the house (for a cat flap or pressure mats). The handling of each sensor and motor is very simple since it’s simply a matter of programming, using one of the available Linux environments, such as leJOS NXJ (Java for LEGO Mindstorms) or NXC (Not eXactly C). There are books and web articles abound on the subject, including this useful start point: http://vikram.eggwall.com/computers/nxt.html. Arduino as an I/O Device The Arduino and its clones are microcontroller boards that you can think of as grown-up LEGO—it provides a simple way of interfacing the real world with the computer, handling basic processing tasks on a chip (instead of in software), and working with hardware motors and sensors. There are many forms of Arduino, based on simple microcontrollers, but the most common development version is the Arduino Diecimila based on the ATmega168 chip, although this is being superseded by the Arduino Duemilanove using the Atmega 328. It supports 14 digital pins that can be configured as either input or output and 6 analog inputs. The missing part here is analog output, which can be provided by using pulse width modulation (PWM 8 ) on 6 of the 14 existing digital outputs or with additional electronics. Power can be provided by the USB port, by a power socket, or by connecting the wires from a battery clip to the board. An onboard jumper is used to switch between USB and external power sources. 7 This is a difficult one to build, by the way, because the suction on most fridge doors is more powerful than the LEGO motors. 8 PWM is where the digital output voltage is switched between high and low so that the average voltage, over time, is somewhere between the two. Not all hardware can be powered like this, however, but it is a cheap compromise. CHAPTER 2 ■ APPLIANCE HACKING 62 To those used to large machines, the specification of the ATMega168 chip appears rather small: • 14KB of available Flash memory, for software • 1KB of SRAM, for data • 512 bytes of EEPROM, for permanent data; acts like a mini hard disk • 16MHz clock speed Even the ATMega328, with double the memory capabilities, seems less than adequate. However, the tasks the Arduino will generally perform are very simple and usually in the realm of comparing various inputs and performing simple logic, so this specification is more than large enough. The complex tasks found in operating systems, like TCP/IP stacks, are not usually necessary since you can transmit requests to a connected PC for these tasks. And when they’re not, the problem is generally solved in hardware by building the appropriate circuit and including the necessary driver software for that hardware component. If you’re experienced with other microcontrollers or PIC chips, the Arduino isn’t different in any technical way to them, so you can continue to use whatever chips you have used previously. However, the Arduino offers many benefits to those less used to electronics: • A C-based language and development environment, instead of assembler. • USB input/output control as standard. • A large community of hackers, publishing project designs and sharing tips. • Robust development boards that are less likely to blow up if you wrongly connect something. • A wide range of prebuilt, compatible circuit boards (called shields) to provide more complex functionality such as wireless communication. You’ll see some examples later in the chapter in the “Arduino Hardware” section. • And, for the purists, open source hardware and architecture. This is an often overlooked point. Having the hardware open source allows clone makers, such as Seeeduino, to exist. Clones can be cheaper and more robust and can use surface- mount components while still remaining pin compatible with the Arduino and its assorted shields. The scope of possible projects is similar to that of the LEGO Mindstorms, although now the circuits can be very much smaller, involving more discrete components and wider functionality achieved through the aforementioned shields. Whereas a LEGO device might be able to beep or play a short sound to indicate the arrival of an e-mail, the Arduino can use speech synthesis or full audio playback. Installation and Setup All Arduino software is written on a PC and transmitted to the board through USB. This is also used to receive any data the Arduino chooses to transmit, by default through /dev/ttyUSB0. (Remember to add your user into the dialout group so that /dev/ttyUSB0 is accessible.) The development can take place in any fashion you desire, but it is simplest with the Java-based IDE. Even if you adopt a command-line approach, the code will need to be compiled using the avr-gcc toolchain, which can be installed under Debian with this: . is simplest with the Java-based IDE. Even if you adopt a command-line approach, the code will need to be compiled using the avr-gcc toolchain, which can be installed under Debian with this:. this is within 10 percent of the 133 value, then you can improve the speed by removing the resistor shown in Figure 2-1 . CHAPTER 2 ■ APPLIANCE HACKING 59 Figure 2-1 . The de-underclocking. (second from the bottom in the R84 stack). Image from http://www.nslu2 -linux. org/gallery/hardware released under cc-by-sa. You can remove it using nail clippers, a soldering iron, a saw, or

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