What is the relation between Arduino's clock and possible VGA resolution?

I doubt if that would be fast enough. See my thread about connecting to a VGA monitor.

Borrowing from that page, so as to not make a link-only answer ...

For 640x480 pixels of active video you have something like this:

Vertical Sync

Let's start with the vertical sync pulses. In fact, we'll show how all the timing data can be derived from three figures:

The screen refresh rate (eg. 60 Hz)
The screen resolution (eg. 640 x 480)

So what is the refresh rate? It's the rate at which the entire screen is redrawn. If you ever looked at Windows screen resolution you probably saw something like this:

That's the refresh rate: 60 Hz (60 times a second). This figure was probably originally chosen because it is the mains frequency in the USA, so that would minimize the artifact of mains hum bars appearing on the screen, in the days of CRT monitors.

The other figure of interest is the screen resolution.

In our case we are going for the minimum we can (640 x 480) and seeing where those figures lead us.

Starting with the refresh rate, a 60 Hz refresh rate will require a "vertical sync" pulse 60 times a second, or a period of 1/60 (16.66 ms).

Generating vertical sync pulses

This code in my VGA output sketch generates the vertical sync pulses:

  // Timer 1 - vertical sync pulses
  pinMode (vSyncPin, OUTPUT);
  Timer1::setMode (15, Timer1::PRESCALE_1024, Timer1::CLEAR_B_ON_COMPARE);
  OCR1A = 259;  // 16666 / 64 uS = 260 (less one)
  OCR1B = 0;    // 64 / 64 uS = 1 (less one)

The clock period is 62.5 ns (1/16000000). By applying a prescaler of 1024 the timer counts up once every 64 µs. So to get a period of 1/60 of a second (16666 µs) we need to count up to 260 (16666 / 64 = 260). Since the timer counts are zero-relative we set OCR1A to count up to 259. This sets the frequency of Timer 1.

Then we need to set the pulse width by putting the correct value in OCR1B. We want a pulse width of two lines. One line is 1 / 60 / 525, namely 31.7 µs. So two lines would be 63.4 µs. This is close enough to exactly one timer count (64 µs). So OCR1B is set to zero (being zero-relative, making it zero gives a count of 1).

Timer 1 is configured to "clear B on compare" which effectively means that it toggles the output pin (D10 on the Uno) so it is high for the duty cycle width (64 µs) and low the rest of the time. If you wanted the opposite sync pulse polarity, change CLEAR_B_ON_COMPARE to SET_B_ON_COMPARE.

The timer is also set up to generate an interrupt, which is used to tell the code that we are starting another vertical cycle, by setting the line count to zero:

ISR (TIMER1_OVF_vect)
  {
  vLine = 0;
  messageLine = 0;
  backPorchLinesToGo = verticalBackPorchLines;
  } // end of TIMER1_OVF_vect

Horizontal sync

Horizontal sync pulses tell the monitor when to start drawing each line.

To calculate the horizontal sync frequency we need to divide the overall frame rate (60 Hz) by the number of total lines (525 if you count the sync pulse itself, and the front and back porches).

In other words:

 (1/60) / 525 * 1e6 = 31.74 µs

We also need to know the sync pulse width. That is documented to be 96 pixels, so we need to know the width of one pixel. That would be the figure above, divided by 800 (being the total screen width including the sync pulse, and front and back porches).

Thus that is:

((1/60) / 525 * 1e9) / 800 = 39.68  ns
1 / (((1/60) / 525 * 1e6) / 800) = 25.2 MHz

So our pixel width is 39.68 ns and the pixel clock is 25.2 mHz.

The horizontal sync pulse width is 96 pixels, so we want a pulse of:

96 * 39.68 ns = 3.8 µs

Generating horizontal sync pulses

Now we are ready to set up the timer for the horizontal sync pulses:

  // Timer 2 - horizontal sync pulses
  pinMode (hSyncPin, OUTPUT);
  Timer2::setMode (7, Timer2::PRESCALE_8, Timer2::CLEAR_B_ON_COMPARE);
  OCR2A = 63;   // 32 / 0.5 µs = 64 (less one)
  OCR2B = 7;    // 4 / 0.5 µs = 8 (less one)

The clock period is 62.5 ns (1/16000000). By applying a prescaler of 8 the timer counts up once every 0.5 µs. So to get a period of 32 µs we need to count up to 64 (32 / 0.5 = 64). Since the timer counts are zero-relative we set OCR2A to count up to 63. This sets the frequency of Timer 2.

Then we need to set the pulse width by putting the correct value in OCR2B. We want a pulse width of 96 pixels (3.8 µs). So OCR2B is set to 7 (being zero-relative, making it 7 gives a count of 8, which is 4 / 0.5).

Again, if you wanted the opposite sync pulse polarity, change CLEAR_B_ON_COMPARE to SET_B_ON_COMPARE.

The timer is also set up to generate an interrupt, which has the sole purpose of waking the processor up from sleep, so it can draw each line with exactly the same delay after the pulse. If it wasn't asleep, there would be a variation of two to three clock cycles (since an interrupt cannot occur during a single instruction) and this gives very bad-looking "jitter" on the screen.

ISR (TIMER2_OVF_vect)
  {
  } // end of TIMER2_OVF_vect

Pixel data

Now things get tricky ...

Let's see how long we have to draw 640 pixels:

((1/60) / 525 * 1e9) / 800  * 640 = 25396.82 ns (25.39 µs)

It just can't be done on this processor. The clock period itself is only 62.5 ns, so there is no way we can output a pixel every 39.68 ns (that is: 25396.82 / 640 = 39.68).

The fastest way we can get bits "out the door" is using the SPI hardware. That can run at a maximum clock rate of twice the system clock, that is, one pixel every 125 ns. So we will have to settle for having the pixels 4 times as wide. A horizontal resolution therefore of 160 pixels. Since we will display 8-pixel characters, that gives us 20 characters per line.

Summary

Even at 25 MHz processor speed (which exceeds its spec) you won't be able to clock out pixels fast enough for 640 pixel width (since the fastest SPI speed is half the processor clock speed).

  I would expect that so long we can feed the signal fast enough that would be enough.

That's the tricky bit. To output data you have to do more than merely send it. You have to read it from memory, so it would take a least a couple of clock cycles to do that.

Example of working at that resolution

A screen shot of my sketch in action (160 characters wide - 640 pixels and 30 characters high - 480 pixels, which is 16 pixels each as they were "doubled" in height to make them look in proportion). The font data was 8x8 pixels, and thus they appear as 16x16 on the screen.

  So does that mean that there really isn't a direct relation between clock speed and resolution? Other than, the clock must be faster than this

To work even at that speed the processor speed needs to be a multiple of the VGA clock, or close enough for the monitor to accept. (Looking at my figures the pixel rate is not in fact a multiple of 39.68 ns, so I am guessing that my monitor was able to adjust).

You could get better results by having a system clock which was an exact multiple of 39.68 ns (around 25 MHz - precisely 25.201613 MHz) - which is what you suggested in the question. However that just gives more accurate timing, you would still get similar resolution to what I show here.

So yes, to work on more monitors you should have a direct relation between clock speed and resolution.

I seem to have a 25.175 MHz crystal in my parts drawer, so perhaps I experimented with this a while back. Of course, you have to recalculate the other timings if you use that, and the processor is running out of spec.


this is exaclty waht get are supposed to do. Use a POST or use a redirect; a POST is way better as the "back" button of the browser will take care of it


ESP8266 - ESP01S with relay. Toggling the relay with http (GPIO0) and GPIO2 at the same time

Contrary to esp-01, on the esp-01S io 0 and io 2 pins have a pull-up resistor.
Wire a button between io 2 and ground and you will read LOW if the button is pushed.
Use a state variable for the state of the relay, don't read back the pin (does it even work to read the state of an output pin with digitalRead on esp8266?).


Sending sine wave from MATLAB and reading on Arduino Uno

No, you can't. The Arduino Uno has no analog outputs to start with and,
as you guessed, it cannot run two programs at the same time.

Maybe you should search for a solution of the initial problem instead.
You should be aware that you cannot get consistent timings with
analogRead(). You will have to read the datasheet of the ATmega328p,
especially the section dedicated to the ADC. Then you will configure the
ADC yourself, at the register level. It has a feature called
“auto-trigger” which is intended to provide perfectly consistent
timings. This is what you are looking for.


Measure cycle count and time of Digital Input

You don't need to do anything on HIGH to LOW. For example, if you are counting how often a door opens you don't also need to count how often it closes, because it must close before it re-opens.

I don't see the point of the interrupt since your code is doing nothing else than checking if the interrupt occurred, so it may as well be checking if the input has changed anyway. This code is simpler:

const int MoldInput = 2;

int lastMoldState = 0;
unsigned long startTime = 0;
unsigned long TotalTime = 0;
unsigned long CycleTimeCounter = 0;

void setup() {
  pinMode (MoldInput, INPUT);
  Serial.begin(115200);
}

unsigned long lastReportedCycleCount = 0;

void loop() {
  int MoldState = digitalRead(MoldInput);
  if (MoldState != lastMoldState) {
    if (MoldState == HIGH) {
      CycleTimeCounter++;  // count times it was high
      TotalTime += millis() - startTime;  // add up time interval
      startTime = millis ();
      delay (100);    // debounce
    }  // end of state being HIGH
    lastMoldState = MoldState;
  }   // end of state change

  if (CycleTimeCounter % 10 == 0 && CycleTimeCounter != lastReportedCycleCount)
    {
    Serial.print (F("Average time after "));
    Serial.print (CycleTimeCounter);
    Serial.print (F(" cycles is "));
    Serial.print (TotalTime / CycleTimeCounter);
    Serial.println (F(" milliseconds"));
    lastReportedCycleCount = CycleTimeCounter;
    }
} // end of loop


That version of the IDE (it seems to change from version to version) differentiates between includes with <...> and includes with "...".

If you use <...> it only looks in the system and library areas.  If you use "..." it also looks inside your sketch.

So in your main INO file change the LED include from:

#include <LED.h>

To:

#include "LED.h"

and it should compile.


Have you tried the turning just running a simple program to check if the led still works, such as

void setup () {
pinMode( 13, OUTPUT );
}
void loop() {
 digitalWrite( 13, HIGH );
 delay(1000);
 digitalWrite(13,LOW);
 delay(1000);
}


Arduino Nano + RC522 + w5500 Ethernet Module

If both modules use SPI then they should each have a separate pin connected to the slave select.

This lets you select which module you are talking to every time you start a communication. If the modules are well behaved then its MISO pin will be in high impedance when it is not selected instead of pulling it low or high trying to send data.

If it is not well behaved then you will need to add a buffer.


Build an improved GSM antenna for arduino mkr gsm 1400

