Bin etwas am rumspielen mit zwei DS18B20 TempSensoren & OLED 128x64.
Ihr werdet es kaum glauben:
Mein Code funtioniert ! :o Nur ich weiß nicht warum...
Die beiden Sensoren so mit Widerstand angeschlossen. Jeweils die Datenleitung vom Sensor an Pin3 Arduino.
Ich bekomme beide Werte bestens angezeigt aber hääää:
Wie weiß der Arduino welcher Sensor 1 und 2 ist? :o
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 size display using I2C to communicate
3 pins are required to interface (2 I2C and one reset)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
// Data wire is plugged into pin 3 on the Trinket
#define ONE_WIRE_BUS 3
// 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);
int T1;
int T2;
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
void setup() {
Serial.begin(9600);
// Start up the sensor library
sensors.begin();
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3D); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay();
// draw a single pixel
display.drawPixel(10, 10, WHITE);
// Show the display buffer on the hardware.
// NOTE: You _must_ call display after making any drawing commands
// to make them visible on the display hardware!
display.display();
delay(2000);
display.clearDisplay();
T1=20;
T2=15;
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("Temperatur T1:");
display.print(T1);
display.write((char)247);
display.println("C");
display.setCursor(0,8);
display.print("Temperatur T2:");
display.print(T2);
display.write((char)247);
display.println("C");
display.drawCircle(50, 50, 10, WHITE);
display.drawTriangle(45,57,45,43,60,50, WHITE);
display.display();
delay(2000);
}
void loop() {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
display.clearDisplay();
display.setCursor(0,8);
display.print("Temperatur T1:");
display.print(sensors.getTempCByIndex(0));
display.write((char)247);
display.println("C");
display.setCursor(0,16);
display.print("Temperatur T2:");
display.print(sensors.getTempCByIndex(1));
display.write((char)247);
display.println("C");
display.display();
delay(1000);
}