Go Down

Topic: Help me control 1 led strip by 2 microcontroller (Read 555 times) previous topic - next topic

kaitoukid93

Jul 05, 2018, 02:20 pm Last Edit: Jul 05, 2018, 02:21 pm by kaitoukid93
Hello
 I want to control a Led strip with 2 different microcontrollers
 atmega328p (the red one) and stm32f407, but I dont know if it works

-both of them are working individually to draw effect on the led strip
now I want to add a button on atmega328p( actually an arduino) to switch between 2 chips

-When I press the button, pin D2 will be set to Low and pin D3 will be set to High, so the output pin 3Y on 74HC125D will be disabled, by the way the output pin 1Y will be enabled---> the LED strip will play the effect from atmega328p (LED pin D4)


-When I press the button once again, pin D2 will be set to High and pin D3 will be set to Low, so the output pin 3Y on 74HC125D will be enabled, by the way the output pin 1Y will be disabled---> the LED strip will play the effect from the stm32f407

the button is connected to atmega328p and all the programming was done on atmega328p, (the atmega328p contain the code to draw effects on the led and the code to set D2-D3 state according to the button is pressed)

please correct me if anything is wrong
thanks


PaulRB

#1
Jul 05, 2018, 05:14 pm Last Edit: Jul 05, 2018, 05:42 pm by PaulRB


I think this is a very strange circuit. But if you are learning something interesting in the process, then good for you.

The idea sounds like it should work. In your sketch, make sure all the /OE inputs on the 74hc125 are HIGH before you set either to LOW. This is because if two of the /OE pins are LOW at the same time, the two Y outputs could short out from one to the other, damaging the 74hc125.

You should also have a 0.1uF bypass cap for the 74hc125. And you should have a 200~500R resistor between the Y1/Y3 pins and the first led in the strip. Also a large cap (eg. 100uF or 470uF or 1000uF, depending on number of leds) across the power going to the strip.

Unsigned_Arduino

  You could use some relays to switch witch microcontroller is sending data. 
Do not touch the String class.

Ever.

kaitoukid93



I think this is a very strange circuit. But if you are learning something interesting in the process, then good for you.

The idea sounds like it should work. In your sketch, make sure all the /OE inputs on the 74hc125 are HIGH before you set either to LOW. This is because if two of the /OE pins are LOW at the same time, the two Y outputs could short out from one to the other, damaging the 74hc125.

You should also have a 0.1uF bypass cap for the 74hc125. And you should have a 200~500R resistor between the Y1/Y3 pins and the first led in the strip. Also a large cap (eg. 100uF or 470uF or 1000uF, depending on number of leds) across the power going to the strip.
thanks for replying
the schematic just describe the idea,I think I will set one of Y1/Y3 to high and the other to low at the setup function

kaitoukid93

You could use some relays to switch witch microcontroller is sending data. 
thanks.  I need the PCB to be small (4*6cm) , can you suggest me a relay (smd)?

PaulRB

thanks for replying
Please don't quote entire posts when you reply. It makes the thread long but does not add anything. If you have questions or comments on particular parts of the post, just quote those parts. Otherwise use Reply, not Quote.

PaulRB

You could use some relays to switch witch microcontroller is sending data. 
There are situations where using a relay is the most convenient way to switch something, but I would not say this is one of those situations.

On the other hand, the OP is using two different MCUs in the same circuit, where one would be sufficient, so maybe convenience is not so important in this circuit!

PaulRB

I need the PCB to be small (4*6cm)
Then get rid of one of the MCUs. The ST is much more powerful than the AVR, so remove the AVR. No switching needed. Save lots of space.

kaitoukid93

Then get rid of one of the MCUs. The ST is much more powerful than the AVR, so remove the AVR. No switching needed. Save lots of space.
yeah. that's my problem. I cant edit the code (shared by the other) and I have no experience on coding with ST ARM
on the other hand ,the code on ST too complex for me, so I chose to add $0.5 (atmega328p) for music LED function

PaulRB

#9
Jul 06, 2018, 05:24 pm Last Edit: Jul 06, 2018, 05:55 pm by PaulRB
Ok, I thought it might be some reason like that.

I would not use a relay for the switching. Your browser 74hc125 chip is a good idea, but if you have trouble buying one, there are many other simple logic circuits that could do the same job.

For example, I think it can be done like this with 74hc00 quad nand gates (and saves you an ATmega pin):



Can someone check my logic above please? Bit rusty!

kaitoukid93

Ok, I thought it might be some reason like that.

I would not use a relay for the switching. Your browser 74hc125 chip is a good idea, but if you have trouble buying one, there are many other simple logic circuits that could do the same job.


thanks. So according to your schematic the D4 and STM pin always opposite. I just need to set D2 to High or Low?
much more simple, but I have a lot of NXP 74HC125D (like few hundred left from my last project) so I was thinking about using it :D


PaulRB

Fine, use 74hc125 if you have them. You could simplify your idea by using one ATmega pin to enable the signal from the STM. You can enable the signal from the ATmega using pinMode() on the atmega led data pin.

kaitoukid93

#12
Jul 07, 2018, 05:49 am Last Edit: Jul 07, 2018, 05:51 am by kaitoukid93
Fine, use 74hc125 if you have them. You could simplify your idea by using one ATmega pin to enable the signal from the STM. You can enable the signal from the ATmega using pinMode() on the atmega led data pin.
thanks. One more question, the stm32 use UART (115200) to set some value, I was able to access by using putty and a USB-TTL converter, now I want to go further

example: when using putty to communicate with stm32 via usb-ttl, I pressed "B" and then press "+" or "-" on keyboard to adjust the brightness. I want to use IR on the atmega328p
Code: [Select]
if (myReceiver.getResults()) {
    myDecoder.decode();
    if (myDecoder.protocolNum == NEC) {
      switch(myDecoder.value) {
        case 0xfd00ff:  //volume down button on the remote
          Serial.print('b');//enter brightness adjust mode
          delay(100);
          Serial.print('-'); //send "-" to serial device
          break;
        case 0xfd807f:  //volume up button on the remote
          Serial.print('b');//enter brightness adjust mode
          delay(100);
          Serial.print('+'); //send "+" to serial device;
          break;
      }

is there any problem? the stm32 using 3v3 logic level and arduino using 5v, I was able to use the same usb-ttl converter and both of them worked just fine

PaulRB

In theory, 5V could damage the STM's pins.

You could use a voltage divider (2 resistors) to reduce the voltage down to 3.3V.

You could run the ATmega at 3.3V (8MHz).

kaitoukid93

In theory, 5V could damage the STM's pins.

You could use a voltage divider (2 resistors) to reduce the voltage down to 3.3V.

You could run the ATmega at 3.3V (8MHz).
But I read somewhere, Stm32's uart is 5V tolerant. Anyway I will add a voltage divider

thanks

Go Up