NXT Keyboard for Ordering System
I've been working on an NXT Keyboard for an Ordering System to use with my LEGO Mindstorms NXT Robot Crane with Ball Sorting Conveyor System, in conjunction with my NXT Line Following Dump Truck. The Keyboard uses 6x RCX type Touch switches connected to my RCX-TouchMux Sensor Multiplexer.

Ordering System's Input Keyboard for My Ball Sorting & Delivery Mechanism.
I have one of Mindsensors' TouchMux's, but it doesn't work very well with the legacy RCX style Touch Sensors. Mindsensors make a very good a RCX Sensor multiplexer for NXT, the RXMux which allows you to connects up to 4 RCX style analogue sensors to your NXT. The RXMux Supports the following Sensors:
- RCX Touch Sensor
- RCX Light Sensor
- RCX Rotation sensor
- RCX Temperature sensor
As I often use more than 4 Touch Sensors in many of my Robots, I needed to construct the RCX-TouchMux as there is no commercial equivalent to my Knowledge available.

NXT 8 Input RCX Touch Sensor Multiplexer Unit
The RCX-TouchMux is a fully compatible, I2C Bus Type Sensor, based on a Philips PCF8574 remote I/O expander. It’s a single integrated circuit that includes eight pins that can be either inputs or outputs. The PCF8574 has eight I/O pins that are labelled P0 to P7. Full Details in a previous Article: NXT – 8 Input RCX Touch Sensor Mux.
Demonstration of the NXT Keyboard for Ordering System
The NXT Keyboard for Ordering System allows you to order any number of four different coloured balls by pressing the corresponding key. The Large 'Red Key' cancels the order, while the large 'White Key' sends your order (eventually to the loading crane).
The Keyboard will be run from the Port 2 on the NXT Brick that controls the Crane, Ball Sorter and Conveyor system. With the RCXTouchMux being I2C based, if needed I can parallel up with any other I2C sensor if needed, provided their I2C Address don't clash. The NXTServo which controls the RC Servo Motors is also on Port 2, leaving Port 4, the RS-485 enabled port. RS-485 is required to drive a Dexter Industries NXTBee Modem which will relay to the delivery truck's NXTBee, that an order is ready for pick-up.

