text:
How do I use SNAP protocol, correctly?
I've reviewed the documentation
I'm still a little lost when it comes to applying the functions. Each of the redundancy check methods take in an unsigned char and return an unsigned char.
Shouldn't there be some sort of boolean return somewhere confirming that the data is accurate?
I've been trying to debug unsigned char* tempData = "snap" to the terminal, writing it directly to the register, according to the doc it should return h17:
  UDR0 = crc8(tempData,sizeof(tempData));

The terminal outputs '?' - as if it cannot be read.

Whereabouts are these functions you are using?

This was the only AVR-GCC example implementation of the protocol: http://www.hth.com/filelibrary/snap/usrcode/GCC01.ZIP

The crc8 function calculates the Cyclic Redundancy Check (8-bit) value for the data you provide. It is then up to you to compare that calculated value with the CRC you have received.
The ? you are seeing in the serial terminal is an unprintable character. It is representing an 8-bit value that doesn't lie within the 32-127 range of normal ASCII characters, or 32-255 of the extended ASCII character set.

Okay! Is this appropriate moving forward?

On the transferring node store the value crc8() returns and call it the 'checksum' , then send it as part of the payload.
On the receiving node call crc8() on incoming tempData and compare it to checksum?

I'm sort of concerned that even if this works my implementation is to simple and I'm missing something. I might try another protocol that has stronger avr examples

The SNAP specification seems very wooly. I'd try something more rigidly defined with proper libraries.  Depending on what you want to achieve my ICSC library might work well for you.

My needs are pretty straight forward, I just need to validate incoming packets. Your library looks solid but I'm not running off Arduino. I think it would be challenging to port.


text:
Arduino LCD changing contrast only makes black boxes less readable i.e. less in contrast
I have seen similar issues posted here but none match my problem exactly.
I have a starter kit and a 16x2 LCD screen that only shows black boxes in the top row using the following code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
  lcd.print("hello, world!");
}

void loop() {

}

All tutorials use a potentiometer to change the contrast but I don't have one so I decided to use chain several resistors. When doing so, the contrast indeed changes, but it changes as a whole. The black boxes become less readable i.e. less in contrast (more vague) but stay completely black.
Just to make sure, I have a cable from the + tray (with 5v) to the VDD port and - tray (with GND) to the VSS port. The K port is on the - tray as well and the A is with a 220 ohm resistor on the + tray.
I have tried no, 3k, 4k, 3220, 10k and 100k ohm on the v0 port to change the contrast.
What could be wrong? Any help is appreciated.
Edit photo:

Black boxes mean the screen isn't being initialized. Check your wiring.

@Majenko I checked it at least 2 times. Either a cable is faulty, I forgot code or my LCD is broken. Can't think of another reason at this point.

Maybe you could show us your wiring and we can check it for you?

@Majenko photo or provide an overview in my question? Following all cables might be a bit messy I fear.

Photo. It's hard to see what you have done from test alone.

@Majenko take a look. I hope it's clear enough

That is almost impossible to follow. Don't you have some more varied colours of wires? Or separate them out a bit so they can be followed manually?

@Majenko I feared so. I do not have that many colors unfortunately. It's the setup shown in this video minus the potentiometer (I used 3 chained 1k resistors): https://youtu.be/Mr9FQKcrGpA?t=3m45s

You have your polarities round the wrong way. VDD and A (for 'anode') should be positive/5V; VSS and K (for 'kathode') are Ground. As you have a backlight, I suspect you have at least A and K the right way round, but you have Vss/Vdd switched.

@CharlieHanson Sorry my bad, A was actually in the + tray and the K in the - tray. Mixed them up in the text. VSS is in the - tray as well like in the text and VDD in the +.

Great, now all you have to do is re-read my comment and find the other mistake you are still making.

@CharlieHanson, K and VSS in the - tray which is connected to ground, VDD and A in the + tray. What am I missing?

Nothing from that comment, but the text in the question is still incorrect. The quality of the photo is so bad that it's very tough to know if it's a typo or actual incorrect wiring. Always check, check, then check again.

Please post the photo in the question, not a link off-site. There is an icon for adding photos to questions.

source: Stack Exchange

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

sort: votes


text:
Programming problem I need both if else cases to work but only else loop is running
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo1, myservo2, myservo3;

int bluetoothTx = 14;
int bluetoothRx = 15;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
myservo1.attach(9);

//Setup usb serial connection to computer
Serial.begin(9600);

//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
 }

void loop()
  {
    if(bluetooth.available()>0)
     {
      if(bluetooth.available()>=4)
       {
        char buffer[4];
          for(int i=0;i<4;i++)
         {
          buffer[i]=bluetooth.read();
         }
       int incomingValue = atoi(buffer);

      if(incomingValue>=1000 && incomingValue<=1360)
        {
           unsigned int servopos = bluetooth.read();
           unsigned int servopos1 = bluetooth.read();
           unsigned int realservo = (servopos1 * 256) + servopos;

         if (realservo >= 1000 && realservo < 1360)
          {
              int servo1 = realservo;
              servo1 = map(servo1, 1000, 1360, 0, 360);
              myservo1.write(servo1);
              Serial.println("servo 1 ON");
           delay(10);
            }
           }
          }
         if(bluetooth.available()==2)
          {
            char inbit=bluetooth.read();
            if(inbit=='A'||inbit=='D');
           {
            char myval= bluetooth.read();
            if(myval== 'A')
            {
              myservo1.attach(9);
            }

             if(myval== 'D')
              {
               myservo1.detach();
              }
             }
            }
           }
          }

You need to add, what values you expect from bluetooth during one loop-call. Calling bluetooth.read() twice in an if may not be that what you want.

I think you are lacking a basic understanding of how serial works.

Also lacking a basic understanding of how to write an if statement.

Your new code is still a mess. Please provide an abstract algorithm of what should be done.

There are so many things wrong with that program I can't begin to sort it out.
Here's some of the most glaringly obvious errors:
if(bluetooth.read() >=0 && bluetooth.read() <=360)

Read a character. Check it's at least 0. Read a second character. Check it's less than 360.  Since characters are between 0 and 255 that will always succeed if there is one character of any form to read (if there is no characters to read you get -1).
else if(bluetooth.read()=='A'||'B'||'C'||'D'||'E'||'F');

Read another character and compare it to 'A'. This if is true if the character read is A. It also succeeds if B, or if C or if D, etc. That's not "if it's equal to C", just "if C". C is a character literal, so it's equivalent to a number. Any number that is not 0 is TRUE, therefore it's equivalent to:
if character is A or TRUE or TRUE or TRUE...

Which of course is just true, so it will always succeed regardless.
char myval= bluetooth.read();
if(myval== 'A')

Read yet another character from bluetooth (I sure hope there are enough there...) then compare it to a list of characters that are the same as you looked at above. You're comparing a new character this time, not the one you compared with the list a few lines beforehand.

Would the changes I made do any help?. I want my code to execute first if loop if the bluetooth sends a value between 1000 and 1360 and second if loop if it sends character A or D.@Majenko

Well, no. Because you can never read a character that is greater than 255 since such a thing doesn't exist. You need to read some tutorials on using serial on the Arduino.

What if I add a buffer?Can I then send values more than 255?and then compare value in the buffer@Majenko

There are a number of ways of transferring data using serial. Simplest is with an ASCII representation. Then yes, read characters into a buffer and use something like atoi to convert that buffer into a number.

Could you check this code please?@Majenko

Please read this: https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

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


text:
Parallel connection to Wiegand 26bit RFID readers
I have situation where I need to read RFID cards. There is already installed Roger security system, Roger gate control board and two rfid readers in parallel. By default board and RFID readers communicate in RACS(some sort of coded protocol) but at the moment system is configured to communicate in Wiegand26. Earlier I used chinese wiegand26 reader with Arduino with no problem.
With Arduino I need to read card read by RFID readers.
Then I process data and make HTTP POST request.
Arduino is supplied from Roger board ~13.5V DC I do not get anything in arduino, even if I connect RFID readers directly to arduino.

CLK is D0 to Arduino Nano pin 2
DTA is D1 to Arduino Nano pin 3

This question is not related only to Arduino.
I want to ask is it possible to do? To read data maybe I need some additional electronics?
What i also noticed that when Arduino is connected in parallel the Roger board not always reads the card from RFID readers.
Roger PR402-BRD
And two readers PRT62LT

This is copy of Electronics.stackexchange

It looks to me like the Wiegand interface is an open-collector interface (like I2C), which is why they can be wired in parallel like that.
As long as the Arduino has both connections set to INPUT (not INPUT_PULLUP and certainly NOT OUTPUT) it shouldn't interfere at all.
By the way, for Wiegand, the two signals are DATA0 and DATA1.  To transmit a 0 the DATA0 line is pulled low. To transmit a 1 the DATA1 line is pulled low.
You should also check that the idle voltage on the lines is indeed 5V as it should be.  Anything more than that could cause the Arduino to chip the voltage to 5V through its internal ESD protection diodes.
Also you must ensure that the Arduino has its ground pin connected to the ground connection of the Wiegand system (which it should be since you are powering it from that).

i am using https://github.com/monkeyboard/Wiegand-Protocol-Library-for-Arduino library pinMode(D0Pin, INPUT);     // Set D0 pin as input
pinMode(D1Pin, INPUT);     // Set D1 pin as input
attachInterrupt(0, ReadD0, FALLING); // Hardware interrupt - high to low pulse
attachInterrupt(1, ReadD1, FALLING); // Hardware interrupt - high to low pulse

As you can see pinMode(D0Pin, INPUT);. Checked the voltage and for my surprise its ~11,5V DATA0 - GND -> 11,5V and same with DATA1 - GND -> 11,5V and yes as you said Arduino chips it to 5V when connected

That could be your problem then - the Arduino would be trying to clamp that to 5V which would cause problems I would guess.  It could also damage the Arduino.  You would probably need to isolate the Arduino from those lines.  Optocouplers would probably be your best bet.

Hmm, but if i will put optocouplers then led in optocoupler will lower the voltage too? I mean resistor+led in series.

Depends on the amount of pullup resistance.  Another option could be to use MOSFETs.  You can calculate the pullup resistance by measuring the current to ground then using Ohm's law - you can then work out a suitable resistance for the LED.  Or with a MOSFET you just need to ensure the threshold level is in the right region to switch on/off at the right times. There's all sorts of ways of doing it.  Op-amps could even be used to apply a fractional gain.

With optocoupler i would need this circuit https://i.sstatic.net/edSjI.png ? Will it work and not interfere Wiegand?

Also i am thinking that MAX232 chip should work here?

If the resistor is high enough (which also relies on the pullup resistor being low enough) then it may not interfere, but chances are it will.  The MAX232 is a great idea!  Certainly worth giving it a go.  Could be the best bet all round really.

