Show Posts
Pages: [1] 2 3 ... 98
1  Using Arduino / Programming Questions / Re: what effects millis() ? on: April 22, 2014, 11:28:42 pm
Thats with a crystal, but when I say within a second, I am timing it by hitting "run" on the remote control, to start counting when the PCs clock changes minutes, so it can be a second or so different - thats why I say within a second.

I also remembered why I didnt use this code 2 years ago when I had the same problem,  after pausing, and starting again, the countdown rapidly counts down at first.

At the time, it was beyond me, but this time I just stuck in  targetMillis = targetMillis + 1000  in the case of the "run" button being pushed.
This also helps the first second always being a second, rather than jumping quickly to 59.
2  Using Arduino / Programming Questions / Re: what effects millis() ? on: April 22, 2014, 03:04:35 pm
Thats better,  thanks Bob.

Its within a second after 3 hours with all libraries and things running.
3  Using Arduino / Programming Questions / Re: what effects millis() ? on: April 22, 2014, 11:42:31 am
Thats where I got the  names from ! 
I have used quite a few of your bits of sketches Bob.

I have swapped things round and added and subtracted, but I will try it again as you have put it and report back.
4  Using Arduino / Programming Questions / Re: what effects millis() ? on: April 22, 2014, 07:04:26 am
LOL  Paul,,   if you knew how many changes I have played with here !
I did try micros as well, so that had odd names too.

I had tried targetMillis,  previousMillis  and all sorts along the way.

I guess I should have tidied it up, but I had been up all night.
5  Using Arduino / Programming Questions / Re: what effects millis() ? on: April 22, 2014, 02:18:36 am
I think that might be the problem on one of my projects Mike,  I will try chamnging it just setting a flag to be picked up in the loop.

Meanwhile I have just done a test with a simple sketch to count secs and minutes . Without the libraries it keeps perfect time compared to my pc clock,

With VW running I lose about 2 seconds in 30 minutes, even if I send nothing to the RX pin.

Is there an easy  way of making millis or VW use the other clock?

