Jauge Fuel qantity RJ85

Avro

PILOTE DE LIGNE
Messages
1 860
Réactions
259
Points
300
Bonjour à tous,
mdfuel.png


@HB-EBC a créé un compas magnétique en utilisant une carte Arduino et un écran OLED ; j'ai aimé son approche et j'ai eu envie de réaliser une jauge utile pour mon projet RJ85/MD88.

Je vais réaliser l'ensemble des afficheurs numériques plus complexes que les classiques montages 7 digits en utilisant cette technique. J'ai donc commencé par une jauge fuel. Pour mon premier essai, j'avais réalisé le compas magnétique sur un écran OLED de 128x64 pixels. J'ai commandé un écran OLED 1.5 pouces de 128x128 pixels pour m'approcher un peu plus de l'original.

Le montage est le même que sur le post de HB-EBC, je vous renvoie donc à son excellent article pour le début de cette réalisation : Compas magnétique
RJ85fuel.png


Voici le code de l'Arduino adapté du compas :

C:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

// -------------------- VERSION 1.0.0 --------------------------------------------/

//Wifi  **************************************************************************/
const char* host = "esp8266fuel";
const char* ssid = "Votre_SSID";
const char* password = "Le_Mot_De_Passe_De_Votre_SSID";


// config static IP
IPAddress ip(192, 168, XXX, XXX); // Remplacer les XXX pour faire correspondre à l'adresse IP que vous voulez donner au compas
IPAddress gateway(192, 168, XXX, XXX); // Remplacer les XXX pour faire correspondre à l'adresse IP de la passerelle de votre reseau (generalement l'adresse IP de votre Box internet).
IPAddress subnet(255, 255, 255, 0); // le sous reseau (generalement pas besoin d'y toucher
IPAddress serveriocp(192, 168, XXX, XXX); // Remplacer les XXX pour faire correspondre à l'adresse IP du PC sur lequel est exécuté SIOC
IPAddress myDns1(1, 1, 1, 1);
IPAddress myDns2(8, 8, 8, 8);


//WebServer server(80);
WiFiClient client;

//Ecran  *************************************************************************/
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int addInt(int a, int b, int c) {
    return a+b+c;
}

//IOCP  **************************************************************************/
char line[64];

String stringVariable;
String stringNumVariable;
bool debug = false;

int count = 0;
float Variable[1500];
//float OldVariable[1500];
bool ConnectionIOCP = false;
int VariablesIn[] = {201,202,203};
const int NbVariablesIn = (sizeof(VariablesIn) / sizeof(VariablesIn[0]));
//int OldVariablesIn[NbVariablesIn];

// variables
long lmain = 0;
long rmain = 0;
long ctr = 0;

void setup() {
  Serial.begin(115200);

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }


  Serial.println();
  Serial.print("ESP board MAC Address:  ");
  Serial.println(WiFi.macAddress());

  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0, 0);            // Start at top-left corner
  display.println(F("ESP MAC Address: "));
  display.println(WiFi.macAddress());
  display.display();

  WiFi.mode(WIFI_STA);
  Serial.println("Booting");
  // Configures static IP address
  if (!WiFi.config(ip, gateway, subnet, myDns1, myDns2)) {
    Serial.println("STA Failed to configure");
  }

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(0, 0);            // Start at top-left corner
  display.println(F("Connected to: "));
  display.println(ssid);
  display.println(F(" "));
  display.println(F("IP address: "));
  display.println(WiFi.localIP());
  display.display();
  delay(5000);

  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_SPIFFS
      type = "filesystem";
    }

    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) {
      Serial.println("Auth Failed");
    } else if (error == OTA_BEGIN_ERROR) {
      Serial.println("Begin Failed");
    } else if (error == OTA_CONNECT_ERROR) {
      Serial.println("Connect Failed");
    } else if (error == OTA_RECEIVE_ERROR) {
      Serial.println("Receive Failed");
    } else if (error == OTA_END_ERROR) {
      Serial.println("End Failed");
    }
  });
  ArduinoOTA.begin();

  display.clearDisplay();

  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_BLACK, SSD1306_WHITE); // Draw 'inverse' text
  // display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(30, 20);            // Start at top-left corner
  display.println(F("Waiting IOCP"));
  display.setCursor(15, 28);            // Start at top-left corner
  display.println(F("server connection"));
  display.display();
  display.setTextColor(SSD1306_WHITE);        // Draw white text

  ArduinoOTA.handle();
  while (!ConnectionIOCP) {

    ArduinoOTA.handle();
    // if you get a connection, report back via serial:
    if (client.connect(serveriocp, 8092)) {
      ConnectionIOCP = true;
      Serial.print("connected to ");
      Serial.println(client.remoteIP());
      display.println(F("connected to "));
      display.println(client.remoteIP());
      display.display();
      client.print("Arn.Inicio:");
      for (int i = 0; i < NbVariablesIn; i++) {
        sprintf(line, "%d:", VariablesIn[i]);
        client.print(line);
        Serial.print(line);
      }

      client.println("");
      if (debug == true) Serial.println("");

    } else {
      ConnectionIOCP = false;
      // if you didn't get a connection to the server:
      Serial.println("connection to IOCP server failed");
    }
  }

}

