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!
Trinket with accelerometer ADXL335
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Trinket with accelerometer ADXL335
Have you followed THESE steps?
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
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.
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Trinket with accelerometer ADXL335
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.
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
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
}
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
}
- Franklin97355
- Posts: 23912
- Joined: Mon Apr 21, 2008 2:33 pm
Re: Trinket with accelerometer ADXL335
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.
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
This is the code:
Pics of the connections:
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!
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);
}
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!
- AnneBarela
- Learn User Page
- Posts: 757
- Joined: Sat Mar 24, 2012 8:56 pm
Re: Trinket with accelerometer ADXL335
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).
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
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!
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!
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
Any suggestions on this?
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
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.
I'd appreciate help on this, thanks.
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Trinket with accelerometer ADXL335
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!
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!
- ishback
- Posts: 33
- Joined: Tue Mar 04, 2014 9:50 pm
Re: Trinket with accelerometer ADXL335
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:
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."
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.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.
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."
- adafruit2
- Posts: 22148
- Joined: Fri Mar 11, 2005 7:36 pm
Re: Trinket with accelerometer ADXL335
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.
Please be positive and constructive with your questions and comments.