Needs more outputs

Hi all.

This is my first post here. I am in need of some help. I done a small home automation using arduino duemilanove but this is not enough for me since I need more outputs. As I said, need of more outputs, I know that this could be solved by using 2 arduino communicating together but for now I went for the easy way, bought the Arduino Mega. I managed to finalize some coding with the help of google on the duemilanove but I found a problem when I tried to use the same coding for the Arduino Mega. What could be the problem?

In this Post I have included the open source programming of Arduino IDE and processing. If someone could point me out what could be the problem why Arduino Mega is not working with the same code I appreciate a lot.

Is there any other type of programming that I need to do?

Take a look below arduino IDE programming!

int message = 0; // This will hold one byte of the serial message
int redLEDPin = 13; // What pin is the red LED connected to?
int greenLEDPin = 12; // What pin is the green LED to?
int blueLEDPin = 11; // What pin is the blue LED to?
int yellowLEDPin = 10; // What pin is the yellow Led to?
int violetLEDPin = 9; // What pin is the violet Led to?
int redLED = 0; // The value/brightness of the LED, can be 0-255
int greenLED = 0; // The value brightness of the LED, can be 0-255
int blueLED = 0; // The value brightness of the LED, can be 0-255
int yellowLED = 0; // The value brightness of the LED, can be 0-255
int violetLED = 0; // The value brightness of the LED, can be 0-255

void setup() {
Serial.begin(9600); //set serial to 9600 baud rate
}

void loop(){
if (Serial.available() > 0) { // Check if there is a new message
message = Serial.read(); // Put the serial input into the message

if (message == 'R'){ // If a capitol R is received...
redLED = 255; // Set redLED to 255 (on)
}
if (message == 'r'){ // If a lowercase r is received...
redLED = 0; // Set redLED to 0 (off)
}

}
analogWrite(redLEDPin, redLED); // Write an analog value between 0-255

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'G'){ // If a capitol R is received...
greenLED = 255; // Set greenLED to 255 (on)
}
if (message == 'g'){ // If a lowercase r is received...
greenLED = 0; // Set greenLED to 0 (off)
}
analogWrite(greenLEDPin, greenLED); // Write an analog value between 0-255

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'B'){ // If a capitol R is received...
blueLED = 255; // Set blueLED to 255 (on)
}
if (message == 'b'){ // If a lowercase r is received...
blueLED = 0; // Set blueLED to 0 (off)
}
analogWrite(blueLEDPin, blueLED); // Write an analog value between 0-255

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'Y'){ // If a capitol R is received...
yellowLED = 255; // Set yellowLED to 255 (on)
}
if (message == 'y'){ // If a lowercase r is received...
yellowLED = 0; // Set yellowLED to 0 (off)
}

analogWrite(yellowLEDPin, yellowLED); // Write an analog value between 0-255

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (message == 'V'){ // If a capitol R is received...
violetLED = 255; // Set violetLED to 255 (on)
}
if (message == 'v'){ // If a lowercase r is received...
violetLED = 0; // Set violetLED to 0 (off)
}
analogWrite(violetLEDPin, violetLED); // Write an analog value between 0-255

}

//Processing programming part

import oscP5.; // Load OSC P5 library
import netP5.
; // Load net P5 library
import processing.serial.*; // Load serial library

Serial arduinoPort; // Set arduinoPort as serial connection
OscP5 oscP5; // Set oscP5 as OSC connection

int redLED = 0; // redLED lets us know if the LED is on or off
int greenLED = 0; // greenLED lets us know if the LED is on or off
int blueLED = 0; // blue LED lets us know if the LED is on or off
int yellowLED = 0; // yellow LED lets us know if the LED is on or off
int violetLED = 0; // violet LED let us know if the LED is on or off
int [] led = new int [6]; // Array allows us to add more toggle buttons in TouchOSC

void setup() {
size(800,100); // Processing screen size
noStroke(); // We don’t want an outline or Stroke on our graphics
oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000
arduinoPort = new Serial(this, Serial.list()[0], 9600); // Set arduino to 9600 baud
}

