13
9/30/09 11:04 AM Near Future Laboratory » Blog Archive » Arduino and the Two-Wire Int…A Short Didactic Parenthetical On Making TWI Work On An Arduino Mini Page 1 of 13 http://www.nearfuturelaboratory.com/2007/01/11/arduino-and-twi/ Arduino and the Two-Wire Interface (TWI/I2C) Including A Short Didactic Parenthetical On Making TWI Work On An Arduino Mini I have been using the Arduino and Atmel microcontroller’s generally using the SPI (serial-peripheral interface), but decided to look at the two-wire (a.k.a. I2C) interface as well. I’m doing this partially because it would be good to know how it works, but also because it’s electrically more compact. It only uses two- wires, rather than the four required for SPI, so schematic designs and board layouts become a bit more manageable. The trade-off is a little bit more complicated protocols semantics, but nothing out of control. (I’m also looking at using a two-axis accelerometer that’s much less expensive than the three-axis one I’ve been using – $4 versus $15. For some experiments, two-axes may be perfectly fine, and I’m happy to save the $11.) The first step was making sure the Arduino would handle the TWI – there’s pretty much no reason it shouldn’t, because the Atmega8 certainly handles it. So, the next step was finding out how best to handle TWI transactions. To do this, I consulted the Atmega8 specification sheet, which has a pretty thorough explanation of the protocol and the implementation details on the Atmega8. (There are also a couple of useful application notes available here and here.) It’s so thorough that I had to print it out. I got a pretty good understanding of how it works but before I started coding, I noticed that there were some TWI libraries both in avrlibc and in the “Wire” library in Wiring.org happens to be packaged as a “sanctioned” external library for Arduino, so that was pretty much that. Nicholas Zambetti, who wrote the Wire library, pretty much told me it should work with no problems, and he was pretty much right. No problems. His library abstracts the TWI innards really nicely, so I don’t have to muck with any Atmega registers or anything of that sort.

Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 1 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Arduino and the Two-Wire Interface (TWII2C)Including A Short Didactic Parenthetical OnMaking TWI Work On An Arduino Mini

I have been using the Arduino and Atmel microcontrollerrsquos generally using the SPI (serial-peripheralinterface) but decided to look at the two-wire (aka I2C) interface as well Irsquom doing this partially becauseit would be good to know how it works but also because itrsquos electrically more compact It only uses two-wires rather than the four required for SPI so schematic designs and board layouts become a bit moremanageable The trade-off is a little bit more complicated protocols semantics but nothing out of control(Irsquom also looking at using a two-axis accelerometer thatrsquos much less expensive than the three-axis one Irsquovebeen using ndash $4 versus $15 For some experiments two-axes may be perfectly fine and Irsquom happy to savethe $11)

The first step was making sure the Arduino would handle the TWI ndash therersquos pretty much no reason itshouldnrsquot because the Atmega8 certainly handles it So the next step was finding out how best to handleTWI transactions

To do this I consulted the Atmega8 specification sheet which has a pretty thorough explanation of theprotocol and the implementation details on the Atmega8 (There are also a couple of useful application notesavailable here and here) Itrsquos so thorough that I had to print it out I got a pretty good understanding of howit works but before I started coding I noticed that there were some TWI libraries both in avrlibc and in theldquoWirerdquo library in Wiringorg happens to be packaged as a ldquosanctionedrdquo external library for Arduino so thatwas pretty much that

Nicholas Zambetti who wrote the Wire library pretty much told me it should work with no problems andhe was pretty much right No problems His library abstracts the TWI innards really nicely so I donrsquot haveto muck with any Atmega registers or anything of that sort

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 2 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

I hooked up my Arduino to a handy accelerometer for testing (Irsquom still using the expensive LIS3LV02DQ)Analog In 4 goes to SDA and Analog In 5 goes to SCL I have pull-up resistors on those lines but Nicolasexplains that his library enables the internal pull-ups on the Atmega so I can probably pull those from mybreadboard Either way itrsquos working just fine even with the external pull-up resistors (Irsquom using 47kresistors)

(I also found in one weird situation that I had to explicitly clear the clock prescaler to get the UARTfunctioning properly This was while getting TWI working on an AT90USB1287 ndash TWI worked fine butthe UART was spitting out garbage On chips where the clock prescaler can be set through the fuses itrsquosimportant to verify that the prescaler isnrsquot hard wired to divide the clock Thisrsquoll cause anything that isdependent on timing to potentially be off kilter In my case the UART was expecting an 8MHz clock todetermine timing and baud rate but the clock was being divided in hardware ndash not even in the firmware)

WireTWI (I2C) on the Arduino Mini

Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share a name theydonrsquot share the same processor The Arduino Mini uses an ATmega168 while the Arduinonormal uses anATmega8 Yoursquoll need to recompilere-rdquoverifyrdquo the Wire library files in order to get TWI to work on theATmega168Arduino Mini Therersquos a thing or two yoursquoll have to do by hand to get this to work and yoursquollneed to do it each time you move code thatrsquos using the Wire library to a different processor In other wordswhen you decide to port the code to the ATmega8 or you put an ATmega16 in your Arduino or whatever acirceurordquo yoursquoll need to recompile these libraries Herersquos the drill

Navigate in a file browser or command prompt to the root of your Arduino file hierarchy Then go into

libtargetslibrariesWiredelete Wireo

libtargetslibrariesWireutilitydelete twio

Once yoursquove done this make one modification to the header file twih in libtargetslibrariesWireutilityLook around line 27 for a commented out line like this

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 3 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define ATMEGA8

Un-comment it (take out the ldquordquo in the front) Thisrsquoll ensure that the internal pull-up resistors on theATmega8 are enabled when yoursquore developing for the normal Arduino Yoursquoll only need to make thischange to twih once and for all Future builds of Arduino should have this fixed

For those who are curious mdash pull-up resistors are required on the TWI lines acirceurordquo SCL and SDA You mayuse your own external pull-ups but enabling the internal ones saves you the hassle But I donrsquot think yoursquolldo much harm if you have the internal onersquos enabled and use external ones But generally yoursquoll want toavoid having both internal and external pull-ups)

Anyway These modifications described above should get TWI working on the Arduino Mini)

Herersquos the code I wrote and ran

include ltWirehgt TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on the Atmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy void setup() pinMode(9 OUTPUT) digitalWrite(9 HIGH) Serialbegin(9600) CLKPR = (1ltltCLKPCE) CLKPR = 0 Wirebegin() join i2c bus (address optional for master) WirebeginTransmission(0x1D) Wiresend(0x20) CTRL_REG1 (20h) Wiresend(0x87) Device on 40hz normal mode all axiss enabled WireendTransmission() void loop() byte z_val_l z_val_h x_val_l x_val_h y_val_l y_val_h int z_val x_val y_val Serialprintln(hello) byte in_byte transmit to device with address 0x1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0x1D) WirebeginTransmission(0x1D) send the sub address for the register we want to read this is for the OUTZ_H register nb supposedly masking the register address with 0x80 you can do multiple reads with the register address auto-incremented Wiresend(0x28) stop transmitting WireendTransmission() Now do a transfer reading one byte from the LIS3L This data will be the contents of register 0x28 WirerequestFrom(0x1D 1) while(Wireavailable()) x_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x29) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable())

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 4 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

x_val_h = Wirereceive() x_val = x_val_h x_val ltlt= 8 x_val += x_val_l Y Axis WirebeginTransmission(0x1D) Wiresend(0x2A) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2B) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_h = Wirereceive() y_val = y_val_h y_val ltlt= 8 y_val += y_val_l Z Axis WirebeginTransmission(0x1D) Wiresend(0x2C) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2D) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_h = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l Set up to read the next register Supposedly if you set the most significant bit of the register address to 1 you can do a multiple read with the register address auto-incrementing This way you dont have to do another write mdash specifying the next register mdash before reading the next register value This would be very good but with a cursory attempt I have yet to make this work WirebeginTransmission(0x1D) transmit to device 4 Wiresend(0x2C) read outx_h stop transmitting WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l z axis acceleration all set Perfectly still and with the z-axis parallel to the ground it should be about 1024-ish (I find in practice it is around 1019) When the z-axis is orthogonal to the ground it should be zero 1024 is +1g acceleration or normal gravity 2048 is +2g 0 is 0g Serialprintln(z_val DEC)Serialprint(x_val HEX) Serialprint( )Serialprint(y_val HEX) Serialprint( ) Serialprintln(z_val HEX)delay(100)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 5 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Technorati Tags Arduino DIY

Related Dispatches

1 Propeller and Arduino Not the most exciting thing but an interesting challenge here Irsquom trying to get a ParallaxPropeller chip to

2 Finding The Way ndash HMC6352 Digital Compass Since I was asked and asked again Irsquoll toss this technotopiasolutions nugget to demonstrate that despite the evidence

3 Reflow Skillet I picked up a nice electric skillet from Target to do some surface-mount technology work It was on sale4 Laboratories Accelerometers And Kitchen Crockery The Memsic 6202 Accelerometer fresh out orsquothe skillet

Wersquove been out of the Laboratory proper mdash the place where things

previous post laquo Flavonoid Notesnext post raquo Quick Note on

About This PostYoursquore currently reading ldquoArduino and the Two-Wire Interface (TWII2C) Including A Short DidacticParenthetical On Making TWI Work On An Arduino Minirdquo an entry on Near Future Laboratory

Published011107 6pm

CategoryArduino Atmel Flavonoid Hardware How To Motion Projects Software sensor

17 CommentsJump to comment form | comments rss [] | trackback uri []

RSS feed | Trackback URI

17 Comments raquo

Comment by Daniel2008-02-09 102313

Hi

how do you call those flexible wires that you are using and where did you get them

Thanks

Daniel

Reply to this comment

Comment by Julian2008-02-11 132135

They are just jumper wires sold from Jameco and also Spark Fun electronics has some aswell (httpwwwsparkfuncomcommerceproduct_infophpproducts_id=8431)

Reply to this comment

Comment by Matthew

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 6 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

2008-02-19 233150

Julian thanks for your excellent example of the TWI on the Arduino It helped me get up andrunning in no time I have one question though I tried to take your example a little furtherby writing my own I2C code (instead of using the wire library) and to do multiple reads fromthe accelerometer However I cannot get it to work Did you ever get the multiple readfunctionality to work I could swear Irsquom following the LIS3LV02DQ data sheet to the T

Thanks

Reply to this comment

Comment by Felixe2008-04-15 010554

Whatrsquos the part number or manufacturer for those cheap accelerometers

Reply to this comment

Comment by Julian2008-04-15 094816

Felixe

Theyrsquore ST Microelectronicsrsquo LIS3LV02DQ a 3-axis accelerometer with digital outputs

I get the break-out boards from Spark Fun Electronics

httptinyurlcommfa6g

Theyrsquore not particularly inexpensive mdash about $15 single quantities for the individual piecesand $43 on the break-out board

Julian

Reply to this comment

Comment by MrScary2008-07-08 044001

Here is a working example based on the code above that does multiple reads at once forreading all three axis Irsquom using this sketch on an arduino nano Thanks for the originalexample

include ltwirehgt

TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on theAtmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy

define OUTX_L 0times28define OUTX_H 0times29define OUTY_L 0times2Adefine OUTY_H 0times2Bdefine OUTZ_L 0times2Cdefine OUTZ_H 0times2D

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 2: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 2 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

I hooked up my Arduino to a handy accelerometer for testing (Irsquom still using the expensive LIS3LV02DQ)Analog In 4 goes to SDA and Analog In 5 goes to SCL I have pull-up resistors on those lines but Nicolasexplains that his library enables the internal pull-ups on the Atmega so I can probably pull those from mybreadboard Either way itrsquos working just fine even with the external pull-up resistors (Irsquom using 47kresistors)

(I also found in one weird situation that I had to explicitly clear the clock prescaler to get the UARTfunctioning properly This was while getting TWI working on an AT90USB1287 ndash TWI worked fine butthe UART was spitting out garbage On chips where the clock prescaler can be set through the fuses itrsquosimportant to verify that the prescaler isnrsquot hard wired to divide the clock Thisrsquoll cause anything that isdependent on timing to potentially be off kilter In my case the UART was expecting an 8MHz clock todetermine timing and baud rate but the clock was being divided in hardware ndash not even in the firmware)

WireTWI (I2C) on the Arduino Mini

Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share a name theydonrsquot share the same processor The Arduino Mini uses an ATmega168 while the Arduinonormal uses anATmega8 Yoursquoll need to recompilere-rdquoverifyrdquo the Wire library files in order to get TWI to work on theATmega168Arduino Mini Therersquos a thing or two yoursquoll have to do by hand to get this to work and yoursquollneed to do it each time you move code thatrsquos using the Wire library to a different processor In other wordswhen you decide to port the code to the ATmega8 or you put an ATmega16 in your Arduino or whatever acirceurordquo yoursquoll need to recompile these libraries Herersquos the drill

Navigate in a file browser or command prompt to the root of your Arduino file hierarchy Then go into

libtargetslibrariesWiredelete Wireo

libtargetslibrariesWireutilitydelete twio

Once yoursquove done this make one modification to the header file twih in libtargetslibrariesWireutilityLook around line 27 for a commented out line like this

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 3 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define ATMEGA8

Un-comment it (take out the ldquordquo in the front) Thisrsquoll ensure that the internal pull-up resistors on theATmega8 are enabled when yoursquore developing for the normal Arduino Yoursquoll only need to make thischange to twih once and for all Future builds of Arduino should have this fixed

For those who are curious mdash pull-up resistors are required on the TWI lines acirceurordquo SCL and SDA You mayuse your own external pull-ups but enabling the internal ones saves you the hassle But I donrsquot think yoursquolldo much harm if you have the internal onersquos enabled and use external ones But generally yoursquoll want toavoid having both internal and external pull-ups)

Anyway These modifications described above should get TWI working on the Arduino Mini)

Herersquos the code I wrote and ran

include ltWirehgt TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on the Atmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy void setup() pinMode(9 OUTPUT) digitalWrite(9 HIGH) Serialbegin(9600) CLKPR = (1ltltCLKPCE) CLKPR = 0 Wirebegin() join i2c bus (address optional for master) WirebeginTransmission(0x1D) Wiresend(0x20) CTRL_REG1 (20h) Wiresend(0x87) Device on 40hz normal mode all axiss enabled WireendTransmission() void loop() byte z_val_l z_val_h x_val_l x_val_h y_val_l y_val_h int z_val x_val y_val Serialprintln(hello) byte in_byte transmit to device with address 0x1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0x1D) WirebeginTransmission(0x1D) send the sub address for the register we want to read this is for the OUTZ_H register nb supposedly masking the register address with 0x80 you can do multiple reads with the register address auto-incremented Wiresend(0x28) stop transmitting WireendTransmission() Now do a transfer reading one byte from the LIS3L This data will be the contents of register 0x28 WirerequestFrom(0x1D 1) while(Wireavailable()) x_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x29) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable())

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 4 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

x_val_h = Wirereceive() x_val = x_val_h x_val ltlt= 8 x_val += x_val_l Y Axis WirebeginTransmission(0x1D) Wiresend(0x2A) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2B) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_h = Wirereceive() y_val = y_val_h y_val ltlt= 8 y_val += y_val_l Z Axis WirebeginTransmission(0x1D) Wiresend(0x2C) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2D) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_h = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l Set up to read the next register Supposedly if you set the most significant bit of the register address to 1 you can do a multiple read with the register address auto-incrementing This way you dont have to do another write mdash specifying the next register mdash before reading the next register value This would be very good but with a cursory attempt I have yet to make this work WirebeginTransmission(0x1D) transmit to device 4 Wiresend(0x2C) read outx_h stop transmitting WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l z axis acceleration all set Perfectly still and with the z-axis parallel to the ground it should be about 1024-ish (I find in practice it is around 1019) When the z-axis is orthogonal to the ground it should be zero 1024 is +1g acceleration or normal gravity 2048 is +2g 0 is 0g Serialprintln(z_val DEC)Serialprint(x_val HEX) Serialprint( )Serialprint(y_val HEX) Serialprint( ) Serialprintln(z_val HEX)delay(100)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 5 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Technorati Tags Arduino DIY

Related Dispatches

1 Propeller and Arduino Not the most exciting thing but an interesting challenge here Irsquom trying to get a ParallaxPropeller chip to

2 Finding The Way ndash HMC6352 Digital Compass Since I was asked and asked again Irsquoll toss this technotopiasolutions nugget to demonstrate that despite the evidence

3 Reflow Skillet I picked up a nice electric skillet from Target to do some surface-mount technology work It was on sale4 Laboratories Accelerometers And Kitchen Crockery The Memsic 6202 Accelerometer fresh out orsquothe skillet

Wersquove been out of the Laboratory proper mdash the place where things

previous post laquo Flavonoid Notesnext post raquo Quick Note on

About This PostYoursquore currently reading ldquoArduino and the Two-Wire Interface (TWII2C) Including A Short DidacticParenthetical On Making TWI Work On An Arduino Minirdquo an entry on Near Future Laboratory

Published011107 6pm

CategoryArduino Atmel Flavonoid Hardware How To Motion Projects Software sensor

17 CommentsJump to comment form | comments rss [] | trackback uri []

RSS feed | Trackback URI

17 Comments raquo

Comment by Daniel2008-02-09 102313

Hi

how do you call those flexible wires that you are using and where did you get them

Thanks

Daniel

Reply to this comment

Comment by Julian2008-02-11 132135

They are just jumper wires sold from Jameco and also Spark Fun electronics has some aswell (httpwwwsparkfuncomcommerceproduct_infophpproducts_id=8431)

Reply to this comment

Comment by Matthew

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 6 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

2008-02-19 233150

Julian thanks for your excellent example of the TWI on the Arduino It helped me get up andrunning in no time I have one question though I tried to take your example a little furtherby writing my own I2C code (instead of using the wire library) and to do multiple reads fromthe accelerometer However I cannot get it to work Did you ever get the multiple readfunctionality to work I could swear Irsquom following the LIS3LV02DQ data sheet to the T

Thanks

Reply to this comment

Comment by Felixe2008-04-15 010554

Whatrsquos the part number or manufacturer for those cheap accelerometers

Reply to this comment

Comment by Julian2008-04-15 094816

Felixe

Theyrsquore ST Microelectronicsrsquo LIS3LV02DQ a 3-axis accelerometer with digital outputs

I get the break-out boards from Spark Fun Electronics

httptinyurlcommfa6g

Theyrsquore not particularly inexpensive mdash about $15 single quantities for the individual piecesand $43 on the break-out board

Julian

Reply to this comment

Comment by MrScary2008-07-08 044001

Here is a working example based on the code above that does multiple reads at once forreading all three axis Irsquom using this sketch on an arduino nano Thanks for the originalexample

include ltwirehgt

TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on theAtmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy

define OUTX_L 0times28define OUTX_H 0times29define OUTY_L 0times2Adefine OUTY_H 0times2Bdefine OUTZ_L 0times2Cdefine OUTZ_H 0times2D

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 3: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 3 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define ATMEGA8

Un-comment it (take out the ldquordquo in the front) Thisrsquoll ensure that the internal pull-up resistors on theATmega8 are enabled when yoursquore developing for the normal Arduino Yoursquoll only need to make thischange to twih once and for all Future builds of Arduino should have this fixed

For those who are curious mdash pull-up resistors are required on the TWI lines acirceurordquo SCL and SDA You mayuse your own external pull-ups but enabling the internal ones saves you the hassle But I donrsquot think yoursquolldo much harm if you have the internal onersquos enabled and use external ones But generally yoursquoll want toavoid having both internal and external pull-ups)

Anyway These modifications described above should get TWI working on the Arduino Mini)

Herersquos the code I wrote and ran

include ltWirehgt TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on the Atmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy void setup() pinMode(9 OUTPUT) digitalWrite(9 HIGH) Serialbegin(9600) CLKPR = (1ltltCLKPCE) CLKPR = 0 Wirebegin() join i2c bus (address optional for master) WirebeginTransmission(0x1D) Wiresend(0x20) CTRL_REG1 (20h) Wiresend(0x87) Device on 40hz normal mode all axiss enabled WireendTransmission() void loop() byte z_val_l z_val_h x_val_l x_val_h y_val_l y_val_h int z_val x_val y_val Serialprintln(hello) byte in_byte transmit to device with address 0x1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0x1D) WirebeginTransmission(0x1D) send the sub address for the register we want to read this is for the OUTZ_H register nb supposedly masking the register address with 0x80 you can do multiple reads with the register address auto-incremented Wiresend(0x28) stop transmitting WireendTransmission() Now do a transfer reading one byte from the LIS3L This data will be the contents of register 0x28 WirerequestFrom(0x1D 1) while(Wireavailable()) x_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x29) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable())

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 4 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

x_val_h = Wirereceive() x_val = x_val_h x_val ltlt= 8 x_val += x_val_l Y Axis WirebeginTransmission(0x1D) Wiresend(0x2A) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2B) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_h = Wirereceive() y_val = y_val_h y_val ltlt= 8 y_val += y_val_l Z Axis WirebeginTransmission(0x1D) Wiresend(0x2C) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2D) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_h = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l Set up to read the next register Supposedly if you set the most significant bit of the register address to 1 you can do a multiple read with the register address auto-incrementing This way you dont have to do another write mdash specifying the next register mdash before reading the next register value This would be very good but with a cursory attempt I have yet to make this work WirebeginTransmission(0x1D) transmit to device 4 Wiresend(0x2C) read outx_h stop transmitting WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l z axis acceleration all set Perfectly still and with the z-axis parallel to the ground it should be about 1024-ish (I find in practice it is around 1019) When the z-axis is orthogonal to the ground it should be zero 1024 is +1g acceleration or normal gravity 2048 is +2g 0 is 0g Serialprintln(z_val DEC)Serialprint(x_val HEX) Serialprint( )Serialprint(y_val HEX) Serialprint( ) Serialprintln(z_val HEX)delay(100)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 5 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Technorati Tags Arduino DIY

Related Dispatches

1 Propeller and Arduino Not the most exciting thing but an interesting challenge here Irsquom trying to get a ParallaxPropeller chip to

2 Finding The Way ndash HMC6352 Digital Compass Since I was asked and asked again Irsquoll toss this technotopiasolutions nugget to demonstrate that despite the evidence

3 Reflow Skillet I picked up a nice electric skillet from Target to do some surface-mount technology work It was on sale4 Laboratories Accelerometers And Kitchen Crockery The Memsic 6202 Accelerometer fresh out orsquothe skillet

Wersquove been out of the Laboratory proper mdash the place where things

previous post laquo Flavonoid Notesnext post raquo Quick Note on

About This PostYoursquore currently reading ldquoArduino and the Two-Wire Interface (TWII2C) Including A Short DidacticParenthetical On Making TWI Work On An Arduino Minirdquo an entry on Near Future Laboratory

Published011107 6pm

CategoryArduino Atmel Flavonoid Hardware How To Motion Projects Software sensor

17 CommentsJump to comment form | comments rss [] | trackback uri []

RSS feed | Trackback URI

17 Comments raquo

Comment by Daniel2008-02-09 102313

Hi

how do you call those flexible wires that you are using and where did you get them

Thanks

Daniel

Reply to this comment

Comment by Julian2008-02-11 132135

They are just jumper wires sold from Jameco and also Spark Fun electronics has some aswell (httpwwwsparkfuncomcommerceproduct_infophpproducts_id=8431)

Reply to this comment

Comment by Matthew

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 6 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

2008-02-19 233150

Julian thanks for your excellent example of the TWI on the Arduino It helped me get up andrunning in no time I have one question though I tried to take your example a little furtherby writing my own I2C code (instead of using the wire library) and to do multiple reads fromthe accelerometer However I cannot get it to work Did you ever get the multiple readfunctionality to work I could swear Irsquom following the LIS3LV02DQ data sheet to the T

Thanks

Reply to this comment

Comment by Felixe2008-04-15 010554

Whatrsquos the part number or manufacturer for those cheap accelerometers

Reply to this comment

Comment by Julian2008-04-15 094816

Felixe

Theyrsquore ST Microelectronicsrsquo LIS3LV02DQ a 3-axis accelerometer with digital outputs

I get the break-out boards from Spark Fun Electronics

httptinyurlcommfa6g

Theyrsquore not particularly inexpensive mdash about $15 single quantities for the individual piecesand $43 on the break-out board

Julian

Reply to this comment

Comment by MrScary2008-07-08 044001

Here is a working example based on the code above that does multiple reads at once forreading all three axis Irsquom using this sketch on an arduino nano Thanks for the originalexample

include ltwirehgt

TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on theAtmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy

define OUTX_L 0times28define OUTX_H 0times29define OUTY_L 0times2Adefine OUTY_H 0times2Bdefine OUTZ_L 0times2Cdefine OUTZ_H 0times2D

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 4: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 4 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

x_val_h = Wirereceive() x_val = x_val_h x_val ltlt= 8 x_val += x_val_l Y Axis WirebeginTransmission(0x1D) Wiresend(0x2A) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2B) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) y_val_h = Wirereceive() y_val = y_val_h y_val ltlt= 8 y_val += y_val_l Z Axis WirebeginTransmission(0x1D) Wiresend(0x2C) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() WirebeginTransmission(0x1D) Wiresend(0x2D) WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_h = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l Set up to read the next register Supposedly if you set the most significant bit of the register address to 1 you can do a multiple read with the register address auto-incrementing This way you dont have to do another write mdash specifying the next register mdash before reading the next register value This would be very good but with a cursory attempt I have yet to make this work WirebeginTransmission(0x1D) transmit to device 4 Wiresend(0x2C) read outx_h stop transmitting WireendTransmission() WirerequestFrom(0x1D 1) while(Wireavailable()) z_val_l = Wirereceive() z_val = z_val_h z_val ltlt= 8 z_val += z_val_l z axis acceleration all set Perfectly still and with the z-axis parallel to the ground it should be about 1024-ish (I find in practice it is around 1019) When the z-axis is orthogonal to the ground it should be zero 1024 is +1g acceleration or normal gravity 2048 is +2g 0 is 0g Serialprintln(z_val DEC)Serialprint(x_val HEX) Serialprint( )Serialprint(y_val HEX) Serialprint( ) Serialprintln(z_val HEX)delay(100)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 5 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Technorati Tags Arduino DIY

Related Dispatches

1 Propeller and Arduino Not the most exciting thing but an interesting challenge here Irsquom trying to get a ParallaxPropeller chip to

2 Finding The Way ndash HMC6352 Digital Compass Since I was asked and asked again Irsquoll toss this technotopiasolutions nugget to demonstrate that despite the evidence

3 Reflow Skillet I picked up a nice electric skillet from Target to do some surface-mount technology work It was on sale4 Laboratories Accelerometers And Kitchen Crockery The Memsic 6202 Accelerometer fresh out orsquothe skillet

Wersquove been out of the Laboratory proper mdash the place where things

previous post laquo Flavonoid Notesnext post raquo Quick Note on

About This PostYoursquore currently reading ldquoArduino and the Two-Wire Interface (TWII2C) Including A Short DidacticParenthetical On Making TWI Work On An Arduino Minirdquo an entry on Near Future Laboratory

Published011107 6pm

CategoryArduino Atmel Flavonoid Hardware How To Motion Projects Software sensor

17 CommentsJump to comment form | comments rss [] | trackback uri []

RSS feed | Trackback URI

17 Comments raquo

Comment by Daniel2008-02-09 102313

Hi

how do you call those flexible wires that you are using and where did you get them

Thanks

Daniel

Reply to this comment

Comment by Julian2008-02-11 132135

They are just jumper wires sold from Jameco and also Spark Fun electronics has some aswell (httpwwwsparkfuncomcommerceproduct_infophpproducts_id=8431)

Reply to this comment

Comment by Matthew

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 6 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

2008-02-19 233150

Julian thanks for your excellent example of the TWI on the Arduino It helped me get up andrunning in no time I have one question though I tried to take your example a little furtherby writing my own I2C code (instead of using the wire library) and to do multiple reads fromthe accelerometer However I cannot get it to work Did you ever get the multiple readfunctionality to work I could swear Irsquom following the LIS3LV02DQ data sheet to the T

Thanks

Reply to this comment

Comment by Felixe2008-04-15 010554

Whatrsquos the part number or manufacturer for those cheap accelerometers

Reply to this comment

Comment by Julian2008-04-15 094816

Felixe

Theyrsquore ST Microelectronicsrsquo LIS3LV02DQ a 3-axis accelerometer with digital outputs

I get the break-out boards from Spark Fun Electronics

httptinyurlcommfa6g

Theyrsquore not particularly inexpensive mdash about $15 single quantities for the individual piecesand $43 on the break-out board

Julian

Reply to this comment

Comment by MrScary2008-07-08 044001

Here is a working example based on the code above that does multiple reads at once forreading all three axis Irsquom using this sketch on an arduino nano Thanks for the originalexample

include ltwirehgt

TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on theAtmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy

define OUTX_L 0times28define OUTX_H 0times29define OUTY_L 0times2Adefine OUTY_H 0times2Bdefine OUTZ_L 0times2Cdefine OUTZ_H 0times2D

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 5: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 5 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Technorati Tags Arduino DIY

Related Dispatches

1 Propeller and Arduino Not the most exciting thing but an interesting challenge here Irsquom trying to get a ParallaxPropeller chip to

2 Finding The Way ndash HMC6352 Digital Compass Since I was asked and asked again Irsquoll toss this technotopiasolutions nugget to demonstrate that despite the evidence

3 Reflow Skillet I picked up a nice electric skillet from Target to do some surface-mount technology work It was on sale4 Laboratories Accelerometers And Kitchen Crockery The Memsic 6202 Accelerometer fresh out orsquothe skillet

Wersquove been out of the Laboratory proper mdash the place where things

previous post laquo Flavonoid Notesnext post raquo Quick Note on

About This PostYoursquore currently reading ldquoArduino and the Two-Wire Interface (TWII2C) Including A Short DidacticParenthetical On Making TWI Work On An Arduino Minirdquo an entry on Near Future Laboratory

Published011107 6pm

CategoryArduino Atmel Flavonoid Hardware How To Motion Projects Software sensor

17 CommentsJump to comment form | comments rss [] | trackback uri []

RSS feed | Trackback URI

17 Comments raquo

Comment by Daniel2008-02-09 102313

Hi

how do you call those flexible wires that you are using and where did you get them

Thanks

Daniel

Reply to this comment

Comment by Julian2008-02-11 132135

They are just jumper wires sold from Jameco and also Spark Fun electronics has some aswell (httpwwwsparkfuncomcommerceproduct_infophpproducts_id=8431)

Reply to this comment

Comment by Matthew

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 6 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

2008-02-19 233150

Julian thanks for your excellent example of the TWI on the Arduino It helped me get up andrunning in no time I have one question though I tried to take your example a little furtherby writing my own I2C code (instead of using the wire library) and to do multiple reads fromthe accelerometer However I cannot get it to work Did you ever get the multiple readfunctionality to work I could swear Irsquom following the LIS3LV02DQ data sheet to the T

Thanks

Reply to this comment

Comment by Felixe2008-04-15 010554

Whatrsquos the part number or manufacturer for those cheap accelerometers

Reply to this comment

Comment by Julian2008-04-15 094816

Felixe

Theyrsquore ST Microelectronicsrsquo LIS3LV02DQ a 3-axis accelerometer with digital outputs

I get the break-out boards from Spark Fun Electronics

httptinyurlcommfa6g

Theyrsquore not particularly inexpensive mdash about $15 single quantities for the individual piecesand $43 on the break-out board

Julian

Reply to this comment

Comment by MrScary2008-07-08 044001

Here is a working example based on the code above that does multiple reads at once forreading all three axis Irsquom using this sketch on an arduino nano Thanks for the originalexample

include ltwirehgt

TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on theAtmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy

define OUTX_L 0times28define OUTX_H 0times29define OUTY_L 0times2Adefine OUTY_H 0times2Bdefine OUTZ_L 0times2Cdefine OUTZ_H 0times2D

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 6: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 6 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

2008-02-19 233150

