system
October 4, 2013, 1:28pm
1
Hi and sorry but I just cant get my code to output anything to the display...
Can anyone help I think iam overlooking somthing....
// using a hall sensor as a tachometer with a LCD display using U8glib / 12864 graphic LCD ST7920
#include "U8glib.h"
#define PMS_PIN 3 // Pin for signal from hall sensor
#define LED_PIN 13 //Using Arduino's Internal LED as an hall sensor indicator for testing the signal.
boolean counted=false;
int t1=0,t2=0;
int hits=0;
int rps=0;
U8GLIB_ST7920_128X64_4X u8g(11, 10, 12); // this is the 12864 graphic LCD ST7920 using pin 11,10,12
//:::::::::::::::::::
void u8g_prepare(void) {
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
void setup(){
pinMode(PMS_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
//:::::::::::::::::::::::::::::::::
// flip screen, if required
//u8g.setRot180();
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
//u8g.setContrast(0x30);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
u8g_prepare();
}
void loop(){
t2 = millis();
if(t2 >= (t1 + 10)){
rps = hits;
hits = 0;
t1=t2;
uint8_t u8g_Begin(u8g_t *u8g);
u8g.print("RPM: ");
u8g.print(rps*60);
}
if(digitalRead(PMS_PIN) == HIGH){
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(PMS_PIN));
}
uint8_t u8g_Begin(u8g_t *u8g);
is probably useless and might lead to a syntax error.
Additionally, you need to enclose the print commands into the "picture loop":
Replace
u8g.print("RPM: ");
u8g.print(rps*60);
with
u8g.firstPage();
do {
u8g.print("RPM: ");
u8g.print(rps*60);
draw();
} while( u8g.nextPage() );
Oliver
system
October 4, 2013, 2:27pm
3
Hi thanks
I get a error with you code:
void loop(){
t2 = millis();
if(t2 >= (t1 + 10)){
rps = hits;
hits = 0;
t1=t2;
//uint8_t u8g_Begin(u8g_t *u8g);
u8g.firstPage();
do {
u8g.print("RPM: ");
u8g.print(rps*60);
draw();
} while( u8g.nextPage() );
}
if(digitalRead(PMS_PIN) == HIGH){
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(PMS_PIN));
}
I get a:
sketch_oct04a.ino: In function 'void loop()':
sketch_oct04a:59: error: 'draw' was not declared in this scope
Did I miss something?
system
October 4, 2013, 2:51pm
4
Hi again
I can get display to output the text ( RPM and speed) if i use "void draw(); but the text is all over the display its like sceensaver, how do i stop this. it looks like its moving with the update here:
void loop(){
t2 = millis();
if(t2 >= (t1 + 500)){
rps = hits;
hits = 0;
t1=t2;
u8g.firstPage();
do {
u8g.print("RPM: ");
u8g.print(rps*60);
void draw();
} while( u8g.nextPage() );
}
if(digitalRead(PMS_PIN) == HIGH){
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(PMS_PIN));
}
This is the updated code:
// using a hall sensor as a tachometer with a LCD display using U8glib / 12864 graphic LCD ST7920
#include "U8glib.h"
#define PMS_PIN 3 // Pin for signal from hall sensor
#define LED_PIN 13 //Using Arduino's Internal LED as an hall sensor indicator for testing the signal.
boolean counted=false;
int t1=0,t2=0;
int hits=0;
int rps=0;
U8GLIB_ST7920_128X64_4X u8g(11, 10, 12); // this is the 12864 graphic LCD ST7920 using pin 11,10,12
//:::::::::::::::::::
void u8g_prepare(void) {
u8g.setFont(u8g_font_6x10);
u8g.setFontRefHeightExtendedText();
u8g.setDefaultForegroundColor();
u8g.setFontPosTop();
}
void setup(){
pinMode(PMS_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
//:::::::::::::::::::::::::::::::::
// flip screen, if required
//u8g.setRot180();
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
//u8g.setContrast(0x30);
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
u8g_prepare();
}
void loop(){
t2 = millis();
if(t2 >= (t1 + 1000)){
rps = hits;
hits = 0;
t1=t2;
u8g.firstPage();
do {
u8g.print("RPM: ");
u8g.print(rps*60);
void draw();
} while( u8g.nextPage() );
}
if(digitalRead(PMS_PIN) == HIGH){
if(!counted){
counted = true;
hits++;
}
} else {
counted = false;
}
digitalWrite(LED_PIN, digitalRead(PMS_PIN));
}
Hi
You can remove the line with "draw()" completly. That was copy-paste error from my side.
Oliver