#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Fonts/FreeSans9pt7b.h>
#include <Q2HX711.h>
#include <Adafruit_SSD1306.h>
int setweightbuttonstate = 0;
const int setweightbuttonpin =6;
const byte hx711_data_pin = 4;
const byte hx711_clock_pin = 5;
Q2HX711 hx711(hx711_data_pin, hx711_clock_pin);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3c ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
int settemp= 0;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
unsigned long x = 0, y = 0;
unsigned long dataArray[10];
int j = 0;
// Temperature prob data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// arrays to hold device address
DeviceAddress insideThermometer;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
pinMode(4, INPUT); //data line //Yellow cable
pinMode(5, OUTPUT); //SCK line //Orange cable
pinMode(setweightbuttonpin, INPUT);
sensors.begin();
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
sensors.setResolution(insideThermometer, 9);
display.clearDisplay();
}
float tempC;
int tempC2;
void printTemperature(DeviceAddress deviceAddress) {
tempC = sensors.getTempC(deviceAddress);
if(tempC == DEVICE_DISCONNECTED_C)
{
//display.clearDisplay();
display.setCursor(00, 00);
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
//display.print("Error: Could not read temperature data");
display.display();
return;
}
}
int tare;
void loop(void) {
display.clearDisplay();
// put your main code here, to run repeatedly:
Serial.begin(9600);
//Serial.readBytes(tempC2);
//Serial.print(tempC2);
sensors.requestTemperatures();
printTemperature(insideThermometer);
display.setCursor(0, 0);
display.setTextSize(1);
setweightbuttonstate = digitalRead(setweightbuttonpin);
display.setTextColor(WHITE);
if(setweightbuttonstate == HIGH){
tare = hx711.read()/100;
}
display.print("Chamber: ");
display.print(tempC);
display.println("C");
display.print("Condenser: ");
display.println(tempC2);
display.println(tare);
display.display();
delay(60);
for (int j = 0; j < 10; j++)
{
digitalWrite(4, LOW);//SCK is made LL
while (digitalRead(5) != LOW) //wait until Data Line goes LOW
;
{
for (int i = 0; i < 24; i++) //read 24-bit data from HX711
{
clk(); //generate CLK pulse to get MSB-it at A1-pin
bitWrite(x, 0, digitalRead(5));
x = x << 1;
}
clk(); //25th pulse
Serial.println(x, HEX);
y = x;
x = 0;
delay(1000);
}
dataArray[j] = y;
}
Serial.println("===averaging process=========");
unsigned long count = 0;
for (j = 0; j < 10; j++)
{
count += dataArray[j];
}
Serial.print("Average Count = ");
count = count / 10;
Serial.println(count, HEX);
}
void clk()
{
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
}
Loading
ds18b20
ds18b20