Skip to content

Instantly share code, notes, and snippets.

@treeherder
Last active October 4, 2015 05:26
Show Gist options
  • Save treeherder/386b18480dd9fce158e1 to your computer and use it in GitHub Desktop.
Save treeherder/386b18480dd9fce158e1 to your computer and use it in GitHub Desktop.
intel edison quickstart for magnitude.io hackathon

From my Edison with ubilinux

$ apt-get install libusb-dev libdbus-1-dev libglib2.0-dev automake libudev-dev libical-dev libreadline-dev rfkill

$ wget http://www.kernel.org/pub/linux/bluetooth/bluez-5.24.tar.xz

$ tar xf bluez-5.24.tar.xz

$ cd bluez-5.24

$ ./configure –disable-systemd

$ make -j 2

$ make install

Then from the original image (I have downloaded on my laptop and mounted the ext4 file locally) you should copy the following folder and files to your Edison ubilinux filesystem:

/etc/bluetooth/

/usr/sbin/bluetooth_rfkill_event

/usr/sbin/brcm_patchram_plus

As the original files from the Yocto image are looking for the bluetooth firmware in the etc folder (instead that from the /lib/firmware) from your Edison ubilinux run:

$ mkdir /etc/firmware

$ cp /lib/firmware/bcm43341.* /etc/firmware/

now from your Edison ubilinux run the bluetooth_rfkill_event in background:

$ bluetooth_rfkill_event &

$ rfkill unblock bluetooth

now you should see the BT device

$ hciconfig dev

and scan for other devices

$ hcitool scan

##intel Edison Yocto linux

###setup on the arduino breakout module:

  • the barrel jack wants 7-17 Volts DC. The official documentation suggests ~12
  • the USB A and the micro USB nearest it are configured with the microswitch between them
    • when the micro USB port is selected, the device is in CLIENT MODE
    • when the USB A port is connected, the device is in HOST MODE
  • the last micro USB port is access to the linux serial terminal

#####1. configure drivers, etc.

  • You'll have to follow the steps for your operating system to be able to connect over usb serial to the edison

#####2. connect to edison

  • use your terminal emulator to connect to the edison
  • screen {your serial port} 115200 -L
  • press enter a few times
  • login as root
  • type reboot otp
  • wait for reboot

#####3. run builtin setup scripts

  • configure_edison --setup
  • follow the rules, jump through the hoops

#####4. do your thang.

  • just kidding! you actually have to configure opkg now...
    • paste into /etc/opkg/base-feeds.conf
    src/gz all http://repo.opkg.net/edison/repo/all
    src/gz edison http://repo.opkg.net/edison/repo/edison
    src/gz core2-32 http://repo.opkg.net/edison/repo/core2-32
    
    • run opkg update
  • you'll probably want to useradd {a user name} so that you can login over SSH
  • run opkg install git *from here, use git to install npm from source

###helpful information for getting started with GPIO:

I highly recommend using Debian Linux. because of access to package management, etc.

[debian for edison] (http://www.emutexlabs.com/ubilinux/29-ubilinux/218-ubilinux-installation-instructions-for-intel-edison)

#!/bin/bash
echo 200 > /sys/class/gpio/unexport
echo 232 > /sys/class/gpio/unexport
echo 208 > /sys/class/gpio/unexport
echo 214 > /sys/class/gpio/unexport
echo 200 > /sys/class/gpio/export
echo 232 > /sys/class/gpio/export
echo 208 > /sys/class/gpio/export
echo 214 > /sys/class/gpio/export
echo low > /sys/class/gpio/gpio214/direction
echo high > /sys/class/gpio/gpio200/direction
echo low > /sys/class/gpio/gpio232/direction
echo in > /sys/class/gpio/gpio208/direction
echo high > /sys/class/gpio/gpio214/direction
echo "i2c over GPIO is configured: A4->SDA, A5->SCL"
/* Copyright (c) 2011, RidgeRun
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the RidgeRun.
* 4. Neither the name of the RidgeRun nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY RIDGERUN ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL RIDGERUN BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <poll.h>
/****************************************************************
* Constants
****************************************************************/
#define SYSFS_GPIO_DIR "/sys/class/gpio"
#define POLL_TIMEOUT (3 * 1000) /* 3 seconds */
#define MAX_BUF 64
/****************************************************************
* gpio_export
****************************************************************/
int gpio_export(unsigned int gpio)
{
int fd, len;
char buf[MAX_BUF];
fd = open(SYSFS_GPIO_DIR "/export", O_WRONLY);
if (fd < 0) {
perror("gpio/export");
return fd;
}
len = snprintf(buf, sizeof(buf), "%d", gpio);
write(fd, buf, len);
close(fd);
return 0;
}
/****************************************************************
* gpio_unexport
****************************************************************/
int gpio_unexport(unsigned int gpio)
{
int fd, len;
char buf[MAX_BUF];
fd = open(SYSFS_GPIO_DIR "/unexport", O_WRONLY);
if (fd < 0) {
perror("gpio/export");
return fd;
}
len = snprintf(buf, sizeof(buf), "%d", gpio);
write(fd, buf, len);
close(fd);
return 0;
}
/****************************************************************
* gpio_set_dir
****************************************************************/
int gpio_set_dir(unsigned int gpio, unsigned int out_flag)
{
int fd, len;
char buf[MAX_BUF];
len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio);
fd = open(buf, O_WRONLY);
if (fd < 0) {
perror("gpio/direction");
return fd;
}
if (out_flag)
write(fd, "out", 4);
else
write(fd, "in", 3);
close(fd);
return 0;
}
/****************************************************************
* gpio_set_value
****************************************************************/
int gpio_set_value(unsigned int gpio, unsigned int value)
{
int fd, len;
char buf[MAX_BUF];
len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
fd = open(buf, O_WRONLY);
if (fd < 0) {
perror("gpio/set-value");
return fd;
}
if (value)
write(fd, "1", 2);
else
write(fd, "0", 2);
close(fd);
return 0;
}
/****************************************************************
* gpio_get_value
****************************************************************/
int gpio_get_value(unsigned int gpio, unsigned int *value)
{
int fd, len;
char buf[MAX_BUF];
char ch;
len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
fd = open(buf, O_RDONLY);
if (fd < 0) {
perror("gpio/get-value");
return fd;
}
read(fd, &ch, 1);
if (ch != '0') {
*value = 1;
} else {
*value = 0;
}
close(fd);
return 0;
}
/****************************************************************
* gpio_set_edge
****************************************************************/
int gpio_set_edge(unsigned int gpio, char *edge)
{
int fd, len;
char buf[MAX_BUF];
len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/edge", gpio);
fd = open(buf, O_WRONLY);
if (fd < 0) {
perror("gpio/set-edge");
return fd;
}
write(fd, edge, strlen(edge) + 1);
close(fd);
return 0;
}
/****************************************************************
* gpio_fd_open
****************************************************************/
int gpio_fd_open(unsigned int gpio)
{
int fd, len;
char buf[MAX_BUF];
len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio);
fd = open(buf, O_RDONLY | O_NONBLOCK );
if (fd < 0) {
perror("gpio/fd_open");
}
return fd;
}
/****************************************************************
* gpio_fd_close
****************************************************************/
int gpio_fd_close(int fd)
{
return close(fd);
}
/****************************************************************
* Main
****************************************************************/
int main(int argc, char **argv, char **envp)
{
struct pollfd fdset[2];
int nfds = 2;
int gpio_fd, timeout, rc;
char *buf[MAX_BUF];
unsigned int gpio;
int len;
if (argc < 2) {
printf("Usage: gpio-int <gpio-pin>\n\n");
printf("Waits for a change in the GPIO pin voltage level or input on stdin\n");
exit(-1);
}
gpio = atoi(argv[1]);
gpio_export(gpio);
gpio_set_dir(gpio, 0);
gpio_set_edge(gpio, "rising");
gpio_fd = gpio_fd_open(gpio);
timeout = POLL_TIMEOUT;
while (1) {
memset((void*)fdset, 0, sizeof(fdset));
fdset[0].fd = STDIN_FILENO;
fdset[0].events = POLLIN;
fdset[1].fd = gpio_fd;
fdset[1].events = POLLPRI;
rc = poll(fdset, nfds, timeout);
if (rc < 0) {
printf("\npoll() failed!\n");
return -1;
}
if (rc == 0) {
printf(".");
}
if (fdset[1].revents & POLLPRI) {
len = read(fdset[1].fd, buf, MAX_BUF);
printf("\npoll() GPIO %d interrupt occurred\n", gpio);
}
if (fdset[0].revents & POLLIN) {
(void)read(fdset[0].fd, buf, 1);
printf("\npoll() stdin read 0x%2.2X\n", (unsigned int) buf[0]);
}
fflush(stdout);
}
gpio_fd_close(gpio_fd);
return 0;
}
@treeherder
Copy link
Author

expand rootfs

root@ubilinux:~# df -h
Filesystem       Size  Used Avail Use% Mounted on
rootfs           1.4G  612M  704M  47% /
/dev/root        1.4G  612M  704M  47% /
devtmpfs         481M     0  481M   0% /dev
tmpfs             97M  316K   96M   1% /run
tmpfs            5.0M     0  5.0M   0% /run/lock
tmpfs            193M     0  193M   0% /run/shm
tmpfs            481M     0  481M   0% /tmp
/dev/mmcblk0p7    32M  5.1M   27M  16% /boot
/dev/mmcblk0p10  1.6G  2.4M  1.6G   1% /home
/dev/mmcblk1p1   7.2G  877M  6.0G  13% /usr

@treeherder
Copy link
Author

[treeherder@gnosis etc]$ scp -r bluetooth  edison:/etc/
proximity.conf                                100%  258     0.3KB/s   00:00    
network.conf                                  100%  120     0.1KB/s   00:00    
input.conf                                    100%  397     0.4KB/s   00:00    
main.conf                                     100% 2323     2.3KB/s   00:00 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment