GPIO control
Description
4 GPIO pins are available to hook up simple input, output or communication (UART, I2C, SPI, ...). This can be used to control some custom external electronics or receive input signal. Pins can be controlled using standard Arduino code, similar as with TotemDuino.
Note
Board revision v1.1 and v1.0 has different GPIO wiring, so follow instructions accordingly
Code examples
Arduino projects: RoboBoardX4/GPIO
Function usage (click to expand)
void setup() {
pinMode(GPIOA, INPUT);
pinMode(GPIOB, OUTPUT);
}
void loop() {
// Read state of GPIOA pin
if (digitalRead(GPIOA) == HIGH) {
// If GPIO pin is pulled HIGH, set GPIOB to HIGH
digitalWrite(GPIOB, HIGH);
}
else {
// If GPIO pin is pulled LOW, set GPIOB to LOW
digitalWrite(GPIOB, LOW);
}
}
Controlling GPIO pins
Revision v1.1
Pins can be controlled using standard Arduino framework functions.
For pin numbers use GPIOA
, GPIOB
, GPIOC
, GPIOD
definitions.
Set GPIO pin output state digitalWrite():
pinMode(GPIOA, OUTPUT);
digitalWrite(GPIOA, HIGH);
pinMode(GPIOA, INPUT);
int state = digitalRead(GPIOA);
int val = analogRead(GPIOA);
analogWrite()
is unavailable at the moment. Will be added in future.
Revision v1.0
GPIO pins are connected to internal driver chip, so functionality is limited.
API is available for each GPIO pin X4.gpioA
, X4.gpioB
, X4.gpioC
, X4.gpioD
.
X4.gpioA.digitalWrite(state
)
- Set GPIO pin A state. Works similar like Arduino function
digitalWrite()
.
Calling this function will reconfigure pin to output.
Parameter:
state
- GND (0V) or VCC (3.3V) [LOW
:HIGH
]
(state
) X4.gpioA.digitalRead()
- Read GPIO pin A state. Works similar like Arduino function
digitalRead()
.
Calling this function will reconfigure pin to input.
Returns:
state
- GND (0V) or VCC (3.3V) [LOW
:HIGH
]
X4.gpioA.analogWrite(value
)
- Set GPIO pin A analog value. Works similar like Arduino function
analogWrite()
. Calling this function will reconfigure pin to output.
Parameter:
value
- analog value [0
:20
]. (0, 10, 20) = (0V, 1.65V, 3.3V).
(value
) X4.gpioA.analogRead()
- Read GPIO pin A analog value. Works similar like Arduino function
analogRead()
. Calling this function will reconfigure pin to output.
Returns:
value
- analog value [0:1023]. (0, 512, 1023) = (0V, 1.65V, 3.3V).
X4.gpioA.pullMode(mode
)
- Turn on GPIO pin A pulldown or pullup resistor. Works similar like Arduino function
pinMode(pin, INPUT_PULLUP)
.
Parameter:
mode
- turn on pulldown or pullup [LOW
:HIGH
]. (LOW, HIGH) = (GND (0V), VCC (3.3V)).