Help. I'm newbie

Hi all.
Please help me, i need the code that can turn on relay when Jinx start output and turn off relay when Jinx stop output.

Jinx > Glediator protocol for arduino > Arduino > 5v Relay > Power supply > WS2811 matrix.

Maybe this picture explained.

Thank you.

Untitled-1.jpg

So it looks like you have everything except the relays working.
Please post your Arduino code inside tags, then we can push you along.

OP’s original picture
c00786c262e0b6c5466eaeefeb6f051053bfd2b5.jpg

Usually we don’t write code for members - what would you learn? - but we like to help you discover and understand on your own terms.

Thank for your replay.
Im still fresh beginner for this arduino, so i only make some change in this glediator protocol. But i dont know what code to make relay detect the Jinx software start output.
(sorry for my bad english)

This the code :

//##############################################################################
//##############################################################################
//                                                                             #
// Glediator to WS2812 pixel converter                                         #
// by R. Heller                                                                #
// V 1.0 - 07.01.2014                                                          #            
// wwww.SolderLab.de                                                           #
//                                                                             #
// Receives serial data in Glediator protocol format @ 1 MBit/s                #
// and distributes it to a connectect chain of WS2812 pixels                   #
//                                                                             #
// Adjust the correct DATA PIN and the correct NUMBER OF PIXELS you are using  # 
// in the definitions section below before uploading this sketch to your       #
// Arduino device.                                                             #
//                                                                             #
// Maxiumim number of supported pixeles is 512 !!!                             #
//                                                                             #
// In the Glediator software set output mode to "Glediator_Protocol",          #
// color order to "GRB" and baud rate to "1000000"                             #
//                                                                             #
//##############################################################################
//##############################################################################


//##############################################################################
//                                                                             #
// Definitions --> Make changes ONLY HERE                                      #
//                                                                             #
// To find out the correct port, ddr and pin name when you just know the       #
// Arduino's digital pin number just google for "Arduino pin mapping".         #
// In the present example digital Pin 6 is used which corresponds to "PORTD",  #
// "DDRD" and "6", respectively.                                               #
//                                                                             #
//##############################################################################

#define DATA_PORT          PORTD
#define DATA_DDR           DDRD            
#define DATA_PIN           6              
#define NUMBER_OF_PIXELS   364


//##############################################################################
//                                                                             #
// Variables                                                                   #
//                                                                             #
//##############################################################################

unsigned char display_buffer[NUMBER_OF_PIXELS * 3];
static unsigned char *ptr;
static unsigned int pos = 0;

volatile unsigned char go = 0;


//##############################################################################
//                                                                             #
// Setup                                                                       #
//                                                                             #
//##############################################################################

void setup()
{
  // Set data pin as output
  DATA_DDR |= (1 << DATA_PIN);
  
  // Initialize UART
  UCSR0A |= (1<<U2X0);                                
  UCSR0B |= (1<<RXEN0)  | (1<<TXEN0) | (1<<RXCIE0);   
  UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00)             ; 
  UBRR0H = 0;
  UBRR0L = 1; //Baud Rate 1 MBit (at F_CPU = 16MHz)
  
  ptr=display_buffer;
  
  //Enable global interrupts
  sei();
}


//##############################################################################
//                                                                             #
// Main loop                                                                   #
//                                                                             #
//##############################################################################

void loop()
{   
  if (go==1) 
  {
    cli();
    ws2812_sendarray(display_buffer, NUMBER_OF_PIXELS * 3); 
    sei();
    go=0;
  }
}


//##############################################################################
//                                                                             #
// UART-Interrupt-Prozedur (called every time one byte is compeltely received) #
//                                                                             #
//##############################################################################

ISR(USART_RX_vect) 
{
  unsigned char b;
  b=UDR0;
  
  if (b == 1)  {pos=0; ptr=display_buffer; return;}    
  if (pos == (NUMBER_OF_PIXELS*3)) {} else {*ptr=b; ptr++; pos++;}  
  if (pos == ((NUMBER_OF_PIXELS*3)-1)) {go=1;}
}


//##############################################################################
//                                                                             #
// WS2812 output routine                                                       #
// Extracted from a ligh weight WS2812 lib by Tim (cpldcpu@gmail.com)          #
// Found on wwww.microcontroller.net                                           #
// Requires F_CPU = 16MHz                                                      #
//                                                                             #
//##############################################################################

void ws2812_sendarray(uint8_t *data,uint16_t datlen)
{
  uint8_t curbyte,ctr,masklo;
  uint8_t maskhi = _BV(DATA_PIN);
  masklo =~ maskhi & DATA_PORT;
  maskhi |= DATA_PORT;

  while (datlen--) 
  {
    curbyte = *data++;

    asm volatile
    (
      "   ldi %0,8  \n\t"   // 0
      "loop%=:out %2, %3  \n\t"   // 1
      "lsl  %1    \n\t"   // 2
      "dec  %0    \n\t"   // 3
      "   rjmp .+0  \n\t"   // 5
      "   brcs .+2  \n\t"   // 6l / 7h
      "   out %2,%4 \n\t"   // 7l / -
      "   rjmp .+0  \n\t"   // 9
      "   nop   \n\t"   // 10
      "   out %2,%4 \n\t"   // 11
      "   breq end%=  \n\t"   // 12      nt. 13 taken
      "   rjmp .+0  \n\t"   // 14
      "   rjmp .+0  \n\t"   // 16
      "   rjmp .+0  \n\t"   // 18
      "   rjmp loop%= \n\t"   // 20
      "end%=:     \n\t" 
      : "=&d" (ctr)
      : "r" (curbyte), "I" (_SFR_IO_ADDR(DATA_PORT)), "r" (maskhi), "r" (masklo)
    );
  }

}


//##############################################################################
//                                                                             #
// End of program                                                              #
//                                                                             #
//##############################################################################

The existing drawing really isn't good enough.

We can't see where the individual power wires are going (pins etc)
Are the 0V/grounds tied together?

As mentioned - it sounds like you (may) have the code & connection between Jinx and the Arduino working.
Forget the relays for now - see if you can control the on-board LED (on/off) with the JINX commands (emulating the future relay) , then start working on the relay output when that works.

I'm not sure when or how long you wan to fire the LED/relay for, but your code most likely needs to be added in this area

if (go==1) 
  {
    cli();
         // ==> turn ON here
    ws2812_sendarray(display_buffer, NUMBER_OF_PIXELS * 3); 
         // ==> turn OFF here - but sendarray() will be VERY fast.
    sei();
    go=0;
  }

How often will the relay switch ON/OFF? Hopefully hardly ever?

lastchancename:
The existing drawing really isn't good enough.

We can't see where the individual power wires are going (pins etc)
Are the 0V/grounds tied together?

As mentioned - it sounds like you (may) have the code & connection between Jinx and the Arduino working.
Forget the relays for now - see if you can control the on-board LED (on/off) with the JINX commands (emulating the future relay) , then start working on the relay output when that works.

I'm not sure when or how long you wan to fire the LED/relay for, but your code most likely needs to be added in this area

if (go==1) 

{
   cli();
        // ==> turn ON here
   ws2812_sendarray(display_buffer, NUMBER_OF_PIXELS * 3);
        // ==> turn OFF here - but sendarray() will be VERY fast.
   sei();
   go=0;
 }

it's keep switching very fast. How to make it only relay on when start output and relay off when stop output for jinx,

Hi,
Welcome to the forum.

Have you written some code JUST to turn the relay or the LED on the UNO ON and OFF every 2seconds.

This is to prove you have connection and power supply.

Thanks.. Tom.. :slight_smile:

Hi, oh yes. Sure, but i like to monitor whenever the Jinx start output, then power supply turn on. But when Jinx stop the output then power supply turn off. The point is, i want to lower the electric consumption (turn off power supply) when nothing to show on Jinx.

Hi,
Did the original code work before to edited it?

Tom... :slight_smile:

yes,.

But main goal is to switch on the power supply for led when Jinx software start output. So we can safe the electric cost when Jinx not running.

Switching the power supply on has a small cost in itself. If the PS is a switching supply then leaving it on when power is not drawn from it will have very small waste. It is something better turned on and left on during run-time, you can control the output with MOSFET(s).

How long does the Jinx run? How often? You can burn up relay or power supply and not save power if switched too quickly again and again.

You know that relays use a lot of power?

In response to your comment in #5,
That was expected...
If i’m reading your expectations correctly, you need to look at starting a counter, and turning the relay on.
After the on-time has elapsed, turn the relay off, and wait for the event to happen again.

This will use the concepts behind millis() to handle the duration timing - not delay().

Romiez_Fach:
But main goal is to switch on the power supply for led when Jinx software start output. So we can safe the electric cost when Jinx not running.

When the LEDs are off the power supply will not be supplying very much power. If you are doing this to save the price of electricity then it will take years to cover the cost of the components you have to buy to do this.

OK, i have a sign board for my tiny kiosk and some PC for daily use . Usually i turn it on when afternoon until 21 PM, someday at mid night lightning burn my arduino, led and CPU even i have shut down my PC. So i decide make switch to cut the line between sign board - PSU. So when i close/ stop the Jinx software then relay cut the power supply outlet and cut data cable between led and arduino.
(sorry for my bad english)

So that is a different reason than the "So we can safe the electric cost" which previously was the only reason you gave.

If it is a lightning strike then a relay is not going to be much good because the high voltage can easily jump the small contact gap of most relays. You need some gas discharge lightning arresters or a surge suppress in the mains lead.

Lightning.... switch off and pull the plug.

The sign is very high tech? Could an Arduino drive it on (safe during storm) battery power? Some Arduinos are very powerful.

As i say, i'm still confuse how to solve the risk of lighting and power cost. But first i need to cut power supply then find some surge arrest

Romiez_Fach:
As i say, i'm still confuse how to solve the risk of lighting and power cost. But first i need to cut power supply then find some surge arrest

You put the whole system on a timer switch at the power outlet, you will never forget turn it off and you cannot save power anymore efficiently.
To ensure 90% protection from lightning, pull the plug out of the wall.
I say 90% because lightning strikes in mysterious ways a wonder to behold.
Tom.... :slight_smile:

I knew a guy who pulled his PC plug from the wall and a strike hit just outside. If he had pulled the PC cord from the box instead of the wall it might have saved the PC but as it was the cord acted like an antenna and some parts burned up.

Can you get affordable insurance?

haha..
please help me, has anyone know how to control this relay ?