Hello. I'm currently creating some cycling rollers (very similar to a turbo trainer), and would like some guidance for the project.
I'm using an IR sensor, OLED screen, and an arduino uno, but also experimenting with the arduino micro. However, I can source more components.
The circuit measures the RPM, taken from a shaft the wheel sits on, and displays this on the screen (code at bottom of post). However, I want to adapt the circuit and code, as well as components to take this measurement of RPM and broadcast it over bluetooth to use with softwares like Zwift, that can interpret it externally; to calculate speed, distance, etc.
How can I accomplish this? What componets will I need? What modification should I make or do you have any suggestions! I would also consider changing the way it measures RPM as it can be quite inaccurate.
Thanks!
#include <Arduino.h>
#include <U8x8lib.h>
#include <SPI.h>
#include <Wire.h>
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
unsigned long rpmtime;
float rpmfloat;
unsigned int rpm;
bool tooslow = 1;
void setup() {
u8x8.begin();
u8x8.setFont(u8x8_font_profont29_2x3_f);
TCCR1A = 0;
TCCR1B = 0;
TCCR1B |= (1 << CS12); //Prescaler 256
TIMSK1 |= (1 << TOIE1); //enable timer overflow
pinMode(2, INPUT);
attachInterrupt(0, RPM, FALLING);
}
ISR(TIMER1_OVF_vect) {
tooslow = 1;
}
void loop() {
delay(1000);
if (tooslow == 1) {
u8x8.clear();
u8x8.drawString(1, 0, "SLOW!");
}
else {
rpmfloat = 120 / (rpmtime/ 31250.00);
rpm = round(rpmfloat);
u8x8.clear();
u8x8.setCursor(1,0);
u8x8.print(rpm);
}
}
void RPM () {
rpmtime = TCNT1;
TCNT1 = 0;
tooslow = 0;
}