Arduino programming problem 2

hi.I wanted to report the problem with arduino 2. any kind of loaded schetck, in the moment when the power supply is missing arduino does not restart and I am forced to connect the pc and wait for the reboot. why?!

sorry, but i did not understand what you mean by above.

I’ll explain. when I use arduino 2 for my projects with cayenne, everything is fine, but if there is no power, arduino does not execute the programming even by resetting the device several times. it starts again only if I connect the pc to the usb socket of arduino and open arduino ide. since it repeats itself with all the devices I have in operation (5)

//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include “EmonLib.h”
EnergyMonitor emon1,emon2; // Create an instance
int CorrenteTot=0;
int PotenzaTot=0;

char username = "
char password = "
char clientID = ";

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
emon1.voltage(0, 1046.26, 1.7); // Voltage: input pin, calibration, phase_shift
emon2.voltage(0, 1046.26, 1.7); // Voltage: input pin, calibration, phase_shift

emon1.current(1, 360); // Current: input pin, calibration.

emon2.current(2,355);
}

void loop() {
Cayenne.loop();
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon2.calcVI(20,2000);

emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
emon2.serialprint();

float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFActor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable

Serial.print (“corrente pinza 1=”);
Serial.println (emon1.Irms);
Serial.print (“corrente pinza 2=”);
Serial.println (emon2.Irms);
Serial.print (“tensione =”);
Serial.println(emon1.Vrms);

CorrenteTot=emon1.Irms+emon2.Irms;
PotenzaTot=CorrenteTot*emon1.Vrms;
Serial.print (“Potenza reale 1=”);
Serial.println(emon1.apparentPower);
Serial.print (“Potenza reale 2=”);
Serial.println(emon2.apparentPower);
}
CAYENNE_OUT_DEFAULT()
{
// Cayenne.virtualWrite(0, emon1.Vrms);
Cayenne.virtualWrite(1, emon1.Vrms,“voltage”,“v”);

//Cayenne.virtualWrite(2, PotenzaTot);
Cayenne.virtualWrite(3,(emon1.apparentPower+emon2.apparentPower),“pow”,“w”);

Cayenne.virtualWrite(5, emon1.Irms,“current”,“a”);
Cayenne.virtualWrite(6, emon2.Irms,“current”,“a”);
//Cayenne.virtualWrite(7, PotenzaTot);
Serial.println(“finito invio”);}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

i am not sure what is happening with your device, but we can do some test to find out the issue.
First, just upload a basic cayenne code https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino/blob/master/examples/Connections/EthernetShieldW5100/EthernetShieldW5100.ino and see if it connect or not.

maybe I wasn’t clear. everything works perfectly. the problem is only due to the lack of power supply, since I have 5 arduino devices that do different things with different programming I wanted help in this regard

maybe i got it now: you have 5 arduino, which when connected to power supply does not work, but when connected to your pc it works?

collegato al pc funziona, ma anche quando lo collego al alimentatore, solo in fase di manancata alimentazione non riparte piu. lasciando tutto come si trova basta collegare alla porta ide il pc e riparte

it is really confusing for me.

  1. you connect your arduino to power supply.
  2. a power failure occurs.
  3. the arduino does not starts and does not connect to cayenne?

yes

it must be an issue with your power supply not providing enough power for your arduino.

ho provato con alimentatori diversi. potrebbe esse un conflitto di programmazione?!
per darvi un altro esempio lo stesso alimentatore collegato al esp8266 che fa la stessa cosa come programmazione non si blocca. arduino due si

what is the voltage of your power supply? if it is working fine when you have connected it to pc, then it is not a programming issue. is it something related to your arduino due or power supply.

ho provato il classico alimentatore da cellulare usb a 5v, uno a 9v, uno a 12v, tutto su 5 arduino diversi stessa storia

not sure what is the issue here. can you run a basic led blink code and see if it works on external power supply.

ora sto provando a cambiare sistema, passando dalla libreria cayennemqtt a esppublish

Before that try running the simplest example that is led blink, to rule out the issue with hardware.

update. only with the cayenne library does it freeze even if a LED flashes. changing the sketch and using the pubsub library to send to cayenne everything works and doing various power outages everything starts again. could there be a kind of block on the programming port wake up?

can you share the cayenne code you are using.

//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>
#include “EmonLib.h”
EnergyMonitor emon1,emon2; // Create an instance
int CorrenteTot=0;
int PotenzaTot=0;

char username = “”;
char password = “”;
char clientID = “”;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID);
emon1.voltage(0, 1046.26, 1.7); // Voltage: input pin, calibration, phase_shift
emon2.voltage(0, 1046.26, 1.7); // Voltage: input pin, calibration, phase_shift

emon1.current(1, 360); // Current: input pin, calibration.

emon2.current(2,355);
}

void loop() {
Cayenne.loop();
emon1.calcVI(20,2000); // Calculate all. No.of half wavelengths (crossings), time-out
emon2.calcVI(20,2000);

emon1.serialprint(); // Print out all variables (realpower, apparent power, Vrms, Irms, power factor)
emon2.serialprint();

float realPower = emon1.realPower; //extract Real Power into variable
float apparentPower = emon1.apparentPower; //extract Apparent Power into variable
float powerFActor = emon1.powerFactor; //extract Power Factor into Variable
float supplyVoltage = emon1.Vrms; //extract Vrms into Variable
float Irms = emon1.Irms; //extract Irms into Variable

Serial.print (“corrente pinza 1=”);
Serial.println (emon1.Irms);
Serial.print (“corrente pinza 2=”);
Serial.println (emon2.Irms);
Serial.print (“tensione =”);
Serial.println(emon1.Vrms);

CorrenteTot=emon1.Irms+emon2.Irms;
PotenzaTot=CorrenteTot*emon1.Vrms;
Serial.print (“Potenza reale 1=”);
Serial.println(emon1.apparentPower);
Serial.print (“Potenza reale 2=”);
Serial.println(emon2.apparentPower);
}
CAYENNE_OUT_DEFAULT()
{
// Cayenne.virtualWrite(0, emon1.Vrms);
Cayenne.virtualWrite(1, emon1.Vrms,“voltage”,“v”);

//Cayenne.virtualWrite(2, PotenzaTot);
Cayenne.virtualWrite(3,(emon1.apparentPower+emon2.apparentPower),“pow”,“w”);

Cayenne.virtualWrite(5, emon1.Irms,“current”,“a”);
Cayenne.virtualWrite(6, emon2.Irms,“current”,“a”);
//Cayenne.virtualWrite(7, PotenzaTot);
Serial.println(“finito invio”);}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}