Pages: [1]   Go Down
Author Topic: U8Glib and analog inputs.  (Read 1567 times)
0 Members and 1 Guest are viewing this topic.
South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I have some pots connects to my mega. I also have u8Glib running my LC7981 driven display.

If i comment out the code for the display updates my analog ins run nice and smooth and sample great....

If i leave int he do{} while for the picture loop it drop me down to around 1 analog update every other second.

Is this just how long it takes to update the display or is there something i can do to get my analog in's sampling more quickly while not sacrificing too much on the display?

Thanks all.
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 4397
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
... or is there something i can do ...
It would be easier to determine if there is something you could do if we first had some information about what you already did.  That's an oblique way of suggesting that you post your code.

Don
Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a lot of code there.

here are some pieces that illustrate generally what i have going on.....

Full code attached if needed.

Code:
void menuSelection(){

  // depending on what menu is displayed do the proper function for the button press

  if (menuNumber == 4 && millis() - lastButtonPress > debounce){
    if (!screenButton4) {
      menuNumber = 3;
      buttonStates = false;
      masterInputs = false;
      slaveOutputs = false;
      lastButtonPress = millis();
    }
  }
}

void getInputs(){

  azimuthMaster = analogRead(azimuthPin); // read analog values from master arm
  shoulderMaster = analogRead(shoulderPin);
  elbowMaster = analogRead(elbowPin);
  pitchMaster = analogRead(pitchPin);
  wristMaster = analogRead(wristPin);
  jawClose = analogRead(jawClosePin);
  jawOpen = analogRead(jawOpenPin);
  freeze = analogRead(freezePin);
  Serial.println(elbowMaster);

  screenButton1 = digitalRead(screenButton1Pin); // set variables to state of pins
  screenButton2 = digitalRead(screenButton2Pin);
  screenButton3 = digitalRead(screenButton3Pin);
  screenButton4 = digitalRead(screenButton4Pin);
  screenButton5 = digitalRead(screenButton5Pin);
  screenButton6 = digitalRead(screenButton6Pin);
  screenButton7 = digitalRead(screenButton7Pin);
  screenButton8 = digitalRead(screenButton8Pin);

  upButton = digitalRead(upButtonPin);
  downButton = digitalRead(downButtonPin);
  leftButton = digitalRead(leftButtonPin);
  rightButton = digitalRead(rightButtonPin);

  if (screenButton1 || screenButton2 || screenButton3 || screenButton4 || screenButton5 || screenButton6 || screenButton7 || screenButton8 || upButton || downButton || leftButton || rightButton){
    anyButtonPressed = true; // if any face button is pressed make this true
  }

  else {
    anyButtonPressed = false; // else no buttons are pressed
  }
}



void Menu(){

  switch (menuNumber){
  case 4: // page to display diag sub pages (analog in, servo out, button state)
    //left aligned position (leftSideOfScreen, vertical position, string  )
    u8g.setFont(u8g_font_unifont);
    u8g.drawStr( 0, 20, "");
    u8g.drawStr( 0, 55, "");
    u8g.drawStr( 0, 90, "");
    u8g.drawStr( 0, 125, "<- Diag");

    //right aligned position (screenWidth-WidthOfString), vertical position, string)
    u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 20, "");
    u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 55, "");
    u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 90, "");
    u8g.drawStr(screenWidth-(u8g.getStrWidth("")), 125, "");
    break;
  }
}

void Diag(){
  if (masterInputs){ // display raw inputs from master controller
    u8g.drawStr(screenWidth/2-(u8g.getStrWidth("Master Inputs"))/2, 12 ,"Master Inputs");
    u8g.drawFrame((screenWidth/2-(u8g.getStrWidth("Master Inputs"))/2)-2, 0, u8g.getStrWidth("Master Inputs")+4, 14);
    /* Display the name of the function aligned just left of center
     then display the value 3 pixels right of the colon */
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Azimuth:"))+15),28,"Azimuth:"); // set label and align
    u8g.setPrintPos(screenWidth/2+18,28); // set location of value print
    u8g.print(azimuthMaster); // value to print
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Shoulder:"))+15),43,"Shoulder:");
    u8g.setPrintPos(screenWidth/2+18,43);
    u8g.print(shoulderMaster);
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Elbow:"))+15),58,"Elbow:");
    u8g.setPrintPos(screenWidth/2+18,58);
    u8g.print(elbowMaster);
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Pitch:"))+15),73,"Pitch:");
    u8g.setPrintPos(screenWidth/2+18,73);
    u8g.print(pitchMaster);
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Wrist:"))+15),88,"Wrist:");
    u8g.setPrintPos(screenWidth/2+18,88);
    u8g.print(wristMaster);
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Jaw Close:"))+15),103,"Jaw Close:");
    u8g.setPrintPos(screenWidth/2+18,103);
    u8g.print(jawClose);
    u8g.drawStr((screenWidth/2-(u8g.getStrWidth("Jaw Open:"))+15),118,"Jaw Open:");
    u8g.setPrintPos(screenWidth/2+18,118);
    u8g.print(jawOpen);
   
  }
}

void draw(void) {
  Menu();
  Diag();
  Logo();
}

void loop(void) {
  getInputs();
  menuSelection();
 

    // picture loop
    u8g.firstPage();
    do {
      draw();
    }
    // Serial.println("drawing");
    while( u8g.nextPage() );
}

* SC_Arm_Menu.ino (8.79 KB - downloaded 5 times.)
* getInputs.ino (3.69 KB - downloaded 9 times.)
* DisplayFunctions.ino (9.56 KB - downloaded 7 times.)
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1526
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

The main problem is, that the picture loop is always executed. It is better to redraw the display only in those cases where the content of the screen has changed. My suggestion is to introduce a flag "is_update_required" and execute the picture loop depending on this flag:

Code:
void loop(void) {
    getInputs();
    menuSelection();    // this procedure should set "is_update_required"
 
    if ( is_update_required )
    {
        // picture loop
        u8g.firstPage();
        do {
          draw();
        }
        // Serial.println("drawing");
        while( u8g.nextPage() );
        is_update_required = 0; // reset the update flag to avoid another redraw
    }
}

Once your program has detected a valid menu change, then the "is_update_required" must be set.
See also this tutorial for U8glib: http://code.google.com/p/u8glib/wiki/tmenu

One more note: The "Menu" addon M2tklib for U8glib also includes this mechanism.

Oliver
Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks very much. I tried something similar earlier when testing but it was a little different than your implementation.

I attempted to do the picture loop itself when the menu was updated. Made it go somewhat goofy. I will try your method and report back.


Logged

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Works like a champ. Thanks very much.
Logged

Pages: [1]   Go Up
Jump to: