Go Down

Topic: Need pickup winder code (Read 346 times) previous topic - next topic

Maplehead

Hello
I am in desperate need to get my pickup winder going.
I have an Arduino Uno with a SparkFun SEN 09299 photo interrupter and a 16by2 display.
My DC motor is run by a PWM board that I also have the Arduino wired into with a DC power supply supplying 9 volts. The motor is not controlled by the Uno. It has a forward/reverse switch and it's run by a pot.
So that's my hardware.
Can anybody supply me with working code? I'm desperate here.
Somebody I was working with has tried but the Uno won't keep up counting at just about the slowest speed. I need to be winding at about 800 RPM.
I need the Uno to tell me how many times the bobbin wheel has spun. I have a notch in it for the photo interruptor to trigger when it see the LED. I want the display to just read how many turns have taken place no matter what the speed.
Any and all help is greatly appreciated.

spycatcher2k

-=-
http://www.uk-pcb.co.uk - UK Based PCB Fab & Assembly Company
Design & Assembly work undertaken - Arduino repairs & testing - PM for details. Arduino & C# PC programming.

cattledog

 
Quote
Somebody I was working with has tried but the Uno won't keep up counting at just about the slowest speed. I need to be winding at about 800 RPM.
I need the Uno to tell me how many times the bobbin wheel has spun. I have a notch in it for the photo interruptor to trigger when it see the LED. I want the display to just read how many turns have taken place no matter what the speed.
A simple pulse counter using that photo interrupter should not be difficult.

Can you post a sketch of how the photo interrupter is connected. Can you post the code you have.

PaulS

Quote
The motor is not controlled by the Uno.
So, what is it you need the Uno to do? Wave pom-poms and cheer?
The art of getting good answers lies in asking good questions.

wildbill

Here's the basic obvious code based on what you describe:
Code: [Select]

#include <LiquidCrystal.h>
const byte interruptPin = 2;

LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

volatile unsigned long Count=0;    // Revolutions
const int DisplayInterval=1000;    // Time between LCD updates (ms)

void setup()
{
lcd.begin(16, 2);
lcd.print("Pickup Winder 0.1");
attachInterrupt(0, DetectSlot, RISING);
}

void loop()
{
static unsigned long lastTime=0;
unsigned long TimeNow=millis(); 
if(TimeNow-lastTime > DisplayInterval)
  {
  lcd.setCursor(0, 1);
  lcd.print(Count);
  lastTime=TimeNow;
  }
}

void DetectSlot()
{
Count++;
}

Compiled, not tested. You'll need to adapt the pin numbers to whatever you actually used.

A possible issue with your existing code was that it was displaying the count too frequently, so this version just does it once a second. Adjust the interval as needed.

Maplehead

Hi Wildbill

That may have worked. Thank you so much. I'm pressed for time on getting a guitar out and can't be dealing with the code right now.
Question, as the wheel spins faster, will the code display the numbers in a "skipping" fasion, like 85 then 97 then 104 for example?

cattledog

#6
Jun 20, 2017, 04:44 am Last Edit: Jun 20, 2017, 04:46 am by cattledog
Quote
Question, as the wheel spins faster, will the code display the numbers in a "skipping" fashion, like 85 then 97 then 104 for example?
Yes, the code displays the count at fixed time periods = DisplayInterval.

Depending on your rpm, if you wanted to display every count, the display might not be stable enough to read.
At 800 rpm, you get a turn every 75 milliseconds and the numbers would roll by in a blur.

Here is the code to display every change in the count. It may jump counts if the display writing time is longer than the interrupt time. The sketch make use of a "protected" copy of the interrupt count data which can not change while being accessed.

Code: [Select]

#include <LiquidCrystal.h>
const byte interruptPin = 2;

LiquidCrystal lcd(12, 11, 6, 5, 4, 3);

volatile unsigned long Count=0;    // Revolutions
//const int DisplayInterval=1000;    // Time between LCD updates (ms)

void setup()
{
lcd.begin(16, 2);
lcd.print("Pickup Winder 0.1");
attachInterrupt(0, DetectSlot, RISING);
}

void loop()
{
//static unsigned long lastTime=0;
static unsigned long copyCount;
static unsigned long last_copyCount;
//unsigned long TimeNow=millis(); 
//if(TimeNow-lastTime > DisplayInterval)
noInterrupts();
copyCount = Count;
interrupts();
if (copyCount != last_copyCount)
  {
  lcd.setCursor(0, 1);
  lcd.print(copyCount);
  //lastTime=TimeNow;
  last_copyCount = copyCount;
  }
}

void DetectSlot()
{
Count++;
}

Go Up