In theory it supports up to 31 slave NXTs (multiplexers), and you can remotely configure analog sensors, and do some simple motor control.
For sensors, you can configure type and mode (or use the equivalent of SetSensor). You can also read the normalized values, as well as the RAW values. I have communication support for all four ports, but on the slave I disallowed it from over-writing the type and mode for port 4 (otherwise RS485 might get disabled).
For motors, you can use commands similar to OnFwd, OnFwdEx, OnRev, OnRevEx, Off, OffEx, Coast, and CoastEx. You can also set a desired position, and the slave will use the EFW implemented APR to try to achieve the position (not perfect, but it's good enough for me). You can read the MotorTachoCount, or issue the ResetTachoCount command. Take a look at the included example.
This is all taken care of in the APIs, but there is a command "register" for each of the motors. Here is a list of the values supported:
Code: Select all
#define MotorFloat 0x01 // make the motor float
#define MotorForward 0x02 // turn on forward, using PWM speed control
#define MotorReverse 0x04 // turn on reverse, using PWM speed control
#define MotorBrake 0x08 // make the motor turn off, using a braking stop
#define MotorResetTacho 0x10 // reset the encoder (can be ORed with any of the other values)
#define MotorAPR 0x20 // use Absolute Position Regulation mode
Never pass a slave value of > 30 to any function. The valid range is 0-30, and the functions do not clip the value. You can either use the values 0 through 30, or RS485Mux1 through RS485Mux31. If you look near the top of the master library, you'll see a global variable named "RS485ActiveSlaves", initialized with the value of 0x00000001. That is a control for what RS485 slaves it will try to communicate with. Each bit represents a slave. being set to 1 would mean slave one is enabled. 2 means slave 2 is inabled. 3 means slave 1 and 2 are enabled...
Since the only thing the slave does is monitor RS485, and send and receive values I didn't think it was necessary to put the task in a "library". I might change that later though.
Make sure you #define RS485AddressMine to something like RS485AddressSlave1, and make every slave is unique (numerical value 1-31).
I have only done a little testing so far. Please let me know of any problems you find (there are bound to be a lot).
Included in the .zip file:
- the master library
- an example program for the master
- the slave program (its the only thing the slave does, so it is a program instead of a "library")
- my RS485 library, on which the programs rely heavily
- my math library