Quantcast
Channel: SparkFun Tutorials
Viewing all articles
Browse latest Browse all 1123

SparkFun Blocks for Intel® Edison - Pi Block

$
0
0

SparkFun Blocks for Intel® Edison - Pi Block a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t412

Introduction

The Pi Block breaks out and level shifts several GPIO pins from the Intel Edison. It presents them in the same configuration as a Raspberry Pi Model B.

Intel Edison Pi Block

Pi Block

Suggested Reading

If you are unfamiliar with Blocks, take a look at the General Guide to Sparkfun Blocks for Intel Edison.

Other tutorials that may help you on your Edison adventure include:

Board Overview

Annotated Pi Block functions

Pi Block Functional Diagram

  • USB Power - used to provide 5V to Pi Block and power the Edison. Note that the data lines are not connected to the Edison.

  • Power Button - The power switch is connected to the “PWRBTN” line on the Edison. This give the user the ability to place an Edison in sleep or power down the module completely. This does not affect power to other Blocks in the stack.

  • Power LED - The power LED illuminates when power is present on VSYS. This can come from the onboard USB Power or any other powered Block in the stack.

  • Expansion Header - The 70-pin Expansion header breaks out the functionality of the Intel Edison. This header also passes signals and power throughout the stack. These function much like an Arduino Shield.

  • LED Jumper - If power consumption is an issue, cut this jumper to disable the power LED.

  • VSYS Jumper - By default, a USB cable must be attached to the USB Power port to provide power to the 5V pins on the RPi B Header. You can power the Edison and Pi Block from another Block (e.g. Base Block), but there will not be 5V on the pins labeled “5V”. By closing this jumper, you can power the Edison and Pi Block from another Block, and ~4.2V (VSYS) will appear on the pins labeled “5V”.

  • RPi B Header - Same configuration as the old Raspberry Pi Model B pinout.

Using the Pi Block

To use the Pi Block, attach an Intel® Edison to the back of the board, or add it to your current stack. Blocks can be stacked without hardware, but it leaves the expansion connectors unprotected from mechanical stress.

Edison installed on Pi Block

Edison installed on Pi Block

We have a nice Hardware Pack available that gives enough hardware to secure three blocks and an Edison.

alt text

Intel Edison Hardware Pack

NOTE: It is recommended to use a console communication block in conjunction with this block like ones found in the General Guide to Sparkfun Blocks for Intel Edison. Once you have the Edison configured, you can remove the console communication block, power the Edison from the Pi Block, and SSH into the Edison.

You can put headers on the Edison side, which gives you easy access to the pin labels. Note that this pinout is mirrored from the Raspberry Pi Model B pinout.

Headers on top of Edison Pi Block

Headers on Edison side

Alternatively, you can populate the back side of the Pi Block with headers. This method gives the same pinout as a Raspberry Pi Model B. You could, in theory, swap the Edison in for your Raspberry Pi on an existing project, or use Raspberry Pi accessories (e.g. Pi Wedge).

Headers on bottom of Edison Pi Block

Or put headers on the back side of Pi Block

Using the Pi Block as an output device

If you want to use the Pi Block to control high power LEDs or relays, an external transistor or MOSFET will be required. It is possible to illuminate a small LED directly from the level shifter. It may not be as bright since the current output of the TXB0108 level converter is very low (~5ma).

alt text

Connection Diagram for Load (LED, Motor, or Relay)

In the terminal, we will demonstrate how to activate and use a GPIO pin as an output.

First navigate to the GPIO directory on the Edison.

cd /sys/class/gpio

Select the GPIO pin to enable. In this case, we used GPIO 14, which is labeled “GP14” on the Pi Block.

echo 14 > export

Navigate to the newly created GPIO directory.

cd gpio14

If you type “ls”, you should see a bunch of variables.

active_low  direction   power       uevent
device      edge        subsystem   value

Let’s set the “direction” of the port to output

echo out > direction

To confirm this, we will “cat” the value

cat direction

You should see the “out” in the command line. Now the device is configured as an output.“value” is where the status of the pin is set, 1 for high, 0 for low.

echo 1 > value

Testing with a multi-meter, small led, or oscilloscope, you should see a “high” status (3.3V) present on gpio14.

Using the GPIO Block as an input device

If you want the Pi Block to read switches, buttons, or other logic level inputs, you must pay attention to pull-up and pull-down resistors. The level converter on board is very weak. Here are two scenarios explained:

alt text

Connection Diagram for Active High Push Button

alt text

Connection Diagram for Active Low Push Button

In the terminal, we will demonstrate how to activate and use a GPIO pin as an input configured as an active high.

First, navigate to the GPIO directory on the Edison.

cd /sys/class/gpio

Select the GPIO pin to enable. In this case let us use GPIO 14.

echo 14 > export

Navigate to the newly created GPIO directory.

cd gpio14

If you type “ls”, you should see a bunch of variables.

active_low  direction   power       uevent
device      edge        subsystem   value

Let’s set the “direction” of the port to output.

echo in > direction

To confirm this, we will “cat” the value.

cat direction

You should see the “in” in the command line. Now the device is configured as an input.“value” is where the status of the pin is set, 1 for high, 0 for low.

cat value

With a button pressed, you should see a 1. When the button is not pressed you should see a 0. Using the up arrow, you can recall previously run commands.

C++ Examples

We’re assuming that you’re using the Eclipse IDE as detailed in our Beyond Arduino tutorial. If you aren’t, you’ll need to go to that tutorial to get up to speed.

Hardware Connection

Hardware support for this library is simple; one basic red LED and one momentary pushbutton. We’re using a 2N3904 NPN transistor to drive the LED, however, as the drive strength of the outputs on the Pi Block is quite weak. As you can see in the diagram, you’ll also need a couple of 1kΩ resistors and a single 330Ω resistor.

Intel Edison Pi Block connections

While we’ve used GPIO45 and GPIO46 in this example, this code can be used with any of the pins on the Pi breakout. The GPIO to MRAA pin map can be found in the Resources and Going Further section.

Code

Follow the instructions in the programming tutorial to create a new project named “SparkFun_Pi_Block_Example”. Once you’ve created the project, open the “SparkFun_Pi_Block_Example.cpp” file and replace all the existing code with the code block below.

language:c
  /****************************************************************
  Example file for SparkFun Pi Block Support

  14 Jul 2015- Mike Hord, SparkFun Electronics
  Code developed in Intel's Eclipse IOT-DK

  Modified on July 30, 2015 by Shawn Hymel, SparkFun Electronics

  This code requires the Intel mraa library to function; for more
  information see https://github.com/intel-iot-devkit/mraa

  This code is beerware; if you use it, please buy me (or any other
  SparkFun employee) a cold beverage next time you run into one of
  us at the local.
  ****************************************************************/

#include "mraa.hpp"

#include <iostream>
#include <unistd.h>

using namespace mraa;
using namespace std;

int main()
{

  // Oddly, GPIO pin assignment numbers when using the MRAA libraries are not
  //  the same as those inside the operating system. Thus, while we're using
  //  pin 46 as far as the OS is concerned to drive the LED, we're using pin 32
  //  as far as MRAA is concerned. The cheat sheet for that can be found here:
  //  https://github.com/intel-iot-devkit/mraa/blob/master/docs/edison.md
  Gpio LEDPin(45);
  LEDPin.dir(DIR_OUT);

  // Now do a quick little flicker.
  LEDPin.write(0);
  usleep(100000);
  LEDPin.write(1);
  usleep(100000);
  LEDPin.write(0);

  // Alternatively, we can declare the pin in "raw" mode, which has a slightly
  //  different and more unwieldy constructor.
  Gpio buttonPin(32, true, true);
  buttonPin.dir(DIR_IN);

  // In this infinite loop, we'll blink the LED once whenever someone presses
  //  the button.
  while (1)
  {
    // We *know* that if the IO pin reads as 0, or is low, read() returns zero.
    //  However, if it's high, it *may* return something else; the only guarantee
    //  is that it will be nonzero. Thus, don't test to see if a read() returned
    //  a 1!!!
    if (buttonPin.read() == 0)
    {
      LEDPin.write(1);
      sleep(1);
      LEDPin.write(0);
      sleep(1);
    }
  }

  return MRAA_SUCCESS;
}

