diff --git a/Makefile b/Makefile index 877bc1d..ba726e8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -all: build # build2 build3 +all: build3 # build2 build3 time: /usr/bin/ntpdate -b -s -u pool.ntp.org @@ -29,10 +29,10 @@ install2: build2 python2 setup.py install --force build3: - python3 setup.py build --force + python3 setup.py build # --force install3: build3 - python3 setup.py install --force + python3 setup.py install # --force ################################################################################ # c++ library diff --git a/source/common.c b/source/common.c index 89272ca..23c85f7 100644 --- a/source/common.c +++ b/source/common.c @@ -167,6 +167,21 @@ pins_t table[] = { { "DGND", "P9_44", 0, -1, -1}, { "DGND", "P9_45", 0, -1, -1}, { "DGND", "P9_46", 0, -1, -1}, + + // These are for the Blue + { "GPO_0", "GP0_0", 57, -1, -1}, + { "GP0_1", "GP0_1", 49, -1, -1}, + { "GP0_2", "GP0_2", 116, -1, -1}, + { "GP0_3", "GP0_3", 113, -1, -1}, + { "GP1_0", "GP1_0", 98, -1, -1}, + { "GP1_1", "GP1_1", 97, -1, -1}, + { "RED_LED", "RED", 66, -1, -1}, // LEDs + { "GREEN_LED", "GREEN", 67, -1, -1}, + + { "UT1_0", "P9_26", 14, 1, -1}, + { "UT1_1", "P9_24", 15, 1, -1}, + + { NULL, NULL, 0, 0, 0 } }; diff --git a/source/event_gpio.c b/source/event_gpio.c index 834239d..6194994 100644 --- a/source/event_gpio.c +++ b/source/event_gpio.c @@ -194,6 +194,10 @@ int open_value_file(unsigned int gpio) // create file descriptor of value file if ((gpio >= USR_LED_GPIO_MIN) && (gpio <= USR_LED_GPIO_MAX)) { snprintf(filename, sizeof(filename), "/sys/class/leds/beaglebone:green:usr%d/brightness", gpio - USR_LED_GPIO_MIN); + } else if(gpio == USR_LED_RED) { // red LED + snprintf(filename, sizeof(filename), "/sys/class/leds/red/brightness"); + } else if(gpio == USR_LED_GREEN) { // green LED + snprintf(filename, sizeof(filename), "/sys/class/leds/green/brightness"); } else { snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio); } @@ -247,7 +251,8 @@ BBIO_err gpio_set_direction(unsigned int gpio, unsigned int in_flag) char filename[40]; char direction[10] = { 0 }; - if ((gpio >= USR_LED_GPIO_MIN) && (gpio <= USR_LED_GPIO_MAX)) { + if (((gpio >= USR_LED_GPIO_MIN) && (gpio <= USR_LED_GPIO_MAX)) || + (gpio == USR_LED_RED) || (gpio == USR_LED_GREEN)) { syslog(LOG_DEBUG, "gpio_set_direction: %u not applicable to the USR LED", gpio); return BBIO_OK; // direction is not applicable to the USR LED pins } @@ -324,7 +329,11 @@ BBIO_err gpio_set_value(unsigned int gpio, unsigned int value) if (access(filename, W_OK) < 0) { snprintf(filename, sizeof(filename), "/sys/class/leds/beaglebone:green:%s/brightness", usr_led_trigger[led]); } - + + } else if(gpio == USR_LED_RED) { + snprintf(filename, sizeof(filename), "/sys/class/leds/red/brightness"); + } else if(gpio == USR_LED_GREEN) { + snprintf(filename, sizeof(filename), "/sys/class/leds/green/brightness"); } else { snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio); } diff --git a/source/event_gpio.h b/source/event_gpio.h index cd250fa..d5e5d93 100644 --- a/source/event_gpio.h +++ b/source/event_gpio.h @@ -48,6 +48,8 @@ SOFTWARE. #define USR_LED_GPIO_MIN 53 #define USR_LED_GPIO_MAX 56 +#define USR_LED_RED 66 +#define USR_LED_GREEN 67 #define PUD_OFF 0 #define PUD_DOWN 1 diff --git a/source/examples/python/button.py b/source/examples/python/button.py new file mode 100755 index 0000000..a660253 --- /dev/null +++ b/source/examples/python/button.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# Reads the PAUSE button using interupts and sets the LED +# Pin table at https://github.com/beagleboard/beaglebone-blue/blob/master/BeagleBone_Blue_Pin_Table.csv + +# Import PyBBIO library: +import Adafruit_BBIO.GPIO as GPIO +import time + +button="GP0_0" # PAUSE=P8_9, MODE=P8_10 +LED ="GP0_1" + +# Set the GPIO pins: +GPIO.setup(LED, GPIO.OUT) +GPIO.setup(button, GPIO.IN) + +print("Running...") + +while True: + state = GPIO.input(button) + GPIO.output(LED, state) + + GPIO.wait_for_edge(button, GPIO.BOTH) + print("Pressed") \ No newline at end of file diff --git a/source/examples/python/gpio.py b/source/examples/python/gpio.py new file mode 100755 index 0000000..d9b1e08 --- /dev/null +++ b/source/examples/python/gpio.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# Blinks some gpio pins on the Blue +import Adafruit_BBIO.GPIO as GPIO +import time + +LEDs = ["GP0_0", "GP0_1", "GP0_2", "GP0_3", "GP1_0", "GP1_1", "UT1_0"] +for LED in LEDs: + print(LED) + GPIO.setup(LED, GPIO.OUT) + +while True: + for LED in LEDs: + GPIO.output(LED, GPIO.HIGH) + time.sleep(0.1) + GPIO.output(LED, GPIO.LOW) + time.sleep(0.1) \ No newline at end of file diff --git a/source/examples/python/i2cmatrix.py b/source/examples/python/i2cmatrix.py new file mode 100755 index 0000000..c0142e4 --- /dev/null +++ b/source/examples/python/i2cmatrix.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# Write an 8x8 Red/Green LED matrix +# https://www.adafruit.com/product/902 + +import smbus +import time +bus = smbus.SMBus(1) +matrix = 0x70 + +delay = 1; # Delay between images in s + +bus.write_byte_data(matrix, 0x21, 0) # Start oscillator (p10) +bus.write_byte_data(matrix, 0x81, 0) # Disp on, blink off (p11) +bus.write_byte_data(matrix, 0xe7, 0) # Full brightness (page 15) + +# The first byte is GREEN, the second is RED. +smile = [0x00, 0x3c, 0x00, 0x42, 0x28, 0x89, 0x04, 0x85, + 0x04, 0x85, 0x28, 0x89, 0x00, 0x42, 0x00, 0x3c +] +frown = [0x3c, 0x00, 0x42, 0x00, 0x85, 0x20, 0x89, 0x00, + 0x89, 0x00, 0x85, 0x20, 0x42, 0x00, 0x3c, 0x00 +] +neutral = [0x3c, 0x3c, 0x42, 0x42, 0xa9, 0xa9, 0x89, 0x89, + 0x89, 0x89, 0xa9, 0xa9, 0x42, 0x42, 0x3c, 0x3c +] + +bus.write_i2c_block_data(matrix, 0, frown) +for fade in range(0xef, 0xe0, -1): + bus.write_byte_data(matrix, fade, 0) + time.sleep(delay/10) + +bus.write_i2c_block_data(matrix, 0, neutral) +for fade in range(0xe0, 0xef, 1): + bus.write_byte_data(matrix, fade, 0) + time.sleep(delay/10) + +bus.write_i2c_block_data(matrix, 0, smile) diff --git a/source/examples/python/i2ctmp101.py b/source/examples/python/i2ctmp101.py new file mode 100755 index 0000000..923c0f9 --- /dev/null +++ b/source/examples/python/i2ctmp101.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 +# Read a TMP101 sensor + +import smbus +import time +bus = smbus.SMBus(1) +address = 0x49 + +while True: + temp = bus.read_byte_data(address, 0) + print (temp, end="\r") + time.sleep(0.25) diff --git a/source/examples/python/install.sh b/source/examples/python/install.sh new file mode 100644 index 0000000..3b7b158 --- /dev/null +++ b/source/examples/python/install.sh @@ -0,0 +1,3 @@ +# Here's what you need to install to run these. + +sudo apt install python3-smbus diff --git a/source/examples/python/leds.py b/source/examples/python/leds.py new file mode 100755 index 0000000..8aa84ef --- /dev/null +++ b/source/examples/python/leds.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# Blinks some gpio pins on the Blue +import Adafruit_BBIO.GPIO as GPIO +import time + +LEDs = ["RED_LED", "GREEN_LED"] + +for LED in LEDs: + GPIO.setup(LED, GPIO.OUT) + +while True: + for LED in LEDs: + GPIO.output(LED, GPIO.HIGH) + time.sleep(0.1) + GPIO.output(LED, GPIO.LOW) + time.sleep(0.1) \ No newline at end of file diff --git a/source/examples/python/pwm.old.py b/source/examples/python/pwm.old.py new file mode 100644 index 0000000..7edc8fd --- /dev/null +++ b/source/examples/python/pwm.old.py @@ -0,0 +1,14 @@ +import Adafruit_BBIO.PWM as PWM + +#set polarity to 1 on start: +#PWM.start("P9_14", 50, 2000, 1) + +#PWM.start(channel, duty, freq=2000, polarity=0) +#duty values are valid 0 (off) to 100 (on) + +PWM.start("P9_14", 50) +PWM.set_duty_cycle("P9_14", 25.5) +PWM.set_frequency("P9_14", 10) + +PWM.stop("P9_14") +PWM.cleanup() diff --git a/source/examples/python/pwm.py b/source/examples/python/pwm.py old mode 100644 new mode 100755 index 7edc8fd..3d352c8 --- a/source/examples/python/pwm.py +++ b/source/examples/python/pwm.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 import Adafruit_BBIO.PWM as PWM #set polarity to 1 on start: @@ -6,9 +7,10 @@ #PWM.start(channel, duty, freq=2000, polarity=0) #duty values are valid 0 (off) to 100 (on) -PWM.start("P9_14", 50) -PWM.set_duty_cycle("P9_14", 25.5) -PWM.set_frequency("P9_14", 10) +SERVO="P9_14" +PWM.start(SERVO, 50) +PWM.set_duty_cycle(SERVO, 25.5) +PWM.set_frequency(SERVO, 10) -PWM.stop("P9_14") +PWM.stop(SERVO) PWM.cleanup() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy