giova014:
Post o código usado para testar o W5100.
Segue abaixo o código:
/*
Basic MQTT example
This sketch demonstrates the basic capabilities of the library.
It connects to an MQTT server then:
- publishes "hello world" to the topic "outTopic"
- subscribes to the topic "inTopic", printing out any messages
it receives. NB - it assumes the received payloads are strings not binary
It will reconnect to the server if the connection is lost using a blocking
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
achieve the same result without blocking the main loop.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Define o MAC ADDRESS da placa de rede
byte ip[] = { 172, 30, 1, 26 }; //Define o endereço IP
byte dns[] = { 172, 30, 1, 3 }; //Define o servidor de DNS
byte gateway[] = { 172, 30, 1, 1 }; //Define o gateway
byte subnet[] = { 255, 255, 255, 0 }; //Define a máscara de rede
EthernetClient ethClient;
PubSubClient client(ethClient);
void callback(char* topic, byte* payload, unsigned int length) {
String MSG;
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i=0;i<length;i++) {
Serial.print((char)payload[i]);
MSG = MSG + (char)payload[i];
}
Serial.println();
Serial.println();
Serial.print(MSG);
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("arduinoClient")) {
Serial.println("connected");
// Once connected, publish an announcement...
client.publish("outTopic","hello world");
// ... and resubscribe
client.subscribe("inTopic");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup()
{
//Inicializa a porta serial de controle
Serial.begin(9600);
// You can use Ethernet.init(pin) to configure the CS pin
Ethernet.init(10); // Most Arduino shields
//Inicializa o Ethernet Shield
Ethernet.begin(mac, ip, dns, gateway, subnet);
client.setServer("172.30.1.25", 1883); //Conecta no servidor Mosquitto
client.setCallback(callback);
// Allow the hardware to sort itself out
delay(2000);
}
void loop()
{
if (!client.connected()) {
reconnect();
}
client.loop();
}
giova014:
Post o código usado para testar o L293D.
Segue abaixo o código:
//Programa : Motor de passo 5v 28BYJ-48 com Motor_2 Motor Shield L293D
#include <AFMotor.h>
double passos_total = 2048; //Numero de passos para 1 rotacao total
//int porta_motor = 2; //1 para motor em M1/M2 e 2 para motor em M3/M4
int angulo = 9; //Angulo de rotacao do eixo
int angulo2 = 9;
double numero_de_passos = 0; //Armazena o numero de passos que o motor vai girar
double numero_de_passos2 = 0;
AF_Stepper Motor_1(passos_total, 1); //Define os parametros do motor
AF_Stepper Motor_2(passos_total, 2); //Define os parametros do motor
void setup()
{
Motor_1.setSpeed(5); //Define a velocidade de rotacao
Motor_2.setSpeed(5); //Define a velocidade de rotacao
Serial.begin(9600);
}
void loop()
{
//Calcula a quantidade de passos, baseado no angulo determinado
numero_de_passos = angulo / (360 / passos_total);
numero_de_passos2 = angulo2 / (360 / passos_total);
//Mostra no serial monitor o numero de passos calculados
Serial.print("Forward: ");
Serial.println(numero_de_passos);
Serial.print("Backward: ");
Serial.println(numero_de_passos2);
//Move o motor. Use FORWARD para sentido horario,
//BACKWARD para anti-horario
Motor_1.step(numero_de_passos, FORWARD, SINGLE);
Motor_1.release();
Motor_2.step(numero_de_passos, BACKWARD, SINGLE);
Motor_2.release();
delay(1000);
}