text:
How can I get a unique address for all my Arduino boards while in RS485?
My attempt is to know how to identify the board I'll be sending parameters to in a serial connection like rs485.  I'm asking because I will have about 11 or so mcu's as "Rx slaves" while my pc is the Master "Tx". I want to know how my code block is being sent to a specific board will be received by just that board and not all the other boards connected to that Rx port COM?
If I send 'LT2|LP3|LM5|LR4|LI6' and I want that to be for one specific Arduino, I don't want all the other 10 arduinos to take those parameters in this serial Rx line.
@Federico Fissore you mentioned in another post "Some boards, when connected to a computer, publish their serial number. My Arduino Uno R3 says"
[16818.451423] usb 3-2: SerialNumber: 85235353137351E02242

how and where can i find this info?

You can't; it's locked up in the other chip.

@ Ignacio Vazquez-Abram dam! ok thanks thought i can just use that to add to my const unique address before i Tx to serial

The simplest thing would be to burn a serial number into each chip's EEPROM, and interrogate that at startup.

@Nick Gammon i dont think that could have sounded more advance for me then anything thus far lol any links on how to go about that ? im just not getting the big picture thanks!

Related to your other thread: I'm looking for a way to Serially communicate with a multi mesh Arduino Slave Network

what was that link for ? @NickGammon

You seem to be also asking this question in another thread. In other words, cross-posting. In the other thread you said if send 'LT2|LP3|LM5|LR4|LI6' and i want that to be for one specific arduino i dont want all the arduinos to take those parameters. Isn't that basically your question here? Asking the same question in multiple threads dilutes the answers, and some people may not notice that there is a similar answer (to one they are about to spend 10 minutes typing) in this other thread. It would be courteous to either not cross-post, or to point out your other thread yourself.

i dont feel like im asking the same question nick how ever if you wan to help i think is you who should stick to one thread, cuz even if i was asking the same question which im not but  lets say i was "would you say your answers are correct?" i mean i am getting different answers aren't i ? this would imply that i am asking 2 completely different question

i mean that the answers being given by both threads aren't consistent and therefor someone is not being honest or knowledgeable about what they are saying for a answer "so think about that for a second and find my logic before you think about going back and forward with a discussion that has nothing to do with the main question in this pg, okay?!
at he end of the day if i was to ask a second question within the same subject i would have to refer to my past exp in this website where i was told that if i have another question to ask START A NEW THREAD

I dont think that could have sounded more advanced for me then anything thus far. Any links on how to go about that?

First, run a sketch like this for each board:
#include <EEPROM.h>

const int SERIAL_NUMBER_ADDRESS = 1023;
const byte SERIAL_NUMBER = 42;
void setup ()
  {
  // don't do it if it has been done before
  if (EEPROM.read(SERIAL_NUMBER_ADDRESS) != SERIAL_NUMBER)
    EEPROM.write(SERIAL_NUMBER_ADDRESS, SERIAL_NUMBER);
  }  // end of setup

void loop () { }

The serial number address can be any address in range for that chip - a Uno has 1024 bytes. I chose 1023 to leave the other addresses free, but it could be 0. Anything you don't need for any other purpose.
Then write a different serial number to each board (eg. 42, 43, 44, 45). Obviously you change the sketch each time you upload to a different board.

Once you have done this (once per board) now each board "knows" its serial number. You can detect this in your main sketch:
#include <EEPROM.h>

const int SERIAL_NUMBER_ADDRESS = 1023;
byte serialNumber;
void setup ()
  {
  Serial.begin (115200);
  Serial.println ();
  serialNumber = EEPROM.read(SERIAL_NUMBER_ADDRESS);
  Serial.print (F("Serial number of this board is: "));
  Serial.println (int (serialNumber));
  }  // end of setup

void loop () { }

Output for me in this case was:
Serial number of this board is: 42

Also I have a post about RS485 on my forum.

Just assign every node a variable like "const int ID = 5" and so on and then before sending the instructions send a line terminator, the ID, line terminator and the data you need to send to the nodes. Every device listens but they all wait their ID to accept the commands. For example:
Serial.write('\n');
Serial.print(ID);
Serial.write('\n');
Serial.print(|LT2|LP3|LM5|LR4|LI6);
Serial.write('\n');

NOTE: This is the easiest way. Most likely not the most reliable or optimized.

Comments are not for extended discussion; this conversation has been moved to chat. (cc @Frank'sDesig'Nature)

why not just use a usb tower and connect all my arduino's to that tower usb style just like when they plug into my pc and connect the other end of the usb tower into my pc ? doesn't that sound more easy and less complex?
this way i can just use the # of the com port as the address?

@Frank Yes that would work.


text:
Are there any Analog pins on the mega that can not be used as Digital?
I am using both Arduino nano and Arduino mega boards in my projects.  I got a nasty surprise the other day when I learned that, on the nano, Analog pins 6 and 7 can not be used as digital pins.
Are there any Analog pins on the mega that can not be used as Digital?

No, the ATmegaXXX0 has no analog pins without GPIO capability.
Additionally, the ATmegaXX8PB adds GPIO capability to the other analog pins plus a couple of the supply pins, so if you can convince someone to slip one of those on instead then you will gain two GPIOs (a respin will be required to access the ones on supply pins). Note that the core will also need to be modified, but it's only a couple of quick changes.

On https://www.arduino.cc/en/Main/ArduinoBoardNano it says:

Analog pins 6 and 7 cannot be used as digital pins.

There is no such corresponding statement on https://www.arduino.cc/en/Main/ArduinoBoardMega2560 and judging by the datasheet all of the analog pins can be used as digital pins.

source: Stack Exchange

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

sort: votes


text:
Using USB on a Leonardo to receive data from PC
I am new to the Leonardo, having only used a duemilanove before, and I am interested in using it's USB capabilities for a project.
Basically I need it to be an input and output device, communicating to an app on the PC (probably written in C#). I need to be able to handle button presses on the arduino and get data back from the PC to display on a display connected to the arduino.
I already have the basics done hardware wise (getting the keypad and displays working as I want them to), but now the tricky part is the USB communication. The only things I can find seem aimed at emulating a keyboard and mouse - I need 2 way communication data wise.
Are there any examples of something like this? I am sort of looking for the arduino equivalent of this: http://www.waitingforfriday.com/index.php/Building_a_PIC18F_USB_device
An alternative would be to just use serial, but I don't want to be fiddling with COM ports on the PC side - it just needs to be plugged in and work.
Would be grateful for any input on this subject, if it is even possible!

Congratulations, you've successfully found a project that goes beyond what the Arduino IDE provides for you out of the box. Your options are to 1) write a custom Arduino core that has additional/only the USB connections you need, or 2) do the same but with LUFA or ASF.

BytesGuy, from ArduinoBoardLeonardo at arduino.cc,  “on the Leonardo, the Serial class refers to USB (CDC) communication”.  That is, its Serial link is a USB link and does not involve any RS232-type serialization at either end of the link, merely the usual amount of link-level serialization that Universal Serial Bus entails.  So I see no reason not to use it, aside from its clunky API.

@IgnacioVazquez-Abrams Yeah I thought it was a bit ambitious :)

@jwpat7 Interesting, I will have to dig a bit deeper with that. I have only used Serial with the old FTDI style duemilanove.

On any version of Windows below 10 you will need to install drivers for the serial to work. It won't just "plug in an work".  For that I think you need to use the USB HID protocol, which is the bi-directional variant of the keyboard and mouse interface.

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


text:
Running both sensor and addressable LED strips at a same time?

I'm trying to obtain the sensors' readings as well as making the LED strips to light up at this particular pattern, if the sensor readings reaches certain values. But since both of these codes are inside the void loop(), there will be a problem. How can I do this correctly?
void loop()
{
    currentSensorReading = analogRead(sensorPin);
    Serial.println(currentSensorReading );

    if(currentSensorReading is in range of certain values){
        rainbowCycle(20);
    } else { turn LEDs off }
}

void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

Cross-posted on Arduino Forum

Rewrite without using delay(). Or alternatively, do the test inside the for loop as well, eg.
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);

    // ----------- ADD THESE THREE LINES ---------------
    currentSensorReading = analogRead(sensorPin);
    if(currentSensorReading is NOT in range of certain values)
        return;

  }
}


text:
Arduino reads bogus from serial
Recently I've started playing around with an Arduino Uno (rev 3), and I've set up a communication bridge between the Arduino and my computer using Python. So I send a command in Python ("ping" for instance), which is then read and interpreted. I've had it working before, using the Python commands to control a motor, but today it became non-responsive. However, only if I boot the serial monitor from the Arduino IDE, it suddenly accepts my commands again. Further inspection reveals that the Arduino is probably reading empty or corrupted data, interpreting it as ð, à and ÿ and such.
Here is an excerpt of the Python code I'm using:
import sys, glob, serial, time, re

class interface:

     timeout = 2    # 10 second time-out

    def __init__(self):
        port = "/dev/ttyACM0"
        self.connect(port)
        pass

    def connect(self, port="/dev/ttyACM0"):
        global arduino
        arduino = serial.Serial(port, baudrate=115200, bytesize=8, parity=serial.PARITY_NONE, stopbits=1, timeout=0.1)  # Establishing connection
        time.sleep(3) # Allowing the connection to settle
        arduino.flush()
        print "Connection established..."

    def ping(self):
        arduino.flush()
        arduino.write("ping")
        msg = self.listen_arduino()
        print msg
        if msg == "ping_ok":
            print "pinged"
            return True
        return False

    def listen_arduino(self):
        timeout = self.timeout
        matcher = re.compile("\n")
        buff = ""
        t0 = time.time()
        buff += arduino.read(128)

        while (time.time() - t0) < timeout and (not matcher.search(buff)):
            buff += arduino.read(128)
        return buff.strip()

And here is the Arduino C code:
String readString;