Julian thanks for your excellent example of the TWI on the Arduino It helped me get up andrunning in no time I have one question though I tried to take your example a little furtherby writing my own I2C code (instead of using the wire library) and to do multiple reads fromthe accelerometer However I cannot get it to work Did you ever get the multiple readfunctionality to work I could swear Irsquom following the LIS3LV02DQ data sheet to the T

Thanks

Reply to this comment

Comment by Felixe2008-04-15 010554

Whatrsquos the part number or manufacturer for those cheap accelerometers

Reply to this comment

Comment by Julian2008-04-15 094816

Felixe

Theyrsquore ST Microelectronicsrsquo LIS3LV02DQ a 3-axis accelerometer with digital outputs

I get the break-out boards from Spark Fun Electronics

httptinyurlcommfa6g

Theyrsquore not particularly inexpensive mdash about $15 single quantities for the individual piecesand $43 on the break-out board

Julian

Reply to this comment

Comment by MrScary2008-07-08 044001

Here is a working example based on the code above that does multiple reads at once forreading all three axis Irsquom using this sketch on an arduino nano Thanks for the originalexample

include ltwirehgt

TWI (I2C) sketch to communicate with the LIS3LV02DQ accelerometer

Using the Wire library (created by Nicholas Zambetti) httpwiringorgcoreferencelibrariesWireindexhtml On the Arduino board Analog In 4 is SDA Analog In 5 is SCL These correspond to pin 27 (PC4ADC4SDA) and pin 28 (PC5ADC5SCL) on theAtmega8 The Wire class handles the TWI transactions abstracting the nitty-gritty to make prototyping easy

define OUTX_L 0times28define OUTX_H 0times29define OUTY_L 0times2Adefine OUTY_H 0times2Bdefine OUTZ_L 0times2Cdefine OUTZ_H 0times2D

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 7: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 7 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

define XAXIS 0define YAXIS 1define ZAXIS 2

void setup()

Wirebegin() join i2c bus (address optional for master)Serialbegin( 9600 )

WirebeginTransmission( 0times1D )Wiresend( 0times20 ) CTRL_REG1 ( 20h )

Wiresend( 0times87 ) Device on 40hz normal mode all axisrsquos enabledWireendTransmission()

void loop()

int val[3] transmit to device with address 0times1D according to the LIS3L datasheet the i2c address of is fixed at the factory at 0011101b (0times1D)

WirebeginTransmission( 0times1D ) send the sub address for the first register we want to read this is for the OUTX_L register

set the MSB so we can do multiple reads with the register address auto-incrementedWiresend( OUTX_L | 0times80) stop transmittingWireendTransmission()

Now do a transfer reading six bytes from the LIS3L This data will be the contents of the X Y and Z registersWirerequestFrom( 0times1D 6 )

while ( Wireavailable() lt 6 ) this isnrsquot really necessary a better thing to do would be to set up an onReceive handler buffer the data and go off and do something else if the data isnrsquot readydelay( 5 )

read the datafor ( int i = 0 i lt 3 i++ ) read low bytebyte low = Wirereceive() read the high byteval[i] = ( Wirereceive() ltlt 8 ) + low

do something with the valuesSerialprint( rdquo x_val = rdquo )Serialprint( val[XAXIS] DEC )Serialprint( rdquo y_val = rdquo )Serialprint( val[YAXIS] DEC )Serialprint( rdquo z_val = rdquo )Serialprintln( val[ZAXIS] DEC )

delay( 250 )

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 8: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 8 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Reply to this comment

Comment by Bryan2008-08-18 092636

Hi Irsquove had success with the Arduino Diecimila(Atmega168) with the accelerometer quitewell

A newbie question

This time Irsquove got a SFErsquos Skinny(Atmega168v 8MHz) with 33v logic levelIn this case do I have reflect the changes in the clock speed for the I2C connection

Thanks a lot

Bryan

Reply to this comment

Comment by Julian2008-08-18 114319

Ooh I havenrsquot heard of the Skinny but it sounds quite useful

Irsquom guessing that you donrsquot need to make any adjustments in the source code TheLilyPad Arduino which also runs at 8MHz can be specified under the menu item ldquoTools-gtBoardrdquo mdash that should compile your code with the correct F_CPU define of 8000000without you mucking about under the hood

Reply to this comment

Comment by Bryan

(Comments wont nest below this level)

2008-08-19 101221

Thank you Julian

Great I donrsquot have to pull my hair out for the source coding adustmentsThe menu item selection will do the job for me Wow

Bryan

Reply here

Comment by Bryan

2008-09-18 100330

Hi Julian

After Irsquove received my Skinny 8MHz clock with 33volt logic from the SFE I had tosolve the problem with the program uploading to the SkinnySince I already had success using your didactic instructions with Arduino Diecimila ndashI2C of LIS3LV02DQ ndash hooked up to my PC I did not suspect the poor old FTDIdriver No success even with numerous changing of reset button timingsAnywaylong story short I found the FTDI driver should be updated and intalled thenew one last week The uploding works greatI still have to connect the Accelerometer to my Skinny at 33VI understand Irsquom quite a bit behind scheduleMy Skinny will be soon connected

Thanks for your help

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 9: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 9 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

(Comments wont nest below this level)

Bryan

Comment by Julian2008-09-21 021822

Hey thanks for the notes Bryan Keep me up to date with how it all works

Julian

Reply here

Comment by Henry

2008-09-29 130543

Hi Julian

Thanks for your very informative example

Irsquove been trying to get a Lilypad to talk to sparkfunrsquos capacitive sensing module (based onthe AD7746) ndash but irsquoversquo got almost nowhere with it

Have you any experience with this chip

cheers

-henry

Reply to this comment

Comment by Julian2008-09-30 011737

Hey Henry

Irsquove never tried this part but I actually think I have it on a break out boardsomewherejust never got to it I used the AD7150 though which is also an I2C deviceNever really had any particular problems with it

Where have you gotten with the AD7746 I can probably help you debug

julian

Reply to this comment

Name (required)

E-mail (required - never shown publicly)

URI

Your Comment (smaller size | larger size)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 10: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 10 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Trackback responses to this post

Anderson Miller - project blog raquo Physical Computing - FinalHow to Connect Multiple Arduino Microcontrollers with I2C | Hack N ModArduino I2C laquo Mikersquos BrainElectronic improvements laquo NEar Space LABoratory

Recent PostsBrand ObamaTangled KnotsInteroperabilityIncongruence Between Public amp PrivateDavid Byrne UrbanismDrama Boredom Simply InfovisualizedNational Science Foundation Creative ldquoITrdquo RFPApproaches To DesignSXSW 2010 Interactive Proposal ndash Design FictionEduardo Galeano Contemplates Historyrsquos ParadoxesPogoplug and The Rise of Network FogPersonas WebGenerative Urban DesignPastiche Scenarios Design CommunicationLift Asia 09 Jeju Korea Sept 17-18

Categories3D Printed (9)Advertising (6)Air Guitar Hero (2)Announcement (1)Announcements amp Calls For Things (8)Apparatus for Capturing Other Points of View (1)Approaches to Design (1)Arduino (22)Atmel (27)Book Review (2)Book Stuff (95)Cartography (15)Conference (20)Contexts (9)Design (95)Design Art Technology (61)

You may use lta href= title=gt ltabbr title=gt ltacronym title=gt ltbgt ltblockquote cite=gt ltcitegt ltcodegt ltdeldatetime=gt ltemgt ltigt ltq cite=gt ltstrikegt ltstronggt ltpre lang= line= escaped=gt in your comment

Add comment

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 11: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 11 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Design as Strategy (8)Design Fiction (29)Design Fiction Chronicles (7)Design for Implications (71)Design Technology (27)Display (6)Disruption (20)Drift Deck (3)Failure (2)Flavonoid (28)General (173)Global Consequences (1)Hardware (61)Health and Fitness (4)How To (41)Improvisation (14)Infrastructure (4)Innovation (41)Interaction Terms (18)Interface (20)Keyboard (5)Landscape (18)Landscape as Interface (19)Measures of Things (3)Mobile (43)MobZombies (4)Money (2)Motion (43)New Interaction Rituals (21)Nokia (5)Observations (80)PDPal (2)Peculiar (37)Photo (11)Play (28)Post-GUI (21)Post-Optimal Design (13)Pre-GUI (3)Presence Awareness (1)Presentation (5)Printed Circuit Board (2)Projects (47)Propeller (5)Proposal (4)Proposed (3)Protocols and Practices (1)Proximity (13)PSX (11)Psychogeography (13)scenario (11)Science Fiction (2)science technology studies (18)Security (5)sensor (24)Sharing (2)SiteNav (4)Slow Messenger (9)Social Practice (36)Software (14)Spain (2)The Future (2)

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 12: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 12 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

Themes (2)Theory (74)Thoughtful Act (6)Thoughtless Acts (5)Time (23)Tools (1)Touch (14)Tourism (9)Travel (10)Trust (6)Undesign (11)Undisciplinarity (35)Urban (36)user experience (10)WiFiArtCache (1)WiFiKu (1)Workshop (4)Worry Wand (1)writing (19)

PagesAbout

Julian Press PhotosJulianrsquos BioNicolasrsquo BioThe Near Future Laboratory Process

Tactical Research AssociatesContactEssaysPresentationsProjects

Drift Deck (Analog Edition)Drift Deck Proposal

FlavonoidFlavonoid mdash 1st PrototypeFlavonoid mdash 2nd PrototypeFlavonoid mdash 3rd PrototypeFlavonoid mdash 5th PrototypeFlavonoid mdash 7th Prototype

High ChairProjects BrieflyPSX mdash Social Engineering Katamari DamacySlow MessengerVis-a-Vis

WiFiKuWorkshops

Most Read PostsChalkbot Versus GraffitiWriterRound One ReadyFIGHTDesign Fiction A Short Essay on Design Science Fact and FictionOverlap 09Call for Artists mdash Locative Cinema CommissionMeasuring the ImmeasurableFollow Curiosity Not CareersDesign Fiction Chronicles The Stability of Food FuturesDesign Fiction Chronicles The Interlaced Histories of Star Trek amp Mobile PhonesWilliam H Whyte Revisited An Experiment With An Apparatus for Capturing Other Points of ViewDesign Fiction Chronicles Cylon Hybrids Tweet Prophecy or Prattle

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS

Page 13: Near Future Laboratory » Blog Archive » Arduino and the ...cs5968/handouts/Arduino-i2c.pdf · Getting TWI working on the Arduino Mini (Although the Arduino and Arduino Mini share

93009 1104 AMNear Future Laboratory raquo Blog Archive raquo Arduino and the Two-Wire InthellipA Short Didactic Parenthetical On Making TWI Work On An Arduino Mini

Page 13 of 13httpwwwnearfuturelaboratorycom20070111arduino-and-twi

ArchivesSelect Month

Powered by Hemingway amp Ninja Monkeys flavored Wordpress

Entries RSS Comments RSS