BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

(Code for) ZeRGBa NOT WORKING

#1

I have tried all that i can but i can’t manage to get the Zergba to work, it seems that it nevers sends the values, when i tell the esp8266 to print the values of Zergba it always tells me 0, i don’t know what else to do.

#define BLYNK_PRINT Serial
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Ticker.h>
Adafruit_BME280 bme;
char auth[] = "1daa8c06625xxxxxxdd5cebdea61";
char ssid[] = "ASUS";
char pass[] = "*******";
Ticker timer;
const byte rmax = 500;
const byte gmax = 500;
const byte bmax = 500;
unsigned int Rpwm = 0;
unsigned int Gpwm = 0;
unsigned int Bpwm = 0;
int r;
int g;
int b;
byte i = 0;
bool A = false;
BLYNK_WRITE(V1) {
 int r = param[0].asInt();
 int g = param[1].asInt();
 int b = param[2].asInt();
}
void setup()
{
  Wire.begin(5, 4);
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  bme.begin(0x76);
  bme.setSampling(Adafruit_BME280::MODE_FORCED,
                  Adafruit_BME280::SAMPLING_X1, // temperature
                  Adafruit_BME280::SAMPLING_X1, // pressure
                  Adafruit_BME280::SAMPLING_X1, // humidity
                  Adafruit_BME280::FILTER_OFF   );
  pinMode(12, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  timer.attach(20, ReadSensor);
  //WidgetLCD lcd(V9);
  delay(100);
}

void loop()
{
  WidgetLCD lcd(V9);
  Blynk.run();
  Rpwm = map(r, 0, 1023, 0, rmax);
  Gpwm = map(g, 0, 1023, 0, gmax);
  Bpwm = map(b, 0, 1023, 0, bmax);
  analogWrite(14, Rpwm);
  analogWrite(12, Gpwm);
  analogWrite(15, Bpwm);
  if(A){
   lcd.clear();
  Blynk.virtualWrite(5, bme.readHumidity());
  Serial.println(bme.readHumidity());
  Blynk.virtualWrite(6, bme.readPressure());
  Serial.println(bme.readPressure());
  Blynk.virtualWrite(0, bme.readTemperature());
  Serial.println(bme.readTemperature());
  lcd.print(0, 0, "T: ");
  lcd.print(3, 0, bme.readTemperature());
  lcd.print(8, 0, "°C");
  lcd.print(0, 1, "Pa: ");
  lcd.print(4, 1, bme.readPressure());
  A = !A;

  }
}
void ReadSensor() {
bme.takeForcedMeasurement();
Serial.println(r);
Serial.println(g);
A = !A;
}




1 Like

#2

Instead of using the void loop() all wrong (for connection reliant processes like Blynk)… why not first try out this example and do some reading about the proper use of the void loop() with Blynk.

0 Likes

#3

@Dmitriy I am sure there was one… if so, when did the official example of the zeRGBa widget get removed from the Sketch Builder?? If there never was… well… then… :blush:

0 Likes

#4

Also… these values will never get passed beyond this function as they are assigned as Local variables and not Global…

https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/

Since you already defined them in the pre-setup… remove the int preceding each command in this function.

1 Like

#5

Thanks for the help man, the weird thing is that it worked for me before, and i did a weird thing with a BLE project and everything went crazy, all my widgets in mi projects where getting values from other devices all of a sudden. And from there on I started a blynk chat for help and never got it, that i remember.

0 Likes

#6

Yes, BLE is a whole other issue… but then I think it is still in beta anyhow.

0 Likes

#7

How can i get the BLYNK_WRITE(V1) to pass the values?

0 Likes

#8

nevermind

1 Like

#9

I still cant get it to work, I changed the int from inside the BLYNK_WRYTE and it still doesnt pass the values, what i cant understand is why it doesnt work now but worked before

0 Likes

#10

I would be surprised if it ever worked… what with multiple Blynk.virtualWrite() commands in the void loop() potentially trying to run hundreds or thousands of times a second :roll_eyes: (20ms is still a bit fast)

Not to mention the LCD Widget define running flat out… that should be in the pre-setup NOT in the void loop() :scream:

Perhaps it is time for you to look at some of those links provided. Nothing much else we can do for you until you fix the obvious issues :wink:

0 Likes