{"id":22608,"date":"2017-10-26T08:00:25","date_gmt":"2017-10-26T15:00:25","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=22608"},"modified":"2021-06-10T16:16:06","modified_gmt":"2021-06-10T23:16:06","slug":"how-to-get-color-data-from-a-color-sensor","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/how-to-get-color-data-from-a-color-sensor\/","title":{"rendered":"How to Get Color Data from a Color Sensor"},"content":{"rendered":"<p>Last week we <a href=\"https:\/\/digilent.com\/blog\/new-product-introduction-pmod-color\/\">introduced<\/a> the Pmod COLOR, our newest sensor Pmod. The Pmod COLOR is a color light sensor, as the name suggests, that communicates the intensity of red, blue, green (RGB) and clear (non-filtered) light present over a simple I2C bus. It is designed for use at close range and is great for object sorting, <a href=\"http:\/\/ams.com\/eng\/content\/view\/download\/145158\">color temperature measurements<\/a> and <a href=\"http:\/\/ams.com\/eng\/content\/view\/download\/145161\">colorimetry<\/a> applications.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/10\/pmod-color-walkaround-1-1024x576.png\" \/><\/p>\n<p>For more information on how the hardware works, you can read the <a href=\"https:\/\/digilent.com\/blog\/new-product-introduction-pmod-color\/\">previous post<\/a> or visit the <a href=\"https:\/\/digilent.com\/reference\/pmod\/pmodcolor\/reference-manual\">Pmod COLOR reference manual<\/a>. Here we&#8217;ll focus on how to get it up and running in software.<\/p>\n<p><strong>Quick Start with the Pmod COLOR<\/strong><\/p>\n<p>Below you&#8217;ll find the set of commands necessary for acquiring data from the Pmod COLOR over its I2C bus.<\/p>\n<ol>\n<li class=\"level1\">\n<div class=\"li\">Power on the Pmod COLOR.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0x52); \/\/device ID 0x29 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod COLOR.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a command to maintain the pointer address OR&#8217;d with the Enable register (0x00)<\/p>\n<pre class=\"code\">I2CWrite(0xA0); \/\/Maintain the pointer address at the Enable register<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod COLOR.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Enable Address and enable the oscillators.<\/p>\n<pre class=\"code\">I2CWrite(0x01); \/\/0x01 enables the oscillators for the timers and ADC channels<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay at least 2.4 mS before starting a data collection initiation.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send the Enable Address and enable the ADCs for all 4 channels.<\/p>\n<pre class=\"code\">I2CWrite(0x02); \/\/0x02 enables the ADC channels<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod COLOR and then send a STOP condition.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Delay 2.4 ms for the ADCs preparing themselves for data measurement and at least 2.4 ms by default for the integration time during the data collection process.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Send a START condition and call the device ID with a write bit<\/p>\n<pre class=\"code\">I2CBegin(0x52); \/\/device ID 0x29 with a write (0) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod COLOR.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a command to auto-increment the address pointer OR&#8217;d with the first data register (0x14)<\/p>\n<pre class=\"code\">I2CWrite(0xB4); \/\/Auto-increment the pointer address starting at the Clear Data Low Byte register<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod COLOR<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Provide a RESTART condition and call the device ID with a read bit<\/p>\n<pre class=\"code\">I2CBegin(0x53); \/\/device ID 0x29 with a read (1) bit<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Wait to receive an ACK from the Pmod COLOR.<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">\n<p>Collect all 8 data bytes corresponding to the low and high data byte registers of the clear, red, green, and blue data, respectively, waiting to receive an ACK from the Pmod Color between each byte.<\/p>\n<pre class=\"code\">I2CReadMultiple(8); \/\/read in the 8 data registers taking advantage of the auto-incrementing pointer<\/pre>\n<\/div>\n<\/li>\n<li class=\"level1\">\n<div class=\"li\">Send a STOP condition.<\/div>\n<\/li>\n<\/ol>\n<p>If you&#8217;d like to see a complete program that implements the above steps, go to the Pmod COLOR <a href=\"https:\/\/digilent.com\/reference\/pmod\/pmodcolor\/start\">resource center<\/a>. Here you&#8217;ll find an example <a href=\"https:\/\/digilent.com\/reference\/lib\/exe\/fetch.php?tok=795835&amp;media=https%3A%2F%2Freference.blog.digilentinc.com%2Flearn%2Fsoftware%2Ftutorials%2Fdigilent-core-install%2Fstart\">Arduino<\/a> program as well as links to our <a href=\"https:\/\/digilent.com\/reference\/learn\/programmable-logic\/tutorials\/pmod-ips\/start\">Pmod IP core tutorial<\/a> for quick drag and drop use with Microblaze designs. In addition, one of our applications engineers created a demo on our new Digilent projects site, <a href=\"https:\/\/projects.blog.digilentinc.com\/\">projects.blog.digilentinc.com<\/a>, using the Pmod COLOR IP core and the Zybo board to <a href=\"https:\/\/projects.blog.digilentinc.com\/arthur-brown\/displaying-color-readings-with-the-pmod-color-and-python-ebd794\">display color reading using Python.\u00a0<\/a><\/p>\n<p>For any questions or comments, visit the <a href=\"https:\/\/forum.digilent.com\/\">Digilent Forum <\/a>or post in the comments section below!<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-22608 jlk' data-task='like' data-post_id='22608' data-nonce='39daa8319e' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-22608 lc'>0<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-22608 jlk' data-task='unlike' data-post_id='22608' data-nonce='39daa8319e' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-22608 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-22608 status align-left'>Be the 1st to vote.<\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Check out our quick start guide!<\/p>\n","protected":false},"author":26,"featured_media":22498,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,35,1563],"tags":[1662,104],"ppma_author":[4491],"class_list":["post-22608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-expansion-modules","category-fpga","category-guide","tag-fpga","tag-project-2"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/10\/pmod-color-walkaround.png","authors":[{"term_id":4491,"user_id":26,"is_guest":0,"slug":"talesab","display_name":"Talesa Bleything","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/4ebebd593afbf3d758e9127934708634ab09aeaa7fcfcf6151f4e9ceb9cf6d0e?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/22608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=22608"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/22608\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/22498"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=22608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=22608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=22608"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=22608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}