Go Down

Topic: ShiftPWM support topic. Latest update: Schematics, high power LED's, LED strips (Read 155168 times) previous topic - next topic


Looking to use ShiftPWM with Vixen for holiday light display. Vixen outputs via Serial
I want to create a code that will take Vixen Output and convert it to ShiftPWM to control relays and Transistors.
Any help is appreciated!

Below is code that allows Vixen to control Arduino

The purpose of this code is to allow the Arduino to use the
generic serial output of vixen lights to control 5 channels of LEDs.
Author: Matthew Strange
Created: 14 October 2010


// Output
int Chan1 = 2;  // red LED,   connected to digital pin 5
int Chan2 = 3;  // green LED, connected to digital pin 6
int Chan3 = 4;  // red LED,  connected to digital pin 9
int Chan4 = 5;  // green LED,  connected to digital pin 10
int Chan5 = 6;  // red LED,  connected to digital pin 11

int i = 0;     // Loop counter
int incomingByte[7];   // array to store the 7 values from the serial port

//setup the pins/ inputs & outputs
void setup()
  Serial.begin(9600);        // set up Serial at 9600 bps

  pinMode(Chan1, OUTPUT);   // sets the pins as output
  pinMode(Chan2, OUTPUT);
  pinMode(Chan3, OUTPUT);
  pinMode(Chan4, OUTPUT);
  pinMode(Chan5, OUTPUT);

void loop()
{  // 7 channels are coming in to the Arduino
   if (Serial.available() >= 7) {
    // read the oldest byte in the serial buffer:
    for (int i=0; i<8; i++) {
      // read each byte
      incomingByte = Serial.read();
    analogWrite(Chan1, incomingByte[0]);   // Write current values to LED pins
    analogWrite(Chan2, incomingByte[1]);   // Write current values to LED pins
    analogWrite(Chan3, incomingByte[2]);   // Write current values to LED pins
    analogWrite(Chan4, incomingByte[3]);   // Write current values to LED pins
    analogWrite(Chan5, incomingByte[4]);   // Write current values to LED pins


I already did this here

You can't use pwm on relays btw. I will post my code this afternoon


elcojacobs said before that ShiftPWM could be used for relays just set to maxbrightness for on and zero for off.
Looking forward to seeing your code.


ematson, I too would love to see your code and how you setup vixen to use it. I have a similar "Christmas" project in mind.


Jun 25, 2012, 08:37 pm Last Edit: Jun 28, 2012, 09:14 pm by TBSkinner Reason: 1
I have read threw quite a bit of the forum posts, and still had a few questions. I am trying to make tail lights for my car that are a set of 5x10 rgb LEDs. I was wondering if it would be better to use ShiftMatrixPWM or ShiftPWM? I would essentially be controlling 600 LEDs so it is within the scope of ShiftPWM but I am concerned about the brightness. I'm very new to programming and Arduino. So if there are some easy examples that would help me out it would be greatly appreciated, maybe something that will help me build a power supply for the ShiftMatrixPWM? I have already made a mock up of an led matrix. Thanks for any help.


I have made a schematic of the circuit I would like to make. Any help wiring it to the arduino would be greatly appreciated. Also i'm not sure about my power circuit and if I need anything else like capacitors in it.


Hey here's the vixen code for you all. Tell me if it works as it isn't my original code. It got erased. Here it is
Code: [Select]
#include <SPI.h>

//Data pin is MOSI (atmega168/328: pin 11. Mega: 51)
//Clock pin is SCK (atmega168/328: pin 13. Mega: 52)
const int ShiftPWM_latchPin=8;
bool ShiftPWM_invertOutputs = 1; // if invertOutputs is 1, outputs will be active low. Usefull for common anode RGB led's.

#include <ShiftPWM.h>   // include ShiftPWM.h after setting the pins!

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
const int numRegisters = 6;
const int CHANNELS = numRegisters*8;

const long baud = 19200; // USB Serial is actually always 12 Mbit/sec
HardwareSerial Uart = HardwareSerial();

static unsigned char currByte;
static unsigned char prevByte;

unsigned char aChannelValues[CHANNELS];
unsigned char ChannelIndex = 0;

// the setup() method runs once, when the sketch starts

void setup() {
    pinMode(ShiftPWM_latchPin, OUTPUT); 
  // SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte.
  // SPI transfer and calculations overlap for the other bytes.

// the loop() methor runs over and over again,
// as long as the board has power
boolean bInDataBlock = false;
boolean bSerial = false;

void loop() {
  if (Serial.available())
    if (Serial.available())
      currByte = Serial.read();
      //Uart.write(currByte); return;
      bSerial = true;


    if (bInDataBlock)
      if (currByte == 0x7F) // Escape Sequence
        if (bSerial) currByte = Serial.read();
        currByte += 0x4E;
      aChannelValues[ChannelIndex++] = currByte;
      if (ChannelIndex >= CHANNELS)
        bInDataBlock = false;
    if ( prevByte == 0x7e && currByte == 0x80 )
      bInDataBlock = true;
      ChannelIndex = 0;
    prevByte = currByte;

void Transfer_To_Ports()
  for (int i; i < CHANNELS ; i++ )


What are these for.
HardwareSerial Uart = HardwareSerial();

This error when compiling
VixenShift.cpp: In function 'void loop()':
VixenShift:72: error: 'Transfer_To_Ports' was not declared in this scope

Could you give some basic info on how this code works. I am a newbie but want to understand

Thanks Again for your code and hard work put into it! I will be sure to give you credit in any code i create as well as my Light Displays!


Jul 16, 2012, 10:31 am Last Edit: Jul 16, 2012, 10:34 am by tsaG Reason: 1

I put everything together and (first) thought it worked.

I got 4 Shift registered wired Serial with 16 DUO Leds. I uploadet the and it looked like as if it worked. But then it comes to the "Fade in all outputs" part. My Arduino crashes and it starts from the beginning.

How could that happen? Is it a wiring problem? I used the USB Port or a 10W power supply, the problem is the same.

I made a movie of my Problem attached to this post.


EDIT: I already uploaded the Blink.sketch to verify if the Arduino is working correctly, and it is.
I already changed the pwmFrequency or setClockDivider . but the problem persists.


Jul 16, 2012, 05:04 pm Last Edit: Jul 16, 2012, 05:13 pm by ematson5897 Reason: 1
Sorry ron, I completely forgot to reply. Those are from the code that I modified. It is designed for teensy, a board with more functionality than a standard arduino. It should work if you delete the serial and uart line. As for the other error,  its clearly defined in the function, so I don't know.

tsaG, sorry I can't help you, I currently don't have a way to open .mov on my tablet. I'll try to find an app, if I can, I'll post back


It seems as if you aren't using decoupling capacitors. Put a .1 uf capacitor between the 5v and gnd of each chip, because your chips signals probably look like this http://hackaday.com/2011/10/25/do-you-know-why-youre-supposed-to-use-decoupling-capacitors/


Jul 16, 2012, 07:03 pm Last Edit: Jul 16, 2012, 07:16 pm by tsaG Reason: 1
Ill give it a try. I tried getting the signal onto my osci. Its hard to trigger the signal when the arduino resets half every second :D

It looks quite good, I think (?)

1. Latch Pin
2. Clock Pin

EDIT: I didnt check the Serial Input pin. Ill check it later!


Those seem fine. If the capacitors don't solve the problem then try making a sketch that uses the shiftout command that sets all outputs to high to rule out a bad power supply


The decoupling capacitor solved the problem. Thanks!


No problem. Decoupling caps are a frequently forgotten necessity


And elco, can I use other SPI devices while using shift(matrix)Pwm? Like ethernet shield and sd card etc.

Go Up