Hi all,
I'm new in Arduino. I have the following problem and hope to find a solution here.
I have a Arduino Mega2560 with a Wifly shield installed. Mega-Pins 50-53 are connected to the Wifly board 10-13.
I have a Arduino program to control a few digital outputs and a servo. These outputs will be controlled over a telnet session or a iPad Connection. As long as I use the Ethernet shield, the programm runs fine, I can control the digital outputs as well as the servo.
as soon as I use the Wifly library, I can control the digital outputs but the Servo is not moving anymore.
I have read somewhere that the Timers are in conflict but even with the ServoTimer2 Library I can not get it to work.
Is there a fact-sheet for the Libraries telling what Registers are used?
Can somebody help me here to get the problem solved?
Are there some limitations I didn't count with?
What I have: Library Wifly downloaded from here : GitHub - sparkfun/WiFly-Shield: WiFly Shield -- A shield for the Roving Networks RN-52 WiFly Module. and did some moving of the Libraries
Arduino Mega2560 IDE 1.0.6 with default Libraries
My code:
/*
* Web Server
*
* (Based on Ethernet's WebServer Example)
*
* A simple web server that shows the value of the analog input pins.
* for the MEGA board: Pins 50->12, 51->11, 52->13, 53->10 Be sure these pins (10-13) are not connected to the Mega
* WiFly will have IP 169.254.1.1
*/
#include <SPI.h>
#include <WiFly.h>
#include <Servo.h>
#include "Credentials.h"
// Pins used on Arduino
const int ledPinGruen = 24;
const int ledPinGelb = 25;
const int ledPinRot = 26;
const int servoPinA = 29;
int ledState = LOW;
// The getInputStream has a blank line
int inputStringIndex = 0;
int inputStringStart = 0;
char inputString[] = {};
Servo myservo; // create servo object to control a servo
WiFlyServer server(23);
void setup() {
pinMode(ledPinGruen, OUTPUT);
pinMode(ledPinGelb, OUTPUT);
pinMode(ledPinRot, OUTPUT);
digitalWrite(ledPinGruen,LOW);
digitalWrite(ledPinGelb,LOW);
digitalWrite(ledPinRot,LOW);
WiFly.begin(true);
Serial.begin(9600);
Serial.println("WiFly Shield AdHoc Example");
if(!WiFly.createAdHocNetwork(ssid)) {
while(1) {
Serial.println("Failed to create network, handle error properly?");
}
}
Serial.println("Network Created");
Serial.print("IP: ");
Serial.println(WiFly.ip());
Serial.println("Starting Server");
server.begin();
myservo.attach(servoPinA); // attaches the servo on pin 28 to the servo object
}
void SetOutput()
{
boolean Output;
String tempString;
int tempInt;
int pos = 0; // variable to store the servo position
inputStringStart++;
if (inputString[inputStringStart+1] == '0') {
Output=LOW;
} else {
Output=HIGH;
}
switch (inputString[inputStringStart]) {
case '0':
digitalWrite(ledPinGruen, Output);
break;
case '1':
digitalWrite(ledPinGelb, Output);
break;
case '2':
digitalWrite(ledPinRot, Output);
break;
case '3':
tempString = inputString;
tempString = tempString.substring(2);
tempInt = tempString.toInt();
Serial.println(tempInt);
myservo.write(tempInt);
break;
default: ;
}
}
void decodeInputString()
{
/*
Format of an inputString:
first char: G or S
G = Get
S = Set
second char: Type
third char: Version
rest: parameterlist
*/
inputStringStart = 0;
switch (inputString[inputStringStart]) {
case 'G':
// do get
break;
case 'S':
// do set
Serial.println("Found S");
SetOutput();
break;
default:
// move start of inputSting
// ToDo in case the first char was not one of the above, move pointer and try again, check pointer against line length
Serial.println("No S or G found");
}
}
void getInputStream(char c)
{
// reads the input till newLine
inputString[inputStringIndex] = c;
inputStringIndex++;
if (c == '\n') {
// you're starting a new line
decodeInputString();
inputStringIndex = 0;
}
}
void loop() {
delay(200);
WiFlyClient client = server.available();
Serial.println("Server Available");
if (client) {
Serial.println("new client");
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
getInputStream(c);
}
}
client.stop();
Serial.println("client disconnected");
}
}