MF42
October 7, 2017, 7:00am
1
Hello,
one of my four photon changes permanently to blinking cyan which seems to be a common problem. After resetting everything seems to work fine, but just for several hours.
This behavior makes the photon useless for me.
I used particle cli device doctor several times but it didn’t help. Any suggestions on what’s causing this issue?
Thanks for your help,
Michael
Moors7
October 7, 2017, 7:57am
2
Most likely your code. Any chance we could see that?
MF42
October 7, 2017, 8:50am
3
yes sure and thanks:
#include "Blynk.h"
#include "BlynkSimpleParticle.h"
char auth[] = "XXXXXXXXXXXXXXXXXXX";
bool needPublish = true;
bool publishReset = false;
uint8_t retry_count = 0;
unsigned long old_connectCheck_time = millis();
unsigned long old_checkLevel_time = millis();
int dataPin = D7;
int chipInh0 = A4;
int chipInh1 = A3;
int chipInh2 = A2;
int onesBit = D0;
int twosBit = D1;
int foursBit = A1;
int eightsBit = A0;
float lastLevel = 0; // will be LOW for the selected sensor in the presense of a magnet
int counter;
float level = 0;
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));
SYSTEM_THREAD(ENABLED);
void setup()
{
Blynk.begin(auth);
pinMode(dataPin, INPUT_PULLUP);
pinMode(onesBit, OUTPUT);
pinMode(twosBit, OUTPUT);
pinMode(foursBit, OUTPUT);
pinMode(eightsBit, OUTPUT);
pinMode(chipInh0,OUTPUT);
pinMode(chipInh1,OUTPUT);
pinMode(chipInh2,OUTPUT);
Particle.function("getRSSI", getRSSI);
Particle.function("getLevel", getLevel);
}
void loop()
{
if(millis() - old_connectCheck_time >= 2000)
{
if(retry_count < 10)
{
if(!WiFi.ready())
{
WiFi.connect();
retry_count++;
}
else if (!Particle.connected())
{
Particle.connect();
retry_count++;
}
else if (!Blynk.connected())
{
Blynk.connect();
retry_count++;
}
}
else
{
WiFi.off();
retry_count = 0;
WiFi.on();
}
old_connectCheck_time = millis();
}
if(millis() - old_checkLevel_time >= 5000)
{
cycleAddressPins();
old_checkLevel_time = millis();
}
Blynk.run();
monitorchanges();
}
void monitorchanges()
{
if (needPublish)
{
Blynk.virtualWrite(V27,lastLevel);
needPublish = false;
}
}
void cycleAddressPins()
{
float total = 0;
counter = 0;
for (int i=0; i<47; i++)
{
digitalWrite(chipInh0, (i < 16)? LOW:HIGH);
digitalWrite(chipInh1, (i > 15 && i < 32)? LOW:HIGH);
digitalWrite(chipInh2, (i > 31)? LOW:HIGH);
delay(50);
digitalWrite(onesBit, (i & 1));
digitalWrite(twosBit, (i & 2) >> 1);
digitalWrite(foursBit, (i & 4) >> 2);
digitalWrite(eightsBit, (i & 8) >> 3);
delay(50);
int reading = digitalRead(dataPin);
if (reading == 0)
{
if (i > 10) total--;
if (i>40) total = total - 4;
total += (float)i*1.0;
counter ++;
}
}
level = (counter >0)? total/(float)counter : -1;
level = level/41*100;
if (level != lastLevel)
{
lastLevel = level;
needPublish = true;
}
}
int getRSSI(String cmd)
{
return WiFi.RSSI();
}
float getLevel(String cmd)
{
return lastLevel;
}
BLYNK_WRITE(V42)
{
if (param.asInt() == 0)
needPublish = true;
}