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

I2C Where do I start


  • Please log in to reply
10 replies to this topic

#1 tax

tax

    New Member

  • Members
  • Pip
  • 1 posts

Posted 19 January 2011 - 03:58 PM

Hi Guys, I need to pickup data from a I2C device vith the Netduino as Master. I cant seem to find any examples. Do you know any or could you give me a pointer on where to start? Im pretty new in this .NET micro framework, so Im suer im making all the Noob mistakes. I have found snippets online, but I have not been able to use them due to missing includes. Kind regards Tax

#2 phantomtypist

phantomtypist

    Advanced Member

  • Members
  • PipPipPip
  • 142 posts
  • LocationNew York, NY

Posted 19 January 2011 - 09:03 PM

Take a look at my code for the I2CBus implemented in the singleton pattern (because you can only have one instance of I2CDevice)

After that, take a look at a driver I wrote for the Bosch BMP085 temperature and pressure sensor.

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 20 January 2011 - 05:09 AM

Im pretty new in this .NET micro framework, so Im suer im making all the Noob mistakes. I have found snippets online, but I have not been able to use them due to missing includes.


Hi Tax,

Welcome to the Netduino community.

If you can share the code snippets you're trying and the errors you're getting (missing includes/references), I'm sure somebody would be happy to help point you in the right direction...

Chris

#4 Ryan Mick

Ryan Mick

    Advanced Member

  • Members
  • PipPipPip
  • 36 posts
  • LocationSacramento, CA

Posted 21 January 2011 - 04:28 PM

It would be nice if there was a beginners tutorial on using I2C with the Netduino. Not just the code but connecting multiple devices to the bus. I know your suppose to use pull up resistors but I can't find any information on when to use them what type or how often. But a short and sweet tutorial would be great to answer these type of question us beginners have. And it would have the added benefit of being easily found.

#5 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 11 April 2011 - 10:52 PM

It would be nice if there was a beginners tutorial on using I2C with the Netduino. Not just the code but connecting multiple devices to the bus. I know your suppose to use pull up resistors but I can't find any information on when to use them what type or how often. But a short and sweet tutorial would be great to answer these type of question us beginners have. And it would have the added benefit of being easily found.

I agree ! Beginners Tutorial Please :)
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#6 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 12 April 2011 - 06:34 AM

I know your suppose to use pull up resistors but I can't find any information on when to use them what type or how often.

There need to be two pull-up resistors connected between I2C signal lines (TWCK, TWD) and positive voltage (+5V or +3.3V depending on the devices connected). The value can vary from ~1.5 kΩ up to ~47 kΩ, 2.2 kΩ or 10 kΩ will work fine. The exact value would have to be calculated based on the bus characteristics, i.e. capacitance, number of devices connected, speed etc.

#7 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 12 April 2011 - 12:21 PM

There need to be two pull-up resistors connected between I2C signal lines (TWCK, TWD) and positive voltage (+5V or +3.3V depending on the devices connected). The value can vary from ~1.5 kΩ up to ~47 kΩ, 2.2 kΩ or 10 kΩ will work fine. The exact value would have to be calculated based on the bus characteristics, i.e. capacitance, number of devices connected, speed etc.

And if I see only SCL and SDA ... no TWCK nor TWD ... This is why we need a tutorial ... with some diagram using a netduino and some sensors (ex: Accelerometer ADXL345, Magnetometer HMC5843 and Gyroscope ITG3200). Real example with real sensors ...

I do understand that hardware is hard (pun intended) ... please help the newbies like me with some tutorials with real things connected, not just LEDs :) I am willing to help but I need input ... hard input !

Mike who wants to play with sensors without burning them !
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#8 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 12 April 2011 - 12:31 PM

And if I see only SCL and SDA ... no TWCK nor TWD ...

I2C Clock = SCL = TWCK
I2C Data = SDA = TWD

'TW' is used in Netduino schematic and Fritzing parts, because it is based on Atmel microcontroller and Atmel calls its I2C implementation "Two-Wire Interface", TWI for short. Sorry for the confusion.

#9 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 12 April 2011 - 12:41 PM

Sorry for the confusion.

LOL It made my point clear though ! LOL

Did I understand correctly, you ALWAYS need pullup resistors ? or only when there is more than one sensor connected to it ? And using a I2CBus class to encapsulate all this would be nice to have (to clean up the code) ?
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !

#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 12 April 2011 - 01:06 PM

Did I understand correctly, you ALWAYS need pullup resistors ?

Yes - technically, you'd need to ensure the I2C signal lines are HIGH, when the bus is free - you can use either a current source or pull-up resistor connected to the positive supply voltage. Pull-up resistors are "easier".

or only when there is more than one sensor connected to it ?

The pull-up resistors should be present always. However, some sensors/devices may have those built-in (e.g. Sparkfun breakout boards).

And using a I2CBus class to encapsulate all this would be nice to have (to clean up the code) ?

I am not sure I understand that - what do you mean by 'encapsulate all this'? As far as I know I2CBus class is used to overcome limitation in the current .NET Micro Framework I2C implementation that does not directly support multiple devices on the same bus (i.e. it is not possible to instantiate second I2CDevice, because it tries to reserve pins that have been already exclusively reserved by the first instance).

#11 Michel Trahan

Michel Trahan

    Advanced Member

  • Members
  • PipPipPip
  • 155 posts

Posted 12 April 2011 - 01:17 PM

However, some sensors/devices may have those built-in (e.g. Sparkfun breakout boards).

Boy do we need a tutorial LOL

what do you mean by 'encapsulate all this'?

Sorry, my lack of knowledge ... I didn't know why it was created ! Thanks !
Started with C in 1985, moved to Vb3 ... to vb6 and stopped. Now started with .Net and learning C# and VB.net and wishing VB.net was on MF !




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.