ESP8266-01 Client
Posted: Wed Feb 08, 2017 5:19 pm
Hello!
Im new at Arduino and now im trying to get a program working.
(the program will read data from my Iphone get GPS position from it. Im using ESP8266-01 to connect the phone and the Arduino..... then the program will calculate the heading from two GPS positions... then i will have a stepmotor or a servo pointing in this direction.)
i have got a program that transfer the GPS from phone to Arduino working....
I have got a program working with the servo....
But when i put this two together somthing strange happens to the Digital ports...
The servo turning each time the ESP8266-01 is getting data or sending data....
I have connected the ESP8266-01 to the 3V and even tried to have external power to it....
Nothing makes the servo stop turning when the wifi is working.
[lis] /*
Koppla Wifi och Arduino
*/
#include <Servo.h>
#include <SoftwareSerial.h>
#include <math.h>
#include "WiFiEsp.h" //"WiFiEsp.h"
TinyGPSPlus gps;
SoftwareSerial Serial1(2, 3);//6,7
Servo myservo;
char ssid[]="XXXX"; //namn på nätverk/telefon
char pass[]="PassXXX"; //lösen nätverk/telefon
int status = WL_IDLE_STATUS; //status
char server[] = "Toconnect"; //server att koppla upp mot
// Initialize the Ethernet client object
WiFiEspClient client;//WiFiEspClient
double stativLat=0;
double stativLong=0;
double heading=0;
double distanceM =0;
int raknare=0;
int pos=0;
void setup()
{
myservo.attach(10); // attaches the servo on pin 9 to the servo
Serial.begin(115200); //serial fönsterhastighet
Serial1.begin(9600); //hastighet för WiFi
WiFi.init(&Serial1);
//Ser om wifi finns telefonen
if (WiFi.status()== WL_NO_SHIELD) {
Serial.println("WiFi hittades inte");
// kör inte vidare
while(true);
}
//kopplar upp mot telefon
while (status != WL_CONNECTED) {
Serial.print("Kopplar upp mot telefon ");
Serial.println(ssid);
// uppkopplad mot telefon
status = WiFi.begin(ssid, pass);
}
Serial.println("Du har kopplat upp mot telefon");
PrintWifiStatus();
// koppla upp mot server
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
//50000/11000
if (client.connect(server, 11000)) {
Serial.println("Connected to server");
}
}
void loop()
{
if (raknare==0){
for (pos = 0; pos <= 360; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
// myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for (pos = 360; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
// myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
delay(5000);
// Serial.print("vrider upp");
}
// if there are incoming bytes available
// from the server, read them and print them
while (client.available()) {
if (gps.encode(client.read())){
if (gps.location.isValid()&& raknare==0){
// Serial.print("inne");
stativLat=gps.location.lat(); // Latitude in degrees (double)
stativLong=gps.location.lng(); // Longitude in degrees (double)
// Serial.print("satte");
// Serial.print(stativLat, 6);
// Serial.print('\n');
// Serial.print(stativLong, 6);
// Serial.print('\n');
raknare++;
}
if (gps.location.isValid()){
double distanceToStativ =
TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
stativLat,
stativLong);
// Serial.print(F("Distance="));
// Serial.print(distanceToStativ, 6);
// Serial.print('\n');
//client.flush();
double courseTo =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
stativLat,
stativLong);
// Serial.println(courseTo);
// Serial.println(TinyGPSPlus::cardinal(courseTo));
//displayInfo();
// Serial.print('\n');
// Serial.print(digitalRead(9));
// Serial.print('\n');
}
}
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
Serial.print('\n');
}
}
void PrintWifiStatus(){
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Adress: ");
Serial.println(ip);
}
[/lis]
Im new at Arduino and now im trying to get a program working.
(the program will read data from my Iphone get GPS position from it. Im using ESP8266-01 to connect the phone and the Arduino..... then the program will calculate the heading from two GPS positions... then i will have a stepmotor or a servo pointing in this direction.)
i have got a program that transfer the GPS from phone to Arduino working....
I have got a program working with the servo....
But when i put this two together somthing strange happens to the Digital ports...
The servo turning each time the ESP8266-01 is getting data or sending data....
I have connected the ESP8266-01 to the 3V and even tried to have external power to it....
Nothing makes the servo stop turning when the wifi is working.
[lis] /*
Koppla Wifi och Arduino
*/
#include <Servo.h>
#include <SoftwareSerial.h>
#include <math.h>
#include "WiFiEsp.h" //"WiFiEsp.h"
TinyGPSPlus gps;
SoftwareSerial Serial1(2, 3);//6,7
Servo myservo;
char ssid[]="XXXX"; //namn på nätverk/telefon
char pass[]="PassXXX"; //lösen nätverk/telefon
int status = WL_IDLE_STATUS; //status
char server[] = "Toconnect"; //server att koppla upp mot
// Initialize the Ethernet client object
WiFiEspClient client;//WiFiEspClient
double stativLat=0;
double stativLong=0;
double heading=0;
double distanceM =0;
int raknare=0;
int pos=0;
void setup()
{
myservo.attach(10); // attaches the servo on pin 9 to the servo
Serial.begin(115200); //serial fönsterhastighet
Serial1.begin(9600); //hastighet för WiFi
WiFi.init(&Serial1);
//Ser om wifi finns telefonen
if (WiFi.status()== WL_NO_SHIELD) {
Serial.println("WiFi hittades inte");
// kör inte vidare
while(true);
}
//kopplar upp mot telefon
while (status != WL_CONNECTED) {
Serial.print("Kopplar upp mot telefon ");
Serial.println(ssid);
// uppkopplad mot telefon
status = WiFi.begin(ssid, pass);
}
Serial.println("Du har kopplat upp mot telefon");
PrintWifiStatus();
// koppla upp mot server
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
//50000/11000
if (client.connect(server, 11000)) {
Serial.println("Connected to server");
}
}
void loop()
{
if (raknare==0){
for (pos = 0; pos <= 360; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
// myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for (pos = 360; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
// myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
delay(5000);
// Serial.print("vrider upp");
}
// if there are incoming bytes available
// from the server, read them and print them
while (client.available()) {
if (gps.encode(client.read())){
if (gps.location.isValid()&& raknare==0){
// Serial.print("inne");
stativLat=gps.location.lat(); // Latitude in degrees (double)
stativLong=gps.location.lng(); // Longitude in degrees (double)
// Serial.print("satte");
// Serial.print(stativLat, 6);
// Serial.print('\n');
// Serial.print(stativLong, 6);
// Serial.print('\n');
raknare++;
}
if (gps.location.isValid()){
double distanceToStativ =
TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
stativLat,
stativLong);
// Serial.print(F("Distance="));
// Serial.print(distanceToStativ, 6);
// Serial.print('\n');
//client.flush();
double courseTo =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
stativLat,
stativLong);
// Serial.println(courseTo);
// Serial.println(TinyGPSPlus::cardinal(courseTo));
//displayInfo();
// Serial.print('\n');
// Serial.print(digitalRead(9));
// Serial.print('\n');
}
}
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
Serial.print('\n');
}
}
void PrintWifiStatus(){
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Adress: ");
Serial.println(ip);
}
[/lis]