Let us continue this discussion in chat.

So i will need to invert the signal on Arduino? If i put +12 to MAX232 pin 8 on pin 9 i read 0V. attachInterrupt(0, ReadD0, FALLING); line will have to be changed to attachInterrupt(0, ReadD0, RISING); ??

Yep.  The MAX232 inverts.

If you would like to use more than 1 Wiegand reader, technically it should be possible to use AVR pin change interrupt. In this case you can use ANY 2 pins, even analog pins.
For example, see http://thewanderingengineer.com/2014/08/11/arduino-pin-change-interrupts/
UPD: There is informationon Wiegand timing, might be useful:
http://proxclone.com/wiegand.html


text:
Custom Arduino board beeps and process freezes while I'm uploading a sketch to it. Why?
The strangest thing is happening to a standalone Arduino board that I designed and built. The board (whose schematics are below) has the following features:

It has a ATmega328P with a 5V voltage regulator and usual circuitry when set up as a standalone controller.
It controls a scoreboard with several 7-display digits linked through the connectors on the right (JP1 through JP12).
It has cursor buttons decoded using a voltage ladder through ANALOG_0 (A0).
It has a Real Time Clock to keep time when it's turned off.
It has an RF receiver module.
It has a UART header (JP17) so I can program the board using a serial port.
It has a speaker attached to digital pin 3 (D3).

I upload sketches to it using a RS232-to-TTL adapter that I've also built (schematics also below) and a Serial-to-USB cable. When programming it, the board behaves much like a Severino board.

What's strange is that, when I upload a sketch, the process is paused in the middle and then the speaker starts to beep continually. It pauses with the following avrdude messages:
avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch
     System wide configuration file is "C:\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf"

     Using Port                    : \\.\COM1
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200

When I press reset on the board, avrdude continues outputting its messages (such as below), the beep stops, the upload continues and the sketch is uploaded successfully to the board.
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
... messages and upload continue and completes successfully.

I don't have the rest of the messages handy here, but I hope you get the idea.
So, my questions are:

What is making the upload process pause?
Why is the buzzer beeping when the process pauses?

In the IDE's preferences turn on the Verbose for upload. This log should provide some insight, or more clues.

Is JP4 (auto reset) closed on your serial converter board? Arduinos that don't have that luxury stop until you reset them, then they upload the sketch. As for the beeping, I have no idea.

Did you try to add a diode in parallel to your SP1? A Speaker is just like a motor: induction can trigger reverse currents, adding a diode is a way to protect it. Also driving a speaker directly from a pin (no current amplification with eg a transistor) may be a problem for your board.

Stupid question: Have you programmed the ATmega328p with a bootloader?

@TheDoctor - Yes, JP4 (auto reset) is always closed.

@jfpoilpret - I thought the buzzer induction may have something to do with the beeping. I'll try and put a diode in. Also, it's not a speaker as marked in the schematics, it's just a small 5V buzzer. I copied the idea of driving it from a digital pin from some shield out there...

@TheDoctor - Yes, I have uploaded a bootloader to the MCU. It get sketches uploaded ok if I put it in an UNO board. And the upload works ok in this board, too, except for the beeping and the pause (but it doesn't time out, which is kinda nice).

@mpflaga - The verbose option is on for upload. I'll try and check where exactly the problem happens in the upload process, but I'm pretty sure is when avrdude is trying to send the code to the board. It says Send three times and then pauses. In a Severino board I have, when auto-reset fails, usually at the same point where the Send message appears, avrdude times out and gives the out of sync message and quits. With this board, it just hangs there until I reset it.

"works perfectly in a UNO" -That is useful info. So your board must have a socket. If so - You can determine the source more specifically with a quick experiment. For each of the IO pins bend the pin out, as not to make contact. Floating! As you insert the IC into your socket. Eventually, with all pins floating your circuit will be out of the question. And as some point between the delay/beep should stop. And report back.

@mpflaga All my boards have sockets! I could not even think about soldering my ATmegas directly to the boards! Also, I wouldn't bend any pins on the poor things... that would be like torturing them. Seriously now, that's a good idea. I'll try it out if I'm brave enough.

@jfpoilpret if the speaker is in fact a buzzer (piezo), then there's no induction, hence no diode needed. Forget my original comment.

@Ricardo copying the full output of avrdude during upload might help find possible answer leads.

One friend of mine who did a lot of electronics in his youth once told me: "if it does not work as you would expect, add a decoupling capacitor". On many occasions, I have followed this advice with great success! In your schematic, it's not clear to me, though, where you could add a decoupling capacity. Have you tried in // with the buzzer? You may also try 2 (one for low freqs, one for high freqs): one electrolytic at least 1uF, one ceramic 100nF. At worst, it won't have any effect :-)

What is making the upload process pause?

Well, given all the comments made under your question, this is definitely a tricky one. You might want to try to add a decoupling capacitor as suggested by @jfpoilpret, though your schematics look alright to me… (maybe ask a review of it on EE SE).
I'd also advice you to copy the avrdude command from Arduino IDE output (you'll find it at the top), and run it in the command shell with lower bitrate:
avrdude -v -v -v -v -C "C:\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf" -P COM1 -patmega328 -U… -B3 -b115200

the higher the -B value is the lower your bitrate is. and -b to the correct baudrate for your bootloader (are you sure this is 115200? it's more common to see 57600).
Did you also set fuses correctly? You might as well want to check the values of the fuses to see if the clocks are correctly set up:
avrdude -U lfuse:r:-:i -U hfuse:r:-:i -U efuse:r:-:i

which will output the values of the fuses. Then to make the values readable, put the values at the bottom of the form on the fuse calculator site, after choosing the Atmega328P MCU from the dropdown list.
Double check that:

you have enough size for the bootloader (usually the more you give it the better it is) ;
you have correctly set up the cristals configuration for your design (which may not be compatible with default Uno settings as setup by the Arduino IDE), checking if you correctly set up the external crystal at 16MHz…

Why is the buzzer beeping when the process pauses?

It's because when the processor does not have the output set up, the values within the registers are in an undefined and unpredictable state. Which means that usually it keeps the last value it had before a reset, or changed state because of some electrostatic weirdness, or is giving some weird PWM output because of the influence of a clock nearby.
So basically, there's something wrong happening when you're uploading your code and that wrong thing has an indirect effect on the audio. I wouldn't worry much about that stuff, but more about the cause of the pausing.
Sadly, I don't have a direct answer for you, but at best a few paths you should investigate more. HTH

+1 Thanks for the hints! Very useful. I'll try them all and report back in a couple of days.

Just wanted to let you know that I fixed the problem. See my answer to this question. Thanks anyway!

I finally found what was causing the problem: the reset signal from pin 4 (DTR - Data Terminal Ready) on the DB9-Female connector was spiking up to 10V before going to 0V and was triggering high-voltage programming on the ATmega. Below is a scope shot showing the situation:

The yellow trace is DTR signal while the green trace is the RESET signal on the ATmega.
According to Atmel's Atmel AVR042: AVR Hardware Design Considerations application note, one should add an ESD diode between ATmega's RESET and Vcc to prevent the reset signal from triggering high-voltage programming mode, like so:

After adding such a small signal diode (1N4148) like the app note recommended, I got the issue fixed. See below the scope shot taken after the diode was added.

Now the 10V peak is gone.
That was a tricky one!! But I could never find what was wrong without research and the right tools. Money on a scope is money well spent!!

This comes about because your reset line does not have the sort of level translator applied to the serial data line.  Most use a level translator ic and run the reset through a channel of that.

@Chris - Yeah, I remember you telling me to use the 2nd MAX232 converter to fix that. I'll take another look and see if I can fix that design. Thanks!!

I'm not sure but the problem may also be related to the auto-reset feature of the converter board.
I copied the converter board design from the Arduino Severino and according to its manual, the serial communication must be set to 19,200 bps for the auto-reset feature to work.

Be sure that computer COM Port speed is set to 19200bps otherwise
  auto reset will not work properly.

Well, I'm using 115,200, so that must be a problem.


text:
Help with code. Fade in LEDs from off (shift register)
I used this tutorial here and decided it to overcomplicate the pattern. For further learning. My code in theory should start the LEDs at a low brightness and fade them in using this code. My expected output is as follows.

All 8 LEDs start out as off.
Fade in slowly.
LEDs turn of one by one from left to right.
LEDs turn on one by one right to left.
Fade out.
Repeat.

This is the loop that fades the LEDs in.
for (byte b = 1; b < 255; b++) {
  setBrightnessUp(b); //sets the brightness up function
  delay(20);
}

This is the function:
void setBrightnessUp(byte brightness) {// 0 to 255
  analogWrite(outputEnablePin, brightness);
}

However at this time it appears to be getting into my loop but not increasing the brightness at all. When the code first runs, the LEDs are on but at a minimum brightness. The rest of the code including the fade out at the end works fine.
Fade out functions:
for (byte b = 255; b > 0; b--) {
  setBrightness(b); //sets the brightness function
  delay(20);
}

void setBrightness(byte brightness) { // 0 to 255
  analogWrite(outputEnablePin, 255 - brightness);
}

Here is the complete code. Excuse the over commenting it helps me learn:
//sets pin out for control pins on shift register

int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
int outputEnablePin = 3; //enables a PWM pin output

//uses byte (8bit binary variable)
byte leds = 0;

void setup() {
  // sets the pins to output mode
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode (outputEnablePin, OUTPUT);
}

void loop() {
  //attempted to make led fade in from 0
  leds = 0; // set led to no output ready for dimming effect
  updateShiftRegister(); //calls the function used for output
  delay(1000); //troubleshooting delay
  for (byte b = 1; b < 255; b++) {
    setBrightnessUp(b); //calls the brightnessup function
    delay(20);
  }
  leds = 255; //Sets the byte variable to 255 or 11111111
  updateShiftRegister(); //calls the function used for output
  delay(500); //waits 1/2 second

  //sets a variable i at 8 and runs while i is more than 1
  //minus 1 each loop
  for (int i = 8; i > -1 ; i--) {
    //Bitclear acts on a byte like its an array
    //it sets the bit at position i to 0 (or off)
    // the left most bit is 7 the right most 0
    bitClear(leds, i);
    updateShiftRegister(); //calls the display function
    delay(250); // waits
  }
  //sets a veriable i at 0 and runs while is less than 8
  //plus 1 each loop
  for (int i = 0; i < 8 ; i++) {
    //same as bitclear but turns on the bit at position i
    bitSet(leds, i);
    updateShiftRegister(); //calls the display function
    delay(250); //waits
  }
  //After the 2 other for loops are finished this will then fade
  //the LEDs out
  //sets the bite to 255 (11111111), while its more that 0
  //and minus 1 each loop
  for (byte b = 255; b > 0; b--) {
    setBrightness(b); //calls the brightness function
    delay(20);
  }
}

// this function outputs the data to the shifter
void updateShiftRegister() {
  digitalWrite(latchPin, LOW);//sets the latch pin to low(off)
  shiftOut(dataPin, clockPin, LSBFIRST, leds);
  // the first 2 functions set the data and clock pins needed
  //to receive data. The LSBFIRST tells it to start at the right
  //most bit (MSBFIRST is oposite). LEDs is our binary array (byte)
  // EG 0000000 would print no lights. It shifts this into the
  //shiftregister at 1 bit at a time from one end or the other
  //(determined by LSBFIRST or MSBFIRST)
  digitalWrite(latchPin, HIGH);  // sets the latch pin to high
  //the low to high state change triggers the output
}

//brightness down slowly
void setBrightness(byte brightness) { // 0 to 255
  analogWrite(outputEnablePin, 255 - brightness);
}

//supposed to fade the brightness up
void setBrightnessUp(byte brightness) { // 0 to 255
  analogWrite(outputEnablePin, brightness);
}

Board layout

I don't see a connection to pin 3...?

Yea its not in the diagram cause its part of the additional work exercise but is in my board.

I was mistakenly thinking that setting the brightness variable to 255 would mean that the LED is full on. This is wrong, 255 is actually off.
So with a little change in my code.
for (byte b = 255; b > 0; b--) {
  setBrightnessUp(b); //calls the brightnessup function
  delay(30);
}

The loop now works. I am still not sure why 255 is off and not on though.

Because the output enable on the shift register is active low.  A low turns it on and a high turns it off.  Newbies tend to want high to always turn something on and low to be off, but in the real world it is more often the other way round.


text:
How to declare and use "Variabled arrays" inside arrays
Good day folks. I'm new here and have been starting to be enthusiast in Arduino. I have a problem and I don't know what I should do, or whether I did something wrong regarding an array of arrays. Surfed on the internet to find a bunch of examples but the only difference is that they don't use arrays that have been declared to have a name inside array.
Every array inside array I see that works is like this:
byte array[2][4] = { {1,2,3,4}, {5,6,7,8} };
Serial.println(array[0][2]); is equal to '3'.

But mine is like this:
byte arrayX[4] = {1,2,3,4};
byte arrayY[4] = {5,6,7,8};

byte arrayZ[2][4] = { arrayX[4], arrayY[4] };

Serial.println(arrayX[2]); is equals to '3'.
Serial.println(arrayZ[0][2]); is equal to '0'.

Why?
Below is what in reality I am experiencing. I hope someone can try this out too.
softAddr = cycle * 2;

is an expression I used for looping where cycle is the iterated variable
for (byte cycle = 0; cycle < 7; cycle++) {}

I did a simple simulation and I guess the way I initialize the parent array, it initializes a new array in the name same from the declared variables but separate.
byte arrayX[4] = {1,2,3,4};
byte arrayY[4] = {5,6,7,8};

void setup() {
  Serial.begin(9600);
  byte glass[2][4] = {arrayX[4], arrayY[4]};
  Serial.print(F("OLD 1: ")); Serial.println(arrayX[0]);
  Serial.print(F("OLD 2: ")); Serial.println(arrayX[1]);
  Serial.print(F("NEW 1: ")); Serial.println(`glass[0][0]`);
  Serial.print(F("NEW 2: ")); Serial.println(`glass[0][1]`);
}

output:

OLD 1: 1
OLD 2: 2
NEW 1: 0
NEW 2: 0

//answered realized
I forgot that the array I put inside the array already had its data based on its index and the [4] resulted to nothing or 0 since there is no value at index [4] (knowing, indexes where 0, 1, 2, 3 on a 4 sized array). I realized this after I made a simple loop declaration not instantly like this:
byte arrayZ[2][4] = { arrayX[1], arrayY[1] };

But like this:
byte arrayX[4] = {10,11,12,13};
byte arrayY[4] = {20,21,22,23};
byte arrayZ[2][4];
void setup() {
  Serial.begin(9600);
  for (byte parent = 0; parent < 2; parent++) {
    for (byte child = 0; child < 4; child++) {
      if (parent == 0) {
        arrayZ[parent][child] = arrayX[child];
      } else {
        arrayZ[parent][child] = arrayY[child];
      }
    }
  }
  for (byte parent = 0; parent < 2; parent++) {
    for (byte child = 0; child < 4; child++) {
      Serial.print(F("value: ")); Serial.println(arrayZ[parent][child]);
    }
  }
}

Output:

value: 10
value: 11
value: 12
value: 13
value: 20
value: 21
value: 22
value: 23

Resulting in simply like this:
byte arrayZ[2][4] = {
  {arrayX[0],arrayX[1],arrayX[2],arrayX[3]},
  {arrayY[0],arrayY[1],arrayY[2],arrayY[3]}
};

done a simple edit on post

I don't see the point in this? You're just re-naming variables here. Waste of memory.

Something is wrong with your type description:
byte arrayX[4] = {1,2,3,4}; byte arrayY[4] = {5,6,7,8};

byte arrayZ[2][4] = { arrayX[4], arrayY[4] };

Serial.println(arrayX[2]); is equals to '3'.
This is normal ... arrayX[0] = 1, arrayX[1] = 2, arrayX[2] = 3
However, the next one is not good:
byte arrayZ[2][4] = { arrayX[4], arrayY[4] };

You are declaring a byte array, but you add arrayX[4] and arrayY[4] which, where arrayX[4] is the 5th elements of arrayX but it has only 4 elements, so it points to memory outside the array (probably into the next array.
byte arrayX[4] = { 1, 2, 3, 4 };
byte arrayY[4] = { 5, 6, 7, 8 };

byte* arrayZ[2] = { arrayX, arrayY };

Serial.print(arrayZ[0][2]);

This should print 3 (not tested).

just got realized that one also :D thank you for your answer

You're welcome (please upvote if it helped you)

yup already did (^_^)b


text:
Reading many analog signals in arduino
I need to measure around 50 - 100 analog sensors (resistors). This poses two challenges:

Arduino has fewer analog pins. I'm targeting something small like arduino Mini or Nano, which can have up to 8 analog pins. The solution for this could be several multiplexors like this one. Is there a better option? Is this the best way to read so many analog sensors with Arduino? I am thinking also in several arduino mini talking through wifi / bluetooth with the main one which would also aid with Problem #2.
There would be a lot of cables for this setup, and I need to keep it all as flat and flexible as possible. So I was thinking of some kind of adesive copper conductor, paper printed circuit or plastic. The thing is that it would become difficult to create if I do it myself. What would be the easiest way to achieve a multi-track, flexible circuit for substituing Arduino cables?

Depending on your performance needs, you could look into a multi-channel ADC with an I2C interface.  Then you can use a single I2C bus to read all of the analog signals.  This may not work if you need to read the signals faster than the I2C bus would allow.

Your question doesn't specify speed, cost, accuracy, or size, and it skimps on electrical and physical details (referring merely to 50–100 resistors and “a lot of cables”) so perhaps can't be properly answered.
ADC's (analog-digital converters) typically are high-impedance devices that measure voltages.  A resistor may be measured in many ways, a few of which are:

Place a known voltage across it; measure current through it
Drive a known current through it; measure voltage across it
Drive some current through it; measure both voltage and current using four-terminal sensing
Measure how long it takes a given capacitor to charge to a trip point, using a known voltage through the resistor under test
Use known resistances to null a Kelvin bridge

For some of the techniques listed above, measurement accuracy is little affected by multiplexer resistance; others might need to use a low-resistance MUX made with relays instead of a MUX ic like the 74HC4067.  Some of the techniques are suitable for wide ranges of resistance, others not; and some for high accuracy, others not.
Suggested Approach
Anyhow, those comments aside, circuits like the following might do the job.  If you have eight analog inputs on your Arduino, you could use up to eight multiplexers to measure up to 128 resistors.

In Figures 1 and 2 above, Rx is a typical unknown resistance, and Rs is a known standard resistor.  Both figures represent voltage divider circuits.
Effect of multiplexer transmission gate resistance
Let Rm denote multiplexer transmission gate resistance.  Rm is unimportant if the circuit of Figure 1 is used because Rm is tiny compared to the input impedance of a unity-gain follower op amp stage.
Rm might or might not be important if the circuit of Figure 2 is used. (a) If Rm differs somewhat from one multiplexer channel to another, Figure 2 may be unsuitable because calibration will be cumbersome.  (b) If Rm is comparable to Rx, Figure 2 is unlikely to produce high-accuracy results.
Whether unity-gain followers are necessary
Whether you need unity-gain followers depends mostly on the size of resistors you are measuring.  Arduino analog inputs are high-impedance (10⁸Ω, but with about 14pF capacitance to Vcc/2).  Atmel suggests analog source impedances of 10KΩ or less for best results.  [See (1,2,3) for additional discussion.]  Briefly:  If Rs+Rx is likely to exceed 20-40KΩ and you wish to measure quickly, use unity-gain followers.
Resistance Formulas
Let Vt be the voltage at the lower end of Rs in either figure.  Vt is the voltage that will be measured at an analog input Aj.
In Figure 1, because Vt = Vcc·Rx/(Rx+Rs), we have Rx = Vt·Rs/(Vcc-Vt).
For the circuit in Figure 2, an additional resistance Rm is in series with Rx, so Vt = Vcc·(Rx+Rm)/(Rx+Rm+Rs), whence Rx = Vt·Rs/(Vcc-Vt)-Rm.  If Rs and Rx are large (eg 40KΩ and 10KΩ) then ignoring Rm may cause only a fraction of a percent of error.  But if Rm is comparable to either of Rs or Rx, either use the circuit of Figure 1 or devote some inputs of each multiplexer to use as calibration inputs.
Analog input reference voltage
If Vcc is 5 V and we choose Rs four times as large as the largest resistance value that you intend to measure, then Vt will be between 0 and 1 V.  You can use an analogReference() call like analogReference(INTERNAL) [or analogReference(INTERNAL1V1) on a Mega] to set the analog reference voltage at 1.1 V, to maximize accuracy of measurement and to minimize the amount of current required through Rx.
Advantages of Figure 2
Unless Rm is a problem (as discussed above) the following advantages of Figure 2 suggest its use:

Lower power requirements:  In Figure 1, all the resistors under test always have current going through them.  In Figure 2, only 1/16 of the resistors are powered at any given time.  Also, by raising \EN to shut down the 4067's (or 74HC4067's if used) all the resistors can be powered off.
Less wiring and fewer parts:  At most eight Rs parts are needed, rather than one Rs per Rx.  Each Rx connects to ground and to one mux input, rather than to ground and to the junction of a mux input with an Rs.

Cable Note
For either figure, seven or eight wires run from the Arduino to each 4067 subcircuit.  One wire from each subcircuit carries Vt back to an analog input.  The other wires connect to all subcircuits in parallel: four channel select lines (A, B, C, D in figures, or S0-S4 in datasheets); Vcc; ground; and \EN unless that line is wired to ground.  Each 4067 subcircuit should have a bypass capacitor, eg 10-100 nF, from Vcc to ground.  Boards like the “Geeetech CD74HC4067 Analog Digital MUX Breakout Board” shown below (about $5 on ebay) might be used, or you could design a custom board and have it made at OSHPark or Seeedstudio.

As I read your question I was thinking of the 4067 chip as part of the solution.
You'd rig one 4067 as the anode and another as the cathode on a grid of 64 resistors. You'd then send select an anode channel and a cathode channel, feed +5 volts into the common for the anode channel, and then feed the common from the anode channel into an ADC input on your Arduino. You'd need to allow for the fact that those chips have an internal resistance of around 180 ohms, (at least the TI chip I looked up did. My CMOS cookbook lists 200 ohms resistance.) As long as you're measuring resistances that are substantially bigger than 400 ohms, that should work (or you could precisely measure the resistance of your 4067 chips at your operating temperature and then adjust your math to compensate.)
Mind you you'd have to sample these resistances one at a time, in round-robin fashion. It would be kinda slow.
If you want to test more than 64 resistances, you could use 2 4067s on either the anode side or the cathode side and use the inhibit pin to select the chip. That would give you the ability to sample 128 resistances.
I did find some 8 and 16-channel serial ADCs. You could use those and some select logic to do the same thing. Take a look at the AD7490. That's a 16 channel serial ADC. That and one of the 4067 16-channel MUX chips would give you 64 ADC inputs in banks of 16.

This will only work if you add diodes in series with all of the resistors and account for the added diode drop.  Otherwise, all of the other resistors connected will significantly affect the measurement.

Not true. With a row and column arrangement of MUX chips, you can connect +5 to one wire of the test resistor and then read the voltage through the other MUX chip.

Let's call the wires drive wires and sense wires.  The drive MUX drives one drive wire to 5v.  The sense MUX then selects a wire to check the voltage.  There is a test resistor that connects each sense wire to each drive wire.  The problem is this:  the sense wire is connected to other drive wires by other unknown resistors, so whatever you do with the other drive wires (grounded or floating) they will affect the measurement of the 'unknown' resistor you are trying to measure.  Either you need one mux pin per resistor, or you need one diode per resistor to isolate a single resistor.

CMOS MUX chips and one-of-n chips have nearly infinite impedance when they are in the open state. Thus, only one path from 5V (drive wire) will be "hot" at any one time, and only one path from the sensor to the arduino (sense wire) will be connected. All other drive wires and sense wires will be open circuits. This would be much easier to describe if I could create a CircuitLab picture of it.

You want to do something like this with resistors, correct?  http://xronosclock.com/home/wp-content/uploads/2014/02/LedMatrix.jpg  The only reason you can get away with this with LEDs is because current can only flow one way through an LED.  If you try this with regular light bulbs, then quite a few of them will light up if you apply power across one row and one column.

No no no no. That is not true. You put a MUX on the rows, and a MUX on the columns. You connect the common on the column MUX to +5V. You connect the sensor line to the row MUX common. You put the resistors you want to measure connecting each row/column. Each MUX chip only connects one row or column. If you select column 0, row 0, you're running +5 v though the "anode" of resistor 0,0, and sensing the output voltage from the "cathode" of that resistor. None of the other resistors has a path between +5 and the sense pin, so they have no impact on the resistance.

And yes, you could also use the same rig with lightbulbs (not LEDs) and light 1 and only 1 lightbulb. I'll make a substantial bet on this, and I'll win. The thing you CAN"T do is connect switches at each address in the grid and figure out what's going on when more than one switch is pressed at a time.

Nope.  No other resistor will have a DIRECT path. But there will be a large number of paths that pass through 3 resistors.  Take a look at that figure I linked to.  Replace all of the LEDs with unknown resistors.  Leave all rows and columns disconnected, except for row 0 and col 0.  Current will flow through the resistor at 0,0.  However, it can also take a path through 1,0 then 1,1 then 0,1 and get to the same place.  Or 2,0 then 2,2 then 0,2.  You can come up with a great many paths like this that will all appear in parallel with the resistor you're trying to measure.

If you replace the LEDs with lightbulbs in the same configuration, then the bulb at 0,0 will light up brightly.  However, ALL of the other lightbulbs will also illuminate as current can take the same set of paths through 3 bulbs to get to the same place.

You're right. I was wrong. My scheme would require a series diode on each unknown resistor to prevent current from flowing backwards through the resistors as you described.

Also, one more thing to note: if you put diodes in there, you are going to get a 0.6 to 0.7 volt drop across the diode, which will have to be accounted for.  If this is constant, then it is a simple matter to compensate for this digitally after taking a reading of the voltage.  However, it is possible that this will vary significantly with current, so you may need to do something a bit more clever.  You need a resistor to ground at the ADC input to put the unknown resistor into a voltage divider.  Perhaps taking two measurements with two resistors would allow the diode drop to be removed.

So what was the bet from???


text:
Do they make 2.54mm 2P Crimpable Micro JST Female connectors?
This may be a dumb question but I need some (preferably with wires already attached) and I'm unable to find any like this. Everything I find has male crimps and female surface mount. That doesn't work for very well with my project because I do not have room in my project box for another board. I'm already cramped just adding the headers that I was planning to solder these wires to.
Here is what I'm looking for in the 1.25mm variety:

I don't believe "micro style" is a JST family designator.  You should start by figuring out which JST family you actually want, often they use two letter designations.  Also, voting to close as this has nothing specifically to do with Arduino, but is rather an entirely generic electronics question.

I've found this product listing on Amazon:
2.54mm spacing JST extension cable.
It resembles the connector you've shown only slightly, but may be the only option out there.
And to contest the above statement, one that looks more like your objective:
Another 2.54mm spacing JST cable
There may be others. I used "jst 2.54 mm 2 pin female cable" as the search terms specifically in Amazon, other sources may have similar results.
Firing up the old Google again, using the last set of search terms, I've found an eBay listing:
eBay product listing
with the source in china. The photo appears correct, although the listing is for two cables, one male, one female, there is a third photo with the circuit board mount type connector.
This particular listing calls them a 2.5 mm connector, close enough? Perhaps a translation error.

The first is not the micro style. I don't think that is the same but I could be wrong. It looks much different. The second appears to be a typo because the picture shows male ends on the wires.

I don't think the first type would be interchangeable with the white connector style. I grabbed the second because of the text and didn't look at the image. I've added a third link, but it has caveats as well.

authors: Хаджимурад Тугайлаев


text:
How to build (concat) a string with big numbers
new to arduino I'm struggling with what sounds like fairly n00b problem...
I've wired up a adafruit GPS-board to my Arduino and it is working as it spits out GPS data to the serial port with Serial.print(GPS.latitude, DEC)
I Now want to concat a string which I can process (read: I want to sent it via an ethernet client.)
This is what I got already:
......
String vnnt = "$VNNT,";

if (GPS.fix) {
   vnnt += "GPS,";

   //this works:
   vnnt.concat(GPS.fix);

   //but this not:
   vnnt.concat(GPS.latitude);

}else{
   vnnt += "INFO,Acquiring Sats";
}

Serial.println(vnnt);

The error message is: Call of overloaded 'concat(float&)' is ambiguous
When I Serial.print(GPS.latitude, DEC) it results in: 4418.5937996050
So it is probably to big or something...
How can I concat the vars and create the long string?

Aren't you missing a semicolon?

and one says vnnt while another says vannut

Sorry some typo's :)

Do you know the datatype of GPS.latitude? E.g. is it a float, int, etc.?

I think it's a float? It says float in the error-message. How can I find out? Is there a var_dump or something?

@stUrb I managed to look it up in the GPS library, and it is indeed a float.

@stUrb, you can check that it is actually a float in the code, in the folder you downloaded, online here: https://github.com/adafruit/Adafruit-GPS-Library/blob/master/Adafruit_GPS.h

The concat function does not implement a float version, but some of char, int, unsigneds...
unsigned char String::concat(long unsigned int)
unsigned char String::concat(unsigned int)
unsigned char String::concat(int)
...

so the compiler does not know how to cast (truncating probably the float) to integer, as there are several options.
You have to convert first your float to string, use dtostrf() or sprintf() then concat to your string.
char outstr[25];
sprintf(outstr, "%f", GPS.latitude);

or
dtostrf(GPS.latitude, 6, 2, outstr);  //check docs for 6, 2 values, and set them for your needs

And then:
vnnt.concat(outstr)

Also note that sprintf is very handy for compact creation of a (char) string:
char msg[80];
sprintf(msg, "$VNNT,GPS, %s %f", GPS.fix, GPS.latitude);

+1 when in doubt, sprintf it out :)

One point of caution though: sprintf() is a complex function, hence it is rather slow and uses quite some memory. Generally, I would avoid it for "production" code (only keep for debug purposes).

That is a good point @jfpoilpret, I didnt take into account. Do you have some order of magnitude of efficiency vs a dtostrf+concat version? Does the same apply to sscanf()? (btw, I now doubt if sscanf() actually works fine in arduino)

I did not perform actual measurements to compare both calls, but I guess one could just take a look at the C code and possibly check the generated assembly. Regarding sscanf, IIRC it has some limitations (with floating point numbers I think).


text:
Simultanous read and read/write on two serial connections
At the moment I'm using two softserials to connect to a GPS and an GSM module.
It seems not possible to have two open software-serials. So I was looking for an solution
After the initial-setup, the GPS module is only needed to be read from; while the GSM module needs to be bidirectional. So:
GPS > listen only
GSM > listen and write

Now I came across the GPS library from Adafruit, which uses an interrupt to receive data. Is this instead of a software serial. Or do I again run into the limitation?
An other solution might be to use the D0 and D1 to attach eg the GPS module. But than I won't be able to see the debug messages in my serial monitor. Is that correct?
Sorry in advance for these n00b questions. But I'm frustrated the things dont work as I want :)
edit

This is the adafruit GPS board.
And the board with whom it is connected: Gboard
The Sim900 is connected to D2/D3 and the GPS is connected to A2/A3.
D0/D1 are connected to a FTDI breakout board, which is plugged into my USB.

About the debug massages when using D0/D1, you'll at least have to provide the spec sheet and circuit diagram for the GPS module and Arduino Uno.

I update the OP with the boards en connections I use.

In case you weren't aware, Mega2560 has four UARTS, which could make life easier.

@gwideman That's a better solution, but for now I have to work with the Gboard. Next version of this device is going to be with at least two UARTS and separeted sim900 and GPS module.

So you want three serial ports: upload/debug (hardware serial), GSM (software serial) and GPS (software serial).  Unfortunately, two SoftSerial ports are not going to work at the same time (or even send and receive at the same time on one SoftSerial port).  In your current configuration it's not going to be solvable.
If you can wire the GPS to different pins, there are a couple of options to try.  One would be to disconnect the FTDI when running (reconnect to program) so you can use the hardware serial port for either GSM or GPS (probably the former).  If you need some print statements for debugging, you could use SoftSerial or AltSoftSerial (and connect the FTDI differently).  Reconnecting between upload/debug and run phases would be a pain but it comes with the platform you are choosing and the number of serial ports you need; you might be able to wire up a DPDT switch externally to do the switching rapidly.
The other and perhaps easier approach would be to connect the GPS to pins 8 and 9, and use AltSoftSerial for the GPS; as long as your baud rate to the GSM is high enough that might work.  (SoftSerial for the GSM will turn off interrupts for excessive periods of time at low baud rates).  Using AltSoftSerial makes use of the single 16 bit timer (Timer1), so this won't work if you use any other library which requires Timer1.

All right! at te moment I am bound to this board/setup, but in the future I'll use the bigger chip with 4 UARTS. For the time being I'm going to use the HWs for the GPS and use the switch-technique. Because after the setup works, I won't be needing the  debug messages as there won't be a computer connected to it.

Am I right that I would be able to use both HW an SS connections at the same time?

Yes, you can use both, with some caveats.  The HW serial library could miss a received byte if interrupts are off too long; and the SS library inhibits interrupts while timing the bits.  If the HW receive rate is much faster than the SS rate, this could be a problem.

Both are 9600 Baud, so that wouldn't be a problem. In the meantime I got it working with the GSM on SS and the GPS on the HWS; it was easier to use the library for the GPS on the HWS.

Adafruit_GPS.h (line 132-), which is included in Adafruit_GPS.cpp (line 13) refers in turn to the SoftwareSerial library on AVR platform and Arduino IDE version > 100.
#ifdef __AVR__
#if ARDUINO >= 100
    SoftwareSerial *gpsSwSerial;
#else
    NewSoftSerial *gpsSwSerial;
#endif
#endif

This means it uses software serial on an Uno. It also means if your problem is indeed with Software Serial, that is the library to check for bugs / updates or commit a patch to.

So the only solution might be to use the hardware RX/TX, with the downside being not able to see the debug messages.

@stUrb Depends on the hardware I guess. I am not familiar with the GPS module.

The solution to your problem might be to combine AltSoftSerial with SoftwareSerial. I haven't done it myself (yet) but I have the same problem as yours.
SoftwareSerial does busy wait for counting time between two bits, so it can't read simultaneously from two ports (some bits could be lost).
AltSoftSerial was created to overcome some of these limitations. It's interrupt-based. Unfortunately, it's harwired for one port (and pins 7 & 8). My understanding is that you can combine it with SoftwareSerial to read from 2 simultaneous ports. Pins 7 & 8 aren't what you need, from the description of the GBoard, but AltSoftSerial is open source, you can change the pin numbers (and possibly some masks) in the source code.
Hope this helps.

I've done exactly this.  The secret sauce for me was the SoftwareSerial.listen().
Before running your GSM commands you have to make sure the GSM module's SoftwareSerial port is "listening".  Then when you're done you have to listen() again to the GPS.
This is, of course, not terribly efficient, while the GSM port is listening any GPS data will be lost, but at least in my case the impact was negligible.
My code is here: https://github.com/lectroidmarc/gsm-tracker
As an aside, I have also considered plugging the GPS into the UART and running debug messages to a SoftwareSerial serial port, to be monitored during testing with another Arduino.  I'm just not sure the benefit would be there.

There is a working example of this, using the Adafruit Ultimate GPS, and the Arduino GSM shield
http://www.mallinson-electrical.com/shop/gpsgsm
I hope this helps

Generally it's not a good idea to post link-only answers. If the link goes down or moves, the answer becomes useless. Please expand by adding some more information (code sample) to the answer.


text:
Failed to read DHT22 sensor using Intel Galileo Gen2 board
Why do I end up with the display

Failed to read from DHT sensor!

in the serial monitor in most cases when I run the code given below? When I reduce the delay to 1000ms the reading shows 0.00 for both temperature and humidity which, as well, is pretty much false. Any help would be highly appreciated.
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
//#define DHTTYPE DHT11   // DHT 11
#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
// NOTE: For working with a faster chip, like an Arduino Due or Teensy, you
// might need to increase the threshold for cycle counts considered a 1 or 0.
// You can do this by passing a 3rd parameter for this threshold.  It's a bit
// of fiddling to find the right value, but in general the faster the CPU the
// higher the value.  The default for a 16mhz AVR is a value of 6.  For an
// Arduino Due that runs at 84mhz a value of 30 works.
// Example to initialize DHT sensor for Arduino Due:
//DHT dht(DHTPIN, DHTTYPE, 30);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hi);
  Serial.println(" *F");
}

Is that library designed for the Galileo? I see that it runs at 400 MHz, whereas the library (when I last used it) was for a 16 MHz Arduino. The DHT11 uses a highly timing-specific protocol. A search for intel galileo dht11 revealed DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one

This is only because i am using the same material as from where ctrl+c and ctrl+v was done! :) Further adding to it, please can you specify in detail the pin connections? means in simple words like which pin is to connect diode with, which pin to connect resistor with from the link you have shared above! (also the specification of diode and resistor). Thanks mate for the help!!! Cheers..

And in addition I am using 3 pin DHT22 (Vcc, Out, Gnd).

The article link by Nick is the same that I found, so it must be a well search problem.
What is described on the Intel forum is that the Galileo is not capable of direct communication with the sensor as it is a computer and not a microcontroller, so therefore lacks the ability for accurate timing required by the sensor and also the DHT* is considered a peripheral and would thus require a way to interface with the "PC".
What is described in the post is to use two pins to create the proper digital signal for the DHT.
The circuit makes use of a diode to protect the output pin.
The OP on the forum describes the connections like this:

Pin 2 of Galileo is connected to the data pin of the DHT11.
Cathode of the diode is connected to pin 3 of the Galileo.
Anode of the diode is connected to the DHT11 data pin.

The diode would be a standard diode, possibly a fast switching signal diode as the 1N4143. The resistor would be the standard pull up resistor of 10K Ohms.
Here is the OPs schematic:

(source: intel.com)
You will also need to make use of the code linked to by the OP in the linked post as it was modified to work with the workaround.

Here it is written, "pin 2 is connected to the DHT11", But whose Pin 2 to connect to DHT and on which pin of DHT i should connect.

@JayM hi, the PIN2 is the Galileo and PIN3 is also the Galileo. Pin 2 is connected to the data pin of the dht, while pin 3 is connected to the cathode of the diode and the anode of the diode to the data pin of the dht check this schematic from the op https://communities.intel.com/servlet/JiveServlet/downloadImage/2-245223-237707/DHTGal.PNG

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


text:
Permanent connections with Arduino Due
The Arduino Uno (for some models) has the ability to dislodge its IC chip. You can mount this on a piece of perfboard and, in essence, have a permanent connection. I will need the beefier Arduino Due, but I do not know how to make permanent connections with this device. Is there any way to form some kind of permanent connection with this board?

Your first sentence is wrong – there is no Arduino that can take its own chips off the board – but perhaps you meant to refer to Arduinos that have the chip in a socket.  Or maybe you are referring to the pin sockets along the edges of the boards.  In any case, you can buy little plastic cases to contain Unos, Dues, etc which may help hold pins into the pin sockets; or less elegantly, can hot-glue your wires in place

The AT91SAM3X8E is only available in QFP and BGA packages. Not in DIP like the UNO.

The chip on the Arduino Mega (ATmega1280) is available in DIP. So that might be an alternative, that's a bit more powerful then the UNO.

@Gerben Having more pins and more memory doesn't really equate to the chip being more powerful. It's still the same wimpy 8-bit core as the '328P. It just means you can be a little lazier with your programming and memory usage.

What it sounds like you want is an Arduino Due footprint prototyping shield.
Arduino make one, although it is out of stock, but it gives you an idea of what you are looking for. There are plenty of other designs out there for purchase of varying degrees of complexity.
You solder the pins in place and mount it on top of your Due just like any shield, and solder your wires and components in where you want them.
An alternative option, of course, is to step away from Arduino and investigate some of the many other chips from other manufacturers out there that are considerably more powerful than the 8-bit ATMegas used on the low-end Arduinos, and yet are still available in a DIP footprint - chips like the PIC32MX1xx/2xx series from Microchip - 28 pin DIP (just like the 328P) yet 50MHz, 32-bit power.  Yes, it will be a bit of a learning curve, but there are helpful options out there that can assist you, like the chipKIT system including the handy DP32 board from Digilent.

Also investigate the Teensy 3 for a much beefier Arduino-compatible system with a small footprint which can be soldered to perfboard etc.

You can disolder the female pin headers from pcb and make permanent connections on the remaining holes.

I think the best thing you can do with this, is that you use temporary wires to connect and test the application and later, when you'll come to part, where you should "make-a-solid", you just solder these wires to the bottom, where pin headers are. I think this is the simplest way to do it.
If you want to do it a bit better, desolder female header pins and solder cables to those holes. It's more electronics-approved that way.
Or the simplest (but not the brighest): Jumper wires can be glued into female header pins, but I strongly unrecommend this option, as same as making a shield for this.
There's another(and most elegant too!) option of making a PCB version of arduino: Add the AtMega, few passive components and proper pads, to solder wires on.


text:
How to control relay using SIM800 and Arduino Mega through SMS?
For my project I need to control relays through SMS and now I can send SMS from my SIM800 module which is connected to Arduino Mega R3. But I tried several shapes for AT commands to receive SMS and parse it to check sender number and SMS text but every time I received a 2 digits number in serial monitor of Arduino,

Post your code.

In below page I found a code which can solve my problem with some modification but when I tried to compile it, there was an error which has displayed gt is not declared in this scope. and I could not find out what gt usage is

LINK: http://www.ayomaonline.com/iot/sim800-controlling-arduino-with-sms/

Replace every > with > and it should work.

Probably something wrong with the website, since > is the HTML entitie for >

thanks for your comment, I had changed the gt symbol with > and &lt with < there is not any error after modification but still not any response when SMS receive

Update your post with the code you have now.

and based on these modifications the code is pasted below:

} else if (lastLine.length() > 0) {
if(nextLineIsMessage) {
Serial.println(lastLine);
if(lastLine.indexOf("LED ON") >= 0){
ledStatus = 1;
} else if(lastLine.indexOf("LED OFF") >= 0) {
ledStatus = 0;
}
nextLineIsMessage = false;
}
}
for( int i = 0; i < sizeof(currentLine);  ++i ) {
currentLine[i] = (char)0;
}
currentLineIndex = 0;
} else

Since code was too long to update here so I had to paste some parts of it. for checking please paste complete code from above link then in void loop do necessary modifications by finding and replacing > with > AND < with <

with below code I could receive sms but still seeking a way to parse it

#include <SoftwareSerial.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial SIM800(10, 11);
void setup()
{
SIM800.begin(19200);
Serial.begin(19200);
SIM800.write("AT+CMGF=1\r"); //set GSM to text mode
delay(1500);
SIM800.write("AT+CPMS="SM"\r"); //Preferred SMS Message Storage
delay(1000);
while(0!=SIM800.write("AT+CNMI=1,2,0,0,0\r\n")){
SIM800.write("AT+CMGR=1\n\r"); //list the first message from SIM Memory
SIM800.write("AT+CMGD=1\r");
}
while(1)
{
if(SIM800.available())
{
}
}
}
void loop()
{
}


text:
How to generate true random numbers over Arduino Uno without any external hardware?
Using a 'random' function in sketch gives same pattern of numbers every-time. But, I need to generate different numbers such that any number to repeat itself should have a very less probability.

If you just want random data (but not true random data, only random pseudo-random data) follow Edgar Bonet solution. Read this article and, of course, the wikipedia page to better understand this. However, unless your application is very particular, you won't need true randomness, because pseudo-random numbers are fine for almost every application

Related: https://arduino.stackexchange.com/questions/50671/getting-a-truly-random-number-in-arduino

The standard (but not very good) solution is to seed the random number generator from an analogRead() on an unconnected pin. For better options, see this answer to a related question.

This, however, is not a "true random numbers generator", it's a randomly seeded pseudo-random generator. This, however, is what I think the OP was requestiong, so +1

