Salve.
Da qualche giorno sto sperimentando con MKR1000.
Avevo messo questo codice, per sperimentare con Telegram.
#include <WiFi101.h>
#include <SPI.h>
#include <TelegramBot.h>
// Initialize Wifi connection to the router
char ssid[] = "xxxx"; // your network SSID (name)
char pass[] = "yyyy"; // your network key
// Initialize Telegram BOT
const char* BotToken = "xxxx"; // your Bot Teken
WiFiSSLClient client;
TelegramBot bot(BotToken,client);
const int ledPin = 6; // the number of the LED pin
void setup()
{
Serial.begin(115200);
while (!Serial) {} //Start running when the serial is open
delay(3000);
// attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
while (WiFi.begin(ssid, pass) != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
bot.begin();
pinMode(ledPin, OUTPUT);
}
void loop()
{
message m = bot.getUpdates(); // Read new messages
if (m.text.equals("On"))
{
digitalWrite(ledPin, HIGH);
Serial.println("message received");
bot.sendMessage(m.chat_id, "The Led is now ON");
}
else if (m.text.equals("Off"))
{
digitalWrite(ledPin, LOW);
Serial.println("message received");
bot.sendMessage(m.chat_id, "The Led is now OFF");
}
}
Lo modifico un po' per poter usare anche uno schermo Lcd con I2C, ma non si vedono le scritte.
Lascio perdere e collego un servo.
Ieri, quindi, riprovo ad usare LCD e collego i poli positivi e negativi ad una batteria da 9 volt, mentre gli altri due pin sono collegati ad A4 e A5.
Questo è il codice
#include <Servo.h>
Servo myservo;
int pos=0;
#include <WiFi101.h>
#include <SPI.h>
#include <TelegramBot.h>
int buzzer = 7; //buzzer connesso al pin 3
// Initialize Wifi connection to the router
char ssid[] = "////"; // your network SSID (name)
char pass[] = "////"; // your network key
// Initialize Telegram BOT
const char* BotToken = "////"; // your Bot Teken
WiFiSSLClient client;
TelegramBot bot(BotToken,client);
const int ledPin = 6; // the number of the LED pin
void setup(){
myservo.attach(9);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
//telegram bot
bot.begin();
message m = bot.getUpdates(); // Read new messages
bot.sendMessage(m.chat_id, "OFFLINE");
while (!Serial) {} //Start running when the serial is open
delay(3000);
// attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
bot.sendMessage(m.chat_id, "Connessione al WiFi");
Serial.println(ssid);
while (WiFi.begin(ssid, pass) != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
pinMode(ledPin, OUTPUT);
bot.sendMessage(m.chat_id, "Connesso al WiFi");
}
void loop()
{
message m = bot.getUpdates(); // Read new messages
if (m.text.equals("On"))
{
for(pos=0;pos<180;pos+=1);{
myservo.write(pos);
}
tone(buzzer,4000,200); //suona nota sul pin 12 alla frequenza di 1000Hz
delay(2000);
noTone(buzzer); //non suona
digitalWrite(ledPin, HIGH);
Serial.println("message received");
bot.sendMessage(m.chat_id, "The Led is now ON");
}
else if (m.text.equals("Off"))
{
for(pos = 180; pos>=1; pos-=1) // In questo caso imposta un ciclo con valori che vanno da 180 a 0
{
myservo.write(pos);
delay(30);
}
tone(buzzer,1000,200); //suona nota sul pin 12 alla frequenza di 1000Hz
delay(2000);
noTone(buzzer);
digitalWrite(ledPin, LOW);
Serial.println("message received");
bot.sendMessage(m.chat_id, "The Led is now OFF");
}
}
Non c'è il codice per LCD, pochè non sono riuscito a caricarlo. Mi spiego meglio.
Accendo il monitor seriale per provarlo, ma si blocca, e non riesco a spegnere nè il monitor nè l'IDE. Riavvio tutto, ma ancora non riesco. Non mi da errori di crash, o simili, si blocca soltanto.
Oggi ho provato a mettere il Blink, ma quando carico, dopo un'attesa infinita, la barra del caricamento scompare, nella log non rimane scritto niente, ma continua ad essere scritto "Sto caricando".
Cos'è successo?