text:
Making Cases for Projects
I've been messing around with arduinos and other microcontrollers for around a year now and I've always struggled to find ways to encase my projects. I've seen some people use custom PCBs and then 3D print a case for that.  How would one go about that? I am only a computer science student so I know nothing about electrical circuitry.
For example, lets say I have a UltraSonic Sensor that uses a Arduino nano to light an LED. How would I transfer that to a single PCB? And are there websites where I can order custom 3D printed cases for my projects?
Please let me know if you need me to make my question clearer. Thank you!

Your question has multiple layers:

The custom PCB: Breadboards are good for experimenting, but not for a finalized circuit. Depending on some factors you can decide between multiple options. One, that I myself often use, is soldering the parts onto a perfboard. That are cheap PCBs, where - depending on the type - you have a grid of single through-hole solder pads or connected groups of through-hole solder pads. I like to use these:

The pads are connected nearly like a breadboard, so it is easy to use with Arduinos and such. You can build your circuit on there by soldering the parts to it, and make the PCB the right size by cutting it into the needed size.
A more professional option is to buy real custom PCBs. You need to create the PCB layout on your PC (common programs are Eagle or Kicad, though there are many others). Then you can choose the PCB manufacturer of your trust and give them your layout files. They will manufacture the PCBs and send them to you. This options costs a bit money (though not a lot) and you will have to wait for the PCBs to arrive.
The casing: There are many options to choose from:

You can buy a generic case somewhere (hardware store, or the internet shop of your trust). Then you can work on it to fit your purpose (drilling holes for the LEDs, using screws or glue to fix your PCB, ...)
There are some standard cases to buy, though most of them most likely don't fit you good, since they are made for special industrial purposes.
You can create a custom 3D printed case. For this you first need to design the case on your PC (a common program is Fusion360, though I'm using FreeCAD). For the actual printing you can either use your own 3D printer, or you can again find a good 3D printing service, that you can give your design file (commonly in the stl format). They will print it for you for a bit of money. You will have to choose between different manufacturing methods, mainly FDM (putting lines of molten plastic onto each other layer after layer) or Resin printing (curing layers of fluid resin one after another). FDM is still cheaper. And you need to decide on the material (PLA is common, others are ABS or even metal (though the last is expensive). Also you need to design your case in a way, that it is good printable with the chosen method. You need to read more about 3D printing elsewhere (there are tons of material about it on the web).

One rule of this site is to not give product recommendations. That's not, what the site is for, and they are pretty fast outdated. Instead you need to do the research yourself.

You might want to look into JLCPCB, who have a good prototype offer. Though because of corona don't expect much currently


text:
i have a problem with mdns i'm using an ESP8266
I am working on a project on which I have to drive a DC 12V motor. I use an ESP8266 I manage to manage my engine remotely but my only problem is the mdns I use the mdns but it does not work. when I upload no error is displayed but I can not access my esp using his name.local

what esp8266 boards package version? PC has Windows or Linux?

I use the ESP12E and the version of my arduino is 1.8.9 my driving board is the pololu and my pc is on linux

sorry i forgot, i use linux on my pc

source: Stack Exchange

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

sort: votes


text:
Arduino to Arduino communication
When I send data to an Arduino Uno via the serial monitor, the serial data goes down the same USB cable used to program the Arduino.  So there must be a device on the Arduino board like a FTDI or USB-capable AVR that drives the RXD pin of the Arduino.  So my question is: When I want two Arduino boards to communicate with each other over serial, many tutorials say just connect RX and TX on one Arduino to TX to RX on the other.  So how come the device on the board that normally drives the RXD pin doesn't "fight" the other Arduino that is also now driving the RXD line?

The Atmega16U2 that does the USB communications is connected to Rx and Tx via 1k resistors, so when communicating with another Arduino it "overpowers" the USB interface. See image:

By the way, note that the Tx and Rx LEDs are connected to the Atmega16U2, not the Atmega328P, so they do not light when doing Arduino-to-Arduino communications.

Measuring with an empty sketch on my Uno, the current between Tx and Gnd was 0.14 mA, not 5 mA. So that suggests that the Atmega16U2 sets the pins to high-impedance when not actually receiving data from the USB interface.
It's logical it would do that, because the 5 mA you mention (in a comment) could be a nuisance if you wanted to use that pin for something else.

Awesome, thanks!  You were both very quick.  So does this mean that it is safe to power the Arduinos via the USB even when they are wired for serial communications with another Arduino?  And that the ATmega16U2 and the other Arduino will fight, but only with ~5mA?

Yes, I think that's done all the time. However, and this is important, because the Arduino-to-Arduino connection will overpower the USB interface, you will have trouble programming it (the one you are trying to program) while they are connected.

It's also possible, although I'm not certain, that the USB chip would set the pins to high-impedance when not actually in use. In fact, I just measured on my Uno, the current between Tx and Gnd was 0.14 mA, not 5 mA. It's logical it would do that, because the 5 mA you mention could be a nuisance if you wanted to use that pin for something else.

@NeilStockbridge So those 1k resistors are probably there as a precaution against you trying to reprogram the chip while it is connected to something else.

If we take a look at this portion of the Arduino Uno schematic (whole schematic is located here):

... we see there are two 1K Ohm (1,000 Ohms) resistors (labeled RN4A and RN4B) between the USB to serial conversion chip on the left to the Atmel processor at center right.  These allow the Rx (Receive) and Tx (Transmit) pins to be back driven by an externally connected device.

Beat me by a few seconds! :)

... you are a hard person to beat in these circles!

That must be an old schematic, as the Uno now has a Atmega328P not an Atmega8. However the principle is the same.

Hmmm, it came right off of arduino.cc's web site.
Oooh, that's what they meant by "Reference Design".

Mine has "Rev 3" on it, so you must have found an earlier revision. It's still a reference design though.

Here's the Rev 3 link.

Another  way to do serial communication between Arduinos is to use the SoftwareSerial library using (digital) pins of your choosing for serial communication between the Arduinos. Incidentally, it avoids interference from your computer under simple serial communication,

The SoftwareSerial library allows serial communication on other digital pins of an Arduino board, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.

https://docs.arduino.cc/learn/built-in-libraries/software-serial
It takes just a little preparation and understanding, but not much.
#include <SoftwareSerial.h>

#define rxPin 10
#define txPin 11

// Set up a new SoftwareSerial object
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

void setup()  {
    // Define pin modes for TX and RX
    pinMode(rxPin, INPUT);
    pinMode(txPin, OUTPUT);

    // Set the baud rate for the SoftwareSerial object
    mySerial.begin(9600);
}

void loop() {
    if (mySerial.available() > 0) {
        mySerial.read();
    }
}

In this example (copied from the above/linked article), you would use the mySerial variable to do your Arduino to Arduino communication in the same way as you use the standard serial connection. You would also need to wire the RX and TX pins of one Arduino to the TX and RX pin of the other Arduino, respectively.
One of the benefits of learning how to use the SoftwareSerial library is that there are many communication devices that use serial connection, such as Bluetooth modules (HC-05, HC-06, and HM-10 for example), that you can now use with ease. In this case, you can replace the wires I had you add with a Bluetooth module and communication between the 2 Arduinos wirelessly. Or you can instead communicate with a mobile device with the Bluetooth module.
https://www.instructables.com/Tutorial-Using-HC06-Bluetooth-to-Serial-Wireless-U-1/
Or you could access the internet with a WiFi module over SoftwareSerial.
https://www.taintedbits.com/2017/07/21/arduino-uno-esp8266-software-serial/

the question doesn't ask how to avoid interference. it asks why there isn't one.

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


text:
Why is this RISING interrupt repeatedly triggering?
I've set up an ISR to trigger on the RISING edge of pin #2, but I find that if pin 2 is held high, the ISR triggers repeatedly.
Here's a trace of the voltage measured right at the pin:

I can see a little bit of noise, but it shouldn't be enough to trigger multiple pulses. I've tried both INPUT and INPUT_PULLUP modes for the pin; behavior is the same.
constexpr byte kClockPin = 2;
constexpr byte kReadWritePin = 3;
constexpr byte kLedPin = 13;
constexpr int kNumAddressPins = 16;
constexpr byte kAddressPins[] = {/* MSB */52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22};
constexpr int kNumDataPins = 8;
constexpr byte kDataPins[] = {/* MSB */45, 43, 41, 39, 37, 35, 33, 31};

volatile bool dirty = false;
volatile uint8_t data = 0;
volatile uint16_t address = 0;
volatile bool read = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(kClockPin, INPUT_PULLUP);
  pinMode(kReadWritePin, INPUT);
  for (byte pin : kAddressPins) {
    pinMode(pin, INPUT);
  }
  for (byte pin : kDataPins) {
    pinMode(pin, INPUT);
  }
  pinMode(kLedPin, OUTPUT);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(kClockPin), OnClock, RISING);
}

void loop() {
  // digitalWrite(kLedPin, digitalRead(kClockPin));
  if (!dirty) return;
  char output[15];
  sprintf(output, "%04x %c %02x", address, read ? 'r' : 'w', data);
  Serial.println(output);
  dirty = false;
  // digitalWrite(kLedPin, digitalRead(kClockPin));
}

void OnClock() {
  read = digitalRead(kReadWritePin);
  data = 0;
  for (byte pin : kDataPins) {
    data = (data << 1) + (digitalRead(pin) ? 1 : 0);
  }
  address = 0;
  for (byte pin : kAddressPins) {
    address = (address << 1) + (digitalRead(pin) ? 1 : 0);
  }
  dirty = true;
}

Turns out the short answer is that I'm still not great at using an oscilloscope.
Longer version is that the noise was very visible at smaller time scales. A filter capacitor had come disconnected from the breadboard in a way that was hard to see, and that was causing a whole bunch of noise. Replacing it fixed the problem.


text:
ESP32 - Html link
I'm programming a ESP32 modue and I have a code that generates an Access Point and displays an html with two buttons that changes the state of 3 leDs. I want to insert a button that calls a second html code that is within (void engine() ) and on this page has the following text ( This page turns on the engine ). Detail: The page that is already displaying in the browser has to be updated by the new html code of the second html page. How can I change my Code to get this third button ?
#include <WiFi.h>
#include <WebServer.h>

const char* ssid     = "ssid";
const char* password = "password";

WiFiServer server(80);

String header;

String output26State = "off";
String output27State = "off";

const int output26 = 26;
const int output27 = 27;

void setup()
{
 Serial.begin(115200);

 pinMode(output26, OUTPUT);
 pinMode(output27, OUTPUT);

 digitalWrite(output26, LOW);
 digitalWrite(output27, LOW);

 WiFi.softAP(ssid, password);
 delay(10);

 IPAddress IP = WiFi.softAPIP();
 Serial.print("IP Address: ");
 Serial.println(IP);

 server.begin();

}

void one()
{
  WiFiClient client = server.available();
  client.println("
Page One
");
  client.println("
<button class=\"button\">Pag Two 2</button>
");
  client.println();
}

void two()
{
  WiFiClient client = server.available();   // Listen for incoming clients
  client.println("
Page Two
");
  client.println("
<button class=\"button\">Page One 1</button>
");
  client.println();
}

void loop()
{
 WiFiClient client = server.available();   // Listen for incoming clients

 if (client)
 {                             // If a new client connects,
  Serial.println("New Client.");          // print a message out in the serial port
  String currentLine = "";                // make a String to hold incoming data from the client
  while (client.connected())              // loop while the client's connected
  {
   if (client.available())               // if there's bytes to read from the client,
   {
    char c = client.read();             // read a byte, then
    Serial.write(c);                    // print it out the serial monitor
    header += c;
    if (c == '\n')                      // if the byte is a newline character
    {
      if (currentLine.length() == 0)
      {

       client.println("HTTP/1.1 200 OK");
       client.println("Content-type:text/html");
       client.println("Connection: close");
       client.println("<!DOCTYPE html>");
       client.println("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
       client.println("<link rel=\"icon\" href=\"data:,\">");
       client.println("");
       client.println("");
       client.println();

       if (header.indexOf("GET /one") >= 0)
       {
        Serial.println("Page One");
        output26State = "on";
        digitalWrite(output26, HIGH);
        one();
       }
       else if (header.indexOf("GET /two") >= 0)
       {
        Serial.println("Page Two");
        output26State = "off";
        digitalWrite(output26, LOW);
        two();
       }
       client.println("
<button class=\"button\">Page Two</button>
");
       client.println("");
       client.println();
       // Break out of the while loop
       break;
      }
      else // if you got a newline, then clear currentLine
      {
        currentLine = "";
      }
    }
    else if (c != '\r')      // if you got anything else but a carriage return character,
    {
      currentLine += c;      // add it to the end of the currentLine
    }
  }
}

 header = "";
 client.stop();
 Serial.println("Client OFF.");
 }

}

Thank You

Did I understand you correctly? You want a button that links to another page and at the same action you want to toggle (or only turn on) the engine?

why don't you use the same html code as the other two buttons? ... just make the necessary changes to make the code unique

369/5000
I'm sorry, I didn't express myself very well, let's simplify my doubts. For example, in my code there is (void one ()) and (void two ()). I want to insert a button that calls (void one ()) and insert an html code inside (void one ()), when (void one ()) is called it displays the html replacing the code of the main page that is inside (void loop ()).

this is an XY problem ... you are asking for help with what you consider to be a solution to your problem, instead of asking for help with the problem ... there are other more effective ways to update a web page ... google arduino html button led ... that will show you how to interact between a web page and a function ... here is one of the hits that may help https://startingelectronics.org/articles/arduino/switch-and-web-page-button-LED-control/

you could have 3 buttons on a webpage and simply make one or more of them invisible ... that way you would not have to reload the web page


text:
Unconsistent time in arduino loop
I have this code:

The output looks like this:

Why are there non-periodically some extremely large values?
Thanks

Serial.println waits if the TX buffer is full. And ATmega32u4 handles the USB port in the background

is there a way to make it faster?

No code as image please. Copy and paste the code as text and format it with the {} button

As explained by theSealion in his answer, this may be due to the
different background tasks performed by the microcontroller. However, I
personally find that 1 ms looks excessive. My guess is that the
main culprit is the USB stack pushing all those bytes down the wire.
In order to check this, I wrote the following program. It measures a
histogram of the loop execution times and then prints it through the
serial port. Since the data is only printed after the measurements are
done, the serial port does not do any work while the timings are being
measured.
const int HISTOGRAM_LENGTH = 512;

uint16_t histogram[HISTOGRAM_LENGTH];

void print_histogram() {
    Serial.println(F("t (us)  count"));
    Serial.println(F("-------------"));
    for (int i = 0; i < HISTOGRAM_LENGTH; i++) {
        if (histogram[i] == 0) continue;  // skip zeros
        Serial.print(i * 4);
        Serial.print('\t');
        Serial.println(histogram[i]);
    }
    Serial.println(F("-------------"));
    Serial.flush();
}

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

void loop() {
    static uint32_t last_time;
    uint32_t now = micros();
    uint32_t dt = now - last_time;
    uint32_t bin = dt / 4;  // resolution of micros() is 4 us
    if (bin >= HISTOGRAM_LENGTH)
        bin = HISTOGRAM_LENGTH - 1;
    if (++histogram[bin] == UINT16_MAX) {
        print_histogram();
        exit(0);
    }
    last_time = now;
}

These are the results when run on an Arduino Uno:
t (us)  count
-------------
8       21888
12      65535
16      632
20      323
56      1
-------------

This shows that most loop iterations take 8–12 µs. Those iterations
that were interrupted took 16–20 µs. The outlier at 56 µs is
most likely the time between the program starting and the very first
iteration of loop().
Here, the only interrupt source that affects the measurements is the
timer interrupt. It fired exactly 955 times during the measurement
period, which is consistent with the number of samples recorded at
16–20 µs. We can see from this data that the timer interrupt takes
roughly 8 µs to run, which is quite reasonable. Again, I would not
consider a 1 ms delay as reasonable.

There are be several "tasks" and interrupts that run in the background and they influence how often the loop() function is called.
For example timer, usart ...
They all need some attention from time to time. If the need some really fixed execution time you must use something like a hardware timer.
and by the way: a maximum of ~1.1ms is not bad for such a small controller. :-)
And as a addition to your question in your comments: I don't think there is a way to make the loop faster. As long as you need the other tasks, you have do give them some time.

Thanks theSealion! In addition, the original problem for this question was that I am driving a stepper motor and I need to communicate with Raspberry Pi using UART. The problem is that when I send some data about the motor to RPi and the motor is already spinning very fast, I often loose a step because there is just way too big delay. Do you have any idea how to solve this?

I don't know how the arduino stepper library is implemented and why you are loosing steps, but in general:
Make sure you don't use any busy waits. Especially when you are communication with the Rapsberry (do not wait for characters to be available).

Alright, I am still figuring out the source of loosing steps and I think I found it. I think it has nothing to do with Serial.print. I would like to run stepper at 3000 steps per second. That means one pulse each 333,3 microsecond. And obviously when there is a ~1.1ms delay, it is too long delay not to loose a step.
BTW I am using AccelStepper library. Is there some possibility to figure this out

I don't understand "a maximum of ~1.1ms is not bad"

In addition, the original problem for this question was that I am
  driving a stepper motor and I need to communicate with Raspberry Pi
  using UART. The problem is that when I send some data about the motor
  to RPi and the motor is already spinning very fast, I often loose a
  step

Your stepper code has to run very consistently to maintain 3000 steps/sec without jitter or dropping steps. It must not have to wait for communication or any other task but be able to issue the next step command on-time. Some possible techniques to accomplish this:

Don't post an entire message to the Pi but send only a few characters at a time, between steps.
Talk to the Pi in shorter, tightly coded messages, and let the Pi expand them if it needs to.
Use the highest baud rate the Uno & Pi can reliably use.
Issue step commands in a timer-driven interrupt routine, with any stepper housekeeping done in the background, between step-commands.
Use a faster processor.


text:
How to power Arduino pro mini and DFPlayer mini togather with 3.7 V LiPo battery?
I made a small box containing Arduino Pro Mini , DFPlayer Mini player and a 3.7V LiPo battery. Is it possible to power two devices with 3.7 V Battery?
What is the best way to save power for longer time performance?

Just remember that a LiPo has 4.3V when it is full and ~3.0V when it is emty. If you have the 3.3V Arduino, you can connect it as it has an internal voltage regulator. the DFPlayer can work up to 5V. So you can connect both. What do you mean with longer time performance? 1 hour? 1 day? 1 week? Stand By? Power Off? When running? And last question: do you have also speakers connected on it (over the same LiPo?). You have to be more specific.

Use a buck/boost voltage regulator. Those are high efficiency switching regulators, and can either increase or decrease the input voltage. Feed the output of the regulator directly into the Arudino's 5V (or 3.3V) line, bypassing the on-board voltage regulator.
What input voltages do the 2 devices need? Both 5V? If so, you can use a single voltage regulator to power both devices. If one needs 3.3V and the other needs 5V you may have to have 2 different voltage regulators.
By using a switching regulator you can bypass the fairly inefficient linear regulator in your Arduino supply 3.3V or 5V to it directly (depending on the type of board you have.)
Edit:
Ok, I looked it up and a DFPlayer Mini player appears to be a shield designed to plug directly into an Arduino. It looks like it can be powered from 3.2 to 5V, so you should be able to use it with either a 3.3V or 5V Arduino Pro Mini. Once you've decided if you're going to use a 3.3V or 5V Arduino, pick a buck/boost voltage regulator with the desired output voltage (or get an adjustable one and set it appropriately.)


text:
Arduino boards are not working with powerbanks!
I have used many Arduino boards with adapters and other power supplies. While connecting with a powerbank for portable projects I have noticed that the power goes off after a couple of seconds and then turn on again after sometimes. Why this is happening with power bank?
I have used following powerbanks:

Basus
Xiaomi

refer to the powerbank datasheet for minimum and maximum allowable load

Most USB powerbanks will automatically turn off if there is not a minimum current draw to keep them turned on.  The Arduino is obviously drawing current below the limit for the devices you have.
A couple of options:

Add some additional load to keep the powerbank on indefinitely.  Of course this may waste power but that's part of the price to pay.
Find a power bank that is less sophisticated.  I have one with a manual on/off switch.  It powers the Arduino just fine until it runs out of power.
Find a different powerbank that has a lower threshold for staying on.  Some vendors give you this spec and others don't.
Modify the powerbank to stay on.  I'm not sure there is a general way to do this but you might experiment with it and see.

Any links to indicate power banks automatically turn off below a certain current or power threshold after a certain time would be useful, even if they are just links to user manuals you are familiar with.

I thought it was a working method of powerbank . Thanks for the suggestion.


text:
Why use \" in arduino code?
While working with JSON parsing I noticed that the char type data string is written like this:
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";

Why there are (escapes) " ---" used in the code? Why can't we use the string normally?

Try it without and see what happens ;-)

Why there are (escapes) " ---" used in the code? Why can't we use the string normally?

Because escapes are required.
In C " means 'The start or end of a string', but \" means 'A double-quote character'.
There has to be a way to distinguish a double-quote character from a string delimiter so the compiler knows which is which. Without escapes your string would look like:
char json[] = "{"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}";

and the compiler would find the end of the string at the second ", and then a load of junk before it finds the end-of-statement ; character. It can't work out what sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}" is supposed to be, since it isn't in the string, but after it.


text:
Byte not written to the memory
In the following code I'm computing crc and setting it as last (11th) byte in the array. The problem is it's sent on I2C just when I print it on the serial terminal.
  static constexpr uint8_t CLICK_MESSAGE_SIZE{11};
  ...
  uint8_t buf[CLICK_MESSAGE_SIZE];
  memcpy(buf, msgMouseClick[clickMessageCounter], CLICK_MESSAGE_SIZE);
  buf[10] = dallas_crc8(buf, 10);
  Serial.println(buf[10], HEX); //!!!has to be here, otherwise is CRC in packet wrong!!!
  Wire.write(buf, CLICK_MESSAGE_SIZE);

When I'm assig the result of to
auto crc = dallas_crc8(buf, 10);
buf[10] = crc;
Serial.println(crc);

and Serial.print ing it. Then It's works. But with  const auto crc = dallas_crc8(buf, 10); It does not!
I have slightly modified Wire library, where I'm passing pointer to the buffer and it's size. With precalculated CRCs on 11th position it's working fine even for hundreds of bytes arrays.
It feels like a black magic, or compiler error. I'm using latest arduino-1.8.10
Any tips or hints?

The code snippets you show look fine to me. Could you post a minimal, reproducible example showing your problem?

I don't get your problem. What do you mean by "it works" and what by "it does not"? Please provide exactly what you expect and what you get in both cases.

If the difference is just in serial monitor, maybe that missing HEX is the issue.

The problem is that without  Serial.println(buf[10], HEX); the value of the last byte sent with Wire.write(buf, CLICK_MESSAGE_SIZE); is the same like in declaration. Not as calculated and set in buf[10] = dallas_crc8(buf, 10);   The Serial.println(buf[10], HEX); is cruical for getting the last byte correctly.

Just to double-check that I understand you correctly: You are saying that without Serial.println(buf[10], HEX); the value at buf[10] is not what you assigned via buf[10] = dallas_crc8(buf, 10); when Wire.write(buf, CLICK_MESSAGE_SIZE); is executed? Is the value the 11th uint8_t from msgMouseClick[clickMessageCounter] or any other value? This seems so improbable that I'd like to ask you for a [example]. You might want to minimize it.

try it with AVR boards package 1.6.21. install it in Boards Manager. it has older version of gcc

Strangely it helped.

the new version of gcc is buggy


text:
i2c man in the middle
I'm developing a bridge, or man in the middle for touch controller and a system board connected with I2C.  The connection is:
Touch Controller(slave)---I2C---(master)STM32(slave)---I2C---(master)ARM Board
The original i2c cable is cut in half and STM32 is sitting in the middle.
The point it letting common communication through and just sometimes after an external trigger injecting a click event. (It's for automated testing.) The TC is the only I2C device on the bus.
Have someone done something similar?
The protocol is simple. The ARM board writes two bytes address.Then reads several(3-259) bytes.
I'm trying to request data from TC after receiveEvent() from master, but I don't know how many bytes shall I request. It also takes time for the answer.
Any ideas?

How is this question Arduino related? Perhaps, you are on the wrong channel. ;-) There is also a better chance of getting help if you provide some code. For me it is complete unclear how the communication TC<--> ARM is done on the protocol level. One guess: It seems the ARM initiates the communication. It sends the TC address to the bus. The ARM orders the TC to write and then provides a clock signal. The TC send the data bytes using the clock. If there is no data left it send a Stop signal.

Let the STM pass a read request from the ARM to the TC. Let the STM read data from the TC and send it to the ARM. If the data is not yet available the STM drives the clock line to LOW that pauses the ARM until there is data. If the TC sends a stop (interrupt) send a stop to the ARM too. If you have data to inject, you can inject it as long as the ARM started the communication and STM has not send the stop flag.

Possibly the only requirement is that the touch controller supports clock stretching. I think generally it's possible, but I see now specific question or code. So, have you allready tried anything?

I've tried passing SDA and SCL trough with interrupts. But the bus frequency is 340kHz and the introduced latency to high. Then I was trying requesting slave in receiveEvent() from master. It hangs the whole system I'll try the trick with driving the SCL down as Peter suggests. Or implementing part of the touch protocol. And I've ordered an I2C multiplexer as fail save solution.


text:
Arduino uno + 5 IR obstacle sensor
I have IR sensor with current draw 100ma i have to connect 5 of them is i can connect all 5 with arduino directly or i have to use external power suplly for them

what sensors exactly?  Can you post a link to a datasheet?

An Arduino UNO has a max current of 20 mA per IO Pin and a max current of 200 mA of all Pins together. If you intent to drive the senders with the pins then this is impossible.
If you power the Arduino with USB, the VCC current is limited to 500 mA (thermo fuses). If you power it externally, it depends on the power supply. Using the voltage from the Vcc Pin is risky (IMHO), because the Arduino needs power too.
So with 100 mA per sensor I would definitively use an external power supply.

Can you please help which power supply i have to use soo that i can give supply to arduino as well as to my sensor externaly (becoz there is no use of give  usb power to arduino if i am connecting external power for sensors ) i want to do it with single power source

I fear, I can not help you, as I know nothing about your setup. And it is also not a good idea not ask a question and than extend it again and again and .... So please ask a new question eventually with a link to this one. The more information you add to the question the more help you will get. Which Sensors do you use (give a link to the data sheet).  How are they used. Are they all active at the same time, or just one or a few. Have you searched the internet for similar problems? Or edit this  question, but add the details I suggested.  (But do not add the details to a comment.)


text:
Temperature anomaly on BS18B20 + NodeMCU on Tingspeak
Temperature drops occasionally from 59+C to -13C or to other random values. Used sketch and info from this site:
http://internetofthinking.blogspot.com/2016/02/upload-ds18b20-temperature-sensor-data.html
NodeMCU powered by phone charger 5v 1a via microUSB.
Placing 4.7 kOm resistor between data wire and 3v3 didn't help me.
Does anyone know how to solve this issue? Like filtering results and pushing to server only values that do not differ by more than n*C, or something like that?
Here is the sketch
#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define myPeriodic 15 //in sec | Thingspeak pub is 15sec
#define ONE_WIRE_BUS 2  // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* server = "api.thingspeak.com";
String apiKey ="-";
const char* MY_SSID = "-";
const char* MY_PWD = "-";
int sent = 0;
void setup() {
  Serial.begin(115200);
  connectWifi();
}

void loop() {
  float temp;
  //char buffer[10];
  DS18B20.requestTemperatures();
  temp = DS18B20.getTempCByIndex(0)+5;
  //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()
  Serial.print(String(sent)+" Temperature: ");
  Serial.println(temp);

  //if (temp != prevTemp)
  //{
  //sendTeperatureTS(temp);
  //prevTemp = temp;
  //}

  sendTeperatureTS(temp);
  int count = myPeriodic;
  while(count--)
  delay(1000);
}

void connectWifi()
{
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) {
  delay(1000);
  Serial.print(".");
  }

  Serial.println("");
  Serial.println("Connected");
  Serial.println("");
}//end connect

void sendTeperatureTS(float temp)
{
   WiFiClient client;

   if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
   Serial.println("WiFi Client connected ");

   String postStr = apiKey;
   postStr += "&field1=";
   postStr += String(temp);
   postStr += "\r\n\r\n";

   client.print("POST /update HTTP/1.1\n");
   client.print("Host: api.thingspeak.com\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   client.print(postStr.length());
   client.print("\n\n");
   client.print(postStr);
   delay(1000);

   }//end if
   sent++;
 client.stop();
}//end send

measure several times ... ignore max and min readings

Have you checked the device's Scratchpad CRC

Idk how to.

How is your device hooked up (diagram)

Device is hooked up in normal mode, right like in this pic

DS18b20 (waterproof) is located on top of the boiler in a special pit for measuring temperatures, there are definitely no any sort of microwaves here, and the temp is not higher than 80C.
I'll try today to change the power supply, just in case, and later switch the sensor into parasite mode.

Discarding (potentially) bogus readings could help as a last resort, but something's going on to cause those bogus readings. You'd be better off finding and fixing that than finding a work-around.
These are pretty stable devices and you shouldn't see more than a couple of LSB (a few 1/4 degC). I'm inclined to suggest noise pickup on the one-wire bus but the bogus samples in your photo look identical. I have a >15' parasitic one-wire bus, just a twisted pair with no shield, and a DS18b20 close to the MCU and another out at the end. I do smooth the input but no de-spiking.
Have you checked the device's Scratchpad CRC between converting and reading the temperature? How is your device hooked up (diagram)? Is it in parasitic mode?


text:
can I program a nano over SPI with another nano?
I'm fairly new to arduino, but I want to program a nano over SPI to skip the bootloader. I know I can program the nano with an uno as a programmer to do this, but I don't have an uno, but I do have a couple of nanos. Can I set up one as a programmer, connect it to another over SPI, and program the 2nd?

from software side there is no difference between Uno and Nano 2018 with new bootloader. older Nano can have old bootloader. Wire over ICSP headers one to one except of the reset pin which should be wired to pin 10 on programmer board

Yes, you can. They use ATmega328 / Atmega328P microcontrollers, which are basically the same.
(The differencies of those microcontrollers are about Brown Out Detection - how they could be set to react on too low voltage. No problem in nearly any Arduino operation.)
The boards differ mainly in the board size and places for pins.

Nano has 328p too. Arduino doesn't use ATmega328

The better then - I do not have one at hands now, so I cannot check it physically. I found the Atmega328 (without P) was mentioned in Tech Specs here https://store.arduino.cc/arduino-nano so I kinda trusted them, but they may did typo or had more verssions historically. Anyway even if they would differ, it would work, if they are both the same, it would work too :)


text:
Program the Arduino Due with the ESP32
I'm trying to do OTA firmware updates for the Arduino Due with the ESP32.
Now so far I'm able to get the firmware from a website and transfer it over UART.
Now I'm looking to get the firmware and upload it to the Arduino due. My understanding is that I have to write it at 0x00080000 and from there I can write al the binary information.
The problem is that I have no idea how to:

Get the Arduino DUE in programming mode
Write to the Arduino DUE (which pins to use, what protocol...)

Can someone give me some pointers as to where to start with this? I have been reading through the documentation of the SAM3x8e, but I don't get any wiser.

reset it over reset pin (with the "double reset") to enter the bootloader. then you can do a serial upload

@Juraj I can't seem to find any documentation on this. Can you point me in the right direction?

sorry my first comment doesn't apply for Due. Here is something about reset and upload: https://www.arduino.cc/en/Guide/ArduinoDue#toc14

Thank you for that. So from what I get now is that have to open the native USB port at 1200 baud, to get it into flash programming mode (or hold the reset down). Then the only thing I have to do is to send the bytes directly to the Arduino?

https://playground.arduino.cc/Bootloader/DueBootloaderExplained/


text:
Understanding SAM3x8e boot program. Misunderstanding the datasheet
I'm trying to make my own firmware uploader for the Arduino DUE by using an ESP32.
While reading through the datasheet I saw that once there's data transmitted over the UART port, the sam3x8e will go into the SAM-BA monitor mode. The flowchart that the datasheet provides is as follow:

How does this make sense, since you can obviously communciate with the DUE over UART?
Do you have to avoid certain hex combinations, or does it get out of this loop automatically?

As far as I remember, it starts if the Flash memory is erased (by holding ERASE input pin low for more than about 250ms). And for example STM32 chips are controlled by BOOT0/BOOT1 input pins to run from bootloader section or flash section or even from RAM

There is a setting in flash that controls whether to boot from flash or to boot from ROM. When you erase the chip it defaults it to ROM.  When you program the chip you (usually) set that setting to boot from flash.


text:
Get data from Bluetooth scale
I am trying to get data from this type of scale
https://acaia.co/products/pearl. It does not show up under discover-able Bluetooth devices on a computer or phone, but it does have an app which it connects to automatically when turned on; the app can then display the weight in real time. This is my first time working with Bluetooth devices and am unsure as to how it is connecting to the app without showing up on other devices. Any information as to what is going on and possibly steps in the right direction would be greatly appreciated.

How is this connected to Arduino? Do you want to use one to communicate with the scale?

If you are sniffing with Microsoft Windows 10 you may want to stop.  Windows 10 is not a great platform to develop on.  It assumes many thing and does not tell the user about the assumptions.  As of late (fall of 2019) Windows 10 will stop connecting to certain BlueTooth devices if Windows 10 thinks the devices are not safe to connect to.

@chrisl yes, sorry the plan is to use an uno with a bluetooth module. We just want to have a way of getting the current weight on the scale

What you need to do is do some bluetooth sniffing to find out how the device is communicating with the phone. Here is a good article on doing that : http://nilhcem.com/iot/reverse-engineering-simple-bluetooth-devices


text:
I am interfacing Amonia Sensor RS485 output with Arduino Mega . not getting any response
I am interfacing Amonia Sensor RS485 output  with Arduino Mega but not getting any response. i need to transmit  {0x06, 0x03, 0x00, 0x00, 0x00, 0x04, 0x45, 0xBE};
frame to sensor then senor will send response frame. i am using Max485 converter which has DE RE pins .could you guide ME to write proer code. please help me i am in trouble
#include <SoftwareSerial.h>

#define SSerialRX        0
#define SSerialTX        1

#define modbusModuleDE   8
#define modbusModuleRE   9

SoftwareSerial RS485Serial(SSerialRX, SSerialTX);
byte byteSend;

//ModbusMaster node;

void setup()
{

 Serial.begin(9600);

 pinMode(modbusModuleRE , OUTPUT);
 pinMode(modbusModuleDE , OUTPUT);

  Serial.println("..... ");

  delay(10);

}

byte buf[8];
void loop()
{

     Serial.print("NH: ");
digitalWrite(modbusModuleDE, 1);
 digitalWrite(modbusModuleRE, 1);
 delay(10);
     byte request[] = {0x06, 0x03, 0x00, 0x00, 0x00, 0x04, 0x45, 0xBE};
     RS485Serial.write(request, sizeof(request));
     RS485Serial.flush();
  digitalWrite(modbusModuleDE, 0);
 digitalWrite(modbusModuleRE, 0);
 delay(10);
     RS485Serial.readBytes(buf, 8);

     Serial.print("DATA:");
    Serial.println(buf[3], HEX);Serial.println(buf[4], HEX);

    delay(1000);

}

help you with what? ... you said nothing about any problem

arduino coding . i wan to transmit data frame to my sensor  {0x06, 0x03, 0x00, 0x00, 0x00, 0x04, 0x45, 0xBE};  then sensor will send me its value. i am not able send proper command through arduino master. can check my code @jsotola


text:
cast from 'char*' to 'char' loses precision
Bit of a noob here. Im trying to use the sensor number (float) in my mqtt topic, but cant seem to get this right. Any help would be appreciated. Keep getting this error (cast from 'char*' to 'char' loses precision)
      char buffer2[5];

       dtostrf(sensor.sensor_no, 4, 2, buffer2);
     char* buffer4 = mqtt_topic + char(buffer2);

  dtostrf(sensor.dht22_t,0, 0, buffer);
     client.publish(buffer4, buffer); //Topic name

You can't add strings like that in C. Create a new empty buffer then use strcpy() and strcat() to fill it with data.

By adding strings together you are actually adding together the addresses in memory where those strings are.
Instead you need to create a new empty buffer and fill it with the contents of the other strings.
char buffer4[32]; // <-- Enough room for both strings and a NULL character

strcpy(buffer4, mqtt_topic);  // Copy in the first string
strcat(buffer4, buffer2); // concatenate the second string

Aaa. Thank you very much


text:
ESP8266 and WPA2 PSK network
I'm having some issues with esp8266 connecting to a wifi network. I'm testing with a hotspot from a mobile phone.  If I set the network to open (no security) my code below works without any issue. If I enable security, WPA2 PSK (I'm assuming that means the personal version) and add the password to the code it fails to connect. Any suggestions as to what the issue might be?
//load softserial library
#include <SoftwareSerial.h>

//set a boolean constant variable to true
//#define DEBUG true
const boolean DEBUG = true;

//RX (pin 2) goes to TX on esp8266, TX (pin 3) goes to RX on esp8266
SoftwareSerial esp8266(2, 3);

//LED pin anode (long leg) is 13 and cathode (short leg) GND
int LED = 13;

//LED status array - led 0 is OFF (0) at startup.
int ledarray[] = {0};

void setup()
{
  //set the LED pin as output
  pinMode(LED, OUTPUT);

  //open the serial port
  Serial.begin(9600);

  //start esp8266 module (note: your esp's baud rate might be different)
  esp8266.begin(115200);

  //reset esp8266 module
  senddata("AT+RST\r\n", 2000, DEBUG);

  //set esp8266 as access point mode
  //senddata("AT+CWMODE=1\r\n", 1000, DEBUG);

  //set esp8266 as wireless station mode (web server)
  senddata("AT+CWMODE=1\r\n", 1000, DEBUG);

  //set network SSID and password if esp8266 is activate as station mode else comment out
  senddata("AT+CWJAP=\"test\", \"\"\r\n", 6000, DEBUG);

  //get ip address for esp8266
  senddata("AT+CIFSR\r\n", 2000, DEBUG);

  //configure esp8266 for multiple connections
  senddata("AT+CIPMUX=1\r\n", 1000, DEBUG);

  //turn on esp8266 server on port 80
  senddata("AT+CIPSERVER=1,80\r\n", 1000, DEBUG);
}

void loop()
{
  //is the esp8266 sending a message
  if(esp8266.available())
  {
    //if received data from esp8266
    if (esp8266.find("+IPD,"))
    {
      //subtract 48 because the read() function returns the ASCII decimal
      //value and 0 (the first decimal number) starts at 48
      int connectionid = esp8266.read() - 48;

      //read the url sent by the client, look for the variable (?)
      String msg;
      esp8266.find("?");
      delay(100);
      msg = esp8266.readStringUntil(' ');
      String command = msg.substring(0);

      //HTML served to browser
      String webpage = "<title>LED WEB SWITCH</title>";
      webpage += "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">";
      webpage += "
LED WEB SWITCH
";

      //if command is T (variable passed in button link on webpage)
      if (command == "T")
      {
        //if position 0 of ledarray is 1
        if (ledarray[0] == 1)
        {
          //turn LED off
          digitalWrite(LED, LOW);

          //set position 0 of ledarray to 0
          ledarray[0] = 0;

          //add text to webpage
          webpage += "
LED STATUS OFF
";
        }
        else
        {
          //turn the LED on
          digitalWrite(LED, HIGH);

          //set position 0 of ledarray to 1
          ledarray[0] = 1;

          //add text to webpage
          webpage += "
LED STATUS ON
";
        }
      }
      else
      {
        //add text to webpage
        webpage += "
LED STATUS OFF
";
      }

      //add the button (notice the href has a '?T')
      webpage += "TAP";

      //create a senddata string to send the wenbpage to the esp8266
      String cipsend = "AT+CIPSEND=";
      cipsend += connectionid;
      cipsend += ",";
      cipsend += webpage.length();
      cipsend += "\r\n";
      senddata(cipsend, 500, DEBUG);
      senddata(webpage, 500, DEBUG);

      //create a string closecommand, append the connection id, a return and newline
      String closecommand = "AT+CIPCLOSE=";
      closecommand += connectionid;
      closecommand += "\r\n";

      //send the closecommane
      senddata(closecommand, 500, DEBUG);
    }
  }
}

void senddata(String command, const int timeout, boolean debug)
{
  //send the received command to the esp8266
  esp8266.print(command);

  //set int variable to the number of millisends since Arduino began
  long int time = millis();

  //while the time and the timeout is less than the number of millisends since Arduino began
  while((time + timeout) > millis())
  {
    //while the esp8266 is sending messages
    while(esp8266.available())
    {
      //display output in the serial window
      Serial.write(esp8266.read());
    }
  }
}

fwiw, it a lot easier to debug if you program the esp instead of the uno.

SoftwareSerial doesn't work reliable at 115200 baud. change the baud rate in AT firmware and in sketch to 9600 baud

I've tried following the advice here: https://arduino.stackexchange.com/questions/24156/how-to-change-baudrate-of-esp8266-12e-permanently
//start at 115200
esp8266.begin(115200);
//set to 9600 and start again
senddata("AT+UART_DEF=9600,8,1,0,0\r\n", 2000, DEBUG);
esp8266.begin(9600);
This does not seem to work, at 9600 it refuses to connect to the network and doesn't give any errors.

The solution to this was nothing to do with WPA2 PSK security or the baud rate being used. In my code I had a space between the WIFI server name and password (me correctly formatting). Apparently the ESP8266 does not like this one bit and the space needs to be removed - like so:
//set network SSID and password if esp8266 is activate as station mode else comment out
senddata("AT+CWJAP=\"test\",\"\"\r\n", 6000, DEBUG);


text:
Will an Arduino Uno be able to read 3x incremental encoders?
Encoders are quadrature 600ppr encoders with X2 counting. Therefore 1200 counts per revolution for each encoder. Is there an edge rate limit? I currently have one encoder hooked up using code with interrupts.

The answer to the title's question is likely yes.  But I think your real question is how fast can (and you need to name a specific platform) a 16MHz Arduino Uno read a GPIO pin.

How fast are the encoders rotating?

Here is an example of some code I used to read two encoders using pin change interrupts.  This is possible to do with one ISR since they all share a common port.  The key is it has to be short.  As long as you can keep all 6 pins from your encoder on the same port, this should be easy to extend to 3 encoders.  It might even work for four on one port.  Or you can make a use a second port and get 3 or 4 more depending on which chip you have.
volatile uint8_t lastPortRead = 0;

volatile int32_t leftCounter = 0;
volatile int32_t rightCounter = 0;

ISR(PCINT2_vect){

    uint8_t portRead = PINC;

    uint8_t whoFired = portRead ^ lastPortRead;
    uint8_t pinsDiff = portRead ^ (portRead << 1); // Will have bits 5 or 7 set if pins on right motor or left motor are diff.  Cleared if same.

    if (whoFired & LEFT_INT_MASK) {
        if (pinsDiff & LEFT_INT_MASK) {
            leftCounter++;
        } else {
            leftCounter--;
        }
    }
    if (whoFired & RIGHT_INT_MASK) {
        if (pinsDiff & RIGHT_INT_MASK) {
            rightCounter++;
        } else {
            rightCounter--;
        }
    }

    lastPortRead = portRead;
}

The answer to the title's question is likely yes. But it would appear the real question is how fast can a given Arduino read a GPIO pin.
Consider there are multiple Arduino platforms.  Each possibly using a different type of processors.  Likely those processors are running at different speeds.  To give a specific answer we need to assume a specific platform, processor and speed.  The current (3rd generation) Arduino Uno runs at 16MHz.  And the Arduino Due runs at 84Mhz.  Since most people use an Arduino Uno let us use it for an example.
In this arduino.cc forum thread it is commented that an Arduino Uno running at 16MHz can execute the "Digital Pin Read" function call in about 4.78us.  Rounding that up to 5us that would be 1/5E-6 or 200000 samples per second.  Likely this can be improved upon if code were written to directly control the processors register for the desired outcome.  This is usually considered a moderately difficult embedded programming task.  And well outside normal Arduino knowledge.  In addition, such code would likely no longer be portable between different Arduino platforms.

there are tags arduino-uno and arduino-due on the question and Uno is in the title. so why the intro?

Good point.  I usually use tags for searching.  Didn't occur to me that tags were used to frame the question.  I'll reword the answer.

and that is in microseconds not milliseconds for digitalRead. "A digitalRead() is about 3.6us. "

You are correct.  Looking through that forum thread I only see the reference for 4.78us.  I edited the answer again and removed the mistake.

so "Will an Arduino Uno be able to read 3x incremental encoders?" (parallel)

Probably.  Or, to put it another way, it would appear unlikely the encoder would create more than 100000 cycles per second.


text:
choosing prober controller to measure engin speed changes
In order to monitor engine speed changes in real time, sensor is detecting the motion of few magnets around a disk driven by the motor.
1st approach Hall effect sensor signal is regulated by LM393 comparative IC, resulting digital clean signal, connected as input to a selected pin then measuring the timing changes between of the signals to calculate the speed changes.
2nd approach is to connect hall sensor directly without modeling to a micro controller ADC, then process the digital noisy unclean signal which require much processing power than 1st approach.
Better approach are welcome, but the question is how to choose proper controller specs for such task

There is too much guesswork in trying to understand what you are asking.  Can you post some schematics, code and pictures?

The first option is way better than the second. Measuring a voltage with the ADC takes time and you don't really need the analog values in your code. (Though depending on the actual values you might not need a comparator befor it. The digital input pin acts as Schmitt Trigger. The only requirement for this is, that the signal range is greater than 0.3*Vcc to 0.7*Vcc.)
About the needed controller: That greatly depends on the speed, that the motor is running at (e.g. the frequency of pulses), and the way you are measuring it.

The easiest Arduino way is to attach an interrupt to the pin and increment a counter variable in it. Reading and resetting the variable in regular time ranges (using millis() will give you the pulse frequency and thus the speed. For this you don't need much extra functionality in the microcontroller. One with external interrupts or pin change interrupts is sufficient (almost all microcontrollers have those).
Another way is to utilize a hardware timer as counter. You can configure a timer of a microcontroller to get it's clock source from a pin. If you connect your sensor output to it, the counter will increment on every edge (falling and rising). The first timer of an Arduino is used by the Arduino core as time-keeper. You can use it to get the time component. Configure the second timer as counter, set it's value to zero, then start the timer and track the time passed using millis(). When the measurement time has passed, you read the counter value, reset it to zero and start a new measurement. While the hardware timer counts the pulses, you can calculate the speed with the number of pulses and the time passed and do whatever you want with it. This approach of course needs at least 2 timers (which most microcontrollers have, I think).

Of course the general speed of the microcontroller, meaning it's clock frequency, is also a concern. But this only becomes relevant, as you reach high pulse frequencies.
This answer is a general overview on how to go on. For a more specific answer, you should edit your question to also be more specific. For example you could include the expected pulse frequency.

Thanks chrisl for your adequate details, I'm concern if the hall sensor direct connection without LM393 will be sufficient so each changes will count.

on the other hand, I don't want to calculate only the speed, but also the real time changes "acceleration" that's why we put many magnet on the rotator not only one, to sense the changes in each rotation not every many rotations.

If it will work without the LM393 depends on the voltage levels of the signal. And what is important is the pulse frequency. What frequency do you expect?

frequency is below 1000 HZ, but my test for the Hall effect sensors available result in different voltage depend on the speed, lower speed means lower voltage

I didn't comprehend the difference between Schmitt trigger and comparator, but I noticed schmitt will keep only the larger wave while smalls will not be detected


text:
reading micro SD card directly from PC
Is it possible to read a microSD card (on a breakout) through the USB port on the arduino? or perhaps another USB port I could attach to the breakout?  Basically, I would like to read data off the card with my laptop without having to go and remove it each time!

yes, that is possible

@jsotola Really? I wonder how (I thought the Arduino did not support USB to be used within a sketch, at least by default).

@MichelKeijzers, use the serial connection for the data transfer ... the OP inquired about the possibility of data transfer ... i do not see a requirement to emulate a flash drive

@jsotola ok than I think we have about the same idea (I deleted my answer based on your comment, now undeleted, shoot at it if it is incorrect though).

doesn't every PC have a SD card reader?

@201, Just in case it is not clear from the comments or answers:  USB contains many different protocols.  The Arduino uses the USB serial protocol.  An SDCard uses the USB mass storage protocol.  Not many, if any, USB peripherals can switch between protocols. I see you have not picked a correct answer yet.  If you want me to elaborate in yet another answer - add a comment stating so.

@Juraj Probably yes, but I think he does not want to remove the SD card ... actually in my project I also am thinking about building the SD card somewhere inside the device (thus not accessible from outside) because it makes building it in an enclosure much easier.

@MichelKeijzers, In my project I show/download the files from SD over a web server

@juraj sounds like a great idea!

@MichelKeijazers can you share the program with me?

@st2000 another protocol like SPI right? can you give me more info about how to do this?

@201, I think Majenko answered your question the best.  But, to add a bit, for complex protocols, there are physical layers / upper layers (USB) and lower layers (USB serial or USB mass storage & others).  The SDCard will need to use USB mass storage and the Arduino interface always uses USB serial.  Yes, at the SDCard one of two possible physical layers is SPI.  But by the time you get to the USB  port, an SDCard is using USB mass storage.  And, unfortunately, that is not what the Arduino supports on its USB port. The Arduino is of course supporting USB serial.

@st2000 So,it is possible to use SPI  to make connection between SD card and Arduino serial, right? the project i'm working on demands the last year's data stored in SD card and show it on PC without ejecting the SD card from shield data logger... it sound complicated to me...

Although, I think i found the answer, i can just ask the serial port to write the file saved in SD card for me with this command : Serial.write(dataFile.read());

so here is another question... can i save data for along time in my SD card? for example for one year?

This web site claims ~10 years.

@st2000 thank you so much

It would be very useful, but afaik this is not possible, since the Arduino sketch you write communicates to the PC via the serial interface only.
The IDE/Arduino driver can use the USB to write your sketch and use the USB for communicating, but for sketches the USB (as direct medium) is not possible.
The SD card will not show up as a specific drive/map/folder on your PC.
Since you want to read the SD card, write in your sketch code to transmit the file(s) you want to send to the PC, to transfer them by UART, and on the PC write a program that reads the serial port and processes it.

In general that's possible. But you can't read the sd card through the arduino's usb port. Instead you have to read the sd card via another protocol, e.g. SPI (look for the apropriate library) and send it to the pc via serial. You'll need software on the pc side to write the content that was read from the arduino to a file.
Take a look at the SD card tutorial to see how to read it.

so, if i want to lets say read the last year history of my data from data logger, can i use SPI to make this connection between SD card and arduino? do you have an example code that may be useful?

There are examples and tutorials out in the internet (I found one for you). But may I ask why you want to use an arduino? Don't you have an sd card reader to use with usb on your laptop?

@201, and how is it wired for data logging? not over SPI?

you're right, but that's actually the project i'm working on right now..

It can't be done with an Arduino, but it can be done with other microcontrollers. You need a microcontroller with a direct USB ("native") connection plus a USB stack that is capable of acting as a USB Mass Storage Device.  Something like the Teensy or chipKIT series of boards can do that.
Then you can write software that will, on command, detach the SD card from your normal sketch operation and re-attach it to the MSD device in the USB stack. You can then read and write to the SD card (though your sketch otherwise cannot access it) as much as you like - then "unmount" the MSD device and detach the SD card from it, at which point your sketch is then free to re-attach itself to the card and start using it again.
Note that the important thing here is that only one functionality can work at a time - either you can read and write the files on the card with your sketch, or you can export the device through MSD. Never both. That way leads to filesystem corruption and loss of data.


text:
sending specific date's data from data logger shield to serial port
I was wondering if it is possible to save lots of data( exp: one year data) in data logger shield and then read them from serial port without ejecting the SD card... this part of my question is fine... the main subject is that i want to read specific date's data from the logger... To explain this better, lets say you have a humidity sensor and saved it's data for a year. Now you want to send the last 6 month's data to your phone via bluetooth. Is it possible?
Also, i wanted to use the circular buffer but that doesn't seem like a good idea because it's costly... any ideas will be such a great help.

how many lines are logged in one day?

Is it important? i wanted to lower the daily sampling, so maybe 2 times...

ok, it is not too much for one year. to copy part of the file to Serial you would read the file line by line from the beginning and start printing after you find the line with the requested start date.

I see a few questions (reading specific data from an SD) and the circular buffer; I think these are two different 'problems'.
Reading specific data from an SD
It depends how you save your data. Do you make one big file, or you create daily a new file for example?
Assuming the last, it's relatively easy, just sent the file contents of the files within a certain date.
In case you have a big file, you need to parse the file, in specific the time stamps you have to include in the file, and send everything within certain dates.
If this takes too long parsing, you could create a second file that contains the starting points (e.g. byte offset) for every day. So e.g. Jan 1 -> 0 means Jan 1 starts at byte 0, Jan 2 -> 3633 starts at byte 3633; you can use some kind of seek function to start reading the data file starting from date; and continuing also checking the end date's byte offset.
You can get the time stamp of a file:
void dateTime(uint16_t* date, uint16_t* time)
{
    DateTime now = rtc.now();
    // return date using FAT_DATE macro to format fields
    *date = FAT_DATE(now.year(), now.month(), now.day());
}

You can start reading from a certain position in a file by using the fseek function, see https://www.arduino.cc/en/Reference/FileSeek.
Circular buffer
This relates to sending bytes (via a peripheral/bluetooth). It is not costly at all. What you do is create a circular buffer (e.g. 50 bytes or whatever). Than you start writing bytes into it (which you copy from the SD file increasing the buffer space. Than you start sending bytes from it, decreasing the buffer space.
I never used Bluetooth, so I don't know how the packet (and size) is sent; if you can just sent packages of a certain or fixed length,  you don't need a circular buffer, just keep reading e.g. 50 bytes, put it in a fixed array, send it, and load it again etc until all bytes are sent.

The idea was to ask for any data history i want through mu cellphone... I wanted to make different files with specific time stamps but then if the period i want wasn't in the files it would be a problem...

And another thing i don't know is how can i specify a certain starting point for my files?

You can get the time by using:
void dateTime(uint16_t* date, uint16_t* time) { DateTime now = rtc.now();  // return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());

Can i also get the period of different times?

So after you write a file (each day), or for the last time once per day, you can get the date back, although it might be even easier to write the date in the file name (data_yymmdd.log)

Not sure what you mean … if you need 5 to 10 December, just read out the 5 files and send them (?)

About reading not from the start, see https://www.arduino.cc/en/Reference/FileSeek

yes for example from 5 to 10 December. how can i do that?

If you have a separate file for each day, read the 5dec file (in parts of e.g. 50 bytes or so), and send each packet, than do the same with the 6dec file etc.

How can i save each data in their own file? for example for 1 week, 1 month, etc. I mean the data from 1 week should also be in the data for one month... can you help me with the code?

That depends, better make some commands that send the information you need (like start/end period).


text:
Using functions in header files
I want to include a function in my sketch I moved to a .h file.
I did it as follows:
My code:
#include "header.h"

void setup() {
  fct();
}

void loop() {

}

My header:
#include "Arduino.h"
#ifndef MYHELPERS_H
#define MYHELPERS_H

void fct() {
// stuff
}

#endif

The same process seems to work for variables but the IDE says this function in not declared in this scope...
I don't understand what I'm doing wrong...
Thanks guys!

for me it compiles. do you have the header file as tab in IDE?

Where exactly does your header file lie? In the same folder as the main sketch? Or in the libraries folder?

This is not the way you separate your project in modules. In a header file you declare what your module offers publically. The implementation goes into another C++ file and this will be compiled separately. -- Please get a good book on basic C++ and/or Arduino programming and read it. This issue is far too broad to be answered in a SE/Arduino question.

This header file was created with the new file button in the Arduino editor and it resides in the same folder as the main sketch.

File->New, creates a new sketch

I found a solution somewhere else on internet...
This portion:
#ifndef MYHELPERS_H
#define MYHELPERS_H

Was not written correctly... "MYHELPERS_H" should've been replaced by the name of my file. Now it works just fine.

there is no relation between the include guard macro name and the name of the file. this answer is wrong.

It's weird but it fixed my problem

Maybe the guard macro name has to be the name using in the #include of the main sketch but it works now I have done this

no. #include takes a file name. and it doesn't care about the content of the file

Anyway, it worked

so change it back and you see it will still work

I'm on a work trip right now and my pc is home

Sorry Spyro, this answer makes absolutely no sense - downvoted.


text:
Arduino UNO R3 + SIM800L / NodeMCU via Hadware Serial. Possible?
I'm using Arduino UNO R3 with NodeMCU and SIM800L module. I have to connect these two devices to UNO and make a serial communication between them: UNO<>SIM800L and UNO<>NodeMCU.
Can I use GPIO0 and GPIO1 of UNO (RX, TX) to communicate with one of above devices?
Thanks in advance.

RX/TX is used to communicate with the computer over USB

Okey, but if I do it this way:

Upload program first.
Power off uno, disconnect from PC and then power ON.
Then connect for example SIM800L to GPIO0 and GPIO1.

?

yes. do you know that you can use the NodeMcu as Arduino?

Why both Uno and NodeMCU? For wifi?

NodeMCU for using it as Web Server.

that is OK, but what for is the Uno? NodeMcu is a development board with 8 io pins, I2C, SPI, PWM, ....

If all you need to do is communicate between the NodeMCU and the SIM800L, what do you need the Arduino for?
Connect the SIM800L directly to the NodeMCU and program the NodeMCU to do whatever communication is needed for the SIM800L.


text:
SIM900 module not reading Sim Card
I am using GPRS Shield for Arduino Uno with SIM900 module on it. I am able to communicate with the module just fine (using AT commands), but whenever I try to use a command which involves sim card (like AT+CCID) I get a message saying ERROR and that's it (while AT+CCID=? returns OK as it should).
So I wanted to ask can it be that I am missing out on some parameter on SIM900 module that would allow using sim card? And is it possible somehow to do a hard reset on all module's parameters (in the documentation a command ATZ is mentioned, but it doesn't seem to reset all parameters)?
Thanks in advance!

try the SIM card in a phone

The SIM card works just fine in my phone (it has PIN disabled as well). Also tried using different SIM cards on the SIM900 module, with same effects.

The "standard" modem reset string is AT&F0 - though whether the SIM900 supports that or not I have no clue.

Even after doing the factory reset with AT&F0 command, I get same results...


text:
Multiple MPU9250 Synced
I am interested in collecting data from 3 MPU9250 via I2C communication protocol. As I've read, I can collect measurements on the same I2C Bus from up to two MPUs. However, how can I collect Synced data from more than 2 MPUs.
And if not Arduino what do you recommend?

After a short view at the datasheet, it seems that a pulse at the FSYNC pin will trigger a measurement. You could tie all  MPU FSYNC pins to one digital output of the Arduino, so that the measurements are  triggered at the same time. Then read the data from the MPUs FIFO like normal

Thank you for your reply @chrisl can you elaborate on the data reading part?

The MPU uses a FIFO buffer for the data. So the time of measurement is not necessarily the same as the time of communication. Additionally there is the FSYNC pin. In the MPU9250 datasheet there is nearly nothing described about that pin, only the pin description:

11    FSY    Frame  synchronization digital input.  Connect  to GND  if  unused.

I would interpret this as: If you pulse this pin to high (active high), a measurement is started. I cannot garantee, that it works this way; I also only can look into the datasheet. For my answer I will assume, that the pin really works this way. You will have to test this yourself.
Based on that info I would propose the following solution (without being able to try it myself due to the lack of MPU):
Connect 1 Arduino digital output pin to the FSYNC pins of all MPUs. If you pulse this pin from LOW to HIGH (and then to LOW again after a short time to return to the passive state), the MPUs will start their measurements. Since they all get the same start pulse, they will do the measurement at the same time. (It may be, that you need to configure the MPU for this) When the measurement is done, the data will be placed in the FIFO buffer. Then you need to grab this data from all the MPUs over I2C.
Here come a trick, so that you can effective connect to a great number of MPUs: The address pin of the MPU is also checked during operation. This means, that you can change the address of an MPU during operation by connecting it's address pin to a digital output pin of your Arduino. Do this with every used MPU, one output pin for one MPU address pin. On the Arduino you set all the pins to the same output state (let's say LOW) to keep all the MPUs on the same address. You must not ever call this address through I2C. If you want to communicate with one of the MPUs, you output a HIGH at it's address pin. This specific MPU will change it's address, where you can now communicate like normal. When you are done communicating with it, just output LOW again. Now you can activate the next MPU for communication by outputting HIGH on it's corresponding address pin.
This way you have 1 inactive address and 1 active address, where the MPU's being there change based on your digital outputs.


text:
NRF24L01 based project freezes for no good reason
I have built and coded a low power NRF24L01 transmitter and receiver, for purposes of transmitting the temperature of the transmitter's environment. I have used an Atmega328P chip for the project. The project itself works well, but after some time, around 10 days or so, the transmitter goes silent.
During my initial troubleshooting, I have concluded that the system hangs up during NRF transmission, and since it's stuck in the transmission phase, it eats up all the battery and dies. For this, I'm also transmitting battery usage, and I have added watchdog timers in my temperature sensing and transmission phases. This has not solved my problem, and I'm stuck as of now.
Some bits of code:
My low power cycle:
 while (1) {
  wdt_reset();  //watchdog timer added for 8S. See the beginning of loop func for timer settings.
  Serial.print("Loop Start ");
  delay(50);
    //Blink only at every wakeup
    digitalWrite(redLed, HIGH);
    setTime = millis() + ( 1 );
    while ( millis() <= setTime ) {
    }
    digitalWrite(redLed, LOW);
    //Blink only at every wakeup

    Serial.println("Powerdown begins");
      delay(50);
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
    sleepCounter++;
    Serial.println("Powerdown over");
      delay(50);
     wdt_enable(WDTO_4S);     // enable the watchdog
  //Reenabling radio for test purposes

//end of radio edit
         Serial.print("Slept for ");
         Serial.println(sleepCounter);
    if ( sleepCounter >= postPeriod || sleepCounter == -1 || interruptState == true ){       ///|| true ) {
      sleepCounter = 0;
      interruptState = false;

      break;

    }

  }

  //Serial.println(micros());
  //Serial.println("DEBUG nRf Test");

  radio.begin();
//  radio.powerUp(); //power up the nRF24

  digitalWrite(redLed, HIGH);

  Set_nRFTX_Data (1);

  nRF_Send ();

In the Set_nRFTX_Data() function, I'm writing my temperature value to the buffer, as such :
   nRF_BufferTX [23] = b1;             // 24th byte the first byte of a two-byte value for precision (msb)
    nRF_BufferTX [24] = b2;              // 25th byte the second byte of a two-byte value for precision (lsb)

And in the nRF_Send() function, I'm sending it over NRF:
void nRF_Send () {

  radio.closeReadingPipe(address);
  radio.openWritingPipe(address);
  radio.stopListening();

  bool isDataTransfer;
  radio.write(nRF_BufferTX, 32);

  radio.openReadingPipe(1, address);
  radio.startListening();
}

If anyone's interested, I may share circuit specifications as well.

is setTime unsigned long?

@Juraj Yes, I define it as unsigned long setTime = 0;

There is a known common problem with some cheap chinese clones of the nRF24L01+ whereby they get stuck in TX mode waiting for an auto-ACK that never arrives. The only way out of it is to reset the nRF24L01+ board through the power-down/up commands.

@Majenko is correct.  I have not used nRF24L01+ for a period of 10 days like the OP, but this solution fixes short-term hangups occurring after a few minutes/hours.

what is the purpose of while ( millis() <= setTime )?

@Juraj , no real purpose other than having the code halt for 1 ms.

@Majenko Hi, thanks for the valuable info, but I'm already using radio.powerDown(); in my void loop cycle for low power modes. Wouldn't this turn it on and off every cycle anyway?


text:
ESP32 Hardware Serial Flow control and full espressif/arduino-esp32 support
I have a similar issue. I want to use the ESP32 with RS485.
I have used the Arduino  and this works well assigning pins, but it seems not to allow full use of the UART.
I see the new uarts in the ESP32 can support the direction control (RTS) of the direction pin and there is actually a hardware RS485 mode.
See the repository that the board package is based on:
https://github.com/espressif/arduino-esp32
Then
https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/include/driver/driver
uart.h
This shows we can actually have full hardware flow control, so no more guessing delays for controlling the DIR lines or getting interrupts when the send buffer is empty in order to know when to switch back to receive.
I found using board manager this did not all get installed, so I followed some tutorials on how to install it manually.
The board either doesn't appear at all, or I can't reference "uart.h".
Any ideas or examples?
Thanks,
Mark

I've got no problem simply including driver/uart.h and copy-paste code from the official RS485 example (https://github.com/espressif/esp-idf/blob/master/examples/peripherals/uart/uart_echo_rs485/main/rs485_example.c). See my example at https://pastebin.com/2PtWJvd6. What is your exact error message?

Also the documentation at https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/uart.html#overview-of-rs485-specific-communication-options and the example docs https://github.com/espressif/esp-idf/tree/master/examples/peripherals/uart/uart_echo_rs485 apply here.

Why would you guys delays for the dir line? Just flush() after sending any data.

your example was of great help solving the problem of driving RTS properly, thanks a lot!
I found a small bug in the code example, the data buffer is allocated in the loop() function instead of setup() and as a result, eventually the memory leak will fill-up all available memory.
Ciao!
Alessandro

Espressif and Arduino use the same UART numbering, and there are no hidden properties of hardwareSerial that are bound to it UART instance So it's possible to perform a reach-around and replace the arduino harwareSerial UART driver instance with an espressif RS485 uart instance and then use Arduinos hardwareSerial methods to communicate with the UART.
#include <Arduino.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <driver/uart.h>

#define ECHO_UART_PORT UART_NUM_1
#define ECHO_TEST_TXD   (25)
#define ECHO_TEST_RXD   (26)
#define ECHO_TEST_RTS   (27)
#define ECHO_TEST_CTS  UART_PIN_NO_CHANGE
#define BUF_SIZE        (127)
#define BAUD_RATE       (9600)

#if   ECHO_UART_PORT == UART_NUM_0
#define         SERIAL_485 Serial
#error  Serial is already committed elsewhere in this code

#elif ECHO_UART_PORT == UART_NUM_1
#define         SERIAL_485 Serial1

#elif ECHO_UART_PORT == UART_NUM_2
#define         SERIAL_485 Serial2
#endif

static const char *TAG = "RS485_ECHO_APP";

void setup() {
    Serial.begin(115200); //uses UART_NUM_0
    //configure UART_NUM_2 for RS485
    const uart_port_t uart_num = ECHO_UART_PORT;
    uart_config_t uart_config = {
        .baud_rate = BAUD_RATE,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .rx_flow_ctrl_thresh = 122,
    };

    Serial.println("Start RS485 application test and configure UART.");

    // start arduino serial port
    SERIAL_485.begin(BAUD_RATE);
    SERIAL_485.setTimeout(1+(10000/BAUD_RATE) ); // 10000 is 10 symbols per byte * 1000 ms per second

    // drop rhe Arduino installed UART driver!
    // we will replace this with a 485 capable driver.
    uart_driver_delete(uart_num);

    // Configure UART parameters
    uart_param_config(uart_num, &uart_config);

    Serial.println("UART set pins, mode and install driver.");
    // Set UART1 pins(TX: IO23, RX: I022, RTS: IO18, CTS: IO19)
    uart_set_pin(uart_num, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);

    // Install UART driver (we don't need an event queue here)
    // In this example we don't even use a buffer for sending data.
    uart_driver_install(uart_num, BUF_SIZE * 2, 0, 0, NULL, 0);

    // Set RS485 half duplex mode
    uart_set_mode(uart_num, UART_MODE_RS485_HALF_DUPLEX);

    ESP_LOGI(TAG, "UART start recieve loop.\r\n");
    SERIAL_485.printf("Start RS485 UART test.\r\n");
}


text:
Adafruit motorshield v2.3 not working
I want to connect my adafruit motor shield v2.3 to a touch board from bare conductive so that the motor turns when one of the electrodes is touched.
I've tested the touch part and that isn't a problem so i tested the motor shield on my arduino uno. I am using the DCMotorTest example and when uploading it doesn't give any errors. The shield is getting powered, but the motor isn't turning.
The motor does turn when connected to a 9v battery.
The motor doesn't turn when connected to motor shield without external power and VIN jumper connected.enter image description here
The motor doesn't turn when connected to motor shield with external power with and without VIN jumper connected.
/*
This is a test sketch for the Adafruit assembled Motor Shield for Arduino v2
It won't work with v1.x motor shields! Only for the v2's with built in PWM
control

For use with the Adafruit Motor Shield v2
---->   http://www.adafruit.com/products/1438
*/

#include <Wire.h>
#include <Adafruit_MotorShield.h>

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Adafruit Motorshield v2 - DC Motor test!");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz

  // Set the speed to start, from 0 (off) to 255 (max speed)
  myMotor->setSpeed(150);
  myMotor->run(FORWARD);
  // turn on motor
  myMotor->run(RELEASE);
}

void loop() {
  uint8_t i;

  Serial.print("tick");

  myMotor->run(FORWARD);
  for (i=0; i<255; i++) {
    myMotor->setSpeed(i);
    delay(10);
  }
  for (i=255; i!=0; i--) {
    myMotor->setSpeed(i);
    delay(10);
  }

  Serial.print("tock");

  myMotor->run(BACKWARD);
  for (i=0; i<255; i++) {
    myMotor->setSpeed(i);
    delay(10);
  }
  for (i=255; i!=0; i--) {
    myMotor->setSpeed(i);
    delay(10);
  }

  Serial.print("tech");
  myMotor->run(RELEASE);
  delay(1000);
}

https://i.sstatic.net/uzsEb.jpg

If you are using a 9V block battery: don't use it. These batteries are made for low power applications and can only provide a low current. Not fitting to drive motors

What should i use instead?

Many possibilities. For example a fitting number of AA batteries in series. Or a LiPo battery

You have two possibilities of powering the shield according to the adafruit documentation.
A: power the Arduino over the power plug (not the USB plug) of the Arduino and set the VIN jumper.
B: Leave the VIN jumper off and power over the power connector of the shield.
Don't try other possibilities. They may kill the shield or the Arduino.
The reason your motor doesn't turn is because you switched it off
myMotor->run(RELEASE);  immediately after you switched it on myMotor->run(FORWARD);.

Setting the VIN jumper is connecting the pins or leaving them not-connected?

I'm unsure, if I understood  your question correctly. If I do, the answer is: Setting the VIN jumper means taking a jumper or other conducting materials and putting it on/between the two VIN pins. These are the two pins close to the power connector on the shield. If they are connected together, the power of the Arduino (but only from the ext Power plug, not from the USB connector) is connected to the power management of the shield and you don't need extra power on the shield.

Yhea that's what i meant sorry for formulating the question so werid. When i leave the VIN jumper and connect the shield to o 9v battery the shields led lights up, but the arduino doesn't

When connecting a couple of AA batteries the same thing happens, i also changed the M1 to M4 but this also didn't do anything

If I understood the documentation correctly, the Arduino must be powered separately even if you power the shield externally. But you can power the shield from the arduino if the VIn Jumper is set on the pins. Then you don't need to power the shield externally.

I just used a different motor-shield and it works now, thank you all for your replies and research in this!


text:
Problem with power supply ws2812b Arduino 5v vs 12v
I have an Arduino wired to ws2812b with 10 100uF capacitors and 2 1000ohm resistors(picture). When I'm plugging 5v power supply everything is working when I plug 9v battery everything is fine but when I'm plugging 12v power supply in one moment leds stops.(NeoPixel standardtest example. How I can power the ws2812b by 12v

I'm rather sure, that WS2812B LEDS are 5V devices, so powering them with 12V will probably destroy them. You didn't show us, how you connected the power supply. Please don't try to power the strip through the Arduino. It will very likely kill the voltage regulator or the protection diode or both on your Arduino.

Your regulator on the Arduino is probably overheating.

The regulator on an Arduino is likely analog.  On this Arduino Uno the regulator is an analog NCP1117ST50T3G as seen in this schematic.  On page 2 of the NCP1117ST50T3G spcification it is stated:

Internal thermal shutdown protection limits the die temperature to
  approximately 175°C. Proper heatsinking is required to prevent
  activation.

Being an analog power regulator, the difference between the input voltage and the regulated output voltage eventually turns into heat.  This may explain why a 9 volt source may work (drop is only 9V - 5V = 4V) while a 12 volt source may not work (drop is 12V - 5V = 7V).
Consider using a 5 volt power source avoiding the Arduino analog power regulator.  Or, if the only source is 12 volts (for example an automobile), consider using an external switching or buck power supply to convert the 12 volt down to 5 volts and again avoiding the Arduino analog power regulator.  Lastly, it should be possible to still power the Arduino with 12 volts and use its internal power regulator to only power the Arduino. Then independently power the LED strip using an external power regulator.  This last option will likely have the benefit of eliminating the capacitor bank seen in the question and associated components.

See if arduino works with strips disconnected
Assuming that you are connecting your 12V to the breadboard
Do not try to use Arduinos voltage regulator to supply something this massive as LED strip (if you did, then arduinos voltage regulator would be burned by now)
If arduino works with strips disconnected
If it does:
check the voltage of the strip if its not written check if each LED has its own resistor. If it doesn't you may see Two or three LED per resistor in series That usually means 12V
This would mean that LEDS would have been dim when on 5V
Then you need to drop the voltage(difficult, I am not sure if even LM350A is strong enough)you can try putting 100 ohm resistor before and across the LED strip this will not be sustainable, but might light the LEDS bit for a bit.
if it works with strips disconnected:
If it doesn't:
Does arduino start?
If it does. see first half of this message
If it doesn't: Does arduino start when connected via USB? (Disconnect from breadboard for this test) if it doesn't board is damaged
if it does you have burned your voltage regulator.
I am not sure what are those capacitors there for. LED's arent very picky about the supply and standard CE marked (legaly) 12DC supply would be suitable for both arduino and the strip supply out of the box


text:
My millis() code doesn't work
I am doing a project with bluetooth and an LED. I wrote a code which supposed to turn on an LED after it receives a byte of value 1 after 5 seconds, unless it receive another byte of value 1 (which make it need to wait another 5 seconds) so that if it receive the byte periodically, the LED doesnt turn on, and only turn on if byte value sending is stopped/bluetooth disconnected. I wrote this code and it doesn't seem to work. It doesn't even turn on the LED after 5 seconds. Can you help me spot the mistake here?
unsigned long timebetween=5000;
unsigned long lastreceivedtime;
int value;
bool timerReady = false;

void setup() {
  pinMode (11,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  unsigned long currentMillis = millis();
  if( Serial.available() >0){
    value = Serial.read();
  }
  if ( value ==1 ){
    lastreceivedtime = currentMillis;
    timerReady = true;
  }

  if(timerReady) {
    if((unsigned long)(currentMillis - lastreceivedtime) >= timebetween){
      digitalWrite(11, HIGH);
      delay(90);
    }
  }
}

how do you know what value Serial.read() returns?

I don't think anything in your code is going to work.
First,
 you are asking the serial.Read to return an integer if it is working.  You might want to change that to a Boolean.
Second,
You are asking for a 1 and only a 1 to make your next if statement true.  If the serial.Read is working the chance it will only return a one, I think is very low
Third,
On the IF statement for setting timerReady. You will set that at a new number each time the program runs through, with the 90ms delay in the last IF statement, it looks like your timer will reset at about every 95-100ms
Fourth,
I think your last 2 IF statements are wrong, I think you want
if(timerReady==true) {
    if((currentMillis - lastreceivedtime) >= timebetween){
      digitalWrite(11, HIGH);
      delay(90);

If you do get this working you might need to set the Boolean back to false and move pin 11 to low at some point.

Thanks a lot! I modified some of the lines and it worked.

Why is it a problem to save the return value of Serial.read() in an int variable? That is actually the type, that gets returned by this function, so why using a boolean here?

Because the only reason he is looking at the serial.Read is to see if it is there and working, he doesn't really care whats there, just that it is working.  The serial.Read is being used as a light switch, on or off, TRUE or FALSE


text:
Press On Hold Off Power Switch
Hi everyone I am hoping someone here can help me.
I am trying to make an arduino turn my project on and off.Using a relay.
I am looking for it to act like a computer power button.
A short press to turn on and them stay on and a long press (say 5 sec) to turn off and then stay off till button is pressed again.
I would like it so that the project can not be accidentally turned off
Can anyone please help.
Thanks

What have you tried so far, and what part is giving you difficulty? If you need a hint to get started, you code will need to store the relay state (on/off), measure the time of  each button-press, and compare the time to the length of a short-press or long-press, depending on the current state.

Hi JRobert after spending the best part of 2 days looking around the web. Reading posts looking at you tube videos. I cant find an example to do this. The Arduino IDE as a button on, off, example in it. But I need a long press to turn off. To prevent accidental power off. Basically I want a pin to go high on a short press. and only go low if it sees a long press of say 5 secs. So if the button is pressed accidentally it will do nothing unless the press is long.

Here is a test sketch that I wrote for a different question. The other question's requirement was for a short press (minimum 100ms) to turn on an LED, and a long press (1 second) would turn it off. With a slight modification of this sketch, it may work for you. You will need to install the Bounce2 library.

// Press and hold button for 100 ms to turn LED ON.
// Press and hold button for 1000 ms to turn LED OFF.
#include <Bounce2.h>

byte buttonState = 0;
const byte ledPin = 3;
const byte buttonPin = 2;
const unsigned long debouncerInterval = 50;
unsigned long buttonPressedTime = 0;
unsigned long currentMillis = 0;

Bounce debouncer = Bounce();

void setup(){
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  debouncer.attach(buttonPin, INPUT_PULLUP);
  debouncer.interval(debouncerInterval);
}

void loop(){

  // Get the current time.
  currentMillis = millis();

  // Check if button was pressed or released.
  if(debouncer.update()){

    // Pressed.
    if(debouncer.read() == 0){
      if(buttonState == 0){
        buttonState = 1;
        buttonPressedTime = currentMillis;
      }
    }

    // Released.
    else{
      buttonState = 0;
    }
  }

  // Turn the LED ON or OFF.
  if(buttonState == 1){
    if(currentMillis - buttonPressedTime >= 1000){
      digitalWrite(ledPin, LOW);
      buttonState = 0;
    }
    else if(currentMillis - buttonPressedTime >= 100){
      digitalWrite(ledPin, HIGH);
    }
  }
}

Thank you so much for your help it works great. I just changed the buttonPreeedTime from 1000 to 5000 and it dose everything I wanted... Thank you so much

To clarify the problem, do you want to control ON OFF using Arduino? It is very simple. Please read this simple tutorial, and modify it according to your needs.

This is not what @David Boswell is trying to do. A short button press turns on the relay, and the user must press and hold the button down for 5 seconds to turn the relay off. The button in the link of the tutorial turns the relay on, then automatically turns the relay off after 5 seconds has elapsed.

@VE7JRO yes of course with small modification. jees.

You hit the nail on the head..VE7JRO. that is what i need to do. Press and hold to turn off


text:
How to create an array from serial.read?
I'm working on a audio-reactive lightinstallation with 16 LED lights.
In Max MSP I analyse my audio and split the frequencies in 16 'parts'.
I store these parts in a message of 16 ints, either 1 or 0 (on of off).
Every time a new frequency is detected the message updates and puts out a new int from 16 numbers (for exampe 1000100100110101).
I receive this number in my serial monitor of my Arduino Uno.
I want to put this 'incomingValues' in an array so I can check if a number/frequency is 0 or 1. When it's 1 I can turn on my relay/ light.
The 'incomingValues' is changing quite quickly but that shouldn't be a problem right?
I tried multiple things to create an array and update this every time a new serial message is coming in but I'm not used to work with Arduino so I could need some help.
Thanks! :)
Here is my code:
int counter;
int incomingValues = 0;
int lights[16];

void setup() {
  Serial.begin(9600);
  counter = 0;
  pinMode(13, OUTPUT);
}

void loop() {

  boolean newValue = false;

  while (Serial.available() > 0) {

    incomingValues = Serial.read();
    Serial.print(incomingValues);
    counter = counter + 1;

    newValue = true;
  }

  if (newValue) {
//    delay(50);
//    lights[counter] = incomingValues;
//
//
//    Serial.print(lights[0]);
//
//    for (int i = 0 ; i < 16 ; i ++) {
//      Serial.print(lights[i]);
//    }
//    Serial.println("");
//    newValue = false;
  }

  if (counter > 15) {
    counter = 0;
    Serial.print("\n");
  }

  if (incomingValues == 1) {
    digitalWrite(13, HIGH);
  } else if (incomingValues == 0) {
    digitalWrite(13, LOW);
  }
}

so, what is the problem?

You already save the data in the lights array (if you uncomment the newvalue if statement). Where exactly do you need help? What doesn't work as how you indended and what does it actally does?

If you are able to send the message as 16 chars, followed by a newline, then here is a test sketch that might work for you. Use the Serial Monitor to send the 1000100100110101 data. Please ensure you have the Serial Monitor set to send a Newline Only.

// Valid input data from serial is 16 chars followed by a newline.
// 1000100100110101
const byte bufferSize = 17;
char inputBuffer[bufferSize + 1];

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

void loop(){

  if(Serial.available() > 0){
    byte bytesRead = Serial.readBytesUntil('\n', inputBuffer, bufferSize);
    if(bytesRead == 16){
      for(byte i = 0; i < 16; i++){
        if(inputBuffer[i] == '1'){
          Serial.print("on ");
        }
        else{
          Serial.print("off ");
        }
      }
      Serial.println();
    }
    else{
      Serial.println("Invalid data length.");
    }
  }
}

Thanks @VE7JRO, it does the job :)
const byte bufferSize = 16;
char inputBuffer[bufferSize + 1];
int myDelay = 20;

void setup(){
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);

}

void loop(){

  if(Serial.available() > 0){
    byte bytesRead = Serial.readBytesUntil('\n', inputBuffer, bufferSize);
    if(bytesRead == 16){
      for(byte i = 0; i < 16; i++){
        if(inputBuffer[0] == 1){
          digitalWrite(13, HIGH);
          delay(myDelay);
        }
        else{
          digitalWrite(13, LOW);
        }
        if(inputBuffer[1] == 1){
          digitalWrite(12, HIGH);
          delay(myDelay);
        }
        else{
          digitalWrite(12, LOW);
        }
      }
      Serial.println();
    }
    else{
      Serial.println("Invalid data length.");
    }
  }
}


text:
What's the relation between arduino standard library and esp8266 library?
Can I only use the Arduino standard library, without touching any esp8266 related header files?
I tried to connect to WiFi , succeeded with ESP8266WiFi.h header, but failed with  Arduino library WiFi.h.
I follow this https://www.arduino.cc/en/Tutorial/ConnectWithWPA WiFi connecting tutorial but the board seems to reboot repeatly (I don't understand the error of course. I know nothing about hardware).
My board is ESP8266 V3 ESP-12N F NodeMcu Lua CP2102

the ESP8266WiFi library is based on the Arduino WiFi library so there are very similar functions so code can be ported between different WiFi libraries for Arduino.

the ESP8266WiFi library has examples in IDE Examples menu

The WiFi shield and an ESP8266 with any of several popular WiFi services firmwares are different pieces of hardware, each of which can provide WiFi services to another device connected to it, such as an Arduino Uno. Their interfaces are different, despite that they could be used to do similar jobs - offloading the WiFi communications from the Arduino - and the two libraries are written to drive each of them, respectively.

Ah I see. That official WiFi.h library is merely for the Arduino WiFi shield "extension" board.