I'm in a desperate situation here. I have a project that is due for my engineering class tomorrow and have no idea how to get my code to upload to xively. The project is a wireless air sensor. Have CO, CO2, Temp, Humidity, and dust sensor all hooked up. I have the code written and it loops great in the serial monitor. Takes readings every 3 seconds or so. What i dont know how to do is how to use my sparkfun cc3000 wifi shield and upload my data to xively. I have researched extensively and just cant figure it out. I could really use some help writing the code that would connect to my wifi network and take the values I'm already registering from the sensors and post them to Xively every 15 seconds or so. I'm new to all this so forgive me if posted in wrong place or wrong way. Please help!
/*Pin Assigments
CO= A2
Dust Sensor= A1 and D2
CO2 = A0
Temp White = A5
Temp Yellow = A4
*/
#include <Wire.h>
#include <Adafruit_AM2315.h>
#include <SD.h>
#include <math.h>
int analogPin = A0; // voltage input from CO2 sensor
int co2 = 9999; // co2 is the co2 concentration. Preset value for code checking
int measurePin = 1; //Connect dust sensor to Arduino A0 pin
int ledPower = 3; //Connect 3 led driver pins of dust sensor to Arduino D2
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
float v400ppm = 4.01; //MUST BE SET ACCORDING TO CALIBRATION
float v40000ppm = 1.55; //MUST BE SET ACCORDING TO CALIBRATION````````````````````````
float deltavs = v400ppm - v40000ppm;
float A = deltavs/(log10(400) - log10(40000));
float B = log10(400);
Adafruit_AM2315 am2315;
void setup(){
Serial.begin(9600);
pinMode(analogPin, INPUT);
pinMode(ledPower,OUTPUT);
if (! am2315.begin()) {
Serial.println("Sensor not found, check wiring & pullups!");
while (1);
}
}
void loop(){
digitalWrite(ledPower,LOW); // power on the LED
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin); // read the dust value
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(sleepTime);
// 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = voMeasured * (5.0 / 1024.0);
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
// Chris Nafis (c) 2012
dustDensity = 0.17 * calcVoltage - 0.1;
int data = analogRead(analogPin); //digitise output from c02 sensor
float voltage = data/204.6; //convert output to voltage
float power = ((voltage - v400ppm)/A) + B;
float co2ppm = pow(10,power);
co2 = co2ppm;
int val;
val=analogRead(2); //Read Gas value from analog 2
Serial.print("Raw Signal Value (0-1023): ");
Serial.println(voMeasured);
Serial.print(" - Voltage: ");
Serial.println(calcVoltage);
Serial.print(" - Dust Density(mg/m3): ");
Serial.println(dustDensity); // unit: mg/m3
Serial.print("Hum: ");
Serial.println(am2315.readHumidity());
Serial.print("Temp: ");
Serial.println(am2315.readTemperature()*9/5+32);
Serial.print("CO2 is: ");
Serial.println(co2);
Serial.print("CO is: ");
Serial.println(val,DEC);
delay(3000);
}
Sorry, Just really trying to get the information. I have researched for days on how to do this and it just isn't making sense to me. No one was answering my questions, so thought i may have posted in wrong section.
Thank you for the reply and the links. I dont know if if the lack of sleep or i just dont understand but i have read so many examples like this one but i just cant figure out how to get them to work. BTW i am using a cc3000 wifi shield from sparkfun. I cant figure out how to substitute the wifi code for the ethernet code that is alread written. I have included a sketch of the connection test for the board that works currently. Can you please help me to understand how to integrate the two? And then to xively? Thank you.
/****************************************************************
ConnectionTest.ino
CC3000 Connection Test
Shawn Hymel @ SparkFun Electronics
January 30, 2014
https://github.com/sparkfun/SFE_CC3000_Library
Connects to the access point given by the SSID and password and
waits for a DHCP-assigned IP address. To use a static IP
address, change the #define USE_DHCP from 1 to 0 and assign an
IP address to static_ip_addr in the Constants section.
NOTE: Static IP is not working at this time.
The security mode is defined by one of the following:
WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA, WLAN_SEC_WPA2
Hardware Connections:
Uno Pin CC3000 Board Function
+5V VCC or +5V 5V
GND GND GND
2 INT Interrupt
7 EN WiFi Enable
10 CS SPI Chip Select
11 MOSI SPI MOSI
12 MISO SPI MISO
13 SCK SPI Clock
Resources:
Include SPI.h and SFE_CC3000.h
Development environment specifics:
Written in Arduino 1.0.5
Tested with Arduino UNO R3
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful, please
buy us a round!
Distributed as-is; no warranty is given.
****************************************************************/
#include <SPI.h>
#include <SFE_CC3000.h>
// Pins
#define CC3000_INT 2 // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN 7 // Can be any digital pin
#define CC3000_CS 10 // Preferred is pin 10 on Uno
// IP address assignment method
#define USE_DHCP 1 // 0 = static IP, 1 = DHCP
// Connection info data lengths
#define IP_ADDR_LEN 4 // Length of IP address in bytes
#define MAC_ADDR_LEN 6 // Length of MAC address in bytes
// Constants
char ap_ssid[] = "SSID"; // SSID of network
char ap_password[] = "PASSWORD"; // Password of network
unsigned int ap_security = WLAN_SEC_WPA2; // Security of network
unsigned int timeout = 30000; // Milliseconds
//const char static_ip_addr[] = "0.0.0.0";
// Global Variables
SFE_CC3000 wifi = SFE_CC3000(CC3000_INT, CC3000_EN, CC3000_CS);
void setup() {
ConnectionInfo connection_info;
int i;
// Initialize Serial port
Serial.begin(115200);
Serial.println();
Serial.println("---------------------------------");
Serial.println("SparkFun CC3000 - Connection Test");
Serial.println("---------------------------------");
// Initialize CC3000 (configure SPI communications)
if ( wifi.init() ) {
Serial.println("CC3000 initialization complete");
} else {
Serial.println("Something went wrong during CC3000 init!");
}
#if (USE_DHCP == 1)
// Connect using DHCP
Serial.print("Connecting to: ");
Serial.println(ap_ssid);
if(!wifi.connect(ap_ssid, ap_security, ap_password, timeout)) {
Serial.println("Error: Could not connect to AP");
}
#elif (USE_DHCP == 0)
// Connect using static IP
// ***TODO: Connect using static IP
#endif
// Print out connection details
if( !wifi.getConnectionInfo(connection_info) ) {
Serial.println("Error: Could not obtain connection details");
} else {
Serial.println("Connected!");
Serial.println();
// Print MAC address
Serial.print("CC3000 MAC Address: ");
for ( i = 0; i < MAC_ADDR_LEN; i++ ) {
if ( connection_info.mac_address[i] < 0x10 ) {
Serial.print("0");
}
Serial.print(connection_info.mac_address[i], HEX);
if ( i < MAC_ADDR_LEN - 1 ) {
Serial.print(":");
}
}
Serial.println();
// Print IP Address
Serial.print("IP Address: ");
printIPAddr(connection_info.ip_address);
Serial.println();
// Print subnet mask
Serial.print("Subnet Mask: ");
printIPAddr(connection_info.subnet_mask);
Serial.println();
// Print default gateway
Serial.print("Default Gateway: ");
printIPAddr(connection_info.default_gateway);
Serial.println();
// Print DHCP server address
Serial.print("DHCP Server: ");
printIPAddr(connection_info.dhcp_server);
Serial.println();
// Print DNS server address
Serial.print("DNS Server: ");
printIPAddr(connection_info.dns_server);
Serial.println();
// Print SSID
Serial.print("SSID: ");
Serial.println(connection_info.ssid);
Serial.println();
}
// Disconnect
if ( wifi.disconnect() ) {
Serial.println("Disconnected");
} else {
Serial.println("Error: Could not disconnect from network");
}
// Done!
Serial.println("Finished connection test");
}
void loop() {
// Do nothing
delay(1000);
}
// Print out an IP Address in human-readable format
void printIPAddr(unsigned char ip_addr[]) {
int i;
for (i = 0; i < IP_ADDR_LEN; i++) {
Serial.print(ip_addr[i]);
if ( i < IP_ADDR_LEN - 1 ) {
Serial.print(".");
}
}
}