To give you any sort of specific information I’d need to know about the sensors themselves. In general, you will make use of the X2’s general purpose IO ports (the 16 pins on the left side of the board).
Starting from the top and moving down, the left-most column of pins are A0 through A7 followed by D0 through D7. The middle column is power (the power source for each bank of four pins is determined by the power solder jumper on the back of the board) and the right column is ground. These pins can either be used as digital inputs or outputs. Additionally, pins A0 through A7 can be used as analog inputs. The first step is deciding if you need to output signals or input them. To set a pin as a digital output, you would use the following code (replace x with the desired pin number):
DDRA |= (1 << PAx);
DDRD |= (1 << PDx);
For example, to make pins A1, A3, and D7 outputs, you would use:
DDRA |= (1 << PA1) | (1 << PA3);
DDRD |= (1 << PD7);
You can then set the value of an output pin to either 1 (5V) or 0 (0V) by setting its PORT value to 1 or 0, respectively. For example:
PORTA |= (1 << PA1); // drive PA1 high (5V)
PORTA &= ~(1 << PA3); // drive PA3 low (0V)
If you want to use a pin as a digital input, you need to clear its DDR bit. The following example will set pins A0, A2, and D0 as digital inputs:
DDRA &= ~(1 << PA0) & ~(1 << PA2);
DDRD &= ~(1 << PD0);
You can then read the value of the pin by checking the bits of the PIN register. The following code will read the input on pins A0 and D0;
pinA0High = ((PINA & (1 << PA0)) != 0);
pinD0High = ((PIND & (1 << PD0)) != 0);
Some sensors will output analog voltages (any voltage between 0 and 5V, rather than being limited to just the two values of high and low). PORTA can be configured to calculate the values of analog voltages. You can see an example of how this is done by looking at the X2 test code that ships on the product. The test code measures the voltage on the user trimpot to determine its position and set the motor speeds accordingly.
What you need to do is find out what input, if any, your sensors require from you. For example, a sonar sensor might require you to send a pulse in order to trigger each sonar ping. You then need to determine what your sensors will be outputting (digital signals or analog voltage) and how to interpret those signals.
- Ben