On one end of the MKR GSM 1400 is a U.FL antenna connector.  To that you need to connect a U.FL To Female SMA Adaptor.  That adaptor can then screw into an SMA GSM Antenna of your choice.


How can I make the Serial Monitor work with the Serial Commands library?

You defined, that every command will end with \r\n. So you need to choose "Both NL & CR" as line ending in the Serial monitor, so that it appends the line ending to your command. If you don't send the correct line ending, the library will think, that the command hasn't finished yet, and thus will do nothing, until it receives the correct line ending.


Endless loop on boot after reflashing ESP-12E with AT firmware

Full answer and writeup to the comments:

The error message is due to the bootloader trying to read the contents of its radio-frontend calibration data (hence the name rf_cal). It compares it with a magic number, 0x05, but fails because it reads 0xFF at that point. 0xff is an indication that you read data from flash which was erased. After erasing a flash-sector, the data in it becomes 0xff 0xff 0xff... Hence it seems as if the bootloader is trying to access the data from the wrong address, thus only reading erased flash data. The RF-calibration data is stored in the file esp_init_data_default.bin and must be flashed to the correct address in order for the bootloader to be able to read it.

The NodeMCU documentation  tells us the needed address for esp_init_data_default.bin given the size of the flash of our ESP module:

The bootloader messages

2nd boot version : 1.6
SPI Speed      : 40MHz
SPI Mode       : QIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)

indicate that the flashed firmware (or that what is overriden by esptool.py) uses the 8 MBit flash size. There should be two ways to fix this:

Put esp_init_data_default.bin to the address the 8Mbit (1 MByte) bootloader expects, which is 0xfc000
Force the usage of the 32 MBit (4 MByte) Flash map by giving esptool.py the parameter --flash_size 32m. This makes esptool.py overwrite a few bytes in the firmware (at 0x000000) to adapt the firmware.

By your comments, method one worked. If there are problems however with the flash or the firmware, consider also trying method 2.


How can I declare global array with its length stored in EEPROM?

You can't create variable length arrays in C. That's not how C works.

Instead you have to create an array that is big enough to store the maximum number of pumps you want to be able to deal with.

The array "size" is then just a number in a variable obtained from wherever you like (including EEPROM).

It doesn't matter if you don't use all of the array. The rest just sits there twiddling its metaphorical thumbs.

The other option, if you are only going to define the array once at startup, or very rarely change the size, is to use malloc():

uint8_t *pumps;
uint8_t nPumps = 0;

void setup() {
    nPumps = EEPROM.read(32);
    pumps = (uint8_t *)malloc(nPumps);
}

You can change the array size then with:

nPumps = 8; // for example
pumps = realloc(pumps, nPumps);

And dispose of the array with:

nPumps = 0;
free(pumps);

It's best to try not to change the array size once created, since that can make swiss cheese of your heap, and is not a friendly thing to do on a small microcontroller. If you can decide the array size once in setup and keep it the same all the time the program is running this is a safe operation. Otherwise it becomes risky.


You need to keep the ground plane away from the antenna. The rest of the module doesn't care (and having a ground plane under it can help with unwanted EMI).
Here's a design I did recently for a customer with the same module in it. It's placed near the edge of the PCB with the ground plane cut out around the antenna:

That layout is actually set up for either the small SMD, the SMD with PA+LNB or the thorugh-hole version. The important thing is that there is a nice big exclusion zone in the ground plane where the antenna is.


ESP8266MOD does not respond to my Uno (Custom board) AT+RST command

If it is a new ESP module, your problem is quite likely a baud rate mismatch, since you are seeing an LED response but getting no reply.

The last batch of ESP-01s I received defaulted to 115200 baud, but that is too fast for SoftwareSerial (SS). You'll need to change it to 9600. My answer to a related question describes one way to change it.

You could also change it with SS. You'd have to start off SS at 115200 baud, which will usually transmit OK; just ignore the apparent garbage that comes back. Then change SS's baud rate to 9600 to match, and you should have solid communication.

These are the three commands you need to send the ESP to accomplish the change:

AT                             # ESP should respond "OK"
AT+RST                         # Resets the ESP
AT+UART_DEF=9600,8,1,0,0       # Sets ESP UART: 9600,N,8,1,no flow ctl

Note: Your module might have been preset to some other rate than 115200, in which case you'll have to try various rates until you can get an intelligible reply. Once you do, set the default rate to 9600.


compensate weight due to acceleration (loadcells)

The force due to acceleration is: F = m*a
So to calculate the weight while accelerating the formula is:
F = mg + ma or F = m(g + a)
Note, of course, that a can be positive or negative depending on whether the elevator is accelerating or decelerating.
The trick here is to know what "a" is.  The best approach is probably to get an accelerometer and use its reading in your calculations.
By the way, the mass is always a constant here.  It does not change, in Newtonian Physics at least, due to acceleration.


What is a cheap way to measure co2 or o2 level in air?

Well, MQ 135 sensor is very cheap general air quality measurement device. It costs around 3$. There is another similar on AliExpress, not even worth mentioning. What is your budget? Gravity from Adafruit seems proper, yet it is at 56$. One that seems actually serious is K30 sensor, but that is around 100$. That 3$ stuff is general, and will work when temperature is constant, humidity is constant and Mars is aligned with Venus.

I think 56$ is ok if they want to have something proper. Remember that you get what you pay for.


char response[300];
tmp = "123";
snprintf(response, 300,
    "[{Name:'Furnace',Value=%s,Alarm={MinValue=%s,MaxValue=%s}},"
    "{Name:'Room',Value=%s,Alarm={MinValue=%s,MaxValue=%s}}]",
    tmp, tmp, tmp, tmp, tmp, tmp);

In other words, you should add, after the format string, as many extra
parameters as there are %s in the format string.

PS: This looks like JSON, but it is not really valid JSON.
The format below should give valid JSON:

"[{\"Name\":\"Furnace\",\"Value\":%s,"
"\"Alarm\":{\"MinValue\":%s,\"MaxValue\":%s}},"
"{\"Name\":\"Room\",\"Value\":%s,"
"\"Alarm\":{\"MinValue\":%s,\"MaxValue\":%s}}]",


How to connect Arduino Pro Mini with PC?

V-USB can be used to create a low-speed USB device in software, but you will need to program the chip before you can use it. It also has a number of caveats that must be adhered to regarding electrical and software specifications, so it not the best choice for an absolute beginner.

A USB-UART bridge (not necessarily a FTDI chip, although that is (was?) the most popular solution) will allow you to program and communicate with the chip over its serial port, but any AVR ISP programmer can also be used to program it without requiring a preexisting bootloader in place.


Arduino RF24 library Delay after write function causes no byte availability

In my situation the issue was with the Transmitter not continuing to transmit after a delay. I was able to resolve the issue using the powerDown (http://maniacbug.github.io/RF24/classRF24.html#aa0a51923a09ba4f3478aba9be0f8a6a1) and powerUp (http://maniacbug.github.io/RF24/classRF24.html#a5cdaf47aa0edd6dca1b9a8bb7972a1a3) functions. Here is a snipet of my code. "radioTx" is the name assigned to my transmitter.

//standard code setup for arduino uno board examples
radioTx.begin();
radioTx.setChannel(108);
radioTx.openWritingPipe(pipe);

}

void loop() {

  int dist_cm = sonar.ping_cm();

  Serial.println(dist_cm);
  radioTx.write(&dist_cm,sizeof(dist_cm));
  radioTx.powerDown();
  delay(5000);
  radioTx.powerUp();

  }


Two function Reset button - long/short press

It can be done with one button, one resistor, one capacitor and one GPIO pin (in addition to the RESET pin):

simulate this circuit – Schematic created using CircuitLab

Pressing the button causes a LOW pulse on the RESET pin (in the exact same way as the USB interface does).

During your startup procedure you read the GPIO pin you have chosen. If it's LOW the button is still being pressed in. If it's HIGH it has been released.

If you are using an Arduino with the normal bootloader the bootloader itself imposes a 2 second delay (which may be enough for you). Alternatively you will need to have your own delay in your program before reading the button to ensure that you have plenty of time to release the button so you don't accidentally reset your settings.


Error building Arduino WiShield Flash example: 'dflash' was not declared in this scope

I doubt anything is wrong with the library, but in your initShield and loop methods you refer to a variable called 'dflash' which does not seem to be defined anywhere.


Arduino(s) not resetting on Serial connection lost / re-established - why?

What you have done is to disable the "HUPCL" signal that is sent when the port is opened/closed.

You can turn the signal back on with:

$ stty -F /dev/ttyACM3 hupcl

And you can turn it off again with:

$ stty -F /dev/ttyACM3 -hupcl

HUPCL means "HangUP on CLose".


Custom ATMega 2560 board won't execute Arduino code

When using an empty ATMega2560 you need to change the fuse settings, otherwise it will just upload your code but it won't execute.
This tutorial explains it very clearly:
Programming ATMega 2560 with Arduino UNO


Does toCharArray prevent a String being created on the heap?

The return value of getString allocates and the deletes a char array in heap for a temporary String object.

For ESP8266HTTPClient and ESP32 HTTPClient library you can use writeToStream or getStream()to read the response without using String class with getString(), where stream is WiFiClient& stream = client.getStream();

getStream, returns the underlying WiFiClient. You can read the data with classic while (stream.available()) { char c = stream.read; ... }

writeToStream copies the data to a stream. My StreamLib library has a stream wrapper over a char array. It is called CStringBuilder.


Increasing the numbers of I/O pins on Arduino Uno

Yes, just use the analog pins. The analog pins are both analog inputs and digital I/O pins. The functions happen to be shared on the pins, in the same way that the interrupt pins are shared with digital I/O, the TX and RX pins are shared with digital I/O and the SPI pins are shared with digital I/O.

Every I/O pin (analog or digital, etc.) can be used as digital I/O.

You can also reduce your required number of I/O pins by using a technique known as multiplexing.

For instance, to read nine buttons you could have them arranged (as in Tic-tac-toe) in three rows of three buttons. You then have three I/O pins for the columns and three I/O pins for the rows - that's just six I/O pins for nine buttons.

The technique is widely used for keypads, but they are just buttons, so the same technique can be applied to any buttons.

The Matrix Keypad how-to

The same can go for LEDs. There are various specialist LED multiplexing techniques that allow for many LEDs to be driven from just a handful of I/O pins.

How to Multiplex an LED Grid... (YouTube)
Charlieplex Library for Arduino


I don't know Proteus, but I think HC05 a bluetooth module? If so, the module interface from HC05 <==> arduino is done through Serial (UART) communication.
Arduino has built in support for this - you don't need any special libraries besides SoftwareSerial.
wire up the module as such:

Then run the following code:

#include <SoftwareSerial.h>

#define rxPin 10 // connected to TX pin of HC05
#define txPin 11 // connected to RX pin of HC05

SoftwareSerial mySerial(rxPin, txPin); // RX, TX
char bt;

