Show Posts
Pages: [1]
1  Using Arduino / Project Guidance / 16 Channel 12v Relay Module and Arduino on: December 09, 2012, 09:54:08 pm
Can someone help me with this relay module? I though it took a 12v power supply to the screw terminals but what I don't get is it has 5v and ground on either end of the 16 low level input pins. Obviously the arduino pins need to be connected to 1 - 16 but does it need ground and 5v power as well? Should the arduino be sinking or sourcing power?
2  Using Arduino / Programming Questions / Re: Renard Protocol and Arduino on: September 24, 2012, 06:08:10 pm
You were right, after digging for awhile I did find this code by Mat er daddy. Right now I'm playing with modifying it to dump the color part because my lights are not RGB pixels.

Code:
#define XMAS_PIN 8
#define xmas_color_t uint16_t
 
#define XMAS_LIGHT_COUNT    (50)
 
#define XMAS_CHANNEL_MAX          (0xF)
#define XMAS_DEFAULT_INTENSITY     (0xCC)
#define XMAS_COLOR(r,g,b)     ((r)+((g)<<4)+((b)<<8))
#define XMAS_COLOR_WHITE     XMAS_COLOR(XMAS_CHANNEL_MAX,XMAS_CHANNEL_MAX,XMAS_CHANNEL_MAX)
#define XMAS_COLOR_BLACK     XMAS_COLOR(0,0,0)
 
bool sync;
 
void xmas_begin(uint8_t pin);
void xmas_one(uint8_t pin);
void xmas_zero(uint8_t pin);
void xmas_end(uint8_t pin);
 
void xmas_begin(uint8_t pin)
{
  digitalWrite(pin,1);
  delayMicroseconds(7);
  digitalWrite(pin,0);
}
 
void xmas_one(uint8_t pin)
{
  digitalWrite(pin,0);
  delayMicroseconds(11); //This results in a 20 uS long low
  digitalWrite(pin,1);
  delayMicroseconds(7);
  digitalWrite(pin,0);
}
 
void xmas_zero(uint8_t pin)
{
  digitalWrite(pin,0);
  delayMicroseconds(2);
  digitalWrite(pin,1);
  delayMicroseconds(20-3);
  digitalWrite(pin,0);
}
 
void xmas_end(uint8_t pin)
{
  digitalWrite(pin,0);
  delayMicroseconds(40); // Can be made shorter
}
 
 
void xmas_set_color(uint8_t led,uint8_t intensity,xmas_color_t color, uint8_t pin)
{
  uint8_t i;
 
  cli(); //Disable interrupts while we write to GECEs
  xmas_begin(pin);
 
  //6-Bit bulb address (MSB first)
  for(i=6;i;i--,(led<<=1))
  {
    if(led&(1<<5))
      xmas_one(pin);
    else
      xmas_zero(pin);
  }
 
  //8-Bit brightness (MSB first)
  for(i=8;i;i--,(intensity<<=1))
  {
    if(intensity&(1<<7))
      xmas_one(pin);
    else
      xmas_zero(pin);
  }
 
  //12 bit Color (Blue, Green, Red) (MSB first)
  for(i=12;i;i--,(color<<=1))
  {
    if(color&(1<<11))
      xmas_one(pin);
    else
      xmas_zero(pin);
  }
 
  xmas_end(pin);
  sei(); //Re-enable interrupts now that we're done writing to GECEs
}
 
void xmas_set_all_one_address(uint8_t pin)
{
  for (int i = 0; i < XMAS_LIGHT_COUNT; ++i)
    xmas_set_color(0,XMAS_DEFAULT_INTENSITY,XMAS_COLOR_BLACK,pin);
}
 
void setup()
{
  delay(10);
  Serial.begin(57600);
  delay(10);
 
  pinMode(5, OUTPUT);
  digitalWrite(5, LOW);
 
  pinMode(XMAS_PIN, OUTPUT);
  digitalWrite(XMAS_PIN, 0);
  xmas_set_all_one_address(XMAS_PIN);
 
  sync = false;
}
 
void wait_for_serial()
{
    while ( ! Serial.available() > 0 ) { }
}
 
int renardReadBytes( uint8_t *bytes, uint8_t bytes_size )
{
  int in_byte = 0;
  int bytes_read;
 
  for ( bytes_read = 0; bytes_read < bytes_size; )
  {
    wait_for_serial();
    in_byte = Serial.read();
 
    switch (in_byte)
    {
      case(0x7E): // We saw the sync byte, start over!
        sync = true;
        return bytes_read;
 
      case(0x7D): // Skip the pad byte
        continue;
 
      case(0x7F): // Escape character, we need to read one more byte to get our actual data
        wait_for_serial();
        in_byte = Serial.read();
        switch (in_byte)
          {
            case(0x2F): // renard wants an 0x7D
              in_byte = 0x7D;
            case(0x30): // renard wants an 0x7E
              in_byte = 0x7E;
            case(0x31): // renard wants an 0x7F
              in_byte = 0x7F;
          }
        }
 
    bytes[bytes_read++] = in_byte;
  }
 
  return bytes_read;
}
 
int renardRead( uint8_t *bytes, uint8_t byte_count )
{
  int in_byte = 0;
 
  while ( ! sync )
  {
    wait_for_serial();
    in_byte = Serial.read();
    if ( in_byte == 0x7E ) // Sync byte signifies start of packet
      sync = true;
  }
 
  if ( sync )
  {
    sync = false;
    wait_for_serial();
    in_byte = Serial.read();
    if ( in_byte == 0x80 ) // Read from here
    {
      return renardReadBytes(bytes, byte_count);
    }
  }
 
  return 0;
}
 
void loop()
{
  uint8_t bytes[4], bytes_read;
  bytes_read = renardRead(&bytes[0], 4);
 
  if ( bytes_read == 4 )
  {
    // We have now received 4 bytes of data per string, do something with them!
    uint8_t red   = bytes[0];
    uint8_t green = bytes[1];
    uint8_t blue  = bytes[2];
    uint8_t white = bytes[3];
 
 
    red = ( red+(white/3) >= (XMAS_CHANNEL_MAX<<4) ? (XMAS_CHANNEL_MAX<<4) : red+(white/3) );
    green = ( green+(white/3) >= (XMAS_CHANNEL_MAX<<4) ? (XMAS_CHANNEL_MAX<<4) : green+(white/3) );
    blue = ( blue+(white/3) >= (XMAS_CHANNEL_MAX<<4) ? (XMAS_CHANNEL_MAX<<4) : blue+(white/3) );
 
    xmas_set_color(0,XMAS_DEFAULT_INTENSITY,XMAS_COLOR((red>>4),(green>>4),(blue>>4)),XMAS_PIN);
  }
}
3  Using Arduino / Programming Questions / Re: Renard Protocol and Arduino on: September 24, 2012, 05:06:32 pm

I have searched everywhere I could think of for his work and tried to get ahold of him. He refers to it as "slightly more complex" but never really goes into any details on how.
4  Using Arduino / Programming Questions / Re: Renard Protocol and Arduino on: September 24, 2012, 04:01:28 pm
Quote
If it misses a step...

My suspicion is that it would be much less work to determine why "it" is missing steps and fix that problem.


It isn't currently but if it were to for any reason it would never resync. That is, from what I can tell, the largest drawback of running a Vixen + Arduino + Serial system. If that can be eliminated by writing some code for Arduino to read a Renard stream (renard has a start and stop byte) that seems to be the best way to go and I think there are a lot of people that would use it. Unfortunately I don't know how to code well enough to write it.
5  Using Arduino / Programming Questions / Renard Protocol and Arduino on: September 24, 2012, 12:08:45 pm
Using the Arduino to control musical Christmas lights from Vixen is easy with serial but has it's limitations. If it misses a step it can't correct itself and everything will be out of sync. It seems that the best solution would be to use the Renard Protocol as it has built in error correction but I can't seem to find any help on programming the Arduino to read the data stream. Unfortunately I'm too new to all of this to program it myself, though if I can't get help I may try. The grand idea would be to figure out how to utilize the Renard protocol and use daisy chained shift registers to run 50+ channels. Any help with programming would be greatly appreciated.
6  Using Arduino / Motors, Mechanics, and Power / Will these SSR's work? on: September 21, 2012, 11:55:00 am
I'm looking for a few SSR's to control 120vAC lighting, all less than 5amp. Would these work or would they hurt my arduino?

http://www.ebay.com/itm/CRYDOM-Solid-State-Relay-SSR-MCX240D5-5A-240Vac-Load-3-15Vdc-Control-New-PCB-/290778148087?pt=LH_DefaultDomain_0&hash=item43b3ba6cf7
7  Using Arduino / Project Guidance / Re: Help shortening code on: September 20, 2012, 04:56:10 pm
My bad, I forgot to recopy the code after I fixed that. Here is the working code.

Code:
/*
  * Simple LED Display with button to change patterns
  *
  * Everytime the button is pressed it skips to the next pattern
  *
  * Created by Cort Naab
  *
  * Circuit:
  * LED from ground to Pin 3 (w/ 220ohm resistor)
  * LED from ground to Pin 6 (w/ 220ohm resistor)
  * Button from ground to Pin 2
*/

const int buttonPin = 2; // select pin for button
int buttonCount = 0; // variable to store number of button presses
int buttonState = 1; // variable to store button state
int lastbuttonState = HIGH; // stores last button state
const int led1Pin = 3; //select led pins
const int led2Pin= 6;
int fadeRate = 5; // fadeRate used in fadeLED() function
int blinkState = 0; // placeholder for functions to remember where they last were
int fade = 35; //setting initial fade brightness
long previousTime = 0; // gets set later by functions and is used in a operation that replaces "delay"
long blinkInterval = 1000; // delay length of blink function
long altInterval = 600; // delay length of alternate funcation
long pulseInterval = 50; // delay legth of pulse function
long fadeInterval = 20; // delay rate of fade function
unsigned long currentTime = millis(); /* sets currentTime to millis that the machine has been on
                                       * this number gets very large very fast so it needs to be in
                                       * long format.
                                       */

void setup() {
   
  pinMode(buttonPin, INPUT); // Set pin mode of button
  digitalWrite (buttonPin, HIGH);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  Serial.begin(9600); // Initialize the serial com
  Serial.println("Serial is active");
}

void loop() {
  // update current time
  currentTime = millis();
  // read the current button state
  buttonState = digitalRead(buttonPin);
 
  // check to see if button state has changed
  if (buttonState != lastbuttonState) {
    // if the button state has changed and is now pressed then...
    if (buttonState == LOW) {
      buttonCount++;
      Serial.print("number of button pushes;  ");
      Serial.println(buttonCount);
    }
  }
  // Save current button state
  lastbuttonState = buttonState;
  // Set pattern to display based on function
  switch (buttonCount) {
    case 0: blinkLED(); break;
    case 1: alternateLED(); break;
    case 2: pulseLED(); break;
    case 3: fadeLED(); break;
    case 4: buttonCount = 0; break;
}

/* There are only notes on the first and last function because
   the middle functions are essentially the same as blinkLED
*/
void blinkLED(){
  /* This replaces the delay you would normally need for "blink"
   * It checks to see if the set interval has passed
   * if it has lets the prgram move on, otherwise skips the rest
   * of this function. This is done to allow a (almost) constant
   * recheck of whether the button has been pressed. Without it
   * button presses get missed during delays
  */
  if (currentTime - previousTime > blinkInterval){
    // updates previousTime
    previousTime = currentTime;

   // blinkState is used throughout the entire program as a spaceholder
   if (blinkState == 1)
   {
     // turn both LED's off
     digitalWrite(led1Pin, LOW);
     digitalWrite(led2Pin, LOW);
     blinkState = 0;
   }
   else
   {
     // turn both LED's on
     digitalWrite(led1Pin, HIGH);
     digitalWrite(led2Pin, HIGH);
     blinkState = 1;
   }
  }
}

void alternateLED() {
  if (currentTime - previousTime > altInterval){
    previousTime = currentTime;
    if (blinkState == 0){
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, LOW);
      blinkState = 1;
    }
    else
    {
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, HIGH);
      blinkState = 0;
    }
  }
}