#include <SPI.h>
        #include <VirtualWire.h>
        #include <MemoryFree.h>
         unsigned long  currentMillis;
        unsigned long  previousMillis = 0;
   int secU=0; 
 int minU=0; 
        void setup(){
           vw_set_rx_pin(19);        // set Rx
          vw_setup(2000); // Bits per sec
          void loop (){   
    currentMillis = millis()  ;
     if(currentMillis > previousMillis)   
       previousMillis = currentMillis  +1000; secU ++ ;   
      if (secU >= 60 )  { secU = 0 ; minU ++  ;}   
        Serial.print(" min= "); Serial.println(minU); Serial.print(" sec = "); Serial.println(secU);
        uint8_t buf[VW_MAX_MESSAGE_LEN];  //  get message
          uint8_t buflen = VW_MAX_MESSAGE_LEN;
          if (vw_get_message(buf, &buflen)) // Non-blocking
            Serial.println("Got: ");  // Show on PC for debugging

          }  //  end of if message
6  Using Arduino / Programming Questions / what effects millis() ? on: April 21, 2014, 11:59:11 pm
I sometimes have problems with timing accuracy when using  the millis() for timing a clock.

I can run the timer alone and its fine, but in some of my projects I also use  VirtualWire  which evidently uses clock1,  and often I have an interrupt connected to pin 2 .

I know you mustnt use pins 9 or 10 for pwm if you are running the VW library.

Is there a problem with either of these libraries affecting the millis accuracy?

I have searched and found a post where someone had problems with VW and another library, and was recommended to change the setup of the VW clock ? ( I didnt understand it )
7  Community / Bar Sport / Re: ship in a bottle 3D printer on: April 18, 2014, 05:57:59 am
Nice comments Jante.

If you think about it, the actual servos/steppers can be a long way from the swivel point at the mouth of the bottle, giving  a higher reduction in errors at the business end. ( my paper napkin wasn't very big :-) )

To get maximum printing area the swivel should be at the mouth of the bottle.

I think the base mat can be printed from the same material first, and stuck to the side or bottom of the bottle ( it could be waves on the sea , whatever )

The tubes I see as 3 sections of tubing from radio telescopic antenna, with the middle diameter one replaced by some mica insulation ,  It could be brazed / soldered at the end, and a hole drilled.

I have a vague notion of using  5  sections of the antenna, with another tube on the outside with an air gap, sensing  the tube touching the glass side of the bottle flexing the "proboscis "  as a sort of end switch.

These are all just thoughts as I drill 50 square holes in plastic boxes while all around are enjoying a holiday !

8  Community / Bar Sport / Re: ship in a bottle 3D printer on: April 18, 2014, 04:35:49 am
How many bottles, er forgotten !

Yes the tube would have to  hottest at the tip, which is why I suggested the coaxial tubes with the current flowing through the narrowest bit where they join at the tip, where the hole is.

Think of the old solder gun with a U shaped copper wire flattened at the end to get hot .

These are just ideas at the moment....
9  Community / Bar Sport / ship in a bottle 3D printer on: April 17, 2014, 09:06:16 pm
I had an idea of making a ship ( or anything )  in a bottle, so googled it and it looks like the only one so far is  where the bottle is printed too.

I have spent many hours drawing this high tech engineering drawing on a napkin :-)   ( I don't think you can see the wine stains on the scan .)

 it takes a little imagination, but basically the lid of the bottle has 2 servos ( X and Y ) attached to it, and a Z avis motor to feed a tube in and out of the bottle.

The thing at the bottom is a half made boat on its side ....

The tube could be 2 coaxial tubes with insulation between them, but joined at the end with a  hole for the melted filament comes out.  A  current flowing through the tubes keeps it hot.

The hole in the bottle lid would be a swivel joint.  With air holes around the lid for ventilation ( fan ? )

Thats as far as I got before getting back to a pile of real jobs to get out.

I might be reinventing the wheel here,  if not, perhaps it could give you guys with free time a project .  If you crowdfund it include me on the team !  

PS  you could of course have the tube fixed, and move the bottle around it.

10  Using Arduino / Programming Questions / Re: array value changing mysteriously on: April 10, 2014, 02:31:10 am
Thanks all,  I will go over it all again this morning,

I was using for ( x = 2 , x<=22,x++ )  thinking about it having 20 positions, but of course the array will allocate all 23 .

Perhaps it is best that I always use a  x=0 to x <  final,   and then add 2 afterwards, I can see what is happening in the array then.

I love this learning, and especially all the help available on the forum.

Thanks Brad for spotting the byte rxnumb [19 ];,  same error on my part, I have made it 20.

"don't put  i <= 10 here"   thats just something I have copied, I couldnt really see the point of it
11  Using Arduino / Programming Questions / Re: array value changing mysteriously on: April 09, 2014, 03:06:00 pm
Thanks Pete

let me play with that.

GIVE THAT MAN A BELLS !  ( its an advert we have in South Africa to honour a great job done  )

I mistook the definition as the range of variables, when its actually the total addresses ? of them ( I dont know the lingo )

So I changed letterstore to [23] and all is fine,  Thanks indeed !

And Grumpy Mike , you were on the right track there, I have bumped your karma up to 499  !
12  Using Arduino / Programming Questions / Re: array value changing mysteriously on: April 09, 2014, 05:08:25 am
Thanks Mike, I thought we had it there, I saw that I had initialised the buffer array, which is set by buflen,  so I removed that and its still the same.

The other buffers I think I have set right ?

I will have to leave it for now, other screaming jobs to get onto, and I will have another look during he night. 

Hopefully some one will spot my errors.
13  Using Arduino / Programming Questions / array value changing mysteriously on: April 09, 2014, 04:47:16 am
I have  almost finished my most ambitious project yet, with some help from you guys along the way.

It is an inline hockey scoreboard,  with 2  teamnames of eight 7x5 LED arrays, plus a whole load of bcd switches for scores, penalties, players number, period etc.

There is also an LCD display and buttons to set the teamnames, or select from a library of previous names.  Thats working fine.

When I transmit to the scoreboard, a 22 or 23 byte message is sent with a digit to say if it is a number command ( 35  or # )  or a letter command ( 42 or * )   followed by the appropriate data.

It starts well enough, you can set both the teamnames, and the age group display,  but as soon as I send a score update, or set time,  the array that I have stored the letters in becomes corrupt, and puts one of the number data into one of my stored letter data.  Which gives a strangely spelt new name.
here is the main loop, with a note to show where the problem arises ,   the buf[2] of the number data, somehow gets written to the buf[21] of the letter array.

( I monitored the free memory and there are 372 bytes spare )

I have attached the whole code,  its really messy and needs tidying up when I can get some free time.

I think I have overlooked something stupid as usual, anybody spot it ?

void loop(){
    if ( standby == HIGH ) { 
      blankalpha ();     // clear teamnames
      blanknumbers ();   // clear numbers
    else  {
      showpenalties (); 
    checktime ();  //  clock countdown
    swapdisplay();  // switch alpha displays between teamname and age group
    uint8_t buf[VW_MAX_MESSAGE_LEN];  //  get message
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    if (vw_get_message(buf, &buflen)) // Non-blocking
      Serial.println("Got: ");  // Show on PC for debugging
      Serial.print(" buflen =   ");
      Serial.println( int (buflen));
      for ( int h = 0; h <=buflen-1; h++ ) { Serial.print(" buffer =   ");
        Serial.print(h); Serial.print( "  =  "); Serial.println( int(buf [h]));
      if ( buf [0] == thisPin ) { //  checking device number
        Serial.println(" pins match   ");   
        standby = LOW;  //  wake up board
        if ( buf [1] == 42 ) {    //  = * ALPHA DATA COMING IN 
          for ( int y = 2; y <=22; y++ ) {
            letterstore [y] = buf [y];   // save incoming names as buf will be changing with scores etc
            Serial.print(" letterstore  "); Serial.print(y);
            Serial.print("  = ");   Serial.println(char ( letterstore [y ]));
          }   //   *****   at this point letterstore 21 is correct as received in the buffer unless
          //  a number button has been pressed, n which case it changes to the new buf[2] value ( key )*****
          group = LOW;  //
          showteamnames ();
        } //  end of if ( buf [1] == '*' )
        if ( buf [1] == 35 )  // =  # NUMERIC DATA INCOMING
          key = buf [2];   
          Serial.print(" key = ");
          Serial.println( int (key));   
          for ( int s = 1; s<= 19; s++ ) {
            rxnumb [s] = buf [s+2] ;     
            Serial.print(" rxnumb  ");   
            Serial.print(" = "); 
            Serial.println( int ( rxnumb [s]));
            penminT =  rxnumb[7];
            penminU = rxnumb[8];
          sortnumbers ();
          refreshpenalties ();
        }  // end of if ( buf [1] == '35' )  //  NUMERIC DATA INCOMING
    }  //  end of if message
  } // end loop
14  Using Arduino / Project Guidance / Re: sudden hassles with Keypad on: March 21, 2014, 02:57:25 pm
I couldn't waste any more time, so I just used the 5 pins straight to the pushbuttons, it cost me 3 extra schottky diodes :-)  but its working fine.

I am using a CD4017 to scan 8 bcd switches, so thats 8 bcd switches, 5 pushbuttons, and a transmitter all from 12 pins.

I have to use the keypad for one of the other projects in line so I must find out what happened.
15  Using Arduino / Project Guidance / sudden hassles with Keypad on: March 21, 2014, 12:18:55 pm
I have been using basically the same sketch for awakening  a remote from sleep, and reading a keypad for 2 years now.
Suddenly now its giving me hassles, I have checked my wiring, even checked that I didn't fit N/C pushbuttons instead of N/O.
here's a sketch  of the circuit for the keypad, actually 5 N/O pushbuttons.

The buttons on column 2 and 3 work most of the time, but sometimes do not send the data, the serial monitor just shows "sleep" when it has gone through its loop.

Both buttons on column 1 do not work.  But if I hook a scope probe on column 1,  both buttons run through the loop ( and show " sleep " )  and intermittently with no scope attached.

I have swapped the physical wiring over from pins 12 and 17, and its still the buttons connected to pin 17 that misbehave.

I have tried different pins for all the keypad, but no different,  any ideas ?

I can just have the 5 switches grounding  5 pins with 5 diodes from the interrupt, but I want to know whats happening ...

Heres the sketch

#include <VirtualWire.h>    // Wireless transmitter/receiver library
#include <Keypad.h>         // Matrix Keypad library
#include <avr/sleep.h>      // powerdown library
#include <avr/interrupt.h>  // interrupts library
uint8_t SW[4]; // assign four data pins from bcd switches

int SW0 = 5;               // bits to read from bcd switches LSB
int SW1 = 6;               
int SW2 = 7;               
int SW3 = 8;               // - MSB
int address = 0;         
int add0;  //  bits generated from bcd switches
int add1;
int add2;
int add3;
int clockPin = 18;
int resetPin = 19;
int PIN = 18;  //  preset pin number to send
int dataB;
int dataC;
int dataD;
int dataF;
int dataG;
int pause=HIGH;
int dpin0 = 0;              // apparently redefined by Serial as Serial Monitor works
int dpin1 = 1;              // apparently redefined by Serial as Serial Monitor works
int pin2 = 2;               // Int0 interrupt pin

int sleep_count = 0;      // flag/counter to tell us to go sleep
// create an array to store data to be sent out
char msg [10]; //   keeping msg 0 for now as we dont have period
// set up the Keypad
const byte ROWS = 2; // two rows
const byte COLS = 3; // three columns
// Define the Keymap
char keys[ROWS][COLS] =
    'A', 'B','C'   }
  ,  // row 1   // 
    'D','E', 'F'   }   
  ,  // row 2   
byte rowPins[ROWS] = {
  14, 15  };  // Keypad uses internal pullups? No externals supplied
// Pressing a Row button connects to a Low Columna and pulls the appropriate Row Diode Low for a Pin2 Low interrupt.
// Column pins are then set back high for the keypad library button determination.
byte colPins[COLS] = {
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// *  Name:        pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
  /* This brings us back from sleep. */
// *  Name:        enterSleep
void enterSleep()
  /* Setup pin2 as an interrupt and attach handler. */
  attachInterrupt(0, pin2Interrupt, FALLING);
  delay(50); // need this?
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // setting up for sleep ...
  sleep_enable();                       // setting up for sleep ...
  ADCSRA &= ~(1 << ADEN);
  PRR = 0xFF;
  sleep_mode();                         // now goes to Sleep and waits for the interrupt
  /* The program will continue from here after the interrupt. */
  detachInterrupt(0);                 //disable interrupts while we get ready to read the keypad
  PRR = 0x00;
  /* First thing to do is disable sleep. */

  // set all the keypad columns back high so can read keypad presses again
  digitalWrite(11, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(13, HIGH);
  // then go to the void Loop()

void setup()
  pinMode(pin2, INPUT);                 // our sleep interrupt pin
  digitalWrite(pin2, HIGH);  // set pull up res
  // define all the unused pins as inputs with internal pullups for lower power state
  pinMode(dpin0, INPUT);                  // apparently redefined by Serial as Serial Monitor works (receiving anyway)
  digitalWrite(dpin0, HIGH);              // apparently redefined by Serial as Serial Monitor works
  pinMode(dpin1, INPUT);                  // apparently redefined by Serial as Serial Monitor works
  digitalWrite(dpin1, HIGH);              // apparently redefined by Serial as Serial Monitor works
  digitalWrite(dpin0, HIGH);
  pinMode (resetPin , OUTPUT );
  pinMode (clockPin , OUTPUT );
  pinMode(SW0, INPUT); // LSB of bcd
  byte add0 = 0;
  pinMode(SW1, INPUT); // LSB+1
  byte add1= 0;
  pinMode(SW2, INPUT);  // LSB+2
  byte add2 = 0;
  pinMode(SW3, INPUT);  // MSB of bcd
  byte add3 = 0;

  PIN = 18; //  ( preset for WPCC to 1101  ( 13 )  Pin number  SACS = 11  Glenwoodrugby 18
  Serial.println("my address is: ");
  Serial.println(PIN, BIN);
  digitalWrite(SW0, LOW);   //  disable pullups on PIN inputs to save current, finished with these pins PIN read.msg[0]
  digitalWrite(SW1, LOW);
  digitalWrite(SW2, LOW);
  digitalWrite(SW3, LOW);

  Serial.println("TX setup");              // for debug only
  // vw_set_rx_pin(0);
  vw_set_tx_pin(4);    //  data
  vw_set_ptt_pin(3); // powers Tx and LED
  digitalWrite(resetPin, HIGH);
  digitalWrite(clockPin, LOW);
  digitalWrite(resetPin, LOW);
// *************************************************************************end of void Setup() 
void loop()
  if (sleep_count>100){                      // check if we should go to sleep because of "time" --> Try shorter versions of this

    sleep_count=0;                           // turn it off for when we wake up
    Serial.println("Sleep");               // for debug only
    //  digitalWrite(3, LOW);// set the columns low before sleeping, otherwise Keypad leaves them high and Rows have nothing to pull low.
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);
    digitalWrite(resetPin, HIGH);  //  making sue 4017 is off
    digitalWrite(clockPin, LOW);
    digitalWrite(resetPin, LOW);
    enterSleep();                             // call Sleep function to put us out
    //  THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()
  }                                           // end of checking to go to sleep
  // Serial.println("wake up and read keypad");
  char key = keypad.getKey();                 // reading the keypad
  if(key)                                     // same as if(key != NO_KEY)- did something change?
    Serial.print("key read =");   
    msg [0]  = PIN;
    msg [1]  = key;
    digitalWrite(resetPin, LOW);  //  making sue 4017 is off
    for ( int h = 2; h <= 9; h++ ) {  // commutate all switch banks 
      digitalWrite(clockPin, HIGH); 
      add3 = digitalRead(SW3);
      add3 = add3 << 3;
      add2 = digitalRead(SW2);
      add2 = add2 << 2;
      add1 = digitalRead(SW1);
      add1 = add1 << 1;
      add0 = digitalRead(SW0);
      address = address|add3;
      address = address|add2;
      address = address|add1;
      address = address|add0;
      msg [h]  = address;
      digitalWrite(clockPin, LOW);
      delay ( 5 );     
    digitalWrite(resetPin, HIGH);  //  making sure 4017 is off
    for ( int k= 0; k <=9; k++ ) { 
      Serial.print("msg = "); 
      Serial.print(" = ");       
      Serial.println(int ( msg[k]) );
    vw_send((uint8_t *)msg, 10);     // send the character out
    vw_wait_tx();                             // Wait until the whole message is gone   
    sleep_count = 0;                          // reset count up to sleep if transmitted a key press
  } //                                           // end of if(key) & transmitting a character
  sleep_count ++;
} // end of void loop 

Pages: [1] 2 3 ... 98