nxt custom sensors - voyagerusers.actrix.co.nz/manningc/lego-nxt/nxt_custom_sensors.pdfnxt custom...
TRANSCRIPT
NXT Custom SensorsCharles Manning
● Overview of existing sensors● Making your own cables● Making your own sensors
Standard Lego sensors
● Touch switch● Light sensor + output LED● Ultrasonic distance (up to 255 cm)● Sound● Others
– Battery voltage– Time– Quadrature encoders in motors
Third party
● Bluetooth– Serial port profile– GPS– Cellphone– Laptop
● I2C (hightechnic etc)– Tilt– Gyro– Compass– ...
Connectors
RJ12 Lego Lego
Lego “Modified RJ12” connector
● Same size and pins as RJ12 6P6 modular connector● Latch is offset for safety?
– Can't plug in phone/modem/etc.● Pin 1 is latch side.● Cable
– 6way modular telephone cable ( sicom CAM6)– 1mm pitch ribbon for extra flexibility– Max 1 metre (according to Lego, longer should be OK)
Modified crimp tool
● Standard RJ12 6P6C– NB Not cheap RJ11 6P4C tool!
● Small file, time and care– File away space to allow the latch to fit.
● You can always borrow mine.
Sourcing special connectors
● mindsensors.com– Special offset plugs & sockets
● Pugs approx USD0.50● Sockets approx USD1
– Extra cables– ... and other bits & pieces
● hightechtic.com
Connector pinout● Analogue input
– 10bit ADC (0..1023)– 10k pullup in NXT– Legacy mode power out!
● Power approx 4.3V– 180mA (total all sensors)
● Digital I/O (x2)– I2C (@9600bps)– Switch enable (DIGITAL0)
● Special firmware– RC servo control, UART,...– Your imagination
RCX Legacy Mode
● WARNING! WARNING! WARNING!– Analogue Input can also output 9V pulses.– This supports RCX powered sensors connected
between pin 1 and 2.– Need current limiting resistor on pin 1 for safety.
● YOU HAVE BEEN WARNED
Switch sensor (Lego)
● R1 for Legacy mode safety.
Custom 2switch sensor● This gives 4 voltage levels
– 1024 = none– 660 = S2– 512 = S1– 400 = both
● Experiment!
LDR Sensor (Custom)
● Not as good as Lego light sensor● No LED
– Easily added● Other resistive sensors
– Thermistor– Potentiometer
Hall Effect Sensor (Custom)
● Detects magnets● LED useful for debugging
– Optional● Tee configuration
– Share port withI2C sensor
● R2 just for safety– RCX legacy mode
Hall Effect (cont.)
● Fridge magnet is alternate strips of North and South.– Can be used as a linear movement sensor
● Use as a start reference for a rotating encoder.● Use your imagination!
I2C sensors
● Maximum flexibility● Maximum challenge● Use 9600 bps I2C connection
– Up to about 1k bytes per second max– Can multidrop sensors
● 127 in theory, a few in practice– Input and output
● Data layouts– Lego Standard– General purpose I2C devices (LCD, memory, ADC,...)
Why AVR?
● Free tools (gcc etc)– Multiplatform (Linux, Windows, OSX, etc)
● Wide power voltage (1.8V to 5.5V)● Designed for C● Low cost● Packed with peripherals● Fast (1 clock instructions)● Reasonable amount of memory
MBOYS ATIO Sensor
● Uses ATMega48 AVR micro● Interfaces to
– 4 Analogue channels (eg. light sensors)– 8 IO pins– Can expand to more
● Sensor configured by software
Mboys01 schematic (simplified)
Mboys Sensor
● Extensible framework– Simple to modify for
other purposes– RS232 debugging
● Uses less than ¼ of RAM and FLASH
● Uses less than 10% of CPU
● Lego layout● Read
– 0x00 “MBOYS “– 0x08 “ATIO “– 0x10 “1.1”– 0x18 Inputs
● 4xADC● PIND
● Write– 0x40 PIND direction– 0x41 PIND output
Accessing ATIO from Lejos
I2CSensor sensor = new I2CSensor(SensorPort.S1);int poll = 1;byte[] data = new byte[5];boolean done = false;
LCD.drawString(sensor.getProductID(),0,2);LCD.drawString(sensor.getSensorType(),0,3);LCD.drawString(sensor.getVersion(),0,4);
sensor.sendData(0x40,(byte)0x07);sensor.sendData(0x41,(byte)(poll & 0x07));
sensor.getData(0x18,data,5);
Resources
● Books– “Extreme NXT” Gasperi et al– “Maximum Lego NXT” Brian Bagnall
● www– embeddedjanitor.blogspot.com– philohome.com– hightechnic.com– mindsensors.com