Boa noite
Eu estava a tentar programar um modulo gsm sim800l e um modulo hc06 para que eu atravez de uma app enviar uma frase para o arduino mega e em seguida essa mesma mensagem seja enviada pelo sim800l para um numero especifico
mas estou a ter alguns erros no codigo
#include <SoftwareSerial.h> // Incluimos a livraria SoftwareSerial
SoftwareSerial GSM1(51, 50); // Declaramos os pinos RX(8) y TX(9) que vamos a usar
SoftwareSerial HC06 (10, 11);
void setup(){
Serial.begin(9600); // Iniciamos a comunicação serie
GSM1.begin(9600); // Iniciamos uma segunda comunicação serie da sim800l
HC06.begin(9600); // Iniciamos uma segunda comunicação serie do HC06
delay(1000); // Pausa de 1 segundo
}
void loop(){
// Função para o envio de um SMS
if (HC06.available()){ // se o arduino receber a frase pelo modulo hco6
String pedido = HC06.read(); } // armazenar em pedido
if (pedido == "")// se o pediido for ""
{} // entao nao fazer nada
else // senao
{GSM1.println("AT+CMGF=1"); // Activamos a função de envio de SMS
delay(100); // Pequena pausa
GSM1.println("AT+CMGS=\"+351965517929\"\r"); // Definimos o número do destinatário em formato internacional
delay(100); // Pequena pausa
GSM1.print(pedido); // Definimos o corpo da mensagem com a frase lida pelo bluetooth hco6
delay(500); // Pequena pausa
GSM1.print(char(26)); // Enviamos o equivalente a Control+Z
delay(100); // Pequena pausa}
}
}
Tags:
Os pinos 10 e 11 não podem ser utilizados para comunicação Serial no Arduino Mega, o próprio código de referência da IDE informa isso.
/*
Software serial multple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)
Note:
Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX:
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Not all pins on the Leonardo and Micro support change interrupts,
so only the following can be used for RX:
8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example
This example code is in the public domain.
*/
Bom dia,
O Arduino Mega possui 4 interfaces seriais . Porque esta usando Softserial?
The Arduino Mega has three additional serial ports: Serial1
on pins 19 (RX) and 18 (TX), Serial2
on pins 17 (RX) and 16 (TX), Serial3
on pins 15 (RX) and 14 (TX). To use these pins to communicate with your personal computer, you will need an additional USB-to-serial adaptor, as they are not connected to the Mega’s USB-to-serial adaptor. To use them to communicate with an external TTL serial device, connect the TX pin to your device’s RX pin, the RX to your device’s TX pin, and the ground of your Mega to your device’s ground.
https://www.arduino.cc/reference/en/language/functions/communicatio...
Envie o arquivo do Sketch.
Copie todas as mensagens de erro e nos informe.
http://labdegaragem.com/forum/topics/sugest-o-de-como-postar?commen...
envie o sketch para o topico a mensagem de erro é a seguinte
Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Placa:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
F:\codigo_gsm_bluetooth\codigo_gsm_bluetooth.ino: In function 'void loop()':
codigo_gsm_bluetooth:15:33: error: conversion from 'int' to 'String' is ambiguous
String pedido = Serial1.read(); }
^
In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:231:0,
from sketch\codigo_gsm_bluetooth.ino.cpp:1:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: candidate: String::String(const __FlashStringHelper*) <near match>
String(const __FlashStringHelper *str);
^
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: conversion of argument 1 would be ill-formed:
F:\codigo_gsm_bluetooth\codigo_gsm_bluetooth.ino:15:32: warning: invalid conversion from 'int' to 'const __FlashStringHelper*' [-fpermissive]
String pedido = Serial1.read(); }
^
In file included from C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/Arduino.h:231:0,
from sketch\codigo_gsm_bluetooth.ino.cpp:1:
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: candidate: String::String(const char*) <near match>
String(const char *cstr = "");
^
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.15.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: conversion of argument 1 would be ill-formed:
F:\codigo_gsm_bluetooth\codigo_gsm_bluetooth.ino:15:32: warning: invalid conversion from 'int' to 'const char*' [-fpermissive]
String pedido = Serial1.read(); }
^
codigo_gsm_bluetooth:17:7: error: 'pedido' was not declared in this scope
if (pedido == "")
^
exit status 1
conversion from 'int' to 'String' is ambiguous
Essas linhas estão incorretas:
String pedido = Serial1.read();
conversão de 'int' to 'String' é ambígua.
'pedido' was not declared in this scope (essa variável não foi declarada)
E tem mais erros ...
Veja no resto do programa, porque esta errado.
Bem-vindo a
Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)
© 2024 Criado por Marcelo Rodrigues. Ativado por