print speed with ST7565


hi all, i'm building instrument panel car, working on tach , speedometer. i'm using teensy freqmeasure libraries read frequency car sensors. using u8glib , st7565 adafruit display.

in code, without picture loop present, serial monitor updates rapidly frequency measurement. when put picture loop code in, both serial monitor , lcd update frequency once per sec. don't know enough know how optimize situation. ideas? obvious mistakes i'm making or slow approaches?

thanks,

code: [select]

#include <freqmeasure2.h>
#include "u8glib.h"
#include <freqmeasure.h>

float frequency;
float frequency2;
double sum=0;
int count=0;
double sum2=0;
int count2=0;

float rpm;
float mph;

u8glib_lm6059 u8g(15, 16, 17, 18, 19); // spi com: sck = 13, mosi = 11, cs = 10, a0 = 9

void draw(void) {
    u8g.setfont(u8g_font_unifont);
    u8g.drawstr( 75, 60, "mph");
    u8g.drawstr( 90, 31, "rpm");
}
void setup(void) {

  serial.begin(57600);
  freqmeasure.begin();
  freqmeasure2.begin();

u8g.setcontrast(150);

}

void loop(void) {
    if (freqmeasure2.available()) {
    // average several reading together
    sum2 = sum2 + freqmeasure2.read();
    count2 = count2 + 1;
    if (count2 > 30) {
      frequency2 = freqmeasure2.counttofrequency(sum2 / count2);
      mph = frequency2*0.45; //(freq* 3600s/hr *mile/8000 clicks)
      serial.println(mph);
      sum2 = 0;
      count2 = 0;
    }
    }
  if (freqmeasure.available()) {
    // average several reading together
    sum = sum + freqmeasure.read();
    count = count + 1;
    if (count > 30) {
      frequency = freqmeasure.counttofrequency(sum / count);
      rpm = frequency/58; //(58 teeth per flywheel revolution)
      serial.println(rpm);
      sum = 0;
      count = 0;
    }
  } 

// picture loop
  u8g.firstpage();

  {
    draw();
      u8g.setprintpos(0, 60);
      u8g.setfont(u8g_font_fur49n);
      u8g.print(mph);
      u8g.setprintpos(80, 20);
      u8g.setfont(u8g_font_fur14);
      u8g.print(rpm);
  }
  while( u8g.nextpage() );
}

you use double speed constructor.
code: [select]
u8glib_lm6059_2x u8g(15, 16, 17, 18, 19);
also hw spi option, if change pins.

i suggest reduce/avoid number of float variables.
perhaps sum , sum2 replaced integer variables.

oliver


Arduino Forum > Using Arduino > Displays > print speed with ST7565


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support