WiFly shield + Arduino + auto-connect issue - wifi

I'm using the WiFly shield with Arduino, and everything works fine: I upload my skecth to Arduino via USB, I connect a 9V battery, I disconnect the USB, and the wifi module transmits everything fine (it transmits data to my web server).
When the battery runs out I replace with another battery, but then the wifi/arduino no longer communicates with my server..
I'm a newbie on Arduino and I don't understand whether if every time the power is off Arduino loses the program, or simply that the wifi is not able to auto-connect...
Is this a software problem or hardware?
And if software what am I doing wrong?
This is my sketch example - I'm just sending a string to my server:
#include "WiFly.h"
#include "Credentials.h" // includes ny user:pass wifi network
Client client("[***myserverip***]", 80);
void setup() {
Serial.begin(9600);
WiFly.begin();
if (!WiFly.join(ssid, passphrase)) {
Serial.println("Association failed.");
while (1) {
// Hang on failure.
}
}
connectServer();
}
void loop() {
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
delay(60000); // check every minute
connectServer();
}
}
void connectServer() {
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
String query = "GET /arduino/test?q=testString HTTP/1.0";
client.println(query);
client.println();
} else {
Serial.println("connection failed");
}
}
So everything works fine but when I unplug the power and plug it back the arduino doesnt restart the process.

I found the solution myself - the problem was with the hardware.
The problem was in my Arduino UNO R2, there is a known bug.
I bought a UNO R3 and I don't have this problem anymore.

Its because Arduino board doesn't have on board power on reset when using external power supply so you will always need to reset it just after supplying power. You can put a capacitor at reset pin to eliminate this issue. But if you are using USB as a power source then USB controller will reset the Arduino so in that case you will never have this problem.

Related

ESP8266 not working after baud rate change

Hello guys I have my ESP8266 connected to my Arduino. Then I typed in AT in the serial monitor. It confirmed this command with OK. After that I typed in AT+UART=9600, 8, 1, 0, 0 which gave me the response ERROR. Then I googled what I could do, which told me that I should try change the baud rate permanently with the command AT+IPR=9600. I did this but I got no response. After that I wondered if everything was ok so I typed in AT. No response. Now I'm a little bit sad because everything started to be great but I don't know how I can fix the whole problem. I also tried to upgrade its firmware with XTCOM Utility but it says it can't connect.
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(2, 3); // RX | TX
void setup() {
Serial.begin(115200); // communication with the host computer
//while (!Serial) { ; }
// Start the software serial for communication with the ESP8266
ESPserial.begin(115200);
Serial.println("");
Serial.println("Remember to to set Both NL & CR in the serial monitor.");
Serial.println("Ready");
Serial.println("");
}
void loop() {
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) { Serial.write( ESPserial.read() ); }
// listen for user input and send it to the ESP8266
if ( Serial.available() ) { ESPserial.write( Serial.read() ); }
}
This is my code. I tried it with both 9600 and 115200 but if I use 115200 the serial monitor just shows some garbage signs. It's kind of frustrating because I can't even interact with the serial monitor as my typed commands don't show up anymore. Do you have any idea how I could fix this problem?
EDIT:
I read that the command AT+IPR=9600 breaks the module and it can just be fixed by reflashing it. Sadly this doesn't work because it somehow can`t connect.

ESP8266 5v Relay USB Disconnection issue

