Skip to content

Adding GPIO for BeagleBone Blue #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

all: build # build2 build3
all: build3 # build2 build3

time:
/usr/bin/ntpdate -b -s -u pool.ntp.org
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down
13 changes: 11 additions & 2 deletions source/event_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions source/event_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions source/examples/python/button.py
Original file line number Diff line number Diff line change
@@ -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")
16 changes: 16 additions & 0 deletions source/examples/python/gpio.py
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 37 additions & 0 deletions source/examples/python/i2cmatrix.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions source/examples/python/i2ctmp101.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions source/examples/python/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Here's what you need to install to run these.

sudo apt install python3-smbus
16 changes: 16 additions & 0 deletions source/examples/python/leds.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions source/examples/python/pwm.old.py
Original file line number Diff line number Diff line change
@@ -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()
10 changes: 6 additions & 4 deletions source/examples/python/pwm.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import Adafruit_BBIO.PWM as PWM

#set polarity to 1 on start:
Expand All @@ -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