Pages: 1 [2] 3   Go Down
Author Topic: bma180 accelerometer  (Read 4635 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

- oops, seems that you are also missing the connection to VIO? Connect it to your 3.3V rail, as well as CS... .

- cpixip
« Last Edit: March 16, 2011, 02:55:09 am by cpixip » Logged

Italy
Offline Offline
Full Member
***
Karma: 3
Posts: 142
jayduino rox
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, I wired it exactly as shown but I still get that one line. I checked all the lines for shorts and it all looks ok

As shown? Which one? The real world jpgs from one of my posts are different from the hand painted wiring scheme you posted before. So I would recheck them one by one.
Logged

Juergen

Offline Offline
Jr. Member
**
Karma: 0
Posts: 72
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

- you might try to use the prg found under http://todbot.com/blog/2009/11/29/i2cscanner-pde-arduino-as-i2c-bus-scanner/, i2cscanner.pde, to check whether you get any response from the chip at all. This scanner should find the appropriate I2C-address active. If you do not see any "found"-indicator, either your setup is wrong or your chip is defective.

- cpixip
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wired the setup exactly as your real world jpgs showed. I will try the i2c scanner after work. Is there nay explanation as to why I would get that one line from the serial monitor and then nothing else? Also I tried switching the #4 and #5 pins on the arduino and still nothing. Where are those supposed to be wired?
Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which Arduino are you using? I presume that you are using the dedicated I2C (TWI) Lines...

If you can post a picture of your hookup and draw and scan a schematic of what you did that would be the most helpful.

Even if you have to draw thew schematic and take a photo... Just use bold markers to do the drawing.  smiley

Logged

Just another Hacker

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using an arduino Uno, i2c pins are analog 4 and 5. I will take a picture later tonight and draw a schematic. I really appreciate all the help! This sensor has been giving me a headache!
Logged

Italy
Offline Offline
Full Member
***
Karma: 3
Posts: 142
jayduino rox
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I wired the setup exactly as your real world jpgs showed. I will try the i2c scanner after work. Is there nay explanation as to why I would get that one line from the serial monitor and then nothing else?

Sure, the example tries to get the serial ID and prints it. There is not much of error handling there.
Then it sits duck because the arduino is not receiving interrupts from the BMA (on digital pin2 or pin3). That could have multiple reasons: the interrupt is not the right pin or the setup wasn't able to tell your sensor to send interrupts.

Try commenting the if (newdata) line in the loop, and if you get some good readings, there is something wrong with the interrupt.

Also try to measure the voltage levels of the BMA180, VDD/VIO is 3.3 and exchanging the 3.3 with 5 is much too easy on the UNO. Check the CS (=VDD) and SDO(GND).

Quote
Also I tried switching the #4 and #5 pins on the arduino and still nothing. Where are those supposed to be wired?

analog 4 and 5 are the I2C lines! 5 must be CLK and 4 SDI (through the voltage conversion!).

Logged

Juergen

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Double checked all the wiring, its all good. All voltage is good.  I took out the if newdata and the #debugon cuase i didnt understand it and it reads the data, but its all zeros, [ 0 0 0 ]. I wonder what the problem is? Do i have to define the interrupt pin? I am using pin 2...
« Last Edit: March 16, 2011, 06:05:55 pm by Albino Cobra » Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If newdata -- reads the "Interrupt" from the Sensor that says that there is newdata.

This is the code as Jurgen Provided...

I added some comments. Do they help?

Code:
/* $Id: isr_read.pde 2011-01-30 06:36:00Z scjurgen@yahoo.com $

  Example for using the BMA180 class

  Written by Jurgen Schwietering
  http://www.schwietering.com/jayduino
  scjurgen@yahoo.com

    This library is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

****/

#include <Wire.h>
#include <bma180.h>

// You could remove the # and see if it prints the setup data
#define DEBUGON

BMA180 bma180;



volatile byte newData=0;
volatile unsigned int countISR=0;
unsigned int served=0;

void BMAISR(void)
{
   countISR++;
   //bma180.readAccel();
   newData=1;
// ****************************************
// This is the interrupt routine that should be fired because you have a wire from pin 3 of the Breakout board
//  to the correct pin on the arduino (Mega 2560 is 2 for ISR0 or three for ISR1)
//**************************
}

void setup()
{
  Wire.begin();
  Serial.begin(9600);

  // maybe the default address got changed... I think it is "3" yes confirmed... it is 3
  // ******************************************************************

  bma180.setAddress((int)BMA180_DEFAULT_ADDRESS);
  bma180.softReset();
  bma180.enableWrite();
  int sversion;
  int id;

  // This following line gets the version....

  bma180.getIDs(&id,&sversion);

  Serial.print("Id = ");
  Serial.print(id,DEC);
  Serial.print(" v.");
  Serial.println(sversion,HEX);

  bma180.setFilter(bma180.F10HZ);
  bma180.setGSensitivity(bma180.G15); // lets put 1.5 G maximum, not doing tests in a space shuttle

 //   ATTACH INTERRUPT to ISRPin 0 or the Pin 2 on the Mega 2560.... I have it on ISR 1 or Pin 3..
 //  Just make sure they match....
 
  attachInterrupt(0, BMAISR, RISING);

  bma180.setSMPSkip();
  bma180.setISRMode();
  bma180.disableWrite();
  delay(2000);
}

unsigned long tAlive;

void loop()
{

  // The ISR Routine set newData to 1 if there was data
  // so yes you could remove it and the two brackets...
// You could also get rid of the "mod 8" routine and just put in a delay to slow things down...

  if (newData)
  {
    
      newData=0;

      // the next line is the one that puts the data into the registers....

      bma180.readAccel();
      served++;
      if (served % 8==0) // skip some data...
      {
          
         // If the read above worked then you have data...
          Serial.print("[");
          Serial.print(bma180.x,DEC);
          Serial.print(" ");
          Serial.print(bma180.y,DEC);
          Serial.print(" ");
          Serial.print(bma180.z,DEC);
          Serial.println("]");
      }
  }
 #ifdef DEBUGON
  if (millis() > tAlive)
  {
     bma180.readAccel();
      Serial.print("ISR's=");
      Serial.print(countISR);
      Serial.print(" served=");
      Serial.println(served);
      Serial.print("t=");
      Serial.print(bma180.temp);
      Serial.print("[");
      Serial.print(bma180.x,DEC);
      Serial.print(" ");
      Serial.print(bma180.y,DEC);
      Serial.print(" ");
      Serial.print(bma180.z,DEC);
      Serial.println("]");

     tAlive=millis()+5000;
     Serial.print("filter reg=");
     Serial.println(bma180.getRegValue(0x20),BIN);
     Serial.print("status_reg1=");
     Serial.println(bma180.getRegValue(0x09),BIN);
     Serial.print("status_reg2=");
     Serial.println(bma180.getRegValue(0x0A),BIN);
     Serial.print("status_reg3=");
     Serial.println(bma180.getRegValue(0x0B),BIN);
     Serial.print("status_reg4=");
     Serial.println(bma180.getRegValue(0x0C),BIN);
     Serial.print("ctrl_reg0=");
     Serial.println(bma180.getRegValue(0x0d),BIN);
     Serial.print("ctrl_reg1=");
     Serial.println(bma180.getRegValue(0x0e),BIN);
     Serial.print("ctrl_reg2=");
     Serial.println(bma180.getRegValue(0x0f),BIN);
     Serial.print("ctrl_reg3=");
     Serial.println(bma180.getRegValue(0x21),BIN);
     Serial.print("ctrl_reg4=");
     Serial.println(bma180.getRegValue(0x22),BIN);
 }
 #endif
}

Logged

Just another Hacker

Italy
Offline Offline
Full Member
***
Karma: 3
Posts: 142
jayduino rox
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

you wrote this as a comment:

Code:
// maybe the default address got changed... I think it is "3" yes confirmed... it is 3
3 is not the default address, it is 0x40
3 is the chip_id that the BMA180 should report back (Id=3h and version 12h).

Did you try the i2c scanner that was mentioned in a previous posting by cpixip?
If it reports back that something is listening on the I2C bus you should be up and running soon.
Logged

Juergen

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The scanner pde wont compile in the arduino ide. I forgot the error is throws at me since I am not on my computer, I will post it when i am back home. Also , newb question but what is the interrupt? And how do I know what pin to put it in?
« Last Edit: March 16, 2011, 07:14:48 pm by Albino Cobra » Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you wrote this as a comment:

Code:
// maybe the default address got changed... I think it is "3" yes confirmed... it is 3
3 is not the default address, it is 0x40
3 is the chip_id that the BMA180 should report back (Id=3h and version 12h).

Did you try the i2c scanner that was mentioned in a previous posting by cpixip?
If it reports back that something is listening on the I2C bus you should be up and running soon.

I think I will plead carelessness and let it go at that... I was being summoned for dinner. Clearly my mind was on more important things.  smiley-roll-sweat  Yes, 0x40 it is...



Logged

Just another Hacker

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is a minor revision of the scanner which will print the addresses in HEX so you don't have to think as hard...

It checks from 01 to 127 (7 Bit Addresses)


Code:
/**
 * I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */

#include "Wire.h"
extern "C" {
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

// Scan the I2C bus between addresses from_addr and to_addr.
// On each address, call the callback function with the address and result.
// If result==0, address was found, otherwise, address wasn't found
// (can use result to potentially get other status on the I2C bus, see twi.c)
// Assumes Wire.begin() has already been called

void scanI2CBus(byte from_addr, byte to_addr,
                void(*callback)(byte address, byte result) )
{
  byte rc;
  byte data = 0; // not used, just an address to feed to twi_writeTo()
 
  for( byte addr = from_addr; addr <= to_addr; addr++ ) {
    rc = twi_writeTo(addr, &data, 0, 1);
    callback( addr, rc );
  }
}

// Called when address is found in scanI2CBus()
// Feel free to change this as needed
// (like adding I2C comm code to figure out what kind of I2C device is there)
void scanFunc( byte addr, byte result ) {
  Serial.print("addr: ");
  Serial.print(addr,HEX);
  Serial.print( (result==0) ? " found!":"       ");
  Serial.print( (addr%4) ? "\t":"\n");
}


byte start_address = 01;
byte end_address = 127;

// standard Arduino setup()
void setup()
{
    Wire.begin();

    Serial.begin(19200);
    Serial.println("\nI2CScanner ready!");

    Serial.print("starting scanning of I2C bus from ");
    Serial.print(start_address,HEX);
    Serial.print(" to ");
    Serial.print(end_address,HEX);
    Serial.println("...");

    // start the scan, will call "scanFunc()" on result from each address
    scanI2CBus( start_address, end_address, scanFunc );

    Serial.println("\ndone");
}

// standard Arduino loop()
void loop()
{
    // Nothing to do here, so we'll just blink the built-in LED
    digitalWrite(13,HIGH);
    delay(300);
    digitalWrite(13,LOW);
    delay(300);
}

Here is my output...

Code:
starting scanning of I2C bus from 0 to 7F...
addr:
addr: 1        addr: 2        addr: 3        addr: 4       
addr: 5        addr: 6        addr: 7        addr: 8       
addr: 9        addr: A        addr: B        addr: C       
addr: D        addr: E        addr: F        addr: 10       
addr: 11        addr: 12        addr: 13        addr: 14       
addr: 15        addr: 16        addr: 17        addr: 18       
addr: 19        addr: 1A        addr: 1B        addr: 1C       
addr: 1D        addr: 1E        addr: 1F        addr: 20 found!
addr: 21        addr: 22        addr: 23        addr: 24       
addr: 25        addr: 26        addr: 27        addr: 28       
addr: 29        addr: 2A        addr: 2B        addr: 2C       
addr: 2D        addr: 2E        addr: 2F        addr: 30       
addr: 31        addr: 32        addr: 33        addr: 34       
addr: 35        addr: 36        addr: 37        addr: 38       
addr: 39        addr: 3A        addr: 3B        addr: 3C       
addr: 3D        addr: 3E        addr: 3F        addr: 40 found!
addr: 41        addr: 42        addr: 43        addr: 44       
addr: 45        addr: 46        addr: 47        addr: 48       
addr: 49        addr: 4A        addr: 4B        addr: 4C       
addr: 4D        addr: 4E        addr: 4F        addr: 50       
addr: 51        addr: 52        addr: 53        addr: 54       
addr: 55        addr: 56        addr: 57        addr: 58       
addr: 59        addr: 5A        addr: 5B        addr: 5C       
addr: 5D        addr: 5E        addr: 5F        addr: 60       
addr: 61        addr: 62        addr: 63        addr: 64       
addr: 65        addr: 66        addr: 67        addr: 68 found!
addr: 69        addr: 6A        addr: 6B        addr: 6C       
addr: 6D        addr: 6E        addr: 6F        addr: 70       
addr: 71        addr: 72        addr: 73        addr: 74       
addr: 75        addr: 76        addr: 77 found! addr: 78       
addr: 79        addr: 7A        addr: 7B        addr: 7C       
addr: 7D        addr: 7E        addr: 7F       
done

0x20 GPD212
0x40 BMA180
0x68 DS1307
0X77 BMP085

The DS18B20 on the One Wire hooked to the I2C is not reporting in...


Logged

Just another Hacker

0
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so I got the scanner working right, however it does not find any addresses.

I re-loaded the sketch for the bma and now it shows the status and control reg along with t=[0 0 0]
Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok so I got the scanner working right, however it does not find any addresses.

I re-loaded the sketch for the bma and now it shows the status and control reg along with t=[0 0 0]

Maybe you have a fried (wrecked) BMA180 -- or just a simple wiring error.  Check, then double check --- and the easiest method is....

Go have a coffee, daydream for a while then come back, recite Ohms law (To frighten the computer) and find your wiring error.

If the scanner does not see the chip -- then you know the problem....
Logged

Just another Hacker

Pages: 1 [2] 3   Go Up
Jump to: