Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pin mapping for 3.3v logic (Smoothie). Also some display updates. #1

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions firmware/stepper_nano_zero/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
//define this if you are using the Mechaduino
//#define MECHADUINO_HARDWARE

//define this if your step, dir and error input are 3.3v instead of 5v (Smoothie)
//IMPORTANT NOTE: The pin labeled "D3" is STEP, the pin labeld "TX" is DIR and the pin labeled "RX" is ERROR.
//The original STEP, DIR and ERROR pins will have no function
#define USE_3_3V_SIGNAL

#define NZS_FAST_CAL // define this to use 32k of flash for fast calibration table
#define NZS_FAST_SINE //uses 2048 extra bytes to implement faster sine tables

Expand Down Expand Up @@ -44,15 +49,23 @@
#else
#define SerialUSB Serial
#endif

#ifdef USE_3_3V_SIGNAL
#define PIN_STEP_INPUT (3) // D3
#define PIN_DIR_INPUT (30) // TX
#else
#define PIN_STEP_INPUT (0)
#define PIN_DIR_INPUT (1)
#endif

#ifdef MECHADUINO_HARDWARE
#define PIN_ERROR (19) //analogInputToDigitalPin(PIN_A5))
#else
#ifdef USE_3_3V_SIGNAL
#define PIN_ERROR (31) // RX
#else
#define PIN_ERROR (10)
#endif
#endif

#define PIN_AS5047D_CS (16)//analogInputToDigitalPin(PIN_A2))
#ifndef MECHADUINO_HARDWARE
Expand Down Expand Up @@ -169,4 +182,4 @@ static void inline RED_LED(bool state)


#endif//__BOARD_H__

105 changes: 66 additions & 39 deletions firmware/stepper_nano_zero/stepper_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,10 @@ void StepperCtrl::LCDShow(char *str)
#ifdef MECHADUINO_HARDWARE //mech does not have LCD
return;
#else
display.clearDisplay();
display.setTextSize(2);
clearAndShowHeader();
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println(str);
#endif
}
Expand All @@ -424,12 +424,12 @@ void StepperCtrl::UpdateLcd(void)
int32_t d;
bool state;

display.clearDisplay();
clearAndShowHeader();


//sprintf(str,"uSteps %d", numMicroSteps);

display.setTextSize(2);
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);

state=TC5_ISR_Enabled;
Expand Down Expand Up @@ -490,7 +490,7 @@ void StepperCtrl::UpdateLcd(void)
sprintf(str, "%dRPM open",RPM);
}

display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println(str);


Expand All @@ -502,7 +502,7 @@ void StepperCtrl::UpdateLcd(void)
y=abs(err-x*100);

sprintf(str,"%01d.%02d err", x,y);
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println(str);
//LOG("%s %d %d %d", str, err, x, y);
//
Expand All @@ -519,7 +519,7 @@ void StepperCtrl::UpdateLcd(void)

//LOG("deg is %d, %d, %d",deg, x, y);
sprintf(str,"%03d.%01ddeg", x,y);
display.setCursor(0,40);
display.setCursor(0,DISPLAY_LINE(2));
display.println(str);

display.display();
Expand All @@ -546,43 +546,43 @@ void StepperCtrl::menu(void)

while (!done)
{
display.clearDisplay();
display.setTextSize(2);
clearAndShowHeader();
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);

if (menuItem==0)
{
sprintf(str,"*Run Cal");
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println(str);
}else
{
sprintf(str," Run Cal");
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println(str);
}

if (menuItem==1)
{
sprintf(str,"*Check Cal");
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println(str);
}else
{
sprintf(str," Check Cal");
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println(str);
}

if (menuItem==2)
{
sprintf(str,"*Exit");
display.setCursor(0,40);
display.setCursor(0,DISPLAY_LINE(2));
display.println(str);
}else
{
sprintf(str," Exit");
display.setCursor(0,40);
display.setCursor(0,DISPLAY_LINE(2));
display.println(str);
}

