|
992
|
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..
|
|
|
|
|
995
|
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 ?
|
|
|
|
|
996
|
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....
|
|
|
|
|
997
|
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 :-) ) #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
|
|
|
|
|
998
|
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... 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);
}
|
|
|
|
|
999
|
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
|
|
|
|
|
1002
|
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? #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();
}
}
|
|
|
|
|