226
ScriptBasic / RPi GPIO Support
« on: April 25, 2019, 10:35:00 AM »
I have the GPIO extension module built with limited testing. I'm assuming the gpio argument is a 0 or 1 indicating the physical hardware or an emuator. It would be sweet if I can access the Python based Sense HAT emulator.
* Unzip to a tmp directory.
* Copy the gpio.so file to your /usr/local/lib/scriba/ directory.
* Copy the gpio.bas file to your /usr/local/include/scriba/ directory.
Simple Test
pi@RPi3B:~/sbrpi/examples $ scriba testgpio.sb
0
pi@RPi3B:~/sbrpi/examples $
gpio.bas (extension module include file)
c_gpio.h (function declarations)
raspberry-gpio-python (wrapped C interface as an ext. module))
BCM2835-ARM-Peripherals.pdf
Note: This was compiled on my RPi 3B. I will compile a Zero version after this is tested.
I have a Raspberry Pi Sense HAT board and a KooKye Smart Home IoT Sensor Kit.
Looking forward to your test scripts!
* Unzip to a tmp directory.
* Copy the gpio.so file to your /usr/local/lib/scriba/ directory.
* Copy the gpio.bas file to your /usr/local/include/scriba/ directory.
Simple Test
Code: Script BASIC
- ' Test GPIO
- IMPORT gpio.bas
- status = GPIO::Setup()
- PRINT status,"\n"
- GPIO::Cleanup
pi@RPi3B:~/sbrpi/examples $ scriba testgpio.sb
0
pi@RPi3B:~/sbrpi/examples $
gpio.bas (extension module include file)
Code: Script BASIC
- 'GPIO Extension Mondule
- GLOBAL CONST SETUP_OK = 0
- GLOBAL CONST SETUP_DEVMEM_FAIL = 1
- GLOBAL CONST SETUP_MALLOC_FAIL = 2
- GLOBAL CONST SETUP_MMAP_FAIL = 3
- GLOBAL CONST SETUP_CPUINFO_FAIL = 4
- GLOBAL CONST SETUP_NOT_RPI_FAIL = 5
- ' Is really 0 for control register!
- GLOBAL CONST IN = 1
- ' Is really 1 for control register!
- GLOBAL CONST OUT = 0
- GLOBAL CONST ALT0 = 4
- GLOBAL CONST HIGH = 1
- GLOBAL CONST LOW = 0
- GLOBAL CONST PUD_OFF = 0
- GLOBAL CONST PUD_DOWN = 1
- GLOBAL CONST PUD_UP = 2
- MODULE GPIO
- DECLARE SUB ::Setup ALIAS "sb_setup" LIB "gpio"
- DECLARE SUB ::ClearEventDetect ALIAS "sb_clear_event_detect" LIB "gpio"
- DECLARE SUB ::EventDetected ALIAS "sb_eventdetected" LIB "gpio"
- DECLARE SUB ::SetRisingEvent ALIAS "sb_set_rising_event" LIB "gpio"
- DECLARE SUB ::SetFallingEvent ALIAS "sb_set_falling_event" LIB "gpio"
- DECLARE SUB ::SetHighEvent ALIAS "sb_set_high_event" LIB "gpio"
- DECLARE SUB ::SetLowEvent ALIAS "sb_set_low_event" LIB "gpio"
- DECLARE SUB ::SetPullUpDn ALIAS "sb_set_pullupdn" LIB "gpio"
- DECLARE SUB ::SetupGPIO ALIAS "sb_setup_gpio" LIB "gpio"
- DECLARE SUB ::GPIOFunction ALIAS "sb_gpio_function" LIB "gpio"
- DECLARE SUB ::OutputGPIO ALIAS "sb_output_gpio" LIB "gpio"
- DECLARE SUB ::InputGPIO ALIAS "sb_input_gpio" LIB "gpio"
- DECLARE SUB ::Cleanup ALIAS "sb_cleanup" LIB "gpio"
- DECLARE SUB ::ShortWait ALIAS "sb_short_wait" LIB "gpio"
- END MODULE
c_gpio.h (function declarations)
Code: C
- int setup(void);
- void setup_gpio(int gpio, int direction, int pud);
- int gpio_function(int gpio);
- void output_gpio(int gpio, int value);
- int input_gpio(int gpio);
- void set_rising_event(int gpio, int enable);
- void set_falling_event(int gpio, int enable);
- void set_high_event(int gpio, int enable);
- void set_low_event(int gpio, int enable);
- int eventdetected(int gpio);
- void cleanup(void)
- void short_wait(void) // wait 150 cycles
raspberry-gpio-python (wrapped C interface as an ext. module))
BCM2835-ARM-Peripherals.pdf
Note: This was compiled on my RPi 3B. I will compile a Zero version after this is tested.
I have a Raspberry Pi Sense HAT board and a KooKye Smart Home IoT Sensor Kit.
Looking forward to your test scripts!