I can get the sensor to work on it's own sketch and I can get the iOS Arduino Manager to work on it's own sketch. When I put the two together it's broken. I have stripped down the code to the very basics:
#include <SoftwareSerial.h>
#include "cozir.h"
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include <Servo.h>
#include <IOSController.h>
#include <avr/wdt.h>
SoftwareSerial nss(10,11);
COZIR czr(nss);
/*
*
* Ethernet Library configuration
*
*/
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC Address assigned to the board
/*
*
* IP info
*
* Using DHCP these parameters are not needed
*/
IPAddress ip(192,168,0,164);
IPAddress gateway(192,168,0,1);
IPAddress subnet(255,255,255,0);
/*
*
* Initialize the Ethernet server library
*/
EthernetServer server(80); // Messages received on port 80
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
//#define CHIPSELECT 4
/**
*
* Other initializations
*
*/
#define YELLOWLEDPIN 13
int yellowLed = HIGH;
float temperature;
#define CONNECTIONPIN 7
int connectionLed = LOW;
float tempf = 0;
/*
*
* Prototypes of IOSController’s callbacks
*
*
*/
void doWork();
void doSync(char *variable);
void processIncomingMessages(char *variable, char *value);
void processOutgoingMessages();
void deviceConnected();
void deviceDisconnected();
/*
*
* IOSController Library initialization
*
*/
IOSController iosController(&server,&doWork,&doSync,&processIncomingMessages,&processOutgoingMessages,&deviceConnected,&deviceDisconnected);
void setup()
{
Serial.begin(9600);
Serial.println("Starting");
delay(3000);
czr.SetOperatingMode(CZR_POLLING);
czr.SetDigiFilter(32);
/*
* Start the Ethernet connection and the server
* ATTENTION: Ethernet Library provided with Arduino 1.0 has the subnet and gateway swapped respect to the documentation
*
*/
Ethernet.begin(mac, ip, subnet, gateway);
server.begin();
/**
*
* Other initializations
*
*/
// Yellow LED on
pinMode(YELLOWLEDPIN,OUTPUT);
digitalWrite(YELLOWLEDPIN,yellowLed);
}
/**
*
* Standard loop function
*
*/
void loop()
{
//iosController.loop();
iosController.loop(500);
}
/**
*
*
* This function is called periodically and its equivalent to the standard loop() function
*
*/
void doWork() {
temperature = 75.26;
float t = czr.Celsius();
float f = czr.Fahrenheit();
float h = czr.Humidity();
float c = czr.CO2();
float digi = czr.GetDigiFilter();
tempf = f;
Serial.print("Celcius : ");Serial.println(t);
Serial.print("Fahrenheit : ");Serial.println(f);
Serial.print("Humidity : ");Serial.println(h);
Serial.print("CO2 : ");Serial.println(c);
Serial.print("Digital Filter : ");Serial.println(digi);
digitalWrite(YELLOWLEDPIN,yellowLed);
}
/**
*
*
* This function is called when the ios device connects and needs to initialize the position of switches and knobs
*
*/
void doSync (char *variable) {
if (strcmp(variable,"S1")==0) {
iosController.writeMessage(variable,digitalRead(YELLOWLEDPIN));
}
}
/**
*
*
* This function is called when a new message is received from the iOS device
*
*/
void processIncomingMessages(char *variable, char *value) {
if (strcmp(variable,"S1")==0) {
yellowLed = atoi(value);
}
}
/**
*
*
* This function is called periodically and messages can be sent to the iOS device
*
*/
void processOutgoingMessages() {
iosController.writeMessage("T",temperature);
iosController.writeMessage("Temp", tempf);
iosController.writeMessage("Led13",yellowLed);
}
/**
*
*
* This function is called when the iOS device connects
*
*/
void deviceConnected () {
digitalWrite(CONNECTIONPIN,HIGH);
}
/**
*
*
* This function is called when the iOS device disconnects
*
*/
void deviceDisconnected () {
digitalWrite(CONNECTIONPIN,LOW);
}
/**
*
* Auxiliary functions
*
*/
/*
* getVoltage() – returns the voltage on the analog input defined by pin
*
*/
float getVoltage(int pin) {
return (analogRead(pin) * .004882814); // converting from a 0 to 1023 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
If I comment out this section the program will run it just won't poll the sensor...
void doWork() {
temperature = 75.26;
//float t = czr.Celsius();
//float f = czr.Fahrenheit();
//float h = czr.Humidity();
// float c = czr.CO2();
// float digi = czr.GetDigiFilter();
//tempf = f;
Serial.print("Celcius : ");Serial.println(t);
Serial.print("Fahrenheit : ");Serial.println(f);
Serial.print("Humidity : ");Serial.println(h);
Serial.print("CO2 : ");Serial.println(c);
Serial.print("Digital Filter : ");Serial.println(digi);
digitalWrite(YELLOWLEDPIN,yellowLed);
}
Not sure where to go from here.
Thanks,
Midgaar