Ciao a tutti, sto lavorando ad un nuovo, anzi sto aggiornando un mio vecchio circuito, è un contatorino geiger che usa arduino come contatore..
Ora, uso uno schermo nokia 5110 visto che ne avevo qualcuno in più e che mi piacciono particolarmente, solo che: Non posso usare la libreria di adafruit perchè a quanto pare mi va in conflitto con l'interrupt che uso per leggere gli impulsi,al che ho ripiegato su di un altra lib, non va pure questa, neho trovato un altra ancora che allegherò, ora, riesco a leggere correttamente gli impulsi infatti li stampo su seriale ed lcd senza problemi foto 1 ma la misura successiva uSv/h (che mi deve visualizzare un float) non lo fa. uSv/h non è, altro come potete vedere da codice che un calcolo che restituisce un float, questo float non riesco a visualizzarlo in nessuna maniera.. Che sia un problema di casting ? ho provato a moltiplicarlo per 100 e trasformarlo ad int e mi appare 0 sempre anche se su seriale arriva a 2000.
Non so dove sbattere la testa, come potete vedere dalla foto 2 i float li visualizza (è uno degli esempi della lib) e pure se dichiaro una variabile es float pi= 3.14 e la stampo la visualizza, ma con uSv non cè verso... potete aiutarmi a svelare l'arcano per cortesia ?
Ciaoo
ps il codice:
#include <LCD5110_Basic.h>
LCD5110 myGLCD(7,6,5,3,4);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
#define LED_PIN 13 // for debug only - flashes 5X at startup
#define TUBE_SEL 9 // jumper to select alt conversion to uSv
// HOW MANY CPM =1 uSV? Two commonly used sets of ratios for the SBM-20 & LND712 are defined:
// libelium now uses: 175.43 for SBM-20 and 100.00 for LND712
// www.utsunomia.com/y.utsunomia/Kansan.html use: 150.51 for SBM-20 and 123.14 for LND712
#define PRI_RATIO 175.43 // no TUBE_SEL jumper - SET FOR SBM-20
#define SEC_RATIO 100.00 // TUBE_SEL jumper to GND - SET FOR LND712
// mS between writes to serial - counts also accumulate seperately for this period
#define LOGGING_PEROID 60000 // best set for at least 1 min (60000 mS) unless testing
// mS between writes to display - counts/period are averaged to CPM < 60000 less accurate
// LOGGING_PERIOD shuld be a multiple of these periods
#define LONG_PERIOD 10000 // mS sample & display below 100 CPM
#define SHORT_PERIOD 5000 // mS sample & display above 100 CPM
#define FULL_SCALE 1000 // max CPM for 8 bars & overflow warning
#define LOW_VCC 4200 //mV // if Vcc < LOW_VCC give low voltage warning
volatile boolean newEvent = false; // true when new event was caught by ISR
boolean lowVcc = false; // true when Vcc < LOW_VCC
unsigned long dispPeriodStart, dispPeriod, dispCnt, dispCPM; // counters for the display period
unsigned long logPeriodStart, logCnt, logCPM; // counters for the logging period
unsigned long checkVccTime;
float uSv = 0.0; // display CPM converted to "unofficial" uSv
float uSvLogged = 0.0; // logging CPM converted to "unofficial" uSv
float uSvRate; // holds the rate selected by jumper
void setup(){
Serial.begin(9600); // comspec 96,N,8,1
attachInterrupt(0,GetEvent,FALLING); // Geiger event on pin 2 triggers interrupt
pinMode(LED_PIN,OUTPUT); // setup LED pin 13
pinMode(TUBE_SEL,INPUT); // setup tube select jumper pin
digitalWrite(TUBE_SEL, HIGH); // set 20K pullup on jumper pin(low active)
dispPeriod = LONG_PERIOD; // start with long display period
Blink(LED_PIN,5); // show it's alive
myGLCD.InitLCD();
myGLCD.setFont(SmallFont);
myGLCD.print("GEIGER COUNTER", CENTER, 16);
delay (2000); // leave the banner up 2 sec.
myGLCD.clrScr(); // clear the screen
myGLCD.print("CPM", LEFT,0); // display static "CPM"
myGLCD.print("uSv/hr ",LEFT,20); // display static "uSv/hr"
Serial.println("CPM \t uSv"); // print header for log
dispPeriodStart = millis(); // start timing display CPM
logPeriodStart = dispPeriodStart; // start logging timer
checkVccTime = dispPeriodStart; // start Vcc timer
}
void loop(){
if (millis() >= dispPeriodStart + dispPeriod) ProcCounts(); // period is over
if (newEvent){ // add to current count
dispCnt++;
logCnt++;
newEvent = false;
}
logCount(); // check if it's time to log & if so log
}
void ProcCounts(){ // aggregate totals and reset counters for each period
// These are calcs for display - less accurate
dispCPM = (dispCnt * 60) /(dispPeriod / 1000); // calc CPM for the period
uSv = dispCPM / uSvRate;
if (dispCPM > 99)dispPeriod = SHORT_PERIOD; // shorten sample period if CPM > 100
else dispPeriod = LONG_PERIOD;
displayCount();
dispCnt = 0; // reset display event counter
dispPeriodStart = millis(); // reset display time
}
void displayCount(){ //questa funzione visualizza quanto visibile in foto 1
myGLCD.setFont(MediumNumbers);
myGLCD.printNumI(dispCPM, RIGHT, 0);
myGLCD.printNumI(uSv, RIGHT, 32);
}
void logCount(){ // unlike logging sketch, just outputs to serial
if (millis() < logPeriodStart + LOGGING_PEROID) return; // period not over
logCPM = float(logCnt) / (float(LOGGING_PEROID) / 60000);
uSvLogged = logCPM / uSvRate; // make uSV conversion
// Print to serial in a format that might be used by Excel
Serial.print(" ");
Serial.print(logCPM,DEC);
Serial.print(",\t");
Serial.print(uSvLogged,4);
Serial.print(",\t"); // comma delimited
Blink(LED_PIN,2); // show it logged
logCnt = 0; // reset log event counter
logPeriodStart = millis(); // reset log time
dispCnt = 0; // reset display event counter
dispPeriodStart = millis(); // reset display time
}
void Blink(byte led, byte times){ // just to flash the LED
for (byte i=0; i< times; i++){
digitalWrite(led,HIGH);
delay (150);
digitalWrite(led,LOW);
delay (100);
}
}
void GetEvent(){ // ISR triggered for each new event (count)
newEvent = true;
}
LCD5110_Basic.rar (380 KB)