Issue
-When using the ESP8266 wired up in this way it will randomly disconnect the USB interface when it powers the relay. It may then re-connect but is sporadic.
-The code can be viewed below, but essentially the relay is powered for 300ms then waits 10 seconds to loop.
Wiring Diagram https://i.stack.imgur.com/4mycx.png
Tests:
I have swapped out the relay, pump, ESP8266, aswell as re-wiring the circuit multiple times to check for a short. I also have a integer incrementing every loop cycle, when the ESP8266 is able to re-connect it will print this variable, which shows the board is not crashing:
Serial output
https://i.stack.imgur.com/ziM8g.png
I then modified the diagram so the 5v power was not in parallel, but where two different power sources, one for the ESP8266 and one for the pump circuit, however the same issue was observed:
Test Wiring Diagram https://i.stack.imgur.com/7S0aP.png
Question:
Why does the USB disconnect when sending the control signal to the relay?
Is there a way to mitigate this?
Code:
int relayInput = 5; // the input to the relay pin
int debug_test = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(relayInput, OUTPUT); // initialize pin as OUTPUT
}
void loop() {
// put your main code here, to run repeatedly:
debug_test ++ ;
Serial.println(debug_test);
digitalWrite(relayInput, HIGH); // turn relay on
Serial.println("Water on!");
delay(300);
digitalWrite(relayInput, LOW); // turn relay off
Serial.println("Water off!");
Serial.println("Waiting 10 seconds");
delay(10000);
}
Parts:
Pump - https://www.ebay.co.uk/itm/Mini-Water-Pump-DC-3V-4-5V-Fish-Tank-Fountain-Aquarium-Submersible-White-Parts/174211676084?hash=item288fd337b4:g:128AAOSwfQteYWF3
ESP8255 - https://www.amazon.co.uk/gp/product/B07F5FJSYZ/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
Relay - https://www.amazon.co.uk/gp/product/B07BVXT1ZK/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
Ok, so researching in to this, it seems when the pump is on it pulls more current (amps) than the PC can provide.
This will be used connected to a external power source which should supply enough current to it, however I also wanted the flexibility to connect it to a PC with a serial connection to troubleshoot.
So in the end something like this:
https://i.stack.imgur.com/MKD1h.png
You are driving a 5v relay module with 3.3v output, which works perfectly for some people but it depends on the relay module and the board, this might be the problem. or the relay draws more than 12mA which is the maximum current can the ESP8266's GPIO deliver.
so I suggest you use an external power source for the relay and control it through the pin (D1 in your case).
Or just use a generic 5v relay with an external 5v power source and control it using a transistor, here is a circuit.
Additional information: https://electronics.stackexchange.com/questions/213051/how-do-i-use-a-5v-relay-with-a-3-3v-arduino-pro-mini?

Unable to read serial/uart pins on NodeMCU

