0

MCP9808 & Ada io
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MCP9808 & Ada io

by morwic on Fri Dec 28, 2018 1:13 am

Hello,
Does anyone have any idea what a working config would be for a mcp9808 on a esp8266 to send data to a single ada io feed ? I've tried the hack on the dht22 config from the ada learn doc's, but I have no luck :(
Thank You

morwic
 
Posts: 45
Joined: Thu Nov 28, 2013 8:37 pm
Location: Houston

Re: MCP9808 & Ada io

by brubell on Fri Dec 28, 2018 11:58 am

The MCP9808 is more similar to the environmental logger project (https://learn.adafruit.com/adafruit-io- ... duino-code) than the DHT22 library.

Post your code, what you got as an output in the Serial Monitor, and I'll help you out.

brubell
 
Posts: 209
Joined: Fri Jul 17, 2015 10:33 pm

Re: MCP9808 & Ada io

by morwic on Fri Dec 28, 2018 12:08 pm

Thank you I'm not a coder and kinda blind... I know it's a great combo LUL. I've been on this for 3 days :( with no joy, thank you so much for your help
Code: Select all | TOGGLE FULL SIZE
/***************************************************
  Adafruit ESP8266 Sensor Module
  Must use ESP8266 Arduino from:
    https://github.com/esp8266/Arduino
  Works great with Adafruit's Huzzah ESP board:
  ----> https://www.adafruit.com/product/2471
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!
  Written by Tony DiCola for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/

// Libraries
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
//#include "DHT.h"
//#include <TMP36.h>
#include "Adafruit_MCP9808.h"

// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();

//TMP36 myTMP36(A0, 3.3);

//DHT 11 sensor
//#define DHTPIN 5
//#define DHTTYPE DHT11

// WiFi parameters
#define WLAN_SSID       "53piritesandonejugofrum"
#define WLAN_PASS       "youMomlikesmyada"

// Adafruit IO
#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "knock knock"
#define AIO_KEY         "no one home"  // Obtained from account info on io.adafruit.com

// DHT sensor
//DHT dht(DHTPIN, DHTTYPE, 15);

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// Setup feeds for temperature & humidity
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/housetemp");
// Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/humidity");

/*************************** Sketch Code ************************************/

void setup() {

  // Make sure the sensor is found, you can also pass in a different i2c
  // address with tempsensor.begin(0x19) for example
  if (!tempsensor.begin()) {
    Serial.println("Couldn't find MCP9808!");
    while (1);
   
  // Init sensor
//  dht.begin();

  Serial.begin(115200);
  Serial.println(F("Adafruit IO Example"));

  // Connect to WiFi access point.
  Serial.println(); Serial.println();
  delay(10);
  Serial.print(F("Connecting to "));
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  Serial.println();

  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());

  // connect to adafruit io
 // connect();
  }
}

void loop() {
    //Serial.println("wake up MCP9808.... "); // wake up MSP9808 - power consumption ~200 mikro Ampere
  //tempsensor.wake();   // wake up, ready to read!

  // Read and print out the temperature, then convert to *F
  float c = tempsensor.readTempC();
  float f = c * 9.0 / 5.0 + 32;
  Serial.print("Temp: "); Serial.print(c); Serial.print("*C\t");
  Serial.print(f); Serial.println("*F");
 
  //Serial.println("Shutdown MCP9808.... ");
  //tempsensor.shutdown(); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
 
  delay(1000);
}

  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
      connect();
  }


  // Grab the current state of the sensor
//  int humidity_data = (int)dht.readHumidity();
  int temperature_data = (int)Adafruit_MCP9808.getTempF();

  // By default, the temperature report is in Celsius, for Fahrenheit uncomment
  //    following line.
   temperature_data = temperature_data*(9.0/5.0) -48.0;

  // Publish data
//  if (! temperature.publish(temperature_data))
    Serial.println(F("Failed to publish temperature"));
  else
    Serial.println(F("Temperature published!"));

//  if (! humidity.publish(humidity_data))
    Serial.println(F("Failed to publish humidity"));
