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

Thread: serial monitor stops working T 3.2

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    3

    serial monitor stops working T 3.2

    Teensy 3.2 arduino 1.8.9 teensydino 1.46

    Could not get serial monitor working and discovered why.
    Program simply compares 9 analog inputs(connected to light sensors) to a setpoint (pot) connected to analog "0"
    each analog input is pared with a digital output using pins 1-9 set as pinmode "output"
    This works, each output is connected to a BI color led with a simple circuit to have red on when low and green on with high
    Problem,
    attempted to monitor all the input analog values with the serial monitor and got no display.
    with other 3.2 just plugged into usb (no pins connected) same code, it worked

    Discovered that when the analog input value was higher than the setpoint when it sets the output pin high,
    it stops the serial monitor

    thinking it might be interfering with the hardware serial ports those outputs were disabled with no change
    seems a logic high level(program generated) on any of the pins 1-9 stops the serial monitor

    Question,
    is there a different way to configure pins to be outputs?

    Thank you
    ScottW

    the code. sure it's not the best way to do this(not a programmer)

    Code:
    int setpoint = A0;
    int setval = 0;
    int optA = A1;
    int optB = A2;
    int optC = A3;
    int optD = A4;
    int optE = A5;
    int optF = A6;
    int optG = A7;
    int optH = A8;
    int optI = A9;
    int luxA = 0;
    int luxB = 0;
    int luxC = 0;
    int luxD = 0;
    int luxE = 0;
    int luxF = 0;
    int luxG = 0;
    int luxH = 0;
    int luxI = 0;
    
    int ledA = 1;
    int ledB = 2;
    int ledC = 3;
    int ledD = 4;
    int ledE = 5;
    int ledF = 6;
    int ledG = 7;
    int ledH = 8;
    int ledI = 9;
    void setup() {
      
     
      analogReadResolution(12);
      pinMode(ledA, OUTPUT);
      pinMode(ledB, OUTPUT);
      pinMode(ledC, OUTPUT);
      pinMode(ledD, OUTPUT);
      pinMode(ledE, OUTPUT);
      pinMode(ledF, OUTPUT);
      pinMode(ledG, OUTPUT);
      pinMode(ledH, OUTPUT);
      pinMode(ledI, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop() {
      setval = analogRead(setpoint);
      
      luxA = analogRead(optA);
      if ( luxA >= setval) {digitalWrite(ledA, HIGH);
      }
      else {digitalWrite(ledA, LOW);
      }
      luxB = analogRead(optB);
      if ( luxB >= setval) {digitalWrite(ledB, HIGH);
      }
      else {digitalWrite(ledB, LOW);
      }
      luxC = analogRead(optC);
      if ( luxC >= setval) {digitalWrite(ledC, HIGH);
      }
      else {digitalWrite(ledC, LOW);
      }
      luxD = analogRead(optD);
      if ( luxD >= setval) {digitalWrite(ledD, HIGH);
      }
      else {digitalWrite(ledD, LOW);
      }
      luxE = analogRead(optE);
      if ( luxE >= setval) {digitalWrite(ledE, HIGH);
      }
      else {digitalWrite(ledE, LOW);
      }
      luxF = analogRead(optF);
      if ( luxF >= setval) {digitalWrite(ledF, HIGH);
      }
      else {digitalWrite(ledF, LOW);
      }
      luxG = analogRead(optG);
      if ( luxG >= setval) {digitalWrite(ledG, HIGH);
      }
      else {digitalWrite(ledG, LOW);
      }
      luxH = analogRead(optH);
      if ( luxH >= setval) {digitalWrite(ledH, HIGH);
      }
      else {digitalWrite(ledH, LOW);
      }
      luxI = analogRead(optI);
      if ( luxI >= setval) {digitalWrite(ledI, HIGH);
      }
      else {digitalWrite(ledI, LOW);
    
       Serial.print(luxA);
       Serial.print("\t");
       Serial.print(luxB);
       Serial.print("\t");
       Serial.print(luxC);
       Serial.print("\t");
       Serial.print(luxD);
       Serial.print("\t");
       Serial.print(luxE);
       Serial.print("\t");
       Serial.print(luxF);
       Serial.print("\t");
       Serial.print(luxG);
       Serial.print("\t");
       Serial.print(luxH);
       Serial.print("\t");
       Serial.print(luxI);
       Serial.print("\t");
       Serial.print(setval);
       Serial.print("\t");
       Serial.println();
       delay(100);
       
           
      } 
    
    }
    Last edited by defragster; 06-01-2019 at 08:29 AM. Reason: Added toolbar '#' CODE block for readability

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,562
    An Array would work like this:

    Code:
    int ledA = 1;
    int ledB = 2;
    int ledC = 3;
    int ledD = 4;
    int ledE = 5;
    int ledF = 6;
    int ledG = 7;
    int ledH = 8;
    int ledI = 9;
    
    const int LED_PINS[] = { ledA, ledB, ledC, ledD ,ledE ,ledF ,ledG ,ledH, ledI };
    
    setup() {
      for ( int ii=0; ii<(sizeof(LED_PINS[])/sizeof(int)); ii++ ) {
        pinMode( LED_PINS[ii], OUTPUT);
      }
    }
    Then using :: digitalWriteFast( LED_PINS[ 0 ], HIGH)
    > would turn on ledA
    > using const allows the Fast() version of Read and Write to be more efficient/faster.

    If the analog pins were put in a parallel array that might work like this:
    Code:
      int luxVal;
      for ( int ii=0; ii<(sizeof(LED_PINS[])/sizeof(int)); ii++ ) {
         luxVal = analogRead( LUX_PINS[ii] );
         if ( luxVal >= setval ) {
            digitalWriteFast( LED_PINS[ii], HIGH );
         }
         else { 
            digitalWriteFast( LED_PINS[ii], LOW );
         }
      }

  3. #3
    Senior Member
    Join Date
    May 2017
    Posts
    207
    >>>each output is connected to a BI color led with a simple circuit to have red on when low and green on with high

    >>>with other 3.2 just plugged into usb (no pins connected) same code, it worked

    My guess is there is something wrong with your circuit such that when you set the pin high, the power supply is shorted out.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,071
    That's my guess too, something about how those LEDs are wired up.

    But let me try to answer this...

    thinking it might be interfering with the hardware serial ports those outputs were disabled with no change
    seems a logic high level(program generated) on any of the pins 1-9 stops the serial monitor
    On Teensy, Serial.print() does NOT use hardware serial or any of the pins. Boards like Arduino Uno do this (pins 0 and 1). Teensy does not. On Teensy, Serial.print() is a virtual USB serial. None of the pins, nor hardware serial, are ever used.

    But if you have a bad circuit that draws far too much power, you can cause Teensy to disconnect from your PC, because the over-current protection that's built into the USB port gets triggered.

  5. #5
    Junior Member
    Join Date
    May 2019
    Posts
    3
    Thank you all for the ideas. I checked for any shorts or over current the led circuit when driven high is sourcing 3ma when low its sinking 1ma so believe I'm within the limits of the chip. pulled the 3.2 out of the circuit and just plugged into breadboard. only hookup is 10k pot across 3.2's 3.3 and pin one ground. Connected to analog 0 as used in my code for the setpoint value
    all other analog inputs and all the outputs are open. start serial monitor see some noise values on all inputs as expected. adjusted pot to value below the noise and the monitor freezes just as when in the circuit. I haven't tried the cool fast code suggested by defragster yet. does anyone see any problems with my code that would cause the serial monitor to quit?
    Really can't thank you all enough so nice to have the help.
    ScottW

  6. #6
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,562
    might be printing too much too fast the delay(100); may be long enough - a bit longer would be sure - but the stuff only needs to print on a change.

    As written that would be added code in each if and else - in a loop it would be easier

  7. #7
    Senior Member
    Join Date
    May 2017
    Posts
    207
    My guess now is that the POT is wired incorrectly and shorts out the 3.3 volts when turned.

    Your program is missing the pinMode(A0,INPUT) statement, but I don't see how that would cause the behavior as described.

  8. #8
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,562
    Quote Originally Posted by rcarr View Post
    My guess now is that the POT is wired incorrectly and shorts out the 3.3 volts when turned.

    Your program is missing the pinMode(A0,INPUT) statement, but I don't see how that would cause the behavior as described.
    Wiring problem makes more sense than the print to fast with the delay(100).

    AFAIK - Analog are handled differently and the setup is handled on the read - using pinMode() on them makes them digital.

  9. #9
    Senior Member
    Join Date
    May 2017
    Posts
    207
    >>> using pinMode() on them makes them digital

    Your right, pinMode statements are not needed.

  10. #10
    Junior Member
    Join Date
    May 2019
    Posts
    3
    Quote Originally Posted by defragster View Post
    Wiring problem makes more sense than the print to fast with the delay(100).

    AFAIK - Analog are handled differently and the setup is handled on the read - using pinMode() on them makes them digital.
    Good Morning,

    Thanks for the ideas,
    Added delays to no affect
    commented out analogReadResolution(12) to default 10
    no effect.
    Pot is not shorting, applying 0-3.3 volts very commonly done

    If any of you have a loose 3.2 with pins sitting around see what you get usb powered and a pot easy

    once URS opens I'll grab another 3.2

    Thanks all,
    ScottW

Posting Permissions

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