text:
Being able to run two functions at once
So I am doing a project where a bunch of servos are moving from 90 - 120 degrees and slowly speed up over time until they reach their max speed and so stay at that speed.
This is being done by editing the delay under the servo sweep for loop.
However though this works it doesn't work with the next component.
WHat I want to happen next is an MFRC522 RFID reader to always be scanning and at any time it detects a card and verifies it the servos from whatever speed they are now at start to slow down.
The problem is I can't get the two functions to run simultaneously. IF the servo is running its sweep function it must finish before the RFID tag can scan. This makes the whole device look very lagy.
Is there a way I can get the RFID scanner to be reading all the time even when the servo sweep for loop is working?
Here is the code:
Please note that I have put printins everywhere to see how often the RFID is scanning etc just while I test the code out.
I essentially have two functions one called nocardservo and yescardservo each one activating if there is a card there or not.
Any help would be fantastic!!
#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>

#define RST_PIN     9       //
#define SS_PIN      10      //

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

Servo myservo;
int pos = 0;
int y = 15;
int z = y;
void setup() {
  myservo.attach(6);
  myservo.writeMicroseconds(1518);
  Serial.begin(9600);       // Initialize serial communications with the PC
  while (!Serial);      // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();       // Init MFRC522
  //ShowReaderDetails();    // Show details of PCD - MFRC522 Card Reader details
  //Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
}

void loop() {
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
nocardservo();
    return;
  }
  delay(20);
  Serial.println("carddetected");
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {

  }
  Serial.println("correctcard");
  yescardservo();
delay(20);
return;
}

//***If card not detected this function runs**//

void nocardservo() {

  for (pos = 90; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
  { // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 90; pos -= 1) // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);

  }
}
}

//***If card is detected this function runs**//

