{"id":432,"date":"2013-11-03T17:06:03","date_gmt":"2013-11-03T16:06:03","guid":{"rendered":"http:\/\/eiseler.synology.me\/wordpress\/?p=432"},"modified":"2013-11-03T17:26:03","modified_gmt":"2013-11-03T16:26:03","slug":"just-a-short-test-of-the-grove-i2c-color-sensor","status":"publish","type":"post","link":"https:\/\/eiseler.de\/wordpress\/?p=432","title":{"rendered":"Just a short test of the Grove I2C Color Sensor"},"content":{"rendered":"<p>Just made a short test of the <a href=\"http:\/\/www.seeedstudio.com\/wiki\/Grove_-_I2C_Color_Sensor\">grove color sensor<\/a>. Tested some Lego. Red, green and blue works well as you can see, but didn&#8217;t manage to measure the difference between red, orange and yellow. Here is the short movie:<\/p>\n<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"584\" height=\"329\" src=\"https:\/\/www.youtube.com\/embed\/wJNKoKqLqFA?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en-US&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation\"><\/iframe><\/span><\/p>\n<p>And here the source:<\/p>\n<pre class=\"brush: c; gutter: false\">\/*\r\nGroove Color Sensor and DX LCD Shield\r\n\r\n http:\/\/www.arduino.cc\/en\/Tutorial\/LiquidCrystal\r\n *\/\r\n\r\n\/\/ include the library code:\r\n\r\n#include \r\n#include \r\n#define COLOR_SENSOR_ADDR  0x39\/\/the I2C address for the color sensor \r\n#define REG_CTL 0x80\r\n#define REG_TIMING 0x81\r\n#define REG_INT 0x82\r\n#define REG_INT_SOURCE 0x83\r\n#define REG_ID 0x84\r\n#define REG_GAIN 0x87\r\n#define REG_LOW_THRESH_LOW_BYTE 0x88\r\n#define REG_LOW_THRESH_HIGH_BYTE 0x89\r\n#define REG_HIGH_THRESH_LOW_BYTE 0x8A\r\n#define REG_HIGH_THRESH_HIGH_BYTE 0x8B\r\n#define REG_BLOCK_READ 0xCF\r\n#define REG_GREEN_LOW 0xD0\r\n#define REG_GREEN_HIGH 0xD1\r\n#define REG_RED_LOW 0xD2\r\n#define REG_RED_HIGH 0xD3\r\n#define REG_BLUE_LOW 0xD4\r\n#define REG_BLUE_HIGH 0xD5\r\n#define REG_CLEAR_LOW 0xD6\r\n#define REG_CLEAR_HIGH 0xD7\r\n#define CTL_DAT_INIITIATE 0x03\r\n#define CLR_INT 0xE0\r\n\/\/Timing Register\r\n#define SYNC_EDGE 0x40\r\n#define INTEG_MODE_FREE 0x00\r\n#define INTEG_MODE_MANUAL 0x10\r\n#define INTEG_MODE_SYN_SINGLE 0x20\r\n#define INTEG_MODE_SYN_MULTI 0x30\r\n\r\n#define INTEG_PARAM_PULSE_COUNT1 0x00\r\n#define INTEG_PARAM_PULSE_COUNT2 0x01\r\n#define INTEG_PARAM_PULSE_COUNT4 0x02\r\n#define INTEG_PARAM_PULSE_COUNT8 0x03\r\n\/\/Interrupt Control Register \r\n#define INTR_STOP 40\r\n#define INTR_DISABLE 0x00\r\n#define INTR_LEVEL 0x10\r\n#define INTR_PERSIST_EVERY 0x00\r\n#define INTR_PERSIST_SINGLE 0x01\r\n\/\/Interrupt Souce Register\r\n#define INT_SOURCE_GREEN 0x00\r\n#define INT_SOURCE_RED 0x01\r\n#define INT_SOURCE_BLUE 0x10\r\n#define INT_SOURCE_CLEAR 0x03\r\n\/\/Gain Register\r\n#define GAIN_1 0x00\r\n#define GAIN_4 0x10\r\n#define GAIN_16 0x20\r\n#define GANI_64 0x30\r\n#define PRESCALER_1 0x00\r\n#define PRESCALER_2 0x01\r\n#define PRESCALER_4 0x02\r\n#define PRESCALER_8 0x03\r\n#define PRESCALER_16 0x04\r\n#define PRESCALER_32 0x05\r\n#define PRESCALER_64 0x06\r\n\r\nint readingdata[20];\r\nint i,green,red,blue,clr,ctl;\r\ndouble X,Y,Z,x,y,z;\r\n\r\n#include \r\n\r\n\/\/ initialize the library with the numbers of the interface pins\r\n\/\/LiquidCrystal lcd(12, 11, 5, 4, 3, 2);\r\nLiquidCrystal lcd(8, 9, 4, 5, 6, 7);   \/\/DX Shield uses other pins\r\n\r\nvoid setup() {\r\n  \/\/ set up the LCD&#039;s number of columns and rows: \r\n  lcd.begin(16, 2);\r\n  \/\/ Print a message to the LCD.\r\n  lcd.print(&quot;hello, world!&quot;);\r\n  Wire.begin(); \/\/ join i2c bus (address optional for master)\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ set the cursor to column 0, line 1\r\n  \/\/ (note: line 1 is the second row, since counting begins with 0):\r\n  lcd.setCursor(0, 0);\r\n  lcd.print(millis()\/1000);\r\n\r\n  setTimingReg(INTEG_MODE_FREE);\/\/Set trigger mode.Including free mode,manually mode,single synchronizition mode or so.\r\n  setInterruptSourceReg(INT_SOURCE_GREEN); \/\/Set interrupt source \r\n  setInterruptControlReg(INTR_LEVEL|INTR_PERSIST_EVERY);\/\/Set interrupt mode\r\n  setGain(GAIN_1|PRESCALER_4);\/\/Set gain value and prescaler value\r\n  setEnableADC();\/\/Start ADC of the color sensor\r\n  while(1)\r\n { \r\n  lcd.setCursor(0, 0);\r\n  lcd.print(&quot;             &quot;);\r\n  lcd.setCursor(0, 0);\r\n  lcd.print(millis()\/1000);\r\n\r\n   readRGB();\r\n   calculateCoordinate();\r\n\r\n  lcd.setCursor(0, 1);\r\n  lcd.print(&quot;                &quot;);  \r\n\r\n  if (x&lt;0.25) {\r\n   \/\/blue \r\n  lcd.setCursor(0, 1);\r\n  lcd.print(&quot;blau&quot;);\r\n  }\r\n  if (x&gt;0.25 &amp;&amp; x&lt;0.36) {\r\n   \/\/blue \r\n  lcd.setCursor(0, 1);\r\n  lcd.print(&quot;gruen&quot;);\r\n  }\r\n\r\n  if (x&gt;=0.36 ) {\r\n   \/\/blue \r\n  lcd.setCursor(0, 1);\r\n  lcd.print(&quot;rot&quot;);\r\n  }\r\n\r\n   delay(1000);\r\n   clearInterrupt();  \r\n }\r\n}\r\n\r\n\/************************************\/\r\nvoid setTimingReg(int x)\r\n{\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(REG_TIMING);\r\n   Wire.write(x);\r\n   Wire.endTransmission();  \r\n   delay(100); \r\n}\r\nvoid setInterruptSourceReg(int x)\r\n{\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(REG_INT_SOURCE);\r\n   Wire.write(x);\r\n   Wire.endTransmission();  \r\n   delay(100);\r\n}\r\nvoid setInterruptControlReg(int x)\r\n{\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(REG_INT);\r\n   Wire.write(x);\r\n   Wire.endTransmission();  \r\n   delay(100);\r\n}\r\nvoid setGain(int x)\r\n{\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(REG_GAIN);\r\n   Wire.write(x);\r\n   Wire.endTransmission();\r\n}\r\nvoid setEnableADC()\r\n{\r\n\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(REG_CTL);\r\n   Wire.write(CTL_DAT_INIITIATE);\r\n   Wire.endTransmission();  \r\n   delay(100);  \r\n}\r\nvoid clearInterrupt()\r\n{\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(CLR_INT);\r\n   Wire.endTransmission(); \r\n}\r\nvoid readRGB()\r\n{\r\n  Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.write(REG_BLOCK_READ);\r\n   Wire.endTransmission();\r\n\r\n   Wire.beginTransmission(COLOR_SENSOR_ADDR);\r\n   Wire.requestFrom(COLOR_SENSOR_ADDR,8);\r\n   delay(500);\r\n   if(8&lt;= Wire.available())    \/\/ if two bytes were received \r\n  { \r\n    for(i=0;i&lt;8;i++)\r\n    {\r\n      readingdata[i]=Wire.read();\r\n      \/\/Serial.println(readingdata[i],BIN);\r\n     }\r\n  }\r\n  green=readingdata[1]*256+readingdata[0];\r\n  red=readingdata[3]*256+readingdata[2];\r\n  blue=readingdata[5]*256+readingdata[4];\r\n  clr=readingdata[7]*256+readingdata[6];\r\n\r\n}\r\n\r\nvoid calculateCoordinate()\r\n{\r\n  X=(-0.14282)*red+(1.54924)*green+(-0.95641)*blue;\r\n  Y=(-0.32466)*red+(1.57837)*green+(-0.73191)*blue;\r\n  Z=(-0.68202)*red+(0.77073)*green+(0.56332)*blue;\r\n  x=X\/(X+Y+Z);\r\n  y=Y\/(X+Y+Z);\r\n  if((X&gt;0)&amp;&amp;(Y&gt;0)&amp;&amp;(Z&gt;0))\r\n  {\r\n    \/*\r\n    Serial.println(&quot;The x,y value is&quot;);\r\n\tSerial.print(&quot;(&quot;);\r\n    Serial.print(x,2);\r\n\tSerial.print(&quot; , &quot;);\r\n    Serial.print(y,2);\r\n\tSerial.println(&quot;)&quot;);\r\n\tSerial.println(&quot;Please reference the figure(Chromaticity Diagram) in the wiki &quot;);\r\n  \tSerial.println(&quot;so as to get the recommended color.&quot;);\r\n  *\/\r\n    lcd.setCursor(4, 0);\r\n  lcd.print(x);\r\n  lcd.setCursor(10, 0);\r\n  lcd.print(y);\r\n\r\n  }\r\n else\r\n {\r\n \/\/Serial.println(&quot;Error,the value overflow&quot;);\r\n  lcd.setCursor(4, 0);\r\n  lcd.print(&quot;Error&quot;);\r\n\r\n }\r\n}<\/pre>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-432\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-432\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-432\" class=\"share-linkedin sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\"><span>LinkedIn<\/span><\/a><\/li><li class=\"share-pocket\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-pocket sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=pocket\" target=\"_blank\" title=\"Click to share on Pocket\"><span>Pocket<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Just made a short test of the grove color sensor. Tested some Lego. Red, green and blue works well as you can see, but didn&#8217;t manage to measure the difference between red, orange and yellow. Here is the short movie: &hellip; <a href=\"https:\/\/eiseler.de\/wordpress\/?p=432\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n<div class=\"sharedaddy sd-sharing-enabled\"><div class=\"robots-nocontent sd-block sd-social sd-social-icon-text sd-sharing\"><h3 class=\"sd-title\">Share this:<\/h3><div class=\"sd-content\"><ul><li class=\"share-facebook\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-facebook-432\" class=\"share-facebook sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=facebook\" target=\"_blank\" title=\"Click to share on Facebook\"><span>Facebook<\/span><\/a><\/li><li class=\"share-twitter\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-twitter-432\" class=\"share-twitter sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=twitter\" target=\"_blank\" title=\"Click to share on Twitter\"><span>Twitter<\/span><\/a><\/li><li class=\"share-linkedin\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"sharing-linkedin-432\" class=\"share-linkedin sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=linkedin\" target=\"_blank\" title=\"Click to share on LinkedIn\"><span>LinkedIn<\/span><\/a><\/li><li class=\"share-pocket\"><a rel=\"nofollow noopener noreferrer\" data-shared=\"\" class=\"share-pocket sd-button share-icon\" href=\"https:\/\/eiseler.de\/wordpress\/?p=432&amp;share=pocket\" target=\"_blank\" title=\"Click to share on Pocket\"><span>Pocket<\/span><\/a><\/li><li class=\"share-end\"><\/li><\/ul><\/div><\/div><\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[6],"tags":[],"class_list":["post-432","post","type-post","status-publish","format-standard","hentry","category-arduino"],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8zAuQ-6Y","jetpack-related-posts":[{"id":1036,"url":"https:\/\/eiseler.de\/wordpress\/?p=1036","url_meta":{"origin":432,"position":0},"title":"Connect Raspberry Pi & Arduino USB bidirectional","date":"25\/10\/2018","format":false,"excerpt":"How to connect an Arduino to a raspberry pi via USB bidirectional. The raspberry reads all from the serial and prints it. Next it reads a textile from a webpage and sends the text (one word) to serial, next a random car to the Arduino. Arduino got a LCD attached\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1049,"url":"https:\/\/eiseler.de\/wordpress\/?p=1049","url_meta":{"origin":432,"position":1},"title":"Arduino mirror image, orientation problem with display MAX7219","date":"13\/11\/2018","format":false,"excerpt":"How to use MAX7219 LED Matrix with Arduino https:\/\/youtu.be\/eAqVJXKpj8I Good Libraries to use with the MAX7219 LED are: https:\/\/github.com\/MajicDesigns\/MD_MAX72XX LED https:\/\/github.com\/MajicDesigns\/MD_Parola Scrolling You'll find lot's of examples after you install the libraries in the Arduino IDE. Arduino mirror image, orientation problem with display MAX7219 How to solve problem with the\u2026","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/eiseler.de\/wordpress\/wp-content\/uploads\/2018\/11\/img_8469.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":437,"url":"https:\/\/eiseler.de\/wordpress\/?p=437","url_meta":{"origin":432,"position":2},"title":"Grove Tick Tock Shield Kit","date":"04\/11\/2013","format":false,"excerpt":"Giving the Tick Tock Shield Kit by Grove a try, I made same changes to the real time clock code. First I wanted to automaticaly change the brightness not only at the start of the code. And second I wanted the date to displayed to. Now it displays alternately with\u2026","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":417,"url":"https:\/\/eiseler.de\/wordpress\/?p=417","url_meta":{"origin":432,"position":3},"title":"Arduino controlling Lego 4x4 (Powerfunctions IR)","date":"29\/10\/2013","format":false,"excerpt":"For the evenings at late summer holidays on a small island in the German north sea I bought a Lego 4x4 Offroader to build with the kids. The truck has 4x4 driving and steering, and is controlled by an ir remote. Coming home with the built truck\u00a0 I was curious\u2026","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"https:\/\/i2.wp.com\/eiseler.de\/wordpress\/wp-content\/uploads\/2013\/10\/IMG_5563-225x300.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1038,"url":"https:\/\/eiseler.de\/wordpress\/?p=1038","url_meta":{"origin":432,"position":4},"title":"Raspberry pi & waveshare 2.7 e-ink Display & python","date":"11\/11\/2018","format":false,"excerpt":"Start with a headless raspberry, no need to connect monitor, keyboard:\u00a0https:\/\/raspberrypi.stackexchange.com\/questions\/10251\/prepare-sd-card-for-wifi-on-headless-pi Find the raspberry in your router and connect with ssh. Useullay steps are: sudo raspi-config sudo reboot (neu einloggen) sudo apt-get update -y sudo apt-get upgrade -y Here's some example python code for drawing text horizontal on the waveshare\u2026","rel":"","context":"In &quot;Hardware&quot;","img":{"alt_text":"","src":"https:\/\/i2.wp.com\/eiseler.de\/wordpress\/wp-content\/uploads\/2018\/11\/img_8466-e1541953811554.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1066,"url":"https:\/\/eiseler.de\/wordpress\/?p=1066","url_meta":{"origin":432,"position":5},"title":"Open Roberta Lab - Beispiele - Examples","date":"20\/11\/2018","format":false,"excerpt":"Als Anregung einige Beispiele f\u00fcr Open Roberta. Der Line follower als Beispiel: Hindernis Erkennung: Stichworte: Linie verfolgen, Beispiel, Farbsensor, color sensor, line","rel":"","context":"In &quot;Arduino&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/eiseler.de\/wordpress\/wp-content\/uploads\/2018\/11\/2018-11-20-15_57_53-Open-Roberta-Lab.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=432"}],"version-history":[{"count":4,"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/432\/revisions"}],"predecessor-version":[{"id":435,"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/432\/revisions\/435"}],"wp:attachment":[{"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eiseler.de\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}