ESP32: can't hold an LED powered

I've just started with ESP32 and I already have a base knowledge from Arduino, so I jumped to Bluetooth and tried a simple ON/OFF button. My problem is that I can't hold the LED turned ON, it shutdown itself for no reason. I might be doing something wrong with uploading things or misundertanding how ESP32 works. I'll leave the code here, really simple

#include "BluetoothSerial.h"

#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#define LED 16

BluetoothSerial SerialBT;

void setup() {
  pinMode (LED, OUTPUT);
  Serial.begin(115200);
  SerialBT.begin("ESP32test"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
}

void loop() {
  while (SerialBT.available())
  {
    int value = SerialBT.parseInt();
    Serial.println (value);    //Debug, ignore
    digitalWrite (LED, value);
  }
  delay(20);
}

EDIT:
By directly debugging from SerialBT.read(), turns out that it sends "-1-1-1-1-1-1-1-1", which "parseInt" reads as 0 every second, so now my question is: How do I ignore it?

Does Serial.println(value); also shows the Led has to go dim?

No, just show what I send. Look at the edit I made, it has some progress

You can make it an unsigned int.. this has no negative values uint8_t (which is an unsigned byte)

The problem is that an int already reads 0. If I use a char, to read I or O, it reads the data I send and 5 '\n' I thing

HOWEVER, if I only use:

void loop() {
  while (SerialBT.available())
  {
    Serial.println (SerialBT.read());
  }
  delay(20);
}

for the loop, it shows the ASCII of my data, followed by 13 ('\r') and 10 ('\n').

I must be doing something wrong and it might be really stupid.

What value of current limiting resistor is in series with the LED?

220Ω, not the appropriate for 3.3v, but is the only one I have. Either way, the problem was that I was reading \r and \n and saving it as a value for the LED. Also, not having data on queue returns -1.
The solution is just ignore \r and \n.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.