Eighth example: NXT brick as embedded system (NxtJLibA autonomous mode) Purpose: Use the NXT brick as a controller in a feedback control system that keeps the temperature of a heater at a constant level. It is generally admitted that an embedded system is a special-purpose computer system designed to perform a few dedicated functions. It is usually embedded as part of a complete device including hardware and mechanical parts. The heart of an embedded system is often a microcontroller that runs a single program stored in a read-only memory (Eprom, Flash). In contrast to a general-purpose computer, the microcontroller contains digital and analog ports in order to communicate easily with external hardware devices such as relays, switches and sensors. The NXT brick is a typical embedded system with its three microprocessors: The 32-bit controller Atmel AT91SAM7S256 runs your programs. It includes a flash memory, a RAM and the USB device interface. The 8-bit Atmel ATMEGA48 manages the pulse width modulation (PWM) of the motors and uses the feedback from the NXT motor rotation sensors to tune the power of each motor. Finally the CSR Bluecore 4 microcontroller performs the Bluetooth communication. Input/Output of the Lego brick is somewhat dedicated to motor and sensor ports. There are no general purpose analog or digital I/O ports, but HiTechnic (http://www.hitechnic.com) developed a Prototype Kit that connects to the brick like an I2C sensor and expands the I/O capabilities of the NXT by 5 analog input channels (0..3.3V, 10 bit) and 6 digital input/output channels (3.3V). There are two versions available, one with a solder breadboard where additional electronic components (resistors, LEDs, ICs, etc.) may be mounted, and one with a solderless experimental breadboard to add external circuitry for developments and tests.
High-power outputs (switching line voltage up to several amps) can be obtained by adding a solid-state relay, such as the Crydon ASO242 (up to 2A @ 280V). Care should be taken to enclose all high-voltage parts in a separate housing, e.g. a power socket-outlet (see figures below). Because the Prototype Kit uses 3.3V logic, a driver should be used, such as the ULN2803. The extra 5V-supply of the Prototype Kit can be used to power the ULN2803. With this design all power is delivered by the NXT brick and no external power-supply is needed. The NXT brick expanded with the HiTechnic Prototype Kit is very convenient to demonstrate many aspects of embedded systems. The following program simply reads the temperature from a Lego temperature sensor and switches a hotplate (heating lamp, soldering-iron, etc.) on and off to keep the temperature at a certain level. // TempReg.java Discussion: Because there is no class for the temperature sensor in the NxtJLib library, we use the temperature sensor like a light sensor. We derive class TemperatureSensor from LightSensor, so we have all methods of LightSensor available. To avoid the typical fast oscillations of the control system, a hysteresis is used.
Assembly of the driver/solid state relay:
Schematic diagram:
Distributors (for Switzerland): HiTechnic NPT1050 (http://www.educatec.ch)
| ||||||||||||||||||||