text:
Drawing bitmap on TFT
So, my .ino file is like this (do not worry about TftDisplay library, it totally works fine and myDrawPixel function just calls the adafruit drawPixel function):
#include "TftDisplay.h"
#include <avr/pgmspace.h>

TftDisplay tft;

const uint8_t myBitmapBitmap [] = {
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,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0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
  0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
};

void setup() {
  Serial.begin(9600);
  Serial.print("Starting...");
  tft.init();
}

void loop() {
  mdrawBitmap(0, 0, myBitmapBitmap, 100, 146, GREEN);
  delay(2000);
  mdrawBitmap(0, 0, myBitmapBitmap, 100, 146, RED);
  delay(2000);
  mdrawBitmap(0, 0, myBitmapBitmap, 100, 146, BLUE);
  delay(2000);
}

void mdrawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
  int16_t i, j, byteWidth = (w + 7) / 8;
  uint8_t byte;
  for (j = 0; j < h; j++) {
    for (i = 0; i < w; i++) {
      if (i & 7) byte <<= 1;
      else byte   = pgm_read_byte(bitmap + j * byteWidth + i / 8);
      if (byte & 0x80) tft.myDrawPixel(x + i, y + j, color);
    }
  }
}

So, I get some really weird things on my TFT. I have no idea what is going on...
As I said, the TftDisplay library is OK, but if you really wonder here is the code:
TftDisplay.h:
#ifndef _TFTDISPLAY_h
#define _TFTDISPLAY_h

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

//#define TFT_CS     15
//#define TFT_RST    5
//#define TFT_DC     2
//#define TFT_SCLK 14
//#define TFT_MOSI 13

#define TFT_CS 26
#define TFT_RST 24
#define TFT_DC 25
#define TFT_SCLK 22
#define TFT_MOSI 23

//#define TFT_CS 10
//#define TFT_RST 8
//#define TFT_DC 9
//#define TFT_SCLK 22
//#define TFT_MOSI 23

/*#define TFT_CS   10
#define TFT_DC   9
#define TFT_RST  8
#define TFT_SCLK 13   // set these to be whatever pins you like!
#define TFT_MOSI 11*/   // set these to be whatever pins you like!

#define BLACK           0x0000
#define BLUE            0x001F
#define RED             0xF800
#define ORANGE          0xe5f442
#define GREEN           0x07E0
#define CYAN            0x07FF
#define MAGENTA         0xF81F
#define YELLOW          0xFFE0
#define WHITE           0xFFFF

/* TFT Dimensions */
#define TFTHEIGHT 160
#define TFTWIDTH 128

class TftDisplay
{
  public:
    TftDisplay();
    ~TftDisplay();

    void init();

    void setDefaultTextSize(int textSize);
    void setDefaultTextColor(uint16_t color);
    void setTextWrap(int status);

    void text(String text, int x, int y, uint16_t color, int textSize);
    void text(String text, int x, int y, uint16_t color);

    void clearPart(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
    void clearScreen();
    void myDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color);
    void myDrawPixel(uint16_t x, uint16_t y, uint16_t color);
    void myDrawRectangle(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color);
    void myDrawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color);
    uint16_t ConvertRGB( byte R, byte G, byte B);
  protected:
    Adafruit_ST7735 *tft;

    int default_textSize;
    uint16_t default_color;
};

#endif

TftDisplay.cpp:
#include "TftDisplay.h"

TftDisplay::TftDisplay()
{

  //init cannot be here as TFT must be inited in arduino setup routine otherwise
  //it crashes everything
}
TftDisplay::~TftDisplay ()
{
  delete tft;
}

void TftDisplay::init()
{

  tft = new Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
  //tft = new Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
  tft->initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  tft->fillScreen(ST7735_BLACK);
}

void TftDisplay::setDefaultTextSize(int textSize){
    default_textSize = textSize;
    tft->setTextSize(textSize);
}

void TftDisplay::setDefaultTextColor(uint16_t color){
    default_color = color;
    tft->setTextColor(color, BLACK);
}

void TftDisplay::setTextWrap(int status){
    tft->setTextWrap(status);
}

void TftDisplay::text(String text, int x, int y, uint16_t color, int textSize)
{
    tft->setCursor(x, y);
    tft->setTextColor(color, BLACK);
    tft->setTextSize(textSize);
    tft->print(text);
    setDefaultTextSize(default_textSize);
    setDefaultTextSize(default_color);
}

void TftDisplay::text(String text, int x, int y, uint16_t color)
{
  tft->setCursor(x, y);
  tft->setTextColor(color, BLACK);
  tft->print(text);
  setDefaultTextColor(default_color);
}

void TftDisplay::clearPart(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
  tft->fillRect(x, y, w, h, BLACK);
}

void TftDisplay::myDrawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t color) {
  tft->drawLine(x0, y0, x1, y1, color);
}

void TftDisplay::myDrawPixel(uint16_t x, uint16_t y, uint16_t color) {
  tft->drawPixel(x, y, color);
}

void TftDisplay::myDrawRectangle(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint16_t color) {
  tft->drawRect(x0, y0, w, h, color);
}

void TftDisplay::clearScreen(){
  tft->fillRect(0, 0, TFTWIDTH, TFTHEIGHT, BLACK);
}

void TftDisplay::myDrawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color){
  tft->drawBitmap(x, y, bitmap, w, h, color);
}

uint16_t TftDisplay::ConvertRGB( byte R, byte G, byte B)
{
  return ( ((R & 0xF8) << 8) | ((G & 0xFC) << 3) | (B >> 3) );
}

You have duplicate instances on the tftDisplay.h.
///////#define TFT_CS 26
#define TFT_RST 24
#define TFT_DC 25
#define TFT_SCLK 22
#define TFT_MOSI 23

//#define TFT_CS 10
//#define TFT_RST 8
//#define TFT_DC 9
//#define TFT_SCLK 22
//#define TFT_MOSI 23

/*#define TFT_CS   10   --->comment this correctly
#define TFT_DC   9
#define TFT_RST  8
#define TFT_SCLK 13   // set these to be whatever pins you like!
#define TFT_MOSI 11*/   // set these to be whatever pins you like!

And if you're using a Mega, it has different pins for SPI as compared to Uno.

As you can see it is commented code... And I use proper ones for Mega. I said dont worry about TftDisplay. Its ok... You are talking like you dont know what commented code is...

My bad, you should've just deleted those lines.


text:
Why can't I use just the digital pins and a ground to use a potentiometer?
First of all I am a newbie. So please excuse.
After doing the first basic project, in which I had hooked up the positive of a LED to a digital input of the Arduino and the negative to the ground of the board, I am assuming that the digital pins in Arduino are positive (are they 5v?).
So why can't the potentiometer be connected in the same way?
Thank you.

A rotary knob encoder may do the trick. It looks very much like a potentiometer, but can be read out by digital pins.

A potentiometer is an analog device, meaning it communicates its position by varying the voltage rather than sending discrete ones and zeros.
If a linear potentiometer is turned half way then the output of the pot will be at half the voltage of the input. If it is turned all the way then the output will equal the input voltage and if it is not turned at all then the output will be 0V.
In order to make sense of the potentiometer you must connect the output to the analog pins and it will give you a 10 bit number, the higher this number the closer the output voltage of the potentiometer is to 5v (or whatever you set the Analog Reference voltage to be, but don't worry about the AREF pin for now).
Digital pins are either on or off, there is no in between, so they do not work for this application
This page has an excellent potentiometer user guide: https://www.arduino.cc/en/Tutorial/Potentiometer

What does  “communicates its login” mean?

@jwpat7 It was a typo I was going for "communicate its logic" but I changed it to "communicate its position" to be more clear. I am trying to say that a digital rotary encoder would tell the Arduino how far it is turned via a digital signal (a packet of ones and zeros), whereas a potentiometer tells the Arduino its position via varying the output voltage.

I had hooked up the positive of led to a digital input of the arduino and negative to the ground of the board.

You shouldn't have done that. It damages both the LED and the Arduino.
The care and feeding of LEDs

So I am assuming that the digital pins in arduino are positive (are they 5v?).

Yes and yes (assuming a 5V Arduino).

So why cant the pot be connected in the same way?

The pot has 3 terminals, so I'm not sure what you mean by that. You are going to connect them to ground, a digital pin, and what else?

Normally you connect one end of the pot to ground, the other end to +5V, and the middle terminal to one of the analog inputs. Then when you turn the pot, the voltage at the analog input changes to be somewhere between 0V and 5V.

A potentiometer is a form of voltage divider - I suggest you read those links to understand more about them.

I am assuming that the digital pins in Arduino are positive (are they 5v?).

On a 5V Arduino, when a GPIO pin is set to OUTPUT and switched HIGH then yes, it is (almost) 5V. When switch LOW it is (almost) 0V or GND. When it is set to INPUT it is neither - it is "high impedance" and senses the voltage on the pin using a set of thresholds.
When the voltage being applied to the pin is above the high threshold (known as VIH) the pin sees it as a logic HIGH and digitalRead() reports it as such. When the voltage being applied is below the low threshold (known as VIL) the pin sees it as a logic LOW and digitalRead() reports it as such.

So why can't the potentiometer be connected in the same way?

So yes, you can connect a potentiometer up to to a digital pin in the same way as you can to an analog pin (one pin to +5V, one pin to ground, and the middle "wiper" pin to the digital input):

When you turn it, instead of reading a value between 0 and 1023 as you would on an analog pin, you will either get a HIGH or a LOW depending on how far you have turned the knob and in which direction. In the region in the middle you will read "who knows?" - that is, maybe HIGH, maybe LOW, depending on the weather and the pin itself.
Note that connecting a potentiometer up like this on a pin set to OUTPUT is dangerous (not to you, to the Arduino) and has the potential to damage the GPIO pin's internal circuitry when the pot is turned all the way one way or the other, since it creates a dead short circuit to either ground or +5V, and the GPIO pin itself, when in OUTPUT mode, is also connected internally to either ground or +5V.
Some pins on microcontrollers (not sure about the Arduino off hand) have Schmitt Trigger inputs. These avoide the "who knows?" region by toggling the input HIGH or LOW depending on when the voltage passes a threshold. For the pin to change from reporting a LOW to a HIGH the voltage has to pass above the high threshold. To then switch to reporting a LOW again it has to drop all the way down to the low threshold. Any voltage in between the two thresholds is ignored completely and the previous state is retained.

Yes, the ATmegas do have Schmitt triggers in their inputs, as stated in the datasheet.

It depends on what you are trying to accomplish.  If you set the pin as output and turn it on, then can use it as 5v power source. This is done frequently when you want the software to be able to turn some part of your system on/off.  If this is what you want, you can put a pot or any other component downstream as long as it doesn't try to draw too much power. See this post for details on that
If you are trying to read the "value" of the pot, it would work as an on/off switch because this is a digital pin. Digital means 0 or 1. When there is enough voltage, it will register as 1, once the voltage gets low enough, it will register as a zero.  If you want to read a full range of values from the pot, you would have to use an analog pin.

For connect a LED you need use a little resistor to limit the current, so you can use the potenciometer with your LED and see the bright ajust.

I had hooked up the positive of a LED to a digital input

A Arduino digital PIN as cofigurable how input or output, if you use it as input you need use this pin for read a digital value (0 or 1), example a button. When you configure the pin to output you can set the value high (~5v) or low (0v).

Analog pot on digital pin will give,
0:from min to half way and
1: from half way to end position
You can use it if this suits your program logic.

That is not correct. You might want to read up on voltage ranges for logic levels. Sparkfun offers a basic tutorial.

source: Stack Exchange

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

sort: votes


text:
Can I hook up an Analog multiplexer to Arduino Nano?
I want to increase the analogue inputs for the Nano. So is it possible to hook up a CD74HC4067 analog multiplexer to it?
Thanks.

Yes, it is. Just follow one of the myriad of tutorials that show you how, or find plenty of questions on here that deal with it.

This answer discusses that exact chip.

yes. those using IO expanders offers more flexibility.

IO expanders are for digital, not analog.

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


text:
Turning an electric vehicle
I am not sure if what I am asking is possible. I was wondering if I would be able to program my Arduino to have my car go straight until one of the wheels hits a certain amount of wheel rotations then initiating a different code within the same causing that wheel to increase that wheels speed. I have already created a code to make it go and stop in a certain amount of rotations.
/* motorshield_code
Pins Utilized
Digital 2 = encoder0APinA
Digital 3 (PWM) = MotorASpeed  //motorshield utilized
Digital 4 = encoder0PinB
Digital 8 = MotorBBrakePin // motorshield utilized
Digital 9 = MotorABrakePin // motorshiled utilized
Digital 11 = MotorBSpeedPin // motorshiled utilized
Digital 12 = MotorADirectionPin // motorshiled utilized
Digital 13 = MotorBDirectionPin // motorshiled utilized
*/

//Encoder values
const int encoder0PinA = 2;
const int encoder0PinB = 4;
const int encoder1PinA = 7;
const int encoder1PinB = 6;
int encoder1Pos = 0;
int encoder0Pos = 0;
int encoder0PinALast = LOW;
int encoder1PinALast = LOW;
int n = LOW;
int i = 0;

//Motorshield Pin Values
const int MotorADirectionPin = 12; //digital pin value for A direction
const int MotorASpeedPin = 3; //analog pin value for A speed (PWM)
const int MotorABrakePin = 9; // digital pin value for A brake
const int MotorBDirectionPin = 13; //digital pin value for A direction
const int MotorBSpeedPin = 11; //analog pin value for A speed (PWM)
const int MotorBBrakePin = 8; // digital pin value for A brake
//Motor Control Values
int BrakeA = LOW; //Brake for motor A, LOW = motor off, HIGH = motor on
int BrakeB = LOW;
int DirectionA = HIGH; //Direction for motor A, LOW/HIGH are opposite (based on wiring) assume Low is forward
int DirectionB = LOW;
int SpeedA = 0; //Speed for motor A, PWM value from 0 - 255 (0 is off)
int SpeedB = 0;
int encoder0stop = 469.125; //stop value for encoder 0
int encoder1stop = 469.125; //stop value for encoder 1

void setup() {
  //Set Digital I/O pins 2 and 4 to inputs for encoder
  pinMode (encoder0PinA, INPUT);
  pinMode (encoder0PinB, INPUT);
  pinMode (encoder1PinA, INPUT);
  pinMode (encoder1PinB, INPUT);
  //Set Digital I/O pins as outputs for motorshield
  //Analog pins are already set so don't have to initialize speed pins
  pinMode(MotorADirectionPin, OUTPUT);
  pinMode(MotorABrakePin, OUTPUT);
  pinMode(MotorBDirectionPin, OUTPUT);
  pinMode(MotorBBrakePin, OUTPUT);
  //Start serial monitor at 9600
  Serial.begin (9600);
  delay (0);
  Serial.print("Last Enc State");
  Serial.print(" ");
  Serial.print("Current Enc State");
  Serial.print(" ");
  Serial.print("Encoder Count");
  Serial.print(" ");
  Serial.print("Speed");
  Serial.print(" ");
  Serial.print("Brake");
  Serial.print(" ");
  Serial.print("Direction");
  delay(2000);
}

void loop() {
  if (i == 0) {
    analogWrite(MotorASpeedPin, 255); //set motor A speed
    analogWrite(MotorBSpeedPin, 255); //set motor B speed
    i++;
  }
  //Set values to write to arduino
  if (encoder0Pos < encoder0stop) {
    //if hasn't reached end encoder value
    //Direction Forward, Brake OFF, speed 125
    DirectionA = HIGH;
    DirectionB = LOW;
    BrakeA = LOW;
    BrakeB = LOW;
    SpeedA = 254;
    SpeedB = 253;
  } else {
    //if has reached encoder value
    //Direction Forward, Brake ON, speed 0
    DirectionA = HIGH;
    DirectionB = LOW;
    BrakeA = HIGH;
    BrakeB = HIGH;
    SpeedA = LOW;
    SpeedB = LOW;
  }

  //Write all values to the arduino
  digitalWrite(MotorADirectionPin, DirectionA); //set motor A direction
  digitalWrite(MotorBDirectionPin, DirectionB); //set motor B direction
  digitalWrite(MotorABrakePin, BrakeA); //write motor A brake on/off
  digitalWrite(MotorBBrakePin, BrakeB); // write motor B brake on/off
  analogWrite(MotorASpeedPin, SpeedA); //set motor A speed
  analogWrite(MotorBSpeedPin, SpeedB); //set motor B speed
  //Read Encoder
  //This is reading PinA which should be set to pin 2 and storing it as n
  n = digitalRead(encoder0PinA);
  //Check to see if pin 2 has changed from LOW to HIGH
  if ((encoder0PinALast == LOW) && (n == HIGH)) {
    //Check to see if pin 4 is LOW -> this determines which direction the encoder is going
    if (digitalRead(encoder0PinB) == LOW) {
      //encoder is going "backwards" decrease encoder position
      encoder0Pos--;
    } else {
      //If pin 4 is HIGH
      //encoder is going "forward", increase encoder position
      encoder0Pos++;
    }
    //Tell us what is happening!
    Serial.print (encoder0Pos);
    //go to the next line of code
    Serial.print(" ");
    Serial.print(encoder0PinALast);
    Serial.print(" ");
    Serial.print(n);
    Serial.print(" ");
    Serial.print(encoder0Pos);
    Serial.print(" ");
    Serial.print(SpeedA);
    Serial.print(" ");
    Serial.print(BrakeA);
    Serial.print(" ");
    Serial.print(DirectionA);
    Serial.println();
    encoder0PinALast = n;
  }
  //Set what the last read of pin 2 was so we can compare to see if it changes
  encoder0PinALast = n;
  //End Code for Encoder Reading
}

If your car is capable of having one wheel change speed, and your Arduino is capable of controlling the speed of that wheel, then of course it is possible. You just have to work out how to program it.

And can you make it run at different speeds? You don't give us any details about what you have - what type of motor etc - so it's hard to know what your setup can do.

yes I can make the motors run at different speeds. the motors are also DC motors and I'm using c++ coding I can also put a picture of the coding I already have

I would say that one of the solutions would be to arrange the code in your car into a finite state machine. So your states would be something like:

Start (reset the encoders and set the initial speed)
Go straight (both motors at 100%)
Turn left (left motor at 75%, right at 100%)
Turn right (right motor at 75%, left az 100%)
Stop (stop both motors)

Example code:
//TODO: Init program and variables
void go_straight()
{
    if(number_of_rotations > 10)
    {
        state = TURN_LEFT
    }
    else
    {
        motor_left = 100;
        motor_right = 100;
    }
}
void turn_left()
{
    if(number_of_rotations > 10)
    {
        state = TURN_RIGHT
    }
    else
    {
        motor_left = 100;
        motor_right = 75;
    }
}
//TODO: Implement remaining methods

void loop()
{
    //Update number of rotations since state change
    update_rotations();
    if(state == START)
        start();
    else if(state == GO_STRAIGHT)
        go_straight();
    else if(state == TURN_LEFT)
        turn_left();
    else if(state == TURN_RIGHT)
        turn_right();
    else
        stop();
    //This code gets executed on every loop cycle and is not dependent on state
    print_status();
    wait(100);
}

is there any way to program it with the code I already have and without rewiring my Electric Vehicle?

Why do you think you would have to rewire your vehicle? My answer was abstracted in a way that it is not dependent on the actual hardware.

You never reset the number of rotations, so it will go from straight, "directly" to turn_right.


text:
How to send command from coordinator to router in Xbee?
I am using an XBee-PRO S2b module. I have sent data from the router Xbee to the coordinator Xbee.
Now I want to send a command packet from the coordinator to the router Xbee to set a pin high.
My coordinator is in API mode and the router is in AT mode.
Can anyone say how to do that?

In order to change the router from the coordinator, you have to create a function that run in a microcontroller that is connected to the coordinator.You can refer to this link , https://www.youtube.com/watch?v=CzH146rR-7I&t=236s

it is using xbee s2 but i think it works under the same protocol.


text:
Detect a non-human moving object
I would like to design a system in which I am able to make a light flash when a motion sensor detects a movement of a non human object such as a car.
(The goal here being that when a car is moving behind me in my blind spot around the corner of a wall in my parking spot I don't back into it.)
I have looked into a few tutorials using arduinos to detect this motion but so far I have only read about the PIR (which only detects humans and animals).
http://www.instructables.com/id/DIY-Arduino-Motion-Sensor-Lighting-Control/?ALLSTEPS
What sensor would be best for this situation or do I need to rethink my system?
(I have no intention of harming anyone or anything :) )

Do you mean that you're trying to detect a moving car, or are YOU the moving object and you're trying to detect a static object that just happens to be a car? If it's the former, would a hot engine not trigger a PIR sensor?

Why the restriction on non-human, exactly? Is it OK if you back into a human? If so, why? If you want something that senses the difference between a moving inanimate object (like a car) and a human, then surely such a detection system would also detect things like dogs and cats. Unless you are going to Google for a "human detector" it seems to me that any sort of distance detector would do. Surely you don't want to reverse into anything, alive or not.

I would try the PIR sensor before writing it off.  It detects changes in infrared radiation from an initial baseline that it reads, so whenever the ambient heat that it sees changes by some threshold, it notifies you.  They might be sensitive enough to see a car coming through, as suggested by others.
A more robust solution could be the ultrasonic proximity sensor, like Majenko mentioned.  Here's one as a starting point: ultrasonic distance sensor.  This will be best if you know that the car will be passing in front of where you point the sensor.  If it's hard to point the sensor to a point where you're sure the car will be coming through, then that's where a PIR would have advantages, as it "sees" a wider area.

If your car is moving at the time, then relative to your car everything is moving.
Automotive companies have spent billions of dollars working on this problem.  There is no "sensor" that can differentiate one moving object from a background that is also moving.
All existing automotive systems that perform this task use cameras and computers, with software such as OpenCV.  This is not something that any Arduino could even come close to doing.
The closest you could get is "is there something in this area that is within a certain distance of me" which you may be able to do with an ultrasound "Ping" sensor.  It won't differentiate between a moving car or a bollard or a child or just the wall you are reversing towards.

I hate to be the wet blanket here but maybe the job is too simple for this much technology. Wouldn't a suitably placed curved mirror give you the information you need?
Or put a PIR sensor around the corner where it can see the car, and put the flashing light where you can see it while backing.

I am not sure why no one has suggested a Microwave Doppler sensor. I am not sure how it would work in an outdoor environment but it is designed to detect motion regardless of whether it is a human. This link has some information about using a cheap Microwave sensor with an Arduino.

You can use the servo motor to rotate the ultrasonic sensor 180°:

In the setup() function of your code, store the distance for every 180° in an array;
In the loop() function, read the distance of each degree and compare with the one in the array.

If the value changes that means that the object has been moved

I would use an ultrasonic distance sensor. They are quite accurate, and are common to use for this kind of problem. You will get all kinds of noise in your data, from all the different surfaces that the ultrasonic sound will bounce off from.
Another option would be infrared distance sensor. Make sure you find one with a long enough range, because the 'usual' one used with arduino examples goes to about 30cm. They are less precise, but very easy to use with arduino. And if I remember correctly they have less problems of getting interference if you have a bunch of them together.
Pir sensors are made to detect the difference in infrared heat coming off a human skin (comparing to when the person is not there). So I would not recommend that.

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


text:
Disabling i2c internal pull up resistors
How do you do this? I've been digging around and I can see that I should do this and supply my own external pull up resistors but I don't know exactly how to disable them. The pages I've been reading never explicity state how.
I'm trying to enable I2C between a leonardo and an uno, but I think the i2c bus is slowing down considerably because of the internal pullups. I want to switch to two 4.7k resistors but I can't figure out how to disable the internal ones. I know that the Wire library enables the internals by default, but how do I edit the library or disable the pullups in my sketch?
Maybe I just haven't been reading the right forums or articles, but if anyone could point me in the right direction that would be much appreciated.
EDIT: So the problem is probably with my setup or code, I'll put it down here. Everything I have before setup is importing libraries and variables like my mac, ip, placeholders for output, pwm, etc.
Master:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial){
  }

  Wire.begin();

  Ethernet.begin(mac, ip);
  delay(1000);

  server.begin();
  if(server.available()){
    Serial.println("Client Available");
  }
}

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

  ethernetwrite();

}

void ethernetwrite() {
  EthernetClient client = server.available();
  while(client) {
    if(client.find("P")) {
      output = client.parseInt();
      pwm = client.parseInt();

      Serial.println("Begin Transmitting");
      Wire.beginTransmission(14);
      Wire.write(output);
      Wire.write('\t');
      Wire.write(pwm);
      Wire.endTransmission();
      Serial.println("Done Transmitting");

      Serial.print(output);
      Serial.print('\t');
      Serial.println(pwm);

    }
  }
}

Slave:
void setup() {
  Wire.begin(14);
  Wire.onReceive(wirewrite);

// *   - Base frequencies:
// *      o The base frequency for pins 3, 9, 10, and 11 is 31250 Hz.
// *      o The base frequency for pins 5 and 6 is 62500 Hz.
// *   - Divisors:
// *      o The divisors available on pins 5, 6, 9 and 10 are: 1, 8, 64,
// *        256, and 1024.
// *      o The divisors available p1on pins 3 and 11 are: 1, 8, 32, 64,
// *        128, 256, and 1024.

    // Leg 1
    pinMode(leg[1], OUTPUT); setPwmFrequency(leg[1],8); analogWrite(leg[1], offset);

    // Leg 2
    pinMode(leg[2], OUTPUT); setPwmFrequency(leg[2],8); analogWrite(leg[2], offset);

    // Leg 3
    pinMode(leg[3], OUTPUT); setPwmFrequency(leg[3],8); analogWrite(leg[3], offset);

    // Leg 4
    pinMode(leg[4], OUTPUT); setPwmFrequency(leg[4],8); analogWrite(leg[4], offset);

    // Mirror
    pinMode(leg[0], OUTPUT); setPwmFrequency(leg[0],clkdivisor); analogWrite(leg[0], 255);
}

void loop() {

    int time = 10;
    time = time*128/clkdivisor;

    // box(time, 255, 1); // box(delay time, radius pwm, pwm step size);
    // autodisplay();
    updateL();

}

void updateL(){
  if (output == 0) pwm = 255 - pwm;
  switch (output) {
    case 1: pin =  3; break;
    case 2: pin =  9; break;
    case 3: pin =  10; break;
    case 4: pin =  11; break;
    case 0: pin = 5; break;
  }
  //if (output < 5) {
    analogWrite(pin, pwm);
  //}
}

void wirewrite(int numBytes) {
  String message;
  while(Wire.available()>0) {
    char c = Wire.read();
    message.concat(c);
  }
  output = Wire.parseInt();
  pwm = Wire.parseInt();
}

When I send data to the master, on the serial monitor it freezes in the first wiring transmission or in the next few, and my slave doesn't seem to respond to the message being sent over i2c. My controls for my device and setup worked prior to my attempts with the Wire library, so there's no problem there.
EDIT: I also am sending a message that looks like this:
"P1 103"
every .4 seconds or so, but I usually can't get past the first transmission between the arduinos

Why bother to disable the internals?  Say the internal is 50K - leaving it enabled and adding the 4k7 would end up with an equivalent of 4.2962K

I think the i2c bus is slowing down considerably because of the internal pullups; I2C is clocked, so it's speed is not dependent on the external resistor. You have to set the I2C clock to a higher frequency, if you want more speed.

Just out of curiosity, why do you want do (disable the resistors)? I think the i2c bus is slowing down considerably because of the internal pullups - no, it isn't. if anyone could point me in the right direction that would be much appreciated - if you could post your code that would be much appreciated.

My bad then, I was misinformed or just misinterpreted what I was reading. I was trying to read up on i2c for a project I'm working on and I'd been seeing a lot of disabling of the internal pullup resistors for people's projects involving i2c, sorry for the ignorance

From the datasheet:

Note that the internal pull-ups in the AVR pads can be enabled by setting the PORT bits corresponding to the SCL and SDA pins, as explained in the I/O Port section.

To disable the internal pull-ups:
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);

or
digitalWrite(2, LOW);
digitalWrite(3, LOW);

It looks like SDA and SCL are constants, so safest would be to do a digitalWrite(SDA, LOW); digitalWrite(SCL, LOW); to avoid worrying about which pin they are on which board.

Just to clarify, as the quote from the datasheet talks about enabling the pullups: These commands disable the pullups.

Let's go back to basics. A low-value pull-up resistor actually improves the shape of the I2C clock and data.

One internal pull-up:

Both ends with the internal pull-up:

10 k external pull-up:

4.7 k external pull-up:

2.2 k external pull-up:

As Majenko pointed out, leaving the internal pull-ups enabled would give you a pull-up between 4.7 k and 2.2 k. And as my screenshots show, that is perfectly acceptable.
In fact, it is probably better. See the nice square signals?

So your hypothesis that the pull-up is responsible for it running slowly is not supported.
You need to post your code, and other details, such as the length of the cable runs.

I think the i2c bus is slowing down considerably ...

What do you mean "slowing down"? Compared to what? What are your figures? What is the transmission time? What do you expect it to be? Some facts please.

Reference
My page about I2C


text:
Arduino Web Server and Relay Module
I am working on a web server project for work. I have a web server setup with an Arduino Meg2560 with Ethernet. I also have a 16 relay board connected to Ethernet with its own IP. I wanted to see if there is a way I can make calls to the relay board via IP from the Arduino Webserver. For example Relay 1 on the relay board can be turned on by typing 192.168.1.4/30000/00 but this opens the web GUI on the board. I need to do the same thing but without opening the webpage or web GUI.

    #include <SPI.h>
    #include <Ethernet.h>

    // MAC address from Ethernet shield sticker under board
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    IPAddress ip(192, 168, 1, 177); // IP address
    EthernetServer server(80);  // Server Port 80

    void setup()
    {
      Ethernet.begin(mac, ip);
      server.begin();
    }

    void loop()
{
EthernetClient client = server.available();  // try to get client

if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
        if (client.available()) {   // client data available to read
            char c = client.read(); // read 1 byte (character) from client
            // last line of client request is blank and ends with \n
            // respond to client only after last line received
            if (c == '\n' && currentLineIsBlank) {
                // send a standard http response header
                client.println("HTTP/1.1 200 OK");
                client.println("Content-Type: text/html");
                client.println("Connection: close");
                client.println();
                // send web page
                client.println("<!DOCTYPE html>");
                client.println("");
                client.println("");
                client.println("<title>Arduino Web Page</title>");
                client.println("");
                client.println("");
                client.println("
Hello from Arduino!
");
                client.println("
A web page from the Arduino server
");
                client.println("");
                client.println("");
                break;
            }
            // every line of text received from the client ends with \r\n
            if (c == '\n') {
                // last character on line of received text
                // starting new line with next character read
                currentLineIsBlank = true;
            }
            else if (c != '\r') {
                // a text character was received from client
                currentLineIsBlank = false;
            }
        } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
} // end if (client)

}

I have my web server working and ready to go on my Arduino I just need help adding code to it for calling my relay board. Thank you

Which model of relay board is this? I don't see any need for server in arduino as you already have one in the relay module.

So what if it "opens a GUI" when you send a GET request to that URL.  That doesn't mean you have to DO anything with that GUI data - you can just ignore it completely.  Just send the GET request then close the connection.

Documentation on the controller you are using is pretty scant, but it looks like you just need to make a GET request to the URI corresponding to the action you need to take.

http://192.168.1.4/30000/00 : Relay-01 OFF
http://192.168.1.4/30000/01 : Relay-01 ON
http://192.168.1.4/30000/02 : Relay-02 OFF
http://192.168.1.4/30000/03 : Relay-02 ON
http://192.168.1.4/30000/04 : Relay-03 OFF
http://192.168.1.4/30000/05 : Relay-03 ON
…
http://192.168.1.4/30000/14 : Relay-8 OFF
http://192.168.1.4/30000/15 : Relay-8 ON
http://192.168.1.4/30000/41 : Enter
http://192.168.1.4/30000/40 : Exit
http://192.168.1.4/30000/42 : Next Page
http://192.168.1.4/30000/43 : Next Page

For example If I wanted to turn off relay 3, I would simple make a GET request to http://192.168.1.4/30000/04 and close the connection. Example code:
IPAddress server(192,168,1,4);
EthernetClient client;
client.connect(server, 80);
client.println("GET /30000/04 HTTP/1.1");
client.println("Connection: close");
client.println();
client.stop();

How do I add that to the Arduino web server I think that is exacly what I am needing to add I would like to just have a link for now say Relay 1 On and it do the Get /30000/01 to turn it on. I added my web server Sketch to the main question. Thank you

Thank you Jake I was able to get the GET code to work. I am new to the Arduino so it took me awhile to figure out what the code is doing.


text:
ble_write slows down my sketch causing problems (Blend Micro & NRF8001)
I'm working on a prototype which uses the RedBearLabs Blend Micro with the NSC's nrf8001 ble chip, but have ran into a problem that I'm not sure how to solve.
I have two tactile buttons connected to the input pins on the Blend Micro, which are used to increase or decrease counters (integers) in my sketch that is in turn displayed on a OLED screen. When I use these buttons to manipulate the counter in offline mode (meaning that the bluetooth is not connected) I can repeatedly press the buttons very quickly and the counter is increased with every push - but when I connect to my phone and try to push the buttons with high frequency (>1-2 per second) the program is not able to react to every button interaction, causing only every second or third click to be registered.
The only thing that I do differently when I am connected is that I'm sending 5 bytes using "ble_write" (part of the RBL nrf8001 library), which seem to cause this delay resulting in missed clicks. Even sending one byte using "ble_write(X)" seem to slow down the sketch so much that this phenomena occurs.
Do any of you had similar problems and possible ways to solve this? I've been considering batching clicks together until I reach a certain amount and then send them at all once - this however may risk that a button is being pressed at the same time as the ble_write is executed, causing missed click.
Offline click looks like this:
if(digitalRead(A4)) {
while (digitalRead(A4)) {        }
offlineIn++;
localIn++;
totCount++;
sleepTimer = 0;
  }

And the online like this:
if (digitalRead(A4)) {
  while (digitalRead(A4)) {        }
  totCount++;
  localIn++;
  sleepTimer = 0;
  ble_write('0');
  ble_write('0');
  ble_write('0');
  ble_write('1');
  ble_write('1');
}

Thanks!

I've solved it by overclocking my blend micro to 16mhz (done in the Arduino IDE). Not a perfect solution but works. :)

This is a bad solution.  Likely what you have accomplished is to halve delays intentionally put there to properly operate the BLE.  If that works, then you should just be using half delays.

Good point. If I would optimise this I would probably need to look into the libraries used in more detail, but since this actually worked - I'm fine with the results.


text:
Sensor for detect there is a car or not ?
please I'm aiming to do a project for parking system but first of thing I need a sensor to detect there is a car or not other than ultrasonic sensor ..
please any one know any kind of those sensors ? pressure sensor or normal sensor ?

Use an inductive loop, like they use in front of traffic lights. Photo-reflector would be another option. Could you expand on your requirements? Is it placed outside? Could you mount a sensor on a ceiling (to prevent dirt from interfering)? Can it be placed in front of the car?  Why can't you use a ultrasonic sensor?

When I Googled car detection sensor -ultrasonic I got 8.4 million hits. Are you looking for something other than what that search found?

Ideas and concepts you could use:
1 - Laser tripwire - acts like a laser security system. If the beam is broken, then you car is there. Put a laser on one side of your garage and a photocell and the other and read its value.
2 - photocell under the car - if the area is always lit, you might be able to put a photocell below the parking spot. Then when your car is on the photocell, it return a different value then when there is nothing.
3 - pressure/weight sensor - both will detect the presence of a heavy object on them.
Hope those ideas hepled you!

thank you for your answer but please can you explain to me the second one (photocell under the car) I did not understand :)

a photocell is a variable resistor, it calculates the intensity off light. If you were in a lit area, lets say the sensor reads 500. then when the car is on the sensor, it will drop to something like 70.

can you give me a link for pressure/weight sensor or picture please :)

https://www.adafruit.com/product/1893

https://www.adafruit.com/products/166


text:
Using 2 piezo buzzers to emit the same tone with phase difference
For a physics project, I want to record the effect of 2 speakers emitting 100hz at different phase differences. Trouble is, the Arduino can only send one tone() signal at a time. How do I create a phase difference effect using one Arduino?

Hint: Start by understanding how tone() works.

For a very simple example you can do something like this:
#define SPEAKER1_PIN    5
#define SPEAKER2_PIN    6

void setup() {
  pinMode(SPEAKER1_PIN, OUTPUT);
  pinMode(SPEAKER2_PIN, OUTPUT);
}

void loop() {
  int phase_delay = 1000;   // Phase delay (in us)
  int freq_delay = 5000;    // Half of square wave at 100Hz (5000us)

  // Generate 2 square waves (out of phase)
  while(1) {
    digitalWrite(SPEAKER1_PIN, HIGH);
    delayMicroseconds(phase_delay);
    digitalWrite(SPEAKER2_PIN, HIGH);
    delayMicroseconds(freq_delay - phase_delay);
    digitalWrite(SPEAKER1_PIN, LOW);
    delayMicroseconds(phase_delay);
    digitalWrite(SPEAKER2_PIN, LOW);
    delayMicroseconds(freq_delay - phase_delay);
    }
}

By the way, 100Hz may be to low of a frequency to get much sound out of a Piezo speaker.  You'll likely have better success by using higher frequencies.

Since the frequency is so low, you can generate the signals in software.
That would not be as clean as timer-generated signals, but it will be
much easier. And probably clean enough for the intended purpose.
In order to generate a tone, you have to repeatedly switch the pin
connected to the piezo. This is very similar to blinking an LED, only
somewhat faster. Blinking an LED is the very first thing you learn to do
with an Arduino, but you may notice that blinking two LEDs is a
little bit trickier. The problem – and the solution – is
discussed in the Arduino tutorial Blink Without Delay. Building on
that tutorial, here is an example program that generates two 100 Hz
signals in quadrature:
const uint8_t PIN_A = 8;
const uint8_t PIN_B = 9;
const uint32_t HALF_PERIOD = 5000;  // 5000 us
const float PHASE_SHIFT = 0.25;     // 1/4 period

uint8_t state_A = LOW;
uint8_t state_B = LOW;

uint32_t last_A_toggle = 0;
uint32_t last_B_toggle = - 2 * HALF_PERIOD * PHASE_SHIFT;

void setup() {
    pinMode(PIN_A, OUTPUT);
    pinMode(PIN_B, OUTPUT);
}

void loop() {
    uint32_t now = micros();
    if (now - last_A_toggle >= HALF_PERIOD) {
        last_A_toggle += HALF_PERIOD;
        state_A = !state_A;
        digitalWrite(PIN_A, state_A);
    }
    if (now - last_B_toggle >= HALF_PERIOD) {
        last_B_toggle += HALF_PERIOD;
        state_B = !state_B;
        digitalWrite(PIN_B, state_B);
    }
}

If you compare this with the above mentioned tutorial, there are a
couple of differences worth noticing:

The timings are measured using microseconds rather than milliseconds,
for getting a better accuracy
The variables holding the times of last toggle are updated like
last_A_toggle += HALF_PERIOD rather than last_A_toggle = now (the
equivalent of previousMillis = currentMillis). This is needed to
keep an accurate average frequency. Otherwise the time taken to
execute the code would make the frequency slightly off.

There is a little trickery in the initialization of last_B_toggle,
which is an unsigned number initialized to a negative value. The
initialization is valid and works modulo 232. Using a small
positive value would have the ill effect of now - last_B_toggle
overflowing to a very large positive number on the first run of
loop(), putting last_B_toggle effectively in the distant past.

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


text:
How can i read and write the data from a Delta plc-s series through Arduino UNO?
I am trying to communicate PLC with arduino through rs232 as well rs 485. But, I am not able to read and write data. I can observe the data in PLC through ladder logic but not in arduino. I am trying to implement the Modbus ASCII here but reading and writing both is not happening.
#include <EmSevenSegment.h>
#include<SoftwareSerial.h>

EmSevenSegment disp(4, 'C', 4, 3, 2);
SoftwareSerial debuggingSerial(0, 1); //RX,TX

[![enter image description here][1]][1]String readlineString = "";
String integerString = "";
String decimalString = "";
String outputString = "";
char startChar = 0x01;
char endChar = 0x01;
//char weight[10];

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

}

void loop() {
  Serial.print("!!!!!!!!!!11111111111\n");
  delay(1000);
  if (debuggingSerial.available())
  {
    Serial.print("!!!!!!!!!!2222222222\n");
    readlineString = debuggingSerial.readString();
    Serial.print(readlineString);
  }

  if (readlineString.length() > 0)
  {
    Serial.print("!!!!!!!!!!333333333333\n");
    integerString = readlineString.substring(10, 12);
    decimalString = readlineString.substring(13, 15);
    int number = (integerString + decimalString).toInt(); // 6789; //Number to be displayed
    disp.print(number); // Print the number
    Serial.print(readlineString);
    readlineString = "";
  }

}

Please find the image of rs232 connection:

Hi, please check the query once again. It is attached now. It is below arduino code.

what are the rs232 signal names of the pins that you connected?

the signal name are Rx(brown wire) and Tx(beside brown wire) and last pin is GND.

that describes three pins .... the picture shows three wires ... that is six pins .... please answer the question again

I am trying to read and write only. I don't think so, we need all the pins for reading and writing using modbus protocol.

You cannot use software serial on pin D0 and D1. Those two pins are for hardware serial (i.e. for your Serial.println())

it means that I can not read and write the value through these two pins


text:
Arduino Uno & Simulink - high frequency pulses
I'm trying to control a large stepper motor with high frequency pulses (eventually around 4kHz), but what I get out of the simulink scope is super different from what the Arduino is putting out. I'm using this variable frequency PWM block: www.mathworks.com/matlabcentral/fileexchange/48563-variable-frequency-pwm-block

(yes, I've tried it on pin 5/6, but if I do that there's no difference)
This is the output from the Simulink scope (period of 0.01s):
and the Arduino is putting out pulses with a period of ~4 seconds. This is on pin 6 of the Uno, by the way. Why won't the Arduino output the same frequency as the Simulink program?

Please amend your question and post the Arduino code. How can we tell what it might be doing without seeing the code? What did you get out of the Simulink scope?

I've added the simulink program (didn't use Arduino code)

Why won't the Arduino output the same frequency as the Simulink program - I don't understand your question. You are asking why the Arduino won't output a certain frequency, but you are not using Arduino code? Well, without code it won't output anything. Perhaps if you clarify.

It is outputting something, because I'm using a physical oscilloscope to measure the output (and my stepper motor is moving, just really slowly). Not 100% sure how it works, but I think Simulink uploads code to the Arduino because the Arduino gives the same pattern of blinking light as it does when Arduino code is uploaded. If you've done this before, do you need to use Arduino code too?

No I haven't used Simulink. I gather from your answers and my research just now, that Simulink is supposed to generate code from your block diagram above and upload that to the Arduino, is that correct?

This is on pin 6 of the Uno, by the way. - you have pin 11 on your Simulink block diagram.

Yes, Simulink generates code from my block diagram. And I've been switching between pins 11 and 6, so the pictures aren't consistent, but the output is the same :(

It seems clear from what you have described that this is a Simulink bug.

Why won't the Arduino output the same frequency as the Simulink program?

The Arduino can output quite a lot of frequencies. I have a page about Arduino timers which describes them in some detail.
However since Simulink is generating the code for the Arduino (which we are not being shown) and since it claims to be generating 0.01 s, and the code it is generating does not do this, that is a bug in Simulink.
I suggest you contact their customer support.
Alternatively you could attempt to program the hardware timers yourself. The page I linked could be a good starting point for such an exercise.


text:
What does []() argument in function mean?
I am working in ESP8266 AsyncWebserver library and have been using this [](parameter) as an argument to some functions as shown below but does not really know what it means. Being a neophyte I am curious to know what does this convention means, its functionalities and how to use it. Hopefully experts here would help me with this.

server.on("/page",HTTP_GET,[](AsyncWebServerRequest * request){
    some code....;
    request->getParam("Param1")->value();
});

That is called a lambda expression and it's a way of including the content of a function as a parameter anonymously instead of writing an actual function and using the name of it.
It's shorthand for:
void myCallback(AsyncWebServerRequest * request) {
    // some code....;
    request->getParam("Param1")->value();
}

// ...

server.on("/page", HTTP_GET, myCallback);

It does have a few benefits over traditional functions at the expense of readability, such as the ability to "capture" local variables from the surrounding scope.

Thanks Mr.@Majenko, I will look further about this topic. So in the above example instead of creating a new function as a callback they used lambda function on the go to use locally within the function scope itself Am I right. Im just curious to know  can we use the variables declared in server.on function inside the lambda

All is explained in the link. But any variable that is defined within the function that server.on appears in can be "captured" by placing it between the [...], so you can then use it from within the lambda expression itself.

Thanks Mr.@Majenko thats useful

More generally, the lambda is actually shorthand for a class declaration somewhere in the enclosing scope, struct unnamed_lambda_helper { /* captured local variables are data members of this class */ auto operator()(/* arguments here */) -> /* return type here, if specified */ { /* body here */ } };, and then the expression creates an instance of this class.

Is it C++ only?

@PeterMortensen It is a C++11 feature (meaning older compilers may not support it).  Of course, other languages do have their own version of this.  To the best of my knowledge, C does not.

Thanks @CortAmmon


text:
How to convert four uint16_t to double float IEEE754?
I am working in a Modbus project where I have to read modbus Holding and Input registers using ESP8266, I am using ModbusMaster232 library. I returns a response buffer array of uint16_t. I need to convert the uint16_t to double precision float. A quick test in ESP8266 shows double datatype in ESP8266 stores 8 bytes.Does anybody know how to convert four uint16_t to double in Arduino. If so please share your knowledge.

Here's a code fragment for converting a uint16_t. Expand this to work with your array of ints from the library.
Remember that on Arduino, - Uno and Mega, at least - doubles are implemented as floats. You won't get the precision you might be expecting.
double xAsDouble;    // ** only float precision despite 'double' declaration
uint16_t xAsInt;

xDouble = xInt;      // the compiler knows how to make this conversion.

Update: After re-reading your question, I realize you're using an ESP8266. My comments about Uno's float precision may not apply.
Update 2: After some discussion, I've learned that the Modbus return is not 4 integers, but a double being passed as 4 words, which need to be reassembled to recreate the original double. The solution will depend on the order in which the words comprising the original double are sent.
Update 3: I suggested the OP try using this general scheme:
// A union lets you look at memory as either (in this case) 4 ints or 1 double
union {
   uint16_t data_out[4];
   double x;
} buffer;

// Assign the data from modbus using the 'int' way of viewing menmory.
// Note I might have the ordering wrong but this is the idea:
buffer.data_out[i] = data_in[i];

Then reading 'buffer.x' would get the 4 words of memory as a double.
... After trying both orderings, the OP reports he is obtaining the expected result,

Thanks for reply @JRobert but I am using uint16_t array with 4 elements not a single uint16_t variable, I have to group this four 16 bit containers to a single 64 bit container representing IEEE754 float variable. Could you elaborate how the code would do that

Do you understand how to use a for() loop to execute one or more statements over the members (items) in an array?

Do you mean
uint16_t data_in={2121,1233,3435,2433}; double data_out=0; for(int i=0; i<4;i++) { data_out = data_out | data_in[i]<<16; }

Yes - please see my edited comment above. You would do the same as in my example, but using [i] to address each of the ints and floats.

Is that code correct @JRobert ?

Take out the left shift - all you need is a simple assignment. The compiler knows from your declarations that 'data_out' is double and 'data_in' is uint_16, and how to assign one to the other, including the proper conversion.

Will try as you said in my ESP8266 board and revert back @JRobert

As I expected I am getting the value of last element in array with decimal @JRobert

Let us continue this discussion in chat.


text:
Uno Ethernet shield and TMP36 reading
I am just getting started with my Uno via the Vilros Ultimate Starter Kit. I've done all of the sample circuits and played around with a few other things.
Today I connected the Ethernet shield with the intention of building a temperature logger. I am finding that the output I get from the included TMP36 temperature sensor is much different with the Ethernet shield installed.
The kit's sample circuit #7 for the temperature sensor connects the sensor directly to 5V and GND and the sensor output to A0. The loop code (compressed a bit for pasting here) looks like this:

float voltage, degreesC, degreesF;
voltage = analogRead(temperaturePin) * 0.004882814;
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC * (9.0/5.0) + 32.0;
// Write to serial; omitting for brevity
delay(1000);

Without the Ethernet shield installed, a typical output I get from this looks like:
voltage: 0.81  deg C: 30.57  deg F: 87.02

That might be a little high but it feels close enough for what I'm going for at the moment (I don't have a reliable thermometer with me, but it's a warm day here). It's close enough, and is stable across readings.
With the shield installed, the exact same circuit and sketch outputs this:
voltage: 0.96  deg C: 46.19  deg F: 115.14

It's still very stable across readings but obviously way off. What could cause this and how can I fix it? I am not expecting the sensor to be perfectly accurate but the major discrepancy I'm seeing makes this unworkable.

Well, three years later I have the same problem. Did you eventually find a solution?


text:
Simon Says Project - Can't go from random lights to user input
I'm new to using an Arduino and I am attempting the Simon Says game. Right now, I do not understand why my program will not go from activating the random lights to the user input. Currently it is flashing all the lights three times like I want it to, but then it will flash three random lights and then go straight to flashing every light, right to left (which is the indicator that the wrong button was pushed).
I am working in Tinkercad/circuits.io and have had the physical implementation looked at, and it is good. I just can't figure out the code. Anything will help, thanks!

// Defining LEDs and buttons.
int leds[] = {12, 10, 7, 4};
int buttons[] = {11, 9, 6, 3};

const int max = 40;
int lightArr[max]; // Array with full patterns of LEDs.
int currArr[max];
int gameState = 0;
int level = 1;
int count = 0; // Counter for every sequence of iterating over the
random array of ints (LEDs).
int buttonPressed = -1;
int correct = 1;

void setup() {
  pinMode(leds[0], OUTPUT);
  pinMode(leds[1], OUTPUT);
  pinMode(leds[2], OUTPUT);
  pinMode(leds[3], OUTPUT);
  pinMode(buttons[0], INPUT);
  pinMode(buttons[1], INPUT);
  pinMode(buttons[2], INPUT);
  pinMode(buttons[3], INPUT);
  randomSeed(analogRead(0));
  allOn();
}

void loop() {
  if (gameState == 0) {
    resetGame();
  } else if (gameState == 1) {
    play();
  } else if (gameState == 2) {
    gameOver();
  }
}

void resetGame() {
  if (level == 1) {
  // Setting up a sequence of random lights.
    for (int i = 0; i < 40; i++) {
      lightArr[i] = random(0,4);
    }
  }
  level = 1;
  gameState = 1;
}

void play() {
  while (correct == 1) {
    showPattern();
    int correct = userInput();
  }
}

void showPattern() {
  for (int i = 0; i < level; i++) {
    delay(500);
    digitalWrite(leds[lightArr[i]], 1);
    delay(500);
    digitalWrite(leds[lightArr[i]], 0);
    delay(500);
  }
}

int userInput() {
  for (int i = 0; i < level; i++) {
    int buttonPressed = readOneButton();
    digitalWrite(leds[buttonPressed], 1);
    delay(500);
    digitalWrite(leds[buttonPressed], 0);
    delay(500);
    if (lightArr[i] != buttonPressed) {
      // User button pressed.
      gameState = 2;
      correct = 0;
    }
  }
}

void gameOver() {
  for (int i = 0; i < 3; i++) {
    digitalWrite(leds[0], 1);
    delay(150);
    digitalWrite(leds[0], 0);
    delay(150);
    digitalWrite(leds[1], 1);
    delay(150);
    digitalWrite(leds[1], 0);
    delay(150);
    digitalWrite(leds[2], 1);
    delay(150);
    digitalWrite(leds[2], 0);
    delay(150);
    digitalWrite(leds[3], 1);
    delay(150);
    digitalWrite(leds[3], 0);
    delay(150);
  }
  gameState = 0;
}

int readOneButton() {
  if (digitalRead(buttons[0])) {
    return 0; // Button: Red
  } else if (digitalRead(buttons[1])) {
    return 1; // Button: Green
  } else if (digitalRead(buttons[2])) {
    return 2; // Button: Blue
  } else if (digitalRead(buttons[3])) {
    return 3; // Button: Yellow
  }
}

void allOn() {
  for (int i = 0; i < 3; i++) {
    digitalWrite(leds[0], 1);
    digitalWrite(leds[1], 1);
    digitalWrite(leds[2], 1);
    digitalWrite(leds[3], 1);
    delay(500);
    digitalWrite(leds[0], 0);
    digitalWrite(leds[1], 0);
    digitalWrite(leds[2], 0);
    digitalWrite(leds[3], 0);
    delay(500);
  }
}

void play() {
  while (correct == 1) {
    showPattern();
    int correct = userInput();
  }
}

Why do you create a new variable called correct and put the value form userInput in that?  Why don't you put the return from userInput into the variable named correct that you already have?  Two variables with the same name in the same scope is NEVER a good idea.  The original correct will never be changed here so this becomes an infinite loop.
Next, look at readOneButton.  It will take the Arduino just a few microseconds to run through that for loop and the whole userInput function.  Unless you are super duper fast at getting that button pressed, it is just going to decide that you didn't press any buttons.  You don't have a case in there for no button pressed, so it is going to return 0.  You should probably wait until the user presses a button before you decide whether he is right or wrong.


text:
Obfuscate string with on SAMD21
I'am looking for a way to obfuscate string at compile time on my personal board build with an SAMD21, i'am using Arduino IDE to compile and upload code. All solution I've found like this one for example doesn't work with Arduino IDE beceause it's for c++14 (using constexpr doesn't compile) is there a solution working for Arduino?

Arduino can use even c++17 https://forum.arduino.cc/t/c-14/633553


text:
Undefined reference to function in custom library
Hello I am making a private Arduino library but am having trouble understanding how it is linked. Why does this h file work, but when I move the definition of board_led to a matching c file, it throws an error at compilation: In function loop: undefined reference to board_led(bool).
I am using the following board manager to compile in the Arduino IDE:
https://raw.githubusercontent.com/maximintegratedmicros/arduino-collateral/master/package_maxim_index.json
I am using the following board target: MAXIM ARM 32bit boards > MAX32630FTHR
#pragma once

#include "Arduino.h"
#include <stdbool.h>
#include <gpio.h>

extern const gpio_cfg_t s_board_led;

extern void board_led(bool on) {
     GPIO_OutPut( &s_board_led, on ? 0 : ~0 );
}

I suspect you're compiling from C++ code, and including that header.
When C++ links to C code, the C++ code needs to see extern "C" on the declaration, or surrounding the declaration (via extern "C" { /* function declarations */ })
If you are compiling C++ code against the C code (and linking them together), try making sure extern "C" is used, for example like this:
// arduino_lib.h
#pragma once

#include "Arduino.h"
#include <stdbool.h>
#include <gpio.h>

extern const gpio_cfg_t s_board_led;

extern "C" void board_led(bool on);

While nothing changes in the .c file
// arduino_lib.c
#include "arduino_lib.h"

const gpio_cfg_t s_board_led = /* some value */;

void board_leb(bool on) {
     GPIO_OutPut( &s_board_led, on ? 0 : ~0 );
}

To complement Bob's answer it is good practice to add header guards for detecting C++ specifically:
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

