Hello all,
I am attempting to hook up 5 load cells, a thermocouple, a RTC clock, a microusb (used for datalogging), an ESP8266 Wifi module and a 4x20 LCD screen on an arduino MEGA.
I have gotten the various aspects working, and now its time for full integration. I apologize in advance for throwing so much at you all at once.
What seems to not be working now, is that I cannot get the Serial monitor stream to pass into my "Sendcommand" function, which essentially passes a string (comma delimited) through ESP to an online service which logs the data over wifi as well. I have tried Stream &Serial1, but then it throws errors that Serial1 is not defined in this scope for both the void loop, and void setup (Where it is actually declared).
Posed is my ENTIRE code [in two parts, max post char count ](Again sorry for so much at once, and its probably atrocious).
Thank you so so much for any help, I've been working on this for months...
#include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "max6675.h"
#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
#include <Adafruit_ssd1306syp.h>
//Calibration constant for load cell 1-5 - This value is obtained using the SparkFun_HX711_Calibration sketch
#define calibration_factor1 -7050.0
#define calibration_factor2 -7050.0
#define calibration_factor3 -7050.0
#define calibration_factor4 -7050.0
#define calibration_factor5 -7050.0
//Pin definitions
#define LoadCellFiveDOUT 11
#define LoadCellFiveCLK 10
#define LoadCellFourDOUT 9
#define LoadCellFourCLK 8
#define LoadCellThreeDOUT 7
#define LoadCellThreeCLK 6
#define LoadCellTwoDOUT 5
#define LoadCellTwoCLK 4
#define LoadCellOneDOUT 3
#define LoadCellOneCLK 2
//Load cell object allocations
HX711 LoadCellOne(LoadCellOneDOUT, LoadCellOneCLK);
HX711 LoadCellTwo(LoadCellTwoDOUT, LoadCellTwoCLK);
HX711 LoadCellThree(LoadCellThreeDOUT, LoadCellThreeCLK);
HX711 LoadCellFour(LoadCellFourDOUT, LoadCellFourCLK);
HX711 LoadCellFive(LoadCellFiveDOUT, LoadCellFiveCLK);
//LCD Object
LiquidCrystal_I2C lcd(0x27,20,21); // set the LCD address to 0x27 for a 16 chars and 2 line display
//OLED Object
Adafruit_ssd1306syp display(37,35);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET
//Wifi Access Point Name and Password
String AP = "temp"; // CHANGE ME
String PASS = "temp"; // CHANGE ME
int counter = 0;
//Counting Variables for wifi processing
int countTrueCommand;
int countTimeCommand;
boolean found = false;
String API = "temp"; // CHANGE ME
String HOST = "api.thingspeak.com";
String PORT = "80";
String field1 = "field1";
String field2 = "field2";
String field3 = "field3";
String field4 = "field4";
String field5 = "field5";
String field6 = "field6";
String field7 = "field7";
//Water value variable
int watervalue = 0;
//Water level variable
int adc_id = 0;
//Clock object
DS3231 rtc(A4, A5);
//Pin allocation for thermocouple
int ktcSO = 49;
int ktcCS = 47;
int ktcSCK = 45;
//Constant for sd card
const int chipSelect = 53;
//Thermocouple object
MAX6675 ktc(ktcSCK, ktcCS, ktcSO);
void setup() {
//wifi initialization
Serial1.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20,"OK");
//Initializes LCD
lcd.init();
lcd.backlight();
//Initializes OLED
display.initialize();
display.setTextSize(1);
display.setTextColor(WHITE);
//Initializes SD Card
pinMode(chipSelect, OUTPUT);
//Starts day and time clock
rtc.begin();
//Initializes date and time - CHANGE IF CLOCK IS OFF, LOAD PROGRAM WITH THIS UNCOMMENTED (update day of week, time and date fields), THEN COMMENT OUT AGAIN
//---------------------------
//rtc.setDOW(WEDNESDAY);
//rtc.setTime(14,06,20);
//rtc.setDate(3,1,2019);
//---------------------------
//Sets load cell calibrations and tares
LoadCellOne.set_scale(calibration_factor1); //This value is obtained by using the SparkFun_HX711_Calibration sketch
LoadCellOne.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
LoadCellTwo.set_scale(calibration_factor2); //This value is obtained by using the SparkFun_HX711_Calibration sketch
LoadCellTwo.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
LoadCellThree.set_scale(calibration_factor3); //This value is obtained by using the SparkFun_HX711_Calibration sketch
LoadCellThree.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
LoadCellFour.set_scale(calibration_factor4); //This value is obtained by using the SparkFun_HX711_Calibration sketch
LoadCellFour.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
LoadCellFive.set_scale(calibration_factor5); //This value is obtained by using the SparkFun_HX711_Calibration sketch
LoadCellFive.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0
delay(500);
}
void loop() {
//Clears OLED display
display.clear();
//Make a string for assembling the data to log to SD:
String dataString = "";
//-------------------------------Wifi Status------------------------------------------
//String displaying wifi status
String wificonnected = "";
if(Serial1)
{
String wificonnected = "Wifi Connected.";
}
else
{
String wificonnected = "Wifi Disconnected.";
}
//OLED Display Wifi Status
display.setCursor(0,0);
display.println(wificonnected);
display.update();
//----------------------------------Date & Time----------------------------------------
//Sets position on LCD and prints date and time
lcd.setCursor(9,4);
lcd.print(rtc.getDateStr());
lcd.setCursor(0,4);
lcd.print(rtc.getTimeStr());
//Adds date and time to datafile string for SD Card
dataString += String(rtc.getDateStr());
dataString += " -- ";
dataString += String(rtc.getTimeStr());
dataString += ",";
//-------------------------------------Load Cell 1--------------------------------------
//Sets position and prints load cell 1 value to LCD
lcd.setCursor(0,1);
lcd.print("1: ");
lcd.print(LoadCellOne.get_units(), 1);
//Adds load cell value to datafile string for SD Card
float LoadCellOneReading = LoadCellOne.get_units();
dataString += String(LoadCellOneReading);
dataString += ",";
//Adds load cell 1 value to thingspeak field 1
String getDataLoad1 = "GET /update?api_key="+ API +"&"+ field1 +"="+LoadCellOneReading;
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getDataLoad1.length()+4),4,">");
Serial1.println(getDataLoad1);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
//-------------------------------------Load Cell 2--------------------------------------
//Sets position and prints load cell 2 value
lcd.setCursor(9,1);
lcd.print("2: ");
lcd.print(LoadCellTwo.get_units(), 1);
//Adds load cell value to datafile string
float LoadCellTwoReading = LoadCellTwo.get_units();
dataString += String(LoadCellTwoReading);
dataString += ",";
//Adds Load cell 2 value to thingspeak field 2
String getDataLoad2 = "GET /update?api_key="+ API +"&"+ field2 +"="+LoadCellTwoReading;
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getDataLoad2.length()+4),4,">");
Serial1.println(getDataLoad2);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
// NEXT PART OF CODE ATTACHED IN NEXT POST