//  else
//    Serial.println(F("Humidity published!"));

  // Repeat every 20 seconds
  delay(10000);

    //create a variable and store the current temperature in
  //celius in it using the getTempC function
  float celsius = myTMP36.getTempC();
 
  //create a variable and store the current temperature in
  //fahrenheit in it using the getTempF function
  float fahrenheit = myTMP36.getTempF();

  //Print the data to the Serial monitor
  Serial.print("Celsius: ");
  Serial.print(celsius);
  Serial.print(" Fahrenheit: ");
  Serial.println(fahrenheit);
  delay(5000);

}

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Adafruit IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if(ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(30000);

  }

  Serial.println(F("Adafruit IO Connected!"));

}
Last edited by brubell on Fri Dec 28, 2018 5:35 pm, edited 1 time in total.
Reason: added code box

morwic
 
Posts: 45
Joined: Thu Nov 28, 2013 8:37 pm
Location: Houston

Re: MCP9808 & Ada io

by morwic on Wed Jan 02, 2019 2:38 pm

any help here ? :(

morwic
 
Posts: 45
Joined: Thu Nov 28, 2013 8:37 pm
Location: Houston

Re: MCP9808 & Ada io

by morwic on Mon Jan 07, 2019 12:02 pm

Any Help yet from Ada ?

morwic
 
Posts: 45
Joined: Thu Nov 28, 2013 8:37 pm
Location: Houston

Re: MCP9808 & Ada io

by abachman on Mon Jan 07, 2019 1:38 pm

After the `delay(1000);` line in your main loop function you have an extra closing curly brace "}", which means your loop is followed by a bunch of extra code that is never executed.

So in your project you have this:
Code: Select all | TOGGLE FULL SIZE
void loop() {
  //Serial.println("wake up MCP9808.... "); // wake up MSP9808 - power consumption ~200 mikro Ampere
  //tempsensor.wake();   // wake up, ready to read!

  // Read and print out the temperature, then convert to *F
  float c = tempsensor.readTempC();
  float f = c * 9.0 / 5.0 + 32;
  Serial.print("Temp: "); Serial.print(c); Serial.print("*C\t");
  Serial.print(f); Serial.println("*F");
 
  //Serial.println("Shutdown MCP9808.... ");
  //tempsensor.shutdown(); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
 
  delay(1000);
}



  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
      connect();
  }


  // Grab the current state of the sensor
//  int humidity_data = (int)dht.readHumidity();
  int temperature_data = (int)Adafruit_MCP9808.getTempF();

  // By default, the temperature report is in Celsius, for Fahrenheit uncomment
  //    following line.
   temperature_data = temperature_data*(9.0/5.0) -48.0;

  // Publish data
//  if (! temperature.publish(temperature_data))
    Serial.println(F("Failed to publish temperature"));
  else
    Serial.println(F("Temperature published!"));

//  if (! humidity.publish(humidity_data))
    Serial.println(F("Failed to publish humidity"));
//  else
//    Serial.println(F("Humidity published!"));

  // Repeat every 20 seconds
  delay(10000);

    //create a variable and store the current temperature in
  //celius in it using the getTempC function
  float celsius = myTMP36.getTempC();
 
  //create a variable and store the current temperature in
  //fahrenheit in it using the getTempF function
  float fahrenheit = myTMP36.getTempF();

  //Print the data to the Serial monitor
  Serial.print("Celsius: ");
  Serial.print(celsius);
  Serial.print(" Fahrenheit: ");
  Serial.println(fahrenheit);
  delay(5000);

}


But the actual code that runs looks like this:
Code: Select all | TOGGLE FULL SIZE
void loop() {
  //Serial.println("wake up MCP9808.... "); // wake up MSP9808 - power consumption ~200 mikro Ampere
  //tempsensor.wake();   // wake up, ready to read!

  // Read and print out the temperature, then convert to *F
  float c = tempsensor.readTempC();
  float f = c * 9.0 / 5.0 + 32;
  Serial.print("Temp: "); Serial.print(c); Serial.print("*C\t");
  Serial.print(f); Serial.println("*F");
 
  //Serial.println("Shutdown MCP9808.... ");
  //tempsensor.shutdown(); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere
 
  delay(1000);
}

abachman
 
Posts: 254
Joined: Mon Feb 01, 2010 12:48 pm

Re: MCP9808 & Ada io

by morwic on Mon Jan 07, 2019 5:47 pm

ahh thank you so much let me try this and see if it will report meow ti ada io :)

morwic
 
Posts: 45
Joined: Thu Nov 28, 2013 8:37 pm
Location: Houston

Please be positive and constructive with your questions and comments.