//LOOP  **************************************************************************/
void loop() {
  ArduinoOTA.handle();
  TaskRead();
  // lecture des variables
  lmain = Variable[VariablesIn[0]]*4170; // 4170 nombre de kg de kero
  rmain = Variable[VariablesIn[1]]*4170;
  ctr   = Variable[VariablesIn[2]]*1997;

  int (*functionPtr)(int,int,int);
  functionPtr = &addInt;
  int totalfuel = (*functionPtr)(lmain,rmain,ctr);

  display.clearDisplay();
  display.setTextSize(1);             // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
  display.setCursor(30, 0);            // Start at top-left corner
  display.println(F(" FUEL QTY "));
  display.setTextColor(SSD1306_WHITE);        // Draw white text
  display.setCursor(8,3);              // Set cursor position, start of line 1
  display.println(F("LFT"));
  display.setCursor(96,3);              // Set cursor position, start of line 1
  display.println(F("RGT"));
  display.setCursor(4,14);              // Set cursor position, start of line 2
  display.setTextSize(2);
  display.println(lmain);
  display.setCursor(77,14);              // Set cursor position, start of line 2
  display.println(rmain);
  display.setCursor(0,40);             // Set cursor position, line 2 10th character
  display.setTextSize(1);
  display.println(F("CTR"));
  display.setCursor(46,32);             // Set cursor position, line 2 10th character
  display.setTextSize(2);
  display.println(ctr);
  display.setCursor(0,57);             // Set cursor position, line 2 10th character
  display.setTextSize(1);
  display.println(F("Tot. fuel"));
  display.setCursor(64,50);             // Set cursor position, line 2 10th character
  display.setTextSize(2);
  display.println(totalfuel);
  display.display();


}


//Fonctions  *********************************************************************/
void TaskRead()  // This is a task.
{
  int NumVariable;
  double VarTemp;
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client)
  {

    if (debug == true) Serial.println("New Client.");
    String header = "";
    //String currentLine = "";
    while (client.connected())
    {
      ArduinoOTA.handle();
    
      if (debug == true) Serial.println("Client Conneted.");
      if (client.available())
      {
        if (debug == true) Serial.println("Client Available.");
        char c = client.read();
        if (debug == true) Serial.write(c);
        header += c;
        //currentLine  += c;
        if (c == '\n')
        {
          if (debug == true) Serial.println("Fin ligne");

          if (header.indexOf("Resp:") >= 0)
          {
            int NextEgalPos = 0;
            int Next2PointPos = 0;
            NextEgalPos = header.indexOf("=", NextEgalPos);
            Next2PointPos = header.indexOf(":", Next2PointPos);
            while ((Next2PointPos > 0) and (NextEgalPos > 0 ))
            {
              stringNumVariable = header.substring(Next2PointPos + 1, NextEgalPos);
              NumVariable = stringNumVariable.toInt();
              Next2PointPos = header.indexOf(":", Next2PointPos + 1);
              if (Next2PointPos <= 0) stringVariable = header.substring(NextEgalPos + 1, header.length());
              else stringVariable = header.substring(NextEgalPos + 1, Next2PointPos);
              VarTemp = stringVariable.toInt();
              Variable[NumVariable] = VarTemp/128/65536;
              NextEgalPos = header.indexOf("=", NextEgalPos + 1);
              if (debug == true)
              {
                Serial.print(" Result : ");
                sprintf(line, "%d = %d", NumVariable, Variable[NumVariable]);
                Serial.println(line);
              }

            }
            break;
          }
          else if (header.indexOf("Vivo:") >= 0)
          {
            client.println("Arn.Vivo:");
            if (debug == true) Serial.println("Dans Vivo !");
            break;
          }
        }
      }
    }
    header = "";
  }
  else
  {
    ConnectionIOCP = false;
    while (!ConnectionIOCP) {

        ArduinoOTA.handle();
        // if you get a connection, report back via serial:
        if (client.connect(serveriocp, 8092)) {
          ConnectionIOCP = true;
          Serial.print("connected to ");
          Serial.println(client.remoteIP());
          display.println(F("connected to "));
          display.println(client.remoteIP());
          display.display();
          client.print("Arn.Inicio:");
          for (int i = 0; i < NbVariablesIn; i++) {
            sprintf(line, "%d:", VariablesIn[i]);
            client.print(line);
            Serial.print(line);
          }

          client.println("");
          if (debug == true) Serial.println("");

        } else {
          ConnectionIOCP = false;
          // if you didn't get a connection to the server:
          Serial.println("connection to IOCP server failed");
        }
      }

  }
}

Dans SIOC, j'ai ajouté 3 variables :

Code:
Var 0201, name LMAIN, Link FSUIPC_IN, Offset $0B7C, Length 4

Var 0202, name RMAIN, Link FSUIPC_IN, Offset $0B94, Length 4

Var 0203, name CTR, Link FSUIPC_IN, Offset $0B74, Length 4

Testé avec P3D pour le RJ85 et pour le MD88 Rotate sous X-Plane 11 avec XPUIPC. une différence de 2kg, rien de dramatique.

Le code est modifié ainsi :
C:
  lmain = Variable[VariablesIn[0]]*4255; // 4255 nombre de kg de kero
  rmain = Variable[VariablesIn[1]]*4255;
  ctr   = Variable[VariablesIn[2]]*9238;

mdfuelv.png
 
Dernière édition:
Super !
Ravi que mon code te serve.
Je vais regarder pour te faire le code de cet instrument avec un écran couleur.
Le problème de rafraîchissement de devrait pas se produire ici car une infime partie seulement de l'écran est a régénérer
 
Pas besoin pour cette jauge de la passer en couleur. Éventuellement, j'ajouterai un Bezel imprimé en 3 D par au-dessus.

L'écran 1.5 pouces, c'est surtout pour avoir une taille plus proche du réel. Pour la couleur, j'aimerais utiliser mon écran "2.2 Inch Round Circle Circular128X128 TFT LCD Display Module Screen Build-in ST7687S Parallel SPI for Arduino" pour la jauge APU.
 
Retour
Haut