Go Down

Topic: Mega 2560 / MP3 Player Shield / Shift Register / MPU-6050 acc/gyro! (Read 1 time) previous topic - next topic

David Cool

Hi all,

I figured I'd post this in audio since the main problem is integrating the MP3 shield.

I started by working on the instructables code here: http://www.instructables.com/id/Use-an-Accelerometer-and-Gyroscope-with-Arduino/

I'm using the Single Pixel sketch near the bottom of the page as a base. I'm using a shift register with a 4x4 led array. It also sends midi out to the computer to make sounds. This works fine and dandy on the UNO.

Since I didn't have the accelerometer and gyro board she uses in the instructable, I picked up an MPU-6050. I used the I2C dev library here: http://www.i2cdevlib.com/devices/mpu6050#source

The combination of the two works well on an UNO. But I want to generate the MIDI via the arduino and not on the computer so the device can be liberated!

I picked up a sparkfun MP3 Player Shield: https://www.sparkfun.com/products/10628

I found a sketch that enable the shield in "real time midi mode". On it's own I can get it to play midi.

The problem is integrating the midi shield code into my existing code. I switched over to a MEGA 2560 so I had more ports to play with, the MP3 shield takes many. I can get the leds working on the shift register, the I2C working for the gyro/acc and real time midi mode working on the shield, but when I combine them... No go.

I'm new to using ports and interrupts. I'm fairly sure I'm having some kind of timing or interrupt problem but I'm not sure.

My code is here: https://gist.github.com/4439033

If anyone has ideas on how to make all this jive, I'd love to hear it!

Thanks!

Krodal

I hope everything I write here is correct. I'm not 100% sure.

The MPU-6050 code by Jeff Rowberg used INT0. This is fixed in his code I think.
That is digital pin 2 (D2).
This is the same for an Arduino Uno and an Arduino Mega 2560.
http://arduino.cc/en/Main/arduinoBoardMega2560
The I2C is on other pins, but you have that part working.

The MP3 shield used also D2 for MP3-DREQ.

I think the others pins are no problem, but only D2.
Since D3 and D4 are in use with the MP3 shield, you have to use pin 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), or 21 (interrupt 2) of the Arduino Mega 2560.

So the software for one of the shields much be changed for the new pin.

For the mp3 sketch, I see this:
Code: [Select]

SoftwareSerial midiSerial(2,3);
...
#define VS_DREQ   2


The VS_DREQ could be set to a different pin. But you also must change the SoftwareSerial call, even the RX for pin 2 is not used.

In your sketch I see that TIMER1 is used. I don't know if that is already in use for another library.

Perhaps you should place the code in three different files (use the drop-down icon on the right of the tab bar in the Arduino IDE).

David Cool

Thanks for the ideas Krodal. I tried some things but still no luck.

I decided to fall back a level of code and eliminate the MP3 shield and focus on using the I2C MPU-6050 and the shift register with the MEGA. Here is the code I'm using:

https://gist.github.com/4444564

It worked fine for the first two times and then just stopped working. So there is definitely some conflict with the I2C dev library and my current code. You can see I eliminated the software serial and just use Serial1 on the MEGA. The weird thing is if I let the circuit sit powered up, sometimes after like 30min or so it will spontaneously start working... So I think there is some conflict that sticks this thing in a loop or fights for port access or something. I wrote the Jeff Rowberg to get his input, hopefully he'll be able to point me to something that helps.

If there are anymore ideas out there, please let me know!

Thanks.

Go Up