So first, I have a code that I have sitting in the Arduino program, but I don’t know how to get it to my Sparkfun ESP8266 thing. I’m not sure the process of how I would do that.
And second, I don’t know how to connect my Blynk to my Sparkfun ESP8266 thing.
This is my first time using Blynk so I’m really unsure of how I would go about this. My project is music reactive LED lights. Basically, I just want to be able to use the Blynk app to change colors/appearances of my LEDs (as seen in this video https://www.youtube.com/watch?v=9X5UZ0_ZNCM). Here is what my Blynk screen looks like. The different modes are what I had in mind. If anyone is really good/familiar with this topic, you can PM me if you want
Mode 0 - Bar flashes
Mode 1 - Spectrum
Mode 2 - Beams
Mode 3 - Mini bar flashes
In the first point, are you referring to my code? I paste it here but it should be complete and working. I just don’t know how to put this code onto the Sparkfun 8266 thing.
#include <Adafruit_DotStar.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFiMulti.h>
// constants
#define NUMPIXELS 60 // number LEDs on the strip
#define ESP8266_LED 5 // ESP8266 on-board LED on port 5
#define MINIBAR_LEN_TREB 7 // len of small bar in mode 3
#define MINIBAR_LEN_BASS 30 // len of mid bar in mode 3
#define MINIBAR_LEN_MIDL 15 // len of mid bar in mode 3
#define DATAPIN 2 // GPIO2 - MOSI
#define CLOCKPIN 4 // GPIO4 - CLK
#define IP_ADDR "74.101.17.188" // IP address of pc running Processing app
#define SSID_NAME "584N6" // SSID of the network in use
#define SSID_PW "JX7TFN36GRPKXVCH" // password to the network in use
// WiFi
ESP8266WiFiMulti WiFiMulti;
// Use above defined pins for DATA and CLK
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DATAPIN, CLOCKPIN);
// Use hardware SPI (DATA-13, SCLK-SCL)
//Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS);
// You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon).
char auth[] = "41ca952815c3452481585b2b8ef6f0bc";
// global variables
bool setupFailed = false; // flag for WiFi setup. if failed, blink onboard LED
WiFiClient client; // create TCP connection
byte val = 0; // val received from Processing app (beat in val bin)
// LED controlling variables
unsigned int r[NUMPIXELS] = {0}; // each index holds the R, G, or B value
unsigned int g[NUMPIXELS] = {0}; // of the LED with that index ranging
unsigned int b[NUMPIXELS] = {0}; // from 0 - 255
int heads[NUMPIXELS] = {-1}; // array holding the heads and tails values
int tails[NUMPIXELS] = {-1}; // of the "beams" that go across the LED strip
int beamCnt = 0;
int beamDelay = 0; // counter that increments and every...
int beamPropDelay = 4; // ...beamPropDelay it updates the beam
int beamLen = -7; // length of beam in LEDs
// Blynk variables
int customize, modeSel; // flags int blynk_r, blynk_g, blynk_b; // r,g,b
void setup()
{
// set up onboard LED mode
pinMode(ESP8266_LED, OUTPUT);
// set up Blynk
Blynk.begin(auth, SSID_NAME, SSID_PW);
// set up WiFi connection to PC
const uint16_t port = 5204;
const char * host = IP_ADDR; // ip or dns
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
WiFiMulti.addAP(SSID_NAME, IP_ADDR);
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, port)) {
Serial.println("connection failed, restart system");
setupFailed = true;;
}
strip.begin();
strip.show();
// random seed
randomSeed(0);
}
// Blynk functions for virtual pins BLYNK_WRITE(V0)
{
modeSel = 0; }
BLYNK_WRITE(V1)
{
modeSel = 1; }
BLYNK_WRITE(V2)
{
modeSel = 2; }
BLYNK_WRITE(V3)
{
modeSel = 3; }
BLYNK_WRITE(V4)
{
customize = param.asInt(); }
BLYNK_WRITE(V5)
{
blynk_r = param.asInt(); }
BLYNK_WRITE(V6)
{
blynk_g = param.asInt(); }
BLYNK_WRITE(V7)
{
blynk_b = param.asInt(); }
BLYNK_WRITE(V8)
{
beamPropDelay = param.asInt(); }
BLYNK_READ(V9)
{
Blynk.virtualWrite(9, modeSel); }
void loop() {
int i; // counter used for misc purposes
int gVal, rVal, bVal; // temporary holder variables for RGB values
// blink onboard LED if wifi failed
if (setupFailed == true)
{
digitalWrite(ESP8266_LED, HIGH);
delay(1000);
digitalWrite(ESP8266_LED, LOW);
delay(1000);
return;
}
Blynk.run(); // Initiates Blynk
if (client.available())
{ // if data is availble to read
val = client.read();
//////////////////// mode 0 ////////////////////
if ( modeSel == 0) // bar flash mode
{
if (!customize) // custom colors
{
gVal = random(0x100);
rVal = random(0x100);
bVal = random(0x100);
}
else // use sliders on Blynk app to determine color
{
gVal = blynk_g;
rVal = blynk_r;
bVal = blynk_b;
}
if (val == 10) // detecting == bin2 (71 < val < 86 Hz )
{
for ( i = 0; i < NUMPIXELS; i++)
{
r[i] = rVal;
g[i] = gVal;
b[i] = bVal;
}
}
}
//////////////////// mode 1 ////////////////////
else if ( modeSel == 1 )
{ // spectrum mode (sub bass, bass, midrange, high mids, high freq)
if (customize)
{
r[val] = blynk_r;
g[val] = blynk_g;
b[val] = blynk_b;
} else {
if (val < 5)
{ // red
r[val] = 0xFF;
g[val] = 0;
b[val] = 0;
}
else if (val < 10)
{ // orange
r[val] = 0xFF;
g[val] = 0xA5;
b[val] = 0;
}
else if (val < 15)
{ // yellow
r[val] = 0xFF;
g[val] = 0xFF;
b[val] = 0;
}
else if (val < 20)
{ // chartreuse
r[val] = 0x7F;
g[val] = 0xFF;
b[val] = 0;
}
else if (val < 25)
{ // green
r[val] = 0;
g[val] = 0x80;
b[val] = 0;
}
else if (val < 30)
{ // spring
r[val] = 0;
g[val] = 0xE6;
b[val] = 0x73;
}
else if (val < 35)
{ // cyan
r[val] = 0;
g[val] = 0xFF;
b[val] = 0xFF;
}
else if (val < 40)
{ // azure
r[val] = 0xF0;
g[val] = 0xFF;
b[val] = 0xFF;
}
else if (val < 45)
{ // blue
r[val] = 0;
g[val] = 0;
b[val] = 0xFF;
}
else if (val < 50)
{ // violet
r[val] = 0xEE;
g[val] = 0x82;
b[val] = 0xEE;
}
else if (val < 55)
{ // magenta
r[val] = 0xFF;
g[val] = 0x00;
b[val] = 0xFF;
}
else
{ // rose
r[val] = 0xFF;
g[val] = 0;
b[val] = 0xFF;
}
}
}
////////////////////
else if ( modeSel == 2 )
{
mode 2 ////////////////////
if (val == 17 )
{ // trigger the beam
if (beamCnt >= NUMPIXELS)
beamCnt = 0;
heads[beamCnt] = 0;
tails[beamCnt] = beamLen;
if (!customize) // every beam gets a random color
{
r[beamCnt] = random(0x100);
g[beamCnt] = random(0x100);
b[beamCnt] = random(0x100);
}
else
{ // using zeRGBa on Blynk app to determine color
g[beamCnt] = blynk_g;
r[beamCnt] = blynk_r;
b[beamCnt] = blynk_b;
}
beamCnt++;
}
}
//////////////////// mode 3 ////////////////////
else if ( modeSel == 3 )
{ // random small bars (bass, mid, treble)
// random colors if custom button not pressed on Blynk app
if (!customize)
{
gVal = random(0x100);
rVal = random(0x100);
bVal = random(0x100);
}
// determine location of bass bar
i = random(60 - MINIBAR_LEN_BASS);
if (val == 10)
{
if (customize)
{
gVal = blynk_g;
rVal = blynk_r;
bVal = blynk_b;
}
for (int j = i ; j < i + MINIBAR_LEN_BASS; j++)
{
r[j] = rVal;
g[j] = gVal;
b[j] = bVal;
}
}
// determine location of mid bar
i = random(60 - MINIBAR_LEN_MIDL);
if (val == 17)
{
if (customize)
{
gVal = blynk_r;
rVal = blynk_b;
bVal = blynk_g;
}
for (int j = i ; j < i + MINIBAR_LEN_MIDL; j++)
{
r[j] = rVal;
g[j] = gVal;
b[j] = bVal;
}
}
// determine location of treble bar
i = random(60 - MINIBAR_LEN_TREB);
if (val == 54)
{
if (customize)
{
gVal = blynk_b;
rVal = blynk_g;
bVal = blynk_r;
}
for (int j = i ; j < i + MINIBAR_LEN_TREB; j++)
{
r[j] = rVal;
g[j] = gVal;
b[j] = bVal;
}
}
}
else if ( modeSel == 4 )
{
for (i = 0; i < NUMPIXELS; i++)
{
r[i] = val;
g[i] = val;
b[i] = val;
strip.setPixelColor(i, g[i], r[i], b[i]);
}
}
}
loop
} }
// mode 2 - beam propagation
// update head location every beamPropDelay // to control beam propagation speed
if (beamDelay++ % beamPropDelay == 0)
{
for (i = 0; i < NUMPIXELS; i++)
{
strip.setPixelColor(heads[i], g[i], r[i], b[i]);
strip.setPixelColor(tails[i], 0);
if (heads[i] >= 0)
{
if ( ++heads[i] >= NUMPIXELS) // reset head
heads[i] = -1;
}
if (tails[i] >= beamLen)
{
if ( ++tails[i] >= NUMPIXELS ) // reset tail
tails[i] = beamLen - 1;
}
}
}
// dimming, all modes except beam (mode 2)
if ( modeSel == 0 || modeSel == 1 || modeSel == 3 )
{
for ( i = 0; i < NUMPIXELS; i++ )
{
if (g[i] > 0)
g[i] /= 1.04;
if (r[i] > 0)
r[i] /= 1.04;
if (b[i] > 0)
b[i] /= 1.04;
strip.setPixelColor(i, g[i], r[i], b[i]);
}
}
strip.show();
delay(5); // give uController time to maintain behind the scenes tasks
}
I took screenshots of the errors I’m getting in Arduino. The code is below the screenshots (sorry if the formatting is bad. I’m new to this site and the code is pretty long). The error comes at the line: bVal = blynk_r;
Anyone know what they mean and the solution(s)? My file name is Capstone:
Please edit your post and format the code correctly with backticks.
The bit where you’re defining these global variables is commented out. A carriage return after “flags “ should sort that out.
You appear to have similar issues with other lines too:
But it’s very difficult to tell because your code isn’t correctly formatted.
Ok. What else would you need to figure out the solution? Is there an ON button on the Sparkfun ESP8266 somewhere that I’m missing? I know that its offline, I just don’t know why its offline and I have no idea why it would be offline. I have it connected to my labtop directly.
Could it be a problem with the cord? I’m using the mini-USB but its one thats mainly used for changing an ANKER small battery. It came with the battery when I bought it. I’m not sure if that makes a difference though
Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
• Add your sketch code. Code should be formatted as example below.
Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.
why you use a lot of wires without a real connection? what is supposed to them must do? I mean, they aren’t really connected to the sparkfun… maybe you disconnected them for try to find where is the error? post a photo of unconnected wires helps nothing…
I only can view the sparkfun esp connected via usb cable… without your code to view how you are trying to connecto to blynk server… is hard to say…
Have you correctly configured the wifi auth? you change the blynk auth to the correct one from the example sketch?
When I upload a default/example code to my Sparkfun ESP8266 Thing Dev Board from Arduino, it works fine. I can turn off and on the LED on the board with GP5 in Blynk. Everything works fine.
But when I upload my specific code (its a code to control a LED light from using Blynk), it goes offline. I have the same auth token in both codes, as well as the SSID and Pass. Any solutions/recommendations? I can post the codes if anyone wants to see
My guess is that either your void loop is full of code, or some other part of your code has delays or takes too long to process - which is starving Blynk.run of processor time.
Is this the right place to post code and see if people can give a solution/recommendation or do I have to go to a different website. I can post the code I have currently.