Show Posts
Pages: 1 2 3 [4] 5 6 ... 100
46  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
47  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  !
48  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.
49  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
50  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.
51  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 

52  Using Arduino / Project Guidance / Re: need to detect button hold via VirtualWire on: March 17, 2014, 07:19:12 am
Well I got there in the end.

When the first data comes in, it starts a two second timer, and a loop counter.

At the end of the 2 secs, it sees how many loops has been, and if its more than 6, it sets the standby function.

One problem was that after blanking, it came back on again , and that was because there was still one lot of data in the VW buffer, so I made it ignore the first data if in standby.

It means they press update for over 2 secs to switch off,  and press update twice to switch back on.  ( it has to do , I had to get it out quick )
The code is not pretty, and is like picking your nose with your thumb !  :-)  but it works !

53  Using Arduino / Project Guidance / Re: need to detect button hold via VirtualWire on: March 14, 2014, 05:04:29 pm
I think I am getting there,  I have 13 jobs to get out and I am getting confused which is which :-)

the standby function in the showtime routine blanks all the displays, I like the schools to leave it in standby as in winter the slight warmth of the power supply keep moisture at bay.
It also saves them walking accross the field to switch on or off !

54  Using Arduino / Project Guidance / Re: need to detect button hold via VirtualWire on: March 14, 2014, 01:31:00 pm
Thanks Crossroads, I tried a few variations on that , but the trouble is that if ((newTime - oldTime) >=1000) will always be when they update the score, perhaps a minute later.

Perhaps I should set a targetMillis as millis + 1000 when the first signal arrives, and set a flag as "counting = 1 "

While  counting is hi, I can count number of signals received , and if > x    enables standby and resets counting. ??
55  Using Arduino / Project Guidance / need to detect button hold via VirtualWire on: March 14, 2014, 08:46:08 am
I have made a remote control for a scoreboard, based on previous ones, but due to oversight, and burning the midnight oil, I forgot to fit my normal  standby button ( to switch off all the displays when not in use )

I was supposed to get this unit out today, and don't have time to add a pushbutton and reprint the decal ( which needs a strip down of 16 bcd switches )

@ Crossroads , finally  I have made a sort of FTDI cable from a $4 usb adaptor, which is plugged in at the back to the receiver on the left, but you can see a socket dangling from the remote too - what a Godsend , I wish you had mentioned it before :-)

Right, so what I have been trying to do, is to have the receiver/display unit go into standby if the update button is held for over a second.
The remote repeatedly transmits, but on the receive side, there is a gap between each  receive.

 if (vw_get_message(buf, &buflen)) // Non-blocking

I know there must be a way to set a timer on the first receive, and somehow make "standby" go high if there is not a second between them, but I just cant see it ( 16 hours sleep since last weekend ! )

Any suggestions ?

Here's the code with debris commented out from what I have tried :-

56  Using Arduino / Networking, Protocols, and Devices / Re: HT12E library on: March 12, 2014, 05:06:03 am
If you look at the first page of this topic, you will see a code I wrote to send to HT12D chips. It was in my early days and very crude, but it worked.
57  Using Arduino / Project Guidance / Re: downlaod sketch via serial pins on: February 21, 2014, 01:03:00 pm
I kept away from the traditional 6 pin header pin for ISP as it was using the SPI pins, that my early pcb bought out to other headers.

The recent telemetry project ( on the same homepage ) was the first time I used the RXD and TXD pins for anything , and as I said it was so nice to add a 100nF cap to the reset pin, and be able to work on the sketch without unplugging the chip all the time !

You never know I might abandon v22 soon and have another go at V1.04 :-)     

58  Using Arduino / Project Guidance / Re: download sketch via serial pins on: February 21, 2014, 10:31:16 am
After I posted this in Project Guidance, I saw a section that includes ISP, but it doesn't matter now, it wont let me delete my own posts for some reason ?

Yes Bob I am suggesting it might be easier to just extend the tx and rx and reset pins from the chipless arduino to the stand alone board to save using the ISP pins.
It would be exactly like running the sketch from the arduino board, but the chip is embedded in the target board.

59  Using Arduino / Project Guidance / downlaod sketch via serial pins on: February 21, 2014, 03:06:20 am
NB  I have found a more appropriate section that deals with ISP, but I cannot delete this post to move it there ?

I never got a chance to buy an FTDI cable, and have always unplugged my embedded chips to tune software in an arduino board.

( I didn't add the normal ISP pins to my stock stand alone pcb that I use )

I am in a mad rush to get a project out, and thought that instead of using the SPI pins, I could just connect pins 1,2,3 , 5volts and ground from my pcb with the embedded chip ( already has bootloader )  to the pins reset, rxd and txd on the headers of my arduino board ( with no chip plugged in ).

I did a search on this but everyone seems to use the ISP pins, I generally never use the serial pins on the chip for anything else.

I made a little telemetry module last month with a USB/TTL converter (  $5 ) and it had the DTR on its header, so I stuck a cap to the reset and could rewrite the sketch no problem.
60  Using Arduino / Networking, Protocols, and Devices / Virtualwire message length on: February 12, 2014, 04:53:32 pm
I have searched on this, and keep coming up with postings of  the original 27 byte payload,  but according to Mikems info

The message length has been increased to 80 , (or payload to 77).   as from V 1.17    :-

1.17 Increase default MAX_MESSAGE_LENGTH to 80. Added vw_get_rx_good() and vw_get_rx_bad() functions.

I need to send about 35 bytes on my current project, and was going to break it into two chunks , then I saw this and will give it a try.
Pages: 1 2 3 [4] 5 6 ... 100