// your function definitions here

#ifdef __cplusplus
}
#endif // __cplusplus

That way the extern "C" is only applied if the header file is included into a c++ file but not if it's included into a c file.


text:
How to use two timers 1 and 4 simultaneously in Arduino Mega 2560
I activated timer 1 and its interrupt on the 2560 board and it works properly. Now I want to run Timer 4 as well. I installed the Timer 4 library, but when I compile the program, I get the following error. This error also occurs for timers 3 and 5:
C:\Users\win 8\Documents\Arduino\libraries\Timer5\Timer5.cpp:110:6:
note: 'void startSlowCountingTimer5()' previously defined here
 void startSlowCountingTimer5(void) {

Thank you for your help.
The full text of the error is as follows
C:\Users\win 8\Documents\Arduino\libraries\Timer5\Timer5.cpp: In function 'void startSlowCountingTimer5()':

C:\Users\win 8\Documents\Arduino\libraries\Timer5\Timer5.cpp:127:6: error: redefinition of 'void startSlowCountingTimer5()'

 void startSlowCountingTimer5(void) {

C:\Users\win 8\Documents\Arduino\libraries\Timer5\Timer5.cpp:110:6: note: 'void startSlowCountingTimer5()' previously defined here

 void startSlowCountingTimer5(void) {

is it actually an error?

If you want to use Timer4, why did you include the Timer5 library? Please show your code and the whole error message

And also provide a link to every library that you are using

This error also occurs for each of the three timers 3, 4 and 5

I downloaded Timer 1 from the Arduino site, which worked fine.

But I downloaded the library of timers 3, 4 and 5 from this site https://github.com/carlosrafaelgn/ArduinoTimer

This is a bug in the library that was fixed in 2017! Please
upgrade.

Thank you "Edgar" for your guidance. My problem is solved.


text:
Can I use Data Logger Shield with Arduino Sensor shield V5.0?
so I did a little research on this but the answer to my particular problem did not exist.
I have a data logger shield created by deek robot (deek-robot.com) which seems pretty similar to adafruits data logger shield so I assume they would use the same pins, about this one I can research and find the pins.
but in case of the sensor shield I could not find anything specially since there is no reference on the manufacturer on the board and only referred to as "Arduino Sensor Shield V5.0",as this is a shield for sensors and has almost every pin available on it I would assume it can use most of the data pins and depends on which pins I connect.
Now my question is that can I use these shields together if I want to use those digital pins already used by the data logger? or I can use them together only if I leave out the digital pins 10 to 13 out of use on my sensor shield?

The 'data logging' shield by Adafruit and Deek Robot has two devices.
First device is the SD card which uses SPI bus. Every SPI device on the SPI bus has to have a select pin CS. On this shield the SD card has pin 10 as the CS pins.
The second device on the data logger shield is a RTC clock. The RTC clock is on the I2C bus.
So the data logger shield uses the I2C pins, the SPI pins and a pin for CS. Arduino in Uno and Mega R3 form factor have the SPI as a 2x3 header and the I2C pins SDA and SCL are last two pins on the header near the USB connector.
On Uno the data logging shield uses pin 10 as CS, 11, 12, 13 as SPI and A4, A5 as I2C.
If you have the version of the data logging shield which can be used on boards other than Uno, then:

On Mega it uses pin 10 as CS, 50, 51, 52 as SPI and 20, 21 as I2C.
On Leonardo it uses pin 10 as CS, 2, 3 as I2C (and the SPI pins which are only on the SPI header).
On Arduino Zero the shield uses pin 10 as CS, 11, 12, 13 as SPI (and the I2c pins are only on the SDA/SCL header).

The 'sensor shield' doesn't have any devices. So it makes no difference in pins usage. With or without the 'sensor shield' if you have the 'data logging' shield attached, you can use only the pins not used by the 'data logging' shield.
Since SPI and I2C are a bus, you can wire additional SPI devices to the SPI pins and additional I2C devices to the I2C pins, but you can't use these pins for anything else if they are configured for the bus.

Ok thanks, a rather thorough answer, I will mark it right away after testing them , but what you indicated seems to be the right answer and even with more details , just another quick and small question, I read that the I2C can be used with as many devices as you want since they don't have CS of their own? this now means I am down to minus 2 analog and minus 4 digital pins, so assuming I hit this cap I will have to use MUXes I suppose

@Hitman2847, I2C doesn't use CS. the devices on I2C bus have addresses. If you need more pins, switch to Mega, but first check if the 'data logger' shield uses pins 11 to 13 or the 2x3 SPI header and the SDA and SCL pins or the A4 and A5 pins.

well the data logger must use the 11 to 13 pins because it only connects physically on the side pins and the 2x3 SPI header is free and not connected to anything


text:
Having problems registering my SIM800 with the network
I have a SIM808, connected via hardware serial to an Arduino Mega. Communication between the Arduino and the SIM808 is fine. However, the quality of the signal is listed as 0 all the time. (AT+CSQ)
I've checked, and there is definitely 2G (and 3G) signal. Power is fine. SIM is unlocked, and works in other M2M equipment.
The network status lights blink rapidly (ie searching for a network) for about 5 seconds. Then it takes one long blink, then goes back to blinking rapidly.
The module is picking up the names of the available networks, yet does not seem to be able to register.
I'm using a prepaid data SIM card from Vodacom (South Africa).

I think you are not giving it enough power, SIM800 module needs 5v/2A stable power source in order to register to network. Try to use a desktop computer power supply it has 5v/2A output wire (refer to colors).

Actually the SIM800 should not be supplied with more than 4.4 V according to the datasheet.  I would be interested to know how this problem was resolved.
I have a similar problem.  I cannot get the SIM800 to connect to Three or the O2 network even though both SIMs work in my mobile phone.
In my case the SIM800 is connected directly to two 18650 Li-Ion batteries in parallel so I don't think it is lack of power.  Perhaps a big capacitor would help.  I will give it a try.  Failing that it might just have a much less adequate antenna and needs to be out in the open.


text:
Why won't this code work on an Arduino Mega 2560 (It works on an Arduino Uno)?
The code below was taken online and was written for the Arduino Uno. I know C++ however I am a beginner with Arduino so I don't understand this compatibility issue or how to fix it. I am very thankful for any help. Here is part of the code - the variable declarations: (I can upload the entire code if that would be more helpful).
ISR(PCINT0_vect) {
  current_time = micros();
  //Channel 1=========================================
  if(PINB & B00000001) { //Is input 8 high?
    if(last_channel_1 == 0) { //Input 8 changed from 0 to 1.
      last_channel_1 = 1; //Remember current input state.
      timer_1 = current_time; //Set timer_1 to current_time.
    }
  } else if(last_channel_1 == 1) { //Input 8 is not high and changed from 1 to 0.
    last_channel_1 = 0; //Remember current input state.
    receiver_input[1] = current_time - timer_1; //Channel 1 is current_time - timer_1.
  }
  //Channel 2=========================================
  if(PINB & B00000010 ) { //Is input 9 high?
    if(last_channel_2 == 0) { //Input 9 changed from 0 to 1.
      last_channel_2 = 1; //Remember current input state.
      timer_2 = current_time; //Set timer_2 to current_time.
    }
  } else if(last_channel_2 == 1) { //Input 9 is not high and changed from 1 to 0.
    last_channel_2 = 0; //Remember current input state.
    receiver_input[2] = current_time - timer_2; //Channel 2 is current_time - timer_2.
  }
  //Channel 3=========================================
  if(PINB & B00000100 ) { //Is input 10 high?
    if(last_channel_3 == 0) { //Input 10 changed from 0 to 1.
      last_channel_3 = 1; //Remember current input state.
      timer_3 = current_time; //Set timer_3 to current_time.
    }
  } else if(last_channel_3 == 1) { //Input 10 is not high and changed from 1 to 0.
    last_channel_3 = 0; //Remember current input state.
    receiver_input[3] = current_time - timer_3; //Channel 3 is current_time - timer_3.
  }
  //Channel 4=========================================
  if(PINB & B00001000 ) { //Is input 11 high?
    if(last_channel_4 == 0) { //Input 11 changed from 0 to 1.
      last_channel_4 = 1; //Remember current input state.
      timer_4 = current_time; //Set timer_4 to current_time.
    }
  } else if(last_channel_4 == 1) { //Input 11 is not high and changed from 1 to 0.
    last_channel_4 = 0; //Remember current input state.
    receiver_input[4] = current_time - timer_4; //Channel 4 is current_time - timer_4.
  }
}

void set_gyro_registers() {
  //Set up the MPU-6050
  if(eeprom_data[31] == 1) {
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
    Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex)
    Wire.write(0x00); //Set the register bits as 00000000 to activate the gyro
    Wire.endTransmission(); //End the transmission with the gyro.
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
    Wire.write(0x1B); //We want to write to the GYRO_CONFIG register (1B hex)
    Wire.write(0x08); //Set the register bits as 00001000 (500dps full scale)
    Wire.endTransmission(); //End the transmission with the gyro
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search.
    Wire.write(0x1C); //We want to write to the ACCEL_CONFIG register (1A hex)
    Wire.write(0x10); //Set the register bits as 00010000 (+/- 8g full scale range)
    Wire.endTransmission(); //End the transmission with the gyro
    //Let's perform a random register check to see if the values are written correct
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search
    Wire.write(0x1B); //Start reading @ register 0x1B
    Wire.endTransmission(); //End the transmission
    Wire.requestFrom(gyro_address, 1); //Request 1 bytes from the gyro
    while(Wire.available() < 1); //Wait until the 6 bytes are received
    if(Wire.read() != 0x08) { //Check if the value is 0x08
      digitalWrite(12,HIGH); //Turn on the warning led
      while(1)delay(10); //Stay in this loop for ever
    }
    Wire.beginTransmission(gyro_address); //Start communication with the address found during search
    Wire.write(0x1A); //We want to write to the CONFIG register (1A hex)
    Wire.write(0x03); //Set the register bits as 00000011 (Set Digital Low Pass Filter to ~43Hz)
    Wire.endTransmission(); //End the transmission with the gyro
  }

Please edit your question and define "doesn't work".  I'm sure the code runs just fine on a Mega. Of course, port B maps to different pins on a Mega than an Uno, ie to digital pins 53, 52, 51... instead of to 12, 13, 14... so it won't do at all the same things on the Mega as the Uno. ¶ In general, include a Minimal, Complete, and Verifiable example of code, not just snippets.  Or provide a link to the online code you referred to.

Thank you, this is my first time posting. Here is a link to the code.

https://drive.google.com/file/d/0B5tJTKkHim16VDFhdHhNUDVOcTA/view?usp=sharing

When I upload to the Arduino Mega, it seems like the code just doesn't run, I'm not entirely sure what the issue is. Here is a link to the code that must be run before the above link's code can be uploaded and run.

https://drive.google.com/file/d/0B5tJTKkHim16NFZUenB6elZEbDA/view?usp=sharing

Break the problem down. Put some serial prints in there, see how far it's getting. If it's really just not running at all, make sure a trivial sketch runs on that device, then find how much you need to strip out of your code to make it basically run. Essentially, as @jwpat7 suggests, create a minimal, complete, verifiable example.

As no preview is available at the given links (for YMFC-AL_setup.ino and YMFC-AL_Flight_controller.ino at drive.google.com) and I don't want to download the code to my system, I haven't looked at the whole program; however, from the code included in the question, it's clear that it uses direct IO rather than Arduino API IO.
Direct IO expressions like PINB & B00000001 [see Edit 1, Note 1] affect differently-numbered digital pins on the Mega than on the Uno or Nano.  (Or, more generally, on boards based on ATmega256x vs ATmega328x or 168x vs ATmega32U4 or 16U4.)
On the Arduino Nano and Uno, PB0–PB5 are assigned to Arduino digital pins 8–13.
On the Arduino Micro with 32U4, PB0–PB3 are not assigned to Arduino digital pins; they connect to SS, SCK, MOSI, MISO, while PB4–PB7 are assigned to Arduino digital pins 8–11.
On the Arduino Mega2560 with  ATmega2560,  PB0–PB3 are assigned to Arduino digital pins 53, 52, 51, 50 respectively, and PB4–PB7 are assigned to 10–13.
Summary:  To adapt direct IO code written for an Uno to a Mega, you may need to change ports and pins numbers.  Just moving wires around to corresponding pins may or may not fix problems; if the code uses a mix of direct IO and API IO (with digitalWrite() etc.) the code may need to be changed as well.  For example, in setup() it might use API pin identifiers, and in ISRs might use direct IO, an approach that will malfunction when transferring code to a differently-mapped board.
Note, see numerous excellent pinout diagrams at pighixxx.com.
Edit 1:
Note 1:  In a file called binary.h, the Arduino IDE's programming environment defines a set of 510 constants whose names consist of a B followed by from 1 to 8 zeroes and ones, with values equal to corresponding binary numbers.  The value of the expression PINB & B00000001 is equal to the low-order bit (PB0) of input register PINB.    The value of PINB & B00001000 is 8 (ie, 1<<3) if PB3 is high, and is 0 if PB3 is low.  Typically, these binary constants are used as bit masks for bit operations (AND &, OR |, XOR ^).
Note 2:  When including code in a stackexchange question or answer, first paste the code into the question or answer editing box; then in that editing box, highlight the code and press ctrl-k.  (Alternately, highlight the code and click the {} icon in the toolbar at the top of the editing box.)
Rather large sections of code can be pasted into questions and answers.  Generally, paste in at least enough to be compilable and exhibit the problem.  If any variable or procedure definitions, #include lines, etc., are left out, people may have to play guessing games to answer the question, and that's generally undesirable as it wastes time and does not elicit good answers.

Thank you for your response, I will look at the Pinout diagrams for both micro controllers. I apologize for the lack of a preview and understand why you wouldn't want to download the file, how would I show a preview for future reference? Also what are the numbers such as B00000100, are they addresses?

@ColinMurphy, see edit 1

The sketch uses I2C to communicate with the Gyro / Accelerometer. On a Uno these pins are A4 (SDA) and A5 (SCL). On a Mega these pins are 20 (SDA) and 21 (SCL).


text:
Two-way communication on multimaster I2C bus
I'm trying to send data both ways between an Arduino Mega 2560 slave and 2  Arduino Nano Zero (ATSAMD21G).
This example is a simplified setup and code. There will be more masters along with passive slaves on the bus (LCD, EEPROM).
Code and results (txt files)
My code is working fine with one master only and the slave active on the bus (data is sent both ways every 2s). I however notice missing transfers to the masters when more than one master is active. The 2 masters to slave transfers are working properly (once the 2 masters are on, the data is received by the slave every 2s from each master).
Is this problem due to collision? How can I handle it?

Unless this is class work or just you exploring how I2C works, I would suggest you stick with 1 master and poll the other I2C slave devices.  Otherwise read up on I2C.  I think you can only have one master at a time and the method to switch who is the master is part of the I2C protocol.  BTW, I know SPI requires more wires, but people generally have less problems getting SPI to work.

The chip itself can detect collisions. I'm not sure if the Wire library fully implemented that. You would need to check the return value of every Wire.endTransmission and every Wire.requestFrom. I agree with st2000, it is better to stay out of trouble and have only one Master. Sometimes an extra interrupt signal is added to the I2C bus, to make it possible that a Slave can notifiy the Master that data is ready and waiting.

I saw quite a lot of people hit a wall with this on Arduinos. It would be great to have a solution to address it that's not a workaround with loss of functionality or extra wires. Having multiple masters that can communicate when they need to, with multiple slaves allows a lot of fun developments!
The protocol and chips are supposed to handle collision but I read the wire library doesn't implement it.
I'll check what I can do with Wire.endTransmission and Wire.requestFrom return values.

Wire.requestFrom returns "byte : the number of bytes returned from the slave device". I guess these bytes can contain the real data or something random due to collision...
Wire.endTransmission returns success or errors, so that should work (Master to slave was already working in my code without this check)
Is there an improved version of the Wire library that handles this better?
Otherwise I'm thinking of polling at a faster rate and add a CRC check, but that would add back and forth communications between masters and slave.

The code had several issues leading to a constant flow of wrong data (with correct data in the middle) between the master that won the bus arbitration. This made it keep the bus too long and eventually give it away to the second master at a random time, with missed transfers from the second master in between. The second master was then behaving the same and so on.
receiveEvent, on the slave side, contained a millis if condition timer that made it time out. I moved the timer to the master side before calling Wire.requestFrom. Avoid slow code in receiveEvent!
receiveEvent, on the slave side, was also confusing real data with incoming requestEvent. I added an if statement to compare the receiveEvent data size with the expected size. Half of the data was wrong without this filter (this should ideally be handled in the Wire library)
These fixes solved the busy bus problem. I figured these out after asking question #35092
The bus speed also had to be reduced because 800 kHz was too fast for the Mega 2560 (but worked between 3 Nano).
The slave has to send the data destined to both masters to each of them because requestEvent can't tell which master is asking for data. The data is then filtered on each master to only keep the relevant information.
The data is now being transferred both ways between the 2 Nano masters and the Mega slave at the correct interval, without corrupt data.
fixed Slave code
fixed Master 1 code
fixed Master 2 code in the same repo (I'm limited to 2 links post)

notice missing transfers to the masters when more than one master is active.

Because you didn't provide a way for the master's to know of a transmission ISS in progress. Lack of conflict resolution. A problem with all multimeter transmission.
A simpler approach is for the slave to signal a transmission from the master. That can be done via a slave requestion pin from the slave to the master.

The I2C protocol handles multimaster, without this kind of workarounds. The communication library should do that too. I could add wires, but who has spare pins?


text:
Is the Arduino Due compatible with a Dual VNH5019 Motor Driver Shield?
I'm planning on buying an Arduino Due and there is a shield I would like to attach to it. I have seen a lot of things saying that some shields are not compatible with Arduino Due... I was wondering if the Arduino Due is compatible with the Dual VNH5019 Motor Driver Shield.
This is where I'm buying it from if you need any extra information on the items:

The Arduino Due
The Dual VNH5019 Motor Driver Shield

Answers greatly appreciated! If you need any specifications let me know.

It is probably electrically compatible if wired point to point, though unclear if direct stacking as a shield would work.  The provided library is AVR-only, though it shouldn't be that difficult to write something that would work on a different processor.  The pins best suited for PWM may be in a different places, which could mean a choice between inefficient software or rewiring.

so its compatible, but the pins must be connected to the correct points?
so I cant just slap the shield on top?

That is unclear.  What was posted was a comment examining potential issues, not an answer.

ok so I went ahead and bought the arduino due and officially tested it out and the Arduino Due is compatible with the Dual VNH5019 Motor Driver Shield!
hope this helps!