void oscEvent(OscMessage theOscMessage) { // This runs whenever there is a new OSC message

String addr = theOscMessage.addrPattern(); // Creates a string out of the OSC message
if(addr.indexOf("/1/toggle") !=-1){ // Filters out any toggle buttons
int i = int((addr.charAt(9) )) - 0x30; // returns the ASCII number so convert into a real number by subtracting 0x30
led* = int(theOscMessage.get(0).floatValue()); // Puts button value into led*
* // Button values can be read by using led[0], led[1], led[2], etc.*

* }*

}
void draw() {
background(200); // Sets the background to a dark grey, can be 0-255
* if(led[1] == 0){ // If led button 1 if off do....*
* arduinoPort.write("r"); // Sends the character “r” to Arduino*
* redLED = 0; // Sets redLED color to 0, can be 0-255*
* }*
if(led[1] == 1){ // If led button 1 is ON do...
* arduinoPort.write("R"); // Send the character “R” to Arduino*
* redLED = 255; // Sets redLED color to 255, can be 0-255*
* }*
fill(redLED,70,5); // Fill rectangle with redLED amount
* ellipse(50, 50, 50, 50); // Created an ellipse at 50 pixels from the left...*
* // 50 pixels from the top and a width of 50 and height of 50 pixels*

* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////*

if(led[2] == 0){ // If led button 1 if off do....
* arduinoPort.write("g"); // Sends the character “r” to Arduino*
* greenLED = 0; // Sets redLED color to 0, can be 0-255*
* }*
if(led[2] == 1){ // If led button 1 is ON do...
* arduinoPort.write("G"); // Send the character “R” to Arduino*
* greenLED = 255; // Sets redLED color to 255, can be 0-255*
* }*
fill(greenLED,70,5); // Fill rectangle with greenLED amount
* ellipse(150, 50, 50, 50); // Created an ellipse at 50 pixels from the left...*
* // 50 pixels from the top and a width of 50 and height of 50 pixels*

* /////////////////////////////////////////////////////////////////////////////////////////////////////////////*

if(led[3] == 0){ // If led button 1 if off do....
* arduinoPort.write("b"); // Sends the character “r” to Arduino*
* blueLED = 0; // Sets redLED color to 0, can be 0-255*
* }*
if(led[3] == 1){ // If led button 1 is ON do...
* arduinoPort.write("B"); // Send the character “R” to Arduino*
* blueLED = 255; // Sets redLED color to 255, can be 0-255*
* }*
fill(blueLED,70,5); // Fill rectangle with greenLED amount
* ellipse(250, 50, 50, 50); // Created an ellipse at 50 pixels from the left...*
* // 50 pixels from the top and a width of 50 and height of 50 pixels*

* ////////////////////////////////////////////////////////////////////////////////////////////////////////////*
if(led[4] == 0){ // If led button 1 if off do....
* arduinoPort.write("y"); // Sends the character “r” to Arduino*
* yellowLED = 0; // Sets redLED color to 0, can be 0-255*
* }*
if(led[4] == 1){ // If led button 1 is ON do...
* arduinoPort.write("Y"); // Send the character “R” to Arduino*
* yellowLED = 255; // Sets redLED color to 255, can be 0-255*
* }*
fill(yellowLED,70,5); // Fill rectangle with greenLED amount
* ellipse(350, 50, 50, 50); // Created an ellipse at 50 pixels from the left...*
* // 50 pixels from the top and a width of 50 and height of 50 pixels*

* ////////////////////////////////////////////////////////////////////////////////////////////////////////////*
if(led[5] == 0){ // If led button 1 if off do....
* arduinoPort.write("v"); // Sends the character “r” to Arduino*
* violetLED = 0; // Sets redLED color to 0, can be 0-255*
* }*
if(led[5] == 1){ // If led button 1 is ON do...
* arduinoPort.write("V"); // Send the character “R” to Arduino*
* violetLED = 255; // Sets redLED color to 255, can be 0-255*
* }*
fill(violetLED,70,5); // Fill rectangle with greenLED amount
* ellipse(450, 50, 50, 50); // Created an ellipse at 50 pixels from the left...*
* // 50 pixels from the top and a width of 50 and height of 50 pixels*
}

What isn't working? I hooked up a green LED to pin 12 on an UNO and ran your Arduino code as is and could control it from the serial monitor. Then I switched the IDE to Mega 2560 and ran it on my mega; it worked exactly the same, so I don't think the Mega itself is the problem.

Hello wildbill.

I tried another example such as blink Led on the duemilanove and than swapped the IDE to Mega and this worked ok with the example. But when I use the below programming the Mega doesnt work. Very strange. Could be that the oscP5 Library doesnt match for the Mega. With the duemilanove using iphone worked flawless and I'm happy, but now I am limited in outputs and I need an upgrade :slight_smile:

Jason

If you're just needing more digital outputs, why not use shift registers? There's also a shield out there there called the centipede shield that will give you 64 digital pins to work with.