Skip to content

Commit a0ffd19

Browse files
authored
Merge pull request #153 from MarkAYoder/master
Adding GPIO for BeagleBone Blue
2 parents a8b35df + e18f5c2 commit a0ffd19

File tree

12 files changed

+158
-9
lines changed

12 files changed

+158
-9
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
all: build # build2 build3
2+
all: build3 # build2 build3
33

44
time:
55
/usr/bin/ntpdate -b -s -u pool.ntp.org
@@ -29,10 +29,10 @@ install2: build2
2929
python2 setup.py install --force
3030

3131
build3:
32-
python3 setup.py build --force
32+
python3 setup.py build # --force
3333

3434
install3: build3
35-
python3 setup.py install --force
35+
python3 setup.py install # --force
3636

3737
################################################################################
3838
# c++ library

source/common.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ pins_t table[] = {
167167
{ "DGND", "P9_44", 0, -1, -1},
168168
{ "DGND", "P9_45", 0, -1, -1},
169169
{ "DGND", "P9_46", 0, -1, -1},
170+
171+
// These are for the Blue
172+
{ "GPO_0", "GP0_0", 57, -1, -1},
173+
{ "GP0_1", "GP0_1", 49, -1, -1},
174+
{ "GP0_2", "GP0_2", 116, -1, -1},
175+
{ "GP0_3", "GP0_3", 113, -1, -1},
176+
{ "GP1_0", "GP1_0", 98, -1, -1},
177+
{ "GP1_1", "GP1_1", 97, -1, -1},
178+
{ "RED_LED", "RED", 66, -1, -1}, // LEDs
179+
{ "GREEN_LED", "GREEN", 67, -1, -1},
180+
181+
{ "UT1_0", "P9_26", 14, 1, -1},
182+
{ "UT1_1", "P9_24", 15, 1, -1},
183+
184+
170185
{ NULL, NULL, 0, 0, 0 }
171186
};
172187

source/event_gpio.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ int open_value_file(unsigned int gpio)
194194
// create file descriptor of value file
195195
if ((gpio >= USR_LED_GPIO_MIN) && (gpio <= USR_LED_GPIO_MAX)) {
196196
snprintf(filename, sizeof(filename), "/sys/class/leds/beaglebone:green:usr%d/brightness", gpio - USR_LED_GPIO_MIN);
197+
} else if(gpio == USR_LED_RED) { // red LED
198+
snprintf(filename, sizeof(filename), "/sys/class/leds/red/brightness");
199+
} else if(gpio == USR_LED_GREEN) { // green LED
200+
snprintf(filename, sizeof(filename), "/sys/class/leds/green/brightness");
197201
} else {
198202
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio);
199203
}
@@ -247,7 +251,8 @@ BBIO_err gpio_set_direction(unsigned int gpio, unsigned int in_flag)
247251
char filename[40];
248252
char direction[10] = { 0 };
249253

250-
if ((gpio >= USR_LED_GPIO_MIN) && (gpio <= USR_LED_GPIO_MAX)) {
254+
if (((gpio >= USR_LED_GPIO_MIN) && (gpio <= USR_LED_GPIO_MAX)) ||
255+
(gpio == USR_LED_RED) || (gpio == USR_LED_GREEN)) {
251256
syslog(LOG_DEBUG, "gpio_set_direction: %u not applicable to the USR LED", gpio);
252257
return BBIO_OK; // direction is not applicable to the USR LED pins
253258
}
@@ -324,7 +329,11 @@ BBIO_err gpio_set_value(unsigned int gpio, unsigned int value)
324329
if (access(filename, W_OK) < 0) {
325330
snprintf(filename, sizeof(filename), "/sys/class/leds/beaglebone:green:%s/brightness", usr_led_trigger[led]);
326331
}
327-
332+
333+
} else if(gpio == USR_LED_RED) {
334+
snprintf(filename, sizeof(filename), "/sys/class/leds/red/brightness");
335+
} else if(gpio == USR_LED_GREEN) {
336+
snprintf(filename, sizeof(filename), "/sys/class/leds/green/brightness");
328337
} else {
329338
snprintf(filename, sizeof(filename), "/sys/class/gpio/gpio%d/value", gpio);
330339
}

source/event_gpio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ SOFTWARE.
4848

4949
#define USR_LED_GPIO_MIN 53
5050
#define USR_LED_GPIO_MAX 56
51+
#define USR_LED_RED 66
52+
#define USR_LED_GREEN 67
5153

5254
#define PUD_OFF 0
5355
#define PUD_DOWN 1

source/examples/python/button.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# Reads the PAUSE button using interupts and sets the LED
3+
# Pin table at https://github.com/beagleboard/beaglebone-blue/blob/master/BeagleBone_Blue_Pin_Table.csv
4+
5+
# Import PyBBIO library:
6+
import Adafruit_BBIO.GPIO as GPIO
7+
import time
8+
9+
button="GP0_0" # PAUSE=P8_9, MODE=P8_10
10+
LED ="GP0_1"
11+
12+
# Set the GPIO pins:
13+
GPIO.setup(LED, GPIO.OUT)
14+
GPIO.setup(button, GPIO.IN)
15+
16+
print("Running...")
17+
18+
while True:
19+
state = GPIO.input(button)
20+
GPIO.output(LED, state)
21+
22+
GPIO.wait_for_edge(button, GPIO.BOTH)
23+
print("Pressed")

source/examples/python/gpio.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
# Blinks some gpio pins on the Blue
3+
import Adafruit_BBIO.GPIO as GPIO
4+
import time
5+
6+
LEDs = ["GP0_0", "GP0_1", "GP0_2", "GP0_3", "GP1_0", "GP1_1", "UT1_0"]
7+
for LED in LEDs:
8+
print(LED)
9+
GPIO.setup(LED, GPIO.OUT)
10+
11+
while True:
12+
for LED in LEDs:
13+
GPIO.output(LED, GPIO.HIGH)
14+
time.sleep(0.1)
15+
GPIO.output(LED, GPIO.LOW)
16+
time.sleep(0.1)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
# Write an 8x8 Red/Green LED matrix
3+
# https://www.adafruit.com/product/902
4+
5+
import smbus
6+
import time
7+
bus = smbus.SMBus(1)
8+
matrix = 0x70
9+
10+
delay = 1; # Delay between images in s
11+
12+
bus.write_byte_data(matrix, 0x21, 0) # Start oscillator (p10)
13+
bus.write_byte_data(matrix, 0x81, 0) # Disp on, blink off (p11)
14+
bus.write_byte_data(matrix, 0xe7, 0) # Full brightness (page 15)
15+
16+
# The first byte is GREEN, the second is RED.
17+
smile = [0x00, 0x3c, 0x00, 0x42, 0x28, 0x89, 0x04, 0x85,
18+
0x04, 0x85, 0x28, 0x89, 0x00, 0x42, 0x00, 0x3c
19+
]
20+
frown = [0x3c, 0x00, 0x42, 0x00, 0x85, 0x20, 0x89, 0x00,
21+
0x89, 0x00, 0x85, 0x20, 0x42, 0x00, 0x3c, 0x00
22+
]
23+
neutral = [0x3c, 0x3c, 0x42, 0x42, 0xa9, 0xa9, 0x89, 0x89,
24+
0x89, 0x89, 0xa9, 0xa9, 0x42, 0x42, 0x3c, 0x3c
25+
]
26+
27+
bus.write_i2c_block_data(matrix, 0, frown)
28+
for fade in range(0xef, 0xe0, -1):
29+
bus.write_byte_data(matrix, fade, 0)
30+
time.sleep(delay/10)
31+
32+
bus.write_i2c_block_data(matrix, 0, neutral)
33+
for fade in range(0xe0, 0xef, 1):
34+
bus.write_byte_data(matrix, fade, 0)
35+
time.sleep(delay/10)
36+
37+
bus.write_i2c_block_data(matrix, 0, smile)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
# Read a TMP101 sensor
3+
4+
import smbus
5+
import time
6+
bus = smbus.SMBus(1)
7+
address = 0x49
8+
9+
while True:
10+
temp = bus.read_byte_data(address, 0)
11+
print (temp, end="\r")
12+
time.sleep(0.25)

source/examples/python/install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Here's what you need to install to run these.
2+
3+
sudo apt install python3-smbus

source/examples/python/leds.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
# Blinks some gpio pins on the Blue
3+
import Adafruit_BBIO.GPIO as GPIO
4+
import time
5+
6+
LEDs = ["RED_LED", "GREEN_LED"]
7+
8+
for LED in LEDs:
9+
GPIO.setup(LED, GPIO.OUT)
10+
11+
while True:
12+
for LED in LEDs:
13+
GPIO.output(LED, GPIO.HIGH)
14+
time.sleep(0.1)
15+
GPIO.output(LED, GPIO.LOW)
16+
time.sleep(0.1)

0 commit comments

Comments
 (0)