I can run the example code for the Max 31855K Thermocouple and so for ESP8266. The problem is when I try to run them together to transmit the reading from the thermocouple. In the attached code, it will work but stop sending data to data.sparkfun.com when you try to take a reading.
// ******** Code drawn from examples, list authors in final version *********************
// ************************ Definitions *************************************************
const char phantServer[] = "data.sparkfun.com";
const char publicKey[] = "aGLVE5gv7mCEvKzdJr6z";
const char privateKey[] = "KEp594eG12cGp56JKnB6";
const uint8_t CHIP_SELECT_PIN = 10; // Using standard CS line (SS)
const uint8_t VCC = 2; // Powering board straight from Arduino Pro Mini
const uint8_t GND = 3;
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SparkFunESP8266WiFi.h>
#include <SparkFunMAX31855k.h>
#include <Phant.h>
Phant phant(phantServer, publicKey, privateKey);
SparkFunMAX31855k Thermocouple(CHIP_SELECT_PIN, VCC, GND);
// ***************************** Setup ************************************************
void setup()
{
int status;
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
pinMode(12, OUTPUT); digitalWrite(12, HIGH); //Setup LM34 Power 5.0 V, // LM34 Ground uses ground
pinMode(6, OUTPUT); digitalWrite(6, LOW); // Setup LVL Converter and Thermal Couple Ground 0.0V
pinMode(7, OUTPUT); digitalWrite(7, HIGH); //Setup LVL Converter High Side Power 5.0 V, // Thermal Couple High and LVL Cinverter Low Side Power use 3.3 power
Serial.begin(9600);
status = esp8266.begin();
if (status <= 0)
{
Serial.println(F("Unable to communicate with shield. Looping"));
while(1) ;
}
Serial.println(F("Press any key to post to Phant!"));
}
//**************************** Main Program Loop *********************************************
void loop()
{
postToPhant();
delay(10000);
}
void postToPhant()
{
// Create a client, and initiate a connection
ESP8266Client client;
if (client.connect(phantServer, 80) <= 0)
{
Serial.println(F("Failed to connect to server."));
return;
}
Serial.println(F("Connected."));
float probe1 = 55.0;
// Thermocouple.readCJT(); // ******* using this line cause a failure on transmitting data
// float probe2=Thermocouple.readTempF(); // ******* using this line cause a failure on transmitting data
Serial.println(temperature);
phant.add(F("chimney"), 500.0*analogRead(A1)/1024);
phant.add(F("exhaust"), probe1);
phant.add(F("intake"), 500.0*analogRead(A2)/1024);
phant.add(F("pipe"), 500.0*analogRead(A3)/1024);
phant.add(F("tank"), 500.0*analogRead(A4)/1024);
phant.add(F("vent"), 500.0*analogRead(A5)/1024);
Serial.println(F("Posting to Phant!"));
client.print(phant.post());
while (client.available())
Serial.write(client.read()); // read() gets the FIFO char
if (client.connected())
client.stop(); // stop() closes a TCP connection.
} :think:
First of all, it is not clear what Arduino module this is connected to. The code talks about pins on the Arduino Pro Mini. But the SparkFun ESP8266 WiFi shield is a different form-factor. Which won’t fit or connect without manually wiring it up. Since there could be potential faults in there I suggest you show a bit more of how that hardware is connected.
In the example of the [SparkFun MAX31855K librarythey check if the return value of readCJT() and readTempF() is an actual number. Since you don’t do that you may be trying to send a number which isn’t a valid one. If the library determines there is a fault while reading it then it does return a N(ot)aN(umber) as result.
If you look at the end of the following link (the actual SparkFunMAX31855k library sourcecode) it shows the content of a checkHasFault function which should send some details over the serial port. It would be great if you could post the contents of your serial monitor log. Depending on how you have things wired up this may be sent to the ESP8266 instead of the PC. So you may not see something in there. But … “'the truth is out there”.
Thanks, I’ll check the error catching code that sounds likely. I am using a redboard, wifisheild, and the sparkfun thermocouple amplifier. The code is cut and paste from the related demos which work independently. The commenting may be off too I was planning to update it with sources as soon as I fix this error. THANKS
I added back in the checkfault, cleaned up and simplified the code a little but still no luck on running the thermocouple at the same time. I also tried stopping the SPI but no use. It seems like the thermocouple code corrupts the phant data. Here is the new code
// ******** Code drawn from examples, list authors in final version *********************
// Portions of code from SparkFun ESP8266 AT library - Phant Posting Example by Jim Lindblom @ SparkFun Electronics
// Portions of code from MAX31855K Thermocouple Breakout Example Code by brent@sparkfun.com
// ************************ Definitions *************************************************
const char phantServer[] = "data.sparkfun.com";
const char publicKey[] = "aGLVE5gv7mCEvKzdJr6z";
const char privateKey[] = "KEp594eG12cGp56JKnB6";
const uint8_t CHIP_SELECT_PIN = 10; // Using standard CS line (SS)
const uint8_t VCC = 7; //
const uint8_t GND = 6;
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SparkFunESP8266WiFi.h>
#include <SparkFunMAX31855k.h>
#include <Phant.h>
Phant phant(phantServer, publicKey, privateKey);
SparkFunMAX31855k Thermocouple(CHIP_SELECT_PIN, VCC, GND);
// ***************************** Setup ************************************************
void setup()
{
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
pinMode(12, OUTPUT); digitalWrite(12, HIGH); //Setup LM34 Power 5.0 V, // LM34 Ground uses ground
pinMode(6, OUTPUT); digitalWrite(6, LOW); // Setup LVL Converter and Thermal Couple Ground 0.0V
pinMode(7, OUTPUT); digitalWrite(7, HIGH); //Setup LVL Converter High Side Power 5.0 V, // Thermal Couple High and LVL Cinverter Low Side Power use 3.3 power
}
//**************************** Main Program Loop *********************************************
void loop() {
Serial.begin(9600);
// ------------- Thermocouple Code ------------------------------------
float temperature=696.0;
temperature = Thermocouple.readCJT();
temperature = Thermocouple.readTempF();
if (!isnan(temperature)) {
Serial.print("\tTemp[F]=");
Serial.println(temperature);
}
SPI.end();
Serial.println("SPI Stopped");
//------------ Begin ESP Code ---------------------------------------
int status=0;
status = esp8266.begin();
delay(500);
if (status <= 0)
{
Serial.println(F("Unable to communicate with shield. Looping"));
while(1) ;
}
ESP8266Client client;
if (client.connect(phantServer, 80) <= 0)
{
Serial.println(F("Failed to connect to server."));
return;
}
Serial.println(F("Connected to Sheild"));
delay(500);
//------------- Post via Phant --------------------
phant.clear();
phant.add(F("chimney"), 500.0*analogRead(A1)/1024);
phant.add(F("exhaust"), temperature);
phant.add(F("intake"), 500.0*analogRead(A2)/1024);
phant.add(F("pipe"), 500.0*analogRead(A3)/1024);
phant.add(F("tank"), 500.0*analogRead(A4)/1024);
phant.add(F("vent"), 500.0*analogRead(A5)/1024);
Serial.println(F("Posting to Phant!"));
client.print(phant.post());
while (client.available())
Serial.write(client.read()); // read() gets the FIFO char
if (client.connected())
client.stop(); // stop() closes a TCP connection.
Serial.println("Posting Complete");
Serial.println(" ");
delay(9000);
}
The serial monitor when working is
Connected to Sheild
Posting to Phant!
Posting Complete
and here is what it does when I include the thermcouple code lines
Temp[F]=77.00
SPI Stopped
Connected to Sheild
Posting to Phant!
+IPD,0,187:HTTP/1.0 400 Bad request
Cache-Control: no-cach
Posting Complete
Valen was on to something. I could be mistating the details here but It turns out that the Phant code appears to use some direct addressing of RAM that can get interferred with when communicating to the thermal couple via SPI. The solution was to not use Phant but directly build a string for the data push to data.sparkfun. In the attached code, I did so and now can post the data through a “Get” call.
// ******** Code drawn from examples, list authors in final version *********************
// Portions of code from SparkFun ESP8266 AT library - Phant Posting Example by Jim Lindblom @ SparkFun Electronics
// Portions of code from MAX31855K Thermocouple Breakout Example Code by brent@sparkfun.com
// ************************ Definitions *************************************************
const char phantServer[] = "data.sparkfun.com";
const char publicKey[] = "aGLVE5gv7mCEvKzdJr6z";
const char privateKey[] = "KEp594eG12cGp56JKnB6";
const uint8_t CHIP_SELECT_PIN = 10; // Using standard CS line (SS)
const uint8_t VCC = 7; //
const uint8_t GND = 6;
#include <SoftwareSerial.h>
#include <SPI.h>
#include <SparkFunESP8266WiFi.h>
#include <SparkFunMAX31855k.h>
#include <Phant.h>
Phant phant(phantServer, publicKey, privateKey);
SparkFunMAX31855k Thermocouple(CHIP_SELECT_PIN, VCC, GND);
// ***************************** Setup ************************************************
void setup()
{
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
pinMode(12, OUTPUT); digitalWrite(12, HIGH); //Setup LM34 Power 5.0 V, // LM34 Ground uses ground
pinMode(6, OUTPUT); digitalWrite(6, LOW); // Setup LVL Converter and Thermal Couple Ground 0.0V
pinMode(7, OUTPUT); digitalWrite(7, HIGH); //Setup LVL Converter High Side Power 5.0 V, // Thermal Couple High and LVL Cinverter Low Side Power use 3.3 power
}
//**************************** Main Program Loop *********************************************
void loop() {
Serial.begin(9600);
// ------------- Thermocouple Code ------------------------------------
float temperature=696.0;
temperature = Thermocouple.readCJT();
temperature = Thermocouple.readTempF();
if (!isnan(temperature)) {
Serial.print("\tTemp[F]=");
Serial.println(temperature);
}
SPI.end();
Serial.println("SPI Stopped");
//------------ Begin ESP Code ---------------------------------------
int status=0;
status = esp8266.begin();
delay(500);
if (status <= 0)
{
Serial.println(F("Unable to communicate with shield. Looping"));
while(1) ;
}
ESP8266Client client;
if (client.connect(phantServer, 80) <= 0)
{
Serial.println(F("Failed to connect to server."));
return;
}
Serial.println(F("Connected to Sheild"));
delay(500);
//------------- Post via a Get Call to Client (Phant Conflicts with SPI) --------------------
String posting="GET /input/aGLVE5gv7mCEvKzdJr6z?private_key=KEp594eG12cGp56JKnB6";
posting+=String("&chimney=");
posting+=String((500.0*analogRead(A1)/1024),2);
posting+="&exhaust=";
posting+=String(temperature,2);
posting+="&intake=";
posting+=String((500.0*analogRead(A2)/1024),2);
posting+="&pipe=";
posting+=String((500.0*analogRead(A3)/1024),2);
posting+="&tank=";
posting+=String((500.0*analogRead(A4)/1024),2);
posting+="&vent=";
posting+=String((500.0*analogRead(A5)/1024),2);
Serial.println(F("Posting to Phant!"));
Serial.println(posting);
client.println(posting);
while (client.available())
Serial.write(client.read()); // read() gets the FIFO char
if (client.connected())
client.stop(); // stop() closes a TCP connection.
Serial.println("Posting Complete");
Serial.println(" ");
delay(9000);
}