last day (21 days later) » 

15:48
2
A: Run encoder code simultaneously with other code in Arduino

chrisl can arduino actually run 2 void loop simultaneously No, it cannot. All AVR based Arduinos (like Uno, Nano, Mega) have only one core, thus they can only execute one thing at a time. The typical way to go is to just not introduce delays and divide up complex things into smaller parts. That way yo...

Hi, I have used your code above, and it does not work, problem still the same. So, I have tried the millis() function in my updated code in my post :) but it still gives the same problem. May I ask if my updated code in my post is correct :) ?
Sorry, but that is a completely different code. In the first you used interrupts for the counting (which is good), in the second one you scrapped all the interrupt code. And because of that you didn't use any of my code (that is code only needed when using interrupts to count).
"it does not work, problem still the same" - I think first you really need to understand what the code from that video does. It seems, that you don't know that. And then you can start to change it. Currently you did show, what code you added to the original and also didn't state what exactly doesn't work. You need to provide a detailed description of what you expected to happen and what actually happened, together with the code and serial output of the code in question. Otherwise we cannot help you
Hi chrisl, I have updated my code to use noInterrupts() in my post, may I know if it is correct? :)
A big thank you for your answer, by the way, very concise :)
Better, but you are still using counter in the if statement and for assigning to temp. The point is to use counter just for assigning its value to a non-volatile variable, in this case county. In the code after that (inside loop()) you should only use county.
And if you want to reset the counter, do this inside the ISR, so in ai0() and ai1()
Hi chris, I have updated my code to exclude the temp? Is it correct? Pardon me, we have quite a discussion here
Have you used these type of rotary encoder which I bought the same from the Youtube video before? Well, actually I was trying to implement PID code under the
Serial.println(county); , but it affects the rotary encoder steps. And without the PID code or when I just put simple if statement or command under the Serial.println(county); , everything works smoothly. Haizz, my code definetely has problem. Is the code I wrote correct haha?
16:23
If the code with the PID shows problems, then you should include that code into your question. I cannot help with a code, that I cannot see
Right, I updating it now
Hi I updated my PID code and my PID code is copied from youtube.com/…
And I combine it with my encoder to actually rotate a propeller suspended on the rotary encoder as shown in this youtube.com/watch?v=MmF5qTqPTxU&ab_channel=NabilMohammad
Actually, my code works, just that after 10 seconds, the encoder reading gets bad and loses its correct angle of rotation
of the stick
The motor I used, however, is a small mini DC brushless motor, 3.7V mini one
just need PWM to control it
But, they didn't provide the Arduino code sadly
16:38
The PID code should not be in the ISR but in loop(). Also no Serial inside of an ISR (that can create deadlocks). The workflow should be the following: In the ISRs: Depending on encoder pins increment or decrement the counter. Reset it if needed. In loop(): read counter variable in local variable with disabled interrupts. Enable interrupts again. if value changed from previous value: execute PID code and output to serial
My overall setup is an encoder as shown in youtube.com/… and a microbrushless motor (Can easily controlled by PWM) and yea, some transistors to amplify the PWM power to be fed to the motors :)
-2
Q: Arduino PID for propeller pendulum to balance horizontally

jessica smiththis hobby project I setup is using an encoder to make the stick to be 90 degress which is at 1500 steps (0 degrees=perfectly horizontal using PID control). My encoder counter code is obtained from video here and I have tested it which works perfectly well. Since this encoder is 1200 steps/rev. i...

is that you or is that just someone doing the same thing?

  last day (21 days later) »