Show Posts
Pages: [1] 2 3 ... 5
1  Forum 2005-2010 (read only) / Troubleshooting / Re: Wire and OneWire conflicts? on: April 01, 2007, 01:31:45 pm
I got DS1631 behaving both with Wire and software i2c.  Here's the Wire code:

Code:
#include <Wire.h>
void setup()
{
  Wire.begin();
  Serial.begin(19200);
}

void loop() {
  ds1631();
}

void ds1631() {
  uint8_t ret, dhi, dlo;
  Wire.beginTransmission(0x48);
  Wire.send(0x51);
  Wire.endTransmission();
  delay(750);
  Wire.beginTransmission(0x48);
  Wire.send(0xAA);  // read temperature command...
  Wire.endTransmission();
  Wire.requestFrom(0x48, 2);
  dhi = Wire.receive();
  dlo = Wire.receive();
  Wire.endTransmission();
  int ihi = (int) (dhi);
  int ilo = (int) (dlo);
  int frac =  ihi * 256 + ilo;
  if (dhi > 0x80) frac = frac - 65536;
  int temp = frac/256;
  frac = frac - temp*256;
  Serial.print(" Temp (C) = ");
  Serial.print(temp);
  Serial.print(".");
  if(frac < 100) Serial.print("0");
  if(frac < 10) Serial.print("0");
  Serial.println(frac);
}


Wire has no means to do a repeated start, as the 1631 wants, it won'd send anything unless you do a stop, but it works OK even with the stop.

D.
2  Forum 2005-2010 (read only) / Troubleshooting / Re: Wire and OneWire conflicts? on: March 22, 2007, 03:36:00 pm
I agree - OneWire seems to work smoothly, although I have only tried it with 3 ds18S20's.  But they have a number of other devices that use onewire - I ordered a few and will try them out when they arrive.  

The problems with i2c using wire are device-specific.  It works fine with the ds1307 clock, but not with the eeprom or the compass sensor I'm using.  Next week I'll have an oscilloscope and I'll keep working on i2c until figure out what's funky.

It was your post that made me aware that OneWire exists, and it is really neat and workable for Arduino.  Thanks!
3  Forum 2005-2010 (read only) / Troubleshooting / Re: Wire and OneWire conflicts? on: March 21, 2007, 05:18:58 pm
OK - at least we are both getting similar results.  I looked at the Wire code and it seems to happily give you the buffer back even if it never received anything.  I will keep working on this.

BTW - were you able to find DS1631 in DIP format?  Where??
4  Forum 2005-2010 (read only) / Troubleshooting / Re: Wire and OneWire conflicts? on: March 21, 2007, 02:12:18 pm
Hi bdmatic,

I am still having trouble making the 24lc256 work.  I have it hooked up the same way you do, only my datasheet seems to want 0xA0 for an address.  Either way it won't work.  What I did was run your code once, then comment out the call to writestuff and try it again.  The data should still be there, but it isn't - only the address bytes I wrote to the eeprom.  I'd be interested to see if you get the same result or not.  One difference is I have 3 devices on my i2c bus, and I'm trying to make them all work at once.  Wire will work with one (a ds1307 clock) but not with the eeprom or a compass module.  Some other i2c code I am trying works with the compass, but not the clock or the eeprom.

Have you tried any other i2c devices?  

D.
5  Forum 2005-2010 (read only) / Troubleshooting / Re: Wire and OneWire conflicts? on: March 18, 2007, 06:35:34 pm
Hi bdmatic,

I tried out your code for the ds18s20 sensor, and it worked fine with OneWire - thanks!.  I am having some trouble with i2c, so I tried your code with the 24LC256, and it seemed to work fine, but I realized Wire uses the same buffer for write and read, so I zeroed it out after the write, and it came back zero.  Maybe my eeprom is hooked up wrong, but could you try this and verify the eeprom read is working?

The ds18s20 is a really cool device!

D.
6  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Bug with TWI/i2c and Atmega168 on: May 16, 2007, 02:44:41 pm
Hi mellis,

The Wire lib works fine on my 168's without making the above change.  I did recompile, because I was having a different problem, so can't confirm if the original .o works as is.

D.
7  Forum 2005-2010 (read only) / Bugs & Suggestions / Serial output to a file on: February 27, 2007, 06:14:49 pm
One thing that might be quite useful would be to direct serial output from Arduino to a specified file.  So instead of opening a serial window, you could direct the same output to a file.

This would be really useful for an application I'm working on, in which I need to take Arduino for an airplane ride, and log a bunch of sensor readings.  Then, on the ground, I could work with the processing of the sensor data.

