In order to use its functions, the toolkit must be loaded using the pkg load command:
pkg load raspi
The toolkit must be loaded on each GNU Octave session.
To control an raspi device, a connection must be made to it by creating an raspi object.
r = raspi("192.168.1.100")
Instead of an IP address, the name of the pi can be used.
r = raspi("raspberrypi.local")
Basic input and output can be performed on a connected raspi device using by calling the read and write functions for a specific gpio pin on the Raspberry Pi.
A list of available pins can get found from the AvailableDigitalPins property of the connected raspi object.
r = raspi(); % get the pins pins = r.AvailableDigitalPins
A pin’s digital logic value can be true (1) or false (0) and can be set using the writeDigitalPin function.
The following example attempts to set the GPIO 17 pin of the connected raspi object "r" to true, waits 5 seconds and then sets it to false:
writeDigitalPin (r, 17, true); pause 5 writeDigitalPin (r, 17, false);
Using the readDigitalPin will read the current logic state of the pin.
value = readDigitalPin (r, 17);
The SPI device addresses connected to the Raspberry can be queried using the scanI2Cbus function.
r = raspi(); devs = scanI2Cbus(r);
I2C devices are created using the i2cdev object, providing the i2c bus and i2c address.
r = raspi(); i2c = i2cdev(r, 0, 0x40);
After creating an I2C device, the device can be communicated to using the read, write, readRegister and writeRegister functions.
A spi device can be created using the spidev object.
r = raspi(); spi = spidev(r, "ce0");
Once created, the device can be communicated to using the writeRead function.
Serial devices can be accessed using the serial dev function.
r = raspi(); ser = serialdev(r, "/dev/serial0", 9600);
A serial device can be communicated to using the read and write functions.
A servo can be controlled be creating a servo object.
r = raspi(); ser = servo(r, servo(p, 17, 'MinPulseDuration', 1e-3, 'MaxPulseDuration', 2e-3)
Once created, the servo can be moved between 0 to 180 degrees, corresponding to the min and max pulse duration using the
writePosition function.