void setup() {
  Serial.begin(9600);
  Serial.println("Hello");

  mySerial.begin(9600);
  mySerial.println("World");
}

void loop(){
  while(mySerial.available()){
    bt = mySerial.read();
    Serial.print(bt);
  }

  while(Serial.available()){
   bt= Serial.read();
   mySerial.print(bt);
  }
}


Why is my potentiometer giving strange reading?

Unfortunately I cannot comment. I can't really think of a reason why your readings are the way they are. Though you did not present to us an image of what potentiometer you are using and how you are really wring it up.

It is possible that your potentiometer is a center tapped type with 4 pins. You could have possibly connected the positive rail to the center tap pin, ground to the side pin and the wiper pin to the Arduino pin so that you would have the result you are getting.

Or potentially, you wired it correctly except for the fact the positive rail you connected to was 10V, but that is really dangerous.

Have you tried measuring the resistance of the potentiometer from one side pin to the other side pin?


The reason for this issue is to do with SPI.

Basically in my custom arduino I have a 4Mbit flash and it communicates over SPI.
It seems that when the RST pin is connected it also automatically initializes the SPI protocol.

When the arduino is powered from RAW + GND directly from an external power source you need to initialize SPI manually.

In your sketch you need to:

    #include <SPI.h>

    void setup() {
        SPI.begin(); // this needs to be invoked before any SPI device gets initialized

        // initialize and use SPI devices
    }


Creating an array, assigning a value to each indices, and assessing the array

There are multiple issues with your program. The most obvious is that,
if you define a variable multiple times, you end up with mutliple
different variables that share the same name. For example:

void setup() {
    int Vs[512] = {};  // this Vs is local to setup()
}

void loop() {
    int i;  // this i is local to loop()
    for (int i = 0;  // this other i is visible within the for loop only
            i <= 511;
            i++)
        ;  // this is the body of the for loop
    {
        ...
        int Vs[i] = {c};  // this Vs is local to loop()
    }
}

Another issue I pointed out in the snippet above is that a semicolon by
itself is an empty (i.e. do-nothing) statement. Thus you for loop is
empty.

There is no point in defining a constant such as analogPin = A0 if you
don't use it.

The value returned by micros() is not an int, it's an
unsigned log.

If you store a voltage in volts in an int, you get a very poor
resolution of one volt. You could store in a float, but that would
fill up the memory of your Arduino. I would rather store the raw
readings, and convert to volts only for printing.

Serial.println() takes time, and you are doing this during the timed
part of your code, which is probably unintended.

Here is a version of your program that may better reflect your
intentions. It takes 512 analog readings, stores them in an array, then
prints them and reports the time taken to do the readings. Then it waits
for one second and repeats the whole thing again.

const uint8_t analogPin = A0;
const int readings_count = 512;
int Vs[readings_count];

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

void loop() {
    // Take a run of analog readings.
    unsigned long start_time = micros();
    for (int i = 0; i < readings_count; i++) {
        Vs[i] = analogRead(analogPin);
    }
    unsigned long stop_time = micros();

    // Print the readings.
    Serial.println("Voltage readings:");
    for (int i = 0; i < readings_count; i++) {
        Serial.println(5.0/1024 * Vs[i]);
    }
    Serial.print("Data recorded in ");
    Serial.print(stop_time - start_time);
    Serial.println(" µs");
    Serial.println();

    // Wait before the next run.
    delay(1000);
}

If you really want to run only one iteration of the process, then you
can just replace delay(1000); by exit(0);. Alternatively, move the
body of loop() to the end of setup(), and keep an empty loop().


Driver shield providing 24+ pins at 100mA (for Mega 2560)

You can:

use a driver chip, e.g. ULN2803 which gives you 8 outputs of up to somewhat 500mA from 8 digital pins
use a serially addressible power+logic chip, such as TPIC6A595NE which gives you 8 outputs, each can drive 350mA, and has a built-in short circuit protection. You can cascade these, 3 chips give 24 outputs, and need only three pins to drive all 24 (or more if you use more chips) outputs.
There are 24 output devices, however not in this current range. 24 output devices are usually i2c or spi based led controllers - some of them gives you goodies like rock solid hardware PWM on all 24 ports - but none of them gives you 100mA output.


Programming Leonardo with TTL to USB cable

The bootloader on the Leonardo operates through the native USB port of the ATMega32U2 chip, not the UART.

You cannot treat it like an Uno because it isn't an Uno.

You can only program it through the USB port or through the ICSP connector.

If you want to use UART to upload you will need to replace the bootloader with a suitable UART based alternative. (Before you ask, no I don't know if one even exists or where to get it if it does).


Updating MAX7456 library to work with Arduino 1.6.6

In the file max7456.h at line 228 change it from:

static void getCARACFromProgMem(const prog_uchar *table, byte i,charact c);

to:

static void getCARACFromProgMem(const char *table, byte i,charact c);

In the file max7456.cpp at line 484 change it from:

void Max7456::getCARACFromProgMem(const prog_uchar *table, byte i, charact car)

to:

void Max7456::getCARACFromProgMem(const char *table, byte i, charact car)

Then it compiles OK (under 1.6.4 at least).


Watchdog timer/deep sleep loop for Atmega 328 Pro Mini 5v 16 mhz

I don't know if this is the best solution, but I found a workaround. In the ISR(WDT_vect) function I added a while statement where I added a boolean variable set to true when running the basic program, and false when I enter looping deep sleep mode. I'd appreciate if someone out there can provide a better solution, but for now this one works for me. Below is the revised code in case anyone's interested.
// thanks to KeyChainino for basic code. I added ADC disable to further reduce power from 0.67mA to 0.54mA
//revised by John Bedford 01/12/2020
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
const int ledPin = 13;
const int resetPin = 9;
volatile boolean wdtInterrupt;    //watchdog timer interrupt flag

// the setup function runs once when you press reset or power the board
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(resetPin, OUTPUT);
  digitalWrite(resetPin,HIGH);
  Serial.begin(9600);
  Serial.println("Resetting..");
  delay(100);
  watchdogSetup();
}

// the loop function runs over and over again forever
void loop() {
  wdtInterrupt= true;
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  for(int i=0; i<9; i++){; //set up loop to force timeout of WDT
    delay(1500);
    Serial.print("Loop ");
    Serial.println(i);
    delay(100);
  }
  wdt_reset();

  waitSleep(2); //go sleep for x loops of WDT settings (8 sec max per loop)
}

void waitSleep(int sleep_cycles) {
  wdtInterrupt=false;
  while (sleep_cycles) {
    goSleep();
    sleep_cycles--;
  }
}

void goSleep() {
  watchdogSetup(); //enable watchDog
  // disable ADC (analog to digital conversion)
  byte old_ADCSRA = ADCSRA;
  ADCSRA = 0;
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_mode();
  //disable watchdog after sleep
  wdt_disable();
  ADCSRA = old_ADCSRA;
}

void watchdogSetup() {

  //WDP3 - WDP2 - WPD1 - WDP0 - time
  // 0      0      0      0      16 ms
  // 0      0      0      1      32 ms
  // 0      0      1      0      64 ms
  // 0      0      1      1      0.125 s
  // 0      1      0      0      0.25 s
  // 0      1      0      1      0.5 s
  // 0      1      1      0      1.0 s
  // 0      1      1      1      2.0 s
  // 1      0      0      0      4.0 s
  // 1      0      0      1      8.0 s

  // Reset the watchdog reset flag
  bitClear(MCUSR, WDRF);

 //The following bit have to be set at the same time otherwise the system doesn't set the right value

 /* Start timed equence */
 //Watchdog Change Enable to clear WD (by setting the WDCE bit) and Enable WD (by setting the WDE bit)
 WDTCSR |= (1 << WDCE) | (1 << WDE);

 //Set new watchdog timeout value to 8 seconds (WDP3 and WDP0 to 1) and enable interrupts instead of reset (WDIE to 1)
 WDTCSR = (1 << WDIE) | (1 << WDP3) | (1 << WDP0) ;
}
void hardwareReset(){;
  digitalWrite(resetPin,LOW);
}

ISR(WDT_vect) {
  while (wdtInterrupt){
   hardwareReset();
  }
}


For the mosfet circuit. Are you using an external power supply? The reason why you cannot mix any color might be due to the fact that you're not providing enough current to the led strip, so it just work fine when turning on each channel individually. Check the current the led strip draws (which usually is provided as amp per channel per meter) and use a power supply that can provide enough current for it.

From the adafuit page

  Connect a 9-12V power supply to the Arduino so that Vin supplies the high voltage to the LED strip. If you want, you can also just use a separate wire that connects to a power supply that provides about +12V. Make sure to connect the ground of that supply to the ground of the Arduino/MOSFETs!


Can a DC motor use more current than its datasheet?

YES (typically resulting in melting the coils). The current used by standard or brushless motors is related to the voltage applied and the load applied. As you approach the load limit, current rises over the limit. There are many ways to control this but controlling the load is the easiest way. DO NOT run the motor through the Arduino even if you think it will be under the 200mA limit. Motors produce a lot of spikes and back-flow.

Here's a tutorial on safely running a motor and controlling the speed: https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/overview


Casting a struct member between uint8_t and char, with regard to serial transfer

You're actually falling into a common problem with pointers in structs.

This structure:

struct SEND_DATA_STRUCTURE
{
  int blinks;
  int pause;

  uint8_t *data;
};

contains three values: blinks, pause and a pointer to the data.

uint8_t *data;

That doesn't contain the data. That only contains the address that the data is stored at in memory.  When you transfer the struct it's that address that you are sending - then when the other end tries to print it all it can do is look at the address it's been told about and try and print whatever is in there - and that is complete garbage.

Instead of storing a pointer to the data you need to store the actual data itself. That means that you need to decide upon a maximum size for that data and pre-allocate the memory within the struct:

#define DATA_SIZE 40

struct SEND_DATA_STRUCTURE
{
  int blinks;
  int pause;

  uint8_t data[DATA_SIZE];
};

Now in order to get the data into that struct you need to fill that array with your payload. For strings the simplest way is:

strncpy((char *)mydata.data, payload, DATA_SIZE);

That will copy up to DATA_SIZE characters from payload into mydata.data.

Note that if payload contains more than DATA_SIZE-1 characters the data in mydata.data will not be NULL terminated. You can get round that by forcing NULL termination:

mydata.data[DATA_SIZE-1] = 0;

In your revised code your payload size is too big. The way the EasyTransfer library works is it has a single byte for the size of the payload. Your total payload size is PAYLOAD_SIZE + 2 ints - that is 255 + 2 + 2 = 259 bytes.  Placed into a single byte that gets truncated to 3. That means you are actually transferring one and a half integers and nothing else.

