3D printed parts: Download here
PCB file: Download here. This is a Gerber file with .zip extension.
MCU: ATTiny85
Display: LCD 0.91" 128x32
Bearing: 2x5x2.5
Shaft diamter: 2mm
Arduino code:
/*
* @copyright The H Lab
* Board ATtiny25/45/85 (no Optiboot)
* Chip: Attiny85
* Clock: 8Mhz internal
* OS: ATTinyCore
* File -> Preferences (Addition Boards Manager URLs) http://drazzy.com/package_drazzy.com_index.json
*/
#include <Tiny4kOLED.h>
#include <TimerOne.h>
#include <PinChangeInterrupt.h>
int count = 0;
int speeds = 0;
int testPin = 1;
void testLed(){
digitalWrite(testPin, HIGH);
delay(100);
digitalWrite(testPin, LOW);
delay(50);
}
void setup() {
pinMode(testPin, OUTPUT);
testLed();
// Send the initialization sequence to the oled. This leaves the display turned off
oled.begin();
// Clear the memory before turning on the display
oled.clear();
// Turn on the display
oled.on();
oled.switchRenderFrame();
// interrupt
attachPCINT(4, triggerFunc, FALLING);
Timer1.initialize(250000); // 0.25s
Timer1.attachInterrupt(calcSpeed);
testLed();
}
void calcSpeed() {
detachPCINT(4);
speeds = count * 80; // x4 (=1 s because count in 0.25s). Then x60 for 1 minute. Finally /3 interrupt per round => 80
count = 0;
attachPCINT(4, triggerFunc, FALLING);
}
void triggerFunc(){
count++;
}
void showSignature() {
oled.setFont(FONT8X16);
oled.setCursor(36, 2);
oled.print(F("The H Lab"));
}
void loop() {
oled.clear();
showSignature();
oled.setFont(FONT6X8);
oled.setCursor(40, 0);
String strSpeed = "";
strSpeed.concat(speeds);
strSpeed.concat(F(" rpm"));
oled.print(strSpeed);
oled.switchFrame();
delay(100);
}