And at this stage im just getting some basic motor controls and LED updates before I get into doing the MPH and RPM reading calculations done.
I’ve modified the stepper.h library to strip out the other wire code and fixed its stepper sequence which was just wrong…
That side of things seem to work fine. Its used code is actually untouched apart from sequence.
Now the trouble is with my LED array.
Where before on the Uno the array would update fine and the motor would run at full speed. I have the LED array updating between each MPH step (23 or so motor steps…)
Can anyone please take a look at this code and tell me why its running so slow? The main reason im using the maple is because its 75mhz. Its meant to be faster than the Uno, should be able to get more done… And i read theres even some basic software multi threading as well…
Which is useful as its going to be calculating MPH and RPM and display those details on motorised dials leds and a lcd display :p
BTW I’m coding from PlatformIO and building and uploading from arduino IDE, cant seem to upload and build form PlatformIO
Also I apologies for my naming conventions and theres plenty of commented out code while Ive been trying to find the cause of the slow down.
The function where things dont seem to be running at proper speed is moveMPH, and slows down when i run the call updateMPHled…
I’ve never claimed to be a coding genius. Im a graphics artist by trade. But if anyone can help me please let me know how to fix this.
Is it really just a flag or setting I need to apply to the STM? Something to call to get it to run full speed?
#include <Arduino.h>
#include <LiquidCrystal_I2C.h>
#include <newStepper.h>
#include <math.h>
#include <FastLED.h>
#define ledPin 3
#define numLeds 24
// Define the array of leds
CRGB led_array[numLeds];
LiquidCrystal_I2C lcd(0x3F, 20, 4);
const int HomeBTN = 13; /// pin connected to button
int MPH = 0; // to be replaced by a MPH calculator in loop connected to bike
int OldMPH = 0;
int differ = 0;
// The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////
//4096
// 2.25 deg per MPH, 5.625/64 = 0.0879, 2.25/0.0879 = 25.6 steps per mph
///////////////////////////////////////////////////////////////////////////////
/////// Stepper Settings /////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
#define StepsPerRev 2080 //2080 seems to be cloest non float figure //37.9 //88641975 /// 2037.88641975 /// 2048 /// 4075.7728395
#define mphRange 80 // dial range for MPH
#define StepsPerMPH ((StepsPerRev) / 2 / (mphRange)) //13
#define speed 15 //500 at 5v 700-750 at 9v some skipping 850 at 12v but too hot i think
//////////Stepper Call
newStepper mph_stepper(StepsPerRev, 8, 9, 10, 11); /// 64 steps per motor 360 (not geared rev)
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void updateMPHled (int cMPH)
{
int light = ((numLeds + .0f) / (mphRange + .0f) * cMPH); // (numLeds / mphRange * cMPH);
//Serial.print("Blah " + String(light));
//Serial.println();
for (int led = 0; led < numLeds; led++)
{
int cVal = 0;
if (led <= light)
{
cVal = 5;
}
led_array[led].setRGB(cVal,cVal,cVal);
FastLED.show();
}
}
//////////////////////////////////////////////////////////////////////////////
void moveMPH(int inMPH) ///function to move motor to the mph detected and displays information on the screen
{
// MPH = inMPH;
//lcd.clear();
//lcd.setCursor(0, 0);
//lcd.print (String("MPH= ") + inMPH);
//lcd.setCursor(0, 1);
//lcd.print (String("Old MPH= ") + OldMPH);
//lcd.setCursor(0, 2);
//lcd.print (String("Difference= ") + (inMPH - OldMPH));
//Serial.print(OldMPH - inMPH);
//Serial.println();
/// will need changing for interrupted calls for faster mph updating. Will need a seporate var holding current mph or step count possision
if (OldMPH < inMPH)
{
for (int i = 0; i < (inMPH - OldMPH); i++)
{
mph_stepper.step(-StepsPerMPH);
updateMPHled((inMPH)); // StepsPerMPH) + (OldMPH / StepsPerMPH) );
}
}
else
{
for (int i = 0; i < (OldMPH - inMPH); i++)
{
mph_stepper.step(StepsPerMPH);
updateMPHled((inMPH)); // StepsPerMPH) + (OldMPH / StepsPerMPH) );
}
}
OldMPH = inMPH;
}
/////////////////////////////////////////////////////////////////////////
void ZeroHome()
{
while (digitalRead(HomeBTN)== HIGH)
{
mph_stepper.step(11);
}
OldMPH = 0;
}
////////////////////////////////////////////////////////////////////////
void setup()
{
mph_stepper.setSpeed(speed);
FastLED.addLeds<NEOPIXEL,ledPin>(led_array,numLeds);
pinMode(HomeBTN, INPUT_PULLUP);
//Serial.begin(9600); /// for serial feedback
/// setting up LCD during testing
//lcd.begin ();
//lcd.backlight();
//lcd.clear();
/// Current starting demo/homing code, to be replaced with reed detection at 0 and led demos.
ZeroHome();
//for (int i = 0; i < (mphRange / 10) + 1; i++)
//{
// moveMPH(i * 10);
// //delay(200);
//}
//delay(1000);
//for (int i = (mphRange / 10) ; i >= 1; i--)
//{
// moveMPH(i * 10);
// //delay(200);
//}
// ZeroHome();
// delay(1000);
}
//////////////////////////////////////////////////////////////////////////////
void loop() {
//lcd.setCursor(0, 3);
//lcd.print (String(digitalRead(HomeBTN)));
//MPH = random(0, mphRange + 1); // to be replaced by code that calculates MPH
// if (MPH < 0)
// {
// ZeroHome();
// }
// else
// {
// moveMPH(MPH);
// }
moveMPH(0);
delay(100);
moveMPH(80);
delay(100);
}

But: If it’s SPI driven, I’m pretty sure that it has something to do with a wrong clock divider.
Candidate is: https://github.com/FastLED/FastLED/tree … /arm/stm32 (I cannot access to github at the moment, I only see a pink(!) angry(!) unicorn…..wuahaa..)
You should compare every single code (module) with your UNO to find out the “slow down part”.
Dont worry its isolated form the maple mini voltage.
Oh and as for debugger…. LOL im really REALLY not that good. Before this my coding experience was VBA :p
I also dont know C++ that well tbh. I can work stuff out and google every single call and function of c++ but some of the basic syntax really is lost on me. For instance I still cant work out what a this-> is… even when googling about i and reading explanations I still dont get it.
So yeah writing my own LED controller library is pretty beyond my skill set.
But: If it’s SPI driven, I’m pretty sure that it has something to do with a wrong clock divider.
Candidate is: https://github.com/FastLED/FastLED/tree … /arm/stm32 (I cannot access to github at the moment, I only see a pink(!) angry(!) unicorn…..wuahaa..)
You should compare every single code (module) with your UNO to find out the “slow down part”.
Just for one test:
Can you please connect USB to your project and just keep the serial monitor open? (USB serial slow down the whole system under special circumstances, mostly a forgotten “Serial.print”) If it’s much faster, search for every Serial.xxx even in the libraries.
dividervalue can be:
SPI_CLOCK_DIV2
SPI_CLOCK_DIV4
SPI_CLOCK_DIV8
SPI_CLOCK_DIV16
SPI_CLOCK_DIV32
SPI_CLOCK_DIV64
SPI_CLOCK_DIV128
SPI_CLOCK_DIV256
ignore that found the library… and it doesnt appear to make any difference… I think ill have to try the other library
The fastwire library has an extra STM32 part of code, but I’m sure that it was not written for STM32duino, but MBED or something. I just wonder that the library compiles. Maybe in soft SPI mode – you have to look at the verbose output of the IDE if there are any “warning” messages.