element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Sensors
  • Technologies
  • More
Sensors
Blog ROHM Ambient Light and Proximity Sensor RPR-0521RS
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Sensors to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 30 Nov 2018 6:35 PM Date Created
  • Views 2202 views
  • Likes 7 likes
  • Comments 4 comments
  • RoadTest
  • rohm
  • road_test
  • hercules
Related
Recommended

ROHM Ambient Light and Proximity Sensor RPR-0521RS

Jan Cumps
Jan Cumps
30 Nov 2018

I'm Road Testing the Rohm SensorShield-EVK-003 (Arduino Compatible) and the sensors that come with it.

In this post, the Ambient Light and Proximity Sensor RPR-0521RSRPR-0521RS.

image

 

The Sensor Shield ecosystemSensor Shield ecosystem is ROHM's test bed for their sensors. It's an Arduino form shield with a number of slots.

The small evaluation boards for their sensors plug into that board.

For each of the sensors, there's an example sketch available.

For this blog post, I'm testing the Ambient Light and Proximity Sensor that comes with the kit.

 

From now on, my blogs on the SensorShield and the ROHM sensors is different.

The first reviews were focusing on the Road Test. I've submitted my review, so now I have my hands free to focus on different aspects.

This time, i capture the i2c traffic and analyse it, because I want to use the sensor with another micocontroller.

 

For the performance of the sensor, please check the reviews of my fellow road testers.

I can confirm that my sensor performed according to the specs.

 

Arduino Example

 

The ROHM example first fires a few questions to the sensor, to verify its identity.

Then it loops and collects data continuously. The output is logged to the monitor.

image

You can see the start of the communication in the image below - this is the initial setup part of the sensor.

At the end of the post I've added a sequence that also shows measurements.

 

image

image: the very first i2c exchanges between Arduino and sensor

 

i2c Initialisation

 

ROHM has provided a good example on how to validate the hardware before talking.

The initialisation code checks the manufacturer and device id. It also checks if the device behaves as expected.

 

  rc = read(RPR0521RS_SYSTEM_CONTROL, &reg, sizeof(reg));
  if (rc != 0) {
    Serial.println(F("Can't access RPR0521RS"));
    return (rc);
  }
  reg &= 0x3F;
  Serial.print(F("RPR0521RS Part ID Register Value = 0x"));
  Serial.println(reg, HEX);

  if (reg != RPR0521RS_PART_ID_VAL) {
    Serial.println(F("Can't find RPR0521RS"));
    return (rc);
  }

  rc = read(RPR0521RS_MANUFACT_ID, &reg, sizeof(reg));
  if (rc != 0) {
    Serial.println(F("Can't access RPR0521RS"));
    return (rc);
  }
  Serial.print(F("RPR0521RS MANUFACT_ID Register Value = 0x"));
  Serial.println(reg, HEX);

  if (reg != RPR0521RS_MANUFACT_ID_VAL) {
    Serial.println(F("Can't find RPR0521RS"));
    return (rc);
  }

  reg = RPR0521RS_ALS_PS_CONTROL_VAL;
  rc = write(RPR0521RS_ALS_PS_CONTROL, &reg, sizeof(reg));
  if (rc != 0) {
    Serial.println(F("Can't write RPR0521RS ALS_PS_CONTROL register"));
    return (rc);
  }

  rc = read(RPR0521RS_PS_CONTROL, &reg, sizeof(reg));
  if (rc != 0) {
    Serial.println(F("Can't read RPR0521RS PS_CONTROL register"));
    return (rc);
  }

  reg |= RPR0521RS_PS_CONTROL_VAL;
  rc = write(RPR0521RS_PS_CONTROL, &reg, sizeof(reg));
  if (rc != 0) {
    Serial.println(F("Can't write RPR0521RS PS_CONTROL register"));
  }

  reg = RPR0521RS_MODE_CONTROL_VAL;
  rc = write(RPR0521RS_MODE_CONTROL, &reg, sizeof(reg));
  if (rc != 0) {
    Serial.println(F("Can't write RPR0521RS MODE CONTROL register"));
    return (rc);
  }

 

 

Then it sets the configuration.

 

  unsigned char index;
  unsigned char als_gain_table[] = {1, 2, 64, 128};
  unsigned short als_meas_time_table[] = {0,0,0,0,0,100,100,100,100,100,400,400,50,0,0,0};

// ...

  reg = RPR0521RS_ALS_PS_CONTROL_VAL;
  index = (reg >> 4) & 0x03;
  _als_data0_gain = als_gain_table[index];
  index = (reg >> 2) & 0x03;
  _als_data1_gain = als_gain_table[index];


  index = RPR0521RS_MODE_CONTROL_VAL & 0x0F;
  _als_measure_time = als_meas_time_table[index];

 

From then on, the firmware queries the sensor.

 

i2c Traffic

 

It's easier to write firmware for a new controller if you have runtime captures of a working design.

That's one of the values of the ROHM SensorShield and code examples.

You have a working example up in no time and you can analyse its behaviour.

That's what you see below. The full init and setup sequence, and then a few data sample cycles.

