Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 14 of 14

Thread: Teensy 3 Analog Read

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    8

    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 by daz1761; 12-07-2013 at 03:10 PM.

  2. #2
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    It is hard to diagnose problems without any code, so please post the complete code.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    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.

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    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.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    Connect the pot to AGND. That will probably take care of the problem where you can't get to a zero reading.

  6. #6
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Quote Originally Posted by PaulStoffregen View Post
    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?

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Just to add, I've tried using the AGND and there is no difference.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    If you disconnect the pot and connect the pin directly to AGND, do you get a zero reading?

  9. #9
    Junior Member
    Join Date
    Dec 2013
    Posts
    8
    Name:  analog is 1.png
Views: 898
Size:  8.1 KBClick image for larger version. 

Name:	Teensy.jpg 
Views:	225 
Size:	135.6 KB 
ID:	1172

    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.

  10. #10
    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.

  11. #11
    Senior Member Constantin's Avatar
    Join Date
    Nov 2012
    Location
    In the yard with a 17' Dia. Ferris Wheel
    Posts
    1,408
    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.

  12. #12
    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?

  13. #13
    Senior Member
    Join Date
    Jun 2013
    Location
    So. Calif
    Posts
    2,828
    With ADCs, don't expect perfection in the data counts. There's always at least on bit of jitter.

  14. #14
    Yea i just wish the Jitter was on the other end. Oh well. Suppose I can put in an offset/ calibration.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •