Arduino

From neil.tappsville.com
Revision as of 08:01, 12 August 2019 by Gonzo (talk | contribs) (Created page with "=== Arduino Dumping Ground === Once I get all of this working as I like, I'll clean this page up. Link to Vixen plugin development videos [http://doityourselfchristmas.co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Arduino Dumping Ground

Once I get all of this working as I like, I'll clean this page up.


Link to Vixen plugin development videos doityourselfchristmas.com/forums/showthread.php?15190-Vixen-Plugin-Tutorial [1]



Software PWM for 16 digital channels

[code.google.com/p/rogue-code/wiki/Soft PWMLibraryDocumentation]



Arduno and Vixen Christmas Lights Controller

doityourselfchristmas.com/forums/showthread.php?12757-Vixen-Generic-Serial-Output-controls-the-Arduino!&p=129693#post129693


Configure Vixen to use serial out - start Vixen then plug in the Ardunio

/*
Allow Vixen to control Arduino PWM outputs.
Neil Tapp 22 July 2011
v0.1 its upto the user to ensure channel count = incoming channel #
Due to 'Vixen generic serial using only ascii and not utf8, we cant
have a distinct header footer marker, thus no 'buffer / data set / error checks'
*/

// Configure outputs
int chanPWM[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
//int chanDigital[] = {22, 24};
int incomingByte[10]; // size of the chanPWM array


// The rest should work automagically.

int chanPWMCount = 0; // saves processing later
//int chanDigitalCount = 0; // saves processing later
int i = 0;     // Loop counter


//setup the pins/ inputs & outputs
void setup()
{
  chanPWMCount = sizeof(chanPWM);
  //chanDigitalCount = sizeof(chanDigital);

 // initalise PWM Channels / Pins
 for (i=0; i < chanPWMCount-1; i++){
    pinMode(chanPWM[i], OUTPUT);
 }
 // initalise digital Channels / Pins
 //for (i=0; i < chanDigitalCount-1; i++){
 //   pinMode(chanDigital[i], OUTPUT);
 // }

 //we cant define the buffer here :(
 Serial.begin(57600);        // set up Serial at 9600 bps
}

void loop()
{
   if (Serial.available() >= chanPWMCount) {
    // read the oldest byte in the serial buffer:
    for (int i=0; i<chanPWMCount; i++) {
      // read each byte
      while (Serial.peek() == '-1'){
       // if the stream breaks we get -1
      }
      incomingByte[i] = Serial.read();
    }
   for (i=0; i < chanPWMCount-1; i++){
    analogWrite(chanPWM[i], incomingByte[i]);
  }
 }}


Vixen Lights is awesome and I wanted to have it control my new little Arduino Duemilanove. I decided to use the generic serial output already in vixen lights as my plugin. I’m using 5 channels on my Arduino (5,6,9,10 & 11) that have PWM so I can fade the LEDs. The generic serial output appears to simply output one byte at a time like so: 06 00 00 00 00 00 0d. I setup my vixen lights sequence to use 7 channels. The first 5 would be for my LEDs, channel 6 is the beat track and channel 7 was a spare. I used a baud rate of 9600. The code simply takes the 7 bytes, stuffs them into an array and then sends them to the hungry LEDs. Check out the code:

Code 
/*
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 = 5;  // red LED,   connected to digital pin 5
int Chan2 = 6;  // green LED, connected to digital pin 6
int Chan3 = 9;  // red LED,  connected to digital pin 9
int Chan4 = 10;  // green LED,  connected to digital pin 10
int Chan5 = 11;  // 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[i] = 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
   }
}


Gamma Correction of LED lights neuroelec.com/2011/04/led-brightness-to-your-eye-gamma-correction-no/

 1: /*

   2:  Change brightness of LED linearly to Human eye

   3:  32 step brightness using 8 bit PWM of Arduino

   4:  brightness step 24 should be twice bright than step 12 to your eye.

   5: */

   6:

   7: #include <avr/pgmspace.h>

   8: #define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness loopup table function

   9:

  10: /*

  11: 5 bit CIE Lightness to 8 bit PWM conversion

  12: L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856

  13: L* = 903.3(Y/Yn), Y/Yn <= 0.008856

  14: */

  15:

  16: prog_uint8_t CIEL8[] PROGMEM = {

  17:     0,    1,    2,    3,    4,    5,    7,    9,    12,

  18:     15,    18,    22,    27,    32,    38,    44,    51,    58,

  19:     67,    76,    86,    96,    108,    120,    134,    148,    163,

  20:     180,    197,    216,    235,    256

  21: };

  22:

  23: int brightness = 0;    // initial brightness of LED

  24: int fadeAmount = 1;

  25:

  26: void setup()  {

  27:   // declare pin 9 to be an output:

  28:   pinMode(9, OUTPUT);

  29: }

  30:

  31: void loop()  {

  32:   // set the brightness of pin 9:, 0-31, 5 bit steps of brightness

  33:   analogWrite(9, CIELPWM(brightness));

  34:

  35:   // change the brightness for next time through the loop:

  36:   brightness = brightness + fadeAmount;

  37:

  38:   // reverse the direction of the fading at the ends of the fade:

  39:   if (brightness == 0 || brightness == 31) {

  40:     fadeAmount = -fadeAmount ;

  41:   }

  42:   // wait for 500 milliseconds to see the bightness change

  43:   delay(500);

  44: }

Ascii Charts

www.ascii-code.com/


Rainbowdunino

Run upto 192 Leds (not sure if this is 192x3 colours, or total) - appears to be 64x tri colour

www.seeedstudio.com/depot/rainbowduino-led-driver-platform-plug-and-shine-p-371.html www.seeedstudio.com/wiki/Rainbowduino


hackaday.com/2013/05/27/ws2811-can-be-addressed-at-800khz-using-a-8mhz-clock/