Additional Examples

Because this block is just a GPIO access device, the existing MRAA GPIO examples can be used with it.

Example projects in the IDE

When you create a new project in the Eclipse IDE, it will offer you the option of several starter projects. Some of them, noted above, are good examples of using the MRAA GPIO functions. They’re more complex than what we’ve provided here, however.

For full documentation of the C++ API for GPIO pins, please visit the official MRAA documentation.

Resources and Going Further

Pin Map

You might have noticed that we used GP46 in hardware and GPIO 32 in our example code. This is because the MRAA library uses a different number for the pins. If you would like to use MRAA to control hardware, figure out which GPIO pins you plan to use on the table below (labeled “Edison Pin”) and then use the MRAA Number in software.

The available pins on the Pi Block have been highlighted in yellow in the table.

Notes:

  • Input/output voltage on the Pi Block is 3.3V
  • Input/output voltage on the GPIO Block is 3.3V by default
  • Input/output voltage on the Arduino Breakout is 5V
  • Input/output voltage on the Mini Breadboard is 1.8V

MRAA pin map table based on Intel’s IOT Dev Kit Repository

Edison Pin (Linux)Arduino BreakoutMini BreakoutMRAA NumberPinmode0Pinmode1Pinmode2
GP123J18-7 20GPIO-12PWM0
GP135J18-1 14GPIO-13PWM1
GP14A4J19-9 36GPIO-14
GP15J20-7 48GPIO-15
GP19J18-6 19GPIO-19I2C-1-SCL
GP20J17-8 7GPIO-20I2C-1-SDA
GP27J17-7 6GPIO-27I2C-6-SCL
GP28J17-9 8GPIO-28I2C-6-SDA
GP4013J19-10 37GPIO-40SSP2_CLK
GP4110J20-10 51GPIO-41SSP2_FS
GP4212J20-9 50GPIO-42SSP2_RXD
GP4311J19-11 38GPIO-43SSP2_TXD
GP44A0J19-4 31GPIO-44
GP45A1J20-4 45GPIO-45
GP46A2J19-5 32GPIO-46
GP47A3J20-5 46GPIO-47
GP487J19-6 33GPIO-48
GP498J20-6 47GPIO-49
GP77J19-12 39GPIO-77SD
GP78J20-11 52GPIO-78SD
GP79J20-12 53GPIO-79SD
GP80J20-13 54GPIO-80SD
GP81J20-14 55GPIO-81SD
GP82J19-13 40GPIO-82SD
GP83J19-14 41GPIO-83SD
GP84J20-8 49GPIO-84SD
GP109J17-11 10GPIO-109SPI-5-SCK
GP110J18-10 23GPIO-110SPI-5-CS0
GP111J17-10 9GPIO-111SPI-5-CS1
GP114J18-11 24GPIO-114SPI-5-MISO
GP115J17-12 11GPIO-115SPI-5-MOSI
GP1282J17-14 13GPIO-128UART-1-CTS
GP1294J18-12 25GPIO-129UART-1-RTS
GP1300J18-13 26GPIO-130UART-1-RX
GP1311J19-8 35GPIO-131UART-1-TX
GP134J20-3 44
GP135J17-5 4GPIO-135UART
GP165A5J18-2 15GPIO-165
GP1826J17-1 0GPIO-182PWM2
GP1839J18-8 21GPIO-183PWM3

Edison General Topics:

Block Specific Topics:


learn.sparkfun.com |CC BY-SA 3.0 | SparkFun Electronics | Niwot, Colorado


Viewing all articles
Browse latest Browse all 1123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>