Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Re: Using interrupt to move step motor on: March 10, 2014, 02:49:56 am
thank you for your answer .It was very helpful to me
My project is a knife that moving up an down and cuts a material to slices(many pages of paper).The step motor will move the material 1 to 3 mm foward so the knife cuts it . Every time the knife finishes one cut ,the motor will start to move .
I thote that this movemend was to fast for arduino to sense the knife but as you say ,it will be ok.
I will take it from start and rewrite my code
2  Using Arduino / Project Guidance / Using interrupt to move step motor on: March 09, 2014, 07:15:36 pm
I am trying to make a step motor move for some steps every time a photosensor resistor triggered .
I have to use interupts so that I will be sure that arduino saw the photosensor
For my project I used the simple interrupt example of blinking a LED and I added my stepmotor rotattion for 100 steps.
The proplem is that the program freezes at first step of the step motor.
Code:
#include <Stepper.h>
int pin = 13;
volatile int state = LOW;
const int stepsPerRevolution = 48; //set step motor
Stepper mystepper(stepsPerRevolution, 8, 9, 10, 11); //pins for step motor

void setup()
{
  mystepper.setSpeed(10);// set the speed of the motor to 30 RPMs
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, RISING);
}

void loop()
{
  digitalWrite(pin, state);
}

void blink()
{
  state = !state;
   mystepper.step(100);
  }
is there a problem with stepper.h library and interrupts ?
3  Using Arduino / Programming Questions / Re: How do I stop Time.Alarm in my sketch? on: February 22, 2013, 03:12:08 pm
yes thank for your advise .Already done smiley
4  Using Arduino / Programming Questions / Re: How do I stop Time.Alarm in my sketch? on: February 21, 2013, 04:32:24 am
Thank you for your awsers .
As I told you before  I chopped  my originally sketch  so it is more easy to understand my problem
Originally this sketch is an egg incubbator  and timer needed for egg spinning smiley-razz
5  Using Arduino / Programming Questions / Re: How do I stop Time.Alarm in my sketch? on: February 21, 2013, 03:29:12 am
my code is  redused to minimal so you can understand what I need.

so my code needs to be like this ?
Code:
#include <Time.h>
#include <TimeAlarms.h>
#include <Stepper.h>
     
      int  MYType;
      int resetPin = A2;
      int addHourPin = A3; 
      int addMinPin = A4;
     
    int ID ;
    int ID2 ;
   
    const int stepsPerRevolution = 48; 
    Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);
     
   
void setup(){
                 
                  stepper.setSpeed(150);
                   setTime(0,0,0,1,1,11);
      ID = Alarm.timerOnce(60, spinning);
      ID2=Alarm.timerRepeat(3600, spinning);
      //           Alarm.timerOnce(60, spinning);  //step motor spins 60 sec after boot
      //           Alarm.timerRepeat(3600, spinning);  //step motor spins after an hour
         }
 
void loop(){
 
             RANDOM COMMANDS ;

 /*=========== GENERAL reset pin. Everithing resets to zero when presed=============*/
 
             if(digitalRead(resetPin) == HIGH){
                                      Resetingeverithing ();
//command to turn off Alarm.timers
disable(ID);
disable(ID2);
                                       setTime(0,0,0,1,1,11);  //at this point  Alarms are trigered always
//command to turn on Alarm.timers
enable(ID);
enable(ID2);
                     }//end of reset
         }  //END of LOOP

void Resetingeverithing () {
 
                     Alarm.delay (2000);
                     lcd.clear();
                     lcd.print("timer will be set back to zero");
                     //going back to loop
         }
                     
void spinning (){
                           stepper.step(100);
         }


because  it gives me  this
Code:
sketch_feb21a:41: error: 'disable' was not declared in this scope
sketch_feb21a:45: error: 'enable' was not declared in this scope
6  Using Arduino / Programming Questions / How do I stop Time.Alarm in my sketch? on: February 20, 2013, 05:10:43 pm
In this sketch I need to add a command  ,so I can stop  TimeAlarm  triger  spinning()  every time i reset timer  (or I add hours with a seccond button).
I need spinning triggered  60 sec after turn on or reset  and after that ,every hour.
thank you

Code:
#include <Time.h>
#include <TimeAlarms.h>
#include <Stepper.h>
     
      int  MYType;
      int resetPin = A2;
      int addHourPin = A3; 
      int addMinPin = A4;
   
   
    const int stepsPerRevolution = 48; 
    Stepper stepper(stepsPerRevolution, 8, 9, 10, 11);
   
   
   
   
   
void setup(){
 
                 
                  stepper.setSpeed(150);
                   setTime(0,0,0,1,1,11);
     
                 Alarm.timerOnce(60, spinning);  //step motor spins 60 sec after boot
                 Alarm.timerRepeat(3600, spinning);  //step motor spins after an hour
         }
 
 
void loop(){
 
            //  RANDOM COMMANDS

 /*=========== GENERAL reset pin. Everithing resets to zero when presed=============*/
 
             if(digitalRead(resetPin) == HIGH){
                                      Resetingeverithing ();
//command to turn off Alarm.timers
                                       setTime(0,0,0,1,1,11);  //at this point  Alarms are trigered always
//command to turn on Alarm.timers
                     }//end of reset
         }  //END of LOOP

void Resetingeverithing () {
 
                     Alarm.delay (2000);
                     lcd.clear();
                     lcd.print("timer will be set back to zero");
                     //going back to loop
         }
                     
                     
void spinning (){
                           stepper.step(100);
         }
7  Using Arduino / Programming Questions / Re: SOLVED How is "adjustTime(adjustment);" command used ? (time library) on: February 13, 2013, 04:11:08 pm
adjustTime(10);  
number "10" is in seconds.
Thank you for your answers
8  Using Arduino / Programming Questions / Re: How is "adjustTime(adjustment);" command used ? (time library) on: February 13, 2013, 03:39:59 pm

Sadly, the documentation provides NO help.  Basically it says "use this function to adjust the time".  The Playground article also shows no examples that include adjustTime(). 

I am trying to find exambles of that command  for 3 days.
I feal like retarded
9  Using Arduino / Programming Questions / Re: How is "adjustTime(adjustment);" command used ? (time library) on: February 13, 2013, 03:36:33 pm
Is posible to give me a practical exable for adding  1 minute or 1 hour  please ?
only the command
Thank you
10  Using Arduino / Programming Questions / SOLVED How is "adjustTime(adjustment);" command used ? (time library) on: February 13, 2013, 12:02:40 pm
How is "adjustTime(adjustment);" command used ?

I want to  send a command to my program ,so an hour or a day is added to timer.
Later those commands will be sent by the press of a button

Is this command ok ? adjustTime(hour()++);
Code:
#include <Time.h>  


void setup()  {
  Serial.begin(9600);
 
  Serial.println("sending time to arduino");
  setTime(0,0,0,1,1,2000);
}

void loop(){
digitalClockDisplay();
delay(1000);
}

void digitalClockDisplay(){
 
  Serial.print(day());
  Serial.print(" ");
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
   Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

11  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: February 13, 2013, 10:51:00 am
How is "adjustTime(adjustment);" command used ?

I want to  send a command to my program ,so an hour or a day is added to timer.
Later those commands will be sent by the press of a button

Is this command ok ? adjustTime(hour()++);
Code:
#include <Time.h> 


void setup()  {
  Serial.begin(9600);
 
  Serial.println("sending time to arduino");
  setTime(0,0,0,1,1,2000);
}

void loop(){
digitalClockDisplay();
delay(1000);
}

void digitalClockDisplay(){
 
  Serial.print(day());
  Serial.print(" ");
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year());
  Serial.println();
}

