<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nate&#039;s blog &#187; Arduino</title>
	<atom:link href="http://www.natenewz.com/category/electronic-projects/arduino-electronic-projects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.natenewz.com</link>
	<description>My various projects</description>
	<lastBuildDate>Wed, 27 Oct 2010 00:07:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Accelerometer on Robot Finger</title>
		<link>http://www.natenewz.com/2009/10/12/accelerometer-on-robot-finger/</link>
		<comments>http://www.natenewz.com/2009/10/12/accelerometer-on-robot-finger/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 14:32:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Electronic Projects]]></category>
		<category><![CDATA[accelerometer]]></category>
		<category><![CDATA[adxl345]]></category>
		<category><![CDATA[arduino]]></category>
		<category><![CDATA[atmega 328]]></category>
		<category><![CDATA[brink]]></category>
		<category><![CDATA[i2c]]></category>
		<category><![CDATA[ISU robot]]></category>
		<category><![CDATA[robot]]></category>

		<guid isPermaLink="false">http://www.natenewz.com/blog/?p=53</guid>
		<description><![CDATA[I helped attach an accelerometer to a robot at ISU, which has  been featured on Discovery Channels show, Brink.

We used an adxl345 digital accelerometer with the breakout board from sparkfun.com, in addition to an arduino.
We used the I^2c wire arduino library. This was a temporary solution so that the research assistants can gather surface [...]]]></description>
			<content:encoded><![CDATA[<p>I helped attach an accelerometer to a robot at ISU, which has  been featured on Discovery Channels show, <a title="Episode of Brink with IASTATE Robot" href="http://science.discovery.com/videos/brink-package-robots-become-human.html" target="_blank">Brink</a>.</p>
<div id="attachment_57" class="wp-caption left" style="width: 310px"><img class="size-medium wp-image-57" title="robot-arm" src="http://www.natenewz.com/wp-content/uploads/2009/10/robot-arm-300x225.jpg" alt="arduino taped onto robots arm" width="300" height="225" /><p class="wp-caption-text">arduino taped onto robots arm</p></div>
<p><div id="attachment_60" class="wp-caption left" style="width: 310px"><img class="size-medium wp-image-60" title="robot-finger" src="http://www.natenewz.com/wp-content/uploads/2009/10/robot-finger-300x225.jpg" alt="Accelerometer taped onto robot finger" width="300" height="225" /><p class="wp-caption-text">Accelerometer taped onto robot finger</p></div><br />
<br style="clear: both;" /></p>
<p>We used an adxl345 digital accelerometer with the breakout board from sparkfun.com, in addition to an arduino.</p>
<p>We used the I^2c wire arduino library. This was a temporary solution so that the research assistants can gather surface texture data to see if it is possible to categorize surfaces based on touch, essentially giving the robot a sense of touch similiar to our fingers.</p>
<p>The final project will most likely include several accelerometers and some sort of pic, hopefully sampling at 1200 Hz, the maximum sampling rate of the accelerometer.</p>
<p>We were only able to sample at 500 Hz max. The limiting factor was the serial port speed. 230400 baud was the highest speed we could use without getting gibberish input on the serial port. This proves that it is possible to go past what the Arduino documentation  for the serial library says <a title="serial library" href="http://www.arduino.cc/en/Serial/Begin" target="_blank">here.</a></p>
<p>We also noticed that the variance increased with the frequency, and so the usefulness of the higher sampling rate obtaining more data is still being analyzed.</p>
<p>The two signal wires are connected to analog in 4, and 5<br />
The two interrupt wires are open<br />
The rest are either held high, or low at 3.3V and Gnd off of the arduino.</p>
<p>Here is the arduino code we created:</p>
<pre id="C" class="prettyprint">
/* The MIT License

Copyright (c) <2009> < Vlad Sukhoy <sukhoy@iastate.edu>, Joe Coleman <jcoleman@iastate.edu>, Ritika Sahai <ritika@iastate.edu>, Nate Nuzum <natenewz@iastate.edu>>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
/*
 * Arduino Duemilanove programming to read the data from ADXL345 accelerometer.
 * This code is a part of tactile sense implementation in rc.
 *
 * It is not advised to use this code at data rates above 400 Hz (bandwidth = 200 Hz)
 * as Arduino serial I/O cannot keep up with the accelerometer at those bandwidths.
 * The actual data rate we can achieve is about 500 Hz, however the accelerometer
 * only supports data rates <= 400 Hz or >= 800 Hz, so we cannot get 500 Hz without
 * discarding some of the data.
 *
 * Using binary coding we might be able to actually transfer at 800 Hz.
 * Using compression we might be able to transfer however much we like, but this
 * will depend on the properties of the data stream.
 *
 * In scratching study we might not really need all 3 vectors, but the magnitude of the
 * deviation from g. Unfortunately, as the device might turn we don't really
 * know where g points to, so we smooth the acceleration vector and use that value
 * for g. If we settle down on that logic, it can be pushed down to Arduino and then we
 * only need to transfer one value per measurement which, together with binary coding
 * and/or compression should put us at 2000+ Hz.
 *
 * Authors:
 * Vlad Sukhoy <sukhoy@iastate.edu>
 * Joe Coleman <jcoleman@iastate.edu>
 * Ritika Sahai <ritika@iastate.edu>
 * Nate Nuzum <natenewz@iastate.edu>
 */

#include < Wire.h >

// The address of the accelerometer device in terms of Arduino board
#define ADXL_ADDR ((byte)0x1d)
// The bandwidth to use for the serial port
// It appears that Duemilanove only supports up to 230400 bits per second
#define SERIAL_BANDWIDTH 230400
#define BUFSIZE 1024

enum registers {
 power_ctl   = 0x2d,
 bw_rate     = 0x2c,
 data_format = 0x31,
 datax0      = 0x32,
 datax1,
 datay0,
 datay1,
 dataz0,
 dataz1,
 fifo_ctl    = 0x38,
 fifo_status = 0x39
};

// bits for the POWER_CTL register
enum power_ctl {
 pc_link        = (1 << 5),
 pc_auto_sleep  = (1 << 4),
 pc_measure     = (1 << 3),
 pc_sleep       = (1 << 2),
 pc_wakeup_mask = 3,
 // Frequency of readings in sleep mode
 pc_wakeup_8hz  = 0,
 pc_wakeup_4hz  = 1,
 pc_wakeup_2hz  = 2,
 pc_wakeup_1hz  = 3
};

// bits and masks for the BW_RATE register
enum bw_rate {
 bw_low_power   = (1 << 4),
 bw_rate_mask   = 0xf,
 // low power modes, the number of Hz is the bandwidth. the data rate is 2x that
 bw_lp_200hz    = bw_low_power | 0xc,
 bw_lp_100hz    = bw_low_power | 0xb,
 bw_lp_50hz     = bw_low_power | 0xa,
 bw_lp_25hz     = bw_low_power | 0x9,
 pw_lp_12dot5hz = bw_low_power | 0x8,
 pw_lp_6dot25hz = bw_low_power | 0x7,
 // regular modes
 bw_1600hz = 0xf, bw_800hz = 0xe, bw_400hz = 0xd, bw_200hz = 0xc, bw_100hz = 0xb,
 bw_50hz = 0xa, bw_25hz = 0x9, bw_12dot5hz = 0x8, bw_6dot25hz = 0x7,
 bw_3dot125hz = 0x6
};

// bits and masks for the DATA_FORMAT register
enum data_format {
 df_self_test  = (1 << 7),
 df_spi        = (1 << 6),
 df_int_invert = (1 << 5),
 df_full_res   = (1 << 3),
 df_justify    = (1 << 2),
 df_range_mask = 0x3,
 df_range_2g   = 0x0,
 df_range_4g   = 0x1,
 df_range_8g   = 0x2,
 df_range_16g  = 0x3
};

enum fifo_ctl {
 fc_mode_bypass  = 0,
 fc_mode_fifo    = (1 << 6),
 fc_mode_stream  = (1 << 7),
 fc_mode_trigger = (3 << 6),
 fc_trigger      = (1 << 5),
 fc_samples_mask = 0x1f,
 fc_samples_32   = 0x1f
};

enum fifo_status {
 fs_fifo_trig    = (1 << 7),
 fs_entries_mask = 0x3f
};

// transmit a register value to the accelerometer
static inline void reg_set(byte regid, byte value) {
 Wire.beginTransmission(ADXL_ADDR);
 byte data[] = {regid, value};
 Wire.send(data, sizeof(data)/sizeof(data[0]));
 Wire.endTransmission();
}

// receive a register value from the accelerometer
static inline byte reg_get(byte regid) {
 Wire.beginTransmission(ADXL_ADDR);
 Wire.send(regid);
 Wire.endTransmission();
 Wire.requestFrom(ADXL_ADDR, (byte)1);
 return Wire.receive();
}

static inline byte fifo_entries() { return reg_get(fifo_status) &amp; fs_entries_mask; }

// one accelerometer measurement
struct measurement {
 int16_t data[3];
};

static inline struct measurement reading() {
 // read 6 bytes from the accelerometer data registers and put the bytes in order
 struct measurement rv;
 Wire.beginTransmission(ADXL_ADDR);
 Wire.send(datax0);
 Wire.endTransmission();
 Wire.requestFrom(ADXL_ADDR, (byte)6);
 int i;
 byte lsb, msb;
 for (i=0; i< sizeof(rv.data)/sizeof(rv.data[0]); ++i) {
   lsb = Wire.receive();
   msb = Wire.receive();
   rv.data[i] = (((int16_t)msb) < < 8) | lsb;
 }
 return rv;
}

void setup() {
 Serial.begin(SERIAL_BANDWIDTH);
 Wire.begin(); // Join I2C bus as a master

 reg_set(power_ctl, 0);             // stand by
 reg_set(bw_rate, bw_200hz);        // bandwidth
 reg_set(data_format, df_range_2g); // request 2g resolution
 reg_set(fifo_ctl, fc_mode_fifo | fc_samples_32); // request 32 entry FIFO (max)
 reg_set(power_ctl, pc_measure);    // start measuring
}

void loop() {
 byte  n, b[BUFSIZE];
 int  bsz = 0;
 struct measurement m;
 while ((n = fifo_entries())) {
   while (n--) {
     m = reading();
     bsz += sprintf((char*)&amp;b[bsz], "%d\t%d\t%d\r\n", (int)m.data[0], (int)m.data[1],
       (int)m.data[2]);
     if (bsz > BUFSIZE - 30)
       goto quit;
   }
 }
 quit:
 Serial.write(b, bsz);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.natenewz.com/2009/10/12/accelerometer-on-robot-finger/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