Dexter Industries NXTBee uses the Digi XBee Radio Modems
The software is written in NXC, and uses custom NXT Sound files to give audible feedback of inputs. Download Keyboard NXC Code, NXT Sound Files, and RCXTouchMux-lib files: KeyboardCode-and-RCXTouchMux-lib.zip (15Kb)
NXT Keyboard NXC Code:
#include "RCXTouchMux-lib.nxc"
#define RcxTouchMux S4
int OrderMagenta, OrderAqua, OrderYellow, OrderRed;
bool Touched[9];
task main()
{
ClearScreen();
SetSensorLowspeed(RcxTouchMux);
RCXTouchMux_Init(RcxTouchMux);
while (true)
{
NumOut(0, LCD_LINE2, Touched[5]);
if (Touched[5] == true)
{ OrderRed = 0; OrderYellow = 0; OrderAqua = 0; OrderMagenta = 0;
NumOut(60, LCD_LINE4, OrderRed);
NumOut(60, LCD_LINE4, OrderYellow);
NumOut(60, LCD_LINE4, OrderAqua);
NumOut(60, LCD_LINE4, OrderMagenta);
PlayFile("Cleared.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE);
Wait(100); PlayFile("Order.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE);
}
NumOut(0, LCD_LINE1, Touched[1]);
if (Touched[1] == true) { OrderRed = OrderRed + 1; PlayFile("Red.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE); }
TextOut(0, LCD_LINE4, "Red = ");
NumOut(60, LCD_LINE4, OrderRed);
NumOut(20, LCD_LINE1, Touched[2]);
if (Touched[2] == true) { OrderYellow = OrderYellow + 1; PlayFile("Yellow.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE); }
TextOut(0, LCD_LINE5, "yellow = ");
NumOut(60, LCD_LINE5, OrderYellow);
NumOut(40, LCD_LINE1, Touched[3]);
if (Touched[3] == true) { OrderAqua = OrderAqua + 1; PlayFile("Aqua.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE); }
TextOut(0, LCD_LINE6, "Aqua = ");
NumOut(60, LCD_LINE6, OrderAqua);
NumOut(60, LCD_LINE1, Touched[4]);
if (Touched[4] == true) { OrderMagenta = OrderMagenta + 1; PlayFile("Magenta.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE); }
TextOut(0, LCD_LINE7, "Magenta = ");
NumOut(60, LCD_LINE7, OrderMagenta);
NumOut(20, LCD_LINE2, Touched[6]);
if (Touched[6] == true)
{ PlayFile("Balls.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE);
Wait(100); PlayFile("Ordered.rso"); until (SoundFlags() == SOUND_FLAGS_IDLE);
}
NumOut(40, LCD_LINE2, Touched[7]);
NumOut(60, LCD_LINE2, Touched[8]);
Wait(250);
// RCXTouchMux_Watch(Port, ArrayName);
bool any = RCXTouchMux_Watch(RcxTouchMux, Touched);
}
RCXTouchMux Library NXC Code:
/* -------------------------------------------------------------
Sparra's RCX Touch Sensor Mux - Based on PCF8574.
The Mux Allows the use of 8 Standard RCX Type Touch
Switches to be Used with the Lego NXT Brick using
the I2C Protocol.
######################################
##### #####
##### RCXTouchMux Library #####
##### #####
######################################
www.rjmcnamara.com
-------------------------------------------------------------*/
#ifndef RCXTouchMux_lib
#define I2CAddr8574 0x40 // I2C Address
/* -----------------------------------------------------------
Initilize RCX Touch Sensor Number Touched
-------------------------------------------------------------*/
int RCXTouchMux_Init(byte port)
{
SetSensorLowspeed(port);
}
/* -----------------------------------------------------------
Get RCX Touch Sensor Number Touched
--------------------------------------------------------------*/
bool RCXTouchMux_Watch(byte port, bool &Touched[])
{
byte WriteBuf[]={I2CAddr8574,0x00}; // Write Buffer addr & data
byte ReadBuf[]; // Receive from PCF8574
int RdCnt=1; // No. Bytes to Read
ArrayInit(Touched, false, 9); // Initilize Array to Store Switch State
WriteBuf[1] = 0xff; // Make PCF8574 Ready to Read
do
{
I2CBytes(port, WriteBuf, RdCnt, ReadBuf); // Read PCF8574
}
while (ReadBuf[0] == 0xff)
for (int i=0; i<8; i++)
{
// Test if Touch Sensors Acivated
if ((ReadBuf[0] & 1) == 0) {Touched[i+1] = true;} else {Touched[i+1] = false;}
ReadBuf[0] >>= 1; // Shift to Next Byte
Wait(10);
}
return Touched;
}
/* -------------------------------------------------------------
Get RCX Touch Sensor Number Touched
---------------------------------------------------------------*/
bool RCXTouchMux_Switch(byte port, bool &Touched[], int Switch)
{
byte WriteBuf[]={I2CAddr8574,0x00}; // Write Buffer addr & data
byte ReadBuf[]; // Receive from PCF8574
int RdCnt=1; // No. Bytes to Read
ArrayInit(Touched, false, 9); // Initilize Array to Store Switch State
WriteBuf[1] = 0xff;
// Make PCF8574 Ready to Read
do
{
I2CBytes(port, WriteBuf, RdCnt, ReadBuf); // Read PCF8574
}
while (ReadBuf[0] == 0xff)
ReadBuf[0] >>= Switch - 1; // Shift to Switch Byte
if ((ReadBuf[0] & 1) == 0) {Touched[Switch] = true;} else {Touched[Switch] = false;}
Wait(10);
return Touched, Switch;
}
#endif
loading...
loading...

Download PDF format





[...] Keyboard for inputting you distance guess [...]