I am using a Uno+WiFi R3 ATmega328P+ESP8266 board, 32Mb flash, USB-TTL CH340G, Micro-USB.
I am able to see the network SSID on my PC and to connect to it, but when I tried to upload a sketch using the Arduino IDE I am getting espcomm_upload_mem failed.
I used the sketch from https://robotdyn.com/uno-wifi-r3-atmega328p-esp8266-32mb-flash-usb-ttl-ch340g-micro-usb.html
void setup() {
Serial.begin(115200);
pinMode(13,OUTPUT);
delay(500);
Serial.println("AT+CIPMUX=1");
delay(2000);
Serial.println("AT+CIPSERVER=1,5000");
delay(2000);
Serial.println("AT+CIPSTO=3600");
delay(2000);
}
void loop() {
while(Serial.available()) {
char Rdata;
Rdata=Serial.read();
if(Rdata=='A'|Rdata=='a') {
digitalWrite(13,HIGH);
delay(50);
} else if(Rdata=='B'|Rdata=='b') {
digitalWrite(13, LOW);
delay(10);
digitalWrite(13, HIGH);
delay(10);
digitalWrite(13,LOW);
} else {
digitalWrite(13, LOW);
}
}
}
Robotdyn Uno/Mega + WiFi boards have switches to make serial connections of Atmega to Usb, esp8266 to USB and Atmega to esp8266. To flash the esp8266 the switches 5, 6, 7 must be ON. switch 7 is flashing mode. to communicate with esp8266 from Serial Monitor, switches 5 and 6 must be ON.
For communication of Atmega with the esp8266 switches 1 and 2 must be ON. In tis settings none of the MCUs is connected to USB. Therefore it is better to use SoftwareSerial on some Atmega pins and connect them with jumpers to the esp8266 header. The header is documented in the schematic.
The code in post is for the Atmega directly connected to esp8266 (switches 1,2)
Related
I'm trying to send data from Arduino UNO to NodeMCU via UART.
What I want to do is that when Arduino UNO sends "on" String to the NodeMCU, NodeMCU lights up its builtin LED, when "off" - it turns off.
I send data from Arduino UNO via standard Serial.println (). On the NodeMCU I use the SoftwareSerial library. I assigned rx and tx to pins D7 and D8 accordingly. Serial ports on Arduino(standard) and NodeMCU(SoftwareSerial) are set at 9600 baud rate.
Standard Serial port (USB) of NodeMCU is set to 115200.
I send the string that I receive from the Arduino to the standard serial port of the node (connected to usb)
The question is:
On the standard port of NodeMCU, which I view through the Arduino IDE, messages coming from the arduino are displayed, and displayed correctly (those that were sent), but the NodeMCU does not want to accept them in conditional statements and light up my LED. Why?
At the same time, when I remap the virtual UART to its original pins (connected to USB, GPIO3 and GPIO1, and send the same messages via usb through the COM port view in the Arduino IDE, the LED turns on and off as I programmed it.
Do you have any ideas why this is happening?
By the way, I do not lower voltage coming from Arduino RX and TX pins from 5V to 3.3V, but since messages are recived coorectly, I don't think that this is causing a problem.
Here's my code:
Arduino:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("on");
delay(1000);
Serial.println("off");
delay(1000);
}
NodeMCU:
#include <SoftwareSerial.h>
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
Serial.println(str);
if(str == "on"){
digitalWrite(D4, HIGH);
}
if(str=="off"){
digitalWrite(D4, LOW);
}
}
Screenshot of COM4:
Screenshot of COM4:
UPD: I tried using sending 1 or 0 as int value via Serial.write() and s.read() and it works, maybe the prolem is in String type somehow
You Use İt Maybe Work
#include <SoftwareSerial.h>
String text = "";
SoftwareSerial s(D7,D8);//rx,tx
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
s.begin(9600);
pinMode(D4,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
String str = s.readStringUntil('\n');
text = str
Serial.println(text);
if(text == "on"){
digitalWrite(D4, HIGH);
}
if(text =="off"){
digitalWrite(D4, LOW);
}
}
I have a problem with the Arduino mega board and the SIM800L module I connect to the RX and TX pins of the module and when I enter the serial monitor it returns these characters, what could it be?
void setup() {
Serial.begin(9600);
//Begin serial communication with Arduino and SIM800L
Serial1.begin(9600);
}
void loop() {
delay(500);
while (Serial.available()) {
Serial1.write(Serial.read()); //Forward what Serial received to Software Serial Port
}
while(Serial1.available()) {
Serial.write(Serial1.read()); //Forward what Software Serial received to Serial Port
}
}
After so much searching and looking on the oscilloscope I have found the solution, In case you are using a LM2596 buck converter to power up the module, remember to common all the ground of the circuit.
I have the ESP8266 connected to my Arduino Uno. With a blank sketch I can use Serial Monitor to connect it to my wifi network using these commands
AT+IPR=9600
AT+CWMODE=1
AT+CWJAP="SSID_HERE",""
It get's an ip and everything. But now I want my sketch to just do this using this code
#include <SoftwareSerial.h>
#define SSID "SSID_HERE"
void setup(){
Serial.begin(9600);
Serial.setTimeout(5000);
delay(1000);
}
boolean connectWiFi()
{
// connect
Serial.println("AT+CWMODE=1");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"");
delay(2000);
if(Serial.find("OK"))
{
Serial.println("AT+CIFSR");
Serial.flush();
delay(1000);
return true;
}
else
{
// Can not connect to the WiFi.
return false;
}
}
But it doesn't work.. The Serial.println shows up in the Serial Monitor, but the ESP8266 doesn't seem to respond. What am I missing?
AT -commands ends with carriage return, so you need to add '\r' to every command you print.
In your code lines looks like:
Serial.println("AT+CWMODE=1\r");
Serial.println("AT+CWJAP=\"SSID_HERE\",\"\"\r");
Serial.println("AT+CIFSR\r");
Reference: https://en.wikibooks.org/wiki/Serial_Programming/Modems_and_AT_Commands/Special_Commands_and_Character_Sequences
The problem here is that you are trying to use pins 0 & 1 for the serial comms, well its part of the problem.. Because the arduino uses serial as well, it for me is only really good to use pins 0 & 1 for serial when i've grounded the reset pin on the arduino. This turns the arduino into a dummy device.
You can use something like software serial and two different pins instead, this way you will not interfere with the hardware serial of the arduino.
Also just to note, the below example will barely work.. For some it will for others it wont.. The problem here is that software serial does not really work / run at 115200..
You can change baud rate via AT+UART_DEF=19200,8,1,0,0 which will also disable flow control, then use software serial with a different speed mySerial.begin(19200)
Using Serial.println("TEXT") will send the line returns for you, so no need to add them unless you use Serial.print("TEXT\r\n")
DO NOT USE: AT+IPR= as this will brick it and require a reflash
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
pinMode(11, INPUT);
pinMode(10, OUTPUT);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("ARDUINO: Starting");
mySerial.begin(115200);
Serial.println("ARDUINO: Sending AT Command");
mySerial.println("AT");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
Following URL will be appear my GSM module and it is included data sheet of the SIM900 module.
http://www.pennybuying.com/gsm-gprs-module-sim900-development-board-lbs-mms-support-arduino-uno-ttl-rs232.html
I have connected only RX,TX,GND and PWR pin between GSM module and Arduino mega board.
Sending a SMS is work properly but receiving SMS is doesn't work.
This is the Arduino Code of sending sms - (Reference - http://tronixstuff.com/2014/01/08/tutorial-arduino-and-sim900-gsm-modules/)
#include <SoftwareSerial.h>
SoftwareSerial SIM900(15,14);
char incoming_char=0;
void setup()
{
Serial.begin(19200); // for serial monitor
SIM900.begin(19200); // for GSM shield
SIM900power(); // turn on shield
delay(20000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(7000);
}
void loop()
{
// Now we simply display any text that the GSM shield sends out on the serial monitor
Serial.println("loop");
if(SIM900.available() > 0)
{
Serial.print("waiting");
incoming_char=SIM900.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
while(1){};
}
}
Try to add SIM900.print("AT+CMGD=1,4\r"); in your setup(). I faced similar problems and the reason was that sim-card memory for messages is full.
You wont get any messages or notification if there is no space in sim memory!
So your setuo loop would look like this
void setup()
{
Serial.begin(19200); // for serial monitor
SIM900.begin(19200); // for GSM shield
SIM900power(); // turn on shield
delay(20000); // give time to log on to network.
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CMGD=1,4\r"); // Deletes all SMS saved in SIM memory
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
}
I have arduino uno connected with itead usbshield. I am receiving the data from android phone and it blinks only when i open serial monitor otherwise it is not. How to blink it independently. Is there any way it relates with opening serial monitor...?
I use pin 13 for blinking it...
Please guide me in to this...
This is the code..
void loop()
{
Usb.Task();
if(adk.isReady()) {
uint8_t msg[1];
uint16_t len = sizeof(msg);
uint8_t rcode = adk.RcvData(&len, msg);
if(rcode && rcode != hrNAK)
USBTRACE2("Data rcv. :", rcode);
if(len > 0) {
Serial.print(F("\r\nData Packet: "));
Serial.print(msg[0]);
digitalWrite(LED,msg[0] ? HIGH : LOW);
}
}
else
digitalWrite(LED, LOW);
}
Regards
Vinod
To which pin is the LED connected? My guess is that it is connected to pin 13
Pin 13 is also wired to the serial port. When ever there is any data transmission happening in the serial port, pin 13 is wired to blink.