Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino + 2 I2C with VNCL4000 Proximity Sensor

i2c proximity sensor netduino plus 2

  • Please log in to reply
6 replies to this topic

#1 pajama

pajama

    New Member

  • Members
  • Pip
  • 4 posts

Posted 14 April 2015 - 12:18 AM

Dear Netduino Community,

I'm having a hard time writing this I2C driver. I've looked through a number of tutorials/examples, but everything I try always throws a System.ArgumentException, without much information.

 

I'm trying to get this little proximity/ambient light sensor up and running with a Netduino Plus 2:

http://www.adafruit....ts/vcnl4000.pdf

 

The important bit in that data sheet is probably the example application:

Addressing:command: 26h, 85h (VCNL4000_I2C_Bus_Write_Adr., Ambient Light Result Register #5 [85]) Read register #5:command: 27h, data (VCNL4000_I2C_Bus_Read_Adr., {High Byte Data of Ambient Light Result Register #5 [85])} Read register #6:command: 27h, data (VCNL4000_I2C_Bus_Read_Adr., {Low Byte Data of Ambient Light Result Register #6 [86])}

 

 

I can't find any other netduino I2C examples that are remotely similar. I would really appreciate any advice! Maybe if someone can help me figure out the most basic example of reading command register #1 (product ID), that would give me a huge step in the right direction. 

 

I've attached a VS project if anyone cares to check it out.

 

Thank you for your time!

Attached Files



#2 scardinale

scardinale

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationNew York, USA

Posted 16 April 2015 - 02:05 PM

@pajama

 

A couple of things that might be causing your difficulties:

  • You are using a 8-bit I2C address in your code. (0x27) and it needs to be a 7-bit address (0x13).
  • Your I2C clock is set too high. I do not think that the Net Micro Framework supports clock at 3400. Try setting your clock to 100 and then (if successful) try a higher clock (400).


#3 pajama

pajama

    New Member

  • Members
  • Pip
  • 4 posts

Posted 16 April 2015 - 09:30 PM

 

  • You are using a 8-bit I2C address in your code. (0x27) and it needs to be a 7-bit address (0x13).
  • Your I2C clock is set too high. I do not think that the Net Micro Framework supports clock at 3400. Try setting your clock to 100 and then (if successful) try a higher clock (400).

 

 

Thank you for the reply! I changed the values above. Still throwing an exception here:

 

 if (transferred != writeBuffer.Length)
                    throw new Exception("Could not write to device.");

 

 

Any ideas?



#4 scardinale

scardinale

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationNew York, USA

Posted 17 April 2015 - 01:17 AM

I would try using the WriteRegister and ReadRegister methods rather than the generic Write and Read methods.



#5 pajama

pajama

    New Member

  • Members
  • Pip
  • 4 posts

Posted 17 April 2015 - 08:10 PM

I would try using the WriteRegister and ReadRegister methods rather than the generic Write and Read methods.

 

Thank you for the suggestion.

Here's what I'm doing, still getting the same error. Should my writebuffer be a different size?

 public byte ReadVersion()
        {
            // write register address
            byte[] writeBuffer = new byte[1];
            I2CBus.GetInstance().WriteRegister(_slaveConfiguration, (byte)CommandRegisters.ProductId, writeBuffer, TransactionTimeout);

            // get the byte result
            byte[] data = new byte[1];
            I2CBus.GetInstance().ReadRegister(_slaveConfiguration, (byte)CommandRegisters.ProductId, data,TransactionTimeout);
            //force the convertion to a signed byte
            return data[0];
        }


#6 pajama

pajama

    New Member

  • Members
  • Pip
  • 4 posts

Posted 17 April 2015 - 08:15 PM

_slaveDevice.Execute(writeXAction, transactionTimeout) is returning 0



#7 scardinale

scardinale

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationNew York, USA

Posted 17 April 2015 - 08:43 PM

@pajama, did you get the PM that I sent to you?

 

I would drop the first WriteRegister call and only use the ReadRegister call.







Also tagged with one or more of these keywords: i2c, proximity sensor, netduino plus 2

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.