Tuesday, May 3, 2016

Fun with RGB LED

People often need home lighting control in their lives. These individuals can easily find relevant products which often use different methods to reach their goal. One of the method is LED lighting, which uses new principles, materials, and means of control. All signs point to a significant increase in the use of LED lighting systems, replacement lamps, and retrofits worldwide, with the greatest growth in general illumination applications.

An RGB LED is actually three LEDs, red, green, and blue inside one package, A single LED die can only emit monochromatic light which could be one of the three primary colors - red, green and blue, known as RGB. To realize more colors, three LED dies need to be used together for RGB color mixing. By controlling the brightness of each of the individual LEDs you can mix pretty much any color you want. Using an RGB LED you can cycle through all colors. Useful to make, Mood Lamp, expressive robot or cool light effects.


Credit: Pavan Kumar Jarmale
Credit: Pavan Kumar Jarmale

Idea

 

Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. These sensors are capable of providing raw data with high precision and accuracy. By using Accelerometer and Magnetometer, we can calculate the orientation (tilt) around Y-axis (Roll) and we can control the color variations of an RGB LED which is connected to Intel Edison based on these angles over Bluetooth.



How it works

 

Android device comes with few built-in sensors amongst those we have used accelerometer and magnetometer. Accelerometer data will contain noise in its output therefore will not be able to give stable values. To overcome this, we combined magnetometer data with accelerometer data to get stable orientation values / angles. The data is the rotational angle from 0 degree to 360 degrees. In Intel Edison, these values are mapped to change in the Intensity of the Red, Green and Blue colors. By changing the duty cycle of the Pulse Width Modulated signal, we can change the brightness of the LED. A particular color when varied can be kept constant by turning off the switch in the app UI or by disconnecting the Bluetooth connection.


Hardware 

 

3. Android Smartphone (Accelerometer and Magnetometer are must)
5. Wires / Connectors


Setup

 

1. Connect Red LED pin to pin 3 of Intel Edison via 220 Ohm resistor
2. Connect Blue LED pin to pin 5 of Intel Edison via 220 Ohm resistor
3. Connect Green LED pin to pin 6 of Intel Edison via 220 Ohm resistor
4. Connect Anode LED pin to 3.3 V supply of Intel Edison



Credit: Mukesh G
Credit: Mukesh G


Software

 

On Android: 

Build the BTRGBControl project using Android Studio and upload the generated apk to your smartphone.
 OR
Download the apk from this link.

On Edison:

  • Bluetooth-SPP Python wrapper
  • PyBluez
The above two application packages are Intel Edison specific. To install and run the program, please follow this link.



Outcome


The outcomes of the project are as follows:

1. Orientation from 180deg to 360deg gives luminous light. Each angle when the
2. Gave better results when the LED was powered at 5V than when it was powered at 3.3V.
3. In one of the program, the red and blue remains constant and green varies at the extreme end of orientation. The other program portrays that blue and green remains constant and red varies at the extreme end of orientation. Similarly, LED can produce many colors by varying the combinations of R, G and B.
4. The color can be kept constant by turning off the switch in the app UI or by disconnecting the Bluetooth connection.


Demo

 






Real life Connect


Using the most simple and direct method, the idea empowers people to control their personal lighting environment from their mobile device. You can easily customize your lighting colors to match your desired mood and atmosphere, transforms your living room into a dance floor and simulate calming moonlight to improve sleep and enhance rest, mimics the sunrise in the morning and synchronize your music with lighting effects. Similarly, we can apply the same concept to control other home appliances.


Credits

On Edison, program was written by Kiran Hegde (Email: kiranmadansar@gmail.com)


Wednesday, November 4, 2015

Boot Intel Edison from SD card (With Debian or Ubilinux)

This tutorial describes a way to boot an Edison board with the Root Filesystem on an external storage (SD card or USB stick). The kernel and bootloader remain on the local eMMC. For now, we are not able to boot a kernel from an external storage.

Before following any of these steps, make sure you have booted ubilinux or debian os (from Emutexlabs) on Intel Edison.


1. Prepare External Storage (MicroSD Card)

 

  • You need to have a SD card formatted with ext4 file system to store the root file system
  • On your desktop computer with Linux installed, using GParted, format your SD card using ext4 file-system. Eject the SD Card and insert it back



  • Download and unpack Debian image from emutexlabs website. In the unpacked directory (with the "flashall.sh" script) run the following commands to prepare the SD card. These commands mount the edison-image-edison.ext4 rootfs image and copy the contents onto the SD card (be sure to be root to do that)


     
  • In the unpacked directory,
sudo su
mkdir Rootfs
mount ./edison-image-edison.ext4 Rootfs
cp -a Rootfs/* /media/saru/eb361b92-c285-44a6-9f32-da393c879487
sync

  • Now, eject the SD Card and ready to boot


2. Find out the SD card device name 

 

On a running Edison board, plug your formatted SD card and get the device name. 
  • Run the below command, 
dmesg | tail -n 10

Here, the SD card device is “/dev/mmcblk1” and the partition we’ve created is "/dev/mmcblk1p1"

 

3. Boot the board using SD card



Debian system on Edison, does not mount the microsd card automatically. To mount sdcard at boot, modify the /etc/fstab system file in edison.
  • Find the UUID for the sd card 
blkid 

  • add an entry for the partition to automount it at startup. Add file system, mount point, type, options, dump and pass information of sdcard partition to fstab file and save it. Example, the format looks like below,
           /dev/sdcX      /media/sdcard    ext4    defaults    0     0
nano /etc/fstab
#Add an entry for the partition
UUID=eb361b92-c285-44a6-9f32-da393c879487    /media/sdcard    ext4    defaults    0 0

mkdir -p /media/sdcard/
reboot
 After reboot, debian os automatically mounts the sdcard.


To boot using the external device, you need to modify the U-Boot environment variable named "mmc-bootargs" with kernel boot arguments. We cannot modify U-Boot environment variables from edison linux console in debian os. It is possible only in U-Boot command prompt.


Note:    
To modify U-Boot env variables, u-boot and u-boot-tools packages are available in debian repository. The tools fw_printenv/fw_setenv in the u-boot source tree normally work with MTD partitions but they don’t support MMC.


To modify u-boot env variables ,during the boot, on the serial console, when it prompts to press a key to stop booting, press any key and then run the following commands in the U-Boot command prompt.

> setenv mmc-bootargs 'setenv bootargs root=${myrootfs} rootdelay=3 rootfstype=ext4 ${bootargs_console} ${bootargs_debug} systemd.unit=${bootargs_target}.target hardware_id=${hardware_id} g_multi.iSerialNumber=${serial#} g_multi.dev_addr=${usb0addr}'

> setenv myrootfs '/dev/mmcblk1p1'

> setenv myrootfs_sdcard /dev/mmcblk1p1

> setenv myrootfs_emmc PARTUUID=012b3303-34ac-284d-99b4-34e03a2335f4

> setenv do_boot_emmc 'setenv myrootfs ${myrootfs_emmc}; run do_boot'

> setenv do_boot_sdcard 'setenv myrootfs ${myrootfs_sdcard}; run do_boot'

> setenv bootdelay 5

> saveenv

> run do_boot_sdcard



After boot, verify that you are using rootfs stored on your external device.


Note: 
If you want to switch to eMMC just occasionally, during the boot, on the serial console, when it prompts to press a key to stop booting, press any key and then run the below command in the U-Boot command prompt that appears:
> run do_boot_emmc

Friday, March 20, 2015

MPU6050 with Intel Galileo (Python interface)

The MPU6050 is an integrated 6-axis Motion-tracking device that combines a 3-axis gyroscope, 3-axis accelerometer, and Digital Motion Processor (Datasheet and Register Mapping).
It is accurate, as it contains 16-bits analog to digital conversion hardware for each channel. Therefore it captures x, y, and z channel at the same time. The sensor has an I2C-bus so we can communicate with this device over I2C.

MPU6050 with Galileo (Arduino Environment):


This is pretty simple, for this you need to boot small SPI flash image (default one). Several sources are already available in internet but if you couldn't find it please check this out.

MPU6050 with Galileo - Python interface (Linux Environment):


To do this, you need to boot bigger linux image.

Connecting the sensor: 




To do this, your image needs to have python-smbus module. python-smbus is a Python module allows SMBus access through the I2C interface on Linux hosts. The host kernel must have I2C support, I2C device interface support, and a bus adapter driver.

The official image doesnot contain python-smbus module.

Workaround for python-smbus on Intel Galileo:  

  • First, you need to use an image with dev-tools installed on it (I’m using an image provided by Intel). Download the image from here.
  • Manually download I2C library from here and extract the tar file.
  • Before compilation, you have to patch a single line.
  • Go to the extracted directory and edit smbusmodule.c file in py-smbus directory. 
  • cd py-smbus
    vi smbusmodule.c
  • Change the constant I2C_SLAVE to I2C_SLAVE_FORCE in line 159 and then compile the source code.
  • make EXTRA="py-smbus"
    make install     # This will create the i2c-tools
    #The tools like i2cdetect and i2cget should be work now
    #Then go into the py-symbus directory and call
    python setup.py install
  • Now you should be able to execute a python script like this.
  • from smbus import SMBus
    bus = SMBus(0)
    bus.write_byte_data(0x20, 0x29, 0x04)

Note: IO mapping in Gen 2 is different from Gen 1.

For Galileo Gen 1:

If you want to communicate with external I2C slaves (like MPU6050, TSL2561), then you need to change the value of GPIO 29 to 0 (default is 1).
echo -n "29" > /sys/class/gpio/export
cd /sys/class/gpio
cat /gpio29/value # check the value of GPIO 29, it is 1 change it to 0
echo -n "out" > /sys/class/gpio/gpio29/direction
echo -n "0" > /sys/class/gpio/gpio29/value # After this, A4 and A5 lines act like
#SDA and SCL lines respectively 

For Galileo Gen 2:
echo -n "60" > /sys/class/gpio/export
cd /sys/class/gpio
cat /gpio60/value # check the value of GPIO 60, it is 1 change it to 0
echo -n "out" > /sys/class/gpio/gpio60/direction
echo -n "0" > /sys/class/gpio/gpio60/value # After this, A4 and A5 lines act like
#SDA and SCL lines respectively 

For IO Mapping, please check the below links.

Python program for MPU6050
#!/usr/bin/python

import smbus
import sys

# This is the address value read via the i2cdetect command
# if AD0 pin is connected to ground, address will be 0x68
# if AD0 pin is connected to vcc, address will be 0x69
 
ADDRESS_LOW      = 0x68
ADDRESS_HIGH     = 0x69

# Power management registers
power_mgmt_1  = 0x6B
power_mgmt_2  = 0x6C
SMPLRT_DIV       = 0x19
#Registers from which read accel, temp and gyro sensor values
ACCEL_XOUT_H  = 0X3B
ACCEL_YOUT_H  = 0X3D
ACCEL_ZOUT_H  = 0X3F

TEMP_OUT_H  = 0X41

GYRO_XOUT_H   = 0X43
GYRO_YOUT_H  = 0X45
GYRO_ZOUT_H   = 0X47

address = ADDRESS_HIGH

def write_byte(radd, val):
    bus.write_byte_data(address, radd, val)

def read_byte(radd):
    return bus.read_byte_data(address, radd)

def read_word(radd):
    high = bus.read_byte_data(address, radd)
    low = bus.read_byte_data(address, radd+1)
    val = (high << 8) + low
    return val

def read_word_2c(radd):
    val = read_word(radd)
    if (val >= 0x8000):
        return -((65535 - val) + 1)
    else:
        return val

try:
    bus = smbus.SMBus(0)
    # Now wake the 6050 up as it starts in sleep mode
    write_byte(power_mgmt_1, 0x01)

    while(True):
        try:

            accel_xout = read_word_2c(ACCEL_XOUT_H)
            accel_yout = read_word_2c(ACCEL_YOUT_H)
            accel_zout = read_word_2c(ACCEL_ZOUT_H)

            gyro_xout = read_word_2c(GYRO_XOUT_H)
            gyro_yout = read_word_2c(GYRO_YOUT_H)
            gyro_zout = read_word_2c(GYRO_ZOUT_H)

            temp_val = read_word_2c(TEMP_OUT_H)
   
            print "######################################"
            print "accelerometer data"
            print "------------------"  

            print "accel_xout: ", accel_xout
            print "accel_yout: ", accel_yout
            print "accel_zout: ", accel_zout

            print "gyro data"
            print "---------"

            print "gyro_xout: ", gyro_xout
            print "gyro_yout: ", gyro_yout
            print "gyro_zout: ", gyro_zout

            temp_dT = (temp_val / 340)+36.53
            print "temp val: ", temp_dT

        except KeyboardInterrupt:
            write_byte(power_mgmt_1, 0x41) # Sleep mode
            print "Keyboard exception arises.
            print "Program interrupted."
            print "Program is going to terminate."
            break

except IOError:
    print "Program IO Error."

except:
    print "Program General Exception." 
 
sys.exit()  

Reference:

Friday, March 6, 2015

Galileo with bigger linux image

Galileo is capable of running two kinds of images (operating system).

  • Small Linux for SPI Flash
  • Full-featured Linux for SD card

There is a fundamental difference. Galileo has an on-board flash memory of size 8Mb, limited amount of space to store its Linux kernel (as well as sketch). The small linux image only allows execution of Arduino sketches. It should be noted that the current firmware will not store sketch in the flash, so it will be lost on power cycle.

As such, the default Linux image is limited in terms of extra features. Fortunately Intel supplies Board Support package, which allows to include everything needed to rebuild the Linux image using Yocto.

But with an SD card, we can boot the Galileo with a bigger Linux image, which provides access to the following: 

  • WiFi drivers – The Galileo supports Intel-chipset WiFi cards with these drivers. Plug them in, and they should be recognized immediately.
  • Python – Python is our favorite when it comes to scripting languages. With Python you can easily post to Twitter, check for unread emails, and perform all sorts of other activities.
  • Node.js – Node.js is a popular JavaScript-based scripting language. A good alternative to Python, if you’re more comfortable with JS.
  • SSH – Secure Shell (SSH) is a very useful network tool that allows you to log into and control a device remotely. With SSH running on your network-connected Galileo, and remotely control the board from any device on the network.
  • openCV – OpenCV is an open-source computer vision application. You can plug a USB webcam into the Galileo’s USB host port, and use OpenCV to track and recognize objects.
  • V4L2Video4Linux2 is a video record and play utility for Linux. You’ll need a USB webcam attached to your Galileo to make use of this.

To boot the Galileo off the bigger Linux image, you’ll need an SD card that is at least 1GB (but less than 32GB). You’ll also need to download the bigger image from Intel’s Drivers page. The file is about 48 MB.

Download the linux image, extract it and copy the contents to your SD card.

Plug in the µSD card and then power it up. The first boot may take a little longer than average.

 

Connecting to Galileo via linux console



  • I would prefer to use ssh to login into Galileo. For that you need to connect your galileo as well as your host machine to the same network.
    • Get the ip address of Galileo using nmap/arp-scan tools in linux.
    • Once you get the ip address you can do ssh.
    • ssh <username>@<ip-address-of-galileo>
      
  • If you have serial console cable, you will be able to see everything including boot sequence.
  • There are many ways. Check this out.


Note:

  • The console UART port is different in Gen1 and Gen2. Please check this link.


Useful links: 

Galileo intial setup to run Arduino sketches

Powering the Galileo


Gen 1: 


  • The Galileo Gen1 should be powered through the barrel jack, using a regulated 5V DC power supply. 
  • After plug-in, just wait for 2 green LEDs to light up (ON and USB).
  • Connect the micro-USB cable to the Intel® Galileo.
  • Connect the other end to your computer.

Gen 2: 


  • The Galileo Gen2 should be powered through the barrel jack, using a 7-15V DC power supply.
  • After plug-in, just wait for 2 green LEDs to light up (ON and USB).
  • Connect the micro-USB cable to the Intel® Galileo.
  • Connect the other end to your computer.



Run the sketch (for linux)


IDE download and setup

  • Download the ide from here and extract the tar.gz file.
  • Go to extracted directory and run the arduino file
  • Open a terminal and run
  • ./arduino
    
  •  If everything is successful, Arduino IDE will be launched (you might need to install java as well to your host machine).


  • Power up the galileo, attach it to the host machine using micro-USB cable.
  • Open a terminal and type
  • ls /dev/ttyACM*
    
  • In IDE, click on Tools menu, select the board (Gen1, Gen2, Edison..) and serial port like /dev/ttyACM0 or /dev/ttyACM1.


  • If the serial port is disabled, you need to give some permission. So type
  • sudo chmod a+rw /dev/ttyACM*
    

Updating the firmware

Before trying to upload any sketch, first you must update the firmware.
  • To update the board firmware go to Help > Firmware Update. Then click Yes to proceed.
  • Make sure you don’t unplug either power or USB from the Galileo. The update procedure will take about five minutes.




As always, the first program to be uploaded to a board is the “Hello, world” of microcontrollers - Blink.
  • To open the Blink example, go to the File > Examples > 01.Basics > Blink.


  • Make sure the Serial Port and Board selections are still correct. Then click the Upload button.
After the upload completes, you should see a tiny, green LED blinking on and off every second. This LED is connected to pin 13 of the Galileo.


Intel Galileo Getting started


Intel Galileo is the first Arduino-certified development board based on Intel x86 architecture designed to be hardware and software pin-compatible with Arduino shields designed for the Arduino Uno R3. Digital pins, Analog inputs, the power header, ICSP header, and the UART port pins are all in the same locations as on the Arduino Uno R3. Galileo is a microcontroller board based on the Intel® Quark SoC X1000 Application Processor, a 32-bit Intel Pentium-class system on a chip (datasheet). Galileo has been designed for the makers, students, educators and DIY electronics enthusiasts.


Galileo Gen1
Galileo Gen2

Intel Galileo features the Intel Quark SoC X1000, 32-bit processor can run at up to 400MHz, and it has 512 KB SRAM built-in. The Galileo board supports the Quark with a wide range of external peripherals.

Galileo has 8MB Flash (to store firmware as well as sketch), an 11KB EEPROM (non-volatile memory), and a µSD slot (which supports up to 32GB). In addition to the memory, contains all sorts of peripherals: 10/100Mb Ethernet, USB 2.0 host and client ports, an RS-232 port, and a mini PCI Express (mPCIE) slot.

The Arduino pins – including six analog inputs, SPI, I2C, UART, and PWM outputs – are all exactly placed where an experienced Arduino user would expect them to be.

Galileo is designed to support shields that operate at either 3.3V or 5V. The core operating voltage of Galileo is 3.3V. However, a jumper on the board enables voltage translation to 5V at the I/O pins. This provides support for 5V Uno shields and is the default behavior. By switching the jumper position, the voltage translation can be disabled to provide 3.3V operation at the I/O pins.

Intel has developed an IDE which is exactly similar to Arduino Software Development Environment (IDE), write the sketch in your host machine, compile and transfer the binary to galileo over usb client port.



Useful links:



Fun with RGB LED

People often need home lighting control in their lives. These individuals can easily find relevant products which often use different meth...