Hey there, I am using an MKR1000 that interfaces with Arduino cloud and Alexa for a project, it all works until I disconnect the PC and use external power. It is connected to a 7805 regulator via its vin and GND pins. Please note that it powers on normally and reaches its loop() phase (I know because the tone function in it works); still it doesn't execute the rest of the code and it appears offline in the device manager. Here is the complete code:
#include <ArduinoGraphics.h>
#include "thingProperties.h"
#include <SPI.h>
#include <WiFi101.h>
#include <Servo.h>
#define bev1 0
#define bev2 1
#define bev3 2
#define bev4 3
#define DAINSERIRE 5000
#define FC1 A0
#define FC2 A1
#define ATTESA 0
#define SELEZIONE 1
#define DISCESA 2
#define RIEMPIMENTO 3
#define RISALITA 4
#define CONSEGNA 5
#define stepsPerRevolution 200
byte p1 = 0;
byte p2 = 1;
byte p3 = 2;
byte p4 = 3;
byte servopin = 6;
byte AscDir = 4;
byte AscStep = 5;
int status = WL_IDLE_STATUS;
int stato = ATTESA;
int sel = 10000;
bool starterVariable = 0;
Servo servo;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
servo.attach(servopin);
pinMode(bev1, OUTPUT);
pinMode(bev2, OUTPUT);
pinMode(bev3, OUTPUT);
pinMode(bev4, OUTPUT);
pinMode(servopin, OUTPUT);
pinMode(AscDir, OUTPUT);
pinMode(AscStep, OUTPUT);
pinMode(6, OUTPUT);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to network: ");
Serial.println(SSID);
// Connect to WPA/WPA2 network:
status = WiFi.begin(SSID, PASS);
}
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false);
// ArduinoCloud.printDebugInfo();
// Serial.println("setup done!");
}
void loop() {
ArduinoCloud.update();
tone(13, 1000, 1000);
digitalWrite(13, LOW);
delay(1000);
}
void riempimentoFun(uint8_t r, uint8_t g, uint8_t b) {
Serial.println("R:" + String(r) + " G:" + String(g) + " B:" + String(b));
Serial.println("selezione");
if(r == 255){
sel = bev1;
}else if(g == 255){
sel = bev2;
} else if (b == 255){
sel = bev3;
}
Serial.println(sel);
Serial.println("discesa");
digitalWrite(AscDir, LOW);
while(analogRead(FC2) < 700){
digitalWrite(AscStep, HIGH);
delayMicroseconds(500);
digitalWrite(AscStep, LOW);
delayMicroseconds(500);
// Serial.println(analogRead(FC2));
}
delay(500);
Serial.println("riempimento");
servo.write(90);
delay(500);
digitalWrite(sel, HIGH);
delay(5000);
digitalWrite(sel, LOW);
servo.write(0);
// riempimentoFun(sel);
delay(500);
Serial.println("risalita");
digitalWrite(AscDir, HIGH);
while(analogRead(FC1) < 700){
digitalWrite(AscStep, HIGH);
delayMicroseconds(500);
digitalWrite(AscStep, LOW);
delayMicroseconds(500);
}
delay(500);
}
void onLoungeAreaChange() {
uint8_t r, g, b;
r = 0;
g = 0;
b = 0;
loungeArea.getValue().getRGB(r, g, b);
// Serial.println("R:" + String(r) + " G:" + String(g) + " B:" + String(b)); //prints the current R, G, B values
if(starterVariable == 1){
riempimentoFun(r, g, b);
} else{
starterVariable = 1;
}
}