From Index 57 on, the firmware queries data. Everything before that is setup.

 

I2C Analysis results


30 november 2018
Bus configuration
SDAChannel 0
SCLChannel 1
Statistics
Decoded bytes39
Detected bus errors0
IndexTimeHexBinDecASCII
0500,00 nsSTART
15,50 μs0x700b01110000112p
295,00 μsACK
3100,00 μs0x400b0100000064@
4190,50 μsACK
5210,00 μsSTART
6215,00 μs0x710b01110001113q
7301,00 μsACK
8306,00 μs0x0a0b0000101010
9395,50 μsNACK
10416,00 μsSTOP
11756,50 μsSTART
12761,50 μs0x700b01110000112p
13851,00 μsACK
14856,50 μs0x920b10010010146’
15946,50 μsACK
16966,50 μsSTART
17971,50 μs0x710b01110001113q
181,06 msACK
191,06 ms0xe00b11100000224à
201,15 msNACK
211,17 msSTOP
2221,28 msSTART
2321,29 ms0x700b01110000112p
2421,38 msACK
2521,38 ms0x420b0100001066B
2621,47 msACK
2721,48 ms0x020b000000102
2821,57 msACK
2921,59 msSTOP
3021,60 msSTART
3121,61 ms0x700b01110000112p
3221,70 msACK
3321,70 ms0x430b0100001167C
3421,79 msACK
3521,81 msSTART
3621,82 ms0x710b01110001113q
3721,90 msACK
3821,91 ms0x010b000000011
3922,00 msNACK
4022,02 msSTOP
4122,05 msSTART
4222,05 ms0x700b01110000112p
4322,14 msACK
4422,15 ms0x430b0100001167C
4522,24 msACK
4622,24 ms0x010b000000011
4722,33 msACK
4822,35 msSTOP
4922,38 msSTART
5022,38 ms0x700b01110000112p
5122,47 msACK
5222,48 ms0x410b0100000165A
5322,57 msACK
5422,57 ms0xc60b11000110198Æ
5522,66 msACK
5622,68 msSTOP
5722,70 msSTART
5822,71 ms0x700b01110000112p
5922,80 msACK
6022,80 ms0x440b0100010068D
6122,89 msACK
6222,91 msSTART
6322,92 ms0x710b01110001113q
6423,00 msACK
6523,01 ms0x000b000000000
6623,10 msACK
6723,10 ms0x000b000000000
6823,19 msACK
6923,20 ms0x000b000000000
7023,29 msACK
7123,29 ms0x000b000000000
7223,38 msACK
7323,39 ms0x000b000000000
7423,48 msACK
7523,48 ms0x000b000000000
7623,57 msNACK
7723,59 msSTOP
78611,13 msSTART
79611,14 ms0x700b01110000112p
80611,23 msACK
81611,23 ms0x440b0100010068D
82611,32 msACK
83611,34 msSTART
84611,35 ms0x710b01110001113q
85611,43 msACK
86611,44 ms0x000b000000000
87611,53 msACK
88611,53 ms0x000b000000000
89611,62 msACK
90611,63 ms0x5a0b0101101090Z
91611,72 msACK
92611,72 ms0x000b000000000
93611,81 msACK
94611,82 ms0x0e0b0000111014
95611,91 msACK
96611,91 ms0x000b000000000
97612,01 msNACK
98612,03 msSTOP

 

This data, with the source code that's available from ROHM, is a big help to get the sensor working in a different setup.

 

Related blog
ROHM Temperature Sensor BD1020HFV
ROHM Magnetometer Sensor BM1422AGMV
ROHM Hall Sensor BD7411G
ROHM Colour Sensor BH1749NUC
ROHM Colour Sensor BH1749NUC - part 2: Other Firmware Libraries
ROHM Ambient Light and Proximity Sensor RPR-0521RS
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 6 years ago in reply to fmilburn +2
    fmilburn wrote: ... ...Separately, I am curious how you generated the nicely formatted table labeled I2C Analysis Results. ... My logic analyser can decode i2c and write the result as a HTML file. I put…
  • DAB
    DAB over 6 years ago +1
    Nice update Jan. DAB
  • fmilburn
    fmilburn over 6 years ago +1
    Hi Jan, I agree completely on the value of ROHM providing modules and code that allow a quick start. Separately, I am curious how you generated the nicely formatted table labeled I2C Analysis Results.…
  • Jan Cumps
    Jan Cumps over 6 years ago in reply to fmilburn

    fmilburn  wrote:

     

    ...

    ...Separately, I am curious how you generated the nicely formatted table labeled I2C Analysis Results. 

    ...

    My logic analyser can decode i2c and write the result as a HTML file. I put the element14 editor in HTML mode and copy/pasted the source into the blog.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 6 years ago

    Another nice write-up on these sensors. Well done!

    Gene

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 6 years ago

    Hi Jan,

    I agree completely on the value of ROHM providing modules and code that allow a quick start.  Separately, I am curious how you generated the nicely formatted table labeled I2C Analysis Results. 

    Frank

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 6 years ago

    Nice update Jan.

     

    DAB

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube