Beagle Board - beagleboard.org

BoneScript

Not Connected
Did you know? This page can interact with your BeagleBone
Type in your BeagleBone's IP address here:

Bacon Cape

The Bacon Cape is an add-on board meant to give you access to some hardware to help build your understanding of doing basic embedded I/O on BeagleBone.

Board activity

When you visit this page and you have a BeagleBone running BoneScript 0.2.3 or newer with a Bacon Cape attached on your local network or connected to your computer over USB, this display will dyanmically update to reflect the board status. The box color should reflect the color of the RGB LED. The top slider should reflect the status of the push button and turn on the blue LED. The middle slider should reflect the status of the slide potentiometer and adjust the brightness of the green LED. The bottom slider should be adjustable on the page and adjust the brightness of the red LED.

More information about the cape can be found at the eLinux.org Bacon Cape page.

Components

These are the major components of the Bacon Cape.

  • S1: a simple push button provides a digital input
    • P8_19: digital I/O connection to BeagleBone
    • Configured as active-low (low when pressed) and uses and external pull-up
  • D1: an RGB LED provides an indicator for digital output
    • P9_16: digital I/O connection for BLUE
    • P9_14: digital I/O connection for GREEN
    • P9_42: digital I/O connection for RED
    • Configured as active-high (lit when high)
  • R10: a slide potentiometer provides an analog input
    • P9_36: analog input connection to BeagleBone
  • U1: shift register feeding a 7 segment display
    • P9_22: CLOCK
    • P9_17: LATCH
    • P9_18: DATA
    • P9_15: CLEAR
    • LED1: connected to shift register output in common anode (active-low) configuration
    • a: last bit shifted out
    • h: first bit shifted out
  • U2: I2C EEPROM connected to I2C2

Demo


Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// read in BoneScript library
var b = require('bonescript');
// define used pins
var LED_RED = 'P9_42';
var LED_GREEN = 'P9_14';
var LED_BLUE = 'P9_16';
var BUTTON = 'P8_19';
var POT = 'P9_36';
var S_DATA  = 'P9_18';
var S_CLOCK = 'P9_22';
var S_LATCH = 'P9_17';
var S_CLEAR = 'P9_15';
// define other global variables
var s = b.LOW;
var digit = 0;
var segments = [ 0xC0, 0xF9, 0xA4, 0xB0, 0x99,
                 0x92, 0x82, 0xF8, 0x80, 0x90 ];
var stopped = 0;
var started = 0;
var platform = {};
// attach jQuery elements
try {
    $('#slider1').slider();
    $('#slider2').slider();
    $('#slider3').slider();
    $('#led1').css('width', '50px');
    $('#led1').css('height', '50px');
    $('#led1').css('background-color', 'rgb(0,0,0)');
    $("#slider3").bind("slidechange", function(event, ui) {
        updateRed({value:(ui.value/100.0)});
    });
    //$('#runbutton').removeAttr('onclick');
    $('#runbutton').click(runClick);
} catch(ex) {}
// configure pins as inputs/outputs
b.pinMode(S_DATA,  b.OUTPUT);
b.pinMode(S_CLOCK, b.OUTPUT);
b.pinMode(S_LATCH, b.OUTPUT);
b.pinMode(S_CLEAR, b.OUTPUT);
b.pinMode('USR0', b.OUTPUT);
b.pinMode('USR1', b.OUTPUT);
b.pinMode('USR2', b.OUTPUT);
b.pinMode('USR3', b.OUTPUT);
//b.pinMode(LED_RED, b.OUTPUT);
//b.pinMode(LED_GREEN, b.OUTPUT);
//b.pinMode(LED_BLUE, b.OUTPUT);
b.pinMode(BUTTON, b.INPUT);
// initial states
b.digitalWrite('USR0', b.LOW);
b.digitalWrite('USR1', b.LOW);
b.digitalWrite('USR2', b.LOW);
b.digitalWrite('USR3', b.LOW);
b.analogWrite(LED_RED, 0);
b.analogWrite(LED_GREEN, 0);
b.analogWrite(LED_BLUE, 0);
b.digitalWrite(S_DATA,  b.LOW);
b.digitalWrite(S_CLOCK, b.LOW);
b.digitalWrite(S_LATCH, b.LOW);
b.digitalWrite(S_CLEAR, b.HIGH);
//b.attachInterrupt(BUTTON, true, b.CHANGE, handleButton);
// call function to read status and perform updates
function start() {
    console.log('Starting Bacon Cape demo');
    b.getPlatform(onGetPlatform);
}
function onGetPlatform(x) {
    platform = x;
    scheduleNextUpdate();
}
function scheduleNextUpdate() {    
    // test for stop and then schedule next update for 50ms
    if(stopped) {
        started = 0;
        console.log('Stopped Bacon Cape demo');
    } else {
        setTimeout(update, 50);
    }
}
function update() {
    // toggle USR0 LED
    s = (s == b.LOW) ? b.HIGH : b.LOW;
    if(platform.bonescript != '0.2.3') {
        b.digitalWrite('USR0', s, doAnalogRead);
    } else {
        b.digitalWrite('USR0', s, do7SegUpdate);
    }
}
function do7SegUpdate(x) {
    // update 7segment LED
    digit = (digit + 1) % 10;
    
    // shift out the character LED pattern
    b.shiftOut(S_DATA, S_CLOCK, b.MSBFIRST, 
        segments[digit], doLatch);
}
function doLatch() {
    // latch in the value
    b.digitalWrite(S_LATCH, b.HIGH, doLatchLow);
}
function doLatchLow() {
    b.digitalWrite(S_LATCH, b.LOW, doAnalogRead);
}
function doAnalogRead() {
    b.digitalRead(BUTTON, updateBlue);
}
function updateBlue(x) {
    if(typeof x.value == 'undefined') return;
    updateLED({blue:1-x.value});
    b.analogRead(POT, updateGreen);
}
function updateGreen(x) {
    if(typeof x.value == 'undefined') return;
    updateLED({green:1-x.value});
    scheduleNextUpdate();
}
function updateRed(x) {
    if(started) {
        if(typeof x.value == 'undefined') return;
        updateLED({red:x.value});
    }
}
function updateLED(led) {
    if(typeof led.red == 'number') {
        b.analogWrite(LED_RED, led.red);
        this.red = led.red;
    }
    if(typeof led.green == 'number') {
        b.analogWrite(LED_GREEN, led.green);
        this.green = led.green;
    }
    if(typeof led.blue == 'number') {
        b.analogWrite(LED_BLUE, led.blue);
        this.blue = led.blue;
    }
    try {
        if(typeof this.red == 'undefined') this.red = 0;
        if(typeof this.green == 'undefined') this.green = 0;
        if(typeof this.blue == 'undefined') this.blue = 0;
        var rgb = 'rgb(' + Math.round(this.red*255) + ',' + 
            Math.round(this.green*255) + ',' +
            Math.round(this.blue*255) + ')';
        $('#led1').css('background-color', rgb);
        $("#slider1").slider("option", "value", this.blue*100);
        $("#slider2").slider("option", "value", this.green*100);
    } catch(ex) {}
}
function runClick() {
    if(!started) {
        started = 1;
        stopped = 0;
        start();
        try {
            $('#runbutton').html('stop');
        } catch(ex) {}
    } else if(!stopped) {
        stopped = 1;
        var p = '/sys/class/leds/beaglebone:green:usr';
        b.digitalWrite('USR0', b.LOW);
        b.digitalWrite('USR1', b.LOW);
        b.digitalWrite('USR2', b.LOW);
        b.digitalWrite('USR3', b.LOW);
        b.writeTextFile(p+'0/trigger', 'heartbeat');
        b.writeTextFile(p+'1/trigger', 'mmc0');
        b.writeTextFile(p+'2/trigger', 'cpu0');
        b.writeTextFile(p+'3/trigger', 'mmc1');
        try {
            $('#runbutton').html('run');
        } catch(ex) {}
    } 
}
X

See also

Reference

Topics

Related functions

Where to buy

See it in action


Last updated by jessica.lynne.callaway on Thu Dec 19 2013 21:53:32 GMT-0000 (UTC).
25244