You need to ensure that your entire struct never exceeds 255 bytes. So you can have a maximum size of data, once you have taken your two integers into account (assuming 16-bit integers on an 8-bit Arduino), of 251 bytes.


CPU information on Arduino Serial Monitor

CPU temperature

Some Arduino boards have a microcontroller with a temperature sensor inside. For example the Arduino Uno can measure the temperature inside the microcontroller.

As far as I know, no one uses it. It is not accurate and a microcontroller should not get hot in the first place. The microcontroller or processor on the Arduino board can run at 100% load and it does not get hot.
The internal temperature sensor is not accurate enough to measure the ambient temperature.
The internal temperature is therefore (almost) useless.

See this page on the Arduino Playground and this forum thread for the internal temperature sensor.

CPU usage

There is no CPU usage. There is no idle task. The microcontroller or processor usually runs all the time at full speed.

It is possible to determine how long the Arduino board stays in delays (via the yield function).
With a external RTC clock it is possible to determine how long the Arduino board stays in sleep mode (some battery powered Arduino projects use the sleep mode).
However, those are very specific things. Perhaps a project requires to measure them, but there is no common use for them.

A good sketch is not supposed to do nothing, it is supposed to check all the inputs and check millis-timers and act if needed. The Arduino loop() function is supposed to run as often as possible to make the Arduino run fast and smooth.

Memory usage

The memory usage is something to be aware of when writing a sketch. An Arduino board has much less memory than a typical computer.

It is possible to determine the unused memory between the stack and the heap.
The function at the bottom of this page can be used to determine the amount of free memory.

I have also seen code to measure the high water mark (memory that is never used at all), but none of them work for all Arduino boards and the code is not reliable.


Bluetooth Communication Not Working with DC Power But Works With USB Power?

Take two 9 volt batteries with same specifications and connect it into the parallel by using this efficiency of current increases and it full fill the current requirement at the time of data transmission and for others modules u r using with the arduino.


unexpected behaviour of encoder with increasing rpm

I think the problem is in the tinkercad simulation:
The encoder is attached to the motor and the motor is always rotating at the same speed. Selecting a different RPM on the component changes the gear ratio and the RPM of the shaft, but not of the motor. That means that the number output after 1s should be always the same.
Why it is not exactly the same, only the programmers of the simulation can tell.
It might have to do with simulation speed, because I get totally different numbers there.
To tell exactly what is going on, a documentation of the components in the simulation and of the simulation would be necessary.


Trying to measure distance using an ultrasound sensor

You have declared int distance outside of any method. That means it's available from all methods. Some people call it a global variable.

However, you have a method int distancefonction(int dt, int distance) which receives int distance as a parameter. This results in an ambiguity: if you refer to distance within the method like

distance = 0.034/2*dt;

should this now refer to the parameter distance or the global variable distance?

The answer is: you can't decide. The C/C++ standard has decided for you and the answer is: the parameter will take precedence and thus hide the global variable. This thing is also called "shadowing".

What does it actually mean?

The global variable distance has an undefined value at the start of the program. Let's assume the value is 0.
distancefonction() is called, passing distance as a parameter. This will create a copy of the value 0 on the stack.
the function will calculate the distance and update the variable on the stack.
The Serial.println() statement within the function accesses the variable on the stack and will print the correct distance.
Once the function is complete, the code in loop() will access the global variable distance, which still has the old value, because only a copy has been updated.

What is the solution?

Of course there are several solutions.

The simplest fix is probably to remove the parameter int distance from distancefonction. Thus the function will not receive a copy and instead operate on the global variable.
Another solution is to let distancefonction return the actual distance. The method signature already indicates that you wanted to return a value: the intfrom int distancefunction(...) says that. At the moment, the function does not return anything. You could write return distance; at the end. This approach could eliminate the global variable completely.


How to communicate with ESP8266 ESP01 by sending data through softwareserial on Arduino Uno?

How about this:

void loop() {
  while(Serial.available() > 0) {
     myESP.write(Serial.read());
  }
  while(myESP.available() > 0) {
     Serial.write(myESP.read());
  }
}

That code will continue to load data to and from the software serial not just one byte. You can also use string concatenation:

String data = "";
while(Serial.available() > 0) {
   data += Serial.read();
}

Or arrays:

int data_max = 4096;
int data_size = 0;
char data[data_max];
while(Serial.available() > 0) {
   if(data_size < data_max) data[data_size++] = Serial.read();
}


It is retired so will I have any problem?

It depends on what you want to do with your arduino. If you need a project that requires future support then dont buy a retired board. If you just want to do basic beginners stuff (like blinking LEDs, controlling motors, sending serial information wired or with an add on shield to send wireless information)-then any arduino can do these basic projects and probably at a cheaper price than 58 dollars.


Since I can not commemnt due to low reputation, I'm "commenting" here.
You can search for LIRC and WinLIRC


Passing non-static member function using bind

In your MyClass example, the drawPaged() call is given only a single argument, while according to the library, it needs two:
void drawPaged(void (*drawCallback)(const void*), const void* pv)

The first argument is the function pointer (or the one wrapped by std::bind!). The second argument seems to be some data that will be passed on to that function. (according to the [linked API)
The error actually explains it, it suspects that you are trying to call void GxEPD2_BW::drawPaged(void ()(const void), const void*). Hence it mentions this as a candidate.
What you need to do is something like this:
display.drawPaged(std::bind(&MyClass::drawClassCallback, this, std::placeholders::_1), &var);

std::placeholders::_1 is the placeholder that represents the var argument that will be passed on when it is called.


How can I list only files that begin with "/LOG?"

Give a filename String to text...

String text = "/LOGsdfsdf";
if(text.startsWith("/LOG")){
//wee file begins with /LOG
}else{
// wops wrong file.
}

Look in here

https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/

Method url startsWith("");

https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/startswith


Can't upload to my Nano after updating to Arduino AVR Boards 1.6.21

Arduino recently changed the bootloader they ship on their official Nano boards. This required a change in the hardware definition for the Nano, which was the sole reason for the Arduino AVR Boards 1.6.21 release.

The new Nano hardware definition is not backwards compatible with Nanos that use the previous ATmegaBOOT bootloader. For this reason a new menu option was added: Tools > Processor > ATmega328P (Old Bootloader). If you select that option the uploads to your Nanos will work again.


Why does an Arduino MEGA 2560 have different PORTS

Thats because Arduino has configured the Mega to do so. In microcontrollers you need to select what use will each pin have based on the availability. To make user interface easy arduino has done this based on what is commonly used by everyone. Even then some functions are still not disabled.

For example 50,51,52,53 are SPI pins on mega which use Pin change interrupt for working. Thus it not necessary we use them for SPI we can also use them for Pin change interrupt.

Similar is the case for pins 10,11,12,13. These PWM pins can also be used for Pin change interrupt but other PWM pins cannot.


Can I power an Arduino with a computer's motherboard?

You want to tap off of the +5VSB pin of the ATX or BTX power supply connector and send it to the 5V pin on the Arduino. Where this will directly drive the VCC(5V) of the UNO.

Note that 5V of the USB basically drives the VCC directly, except through a MOSFET that acts as a blocking diode to prevent local VCC from flowing back to the 5V_USB.

Not sure if you are suggesting that the 5V USB is frying Arduino's. If so that is bad. If true; Fix that first.

That said (with good 5V usb) you should be able to find or configure (BIOS) so that a USB connector will remain powered, and allow a wake up from mouse movement. Hence a possible solution would be to use a Leonardo/Micro's Mouse emulation to do just that as to wake the PC, without any hardware mod's.

Freeduino Micro's are pretty cheap.


How can I get ultra clean dc wall power for my arduino project?

This is what I use, although admittedly not in your application. I run it from a 12V wall adaptor and adjust the output voltage to suit my requirements. The input should ideally be at least a couple of volts above the output(depends on current and temperature at 25degC and 20mA it's > 1.6V and 1.5A at the same temp it's > 2.7V).

Another alternative if you want to really go to town would be to repurpose an old computer ATX or similar PSU. There are plenty of guides out there and it's a straightforward job.


I am working on a thermometer and humidity why am i getting this error

This indicates your IDE is missing the "Adafruit Unified Sensor" library as outlined here.

To install it, select "Tools" -> "Manage Libraries" and search for "Adafruit Unified Sensor". You can install the library by selecting it and pressing "Install".


ESP-12F responds only to a few basic AT commands

You can't connect to an access point until you put the module into Station mode.

AT+CWMODE=1

That will put it in STA mode.  You can alternatively make it an access point (AP mode) with:

AP+CWMODE=2


Summary:
It looks as though you can just drive BL directly with the PWM-output.
What happens when you do?

Details:

(1)  As shown, even  if the circuit did what you wanted, all you would be doing is providing a rail to rail (0V to 3.3V ) signal to the BL pin. You can do this by connecting PWM-out to BL directly.
Does this work?

If the LCD and Arduino used differing power supplies the MOSFET may be useful.

(2) To use circuit almost as-is you need a PChannel FET.
Swap Drain and Source and it will provide PWM to the BL pin. When BL is high the FET is off. When BL is low the FET is on. The FET used must turn on with about 3V between gate and source.

(3) To use the N Channel BS170 you must drive the gate +ve above the source by an amount that is enough to just turn it one "plus a little more". This is called Vth (Vthreshold). The BS170 has Vth ~= 1.8V at low currents. Vth varies somewhat between samples. When you connect the gate to +3.3V the FET tried to turn on but as the source rises it reduced Vgs until it reaches about Vth. Raising the source above this level reduced Vgs to below Vth so the FET is not turned on.
ie this is what a=accounts for the 1.5V that you see as 3.3V - 1.8V = 1.5V.

To use the BS170,
connect the source to ground,
connect drain via a say 1k resistor to +3.3V,
connect drain to BL,
drive gate with PWM.

BUT why does not just driving BL with PWM do what you want?
A data sheet for the display would be useful.


How to move Servo in between three positions

The logic looks OK to me. But be aware that these servos don't perform well at or close to their limits - mine tend to jitter there but there may be other issues as well. I have 10 of these hobby servos; each has a different jitter-band at the ends of its travel. You may have better success driving them to 10, 90, and 170 degrees.


How to serially transfer/read an image to Arduino

You can send anything you like through the serial port. It is just 8-bit raw data. The onus is on you, however, to implement a suitable high level protocol with which to transfer the data.

One important thing to bear in mind though: JPEG is a highly compressed complex image format. I am not aware that anyone has ever managed to squeeze JPEG decompression into a lowly Arduino. Instead you will need to use a decompressed image format such as BMP, or do the decompression on the computer before-hand and send the raw RGB image data over the serial instead.


Controlling a LED array from Arduino NANO

You can control a grid of 8x12 LEDs using 8+12 (20) GPIO pins if your chosen board has that many. If it doesn't you can use a 3-to-8 decoder (e.g., 74HC138 - active low outputs, ideal for driving a P-channel MOSFET for the anodes of each row) to reduce that to 3+12 (15). You could cascade two of them and rotate the arrangement so it's 8+4 (12), though that's harder to do (although you can get 4-to-16 decoders too which would be simpler).

For multiplexing you don't want to use shift registers, they're too slow for smooth updates. You also don't want to drive each LED individually when you're working with that quantity, it just gets unmanageable and the power consumption would be excessive.

If you wanted to use shift registers you could use one (or multiple cascaded) to clock a single bit along them to select each row in turn. You could then reduce the pin requirement to 8+3 (clock + data + reset) though that gets a little more complex to program.

And yes, before you ask, you can address individual LEDs in the grid with multiplexing. You select one individual row (or column, but I'll just say row from now on) at a time and tell it which LEDs to light on that row, then move to the next row. This is why using a 3-to-8 decoder is good because it can only activate one row at a time which is what you want when multiplexing.


It has come to my attention I never posted a followup to this but I was actually able to solve this problem by shielding the wire going from the switch to the arduino. The switch's wire was about 2 to 3 inches long and I wrapped aluminum foil around it, which shielded the signal from what I suspected was EMI induced by the switching converters.


Cannot assign COM port to HC-05 bluetooth device

Based on my experience, there is nothing wrong (yet) on the Arduino. You can check  this or this. Unlike previous windows version, Win 10 tend to "ignore" bluetooth connection, so you have to assign the COM port manually.


Controlling multiple 12v solenoids with 5v relay modules (Arduino Reset Issue)

Some of those 5V "digital" relays can be wired using a separate power supply for the relays and the Arudino. You have to move a jumper to use separate power supplies.

My guess is that you're powering both your Arudino and your relay coils from the same 5V supply, and when you energize all 4 relays at the same time you draw too much current and the Arduino doesn't get enough voltage and resets.

Read up on your relay modules, and either re-wire them using 2 different 5V supplies, or switch your 5V supply to a higher current supply. (and possibly adding a filtering capacitor to the Arduino to smooth out the power fluctuations as the relays energize and de-engergize)

I used a 4-channel relay unit in a project of mine that has optical isolation of the relay control lines, and can be wired to use separate power supplies for the Arudino and the relay power. When wired with separate power supplies, the relay's control lines just draw CMOS logic levels to control the different relay channels, and get the power for the coils independently from the microcontroller's power.


Using Arduino to show images in Serial Monitor

Based on this guide, he doesn't actually display the images on the serial monitor, only the image data for each pixel.

Then another program (Javascript and some HTML) on the PC side collects the data and converts it to a greyscale image.


How to use ESP8266 wifi shield as a hotspot?

Connecting through the ESP8266 to the internet would require the ESP8266 to handle Network Address Traversal and/or routing, which is not officially supported.

However, if you are prepared to do a lot of work, it can be done. The performance and reliability is bad, but it can be done. See http://bbs.espressif.com/viewtopic.php?t=960 Note that this will require far more skills than running the examples in the Arduino IDE.


Class TKPotentiometer has no member named 'read'

As soon as I finished writing the question, it came to my mind that perhaps I misspelled something, so I looked for a file in the Menu's sketchbook that I could load.

With my surprise, I found the same exact code as I posted, with a little difference:

pot.read() was substituted with pot.get()


Arduino Uno rev 3 toggling a 230 V submersible pump on intervals

The Arduino will easily drive this relay board, and it needs only a very small input current.

The board you linked to has a built-in optical isolation circuit, so there is no direct electrical connection between the Arduino-side of the circuit and the relay side. This should protect your Arduino if something goes wrong. For what it's worth, the product description specifies this board is suitable for "AC [...] appliances such as [...] motors". A pump is primarily a motor.

The voltage may fluctuate when the pump is started and stopped (Back-EMF). It's hard to say what this might do to the relay board if it goes way over specification. Perhaps you might be happier with a much more robust solid-state relay (SSR) that has a higher rating than the target load. Something
like SSR-25DA 25A Solid State Relay - White. Since solid-state relays are non-mechanical, they will not wear-out from repeated switching either.

You may also want to build some fail-safe sensors into your project. For example, water level float switches for both high-water and low-water marks.


why not?

Well ok ... they might not connect a USB to each one as there are faster ways - flyingProbe/PogoPins on a "bed of nails"

http://en.wikipedia.org/wiki/In-circuit_test

This type of temporary connection speeds up testing & pre-programming considerably.

Each card that is made has to go through some form of test process at the end (flying probe or manual).

https://learn.sparkfun.com/tutorials/electronics-assembly

  On boards that require programming or calibration, additional steps
  are taken to load code and verify the output.


Ultrasonic Sensor scanning too often resulting in a whirring noise

If you want to sample at 4Hz (4 times per second), you need to change your headers accordingly:

const int serialPeriod = 250;       // only print to the serial console every 1/4 second
unsigned long timeSerialDelay = 0;

const int loopPeriod = 250;          // a period of 250ms = a frequency of 4Hz
unsigned long timeLoopDelay   = 0;


how can i use multiple 7 segment in tinckercad

It sounds like you will need to multiplex them.

Assuming common cathode LEDs:

Set up a transistor for each digit that activates the ground for that digit. (Lighting all the segments of a digit will probably exceed the max current sink of one of your digital pins.) You may be able to drive a single segment directly from an output pin, assuming it's current draw is ≤20 mA. If the segments draw > 20 mA then you will likely need transistors for the segment drivers as well. (The max output of a pin on most Arduinos is actually 40 mA, and if the average current when multiplexed across 5 digits is < 20 mA, you might get away with drawing up to 40 mA per segment. I'd ask somebody with more electronics experience than me to confirm this.)

Write your code to switch one digit's ground on at a time, after turning on the desired anode (segment) pins. Cycle through the digits rapidly and they will all appear to be on at the same time.

The pseudo-code:

setup {
   digit index = 0
   turn all pins (segment anodes and digit cathodes) to open state
}

loop {
   set up segments pins for digit[index]
   Turn on cathode for that digit
   short delay to allow segments of current digit to glow
   turn off cathode (ground) of current digit
   digit index = (digit index + 1) % num_digits
}

The above would require a digital pin for each segment, and a pin for the ground of each digit. (7 + 5 = 12 digital pins total.) Without multiplexing, you'd need 7x5 = 35 digital pins, and would still have to make sure you didn't exceed the total current output limits of the Arduino. (35 segments x 20 mA/segment would be 700 mA total.) Most Arduinos have a total current output of no more than 200 mA across all pins, so you could not light up all the segments of more than 2 digits at once, assuming 20 mA/segment.)

Note that it might be easier to ignore all of the above and get a serial LED display driver like a MAX7219. You just need 2 digital lines to drive that, and it will control 8  8-segment digits (7 segments plus a decimal point at each position)


Enable free fall detection using Arduino

Sitting an accelerometer flatly on a bench will produce a value of 1G in one of the 3 axes.

Free fall of an accelerometer (assuming you haven't reached terminal velocity) should read near zero on all 3 axes.

I am not aware of a mode you can set for this, but if you check the values of the 3 axes and all are close to zero, you are probably in a free fall condition.


Yes. You need to create new unique names for them using udev rules.

By using the unique serial number, along with the VID and PID of the board you can use udev to create a symbolic link to a device name of your choice. Best to keep it to something that the Arduino IDE recognises if you want to access the link from within there for programming (otherwise you can choose what you like).

Rules are stored in /etc/udev/rules.d and take the form of .rules files with various instructions in.  One example, that should do what you want, is:

SUBSYSTEMS=="usb", ATTRS{product}=="Arduino Uno", ATTRS{serial}=="6493832323135111C0A1", KERNEL=="ttyACM*", SYMLINK+="ttyACM50", MODE="0666", GROUP="plugdev"

Of course, tweak it to your personal requirements.

Once you have crafted your rules be sure to restart udev:

sudo systemctl restart udev

or

sudo /etc/init.d/udev restart

and plug your board in.

Genuine Arduino devices usually use /dev/ttyACM* not /dev/ttyUSB*. If you have /dev/ttyUSB* then you are either on a very old device (with an FT232 chip) or a cheap Chinese clone.

If the latter then your mileage may vary somewhat.


I believe that your error is in that you declare LEDpin as pin 13 and then your motor B as pin 13 as well, that to me would result in errors when you write to the led in the else statement at the end of your code. I would recommend that you clean this up, don't use pins for different things. Try this first.

Your logic is ok in terms of functionality.

Also why is there inconsistency at this part on your code:

digitalWrite(12, LOW); /*move channel A motor half-speed */
  digitalWrite(9, LOW);
  analogWrite(3, 123);

  digitalWrite(13, HIGH); /*move channel B motor half-speed */
 digitalWrite(8, LOW);
  analogWrite(11, 123);

Why do you say pin 12 must beLOW and 13 HIGH when moving forward? Is this the way your un-mentioned circuit setup works, if possible could you add this info?


Too slow start up with Atmega2560 on custom PCB

I am closing the case. It is not 100% satisfaction though. Because, using Visual Studio with Visual Micro didn't help me on that issue in a natural way but something else.

For the future reference for somebody might get benefit out of this, I like to explain here what I did to get over this issue briefly. As @Gerben (big credits go to him) has pointed the right direction, I did check fuses by installing Atmel Studio 7 and use its programmer.

Yes, the fuses were completely wrong. I have therefore read the fuses from my healthy PCB and noted aside and then applied these very same fuse settings to the slow working PCB. I have just programmed the fuses, Firmware was the one I programmed earlier in the uC. So, voilà, the slowness has gone.

I think I am going to use Atmel Studio 7 now on next to Visual Studio as it has everything built-in including Arduino support.

Thanks everybody involved.


There are a number of issues with the tutorial you've listed there.

Firstly, a voltage divider is very highly recommended as the ESP8266 cannot handle more than 3.3V, however, the connections for the voltage divider in the tutorial you linked to are the wrong way round (as you suspected).

Secondly, you cannot power the ESP8266 directly from the Arduino, as the power requirements are higher than the Arduino's on board 3.3V regulator. A separate power supply or regulator is recommended. This might be cause of it getting hot (the onboard regulator maybe - but I can't be sure as there is not enough information from your initial post as to exactly what is getting hot).

There are 2 LED's on the ESP8266 shield (the one used in the tutorial you've linked to) one is power and the blue one is wifi communication.

The other potential issue with the tutorial you've linked to is that they have used Arduino pins 0 and 1 to connect to the ESP8266 - while this will work, the problem is that the Arduino uses pins 0 and 1 to communicate over USB with a computer, which means that in in that configuration you cannot use Serial monitor to send/receive data.


CRC test fail on MS5803-14BA pressure sensor - what can I do?

Where this problem can be originating from?