void yescardservo() {

  for (pos = 90; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
  { // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(50);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 90; pos -= 1) // goes from 180 degrees to 0 degrees
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(50);

  }

}

The "secret" is in the use of the millis() function which allows you to take a snapshot of the current time and compare it to a later time . This is how JamesG referenced 'Blink Without Delay' achieves its result.Note that any copies of the value of millis()  must be stored in an "unsigned long" variable and use of eg "long" as in the previousMillis() save in the 'Blink Without Delay' example will cause errors in some cases.

What you want to implement is described in Blink Without Delay.  Basically, instead of using the delay function to just wait until your time has elapsed, you use variables to measure how much time has elapsed and only execute your operation when it has.  In the mean time, you can check on other things and do those in the mean time.

Good reference. Comment only: Note that any copies of the value of millis()  must be stored in an "unsigned long" variable and use of eg "long" as in the previousMillis() save in the 'Blink Without Delay' example will cause errors in some cases.

have a look my example program below for you reference.
/*
 * Author BALASAIDULU.N
 * function -1 : Fading led with pwm pin 9
 * fucntion -2 : Blinking LED on pin 13
 * connect an LED on pin 9 with a 330 ohms resistor
 */
     int leda=9;
     int ledd=13;
int i,g,s1,s2;
int switchPin=8;

void setup() {
pinMode(ledd,OUTPUT);
pinMode(switchPin,INPUT);
}

void fading()
{
  st:
  if(s1==0){
if(s1==1){goto hy;}
analogWrite(leda,i);
delay(30);
i+=5;
if(i>255){s1=1;}
goto st1;
  }
hy:

if(i<0){s1=0;goto st;}
i-=5;
analogWrite(leda,i);
delay(30);
 st1:
delay(10);
}

void blinking()
{
digitalWrite(ledd,HIGH);
delay(30);
digitalWrite(ledd,LOW);
delay(30);

}
void loop() {

int g;
g=digitalRead(switchPin);
if(g==1) {delay(50);}
if(g==0){
blinking();
fading();}
}

What is wrong with using goto: https://stackoverflow.com/questions/3517726/what-is-wrong-with-using-goto


text:
Can I hook up a compass directly to my GPS module?
I have a Parallax PMB-688 GPS module I'm using with an Arduino and was wondering if I could hook up a compass directly to my GPS. The GPS has an RX port which I hypothesized a compass could be attached to but I don't know if the GPS would be able to comprehend the compass data alone or if I would need to hook it up to the Arduino separately. Please let me know if you have done this or know whether or not it will work. Thanks,
Chris

Unfortunately this will not work. If you take a look at the documentation for the module (here and here) you'll see that the RX pin is just there to receive commands for doing things like changing the baud rate and the protocol. The GPS wouldn't be able to comprehend the compass data.

Thanks, this was really helpful. I should have checked the documentation before asking the question.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
7segment blink when the button is pressed
I have programmed an IR remote control along with an LED and an 8bit 7segment on an Arduino Uno.
the segment displays the number I press via the remote, and the LED turns on and off
here's my code:
case 16738455:
  Serial.println(0);
  if (oldvalue == results.value){
    on(num0);
    delay(1000);
    on(num00);
    delay(1000);
    oldvalue = results.value;
  }

oldvalue stores the last value pressed, which is the DEC value of the buttons, num0 displays the number zero, and num00 turns all the segments off.
I want the 7segment to blink again when I press the same button again.
Can anyone help me with this?
Thanks

You have to provide more code if you want some help. What is the code for the on function? What else is inside your loop() function?

The code is long, this is the dropbox link to it:
https://www.dropbox.com/s/haw498jlwmol75z/IRwith7segment.ino

Please put it on pastebin - dropbox is too transient.

http://pastebin.com/9iYgyrd5

A simple solution would be to not worry about blinking as a piece of code, ie. remove those delays (I hate blocking code) and instead, if you are currently receiving a signal from the remote, do not display any number (or display your num00). Once the value is received and processed, then display that number.
This way, whilst ever the remote button is down, the display will blank out, and the number will appear as soon as the number is released. If it's the same number, then you will see the number, see a blank display, and then see the same number again. Obviously, if it's a different number, the new number would be displayed.
Since most people would only press the remote button for 100-1500ms, it should give you a nice delay anyway.
Finally, you may encounter some flashing if you process the data so quickly and the remote auto repeats. This could be handy if that number is processed multiple times by the receiving unit. The flashing would indicate that that is the case. If that is undesired, implement a simple state machine.
edit: your pastebin code came up whilst I was writing this answer. Having a quick look at your code, I would suggest that in the section:
if (irrecv.decode(&results)) {
  //receiving data? display nothing
  on(num00);
  digitalWrite(ledPin, HIGH);
  Serial.println(results.value, DEC);
  irrecv.resume();
  delay(100);
  int oldvalue = results.value;
  switch(results.value){
    case 16738455:
      Serial.println(0);
      num2display=0;      // make sure to declare this var somewhere
      //if (oldvalue == results.value){
      //  on(num0);
      //  delay(1000);
      //  on(num00);
      //  delay(1000);
      //} else {   // I think you missed an else here
      //  oldvalue = results.value;
      //}
      //on(num0);
      //delay(1000); // you don't want such large blocking delays
      irrecv.resume();
      break;
    case 16724175:
      Serial.println(1);
      num2display=1;       // add this for each section
      irrecv.resume();
      break;
      . . .
  }
}
else{
  digitalWrite(ledPin, LOW);
  on(num2display);
}

you only set the variable to be displayed, but display num00. Then in the else, you can display that number

Responding to a button being released is a little tricky with IR remotes. Unlike a physical button, you don't get a steady signal while the remote button is held. Rather, you get a repeating signal, which could end up looking like lots of presses in quick succession.

@PeterR.Bloomfield I did think of that after the fact (or towards the end of the answer), but that could be easily avoided: you would know the pause between transmissions, set a timeStart flag, and don't display before timeStart+timeLag. Resetting this at the beginning of each new repeated burst would ensure it only appears at the end of the transmission.

Thank you for your help Madivad
With all respect but I don't think you understood the code well
Here's the youtube link to it's video and what it does:
link
When I press a button, the 7segment displays that number, but what I want is, when I press the same button twice, the 7segment should blink in the second time, all the segments turn off and on again

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Intermittent jittering servo
I'm controlling a Hitech HS-625MG servo from a 10k slider via a Nano. For a while the motion tracks the slider position even when moved quickly.
Then, for no reason I can find, it will stop following smoothly & only move in jittery steps & then move as expected again!
The code is cut & paste from the pot-servo example..
#include <Servo.h>

Servo myservo_1;  // create servo object to control a servo

int potpin_1 = A0;  // analog pin used to connect the potentiometer

int val_1;    // variable to read the value from the analog pin

void setup() {
  myservo_1.attach(7);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val_1 = analogRead(potpin_1);             // reads the value of the potentiometer (value between 0 and 1023)

  val_1 = map(val_1, 0, 1023, 0, 180);      // scale it to use it with the servo (value between 0 and 180)

  myservo_1.write(val_1);                   // sets the servo position according to the scaled value

  delay(15);                                // waits for the servo to get there
                                            // have tried values ranging from 5 to 25 same behaviour
}

YouTube vid of the behaviour
Anyone seen this kinda thing before?
EDIT: That is the full code listing & here's the circuit diagram, the same as the knob example frome the Servo examples page except the servo is not being powered by the Nano but is sharing the same power supply. (sorry not next to it at the moment)

We see it all the time. Probably not enough power for the servo motor. Please update your question and show your full sketch and tell how the potentiometer and servo motor is connected or show a schematic.

@Jot have edited the OP. Would a cap across the wiper and ground help?

If you are between working and not-working, then a capacitor might help. I prefer to fix the cause. That the not a full sketch, the loop function is missing a '}' at the end. Did you connect the arduino gnd to the power supply gnd? What kind of power supply is it? 5v 1a ? Please tell us what kind of servo motor it is, can you also give a link to it? A week or so ago, someone had a servo motor that could request more than 2a, it didn't work and a small servo motor was okay.

edited the code. Arduino, wiper & servo (hitec HAS625MG) share the same power rails, V+ = 12v

That is not a 12v servo motor. That servo motor needs 4.8 to 6v, as most servo motors do. That servo motor is fast and has power, and its stall current is 2.5 amps according to this: https://hitecrcd.com/products/servos/sport-servos/analog-sport-servos/hs-625mg/product therefor you need a power supply of 5v 2.5a for the servo motor. This is indeed a power issue that we see all the time.

I feel like an idiot, thankyou its all working now. It might be worth putting this down as a proper answer and using it as a refernece post for when this issue is asked about again?

A servo motor requires a lot of current.
Many have problems when using a servo motor. Sometimes it works a few seconds and then it starts to jitter or it moves a little and then stops or it does nothing and makes a small click noise.
The problem is that servo motors requires a lot of current. Even the small servo motors can require a peak current of 0.5 A. Larger, stronger, and faster servo motors can easily request a peak of a few Amps.
To find the maximum current for the servo motor, look at the stall current of the servo motor.
When a servo starts to turn, it needs a short peak current. That peak current can be near the stall current.
Don't buy a "strong" and "fast" servo motor.
That may sound appealing, but it is better to start with a humble and timid servo motor.
The servo motors have a DC motor with gears inside. Because of the gears it is already strong.
Use a power supply of 5V with enough Amps to be able to supply the stall current of the servo motor.
Use that power supply to power the servo motor (the red wire).
Connect the GND of the power supply to the GND of the servo motor (the black wire) and the GND of the Arduino board.
The 5V pin of the Arduino board can not supply enough power for a servo motor.
It is in the official Arduino examples, but many run into problems with not enough power.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Is it better to use c_str or toCharArray?
When reading/trying a recent answer, I was surprised to see that Arduino's String class supports the c_str() method, just like the C++ std::string class. As expected, it appears to get a pointer to the string's contents as a null-terminated char array (i.e. C-style string).
However, (as far as I can see) that method is not mentioned in the official Arduino documentation. Additionally, in all example code I've seen using String, a different approach seems to be used. A secondary char buffer is setup, and then the contents of the string are copied to it using String::toCharArray(). This obviously requires double the memory, plus an O(n) copy operation.
It seems like c_str() should be the preferred approach. Is there some reason why toCharArray() is more commonly used?

Because new Arduino users don't want to branch out

Re "that method is not mentioned in the official Arduino documentation": It is available now: c_str()

It seems like c_str() should be the preferred approach. Is there some reason why toCharArray() is more commonly used?

basically, I'd say it's a lack of knowledge from the people doing the codes you've seen. Definitely c_str() is better. Though, what I see even more often is the use of character arrays char* strings instead of String (and I plead guilty of that as well in my own codes).
And that's because the Arduino library has been built upon a messy set of C and C++ libraries and coding style. Trying to make things easier actually messed them up and complicated them more.
That's actually why we have new projects like xpcc trying to make a real and smart use of the C++ abilities in the embedded world.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
attiny85 and arduino - analogRead + pwmOut
I am using the Arduino IDE to program the attiny85. I want to take an incoming analog reading, then based on that reading, output a specific PWM value. Here's my circuit:

and here's my code:
// to run on attiny85

const byte pwmPin = 0;
const byte analogInPin = A2;

void setup() {
  pinMode(pwmPin, OUTPUT);
}

void loop() {
  int analogIn = analogRead(analogInPin);
  analogWrite(pwmPin, analogIn);
}

should be very simple- I have no problems uploading code to the attiny85, and no problems with simple tests like outputting a specific PWM value (not based on the analog read). but when I try to combine the two- read, then write that value, I can't seem to get things to work. In this circuit for example- I get a reading of 1023 (5v) on the arduino micro- instead of a reading of ~ 790 (3.85v) which is what I should expect. I've used a multimeter to verify the voltages in this circuit- so I think I must either be doing something wrong with my expectations of how to wire up or program the attiny85.

A schematic of your circuit would probably be more helpful than an implementation schema with a breadboard. Do you have such a schematic? If yes, add it to your question.

I don't see any clock (quartz or ceramic resonator) for your ATtiny, is this normal?

@jfpoilpret yeah you have a few choices for using the internal clock.

Did you try to add a short delay in your loop? What may happen is that your loop is running too fast, and each new analogWrite() call would "reset" the PWM of the pin, making it always up (no time to use PWM). I would try delay(1000) for a start.

Did your multimeter read 3.85v after the low pass filter? (so right on the Micro's input pin)

i needed to re-range the input to 8 bit. analogIn = map(analogIn, 0, 1023, 0, 255);

it works fine. btw i am using the internal 8mhz - attiny85. also using arduino-tiny core. thanks for all your suggestions.

just to clarify - the adc input on the attiny85 is 10bit. the pwm output is 8bit. thus the map().

@GradeSchool It would be helpful if you could write your solution as an actual answer, so that future visitors can find it more easily. Thanks!

i tried to do that, but this site won't let me for like 8 more hours. i will do so as soon as i can.

Could you throw in some capitals in your text to improve readability? Also a proper circuit diagram, rather than a wiring diagram would help a lot.

Analog read is 10-bits (2^10 = 0-1023 range), analog write is 8-bits (2^8 = 0-255 range). Ditch the lower two bits of the result either by doing:
analogIn = analogIn >> 2;

which can be shortened to:
analogIn >>= 2;

Or you can use the rather complex map function:
analogIn = map( analogIn(0, 1023, 0, 255) )

Sorry, didn't see the answer in the comments.

+1 Not a problem. It's good to have it all spelled out in a proper answer anyway.

i needed to re-range the 10bit input to 8 bit for the pwm out.
// to run on attiny85

const byte pwmPin = 0;
const byte analogInPin = A2;

void setup() {
}

void loop() {
  pinMode(pwmPin, OUTPUT);
  int analogIn = analogRead(analogInPin);
 analogIn = map(analogIn, 0, 1023, 0, 255);
 analogWrite(pwmPin, analogIn);
}

the map function takes a lot of clock cycles compared to the bitshift describes in Cybergibbons' answer.


text:
Setting up the MMA8452 to trigger interrupt
I am working with the MMA8452q accelerometer by Freescale.  I am trying to set it up to be in low power mode, to go to sleep when no motion has happened, and to wake up due to motion being detected and trigger the  interrupt that corresponds to it.  I am using Arduino.
I have verified the accelerometer works (i.e. can read off accelerometer data and communicate properly to it via I2C), and I have also verified that the interrupt and handler all work (by manually triggering the interrupt as compared to using the accelerometer).  However, after initializing using the code below, my interrupt due to motion is not getting triggered.
-The datasheet can be found here: http://www.freescale.com/files/sensors/doc/data_sheet/MMA8452Q.pdf
-App note can be found here: http://cache.freescale.com/files/sensors/doc/app_note/AN4074.pdf
My code is as follows:
void MMA8452::initMMA8452(unsigned char fsr)
{
    //CONFIGURE THE ACCELEROMETER
    MMA8452Standby();  // Must be in standby to change registers

    //Set up the full scale range to 2, 4, or 8g.
    if ((fsr==2)||(fsr==4)||(fsr==8))
        writeRegister(XYZ_DATA_CFG, fsr >> 2);
    else
        writeRegister(XYZ_DATA_CFG, 0);

    writeRegister(CTRL_REG1, readRegister(CTRL_REG1) | bmRES1DOT56);  //1.56Hz resolution in both wake and sleep mode (lowest power)
    writeRegister(CTRL_REG2, readRegister(CTRL_REG2) | (LP << SMODS) | (LP << MODS) | (1 << SLPE));  //LOW POWER MODE IN SLEEP & ACTIVE STATES WITH LOWEST SAMPLING

    writeRegister(CTRL_REG3, (1 << WAKE_FF_MT));        //ONLY WAKE UP FROM MOTION DETECTION
    writeRegister(CTRL_REG4, (1 << INT_EN_ASLP) | (1 << INT_EN_FF_MT));  //ENABLE SLP/AWAKE INTERRUPT (INTERRUPT THROWN WHENEVER IT CHANGES) & MOTION INTERRUPT TO KEEP AWAKE
    writeRegister(ASLP_COUNT, ASLP_TIMEOUT);    //162s TIMEOUT BEFORE SLEEPING

    writeRegister(CTRL_REG5, (1 << INT_CFG_FF_MT) | (1 << INT_CFG_ASLP));  //INTERRUPT SLEEP AND FREE FALL TO INT1 PIN OF MMA8452

    //SETUP THE MOTION DETECTION
    writeRegister(FF_MT_CFG, (1 << ELE) | (1 << OAE));      //MOTION DETECTION AND LATCH THE RESULT WHEN IT HAPPENS AS OPPOSED TO COMBINATIONAL REAL TIME
    writeRegister(FF_MT_THS, MOTION_THRESHOLD);             //MOTION DETECTION THRESHOLDS
    writeRegister(FF_MT_COUNT, MOTION_DEBOUNCE_COUNT);      //TIME MOTION NEEDS TO BE PRESENT ABOVE THE THRESHOLD BEFORE INTERRUPT CAN BE ASSERTED

    MMA8452Active();
};

I played around more with it, and this code works:
void MMA8452::initMMA8452(unsigned char fsr, unsigned char dr, unsigned char sr, unsigned char sc, unsigned char mt, unsigned char mdc)
{
    MMA8452Standby();

//Set up the full scale range to 2, 4, or 8g.
if ((fsr==2)||(fsr==4)||(fsr==8))
    writeRegister(XYZ_DATA_CFG, fsr >> 2);
else
    writeRegister(XYZ_DATA_CFG, 0);

writeRegister(CTRL_REG1, readRegister(CTRL_REG1) & ~(0xF8));
if (dr<= 7)
    writeRegister(CTRL_REG1, readRegister(CTRL_REG1) | (dr << DR0));
if (sr<=3)
    writeRegister(CTRL_REG1, readRegister(CTRL_REG1) | (sr << ASLP_RATE0));

writeRegister(CTRL_REG2, readRegister(CTRL_REG2) | (LP << SMODS) | (LP << MODS) | (1 << SLPE));  //LOW POWER MODE IN SLEEP & ACTIVE STATES WITH LOWEST SAMPLING
writeRegister(ASLP_COUNT, sc);

// Set up interrupt 1 and 2: 1 = wake ups, 2 = data
writeRegister(CTRL_REG3, (1 << WAKE_FF_MT) | (1 << IPOL));  // Active high, push-pull interrupts, sleep wake up from motion detection
writeRegister(CTRL_REG4, (1 << INT_EN_ASLP) | (1 << INT_EN_FF_MT) |  (1 << INT_EN_DRDY));  // DRDY ENABLE SLP/AWAKE INTERRUPT (INTERRUPT THROWN WHENEVER IT CHANGES) & MOTION INTERRUPT TO KEEP AWAKE
writeRegister(CTRL_REG5, (1 << INT_CFG_ASLP) | (1 << INT_CFG_FF_MT));  // DRDY on INT1, ASLP_WAKE INT2, FF INT2
writeRegister(CTRL_REG5, readRegister(CTRL_REG5));

//SETUP THE MOTION DETECTION
writeRegister(FF_MT_CFG, 0xF8);     /*MOTION DETECTION AND LATCH THE
                                    //RESULT WHEN IT HAPPENS AS OPPOSED
                                    //TO COMBINATIONAL REAL TIME*/
    writeRegister(FF_MT_THS, mt);       //MOTION DETECTION THRESHOLDS
    writeRegister(FF_MT_COUNT, mdc);    //TIME MOTION NEEDS TO BE
                                        //PRESENT ABOVE THE THRESHOLD BEFORE INTERRUPT CAN BE ASSERTED

    MMA8452Active();
}


text:
how to know which pin is being used, change pin?
i am having an issue where i am unsure how my device knows what pins its using. Version #1 is a timeclock which is simply declared with no pin numbers. Version #2 is a simple loop with a device on pin A0;
So how can i set / change the pins for the clock to use. Currently it is on A4 & A5.
If i wanted to move the clock to say pins.. A1 and A2, how would i do that?
Thanks
Version #1-------------------------------------------------
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();

  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
 //   RTC.adjust(DateTime(__DATE__, __TIME__));
  }

}

void loop () {

    DateTime now = RTC.now();

    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    delay(3000);
}

Version #2---------------------------------------------------------
int powerswitch1 = A0;
void setup()
{
pinMode(powerswitch1, OUTPUT);
}

void loop ()
{

digitalWrite(powerswitch1, HIGH);
delay(500);
digitalWrite(powerswitch1, LOW);
delay(500);
digitalWrite(powerswitch1, HIGH);
delay(500);
}

Your confusion is over the multiple functions of analog pins A4 and A5.
In addition to being analog pins, they are also the pins configured internally for I2C/TWI serial, which is interfaced with using the Wire library on arduino. Since those are the only two pins Wire can use, there is no need to specify them, the sketch just calls Wire.begin() to set everything up.
If you need a second I2C device you can simply connect them both up to A4 and A5 at the same time, the protocol is designed to support that kind of thing. If you need to use A4 and A5 for something else besides I2C, you can't continue to use the hardware I2C library.
It is possible to use a software implementation of I2C/TWI serial on other pins, but usually soft-serial implementation have some drawbacks compared to the hardware version. There is an implementation on the arduino playground here: http://playground.arduino.cc/Main/SoftwareI2CLibrary
That said, the RTC library you are using seems to internally use the Wire library, so it would take some hacking to switch it to a different I2C implementation.


text:
Arduino Yun doesn't link any library
I'm writing code for a project with Arduino Yun. My project is quite simple: it takes a picture with a webcam and saves it in a PNG or JPEG file format. I've already installed the uvc driver for Arduino Yun and tested it with my webcam and the fswebcam application. The application saved pictures both in PNG and JPEG format successfully, so I went on and installed the C compiler, make and binutils for Arduino Yun and started to write my own application that would do the same thing (just taking a picture and saving it in PNG format). After writing the code to capture the pixels of the image, I decided to write them down in a PNG file format by using the libpng library available for Arduino Yun through luci web control panel. After installing the package, I included the png.h (using #include png.h) in my source code and wrote the code to write those pixels down in a simple PNG file (thanks to this tutorial: http://www.labbookpages.co.uk/software/imgProc/libPNG.html).
What's the problem? It just won't compile! I tried everything and all I got were "undefined reference to 'function name here'" errors. I thought that, maybe, libpng was buggy so I moved to libjpeg. No luck! I get the same errors over and over again. I really don't know what else I can do, I tried everything, it just seems that the Arduino Yun C compiler can't handle "external" libraries. I thank you in advance for any help you'll give me...
Here are the errors I get when I try to compile it using the libjpeg library:
/tmp/ccdzMFgN.o: In function `salvaImmagineJPEG':
    ScattaFoto.c:(.text+0x1d9c): undefined reference to `jpeg_std_error'
    ScattaFoto.c:(.text+0x1da8): undefined reference to `jpeg_std_error'
    ScattaFoto.c:(.text+0x1dc8): undefined reference to `jpeg_CreateCompress'
    ScattaFoto.c:(.text+0x1dd4): undefined reference to `jpeg_CreateCompress'
    ScattaFoto.c:(.text+0x1dec): undefined reference to `jpeg_stdio_dest'
    ScattaFoto.c:(.text+0x1df8): undefined reference to `jpeg_stdio_dest'
    ScattaFoto.c:(.text+0x1e2c): undefined reference to `jpeg_set_defaults'
    ScattaFoto.c:(.text+0x1e38): undefined reference to `jpeg_set_defaults'
    ScattaFoto.c:(.text+0x1e54): undefined reference to `jpeg_set_quality'
    ScattaFoto.c:(.text+0x1e60): undefined reference to `jpeg_set_quality'
    ScattaFoto.c:(.text+0x1e78): undefined reference to `jpeg_start_compress'
    ScattaFoto.c:(.text+0x1e84): undefined reference to `jpeg_start_compress'
    ScattaFoto.c:(.text+0x1ed8): undefined reference to `jpeg_write_scanlines'
    ScattaFoto.c:(.text+0x1ee4): undefined reference to `jpeg_write_scanlines'
    ScattaFoto.c:(.text+0x1f10): undefined reference to `jpeg_finish_compress'
    ScattaFoto.c:(.text+0x1f1c): undefined reference to `jpeg_finish_compress'
    collect2: ld returned 1 exit status

Were you going to share the errors with us?

It's not the compiler, it's the libpng package (and other libraries too).  It only contains the runtime shared library (.so) files.  You can't use it for development.
I haven't yet found if it's possible to directly install a full development package or not - normally development for OpenWRT is done outside the low-powered chip using a cross-compiler environment on a PC.

Thanks for your reply. I actually considered the cross-compiling solution but I let it as last resort. Do you (or does anybody) know how to set up an Arduino Yun cross-compiling environment? Thanks in advance.

Just follow the OpenWRT instructions for that chip.


text:
Is it better to use #define or const int for constants?
Arduino is an odd hybrid, where some C++ functionality is used in the embedded world—traditionally a C environment. Indeed, a lot of Arduino code is very C like though.
C has traditionally used #defines for constants. There are a number of reasons for this:

You can't set array sizes using const int.
You can't use const int as case statement labels (though this does work in some compilers)
You can't initialize a const with another const.

You can check this question on StackOverflow for more reasoning.
So, what should we use for Arduino? I tend towards #define, but I see some code using const and some using a blend.

a good optimizer will render it moot

Really? I don't see how a compiler is going to resolve things like type safety, not being able to use the to define array length and so on.

I agree.  Plus, if you look at my answer below, I demonstrate that  there are circumstances when you don't really know which type to use, so #define is the obvious choice.   My example is in naming Analog pins - like A5.  There is no appropriate type for it that could be used as a const so the only choice is to use a #define and let the compiler substitute it as text input before interpreting the meaning.

It's important to note that const int does not behave identically in C and in C++, so in fact several of the objections against it that have been alluded to in the original question and in Peter Bloomfields's extensive answer are not valid:

In C++, const int constants are compile time values and can be used to set array limits, as case labels, etc.
const int constants do not necessarily occupy any storage. Unless you take their address or declare them extern, they will generally just have a compile time existence.

However, for integer constants, it might often be preferable to use a (named or anonymous) enum. I often like this because:

It's backward compatible with C.
It's nearly as type safe as const int (every bit as type safe in C++11).
It provides a natural way of grouping related constants.
You can even use them for some amount of namespace control.

So in an idiomatic C++ program, there is no reason whatsoever to use #define to define an integer constant. Even if you want to remain C compatible (because of technical requirements, because you're kickin' it old school, or because people you work with prefer it that way), you can still use enum and should do so, rather than use #define.

You raise some excellent points (especially about the array limits -- I hadn't realised the standard compiler with Arduino IDE supported that yet). It's not quite correct to say that a compile-time constant uses no storage though, because its value still has to occur in code (i.e. program memory rather than SRAM) anywhere that it's used. That means it impacts available Flash for any type that takes up more space than a pointer.

"so in fact several of the objections against it that have been alluded to in the original question" - why are they not valid in the original question, as it is stated these are constraints of C?

@Cybergibbons Arduino is based on C++, so it's not clear to me why C only constraints would be pertinent (unless your code for some reason needs to be compatible with C as well).

@PeterR.Bloomfield, my point about constants not requiring extra storage was confined to const int. For more complex types, you're right that storage may be allocated, but even so, you're unlikely to be worse off than with a #define.

EDIT: microtherion gives an excellent answer which corrects some of my points here, particularly about memory usage.

As you've identified, there are certain situations where you're forced to use a #define, because the compiler won't allow a const variable. Similarly, in some situations you're forced to use variables, such as when you need an array of values (i.e. you can't have an array of #define).
However, there are many other situations where there isn't necessarily a single 'correct' answer. Here are some guidelines which I would follow:
Type safety
From a general programming point-of-view, const variables are usually preferable (where possible). The main reason for that is type-safety.
A #define (preprocessor macro) directly copies the literal value into each location in code, making every usage independent. This can hypothetically result in ambiguities, because the type may end up being resolved differently depending on how/where it's used.
A const variable is only ever one type, which is determined by its declaration, and resolved during initialisation. It will often require an explicit cast before it will behave differently (although there are various situations where it can safely be implicitly type-promoted). At the very least, the compiler can (if configured correctly) emit a more reliable warning when a type issue occurs.
A possible workaround for this is to include an explicit cast or a type-suffix within a #define. For example:
#define THE_ANSWER (int8_t)42
#define NOT_QUITE_PI 3.14f

That approach can potentially cause syntax problems in some cases though, depending on how it's used.
Memory usage
Unlike general purpose computing, memory is obviously at a premium when dealing with something like an Arduino. Using a const variable vs. a #define can affect where the data is stored in memory, which may force you to use one or the other.

const variables will (usually) be stored in SRAM, along with all other variables.
Literal values used in #define will often be stored in program space (Flash memory), alongside the sketch itself.

(Note that there are various things which can affect exactly how and where something is stored, such as compiler configuration and optimisation.)
SRAM and Flash have different limitations (e.g. 2 KB and 32 KB respectively for the Uno). For some applications, it's quite easy to run out of SRAM, so it can be helpful to shift some things into Flash. The reverse is also possible, although probably less common.
PROGMEM
It's possible to get the benefits of type-safety while also storing the data in program space (Flash). This is done using the PROGMEM keyword. It doesn't work for all types, but it's commonly used for arrays of integers or strings.
The general form given in the documentation is as follows:
dataType variableName[] PROGMEM = {dataInt0, dataInt1, dataInt3...};

String tables are a bit more complicated, but the documentation has full details.

For variables of a specified type which are not altered during execution, either can usually be used.
For Digital pin numbers contained in variables, either can work - such as:
const int ledPin = 13;

But there is one circumstance where I always use #define
It is to define analog pin numbers, since they are alphanumeric.
Sure, you can hard-code the pin numbers as a2, a3, etc. all throughout the program and the compiler will know what to do with them.  Then if you change pins then each use would need to be changed.
Moreover, I always like to have my pin definitions up at the top all in one place, so the question becomes which type of const would be appropriate for a pin defined as A5.
In those cases I always use #define
Voltage Divider Example:
//
//  read12     Reads Voltage of 12V Battery
//
//        SDsolar      8/8/18
//
#define adcInput A5    // Voltage divider output comes in on Analog A5
float R1 = 120000.0;   // R1 for voltage divider input from external 0-15V
float R2 =  20000.0;   // R2 for voltage divider output to ADC
float vRef = 4.8;      // 9V on Vcc goes through the regulator
float vTmp, vIn;
int value;
.
.
void setup() {
.
// allow ADC to stabilize
value=analogRead(adcPin); delay(50); value=analogRead(adcPin); delay(50);
value=analogRead(adcPin); delay(50); value=analogRead(adcPin); delay(50);
value=analogRead(adcPin); delay(50); value=analogRead(adcPin);
.
void loop () {
.
.
  value=analogRead(adcPin);
  vTmp = value * ( vRef / 1024.0 );
  vIn = vTmp / (R2/(R1+R2));
 .
 .

All the setup variables are right at the top and there is never going to be a change to the value of adcPin except at compile time.
No worries about what type adcPin is.  And no extra RAM is used in the binary to store a constant.
The compiler simply replaces each instance of adcPin with the string A5 before compiling.

There is an interesting Arduino Forum thread that discusses other ways to decide:
#define vs. const variable  (Arduino forum)
Excertps:
Code substitution:
#define FOREVER for( ; ; )

FOREVER
 {
 if (serial.available() > 0)
   ...
 }

Debugging code:
#ifdef DEBUG
 #define DEBUG_PRINT(x) Serial.println(x)
#else
 #define DEBUG_PRINT(x)
#endif

Defining true and false as Boolean to save RAM
Instead of using `const bool true = 1;` and same for `false`

#define true (boolean)1
#define false (boolean)0

A lot of it comes down to personal preference, however it is clear that #define is more versatile.

In the same circumstances, a const will not use more RAM than a #define. And for the analog pins, I would define them as const uint8_t, although const int would make no difference.

You wrote “a const doesn't actually use more RAM [...] until it is actually used”. You missed my point: most of the time, a const does not use RAM, even when it is used. Then, “this is a multipass compiler”. Most importantly, it is an optimizing compiler. Whenever possible, constants get optimized into immediate operands.

You can't set array sizes using const int.

You can with constexpr int:
constexpr auto size{ 15 };
int array[size]{};

You can't use const int as case statement labels (though this does work in some compilers)

Again, you can with constexpr int:
constexpr auto zero{ 0 };
constexpr auto one{ 1 };

int number{ 1 };
switch (number)
{
case zero: Serial.println("zero!"); break;
case one:  Serial.println("one!"); break;
default:   Serial.println("neither!"); break;
}

You can't initialize a const with another const.

You can even initialize a constexpr with another constexpr:
constexpr int x{ 1 };
const     int y{ x };
constexpr int z{ x };

Furthermore, constexpr guarantees that the variable gets evaluated at compile-time, unlike const. constexpr also doesn't have some of the disadvantages that preprocessor macros have(learncpp):

Debuggers like Visual Studio's don't let you watch preprocessor macros.
Macros can conflict with normal code.
Macros don't have scope, which increases the chance of naming conflicts.


text:
EFCom GPRS/GSM Shield
I have an EFCom GPRS/GSM Shield
http://www.elecfreaks.com/wiki/index.php?title=EFCom_GPRS/GSM_Shield
and I am using it with a mega 2560. The problem is that the code in the wiki page
//Serial Relay - Arduino will patch a
//serial link between the computer and the GPRS Shield
//at 19200 bps 8-N-1
//Computer is connected to Hardware UART
//GPRS Shield is connected to the Software UART

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup() {
  mySerial.begin(19200);               // the GPRS baud rate
  Serial.begin(19200);                 // the GPRS baud rate
}

void loop() {
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

makes use of software serial but mega 2560 cannot use software serial on pin 2, as in the arduino reference, thus I changed the pins to 50 and 51 and used external female-male headers to connect s_tx to pin 50 "rx" , and s_rx to pin 51 "tx", still no response with the AT command...
code after update is :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(50, 51);
void setup() {
  mySerial.begin(19200);               // the GPRS baud rate
  Serial.begin(19200);                 // the GPRS baud rate
}

void loop() {
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

Note that I am using the Arduino IDE serial monitor.

Try to connect "Pin RX on Mega to Pin RX on Shield" an "Pin TX on Mega to Pin TX on Shield":

Pin 50 (Rx)  on Mega <==> Pin 2 GSM Rx on Shield
Pin 51 (Tx)  on Mega <==> Pin 3 GSM Tx on Shield

I use an Geeetech Shield with a Mega 2560 and connect RX to Rx and TX to TX. Works fine.
Another solution is to use Serial1 instead of using SoftwareSerial ...
First connect:

Pin 19 (Rx1)  on Mega <==> Pin 2 GSM Rx on Shield
Pin 18 (Tx1)  on
Mega <==> Pin 3 GSM Tx on Shield

    //Serial Relay
    unsigned char buffer[64];  // buffer array for data receive over serial port
    int count=0;               // counter for buffer array
void setup()
{
  Serial1.begin(19200);
  Serial.begin(19200);
}

void loop()
{
  if (Serial1.available())
  {
    while(Serial1.available())
    {
      buffer[count++]=Serial1.read();
      if(count == 64)break;
    }
    Serial.write(buffer,count);
    clearBufferArray();
    count = 0;
  }
  if (Serial.available())
    Serial1.write(Serial.read());
}

void clearBufferArray()
{
  for (int i=0; i<count;i++)
  {
    buffer[i]=NULL;
  }
}

You can use a Arduino IDE's Serial Monitor, Serial Terminals(sscom32) or Bray++ Terminal to send AT commands to the Shield, communicate with it.
I hope this information is helpful.


text:
Use object of other class within class
I am writing a class for a project which will take care of handling any LCD updates for my project. The way I want to handle this is to initialize the LCD object in my main file, and then pass the LCD object on to my own class when initializing it.
The LCD object should be declared a private object in my class so several member functions can access it.
The problem is I can't find how to initialize the object correctly in the .h file.
Below is what I currently have, but when I try to build it, I get:
LCDController.h:_Clcd1' should be initialized
LCDController.h:_Clcd2' should be initialized

main .ino file:
void setup()
{
  //LiquidCrystal lcd(RS,RW,Enable1,Enable2, data3,data2,data1,data0);
  LiquidCrystal lcd(12, 11, 7, 6, 5, 4);  //declare two LCD's
  LiquidCrystal lcd2(12, 10, 7, 6, 5, 4); // Ths is the second

  LCDController.init(lcd, lcd2);
}

LCDController.h file:
// LCDController.h

#ifndef _LCDCONTROLLER_h
#define _LCDCONTROLLER_h

#if defined(ARDUINO) && ARDUINO >= 100
    #include "Arduino.h"
#else
    #include "WProgram.h"
#endif
#include <LiquidCrystal.h>
class LCDControllerClass
{
 protected:

 public:
    void init(LiquidCrystal& Clcd1, LiquidCrystal& Clcd2);
private:
   void _UpdateLCD(int iLine, int iPosition, String cText);
   LiquidCrystal& _Clcd1;
   LiquidCrystal& _Clcd2;
};

extern LCDControllerClass LCDController;

#endif

LCDController.cpp file:
#include "LCDController.h"
#include <LiquidCrystal.h>

void LCDControllerClass::init(LiquidCrystal& Clcd1, LiquidCrystal& Clcd2)
{
   _Clcd1 = Clcd1;
   _Clcd1.begin(40, 2);
   _Clcd1.clear();

   _Clcd2 = Clcd2;
   _Clcd2.begin(40, 2);
   _Clcd2.clear();

}

What happens if you move the lcd and lcd2 definitions outside the setup function?

In C++, a class that holds reference members (in your sample, LiquidCrystal& _Clcd1; and LiquidCrystal& _Clcd2;) must ensure these references are initialized at construction time, not later.
This means your void init(LiquidCrystal& Clcd1, LiquidCrystal& Clcd2); method is not the right way to initialize _Clcd1 and _Clcd2 because it will be called after construction time.
You have 2 ways to solve this issue,t hat I will detail further below.
HOWEVER, before we discuss the solutions, you must be aware that your sample code has a huge defect in setup() method code!
void setup()
{
    //LiquidCrystal lcd(RS,RW,Enable1,Enable2, data3,data2,data1,data0);
    LiquidCrystal lcd(12, 11, 7, 6, 5, 4);  //declare two LCD's
    LiquidCrystal lcd2(12, 10, 7, 6, 5, 4); // Ths is the second

    LCDController.init(lcd, lcd2);
}

Here, you create lcd and lcd2 in your setup method, but their life ends at the end of setup(), because they have been allocated on the stack. Using these outside setup() will most likely cause your program to crash as soon as your loop() tries to access lcd or lcd2, indirectly through LCDController method calls.
To remove this defect, you must declare these variables outside setup:
//LiquidCrystal lcd(RS,RW,Enable1,Enable2, data3,data2,data1,data0);
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);  //declare two LCD's
LiquidCrystal lcd2(12, 10, 7, 6, 5, 4); // Ths is the second

void setup()
{
    LCDController.init(lcd, lcd2);
}

Now you can use them anywhere in your program, you are sure they are present and "alive".
Now we can go to the solutions of the original compilation problem.
1. Initialize references at construction by adding a constructor
class LCDControllerClass
{
    public:
    LCDControllerClass(LiquidCrystal& Clcd1, LiquidCrystal& Clcd2)
    : _Clcd1(Clcd1), _Clcd2(Clcd2) {}
    ...
};

You can still keep an void init() method to complete the initialization if you don't want it to occur right at construction time, or you can fully integrate the current init() content into the constructor and re,voe init() altogether:
class LCDControllerClass
{
    public:
    LCDControllerClass(LiquidCrystal& Clcd1, LiquidCrystal& Clcd2)
    : _Clcd1(Clcd1), _Clcd2(Clcd2)
    {
        _Clcd1.begin(40, 2);
        _Clcd1.clear();

        _Clcd2.begin(40, 2);
        _Clcd2.clear();
    }
    ...
};

In anycase, you will have to change the way you instantiate your LCDControllerClass LCDController which you did not show in your sample code, that would be something like this:
LiquidCrystal lcd(...);
LiquidCrystal lcd2(...);
LCDControllerClass LCDController(lcd, lcd2);

That obviously requires that you can instantitate lcd and lcd2 before creating LCDController. If that is not possible for you, then  you'll have to use the second way.
2. Replace references with pointers
As mentioned before, in a class reference members MUST be initialized at construction time (moreover, they cannot be changed afterwards, to point somewhere else). This is not the case for pointers however:
class LCDControllerClass
{
    public:
    void init(LiquidCrystal* Clcd1, LiquidCrystal* Clcd2);

    private:
    void _UpdateLCD(int iLine, int iPosition, String cText);
    LiquidCrystal* _Clcd1;
    LiquidCrystal* _Clcd2;
};

void LCDControllerClass::init(LiquidCrystal* Clcd1, LiquidCrystal* Clcd2)
{
   _Clcd1 = Clcd1;
   _Clcd1->begin(40, 2);
   _Clcd1->clear();

   _Clcd2 = Clcd2;
   _Clcd2->begin(40, 2);
   _Clcd2->clear();
}

Note that now, you need to use the arrow notation -> to access _Clcd1 and _Clcd2 members (dot notation cannot work for pointers).
The rest of the code should be slightly modified to reflect this change:
//LiquidCrystal lcd(RS,RW,Enable1,Enable2, data3,data2,data1,data0);
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);  //declare two LCD's
LiquidCrystal lcd2(12, 10, 7, 6, 5, 4); // Ths is the second

void setup()
{
    LCDController.init(&lcd, &lcd2);
}

Note that we now have to pass the address of lcd and lcd2 to init(), by using & before their names.

Thanks for this great answer! Besides fixing my actual problem, you took the time to explain what was going wrong and I also understand the how and why. Thanks for making StackExchange great!

Could you also explain how I can later on in another member function of my LCDControllerClass create what I think should be another pointer to either _Clcd1 or _Clcd2? I have another member function should is in charge of putting text on the LCD, and depending on the line number that is passed to it (can be 1 to 4), it either has to update _Clcd1 or _Clcd2. I tried to accomplish this by defining LiquidCrystal* CActiveLCD = &_Clcd1 but this does compile but seems to crash my arduino...

@Alex I would suggest you post a new question (it is better than mixing several problems in one question) with the updated code, the explanation of what you want to achieve, and the problem you currently have. Cheers!

I was actually thinking if I should post a new question or not :) I just posted https://arduino.stackexchange.com/questions/9319/how-to-dynamically-switch-between-between-2-objects, would be great if you could chime in. Thanks again!


text:
Sniffing Bluetooth Packets
I'm attempting to create something similar in nature to the Ubertooth one. I'd like to sniff Bluetooth packets using the Arduino.
I've found a few nRF24L01+ wireless modules, which appear to operate on a frequency similar to Bluetooth LE. Unfortunately, I don't believe this will work for Bluetooth or BLE.
What would be the best way to sniff radio frequencies in the Bluetooth range from Arduino, am I on the right track?

You'd need access to the raw data in the 2.4 ghz spectrum. The arduino just isn't fast enough for that. You could use dedicated hardware like the Ubertooth, or you could connect a Software Defined Radio to your PC.  People are using a $20,- DVB-T TV tuner dongle based on the RTL2832U chipset for that.

Depending on what sorts of data you want to see (ie the more public parts before private ones are negotiated, if they even are in the cases of interest), you may be able to simply use a bluetooth or BLE chip.

@ChrisStratton I'm interested in the entire protocol, including the pairing proccess.


text:
Are there any commonly available and supported backlit, monochrome graphic LCDs with more than 128x64 pixels?
I am currently using a ST7565 graphic LCD for display in a heat pump system.
This LCD has the following characteristics:

128x64 pixels
2.5"x1.5"
monochrome, no greyscale
backlit
good viewing angles
serially connected (i.e. only uses a small number of pins)
high enough refresh rate to show animated icons
low cost (£20)
has a high-quality, maintained library
available from multiple sources for several years

I am finding the resolution of the screen limiting for my application. Ideally I would like a display that is exactly the same but with a higher resolution. Something between
I do not want:

colour (largely as the display is less visible, but also increased cost and code complexity), but red/green/blue on black would be OK.
a physically smaller display (all of the OLED displays are small - 2" and below) as it needs to be visible from a distance

Are there any displays that meet these requirements?
I hope that the specific requirements here mean that this is not a simple "shopping question".

OLED displays may be smaller, but their much higher brightness makes them readable from a bit further comparatively speaking.

I tested a 1.8" OLED display next to the 2.5" LCD and found that the LCD was much easier to read in a room with daylight.

OLED > LCD --> microview.io

Here you can find a bunch of displays at new haven display, which are big and OLED and not too expensive:

2.7" 128x64 OLED
3.12" 256x64 OLED

Those OLED Displays have a really excellent viewing angle and can be read from far (given you accept those sizes, which are >2").
Otherwise, the biggest I know about are LCD ones from NHD over there:

320x240 LCD with backlight

What's good with them, it's that they can cope with production in case this is needed, their prices are decent and their product just work(cTMr). You can find the u8g library to run them.

Unfortunately they all seem to be parallel rather than serial. I think I might have to resign myself to using a larger ATmega.

no they aren't. The NHD12864-2.7 can be controlled using 4 wires, and the NHD320240 can be controlled with less pins as well, looking at the S1D13700 Driver's datasheet (never tried that one, but I'm using the former in serial mode and it works very well).

The NHD12864-2.7 doesn't satisfy the requirement of being higher resolution though. All the connection diagrams seem to show D7:0 being connected in the S1D13700 data sheet, don't they?

hm.. looking again, I may have thought wrongly. Indeed, the NHD12864-2.7 is not of a higher resolution, but it's an OLED bigger than 2", and you've got the 3.12" displays, which are wider but having a better resolution (256x64).

N.B.: you may use an i2c port expander as well, or a small cheaper AVR as interface.

by the way, you can check also the supported display list of the u8glib project, to help you make a choice. They got a few big displays.


text:
How do I set Grove GPS to use A-GPS?
I am using a grove GPS http://www.seeedstudio.com/wiki/Grove_-_GPS
I attached the GPS to Serial1 of Arduino Mega 2560.
The baudrate of the GPS is set to 9600.
Library wise, I am using TinyGps to parse the GPS data.
The GPS receiver can only get a valid data if it can see a clear sky.
I read uBlox documentation and it states that I can use A-GPS.
So, my question is, how do I actually set the Grove GPS that is attached to my Mega, to use A-GPS?

A-GPS uses a network connection to download GPS almanac and ephemeris data to enable satellites to be located faster. Otherwise the GPS device has to wait for the data to be sent by a satellite, which may take up to 12.5 minutes. Alternatively, the GPS device can send noise GPS data to an assistance server which will process it and send back a fix.
A-GPS requires a network connection to an A-GPS server. You can't just 'turn it on'. There are some modules out there that combine GPS with a 3G modem which do A-GPS automatically.

In other words, are you saying that I cannot use A-GPS on the grove GPS? I do have the official GSM/GPRS shield attached to the mega too on top of the Grove GPS However.

You would have to find a server, see http://www.u-blox.com/en/assisted-gps.html

But then, how do I configure the Grove GPS on the arduino to use A-GPS?

I'm guessing it will be in the datasheet or app note for the UBlox chipset. A lot of work required.

If you connect your Grove GPS to a Raspberry Pi, it keeps track of the ephemeris data, so after rebooting you can find a signal quicker. eg. using gpsd package. If your Pi is last used in a different country, the stored data wont make sense, so it will have to wait for fresh data sent by the satellite anyway


text:
Hub RFID Arduino + WIFI
I will start an Arduino project and its main requirement is that some RFID readers (at most 6 readers) be connected and controled by the arduino board.
I do not have a strong background in eletronics, and therefore I do not have any idea in how to start it. Is it possible to connect more than one RFID reader to an Arduino board? If it is possible, which reader is the best for this porpouse?
Another requirement of this project is the need to send the data collected by each RFID reader to a PC server through WIFI. For this what is better to use, an Arduino UNO with a WIFI shield or an Arduino YUN? What is better and why?
Thanks!!!

Which RFID reader will you use? Depending on model a different amount of pins are used (from 1 to 3 at least). So if you choose a reader that only requires 1 pin you might be able to connect all 6 to one arduino. Another question is how far apart these should be? If very far it might not be feasable anyways, and easier to use multiple arduinis... As you say that each reader should send its data over wifi. Then instead of putting cables for each RFID to a central Arduino, just put down Ethernet cable and use a standard Ethernet module and multiple arduinis to send the data to a PC.

I have not decided yet which RFID reader I will use. Can you sugest anyone? The idea is build a smart table that can recognize tagged objets over it, thus I think that the distance is not more than 1 meter between each reader and the Arduino. If required more than one Arduino the project is not be feasible. WIFI is a primary requirement, the client do not want data cables from table to a PC, all data collected by the RFID reader must be sent through WIFI.

Ok, then it wouldnt be a problem to connect multiple rfid readers to one arduino I guess, if the library allows this. I cannot recommend any reader, as I have just bought a simple one from ebay, but havent tried it yet, so I really cant comment on functionality either. I'll have to get back to you when I have tried this out...


text:
Wiring Lilypad USB + ESP8266 Serial WiFi Module
I am trying to solve the following scenario:
Lilypad USB connected to WIFI through ESP8266 Serial WiFi Module.
http://arduino.cc/en/pmwiki.php?n=Main/ArduinoBoardLilyPadUSB
http://www.seeedstudio.com/wiki/WiFi_Serial_Transceiver_Module
According to the wiki:
I should connect to TX RX pins. None of them are present as "selectable pins", because they are built in.
This post Using LilyPad Arduino USB with LilyPad Xbee Shield  talks about using SoftwareSerial something that is new to me.
Could anyone explain how should I proceed with the wiring and if possible a sample sketch just to connect the lilypad usb with the WIFI module to my personal WIFI.
Edit:
I found the following tutorial (spanish one but easy to follow...) where they use the Arduino UNO. I tried the example with the software serial and it worked.
I saw in that tutorial sometimes the pin RST is needed. So I tried to do the same with the lilypad USB, but still didn't work.

First, upload the sketch below to your Arduino. Then, try to tie RX (pin 3) and TX (pin 2) of SoftwareSerial together. Open the Serial Monitor and send some text and see if you get it back as a response.
#include <SoftwareSerial.h>
SoftwareSerial Serial1(3, 2);

void setup()
  {  Serial.begin(9600);
     Serial1.begin(9600);
  }

void loop()
  {
     if (Serial1.available())
         { char c = Serial1.read() ;
           Serial.print(c);
         }
     if (Serial.available())
         {  char c = Serial.read();
            Serial1.print(c);
         }
   }

Once you get a response, then your SoftwareSerial part is working and you can then try to connect to your ESP8266.

authors: Nabil Akroud - نبيـــل عكــرود


text:
Didn't have MAC address on Wiznet based ethernet shield (cloned)
My Ethernet shield dont have any MAC address, please tell me how to find the MAC address, I'm stucked! Here is the link from where I bought the Ethernet shield.
http://www.amazon.in/gp/product/B00AXVX5D0?ie=UTF8&at=&force-full-site=1&ref_=aw_bottom_links

You can set the Mac address to whatever you want.  Many of the example sketches will have one already present, but as long you follow the standard mac format it should be happy (I am using the same shield).  In the Examples menu, you should see Ethernet then Webserver where you can find the following example.  You can change it a bit, but most of the time I just leave it alone.
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

"You can set the Mac address to whatever you want." Yes, if you don't care about duplicated addresses, already assigned addresses or even broadcast addresses. To do it right, read a bit about MAC addresses, e.g. starting with Wikipedia about MAC addresses

Ethernet will work as long as two different machine in the LAN don't have the same MAC address, as @Nathan wrote in his answer.
The MAC address is built by two parts, a prefix which are given to manufacturers of network devices and is called OUI, and a suffix that is the node part that manufacturers can use as they wish.
If you want to build an MAC address yourself, use a Locally administered address.  Universally administered and locally administered addresses are distinguished by setting the second-least-significant bit of the most significant byte of the address.
That will make this address to not use any OUI prefix, as that bit is zero on OUI, which minimize the risk of two or more devices have the same MAC address in same LAN.
If you get the same MAC addresses you will get very strange results if they happen to be in the same LAN, I tell you.  Been there, done that, and it wasn't fun to debug.
Here are a site that looks up MAC addresses (and generate random ones).  But if you want to see which manufacturer have that MAC address, you read it from IEEE and their list.

so can i use the mac address which is generated by random mac address generator from the link u provided?

Yes, you can.  But it is still up to you to know that the MAC address is unique for your LAN, because you could theoretically end up with two equal addresses,  even though the risk are rather slim. But still slimmer than to use one that are used in examples, like DE:AD:BE:EF:FE:ED. ;-)


text:
nRF24L01 pipe question
I am looking through the example code found here. I know there are 6 pipes that the nRF24L01 module can use but I've been searching the internet for the address designations and have been able to find nothing. More specifically on line 37, is there a reference for where the author is getting 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL?
Thanks.

Check RF24 API doc for openReadingPipe() here: http://maniacbug.github.io/RF24/classRF24.html#aa7e8523f86f9f8f20c274e0c89a5fd45 it mentions you can use any values for the last address byte.

So I looked through the documentation but it doesn't mention how the pipe address is chosen. It just say they should share the first 32 bits. For example 0xF0F0F0F0(XX), does 0x count as a byte? Or is F0F0F0F0 the 32 bits that matter? Also, does it matter if it's not F0F0F0F0 as long as the pipes share those 32 bits? How about the last two significant bytes (XX)? Are those arbitrary as well?

The 0x... prefix is just to tell the value is in hexadecimal. This is because 99 in decimal is different from 99 in hexadecimal, even though they look the same. So instead we use 0x99.

The code you a using only supports 1 pipe. The nRF24L01 has 2 unique pipes (0 and 1). It also has 4 additional pipes (2, 3, 4 and 5), where you can only set the least-significant-byte. The other bytes will be the same as the second pipe (1).

Thanks for the response, I guess I just still don't understand if there's a process to set the least-significant-byte. For ex like E1 or D2 in the pipes listed above...

As most of the people have posted, the values for the pipe are arbitrary, but must follow the rules per the API:

Pipes 1-5 should share the first 32 bits. Only the least significant
  byte should be unique, e.g.

Before I answer your question, I think an explanation on Hex and Decimal values are needed.
The 40 bit hexadecimal is a number representation of base 16. A decimal is of base 10. So you can convert a Hex Value to Decimal. As this is out of scope for the question, you can google on how to convert from one to another. There are some online converters:
Hex to Decimal Converter
You will see when you convert the Hex value to decimal, that its just a number representation. When you convert, you drop the 0x and LL. As stated the 0x indicates the value is a hex value and LL means type Long Long.
So to answer your question, use the a converter to find a hex number like:
F0F0F0F0A1
F0F0F0F0A2
F0F0F0F0B4
F0F0F0F0E9

Just change the last 2 digits (least significant bit):
Pipes 1-5 should share the first 32 bits. Only the least significant byte should be unique, e.g.
   openReadingPipe(1,0xF0F0F0F0AA);
   openReadingPipe(2,0xF0F0F0F066);

Add the 0x and LL
0xF0F0F0F0A1LL
0xF0F0F0F0A2LL
0xF0F0F0F0B4LL
0xF0F0F0F0E9LL

All should work.
I am no expert on hex, as I am learning, so if I am incorrect, then please someone correct me.
Finally, the nRF24L01 datasheet makes the following point that the choice of address is not completely arbitrary:

Note: Addresses where the level shifts only one time (that is, 000FFFFFFF) can often be detected in noise and can give a false detection, which may give a raised Packet Error Rate. Addresses as a continuation of the preamble (hi-low toggling) also raises the Packet Error Rate.

@bersch - Is that relevant? The OP was asking how the pipe values are choosen e.g. where the author is getting 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL?, not how the pipes are used.

From my testing, the values are arbitrary as long as your pipe 0 & 1 are the same on the Transmitter and the receiver

I am working on mine. I will have 1 transmitter and 4 receivers

There's something that everyone forgets to tell you:
Pipes at receiver should be shortened after the first one
const uint64_t pipe01 = 0xE8E8F0F0A1LL;
const uint64_t pipe02 = 0xA2LL;
const uint64_t pipe03 = 0xA3LL;
const uint64_t pipe04 = 0xA4LL;
const uint64_t pipe05 = 0xA5LL;
const uint64_t pipe06 = 0xA6LL;

radio.openReadingPipe(1, pipe01);
radio.openReadingPipe(2, pipe02);
radio.openReadingPipe(3, pipe03);
radio.openReadingPipe(4, pipe04);
radio.openReadingPipe(5, pipe05);

Pipes at transmitter should be
const uint64_t pipe01 = 0xE8E8F0F0A1LL;
const uint64_t pipe02 = 0xE8E8F0F0A2LL;
const uint64_t pipe03 = 0xE8E8F0F0A3LL;
const uint64_t pipe04 = 0xE8E8F0F0A4LL;
const uint64_t pipe05 = 0xE8E8F0F0A5LL;
const uint64_t pipe06 = 0xE8E8F0F0A6LL;

uint64_t setPipeToSend = pipe01; // or pipe02 or pipe03 or pipe04 or pipe05
radio.openWritingPipe(setPipeToSend );

If you want to know which pipe's message has come, use
  uint8_t someVariable;
    if (radio.available(&someVariable))
    {
       Serial.print("pipe number ");
       Serial.printLn(someVariable);
    }

Also pipe number 6 is used for receiving acknowledge messages.
In addition, the initialization code must have radio.enableDynamicPayloads();
This one works well for me:
    radio.begin();
    //radio.setChannel(0x57); //if set should be the same at the both sides
    radio.setPALevel(RF24_PA_LOW);  // "LOW" is more stable mode
    radio.enableAckPayload(); //for autoanswers
    radio.openWritingPipe(pipe01); //for sending
    //link pipe numbers to the pipe addresses
    //radio.openReadingPipe(1, pipe01); // I use pipe01 for sending
    radio.openReadingPipe(2, pipe02);
    radio.openReadingPipe(3, pipe03);
    radio.openReadingPipe(4, pipe04);
    radio.openReadingPipe(5, pipe05);
    radio.enableDynamicPayloads(); //must have for multi pipe receiving
    radio.startListening();  //start listening

Good luck...

whats pipe defined as in your example?

I have edited the code. You can use any of these 'pipes' for sending, but don't forget (like me) to exclude that pipe from reading.


text:
Blink without delay for 5 times every 20 seconds
I'm trying to write a blink without delay code that will wait 20 seconds, then blink 5 times, then wait another 20 seconds - rinse and repeat.
Here's the minimal code I wrote:
if (currentTime % 20000 == 0) {
  for (int x = 0; x <= 5; x++) {
    if (currentTime % 500 == 0) {
      if (solenoid == LOW) {
        solenoid = HIGH;
      }   else {
        solenoid = LOW;
      }
      digitalWrite(solenoidpin, solenoid);
    }
  }
}
}

All this seems to do is set solenoid to HIGH and keep it there. If I get rid of the for loop and the second if statement, I can get it to switch between low and high every 20 seconds, but adding the if and for loops seems to kill it. Any thoughts on how to make this work?

Why are you executing it in a for loop 6 times? If currentTime % 500 == 0 is true, it will flip the solenoid state 6 times (i.e., not change it).

By comparing the result of the modulo operation on a micros() value, you will only "trigger" if you happen to approach each if statement on exactly the microsecond boundary. Depending on your other code, you may find that the Arduino doesn't get around to your if statements on every sequential millisecond, and so you may miss some triggers. Better to do the subtract-and-compare operation that the BlinkWithoutDelay actually uses. That way, your if will trigger, even if you happened to miss the time by one millisecond.

That code just flips the solenoid really fast for a milisecond, then repeats it in 20 seconds. The for loop and the second if are pointless. In the for loop the variable currentTime doesn't change and the second if is always true because 20000 is divisible by 500.

// assuming blinking is 500ms ON, 500ms OFF, so 4500ms for 5 blinks.

int tick = (currentTime/500) % 49;
// if one tick is 500ms, that means,
//    1 tick ON, 1 tick OFF, 1 tick ON, ... , 1 tick ON, 40 ticks OFF (for a total of 49 ticks)
if( ( tick < 5*2 ) && ( tick%2==0 ) )// only turn ON the led on the first 10 ticks (5 ON; 5 OFF)
                                     //  and only if the number of ticks is ODD
    digitalWrite(solenoidpin, HIGH);
else
    digitalWrite(solenoidpin, LOW);

What I did was convert the milliseconds in to ticks of 500 ms. Then based on the tick value, update the led.
PS I tested it on a Arduino Pro Mini

converting elapsed time to tick makes all kinds of sense. ... it is so easy to expand the number of controlled pins ... you could use lookup tables to make complex timing patterns like in a drum machine

This is smart. But note that: 1. The division and modulo operators are computationally expensive, although tick%2 would be cheap if tick was unsigned. 2. The formula for tick is ill-behaved when millis() rolls over. Both issues could be fixed by updating tick within a if (millis() - lastMillis > 500) { ... } construct.


text:
Multiple definition of '__vector_36' (intterupts)
I'm having some conflicts between the core HardwareSerial.cpp and an external DMX library.
For DMX I'm using the Four Universes DMX 512 Library. Using the library standalone, it all works perfectly. But when combining it with other libraries, I'm getting the error:
core.a(HardwareSerial.cpp.o): In function '__vector_36':
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/HardwareSerial.cpp:147: multiple definition of '__vector_36'
Dmx\lib_dmx.cpp.o:C:\Program Files (x86)\Arduino\libraries\Dmx/lib_dmx.cpp:206: first defined here

The DMX library uses the UART hardware to generate the DMX signals. It supports four universes on the Arduino Mega since that has four UART hardware parts. Now, I'd like to only use the second hardware part, so the UART1. In the DMX library this is easily adjusted in the .h-file, by commenting out the non-used serial ports.
The line from lib_dmx.cpp that is conflicting is this line:
#if defined(USE_UART1)
ISR (SIG_USART1_RECV)
{
  ArduinoDmx1.Process_ISR_RX(1);
}
#endif

The line from hardwareSerial.cpp that is conflicting is in the ISR here:
#if defined(USART1_RX_vect)
  void serialEvent1() __attribute__((weak));
  void serialEvent1() {}
  #define serialEvent1_implemented
  ISR(USART1_RX_vect)
  {
    if (bit_is_clear(UCSR1A, UPE1)) {
      unsigned char c = UDR1;
      store_char(c, &rx_buffer1);
    } else {
      unsigned char c = UDR1;
    };
  }
#endif

I have been having issues with this for a very long time and don't have a solution at hand yet. It's also a but unclear to me how the interrupts on Arduinos are arranged. I've also included the .ino I'm using currently. I'm also using another Ethernet Library than the default, one that includes multicast UDP (found here).
lib_dmx.h
> /***************************************************************************
> *
> * Title          : Arduino DMX512 library. 4 input/output universes.
> * Version        : v 0.3 beta
> * Last updated   : 07.07.2012
> * Target         : Arduino mega 2560, Arduino mega 1280, Arduino nano (1 universe)
> * Author         : Toni Merino - merino.toni at gmail.com
> * Web            : www.deskontrol.net/blog
> *
> * Based on ATmega8515 Dmx library written by Hendrik Hoelscher, www.hoelscher-hi.de
>
> ;***************************************************************************/
> #ifndef __INC_DMX_H
> #define __INC_DMX_H
>
> #include <avr/io.h>
> #include <stdint.h>
> #include <avr/interrupt.h>
> #include <util/delay.h>
> #if ARDUINO >= 100   #include "Arduino.h"
> #else    #include "WProgram.h"
> #endif
>
> //#define        USE_INTERBYTE_DELAY     // rare cases of equipment
> non full DMX-512 compliant, need this
>
> // *** comment UARTs not used *** //#define        USE_UART0
> #define        USE_UART1 //#define        USE_UART2 //#define        USE_UART3
>
> // New DMX modes *** EXPERIMENTAL ***
> #define        DMX512            (0)    // DMX-512 (250 kbaud - 512 channels) Standard USITT DMX-512
> #define        DMX1024           (1)    // DMX-1024 (500 kbaud - 1024 channels) Completely non standard - TESTED ok
> #define        DMX2048           (2)    // DMX-2048 (1000 kbaud - 2048 channels) called by manufacturers DMX1000K, DMX 4x or DMX 1M ???
>
> // DMX-512  (250 kbaud - 512 channels) Standard USITT DMX-512
> #define        IBG_512           (10)                      // interbyte gap [us]
> #define        DMX_512           ((F_CPU/(250000*8))-1)    // 250 kbaud
> #define        BREAK_512         ( F_CPU/(100000*8))       // 90.9 kbaud
>
> // DMX-1024 (500 kbaud - 1024 channels) Completely non standard
> #define        IBG_1024          (5)                       // interbyte gap [us]
> #define        DMX_1024          ((F_CPU/(500000*8))-1)    // 500 kbaud
> #define        BREAK_1024        ( F_CPU/(200000*8))       // 181.8 kbaud
>
> // DMX-2048 (1000 kbaud - 2048 channels) Non standard, but used by
> manufacturers as DMX1000K or DMX-4x or DMX 1M ???
> #define        IBG_2048          (2)                       // interbyte gap [us] + nop's to reach 2.5 uS
> #define        DMX_2048          ((F_CPU/(1000000*8))-1)   // 1000 kbaud
> #define        BREAK_2048        ( F_CPU/(400000*8))       // 363.6 kbaud
>
> // Inline assembly: do nothing for one clock cycle.
> #define        nop()             __asm__ __volatile__("nop")
>
> #ifdef __cplusplus extern "C" {
> #endif   #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
>     #if defined(USE_UART0)
>       void SIG_USART0_RECV  (void) __attribute__((__always_inline__));
>       void SIG_USART0_TRANS (void) __attribute__((__always_inline__));
>     #endif
>     #if defined(USE_UART1)
>       void SIG_USART1_RECV  (void) __attribute__((__always_inline__));
>       void SIG_USART1_TRANS (void) __attribute__((__always_inline__));
>     #endif
>     #if defined(USE_UART2)
>       void SIG_USART2_RECV  (void) __attribute__((__always_inline__));
>       void SIG_USART2_TRANS (void) __attribute__((__always_inline__));
>     #endif
>     #if defined(USE_UART3)
>       void SIG_USART3_RECV  (void) __attribute__((__always_inline__));
>       void SIG_USART3_TRANS (void) __attribute__((__always_inline__));
>     #endif   #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
>     #if defined(USE_UART0)
>       void USART_RX_vect    (void) __attribute__((__always_inline__));
>       void USART_TX_vect    (void) __attribute__((__always_inline__));
>     #endif   #endif
> #ifdef __cplusplus };
> #endif
>
> class CArduinoDmx  {    #if defined(__AVR_ATmega1280__) ||
> defined(__AVR_ATmega2560__)
>     #if defined(USE_UART0)
>       friend void SIG_USART0_RECV  (void);
>       friend void SIG_USART0_TRANS (void);
>     #endif
>     #if defined(USE_UART1)
>       friend void SIG_USART1_RECV  (void);
>       friend void SIG_USART1_TRANS (void);
>     #endif
>     #if defined(USE_UART2)
>       friend void SIG_USART2_RECV  (void);
>       friend void SIG_USART2_TRANS (void);
>     #endif
>     #if defined(USE_UART3)
>       friend void SIG_USART3_RECV  (void);
>       friend void SIG_USART3_TRANS (void);
>     #endif   #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
>     #if defined(USE_UART0)
>       friend void USART_RX_vect    (void);
>       friend void USART_TX_vect    (void);
>     #endif   #endif    public:    enum {IDLE, BREAK, STARTB, STARTADR};     // RX DMX states    enum {TXBREAK, TXSTARTB, TXDATA};
> // TX DMX states
>       volatile uint8_t    *RxBuffer;            // array of RX DMX values    volatile uint8_t    *TxBuffer;            // array of TX DMX
> values
>
> private:    uint8_t     gRxState;    uint8_t    *gRxPnt;    uint8_t
> IndicatorCount;    uint8_t     USARTstate;            uint8_t     RxByte;
> uint8_t     RxState;    uint8_t     mUART;    uint8_t     gTxState;
> uint16_t    RxCount;    uint16_t    gCurTxCh;         uint16_t
> rx_channels;                  // rx channels number    uint16_t
> tx_channels;                  // tx channels number    uint16_t
> rx_address;                   // rx start address    uint16_t
> tx_address;                   // tx start address    int8_t
> rx_led;                       // rx indicator led pin    int8_t
> tx_led;                       // tx indicator led pin    int8_t
> control_pin;                  // max485 input/output selection pin
> uint8_t     dmx_mode;                     // Standard USITT DMX512 =
> 0, non standard DMX1024 = 1, non standard DMX2048 (DMX1000K) = 2
> uint8_t     speed_dmx;    uint8_t     speed_break;    uint16_t
> CurTxCh;    uint8_t     TxState;    uint8_t    *RxPnt;
>
> #if defined(USE_INTERBYTE_DELAY)       void        delay_gap          ();
> #endif
>
> public:    void        stop_dmx           ();    void        set_speed
> (uint8_t mode);    void        set_control_pin    (int8_t  pin)
> { control_pin     = pin;      }    void        init_rx
> (uint8_t mode);  // Standard USITT DMX512 = 0, non standard DMX1024 =
> 1, non standard DMX2048 (DMX1000K) = 2    void        set_rx_address
> (uint16_t address)   { rx_address      = address;  }    void
> set_rx_channels    (uint16_t channels)  { rx_channels     = channels;
> }    void        init_tx            (uint8_t mode);  // Standard USITT
> DMX512 = 0, non standard DMX1024 = 1, non standard DMX2048 (DMX1000K)
> = 2    void        set_tx_address     (uint16_t address)   { tx_address      = address;  }    void        set_tx_channels
> (uint16_t channels)  { tx_channels     = channels; }
>
>    void        attachTXInterrupt  (void (*isr)(uint8_t uart))      {
> TXisrCallback   = isr; }   // register the user TX callback    void
> attachRXInterrupt  (void (*isr)(uint8_t uart))      { RXisrCallback
> = isr; }   // register the user RX callback
>        //void         Process_ISR_RX(uint8_t rx_isr_number);
>
>    void        (*TXisrCallback)   (uint8_t uart);    void
> (*RXisrCallback)   (uint8_t uart);
>
>    inline void Process_ISR_RX     (uint8_t  rx_isr_number);    inline
> void Process_ISR_TX     (uint8_t  tx_isr_number);    public:
> CArduinoDmx                    (uint8_t uart)       { rx_address
> = 1;
>                                                          rx_channels     = 8;
>                                                          tx_address      = 1;
>                                                          tx_channels     = 8;
>                                                          mUART           = uart; }   };
>
> #if defined(USE_UART0)   extern CArduinoDmx ArduinoDmx0;
> #endif
> #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)   #if defined(USE_UART1)
>     extern CArduinoDmx ArduinoDmx1;   #endif   #if defined(USE_UART2)
>     extern CArduinoDmx ArduinoDmx2;   #endif   #if defined(USE_UART3)
>     extern CArduinoDmx ArduinoDmx3;   #endif
> #endif
>
> #endif

lib_dmx.cpp
/***************************************************************************
*
* Title          : Arduino DMX512 library. 4 input/output universes.
* Version        : v 0.3 beta
* Last updated   : 07.07.2012
* Target         : Arduino mega 2560, Arduino mega 1280, Arduino nano (1 universe)
* Author         : Toni Merino - merino.toni at gmail.com
* Web            : www.deskontrol.net/blog
*
* Based on ATmega8515 Dmx library written by Hendrik Hoelscher, www.hoelscher-hi.de

;***************************************************************************/
#include "lib_dmx.h"
#include <SPI.h>

#if defined(USE_UART0)
  CArduinoDmx ArduinoDmx0(0);
#endif
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART1)
    CArduinoDmx ArduinoDmx1(1);
  #endif
  #if defined(USE_UART2)
    CArduinoDmx ArduinoDmx2(2);
  #endif
  #if defined(USE_UART3)
    CArduinoDmx ArduinoDmx3(3);
  #endif
#endif

// *************** DMX Transmision Initialisation ****************
void CArduinoDmx::init_tx(uint8_t mode)
{
  cli();          //disable interrupts
  stop_dmx();                         //stop uart
  dmx_mode = mode;
  set_speed(dmx_mode);

  if(control_pin != -1)
  {
    pinMode(control_pin,OUTPUT);        // max485 I/O control
    digitalWrite(control_pin, HIGH);    // set 485 as output
  }

  if(mUART == 0)
  {
    pinMode(1, OUTPUT);
    UBRR0H   = 0;
    UBRR0L   = speed_dmx;
    UCSR0A  |= (1<<U2X0);
    UCSR0C  |= (3<<UCSZ00)|(1<<USBS0);
    UCSR0B  |= (1<<TXEN0) |(1<<TXCIE0);
    UDR0     = 0;                                     //start USART 0
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  else if(mUART == 1)
  {
    pinMode(18, OUTPUT);
    UBRR1H   = 0;
    UBRR1L   = speed_dmx;
    UCSR1A  |= (1<<U2X1);
    UCSR1C  |= (3<<UCSZ10)|(1<<USBS1);
    UCSR1B  |= (1<<TXEN1) |(1<<TXCIE1);
    UDR1     = 0;                                     //start USART 1
  }
  else if(mUART == 2)
  {
    pinMode(16, OUTPUT);
    UBRR2H   = 0;
    UBRR2L   = speed_dmx;
    UCSR2A  |= (1<<U2X2);
    UCSR2C  |= (3<<UCSZ20)|(1<<USBS2);
    UCSR2B  |= (1<<TXEN2) |(1<<TXCIE2);
    UDR2     = 0;                                     //start USART 2
  }
  else if(mUART == 3)
  {
    pinMode(14, OUTPUT);
    UBRR3H   = 0;
    UBRR3L   = speed_dmx;
    UCSR3A  |= (1<<U2X3);
    UCSR3C  |= (3<<UCSZ30)|(1<<USBS3);
    UCSR3B  |= (1<<TXEN3) |(1<<TXCIE3);
    UDR3     = 0;                                     //start USART 3
  }
#endif

  gTxState = BREAK;                                     // start with break
  TxBuffer = (uint8_t*)malloc(tx_channels);     // allocate mem for buffer
  memset((uint8_t*)TxBuffer, 0, tx_channels);   // fill buffer with 0's
  sei();          //enable interrupts
}

// ************************ DMX Stop ***************************
void CArduinoDmx::stop_dmx()
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  if(mUART == 0)
  {
    UCSR0B &= ~((1<<RXCIE0) | (1<<TXCIE0) | (1<<RXEN0) | (1<<TXEN0));
  }
  else if(mUART == 1)
  {
    UCSR1B &= ~((1<<RXCIE1) | (1<<TXCIE1) | (1<<RXEN1) | (1<<TXEN1));
  }
  else if(mUART == 2)
  {
    UCSR2B &= ~((1<<RXCIE2) | (1<<TXCIE2) | (1<<RXEN2) | (1<<TXEN2));
  }
  else if(mUART == 3)
  {
    UCSR3B &= ~((1<<RXCIE3) | (1<<TXCIE3) | (1<<RXEN3) | (1<<TXEN3));
  }
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  if(mUART == 0)
  {
    UCSR0B &= ~((1<<RXCIE0) | (1<<TXCIE0) | (1<<RXEN0) | (1<<TXEN0));
  }
#endif
}

// *************** DMX Reception Initialisation ****************
void CArduinoDmx::init_rx(uint8_t mode)
{
  cli();          //disable interrupts
  stop_dmx();
  dmx_mode = mode;
  set_speed(dmx_mode);

  if(control_pin != -1)
  {
    pinMode(control_pin,OUTPUT);        //max485 I/O control
    digitalWrite(control_pin, LOW);     //set 485 as input
  }

  if(mUART == 0)
  {
    pinMode(0, INPUT);
    UBRR0H   = 0;
    UBRR0L   = speed_dmx;
    UCSR0A  |= (1<<U2X0);
    UCSR0C  |= (3<<UCSZ00)|(1<<USBS0);
    UCSR0B  |= (1<<RXEN0) |(1<<RXCIE0);
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  else if(mUART == 1)
  {
    pinMode(19, INPUT);
    UBRR1H   = 0;
    UBRR1L   = speed_dmx;
    UCSR1A  |= (1<<U2X1);
    UCSR1C  |= (3<<UCSZ10)|(1<<USBS1);
    UCSR1B  |= (1<<RXEN1) |(1<<RXCIE1);
  }
  else if(mUART == 2)
  {
    pinMode(17, INPUT);
    UBRR2H   = 0;
    UBRR2L   = speed_dmx;
    UCSR2A  |= (1<<U2X2);
    UCSR2C  |= (3<<UCSZ20)|(1<<USBS2);
    UCSR2B  |= (1<<RXEN2) |(1<<RXCIE2);
  }
  else if(mUART == 3)
  {
    pinMode(15, INPUT);
    UBRR3H   = 0;
    UBRR3L   = speed_dmx;
    UCSR3A  |= (1<<U2X3);
    UCSR3C  |= (3<<UCSZ30)|(1<<USBS3);
    UCSR3B  |= (1<<RXEN3) |(1<<RXCIE3);
  }
#endif

  gRxState = IDLE;
  RxBuffer = (uint8_t*)malloc(rx_channels);   // allocate mem for buffer
  memset((uint8_t*)RxBuffer, 0, rx_channels); // fill buffer with 0's
  sei();          //enable interrupts
}

// *************** DMX Reception ISR ****************
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART0)
    ISR (SIG_USART0_RECV)
    {
      ArduinoDmx0.Process_ISR_RX(0);
    }
  #endif
  #if defined(USE_UART1)
    ISR (SIG_USART1_RECV)
    {
      ArduinoDmx1.Process_ISR_RX(1);
    }
  #endif
  #if defined(USE_UART2)
    ISR (SIG_USART2_RECV)
    {
      ArduinoDmx2.Process_ISR_RX(2);
    }
  #endif
  #if defined(USE_UART3)
    ISR (SIG_USART3_RECV)
    {
      ArduinoDmx3.Process_ISR_RX(3);
    }
  #endif
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  #if defined(USE_UART0)
    ISR (USART_RX_vect)
    {
        ArduinoDmx0.Process_ISR_RX(0);
    }
  #endif
#endif

void CArduinoDmx::Process_ISR_RX(uint8_t rx_isr_number)
{
  if(rx_isr_number == 0)
  {
    USARTstate = UCSR0A;                  //get state
    RxByte     = UDR0;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE0))         //check for break
    {
      UCSR0A  &= ~(1<<FE0);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

  else if(rx_isr_number == 1)
  {
    USARTstate = UCSR1A;                  //get state
    RxByte     = UDR1;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE1))         //check for break
    {
      UCSR1A  &= ~(1<<FE1);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
  else if(rx_isr_number == 2)
  {
    USARTstate = UCSR2A;                  //get state
    RxByte     = UDR2;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE2))         //check for break
    {
      UCSR2A  &= ~(1<<FE2);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
  else if(rx_isr_number == 3)
  {
    USARTstate = UCSR3A;                  //get state
    RxByte     = UDR3;                //get data
    RxState    = gRxState;                    //just get once from SRAM!!!
    if (USARTstate &(1<<FE3))         //check for break
    {
      UCSR3A  &= ~(1<<FE3);                 //reset flag
      RxCount  = rx_address;                  //reset frame counter
      gRxState = BREAK;
    }
  }
#endif

  if (RxState == BREAK)
  {
    if (RxByte == 0)
    {
      gRxState = STARTB;                          //normal start code detected
      gRxPnt   = ((uint8_t*)RxBuffer + 1);
    }
    else
      gRxState = IDLE;
  }
  else if (RxState == STARTB)
  {
    if (--RxCount == 0)                         //start address reached?
    {
      gRxState   = STARTADR;
      RxBuffer[0]= RxByte;
    }
  }
  else if (RxState == STARTADR)
  {
    RxPnt  = gRxPnt;
    *RxPnt = RxByte;
    if (++RxPnt >= (RxBuffer + rx_channels))    //all ch received?
    {
      gRxState= IDLE;
      if (*RXisrCallback) RXisrCallback(mUART);   // fire callback for read data
    }
    else
    {
      gRxPnt = RxPnt;
    }
  }
}

// *************** DMX Transmision ISR ****************
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  #if defined(USE_UART0)
    ISR(SIG_USART0_TRANS)
    {
      ArduinoDmx0.Process_ISR_TX(0);
    }
  #endif
  #if defined(USE_UART1)
    ISR(SIG_USART1_TRANS)
    {
      ArduinoDmx1.Process_ISR_TX(1);
    }
  #endif
  #if defined(USE_UART2)
    ISR(SIG_USART2_TRANS)
    {
      ArduinoDmx2.Process_ISR_TX(2);
    }
  #endif
  #if defined(USE_UART3)
    ISR(SIG_USART3_TRANS)
    {
      ArduinoDmx3.Process_ISR_TX(3);
    }
  #endif
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  #if defined(USE_UART0)
    ISR(USART_TX_vect)
    {
      ArduinoDmx0.Process_ISR_TX(0);
    }
  #endif
#endif

void CArduinoDmx::Process_ISR_TX(uint8_t tx_isr_number)
{
  TxState = gTxState;

  if(tx_isr_number == 0)
  {
    if (TxState == TXBREAK) //BREAK + MAB
    {
      UBRR0H   = 0;
      UBRR0L   = speed_break;
      UDR0     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR0H   = 0;
      UBRR0L   = speed_dmx;
      UDR0     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif
      CurTxCh = gCurTxCh;
      UDR0 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(0); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)

  else if(tx_isr_number == 1)
  {
    if (TxState == TXBREAK)
    {
      UBRR1H   = 0;
      UBRR1L   = speed_break;
      UDR1     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR1H   = 0;
      UBRR1L   = speed_dmx;
      UDR1     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif
      CurTxCh = gCurTxCh;
      UDR1 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(1); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
  else if(tx_isr_number == 2)
  {
    if (TxState == TXBREAK)
    {
      UBRR2H   = 0;
      UBRR2L   = speed_break;
      UDR2     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR2H   = 0;
      UBRR2L   = speed_dmx;
      UDR2     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif
      CurTxCh = gCurTxCh;
      UDR2 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(2); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
  else if(tx_isr_number == 3)
  {
    if (TxState == TXBREAK)
    {
      UBRR3H   = 0;
      UBRR3L   = speed_break;
      UDR3     = 0;                                 //send break
      gTxState = TXSTARTB;
    }
    else if (TxState == TXSTARTB)
    {
      UBRR3H   = 0;
      UBRR3L   = speed_dmx;
      UDR3     = 0;                                 //send start byte
      gTxState = TXDATA;
      gCurTxCh = 0;
    }
    else
    {
      #if defined(USE_INTERBYTE_DELAY)
        delay_gap();
      #endif
      CurTxCh = gCurTxCh;
      UDR3 = TxBuffer[CurTxCh++];               //send data
      if (CurTxCh == tx_channels)
      {
        if (*TXisrCallback) TXisrCallback(3); // fire callback for update data
        gTxState = TXBREAK;   // new break if all ch sent
      }
      else
      {
        gCurTxCh = CurTxCh;
      }
    }
  }
#endif
}

void CArduinoDmx::set_speed(uint8_t mode)
{
  if(mode == 0)
  {
    speed_dmx   = DMX_512;    // DMX-512  (250 kbaud - 512 channels) Standard USITT DMX-512
    speed_break = BREAK_512;
  }
  else if(mode == 1)
  {
    speed_dmx   = DMX_1024;   // DMX-1024 (500 kbaud - 1024 channels) Completely non standard, but usefull ;)
    speed_break = BREAK_1024;
  }
  else if(mode == 2)
  {
    speed_dmx   = DMX_2048;   // DMX-2048 (1000 kbaud - 2048 channels) Used by manufacturers as DMX1000K, DMX-4x or DMX-1M ???
    speed_break = BREAK_2048;
  }
}

#if defined(USE_INTERBYTE_DELAY)

void CArduinoDmx::delay_gap() // rare cases of equipment non full DMX-512 compliant, need this
{
  if(dmx_mode == 0)
  {
    _delay_us(IBG_512);
  }
  else if(dmx_mode == 1)
  {
    _delay_us(IBG_1024);
  }
  else if(dmx_mode == 2)
  {
    _delay_us(IBG_2048);
  }
}
#endif

myFile.ino
/*-----------------------------------------------------------------------------
        include files
------------------------------------------------------------------------------*/
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <lib_dmx.h>

#define DMX512  (0)

byte mac[] = { 0xDD, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,0,0,2); // TODO: assign ip address from DHCP
unsigned int multicastPort = 8888;
IPAddress multicastIp(239,0,0,57);

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];

EthernetUDP Udp;

int sensorValue = 0;
int ledState = 0;
int DMXPin = 0;

void setup() {

  // DMX
  ArduinoDmx1.set_control_pin(DMXPin);
  ArduinoDmx1.set_rx_channels(1);
  ArduinoDmx1.set_tx_channels(5);
  ArduinoDmx1.init_tx(DMX512);

  Ethernet.begin(mac,ip);
  Udp.beginMulti( multicastIp, multicastPort );
  Serial.begin(9600);

}

void loop() {
  int packetSize = Udp.parsePacket();
  if(packetSize){
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++){
      Serial.print(remote[i], DEC);
      if (i < 3){
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer[0]);

    ArduinoDmx1.TxBuffer[0] = (int)packetBuffer;
  }
}

It seems that, from the discussion on the page you link to, the author of the DMX Library himself is not sure how to get this to run.
The easiest solution, it seems to me, is to modify HardwareSerial.cpp in your Arduino core to no longer use that interrupt vector.

I was hoping to prevent editing of core libraries, but I guess there's no other option... Thanks :)

You use the Serial.begin(9600) and other Serial functions in your sketch. Therefore the HardwareSerial library is included. Just avoid the Serial stuff in your sketch, it won't work anyway, because the DMX uses the same serial port.
Have a look to
"Don't use the Arduino Serial implementation"
in
http://www.mathertel.de/Arduino/DMXSerial.aspx
The Four Universes DMX 512 Library works the same way as the DMXSerial library.