Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: thsamog on Jan 28, 2016, 12:14 pm

Title: Beginner needs help with music organ/spectrum.
Post by: thsamog on Jan 28, 2016, 12:14 pm
Hello, me and my girlfriend are trying to build some awesome lightning into car and our house. In ebay there are alot of RGB music controllers but they don't look like they are doing create job. Im trying to get some tips and tricks or maybe some code parts how we should get started.

Project idea ?

Pretty customosiable with profiles
Atleast 2 profiles for start (Still color & Music)
Working with bluetooth (Android we maybe develope app for it later first some console to send codes)
3 RGB outputs atleast but also expendable easyly. (Low hz, Medium hz and high hz).


We allready have arduino starter kit (Actually 2 of these) what else do we need ? Google is not my friend in this project.

Amy help would be karma+ ! Thanks !


EDIT: Here are some useful stuff that might help this project:
https://www.sparkfun.com/products/10468 - Graphic Equalizer Display Filter
https://www.sparkfun.com/products/13116 - Spectrum Shield (EXPENSIVE)
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Jan 28, 2016, 06:31 pm
I would use the WS2812b LED strips marketed by AdaFruit as Neopixels. They are a game changer when it comes to LED displays.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Jan 28, 2016, 08:32 pm
Thanks but we'd like to use analog RGB strip. We have allready ordered them. Reason is that they are cheaper. We both are just very noob with Arduino boards.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: CrossRoads on Jan 28, 2016, 09:21 pm
RGB strip as in not individually controllable LEDs, all LEDs in the strip are the same color based on PWM control of the R, G, and B pins, with 12V applied to the common pin?
How many groups of 3 LED segments are you planning to power? Each group needs about 20mA/color.
A N-channel MOSFET like AOI-510 or AOI-514 per pin may be all you need with a 180 ohm resistor between the Arduino PWM pin (3,5,6,9,10,or 11) and the MOSFET gate, and a 10K resistor from the gate to Gnd to hold the MOSFET off when the Arduino resets. Connect the power supply Gnd to the Arduino Gnd so there is a common reference point.
http://www.digikey.com/product-search/en?keywords=aoi514 (http://www.digikey.com/product-search/en?keywords=aoi514)
Here's a video of 8 fading some single color strips up & down on a board I offer.
http://youtu.be/hAVf1D1L-7c (http://youtu.be/hAVf1D1L-7c)
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Jan 28, 2016, 10:01 pm
Thanks but we'd like to use analog RGB strip. We have allready ordered them. Reason is that they are cheaper.
That dosn't sit very well with your previous statement.
Quote
Im trying to get some tips and tricks or maybe some code parts how we should get started.
They are cheaper because, as CrossRoads said, the whole strip has to be the same colour. This limits the display you can get.

Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Jan 29, 2016, 09:59 am
RGB strip as in not individually controllable LEDs, all LEDs in the strip are the same color based on PWM control of the R, G, and B pins, with 12V applied to the common pin?
How many groups of 3 LED segments are you planning to power? Each group needs about 20mA/color.
A N-channel MOSFET like AOI-510 or AOI-514 per pin may be all you need with a 180 ohm resistor between the Arduino PWM pin (3,5,6,9,10,or 11) and the MOSFET gate, and a 10K resistor from the gate to Gnd to hold the MOSFET off when the Arduino resets. Connect the power supply Gnd to the Arduino Gnd so there is a common reference point.
http://www.digikey.com/product-search/en?keywords=aoi514 (http://www.digikey.com/product-search/en?keywords=aoi514)
Here's a video of 8 fading some single color strips up & down on a board I offer.
http://youtu.be/hAVf1D1L-7c (http://youtu.be/hAVf1D1L-7c)
Yes i know that. And i'd like to have it thatway. For example one strip is 30hz - 60hz . Second one would be
 80hz - 160hz and so on. And if possible maybe like i have 6 strips 3 for left channel and 3 for right channel.


That dosn't sit very well with your previous statement.
They are cheaper because, as CrossRoads said, the whole strip has to be the same colour. This limits the display you can get.
Id like to get them just flashing to the music. And yes i know that limit maybe in future we make second arduino to something with digital leds.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Jan 29, 2016, 10:43 am
What you need to get is a MSGEQ7 chip. This splits audio into 7 bands. You can then use this data to turn the LEDs on and off.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Jan 31, 2016, 12:22 am
I found this from google http://www.instructables.com/id/DIY-Arduino-LED-Color-Organ-20/

It seems best tutorial out there... Im sorry if im asking too much help but this resistors and transistors are pretty new for me. I have always followed only tutorials. I think i can handle the code myself (web developer), but id like to get some help with me.

So would this be stable and working project.

How would i implemet this for 3 or 6 RGB strips ?
1. L Low Hz
2. R Low Hz
3. L Medium Hz
4. R Medium Hz
5. L High Hz
6. R High Hz

Or
1. L/R Low Hz
2. L/R Medium Hz
3. L/R High Hz

I cheked up MSGEQ7 datacheet and though about that
63hz-160hz would be like one strip.

If i understand right then something like when
63hz signal is coming it would be example red then for if both are coming it would be blue and when 160hz singnal is coming it would be green. And maybe it transfers somehow smooth.

and then 400-2500 would be second strip
and last strip would be 6250 and 16000

Also would i need two MSGEQ7 chips if i would like to make Left and right channels ?
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Jan 31, 2016, 06:43 am
First off most Instructables are crap and contain errors. My advice is never to try and learn anything from them. We seen to be an Instructables support unit at times and it is very annoying.

Yes you need two chips if you have two audio channels.

I would advise you to just start with one first and get the feel of it.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Helmuth on Jan 31, 2016, 10:52 am
Quote
Yes you need two chips if you have two audio channels.

I would advise you to just start with one first and get the feel of it.
I agree, except he goes for the spectrum shield (https://www.sparkfun.com/products/13116) which has 2 MSGEQ7s already.

I´m playing with it at the moment:

OLED audio visualisation (https://www.youtube.com/watch?v=hvbIZPFd3bk)

LED audio visualisation (https://www.youtube.com/watch?v=il5wc79k8LA)


Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Jan 31, 2016, 05:17 pm
First off most Instructables are crap and contain errors. My advice is never to try and learn anything from them. We seen to be an Instructables support unit at times and it is very annoying.

Yes you need two chips if you have two audio channels.

I would advise you to just start with one first and get the feel of it.
Okei, i understand its just i dont understand almost anything about resistors and etc.. I order the 2 MSGEQ7's tomorrow and start playing with just one.

I agree, except he goes for the spectrum shield (https://www.sparkfun.com/products/13116) which has 2 MSGEQ7s already.

I´m playing with it at the moment:

OLED audio visualisation (https://www.youtube.com/watch?v=hvbIZPFd3bk)

LED audio visualisation (https://www.youtube.com/watch?v=il5wc79k8LA)


Wow nice. I think i have to order also digital led stripe soon ! :)
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Helmuth on Jan 31, 2016, 05:28 pm
Well, the MSGEQ7 alone will not work. Please read the datasheet (https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf) first. Page 4: Typical Application.

Or have a look for MSGEQ7 breakout boards (http://www.ebay.de/itm/MSGEQ7-breakout-board-7-band-graphic-equalizer-for-audio-for-Arduino-RPi-PIC-/301210655107).
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 01, 2016, 10:03 am
So for my part list i will need atleast.

2x MSGEQ7
18x FQB30N06L MOSFETS
2x 33pF Capacitor
2x 200k Ohm Resistor
2x Audio Jack 3.5mm
6x RGB Led Strips (Allready have)
1x Arduino (Allready have)

Later - 1x ATmega328 to get this more permanent.


This thing would get power from car battery i hope its okey thatway?

Do i need anything else ?


EDIT: No now i did something wrong.  Is this project possible with arduino uno ? If i'd like to have 6 channels, every channels has 3 colors (RGB) it does 18 inputs.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 01, 2016, 10:20 am
I don't see where all 18 FETs come into it.

You are best to draw the diagram of how you are going to wire things up and make your parts list from that. Please don't use Fritzing.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 01, 2016, 06:23 pm
So i have learnde whole day circuits and arduino. I finished this

https://123d.circuits.io/circuits/1542618-car-rgb-color-organ-project

Is this okey ? Improvements ?

Now im stuck again. It seems that i need 18 PWM Pins. Uno has only 6. So i found shift pwm https://github.com/elcojacobs/ShiftPWM. Also i found a hack to use ANALOG ports as digital. So in total i would use all analog and all digital ports. I also need TX & RX port becose we are trying to make some IR remote or bluetooth remote(android).

Other thing i found was that there is PWM Drivers like this https://www.adafruit.com/products/2928
Maybe i should use something like that ?

I think i need 18 FETS becose led strips needs 12v. I'd like to get 6 strips and every strip has 3 colors. So 6x3 is 18.

All tips and improvements are welcome. I would just like te keep price down.

EDIT: Also what would be best way to make car battery stabilizer. And is it okey to run whole system with 12v ? My calculations show that i need 2.6A for leds. So i'm thinking off 12v 3A regulator. Maybe with fuse.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 01, 2016, 11:12 pm
Quote
Is this okey ?
No.
There is nothing to limit the current in the LEDs and what are these switches?

Quote
I think i need 18 FETS becose led strips needs 12v.
Why is the number of LEDs dependent on the supply voltage?

Quote
I'd like to get 6 strips and every strip has 3 colors. So 6x3 is 18.
You only need a separate PWM output for every different control you need. You only have 7 channels for each audio channel, therefore you can not possibly need more than 14 PWM channels. If you want to drive two strips with the same signal then simply connect the same PWM signal to each FET or transistor driving that chip.

Quote
Also what would be best way to make car battery stabilizer.
Is this a battery in a car that is working? If so this is very tricky. Normally the battery would be being charged at 13.6V but it can also surge up to 15V with higher spikes. When the car is not working you might get anywhere between 12.5 and 11V depending on the state of the battery. So getting 12V is hard because a regulator needs a few volts more on the input than it's output is going to be.

Quote
And is it okey to run whole system with 12v
Yes it is but take note of the above.

Quote
Maybe with fuse.
A fuse will normally blow way after any electronics it is trying to protect has meted.

Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 02, 2016, 11:24 am
First of all you are AWSEOME for helping me so much !

No.
There is nothing to limit the current in the LEDs and what are these switches?
Yes i know that part is not yet done. I havent figured out how would i do it.
I was thinking about that you can switch every led off and on. Actually i should make it inside code somehow.

Why is the number of LEDs dependent on the supply voltage?
Sorry i didnt understand the question. English is not my main language.

You only need a separate PWM output for every different control you need. You only have 7 channels for each audio channel, therefore you can not possibly need more than 14 PWM channels. If you want to drive two strips with the same signal then simply connect the same PWM signal to each FET or transistor driving that chip.
I love your brains. I have to think more out of box. Clever !

Is this a battery in a car that is working?
Yes it is.

So now i have to figure out stabilizer and how i get leds connected.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 02, 2016, 11:36 am
Quote
Sorry i didnt understand the question. English is not my main language.
You said:-
Quote
I think i need 18 FETS becose led strips needs 12v.
[English lesson]
That says because you have 12V you need 18 FETs. That is saying there is a relationship between the voltage and the number of LEDs. Clearly there is not.
[/English lesson]

Quote
I was thinking about that you can switch every led off and on.
I thought we had established that you were using strips, you can not control individual LEDs when they are on a 12V strip. The strips wire up the LEDs in groups of three in series and one current limiting resistor. That is how they work off 12V. You need to switch the ground pin for each colour to turn that colour on. This is best done with a logic level FET. The FET is switched by putting the PWM output on its gate pin. See:-
https://learn.adafruit.com/rgb-led-strips/usage (https://learn.adafruit.com/rgb-led-strips/usage)

Quote
So now i have to figure out stabilizer
It would be much easier if you didn't use 12V, as it is you need to regulate arround a voltage that could be above or below the voltage you want. The only way to do that is to use a buck/boost regulator circuit, at that power these tend to be expensive and they are not circuits you can make yourself because they need proper layout in order to be stable.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 02, 2016, 01:00 pm
It would be much easier if you didn't use 12V, as it is you need to regulate arround a voltage that could be above or below the voltage you want. The only way to do that is to use a buck/boost regulator circuit, at that power these tend to be expensive and they are not circuits you can make yourself because they need proper layout in order to be stable.
Is there better way to implement this system into car ? I was thinking that would the currency be stable if car is not moving. It's not even legal to make you car a discoball. Or is there any simple way to make it more stable.

Also i updated my circuit https://123d.circuits.io/circuits/1542618-car-rgb-color-organ-project

I used your tip for 14 FET's, do you have idea how i could implement these missing 4 Red inputs of LED strips?
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 02, 2016, 02:42 pm
Quote
I used your tip for 14 FET's, do you have idea how i could implement these missing 4 Red inputs of LED strips?
Missing 4? You have still not got it. There are a missing 8 PWM signals.

There are only 6 pins on the Arduino capable of PWM,  to get more you have to use this library:-
http://forum.arduino.cc/index.php?topic=19451.0 (http://forum.arduino.cc/index.php?topic=19451.0)

Quote
Also i updated my circuit https://123d.circuits.io/circuits/1542618-car-rgb-color-organ-project
Those LED strips are wrong. You have drawn then as common cathode RGB LEDs, where as in fact your strips should be common anode strips. They should also be strips not individual LEDs. I know what you are going to say, that the program doesn't have that part, so you will have to make your own part and if that is not permitted abandon that package and draw with pen and paper. That is the MAJOR trouble with schematic software package, if you do not use the correct symbol then people can't follow what you have done.

You have to decide what strips to connect to what drivers, you only have 14 different signals of data so you can not drive each strip you have independently because there is no data to drive it with, so....
You have to decide how to distribute the 14 data channels over your 18 strips / colours. That means 4 of these have to be common with one or more of the 14 you already used. You have to make that decision as to which.

Each FET needs a 150R to 330R resistor in series between the gate and the Arduino PWM pin, and also a 10K from the gate to ground. Let's get the design right first before you worry about powering it in a moving car.   
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 02, 2016, 04:29 pm
Missing 4? You have still not got it. There are a missing 8 PWM signals.

There are only 6 pins on the Arduino capable of PWM,  to get more you have to use this library:-
http://forum.arduino.cc/index.php?topic=19451.0 (http://forum.arduino.cc/index.php?topic=19451.0)
Yes i allready found that. Also i found this one https://github.com/elcojacobs/ShiftPWM Whats the difference between these two ?

Each FET needs a 150R to 330R resistor in series between the gate and the Arduino PWM pin, and also a 10K from the gate to ground. Let's get the design right first before you worry about powering it in a moving car.   
https://123d.circuits.io/circuits/1547536-car-rgb-color-organ-project/ Is it looking better now ?

How can i thank you with all this help ? I just rep+ every post ! :)

Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 02, 2016, 04:52 pm
Quote
Also i found this one https://github.com/elcojacobs/ShiftPWM Whats the difference between these two ?
That is for using shift registers, you need to have a chain of shift registers and this will generate PWM on the outputs. This is way more CPU intensive and requires more hardware in your case 3 shift registers.

Quote
Is it looking better now
No you have the resistors wrong. The 10K should go from the gate to ground. These should not be two resistors in the gate, there should be only one, whose value is between 150R to 330R. That R means ohms not K ohms, the 4 red LEDs are still not connected up.

You have all the gate resistors going to the same place, each one should be connected to a separate PWM pin.


Schematic is starting to look a bit messy, try and separate the wires more so they are easier to trace and not over one another.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 03, 2016, 06:38 pm
Schematic is starting to look a bit messy, try and separate the wires more so they are easier to trace and not over one another.
Yes i noticed. This webpage is annoying with wires. But im not at home and i dont have right equipment to draw these things. But i did my best is it looking better now ?

If there is a change that you have account tho this website i can give you permission to edit.

But here: https://123d.circuits.io/circuits/1547536-car-rgb-color-organ-project

It seems that this site is not very good with larger project's. It starts lagging like hell.

EDIT: These wires went again on tom of each other.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 04, 2016, 12:34 pm
Quote
But i did my best is it looking better now ?
Yes you seem to have got the FETs and resistors right now.

Quote
It seems that this site is not very good with larger project's.
You mean "projects" no apostrophe required for a plural ( sorry my wife is an English teacher )

I would agree, I have only come across it once before and I find it very difficult to navigate on my Mac. It seems that the touch pad gestures are all wrong compared to how all other applications work.

I just use a generic 2D drawing package ad group component symbols so I don't have to redraw them from scratch each time. Using a ground symbol and a supply symbol will make the circuit look a lot neater. Also a good tip is to have the ground down and the power up on the page, that improves readability.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 07, 2016, 09:15 pm
Thanks for you help all ! I have ordered all components now. I start the code but i hade one more idea.

Is it somehow possible to calculate two outputs avarge into one without arduino.

MSGEQ7 gives me 7 outputs but if i would get 9 out by calculating
1 and 2 output avarge and 6 and 7 output.


Like he does: https://www.youtube.com/watch?v=C-h5eGZbqNs&feature=youtu.be
http://www.embedded.com/electronics-blogs/max-unleashed-and-unfettered/4439541/BADASS-Display-Coding-Competition
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 07, 2016, 09:25 pm
Quote
without arduino.
What do you mean by this?
Yes you can do that with the arduino but why without.
You could also interpolate, that is put in an extra channel which is the average between two adjacent channels.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 08, 2016, 12:53 pm
My girlfriends teacher suggested us to switch to ULN2003 so we did.

It looks now like this:
https://123d.circuits.io/circuits/1547536-car-rgb-color-organ-project
(http://i.imgur.com/wdXUllo.png)

What do you mean by this?
Yes you can do that with the arduino but why without.
You could also interpolate, that is put in an extra channel which is the average between two adjacent channels.
Now i didn't understand. But i try to explain my self better.
So as you can from picture i'f like to get O6 & O7 and calculate their avarge into LED 1 R.
Also for O1 & O2 into Led 3 R. And the same with other chip.
I can't use arduino becose no ports left.
(http://i.imgur.com/7cPzs1C.png)

Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 08, 2016, 02:03 pm
Quote
My girlfriends teacher suggested us to switch to ULN2003 so we did.
Your girlfriends teacher is an idiot and does not know much about electronics. That chip can only switch about 600mA at any one time.
See:-
http://www.thebox.myzen.co.uk/Tutorial/Power.html (http://www.thebox.myzen.co.uk/Tutorial/Power.html)

and

http://www.thebox.myzen.co.uk/Tutorial/Power_Examples.html (http://www.thebox.myzen.co.uk/Tutorial/Power_Examples.html)
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Feb 09, 2016, 12:41 pm
That chip can only switch about 600mA at any one time.
So its 600mA for one output or in total ? We are using two chips so its 1.4A for one chip. We have only 4m of leds. This is going into car so not very much. The actuall reason we switched was that school doesent had any mofset if im not wrong.

Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on Feb 09, 2016, 12:55 pm
Quote
So its 600mA for one output or in total ?
In total for one chip.
The limit for one output is 500mA but no more than a total of 600mA being sunk at any time.
Did you not read those links? That is what they said.

Quote
We are using two chips so its 1.4A for one chip.
So that is way too much.

Quote
The actuall reason we switched was that school doesent had any mofset
Well you should have said that before, it is well known that the laws of physics can be suspended by a school if only they fill in form "Physics Laws exception form number GzeroD"
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on May 13, 2016, 01:01 pm
Hello, it's been a long time.

Now we have all components and time to start building this thing.

Except we got 220K ohm resistors when we need 200K ohm resistors.
https://123d.circuits.io/circuits/1547536-car-rgb-color-organ-project#schematic

R1L & R1R

So my question is can we still use 220K ohm resistors ? Or do we NEED 200K ohm resistors ?

EDIT or maybe its better to use 270K ohm ?
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on May 13, 2016, 09:20 pm
Yes you can use 220K. It might just shift the peak of the filter frequencies by a few tens of Hz but it will not be noticeable.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on May 13, 2016, 11:04 pm
Thanks for your answer, we will get the right ones just to make sure but we will start building with 220K.

Except now we have two more problems.

1. I think one of my MSGEQ7 is broken. I switched them around and everything but still one chip shows only 0 0 0 0 0 0 0.

2. The numbers i get don't make any sense for me. Whole row is same (almost) and its like volume. When i turn music louder the numbers get bigger.

My serial output: http://laravel.io/bin/bEMnX

My code that i use is this: http://laravel.io/bin/Xyqvj

Credit goes to: http://www.eetimes.com/author.asp?doc_id=1323030&page_number=3
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on May 13, 2016, 11:24 pm
Quote
I switched them around and everything but still one chip shows only 0 0 0 0 0 0 0.
Does the 0s follow the chip or does it stay on the same side.
It is likely you have wired things wrong.

Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on May 14, 2016, 01:00 am
No, if i swap the chips the 0's change side. Or if i change A4 & A5 but that one makes sense.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: Grumpy_Mike on May 14, 2016, 09:46 am
Ok so that points to one faulty chip. It could be the other is faulty as well or as I said is not wired correctly. This includes things like the bread board not making connections correctly.
The software too is a bit simplistic on the reading in side. Look at the data sheet and you will see that the software you are using doesn't make the waveform that the data sheet says it needs in order to get the samples out correctly.
You also might have swapped the reset and strobe lines lines.
Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Dec 10, 2016, 09:15 pm
It has been a long time but the project is not dead.

We have been tweaked it somehow and allready included an android app.
But now we have faced couple problems.

1. First we got a idea to start uploading code from bluetooth.

   We couldnt get it anyhow to work. Windows connects to it and gets right COM's.
   We got a lot of different errors but we got ' Not in sync: resp=0x** ' the most.
   Now we are using a arduino board to upload a data.

2. Then we started to move on and we tryed to get the code working with usb serial.
   Our problem is that we cant get and save data variable from serial as an string.
   I would use this string to run different profiles. Also we would like to adjust brightness.

   I have tryed different compinations from google.
   
   I have still however figuret out what is right way to control data variable and brightness       variable   differently.

Also i would like to do some saving there and here but im not sure how this would work out.

Here is code: https://github.com/alanaasmaa/RGB-Color-Organ

Title: Re: Beginner needs help with music organ/spectrum.
Post by: thsamog on Dec 12, 2016, 03:57 pm
I got the Serial to work. Now i can get strings, but now when i include this
Quote
if (data == "OFF")
  {
    for (int i = 0; i < 7; i++)
    {
    Palatis::SoftPWM.set(pwmLEDsLeft, 1);
    Palatis::SoftPWM.set(pwmLEDsRight, 1);
    }
  }
my code crashes. And arduino does not do anything it works like one sec and then stops working.

Full code is here:
Quote
#define SOFTPWM_OUTPUT_DELAY
#include <SoftPWM.h>                                  // Include Palatis SoftPWM libary github.com/Palatis/arduino-softpwm
SOFTPWM_DEFINE_CHANNEL(3, DDRD, PORTD, PORTD3);       // Arduino pin 3
SOFTPWM_DEFINE_CHANNEL(5, DDRD, PORTD, PORTD5);       // Arduino pin 5
SOFTPWM_DEFINE_CHANNEL(6, DDRD, PORTD, PORTD6);       // Arduino pin 6
SOFTPWM_DEFINE_CHANNEL(7, DDRD, PORTD, PORTD7);       // Arduino pin 7
SOFTPWM_DEFINE_CHANNEL(8, DDRB, PORTB, PORTB0);       // Arduino pin 8
SOFTPWM_DEFINE_CHANNEL(9, DDRB, PORTB, PORTB1);       // Arduino pin 9
SOFTPWM_DEFINE_CHANNEL(10, DDRB, PORTB, PORTB2);      // Arduino pin 10
SOFTPWM_DEFINE_CHANNEL(11, DDRB, PORTB, PORTB3);      // Arduino pin 11
SOFTPWM_DEFINE_CHANNEL(12, DDRB, PORTB, PORTB4);      // Arduino pin 12
SOFTPWM_DEFINE_CHANNEL(13, DDRB, PORTB, PORTB5);      // Arduino pin 13
SOFTPWM_DEFINE_CHANNEL(14, DDRC, PORTC, PORTC0);      // Arduino pin A0
SOFTPWM_DEFINE_CHANNEL(15, DDRC, PORTC, PORTC1);      // Arduino pin A1
SOFTPWM_DEFINE_CHANNEL(16, DDRC, PORTC, PORTC2);      // Arduino pin A2
SOFTPWM_DEFINE_CHANNEL(17, DDRC, PORTC, PORTC3);      // Arduino pin A3
SOFTPWM_DEFINE_OBJECT_WITH_PWM_LEVELS(14, 102);       // Define how many pwm channels project uses and how many steps it has
// MSGEQ7 bands = 63Hz, 160Hz, 400Hz, 1,000Hz, 2,500Hz, 6,250Hz, 16,000Hz
static volatile uint8_t v = 0;
int ctrlReset = 2;                                    // Digital pin 2 = signal to reset MSGEQ7s
int ctrlStrobe = 4;                                   // Digital pin 4 = signal to strobe (read data from) MSGEQ7s
int channelLeft = A5;                                 // Analog pin A5 = spectrum data from left channel
int channelRight = A4;                                // Analog pin A4 = spectrum data from right channel
int spectrumLeft[7];                                  // Array to store 7 bands of spectrum data from left channel
int spectrumRight[7];                                 // Array to store 7 bands of spectrum data from right channel
int pwmLEDsLeft[] = {3, 5, 6, 7, 8, 9, 10};           // Array to store data where leds are connected.
int pwmLEDsRight[] = {11, 12, 13, 14, 15, 16, 17};    // Array to store data where leds are connected.
int brightness = 50;
String data = "ON";                                          // Mode ON = Music, 2 = Still, Anything else = off
String bluetooth;

void setup()
{
  Serial.begin(9600);
  pinMode(ctrlReset, OUTPUT);                         // Define reset as output
  pinMode(ctrlStrobe, OUTPUT);                        // Define strobe as output
  digitalWrite(ctrlReset, LOW);                       // Pull the reset signal low
  digitalWrite(ctrlStrobe, HIGH);                     // Drive the strobe signal high
  Palatis::SoftPWM.begin(60);                         // Begin with 60hz pwm frequency
  //Palatis::SoftPWM.printInterruptLoad();            // Print interrupt load for diagnostic purposes
}


void loop()
{
  while (Serial.available())
  {
    delay(10);
    char c = Serial.read();
    if (c == ':')
    {
      break;
    } 
    bluetooth += c;
  }
  if (bluetooth.length() > 0) {
    data = bluetooth;
    bluetooth="";
  }
  if (data == "ON")
  {
    readMSGEQ7();
    writeLEDs();
  }
  if (data == "OFF")
  {
    for (int i = 0; i < 7; i++)
    {
    Palatis::SoftPWM.set(pwmLEDsLeft, 1);
    Palatis::SoftPWM.set(pwmLEDsRight, 1);
    }
  }
  Serial.print(data);
  Serial.print("\n");
}

void readMSGEQ7()
{                                                       // Read the seven spectrum bands from the MSGEQ7 chips
  digitalWrite(ctrlReset, HIGH);                        // Pulse the reset signal, which causes
  digitalWrite(ctrlReset, LOW);                         // the MSGEQ7s to latch the spectrum values
  delayMicroseconds(72);                                // Delay to meet minimum reset-to-strobe time
  int nF = 50;                                          // Noise filter level.
  for (int i = 0; i < 7; i++)                           // Cycle through the 7 spectrum bands
  {
    digitalWrite(ctrlStrobe, LOW);                      // Read current band (then increment to next band)
    delayMicroseconds(36);                              // Wait for outputs to settle
    spectrumLeft = analogRead(channelLeft) / 10;     // Store current values from left & right channels
    spectrumRight = analogRead(channelRight) / 10;   // Divide 0-1023 by 10 to give about 0-100
    //if (spectrumLeft < nF) spectrumLeft = 0;      // Noise filter left
    //if (spectrumRight < nF) spectrumRight = 0;    // Noise filter right
    digitalWrite(ctrlStrobe, HIGH);
    delayMicroseconds(36);                              // Delay to meet minimum strobe-to-strobe time
  }
}

void writeLEDs()
{
  for (int i = 0; i < 7; i++) {
    Palatis::SoftPWM.set(pwmLEDsLeft, spectrumLeft);
    Palatis::SoftPWM.set(pwmLEDsRight, spectrumRight);
    Serial.print(spectrumLeft);
    if (spectrumLeft < 10) Serial.print(" ");
    Serial.print(" ");
    Serial.print(spectrumRight);
    if (spectrumRight < 10) Serial.print(" ");
    Serial.print(" | ");
  }
  Serial.print("\n");
}