Allocate 4 bytes in EEPROM to save a seed value.
Use the EEPROM library (#include ). Use EEPROM.put() and EEPROM.get() functions to write and read the seed value to EEPROM.
In setup(): Read the seed_value from EEPROM, increment it and write it back to EEPROM. Then call randomSeed(seed_value).
Now, after every run of setup(), random() will create a whole new random sequence. If you need a new sequence within your sketch, you can repeat the process, and don't forget to write the new seed to EEPROM for next time.
Note that I didn't bother with initialising the EEPROM value the first time we run. It'll probably be zero when you start a new Arduino board, but the only thing that matters is that you increment it each run. Incrementing by 1 will do the trick, but any increment value will probably do.

I notice that the title said "true random", but the question asked for something different. My suggestion solves the request, but it's not a "true random" generator, of course.

The EEPROM usually has a initial value of 255 on a fresh Atmel AVR chip.

Oh? I thought I remembered finding zeros up there, but it doesn't matter in this case. Thanks.


text:
What is the maximum SPI speed for a slave Uno/clone?
I have a Rapsberry Pi master sending SPI requests to an Uno Chinese clone slave : I send 16 characters to the Arduino, which answers 16 others characters. What I send is not important, it's the Arduino answer that matters.
When I set the speed on the Raspberry Pi at 1 Mbit/s with my C program, the received answer coming from the Arduino is mostly garbage (random characters), but this issue disappears with lower speeds.
So that leads me to this question : what is the maximum SPI speed for a slave Uno/clone, in order to have no errors ?
Edit : the Arduino code :
#include <SPI.h>

char receivingBuffer[5];
char sendingBuffer[5] = {'T', 'e', 's', 't', '!'};

volatile char bytes_received = 0;

void setup()
{

  SPCR |= bit(SPE);

  pinMode(MISO, OUTPUT);

  SPI.attachInterrupt();

  SPDR = sendingBuffer[bytes_received];

}

ISR(SPI_STC_vect)
{

  if (++bytes_received == 5)
  {

    bytes_received = 0;

  }

  SPDR = sendingBuffer[bytes_received];

}

void loop()
{

  //

}

Also, the C code on the RPi :
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPiSPI.h>

#define SPI_CHANNEL 0
#define SPI_SPEED   1000000 // Hz.

int main(void)
{

   wiringPiSPISetup(SPI_CHANNEL, SPI_SPEED);

   while (1)
   {

      char buf[5] = {'T', 'e', 's', 't', '?'};

      printf("Sending   : %s\n", buf);

      wiringPiSPIDataRW(SPI_CHANNEL, buf, 5);

      printf("Receiving : %s\n\n", buf);

      sleep(1);

   }

   return 1;

}

The theoretical maximum is 8Mbps, which is F_CPU/2. What matters though is that you react fast enough to the requests for each byte and fill the buffer fast enough. That's down to your program to determine.

Please show your code. What you are doing in order to answer is highly relevant. If you are sending at 1 Mbits/s then the slave doesn't have many clock cycles to formulate a response.

I added the Arduino code.

What happens if you set a transfer speed of >1Mbps and put a delay in between each byte (at the Pi side) - does it start working then?

With 1.5 or 2 Mbps, I receive the first character of the expected answer, and the other characters are the sent message's ones.

I have a 1 second delay in the while() loop between two messages, but I'm using the WiringPi library to work with SPI, and I don't think I can put a delay between two bytes.

Sure you can. Just send one byte instead of 5.

The maximum speed for Arduino as a slave is F_CPU/4, so it's 4Mbps.
When the Arduino is the master it can work at F_CPU/2, so it's 8Mbps

Thank you for your answer ! Do you have any source to confirm this ?

You can find this in ATmega328 datasheet. The ATmega328 is the chip on Arduino Uno.


text:
Disable other buttons while one of buttons is pressed
I'm making a project with three buttons. What I'm trying to do is to disable other buttons (make them not respond to a click event) when one of three buttons is pressed.
For now I have this code:
    const int button1=3;
    const int button2=4;
    const int button3=5;

    int button1State=0;
    int button2State=0;
    int button3State=0;

    void setup() {
    pinMode(button1, INPUT);
    pinMode(button2, INPUT);
    pinMode(button3, INPUT);
    }

   void loop() {
   button1State=digitalRead(button1);
   button2State=digitalRead(button2);
   button3State=digitalRead(button3);

   if( button1State == HIGH){
   // do some stuff
   }

    if( button2State == HIGH){
    // do some stuff
    }

    if( button3State == HIGH){
    // do some stuff
    }

    }

Do you have any ideas how I could do it?
Thanks is advance for any suggestions!

what code do you have so far?

I've added a code to the post question

Yea, definitely use an FSM as per my suggestion below.

The best solution for this is a finite state machine. There are lots of tutorials on state machines, just google.
Finite state machines are a very important concept in coding. You will find the need for them everywhere. Do yourself a favour, and read up about them, practice them, understand them, love them. Understand when they will be useful, and when they are not. If you do not, you will be back here shortly, with another question, which could also be solved by a finite state machine.
I strongly recommend you use this task as a practice task for learning about finite state machines.
Note also that, in electrical circuits, you frequently get bounce - when you push a button, your arduino will see many "button presses" (from off, to on, back to off), until it settles down. See http://blog.kennyrasschaert.be/images/20140401/Bouncy_Switch.png for example. A state machine can also help you with this.
If you don't want to learn about FSMs, read on:
initialise last_button_pressed to 0 (meaning no button pressed)
if last_button_pressed>0
   if not(is_button_pressed(last_button_pressed) then
      last_button_pressed=0
else (no button is pressed)
   for each button_to_check (1,2,3)
      if last_button_pressed=0 and is_button_pressed(button_to_check) then
         last_button_pressed=button_to_check

Thanks a lot for your suggestion. I'll surely learn about finite state machine and hope it will work for me

The principle of FSMs are not that difficult. Have a go, and post your state diagram here, and I will give you some more pointers. Then you can try implementing it, and I can give you more pointers.


text:
Arduino LDR sensor stained
I bought a light sensor (LDR), but he got stained, what it means? It is used? Or is residuum of time?
I must give back? I have to clean up or something?
I bought as new, so I tested one of the LEDs will not turn on.
I bought the (Mercado Livre in BRAZIL).
The product is:
http://www.gbkrobotics.com.br/exemplo-produto/p7-sensor-de-luz-com-leds.pdf
I pay R$8 BRL (equivalent aprox. $2 dollars) but, i just wanted to know if he had something I could do, because only shipping was R$ 13 BRL ($4 dollars)

I'm starting with Arduino, thx

Do you have a picture of the front, or a datasheet/part number?
It could be that the LED is in the wrong way around, or that it is simply broken.
The stains could be due to moist. Have you bought the item off e-bay? Then you should contact the seller, give him pictures of the stains and defective LED. They're usually very kind and if all else fails, you can open a PayPal dispute (if you really want to get your money back).

Hey, man! I update the question, please check?

I doesn't look that  bad in the photo. Try cleaning it with some alcohol or acetone on a tissue. Otherwise it's probably inconsistent thickness in the blue soldermask that was applied. This wouldn't affect it's function anyways.

It's a light sensor. So try covering the sensor (check if the lights go off) and try shining a flash-light on it. That might make all three LED's go on.

I've read you post a couple of times and I get the impression you would like this board to work, so here are some quick check to try and find the fault.

You need a bread board
An arduino
A 200-300 ohm resistor.
Some wires. About 6 hands :)

Connect the board ground to the breadboard.  Then connect the to the resistor.  Then connect that to the power supply ground.
Take the positive off the power supply and touch it to the LED1 pin and check LED1 lights up.  Repeat with 2 and 3.
Switch every thing off
Connect the Positive to the Vcc connection of the board.
Connect a wire between Arduino A0 and "Sinal Analog"
Load this sketch
   void setup() {
       Serial.begin(9600);
    }
   void loop() {
       Serial.println(analogRead(A0));
       delay(250);
   }

When you cover the LDR it should read a lower number when you shine a light on it should read a higher number.
Turn everything off again, and if you have a multi meter test the resistance of the resistor on the board it should be 300 ohms, but I can't remember which way to read the bands and it might be 10K ohms, which would be a problem.
If anything doesn't work then they can all be fixed for a few cents and you don't need to worry about the discolouration.
Hope that helps you.

Thank you for your help. The store sent me a new sensor. The LED3 dosn't work )):

If you don't need to return the broken one then replacing LED three should be very easy (if you get it the right way round) and then you have two :)


text:
BMP280 returns 0
I have connected a BMP280 temperature/pressure sensor to an Arduino Uno just like here:

and used the example code provided by the Adafruit BMP280 library. However, the values for temperature and pressure return 0.00 on the serial monitor. What might be the reason for this? I have set it up in I2C mode and deleted the lines responsible for the SPI connections.
    /***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMEP280 Breakout
  ----> http://www.adafruit.com/products/2651

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK 13 // deleted the following 4
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10

Adafruit_BMP280 bme; // I2C
// and the following 2 lines:
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));

  if (!bme.begin()) {
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}

void loop() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

    Serial.print("Pressure = ");
    Serial.print(bme.readPressure());
    Serial.println(" Pa");

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcase
    Serial.println(" m");

    Serial.println();
    delay(2000);
}

Yes, the manufacturer's data sheet says there is one integrated (120 Ohms)

Well, I followed this tutorial http://www.instructables.com/id/How-to-Use-the-Adafruit-BMP280-Sensor-Arduino-Tuto/step2/The-Circuit/. Where in the schematic would I place such a resistor?

I2C has to have pull up resistors on the data lines, otherwise it just doesn't work.
Have a quick search for the correct value but off the top of my head is 4.7k ish.
You have to place a resistor from the SDA and SCK lines to the +5V and suddenly it will jump into life. (Hopefully)

I suspect there are already pull-ups on the breakout; doesnt make any sense to not include them. Also if there were no pull-ups, begin() would have failed and there'd be a different error message

The recommended value is 10k, according to the documentation. When I connect one of them each between the data pin and V+, I still get an output of 0

Recently i bought a bmp280 which is not an adafruit one and connected it to esp32 and and tried to upload the code from the examples test but i got the error no valid bmp 280 found, i searched on google and found
https://www.circuitschools.com/interfacing-bmp280-with-esp-32-on-i2c-with-errors-and-solutions/
i read on i2c addresses errors,then from there i copied the code for an i2c scanner and ran it to get the correct i2c address  I checked on I2c address and replaced the i2c hex address in the BMP initiialization line.
then the sensor worked and gave me temp, pressure and approx altitude. Thanks

well the reason for changing the I2C address from 0x77 to 0x76 is when you have your SD0 pulled down to ground.
If there is nothing attached to SD0 on the BMP280 the device address is 0x77 by default.

I had the same problem and I solved it by changing I2C address from 0x77 to 0x76, in Adafruit_BMP280.h

Good answer, and it would be better if you also had an explanation


text:
where I can find ground?
there is AVR AVR ATmega32 and a board within.
there is outputs for all ports (A, B, C, D) on board, and Vcc.
the problem is - I have no external GND output.
to watch current - I should search for GND pin everytime.
and now I need ground on my solderless board for LEDs and temperature sensor.
let's guess that I have no idea what is current or electricity.
so the question is: where I can find ground to connect it to solderless board?
maybe I can use something else, except MCU? (like my hand or smth :D)

Without knowing what your board is it's impossible to answer you.

Image is broken.

@Majenko, reuploaded, check it now

I'm amazed that there are six Vcc pins yet not a single GND pin. Have you tested for continuity to see if it's an error in the silkscreen?

to watch current - I should search for GND pin everytime - I don't understand this bit. How does finding GND help you watch current?

It looks like there are two pins at each of the I/O pin locations. Is one of the ground? Measure with a meter to a known ground (e.g., on the reset switch or in the programmer sockets).

I've just sorted things out.
There is two interfaces - ISP and JTAG. ISP is busy with programmer everytime, but JTAG is free.
So, I have found pinout of JTAG interface and achieved GND.
There is pinout:

(source: digital-circuitry.com)

You can check if any pin at J1 to J8 happens to be GND also.

Pin 11 of the chip itself is GND (see below). In the photo it appears to have a decoupling capacitor between GND and VCC (pin 10). You could solder a wire onto pin 11 (on the chip socket, not the pin itself) - it might be easier on the back of the board. Also pin 31 would be an option.

Also the reset switch is almost certainly wired (on one side) to GND. It looks to me like most of the board is "ground plane" (continuous copper) so find which part of the switch is wired to that, and solder a wire to it.


text:
Pass class's public function as an argument to external command
I am trying to write a library for encoders.
main.ino:
#include <./Encoders.h>

Encoders encoders();

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

void loop(){
    Serial.print("");
}

Encoders.h:
#ifndef Encoders_h
#define Encoders_h

#include "Arduino.h"

class Encoders{
    public:
        Encoders();
        void EncodersSetup();
        long RightCount;
        long LeftCount;
        void R_A_RISE();
        void R_A_FALL();
        void R_B_RISE();
        void R_B_FALL();
        void L_A_RISE();
        void L_A_FALL();
        void L_B_RISE();
        void L_B_FALL();
    private:
        short R_A_SIG, R_B_SIG, L_A_SIG, L_B_SIG;
};

#endif

Encoders.cpp
#include "Arduino.h"
#include "Encoders.h"

long RightCount;
long LeftCount;
long R_A_SIG, R_B_SIG, L_A_SIG, L_B_SIG;

Encoders::Encoders(){
    attachInterrupt(0, R_A_RISE, RISING);
    attachInterrupt(1, R_B_RISE, RISING);
    attachInterrupt(2, L_A_RISE, RISING);
    attachInterrupt(3, L_B_RISE, RISING);
    R_A_RISE();
}

void Encoders::R_A_RISE(){
    detachInterrupt(0);
    R_A_SIG = 1;
    if(R_B_SIG == 0){
        RightCount++;
    }
    if(R_B_SIG == 1){
        RightCount--;
    }
    attachInterrupt(0, R_A_FALL, FALLING);
}
void Encoders::R_A_FALL(){
    detachInterrupt(0);
    R_A_SIG = 0;
    if(R_B_SIG == 1){
        RightCount++;
    }
    if(R_B_SIG == 0){
        RightCount--;
    }
    attachInterrupt(0, R_A_RISE, RISING);
}
void Encoders::R_B_RISE(){
    detachInterrupt(1);
    R_B_SIG = 1;
    if(R_A_SIG == 1){
        RightCount++;
    }
    if(R_A_SIG == 0){
        RightCount--;
    }
    attachInterrupt(1, R_B_FALL, FALLING);
}
void Encoders::R_B_FALL(){
    detachInterrupt(1);
    R_B_SIG = 0;
    if(R_A_SIG == 0){
        RightCount++;
    }
    if(R_A_SIG == 1){
        RightCount--;
    }
    attachInterrupt(1, R_B_RISE, RISING);
}
void Encoders::L_A_RISE(){
    detachInterrupt(2);
    L_A_SIG = 1;
    if(L_B_SIG == 0){
        LeftCount++;
    }
    if(L_B_SIG == 1){
        LeftCount--;
    }
    attachInterrupt(2, L_A_FALL, FALLING);
}
void Encoders::L_A_FALL(){
    detachInterrupt(2);
    L_A_SIG = 0;
    if(L_B_SIG == 1){
        LeftCount++;
        }
    if(L_B_SIG == 0){
        LeftCount--;
        }
    attachInterrupt(2, L_A_RISE, RISING);
}
void Encoders::L_B_RISE(){
    detachInterrupt(3);
    L_B_SIG = 1;
    if(L_A_SIG == 1){
        LeftCount++;
    }
    if(L_A_SIG == 0){
        LeftCount--;
    }
    attachInterrupt(3, L_B_FALL, FALLING);
}
void Encoders::L_B_FALL(){
    detachInterrupt(3);
    L_B_SIG = 0;
    if(L_A_SIG == 0){
        LeftCount++;
    }
    if(L_A_SIG == 1){
        LeftCount--;
    }
    attachInterrupt(3, L_B_RISE, RISING);
}

When I try to compile this, I get errors like this:
C:/Users/marcel/Documents/dev/Arduino/encodeurs/Encoders.cpp:10:38: error: cannot convert 'Encoders::R_B_RISE' from type 'void (Encoders::)()' to type 'void (*)()'

I tried answers on other threads. Most said to make the functions passed to attachInterrupt() static. That threw different errors:
C:/Users/marcel/Documents/dev/Arduino/encodeurs/Encoders.cpp:16:33: error: cannot declare member function 'void Encoders::R_A_RISE()' to have static linkage [-fpermissive]

I also tried this:
attachInterrupt(0, &Encoders::R_A_RISE, this, RISING);

with no success.
The Arduino in question is a Mega but I doubt that matters.
Edit: Per Nick Gammon's answer, I now have this.
MotorEncoderMaster.ino
#include </home/marcel/dev/Arduino/encoders/MotorEncoderMaster/Encoders.h>
Encoders * Encoders::instances [2] = { NULL, NULL };

// instances of our class
Encoders right;
Encoders left;

void setup (){
    right.begin (2);   // pin D2
    left.begin (3);   // pin D3
}  // end of setup

void loop (){
    // whatever
}  // end of loop

Encoders.h:
class Encoders{
    volatile bool switchChanged;

    static Encoders * instances [2];

    static void switchPressedExt0(){
        if(Encoders::instances [0] != NULL){
            Encoders::instances [0]->switchPressed();
        }
    }

    static void switchPressedExt1 (){
        if (Encoders::instances [1] != NULL){
            Encoders::instances [1]->switchPressed();
        }
    }

    public:
        void begin (const int whichPin){
            pinMode (whichPin, INPUT_PULLUP);
            switch (whichPin){
                case 2:
                    attachInterrupt(0, switchPressedExt0, CHANGE);
                    instances [0] = this;
                    break;

                case 3:
                    attachInterrupt(1, switchPressedExt1, CHANGE);
                    instances [1] = this;
                    break;

            }
        }

        void switchPressed(){
            switchChanged = true;
        }

};

When I try to compile this, I get :
In file included from MotorEncoderMaster.ino:1:0:
/home/marcel/dev/Arduino/encoders/Encoders.h: In static member function ‘static void Encoders::switchPressedExt0()’:
/home/marcel/dev/Arduino/encoders/Encoders.h:7:34: error: ‘NULL’ was not declared in this scope
    if(Encoders::instances [0] != NULL){
                                  ^
/home/marcel/dev/Arduino/encoders/Encoders.h: In static member function ‘static void Encoders::switchPressedExt1()’:
/home/marcel/dev/Arduino/encoders/Encoders.h:13:35: error: ‘NULL’ was not declared in this scope
    if (Encoders::instances [1] != NULL){
                                   ^
/home/marcel/dev/Arduino/encoders/Encoders.h: In member function ‘void Encoders::begin(int)’:
/home/marcel/dev/Arduino/encoders/Encoders.h:21:24: error: ‘INPUT_PULLUP’ was not declared in this scope
     pinMode (whichPin, INPUT_PULLUP);
                        ^
/home/marcel/dev/Arduino/encoders/Encoders.h:21:36: error: ‘pinMode’ was not declared in this scope
     pinMode (whichPin, INPUT_PULLUP);
                                    ^
/home/marcel/dev/Arduino/encoders/Encoders.h:24:45: error: ‘CHANGE’ was not declared in this scope
       attachInterrupt(0, switchPressedExt0, CHANGE);
                                             ^
/home/marcel/dev/Arduino/encoders/Encoders.h:24:51: error: ‘attachInterrupt’ was not declared in this scope
       attachInterrupt(0, switchPressedExt0, CHANGE);
                                                   ^

Interrupt Service Routine (ISR) outside a class
Let's consider a simple use of interrupts:
volatile bool switchChanged;

void switchPressed ()
  {
  switchChanged = true;
  }  // end of switchPressed

void setup ()
  {
  pinMode (2, INPUT_PULLUP);
  attachInterrupt (0, switchPressed, CHANGE);
  }  // end of setup

void loop ()
  {
  // whatever
  }  // end of loop

That compiles fine.

ISR inside a class as a class function (method)
Now let's imagine we want to put the interrupt handling into a class for our convenience.
class myClass
  {
  volatile bool switchChanged;

  public:

  void begin ()
    {
    pinMode (2, INPUT_PULLUP);
    attachInterrupt (0, switchPressed, CHANGE);   // <--- line 10
    }  // end of myClass::begin

  void switchPressed ()
    {
    switchChanged = true;
    }  // end of myClass::switchPressed

  };  // end of class myClass

myClass foo;  // make an instance of myClass

void setup ()
  {
  foo.begin ();
  }  // end of setup

void loop ()
  {
  // whatever
  }  // end of loop

That does not compile:
ISR_in_class_test.ino: In member function ‘void myClass::begin()’:
ISR_in_class_test:10: error: argument of type ‘void (myClass::)()’ does not match ‘void (*)()’

What is going on here?
ISRs have to be static functions, taking no arguments. However (non-static) class functions have an implied this-> pointer which points to the particular instance of the class.
For example, if we have two instances:
myClass foo;
myClass bar;

If we call foo.begin() then this-> points to "foo", and if we call bar.begin then this-> points to "bar".
However an ISR, when fired by the processor, cannot know whether this-> is "foo" or "bar" or something else. Thus the compiler cannot compile that line.

ISR inside a class as a static class function
We can try to work around this by making the class function static. Doing that means that the function is not tied to any particular instance, and thus the attachInterrupt line will compile.
class myClass
  {
  volatile bool switchChanged;   // <--- line 3

  public:

  void begin ()
    {
    pinMode (2, INPUT_PULLUP);
    attachInterrupt (0, switchPressed, CHANGE);
    }  // end of myClass::begin

  static void switchPressed ()
    {
    switchChanged = true;   // <--- line 15
    }  // end of myClass::switchPressed

  };  // end of class myClass

myClass foo;  // make an instance of myClass

void setup ()
  {
  foo.begin ();
  }  // end of setup

void loop ()
  {
  // whatever
  }  // end of loop

However now we have a different problem:
ISR_in_class_test.ino: In static member function ‘static void myClass::switchPressed()’:
ISR_in_class_test:3: error: invalid use of member ‘myClass::switchChanged’ in static member function
ISR_in_class_test:15: error: from this location

A non-static class variable cannot be called from a static class function. Why? Because the compiler doesn't know which variable you want. Is it foo.switchChanged or bar.switchChanged?

ISR inside a class as a static class function with static variables
To make the static function work, it can only access static variables. So we can make switchChanged static. Plus we need to define an instance of this static variable.
class myClass
  {
  static volatile bool switchChanged;  // declare

  public:

  void begin ()
    {
    pinMode (2, INPUT_PULLUP);
    attachInterrupt (0, switchPressed, CHANGE);
    }  // end of myClass::begin

  static void switchPressed ()
    {
    switchChanged = true;
    }  // end of myClass::switchPressed

  };  // end of class myClass

volatile bool myClass::switchChanged;  // define

myClass foo;  // make an instance of myClass

void setup ()
  {
  foo.begin ();
  }  // end of setup

void loop ()
  {
  // whatever
  }  // end of loop

Now the class compiles. However we have thrown away most of the advantages of having a class in the first place, as we are forced to use a static function, and that static function can only access static variables.

Glue routines
To work around this problem we can write short "glue" routines. These are functions that interface between an ISR and an instance of a class.
class myClass
  {
  volatile bool switchChanged;

  static myClass * instances [2];

  static void switchPressedExt0 ()
    {
    if (myClass::instances [0] != NULL)
      myClass::instances [0]->switchPressed ();
    }  // end of myClass::switchPressedExt0

  static void switchPressedExt1 ()
    {
    if (myClass::instances [1] != NULL)
      myClass::instances [1]->switchPressed ();
    }  // end of myClass::switchPressedExt1

  public:

  void begin (const byte whichPin)
    {
    pinMode (whichPin, INPUT_PULLUP);
    switch (whichPin)
      {
      case 2:
        attachInterrupt (0, switchPressedExt0, CHANGE);
        instances [0] = this;
        break;

      case 3:
        attachInterrupt (1, switchPressedExt1, CHANGE);
        instances [1] = this;
        break;

      } // end of switch
    }  // end of myClass::begin

  void switchPressed ()
    {
    switchChanged = true;
    }

  };  // end of class myClass

myClass * myClass::instances [2] = { NULL, NULL };

// instances of our class
myClass foo;
myClass bar;

void setup ()
  {
  foo.begin (2);   // pin D2
  bar.begin (3);   // pin D3
  }  // end of setup

void loop ()
  {
  // whatever
  }  // end of loop

This is a bit fiddly, however what it is doing is remembering in an array which instance of the class is associated with which interrupt. The "glue" routines switchPressedExt0 and switchPressedExt1 call the appropriate instance of the switchPressed function by using the remembered class pointer.
Now the non-static function switchPressed can access non-static class variables.

Adapted from my web page Calling an ISR from a class

The whole point of this was to break my code into multiple files. When I put the class declaration in a different file and #include it, I get this error: http://pastebin.com/TkBCG74G. Is there a way to declare the class in another file and not break everything?

Of course. However not seeing your code it is hard to advise.

Code: https://bitbucket.org/MarcelRobitaille/encoders/

See my reply here Classes and objects: how many and which file types do I actually need to use them? - you don't need to include .ino files - the IDE does that for you (if they are in the same folder). Also don't call your files "main.xxx".

Rename your file Encoders.ino to be Encoders.h and include that into your main file. Rename your main file to be something other than main.ino. Then it compiles.

Still not compiling: http://pastebin.com/g2c5NQ6S

What is still not compiling? We seem to be jumping from error messages, to code. The fact is, that I got it to compile. Therefore you are doing something different from me.

Could you send me your files so I know if it's my code or my compiler? Thanks.

Rather than having me send you files (which other readers won't see) please amend your original question to show what your code is now, exactly, including file names. Then post the error message underneath, rather than having it in Pastebin somewhere.

Is that what you meant or should I remove what I used to have?

That's fine - I wasn't sure whether to suggest editing the original or not. It would have been in the edit history. Anyway, give me a minute to look at it.

Why don't you have #include "Encoders.h" - instead of that huge include statement? - Is that not in the same folder?

I changed that include line to what I suggested: #include "Encoders.h" and it compiled fine under IDE 1.6.7. Just those two files.

what do you know. It worked in 1.6.7. I had to use my windows laptop. Unfortunately I can't easily get 1.6.7 on my main pc because the linux package repo is behind. Anyway I am rambling. Thanks for all your help!

I just download the Linux package onto my Ubuntu and run from that (my test was on Ubuntu). You don't need to wait for the package to be updated.

@NickGammon: why don't you use as ISR a friend function, paired to a reference to the class instance? The reference can be a static field in the class itself. I would find it much more expressive.

@IgorStoppa - can you give an example somewhere? There are probably other ways of achieving this, but the method I showed was integrated into the class. I don't see how using a friend gets around needing to know which instance of the class the interrupt is for.

@NickGammon: I meant that the class does have a static pointer to an instance of itself. This cannot be avoided. But the friend function could be the ISR itself. It would get away with one level of indirection (you called it "the glue"). If it's not clear what I mean, where could i put a snippet of code?

Er, yes but the ISR won't know which class instance to call? You can make your own answer with your alternative example. :)

Isn't this solution the equivalent of using named static functions for every possible pin?

Yes, effectively. There is no easy workaround, except to make static functions for each pin, one way or the other.


text:
LCD 16x2 Blank Display
I am using the following wiring diagram from a tutorial.  I need to follow this configuration because later tutorials build on this example.  I have looked at other solutions, but they follow a different pattern and I am still learning, so don't have the sophistication to adapt.  I've looked at:
Hacktronics
StackExchange
The picture shows Freeduino, but I am using an Arduino Uno (does that make a difference?)

Here is the code I am using:
#include <LiquidCrystal.h>
int rs = 3;
int enable = 4;
int d4 = 5;
int d5 = 6;
int d6 = 7;
int d7 = 8;

int rows = 2;
int cols = 16;
LiquidCrystal lcd (3, 4, 5, 6, 7, 8);

void setup() {
  // put your setup code here, to run once:
  pinMode (rs, OUTPUT);
  pinMode (enable, OUTPUT);
  pinMode (d4, OUTPUT);
  pinMode (d5, OUTPUT);
  pinMode (d6, OUTPUT);
  pinMode (d7, OUTPUT);
  lcd.begin(cols, rows);
  lcd.clear();
}

void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(0,0);
  lcd.print("Hello World");
  delay(1000);
  lcd.setCursor(0,1);
  lcd.print("Goodbye World");
  delay(1000);
}

Unfortunately, I am getting a blank screen (it is lit up, but blank).  So questions:

Is the diagram correct?
Is the code the problem?
What else should I look for?

Change the contrast

Can I change the contrast in the code?  Turning the screw on the pot doesn't seem to have any effect.

Remove all the connections to the display except for power ground and contrast. Then power it on and turn the pot till you see a row of black blocks on the first line and nothing on the second line.

In my experience, contrast can mess pretty bad. I spend days to look for "why my LCD goes blank", thinking there is something wrong with my code. Turns out the characters appear when I change the contrast

1) Diagram seems to be fine. However we don't see pin numbering on LCD. Sometimes pins are like:  15 16 1 2 3 4 ... 14 (at least pin 1 is usualy marked).
2) Library should take care of inputs or outputs. So you can remove pinModes for them. Also change variables to constant variables and use them for lcd initialization: LiquidCrystal lcd(rs, enable, d4, d5, d6, d7);
3) Potentiometer in diagram is contrast setting. You have to preset correct value for it. Start with everything is black and find value where this black is almost invisible. If you've something displayed on LCD, it would be even easier to find right position as text just shows up.
Edit: I've just tested it and it's working fine. With the same wiring and contrast pot adjusted to the right position

Pins are numbered 16...1 left to right.

Check the voltage. your LCD should get 5v to work properly.
if you are powering it through your computer USB, Arduino could be outputting less than 5v.
PS: it happened to me yesterday.