Show Posts
|
|
Pages: 1 [2] 3
|
|
16
|
Using Arduino / Project Guidance / Re: Direct WAV playback from SD: The Beginnings of a Library...
|
on: October 22, 2012, 01:52:58 am
|
Been a while, but work on this library has slowed to a crawl since it works fairly well at this point. Thought it would be worth an update: Features: PCM/WAV playback direct from SD card to attached speaker/amplifier Asynchronous Playback: Completely interrupt driven. Allows main loop to execute instructions while playback occurs. Playback uses a single timer (Timer 1) Supported formats: WAV files, 8-bit, 8 to 20khz Sample Rate (autodetection), mono Supported devices: Arduino Uno, Nano, Mega, etc. Files easily converted using iTunes or other software: iTunes Conversion: Click > Edit > Preferences > Import Settings Change the dropdown to WAV Encoder and Setting: Custom > 16.000kHz, 8-bit, Mono Right click any file in iTunes, and select "Create WAV Version" Copy file to SD card using computer Contains optional proof-of-concept add-on library for RF (Wireless) audio streaming using NRF24L01+ radio modules. See readme files for details. The current version can be found here: https://github.com/TMRh20/TMRpcm
|
|
|
|
|
18
|
Using Arduino / Project Guidance / Re: Help, Advice required
|
on: October 20, 2012, 04:18:43 pm
|
|
Yeah, same programming and connections for the Nano.
The main thing to look at is the chip. Uno and Nano can both use Atmega328 chips, so most things are completely interchangeable. Anything with a different chip will have some differences.
|
|
|
|
|
22
|
Using Arduino / Programming Questions / Re: Timer1 not firing
|
on: September 17, 2012, 06:31:28 pm
|
You just need to set COM1A0 and COM1B0 (TCCR1A register) to toggle on compare match, instead of 'set on compare match' : // controlling pins A=pin9. B=pin10 pinMode(10, OUTPUT); pinMode(9, OUTPUT); TCCR1A &= (unsigned char)~0b11110011; // zeros are reserved bits // TCCR1A |= 0b00; // WGM1[1,0] = 0b00, with WGM1[3,2]=01 for CTC; WGM1[3]=0 i/p TCCR1A |= 0b01010000; // COM1A[1,0]= TCCR1A[7.6]=10; COM1B[1,0]= TCCR1A[5,4]=10 ; clear on match // COM1A[1,0]= 1 ; inv-output // normal DIO
// TCCR1B[7,6] : input capture only, noise filter , edge detection. [5] reserved // NB only on 16b counter cf force comp on 8b
TCCR1B &= ~0b11111; TCCR1B |= 0b01101; // 01101: WGM2[3,2]=01 + "div 1024" -> 16kHz tick: OCR1A sets count ... OCR1A = 16; // set cycle length = 16kHz /16/2 = circa 1/2 kHz /* 338: 80 e1 ldi r24, 0x10 ; 16 33a: 90 e0 ldi r25, 0x00 ; 0 33c: 90 93 89 00 sts 0x0089, r25 340: 80 93 88 00 sts 0x0088, r24 */
TIMSK1 = 0b001; // in CTC, TOV1 triggers at MAX, ie OCR1A match
or how I find it easiest: pinMode(9,OUTPUT); pinMode(10,OUTPUT); TCCR1A = _BV(COM1A0) | _BV(COM1B0); TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10); OCR1A = 16; TIMSK1 = _BV(TOIE1);
|
|
|
|
|
23
|
Using Arduino / Programming Questions / Re: Read duty cycle of a pwm pin on Arduino Mega... ?!
|
on: September 12, 2012, 01:48:43 pm
|
|
I think it should be possible to get the information from the Arduino timer registers directly.
I'm not exactly sure about the details when using analog write, but if you generated your own PWM signal using timer1 for example, with ICR1 or OCRnA for duty cycle, you should be able to query the value of OCRnA or ICRn at any time to find the duty cycle.
My assumption is that analogwrite uses similar timing functions, so you should be able to grab the details from the Arduino registers. Of course, I could be completely wrong...
|
|
|
|
|
24
|
Using Arduino / Programming Questions / Re: Interrupt / Timer advice: Driving LED matrix while reading serial data
|
on: August 23, 2012, 06:48:21 pm
|
I ran into a similar problem recently, and overcame it using 'nested interrupts'. I don't know if this would be the best method for you, but here it is.. Basically, every time an interrupt is triggered, global interrupts are disabled while it completes, so other interrupts cannot run. The way I used around that, the main steps would be something like follows: (I posted some info on my blog too: http://tmrh20.blogspot.ca/2012_07_01_archive.html)a: COMPB interrupt triggered b: Disable COMPB interrupt from within the COMPB interrupt vector c: Enable 'Global Interrupts' d: Let COMPB do its thing, OVF will interrupt it when it needs to read Serial data e: Last step before COMPB completes is to re-enable itself It would require two interrupts the way I see it, but the code might be something like this:
ISR(TIMER1_COMPB_vect){ TIMSK1 &= ~_BV(OCIE1B); //Disable this interupt, otherwise seems like it will try to trigger again next cycle even if not complete sei(); //Now enable global interupts before this interrupt is finished // take as long as you like to do what you need here, this interrupt will keep trying to complete while other interrupts... interrupt it // while(x < yourMom){delay{10)}
TIMSK1 = ( _BV(OCIE1B) | _BV(TOIE1) ); //Re-enable this interrupt }
ISR(TIMER1_OVF_vect){
//check for serial data at a defined rate and have your way with it
}
Then you just have to work out the timing period and configuration on timer1 that works best with your code. You can also modify the duty cycle on your timer on the fly, which would affect the timing of COMPB and possibly OVF depending on configuration. Edit to add: I just remembered this partial implementation of Serial.bufferUntil() I found a while back: https://github.com/cmaglie/Arduino/commit/86ae0f9e8b16f319dbf306bbfa483409b94abe3c and http://code.google.com/p/arduino/issues/detail?id=535 this may be closer to what you are looking for
|
|
|
|
|
26
|
Using Arduino / Project Guidance / Re: NRF24L01 can not be initialized
|
on: August 19, 2012, 03:11:10 pm
|
|
Here is my pin configuration, it seems to differ slightly from what you posted initially, so thought it might be worth posting:
Mega: 48 (CE), 49 (CSN), 50 (MISO), 51 (MOSI), 52 (SCK)
RF24 radio(48,49);
Nano/Uno:
9 (CE), 10 (CSN), 11(MOSI), 12(MISO), 13(SCK)
RF24 radio(9,10);
|
|
|
|
|
27
|
Using Arduino / Project Guidance / Re: NRF24L01 receives Data from nowhere
|
on: August 18, 2012, 01:58:59 pm
|
|
Your screenshot seems to indicate the device is not getting detected properly. It should display the correct addressing on boot: RX_ADDR_P0-1 = 0xf0f0f0f0d2 0xf0f0f0f0e1
I can recreate your issue by reversing the following line:
RF24 radio(49,48);
My best bet is that you just have a couple wires reversed.
|
|
|
|
|
28
|
Using Arduino / Project Guidance / Re: Problems with code for piezo buzzer & push button
|
on: August 15, 2012, 01:35:37 pm
|
Something like the following may work for you: int c = 1915; //define note C as 1915Hz int d = 1700; int e = 1519;
int tune[] = {c,d,d,0,e,c,e,d}; //define the order of notes to play
for(int i = 0; i < sizeof(tune); i++){ // do as many times as the tune[] array is long tone(speakerPin, tune[i],200); // use the Tone() function to make sounds for 200milliseconds delay(200); // wait 200ms before next note }
edit: sorry, threw that together on my lunch-hour and was interrupted. this actually compiles now...
|
|
|
|
|
30
|
Using Arduino / Project Guidance / Re: Controlling an RC car via XBOX controller
|
on: August 12, 2012, 03:52:08 pm
|
Your question seems a bit confusing, but there are a few ways you can input data to the Arduino without using the Serial Monitor: 1. Set up your own External buttons to use as controls: http://arduino.cc/it/Tutorial/Button 2. As previously suggested, use Processing to capture keyboard events and send them or other data over a serial connection like so: import processing.serial.*; //use the Serial library Serial myPort; // Create object from Serial class
void setup() { size(200, 200); //set window size to 200 by 200 pixels String portName = Serial.list()[0]; //list serial ports, save the first one as portName myPort = new Serial(this, portName, 9600); //initialize the serial port object }
void draw() { //this is like the 'loop' section of code on Arduino background(255); // set background color if(keyPressed) { //if a key is pressed, do the following if ( key == 'f' || key == 'F' ){ myPort.write(key); println(key); delay(200); } // if the key is f or F, write it to the serial port, then wait 200 miliseconds } }
3. Embed an Arduino Nano or comparablly small device in the Xbox controller to monitor joystick/button actions and send the data to the device directly, or via an RF (Radio) module. example: http://tmrh20.blogspot.ca/2012_03_01_archive.html Update: Added comments to code per request by OP
|
|
|
|
|