Closed mjs513 closed 2 years ago
Here is the sketch that is now fixed:
//==============================================
// Display Configuration
//----------------------------------------------
#include <ILI9341_t3.h>
#include <ILI9341_t3_Controls.h>
#include <font_Arial.h>
#include <font_ArialBold.h>
#define FONT_TITLE Arial_16
#define FONT_DATA Arial_10_Bold
// defines for pin connection
#define TFT_CS 10
#define TFT_DC 9
#define LED_PIN 13
// defines for locations
#define BXCENTER 80
#define BYCENTER 120
#define BDIAMETER 75
#define BLOWSCALE -600
#define BHIGHSCALE 600
#define BSCALEINC 100
#define BSWEEPANGLE 300
#define B1XCENTER 240
#define B1YCENTER 120
#define B1DIAMETER 75
#define B1LOWSCALE -20
#define B1HIGHSCALE 20
#define B1SCALEINC 5
#define B1SWEEPANGLE 300
// defines for colors
#define BNEEDLECOLOR C_ORANGE
#define BDIALCOLOR C_DKBLUE
#define BTEXTCOLOR C_WHITE
#define BTICCOLOR C_GREY
#define B1NEEDLECOLOR C_WHITE
#define B1DIALCOLOR C_DKBLUE
#define B1TEXTCOLOR C_WHITE
#define B1TICCOLOR C_GREY
// create the display object
ILI9341_t3 Display(TFT_CS, TFT_DC);
int bBits;
float bData;
// create the dial object(s)
Dial Bits(&Display, BXCENTER, BYCENTER, BDIAMETER, BLOWSCALE , BHIGHSCALE, BSCALEINC, BSWEEPANGLE);
Dial IndexCnt(&Display, B1XCENTER, B1YCENTER, B1DIAMETER, B1LOWSCALE , B1HIGHSCALE, B1SCALEINC, B1SWEEPANGLE);
//==============================================
// Quad Encoder Configuration
//----------------------------------------------
#include "QuadEncoder.h"
uint32_t mCurPosValue;
uint32_t old_position1 = 0;
QuadEncoder myEnc1(1, 0, 1, 0, 4); // Encoder on channel 1 of 4 available
// Phase A (pin0), PhaseB(pin1), Pullups Req(0)
//==============================================
void setup() {
while(!Serial && millis() < 4000);
// you know the drill
pinMode(LED_PIN, OUTPUT);
Display.begin();
Display.setRotation(1);
Display.fillScreen(C_BLACK);
digitalWrite(LED_PIN, 255);
// initialize the dials
Bits.init(BNEEDLECOLOR, BDIALCOLOR, BTEXTCOLOR, BTICCOLOR, "Cnts", FONT_TITLE, FONT_DATA);
IndexCnt.init(B1NEEDLECOLOR, B1DIALCOLOR, B1TEXTCOLOR, B1TICCOLOR, "Cnts", FONT_TITLE, FONT_DATA);
/* Initialize the ENC module. */
myEnc1.setInitConfig(); //
myEnc1.EncConfig.positionInitialValue = 0;
myEnc1.EncConfig.IndexTrigger = ENABLE;
myEnc1.EncConfig.INDEXTriggerMode = RISING_EDGE;
myEnc1.EncConfig.positionMatchMode = ENABLE;
myEnc1.EncConfig.positionCompareValue = 300;
myEnc1.init();
}
void loop() {
static int mCurPosValue = 0;
static int mPrevPosValue = 0;
/* This read operation would capture all the position counter to responding hold registers. */
mCurPosValue = myEnc1.read();
if (mCurPosValue != mPrevPosValue) {
Serial.printf("Current position value1: %ld\r\n", mCurPosValue);
Serial.printf("Position differential value1: %d\r\n", (int16_t)myEnc1.getHoldDifference());
Serial.printf("Position HOLD revolution value1: %d\r\n", myEnc1.getHoldRevolution());
Serial.printf("Index Counter: %d\r\n", myEnc1.indexCounter);
Serial.println();
// update the dials
bBits = (float) mCurPosValue;
Bits.draw(bBits);
bData = (float) myEnc1.indexCounter;
IndexCnt.draw(bData);
mPrevPosValue = mCurPosValue;
}
if (myEnc1.compareValueFlag == 1) {
/* Read the position values. */
Serial.printf( "Compare Match at %1d\n", myEnc1.EncConfig.positionCompareValue );
myEnc1.compareValueFlag = 0;
//resets counter to positionInitialValue so compare will hit every 200
myEnc1.write( myEnc1.EncConfig.positionInitialValue );
// re-enable the CMPIE
myEnc1.channel[2].ENC->CTRL |= ENC_CTRL_CMPIE_MASK;
}
}
// this seems odd, recasting to a float and storing in uint32_t bBits = (float) mCurPosValue; // test it... Serial.println(bBits,6); // maybe do this in stead? Bits.draw((float) bBits); bData = (float) myEnc1.indexCounter; Serial.println(bData,6); IndexCnt.draw(bData);
Thanks, Kris @.***
On Wednesday, December 22, 2021, 09:50:47 AM CST, Mike S ***@***.***> wrote:
Here is the sketch: //============================================== // Display Configuration //----------------------------------------------
// defines for pin connection
// defines for locations
// defines for colors
// create the display object ILI9341_t3 Display(TFT_CS, TFT_DC);
int bBits; float bData;
// create the dial object(s) Dial Bits(&Display, BXCENTER, BYCENTER, BDIAMETER, BLOWSCALE , BHIGHSCALE, BSCALEINC, BSWEEPANGLE); Dial IndexCnt(&Display, B1XCENTER, B1YCENTER, B1DIAMETER, B1LOWSCALE , B1HIGHSCALE, B1SCALEINC, B1SWEEPANGLE);
//============================================== // Quad Encoder Configuration //----------------------------------------------
uint32_t mCurPosValue;
uint32_t old_position1 = 0; QuadEncoder myEnc1(1, 0, 1, 0, 4); // Encoder on channel 1 of 4 available // Phase A (pin0), PhaseB(pin1), Pullups Req(0) //==============================================
void setup() {
while(!Serial && millis() < 4000);
// you know the drill pinMode(LED_PIN, OUTPUT);
Display.begin(); Display.setRotation(1); Display.fillScreen(C_BLACK); digitalWrite(LED_PIN, 255);
// initialize the dials Bits.init(BNEEDLECOLOR, BDIALCOLOR, BTEXTCOLOR, BTICCOLOR, "Cnts", FONT_TITLE, FONT_DATA); IndexCnt.init(B1NEEDLECOLOR, B1DIALCOLOR, B1TEXTCOLOR, B1TICCOLOR, "Cnts", FONT_TITLE, FONT_DATA);
/ Initialize the ENC module. / myEnc1.setInitConfig(); // myEnc1.EncConfig.positionInitialValue = 0; myEnc1.EncConfig.IndexTrigger = ENABLE; myEnc1.EncConfig.INDEXTriggerMode = RISING_EDGE; myEnc1.EncConfig.positionMatchMode = ENABLE; myEnc1.EncConfig.positionCompareValue = 300; myEnc1.init(); }
void loop() { static uint32_t mCurPosValue = 0; static uint32_t mPrevPosValue = 0;
/* This read operation would capture all the position counter to responding hold registers. */
mCurPosValue = myEnc1.read();
if (mCurPosValue != mPrevPosValue) {
Serial.printf("Current position value1: %ld\r\n", mCurPosValue);
Serial.printf("Position differential value1: %d\r\n", (int16_t)myEnc1.getHoldDifference());
Serial.printf("Position HOLD revolution value1: %d\r\n", myEnc1.getHoldRevolution());
Serial.printf("Index Counter: %d\r\n", myEnc1.indexCounter);
Serial.println();
// update the dials
bBits = (float) mCurPosValue;
Bits.draw(bBits);
bData = (float) myEnc1.indexCounter;
IndexCnt.draw(bData);
mPrevPosValue = mCurPosValue;
}
if (myEnc1.compareValueFlag == 1) {
/* Read the position values. */
Serial.printf( "Compare Match at %1d\n", myEnc1.EncConfig.positionCompareValue );
myEnc1.compareValueFlag = 0;
//resets counter to positionInitialValue so compare will hit every 200
myEnc1.write( myEnc1.EncConfig.positionInitialValue );
// re-enable the CMPIE
myEnc1.channel[2].ENC->CTRL |= ENC_CTRL_CMPIE_MASK;
}
}
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.Message ID: @.***>
Yep agree cleaning up the sketch now so it reads:
// update the dials
Bits.draw(mCurPosValue);
IndexCnt.draw(myEnc1.indexCounter);
Still want to add a few things to the display then need to finish debugging an issue with Quad encoder library.
PS keep forgetting to tell you - you really are a wizard with these graphing functions - they really do make it so much easier to work with displays. Still have on my todo list the use of the powerpoint conversion for the gui
Hi Kris - ok putting the issue with the right library. So lets start over. I am trying to use a dial gauge to go from say -600 to +600 so I configure the range on one of the dials with those values and it displays properly. Yet when I tried to plot a negative value it just pointed straight down. So now for some added info.