void pulseLED() {
  if (currentTime - previousTime > pulseInterval){
    previousTime = currentTime;
    if (blinkState == 0){
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, HIGH);
      blinkState = 1;
   }
    else if (blinkState == 1){
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, LOW);
      blinkState = 2;
   }
    else if (blinkState == 2){
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, LOW);
      blinkState = 3;
    }
    else
    {
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, HIGH);
      blinkState = 0;
    }
  }
}

// this function uses the internal PWM by through the analogWrite command
void fadeLED() {
  // setting the delay same as blinkLED()
  if (currentTime - previousTime > fadeInterval){
    previousTime = currentTime;
   
    // turns on LED 1 to brightness they were left off at or initial brightness set up top
    analogWrite(led1Pin, fade);
    // turns on LED 2 to the inverse brightness
    analogWrite(led2Pin, -fade);
    // Changes fade value by adding rate specified up top
    fade = fade + fadeRate;
    // when the program reaches maximum fade 0 or 255 this reverses its direction
    if (fade == 35 || fade == 255){
      fadeRate = -fadeRate ;
    }
  }
}

   
8  Using Arduino / Project Guidance / Re: Help shortening code on: September 20, 2012, 04:36:56 pm
 smiley Thanks for the help guys. Time for me to move onto an actual project. Rest assured you will be hearing from me again.

Working code:
Code:
/*
  * Simple LED Display with button to change patterns
  *
  * Everytime the button is pressed it skips to the next pattern
  *
  * Created by Cort Naab
  *
  * Circuit:
  * LED from ground to Pin 3 (w/ 220ohm resistor)
  * LED from ground to Pin 6 (w/ 220ohm resistor)
  * Button from ground to Pin 2
*/

const int buttonPin = 2; // select pin for button
int buttonCount = 0; // variable to store number of button presses
int buttonState = 1; // variable to store button state
int lastbuttonState = HIGH; // stores last button state
const int led1Pin = 3; //select led pins
const int led2Pin= 6;
int fadeRate = 5;
int blinkState = 0;
int fade = 35; //setting initial fade brightness
long previousTime = 0;
long blinkInterval = 1000;
long altInterval = 600;
long pulseInterval = 50;
long fadeInterval = 20;
unsigned long currentTime = millis();

void setup() {
   
  pinMode(buttonPin, INPUT); // Set pin mode of button
  digitalWrite (buttonPin, HIGH);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  Serial.begin(9600); // Initialize the serial com
  Serial.println("Serial is active");
}

void loop() {
  // update current time
  currentTime = millis();
  // read the current button state
  buttonState = digitalRead(buttonPin);
 
  // check to see if button state has changed
  if (buttonState != lastbuttonState) {
    // if the button state has changed and is now pressed then...
    if (buttonState == LOW) {
      buttonCount++;
      Serial.print("number of button pushes;  ");
      Serial.println(buttonCount);
    }
  }
  // Save current button state
  lastbuttonState = buttonState;
  // Set pattern to display
  switch (buttonCount) {
    case 0: blinkLED();
    case 1: alternateLED();
    case 2: pulseLED();
    case 3: fadeLED();
    case 4: buttonCount = 0;
}

void blinkLED(){
  if (currentTime - previousTime > blinkInterval){ // checks to see if the interval has passed
   previousTime = currentTime; // updates previousTime
   if (blinkState == 1)
   {
     digitalWrite(led1Pin, LOW);
     digitalWrite(led2Pin, LOW);
     blinkState = 0;
   }
   else
   {
     digitalWrite(led1Pin, HIGH);
     digitalWrite(led2Pin, HIGH);
     blinkState = 1;
   }
  }
}

void alternateLED() {
  if (currentTime - previousTime > altInterval){
    previousTime = currentTime;
    if (blinkState == 0){
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, LOW);
      blinkState = 1;
    }
    else
    {
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, HIGH);
      blinkState = 0;
    }
  }
}

void pulseLED() {
  if (currentTime - previousTime > pulseInterval){
    previousTime = currentTime;
    if (blinkState == 0){
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, HIGH);
      blinkState = 1;
   }
    else if (blinkState == 1){
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, LOW);
      blinkState = 2;
   }
    else if (blinkState == 2){
      digitalWrite(led1Pin, HIGH);
      digitalWrite(led2Pin, LOW);
      blinkState = 3;
    }
    else
    {
      digitalWrite(led1Pin, LOW);
      digitalWrite(led2Pin, HIGH);
      blinkState = 0;
    }
  }
}

void fadeLED() {
  if (currentTime - previousTime > fadeInterval){
    previousTime = currentTime;
    analogWrite(led1Pin, fade);
    analogWrite(led2Pin, -fade);
    fade = fade + fadeRate;
    if (fade == 35 || fade == 255){
      fadeRate = -fadeRate ;
    }
  }
}

   
9  Using Arduino / Project Guidance / Help shortening code on: September 20, 2012, 10:56:23 am
I just got my Arduino yesterday and this is the first code I've put together entirely myself. Everything works but I feel like the part where it's deciding which function to call could be shortened a lot, I just don't know how. Can someone let me know if it's possible and how? Another question I have is if it's in the middle of running a function the button is pressed it doesn't know. Anyway to fix that or is it just something that has to be dealt with? My goal is to have one heck of a Halloween show and I figure that gives me about a month to learn how to program it.

Code:
/*
  * Simple LED Display with button to change patterns
  *
  * Everytime the button is pressed it skips to the next pattern
  *
  * Created by Cort Naab
  *
  * Circuit:
  * LED from ground to Pin 3 (w/ 220ohm resistor)
  * LED from ground to Pin 6 (w/ 220ohm resistor)
  * Button from ground to Pin 2
*/

const int buttonPin = 2; // select pin for button
int buttonCount = 0; // variable to store number of button presses
int buttonState = 1; // variable to store button state
int lastbuttonState = HIGH; // stores last button state
const int led1Pin = 3; //select led pins
const int led2Pin= 6;

void setup() {
   
  pinMode(buttonPin, INPUT); // Set pin mode of button
  digitalWrite (buttonPin, HIGH);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  Serial.begin(9600); // Initialize the serial com
  Serial.println("Serial is active");
}

void loop() {
  // read the current button state
  buttonState = digitalRead(buttonPin);
 
  // check to see if button state has changed
  if (buttonState != lastbuttonState) {
    // if the button state has changed and is now pressed then...
    if (buttonState == LOW) {
      buttonCount++;
      Serial.print("number of button pushes;  ");
      Serial.println(buttonCount);
    }
  }
  // Save current button state
  lastbuttonState = buttonState;
  // Set pattern to display
  if (buttonCount == 0) {
    blinkLED();
  }
  if (buttonCount == 1) {
    alternateLED();
  }
  if (buttonCount == 2) {
    pulseLED();
  }
  if (buttonCount == 3) {
    buttonCount = 0;
  }
}

void blinkLED() {
  digitalWrite(led1Pin, HIGH);
  digitalWrite(led2Pin, HIGH);
  delay(1000);
  digitalWrite(led1Pin, LOW);
  digitalWrite(led2Pin, LOW);
  delay(1000);
}

void alternateLED() {
  digitalWrite(led1Pin, HIGH);
  digitalWrite(led2Pin, LOW);
  delay(1000);
  digitalWrite(led1Pin, LOW);
  digitalWrite(led2Pin, HIGH);
  delay(1000);
}

void pulseLED() {
  digitalWrite(led1Pin, HIGH);
  digitalWrite(led2Pin, HIGH);
  delay(50);
  digitalWrite(led1Pin, LOW);
  digitalWrite(led2Pin, LOW);
  delay(50);
  digitalWrite(led1Pin, HIGH);
  digitalWrite(led2Pin, LOW);
  delay(50);
  digitalWrite(led1Pin, LOW);
  digitalWrite(led2Pin, HIGH);
  delay(50);
}
10  Using Arduino / Audio / Audio Playback for Halloween Show on: September 19, 2012, 09:55:41 am
I am trying to put together a Halloween robot that's motion activated. If possible I'd really like to add a voice to it but to be honest I'm still trying to figure out the lighting and motors for it. Has anyone purchased a cheap voice recorder from target and hacked into the "play" button? Seems to be this would be a quick and easy way to get voice and allow me to focus on the rest of the project.

If that sounds dumb please help me on a good way to give my robot a voice that would be relatively simple to setup.
Pages: [1]