As per page 7 and page 14 of the data sheet, there are 16 bytes of PROM in the unit which contain calibration information determined and written at the factory. This calibration information includes coefficients that must be used by whatever's reading the sensor to adjust for manufacturing variations. The data also include a CRC check code to let you confirm you've read the PROM correctly.

So there are three possibilities here:

The CRC as written to PROM is wrong.
There was an error while transferring the data from PROM to your MCU.
The software is doing the CRC calculation incorrectly.

The source code suggests that the most likely reason for this sort of failure is faulty wiring between the MCU and the sensor.

What kind of limitations I have for not passing the CRC test? Does it mean that the collected data can not be trusted?

Potentially, yes. To determine how bad things really are and what might be going wrong you need to do a bit more experimentation.

When you call the initializeMS_5803() function you pass it a boolean parameter determining whether it's running in verbose mode. Set this to true so it prints out the coefficients 0 through 7 to the serial port during initialization. Restart your Arduino several times, ideally under different conditions of temperature, power, physical wire configuration (if any), etc., and see if the values ever change. If they are ever different from a previous run, you have either cabling corrupting the data transfer or a defective sensor. You may be able to look at which bits change, if any change consistently, to get some insight into how "random" the problem really is. (Could it be that only a certain bit pattern is being transmitted unreliably?)

If all values always read the same, compare them to the values read from your good sensor. If they're quite similar, and you're generally getting similar readings under similar conditions from both sensors, I would suspect possibility 1 or 3 above, and reckon that you're likely to be getting reasonably reliable data from the sensor. If the values are vastly different this doesn't necessarily mean that the sensor will be unreliable; I have no idea how much these coefficients vary from unit to unit.

If I use the raw readings D1 and D2 from a sensor that have failed the CRC test and pos-compensate them in the computer, will I have trustful results?

Again, that depends on whether or not it looks as if you're getting corruption on the data link. As above, if you ever read different PROM data from run to run on startup, the sensor is much less likely to be producing trustworthy data.

You could also try comparing the raw readings from both sensors under conditions as close to identical as you can make them. I don't know how close in calibration the two sensors are, but if they are close, the raw data should look similar and that would be a sign of reliability.

How to solve it?

First, determine if you are getting the same or different PROM values across multiple startups. If they're always the same, send your good and bad values to the author of the driver and ask him if he thinks his CRC algorithm might have an error in it. (Or check it yourself against the application note mentioned in the data sheet, if you feel up to it.)

If the CRC algorithm in the software you're using is correct, given that you appear to reading successfully from another sensor, I'd send the sensor giving the CRC error back to the manufacturer, along with the coefficients you had read, with a query as to whether they have got the CRC wrong or you're reading the data wrong.

If you're getting different PROM values, that's either a faulty sensor or a wiring problem. You may be able to help isolate this with the usual tricks: slow down the transfer speed (with Wire.setClock()) to see if that reduces data corruption, re-wire the circuit with different (and preferably shorter) wires and other parts, make sure you've got caps in the appropriate places to filter noise, put a scope or a logic analyzer on the SCK and SDA lines to see if you can see any dodgy-looking waveforms, and so on. If anything looks strange, you can always use your working unit for comparison. If all that still looks good, it may well be a faulty sensor.


Did you know that the Arduino Uno uses the Atmel ATmega328P processor?

using the ADC for analog input in assembly language

You may want to skim through Chapter "24. Analog-to-Digital Converter" of the ATmega328P datasheet.

You may want to read application note "AVR126: ADC of megaAVR in Single Ended Mode" and browse through the corresponding AVR126 example software.
(It's in the C language, but it mentions all the registers you'll need to read the ADC in your assembly language program).
(As you can tell from the ATmega328 datasheet, the ATmega88 has exactly the same ADC as the ATmega328).

"Assembler source code for the conversion of an analogue voltage to an 8-bit-number",
"AVR ASM Introduction: A moron's guide to ADC"
and
"ATmega8 ADC Example"
have a pure assembly language program for reading the ADC on a Atmel AVR chip
-- alas, on a slightly different chip that may have slightly different registers than the ATmega328P.

Good luck!


Timers, PWM pins and digital outputs on Arduino Mega

You can use them for any purpose other than PWM.  You can even use them for PWM as long as the settings for the timer allow you to produce the waveform you want.
The reason PWM broke was that you had changed the settings for the timer.  The timer is what controls the PWM.  When you changed those settings you either turned the PWM function off or set some setting where it wouldn't work.  Then the pins associated with that timer didn't get PWM anymore.  You can do anything else you want that doesn't involve the timer including use the pin for input or output or any other special function it has not related to the timer.
If you change the timer interrupt to TIMER0, then you run the risk of delay, millis, and micros stop working right.  They depend on the TIMER0 overflow interrupt running at a set interval to count time.  It depends on how you set the timer up.
I would suggest you do some reading on how these timers work.  The Datasheet for the ATMega328P chip is a great place to start.


The Capacitive Sensor library on a D1 Mini

Actually it looks like the answer was in the early 2017 thread all along. I switched to a 400k resistor and it works! (I've only verified this just for pins 5 -> 6, although I'd expect it works for any combination of pins not including D0 / D3 / D4 / D8.)

However, a caveat here -- it doesn't work well. With an Arduino and a ~6m resistor, you can sense a change in capacitance from several inches away, with a nice continuous increase in capacitance as you get closer. At least for me, the 400k resistor had very low operational range, only maybe 1/2 in. or so, and even then the differences were subtle. But increasing to a 600k resistor replicated the initial problem -- I just got the "-2" error message consistently. And going down to a 200k resistor just decreased the range as you'd expect. So there seems to be a very narrow operational range of resistance for the D1 Mini, with less utility than the Arduino.


Use ATtiny85 to perform initial config on a Cisco router using its USB console port

It's been a couple of decades since I was programming Cisco routers, firewalls and switches but I appreciate you pain. Like @Gerben says, you need a bigger processor, an ATtiny85 isn't going to be able to hold a lot of config and even the basic configs I used were about 4 to 6KB.

If there is anything in the configs that is different, you idea is going to hit problems.  Are the device names and passwords all the same? In which case you probably want the engineer to be able to set some configuration data in you "programmer", could they set this specialisation data using their mobile phone?

I doubt you will have any problem connecting an "Arduino" via serial (RS232) to a Cisco router. However you now have to encapsulate the serial in "USB", which I don't think will be straight forward for an "Arduino".

I can't think of an option that doesn't require power, but as an alternative to your idea what about using a Raspberry Pi to connect to the router via USB. Stick a touch screen on it and a battery pack to power it.


how to send input values from host computer to arduino

The easiest method is to use the serial communication. Use the sample code at http://arduino.cc/en/Tutorial/SwitchCase2, upload that to an Arduino, start the serial monitor (Ctrl+Shift+M), make sure the baud rate is the same as set in the code (9600 in this case), then write the commands and send them to the Arduino.

Edit
Since the serial characters are usually read one by one you need a character that will signal the end of the string. This is usually a newline \n, but can be any character you choose (and can be sent to Arduino).

Sample code (processString would be your function to do something with the string):

char buf[64];
byte cnt = 0;
void loop()
{
    while (Serial.available()>0) {
        byte c = Serial.read();
        // Check for terminator character or the size of buffer
        if (c == '\n' || cnt >= 63) {
            // Add the terminating 0
            buf[cnt] = 0;
            // Process the full string
            processString(buf);
            // Prepare to read the next string
            cnt = 0;
        } else {
            // Not terminator - add to string
            buf[cnt++] = c;
        }
    }
}


Arduino UNO Chinese Clone LEDs not lighting up

Use one resistor per led, not one for all of them.

This is because different color leds have different forward voltages. Red requires a lower voltage to light up. So it will guzzle up all available current, while the blue leds are waiting for the voltage to go higher (which never happens).


Basically the formatting and layout of your program is completely wrong.  You haven't actually defined this smsReceivingFunction anywhere.  You have created a prototype to it part way through your loop() function, but not created the actual function.

You should learn to strictly indent your program properly.  It is important, since by doing so you can follow the flow and structure of your program much easier.

For instance, if I pass your program through Artistic Style to attempt to automatically correct your indenting it results in this:

#include <OneSheeld.h>
float lat ;
float lon ;
char charlat [30];
char charlon [30];
char readings [150];
int buttonPin = 11;
int ledPin = 12;

void setup() {
    // put your setup code here, to run once:
    OneSheeld.begin();
    /* Set the button pin as input. */
    pinMode(buttonPin, INPUT);
    /* Set the LED pin as output. */
    pinMode(ledPin, OUTPUT);
    SMS.setOnSmsReceive(&smsReceivingFunction);
}

void loop()
{
    charlat[0] = 0;
    charlon[0] = 0;
    readings [0] = 0;
    if (digitalRead(buttonPin) == HIGH) {
        /* Turn on the LED. */
        digitalWrite(ledPin, HIGH);
        delay( 1000);
        digitalWrite(ledPin, HIGH);
        delay( 500);
        lat = GPS.getLatitude();
        lon = GPS.getLongitude();
        dtostrf(lat, 3, 7, charlat);
        dtostrf(lon, 3, 7, charlon);
        strcat(readings, "please call me I i do not pick up the call please reach to my location:\n");
        strcat(readings, "http://maps.google.com/maps?q=");
        strcat (readings, charlat);
        strcat(readings, ",");
        strcat (readings, charlon);
        SMS.send("+917771914436", readings);
        void smsReceivingFunction(const char * number, const char * text);

        if (!strcmp(number, "+7771914436")) {           /* phone number from which you will send the sms "PUT YOURS IN PLACE OF +1234567890" */
            if (!strcmp(text, "?")) {
                lat = GPS.getLatitude();
            }

            lon = GPS.getLongitude();
            dtostrf(lat, 3, 7, charlat);
            dtostrf(lon, 3, 7, charlon);
            strcat(readings, "please call me I i do not pick up the call please reach to my location:\n");
            strcat(readings, "http://maps.google.com/maps?q=");
            strcat (readings, charlat);
            strcat(readings, ",");
            strcat (readings, charlon);
            SMS.send("+917771914436", readings);
        }
    }
}
}

As you can now see you have an extra } at the end of your sketch, so your brackets are not balanced. That in itself is a syntax error.  Also you can see your function prototype slap bang in the middle of your loop() function:

...
        SMS.send("+917771914436", readings);
        void smsReceivingFunction(const char * number, const char * text);

        if (!strcmp(number, "+7771914436")) {           /* phone number
...

I think, though of course I can't actually test this since I don't have your hardware, that you really meant to start a new function at that point in your program, and of course that would mean finishing the previous function first: you cannot nest functions inside each other.  So I would guess your program should have looked something more like this:

#include <OneSheeld.h>
float lat ;
float lon ;
char charlat [30];
char charlon [30];
char readings [150];
int buttonPin = 11;
int ledPin = 12;

void setup() {
    // put your setup code here, to run once:
    OneSheeld.begin();
    /* Set the button pin as input. */
    pinMode(buttonPin, INPUT);
    /* Set the LED pin as output. */
    pinMode(ledPin, OUTPUT);
    SMS.setOnSmsReceive(&smsReceivingFunction);
}

