Jump to content
ELFORUM - Forumul electronistilor

Ajutor cu un volt-termometru cu display OLED


fratello
 Share

Recommended Posts

Va salut !

Am facut un volt-termometru (cu intentia de a-l utiliza in masina) folosind :

-Arduino Nano

-display OLED de 1,3"

-senzor de temperatura DS18B20.

Atasez schema, foto cu montajul, codul sursa.

 

Intampin urmatoarea problema :

-dupa ce alimentez montajul (dintr-o sursa reglabila de tensiune, cu transformator, punte, condensator de filtraj ... deci nu sursa in comutatie) montajul functioneaza perfect : masoara corect tensiunea la intrare, in sens crescator/decrescator, masoara in acelasi timp si variatia temperaturii ;

-dupa un timp (neprecizat !) montajul nu mai reactioneaza : nu mai sesizeaza variatiile nici ale tensiunii, nici ale temperaturii !  Isi "revine" dupa reconectarea alimentarii.

 

Va rog sa va exprimati parerile vis-a-vis de acest comportament anormal. Nu imi dau seama daca este din cauza softului (dar cum de merge bine o vreme ...) sau din cauza hardware-ului.

Va multumesc anticipat pentru orice sugestie !

 

 

LE : Sursa inspiratiei pentru voltmetru : https://www.electronics-lab.com/project/arduino-voltmeter-using-sh1106-oled-display/

 

#include "U8glib.h"            // U8glib library for the OLED
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
           
#define ONE_WIRE_BUS 2 //Pin DS al senzorului DS18B20
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress;

U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NO_ACK); 


int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K)
float R2 =  10000.0; // resistance of R2 (10K) 
int value = 0;

double temp;



void setup()
{
  pinMode(analogInput, INPUT);
  sensors.begin();
  sensors.setResolution(tempDeviceAddress, 12);
}

void loop(){
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 5.0) / 1024.0; 
   vin = vout / (R2/(R1+R2)); 

if (vin<0.09) {
  vin=0.0;//statement to quash undesired reading !
  }
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);
  if (tempC != DEVICE_DISCONNECTED_C)
  {
    temp=tempC;
  }
  else
  {
    temp= 99.9;  //aici mesajul de eroare senzor !!!!
  }

  u8g.firstPage();  
  do 
    {
     draw();      
    }
  while( u8g.nextPage() );
delay(500);
}

void draw(void) 
{
    u8g.setFont(u8g_font_helvB24r);         // select font
//  u8g.setFont(u8g_font_profont29r);        
//  u8g.setFont(u8g_font_fub20r);
//  u8g.setFont(u8g_font_fur20r);
    u8g.drawRFrame(0, 30, 128, 32, 10);     // draws frame with rounded edges


if (vin>9.99) {
  u8g.setPrintPos(20,25);
 }
  else {
  u8g.setPrintPos(38,25); 
 } 


  u8g.println(vin,1);                        //Prints the voltage
  u8g.setPrintPos(84,25); 
  u8g.println(" V");


if ((temp<0)&& (abs(temp)<9.9)){
  u8g.setPrintPos(28,60);  
  u8g.println(temp,1);                       //Prints the temperature
  u8g.drawCircle(87,40,4);
  u8g.drawCircle(87,40,3);
  u8g.println(" C ");  
 }
  else if (temp<0) {
  u8g.setPrintPos(10,60);   
 }
 else if (temp>9.99){
 u8g.setPrintPos(20,60);
 }
 else{
 u8g.setPrintPos(38,60);  
 }
 u8g.println(temp,1);                        
 u8g.drawCircle(88,40,4);
 u8g.drawCircle(88,40,3);
 u8g.println(" C");
 }

 

1707588135817.jpg

1707586804408.jpg

1707586804423.jpg

Edited by fratello
Link to comment
Share on other sites

  • Replies 104
  • Created
  • Last Reply

Top Posters In This Topic

In soft nu prea vad probleme, poti incerca cu un alt nano daca ai, poate ai prins una cu probleme. Eu am patit cu ESP32 asa, merge cat merge si dupa pur si simplu se blocheaza, partea interesanta este ca a mers 3 luni fara probleme si numai dupa aia a inceput sa faca figuri din astea. 

Activeaza WDT-ul:

 

Pune in functia setup:

 wdt_disable();
 wdt_enable(WDT_PERIOD_2KCLK_gc); // set watchdog to 2 secs

 

Iar in functia loop undeva 
 

wdt_reset();

 

Daca functia de "reset" nu e apelata cel putin o data la 2s se va reseta automat uC-ul, chiar daca uC e blocat si nu reationeaza la nimic. WDT-ul este un hardware separat independent de partea de CPU care ruleaza softul.

Edited by Bandi Szasz
Link to comment
Share on other sites

Multumesc, voi incerca si cu WDT.

Intre timp am citit ca erau probleme cu libraria u8glib, exact in ceea ce priveste updatarea displayului , asa ca am trecut la U8g2lib. Monitorizez si revin.

// Librarie grafica U8G2LIB !!!

#include "U8g2lib.h"  
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
           
#define ONE_WIRE_BUS 2 //Pin DS al senzorului DS18B20
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress tempDeviceAddress;

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE); //sau cel de mai jos
//U8G2_SH1106_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);


int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // resistance of R1 (100K)
float R2 =  10000.0; // resistance of R2 (10K) 
int value = 0;

double temp;

float tempC = sensors.getTempCByIndex(0); // mutata din loop

