<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Current beta Wire library implementation with support for hardware I2C</title>
		<link>http://forums.leaflabs.com/topic.php?id=1033</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:01:43 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1033" rel="self" type="application/rss+xml" />

		<item>
			<title>ala42 on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-28508</link>
			<pubDate>Mon, 19 Aug 2013 18:40:02 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">28508@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Just some simple functions to abstract the wire library and avoid the typical word length problems between 8-bit and 32-bit CPUs.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;byte readByteI2C() {
	return Wire.read();
}

byte readByteI2C(int deviceAddress) {
	Wire.requestFrom(deviceAddress, 1);
	return Wire.read();
}

int readWordI2C(int deviceAddress) {
	Wire.requestFrom(deviceAddress, 2);
	return (Wire.read() &#38;lt;&#38;lt; 8) &#124; Wire.read();
}

int readWordI2C() {
	return (Wire.read() &#38;lt;&#38;lt; 8) &#124; Wire.read();
}

int readShortI2C() {
	return (signed short)readWordI2C();
}

int readShortI2C(int deviceAddress) {
	Wire.requestFrom(deviceAddress, 2);
	return readShortI2C();
}

int readReverseShortI2C() {
	return (signed short)( Wire.read() &#124; (Wire.read() &#38;lt;&#38;lt; 8));
}

void updateRegisterI2C(int deviceAddress, byte dataAddress, byte dataValue) {
	Wire.beginTransmission(deviceAddress);
	Wire.write(dataAddress);
	Wire.write(dataValue);
	Wire.endTransmission();
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>chlee on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-28506</link>
			<pubDate>Mon, 19 Aug 2013 16:16:58 +0000</pubDate>
			<dc:creator>chlee</dc:creator>
			<guid isPermaLink="false">28506@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ala42-Where is the function &#34;updateRegisterI2C&#34; defined? I can't find it in the HardWire library or the example code you linked. Thank you!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-28493</link>
			<pubDate>Fri, 16 Aug 2013 18:32:42 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">28493@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;The sensor manual is a good place to start :).  There are enough sample codes floating around, e.g. here: &#60;a href=&#34;https://github.com/AeroQuad/AeroQuad/tree/master/Libraries/AQ_Compass&#34; rel=&#34;nofollow&#34;&#62;https://github.com/AeroQuad/AeroQuad/tree/master/Libraries/AQ_Compass&#60;/a&#62;&#60;br /&#62;
If you still have no idea, take what you need from my test code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;//#define SENSOR_GAIN 0x00  // +/- 0.7 Ga
#define SENSOR_GAIN 0x20  // +/- 1.0 Ga (default)
//#define SENSOR_GAIN 0x40  // +/- 1.5 Ga
//#define SENSOR_GAIN 0x60  // +/- 2.0 Ga
//#define SENSOR_GAIN 0x80  // +/- 3.2 Ga
//#define SENSOR_GAIN 0xA0  // +/- 3.8 Ga
//#define SENSOR_GAIN 0xC0  // +/- 4.5 Ga
//#define SENSOR_GAIN 0xE0  // +/- 6.5 Ga (not recommended)

void initializeHMC5883(int addr) {
	updateRegisterI2C(addr, 0x01, SENSOR_GAIN); // Gain as defined above
	delay(20);
	updateRegisterI2C(addr, 0x02, 0x01); // start single conversion
	delay(20);
}

void MeasureHMC5883(int addr)
{
	int measuredMagX;
	int measuredMagZ;
	int measuredMagY;

	initializeHMC5883(addr);
	print(&#38;quot;HMC5883 axis readings\r\n&#38;quot;);
	do {
		sendByteI2C(addr, 0x03);
		Wire.requestFrom(addr, 6);
		measuredMagX = readShortI2C();
		measuredMagZ = -readShortI2C();
		measuredMagY = -readShortI2C();

		float magX = measuredMagX;
		float magY = measuredMagY;

		const float tmp  = sqrt(magX * magX + magY * magY);

		float hdgX = magX / tmp;
		float hdgY = -magY / tmp;
		float hdg = atan2(hdgY, hdgX);
		if(hdg &#38;lt; 0) {
			hdg = 2*PI + hdg;
		}

		print(&#38;quot;x %4d  y %4d  z %4d  hdgX %5.2f  hdgY %5.2f  hdg %5.2f\r&#38;quot;, measuredMagX, measuredMagY, measuredMagZ, hdgX, hdgY, degrees(hdg));
		updateRegisterI2C(addr, 0x02, 0x01); // start single conversion
		delay(50);
	} while(GetKeyAndScroll() &#38;lt; 0);
}&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>chlee on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-28492</link>
			<pubDate>Fri, 16 Aug 2013 17:39:00 +0000</pubDate>
			<dc:creator>chlee</dc:creator>
			<guid isPermaLink="false">28492@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi, I'm trying to connect HMC5883L to Maple-mini by modifying your ADXL345 example code. However, I don't fully understand the void intADXL() function. More specifically,&#60;/p&#62;
&#60;p&#62;ADXL_write_reg(ADXL_CONTROL_REGISTERS,DATA);&#60;/p&#62;
&#60;p&#62;How do you know what data put for each register mode? (like 0x08 for ADXLREG_POWER_CTL in your example code).&#60;/p&#62;
&#60;p&#62;Thanks for any help!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-21839</link>
			<pubDate>Thu, 03 Jan 2013 17:36:36 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">21839@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;mario - ala42's explanation is most likely correct, or you have set the IDE to load the program in to RAM.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ala42 on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-21837</link>
			<pubDate>Thu, 03 Jan 2013 13:21:09 +0000</pubDate>
			<dc:creator>ala42</dc:creator>
			<guid isPermaLink="false">21837@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Looks like you defined a large static/global array in your code, which needs more ram than is available.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mario on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-21836</link>
			<pubDate>Thu, 03 Jan 2013 03:59:25 +0000</pubDate>
			<dc:creator>mario</dc:creator>
			<guid isPermaLink="false">21836@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I used the library HardWire and the program example Wire_Test.pde to the link. When I compiled the Maple IDE show the following message:&#60;/p&#62;
&#60;p&#62;Also note that because of preprocessing, line numbers won't match up exactly.  We're working on a fix.&#60;br /&#62;
c:/archivos de programa/maple-ide-0.0.12-windowsxp32/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/bin/ld.exe: &#38;lt;BUILD&#38;gt;\Wire_Test.cpp.elf section &#60;code&#62;.data&#38;#39; will not fit in region&#60;/code&#62;ram'&#60;br /&#62;
c:/archivos de programa/maple-ide-0.0.12-windowsxp32/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.4.1/../../../../arm-none-eabi/bin/ld.exe: region `ram' overflowed by 3176 bytes&#60;br /&#62;
collect2: ld returned 1 exit status&#60;/p&#62;
&#60;p&#62;What happens?&#60;/p&#62;
&#60;p&#62;Thaks!!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-20214</link>
			<pubDate>Sun, 07 Oct 2012 23:08:14 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">20214@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;You never actually start the HardWire interface. Call portinLib.begin() at some time to get it to work.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>hitcher404 on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-20172</link>
			<pubDate>Wed, 03 Oct 2012 18:51:57 +0000</pubDate>
			<dc:creator>hitcher404</dc:creator>
			<guid isPermaLink="false">20172@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hi there, having some issues with the new Wire implementation in libmaple, must be something I'm not doing right, but thought I'd ask here.&#60;/p&#62;
&#60;p&#62;Having problems using HardWire in my own libraries:&#60;/p&#62;
&#60;p&#62;For example this code (totally stripped out version of something for reading from an ITG-3200 gyro) works fine:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/qgGe9PZ7&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/qgGe9PZ7&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;But this main:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/EYeSA6L1&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/EYeSA6L1&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;With this simple library with identical code to the previous main.cpp, just moved to a lib:&#60;/p&#62;
&#60;p&#62;Gyro.cpp   :  &#60;a href=&#34;http://pastebin.com/smFJ8uSp&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/smFJ8uSp&#60;/a&#62;&#60;br /&#62;
Gyro.h     :  &#60;a href=&#34;http://pastebin.com/9Zq6Wdw6&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/9Zq6Wdw6&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;doesnt work.&#60;/p&#62;
&#60;p&#62;The second main.cpp with Gyro.cpp/h as a library fails at the first .endTransmission, in the same way that it would if you picked the wrong i2c port/pins.&#60;/p&#62;
&#60;p&#62;Have been using the old version of wire in libraries like this just fine, as well as things like HardwareSPI objects etc.&#60;/p&#62;
&#60;p&#62;Even tried passing a pointer to the HardWire object instantiated in main.cpp to the Gyro class, it produces data the first time its called but fails the very next.&#60;/p&#62;
&#60;p&#62;Sure its something my abysmal C++ is causing, but just cant see it after lots of trying different things, why are HardWire objects any different from HardwareSPI objects or any of the other ones I've used in my own 'libraries' before?&#60;/p&#62;
&#60;p&#62;Honest thanks for any help.. apologies if this is the wrong place to be asking such questions.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-11520</link>
			<pubDate>Tue, 03 Jul 2012 11:58:21 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11520@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
I wanted to ask if there is a way of getting the IDE to use the new style.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Not for a bit, at least. The IDE doesn't use Make to compile libmaple; it hand-hacks the calls to GCC etc., and the current hacks won't be able to cope with the extra build logic in place for STM32F2.&#60;/p&#62;
&#60;p&#62;I've rewritten big chunks of the IDE build system at least twice now, and I'm getting pretty sick of it, so I'm going to just bite the bullet and teach it how to use Make. If anyone would like to volunteer to help test the results on Windows (say, with a new Wire library...), that'd be great.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=4#post-11510</link>
			<pubDate>Mon, 02 Jul 2012 19:56:28 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">11510@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;It's OK; there weren't many lines to change. Note that editor support for detecting long lines goes a long way. For example, I've configured my text editor to display characters that are past the line length limit in an ugly color, so I notice them immediately.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Actually, the text editor I have, Notepad++, does have this, just it wasn't enabled. So learnt how to set it up from here:&#60;br /&#62;
&#60;a href=&#34;http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Managing_Line_Lengths&#34; rel=&#34;nofollow&#34;&#62;http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Managing_Line_Lengths&#60;/a&#62;&#60;br /&#62;
Now it will highlight everything over 80 characters. The fun thing is, while search I also found it has a white space trim function which will be useful.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;It speeds up cpp when files are included multiple times:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html&#34; rel=&#34;nofollow&#34;&#62;http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html&#60;/a&#62;&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Ah ok, didn't know that, I'll remember that!&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;The warning is for files which don't have a newline at the end, not for files that do ;).&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Fun thing is, removing newlines at the end removed that warning!&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;Please be more specific; &#34;there's a problem&#34; doesn't really tell me anything useful.&#60;/p&#62;
&#60;p&#62;If you're talking about the include style having changed (e.g. #include &#38;lt;libmaple/i2c.h&#38;gt; instead of #include &#34;i2c.h&#34;), there's no fix: the new include style is here to stay. See the blog post for more details:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/2012/07/libmaple-new-include-style-on-the-way/&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/2012/07/libmaple-new-include-style-on-the-way/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Keeping a &#34;backport&#34; of the library for IDE v0.0.12 as you have done is a sensible and nice thing, so thanks for doing it.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Whoops! My bad, shouldn't said that the new include style did not work with the IDE. Sometimes really need to reread my messages an hour after clicking submit. As for the new include style, I have no issues with it, but meant development using the IDE wasn't possible with the same library in libmaple. I wanted to ask if there is a way of getting the IDE to use the new style.&#60;/p&#62;
&#60;p&#62;The 'backport' was the only thing I could think of doing which would allow current users of the IDE to use the new library.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=3#post-11493</link>
			<pubDate>Mon, 02 Jul 2012 13:01:00 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11493@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
Not a problem. I see you touched up the files after the commits, could have sworn I went through and made it 80-column strict. Oh well.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;It's OK; there weren't many lines to change. Note that editor support for detecting long lines goes a long way. For example, I've configured my text editor to display characters that are past the line length limit in an ugly color, so I notice them immediately.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Also what does the include optimisation do exactly?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;It speeds up cpp when files are included multiple times:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html&#34; rel=&#34;nofollow&#34;&#62;http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html&#60;/a&#62;&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Could have sworn that I got a warning or error about new lines at the end of files when I made the patch, which is why I removed them.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;The warning is for files which &#60;em&#62;don't&#60;/em&#62; have a newline at the end, not for files that do ;).&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
EDIT: mbolivar, there is a slight problem when using the library from github with IDE v0.0.12, can you recommend a fix for this?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Please be more specific; &#34;there's a problem&#34; doesn't really tell me anything useful.&#60;/p&#62;
&#60;p&#62;If you're talking about the include style having changed (e.g. &#60;code&#62;#include &#38;lt;libmaple/i2c.h&#38;gt;&#60;/code&#62; instead of &#60;code&#62;#include &#38;quot;i2c.h&#38;quot;&#60;/code&#62;), there's no fix: the new include style is here to stay. See the blog post for more details:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://leaflabs.com/2012/07/libmaple-new-include-style-on-the-way/&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/2012/07/libmaple-new-include-style-on-the-way/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Keeping a &#34;backport&#34; of the library for IDE v0.0.12 as you have done is a sensible and nice thing, so thanks for doing it.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=3#post-11460</link>
			<pubDate>Fri, 29 Jun 2012 21:10:40 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">11460@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Not a problem. I see you touched up the files after the commits, could have sworn I went through and made it 80-column strict. Oh well.&#60;/p&#62;
&#60;p&#62;Also what does the include optimisation do exactly?&#60;br /&#62;
Could have sworn that I got a warning or error about new lines at the end of files when I made the patch, which is why I removed them.&#60;/p&#62;
&#60;p&#62;EDIT: mbolivar, there is a slight problem when using the library from github with IDE v0.0.12, can you recommend a fix for this?&#60;/p&#62;
&#60;p&#62;For others who want to use this library, I've uploaded it here:&#60;br /&#62;
&#60;a href=&#34;http://www.crennsmind.com/Code/Maple/Libraries/WireBase/Wire-120630.zip&#34; rel=&#34;nofollow&#34;&#62;http://www.crennsmind.com/Code/Maple/Libraries/WireBase/Wire-120630.zip&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Unzip the file into the libraries directory.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=3#post-11454</link>
			<pubDate>Fri, 29 Jun 2012 11:42:02 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11454@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Merged. Thanks, crenn!&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/commit/b98596cbda81efeedfb20692b267e10b754a3798&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/commit/b98596cbda81efeedfb20692b267e10b754a3798&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>crenn on "Current beta Wire library implementation with support for hardware I2C"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1033&amp;page=3#post-11451</link>
			<pubDate>Fri, 29 Jun 2012 03:44:12 +0000</pubDate>
			<dc:creator>crenn</dc:creator>
			<guid isPermaLink="false">11451@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Just letting everyone know, the library is due to be included in the master branch of libmaple soon after a few formatting and fixes were done. All future releases of libmaple will include this library (unless a better library is made).
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