void loop()
{
    charlat[0] = 0;
    charlon[0] = 0;
    readings [0] = 0;
    if (digitalRead(buttonPin) == HIGH) {
        /* Turn on the LED. */
        digitalWrite(ledPin, HIGH);
        delay( 1000);
        digitalWrite(ledPin, HIGH);
        delay( 500);
        lat = GPS.getLatitude();
        lon = GPS.getLongitude();
        dtostrf(lat, 3, 7, charlat);
        dtostrf(lon, 3, 7, charlon);
        strcat(readings, "please call me I i do not pick up the call please reach to my location:\n");
        strcat(readings, "http://maps.google.com/maps?q=");
        strcat (readings, charlat);
        strcat(readings, ",");
        strcat (readings, charlon);
        SMS.send("+917771914436", readings);
    }
}

void smsReceivingFunction(const char * number, const char * text) {
    if (!strcmp(number, "+7771914436")) {           /* phone number from which you will send the sms "PUT YOURS IN PLACE OF +1234567890" */
        if (!strcmp(text, "?")) {
            lat = GPS.getLatitude();
        }
        lon = GPS.getLongitude();
        dtostrf(lat, 3, 7, charlat);
        dtostrf(lon, 3, 7, charlon);
        strcat(readings, "please call me I i do not pick up the call please reach to my location:\n");
        strcat(readings, "http://maps.google.com/maps?q=");
        strcat (readings, charlat);
        strcat(readings, ",");
        strcat (readings, charlon);
        SMS.send("+917771914436", readings);
    }
}


-999 means that it didn't get a result from the DHT.  You need to filter them out - which you are attempting to do, but wrongly.

Your line of code:

if((DHT.temperature || DHT.humidity) > -25) {

is not doing what you thing it is.

If you start from the inner most brackets and "reduce", you get:

Is DHT.temperature or DHT.humidity?

That makes no real sense - except in C any number that isn't 0 is "true" and 0 is "false", so that really means:

Is DHT.temperature not 0 or DHT.humidity not 0?

And of course that will be "true" in 99.99999% of situations.  So insert that into the if again:

if (true > -25) {

Is true more than -25? Well, the reverse of what I stated above is also true: "true" is 1 and "false" is 0.  So is 1 greater than -25? Yes. It is.

Instead you should be testing each value separately:

if ((DHT.temperature > -25) && (DHT.humidity > -25)) {

Also your constraints are doing nothing.  constrain() doesn't modify (limit) the variable you pass to it. Instead it takes the value in that variable, constrains it, and returns the new constrained value to you for you to assign to a new variable.  So you should:

float temperature = constrain (DHT.temperature, -25, 70);

And then you can use the temperature variable instead of DHT.temperature, and you can guarantee that it will be between -25 and +70.


Attaching Microcontroller to DAC evaluation board

Your DAC uses the SPI protocol.  For that you want to connect it to the SPI header. That's the 6-pin (3x2) header numbered 11 on the uC32.

Connect:

The uC32's SCK pin to the DAC's SCLK
The uC32's SDO pin (MOSI) to the DAC's SDIN pin.
The uC32's SDI pin (MISO) to the DAC's SDO pin.

The other pins (I am not sure what they all do off hand, but the datasheet details them) can connect to any GPIO pins you like (except pins 11-13 which duplicate the SPI header - so you could use those instead if you prefer - 11=MOSI, 12=MISO, 13=SCK).


I prefer to use unions. example:

union fourbyte {
  uint32_t dword;
  uint16_t word[2];
  uint8_t  byte[4];
};

union fourbyte val;

val.dword = 0x03020100;

Serial.println(val.byte[0], HEX);
Serial.println(val.byte[1], HEX);
Serial.println(val.byte[2], HEX);
Serial.println(val.byte[3], HEX);

Serial.println(val.word[0], HEX);
Serial.println(val.word[1], HEX);

Serial.println(val.dword, HEX);


Arduino simultaneous push button for a counter

while (digitalRead(pbutton1) == HIGH); This blocks execution so nothing else can happen while the button is pressed. To avoid continous updating of the var while the button is pressed, create 3 booleans that keep track of the button state.

bool button1_is_pressed = false;
....
// If the button is pressed AND it was not previously pressed
if (digitalRead(pbutton1) == HIGH && !button1_is_pressed) {
    button1_is_pressed = true;
    lcd.print(count++);
}
// Not pressed - reset state variable
else if (digitalRead(pbutton1) == LOW) {
    button1_is_pressed = false;
}

Do this for the other buttons as well.


VSCode Platformio Schedule.h: No such file or directory

Did you install the libraries you need / use?

You could do it either via the platformio screen or add the names directly to the
platformio.ini

lib_deps =
    Firebase ESP8266 Client@>=2.7.8

And additionally ESP8266WiFi.h is an ESP8266 library
for the ESP32 you should use the lib #include <WiFi.h>

EDIT: To update the project libraries, select 'Update Project Libraries' from the project tasks.


Putting them all in a single condition like that is absolutely fine. C/C++ uses "short circuit evaluation" which means it will stop as soon as it's determined the outcome. If everything is combined using logical AND operators (&&) then that means it will stop as soon as one of them evaluates to false.

For example:

 if (blah() && foo()) { ... }

If blah() returns false, it will never call foo() at all because it already knows the overall outcome is false.

The reverse happens with the logical OR operator (||):

 if (blah() || foo()) { ... }

If blah() returns true in this case, it won't call foo(). That's because it already knows the overall outcome is true.


Does the square-wave nature of PWM dictate how much resistance you need?

It's... mostly wrong. For three independent reasons.

The LEDs themselves, like all diodes, absorb some of the electrovoltaic potential of the electricity passing through them, resulting in a voltage decrease in their circuit. This means that although 5V is being used to power the resistor and LED in a circuit, only some of that voltage is passing through the resistor. If we use a typical (for blue, white, and other exotic colors) forward voltage (Vf) of 2.8V, this means that the resistor only has 2.2V across it. For a 200ohm resistor, this means that only 11mA is passing through the circuit. If you want 20mA to pass through the LED you need to use a resistance of 110ohm instead.

Second, the voltage from the MCU pins themselves depend on the current passing through them. Section 32.7 of the ATmega2560 datasheet, "Typical Characteristics - Pin Driver Strength" has charts for voltage versus current for both sourcing and sinking current; at 20mA the voltage drops to about 4.5V, which means that the resistance required for a 2.8V LED drops from 110ohm down to 85ohm.

Third, although semiconductors (i.e. the MCU and LED) can be damaged when too much current passes through them, it is not the current itself that causes the damage. The current passing through the voltage drop results in a consumption of power, and this power subsequently turns into heat. This heat then causes the breakdown of the semiconductor material. Even a junky, third-hand LED can take bursts of current up to 35mA or so without being damaged, provided the duration is limited. With a PWM signal this duration is directly linked to both the frequency and the duty cycle of the signal. You will need to see the datasheet for the LED in question to figure out what the maximum safe current and duration are, but the implication is that if you keep the frequency high enough and the duty cycle low enough, you can get away without any resistor at all and both the MCU and LED will survive.


I think the problem is, that your delays are just too short, so you see the blinking not as blinking, but as a dim lit led.

Maybe you can try the following code:

void loop() {
 while (keepgoing == 1) {
  digitalWrite(ledone, HIGH);
  digitalWrite(ledtwo, LOW);
  delay(500);
  digitalWrite(ledone, LOW);
  digitalWrite(ledtwo, HIGH);
  delay(500);
 }
}

Is this working?


You can use an Arduino on a breadboard to get you going. From the breadboard, you can then develop a circuit on a pre-made PCB like this:

Then to a custom PCB, if you so desire.


I'm personally not really in to this RTFM kind of answer, but in this case it really do answer most of your questions about the bootloader part: http://arduino.cc/en/Hacking/Bootloader

About the error, a quick search on SO gives you this: https://stackoverflow.com/questions/24240285/arduino-nano-3-avrdude-stk500-getsync-not-in-sync-resp-0x00


My button stays on high if I press it once, what did I do wrong?

From what I can tell from your drawing, you have both sides of your button tied to 5V.  The green wire on one side and the blue wire through the resistor on the other.  So yes, the button will always read HIGH.

Instead, remove the resistor, tie one side of the button to the pin and the other side to ground.  Use INPUT_PULLUP in your pinMode cal instead of just INPUT.  Now a pressed button will read LOW and not pressed will read HIGH, so you'll have to reverse your logic in your code.  But the wiring will be much nicer.


This is a bug in a previous version of the library as mentioned on
https://github.com/bportaluri/WiFiEsp/issues/14

You can alternatively use WiFi.softAPgetStationNum() to get the count of stations connected to the AP interface.


In the Tutorial, which you are following, it says,

  So we will use the 2 wire method. Simply connect both the GND and VDD
  pins to 0V (yes both)

and it shows:

but I think you are missing this step, because i can't see any connection like that here:


TMC26XMotorTester:44: error: 'TMC26XStepper' does not name a type

Arduino libraries are normally written as a C++ Class.  When you start a sketch you normally tell the compiler where to find that Class and to Instantiate that class.  If the compiler does not find the Class and you attempt to Instantiate it, the compiler will telly you it does not know what to do.  That is, it will tell you the thing you are using (TMC26XStepper) does not describe anything or is not a Type.

Study the structure of Arduino libraries to make sure what you have installed agrees with the common Arduino library.

Also, newer version of the Arduino IDE can download and unpack libraries automatically given both the IDE and the library are setup to do this.


So you want to use the 5V voltage regulator on the Arduino serve as the supply for your 5V components, and feed the 5V regulator from the 12V supply that powers your solenoid?

The problem with that plan is heat. The voltage regulator on the Arduino is a poorly heat-sinked (heat-sunk?) "linear" regulator. A linear voltage regulator is basically a solid state circuit that converts excess voltage to heat.

The higher the supply voltage you provide to the voltage regulator, the more heat it generates for a given current load.

If you feed 12V into the Arduino's voltage regulator, it needs to reduce the voltage from 12V to 5V. 12V - 5V is 7V. So it will convert 7V to heat. You're only drawing ≈220 mA. Total power that will be converted to heat is 7V*0.22A, or around 1.54 watts of power. You should budget for at least 50% more current than you think you'll need, so lets use 330 mA. 7.0*0.33 is about 2.3 watts.

From a little research I did, it sounds like a typical Arduino voltage regulator can dissipate around 1 watt of heat. You're well over that limit even at your low ≈220mA number, so you need a solution that won't overheat your Arduino's voltage regulator.

If you were to instead supply the Arduino's voltage regulator with 7.5V, it would have a lot less work to do. That's a voltage drop of 2.5V. So for a 0.33 max current draw, that would be 2.5*0.33, or about 0.83 watts. That would be under the 1 watt ceiling. However, it sounds like your project is based on a 12V supply.

You could instead use an external switching voltage regulator to reduce 12V to 5V. (search for "boost voltage regulator".) Those are much more efficient, and don't generate nearly as much heat. You could then feed regulated 5V directly into the USB input on your Arduino, as well as supplying it to your other 5V components.


Changing preferences.txt to 4-space tabs, how to AutoFormat existing code?

The auto formatter (astyle) uses a separate configuration to the editor (crazy, I know, but that's the Arduino mentality for you...).

It uses a separate configuration, which is in the lib folder of your Arduino program, called formatter.conf.

Copy that file to the same location as preferences.txt so it doesn't get overwritten when you upgrade the IDE.
Edit the file and change indent=spaces=2 to indent=spaces=4

The auto format should now be the same as the editor format.


How does ESP8266 work as web server with Arduino?

The exact same way as any other ESP8266 example. The fact that you are using it as a web server doesn't change how you wire it.

For that specific code snippet it even tells you in the comments:

// make RX Arduino line is pin 2, make TX Arduino line is pin 3.
// This means that you need to connect the TX line from the esp to the Arduino's pin 2
// and the RX line from the esp to the Arduino's pin 3


How do you wire a ssr relay to a arduino nano

According to its datasheet, the FSS1-102Z doesn't work with DC-voltage. Also the minimal voltage required is 50VAC. Here is the excerpt from the datasheet:


if I change the string "Starting.." to "Start" it will run fine! This probably has something to do with filling up the RAM of the Tiny, right?

That symptom does suggest RAM overflow, in spite of the relatively low RAM use (28%) reported during compilation.

To reduce memory use slightly more, you can move the string "Starting.." to PROGMEM by changing from line 1 below to line 2.

  mySerial.print("Starting..");     // line 1
  mySerial.print(F("Starting.."));  // line 2

To save another handful of RAM bytes, change lines like mySerial.print("."); and mySerial.print("z"); to mySerial.print('.'); and mySerial.print('z');.  That is, you are printing single-character strings; each string has a null terminating byte; instead just print single characters.

References and discussion of the F() macro include 1, 2, 3, 4, 5 and also see  How do I squeeze code to fit onto an ATTiny.  Also, there are some really compact software serial libraries targeted for ATtinies, which may save hundreds of bytes of flash and dozens of bytes of RAM.


Is this legal?

typedef const char ProgChar;
ProgChar AT[] = "AT";

I would think that the PROGMEM can't be in the typedef, i.e.:

typedef const char ProgChar;
ProgChar AT[] PROGMEM = "AT";


The console port is only listening on 127.0.0.1 (for security), so only the Yun itself can connect to the console.

You can weaken security and open the port up to the entire local network by editing the file /usr/lib/python2.7/bridge/console.py and change the value 127.0.0.1 to 0.0.0.0.

Any machine on your local network will then be able to connect directly to port 6571.


Build a timer that starts and stops timing when 2 wires are broken

You have a number of problems in your code. For one thing, you are doing a lot of printing:

void loop() {
  // check and read value of input:
  int sensorValue1 = digitalRead(7);
  int sensorValue2 = digitalRead(6);
  Serial.println(sensorValue1);
  Serial.println(sensorValue2);

  if (sensorValue1 = HIGH) {
    startTime = micros();
    Serial.println(sensorValue1);
  }
  if (sensorValue2 = HIGH) {
    stopTime = micros();
    Serial.println(sensorValue2);
  }
  unsigned long totalTime = (sensorValue1 - sensorValue2);
  String strPrint = strTime + totalTime;
  Serial.println(strPrint);      // prints "Time"

}

At 9600 baud each byte output takes 1/960 seconds (about 1 ms). A println adds a carriage-return/linefeed to what you are printing so I estimate:

3 + 3 + 7 + 7 = 20 bytes (20 ms)

That is every time around the loop! You will soon find the output buffer filling up, and thus are limiting the rate at which you can test times to be the nearest 20 ms which makes using micros() a bit redundant. You won't get that accuracy.

Plus, the String class does dynamic memory allocation which will slow things down. Why use String at all? For example, you can print "Time" like this:

Serial.println ("Time:");

Next, this assigns not compares:

  if (sensorValue1 = HIGH) {

That statement makes sensorValue1 HIGH (always) and then tests if it is true, which it always will be. You want:

  if (sensorValue1 == HIGH) {

Finally, as mentioned by Majenko, make the inputs INPUT_PULLUP and wire the other end to ground, like this:

  pinMode(7, INPUT_PULLUP);   // set up pin 7
  pinMode(6, INPUT_PULLUP);   // set up pin 6

Edit - after amended question.

// declare variables
unsigned long startTime, stopTime;
unsigned long totalTime = (stopTime - startTime);

You don't declare totalTime like that. It appears you want totalTime to eventually subtract startTime from stopTime.

Just declare totalTime without any calculations, and do the calculation when it is needed. eg.

// declare variables
unsigned long startTime, stopTime;
unsigned long totalTime;

...

  if (sensorValue2 == HIGH) {
    stopTime = micros();
    totalTime = stopTime - startTime;
    Serial.print ("Time: ");
    Serial.println (totalTime);
    }  // end of second sensor tripped

Note the "==" there, without it the code thinks both sensors tripped immediately.


Reading inside critical sections from ISR

You should use critical sections around any operations that could potentially be affected by the execution of an ISR (or which could affect an ISR) that aren't atomic.

Simply put, an atomic instruction is one which can be represented by a single assembly language instruction. You can't interrupt during the execution of an assembly instruction, so anything that only takes one instruction can't be interrupted until it's complete.

Examples would be moving a value from one 8-bit variable (assuming an 8-bit architecture) into a register, storing an 8-bit value into memory, etc.

What instructions are likely to be atomic very much depends on the architecture that you are working on.  The only real way to be sure is to compile the code into assembly language and examine what is produced. Of course, that means learning the assembly language of your chosen architecture.

However: if in doubt, use a critical section. Better to be safe than sorry. But keep those critical sections as short as possible to not disturb the interrupts more than is needed.

For example, instead of starting a critical section, reading some volatile value, doing some calculations with it, and writing it elsewhere, you should use the critical section just to read the volatile value into a temporary variable. After the critical section, you can then do your calculations and things with it, while the interrupt is then free to be called again.


What I'm going to say is probably not the most efficient way to do it, but it should work: if your DUE is used as gadget and you wnat to detect the presence of a master, connect a GPIO to the +Vcc line of the usb port and either poll or program an edge triggered interrupt to detect when the line goes high.


#include "DHT.h"
#define Type DHT11
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int sensePin=2;
DHT HT(sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
int dt=1000;

void setup() {
  // put your setup code here, to run once:
   Serial.begin(9600);
   HT.begin();
   delay(setTime);
   lcd.begin(16,2);
 }

void loop() {
   humidity=HT.readHumidity();
   tempC=HT.readTemperature();
   tempF=HT.readTemperature(true);

   lcd.setCursor(0,0);
   lcd.print("Temp F= ");
   lcd.print(tempF);
   lcd.setCursor(0,1);
   lcd.print("Humidity= ");
   lcd.print(humidity);
   lcd.print(" %");
   delay(500);
   lcd.clear();

   Serial.print("Humidity: ");
   Serial.print(humidity);
   Serial.print("% Temperature ");
   Serial.print(tempC);
   Serial.print(" C ");
   Serial.print(tempF);
   Serial.print(" F ");
  }


Wireless Shield Not being detected w/ Arduino Uno R3

Your problem:

You have a CC3000 WiFi shield
You are using the WiFi library for the Arduino WiFi Shield
The Arduino WiFi Shield is a HDG204 based shield, not CC3000

Get the right library for your shield, install it, and try the examples and tutorials that come with it.


How can i get rid of the error "cannot convert 'String' to 'const char*'"

there is no reason for command to be a String array. Instead make it a const char**:

const char** commands = {"/test", "/say", "/reset", "/sleep"};


How do I pull chip select pin up and down, when I have CAN shield and Newhaven Display 4.3CTP-SHIELD-N share the same chip select pin(10)?

You will have to use a different chip select pin for one of the shields.  You should do it to the display shield since that goes on top.

Change the code to use a different chip select pin for the display shield
Break or cut off pin 10 from the display shield, and solder a wire from where pin 10 was to your newly chosen chip select pin.


You can either use a breadboard Or Female to Female Jumber wires.

Ofoucrse you can always solder yourself the two modules together with wires.

PS. Too low reputation to comment, so i insert this as answer


This is hard to debug from afar...

Your sketch looks correct (hardly surprising, since it's just the Blink example). But I'd try to use IO18/SPI_CLK for clock and IO23/SPI_MOSI for data, as these are the hardware SPI pins of the ESP32. It might very well be that using these pins removes the warning about hardware SPI.

As I don't know all the variants of a WS2801 strip... is it maybe one of those strips that runs at 12V and can only be cut every three LEDs? This would explain why there are three LEDs lighting up instead of one (because then there would be one chip for three LEDs -- in other words, each "pixel" in your leds array corresponds to three physical LEDs)

Then there might be a problem with the voltage output of your ESP32 board. The ESP is running at Vcc=3.3V. The chips of the strip are running at Vcc=5V and expect 5V on their inputs. A logical 1 is assumed when the input in question is 0.7 * Vcc, i.e. the input signal may not be less than 3.3V. Now imagine that the power regulator on your ESP board drives the ESP at a teensy bit less (e.g. at 3.25V) and the power supply for the strip outputs a teensy bit more (e.g. 5.1V) -- suddenly, a logical 1 from the ESP is at 0.637 times the strips' Vcc and therefore in the undefined limbo between 0.3*Vcc (highest definition for logical 0) and 0.7*Vcc (lowest definition for logical 1). A level shifter module would help here to increase the ESP's output signal voltage (costs a few cents when ordered directly from China).

Then, at last, are you sure that the color order of the strip is RGB (as stated in your setup line)? I've seen more strips using GRB or BGR... which would explain why you see blue instead of red.


How to slowly change direction of the stepper motor with AccelStepper?

I have tested it on real motor, and it works as I want with function .moveTo . Speed slowly changed from +maxSpeed to -maxSpeed acording to Acceleration
#define maxSpeed 1000
#define Acceleration 500
............
void setup(){
  stepper.setMaxSpeed(maxSpeed);
  stepper.setAcceleration(Acceleration);
}
void loop() {
 ............
 if(bDirection!=bDirection_last)
 {
  stepper.moveTo(bDirection?6000000:-6000000);
  ...........
 }
 stepper.run();
}