void printDigits(int digits){
   Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

12  Using Arduino / Programming Questions / Re: help on time library .unkown commands on: February 11, 2013, 11:19:45 am
thank you for your answers . they were enlinghtening
13  Using Arduino / Programming Questions / help on time library .unkown commands on: February 11, 2013, 11:02:15 am
what is the meaning of those commands  in SerialTime example ?
Code:
#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message
#define TIME_REQUEST  7    // ASCII bell character requests a time sync message
.....
time_t requestSync()
{
  Serial.print(TIME_REQUEST); 
 return 0; // the time will be sent later in response to serial mesg
Where can I read about those commands ?
 I google them  and  only the SerialTime example came up
I read  time  filefolder  and I can't find anithing about those commands (with capital letters like:TIME_MSG_LEN)
14  Using Arduino / Programming Questions / Re: need timer to count and display time from zero to 30 days (day-hour:min:sec) on: February 09, 2013, 09:05:13 am
This is what I made 1 year ago .But to succeeded  I changed time  libraries  . Now with a fresh version of arduino ,this cod doesn't run . I lost my changed time library and I cant remember the changes that I have made
In this program a counter starts from zero. you can add hours and mins  by pressing pins or you can erase timer.
Also there is a backup ,every hour, in case of power loss.
Code:
#include <DateTime.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>
/* LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)./. */
 
    int resetPin = 10; // pin 10 resets the time
    int addHourPin = 9;
    int addMinPin = 8;
    long restoreTime = 0;
    int  restoreDay = 0;
    int eepromTime = 0;
    int eepromDay = 0;
    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);//create object to control an LCD

void setup(){
 
       lcd.begin(16, 4);  // set up the LCD's number of columns and rows
       digitalWrite(resetPin,HIGH);  // this line enables pull-up
       digitalWrite(addHourPin,HIGH);// this line enables pull-up
       digitalWrite(addMinPin,HIGH);// this line enables pull-up
       pinMode(13,OUTPUT);          // we flash the LED each second
       pinMode(resetPin, INPUT);    // a button on this pin resets the time
       pinMode(addHourPin, INPUT);//add hours to counter
       pinMode(addMinPin, INPUT);//add hours to counter
       
       DateTime.sync( 0 );             // set time to zero
 
 
 /*Restoring Time  after every power failure*/
       
       restoreDay = EEPROM.read(10); //Read days passed
       restoreTime = EEPROM.read(0); //read hours passed
       if (restoreDay !=0) { 
       restoreTime = (restoreTime*3600+(restoreDay-1)*86400); //add days and hours to datetima counter
       DateTime.sync(restoreTime);
       }
 delay (30);
 
}


void loop(){
  /* --------- Prints time in hours, minutes and seconds ----------- */
 DateTime.available(); // needed to refresh the clock time
 
      /* GENERAL reset pin. Everithing resets to zero when presed*/
       if(digitalRead(resetPin) == HIGH){
           
           for (int u = 0; u < 20; u++)
           EEPROM.write(u, 0);            // write a 0 to all 512 bytes of the EEPROM
           DateTime.sync( 0 );            // reset time to zero if button pressed
            }
 
 
 
 time_t timeNow = DateTime.now();
 time_t customTime = timeNow;
 
 
     if(digitalRead(addHourPin) == HIGH){
         customTime += (86400 * 1); //add 3600 sec  for 1 time(for test,adds a day)
         DateTime.sync(customTime);   // increase hour by one (1 day)
             }
   
     if(digitalRead(addMinPin) == HIGH){
         customTime += (60 * 1);
         delay (100);
         DateTime.sync(customTime);      // increase min by one
       }
 
     
      //... BACKUP TIME EVERY 1 HOUR...//
     
      if ((DateTime.Minute) == 1 && (DateTime.Second)==10 ) {
          eepromTime  = DateTime.Hour;
          EEPROM.write(10,eepromDay);
          eepromDay = DateTime.Day ;
          EEPROM.write(0,eepromTime);
         }
 
 
 // lcd  PRINT
 
 lcd.setCursor(0,0);
 lcd.print("Hr:min:sec");
 lcd.setCursor(12,0);
 lcd.print(DateTime.Hour,DEC);    // prints total hours
 lcd.print(":");
 lcd.print(DateTime.Minute,DEC);  // and minutes since reset
 lcd.print(":");
 lcd.print(DateTime.Second,DEC);  // and sec since reset
 lcd.print(" ");                  // clears second digit every minute
 
 lcd.setCursor(0,1);
 lcd.print("Project Day");
 lcd.setCursor(13,1);
 lcd.print(DateTime.Day,DEC);    // prints total days
 lcd.print(" ");
 
 /*test perposes lines*/
 lcd.setCursor(0,3);
 lcd.print("epromDay ");
 lcd.print(eepromDay);
 lcd.print(" time ");
 lcd.print( eepromTime );   
 lcd.print("  ");
 
 digitalWrite(13, LOW);           //light the LED every second
 delay (10);
 digitalWrite(13, HIGH);                 //
}
15  Using Arduino / Programming Questions / need timer to count and display time from zero to 30 days (day-hour:min:sec) on: February 08, 2013, 08:32:50 pm
I need a counter ,for time elapsed from zero point (reset)  but this timer must count for days.
it will show to display "day 2 :00:01:03"  and thiw will mean that its elapsed 2 days and 1 min 3 sec from the time I pressed reset button.

My only question is how can I start this timer on mega8

Thank you
Pages: [1] 2