Nu har jag kommit en bit till,
Har fått hem 7 av 9 temperaturgivare och koden verkar funka.
Nu saknas 1-wire enheter som kan ta typ K givare till rökgas och förbränning.
Dessa är inte lätta att hitta till en rimmlig peng när temperaturen stiger över 1000 grader.
Varvräkningen på skruven har jag inte fått till än, får nog skriva om den biten kod tips och ideer mottages tacksamt.
Avståndsmätningen i silon verkar stabil även om toleransen är lite stor,
men där ändras inget snabbt och det ska mest användas som indikator för påfyllning.
Får nog bli att byta LCD på sikt, svårt att få informationen lätt läst på 2 rader med 16 tecken.
- Kod: Markera allt
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <SD.h>
#include <EthernetServer.h>
#include <util.h>
#include <Ethernet.h>
#include <Dns.h>
#include <EthernetUdp.h>
#include <Dhcp.h>
#include <EthernetClient.h>
#include <LiquidCrystal.h>
/*
The circuit:
* LCD RS pin to digital pin 27*2*
* LCD Enable pin to digital pin 28*3*
* LCD D4 pin to digital pin 32*4*
* LCD D5 pin to digital pin 31*5*
* LCD D6 pin to digital pin 30*6*
* LCD D7 pin to digital pin 29*7*
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
*/
//LCD
LiquidCrystal lcd(27, 28, 32, 31, 30, 29); // Testing might be switched for serial.
// Start Number Storage
byte TempBoiler = 0; //DS18B20
byte TempTopTank = 0; //DS18B20
byte TempBottomTank = 0; //DS18B20
byte TempSupplyLine = 0; //DS18B20
byte TempReturnLine = 0; //DS18B20
int TempOutSide = 0; //DS18B20 needs to handle -value
byte TempInSide = 0; //DS18B20
int TempFire = 0; //MAX31850+K thermocouple
int TempSmoke = 0; //MAX31850+K thermocouple
int AugerTurnCount = 0; // Feedauger turns
int FuelLevel = 0; // Level in fuel silo
float test = 0;
// End Number Storage
//FuelLevel
const int trigger = 22;
const int echo = 23;
float distance;
//FuelLevel End
// AugerTurnCount Start
const int TurnSwitch = 53; // the pin that the switch is attached to
// Variables will change:
int TurnSwitchCounter = 0; // counter for the number of switch presses
int TurnSwitchState = 0; // current state of the switch
int TurnSwitchLastState = 0; // previous state of the switch
//AugerTurnCount End
//Temperature gathering
#define ONE_WIRE_BUS 10 // Data wire is plugged into pin ? on the Arduino
OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature.
// Assign the addresses of your 1-Wire temp sensors. Inspration from http://www.hacktronics.com/
DeviceAddress insideTemp = { 0x28, 0xFF, 0xA0, 0x36, 0x66, 0x14, 0x03, 0x7B };
DeviceAddress outsideTemp = { 0x28, 0xFF, 0x41, 0xB6, 0x66, 0x14, 0x02, 0xEB };
DeviceAddress supplyTemp = { 0x28, 0xFF, 0x51, 0x3E, 0x66, 0x14, 0x03, 0x0C };
DeviceAddress returnTemp = { 0x28, 0xFF, 0xA9, 0x37, 0x66, 0x14, 0x03, 0x07 };
DeviceAddress boilerTemp = { 0x28, 0xFF, 0xF3, 0xA7, 0x66, 0x14, 0x02, 0x90 };
DeviceAddress topTemp = { 0x28, 0xFF, 0x4C, 0x36, 0x66, 0x14, 0x03, 0x80 };
DeviceAddress bottomTemp = { 0x28, 0xFF, 0xFE, 0x38, 0x66, 0x14, 0x03, 0x59 };
//DeviceAddress fireTemp = { 0x28, 0xFF, 0x51, 0x3E, 0x66, 0x14, 0x03, 0x0C }; NEED UPDATE
//DeviceAddress smokeTemp = { 0x28, 0xFF, 0x51, 0x3E, 0x66, 0x14, 0x03, 0x0C }; NEED UPDATE
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
//FuelLevel Start
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
//FuelLevel End
//Auger turn start
pinMode(TurnSwitch, INPUT); // initialize the switch pin as a input:
//Auger turn end
// Tempsensors
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideTemp, 9);
sensors.setResolution(outsideTemp, 9);
sensors.setResolution(supplyTemp, 9);
sensors.setResolution(returnTemp, 9);
sensors.setResolution(boilerTemp, 9);
sensors.setResolution(topTemp, 9);
sensors.setResolution(bottomTemp, 9);
//sensors.setResolution(fireTemp, 9);
//sensors.setResolution(smokeTemp, 9);
// put your setup code here, to run once:
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
//Serial.print("C: ");
//Serial.print(tempC);
test = tempC;
//Serial.print(" F: ");
//Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop() {
// Debugg start
Serial.print("number of button pushes: ");
Serial.println(TurnSwitchCounter);
Serial.print("meters: ");
Serial.println(distance);
Serial.print("centimeters: ");
Serial.println(FuelLevel);
Serial.print("1 Inside ");
Serial.println(TempInSide);
Serial.print("2 Outside ");
Serial.println(TempOutSide);
Serial.print("3 Supplyline ");
Serial.println(TempSupplyLine);
Serial.print("4 Returnline ");
Serial.println(TempReturnLine);
Serial.print("5 Boiler ");
Serial.println(TempBoiler);
Serial.print("6 Top Tank ");
Serial.println(TempTopTank);
Serial.print("7 Bottom Tank ");
Serial.println(TempBottomTank);
//more will come when it arrives.
//Debugg end
Convert_All ();
AugerTurn_Count ();
Temp_In_Out ();
Temp_Sup_Ret ();
Temp_Tank ();
Temp_Boilier ();
Summary ();
Write_SD ();
Update_Web();
Twitter();
Fuel_Level();
LCD_Print();
}
void LCD_Print (){ // Update LCD.
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(1,0);
lcd.print("PL");
lcd.print(FuelLevel);
lcd.setCursor(6,0);
lcd.print("TT");
lcd.print(TempTopTank);
lcd.setCursor(10,0);
lcd.print(TempBottomTank);
lcd.setCursor(14,0);
lcd.print("S");
lcd.print(TempSupplyLine);
lcd.setCursor(0,1);
lcd.print("R");
lcd.print(TempReturnLine);
lcd.setCursor(4,1);
lcd.print("OS");
lcd.print(TempOutSide);
lcd.setCursor(9,1);
lcd.print("IS");
lcd.print(TempInSide);
}
void Convert_All (){
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
delay(5000); //OneWire messuare, convert, get ready to deliver. Will be 3 wire setup(VCC,DATA,GND).
}
void Fuel_Level () { //Get distance in silo
// Set the trigger
digitalWrite(trigger, LOW);
delayMicroseconds(10);
// Start measurement
digitalWrite(trigger, HIGH);
delayMicroseconds(50);
digitalWrite(trigger, LOW);
// Acquire data and convert it to meters.
distance = pulseIn(echo,HIGH); // data acquisition.
distance = distance * 26 / 100 / 2 / 1000; // data converstion.
FuelLevel = distance * 100; // convert to centimeters and avoid more float.
}
void Twitter () { // Send status and alarms on interval and direct.
}
void Update_Web () { //Send to/Update webserver internal/external?
}
void Write_SD () { //Write to SD card, use Summary.
}
void Summary () { //Put it together for statistics.
}
void Temp_Boilier () { //All in boilier water,fire,smoke.
printTemperature(boilerTemp);
TempBoiler = test;
}
void Temp_Tank () { //All in tank top,bottom.
printTemperature(topTemp);
TempTopTank = test;
printTemperature(bottomTemp);
TempBottomTank = test;
}
void Temp_Sup_Ret () { //All lines supply,return. Maybe put this in Temp_Tank
printTemperature(supplyTemp);
TempSupplyLine = test;
printTemperature(returnTemp);
TempReturnLine = test;
}
void Temp_In_Out () { //All outside,inside
printTemperature(insideTemp);
TempInSide = test;
printTemperature(outsideTemp);
TempOutSide = test;
}
void AugerTurn_Count () { //Turn counter auger
TurnSwitchState = digitalRead(TurnSwitch); // read the switch input pin:
if (TurnSwitch != TurnSwitchLastState) { // compare the switchState to its previous state
if (TurnSwitch == HIGH) { // if the state has changed, increment the counter
TurnSwitchCounter++;// if the current state is HIGH then the switch wend from off to on:
// Serial.println("on");
//Serial.print("number of button pushes: ");
//Serial.println(TurnSwitchCounter);
}
else {
// if the current state is LOW then switch
// wend from on to off:
//Serial.println("off");
}
}
TurnSwitchLastState = TurnSwitchState; // save the current state as the last state,for next time through the loop
AugerTurnCount = TurnSwitchCounter; // Update for statistics
}
Måste klura ut något filter för loggningen,
vet inte riktigt hur än men tankarna går mot dubbla numeriska register för att jämföra med och sållningen sker med +/- toleranser ?
Det ligger en del pauser (delay) inlagt för att inte överbelasta LCD och seriella monitorn när det testkörs,
dom ska bort sen när sållningen funkar.
Om Jesus Kristus skulle återuppstå och se allt som görs i hans namn, så skulle han aldrig sluta spy.
- Woody Allen