Networking and Communications

My final project is a RGB Lamp made in concrete, was designed to work as a Output device in networking regulated by two inputs. The inputs idea is to dim ligth intensity and change the RGB color game, for this I am using two potentiometers. There are five Output devices which four are rows of five RGB LED’s and one that only has one RGB LED, this one is on charge of the communication between all.

Boards Design and production

I designed the Boards using Eagle, and all the components are from the Fab Inventory so if you want to make yours have a look to the list below and the fab inventory. Just in case to double check info updates of the components because the list is constantly being updated.

The RGB LED’S used work with 5V and there is a power regulator of 4.7V that protects the components in case to receive more power than the accepted. The LED’s are using 499 resistor for green and blue color, and for red color two 499 resistor one over the other to cruze them and create the half of the power that requires. Programing is made through the 6 PIN HEADER and Power, RX and TX with the 4 PIN HEADER.

Then I proceed to mill them with the Roland Modela using bits of 1/64 for traces and 1/32 for cut it, once were ready I soldered all the boards and then they were ready to program.

Final Project files

Programing

For programing the four lighting boards I am using Arduino IDE, the program consist in turn on/off the RGB game of colors (white, red, green, blue, yellow, cyan, magenta) and one set that fades the whole color game. So the boards function when they are connected to the power, but they were designed to be slave by the bridge which has connected the power supply, and two potentiometers that one dims the light intensity and other for change the color set program.

I need two different codes: first for the ATTINY 45 Nodes and second for ATTINY 44 Master.

The ATTINY 45 Node Code


/* Attiny45a co. nod rgb led lighting system


created 2014
by Juan Esteban Vallejo (with Andrew Leek)
*/

#include
SoftwareSerial mySerial(3, 4); // RX, TX

// constants won't change.
// They're used here to set pin numbers:
const int ledRed = 1; // red
const int ledGreen = 0; // green
const int ledBlue = 2; // blue


int colorNumber = 0;
int intensityNumber = 0;

PROGMEM prog_uchar color_table[6][3] =
{
{1, 1, 0},
{0, 1, 0},
{0, 1, 1},
{0, 0, 1},
{1, 0, 1},
{1, 0, 0}
};

void setup() {
mySerial.begin(4800);

// initialize the LED pin as an output:
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);
}

void loop(){

while (mySerial.available() > 0)
{
colorNumber = mySerial.parseInt();
intensityNumber = mySerial.parseInt();

if (mySerial.read() == '\n')
{
//Do nothing
}
}

int redValue = pgm_read_byte_near ( &(color_table[colorNumber][0]) );
int greenValue = pgm_read_byte_near ( &(color_table[colorNumber][1]) );
int blueValue = pgm_read_byte_near ( &(color_table[colorNumber][2]) );

if(intensityNumber > 900)
{
intensityNumber = 900;
}

if(intensityNumber > 0)
{
digitalWrite(ledRed, redValue);
digitalWrite(ledGreen, greenValue);
digitalWrite(ledBlue, blueValue);

delayMicroseconds(intensityNumber);

digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledBlue, HIGH);

delayMicroseconds(1000 - intensityNumber);
}

}

The circuits are going to be connected in networking slaved by the main board that receives input commands, so I used the SoftwareSerial library that allows serial communication to define the RX TX. Inputs are analog potentiometers, the turning is divided by the number of steps that the program requires. First dims the light from 0 which is off to highest light intensity and second change to 7 seven colors.

All the functions I want to have in the Lamp exceeds the microprocessor memory, so my colleague Andrew Leek advised me to run the program with a variable modifier from Arduino called PROGMEN to save memory and run a lighter program.

I declared the pins RGB LED colors are using and then used the next code to define the colors I want the LEDs combination produce (red, green, blue, cyan, magenta, yellow, white), this action is saving enough memory to have the rest of the program.


PROGMEM prog_uchar color_table[6][3] =
{
{1, 1, 0},
{0, 1, 0},
{0, 1, 1},
{0, 0, 1},
{1, 0, 1},
{1, 0, 0}
};

The ATTINY 44 Bridge Code


/* Attiny44a co. bridge networking 1 rgb led


created 2014
by Juan Esteban Vallejo (with Andrew Leek)
*/

#include
SoftwareSerial mySerial(3, 2); // RX, TX

// constants won't change.
// They're used here to set pin numbers:
const int ledRed = 10; // red
const int ledGreen = 9; // green
const int ledBlue = 8; // blue

const int potPin1 = 0; // select the input pin for the potentiometer
const int potPin2 = 1; // select the input pin for the potentiometer

PROGMEM prog_uchar color_table[6][3] =
{
{1, 1, 0},
{0, 1, 0},
{0, 1, 1},
{0, 0, 1},
{1, 0, 1},
{1, 0, 0}
};

void setup() {

// initialize the LED pins as an output:
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledBlue, OUTPUT);

// initialize the potentiometer pins as an input:
pinMode(potPin1, INPUT);
pinMode(potPin2, INPUT);

// Open serial communications and wait for port to open:
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
//mySerial.println("Hello, world?");
}

void loop(){

int colorPot = analogRead(potPin1); // read the value from the sensor
int intensityPot = analogRead(potPin2); // read the value from the sensor

int colorNumber = (colorPot/204); //1023/5 = 204 (6 pieces = 6 colors)
int intensityNumber = intensityPot; //1023/5 = 204 (6 pieces = 6 colors)

mySerial.print(colorNumber, DEC);
mySerial.print(',');
mySerial.println(intensityNumber, DEC);

int redValue = pgm_read_byte_near ( &(color_table[colorNumber][0]) );
int greenValue = pgm_read_byte_near ( &(color_table[colorNumber][1]) );
int blueValue = pgm_read_byte_near ( &(color_table[colorNumber][2]) );

if(intensityNumber > 900)
{
intensityNumber = 900;
}

if(intensityNumber > 0)
{
digitalWrite(ledRed, redValue);
digitalWrite(ledGreen, greenValue);
digitalWrite(ledBlue, blueValue);

delayMicroseconds(intensityNumber);

digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledBlue, HIGH);

delayMicroseconds(1000 - intensityNumber);
}
}


Summering both codes do the same program, what changes is the microprocessors (ATTINY 44/45):
-Change the light intensity
-Change to 7 different RGB colors
-Turn ON/OFF