Microview and Timers with attachInterrupt

General MicroView Support area - You have questions, find your answers here.

Moderators: phalanx, Help@GeekAmmo, marcus@geekammo

Post Reply
veckoff
Posts: 4
Joined: Wed Nov 11, 2015 7:08 am

Microview and Timers with attachInterrupt

Post by veckoff » Wed Nov 11, 2015 7:40 am

Hi,
I make a litle program with the Timerone library (http://www.prometec.net/wp-content/uplo ... merOne.zip) but the Microview don't display nothing
I know there are some incompatibilities when interrupts are used, this will be a case?

#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 );
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);


}

scotta
Posts: 45
Joined: Thu Jul 24, 2014 1:31 pm
Location: Toronto, Canada

Re: Microview and Timers with attachInterrupt

Post by scotta » Thu Nov 12, 2015 7:16 am

I don't see any uView.display(); in your loop() function.

scotta
Posts: 45
Joined: Thu Jul 24, 2014 1:31 pm
Location: Toronto, Canada

Re: Microview and Timers with attachInterrupt

Post by scotta » Thu Nov 12, 2015 7:54 am

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.

Code: Select all

#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 ***
}

scotta
Posts: 45
Joined: Thu Jul 24, 2014 1:31 pm
Location: Toronto, Canada

Re: Microview and Timers with attachInterrupt

Post by scotta » Thu Nov 12, 2015 9:05 am

I found the problem. It's not obvious.

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

Code: Select all

#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 ***

}

scotta
Posts: 45
Joined: Thu Jul 24, 2014 1:31 pm
Location: Toronto, Canada

Re: Microview and Timers with attachInterrupt

Post by scotta » Thu Nov 12, 2015 9:23 am

One more thing.

You are missing pinMode() functions to set the pins to outputs.

Code: Select all

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);
}

veckoff
Posts: 4
Joined: Wed Nov 11, 2015 7:08 am

Re: Microview and Timers with attachInterrupt

Post by veckoff » Thu Nov 12, 2015 11:25 am

Thanks a lot, all of you!!,
well, the original sketch its more big and I cut it for copy here,
this code is for mi DIY Skytracker (https://www.youtube.com/watch?v=ye6biVz5RqI)

veckoff
Posts: 4
Joined: Wed Nov 11, 2015 7:08 am

Re: Microview and Timers with attachInterrupt

Post by veckoff » Thu Nov 12, 2015 12:45 pm

Hi Scotta,
well, my sketch work fine now, thanks.
I have a last question, I've been looking for a good diagram for pinout of the Microview that compare with the pins of Arduino Uno.
Where can I find this?
It would be easier to make the necessary program changes to move programs from arduino Uno to Microview.

By

scotta
Posts: 45
Joined: Thu Jul 24, 2014 1:31 pm
Location: Toronto, Canada

Re: Microview and Timers with attachInterrupt

Post by scotta » Thu Nov 12, 2015 3:50 pm

I don't know of any direct comparisons between the MicroView and an Arduino Uno.

The pinout for the MicroView is can be found here:
http://learn.microview.io/Intro/general ... oview.html
and a schematic is here:
https://cdn.sparkfun.com/datasheets/Dev ... roView.pdf

A similar pinout for the Uno is here:
https://i2.wp.com/foros.giltesa.com/otr ... ut/uno.jpg
and a schematic is here:
https://www.arduino.cc/en/uploads/Main/ ... ematic.pdf

The pin numbers are the same for the MicroView and the Uno but the MicroView only has connections for I/O pins:
0 (RXD), 1 (TXD), 2, 3, 5, 6
A0, A1, A2, A3, A4 (SDA), A5 (SCL)

The other pins available on the MicroView are:
GND, VIN, 5V, RESET

veckoff
Posts: 4
Joined: Wed Nov 11, 2015 7:08 am

Re: Microview and Timers with attachInterrupt

Post by veckoff » Fri Nov 13, 2015 9:46 am

Thanks a lot Again !

Post Reply