Expand Down Expand Up @@ -612,39 +612,39 @@ void StepperCtrl::menu(void)
switch(menuItem)
{
case 0:
display.clearDisplay();
display.setTextSize(2);
clearAndShowHeader();
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println("Running");
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println("Cal");
display.display();
calibrateEncoder();
break;
case 1:
{
display.clearDisplay();
display.setTextSize(2);
clearAndShowHeader();
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println("Testing");
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println("Cal");
display.display();
int32_t error,x,y,m;
error=maxCalibrationError();
x=(error*100 *360)/ANGLE_STEPS;
m=x/100;
y=abs(x-(m*100));
display.clearDisplay();
display.setTextSize(2);
clearAndShowHeader();
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println("Error");

sprintf(str, "%02d.%02d deg",m,y);
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println(str);
display.display();
while (digitalRead(PIN_SW3));
Expand All @@ -669,15 +669,15 @@ void StepperCtrl::showCalError(void)
#else
char str[100];

display.clearDisplay();
display.setTextSize(2);
clearAndShowHeader();
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);

sprintf(str,"Calibration");
display.setCursor(0,0);
display.setCursor(0,DISPLAY_LINE(0));
display.println(str);
sprintf(str,"Error");
display.setCursor(0,20);
display.setCursor(0,DISPLAY_LINE(1));
display.println(str);
display.display();
#endif
Expand All @@ -691,21 +691,48 @@ void StepperCtrl::showSplash(void)
char str[100];

display.clearDisplay();
display.setTextSize(2);
display.setTextSize(DISPLAY_TEXT_SIZE);
display.setTextColor(WHITE);

sprintf(str,"Misfit");
display.setCursor(0,0);
sprintf(str,"Misfit Tech");
display.setCursor(0,DISPLAY_LINE(0));
display.println(str);
sprintf(str,"Tech");
display.setCursor(0,20);
sprintf(str,"http://misfittech.net");
display.setCursor(0,DISPLAY_LINE(1));
display.println(str);
sprintf(str,"Nano Zero Stepper");
display.setCursor(0,DISPLAY_LINE(2));
display.println(str);
display.setCursor(0,40);
display.setCursor(0,DISPLAY_LINE(3));
display.println(VERSION);
display.display();
#endif //no mechaduino
}

void StepperCtrl::clearAndShowHeader(void)
{
#ifdef MECHADUINO_HARDWARE //mech does not have LCD
return;
#else
char str[100];

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);

sprintf(str,"Misfit Tech");
display.setCursor(0,0);
display.println(str);
sprintf(str,"Nano Zero Stepper");
display.setCursor(0,8);
display.println(str);


display.setCursor(72,0);
display.print(VERSION);
#endif //no mechaduino
}


int StepperCtrl::begin(void)
{
Expand Down Expand Up @@ -1526,4 +1553,4 @@ void StepperCtrl::printData(void)

if (state) enableTCInterrupts();

}
}
11 changes: 10 additions & 1 deletion firmware/stepper_nano_zero/stepper_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

#define N_DATA (1024)

#define DISPLAY_TEXT_SIZE 1
#define DISPLAY_LINE_HEIGHT (10*DISPLAY_TEXT_SIZE)

// the Yellow/Blue SDD1306 has 19 pixels at the top that are for the yellow section
#define DISPLAY_HEADER_OFFSET 19

#define DISPLAY_LINE(LINENUM) (LINENUM*DISPLAY_LINE_HEIGHT)+DISPLAY_HEADER_OFFSET

typedef enum {
CTRL_OFF =0,
CTRL_SIMPLE = 1, //simple error controller
Expand Down Expand Up @@ -89,6 +97,7 @@ class StepperCtrl

//these are LCD functions
void showSplash(void);
void clearAndShowHeader(void);
void menu(void);
void showCalError(void);
int32_t measureMeanEncoder(void);
Expand Down Expand Up @@ -143,4 +152,4 @@ class StepperCtrl
};

#endif //__STEPPER_CONTROLLER_H__

7 changes: 5 additions & 2 deletions firmware/stepper_nano_zero/stepper_nano_zero.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ void setup() {
boardSetupPins();
int to=20;
SerialUSB.begin(460800);

#ifndef USE_3_3V_SIGNAL
Serial5.begin(460800);
SysLogInit(&Serial5,LOG_DEBUG); //use SWO for the sysloging
#endif
LOG("Power up!");
while (!SerialUSB)
{
Expand All @@ -51,7 +52,9 @@ void setup() {
}; //wait for serial

//return;
#ifndef USE_3_3V_SIGNAL
SysLogInit(&Serial5,LOG_DEBUG); //use SWO for the sysloging
#endif
LOG("SErial up!");
SerialUSB.println("starting begin");
stepperCtrl.begin(); //start controller before accepting step inputs
Expand Down Expand Up @@ -108,4 +111,4 @@ void loop() {
}

return;
}
}