Arduino + HC-05 Code Unresponsive

I have made a simple sketch that sets the colour of a single neoPixel and allows the user to change it’s colour using the zeRGBa control in the Blynk app.

The hardware works and if I use different code with a terminal application I can change the colour of the neoPixel and interact with the project as expected.

The issue is when I add Blynk integration the project soes not behave as expected. Sometimes Blynk won’t connect, other times it will but wont change the colour and other times it will work really well.

If I send data from my project to the Blynk app the code on the Arduino will hang after connection.

It looks like the Blynk library could contain errors but i’m not sure. I have pasted my code below incase I have made any mistakes.

Many Thanks,

#define BLYNK_USE_DIRECT_CONNECT

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);

#include <BlynkSimpleSerialBLE.h> 

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


#include <EEPROM.h>

char auth[] = "YOURAUTH HERE"; //deleted for this forum post

int RED = 0;
int GREEN = 0;
int BLUE = 0;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, 4, NEO_RGB + NEO_KHZ800);

boolean toLight = true;

void setup() {
  // put your setup code here, to run once:
    Serial.begin(57600);
    
    BTSerial.begin(57600);
  
    pixels.begin();
    delay(100);

    RED = int(EEPROM.read(0));
    GREEN = int(EEPROM.read(1));
    BLUE = int(EEPROM.read(2));

    pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
    pixels.show();

    Blynk.begin(BTSerial, auth);
    
}

void loop() {
  // put your main code here, to run repeatedly:

    Blynk.run(); //Listen for blynk commands

     pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
     pixels.show();

}

BLYNK_WRITE(V0) // zeRGBa assigned to V0
{
    // get a RED channel value
    RED = param[0].asInt();
    // get a GREEN channel value
    GREEN = param[1].asInt();
    // get a BLUE channel value
    BLUE = param[2].asInt();
    
    EEPROM.write(0, RED);
    EEPROM.write(1, GREEN);
    EEPROM.write(2, BLUE);
        
    pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
    pixels.show();
    
}

Please edit your post to add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

I don’t think BLYNK_WRITE works with bluetooth.
Also, your void loop probably shouldn’t include this:

pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
pixels.show();

Pete.

Thankyou for your relpy, where would I put

pixels.setPixelColor(0, pixels.Color(RED,GREEN,BLUE));
pixels.show();

should it be in it’s own function?

What can I use instead of BLYNK_WRITE to get data from the Blynk app?

EDIT; sorry I’ve just seen your link in the above post, ignore my first question!

I haven’t used Neopixels very much, and can’t be bothered to go off and research code examples, but I’m pretty sure that they only need to be told what to do once, rather than hundreds of times per second. If that’s the case then I’d out this code in its own function and call it only when you want then neopixel to do something different from what its already doing.

I might be wrong about the BLYNK_WRITE with bluetooth. I know that the sync commands don;t work so you cant pill-back the correct values from the app when the MCU connects.
Personally, I don’t think Bluetooth is a sensible connection method for an IoT system and hopefully it will be dropped in Blink v2.0
If I were you I’d use an ESP8266 and Wi-Fi, it will solve all of the issues that you’re currently having with connectivity.

Pete.

OK thank you Pete.

I agree that Bluetooth is not a good solution for this type of application, the only reason I used it was because I needed to add remote features with what I already had.

I’m currently rewriting the code where I only write to the neoPixels when the colour is changed.

Thanks for your help.