Go Down

Topic: Problem combining two programs (Read 1 time) previous topic - next topic


Hi all.
first post here so please go easy on me :)
I'm new to Arduinos, although I work in I.T. (networking) so hopefully I'll be able to pick it up as I go along.

I tried including the code in my post, but it said I'd exceeded my character count, so I've put the code in text files in my dropbox folder.

I'm building a full size Aluminium R2D2, and I'm going to be using an Arduino Uno to control the led's for the charge bay indicator (the bit in the Empire Strikes back when Luke plugs a lead into R2 to recharge him) and also to play the sounds.
To make the sounds, I'm using a Vmusic2 module. Currently, I just have a load of samples on the Vmusic2 module.
The led's are driven by a board usin a MAX72XX chip. this chip also monitors the voltage of the battery, so it will light up a green/amber/red LED to represent the battery charge status.

I got some code off the R2 forum, which seems to work fine (I haven't got the MAX72XX board made up yet) in that it gives no errors when compiled, uploads ok, and flashes the on board LED.
The code I've used for that, is here.


The code for the Vmusic2 module which I found on a search through this forum a while back is here.


I changed the code slightly to make the Vmusic2 module play all the samples repeatedly and randomly.

My ultimate aim is that I want the LED board to work, and also the Vmusic2 module to play random samples, ideally at a random interval between 5 and 10 seconds apart, but I don't know whether that's possible as it appears a delay of 5000ms would also delay the code update that the Arduino sends to the LED board.

Anyway, for the time being I'd be happy to just get the two working together with no delay. I can always add empty space to the MP3's I'm using if need be.

So, I've tried to combine the two sketches together to get the code that will do both, but it doesn't seem to be working.
It compiles ok, and the LED side of things work.. but it doesn't seem to be sending the command to the Vmusic2 module.

all I actually need to send to the Vmusic2 module is the VRR command to tell it to play all the samples randomly, and in a loop. I think the VRR command does that. once it executes, that should be it.
But, I just can't get that to happen.
I've tried putting the Vmusic2 sketch code in the void setup and void loop parts of the code, but it still doesn't work.
The Vmusic2 sketch on it's own works, so I know all the pinouts are OK.. Just doesn't work in a combined code form.

This is the combined code I'm currently using.


It validates ok, and uploads ok. Just doesn't play the sounds.
The Vmusic module comes on power wise, just doesn't play.
The pinouts I'm using are
Arduino      Vmusic
5v              5v
GND           GND
GND           CTS
TX>1          RX

As I say, I'm new to Arduinos so I'm not where I'm going wrong really.
It appears the MAX chip is 19200 and the Vmusic2 is 9600, so I've tried to combine the code including changing from 19200 to 9600 and vice versa. that may be wrong though.
The serial monitor does show the correct output for the LED code though, showing which LED it will light based on the battery voltage.
It really does just appear to be the Vmsusic part that doesn't want to happen. If I can just send that VRR command to it, I'll be happy. :)

Sorry this is a long one, but I've tried to include as much as I can.



You have connected your Vmusic2 module to the serial interface (pins 0 and 1), so you cannot use the serial interface (on the USB) for debugging anymore. You either change your Vmusic2 to SoftwareSerial (on pins 2 and 3 for example) or you do your debugging there (then you need a USB2Serial on these pins I guess). You set the baud rate for the serial interface to 19200, your Vmusic2 needs 9600 (according to the manual). You cannot switch between the two speeds (one for the debugging output, the other for the commands to Vmusic2). All your debugging output will confuse the Vmusic2 module as it sees the traffic too but cannot interpret it correctly. The serial line cannot be shared between the two devices (USB debug and Vmusic2).

In your code:

Code: [Select]
LedControl lc=LedControl(13,12,11,1);

in the example code it reads

Code: [Select]
LedControl lc1=LedControl(12,11,10,1);

Have you really connected your LED chip to pin 11, 12 and 13?


Thankyou for your reply.

I haven't actually connected the LED chip yet, as I haven't received the boards in order to build it yet.
Do you know which pins I should be connecting to? I'm afraid I'm very new to this.

With regards the speed and the debugging, I'm afraid this is where my lack of understanding of coding comes in.
So, I need to turn off debugging at 19200 to be able to communicate with the Vmusic2 commands correctly? If I set the whole program to 9600 will that talk to the LED chip ok still?


The LED chip is connected with some sort SPI (another serial interface working with a clock line, two data lines and a chip select line). So it does not use the UART (Serial object) interface (and it has no fixed baudrate as it's clocked by a separate line/pin).

If you remove all Serial.print()/.println() statements that are for debugging only, so everything except these two lines:

Code: [Select]
  Serial.print("VRR"); //#play this file 4.wav

and change the Serial.begin(19200) to Serial.begin(9600) in the setup() routine and remove all other calls to Serial.begin().


Hey, thankyou. I'll try that now :)


That works!! although I haven't tried my LED chip yet.
On an Arduino Uno, do you know which pins I should use for the LED chip controller.

I'll now work out the code to make each sample play randomly after random delay. I think I can find examples of that. :)


I'd use the pins of the example code (10, 11 and 12) if you're not forced to choose other. This way you don't have to change examples and use all the tutorial stuff with your installation too.

If you're gonna change your code anyway take a look at the BlinkWithoutDelay example and compare it with the standard blink example. You will get much more flexibility with your project if you restructure your code so you don't need delay() anymore.


Go Up