Hallo,
mein Code unten macht sowas:
Link zur Grafik: http://www.bilderload.com/bild/392339/img01351Y0S7.jpg
Du findest aber ähnliches überall ins Netz.
Viele Grüße,
Julien
// Arduino: Nano V3.0 ATmega328P Board, Arduino kompatibel, USB CH340G
// OLED Display: I2C/IIC/TWI 128x64 SSD1306
// ref u8glib: https://github.com/olikraus/u8glib
// ref u8glib/wiki: https://github.com/olikraus/u8glib/wiki/userreference
#include <U8glib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Constructors
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Constants
const int STRING_HEIGHT = 12;
const int DISPLAY_WIDTH = 128;
const int DEGREE_RADIUS = 1;
const char CANON_650DAC[] = "Canon 650DA Cooled";
const float R1 = 21.75;
const float R2 = 8.17;
const float RFactor = (R1+R2)/R2;
// Variables
int x, y, width;
float temperature_sensor, temperature_ambient, temperature_delta, voltage, Vcc;
// Methodes
void draw(void) {
// set font
u8g.setFont(u8g_font_6x12); // u8g.setFont(u8g_font_unifont);
// Header
x = 0;
y = STRING_HEIGHT;
u8g.setPrintPos(x, y);
u8g.print(CANON_650DAC);
// Draw H Line
x = 0;
y++;
u8g.drawHLine(x, y + 1, DISPLAY_WIDTH);
// Ambient & Sensor Temperature
x = 0;
y += STRING_HEIGHT + 1;
u8g.setPrintPos(x, y);
u8g.print("Ta");
width = u8g.getStrWidth("Ta");
x += width + 3;
u8g.setPrintPos(x, y);
u8g.print(temperature_ambient);
width = u8g.getStrWidth("-88.88");
x += width + 1;
u8g.drawCircle(x, y - STRING_HEIGHT + 2*DEGREE_RADIUS + 1, DEGREE_RADIUS, U8G_DRAW_ALL);
x += 2*DEGREE_RADIUS + 1;
u8g.setPrintPos(x, y);
u8g.print("C");
width = u8g.getStrWidth("C");
// Draw V Line
x += width;
u8g.drawVLine(x + 3, y - STRING_HEIGHT, STRING_HEIGHT + 2);
// x += width;
u8g.setPrintPos(x, y);
u8g.print(" Ts");
width = u8g.getStrWidth(" Ts");
x += width + 3;
u8g.setPrintPos(x, y);
u8g.print(temperature_sensor);
width = u8g.getStrWidth("-88.88");
x += width + 1;
u8g.drawCircle(x, y - STRING_HEIGHT + 2*DEGREE_RADIUS + 1, DEGREE_RADIUS, U8G_DRAW_ALL);
x += 2*DEGREE_RADIUS + 1;
u8g.setPrintPos(x, y);
u8g.print("C");
// Draw H Line
x = 0;
y++;
u8g.drawHLine(x, y + 1, DISPLAY_WIDTH);
// Delta Temperature
x = 0;
y += STRING_HEIGHT + 1;
u8g.setPrintPos(x, y);
u8g.print("Delta ");
width = u8g.getStrWidth("Delta ");
x += width;
u8g.setPrintPos(x, y);
u8g.print(temperature_delta);
width = u8g.getStrWidth("-88.88");
x += width + 1;
u8g.drawCircle(x, y - STRING_HEIGHT + 2*DEGREE_RADIUS + 1, DEGREE_RADIUS, U8G_DRAW_ALL);
x += 2*DEGREE_RADIUS + 1;
u8g.setPrintPos(x, y);
u8g.print("C");
// Draw H Line
x = 0;
y++;
u8g.drawHLine(x, y + 1, DISPLAY_WIDTH);
// Voltage
x=0;
y += STRING_HEIGHT + 1;
u8g.setPrintPos(x, y);
u8g.print("Vin ");
width = u8g.getStrWidth("Vin ");
x += width;
u8g.setPrintPos(x, y);
u8g.print(voltage);
width = u8g.getStrWidth("88.88");
x = x + width;
u8g.setPrintPos(x, y);
u8g.print(" Volt");
// drawHLine;
}
void drawHLine(void) {
x = 0;
y++;
u8g.drawHLine(x, y + 1, DISPLAY_WIDTH);
}
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1125300L / result; // Back-calculate AVcc in mV
return result;
}
// Setup & Loop
void setup(void) {
// start serial port
Serial.begin(9600);
Serial.println(CANON_650DAC);
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
void loop(void) {
// Send the command to get the voltages
Vcc = readVcc()/1000.0;
unsigned int raw_bat = analogRead(A0);
voltage = (raw_bat * (Vcc / 1023) * RFactor);
// Send the command to get temperatures
sensors.requestTemperatures();
temperature_sensor = sensors.getTempCByIndex(0);
temperature_ambient = sensors.getTempCByIndex(1);
temperature_delta = temperature_sensor - temperature_ambient;
Serial.print("Vin: ");
Serial.print(voltage);
Serial.print(" Volt");
Serial.println("");
Serial.print("T: ");
Serial.print(temperature_sensor);
Serial.print(" *C");
Serial.println("");
Serial.print("T: ");
Serial.print(temperature_ambient);
Serial.print(" *C");
Serial.println("");
Serial.print("T: ");
Serial.print(temperature_delta);
Serial.print(" *C");
Serial.println("");
// picture loop
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
// rebuild the picture after some delay
delay(500);
}