Notifications
Clear all

Serial Monitor Blues

5 Posts
3 Users
3 Reactions
149 Views
(@rebeljd)
Member
Joined: 2 years ago
Posts: 22
Topic starter  

I working on a project using an ESP32 and seem to be having intermittent issues with the serial monitor.  The attached sketch illustrates the problem (it is just of portion of the sketch I'm working on.  The serial monitor has worked a few times this sketch, but mostly it does not.  I've done many projects with this ESP32 and have never had this issue.  I did just upgrade to the latest version of the Arduino IDE (2.3.4)  

This is a simple sketch so I don't know why I can't get the serial monitor to work.  It simply passes thru two inputs to two outputs using interrupts. The blink portion in the loop works fine, but the Serial.println does not.   Any help is appreciated.

Jim

#include<arduino.h>
#define INPUT_A 12  
#define INPUT_B 27  
#define OUTPUT_A 23
#define OUTPUT_B 01
void IRAM_ATTR ISR_A() {
  digitalWrite(OUTPUT_A, digitalRead(INPUT_A));
}
void IRAM_ATTR ISR_B() {
  digitalWrite(OUTPUT_B, digitalRead(INPUT_B));
}
void setup() {
  Serial.begin(115200);
  pinMode(2,OUTPUT);
  pinMode(INPUT_A, INPUT);
  pinMode(INPUT_B, INPUT);
  pinMode(OUTPUT_A, OUTPUT);
  pinMode(OUTPUT_B, OUTPUT);
  attachInterrupt(INPUT_A,ISR_A,CHANGE);
  attachInterrupt(INPUT_B,ISR_B,CHANGE);
    }
void loop() {
  digitalWrite(2, HIGH);  
  delay(250);                      
  digitalWrite(2, LOW);  
  delay(250);                      
  Serial.println("I'm Looping");
}

   
Quote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 8046
 

@rebeljd The recommended approach for an ISR is to do as little as possible. Ideally set a flag that gets processed in the main loop.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 4 years ago
Posts: 1924
 

Hi @rebeljd,

  I agree with Ron (@zander)'s comment, but maybe in this case, I would also check out your port selections, especially GPIO 1, assuming this reference is correct (and RNT stuff is usually reliable).

See https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

which includes:

UART

The ESP32 supports up to three UART interfaces: UART0, UART1, and UART2, depending on the ESP32 board model you’re using.

  • UART0 is usually reserved for communication with the serial monitor during upload and debugging. However, you can also use it for communication with other devices after uploading the code if the Serial Monitor is not needed.

and

image

 (click table to see enlarged version)

Best wishes, Dave


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 8046
 

@davee @rebeljd Oops, yes I missed that, and I just noticed I don't see any mention of pullups or downs, floating input pins are unpredictable. Also you should put in error checking for each function or procedure call.

BTW, I still have no idea what you are doing, but it seems interesting,

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@rebeljd)
Member
Joined: 2 years ago
Posts: 22
Topic starter  

Well, that was a little embarrassing, Output_B was supposed to be 22, not 01.  I've actually have a copy of that RNT document, I just didn't look at close enough.  The serial monitor works fine now.

What I'm building is a Torch Height Controller (THC) for a CNC Plasma cutter.  The two interrupt inputs are the Step and Direction signals from the CNC, which are simply passed straight thru the ESP32 to the Stepper Motor controller for the Z Axis, which moves the torch up and down.  When the torch is actually on the THC will monitor the DC voltage of the torch, which is proportional to the distance the torch is above the material it is cutting.  There will be a setpoint in the THC which is compared to measured voltage and then controls the Step and Direction outputs to maintain the desired height.  

The two ISRs are used to simply pass the Step & Direction signals thru to the outputs.  There will be no other code in the ISR's.  I've actually got this portion working on the bench and it works well.

I like to test code separately in sections and now that this portion is working, I'll move on to the control portion and then on to the touch screen portion.

I could actually purchase a THC, but what's the fun in that.

Thanks again for your help.

And Ron, would you please stop sending that cold weather our way....


   
DaveE and HeliSteve reacted
ReplyQuote