void setup()
{
    u8g2.begin();
  pinMode(analogInput, INPUT);
  sensors.begin();
  sensors.setResolution(tempDeviceAddress, 12);
}

void loop(){
    u8g2.clearBuffer();          // clear the internal memory
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 5.0) / 1024.0; 
   vin = vout / (R2/(R1+R2)); 

if (vin<0.09) {
  vin=0.0;//statement to quash undesired reading !
  }
  sensors.requestTemperatures();

  if (tempC != DEVICE_DISCONNECTED_C)
  {
    temp=tempC;
  }
  else
  {
    temp= 99.9;  //aici mesajul de eroare senzor !!!!
  }

  u8g2.firstPage();  
  do 
    {
     draw();      
    }
  while( u8g2.nextPage() );
delay(500);
}

void draw(void) 
{
    
    u8g2.setFont(u8g2_font_helvB24_tf);       // select font   
    u8g2.drawRFrame(0, 30, 128, 32, 10);     // draws frame with rounded edges


if (vin>9.99) {
  u8g2.setCursor(20,25);
 }
  else {
  u8g2.setCursor(38,25); 
 } 


  u8g2.println(vin,1);                        //Prints the voltage
  u8g2.setCursor(84,25); 
  u8g2.println(" V");


if ((temp<0)&& (abs(temp)<9.9)){
  u8g2.setCursor(28,60);  
  u8g2.println(temp,1);                       //Prints the temperature
  u8g2.drawCircle(87,40,4);
  u8g2.drawCircle(87,40,3);
  u8g2.println(" C ");  
 }
  else if (temp<0) {
  u8g2.setCursor(10,60);   
 }
 else if (temp>9.99){
 u8g2.setCursor(20,60);
 }
 else{
 u8g2.setCursor(38,60);  
 }
 u8g2.println(temp,1);                        
 u8g2.drawCircle(88,40,4);
 u8g2.drawCircle(88,40,3);
 u8g2.println(" C");
 }

 

Link to comment
Share on other sites

Hm... se pare ca hw e o problema.

Nici dupa trecerea la u8g2 nu s-a rezolvat problema.

Asa ca am adaugat in setup :

wdt_disable();

wdt_enable(WDTO_2S); // set watchdog to 2 secs

si in loop :

wdt_reset();

 

Deocamdata vad ca nu s-a mai intepenit ....

Edited by fratello
Link to comment
Share on other sites

Nu, nu s-a rezolvat ... In momentul in care se blocheaza ledul L clipeste continuu iar Arduino nu se poate reseta din butonul de pe placa (https://jkdgreat.wordpress.com/2021/08/18/arduino-nano-not-responding-with-l-led-blinking-fast/).

Isi revine doar la realimentare.

Voi incerca (daca mai am ...) cu un alt Arduino :(

Edited by fratello
Link to comment
Share on other sites

Da ciudat, nu stiu exact cat ocupa U8glib, eu am folosit libraria de la Adafriut pt OLED, in orice caz mananca foarte mult RAM displayul ala minuscul si nu e exclus sa se blocheze din cauza RAM-ului, eu cum mi-am facut PCB de la 0 am folosit tinyAVR ( seria noua ) care are 1kb RAM in plus fata de nano.

Link to comment
Share on other sites

Update.

Am sters EEpromul. Am reprogramat Arduino. De 1 ora functioneaza OK, nu s-a mai blocat.

Pentru stergere am folosit acest cod :

/*
 * EEPROM Clear
 *
 * Sets all of the bytes of the EEPROM to 0.
 * Please see eeprom_iteration for a more in depth
 * look at how to traverse the EEPROM.
 *
 * This example code is in the public domain.
 */

#include <EEPROM.h>

void setup() {
  // initialize the LED pin as an output.
  pinMode(13, OUTPUT);

  for (int i = 0 ; i < EEPROM.length() ; i++) {
    EEPROM.write(i, 0);
  }

  // turn the LED on when we're done
  digitalWrite(13, HIGH);
}

void loop() {
  /** Empty loop. **/
}

 

 

 

Update : tocmai ce s-a blocat ! Din nou clipeste ledul L, Arduino nu poate fi resetat ....

Maine incerc cu alt Arduino.

 

Edited by fratello
Link to comment
Share on other sites

Am incercat sa rescrie bootloaderul la placa problematica. Am intampinat aceleasi problema ca userul Ionut2013 ; placa nu raspunde... Este probabil un fake si de aici erorile.

Va multumesc pentru suport. Dat fiind ca (cel putin) una din placile Arduino Nano functioneaza corect, o voi pastra in montaj pe aceasta.

err_boot.jpg

Edited by fratello
Link to comment
Share on other sites

"O alta placa Arduino inca functioneaza, de acum 9 ore."

Da, a functionat, dar fara DS18B20 si fara Vin, doar alimentata din portul USB al PC-ului.

Acum....UPDATE !!!

Si aceasta "noua" placa Arduino se blocheaza !!!

Am crezut ca este de la senzorul DS18B20 ; l-am deconectat, dar dupa un timp iar se blocheaza placa (cu aceeasi manifestare : led L clipeste rapid).

Am crezut ca este de la partea de voltmetru ; am deconectat intrarea A0, dar, la fel, dupa un timp se blocheaza.

Oare sa fie din faptul ca alimentez cu asa ceva montajul ???

 

 

Ceva noi sugestii ?? Multumesc.

 

Edited by fratello
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share




×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines