Show Posts
Pages: 1 ... 80 81 [82] 83 84 ... 97
1216  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 14, 2011, 02:50:02 am
Yes I have one on top of the chips Vcc to GND, it looks scruffy but old habits die hard, if I use double sided board they go on the board/groundplane.

1217  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 13, 2011, 01:37:00 am
That seems to be working fine.

With the full SD format and the half speed I hope its all OK now, thanks for your help.
1218  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 13, 2011, 12:00:15 am
I tried to work out how to set the previousmillis,  but for the one second countdown I cant see how to do it on every pause, so that it restarts at wherever it was.

I worked out a system that would not only time the first second 90% right, but would also restart part way through the second count.

I am now counting in 100mS and dividing by 10 at the display code.

So for 14 seconds timing, I start the timer at 149, and it shows 14 for ( nearly ) the first second. ( the buttons are pressed by somebody with half a second reflexes , so 100mS lost will not make any difference )

If the time is paused half way through a second, it will resume at halfway through when the run button is pressed.

The other advantage is that if required I can easily display the last 10 seconds as seconds and tenth of seconds simply by not dividing by 10 if T < 100  ( last 10 secs )  I have seen this on TV but don't know if it is appropriate for a shot clock.
Everything works great except that one of the preset countdown times required is 60 seconds,  so the preset start count should be 609 which doesn't fit in the Virtual Wires one byte transmission, and comes out at the Rx as 97.

Is there a way for VW to handle numbers greater than 256?  like sending in two parts and sticking together at the far end?

I have had a look at the VWire  pdf manual , but nothing there...
1219  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 12, 2011, 10:23:57 pm
thanks, that was what I saw.
I cant remember at what speed/bits I recorded the wav files, but its only a voice announcement so if I reduce it it shouldnt notice ( I used to use the ISD chips which were pretty slow and acceptable )
1220  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 12, 2011, 12:02:36 am
The plot thickens :-)

I had 4 "Kingston" cards, one of which had "failed" ( though I could still read the files on my PC ),

and 2  traxdata  cards, neither of which worked from the start.

I downloaded the formatter3 and started with a FULL OVERWRITE format ( over half an hour ! ) of one of the nonworking traxdata cards.

I copied the audio files on to it, and it worked 100 %  !

I thought I had hit gold, and decided to reformat all the cards like this, however I got the 2 traxdata cards mixed up, and to see which one had been properly formatted, I tested to see which one worked - and they both did !!

So I have no idea what is going on.   I am formatting all the cards anyway,

Should I slow something down in the card reading to help matters?  I think I saw a choice of some speed..
1221  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 11, 2011, 05:04:55 pm
Creative indeed, but I am still getting the hang of basics   smiley-confuse
1222  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 11, 2011, 05:19:12 am
Yes I should rather use true or high,  I will clean it all up and have a rethink tonight.

On second thoughts make that tomorrow, we are off to the Niel Diamond concert at the Cape Town Stadium tonight !
1223  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 10, 2011, 05:37:47 pm
One trouble  is that whenever I pause the timer and restart it during the countdown, it loses the first second  , so I suppose the firstrun approach wouldn't help that.

Nick, I see what you mean by initialising the previoushornMillis to something other than zero (for example, millis ()).  but where do I do it ?

If I do it in the setup, it wont help with pausing and restarting the clock?    If I do it in the loop it will not be able to check how the time is going each loop ???

Unless I can set it the time of the start button somehow.....


I have got the manual horn working ( toot) for 2 seconds at a time, its OK if I only touch the button on the remote briefly, but if I hold it for too long it throws off the timing of the countdown.

Is there a software interrupt that I can use on the rising edge of my "toot" signal from the receiver decoder( ie , not from either of the normal interrupt pins  ?
1224  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 10, 2011, 03:09:24 pm
Thanks Rob,  I have now just used millis() as suggested above,  I don't know why  "blink without delay " has it  unsigned long currentMillis = millis();   ???

For the countdown I tried:-

   if(millis() > LED_timer){          //executes once immediately (LED_timer initialized to 0)
          LED_timer = millis() + 1000;  //store time of next execution... right now + 1000ms
          programTimer--;     //decrement program timer -1second


as suggested by iklin6, which works, but the first second is skipped through instead of waiting for a second, it is obvious from the code, but not clear how to overcome....
1225  Using Arduino / Programming Questions / Re: blink without delay brain problem on: April 10, 2011, 02:23:19 am
Thanks guys, its a bit clearer in the morning !
Heres all the definitions Nick.
(the project is for a sport countdown clock with a horn at the end for 4 seconds ( and an option not started yet for a 2 second "toot" of the horn when required.)

Theres a couple of functions for displaying the time, and for checking the buttons.

I started off with neat functions for each part, but put a lot of it back in the loop for testing.
There is a lot of comented out rubbish still there,  I will tidy it up later..  ( after the F1 Grand Prix which is about to start :-)  )


Code:
#include <VirtualWire.h>
#define ledPin 13 
#define latchPin 19  // rck
#define clockPin 18  // sck
#define dataPin 16   // ser in
#define blankPin 15  // notG
#define clearPin 17  // not SCLR

int secNibble10;
int secNibble;
int PIN;
int key;
int T = 0;
int toot = 0;
int pause = 1;
int blank = 0;
int horn = 0;
int tens;
int units;
 long previousMillis = 0;        // will store last time LED was updated
 long previoustootMillis = 0;
 long previoushornMillis = 0;


int SW0Pin = 3;               // bits to read in unique address - LSB
int SW1Pin = 4;               // bits to read in unique address
int SW2Pin = 5;               // bits to read in unique address
int SW3Pin = 6;               // bits to read in unique address - MSB
int address = 0;            // bits put together afteer reading switches
int add0;
int add1;
int add2;
int add3;



void setup()
{

  pinMode(SW0Pin, INPUT); // LSB of remote Address
  digitalWrite(SW0Pin, HIGH);
  byte add0 = 0; // read the value of SW0
  pinMode(SW1Pin, INPUT); // LSB+1
  digitalWrite(SW1Pin, HIGH);
  byte add1= 0;
  pinMode(SW2Pin, INPUT);  // LSB+2
  digitalWrite(SW2Pin, HIGH);
  byte add2 = 0;
  pinMode(SW3Pin, INPUT);  // MSB of address
  digitalWrite(SW3Pin, HIGH);
  byte add3 = 0;

  // put our address together
  // read our expansion address
  add3 = digitalRead(SW3Pin);
  // shift it left 3 places
  add3 = add3 << 3;
  add2 = digitalRead(SW2Pin);
  // shift it left 2 places
  add2 = add2 << 2;
  add1 = digitalRead(SW1Pin);
  // shift it left 1 place
  add1 = add1 << 1;
  add0 = digitalRead(SW0Pin);
  // now OR it together
  address = address|add3;
  address = address|add2;
  address = address|add1;
  address = address|add0;
  Serial.println("Rx PIN is: ");
  Serial.println(address, BIN);
  Serial.begin(9600); // Debugging only
  Serial.println("setup");
  pinMode(ledPin, OUTPUT);
  pinMode(blankPin, OUTPUT);
  pinMode ( latchPin, OUTPUT);
  pinMode ( clockPin, OUTPUT);
  pinMode ( dataPin, OUTPUT);
  pinMode (clearPin , OUTPUT);

  digitalWrite(ledPin, LOW);


  vw_set_rx_pin(9);        // set Rx
  vw_setup(4000); // Bits per sec
  vw_rx_start();   
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop ()
{

  // insert the T blinkwithoutpause here, doesnt matter about delays if message received as T will always be reset to Tx time

  showT ();  // runs the display countdown and update function

  ////////////////////////////////////////////////////////////

  if (T >= 0 && pause == 0 ) {

    unsigned long currentMillis = millis();

    if(currentMillis - previousMillis > 1000) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;   

      T -- ;

      Serial.println(T);
      Serial.println("");
      if ( T== -1 ){
        T = 0 ;
      }
    }
  }

  ////////////////////////////////////////////////////////////////





  if ( T <= 0 && pause == 0 && horn == 0) { // if countdown reaches zero and horn is off
    horn = 1;   
    Serial.print("horn is   ");     
    Serial.println(horn); 
  }

  if ( horn == 1) {
    pause = 1;   

    unsigned long currenthornMillis = millis();
   
    if(currenthornMillis - previoushornMillis > 4000) {
      // save the last time you blinked the LED
      previoushornMillis = currenthornMillis;   
      //pause = 1;
      horn = 0 ;
    }


    Serial.print("horn is   ");
    Serial.println(horn);

  }

  // }
  //}
  // sound horn for 4 seconds
  //}//  end of endhorn funct







  // endhorn ();  }
  digitalWrite(ledPin, horn);
  //  pause = 1;   
  //}  // if time 0 and still counting down, runs endhorn then pauses countdown

    if ( toot == 1 )   {
    // must do blinkwithout delay here, not subroutine as is would wait 2 secs before coming back ??
    toot = 0;
  }   // if toot button pressed runs horn 2 seconds and resets toot to 0 until next toot press

  // look for wireless input
  // Turn off LED ready to flash to show working a message

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    ///////////////////////////////////////////////////////////////////////////////////  if message check PIN
    digitalWrite(ledPin, LOW); // Turn on LED to show working a message

    // Message with a good checksum received, dump it.
    Serial.println("Got: ");  // Show on PC for debugging

    PIN = buf[0];   // read Tx PIN number from buffer 0
    if ( PIN == address ) {   //  everything below only runs if PINs match
      Serial.println(" PINs match ") ;

      blank =0;  //  brings display out of standbye with any button pressed

      key = buf[1];  // if PINS match, read key number from buffer 1
      T = buf[2];  // if PINS match, reset time left T from buffer 2

      Serial.print(" Tx PIN address = ");   
      Serial.println(PIN);
      Serial.print(" key number = ");     
      Serial.println(key);
      Serial.print(" seconds remaining = ");   
      Serial.println(T);
      Serial.print(" Rx PIN address = ");   
      Serial.println(address);
      Serial.println(""); // spaces it out for the monitor

      checkbutton ();    ////////////////////////////////////////////////////////////// decode keys

      Serial.print("time = ");     
      Serial.println(T);
      Serial.print("pause = ");     
      Serial.println(pause);
      Serial.print("key = ");     
      Serial.println(key);
      Serial.print("address = ");     
      Serial.println(address);
      Serial.print("toot = ");     
      Serial.println(toot);
      Serial.print("blank = ");     
      Serial.println(blank);
      Serial.println("");

      if ( blank == 1 ) { 
        digitalWrite(blankPin, HIGH);
        T=0;
        pause = 1;
      } // blank the shift reg, reset and stop the clock when in standbye

    } // end of if PINs match
  }//  end of if message received
}  //  end of loop
1226  Using Arduino / Programming Questions / blink without delay brain problem on: April 09, 2011, 09:11:29 pm
I have two timing parts, based on the blink without delay, one works fine, but a simple one to turn on a horn for 4 seconds instantly turns it off again,  I must be missing something stupid !  ( Its 4 am )

heres the bit of code, its supposed to sound the horn at the end of countdown on the clock, which triggers fine, but the four seconds doesnt work..  any clues?  The first part is the time T countdown part that works...

Code:
void loop ()
{

  showT ();  // runs the display countdown and update function

  ////////////////////////////////////////////////////////////

  if (T >= 0 && pause == 0 ) {

    unsigned long currentMillis = millis();

    if(currentMillis - previousMillis > 1000) {
      // save the last time you blinked the LED
      previousMillis = currentMillis;   

      T -- ;

      Serial.println(T);
      Serial.println("");
     
    }
  }

 

  if ( T <= 0 && pause == 0 && horn == 0) { // if countdown reaches zero and horn is off
    horn = 1;   
    Serial.print("horn is   ");     
    Serial.println(horn); 
  }

  if ( horn == 1) {
    pause = 1;   

    unsigned long currenthornMillis = millis();
   
    if(currenthornMillis - previoushornMillis > 4000) {
       previoushornMillis = currenthornMillis;   
   
      horn = 0 ;
    }


    Serial.print("horn is   ");
    Serial.println(horn);

  }
1227  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 08, 2011, 08:26:17 am
Theres some things to go on now, this afternoon the card that wasn't working, started working again...  so it must be something working near the limits somewhere.

I am not using a shield, the chips are in sockets on a pcb, and I am using the buffer to convert the levels to 3v3.

I will try the associations formatter tonight, thanks
1228  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 07, 2011, 04:03:16 pm
Thanks,  so do you have any advice about which cards to use with the waveHC library,? or how I should format them perhaps ?
1229  Using Arduino / Storage / Re: should I upgrade to the SD library ? ( from the wavehc ) on: April 07, 2011, 08:19:47 am
 I don't need to record anything, the audio files I record with my PC,  I just need a .wav file reader and DA to get the audio out ( one of 9 files recorded )
1230  Using Arduino / Storage / should I upgrade to the SD library ? ( from the wavehc ) on: April 07, 2011, 06:45:12 am
I have been busy on several projects at once, and havn't checked on playing audio files from an SD card for a while.
I made my project that announces a message, controlled from another arduino chip that does the video side, using the wavehc library, which I copied and pasted , but never really understood.

I had one problem when trying to queue the messages ( done on the video chip ) but I got round that by removing the "if playing STOP"  part.

I did have hassles with some makes of SD card ( 2Gb) not working, but I used 4 of the same Kingston cards that seemed OK.

2 of these units have had the card fail, one which is a real failure, and the other I can still see the wav files on it, but it doesn't work.

I remember there was some talk about it being fussy with which cards are used.

Will the new SD library overcome this problem ?  I am using the 328 chips programmed from a Duemilanove board.

My existing code for the sound chip is below, would it be easy to update?
Code:
#include <ArduinoPins.h>
#include <FatReader.h>
#include <FatStructs.h>
#include <mcpDac.h>
#include <SdInfo.h>
#include <SdReader.h>
#include <WaveHC.h>
#include <Wavemainpage.h>
#include <WavePinDefs.h>
#include <WaveUtil.h>


#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f; // This holds the information for the file we're play

WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

#define DEBOUNCE 100  // button debouncer

// testing bcd conversion

int talkingPin = 19;  // high while audio playing to video chip to keep number on.
int aPin =18; //define pin numbers for bcd inputs from dequeued  HT12D
int bPin =17;
int cPin =15;
int dPin =16;
int vtPin = 14; // define pin numbers for valid transmission input from HT12D
int track ; // define audio track number
int bcda ; // define bcd digitalreads for BCD/dec conversion
int bcdb;
int bcdc;
int bcdd;
int valid ;  // to be set high if vt in

// this handy function will return the number of bytes currently free in RAM, great for debugging!
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);

}

void setup() {
  // set up serial port
  Serial.begin(9600);

  pinMode (aPin,INPUT);  //bcd inputs from HT12
  pinMode (bPin,INPUT);
  pinMode (cPin,INPUT);
  pinMode (dPin,INPUT);
  pinMode (vtPin,INPUT);  // valid trasnmission input
  pinMode (talkingPin,OUTPUT); // display enable to vga chip




  putstring_nl("WaveHC with 9 inputs");

  putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble!

  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);

  // pin13 LED
  pinMode(13, OUTPUT);

  // enable pull-up resistors on switch pins (analog inputs)
  // digitalWrite(14, HIGH);
  //digitalWrite(15, HIGH);
  // digitalWrite(16, HIGH);
  //digitalWrite(17, HIGH);
  // digitalWrite(18, HIGH);
  // digitalWrite(19, HIGH);

  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {   //play with 8 MHz spi (default faster!)
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);    // then 'halt' - do nothing!
  }

  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);

  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;     // we found one, lets bail
  }
  if (part == 5) {     // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck(); // Something went wrong, lets print out why
    while(1);    // then 'halt' - do nothing!
  }

  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?

  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);     // then 'halt' - do nothing!
  }

  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
}

void loop() {

  bcda = digitalRead ( aPin );  // read the state of the video micro dequeued "decode" data outputs  
  bcdb = digitalRead ( bPin );
  bcdc = digitalRead ( cPin );
  bcdd = digitalRead ( dPin );
  valid = digitalRead ( vtPin );  // check if signal received, set valid high

  if (bcda==1 && bcdb==0 && bcdc == 0 && bcdd == 0 ) { //bcd / dec decoding to give track number to be read
    track = 1;
  }  // convert bcd to dec
  if (bcda==0 && bcdb==1 && bcdc == 0 && bcdd == 0 ) {
    track = 2;
  }
  if (bcda==1 && bcdb==1 && bcdc == 0 && bcdd == 0 ) {
    track = 3;
  }
  if (bcda==0 && bcdb==0 && bcdc == 1 && bcdd == 0 ) {
    track = 4;
  }
  if (bcda==1 && bcdb==0 && bcdc == 1 && bcdd == 0 ) {
    track = 5;
  }
  if (bcda==0 && bcdb==1 && bcdc == 1 && bcdd == 0 ) {
    track = 6;
  }
  if (bcda==1 && bcdb==1 && bcdc == 1 && bcdd == 0 ) {
    track = 7;
  }
  if (bcda==0 && bcdb==0 && bcdc == 0 && bcdd == 1 ) {
    track = 8;
  }
  if (bcda==1 && bcdb==0 && bcdc == 0 && bcdd == 1 ) {
    track = 9;
  }  

  //Serial.print ( track);
  //Serial.print( bcda);
 // Serial.print ( bcdb);
 // Serial.print ( bcdc);
 // Serial.print( bcdd);
 // Serial.println ( valid);




  //putstring("."); // uncomment this to see if the loop isnt running
  if (track==1) {
    playcomplete("doornum1.wav");
  }
  else;
  if (track==2) {
    playcomplete("doornum2.wav");
  }
  else;
  if (track==3) {
    playcomplete("doornum3.wav");
  }
  else;
  if (track==4) {
    playcomplete("doornum4.wav");
  }
  else;
  if (track==5) {
    playcomplete("doornum5.wav");
  }
  else;
  if (track==6) {
    playcomplete("doornum6.wav");
  }
  else;
  if (track==7) {
    playcomplete("doornum7.wav");
  }
  else;
  if (track==8) {
    playcomplete("doornum8.wav");
  }
  else;
  if (track==9) {
    playcomplete("doornum9.wav");
  }

}
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
  // call our helper to find and play this name
  playfile(name);
  if (wave.isplaying) {//   set display enable high to vga chip
    digitalWrite(talkingPin, LOW);
  }
  else
  {  
    digitalWrite(talkingPin, HIGH);
  }
  while (wave.isplaying) {

  }
  // now its done playing
}

void playfile(char *name) {
  // see if the wave object is currently doing something
 //if (wave.isplaying) {// already playing something, so stop it!
 //  wave.stop(); // stop it
//}
  // look in the root directory and open the file
  if (!f.open(root, name)) {
    putstring("Couldn't open file ");
    Serial.print(name);
    return;
  }
  // OK read the file and turn it into a wave object
  if (!wave.create(f)) {
    putstring_nl("Not a valid WAV");
    return;
  }
  if (valid == 1){
    // ok time to play! start playback
    wave.play();

  }

}
Pages: 1 ... 80 81 [82] 83 84 ... 97