void setup() {
    Serial.begin(115200); // use the same baud-rate as the python side
}

void loop() {
    readString = listen(); // listen for any commands
    if (readString.length() > 0) {

        Serial.println(readString); // print the command

        if(readString == "ping") {
          Serial.write("ping_ok");
        }
    }
}

String listen() {
    String readString;
    while (!Serial.available());
    while (Serial.available()) {
        delay(1); // Allow the buffer to fill
        if (Serial.available() > 0) {
            char c = Serial.read();
            readString += c;
        }
    }
    return readString;
}

I suspect there is something fishy with the connection I'm making on the Python side, as the Arduino IDE serial monitor works just fine. I hope anyone can spot the problem in this code, I'm willing to provide more details on request.
Thanks

Try with one letter. See if that helps.

change the code to Serial.available()>0 because by default the output is -1, this could be the reason you are receiving junk values.

I've discovered that there was another program trying to access the Arduino, interfering with the code above and causing corruption of the signal. After terminating the intrusive program, the code worked just fine.


text:
How to use a grove speaker without using delayMicroseconds?
is there another way to replace delayMicroseconds(BassTab[note_index]) as I cannot have delays in my loop due to the need of having multi-tasking in my sketch.
Grove speaker: http://www.seeedstudio.com/depot/Grove-Speaker-p-1445.html
/*macro definition of Speaker pin*/
#define SPEAKER 8

int BassTab[]={1911,1702,1516,1431,1275,1136,1012};//bass 1~7

void setup()
{
  pinMode(SPEAKER,OUTPUT);
  digitalWrite(SPEAKER,LOW);
}
void loop()
{
    sound(5);
    delay(5000); //Wait 5second and play the sound again
}

void sound(uint8_t note_index)
{
  for(int i=0;i<100;i++)
  {
    digitalWrite(SPEAKER,HIGH);
    delayMicroseconds(BassTab[note_index]);
    digitalWrite(SPEAKER,LOW);
    delayMicroseconds(BassTab[note_index]);
  }
}

It's just a small amplifier and speaker - what you put into the SIG pin gets amplified and sent out the speaker.
Instead of doing the audio generation manually like that I would suggest using the tone() function which will generate an audio tone at a desired frequency in the background.

https://www.arduino.cc/en/Reference/Tone


text:
How to blink a series of LED alternately only one at a time
I am very much new to Arduino. I recently bought an adruino uno. i can blink an LED alternately. Such as, 1st blink red, then blink green, then blue like that. once only one LED should blink.
I have provided the code blinking an LED. How to modify this to blink multiple LED one after another.
void setup() {

  pinMode(13, OUTPUT);

}

void loop() {

  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

Could you please provide some more details? What are you trying to do? What have you tried so far? Are you trying to control multiple LEDs?

Most newbie problems involve more than code. The problem often lies in the wiring. Please give us some information about your wiring.

i have provided code of blinking one LED. now i just want to blink multiple LED one after another. alternately.

Who flagged this a "unclear what you are asking"? It's clear. He wants to blink 3 LEDs in sequence.

yes @NickGammon

You could always copy and paste:
void setup() {

  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

}

void loop() {

  digitalWrite(11, HIGH);
  delay(1000);
  digitalWrite(11, LOW);
  delay(1000);

  digitalWrite(12, HIGH);
  delay(1000);
  digitalWrite(12, LOW);
  delay(1000);

  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

A bit better would be to learn about functions:
void setup() {

  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

}

void blink (const byte which)
  {
  digitalWrite(which, HIGH);
  delay(1000);
  digitalWrite(which, LOW);
  delay(1000);
  }  // end of blink

void loop() {
  blink (11);
  blink (12);
  blink (13);
}

And you could learn about loops:
void setup() {
  for (int i = 11; i <= 13; i++)
    pinMode(i, OUTPUT);
}

void blink (const byte which)
  {
  digitalWrite(which, HIGH);
  delay(1000);
  digitalWrite(which, LOW);
  delay(1000);
  }  // end of blink

void loop() {
  for (int i = 11; i <= 13; i++)
     blink (i);
}

There is a whole world of stuff to learn. Enjoy the process!

thnksssssssss :)

Have you considered connecting another LED and turning one on and the other off sequentially?
void setup() {

  pinMode(13, OUTPUT);
  pinmode(NewLEDPin, OUTPUT);

}

void loop() {
  digitalWrite(NewLEDPin,LOW);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(NewLEDPin,HIGH);
  digitalWrite(13, LOW);
  delay(1000);
}

i'll try , but what is it "NewLEDPin" ,,, there is no PIn no ..

@user3099225 look, there are two parts to any program, the software and the hardware. The software is in front of you, and the hardware is for you to set up. Connect another led to the board in a similar manner to the way your first led us connected and replace "NewLEDPin" with the pin that the led is connected to


text:
Speaker not producing the right sound after a led strip was introduced

Grove speaker:
http://www.seeedstudio.com/depot/Grove-Speaker-p-1445.html
ws2812-led strip

Hi, I have been working to produce tones on a speaker and it works with the following code
    int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3, NOTE_B3, NOTE_C4};
    ...
    ...
    tone(pin, melody[pitch]);

After I included my addressable LED strip sketch codes, the speaker does not produce the same tone as normally it does. It sounded distorted this time round.
void loop()
{
  strip.Update(); //NeoPatterns strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800, &StripComplete);
}

Class:
// NeoPattern Class - derived from the Adafruit_NeoPixel class
class NeoPatterns : public Adafruit_NeoPixel
{
  public:

// Member Variables:
    ...
    ...

void (*OnComplete)();  // Callback on completion of pattern

// Constructor - calls base-class constructor to initialize strip
NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)())
  : Adafruit_NeoPixel(pixels, pin, type)
{
  OnComplete = callback;
}

// Update the pattern
void Update()
{
  if ((millis() - lastUpdate) > Interval) // time to update
  {
    lastUpdate = millis();
    switch (ActivePattern)
    {
      case RAINBOW_CYCLE:
        RainbowCycleUpdate();
        break;
      default:
        break;
    }
  }
}

// Initialize for a RainbowCycle
void RainbowCycle(uint8_t interval, direction dir = FORWARD)
{
  ActivePattern = RAINBOW_CYCLE;
  Interval = interval;
  TotalSteps = 255;
  Index = 0;
  Direction = dir;
}

// Update the Rainbow Cycle Pattern
    void RainbowCycleUpdate()
    {
      for (int i = 0; i < numPixels(); i++)
      {
        setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255));
      }
      show(); // When I comment this line, the speaker will work properly. What is happening?
      Increment();
    }

The tone() command is interrupt driven.
To get the tight timing needed by the LED strips interrupts are disabled while sending the data.
That means the tone() command stops while you're updating the LED strips and starts again afterwards.
The end result will be the sound is corrupted - maybe sounding like it's bubbly or underwater or just "rough".
The two basically can't work together and I'm not sure what to suggest to make them work together on a low-end MCU like the AVR.

What about using this library? http://forum.arduino.cc/index.php?topic=143940.0

or are there any possible workaround to play a sound together with the LED strip? My sketch will consist of a sensor,a servo and a LED strip.

That one also uses interrupts.

Either only update the led strip in between tones, or build your own tone function that changes the PWM frequency on one of the PWM pins (probably 9 or 10, since timer1 would be the most useful for that).


text:
arduino due-Python interfacing for high speed data rate
Four our project, I want to send data mesured by an Arduino due to a computer via Pyton very vast. So I tried to make a simple benchmark by sending 10240 int datas to determine the time it take. In order to do this, I first try using the programming port and execute this simple script:
int i=1;
int maxv=10240;
int value[10240];
int deb, fin;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(250000); //serial initialisation
  for (i=0 ; i<maxv ; i++){
    value[i]=i;
  }
  delay(200);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("starti"); //flag
  deb=micros();
  for (i=0 ; i<maxv ; i++) { // sending loop
      Serial.println(value[i]);
  }
  fin=micros();
  Serial.println("stopi");
  Serial.println((fin-deb)/1000000.0);
  delay(2000); //waiting
}

So with this I can mesure the time it take to send all the datas. And I receive it with this Python's script:
import numpy as np
import serial
ser = serial.Serial('/dev/ttyACM0', 250000)

value=np.empty(10240)

temp=ser.readline()

while temp!='starti\r\n': #search for the flag
    temp=ser.readline()

for j in range(10240):
    value[j]=int(ser.readline())

ser.readline()

time=float(ser.readline())
print time

with this beaudrate, it take nearly 2.4s which too slow for my purpose. If  try another baudrate, 500000 for example I read data like this : �Ë$Pd@s`¥š... I have this for all baudrate higher than 250000.
So I tried the native port which normaly send the data as fast as he can, but we this it took nearly 1.3s, and it's again too slow for my purpose.
I checked that it is not python wich is too slow, by doing the same than in the last example:
import time
import numpy as np

value=np.empty(10240)

deb1 = time.clock()

for j in range(10240):
    value[j]=j

fin1= time.clock()
print fin1-deb1

and it took only 4ms. So is it clearly the arduino wich send the data to slowly.
So how can I increase the data flux? I have seen the serial.write(buf,len) function which seems does not convert the data into ascii caracters. Does this function will be faster by putting the correct arguments? And, if it's the cas, how can I read this with Python?

There's two things you need to know:

The Serial.write(buf, len) function sends the raw data - one byte for every "len" count.
On the Due integers are 32-bits, so each one takes 4 bytes.

So first you need to define how big the numbers are you'll be dealing with and use data types that are big enough without being wasteful - you have 3 choices: char, short and int - 8, 16 and 32 bits respectively.

Values between 0 and 255 use an unsigned char (uint8_t)
Values between -128 and 127 use a signed char (int8_t)
Values between 0 and 65535 use an unsigned short (uint16_t)
Values between -32768 and 32767 use a signed short (int16_t)
Values between 0 and 4,294,967,295 use an unsigned int (uint32_t)
Values between −2,147,483,648 and 2,147,483,647 a signed int (int32_t)

One very tricky thing with this kind of binary data transfer is knowing where a value starts and ends.  You don't get that kind of issue with ASCII representations as you have a line feed and/or a carriage return after each full value and the range of valid characters that make up a value is very narrow and can never contain the delimiting character.  You don't have that luxury with binary transfers as there is no byte value that can't appear in a data stream.  However, there could be byte sequences that could never appear in the data stream - numbers you know you'll never be using that could form part of a synchronizing header (say, in hexadecimal, 0xFF 0xFF 0xFF 0xFF 0x00 0x00 0x00 0x00 - or in signed shorts that would be a sequence of 65535 65535 0 0) - once you see that sequence of bytes you know you're lined up with your data stream and can receive it byte by byte and build up the right sized values from that.
You can estimate your transfer time by working with the baud rate and knowing the data size.  For instance, to transfer 1000 short (16 bit) values at 250000 baud should take around:

1000 * 2 = 2000 bytes
250000 baud = 25000 bytes per second (8 bits for the byte, 2 bits for the start and stop bit)
2000 / 25000 = 0.08s

Ok, let say I want to send 1000 short as you suggest. Which function I should use to access the 0.08s for time transfert you told? The Serial.write() function or an another? Do you have a simple example?
Thanks

Yes use serial.write.

@Majenko: I didn't realize that int on the Due takes a whole 4 bytes. I suppose that's related to the difference between a 32-bit and 8-bit processor? Would a byte variable then also take twice as much space compared to the Uno? I'm surprised I didn't run into any obvious problems from this.

@jerry no a byte is always a byte, I.e., 8 bits. A byte is a basic unit, an integer is a numerical concept. Ints in c come in two basic sizes: short and long. Short is 16 bits and long is 32 bits. Unless you specify a size the default is used. On 8 bit systems a long takes a lot more processing than a short, so a short is the default. The opposite is true on 32 bit do a long is the default.


text:
How to use the eclipse arduino scope?
I am quite new to the Arduino stuff. I have got the Arduino IDE installed side by side with Eclipse. I am using Eclipse with the Arduino plugin, which is working well for me, including the SerialMonitor.
If you're using Eclipse with the Arduino plugin, it'll also add two new views. One is the serial monitor, the other one is called scope. Scope is a 6 channel Oscilloscope. But I don't know how to get values displayed there.
I am just curious how to use the scope there. I can't find any tutorial for this.
Can somebody explain how to show something inside the scope?

What type of scope you are talking about?Add more explanation to your question.!

Well, if you're using eclipse with the arduino plugin, it'll also add two new views. One is the serial monitor, the other one is called scope. Scope is a 6 channel Oscilloscope. But i dont know how to get values displayed there.

I don't know about eclipse scope, but there is a software Proteus, it has an option of virtual oscilloscope. You can use that.!

Thanks for the hint, but that doesn't answer my question ;)

http://blog.baeyens.it/#post12 may help.

@yeti Thanks, i found this link also during my own search. Unfortunately it doesn't help at all

Can you post the link to the instructions you are using for the scope?
I have used Eclipse with Arduino, but I never noticed such thing.

@IgorStoppa there is not any manual, just use the adruino menu from eclipse to open scope, its just beside the serial monitor

The simplot library (referenced below) is an excellent example of how to use the scope which works as advertised.
Firstly, readers should note that there are two different Arduino plugins for Eclipse ("Eclipse C++ IDE for Arduino" and "Arduino Eclipse plugin named Sloeber V3"). Only the latter has a scope and a seriel monitor that allows data to be sent.
Getting simplot and the scope to work, however, can be a problem depending on the platform. On a Mac, with the latest version of Eclipse (Neon.2 Release Candidate 2) and the Sloeber V3 plugin, the default path to the Private Library is Users/yourname/Arduino/libraries. Unfortunately, this path doesn't (necessarily) exist.
One could spend hours trying to figure out how and where to import a library when the critical library folder doesn't exist.
The solution (at least on a Mac):

Create a folder (arbitraily) named "Users/yourname/Eclipse/libraries".
Include this folder in Eclipse - Preferences - Arduino - Private Library Path
Download jantje's entire Github Arduino Library, unpack it and move the "simplot" folder into your Private Library Folder. "simplot" should now show up in the libraries.
Use: Arduino - Add a Library to the Selected Project
Or build a project using the simplot.ino example.

It should work beautifully.

Given that two bytes are short, you send:

SCOPE_START_DATA short flag: 0xCDAB
short number of following bytes to read (for example, 0x0002 for only one channel)
one short per channel

P.S. This is shamelessly stolen from it.baeyens.arduino.monitor.views.ScopeListener

The plugin FAQ links to a defunct website. However the internet wayback machine reveals some good info (https://web.archive.org/web/20150321054307/http://www.negtronics.com/simplot). In particular a link to the arduino forums that has some code samples: http://forum.arduino.cc/index.php?topic=58911.0

Try the simplot library.
It is from the author of the plugin and works with both 32 and 8 bit processors. There is an example included that should get you going.
The plotter itself automatically connects to the first serial connection so there is no connect needed for the plotter like there is for the serial connection.

Does this help the user use the scope, which is apparently within Eclipse, when the Arduino plugin is used? Seeing as you have a GitHub repository for the arduino-eclipse-plugin, and you are the author of the Arduino plugin, presumably it does. If you could expand upon your answer that would be very helpful. :-)

Honestly, I don't know how to extend more on this.
And downvoting -with no clear remark on what is should be fixed- does not help my appetite to be active on this site.
Sounds like "it doesn't work"


text:
Advice on setting up a real-time audio equaliser
First time Arduino user here.
We have a microphone set-up which feeds back loudly on particular frequencies and need an equalizer to (preferably automatically) detect spikes in particular frequency bands and attenuate them before sending them on to the speakers. The dB level that has been cut from that frequency channel would then be displayed on an LED matrix such as this one:

Does the Arduino have the processing capabilities to keep up with the audio without noticeable lag? As the LEDs will only be a visual indication of the affect the attenuation is having on the frequencies, it is not particularly important that these be fast. Unfortunately, as the audio stream will be vocals, even a slight delay will render the thing useless. What delay might I expect with a single mono channel going through the arduino?
I expect that I will eventually have to revert to the less-interesting project of an RTA which takes a split of the audio sends to the speakers and simply displays the frequency band intensities rather than altering them.
I'd appreciate any thoughts.

How were you planning on performing the attenuation?

Have you looked at using an FPGA?

Try Googling "Arduino FFT". I found this one for example which looks remarkably like what you are asking about.

Somewhat possible if you accept that the Arduino won't be doing most of the work:

Yes, the Arduino can sample audio and perform FFT on it, though not fast and not at high frequencies
Yes, the Arduino can decide what to do depending on the power of different buckets
Yes, the Arduino can display the results
No, the Arduino cannot do realtime audio filtering.

If you accept that the filtering will have to be done with a bank of analogue band-cut filters that the Arduino turns on and off as needed then it may be possible.
The Arduino Due might be a more suitable candidate since it will be able to sample and do the FFT much faster so you'll be able to respond to the peaks much quicker, and the displaying won't get in the way so much, but actively filtering inside the chip really requires a DSP.


text:
Creating a keypad matrix that will communicate wirelessly with an Arduino Uno
I have a 30 button matrix and I would like to use a keyboard encoder to decipher what button was pressed. I would like that information (what button was pressed) to be wirelessly sent to my arduino uno nearby. What is the easiest solution? Can/how can I incorporate Arduino's Bluetooth shield to achieve this?

Which keyboard encoder? Or are you asking how to make one? Are you planning to have a second Arduino adjacent to the matrix to encode the keypresses?

Bluetooth is overkill, and unnecessarily complex for this simple task. Try looking and XBee, NRF24L01, or those cheap 433MHz transmitter/receiver pairs.

NRF24L01 is the best option. Takes the lowest amount of power if properly configured.


text:
Serial communication using Arduino and TeraTerm
I wrote a simple serial program using Arduino Mega 2560, it is connected to COMPORT 10. Here is the program I Wrote,
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println("HELLO");
  delay(1000); //Send every one second
}

Now, I tried to send this message "Hello" to TeraTerm (COMPORT 1, for this I just hooked up Tx and Rx to the Arduino's Rx0 and Tx0. Doing this I do receive message in my TeraTerm screen but the received message doesn't make sense, its receiving garbage. Its not the case of mismatch of baud rate I am using 9600 on both the side.
However I do receive message "HELLO" in the serial monitor. Is there something I am doing wrong that I am not receiving message on TeraTerm.

Possibly related: Common Serial Problems

I presume this works with the serial monitor in the Arduino IDE?

Where did you hooked up your tx rx? what is the device? Are you connecting you arduino to your pc using cable? Explain a little bit about your circuit!

Are you just plugging straight into a 9 pin D connector on the back of your computer, or are you using a USB to serial adapter of some form - if so, what is it (link)?

What is TeraTerm? Can you post a link please? it is connected to COMPORT 10 ... COMPORT 1, for this I just hooked up Tx and Rx to the Arduino's Rx0 and Tx0. You've lost me here. You connected what to what?

@NickGammon Tera Term is like a serial monitor just like hyper terminal,putty,docklight. Well this question needs a more explanation because author dont need to connect anything, arduino itself is connected to Com port so you can easily see what you are sending. Or if he is connecting it to some device, then what device?

My guess, from the scant information we have so far, is that the signals are inverted polarity, and quite possibly the wrong voltage as well.

... I just hooked up Tx and Rx to the Arduino's Rx0 and Tx0.

But neither device knows what voltage they are. You need to connect ground as well so that they have a common reference.

You mean the pin no 5 of the serial connector to the ground of the Arduino?

Whatever ground is to whatever ground is.

This still doesn't help, I am still receiving same kind of message, nothing changed :\

These devices are already connected via USB. Apart from implementing some type of opto or galvanic isolation, not much else we can do, yeah?

Hello everyone thanks for your reply,
I found the problem :D and was also able to solve it.
I was directly connecting the Tx and Rx pin of Arduino to the Rx and Tx pin of DB9 connector on PC. Since, DB9 on the PC operates on higher voltage than the operating voltage of the Arduino which is 5V. This mis-match of the voltage was causing the problem, So in order to solve this i added a level shifter in between (MAX232) and now it works perfect.
Thanks everyone for replying.


text:
How to interconnect multiple Arduinos with a Rpi to control home-lights/switches
While planning the lightning infrastructure (wall-switches and lights) of my new home (it's still under-construction) I choosed to go through the "automated route" way and due to my background (I'm an "old" system/network administrator with programming skills and plenty of Open-Source "passion" and "advocacy") I'm seriously trying to implement it with three Arduinos and one RPi2.
Due to number/location of wall-push-buttons and lights, I'd like to use three MEGA interfacing both wall-push-buttons and lights of surrouding rooms. Furthermore, a RPi2 (or similar) will be used as a "controller" to properly programs MEGAs, when needed, and interfacing some other equipments (touch-screen; wifi tablet/smartphone; remote-controls; etc.) via the IP-network.
The schema I'm trying to implement is similar to this one:

where you see:

9 lights (L1 to L9) each one controlled by its own dedicated relay (R1 to R9);
7 wall push-buttons (WPB1 to WPB7), to be used to turn on/off one or more lights;
3 MEGAs interfacing wall-push-buttons and lights;
1 RPi2, acting as "supervisor" and "Internet/Ethernet gateway".

My main architectural problem relates to the interconnection between RPI2 and MEGAs. As each device will be located several tens of meters aways from each other, I ended with two only option (please, correct me if I'm wrong):

Ethernet
RS485

(BTW: I'm explicitely excluding "wireless connections", as I've already placed all the electrical pipes in a "compatible" way. In other words: I'd like to avoid wireless technologies within the "controlling network")
As for Ethernet, I'll choose it as a 2nd option, due both to a slightly higher cost and complexity (need a switch to be powered on; additional cabling issues; etc.).
I've extensively researched the "RS485 bus" and found that it's relatively easy --from a physical point of view-- to implement it with two wires in a multidrop configuration.
Unfortunately, from an "application point of view", things are more complex as it supports only "half-duplex" communications and, even worse, there is no provision to avoid "collisions" when communicating (that's why, probably, the MODBUS protocol --tipically employed on RS485 bus-- provides a "single-master; multiple-slaves" scenario).
Before the questions, I need to add another constraint: I want the infrastructure to be "as much fault-tolerant as possible", expecially towards problems with the BUS and/or with the "controller" (the RPI2). In other words:

each MEGA should allow to turn on its own lights when one of its own push-button requires this. For example:

if WPB1 controls L2 and L3, it need to be working even if the BUS is broken or the RPI2 is powered off;
if WPB3 controls L4 and L9, then should the bus/RPI2 have problems, only L4 will be powered on when WPB3 is pressed;

So, after all of the above, here are my questions:

is a two-wire RS485 multidrop bus, a suitable choice for my scenario?
if not, which (possibly cheap and simple) other solutions may I investigate?
if yes, which is the logic that I need to implement on MEGAs, as:

a) they need to act as "slave", with respect to RPI2 when turning on lights commanded by push-button connected to other MEGAs or when the RP2 decide to turn-on some lights (for example, due to remote/Internet access);
b) they need to act as "master", when one of their push-buttons is pressed and... this need to be communicated to RPI2 so to send commands to other MEGAs so to turn on "hosted" lights;

as for 3b), insted of having MEGAs acting as master when a WPB is pressed, may I implement a "frequent-polling" logic on the RPI2? If yes, which is a reasonable value for such a polling (1 poll per second? 5 polls per second? too much? too low?)

I understand that this is a too-wide question, but I really did lots of researches and despite lots, and lots, and lots of on-line documentation, I've been unable to find an answer to those questions.

Update 1

in terms of total numbers, I'll have 31 lights to be controlled by 46 wall push-buttons, more or less equally distributed in 4 distinct panel-boards;
As for the choise of MEGA (vs. UNO), I've choosed MEGA due to the bigger number of I/O PINs. I simply choosed the board with the maximun number of PINs;
As for the RPI2, I choosed to employ a proper "computer" (vs. an additional microcontroller), 'cause I want a sort of "decoupling" between the "physical controlling network" and the "User Management Interface". In other words, I want the management of physical buttons/relais to be handled by PLC-like device (Arduino: very quick power on; sort of real-time performance; very reliable; minor/no external "computing" factors introducing delays/problems); while, at the same time, all the user-interface be handled by a real-computer where I can easily write powerful HTTP web-services and/or really complex "logics", using technologies and languages that doesn't fit well with Arduino (later on --much later on--, I plan to add several 150$ full-HD 10.1" android tablets allaround the house, that will act as wireless "clients" towards what need to be a "powerful" (in terms of computing capacities) web-server; Also I plan to add various sensors [temperature; humidity; contacts; power-meters; etc.] whose data need to be stored for trending/archiving reasons). Hence, I tought about RPi2, than can easily be replaced with something more powerful, should it be needed.

You'll probably want something connected to the RPi that can do 9-bit communications on RS-485. Linux doesn't support 9-bit UARTs so you'd have to play ugly tricks with the parity bit without it.

What if I'll connect, via RS485, only ARDUINOs? I mean, the problem you're mentioning is strictly introduced by connecting RPI to RS485, right? I'm asking, 'cause based also on @nick-gammon answer below, I'll probably terminate the RS485 bus on ad additional Arduino, and having the interconnection between RPI and Arduino using Ethernet (and not RS485). In such a case, RPI will not need to speak RS485 and problem shoud disappear, right?

I just wanted to note that the chance of packet collisions is rather low. You only send packets when a switch is pressed, or when a light needs to turn on. Unless you live inside a disco, this only happens a few times a day per light/switch.

@Gerben: with my two young sons (2,5 and 5,5), I can assure you that such a probability is NOT so low as you might expect under "normal" conditions :-). Jokes aside, consider that should everything runs smoothly, I plan to add LOTS of additional sensors/devices to be queried via "bus traffic" (temperature/humidity sensors [one per room]; open/close contacts for doors/windows [at least two for each windows]; electricity-power-meters and water-usage-meters probably generating "pulses" to be collected in some way. So, again, when "collision" will happen, will my MEGAs "survive"? Or they'll burn?

I did a lengthy post about RS485.

First, your use of Megas seems an overkill, unless you already have them to hand. A Uno, or one of the smaller form-factor boards would seem to be perfectly adequate to monitor a few switches and turn on a couple of lights.
Even the Rpi seems unnecessary. Another Uno could easily monitor your RS485 lines and connect via Ethernet (an Ethernet shield) to the rest of your house or whatever you are doing.

... there is no provision to avoid "collisions" when communicating ...

Well, you build that in. You give each Mega an address (eg. stored in EEPROM) and then you "address" the one you want, and then wait for a response. For example, in the code from my page above:
Master
#include "RS485_protocol.h"
#include <SoftwareSerial.h>

const byte ENABLE_PIN = 4;
const byte LED_PIN = 13;

SoftwareSerial rs485 (2, 3);  // receive pin, transmit pin

// callback routines

void fWrite (const byte what)
  {
  rs485.write (what);
  }

int fAvailable ()
  {
  return rs485.available ();
  }

int fRead ()
  {
  return rs485.read ();
  }

void setup()
{
  rs485.begin (28800);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
  pinMode (LED_PIN, OUTPUT);  // built-in LED
}  // end of setup

byte old_level = 0;

void loop()
{

  // read potentiometer
  byte level = analogRead (0) / 4;

  // no change? forget it
  if (level == old_level)
    return;

  // assemble message
  byte msg [] = {
     1,    // device 1
     2,    // turn light on
     level // to what level
  };

  // send to slave
  digitalWrite (ENABLE_PIN, HIGH);  // enable sending
  sendMsg (fWrite, msg, sizeof msg);
  digitalWrite (ENABLE_PIN, LOW);  // disable sending

  // receive response
  byte buf [10];
  byte received = recvMsg (fAvailable, fRead, buf, sizeof buf);

  digitalWrite (LED_PIN, received == 0);  // turn on LED if error

  // only send once per successful change
  if (received)
    old_level = level;

}  // end of loop

You configure the RS485 transceiver to either send or receive. Normally it is in receive mode, and you switch to send mode to send a "packet" of data. (See "enable sending" above).

Now the addressed device turns its transceiver into "send" mode and replies. The code in the library I wrote has a time-out, so if that particular slave is dead, the receive times out. You might remember that at the master end and try to communicate with it less often. Or you may not care if the time-out is short.
Slave
#include <SoftwareSerial.h>
#include "RS485_protocol.h"

SoftwareSerial rs485 (2, 3);  // receive pin, transmit pin
const byte ENABLE_PIN = 4;

void fWrite (const byte what)
  {
  rs485.write (what);
  }

int fAvailable ()
  {
  return rs485.available ();
  }

int fRead ()
  {
  return rs485.read ();
  }

void setup()
{
  rs485.begin (28800);
  pinMode (ENABLE_PIN, OUTPUT);  // driver output enable
}

void loop()
{
  byte buf [10];

  byte received = recvMsg (fAvailable, fRead, buf, sizeof (buf));

  if (received)
    {
    if (buf [0] != 1)
      return;  // not my device

    if (buf [1] != 2)
      return;  // unknown command

    byte msg [] = {
       0,  // device 0 (master)
       3,  // turn light on command received
    };

    delay (1);  // give the master a moment to prepare to receive
    digitalWrite (ENABLE_PIN, HIGH);  // enable sending
    sendMsg (fWrite, msg, sizeof msg);
    digitalWrite (ENABLE_PIN, LOW);  // disable sending

    analogWrite (11, buf [2]);  // set light level
   }  // end if something received

}  // end of loop

Note: The example code from my linked page does not read the address from EEPROM, however that is trivial to implement.

I can't see any particular reason why you could not interrogate the slaves quite frequently. What else would the master be doing? You could also set up the master as a HTTP server so you could talk to it from your laptop, or some other part of the house.

My wiring:

To demonstrate the idea, I set up two Unos, connected via about 8 m of bell-wire (not even twisted pair, and certainly not shielded).

One Uno was running the standard ASCII table sketch (at 9600 baud), its Tx pin went into the LTC1480, and then the A/B pins went to the bell wire.
The other Uno was connected as a USB interface (Reset connected to ground) and it was just echoing whatever arrived on the Tx pin to the USB.
As far as I could see, it worked perfectly.

I will not need any poll at all, as with your approach I can implement a "single-master/multiple-slave" context... but with a "moving" master. Is this right?

My answer above assumed that the slaves were more likely to fail than the master (can't quite think why this would happen, but perhaps based on the fact that there are more slaves than masters, and the master doesn't control things like lights).
I find my Arduinos extremely reliable when doing simple things (like unlocking a door when a RFID card is presented).
You could conceivably build a fall-back position into the slaves. After all, if they get polled every second, and then no poll arrives, they could conceivably attempt to take over as master, perhaps in ascending order of device number, to avoid conflicts. Part of this polling by the "new master" could be to check the "original master" to see if it was ready to resume its duties.
The library I described on my linked page has error checking built into it, the idea being that by checking a CRC on the packet you ensure that you don't come in half-way through a packet and misinterpret the data in it.
You could also build in some randomness of poll times to resolve a deadlock if two slaves attempted to become master at once. If a slave failed it could wait for a random (and increasing) time before trying again to give another slave a chance to do it.

I just wanted to note that the chance of packet collisions is rather low. You only send packets when a switch is pressed, or when a light needs to turn on.

Gerben is right, but I would be worried that a notification about a switch had gone unnoticed. One possible work-around here is rather than the slaves replying with state changes to a query, they reply with the current state. So it might go:
Master: Slave 3, what is your status?
Slave 3: Lights 1 and 4 on, lights 2 and 3 off.

I will not need any poll at all, as with your approach I can implement a "single-master/multiple-slave" context... but with a "moving" master. Is this right?

I've been thinking about this a bit, and I think now you could make a system that is basically master-free. It could work like this:

Each device has its own address, which it gets from EEPROM (or DIP switches). eg. 1, 2, 3, 4, 5 ...

You choose a range of addresses you are going to use (eg. maximum of 10)

When the device powers up it first listens for other devices "talking" on the bus. Hopefully it will hear at least one other (if not, see below).

We decide on a fixed "message packet", say of 50 bytes including address, CRC, etc. At 9600 baud that would take 52 ms to send.

Each device gets a "slot" of time, and waits its turn to talk to the bus.

When its timeslot arrives, it goes into output mode, and broadcasts its packet which includes its own address. Therefore all the other devices can now read its status (and act upon it if necessary). Eg. device 1 might report that switch 3 is closed, which means device 2 must turn a light on.

Ideally, you know your timeslot has arrived because your device address is one greater than the packet you just listened to. Eg. You are device 3. You just heard device 2 announce its status. Now it's your turn. Of course, you wrap around at the maximum number, so after device 10 you go back to device 1.

If a device is missing and does not respond, you give it (say) half a timeslot to respond, and then assume it is dead, and every device on the bus now assumes the next timeslot has started. (eg. You heard device 2, device 3 should respond, after 25 ms of inactivity, device 4 can now respond). This rule gives a device 25 ms to respond, which should be plenty even if it is servicing an interrupt or something like that.

If multiple devices in sequence are missing you count a 25 ms gap for each missing device, until it is your turn.

Once you get at least one response the timing is resynchronized, so any drift in clocks would be cancelled.

The only difficulty here is that upon initial power-up (which might happen simultaneously if the power to the building is lost and then restored) there is no device currently broadcasting its status, and thus nothing to synchronize to.
In that case:

If after listening long enough for all devices to be heard (eg. 250 ms) and hearing nothing, the device tentatively assumes it is the first one and makes a broadcast. However possibly two devices will do that at the same time, and thus never hear each other.

If a device has not heard from another device, it staggers the time between broadcasts randomly (perhaps seeding the random-number generator from its device number, to avoid all devices "randomly" staggering the broadcasts by the same amount).

This random staggering by additional amounts of time won't matter, because there is no-one listening anyway.

Sooner or later one device will get exclusive use of the bus and the other ones can then synchronize with it in the usual way.

This random gap between attempts to communicate is similar to what Ethernet used to do when multiple devices shared one coaxial cable.

Demo of master-free system
This was an interesting challenge, so I put together a demo of doing this without having any specific master, as described above.
First you need to set up the current device address, and the number of devices, in EEPROM, so run this sketch, changing myAddress for each Arduino:
#include <EEPROM.h>

const byte myAddress = 3;
const byte numberOfDevices = 4;

void setup ()
  {
  if (EEPROM.read (0) != myAddress)
    EEPROM.write (0, myAddress);
  if (EEPROM.read (1) != numberOfDevices)
    EEPROM.write (1, numberOfDevices);

  }  // end of setup

void loop () { }

Now upload this to each device:
/*
 Multi-drop RS485 device control demo.

 Devised and written by Nick Gammon.
 Date: 7 September 2015
 Version: 1.0

 Licence: Released for public use.

 For RS485_non_blocking library see: http://www.gammon.com.au/forum/?id=11428
 For JKISS32 see: http://forum.arduino.cc/index.php?topic=263849.0
*/

#include <RS485_non_blocking.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>

// the data we broadcast to each other device
struct
  {
  byte address;
  byte switches [10];
  int  status;
  }  message;

const unsigned long BAUD_RATE = 9600;
const float TIME_PER_BYTE = 1.0 / (BAUD_RATE / 10.0);  // seconds per sending one byte
const unsigned long PACKET_LENGTH = ((sizeof (message) * 2) + 6); // 2 bytes per payload byte plus STX/ETC/CRC
const unsigned long PACKET_TIME =  TIME_PER_BYTE * PACKET_LENGTH * 1000000;  // microseconds

// software serial pins
const byte RX_PIN = 2;
const byte TX_PIN = 3;
// transmit enable
const byte XMIT_ENABLE_PIN = 4;

// debugging pins
const byte OK_PIN = 6;
const byte TIMEOUT_PIN = 7;
const byte SEND_PIN = 8;
const byte SEARCHING_PIN = 9;
const byte ERROR_PIN = 10;

// action pins (demo)
const byte LED_PIN = 13;
const byte SWITCH_PIN = A0;

// times in microseconds
const unsigned long TIME_BETWEEN_MESSAGES = 3000;
unsigned long noMessagesTimeout;

byte nextAddress;
unsigned long lastMessageTime;
unsigned long lastCommsTime;
unsigned long randomTime;

SoftwareSerial rs485 (RX_PIN, TX_PIN);  // receive pin, transmit pin

// what state we are in
enum {
   STATE_NO_DEVICES,
   STATE_RECENT_RESPONSE,
   STATE_TIMED_OUT,
} state;

// callbacks for the non-blocking RS485 library
size_t fWrite (const byte what)
  {
  rs485.write (what);
  }

int fAvailable ()
  {
  return rs485.available ();
  }

int fRead ()
  {
  lastCommsTime = micros ();
  return rs485.read ();
  }

// RS485 library instance
RS485 myChannel (fRead, fAvailable, fWrite, 20);

// from EEPROM
byte myAddress;        // who we are
byte numberOfDevices;  // maximum devices on the bus

// Initial seed for JKISS32
static unsigned long x = 123456789,
                     y = 234567891,
                     z = 345678912,
                     w = 456789123,
                     c = 0;

// Simple Random Number Generator
unsigned long JKISS32 ()
  {
  long t;
  y ^= y << 5;
  y ^= y >> 7;
  y ^= y << 22;
  t = z + w + c;
  z = w;
  c = t < 0;
  w = t & 2147483647;
  x += 1411392427;
  return x + y + w;
  }  // end of JKISS32

void Seed_JKISS32 (const unsigned long newseed)
  {
  if (newseed != 0)
    {
    x = 123456789;
    y = newseed;
    z = 345678912;
    w = 456789123;
    c = 0;
    }
  }  // end of Seed_JKISS32

void setup ()
  {
  // debugging prints
  Serial.begin (115200);
  // software serial for talking to other devices
  rs485.begin (BAUD_RATE);
  // initialize the RS485 library
  myChannel.begin ();

  // debugging prints
  Serial.println ();
  Serial.println (F("Commencing"));
  myAddress = EEPROM.read (0);
  Serial.print (F("My address is "));
  Serial.println (int (myAddress));
  numberOfDevices = EEPROM.read (1);
  Serial.print (F("Max address is "));
  Serial.println (int (numberOfDevices));

  if (myAddress >= numberOfDevices)
    Serial.print (F("** WARNING ** - device number is out of range, will not be detected."));

  Serial.print (F("Packet length = "));
  Serial.print (PACKET_LENGTH);
  Serial.println (F(" bytes."));

  Serial.print (F("Packet time = "));
  Serial.print (PACKET_TIME);
  Serial.println (F(" microseconds."));

  // calculate how long to assume nothing is responding
  noMessagesTimeout = (PACKET_TIME + TIME_BETWEEN_MESSAGES) * numberOfDevices * 2;

  Serial.print (F("Timeout for no messages = "));
  Serial.print (noMessagesTimeout);
  Serial.println (F(" microseconds."));

  // set up various pins
  pinMode (XMIT_ENABLE_PIN, OUTPUT);

  // demo action pins
  pinMode (SWITCH_PIN, INPUT_PULLUP);
  pinMode (LED_PIN, OUTPUT);

  // debugging pins
  pinMode (OK_PIN, OUTPUT);
  pinMode (TIMEOUT_PIN, OUTPUT);
  pinMode (SEND_PIN, OUTPUT);
  pinMode (SEARCHING_PIN, OUTPUT);
  pinMode (ERROR_PIN, OUTPUT);

  // seed the PRNG
  Seed_JKISS32 (myAddress + 1000);

  state = STATE_NO_DEVICES;
  nextAddress = 0;

  randomTime = JKISS32 () % 500000;  // microseconds
  }  // end of setup

// set the next expected address, wrap around at the maximum
void setNextAddress (const byte current)
  {
  nextAddress = current;
  if (nextAddress >= numberOfDevices)
    nextAddress = 0;
  }  // end of setNextAddress

// Here to process an incoming message
void processMessage ()
  {

  // we cannot receive a message from ourself
  // someone must have given two devices the same address
  if (message.address == myAddress)
    {
    digitalWrite (ERROR_PIN, HIGH);
    while (true)
      { }  // give up
    }  // can't receive our address

  digitalWrite (OK_PIN, HIGH);

  // handle the incoming message, depending on who it is from and the data in it

  // make our LED match the switch of the previous device in sequence
  if (message.address == (myAddress - 1))
    digitalWrite (LED_PIN, message.switches [0]);

  digitalWrite (OK_PIN, LOW);
  } // end of processMessage

// Here to send our own message
void sendMessage ()
  {
  digitalWrite (SEND_PIN, HIGH);
  memset (&message, 0, sizeof message);
  message.address = myAddress;

  // fill in other stuff here (eg. switch positions, analog reads, etc.)

  message.switches [0] = digitalRead (SWITCH_PIN);

  // now send it
  digitalWrite (XMIT_ENABLE_PIN, HIGH);  // enable sending
  myChannel.sendMsg ((byte *) &message, sizeof message);
  digitalWrite (XMIT_ENABLE_PIN, LOW);  // disable sending
  setNextAddress (myAddress + 1);
  digitalWrite (SEND_PIN, LOW);

  lastCommsTime = micros ();   // we count our own send as activity
  randomTime = JKISS32 () % 500000;  // microseconds
  }  // end of sendMessage

void loop ()
  {
  // incoming message?
  if (myChannel.update ())
    {
    memset (&message, 0, sizeof message);
    int len = myChannel.getLength ();
    if (len > sizeof message)
      len = sizeof message;
    memcpy (&message, myChannel.getData (), len);
    lastMessageTime = micros ();
    setNextAddress (message.address + 1);
    processMessage ();
    state = STATE_RECENT_RESPONSE;
    }  // end of message completely received

  // switch states if too long a gap between messages
  if  (micros () - lastMessageTime > noMessagesTimeout)
    state = STATE_NO_DEVICES;
  else if  (micros () - lastCommsTime > PACKET_TIME)
    state = STATE_TIMED_OUT;

  switch (state)
    {
    // nothing heard for a long time? We'll take over then
    case STATE_NO_DEVICES:
      if (micros () - lastCommsTime >= (noMessagesTimeout + randomTime))
        {
        Serial.println (F("No devices."));
        digitalWrite (SEARCHING_PIN, HIGH);
        sendMessage ();
        digitalWrite (SEARCHING_PIN, LOW);
        }
      break;

    // we heard from another device recently
    // if it is our turn, respond
    case STATE_RECENT_RESPONSE:
      // we allow a small gap, and if it is our turn, we send our message
      if (micros () - lastCommsTime >= TIME_BETWEEN_MESSAGES && myAddress == nextAddress)
        sendMessage ();
      break;

    // a device did not respond in its slot time, move onto the next one
    case STATE_TIMED_OUT:
      digitalWrite (TIMEOUT_PIN, HIGH);
      setNextAddress (nextAddress + 1);
      lastCommsTime += PACKET_TIME;
      digitalWrite (TIMEOUT_PIN, LOW);
      state = STATE_RECENT_RESPONSE;  // pretend we got the missing response
      break;

    }  // end of switch on state

  }  // end of loop

As it currently stands, if you close a switch on A0 (short to ground) it will turn off a LED (pin 13) on the next highest device in sequence. This proves that the devices are talking to each other. Of course in practice you would have something more sophisticated in the packet which is being broadcast.
I found in testing that the LED appeared to come on and off instantly.
With all devices disconnected the first one connected will "hunt" for other devices. If you have debugging LEDs connected as I did you can see the "search" LED come on at random intervals as it broadcasts its packet with randomly-varying gaps. Once you have a second one connected they settle down and just exchange information. I tested with three connected at once.
It would probably be more reliable with HardwareSerial - I used SoftwareSerial to help with debugging. A few small changes would accomplish that.

Amended schematic

Screen-shots of the code in action
These images show the code working. First, with only one device connected:

You can see from the pulses there that the device is broadcasting its data at randomly-varying intervals, to avoid continuing to clash with another device that powered up at the same moment.

Now we see blocks of data from two devices, with roughly the same size gaps in the middle. I configured it for four devices, but only two are present, so we see two blocks of data, and two gaps.

Now with three devices online, we see three blocks of data, and one gap, as the missing device is bypassed.

If you are checking the figures, these were taken with the baud rate doubled, as a test, to 19200 baud.

Cable run test
For a proper hardware test, I connected the devices up to my in-house UTP cabling. I have cat-5 cable running from various rooms to a central plug-board. Going from one end of the house to another (a reasonable length run) it still works fine. There is 5 m cable between the Arduino and the wall socket, for a start. Plus another 5 m cable at the other end. Then there are about 2 x 15 m runs from the rooms to the switch room, and inside that there is a short bridging cable to connect them together.
This was with the boards still programmed to run at 19200 baud.

1st) Thanks VERY MUCH for your answer and RS-485 tutorial. I'll surely use it ; 2nd) as for MEGA and RPIs involvement, I've updated the OP. Please, refer to it for details; 3rd) as for "I can't see any particular reason why you could not interrogate the slaves quite frequently", is a 10-polls per second, on a 9600 baud rate,  a reasonable choice? And finally: if I understood correctly, I will not need any poll at all, as with your approach I can implement a "single-master/multiple-slave" context... but with a "moving" master. Is this right?

See updated answer.

See amended answer which demonstrates a moving master concept.

is a 10-polls per second, on a 9600 baud rate, a reasonable choice? - in my current test (see screenshots) I am testing 4 devices repeatedly in 75 ms at 19200 baud, so that is 13 status reports a second. Basically that means one device should react to a status change (eg. a switch closure) from another device in 1/10th of a second. Your initial question mentioned 4 devices, so you should be able to get similar results.

could you please tell me where you got the white wire clip that is in the picture with the red background (the clip is attached to the wire bundle)

Ebay: https://www.ebay.com/itm/400846299509 . Search for 10x 2p Spring Connector wire no welding no screw.

Remember RS485 is not a protocol, it is a definition of a physical transport layer.  With the Mega as you chose you can use serial 1,2,3 and run them in full duplex mode over the RS485 network e.e. you can receive what you send.
I have it operating in a multi master configuration.  Each mega when it transmits it also receives what it just sent and can determine on a byte by byte basis if it needs to back off.  The delay before coming back on line is determined by the node address and when the bus becomes available.
The code will use the write function instead of the print function allowing each byte to be checked. (In time I probably will do it via software and emulate CAN or just use a can controller). Yes 8 bits works just fine, the ninth bit is a parity bit or other uses depending on who is defining it.
My test system is operating with packets and sends in this format:
|Length|Target|Source|Sequence|Command|Flags|Data|Check
and expects an ACK in response.  This is relative simple first pass and has no illegal codes. All bytes are Hex but you can use what you want.
This gives me Carrier Sense, multiple access but with destructive arbitration.  If you want CSMANDA just use a CAN physical layer or bit bang the data you send then you can arbitrate on a bit by bit basis.  It won't be that much different in software other then the transmit portion.
I am planning on using the RPi with Linux as the main node. With 8 bit data it will work just fine.  I just started about two weeks ago on this configuration and so far it is going well. I am operating at 9600 baud and have a lot of free time.
Gil

How do you have things set up to sense collisions? Does the particular chip you're using for the RS-485 interface return the sensed data on the link on the RX line at the same time as you send it data on the TX line and it transmits that?

If you want to use Nick Gammon's protocol you might find this useful: https://github.com/Sthing/Nick-Gammon-RS485
It is my implementation of the protocol in Python (for use on a RaspberryPi).
I have only tested python-to-python yet, testing against Nick Gammon's code is next on my to do list.
/Thing

I've been succesfull, lately, in testing Nick Gammon's RS485 non-blocking protocol, between three MEGAs in a "one master, two slaves" scenario. I've encountered several problems, mainly introduced by the usage of physical serials (and not SoftwareSerials). Luckily, I've been able to fix everything. I've published the running code (with some other details) here: https://github.com/verzulli/arduino-smart-home - I'm currently actively working on such project, and plan to update it during upcoming weeks.

I think the CDBUS protocol for RS485 is exactly what you want, it introduce an arbitration mechanism that automatically avoids conflicts like the CAN bus. I can even transfer video stream through it:

Full video:
https://youtu.be/qX5dh4wcfSk
The Raspberry Pi can output preview video and control command at the same time. We can monitor the recognition process on the PC. When problems are encountered, it is convenient to know the reason and adjust the parameters, and disconnecting the PC will not affect the demo operation.

In addition, the Raspberry Pi can access the internet at any time through the PC, and it is easy to update software and for remote control.
Details about the CDBUS:

https://github.com/dukelec/cdbus_doc (Introduction)
https://github.com/dukelec/cdbus_ip (Protocol details & FPGA IP core)

Update:
Connect the CDCTL-Bx controller to an Arduino:

The mention of video is irrelevant to the question asked and the Arduino subject of this site, and so a bit distracting from it.  Such a volume of data could well cause problems for resource constrained systems unless elegantly handled.  If you want to propose this scheme, you should explain how it is suitable for the problem of the question, and for an Arduino... if it actually is.

It's the same for Arduino, replace the Raspberry Pi Zero in my diagram to an Arduino, in other words, add an external shield board of RS485 controller for Arduino, communicate through I2c or SPI interface.

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


text:
How to network multiple Arduinos so they react to the same signal
I want to build a project that contains multiple Arduino nano's, each connected to one controlling Raspberry Pi.  I would like to send one signal (a string of characters or numbers) which would be the master state, which the other Arduinos would react to based on their programming.  What is the best way to do this?
Can the Arduino support a protocol for this, or will it need additional hardware?
Max distance: 30 meters

Pretty similar to How to interconnect multiple Arduinos with a Rpi to control home-lights/switches

Interesting.  is RS485 bus the way to go?  Looks like it needs extra hardware.

Yes, but the extra hardware is pretty trivial. I read recently (I can try to find the reference) that RS232 (normal serial) was not intended for long runs. In any case a Nano is 5V signal, not even RS232.

Perhaps there is a better solution

Perhaps, but I2C and SPI are designed for even shorter cable runs. Serial is probably the most reliable, but the voltage drop over 30 m, plus noise picked up, is likely to make it unreliable. You could get one of those cheap radio transmitters, but that again is extra hardware.

Another option is wireless - especially if it's one-directional. May be an advantage? Will almost certainly be more expensive and error-prone.

Wireless is an attractive option.  Most of my Arduinos can function on 1 way transmissions, but a few need 2 way.

Have you thought about inexpensive RF?  It would only require about 2 pins and you could effectively write your code so that you're treating the RF as a bus to which the arduinos are connected.

yes, I have a few of those.  I'd like to use a wired option for this

Rule 1 do not connect Arduino pins to long wires.
You can achieve your your goal in many ways, a serial interface looks good from here.  I am doing it with a RS485 interface, note it is an interface not a protocol. You can use CAN, Wi-fi and many others.  It sounds like all the units except 1 will be receiving data, the other is transmitting it to the other devices.  RS485 will work good and it needs only 5V.  It will work over several thousand feet and some reasonable speeds. You can use a UART either hardware or software to accomplish the task with a RS-485 driver at each node.  You need to remember you need to wire from point to point with the terminating resistors only on the end nodes.


text:
SSH and web interface broken on Yun
I have two Arduino Yuns that are not accessible at all on the network. I can't go to the arduinoname.local, ssh arduinoname.local, as I previously could. I know at least one it working because it sends emails as I programmed it, yet it seems there is no longer a way to ssh into it. Any ideas?
Yes, I have unplugged, plugged in the router,  and the yuns.

It turns out the problem is a fairly common one - Actiontec wireless access points break this way when set to Both, not AES - see https://superuser.com/questions/522781/unable-to-ssh-from-any-wireless-ip-to-another-wireless-ip-on-home-network
Apparently on other routers this bug is marked as a feature, "Wireless Isolation" or something.


text:
What are some fun things you can do using the ICSP header?
I bought 10 Arduino Nanos for a project, each with all of their headers soldered in place.  Each was going to go into a tiny space, so I found myself needing do desolder the ICSP headers.
This led to a bit of a moral conundrum.  What would I lose by removing these useful looking headers.  They cover quite a lot of space on the nano, so they must be important right?  Am I going to regret removing these things when I finally realize how useful they are (I thought to myself.)
In the end, I did remove the ICSP headers, but the event got my thoughts going.  What is this header all about?  Why is it there?  What can I do with it?  I began to search for things that I could do with the ICSP header, but engaging results were not forthcoming ( except for this project:  https://www.arduino.cc/en/Hacking/ParallelProgrammer )
Anyway, I was more interesting in things that flash, move, jump, sing, and such, so are there any interesting things that can be done with the ICSP header?

Mostly useless. You can always add them back if you need to, or use the other pins (as the ISP header pins are the same as pins 11,12,13,RESET,GND,VCC)

Are they the same pins for all Arduinos (mega, nano, etc.)?

Not necessarily. Pins 11, 12, 13 are MOSI, MISO, SCK on the ATMega328 based boards (like Uno and Nano).

You can use every single last byte of flash on the device.
Since you're performing low-level programming of the device you get the entire chip to play on, without having to worry about bootloaders and such.

You can debug (breakpoint, single-step, watch, disassemble, etc.) the code on the chip using software on your computer.
Admittedly the devices you'd need in order to do so are more expensive than a simple ISP programmer and it only works with specific pieces of software, but it can be done.

One interesting thing I just came up with: you could use this header to attach a simple control panel for your Arduino.
Imbed the Arduino in any place/box/machine you like. Then use a cable with a 6 pin connector to connect the header to a small control panel.  The panel could have 3 buttons or LEDs, a reset button and a power plug.


text:
Using for loop to set pinMode
I notice problems with my output pins when I use this method of setting their pinMode:
int allOutputPins[] = {3, 4, 9, 10, 5, A3, 11, 12, 7, 8, A1, A2};

for(int a = 0; a < sizeof(allOutputPins); a++){
   pinMode(allOutputPins[a], OUTPUT);
  }//end for

Am I doing something wrong?

Re  “Am I doing something wrong?”, yes :)
The sizeof(allOutputPins) expression returns the size of allOutputPins[] in terms of bytes, so is 24 because the array contains 12 two-byte integers.  The loop's last 12 pinMode() calls will be garbage.
Among other ways of fixing the problem, you could change the expression to sizeof(allOutputPins)/sizeof(int) [which has the same value, 12, as (sizeof allOutputPins)/sizeof(int); eg see the syntax entries for the sizeof operator at cppreference.com] or you could change the base type of the array to byte or uint8_t.

I would recommend using sizeof allOutputPins / sizeof allOutputPins[0] instead. This idiom is more robust because it works independently of the type of the array. I would use it even if I change allOutputPins base type to uint8_t.

What you needed and were expecting was the count of the items in the array. I need this so regularly, I keep a countof macro, #define countof(a) (sizeof(a)/sizeof(a[0])) in my local.h file (personal file of common idioms).

Thanks @JRobert that's a good idea. Is that all I need to define to use it?

You also need to use the countof define like this: for(int a = 0; a < countof(allOutputPins); a++){

You would need to #include <local.h> in your sketch (the Arduino IDE won't know to do it for you); thereafter you can use it anywhere in your sketch, such as how @NickGammon just described.


text:
Inheritance: error in calling the constructor of the base class?
I want to write a library for the RGBDigit shield (http://rgbdigit.com/), which essentially is an Adafruit Neopixel strip, packed as a 7 segment display. The shield also has a DS3231 clock and an IR receiver.
So my plan was to make a class RGBDigit, which inherits from the Adafruit_NeoPixel class and add private objects DS3231 and IRrecv.
This is my RGBDigit.h:
#ifndef RGBDigit_h
#define RGBDigit_h

#include <Arduino.h>
#include "Wire.h"
#include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "../IRremote/IRremote.h"
#include "../DS3231/DS3231.h"

class RGBDigit : public Adafruit_NeoPixel {
    public:
        RGBDigit(int nDigits);
        ~RGBDigit();
    private:
        int _nDigits;
        DS3231 _clock;
        IRrecv* _ir;
};

#endif

This is RGBDigit.cpp:
#include "RGBDigit.h"

RGBDigit::RGBDigit(int nDigits)
    : Adafruit_NeoPixel(8 * nDigits, 12, NEO_GRB + NEO_KHZ800),
    _nDigits(nDigits)
{
    _ir = new IRrecv(10);
    _ir->enableIRIn(); // Start the receiver
    Adafruit_NeoPixel::begin();
}

RGBDigit::~RGBDigit()
{
    delete _ir;
}

And this is my Arduino sketch:
#include <Wire.h>
#include <RGBDigit.h>

RGBDigit display = RGBDigit(4);

void setup() {
    // put your setup code here, to run once:

}

void loop() {
    // put your main code here, to run repeatedly:

}

I get al lot of "undefined reference" errors:
RGBDigit/RGBDigit.cpp.o: In function `RGBDigit::RGBDigit(int)':
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:23: undefined reference to `Adafruit_NeoPixel::Adafruit_NeoPixel(unsigned int, unsigned char, unsigned char)'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:23: undefined reference to `DS3231::DS3231()'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:25: undefined reference to `IRrecv::IRrecv(int)'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:26: undefined reference to `IRrecv::enableIRIn()'
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:27: undefined reference to `Adafruit_NeoPixel::begin()'
RGBDigit/RGBDigit.cpp.o: In function `RGBDigit::~RGBDigit()':
/home/ralph/Arduino/libraries/RGBDigit/RGBDigit.cpp:30: undefined reference to `Adafruit_NeoPixel::~Adafruit_NeoPixel()'
collect2: error: ld returned 1 exit status

But I don' t understand why. What am I doing wrong?

You're assuming that the IDE is smart enough to know that it needs to copy over and link the other libraries.

#include "../Adafruit_NeoPixel/Adafruit_NeoPixel.h"
#include "../IRremote/IRremote.h"
#include "../DS3231/DS3231.h"

What you're doing there is telling the compiler where, relative to where it's performing the compiling (or one of its include directories), the header files you list are.
What you're not doing is telling the IDE where the CPP files are to compile and link with your sketch.
When including anything external to the sketch folder that is more than just a header file you must treat it as an Arduino library - that is, place it in one of the standard library folders and name it properly (libraries should be named LibraryName/LibraryName.h).
Then you include the libraries properly:
#include <Adafruit_NeoPixel.h>
#include <IRremote.h>
#include <DS3231.h>

You must do that in both your sketch and your custom library.  That way the IDE knows where to look for the files to compile - the compiler doesn't understand the concept of an Arduino library (and thus the CPP files associated with a header file) - that is purely down to the IDE gathering the data by examining your sketch and locating the right files to then pass to the compiler.

Thank you very much; I understand it now! But isn't it a bad thing that someone who wants to use my RGBDigit library, also needs to know which other classes and libraries are used by RGBDigit?

@Ralph: With all due credit to the Arduino IDE's developers for a basic download-and-go beginners IDE, it has its limitations. You have met some of them.

@Ralph Yep, that's a shortcoming all right.  One that I addressed in my replacement IDE - UECIDE.  Upgrade to that and you won't see that problem since it can recursively scan libraries for other libraries that they rely on.

See How the IDE organizes things for more details about this. But isn't it a bad thing that someone who wants to use my RGBDigit library, also needs to know which other classes and libraries are used by RGBDigit? - most IDEs need you to tell them, one way or another, which libraries to use. If UECIDE does that automatically, that sounds good. However if you rely upon a different IDE, now you need to tell your users that it only works with that IDE. Maybe you could just explain in the documentation you post with it?


text:
Pause code untill a button is pressed
I need some code to pause the Arduino code until a button is pressed. I have a long program and at point I need a condition that if a Button on pin A2 is pressed then go forward, otherwise wait.
I tried using if with a condition but it failed for my purpose. I think this is because when if(...) detects that the button is not pressed, it moves to next lines (as usual). But I have a long program and I want to wait forever until the button is pressed.

Is it active high or active low (are you using pullup or pulldown resistors)?

See my edit please. I am just using a Pushbutton with a resistor. I tested the button with different programs. It all works fine.

You haven't answered my question though.  Is the resistor connected to +5V or to GND? It makes a big difference to the code snippet I will spoon feed you.

The resistor is connected to Ground. Help me