I am unable to read the serial pins in the NodeMCU Lua environment. I have only been able to read the USB serial port.
I have connected a serial adapter to the rx, tx, and g pins.
I have tried this code:
uart.on("data","\n",function(data) print("receive from uart:", data) end, 0)
I enter text in the ESplorer console and it does read that. It doesn't read anything I send over a serial adapter plugged into the rx/tx/g pins.
uart.write(0, "hello")
I disconnected the USB cable and powered it with the serial adapter. Nothing was sent using this code. I tried uart.write(0, and uart.write(1,.
How do I read the pin serial ports instead of the usb serial port?
I needed to unplug the USB cable. The device gets confused if the USB cable is plugged in and you're trying to use the pin serial port.
See my question on the esp forums:
https://www.esp8266.com/viewtopic.php?f=22&t=19768
You have to use different pins then the RX and TX as they are the same as the USB port you are connecting your NodeMCU with to your PC
You can use any other 2 free gpio pins as a serial port with the help of https://github.com/scottwday/EspSoftSerial library. This library is specificly for ESP8266 on which your NodeMCU is based.
This way you have 2 serial ports, one through the usb and another one to connect to other devices.
Some simpel code to implement the Software serial below.
#include <SoftwareSerial.h>
#define BAUD_RATE 9600
SoftwareSerial Serial2(D8, D7, false, 8); //Here you choose the pins you connect the RX TX device to
//The first pin you choose is RX the second TX
// in my example these are the D8 and D7 pins on the nodeMCU
// D8=RX .... D7=TX
void setup() {
Serial.begin(BAUD_RATE);
Serial2.begin(BAUD_RATE);
Serial.println(" ### Hello ###");
Serial2.println(" ### Hello ###");
}
void loop() {
}
}

Serial Communication of Sony Spresense with ESP8266 E12

I'm trying to create a simple serial communication between my ESP8266 E12 and a Sony Spresense. I have connected the Spre.RX with ESP.TX, the Spre.TX with ESP.RX and Spre.GND with ESP.GND.
Receiver:
byte rcvByte;
void setup() {
Serial.begin(9600);
while (!Serial) {;}
Serial.println("Receiving");
}
void loop() {
if (Serial.available()) {
rcvByte = Serial.read();
if (rcvByte == 'H') {
Serial.println("High");
}
if (rcvByte == 'L') {
Serial.println("Low");
}
}
}
Sender:
void setup() {
Serial.begin(9600);
while (!Serial) {;}
Serial.println("Sending");
}
void loop() {
Serial.print('H');
delay(1000);
Serial.print('L');
delay(1000);
Serial.println();
}
Unfortunately, nothing happens. I tried both, ESP as Sender and Spresense as Receiver and vice versa.
It works like a charm when I connect my ESP and a Arudino Uno, in both ways.
Do I have to enable the RX/TX pins with the Spresense somehow? I have tried the pins on the developer board as well as the small board directly. Any suggestions?
I took a quick look into this and my best guess, or tip after checking the code is to try the following on the Spresense side:
Simply change Serial to Serial2.
void setup() {
Serial2.begin(9600);
while (!Serial2) {;}
Serial2.println("Sending");
}
void loop() {
Serial2.print('H');
delay(1000);
Serial2.print('L');
delay(1000);
Serial2.println();
}
I have not tested so please do if you can.
I noticed a small detail in the hardware datasheet provided at:
Spresense Hardware Documents
In the section labeled - 2. Differences between Spresense and Arduino Uno:
It has a small table showing the comparison with explanations.
Located at the bottom of the table one can see the boxes for UART Serial communication.
Note the existence of two serial outputs on the spresense board. The Spresense Main board (smaller nano like) has a serial UART rx/tx pair with syntax variable -> "serial" but in addition the Spresense expansion shield also has a second UART RX/TX pair with syntax -> "serial2"
"The Spresense main board and extension board have UART terminals.
It is not possible to use the UART on both the main board and the extension board at the same time.
The extension board is configured to have the UART enabled when it is shipped. To use the UART pins on the main board when attached to the extension board, a 2.54mm pitch jumper have to be connected to pin 1 and 2 on JP10 of the extension board to disable the extension board UART. No jumper is supplied with the Spresense boards so this has to be purchased separately.
When the extension board UART is activated, the UART pins (D00, D01, D27 and D28) of the main board cannot be used as GPIO."
I ended up spending about three days pulling my hair out before i realized looking at documentation provides all the answers one could need..
The killer is in the details on this one.
This should provide some clarity to others experimenting with UART communication between spresense products while attempting utilize the expansion board.

Redpark Serial Cable Arduino iOS

I've used the RedPark seriable cable with iOS before however, I've only been using it to receive data from an Arduino. My ambition is to be able to transmit information from the iPhone to the Arduino also.
At the moment it's set up to receive
Arduino RX -> Redpark TX
Arduino TX -> Redpark RX
Arduino 5V -> Redpark 5V
Arduino GND -> Redpark GND
The example I used was to toggle the LED on an Arduino board...
void setup() {
Serial.begin(9600); // Start the serial port
pinMode(13, OUTPUT); // Set the built-in LED to output mode
}
void loop() {
if (Serial.available()) { // If there's anything on the serial port,
byte cmd = Serial.read(); // read a single byte from it.
if (cmd == '1') { // If the command is the character '1',
digitalWrite(13, HIGH); // set the LED on
}
if (cmd == '0') { // If the command is the character '0',
digitalWrite(13, LOW); // set the LED off
Serial.print(cmd, BYTE);
}
}
}
I also used the accompanying iPhone app with the Redpark serial cable. I have confirmed I am able tor receive text (using the default app that comes with the RedPark serial cable. So I know that when the iPhone is connected to the Arduino, I am able to receive transmitted data from the Arduino. I can't however transmit any data (the default app allows you to transmit data + the app confirms that the iPhone has sent data. However I am unable to fall into this method on the Arduino, when sending from the iPhone.
if(Serial.available())
{
...
}
For reference, the iPhone I'm using is the iPhone5 with the 30 pin to lightning adapter.

Resources