I am new to the Particle Photon but have done some stuff with Arduinos. I am suing my Photon with the Particle Shield. I am also wiring everything to the shield pins.
I am using the Photon to trigger a camera via the camera’s GPIO opt-isolated input lines. If I execute pulses (digitalwrite) that are a couple of seconds apart, all works well. However, if I execute numerous pulses with a short duration apart, the program running on the Photon loses connection to the internet and I get a flashing green. The only way to get the micro working again is either to disconnect then reconnect the camera/board input wire or to recycle power to the micro.
When I separate the camera wire from the board, the program continues to work regardless of the pulse frequency.
I have tried SYSTEM_THREAD(ENABLED) and it has improved the problem but has not eliminated it.
I have already checked with the camera manufacturer. The camera digital input lines are opto-isolated and do not send anything back.
Can you help me find out what the problem is? For example, if I wire the camera digital inputs directly to the Photon?
These command (Spark) are deprecated and you need to use Particle. Furthermore, doing 3 publishes in a row violates the 1 publish per second rule and will cause the Cloud to choke back your publish requests. Take a look at the documentation. You could combine everything into a single publish using sprintf().
This code will essentially set both Hammo and iPub to the same value. Was this intended? You need to read up on parsing a command string if you expected 2 arguments to be parsed.
I am on my way to the airport so I will do the soft delay later.
Initially, the camera optoinputs were connected to the Particle Shield GND and the input was connected to pin 7 on the shield. That is when i was having loss of internet connection.
However, I have changed and connected now the camera input directly to D7 on the Photon and the problem seems to go away.
My current code is below:
#include "LIDARLite.h"
SYSTEM_THREAD(ENABLED);
LIDARLite myLidarLite;
unsigned long old_time = 0;
String stringOne;
double Distance = 0;
double Distance1 = 0;
int iDist = 0;
int ipub = 0 ;
int brewCoffee(String command);
int photoresistor = A0; // This is where your photoresistor is plugged in.
int power = A3;
int Light;
int triggerPin = D7; // Pin 4 on Shield
float triggerDist = 2; //Trigger Distance
void setup()
{
Serial.begin(9600); // Initialize serial connection to display distance readings
pinMode(triggerPin, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D5, OUTPUT); //Green
pinMode(photoresistor,INPUT); // Our photoresistor pin is input (reading the photoresistor)
pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)
digitalWrite(triggerPin, LOW);
// Next, write one pin of the photoresistor to be the maximum possible, so that we can use this for power.
digitalWrite(power,HIGH);
digitalWrite(D5, HIGH);
Particle.variable("stringOne", stringOne);
//Particle.variable("Distance", Distance);
// Particle.variable("ipub", &ipub, INT);
//Particle.variable("ipub", ipub);
//Particle.variable("light", Light);
Particle.function("brew", brewCoffee);
myLidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz
myLidarLite.configure(0); // Change this number to try out alternate configurations
//myLidarLite.configure(3); // Change this number to try out alternate configurations
}
void loop()
{
Light = analogRead(photoresistor);
// Take a measurement with receiver bias correction and print to serial terminal
Distance1=(0.0328 * myLidarLite.distance());
iDist = Distance1 * 10. ;
Distance = iDist/10.;
Serial.print(Distance);
Serial.print(" ");
Serial.print(Light);
Serial.print(" ");
Serial.println(ipub);
if (Distance < 150)
{
// Take 99 measurements without receiver bias correction and print to serial terminal
for(int i = 0; i < 99; i++)
{
Distance1=(0.0328 * myLidarLite.distance(false));
iDist = Distance1 * 10. ;
Distance = iDist/10.;
Serial.print(Distance);
Serial.print(" ");
Serial.print(Light);
Serial.print(" ");
Serial.println(ipub);
delay(1);
}
//}
if (ipub ==7) //Trigger Mode
{
if (Distance < 4)
{
digitalWrite(triggerPin, HIGH);
delay(10);
digitalWrite(triggerPin, LOW);
delay(500);
}
}
if (ipub == 666) System.reset();
if (ipub ==1) //Publish
{
digitalWrite(D3, LOW);
digitalWrite(D2, HIGH);
digitalWrite(D5, LOW);
stringOne=String(Distance) + " ft " + String(ipub) + " " + String(Light);
Particle.publish("Results", String(stringOne) );
//Particle.publish("Distance", String(Distance) + " ft");
//Particle.publish("ipub", String(ipub) );
//Particle.publish("Light", String(Light) );
delay(2500);
digitalWrite(D3, LOW);
digitalWrite(D2, LOW);
digitalWrite(D5, HIGH);
delay(2500);
}
delay(1);
}
}
void triggerCamera()
{
digitalWrite(triggerPin, HIGH);
delay(100);
digitalWrite(triggerPin, LOW);
delay(100);
}
int brewCoffee(String command)
{
ipub = command.toInt();
}