Offline
Newbie
Karma: 0
Posts: 3
|
 |
« Reply #240 on: June 23, 2012, 10:03:59 pm » |
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 } }
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
|
 |
« Reply #242 on: June 24, 2012, 09:26:30 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Australia
Offline
Jr. Member
Karma: 2
Posts: 62
|
 |
« Reply #243 on: June 24, 2012, 11:04:18 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #244 on: June 25, 2012, 01:37:30 pm » |
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.
Skinner
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.
|
|
|
|
« Last Edit: June 28, 2012, 02:14:17 pm by TBSkinner »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 189
|
 |
« Reply #245 on: June 25, 2012, 01:50:53 pm » |
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 #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.setBitOrder(LSBFIRST); // SPI_CLOCK_DIV2 is only a tiny bit faster in sending out the last byte. // SPI transfer and calculations overlap for the other bytes. SPI.setClockDivider(SPI_CLOCK_DIV4); SPI.begin(); Serial.begin(baud); ShiftPWM.SetAmountOfRegisters(numRegisters); ShiftPWM.Start(pwmFrequency,maxBrightness); }
// 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; Transfer_To_Ports(); } } if ( prevByte == 0x7e && currByte == 0x80 ) { bInDataBlock = true; ChannelIndex = 0; } prevByte = currByte; } }
void Transfer_To_Ports() { for (int i; i < CHANNELS ; i++ ) { ShiftPWM.SetOne(i,aChannelValues[i]); } }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 3
|
 |
« Reply #246 on: June 26, 2012, 03:23:01 pm » |
What are these for. HardwareSerial Uart = HardwareSerial(); Transfer_To_Ports();
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!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 1
Posts: 94
|
 |
« Reply #247 on: July 16, 2012, 03:31:57 am » |
Hi!
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.
-tsaG
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.
|
|
|
|
« Last Edit: July 16, 2012, 03:34:17 am by tsaG »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 189
|
 |
« Reply #248 on: July 16, 2012, 10:04:10 am » |
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
|
|
|
|
« Last Edit: July 16, 2012, 10:13:21 am by ematson5897 »
|
Logged
|
|
|
|
|
|
|
Offline
Jr. Member
Karma: 1
Posts: 94
|
 |
« Reply #250 on: July 16, 2012, 12:03:06 pm » |
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  It looks quite good, I think (?) 1. Latch Pin 2. Clock Pin EDIT: I didnt check the Serial Input pin. Ill check it later!
|
|
|
|
« Last Edit: July 16, 2012, 12:16:59 pm by tsaG »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 189
|
 |
« Reply #251 on: July 16, 2012, 12:35:53 pm » |
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
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 1
Posts: 94
|
 |
« Reply #252 on: July 17, 2012, 03:21:05 am » |
The decoupling capacitor solved the problem. Thanks!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 189
|
 |
« Reply #253 on: July 17, 2012, 10:06:54 am » |
No problem. Decoupling caps are a frequently forgotten necessity
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 189
|
 |
« Reply #254 on: July 31, 2012, 07:17:57 pm » |
And elco, can I use other SPI devices while using shift(matrix)Pwm? Like ethernet shield and sd card etc.
|
|
|
|
|
Logged
|
|
|
|
|
|