Primo proggetto

Ciao a tutti, sono nuovo del mondo della programmazione e sto cercando di imparare e correggere i miei errori :sweat_smile:.
seguendo un tutorial su youtube ho creata il mio manometro turbo e ora sono alle prese con il codice che anch'esso era presente ma in formato diverso da come serve al mio progetto, sicuramente voi saprete aiutarmi.
il codice è il seguente :

#include <GyverOLED.h>
GyverOLED<SSH1106_128x64> oled;

// This is the code required for the boot image. Use the GyverOLED BITmaper or ImageProcessor tool to create this code with your own image
const uint8_t mt_boost_128x64[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0x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x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7C, 0x7C, 0x7E, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x07, 0x01, 0x00, 0x3F, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7C, 0x7C, 0x7E, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x07, 0x01, 0x00, 0x0F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F, 0x7D, 0x7C, 0x7E, 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x0F, 0x01, 0x00, 0x00, 0x40, 0x78, 0x7E, 0x7F, 0x7F, 0x7F, 0x3F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

float boostOutput = 0.0;
float peakBoost   = 0.0;
float boostBarValue;
float peakBoostBar;
int   boostBar;

void setup() {
  oled.init();
  oled.clear();
  oled.drawBitmap(0, 0, mt_boost_128x64, 128, 64);
  oled.update();
  delay(1500);
}

void loop() {

  // Lettura sensore
  int sensorValue = analogRead(A0);

  // Conversione PSI
  if (sensorValue < 206) {
    boostOutput = 0.0;
  } else {
    boostOutput = (sensorValue - 205) / 13.5;
  }

  // Peak boost
  peakBoost = max(peakBoost, boostOutput);

  // Conversione in BAR
  boostBarValue = boostOutput * 0.0689476;
  peakBoostBar  = peakBoost  * 0.0689476;

  // Barra grafica
  boostBar = constrain(boostOutput * 4, 0, 78);

  // Display
  oled.clear();
  oled.setScale(4);
  oled.setCursor(5, 1);
  oled.print(boostBarValue, 2);
  oled.print(" BAR");

  oled.setScale(2);
  oled.setCursor(5, 5);
  oled.print("P:");
  oled.print(peakBoostBar, 2);

  // Barra boost (5 pixel di altezza)
  for (int i = 0; i < 5; i++) {
    oled.fastLineH(50 + i, 5, 5 + boostBar);
  }

  oled.update();
  delay(100);
}

// Function for drawing lines. Pulled from GyverOLED library
void  fastLineH ( int y, int x0, int x1, byte fill);

Ho provato a convertire i PSI in Bar e inserire i decimali

Buonasera e benvenuto nella sezione Italiana del forum,

cortesemente, come prima cosa, leggi attentamente il REGOLAMENTO di detta sezione, (... e, per evitare future possibili discussioni/incomprensioni, prestando molta attenzione al punto 15), dopo di che, come da suddetto regolamento (punto 16.7), fai la tua presentazione NELL'APPOSITA DISCUSSIONE (... quello che vedi in blu è un link, fai click su di esso per raggiungere la discussione) spiegando bene quali esperienze hai in elettronica e programmazione, affinché noi possiamo conoscere la tua esperienza ed esprimerci con termini adeguati.

Grazie,

Guglielmo

P.S.: Ti ricordo che, purtroppo, fino a quando non sarà fatta la presentazione nell’apposita discussione, nel rispetto del succitato regolamento nessuno ti risponderà (eventuali risposte o tuoi ulteriori post, verrebbero temporaneamente nascosti), quindi ti consiglio di farla al più presto. ;)

... quindi, la domanda quale ? Che aiuto ti serve ?

Guglielmo

Il mio problema è che il tutorial e quindi anche il codice utilizza una scala di lettura i psi e ho provveduto a fare la conversione in bar il problema in se per se è che avrei bisogno di inserire i decimali poichè il manometro attualmente mi darebbe solo degli interi, invece io io vorrei che restituisse anche valori tipo 0.1-0.2 ecc
eovviamente anche valori negativi -0.1 -0.2 ecc
grazie

