Can't turn off pull-up resistors on 3.2?

Status
Not open for further replies.

Kyub

New member
I've just started a new project with the Teensy 3.2 where I am rolling my own capacitive sensor. When I set the pins to input, the pull up resistor seems to come without using PULL-UP. I have tried several different pins to the same effect. I'm a long-time Teensy 2 user and think I have done this before on the 2.0 with no problem.

Here is a simplified program that I tried. The circuit is a 100 M resistor from pin 19 to 22, with oscilliscope on pin 22 which shows a continous high state (small voltage divider effect ripple). Pin 19 shows the expected square wave. Thanks for any insight.

Teensyduino 1.42/ Teensy 3.2/ 96MHz/USB MIDI


Code:
//teensy 3.2
long int lasttime=0;
const int driver = 19;
const int in = 22;
bool toggle = false;

//********setup***************
void setup()
{
  pinMode(driver, OUTPUT);
  pinMode(in, INPUT);
  //digitalWrite(in, LOW); //tried this too, no luck
}

//*********Main Loop ***************
void loop()
{
  //**************************************************
  if (millis() > lasttime) //run this once every 2000 ms
  {
    lasttime = millis() + 2000;
    if (toggle == true)
    {
      digitalWrite(driver, HIGH);
      toggle = false;
    }
    else
    {
      digitalWrite(driver, LOW);
      toggle = true;
    }

  }

}// end of main
 
Last edited by a moderator:
Is there a picture of the setup? How was it determined there was an active PULL_UP voltage?

The code doesn't show any attempt to read the "in" pin value?
 
Paul:: Other that a mention on the CapacitiveSensor page I don't find touchRead() documented??? … just a source tree function ...

This sketch is working for me to tell when I touch a wire/resistor in a female header on pin 22. It has extra feedback (more than needed?) to know more about what is going on:
Code:
// https://forum.pjrc.com/threads/53571-Can-t-turn-off-pull-up-resistors-on-3-2
const int in = 22; //  T_3.2 native touch pins :: 0, 1, 15-19, 22, 23, 25, 32, 33
bool toggle = false;
const uint32_t MIN_TOUCH = 900; // adjust as observed/needed

//********setup***************
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(19200);
  while ( !Serial && millis() < 4000 );
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  Serial.print("\t Touch Values:  ");
  digitalWrite(LED_BUILTIN, HIGH);
  for ( int ii = 0; ii < 10; ii++ ) {
    Serial.print( touchRead( in ) );
    Serial.print( " ,  " );
    delayMicroseconds(2001); // wait to test touchRead()
  }
  Serial.println();
}

//*********Main Loop ***************
void loop()
{
  static uint32_t tic = 0;
  static uint32_t noTch = 0;
  uint32_t tVal;

  if ( (tVal = touchRead( in )) > MIN_TOUCH ) {
    if ( false == toggle ) {
      tic++;
      toggle = true;
      digitalWrite(LED_BUILTIN, HIGH);
      Serial.print("\nTouch Value:");
      Serial.print( tVal );
      Serial.print("\t NO Touch Value:");
      Serial.print( noTch );
      Serial.print("\tTouch Detected #");
      Serial.print( tic );
    }
    else
      Serial.print(".");
    delay ( 50 );
  }
  else {
    if ( toggle ) {
      Serial.print("\t NO Touch Value:");
      Serial.print( tVal );
    }
    toggle = false;
    digitalWrite(LED_BUILTIN, LOW);
    noTch = tVal;
  }
  delayMicroseconds(2001); // Do other stuff or wait to test touchRead()
}// end of main
 
Last edited:
Surprising how simple it is with the hardware touch detect!

Added comments and edited printing - all those values seem useful for observing/debugging a single Touch pin - so they remain.

Odd thing is untouched can go from 731 to 900, but 901 to 2099 is touched on this T_3.2 as wired, so seeing the numbers is useful::
Code:
const int tPin = 22; //  Teensy card [LC, 3.2, 3.6] shows 'Touch' pins
const uint32_t MIN_TOUCH = 900; // adjust as observed/needed

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(19200);
  while ( !Serial && millis() < 4000 );
  Serial.println("\n" __FILE__ " " __DATE__ " " __TIME__);
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.print("\t Touch Values"); // Show some initial reference values,
  for ( int ii = 0; ii < 10; ii++ ) {
    Serial.print( ":  " );
    Serial.print( touchRead( tPin ) );
  }
  Serial.println();
}

bool TouchOn = false;
void loop()
{
  static uint32_t tCnt = 0; // Touch Count
  static uint32_t noTch = 0; // record last no Touch
  uint32_t tVal;
  if ( (tVal = touchRead( tPin )) > MIN_TOUCH ) { // Record and Test Read value for Touch
    if ( false == TouchOn ) {
      tCnt++; // record NEW touch
      TouchOn = true;
      digitalWrite(LED_BUILTIN, HIGH); // LED on during touch
      Serial.print("\n Cnt:");
      Serial.print( tCnt );
      Serial.print("\t NO Tch Val:");
      Serial.print( noTch );
      Serial.print("\t Tch Val:");
      Serial.print( tVal );
    }
    else
      Serial.print("."); // Display '.' while touch continues
    delay ( 50 );
  }
  else {
    noTch = tVal;
    if ( TouchOn ) {
      Serial.print("  End Tch Val:");
      Serial.print( noTch ); // Show value seen when touch stopped
    }
    TouchOn = false;
    digitalWrite(LED_BUILTIN, LOW); // No touch, no LED
  }
}
 
Last edited:
The MK20 chip on Teensy 3.2 has a hardware issue where there is a very weak pullup current over some of the input voltage range. But it's not the entire range, which can make this very confusing. It's much less than when INPUT_PULLUP is used.

You can avoid this leakage current with INPUT_DISABLE. But in that mode, the pin always reads zero.

Unfortunately, with this chip you simply can not have extremely high input impedance over the full input voltage range while the input circuitry is active. It's a hardware issue and you must work around it. I put one workaround into the CapacitiveSensor library years ago. Maybe look at that code for some inspiration?

Or you could use touchRead(pin) - possibly with 74HCT4051 mux chips if you need more inputs. The hardware capacitive sensing doesn't have this problem, and it has very nice hardware to do this measurement faster and more accurately than can usually be achieved using GPIO.
 
Opps - I failed to fully read the OP. Good answer Paul.

Paul - Is there published usage info on touchRead() that I couldn't find? Does that post #4 look like a valid and useful example to add?

I just ran it on T_LC and it works just as well with a lower setpoint based on the initial scan/output in setup().
 
Great answers. And this explains why the pins drop low on reset (which let me know they could). Thanks much!
 
Status
Not open for further replies.
Back
Top