Trinket with accelerometer ADXL335

Adafruit's tiny microcontroller platform. Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Trinket with accelerometer ADXL335

Post by ishback »

I'm using a 3V Trinket board with a 3-axis accelerometer ADXL335, and I'm having trouble measuring the values - they only vary around 0.2V. I'm not using the Voltage Reference which is recommended here https://learn.adafruit.com/adafruit-ana ... uts/wiring but it doesn't seem compulsory. I'm assuming the Trinket doesn't have the pin to use for Reference. I'm using the pins #0 and #2 for a LED matrix, and #3 and #4 for the accelerometer.

Any suggestions? Thanks!

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Trinket with accelerometer ADXL335

Post by Franklin97355 »

Have you followed THESE steps?

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

Yes, note that I pointed to the same link. It describes the connection with an Arduino, which I tried and works fine, but the issue is with the Trinket and the fact that I cannot use the AREF pin.

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Trinket with accelerometer ADXL335

Post by Franklin97355 »

The AREF in the tutorial is to reduce the reference voltage from 5v to 3v so you get better resolution. Since you are using the 3v trinket you are already at that resolution and need do no more.

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

I still have the same trouble. I found out that pin #3 has a tension of 3V, and #4 of 0V, without being connected to the accelerometer, even if they are set up as INPUT. I've read something about one of these pins having a pull-up resistor - is there any way to disable it?

The accelerometer is giving proper readings when disconnected from the Trinket pins (e.g. at 0 degrees Y reads 1.5V, and changes up and down with orientation), but it sticks to 0.5V when connected to the pin #4 and it barely changes with orientation, like there is a tension being forced from the Trinket.

The bit of the code that may have something wrong:

const uint8_t ypin = 2; // A2 is in pin #4 // y-axis
const uint8_t zpin = 3; // A3 is in pin #3 // z-axis

void setup() {
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}

void loop(){
int y = analogRead(ypin);
int z = analogRead(zpin);
// stuff with y and z
}

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Trinket with accelerometer ADXL335

Post by Franklin97355 »

Here is the pinouts and pin usage for the trinket. I'm not sure why you are getting these problems. Could you post clear pictures of your board and the connections to it? And your complete sketch ? Please use the code button "</>" as shown below.
Code Button.jpg
Code Button.jpg (4.49 KiB) Viewed 608 times

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

This is the code:

Code: Select all

#include <TinyWireM.h>
#include "Adafruit_LEDBackpack_Tiny.h"
#include "Adafruit_GFX_Tiny.h"

Adafruit_8x8matrix matrix = Adafruit_8x8matrix();

void setup() {
  //for the pinMode calls, use the Pin number (stenciled on Trinket),
  //for analogRead, use the analog number.
  //Using the PIN number here
  pinMode(3, INPUT);  // y axis 
  pinMode(4, INPUT);  // y axis
  matrix.begin(0x70);
}

void loop(){
  matrix.clear();
  int y = analogRead(3);  //using the ANALOG number here
  int z = analogRead(2);
  
// I display the range using pixels on the LED screen for debugging.

  if (y>0 && y<100){
    matrix.drawPixel(0, 0, LED_ON);  
  } else if (y>=100 && y<200){
    matrix.drawPixel(1, 0, LED_ON);
  } else if (y>=200 && y<300){
    matrix.drawPixel(2, 0, LED_ON);
  } else if (y>=300 && y<400){
    matrix.drawPixel(3, 0, LED_ON);
  } else if (y>=400 && y<500){
    matrix.drawPixel(4, 0, LED_ON);
  } else if (y>=500 && y<600){
    matrix.drawPixel(5, 0, LED_ON);
  } else if (y>=600 && y<700){
    matrix.drawPixel(6, 0, LED_ON);
  } else if (y>=700){
    matrix.drawPixel(7, 0, LED_ON);
  }
  
  if (z>0 && z<100){
    matrix.drawPixel(0, 1, LED_ON);  
  } else if (z>=100 && z<200){
    matrix.drawPixel(1, 1, LED_ON);
  } else if (z>=200 && z<300){
    matrix.drawPixel(2, 1, LED_ON);
  } else if (z>=300 && z<400){
    matrix.drawPixel(3, 1, LED_ON);
  } else if (z>=400 && z<500){
    matrix.drawPixel(4, 1, LED_ON);
  } else if (z>=500 && z<600){
    matrix.drawPixel(5, 1, LED_ON);
  } else if (z>=600 && z<700){
    matrix.drawPixel(6, 1, LED_ON);
  } else if (z>=700){
    matrix.drawPixel(7, 1, LED_ON);
  }
  
  matrix.writeDisplay();
  delay(500);
}
Pics of the connections:

Image

Image

Measured with voltimeter again, same issue - pins have tensions, so readings are not correct. Or if I connect pin #4 to axis Y I get a different reading (or voltage) than if I connect pin #3 to the same axis Y.

Thanks for your help on this!

User avatar
AnneBarela
Learn User Page
 
Posts: 757
Joined: Sat Mar 24, 2012 8:56 pm

Re: Trinket with accelerometer ADXL335

Post by AnneBarela »

Like Franklin says, you have to look atthe Trinket schematic. Pin 3 has a 1.5K pullup for USB, both have a 68 ohm resistor in clamped with a 3.3v diode (Trinket 5V). You need to see what the accelerometer wants to signal, a resistor from pin 3 to ground of the correct size can balance the signal. Be sure when you program Trinket you take it off the breadboard then carefully put it back in the exact place if you have connections on pins 3 & 4 (or remove connections, flash, then remake the connections).

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

Sorry I may be asking silly questions, not super friendly with schematics yet... how can I calculate which resistor I need to balance the signal? Just to understand, adding a resistor to ground will compensate the 1.5K pullup - wouldn't it be 1.5K to ground as well?
The accelerometer give values 0-3.3V, though I think for the acceleration I'd be measuring it will be between 1 and 2.2V. I'm using a 3V trinket.

Thanks!

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

Any suggestions on this?

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

I tried a 1K resistor to balance the pull-up resistor but it clamps the value of the accelerometer at a fix 1,25V. Can someone explain me how to balance the pull-up resistor? It's just about compensating the 1,5K of the pull-up or it has something to do with the 68 ohm resistor too? I couldn't find any information about how to balance a pullup resistor.

I'd appreciate help on this, thanks.

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: Trinket with accelerometer ADXL335

Post by adafruit2 »

We haven't tried the ADXL335 with a trinket - but first up, there's a bunch of pins that need more solder. you should not be able to see any gold pads on solder joints.
Don't forget that the analog pins' names are not the same as the digital pins. Try testing one pin at a time. That's what we can suggest. It may not be able to work but let us know if you solve it!

User avatar
ishback
 
Posts: 33
Joined: Tue Mar 04, 2014 9:50 pm

Re: Trinket with accelerometer ADXL335

Post by ishback »

I've re-soldered and revised all the pins and they're fine. I'm trying to isolate where the issue may be, and as mentioned in previous posts and pointed out by thekitty:
Pin 3 has a 1.5K pullup for USB, both have a 68 ohm resistor in clamped with a 3.3v diode (Trinket 5V). You need to see what the accelerometer wants to signal, a resistor from pin 3 to ground of the correct size can balance the signal.
The rest seems to be fine. The readings of the accelerometer with pin #4 (which doesn't have the pull-up resistor) are coherent, the issue is only with pin #3.

I understand that with a normal Arduino you can disable that internal resistor with code, and you cannot do that with the Trinket. But independently of the hardware and sensors I'm using, I'm just asking some help to understand what's happening and knowing how to solve this isolated issue - balancing a pull-up resistor. Next day I (or someone else) may want to connect another sensor to that pin and I'll run into the same issue.

If it makes more sense, we can more this to a more specific post: "How to balance the pull-up resistor in pin #3 in the Trinket for analog readings."

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: Trinket with accelerometer ADXL335

Post by adafruit2 »

Could be the analog output of the accelerometer is not 'strong enough' to overcome the resistors. if so, you can use an opamp to possibly buffer the signal. or maybe its something else thats a problem...we don't know because we haven't tried this particular combination.

Locked
Please be positive and constructive with your questions and comments.

Return to “Trinket ATTiny, Trinket M0”