Teensy 3 Analog Read

Status
Not open for further replies.

daz1761

Member
Teensy 3 Analog Read: java.lang.OutOfMemoryError: Java heap space

I've connected a 10K pot into my Teensy 3 to test its analog read and output the value to the Arduino serial monitor. I seem to be getting most of the resolution, except when it should read 0 at a steady rate. Instead I get the values between 1 and 1023 rather than 0 to 1023. I've tried a few pots and different analog ins.

Also, when I comment out the 250ms delay to leave no delay at the end of the loop, the Arduino IDE eventually needs to be forced quit (mac) as it seems to struggle with the speed of the loop (baud 9600). I've tried increasing the baud speed, but the problem still persists.

To add, I get a java.lang.OutOfMemoryError: Java heap space
 
Last edited:
Where did you connect the other 2 wires of the pot? Is the ground side connected to GND or AGND. That probably matters.

Sadly, the Arduino software gets overwhelmed by the amount of data Teensy 3.0 can transmit at maximum speed. That java-based software is very inefficient and it seems to leak memory like crazy with incoming data. The same happens if you run such a program on Arduino Due using its native USB port, so this problem is definitely not unique to Teensy. I've looked at that java code several times, hoping to find a solution. But it involves some complex message passing through java's GUI layers. I'm not a java expert when it comes to that stuff, so I've not been able to find any solution. Maybe I'll look again in a month or two, but I'm not hopeful.
 
Thanks for the reply's

Sorry heres my code:

Code:
void setup() {
  
  Serial.begin(38400);
  pinMode(13, OUTPUT);  // use built in Teensy LED
  pinMode(12, INPUT);  // push button
  //digitalWrite(12, HIGH);  // enable internal pull-up resistors
}


void loop() {
  
  int buttonState = digitalRead(12);
  digitalWrite(13, buttonState);
  
  int val = analogRead(14);
  Serial.print("analog 0 is: ");
  Serial.println(val);
  //delay(50);
  
}

It seems to be better with a delay of 50ms, but still i'm unsure why its only reading 1 to 1023. Saying that, I had a go at sending some MIDI messages to Max using the same potentiometer, and my value for the modulation control was steady at 0 to 127 :)

Where did you connect the other 2 wires of the pot? Is the ground side connected to GND or AGND. That probably matters.

Ah, sorry I connected to pin GND right next to pin 0. I had the 3.3v and GND connected to my side rails of my breadboard. I'm a little confused now, does this mean I need to connect the 3.3v, GND and AGND to my breadboard rails? Also how come they are separate? Sorry I'm so used to the Arduino.

So, going back to the Java problem, this is just with the serial monitor and not general performance because my plan is to make a MIDI controller for a uni project and wont be using any delays. If its a serial monitor problem I'll just make sure I stick a small delay in there until the problem is solved.
 
Connect the pot to AGND. That will probably take care of the problem where you can't get to a zero reading.

Thanks, so If I am using digital and analog modules, connect all digital to GND and all analog to AGND? If so is it possible to send both GND and AGND to the power rails of my breadboard? or is it best to assign them to separate rails?
 
analog is 1.pngTeensy.jpg

Yes I literally disconnected from the main GND to AGND. I've attached some pictures to illustrate my current breadboard setup. The switch is controlling the onboard pin 13 LED with a pull-down resistor of 10K.
 
Bumping an old thread. I am having this problem as well. I can only read 1 to 1023. Analog pin tied to AGND or regular ground.
 
Did you adjust the resolution? IIRC, the default is 10 bits, so a 0-1023 range would make sense. In other words, please post your code as well.
 
I am using the basic code found here: https://www.pjrc.com/teensy/tutorial4.html
at default resolution the range is 1 to 1023.
at 8 bits resolution the lowest value is still 1.
at 16 bits resolution the low value jumps around from 0 to 3. This is most prevalent on A0 and A1. What's interesting is that at 16 bits some of the other analog pins (A3-A5) are steady at 0.

I feel like this is a noise issue but just not sure what to do about it. Analog to AGND should be zero no?
 
Status
Not open for further replies.
Back
Top