Sound useful?

D.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Basic issue using Wire library with Arduino on: May 09, 2007, 03:32:07 pm
I found this link helpful: http://research.techkwondo.com/blog/julian/279  - you may need to make a change to the Wire library to get it to use the proper pins for the 168.  I have gotten Wire to work fine with the DS1631, and am happy to give you that code - the major difference is the temperature resolution.  I've also written a software I2C library that can use any pins you want - it's quite a bit smaller than Wire also.

D
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to convert analogRead value from accelerom on: March 04, 2007, 08:35:39 am
You can use float variables.  You may need to include math.h for some functions.  Like so:

float gvalue, adc;

adc = (float)(ADCvalue);
gvalue = ((adc*3.0)/1024.-1.5))/3.0;

Floating point takes a while on the ATMega, so be careful about timing.

D.
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to convert analogRead value from accelerom on: March 03, 2007, 08:28:22 pm
No!  The 330 is a 3v device, so don't feed it 5v - you might fry it.  If you aren't reading any 5v analog devices I think you can connect the 3v to aref.  Be careful - I don't know your situation, and I might be wrong.

I'll look for better information, and get back to you.

D.
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to convert analogRead value from accelerom on: March 03, 2007, 06:30:20 pm
What I tried was 512 samples at 20 ms apart, and use a long variable to accumulate it into, so as not to overflow a 16-bit int.  I'm wanting to make a IMU to take flying, mainly for attitude reference.  These little sensors are very neat!  I'm also using some ADRSX401 gyro/rate sensors, which are 5v devices, so the aref thing gets complicated.  

If you are doing IMU stuff, there's good info over Spark Fun forum.

D.
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to convert analogRead value from accelerom on: March 03, 2007, 02:38:49 pm
I should have mentioned that aref needs to be connected to 3v to use the entire 0-1023 range.  Otherwise 1023 will mean 5v and -3 to +3G will in the first 3/5 of that range.

D.
13  Forum 2005-2010 (read only) / Syntax & Programs / Re: How to convert analogRead value from accelerom on: March 03, 2007, 09:26:54 am
I have the same type accelerometer, and I find I need to calibrate each axis for -1, 0, and 1 G.  You can do this by orienting the accelerometer with each axis pointing up, down, or sideways, and averaging a large number of samples.  Ideally, 0 should be -3 G, 511 should be zero G and 1023 should be +3 G, but I find they're each a little different.

Have fun!

D.
14  Forum 2005-2010 (read only) / Interfacing / Re: ADXL320 and ATMEGA88 on: May 10, 2007, 01:55:45 pm
My readings for the ADXL330 don't jump by more than +-1 unless there is vibration or it is sitting on something unsteady.  One thing I found helped was to wire the voltage supplied to the accelerometer to the AREF pin, and add this to your defs:

Code:
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

Then put this in your setup function:

Code:
 
  cbi(ADMUX, REFS1); //clear REFS1 bit (0)
  cbi(ADMUX, REFS0); //clear REFS0 bit (0)

I had to do this since the ADXL330 is a 3.3v part, but it seemed to improve the ADC results.  I have read recommendations to put a capacitor between AREF and GND to filter out noise, but haven't found it necessary.

Another issue is that the output impedence of the accelerometer may be higher than the input impedence of the ADC, leading to bad data.  This can be fixed adding a buffer (just an op amp with a gain of 1, but lower impedence output) between the accelerometer and ADC.  I have good results using a MCP6004 (they still make a DIP version!!).

I found this link pretty educational about buffers and ADC's: http://www.maxim-ic.com/appnotes.cfm/an_pk/1094

Are you powering your project with USB?  It can be pretty noisy.

D.
15  Forum 2005-2010 (read only) / Interfacing / Re: ADXL320 and ATMEGA88 on: May 09, 2007, 01:26:18 pm
You are correct - but the lack of resolution is due to the 10-bit ADC, not the accelerometer itself.  You could use an external ADC with more resolution, say 12 or 16 bits, or use an accelerometer with a built-in ADC and a digital interface.  The LIS3LV020Q is pretty nice and will give you 1 milli-G resolution using either I2C or SPI, and you don't have to worry about buffering and hooking up a separate ADC chip.

I have a ADXL330, which is a 3-axis +-3g accelerometer, so resolution on the 10-bit ADC is about 1/100 G - not bad, but I think the device is more accurate than that, and a 12-bit ADC would help.

Good luck,

D.
Pages: [1] 2 3 ... 5