Wednesday, June 18, 2014
On 3:48 PM by Anonymous
Overview
Take control of input and output devices with this BeagleBone Relay cape. The relay cape makes it easy to turn on/off devices such as motors, alarms, lights, read switches, external triggers, and sense motion detectors. Applications can range from alarms, and access control, security to robotics. In this tutorial we will explore some of the features and capabilities of this cape.Key Features
- Dual SPDT high current relays - with LED indicators
- Four digital inputs- 3V to 12V tolerant
- Four push-button switch inputs
- Four digital outputs with 3.3 or 5V levels - LED indicators
- R/C Remote Control servo-motor port
- Blue status LED - user programmable
- Input port for potentiometer or voltage measurement (1.8V max)
- Voltage measurement (ex: battery voltage) (18V max)
- Cape eeprom for BeagleBone Cape manager
- Easy to use screw terminal connections
- Compact design fits inside expandable case
What you will need
- BeagleBone Black
- Relay Cape and User Manual
- USB A-to-Mini B cable (supplied with BeagleBone)
- AC adapter 5 Volts, 2 Amp (required)
- Computer with available USB port
- BeagleBone expandable case Orange or Black (recommended)
- Prototype parts kit (suggested)
Steps to follow
If this is your first time using the relay cape, you need to set-up the cape manager to recognize the board.
STEP 1
Download the device tree overlay file for Cape Manager to your BeagleBone Black computer.STEP 2
Copy the downloaded file to /lib/firmware (from a terminal)cp CBB-Relay-00A0.dtbo /lib/firmware
STEP 3
Remove power from the BeagleBone and insert the Relay cape into P8 and P9 connectors.STEP 4
Reboot your BeagleBone and verify the overlay is loadedcat /sys/devices/bone_capemgr.*/slots
This shows the Relay cape overlay is installed in the first slot address (default) "0:". The address can be changed using the cape eeprom dip slide switches (see Relay cape manual).
STEP 5
We can now download and run a simple program.Download CBB-relay-leds.js File
Save file as “CBB-relay-leds.js”
STEP 6
In Cloud 9, Click RUN to start the CBB-relay-leds program.Pressing push-button S1,S2,S3,S4 will control the corresponding outputs O1,O2,O3,O4. The Blue LED will blink. Relay K1 will also turn ON with S1, and K2 will turn ON with S4.
In addition the status of the input pins are displayed to the console, along with the values of the analog inputs
NOTE: the black jumper must be installed in VOUT for either +3.3 or +5V position.
(see CBB-relay manual for details)
Bonescript program listing
// NOTE: External 5V required var b = require('bonescript'); var BlueLedPin = "P9_24"; var In1Pin = "P8_11"; var In2Pin = "P8_12"; var In3Pin = "P8_14"; var In4Pin = "P8_15"; var Out1Pin = "P9_42"; var Out2Pin = "P9_22"; var Out3Pin = "P9_21"; var Out4Pin = "P9_16"; //var DVMPin = "P9_40"; // divided by 10 //var PotPin = "P9_36"; // Potentiometer var K1Pin = "P8_18"; var K2Pin = "P9_27"; var potValue = 0; var battValue= 0; var in1value = 0; var in2value = 0; var in3value = 0; var in4value = 0; var state = 0; b.pinMode(In1Pin, b.INPUT); b.pinMode(In2Pin, b.INPUT); b.pinMode(In3Pin, b.INPUT); b.pinMode(In4Pin, b.INPUT); b.pinMode(Out1Pin, b.OUTPUT); b.pinMode(Out2Pin, b.OUTPUT); b.pinMode(Out3Pin, b.OUTPUT); b.pinMode(Out4Pin, b.OUTPUT); b.pinMode(K1Pin, b.OUTPUT); b.pinMode(K2Pin, b.OUTPUT); b.pinMode(BlueLedPin, b.OUTPUT); b.digitalWrite(K1Pin, b.LOW); b.digitalWrite(K2Pin, b.LOW); b.digitalWrite(Out1Pin, b.LOW); b.digitalWrite(Out2Pin, b.LOW); b.digitalWrite(Out3Pin, b.LOW); b.digitalWrite(Out4Pin, b.LOW); setInterval(readPins, 500); function readPins() { state = state ? 0 : 1; b.digitalWrite(BlueLedPin, state); in1value = b.digitalRead(In1Pin); in2value = b.digitalRead(In2Pin); in3value = b.digitalRead(In3Pin); in4value = b.digitalRead(In4Pin); b.digitalWrite(Out1Pin, in1value); b.digitalWrite(Out2Pin, in2value); b.digitalWrite(Out3Pin, in3value); b.digitalWrite(Out4Pin, in4value); b.digitalWrite(K1Pin, in1value); b.digitalWrite(K2Pin, in4value); // potValue = b.analogRead(PotPin)*1.8; // battValue = b.analogRead(DVMPin)*18; console.log(in1value, in2value, in3value, in4value, potValue, battValue); //console.log(potValue, battValue); }
Making a Relay connection
A relay is an electro-mechanical device. Inside the relay, a coil of wire forms an electro-magnet. When energized this coil creates a temporary magnet that draws or closes (ON) mechanical contacts of a switch. The contacts are arranged so that one pair is Normally Open (disconnected) and a second pair is Normally Closed (connected). Energizing the relay changes the contacts state. "SPDT" means single Single-Pole Double-Throw. In simple terms a single common (C) contact (or pole) point can be 'thrown' to either a normally open (NO) contact or a normally closed (NC) contact. The Normally closed contact is closed (electrically connected) even when power is removed.In this simple connection example, a 9 Volt battery is connected to a a light using the Normally Open contacts of relay 2. This circuit will turn ON the light when the relay is energized. A connection is made between 2NO and 2CO by the relay contacts. A small screw driver is required to secure the wire, by tightening the screw above the contact terminals.
- Black wire from Battery (-) to Relay 2 "2NO" (Normally Open) contact
- Green wire from Relay 2 "2CO" (Common) contact to Light terminal 1
- Red wire from Light terminal 2 to battery (+)