The construct you are looking for is called while.
Instead of doing "If the button is pressed then continue" you need to do "while the button is not pressed do nothing".
Assuming you have an "active low" button (that is, a resistor pulling it up to +5V when not pressed, so digitalRead(A2) == LOW is "pressed"), you can do:
while (digitalRead(A2) == HIGH) {
  // Do nothing
}

So while it's not pressed (digitalRead(A2) == HIGH) don't do anything.  As soon as digitalRead(A2) returns LOW (so it is not == HIGH any more) the while loop will finish and your sketch can continue.
I write all about the while loop in an article here.

will it continue right from where it has stopped..? Lets say if my motor is at 67 degrees it should resume from the same. Is it doing the same..?

I need a code to pause arduino code until a button is pressed.

I wrote a simple function to do this.
Usage:
buttonWait(<pin_number>);

Code:
/* the function */
void buttonWait(int buttonPin){
  int buttonState = 0;
  while(1){
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) {
      return;
    }
  }
}

void loop() {
  buttonWait(2); // wait for button press on pin 2
  // do something
  // ...
}

This code assumes that you have a pulldown resistor, but you can easily modify it to work with a pullup resistor instead, if you feel the need:

simulate this circuit – Schematic created using CircuitLab
See example code here!

Thank you rahuldottech!! I had been fussing with my code for several months on and off and tonight...I hit gold!!

@Osprey That's great to hear! :)

The battery doesn't make sense in that circuit. you have it wired to use +5V from VCC, which is correct, but why have a battery hooked to +5V? (Unless you are planning to bypass the internal regulator and the battery is really a regulated 5V supply?)

Here are two ways you might have wired the button. If you wired it with a pullup, you will need to test for LOW (the button will ground its output when pressed). If pulldown, the button will raise its output when pressed and you would test for HIGH.
If you will be testing the button again within less than a second, don't forget to debounce it. Switches send a bunch (technical term :) of pulses for a significant fraction of a second during a make or bread. See Nick Gammon's "Switches" page for a thorough discussion.

Pausing a program can be accomplished using Light Sleep mode as demonstrated in given URL: https://www.youtube.com/watch?v=GIbSt5mJ5VY

Welcome to Arduino! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.

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


text:
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)
I’m sorry if I sound ignorant and naive, but I’m brand new to Arduino;  very keen, but know very little.
I started with a Sainsmart Arduino Uno clone board.  I downloaded the software, which opened OK (or at least seemed to), but the Serial Monitor kept telling me that there was a communication error, and a yellow light kept flashing on the Sainsmart board.
I got hold of a genuine Arduino (from Jameco), uninstalled everything Arduino, and started again from scratch.
Now I get the message:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

And after enabling the verbose output, got:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)

Tried again, and:
Arduino: 1.6.5 (Mac OS X), Board: "Arduino/Genuino Uno"
Error opening serial port '/dev/cu.Bluetooth-Modem'. (Port busy)

I’m using a MacBook Pro, using Yosemite 10.10.5.

Try restarting your computer.

Why are you trying to communicate with a bluetooth modem when the Arduino plugs in through USB?

Is there a /dev/tty.Bluetooth-Modem? @Majenko that's an OSX thing. I have the same thing here on my Mac.

@Gerben I know what it is - I am just wondering why the OP is trying to use it.  It's the equivalent to /dev/rfcomm* on Linux.

Sounds like the wrong port to me. It shouldn't be on the Bluetooth-Modem port.

The Bluetooth Modem port is obviously wrong, but it's there on just about every Mac, so people seem to choose it in desperation when their Arduino (or more commonly clone) is not recognized.  Needless to say it will not work.

You are not selecting the correct port to upload to - hence the strange message about the Bluetooth modem. Start by unplugging your Uno and running Arduino. Select Tools -> Port from the menu bar. You should see a list of options. Now plug in your Uno and do the same again. You should see an extra port listed now - this will be the Uno. Select it. You will need to check this every time you connect a board.
Also, before you click Upload, make sure you have Arduino Uno selected under Tools -> Board in the menu bar.


text:
AVRdude + Arduino leonardo: can't flash over bootloader, not in sync: resp=0x3f
I would like to program an arduino leonardo board with atmega32u4 on win8.1 x64.
I have the latest AVRdude.
I installed the necessary drivers, after reset it can be enter programming mode, and I can program with arduino studio.
But now, the avrude gives this:
    C:\>avrdude -carduino -P COM5 -n -p m32u4 -b19200 -v

avrdude: Version 6.1-svn-20131205, compiled on Dec  5 2013 at 17:34:22
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "c:\GNU_GCC_ARM\bin\avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 19200
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x3f
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x3f

avrdude done.  Thank you.

I tried also with 57600 baud.
Any idea? Thanks.

You're specifying the wrong bootloader protocol via -carduino. The Arduino bootloader is for boards using the Diecimila bootloader. The Leonardo uses the "AVR109" bootloader - named after the Atmel Application Note which describes its protocol.
Try this command on for size:
avrdude -cavr109 -P COM5 -n -p m32u4 -b57600 -v

Don't forget to press the reset button (or open and close COM5 at 1200 baud) first to run the bootloader.


text:
Arduino Serial Monitor
I am currently trying to see the result of a query to a thingspeak field.
This works great when I just use a empty sketch and type the commands manually, but using the following sketch I cannot see the value of +IDP,0,1:1
This means, at field 1, the value 1 is stored. If 0 was stored, it would be +IDP,0,1:0
How it is possible to "ask" if "+IDP,0,1:0" exists at the serial message from the ESP8266? Serial.find does not work....
Here my sketch:
#include<stdlib.h>
#include <SoftwareSerial.h>

SoftwareSerial monitor(2,3); //rx tx
#define SSID "WLAN-0E0265"
#define PASS "2738564673200634"
int ledPin = 13;
String c;
void setup() {
  Serial.begin(9600);
  monitor.begin(9600);
  monitor.println("AT");
  delay(1000);
  monitor.println("AT+CIPMUX=1");
  delay(1000);
  monitor.println("AT+CWJAP=\"WLAN-0E0265\",\"2738564673200634\"");
  delay(5000);
  if(monitor.find("OK"))
    Serial.println("JAP worked");

  monitor.println("AT+CIPSTART=0,\"TCP\",\"api.thingspeak.com\",80");
  delay(2000);
  if(monitor.find("OK"))
    Serial.println("CIPSTART worked");
  monitor.println("AT+CIPSEND=0,110");
  delay(2000);
  if(monitor.find(">"))
    Serial.println("CIPSEND worked");
  monitor.print("GET https://api.thingspeak.com/channels/54209/fields/1/last \r\n");
  delay(10000);
  monitor.println("GET https://api.thingspeak.com/channels/54209/fields/1/last");
  delay(2000);
  String readString;
  ledPin = 13;
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//SEARCH FOR THE :0 or :1                           <-- Here is the problem, rest works fine
  if(Serial.find(":0")){
 //turn pin off
}
  if(Serial.find(":1")){
 //turn pin on
}

}

void loop(){

}

The problem is that you can't use serial's find function to look for one thing or another.  It is a greedy function and it will consume everything coming in to the serial port until it finds what it's looking for or until it times out.  That includes the :1 if you are using find to look for the :0 at the time.
Instead you either need to receive the whole string into memory and examine the string to see what it contains, or you need to manually process the data as it comes in character by character to decide what there is.

Hi thaks for the reply, you mean probably something like this:    if(monitor.available()){
while(monitor.available()){
s = s + monitor.readString(); // monitor.read() will lead to the same result ....
}
}
Serial.println(s);                                         this also does not show up the whole code like I see when I manually type it into the Serial monitor.. I think the Serial.available and serial.find has some timeout or so...

@Merki, if your if statement has no else part, just leave it off.  That is, for a condition c,  the construct  while(c){...} has the same effect as if(c){ while(c){...} } (unless race conditions apply).

You should read this to understand how to read the whole string into memory: http://hacking.majenko.co.uk/reading-serial-on-the-arduino - it's not as easy as you are thinking it is.