I added uView.display(); to the end of loop() but it still didn’t display anything.
I experimented and found that it works if you remove
//digitalWrite(myStep, paso );
from the interrupt routine. I don’t know why this causes a problem.
#include <TimerOne.h>
#include <MicroView.h>
#define myDir 3 // Direction
#define myStep 4 // Step
int paso = LOW;
int m, mu=0,md=0;
int s, su=0,sd=0;
int l, lu=0,ld=0,lc=0;
volatile float angulo = 0;
volatile long tiempo = 0;
float A;
long N;
void setup() {
uView.begin();// begin of MicroView
uView.clear(ALL); // erase hardware memory inside the OLED controller
uView.display(); // display the content in the buffer memory, by default it is the MicroView logo
uView.clear(PAGE);
digitalWrite(myDir, 0 );
Timer1.initialize(67839);
Timer1.attachInterrupt(anticlockwise);
}
void anticlockwise() {
paso!=paso;
//digitalWrite(myStep, paso ); // <- this causes the problem ***
angulo=angulo + 0.0002826633165;
tiempo=tiempo + 68;
}
void loop() {
noInterrupts();
N = tiempo;
A=angulo;
interrupts();
uView.setFontType(0);
uView.setCursor(0,0);
uView.print(A);
uView.setCursor(0,8);
uView.print(N);
uView.display(); // <- added this ***
}
You are using pin 4 for myStep. Pin 4 is used to enable the 3.3V regulator that powers the display. When your interrupt routine set pin 4 LOW it powered off the display. Even setting pin 4 to HIGH would not make anything appear on the display because it is not being initialised again.
You also have an error in your code to toggle paso.
paso!=paso;
should be
paso = !paso;
Here’s a working version, using pin 5 for myStep instead of pin 4
#include <TimerOne.h>
#include <MicroView.h>
#define myDir 3 // Direction
#define myStep 5 // Step <- changed from pin 4 to pin 5 ***
int paso = LOW;
int m, mu=0,md=0;
int s, su=0,sd=0;
int l, lu=0,ld=0,lc=0;
volatile float angulo = 0;
volatile long tiempo = 0;
float A;
long N;
void setup() {
uView.begin();// begin of MicroView
uView.clear(ALL); // erase hardware memory inside the OLED controller
uView.display(); // display the content in the buffer memory, by default it is the MicroView logo
uView.clear(PAGE);
digitalWrite(myDir, 0 );
Timer1.initialize(67839);
Timer1.attachInterrupt(anticlockwise);
}
void anticlockwise() {
//paso!=paso; // <- this is wrong ***
paso = !paso; // <- changed to this ***
digitalWrite(myStep, paso );
angulo=angulo + 0.0002826633165;
tiempo=tiempo + 68;
}
void loop() {
noInterrupts();
N = tiempo;
A=angulo;
interrupts();
uView.setFontType(0);
uView.setCursor(0,0);
uView.print(A);
uView.setCursor(0,8);
uView.print(N);
uView.display(); // <- added this ***
}
You are missing pinMode() functions to set the pins to outputs.
void setup() {
uView.begin();// begin of MicroView
uView.clear(ALL); // erase hardware memory inside the OLED controller
uView.display(); // display the content in the buffer memory, by default it is the MicroView logo
uView.clear(PAGE);
pinMode(myDir, OUTPUT); // <- added this ***
pinMode(myStep, OUTPUT); // <- added this ***
digitalWrite(myDir, 0 );
Timer1.initialize(67839);
Timer1.attachInterrupt(anticlockwise);
}