Project

General

Profile

code arduino pour l'afficheur » tec_oled.ino

Frédéric Blanc, 2020-02-13 15:04

 
/**
* @brief Affichage consigne et temperature photodiode regulateur TC8
* @date 13/02/2020
* @author F.BLANC LAAS-CNRS
* http://homepages.laas.fr/fblanc/
*/
#define VERSION "TEC20200213 F.Blanc"
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h>
#include <math.h>

U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE); // All Boards without Reset of the Display
int adcViPIN = A0; //tension consigne
int adcVtPIN = A1; //tension thermistor P/N 3000341
#define RSI 1472.0 //resistance de refence pour le calcul du courant
#define GAIN 5.62 //gain pour la consigne
#define VREF1 1.031 // tension de reference du thermistor
#define AREF 4.096 // reference de tension du regulateur TC8

void setup(void)
{
analogReference(EXTERNAL); //reference de tension externe
u8g2.begin();
u8g2.enableUTF8Print(); // enable UTF8 support for the Arduino print() function
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_logisoso20_tr);
u8g2.setCursor(5, 37);
u8g2.print("LAAS");
u8g2.setCursor(30, 62);
u8g2.print("CNRS");
u8g2.setFont(u8g2_font_6x12_tf);
u8g2.setCursor(5, 8);
u8g2.print(VERSION);
u8g2.sendBuffer();
delay(5000);
}

void loop(void)
{

float vi = analogRead(adcViPIN) * AREF / 1024 / GAIN;
delay(100);
float vt = analogRead(adcVtPIN) * AREF / 1024;

float curr = vi / RSI;

float rs = VREF1 / curr;
float lrs = (float)log10(rs);
float consigne = 6.9338 * lrs * lrs - 109.1 * lrs + 300.07; // thermistor P/N 3000341
float rt = (vt - VREF1) / curr;
float lrt = (float)log10(rt);
float temp = 6.9338 * lrt * lrt - 109.1 * lrt + 300.07; // thermistor P/N 3000341

char text[8];
//u8g2.clear();
u8g2.clearBuffer();
//affichage consigne
dtostrf(consigne, 4, 0, text );
u8g2.setFont(u8g2_font_logisoso16_tf);
u8g2.setCursor(5, 16);
u8g2.print("cons");
u8g2.setCursor(45, 16);
u8g2.print(text);
u8g2.print("°C");

//affichage temp
dtostrf(temp, 4, 0, text);
u8g2.setFont(u8g2_font_logisoso32_tf);
u8g2.setCursor(5, 60);
u8g2.print(text);
u8g2.print("°C");

u8g2.sendBuffer();
delay(500);
}
    (1-1/1)