Fai una lettura analogica ... ma di COSA? Che sensore leggi? Hai un datasheet?

Guglielmo

[quote="river799, post:1, topic:1419988"]

float boostOutput = 0.0;
float peakBoost   = 0.0;
float boostBarValue;
float peakBoostBar;
int   boostBar;

void setup() {
  oled.init();
  oled.clear();
  oled.drawBitmap(0, 0, mt_boost_128x64, 128, 64);
  oled.update();
  delay(1500);
}

void loop() {

  // Lettura sensore
  int sensorValue = analogRead(A0);

  // Conversione PSI
  if (sensorValue < 206) {
    boostOutput = 0.0;
  } else {
    boostOutput = (sensorValue - 205) / 13.5;
  }

  // Peak boost
  peakBoost = max(peakBoost, boostOutput);

  // Conversione in BAR
  boostBarValue = boostOutput * 0.0689476;
  peakBoostBar  = peakBoost  * 0.0689476;

  // Barra grafica
  boostBar = constrain(boostOutput * 4, 0, 78);

  // Display
  oled.clear();
  oled.setScale(4);
  oled.setCursor(5, 1);
  oled.print(boostBarValue, 2);
  oled.print(" BAR");

  oled.setScale(2);
  oled.setCursor(5, 5);
  oled.print("P:");
  oled.print(peakBoostBar, 2);

  // Barra boost (5 pixel di altezza)
  for (int i = 0; i < 5; i++) {
    oled.fastLineH(50 + i, 5, 5 + boostBar);
  }

  oled.update();
  delay(100);
}

int sensorValue = analogRead(A0);
all'ingresso A0 ho collegato un sensore di pressione a 12volt la scala di riferiemnto va da -1 bar a +3 bar

secondo me il problema potrebbe essere che la libreria utilizzata non supporta il parametro ler stampare i decimali in oled.print
prova a metterli in stringa e stamparli cosi

char boostStr[10];
char peakStr[10];

dtostrf(boostBarValue, 4, 2, boostStr);   // valore, larghezza, decimali, array
dtostrf(peakBoostBar, 4, 2, peakStr);

oled.print(boostStr);
oled.print(" BAR");

oled.print("P:");
oled.print(peakStr);

ciao dopo un po di prove sono riuscito nel mio intento il manometro legge sia in pressione che in depressione vi giro il codice e vi ringrazio ora sono in attesa di stampare le cover in 3d

#include <GyverOLED.h>

GyverOLED<SSH1106_128x64> oled;

// This is the code required for the boot image. Use the GyverOLED BITmaper or ImageProcessor tool to create this code with your own image
const uint8_t mt_boost_128x64[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
};

float boostOutput = 0.0;
float peakBoost = 0.0;
float boostBarValue;
float peakBoostBar;
int boostBar;

void setup() {
  oled.init();
  oled.clear();
  oled.setScale(1);
  oled.setCursor(0, 0);
  oled.print("Scala 1");


  oled.init();
  oled.clear();
  oled.drawBitmap(0, 0, mt_boost_128x64, 128, 64);
  oled.update();
  delay(5500);
}


void loop() {
  int sensorValue = analogRead(A0);
  float voltage = sensorValue * (12.7 / 1023.0);

  boostBarValue = (voltage - 2.5) / 2.0;
  boostBarValue = constrain(boostBarValue, -1.0, 3.1);

  if (boostBarValue > peakBoostBar) peakBoostBar = boostBarValue;

  oled.clear();

  oled.setScale(2);
  oled.setCursor(2, 1);
  oled.print(boostBarValue, 2);
  oled.print(" BAR");

  int centerX = 64;
  int barLen = constrain(abs(boostBarValue) * 30, 0, 30);

  if (boostBarValue < 0) {
    for (int i = 0; i < 5; i++)
      oled.fastLineH(40 + i, centerX - barLen, centerX);
  } else {
    for (int i = 0; i < 5; i++)
      oled.fastLineH(40 + i, centerX, centerX + barLen);
  }

  //oled.fastLineV(35, centerX, 50);

  oled.update();
  delay(99);
}