How to stop sending the last received char of UART echo function?

There are many, many problems with this code. The most fundamental flaw
is that it uses linear buffers, where you should be using circular
buffers instead. I'll come to this later. Now, if we look
at the details, in the header file:

#define Buf_OF      0x0200

This, and a few other macros, serve no purpose. Do not put "TODO" items
in the code: put them in a TODO file, or as comments. Strive to always
have your code in a clean state. More so when you post it in a public
place.
#define buf_mask Buf_s - 1

This is presumably intended to be used as a bit mask, but it will not
work reliably. For example, if you try to complement the mask as
~buf_mask, the preprocessor will expand that to ~Buf_s - 1, and the
compiler will interpret it as (~Buf_s) - 1, which is not what you
want. You should always parenthesize any expression you use in a macro,
as
#define buf_mask (Buf_s - 1)

Later,
void put_s(uint8_t *str);

If you want to be able to issue calls like put_s("Hello!");, then you
should declare the function as:
void put_s(const char *str);

Now, in the implementation, you have:
static volatile uint8_t rx_errors,tx_sBuf,rx_sBuf;

All those are unused. Remove them. Again, this is supposed to be a
program, not a TODO list.
Later,
uint16_t get_char(void)
{
    if (rx_cnt == 0)
        return NO_DATA;
    else if (rx_p < rx_cnt)
        return rx_buf[rx_p++];
}

The compiler should have warned you about this: what if both conditions
are false? In this case the function will return by reaching its end,
with no specified return value. This is undefined behavior. You should
probably return NO_DATA in this case. But then, that's what you should
return every time you are not returning valid data, so the function can
be simply written as:
uint16_t get_char(void)
{
    if (rx_p < rx_cnt)
        return rx_buf[rx_p++];
    else
        return NO_DATA;
}

Later, in ISR(USART_RX_vect),
if (rx_cnt < 32)
    rx_buf[rx_cnt++]=UDR0;
else
    rx_cnt = 0;

If you set rx_cnt to zero without updating rx_p, then the subsequent
characters that you will put in the buffer will be ignored by
get_char() until you fill the buffer up to rx_p. Thus you presumably
want to set rx_p to zero also. And if you do this at the start if the
ISR, you ensure that at least the current character is not lost:
// when the counter reached max value, reset the buffer
if (rx_cnt >= 32) {
    rx_p = 0;
    rx_cnt = 0;
}
rx_buf[rx_cnt++]=UDR0;

Further in the ISR:
if (!(UCSR0A & (1<<RXC0)))
    UCSR0B &= ~(1<<UDRIE0);

This makes no sense: if you have no pending character in the receive
register (which you should not have, as you have just read that
register), then you disable the ISR that serves the transmitter. The
transmitter and the receiver should be able to work independently:
remove those lines.
Then, in ISR(USART_UDRE_vect):
for (i=0;i<tx_cnt;i++)
    tx_buf[i]=0;

This serves no purpose. If you handle your buffers properly, you should
never access uninitialized data in them. Thus you will never read the
zeroes you are writing here. Again, remove those lines.
If you implement all the fixes above, you should end up with a code that
“kind of” works. There are still a couple of issues though:
Race conditions
If get_char() gets interrupted by ISR(USART_RX_vect), you can get
what is known as a “race condition”, which can lead to incoherent
behavior or data corruption. For example, testing rx_p<rx_cnt is not
atomic: the CPU has to read rx_cnt from RAM, then read rx_p, then
compare them. If the interrupt fires between the two memory reads, the
ISR can set both values to zero, then the test will compare the old
rx_cnt with the new rx_p (which is now zero) and incorrectly assume
there is valid data to be returned.
There are other places where this can byte you. For example, rx_p++ is
not atomic either, it's a read-modify-write sequence that can very well
be interrupted in the middle. And there are similar issues if
put_char() gets interrupted by ISR(USART_UDRE_vect).
The fix for these issues is to disable interrupts while you are in the
“critical sections” that access data shared with the ISRs. This can be
done using noInterrupts()/interrupts() pairs or, if you prefer the
avr-libc style, with atomically executed code blocks. For
example:
#include <util/atomic.h>

uint16_t get_char(void)
{
    uint16_t result = NO_DATA;
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
        if (rx_p < rx_cnt)
            result = rx_buf[rx_p++];
    }
    return result;
}

A similar protection is needed in put_char().
Linear buffers
This is the main flaw, because it will require you to rethink a
significant part of your code. Imagine what can happen if the UART
transmitter lags slightly behind your program calling put_char(). Say
you reach tx_p = 30 and tx_cnt = 32. Then your
buffer has 30 “empty” cells (from 0 to 29 the space is available, as
that data has already been sent) and two cells with bytes pending to be
sent (at positions 30 and 31). If you call now put_char() to send an
extra byte, that byte will be lost (because tx_cnt<32 is false). This
is unacceptable: you should not loose data when the buffer is almost
empty!
The solution is to put the extra byte at position 0, the next one at
position 1, etc. But this creates a complication: now the pending bytes
are at positions 30, 31, 0, 1... At this point your buffer becomes a
circular buffer. It's not a big deal, but you must
read about the subject before you try to implement it.
Note that the same issue applies to the receive buffer: both buffers
should be made circular.


Regarding running multiple functions using millis

First of all, you should notice there is a problem with your logic:

 int A = digitalRead(2);
 if(A == LOW)
 {
  b = millis();
 }

Here you are testing the state of the pin. If it's LOW you take a
record of the time. This is wrong. What you want to record is the time
at which the inputs falls, not when it's LOW.
This is called state change detection. In order to implement
it, you have to compare the pin state that you just read with
the previous state. The correct condition is “if the pin was HIGH
last time I read it and is now LOW”:

// Global variable:
int pin_state = HIGH;

// Within loop():
int new_pin_state = digitalRead(2);
if (pin_state == HIGH && new_pin_state == LOW) {  // it just fell
    time_of_fall = millis();
    pin_state = new_pin_state;
}

Note that this assumes that the default state is HIGH. If the pin
turns out to be LOW at power-up, then the code will assume it just
fell when the program started.

Next, you have to remove any occurrence of delay() from your code.
That will only make your timings wrong. At this point you have
non-blocking code that can easily be adapted to handle multiple input
channels.

Then you have to identify the variables that are channel-specific, and
have a per-channel version of each variable (arrays are useful here).
Then your code only needs to loop through the arrays.

Instead of having multiples arrays, you can make the code cleaner by
grouping all the channel-specific data into a single data structure:

struct Channel {
    byte pin;
    byte state;
    unsigned long fell, rose;  // times of fall and rise
};

This way you can have a single array that holds all the data for all the
channels:

const int CHANNEL_COUNT = 5;

Channel channels[CHANNEL_COUNT] = {
    { 2, HIGH, 0, 0 },
    { 3, HIGH, 0, 0 },
    { 4, HIGH, 0, 0 },
    { 5, HIGH, 0, 0 },
    { 6, HIGH, 0, 0 }
};

The code now becomes quite simple: you just loop through the array and
handle one channel at a time:

void setup()
{
    for (int i = 0; i < CHANNEL_COUNT; ++i) {
        pinMode(channels[i].pin, INPUT);
    }
    Serial.begin(9600);
    Serial.println("pin,fell,rose,low time");
}

void loop()
{
    for (int i = 0; i < CHANNEL_COUNT; ++i) {
        Channel &c = channels[i];
        byte new_state = digitalRead(c.pin);
        if (c.state == HIGH && new_state == LOW) {  // input fell
            c.fell = millis();
        }
        else if (c.state == LOW && new_state == HIGH) {  // input rose
            c.rose = millis();
            display_channel(c);
        }
        c.state = new_state;
    }
}

The function display_channel() is left as an exercise to the reader
;-) (hint: it's prototype should be
void display_channel(const Channel &c); in order to avoid
unnecessarily copying the data structure.

Next step in code modularity would be to turn the Channel structure
into a class with a proper constructor, and make display_channel() a
method of that class.


How do i use the Keypad.h library to get my keypad press to run one
line of code when i press a button and another line when i release the
button

Edit 1:
void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    Serial.println(key);
  }

  if (keypad.isPressed('*'))
  {
  randomr = random(10, 2000);
  Serial.println(randomr);
  }

}

From the link: https://playground.arduino.cc/Code/Keypad/ you can find all the functions supported by the Keypad library.
One relevant function is
KeyState getState()

It returns the current state of any of the keys.
The four states supported are IDLE, PRESSED, RELEASED, and HOLD.
Hence you can use this function for the keys you are interested in.
Also, if helpful consider this function as well.
setHoldTime(unsigned int time)

Set the number of milliseconds the user will have to hold a button until the HOLD state is triggered.

You can find the keypad.h library in action here. I motivate you to also try the code with this online Arduino emulator
you already have a builtin function defined to get the status of the key pressed
void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    Serial.println(key);
  }
}

I have a poorly taken screenshot for the same for your quick reference.
Original Arduino emulator link: (you can play with the logic)

https://wokwi.com/playground/keypad

Disclosure: We work at wokwi.com, to create interesting tools and libraries for the Arduino community
https://github.com/wokwi
for a more free demonstration of the libraries:
https://github.com/wokwi/arduino-libraries


How to avoid pulling the RX0 pin to reset sketch

It looks like your RFID readers are very chatty on startup, and the board is going into bootloader mode.

I'd consider either controlling the RFID reader's power using another pin (and a transistor or mosfet if the reader needs more than 20mA), or using a gate ( AND for instance, or a simple switch IC like the 4066) that you can control to disable the RX0 input until program start.

Another thing I've done in the past is multiplexed multiple serial devices to one serial input.  The RFID readers probably have outputs that indicate a card presence, so use those and a multiplexor.  When the card presence is indicated, connect that serial port using the multiplexor, read the card and act accordingly, then wait for another card detect event.


This blog describes the author's open-source, cross-platform library in C to talk to an Arduino via serial. The library is available on GitHub. A C project on your Mac can use it to communicate with your Arduino. You'll probably want to create a simple command protocol to keep the two in sync, as serial is pretty "barefoot" by itself, being just a stream of bytes with no markers, packets, or check-sums unless you impose such structures on your data, yourself. It probably doesn't need to be very complex, depending what your application needs.

I have found similar projects in Python and in Java for the Mac/Windows/Linux/<whatever> side; there's plenty of work already done for you.


Can I access individual pixels on my 16x2 LCD display

It's possible to define custom characters for “generic 16x2 LCD displays” [ie, displays based on HD44780 or equivalent controllers], but only up to eight such characters at the same time.  See LiquidCrystal.CreateChar for details.  See page 2 and part of page 1 of the Print degree symbol ° on LCD arduino.cc thread for create-character examples that don't use the library.  Page 1 of that thread also shows a table of all the characters built into typical HD44780 controllers, some of which may perhaps meet your needs.

For pixel-by-pixel LCD control, look at graphics LCDs, eg the KS0108 or LCD12864 and similar.


utility/spi_com.h error when compiling Marlin for Arduino mega with Ramps 1.4

trying to load Marlin 2.0.x onto Arduino Mega

I have no specific knowledge of Marlin.
For the moment, I'm ignoring the fact that it seems to be looking for STM32 files which would seem to play no role on an Arduino Mega.
I cloned the Marlin github repo and found no mention of a file "MarlinSPI.h" in the 2.0.x branch.  There is however a MarlinSPI.h in tag 1.1.9.1
You appear to be working with the code for the wrong version (or branch) of Marlin.


Personally I like to try to use red wires for +5V, black or blue for ground, and yellow for data. However as Majenko said in a comment, the colour is irrelevant to the operation.

The usefulness of colour is just that if you stick to a system (like red for +5V and black for ground) then there is a visual check you make when connecting up a circuit, so you don't accidentally put things in backwards, like you might if every wire is yellow.

Also, if you run half-a-dozen wires from one place to another, using different colours is another way of making it easier to see you have connected the correct things together.

Having said all that, the colour does not otherwise affect things.


Saving a .txt file to SD Card and Reading each content data to txt file then save it to a variable

myFile.read() reads just one byte from the file - not the whole file or even a whole line.

You're reading one byte, then printing it. Then reading a second byte, storing that in a variable, then printing the variable. Then you loop back to the beginning again.

So you're printing alternate "odd" bytes, and storing / overwriting the variable with "even" bytes. So you just get nonsense.

You're storing the data in your file as ASCII text, so it's necessary to read the entirety of each line and then convert that string of characters into a number. Or read each character in turn and manipulate your total value for the line.

For example:

long savedNum = 0;
long numberOne = 0;

while (myFile.available()) { // Something left to read
    char c = myFile.read(); // Get the next character
    if (isdigit(c)) { // It's a number 0-9
        savedNum *= 10; // Make room by decimal shifting to the left
        savedNum += (c - '0'); // Convert the character to a number and add it to the total
    } else if (c == '\n') { // End of line
        Serial.print(F("The number is: "));
        Serial.println(savedNum); // Show us the number
        numberOne = savedNum;  // Store it somewhere else - enhance this for multiple numbers.
        savedNum = 0;  // Reset to 0 ready to read the next line
    }
}

The Arduino API (Stream class) also includes some handy helper functions, such as:

int num = myFile.parseInt(); // get the next integer

There's no parseLong() though, but despite its name, parseInt() actually returns a long.  That reads characters up until it gets a non-numeric character and converts them to a long using the same method as in my example. It doesn't distinguish lines, though, so can be used to get separate numbers on the same line, such as 32847,2345534,12,-43.

With your file though you may need to filter out the extra \r that may be in there from the line endings or you'll get missing numbers.


Difference between Ciao REST server and Ciao REST connector and when to use each or the other

I don't know about "Ciao" but generally a rest server answers requests from a client that is connecting via a rest connector.
You client will use POST, GET, PUT, etc. to ask the server to provide a service.  This could be as simple as "GET .\index.htm" or more likely posting information to be stored in a database.

The server will sit waiting for these requests and will have handling routines for each specific request and might supply a response.


Accessing raspberrypi.local from Nodemcu

In order to access the API, your NodeMCU needs to know the IP address your Pi has at this time. There are several ways to resolve raspberrypi.local to the actual IP. Assuming the NodeMCU got its IP assigned by your WiFi hotspot, it also received a DNS server IP. This is where the NodeMCU would ask first. However, if this DNS server is hosted by your internet provider, it obviously would not know what to respond when asked for your raspberrypi.local.

Another way, especially for .local domains, is mDNS. NodeMCU has a module to do that.

If you work with this a lot, consider running a local development network with your own DHCP/DNS combo. dnsmasq is a good place to start. Lots of tutorials online. The Pi can host that for you.


Running sensor input for given time, stopping, then running seperate scheduled relay output

If you are just running the relays off the 1 Amp supply, and there aren't more than 6 relays they shouldn't draw more than an amp.(I will edit this statement if need be)
What you can do in the way of coding you can is to do a classic spinoff of using the millis() function.

//monitors temperature and schedules its operations
//RSM
#define TimeBetweenHydration 10000  //10 seconds
#define TimeBetweenThermal 1000  //1 second
#define Temperature_Thresh  25   //25°C

float temperature = 0.00;

unsigned long lastTempReadTime = 0;  //keep track of the time temperature was checked
//boolean MotorOn = false;  //state monitoring

unsigned long lastWaterTime = 0; //last time the system did something with the watering thing
//boolean Watering = false; //state monitoring

// other variables related to specifics
//…
//

void setup(){

//setup of analog inputs
//setup of digital pins

}

void loop(){

 unsigned long presentTime = millis();

if((presentTime - lastTempReadTime) > TimeBetweenThermal){
lastTempReadTime = presentTime;
 int inADC = analogRead(0);

  //do whatever conversion is needed to get a value of the temperature
temperature = inADC*3.14;

if(temperature > Temperature_Thresh){

//   if(!MotorOn){
     digtalWrite(RLY, HIGH); //turn on pump
//     MotorOn = true;
//  }
 }
  else{
  digitalWrite(RLY, LOW); //turn off pump
  }
}

   if((presentTime - lastWaterTime) > TimeBetweenHydration){
   lastWaterTime = presentTime;

//put your watering code stuff here

  }
}

If you want to make the pump run without a microcontroller you could use a comparator with the thermistor and use its output to switch a transistor. I do not have the 555 timer art skills.

T1 is you thermistor. You should use the values listed for R1 - R3. The transistor, coil and flyback diode are there to show how you should connect it up, the coil could be a motor or a relay to control the motor. The comparator changes around the 30-40Kohm mark.


just add a = EEPROM.read(addr); in your setup
also, you can remove byte value and use a you wrote to memory in the previous line


Can a timer be used in both CTC and (fast) PWM mode simultaneously?

Technically no. CTC and PWM are distinct modes of operation.

However, more advanced PWM modes, specifically mode 7 for 8-bit timers and modes 14 and 15 for 16-bit timers, allow specifying an arbitrary timer duration in OCRxA or ICRx while still allowing PWM operation using the other output compares.


Will adding Ethernet shield reduce the IO count of Arduino?

You should use a Mega if you really need so many gpio pins.

Arduino Ethernet and WiFi shields and their clones use 3 GPIO pins with SPI function with connection on ICSP header. Next they use the Slave Select signaling pin 10 and the SD card Slave Select signaling pin 4. The shields are compatible with Mega. So you should still have enough pins.

esp8266 can be connected to SPI. then it uses the same pins like the Ethernet shield except of the SD card slave select pin.

if you connect esp8266 to Serial port, then all the pins are free. Mega has 4 Serials.

esp8266 is cheaper but you need to connect it with level shifters and have a good power supply. there is no good esp8266 shield for now. The Mega + WiFi board from Robotdyn has the esp8266 on board with Serial connection.


How to control an Arduino connected device accross the Internet?

Perhaps a message brokering service like MQTT is what you are looking for. Far too much to it to explain it all here, but basically it lets you publish messages and subscribe for messages, over a network.


Blynk, but continue program if Blynk connection fails

You can try my Blynk_WM or Blynk_Async_WM library with their Blynk.begin() functions are not blocking.

Check Why using this Blynk_WiFiManager with MultiWiFi-MultiBlynk features
Why using this Blynk_WiFiManager with MultiWiFi-MultiBlynk features
You can see that the system automatically detects and connects to the best or avaiable WiFi APs and/or Blynk Servers, whenever interruption happens. This feature is very useful for systems requiring high degree of reliability.
Moreover, this Blynk.begin() is not a blocking call, so you can use it for critical functions requiring in loop().
Anyway, this is better for projects using Blynk just for GUI (graphical user interface).
In operation, if WiFi or Blynk connection is lost, Blynk.run() will try reconnecting automatically. Therefore, Blynk.run() must be called in the loop() function. Don't use:
void loop()
{
  if (Blynk.connected())
     Blynk.run();

  ...
}

just
void loop()
{
  Blynk.run();
  ...
}

It's also beneficial to search in Blynk Forum for more information and examples


SD Library function doesnt work while using second SPI port with ESP32

Ok i found the solution. It was not too complicated. I just assumed the problem was in the code. This works well enough (dont ask me about the counter--)

  unsigned short EKG_recording::count_files_from_SD() {

  root = SD.open("/");
  root.rewindDirectory(); //Sets to beginning of directory

  while (true)
  {
    File entry = root.openNextFile();

    if(!entry){
      Serial.println("Anzahl der Daten");
      counter--;
      return counter;
    }
    counter++;
    entry.close();
  }
}

It was just because i used SD.open() always inside the class-functions, so every file root was bound to the class.


Since you're (probably) using a C++ compiler, it's usually easier to declare structures like this:

struct CarSpeed
{
    int fr, fl, br, bl;
};

(Note that there's no need for typedef.)

You can then return an instance of it directly from your function:

CarSpeed ReadSpeed()
{
    CarSpeed data;

    data.fr = ...;
    data.fl = ...;
    data.br = ...;
    data.bl = ...;

    return data;
}

You can call it from another function like this:

CarSpeed speed = ReadSpeed();

That will copy the contents of the structure into an object called speed. In this example, it's an 8 byte structure so it's a non-trivial copy. That shouldn't be a big problem unless you're calling it very frequently though.

As noted in another answer, using a pointer (or a reference) can be more efficient if necessary.


Sensing concentration of methane with MQ-4 methane sensor?

Actually, you are getting raw data from the sensor. A little bit of math should be done in order to calibrate it and based on the chart in datasheet, measure the real value in PPM.

The calibration basically helps you find R0, which is an internal resistance (along with RS form a voltage divider) that could be derived by doing calibration in a clean environment. After that, you use R0 to calculate a ratio and then look at the datasheet's chart to measure whatever gas you want since there is a curve describing it.

Please refer to this tutorial for more information. I have developed a similar application using MQ-4 before.

It is related to MQ-2, you may have noticed that all theses sensors have similar features and principle applications.


The constructor in your Pwm class declares a local variable LED which it sets equal to the parameter led. You use the member variable LED in other methods, so you probably meant to set the member variable of the same name, not create a local.

Remove the int from before LED = led in the constructor.


How to use more than 2 I2S microphones on MKR Zero?

By definition, the I2S bus only allows up to 2 channels to be transmitted at the same time.  Here is a quote from the Details section of the Wikipedia's I2S page:

  The word select clock lets the device know whether channel 0 or
  channel 1 is currently being sent, because I²S allows two channels to
  be sent on the same data line.

This is further illustrated in Figure 8 / Page 6 of the Knowles SPH0645LM4H data specifications.  In this figure we see where 2 SPH0645LM4H microphones are configured (ground or Vcc to the SEL pin 2) such that they can be multiplexed onto the I2S bus by the I2S bus master.


Do I have to use an external power supply when connecting an ultrasonic sensor to Arduino?

From the question I assume you power your Arduino via USB in which case you don't need an external supply. The HC-SR04 draws 15 mA with is far below the specifications for USB. I did this myself some time ago:


It is called at the end of the reception of the entire packet - i.e., when the slave receives the final STOP bit.  It is passed the number of bytes received (which is the number of bytes you requested since I2C has no way of being able to work out if it is actually receiving real data - see here) as the only parameter so you know how many bytes you can then read from the internal buffer without overflowing it.


How is interaction with CDC device with no interface endpoints working?

Micronucleus uses control transfers to upload code (it's not a CDC device). You don't need an endpoint for control transfers - they use the implicit endpoint 0 that is always present whether you define one or not.

You only need to define endpoints for interfaces that want to communicate using bulk, interrupt or isochronous transfers.

Bus 003 Device 073: ID 16d0:0753 MCS Digistump DigiSpark
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x16d0 MCS
  idProduct          0x0753 Digistump DigiSpark
  bcdDevice            1.02
  iManufacturer           0
  iProduct                0
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           18
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         0 (Defined at Interface level)
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
Device Status:     0x18c0
  (Bus Powered)
  Debug Mode


control Arduino board using Android sensors and wifi?

Is it possible?  Yes, it's certainly possible.  You can read the sensor values from within an Android program. It's possible to get Android to communicate with the Arduino through the USB.  The Arduino can be programmed to respond to what it gets through the serial.

Is it easy? Well, that depends on how good you are at Android programming.

One good place to start might be the ArduinoFirmata-Android project.  Don't worry about programming the Arduino, just install Firmata on it.  Then it's all down to how you program the Android device.  The Arduino just becomes a peripheral to your phone.


Only if you drop to low-level access, and only if the pins are on the same port.

#define pinset 0x55

 ...

PORTC |= pinset;
delay(1000);
PORTC &= ~pinset;


Does the reset button work when not powered?

The reset on an Arduino does not erase anything. It merely restarts execution of an already uploaded program. Also the AVR needs to be powered on for it to realize whether it has been reset.

Every time you power on an Arduino it automatically starts code execution from the beginning of the program in the flash memory.


Simply reverse the steps you took on the sending side.

Create a char array of sufficient size as well as an index variable to keep track of your position within the array. An Arduino String may be more convenient, though they can cause a lot of problems.
In a loop, use available() to wait for incoming chars and add them to the array you've created, using your index variable.
Keep going in the loop, while checking for that unique character (\n, perhaps) that signals the end of a packet. Add this last byte to the array and then terminate the string with null or \0.

If you want to re-use the array for another packet, simply set the index variable to 0 and continue.


Uploading Marlin Firmware To Melzi-ATmega1284p

It looks like the Marlin firmware supports two versions of the Melzi board, although it isn't clear if it specifically includes the 2.0 version. The best thing to do is just try it. In the Configuration.h file find the section where it says:

#ifndef MOTHERBOARD
  #define MOTHERBOARD BOARD_ULTIMAKER
#endif

Now replace BOARD_ULTIMAKER with BOARD_MELZI_1284 and try that. If that doesn't work you can try just BOARD_MELZI. If neither of those work, you are out of luck, unless you are willing to dig in and do the pin mappings yourself.


Numbers retrieved from an rtc are usually returned as a char or integer.

On this basis, you want

ones_column = bytefromrtc % 10;
tens_column = (bytefromrtc / 10) % 10;
hundreds_column = (bytefromrtc / 100) % 10;

the % operator returns the modulus - if you divide 42 by 10, the answer is 4, with a remainder of 2. % returns the remainder, in this example, 2.

To do the tens column, first get rid of the last digit by dividing by 10, then do the modulus as above. Since bytefromrtc is not a float, if you divide it, you lose the remainder - 42 / 10 = 4, not 4.2.

If the output is a word, or integer, or long integer, the method is exactly the same, except for the number of digits you can get out.


How do I connect velostat to an arduino?

Usually a variable resistance sensor is used in a voltage divider circuit:

In the above example a thermistor is connected to the positive supply and a pull down R1 is connected to ground.  The voltage where they meet is measured using one of the Arduino's analog inputs pins.

Choosing R1 is tricky.  If it is too large compared to the variable resistance sensor the voltage fluctuation at Vout will be too small to measure.  The same problem exists if R1 is too small compared to the variable resistance sensor.  Also, you need to mind the current through the sensor.  If the combined resistance of R1 and the sensor is too small the current may damage the sensor, over heat R1 and / or put a heavy drain on your power source.


See the configTICK_RATE_HZ configuration option.
Also note it is better to specify times in milliseconds, rather than ticks, so you can change the tick frequency without effecting the timing (other than the resolution of the time).

The pdMS_TO_TICKS() macro can be used for that purpose, for example to create a delay of 100ms.

const TickType_t xBlockTime = pdMS_TO_TICKS( 100 );
vTaskDelay( xBlockTime );


The link you posted describes a TFT LCD Touch screen unit with the SPFD5408 controller, referenced in this Instructable for use with the Mega. You might start there and migrate to the Yun once you get the screen working.


Atmega328p clock and safe operation zone

Just let CKDIV8 set (it just sets system clock prescaler to /8). And you can set different system clock prescaler later.

For changing system clock prescaler you need:

#include <avr/power.h>

And:

clock_prescale_set(clock_div_2); // possible values are clock_div_1 ... clock_div_256

Just don't forget that millis, delays and basically everything based on F_CPU might be slower/faster when prescaler gets changed.


Most digital pins on Arduinos are qualified to handle up to 25 mA typically and 40 mA at most.  If more current than that is drawn or sunk, the pin voltage will drop or rise, out of specification.  This is due to resistance in the pin drivers, and by Ohm's law, voltage equal to current times resistance will develop.  That “lost” power (voltage times current) is converted to heat within the microcontroller, and can damage it.

The fan motors probably draw rather more than 25 mA; they probably require a few hundred mA.  You can add transistors or motor controllers between the Arduinos and the fans to deal with such current loads.


Modifications to the ArduinoISP.ino sketch
I made the following changes to the ArduinoISP.ino file it exists in IDE version 1.8.13, and uploaded it to the NodeMCU board.
In short, I commented out (by way of #if 0) the heartbeat, err, etc LED related stuff.  Not doing this causes the board to reset for reasons that would probably be apparent if I researched it, but I haven't and since I don't plan on using the LEDs and that you may not, I figured I would get this to you sooner.
I changed RESET to be SS which on NodeMCU is D8.
Why LED related code causes resets
... Out of curiosity I just went and looked at the ESP-12F and ESP8266EX datasheets.  GPIO7, GPIO8, GPIO9 all go to the ESP-12F's SPI flash (program storage), so ostensibly monkeying with them interferes with the modules ability to keep executing from the SPI flash.  They're not routed to NodeMCU pins, probably for that reason.  So there's the answer to that.
Differences
@@ -70,7 +70,7 @@
 // The standard pin configuration.
 #ifndef ARDUINO_HOODLOADER2

-#define RESET     10 // Use pin 10 to reset the target rather than SS
+#define RESET     SS // Use pin 10 to reset the target rather than SS
 #define LED_HB    9
 #define LED_ERR   8
 #define LED_PMODE 7
@@ -216,15 +216,17 @@

 #endif

 void setup() {

   SERIAL.begin(BAUDRATE);

+#if 0
   pinMode(LED_PMODE, OUTPUT);
   pulse(LED_PMODE, 2);
   pinMode(LED_ERR, OUTPUT);
   pulse(LED_ERR, 2);
   pinMode(LED_HB, OUTPUT);
   pulse(LED_HB, 2);
+#endif

 }

@@ -276,6 +278,7 @@
 }

 void loop(void) {
+#if 0
   // is pmode active?
   if (pmode) {
     digitalWrite(LED_PMODE, HIGH);
@@ -291,6 +294,7 @@

   // light the heartbeat LED
   heartbeat();
+#endif
   if (SERIAL.available()) {
     avrisp();
   }

NodeMCU to ATTiny85 ISP Wiring
The board is wired to the ATTiny85 as follows:
NODEMCU 3.3V -> ATTINY85 PIN 8
NODEMCU GND  -> ATTINY85 PIN 4
NODEMCU D5   -> ATTINY85 PIN 7
NODEMCU D6   -> ATTINY85 PIN 6
NODEMCU D7   -> ATTINY85 PIN 5
NODEMCU D8   -> ATTINY85 PIN 1

On the NodeMCU you'll find all 6 of these together on the right.
Verifying AVRDUDE functioning
avrdude -P /dev/ttyUSB0 -c stk500v1 -b 19200 -p attiny85

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e930b (probably t85)

avrdude: safemode: Fuses OK (E:FF, H:DF, L:71)

avrdude done.  Thank you.

I've been playing with this chip, so don't be surprised that I don't have the same fuse values you have.


Converting Arduino LCD Programs to Serial I2C LCD code

i got my lcd working on I2C following the steps in this link http://forum.arduino.cc/index.php?topic=128635.0


Using rotary encoders with pin change interrupts

check the library to see if it debounces the input.

if not, write your own code. usually state machine-based approaches are very resistant to switch bounces.


Sending serial data to Arduino from Matlab(not using support package)

Got it, instead of depending on the Serial object, i sent the line feed to arduino. All this time it has been waiting for the Line feed that never arrived.

delete(instrfindall)
s = serial('COM3', 'BaudRate', 9600); %38400
fopen(s);
pause(0.1);
text = input('enter','s');
fprintf(s,'%s\n',text,'sync');
pause(0.1);
d = fscanf(s,'%s');
pause(0.1);
delete(instrfindall)


There is the aJson library that allows you to work with JSON objects in Arduino.

However, depending on the complexity of your program, I would just do it manually to save memory. You may be able to just copy the functions you want out of the library.

Then check out the WebClient library which has an example for making a POST request at the bottom.


The thing to remember about electrons is they are a negative charge.  That means that the direction of current flow (positive charge) is opposite to the direction of flow of the actual electrons (negative charge). Picture it like those "compression jams" you get on the motorway (freeway) where cars that are travelling too close together have to slam their breaks on to avoid running into each other.  The one at the front slams its breaks on briefly then carries on. The one behind has to do the same, and so on and so forth.  You then get a wave effect travelling in the opposite direction to the direction of travel of cars as they slam their breaks on in turn.  The cars are moving forwards, but the compression jam is moving backwards.  Similar in a circuit - the electrons are moving forward, but the charge is moving backwards.

Another way to visualize it is as a bubble in a pipe of stationary water.  The bubble moves in one direction, but in order for it to do that the water has to flow past the bubble in the opposite direction.*

So the current flows out of pin 13 through the LED and to ground, but the electrons themselves are actually flowing from ground through the LED and in to pin 13 (where they eventually return back to ground through the power supply).

For how the IO pin works it's best to picture it as a pair of switches - one connected to Vcc and one connected to GND.  For instance, this is the LED wired up with the IO pin set to HIGH:

You can see that S1, being on, forms a circuit between the battery and the LED to allow the current to flow.

When the IO pin is set to LOW the circuit looks a bit like this:

You see that S1 is now turned off, and S2 is turned on.  the connection from that battery is now broken, and current can't flow.

But, you ask, what is the point of S2 here? It doesn't actually do anything.  No, not in that circuit it doesn't. But consider if you re-arrange the circuit to be like this:

Now it's S2 that is controlling the connection to the battery.  S1 is now the redundant switch.

This leads to some terminology.

When S1 is closed the IO pin is said to source current since it is pretty much connected directly to the positive power source.

When S2 is closed instead the IO pin is said to sink current since it is connected to ground, so current can "sink" down to ground through it.

As far as breadboards are concerned - they are just collections of metal strips that are used to join wires and component leads together in whatever way you need to.  There is no one part of it that is any different to any other, and there is nothing that says you must use this bit in a certain way, or that bit in another way.

Your typical breadboard has sprung metal clips that are arranged in this pattern:

You can use any collection of holes for any purpose you choose.

That said, normally the blue (or black) marked line of holes down each side is used for ground, and the red line of holes is used for power.  As both sides of the board are separate it is possible to use different voltages on each side, or the same voltage on both sides, etc.  That can be especially useful when you're working on a circuit that has, say, +3.3V and +5V in it.  Another common split usage is for a positive voltage on one side and a negative voltage on the other - common when working with op-amps.  Just remember which is which.

* This is a complete lie, but it's as close as you need to know at this point in your education. https://en.wikipedia.org/wiki/Lie-to-children


Can anyone recommend a breadboard for the new Arduino 101?

A breadboard is nothing but a way to attach multiple wires to the same pins. There are many different kinds as can be seen in these images. There's no right or wrong when it comes to breadboards, as long as you have enough pins to prototype you should be good to go.


Terminal read-only serial monitor without blocking serial port for sketch upload

(using screen, socat and others) but none of them deals with the question how to not block the port.

Other pointers on how to solve the issue are appreciated!

I say:

Virtually all hardware problems can be solved with software. But, sometimes, the $50000 software problem can be solved with the $2 hardware solution.

This is one of those cases. Buy a CP2102 6-pin serial UART USB adapter for < $2 on Ebay, or for < $10 on Amazon, to provide a second serial interface to the same Arduino (both connected to the same hardware UART built in to the Arduino's ATmega328 mcu). Let the main USB serial interface handle code uploads to the Arduino. Let this 2nd, external UART handle READ-ONLY from the Arduino!
Plug it in:
Arduino     CP2102 USB 6-pin UART
-------     ---------------------
Tx          Rx
GND         GND

Done. Do NOT plug in the CP2102 Tx to anything.
Now, use screen, or my crude datalogging Python serial terminal I wrote here (eRCaGuy_PyTerm), or a 2nd instance of the Arduino IDE with the Serial Monitor, or any other serial terminal for that matter, to read from the CP2102 while the Arduino's built-in USB adapter does code uploading.
Two serial interfaces to the same pins on the Arduino: one does Tx/Rx to/from the Arduino, while the other does only Rx to read from the Arduino.
I use a 2nd UART like this all the time as a trick to allow me to read the data from the Arduino into one Serial Monitor in one instance of the Arduino IDE so I can see the numbers, and I use the external CP2101 USB adapter to read the same exact data from the Arduino into the Serial Plotter of another instance of the Arduino IDE so I can see the live, plotted graphs!
It's amazing how well this works. Quick hack. Easy solution.

Note: to you use my eRCaGuy_PyTerm Python serial terminal, first set all your serial parameters inside the user_config.py file, then run python3 serial_terminal.py to run the program. It is a 2-way serial terminal, with datalogging. It works quite well. I really should improve its readme and post some examples someday.


I rather suspect the AB Shutter 3 is a Bluetooth HID device (like a keyboard or a mouse). The HC-05 can only communicate with Bluetooth Serial devices, such as the HC-06 or systems that can emulate a serial device (such as a computer or a smartphone).

You won't get them to communicate no matter how hard you hit them.


Setting a Pin to HIGH to simulate a button with a "pull up" resistor

First of all, I don't think you will need full simulation of a button. There are a couple of things this approach won't have:

Bouncing: it'll be (kinda, minus interference) a square wave. With a real button, the metal contacts "bounce," thus creating a weird waveform. Depending on interference, you'll still need debouncing code, although I would be surprised if it was necessary. I'd inlcude it in case I modified it to add a real button and/or there's some weird interference.
The time it's "pushed" may be very short, depending on your code. Keep this in mind when designing this.

Basically, you're hooking up the Arduino and the RPi together, with a voltage divider or a level shifter between the two.

Voltage divider:

Sparkfun

That is a voltage regulator (drawn four different ways; it's the same circuit). I calculated the values you will need: 1700 ohm for R1, 3300 ohm for R2.

Of course, serial (with USB of the Arduino) communication would be a lot easier...


How do I use 2 ultrasonic sensors to control a 5v motor?

This is very simple using the map() instruction. Here's the code you would use (feel free to modify values:

int speed = 112 + map(distance, 0, 20, 0, 112) - map(distance2, 0, 20, 0, 112);

So if both sensors gave equal values, they would offset each other. To make it still work if an object is removed, you could just use the last distance/distance_2 value and update the other.

One issue with this approach is, if the line of transformation of the object is not perpendicular to the line of the pings, the value will go:

  10 → 11 → 12 → 13 → 14 → 15 → 16 → 17 → 18 → 19 → 20 → [Out of range]

I've added some pretty animations to show you what I mean:

Perpendicular:

Collinear:

As I understand, this is what you want:

int motorPin = 9;
int trigPin = 13;
int echoPin = 12;
int trigPin2 = 5;
int echoPin2 = 4;
int postdist = 112;
int postdist2 = 112;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(motorPin, OUTPUT);
}

void loop() {
  //First Read
  int duration, distance;
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (1000);
  digitalWrite (trigPin, LOW);
  duration = pulseIn (echoPin, HIGH);
  distance = (duration/2) / 29.1;
  int ltol = postdist - 5;
  int htol = postdist + 5;
  if (distance > 20 || !(distance > ltol && distance < htol)) {  // Distance from sensor
    Serial.println("Out of range");
    distance = postdist;
  }
  //Second Read
  int duration2, distance2;
  digitalWrite (trigPin2, HIGH);
  delayMicroseconds (1000);
  digitalWrite (trigPin2, LOW);
  duration2 = pulseIn (echoPin2, HIGH);
  distance2 = (duration2/2) / 29.1;
  int ltol2 = postdist2 - 5;
  int htol2 = postdist2 + 5;
  if (distance2 > 20 || !(distance2 > ltol2 && distance2 < htol2)) {  // Distance from sensor
    Serial.println("Out of range");
    distance2 = postdist2;
  }
  //Math:
  Serial.print("Distances-1: ");
  Serial.print(distance);
  Serial.print(" cm 2: ");
  Serial.print("Distances-1: ");
  Serial.print(distance2);
  Serial.println(" cm");
  postdist = distance;
  postdist2 = distance2;
  int speed = 112 + map(distance, 0, 20, 0, 112) - map(distance2, 0, 20, 0, 112);
  if(speed < 60) {speed = 60;} //Modify 60 to meet your needs for minimum threshold
  analogWrite (motorPin, speed);
  Serial.print("Motor Speed: ");
  Serial.println(speed);
  delay(500);
}

Changelog: forgot to edit postdist/postdist2 at end of cycle, added minimum threshold, prevent very small changes in voltage to keep voltage stable and prevent noise.


Why would uninitialized SD-card module without card disable CAN-Bus shield?

Without seeing schematics this is purely supposition:

My guess is that the SD shield contains bi-directional level shifting. The MISO pin, which connects the DO pin of the SD card to the MCU, will have a 3.3V -> 5V level translator on it.  This, with no SD card inserted, will be floating (flapping around in the breeze) causing the output of the level translator to randomly produce digital signals on the MISO pin. These signals interfere with the MISO signals from your CAN shield.

How best to cure the problem very much depends on what level shifting is in the circuit and how it is controlled and wired. For that we will need to see schematics of both the CAN and SD card shields.


Disabling i2c internal pull up resistors

From the datasheet:

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

To disable the internal pull-ups:

digitalWrite(A4, LOW);
digitalWrite(A5, LOW);

or

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


Problem with arduino starter kit project 7

I see the problem. The connections to the first 2 buttons are correct. You're missing a yellow wire linking the output of the bottom 2 buttons to AO however, so the 3rd and 4th buttons are not connected to your A0 pin at all. Add a yellow wire between row 24 and row 20 on your breadboard.
EDIT:
I see now that there is a green wire connecting rows 24 and 20 together. However, that is the likely place where things go wrong. I would suggest taking a couple of jumpers and connecting them to a multimeter set to continuity mode. Put one in row 28, and then test continuity to row 24, row 20, and row 16.
One of your wires may not be seated into the breadboard properly, or you may even have a bad row on your breadboard. I've seen that before.
EDIT #2:
A multimeter is your friend. If you don't have one, you should get one, and learn how to use it. It's invaluable for troubleshooting circuits. (Get one that has a continuity mode that beeps when it detects continuity, and that has auto-ranging voltage and resistance measurements.)


I have a sketch that programs bootloaders. A side-effect of that sketch is it fixes up the "divide clock by 8" fuse.

It looks like the wiring will be the same, but cross-check on that page (scroll down to the part about programming the Mega2560).

Once a bootloader is installed you could use it, if you get an FTDI cable, or simply go back to using the ArduinoISP now that the fuse is fixed.


There are a couple more places you can sample the 5V signal, see the photo here:

On the right, on the ICSP header, the pin marked VCC is also connected to the 5V signal. Try testing that.

(The other one is pin 2 of the ICSP interface for the USB chip, but the one on the right should be adequate for testing).

I don't know why you are mucking around with LEDs and resistors, just put your meter between Gnd and 5V.

I find sometimes that the hookup cable has failed, try testing that (or try with a different cable).


If you change your sketch to this one, you'll see the issue:

const int W = 10;
bool wOn = false;

void setup() {
  Serial.begin(9600);
  pinMode(W, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(W) == LOW) {
    wOn = !wOn;
  }

  if (wOn) {
    //Serial.println("toggled on");
  }
  Serial.println(wOn);
}

The button's contacts "bounce" (Google "contact bounce"), sending multiple low to high signals. There are several software solutions that will eliminate this issue. Have a look at: arduino.cc/en/Tutorial/Debounce. There are a couple of libraries that simplify de-bouncing buttons: playground.arduino.cc/Code/Debounce and playground.arduino.cc/Code/Bounce


Are DAC pins useful for anything besides working with audio?

They are incredibly useful.  They are essentially how you deal with the analog world.

For example, I'm using two of them in a project here that uses a frequency generator and a couple of op-amps to create a VSWR bridge, allowing me to figure out the resonant frequencies of an antenna...  The parts with the arduino cost less than $20... Buying something that does the same thing is about $300!

So, yes, they are very useful. :)


Stable temperature sensor under voltage fluctuations

The DS18B20 is a temperature sensor with a digital interface (1-Wire). It works at 3.3 to 5V and the cable length can be a number of meters. It is accurate to 0.5°C.

The DS18B20 is probably the most used temperature sensor for Arduino projects. Its price starts at less than a dollar/euro. You only need the DS18B20, a pullup resistor of 10k and a digital pin.

In the Arduino IDE, go to the Library Manager and search for 'onewire'. Install the "OneWire by Jim Studt, Tom Pollard, ... Paul Stoffregen, ...".
Then search for 'dallas' and install "DallasTemperature by Miles Burton, ...".
The OneWire library on its own can read the temperature of the DS18B20, but the DallasTemperature makes it easier to use.
Look for the examples of the DallasTemperature in the Arduino IDE to start with the DS18B20.

The 1-Wire is a bus, you can add more DS18B20 sensors to the same wire. The DallasTemperature library has two options. Select either a sensor by index, or by its ID. Every DS18B20 has a unique ID inside the sensor.

Sometimes an analog temperature sensor has specific advantages, for example a ntc temperature sensor or a thermocouple sensor. For normal indoor or outdoor usage, the digital temperature sensors are far more easier to use.

Why measure only the temperature ? If you want the baromic pressure and humidity as well, the BME280 has it all. Its temperature accuracy is not very accurate, it is only ±1°C.


Subtraction with doubles returning zero erroneously

You are not providing the input values in the correct type:

calcPID(0.00, 250, 0.0);

will return 0, while

calcPID(0.00, 250.0, 0.0);

will return 250

UPDATE

Here you can get a working test case: it's running on a different processor, so don't expect to behave exactly as the 8bit MCU at Arduino's core.


Timer STM32 #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting

The Roger Clark's STM32 core  you're using is not currently supported. I don't know in the future if I can add that core into the supported list.
You have to use this Arduino_Core_STM32.
Convert to new core by following the intructions in Getting Started


could not convert 'digitalWrite(8u, 1u)' from 'void' to 'bool'

This line of code is the source of your problem.

void loop() {

  if (digitalWrite(8, HIGH));

If expressions expect a boolean (true/false), but if you check the documentation for digitalWrite(), you’ll see it returns “Nothing” (i.e. void).

You need to use digitalRead() to check the current state of the pin.


Do all the processing on the Arduino, and supply the results to Matlab over serial.

I'm not 100% sure about your particular encoder, but generally encoders talk in "Grey Code".  This is a series of bits which allow you to know the direction the encoder has turned.

There are a number of libraries and tutorials for Arduino dealing with encoders.

http://playground.arduino.cc/Main/RotaryEncoders
http://www.hobbytronics.co.uk/arduino-tutorial6-rotary-encoder

The one I use comes from here:

http://www.pjrc.com/teensy/td_libs_Encoder.html

It would be best to use a library with interrupt routines on pins 2 & 3 (these support external hardware interrupts), so whenever the pin gets a signal from the encoder, the Arduino can act on it immediately.  If you do not use these pins, and have time-consuming processing in the loop(), it's easy to miss 'ticks' from the encoder.

#include <Serial.h>

// Rotary Encoder (Interrupt Driven)
#define ENCODER_PIN_A       2 /* must be pin2 for interrupt */
#define ENCODER_PIN_B       3 /* must be pin3 for interrupt */
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
Encoder encoder(ENCODER_PIN_A,ENCODER_PIN_B);

void setup()
{
    Serial.begin(115200);
    // Gentlemen, start your encoders
    pinMode(ENCODER_PIN_A,INPUT_PULLUP);
    pinMode(ENCODER_PIN_B,INPUT_PULLUP);
}

void loop()
{
    unsigned long start_time = millis();
    Serial.println("Dear Matlab...");

    while (1)
    {
        unsigned long now = millis();
        unsigned int encoder_value = encoder.read();

        // Do whatever angular velocity processing is needed here
        unsigned long ticks_per_ms = encoder_value / (now - start_time);

        // Send the result back to Matlab
        Serial.println(ticks_per_ms,DEC);
    }
}

I think for your encoder the "A" and "B" outputs are where the grey code will be coming from.  These would be connected to Arduino pins 2 & 3.

Obviously the code above is not a complete solution, and needs to take care of edge-conditions like overflow of millis() after some time, etc. etc.


Sending data to serial port using Processing IDE (Debug works but run doesn't)

I'm confused.  What language is this?
Anyway my guess is that you aren't terminating what you send to the Arduino properly (would have helped to see the Arduino code).  The reason I think its this is you are sending a zero after you number.  How does the Arduino know that the zero is not part of the number, do you mean a null or new line?


Is there such a thing as an "Always" loop?

There's nothing officially called an "always" loops as such. However, you can make a loop which goes on forever like this:

while (true)
{
    // this bit repeats forever
}

A while loop checks the condition before every iteration of the main body. If it detects that the condition equals boolean false then it will stop the loop and move on to the next bit of code.

Normally, the condition would be some kind of expression, like (x < 10). However, in the example above, the condition is hard-coded as true, meaning it will never be false so it will never stop.


This code is used to upload temperature data on pin A0 to things speak
Create thingspeak account and create channel you get api key it seems that this code uses field1 to upload data upload this code to arduino the change ssid and password


Arduino ESP8266 module communicate through Arduino IDE terminal

While it sounds like you have a serial voltage problem, even with that fixed you still have a conceptual problem with the serial links.

On a traditional Arduino like an Uno, pins 0 and 1 (which are the only hardware UART on the version of the ATmega in use) are already used for communication to the PC and serial monitor.

Thus you cannot use these to talk to the ESP8266, unless you effectively remove either the ATmega or the computer from the situation.  Some people do pull the ATmega out of its socket, or hold it in reset and thus "borrow" the Arduino's USB serial solution to talk directly from a PC to an ESP8266.  And in other cases someone working on a more completed project will forgo the computer serial connection, and use the ATmega's hardware UART to talk to the ESP8266.

But what you are trying to do, in talking to the ESP8266 through the ATmega, is not going to work when both conversations are trying to happen on the same pins.  Your code tries to use a software UART to talk to the ESP8266, which is potentially workable - but it will not accomplish your goal until you move the ESP8266 to different Arduino pins, in both the wiring and the sketch, in order to remove the present conflict over pins 0 and 1.


How can I connect an OLED display to arduino

Yes, you can. If you have the adaptor board for it as shown in the video.

The key item from the description to note is the driver chip: SSD1309

That is what you need to know to find a library and connection schema.


What are the parameters of the browseUrl() callback in the Ethercard library?

Apparently, the callback is executed on every packet which arrives by the browseUrl call.

"off" and "len" are pointers to the Ethernet buffer holding the data. "Off" are the initial value (offset) and "len" (length) is the amount of data received.

"byte status", I am not sure what it means, but it's very likely will be some kind of error code. It's not being used in any sample I am seeing, so I am really wondering what it means...

Check this link for a fully working sample

Callback here are called browseUrlCallback1 and browseUrlCallback2.

Can't figure out a link with the detailed documentation. If someone has it, please post it.


You don't. Instead you just remember what millis() was when you pressed your start button, then subtract that from whatever millis() is showing at any other point in the future.


Arduino Yun - not enough i2c & interrupt pins?

OR the interrupt lines together so that you only need 1 external interrupt. Then when an interrupt is triggered, poll the devices until you find the one that triggered the interrupt. If the interrupt outputs are open-drain then you can wired-OR them together, otherwise you will need something like the 74LVC32 to OR the push-pull outputs together.


Controlling 12v DC LED strips using Arduino UNO

It's not safe for the MCU without transistors or so.

You can use some kind of LED driver (for example TLC5940 with on chip PWM) or ULN2003 as 8 channel low side switch (instead of 8 transistors, PWM is possible if you do it programmatically) or many others.

With single transistor it looks like:

Where R_1 can be about 1K and transistor can be any NPN that could handle led current.


If you connect one of these and you can see it light up with your naked eye then it is not an IR LED, it's a visible-light LED. It's also not an IR sensor.

If you want to see IR, point a digital camera (like in your phone) at it and apply power. The sensors in digital cameras almost always detect some IR, so you can see a faint light on the screen. To test this, point your phone at a TV remote and press the button. If you see a flashing light in your phone's screen, you know it can "see" IR (Most digital cameras have an IR filter to get rid of most of the IR going into the camera, but they generally allow enough IR through that if you point them directly at an IR LED you can usually see it, at least faintly.)

Note that you should be able to use a visible light LED as a light source for an IR photoresistor/photodiode/phototransistor, since visible light LEDs will also give off some IR. However, an IR LED will put out a WHOLE LOT more IR than a visible light LED at of the same power.

The black one is probably an IR receiver. The color of the lens probably blocks visible light but not IR.

All the IR LEDs I've seen have looked clear, but I could not see any visible light when I powered them up.


Teensy4.1 with 2x 8MB PSRAM Chips: external_psram_size=0 but EXTMEM char[] works as expected?

I'm afraid your test program doesn't work as you intended. I tested it with a T4.1 without RAM soldered on and it gives the same result as in your question.

You didn't declare your array volatile. Thus, the compiler can (and probably will) simply optimize the reading back away.
Even if you declare the variable volatile the processor reads back the value from the cache line, i.e. you always get the correct value back, even without any external RAM.

Here a simple test program showing the effect. It always switches the LED on, even without external RAM soldered on the board.
EXTMEM volatile int test;

void setup()
{
    pinMode(13, OUTPUT);

    test = 42;
    if(test == 42)
    {
        digitalWriteFast(13, HIGH);
    }
}

void loop(){
}

Here the disassembly of the setup function. It clearly shows that the processor tries to store 42 in the (non existing) external RAM and reads it back from there. Obviously the read back value comes from the cache line.
(comments added by me)
void setup()
{
      7c:   push    {r3, lr}                         // pinMode code
    pinMode(13, OUTPUT);                             //
      7e:   movs    r1, #1                           //
      80:   movs    r0, #13                          //
      82:   bl  160c <pinMode>                       //-------------

    test = 42;
      86:   ldr r3, [pc, #20]   ; (9c <setup+0x20>)  // load r3 with address of 'test' (0x70000000, stored at 0x9C)
      88:   movs    r2, #42 ; 0x2a                   // load r2 with #42
      8a:   str r2, [r3, #0]                         // store content of r2 at address stored in r3. i.e., store #42 0x7000'0000 (EXTRAM)

    if(test == 42)
      8c:   ldr r3, [r3, #0]                         // volatile forces the compiler to read back 'test' (store it in r3)
      8e:   cmp r3, r2                               // check if equals r2 (contains #42)
      90:   bne.n   9a <setup+0x1e>                  // goto 0x9A if not equal

CORE_PIN13_PORTSET = CORE_PIN13_BITMASK;             // digitalwritefast code (next 3 lines)
      92:   ldr r3, [pc, #12]   ; (a0 <setup+0x24>)  // ...
      94:   movs    r2, #8                           // ...
      96:   str.w   r2, [r3, #132]  ; 0x84           // -------

      9a:   pop {r3, pc}                             // return from setup()

      9c:   .word   0x70000000                       // Address of 'test'; EXTRAM starts at 0x7000'000
      a0:   .word   0x42004000                       // Address of GPIO register for LED


Using Arduino Yún to send data through Ethernet

There are three bits of information you need to know:

The Ethernet port is connected to a tiny Linux computer
On Linux you can do HTTP POST and HTTP GET using a program called cURL
The AVR chip can tell the Linux computer what to do using the Process library.

Putting all those together: You need to use the Process library to tell Linux to run curl with the right parameters.

Just like the tutorials show you:

https://www.arduino.cc/en/Tutorial/Process


Writing to partially reserved registers of sensors

You always write a whole byte when you set the register. You only need to "mask out" those bits if there's a danger that you may inadvertently set them to 1, for instance through some value over flow from other bits when combining values together to form that byte.
If you're not doing that then there's nothing to mask out.  For instance if you just want to set a specific set of bits then just set that value - 0b00101001 is going to be 0b00101001 whether you mask it or not.
If you decide you really want to mask a value, for instance if you are writing a library and you have no control over what an end user may decide to pass to a function, then & (or &=) is your friend:
uint8_t val = 0x55; // 0b01010101 in binary
val &= 0b00111111; // or 0x3F if you want to use HEX
// val is now 0x15 since bit 6 has been "masked" to 0.


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


According to the Arduino Software Release Notes, support for the Arduino Micro was added in 1.0.2.


Advanced ADC setup on Due (SAM3X8E) to increase precision

Generally speaking the input BandWidth of the analog signal is a major cause of noise in a ADC circuit as well as improper ground and reference generation and layout techniques.  Be very careful that ALL of the analog paths do not have any digital current return paths. Remember that at 12 bit for a 1.25V reference an LSB is ~300uV. I have not ever measured the SNR of the SAM ADC but I doubt that it is the specified ~60db (i.e. 10bit) unless absolute care is taken during the layout/routing.
Recommend:
1) Limit input BW to the correct channel ground. (well below Nyquist BW if possible to avoid alliasing)
2) Oversample if possible.
3) Insure low digital I/O of peripherals during sample period.


Why not use the barrel input connector and input 12VDC there, the filtering etc on the board will help. Also as dandavis stated you need a bigger power supply or remove about 1/2 of your LEDs.


How to store a string in an object and retrieve it safely later?

void Bank::addPreset(const char* presetName, String presetData, char presetLocaton)
{
  Preset preset(presetName, presetData);

  switch (presetLocaton)
  {
    case PRESET_LOCATION_1:
      _A = &preset; break;
    case PRESET_LOCATION_2:
      _B = &preset; break;
    case PRESET_LOCATION_3:
      _C = &preset; break;
    case PRESET_LOCATION_4:
      _D = &preset; break;
  }
}

I can't see how this is going to work because you are storing somewhere outside a function a pointer to a local variable inside the function. As soon as addPreset exits the variable preset will go out of scope, and a pointer to it will be undefined.

You should probably do a new to make a new instance of Preset which it is then valid to store outside the scope of the function.


setting output analog/digital pin to ground

Yes, setting a pin to OUTPUT and setting it LOW effectively connects the pin to ground (via a few ohms of resistance).

There's a couple of things wrong with your code, though, which you should address:

Use digitalWrite() not analogWrite().

analogWrite(pin, 0) is effectively the same as digitalWrite(pin, 0), but it's ambiguous to someone reading your code.

You never "release" the pin, so once it goes LOW it stays LOW.  You should emulate open drain by setting it to INPUT when not using it.
You should get into the habit of putting repeated code into functions to make it more understandable what's going on.

For example:

void setup() {
  Serial.begin(9600);
  pinMode(ds1, INPUT);
  pinMode(d1, INPUT);
  waitForCD();
}

void loop() {
  triggerEject();
  waitForCD();
  delay(1000);
}

void triggerEject() {
  pinMode(d1, OUTPUT);
  digitalWrite(d1, LOW); // Press the button
  delay(100); // This is how long the button is pressed for
  pinMode(d1, INPUT); // Release the button
}

void waitForCD() {
  while(!analogRead(ds1)) //if the CD isn't inside the drive wait
  {}
}

!analogRead(ds1) will only ever be true if the voltage at pin A2 is exactly zero volts. If you really want to read an analog voltage here you should find a threshold value that the value is compared to:

while (analogRead(ds1) < 100)) {}

Or it may be that you actually want to use digitalRead()...


You'll likely do less damage de-soldering it than trying to snip it off. Use a de-soldering pump to remove as much molten solder as you can, then heat again with de-soldering braid to wick up the remainder. If the jack's solder terminals were bent over (to stabilize the part before it was soldered) you may need to straighten them with a tweezer-nosed plier. Then you should be able to lift the part off the board. Don't overheat the board or heat any other parts or solder joints than those you intend to remove.


At times like this it is useful to refer to the datasheet.  You can, in that document, find this paragraph:

  4. Power and Pin

  DHT11’s power supply is 3-5.5V DC. When power is supplied to the sensor, do not send any instruction to the sensor in within one second in order to pass the unstable status. One capacitor valued 100nF can be added between VDD and GND for power filtering.

So you can see that if you power down the sensor completely you have to wait at least 1 second before you can do anything with it.

With it just in the low power mode it defaults to between readings you can immediately start reading as soon as your ATMega wakes up.

So you have to ask yourself: Does running the ATMega at full power for 1 second consume more or less power than running the DHT11 in low power mode for 8 seconds?

As a rough guestimate - if the ATMega is using 30mA (ballpark figure) for 1 second (that's 30mAs - milliamp-seconds), and the DHT11 uses 50uA for 8 seconds, then you have 0.05*8 = 0.4mAs.

That's 0.4mAs (sleeping) vs 30mAs (powered down). So I'd go for leaving it powered and avoid the one second delay at full power.

Another option that may save more power would be to:

Power off the DHT11
Sleep 8 seconds
Power on the DHT11
Sleep 1 second
Read DHT11
Go to 1

Of course, that means your loop then takes 9 seconds not 8. You could compensate by sleeping for multiple amounts to make 7 seconds:

Sleep 4 seconds
Sleep 2 seconds
Sleep 1 second
Power on the DHT11
Sleep 1 second
Read DHT11
Power off the DHT11
Go to 1

But of course that then makes your sleeping less efficient - so is it really worth it?


It is possible to revive my Arduino Leonardo (mini beetle) board?

Probably you have overwritten your Bootloader.
Connect MOSI, MISO, SCK and RESET to an ISP-Programmer and flash the file
Caterina-LilyPadUSB.hex
to it.
There are lots of tutorials on the net how to use a spare arduino as an ISP-Programmer.


"char inChar = (char)Serial.read();" why is the "char" in brackets? and what is it called

It is called type casting and will convert one type to another. The return type of Serial.read() is int, because it will return -1, when you try to read without any bytes being available. The casting with (char) will drop the high byte of the (2-byte long) integer, leaving only the lower byte. This byte will contain the actual read data, in which you are interested here.

Casting is a complex thing, because there can be different ways to convert different types (for example maintaining the bit-content vs. maintaining the decimal value). The casting, that you are seeing here, should only be done, if you really know, what you are doing. The bits will not be changed to maintain the correct value, but the bit-content will be preserved, unless the new type is smaller than the former. In this case the rest is lost. Also, if you try to cast a float value to an int value with this, you will get a totally different decimal value out of it, because the numbers are encoded in the bits in a totally different way. Here it is known to be OK, especially, if you are checking for available bytes before reading with Serial.available(), because the library puts the ASCII data in the lower byte.

For further explanations you should consult C/C++ guides.


CIPSEND to ESP8266 returning bytes but no content

In my experience, the "busy" message appears when you try to start a new AT command or to send data before the ESP8266 is ready. You say that you are running this test with the commands in "a script" which suggests to me that there is no significant delay between lines.

You should either wait between commands until the EXP8266 responds (usually with "OK" or ">") or add a delay of a few seconds between commands.


Get the uploaded code from arduino by using arduino IDE 1.0.6


Sending a character 'A' through blinking led

Instead of printing '0' or '1' set the LED pin off or on, like this:

const int LEDTrans = 13;
const int timeWaitOn = 1000;  // millisec (1 sec)
const int timeWaitOff = 1000; // millisec (1 sec)

void setup() {
  // Turn the Serial Protocol ON
  Serial.begin(115200);
  Serial.println("Send letter:");
  pinMode (LEDTrans, OUTPUT);
}

void loop() {
  /*  check if data has been sent from the computer: */
  if (Serial.available()) {
    byte byteRead = Serial.read();
    // will print the binary representation of 'byteRead' as 8 characters of '1's and '0's, MSB first.
    for ( uint8_t bitMask = 128; bitMask != 0; bitMask >>= 1 ) {
      if ( byteRead & bitMask ) {
        digitalWrite(LEDTrans, HIGH); //turn the led on
        delay(timeWaitOn); //delay in millisec (1 sec)
        digitalWrite(LEDTrans, LOW); //turn the led off
      } else {
        delay(timeWaitOff); //wait a sec
      } // end of if
    } // end of for loop
  } // end of if something available
} // end of loop

  how do i count the flashes? is it based on the binary 01000001?

Here's the problem ... according to what your question seems to ask for, you are wanting an LED to flash for a 1 and be off for a zero. So the results (which my code provides) would look like this:

So, you get two flashes, the first one second after it starts, then there is a gap of 5 seconds, and then another flash. That would be 01000001.

However, how do you know when to start counting flashes? It might be:

That would be 00000001.

Or even:

That would be 10000010.

You can see, can't you, that you can't make any meaningful deduction at the receiving end about what the character is?

So what asynchronous serial (normal serial on an Arduino) does is have a Start Bit which signals when to start counting, like this:

Normally the serial port is high (continuous 1s) and then when a 0 arrives that means "start counting". So, you wait 1½ bits of time and then sample at the known baud rate. In your example, where you want 1 second per bit, the baud rate would be 1 (one bit per second). Thus, you sample every one second. Normally baud rates are somewhat faster than that, like 9600 or 115200 samples per second.

Also there is a Stop Bit which is always a 1. This guarantees that there will be at least a single 1 at the end of each byte, so that we can tell when the next start bit arrives.

There are other ways of doing this, for example a short pulse might represent a zero, and a longer pulse represent a one. In that case, any pulse at all could represent the start of a byte, and then you just measure how many short pulses, and how many long pulses, you get (for some definition of "short" and "long").


How to change Windows 10 Device Manager so Arduino NANO COM3 can operate on COM4

In device manager, right click on the device and select "Properties". Then go to the tab "Connection properties" and click on "Advanced". There you can change the COM port number assignment for a particular device.


Phasing a Stepper Motor Control Project Problem

I might suggest looking at 3D printing firmware such as Repetier and Marlin, and the Arduino Playground for smaller projects such as simple stepper control, reading and debouncing switches, and digital rotary and Analog pots. I bought a cheap (wired USB) PS3 controller to get some ideas. It has a wide variety of input options. And the local hardware store comes in handy along the way.

I'd also recommend moving up from the Arduino native IDE to something like the free version of Microsoft Visual Studio with the Visual Micro add-in for Arduino. This will give you breakpoints, variable access, and handy formatting enhancements.

Getting to where you want will take a while, but the end result will be lots of learning, and an end project that does exactly what you want, which no one else sells or even has.


Is there a way to combine a 3-axis accelerometer/gyroscope into one value?

The answer is: technically, yes, it is possible. The combined result is called Quaternion. This is what is typically used in 3D programs.

But most likely that is not what you had in mind.

Usually one can do a simplification and reduction of dimensions when in presence of some constraint.

Imagine that your moving object is bound to a planar surface: no matter how you tilt and rotate and pan it, it is still a 2D surface, plus a quaternion indicating the rototranslation.

But, once you have established the coefficients applied to the rototranslation, it is 2D.

Similar 1D case: imagine that your moving object is bound to some well-known geometrical shape, say a circumference. Once you have established how the circumference is oriented in the 3D space and its radius, you can express the position of your device by indicating either the angle or the distance from a reference point on the circumference.

In both cases you can simplify the representation because of constraints that do not allow for real 3d movement.

But if your device is a flying drone that can rototranslate freely within certain boundaries (max horizontal range, min/max altitude), there is no way that you can simplify the 3d coordinates.

If, instead, your question was related to the protocol used to read info from the accelerometer, you are bound to the protocol defined in the datasheet, by the manufacturer.


One omission from your code which might be causing the problems is the fact that you haven't set the pinMode. You need to set the pins as OUTPUT in setup()

#efine FAN1 3
#define FAN2 5

void setup() {
    pinMode(FAN1, OUTPUT);
    pinMode(FAN2, OUTPUT);
}

void loop() {
  int speed1 = 127;
  int speed2 = 25;
  analogWrite(FAN1, speed1);
  analogWrite(FAN2, speed2);
  delay(10000);
}

I am curious to know why you declared FAN1 and FAN2, but didn't use them - I'd recommend changing the analogWrite statements to use them instead of referring to the pin numbers directly.

Also, the way you're using the pin and speed means that you're using speed2 for FAN1 and vice versa, I've switched these in my example so FAN1 and speed1 go together.


Based on the image .. i see that the programmer pins at the back of the shield and the arduino aren't connected properly.. That might be the error or at least happened with me.
Apart from that, certain network need to identify the mac address from a look up table and if the shield mac address matches, then only network transactions are allowed.
Also i suggest you to drop the virtual machine mac address and networking protocols and try upon the base OS which you have on your computer.


SIM900A showing Starting modem test...ERROR, no modem answer. Checking IMEI...Modem's IMEI: 0

Note:

Detailed Solution can be found Here

Excerpt:

My Pins connections were wrong, it should not be: 0 and 1 it should be 2 & 3

Also SoftwareSerial.h is not working with SIM900A

Pins:

All connections should be like this:

SIM900A - Arduino
=================
VCC     - VDC (+5V)
GND     - GND
5VR     - Connect to Arduino TX (Pin 3)
5VT     - Connect to Arduino RX (Pin 2)

Details Here


Change RF Receiver Frequency by Antenna Length

No, changing the antenna length will only change the resonant frequency of the antenna circuit. That is, it will affect the sensitivity of the receiver, but won't actually change the frequency that the receiver "listens" to.


Use the Time library a.k.a. TimeLib.h. It will keep time between calls to your source of time, if it is your MQTT call or NTP server.

In your code you will use the Time library to get time and the source of the current time is independent from the rest of the code.

The TimeLib has a function setTime to set the current time and then it keeps the time using millis(). You can update the time by calling setTime again. The timestamp value for setTime is 'Unix Epoch' - number of seconds from "1970-01-01 00:00:00".

If you decide to add NTP to your project, you can use NtpClientLib. It sets the time to TimeLib with one simple line of code in setup(). Example NTP.begin("pool.ntp.org", 1, false);.


ESP8266 on WiFi without password, possible?

Yes it works! You can use:

WiFi.begin(ssid, NULL)

or even leave the passphrase empty, because it's optional:

Wifi.begin(ssid)

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


error: 'CLASS' does not name a type only when creating object inside another object

I think these lines still need to be in your main sketch file (in addition to being in your custom class file):

#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>

If I remember the Arduino IDE quirks correctly, it uses the #include directives in the main sketch file to determine which libraries to actually link. It's one of those annoying features that was intended to be beginner-friendly but sometimes just makes things more confusing.


How can I find and specify the address of my adafruit MMA8451 accelerometer in arduino code?

You can't have 4 of those on one bus. The maximum is 2.

The pin SA0 defines the least significant bit of the I2C address. From the datasheet:

  7 | SA0 | I2C least significant bit of the device I2C address, I2C 7-bit address = 0x1C (SA0 = 0), 0x1D (SA0 = 1).

In fact, as it states on the Adafruit website (if you'd care to read it sometime):

  A is the I2C Address select pin. By default this is pulled down to ground with a 10K resistor, for an I2C address of 0x1C. You can also connect it to the 3Vo pin for an address of 0x1D

If you want more than 2 you will either have to have multiple I2C busses or use an I2C multiplexer (such as this one) to select different branches on the same bus.


Decide on baud rate for a project using Arduino Uno R3

I most cases it doesn't matter!

In some cases the highest possible is preferred, as it prevents delays. That is when the buffer is full (when sending large amounts of data through the serial connection). As Serial.write will block until there is room in the buffer. In most cases this won't be an issue.

When running your arduino at slower speeds, you have to select a lower baudrate, or the micro-controller can't keep up.

When connection to other devices (e.g. GSM shield) using serial, that device may require a specific baudrate.


Ideally, you would use a proper recursive JSON parser, like the one
suggested in prakharsingh95's answer. However, if code speed and size
are critical considerations, and if the format of the response is
narrowly constrained, then you can build a fast special-purpose parser.

Here is a simple example. It assumes the response has been stored in the
response char array:

static const char key[] = "\"action_status\"";
const char *p, *q;
char action_status[16];

for (p = response; ; p = q) {
    p = strstr(p, key);    // find key
    if (!p) break;         // not found
    p = strchr(p, ':');    // find ':' between key and value
    p = strchr(p, '"');    // find opening quotes for the value
    q = strchr(p+1, '"');  // find closing quotes

    // Report finding.
    strncpy(action_status, p+1, q-p-1);
    action_status[q-p-1] = '\0';
    Serial.print("Found action status: ");
    Serial.println(action_status);
}

Of course, in production code you would check that every strchr call
returns a non-NULL pointer. And you would check that the status you
found fits in your buffer.

Edit about the pros and cons of this method:

Compared to a proper JSON parser, this approach will give you smaller
and faster code, the drawback is it being more fragile. For example,
this will not detect a corrupted JSON, and it will return garbage if the
action_status happens to be a number instead of a string, or is a
string with embedded double quotes, or if the string "action_status"
appears as a value of some other field... A full JSON parser should
correctly handle all these cases.

On a non-embedded computer, a proper JSON parser would probably be the
only appropriate answer. On a constrained microcontroller environment,
you sometimes have to make trade-offs. In this particular instance, the
“best” answer depends on how much you weight speed and size vs.
robustness against unexpected input.


Send AT commands to ESP8266 from Arduino Nano serial monitor

First problem is that io 0 of the esp8266 must be pulled HIGH for normal boot. With io 0 not HIGH, the esp8266 starts in flashing mode.

Your other problem is the reset pin connection. It must be connected with pull-up resistor or not connected.

See ESP8266 Hardware Design Guidelines

  Pin32 serves as an RST pin which can be left floating when it is not
  used. The reset pin is held low when the chip is enabled. In order to
  avoid resets caused by external interference, the lead is generally
  required to be short, and no external pull-up resistor is necessary

I suspect that "The reset pin is held low when the chip is enabled." is a bad translation. They say in pin description "32 EXT_RSTB I External reset signal (Low voltage level: Active)". What they mean is that the chip resets when reset pin is set LOW.


How to read/write variables persistenly on Arduino Due (no EEPROM/shield)?

I really hope that somebody knows differently, but I'm fairly sure that the answer is that you can't directly save runtime data back to the Arduino Due board.  I've looked into this myself and have only found answers saying "wire up an external EEPROM" or similar.  Whilst it seems that it should be technically possible to write into unused (or pre-reserved) areas of the program memory, I suspect that the CPU has to be put into a special mode to do this, which is very probably only possible from the bootloader when flashing a new program to it.

I've chosen to go with FRAM chips for data storage. Link to mine.  They are difficult to wire up - the only ones I found were in surface mount packages (although some hobby retailers sell them mounted to little boards with header pins), but they are very cheap, very durable (you can write to them a great number of times before they wear out), operate at high speeds and you can read/write single bytes from/to them.  Other storage chips often require you to write whole "pages" of data at a time which can mean reading in the existing data, modifying it, then writing it back.

Additional comments:
In your original question, you state that the contents of your PROGMEM located array must be restored on restarts.  I don't think this is the case.  That would suggest that the contents are stored elsewhere and code is in place to overwrite them, however it could be the case that they are copied into working RAM, which would mean that the PROGMEM macro is not actually doing anything on the Due - which may well be the case.

Modify your code to change one of the values of the array (within the bounds of the array!) and then print its value out again after changing it.  If the value printed has changed then this means that PROGMEM is not actually doing what it is supposed to do on the Due, which would be a real shame.


Switch Control Between Two Different Techniques

the PID is looking at the RPMs and giving an output but that output is
  being ignored because another operation has servo control.

PID is not something, that happens somewhere in the background without you having any control. On the Arduino it is done in software, so you can totally control it. Why should you run a PID calculation, if you don't use the value? The solution is to simply only do the appropriate calculation depending on the RPM at any given time. No need to do 2 calculations at the same time. I will form that into a code with explanations:

You have 2 ways of calculating the needed servo values:

Your "getting close" method
The PID method

To switch between those methods you need to make a decision based on the RPM. If the RPM is outside of your interval, the first method is used. If it is inside, the second will be used. Decision/conditionals are often wrote with an if else statement. Look at this (not tested) code snippet:

int target_rpm = 700;
int half_interval = 20;
int current_servo_pos = 0;

void loop(){
    current_rpm = analogRead(AMPS);

    if(current_rpm > target_rpm - half_interval && current_rpm < target_rpm + half_interval){
        // Do the PID calculation here and save the result in current_servo_pos
    } else {
        // Do the "getting close" calculation here and save the result in current_servo_pos
    }

    myservo.write(current_servo_pos);
}

I didn't go into detail about the actual calculation, since that is not important here. You may use any calculation, that you like there. For PID you can find libraries, that do the calculation for you, for example here at github.

The code will simply decide based on the RPM, what calculation should be used. If the RPM goes out of the interval for some reason (maybe is was disturbed and lost some speed), it will automatically use the "getting close" method until it is again inside of the interval.

Note: The numbers, that I used here, are arbitrary. You should change them to what ever you need.


The WS2812B chips are highly timing-dependent. You have to clock out bits within a range of ±150 ns. This isn't likely to work well with clocking in bits from an IR remote. You are finding errors on the IR codes - that doesn't surprise me.

I suggest you use your idea of two Nanos. One can be reading IR codes. The other can display a stream of pixels and then "ask" the other one (eg. via serial or I2C) if a different command has arrived. That way the timing can be shifted in such a way that both processors are not interrupted when they are busy.


That's actually quite an involved question to answer. The short answer is "Yes, you can do without the regulator as long as you get the voltage right".

And that is where it gets tricky.

The datasheet states:

  Operating Voltage:

  1.8 - 5.5V

So you can power it from two or three AA batteries, for instance (3V - 4.5V). However, that is not the whole story.

The voltage you provide it with dictates what frequency the chip can reliably run at. Later in the datasheet is this nice little graph:

Since the normal Uno-like arrangement runs at 16MHz you're looking at a minimum voltage of around 3.8V - 4V (it's actually quite hard to work out from that graph).

But if you are willing to reduce your clock speed to 8MHz (which is what the 3.3V Arduino "Pro" boards run at) then you can drop right down to about 2.5V.

At a 2.5V lower limit with 3 AA batteries it would equate to a minimum voltage of 0.83V per cell, which is below the normal minimum accepted "flat" voltage of 0.9V per cell.

So powering from 3 AA batteries with a clock speed of no more than 8MHz would give you probably the best run-time.  Note, also, that a decrease in clock frequency decreases the current consumption as well - the slower you run the chip the less current it needs. You can see that in this graph in the datasheet:

And yes, as you can see, the lower the supply voltage the lower the current as well. So as the batteries run down and the voltage drops so does the current, reducing the speed at which the batteries will run down.

As you can see, if you don't mind the supply voltage changing (which of course will affect everything else in the circuit, so you need to check those out first), running directly from batteries without a regulator can actually have advantages. But as I say, you need to check what else you are running in the circuit to make sure it doesn't mind if the power supply voltage drifts.

And don't forget, also, that the supply voltage affects the ADC readings, since they are referenced to that voltage as well.


It becomes lots easier if you see the yun as a linux computer with a arduino connected over serial.
Then the question becomes: what is the best way to send commands over the internet to a (linux) computer.
Answer: there are so many ways because there is no best way.
What are the main key drivers:
Your linux computer needs to be reachable from the internet. That means opening your local network(firewall). The firewall is there for a reason. Do you have the skills to open your firewall and still be safe? If so you can run a service (lots of options) and reach your yun from anywhere on the internet. Just as you do locally.

If not you will need to go to a polling system. You use a server which is on the internet and send you request to that server. Your yun polls that server to get the messages you send.

There is a third option: If you can open your firewall from the internet, and you are the only user of the service and you very rarely need the service you can temporarily open the firewall when you need it
.


This will work fine. The easiest way to do this is using IR Sensor Module.

This will give you a digital output of whether there is someone in front of sensor or not. Use can use it as an Edge Trigger to detect Humans passing by.

You can buy one. They are both cheap and easily available.

Or you can create your own.


How to make PCA9685 work with Arduino Due?

I made it working by this way: despite PCA9685 datasheet recommendations, we do not need to connect OE pin to VCC. Also we do not need to connect OE to ground as it recommended in some instructions related to other Arduinos.

So we should leave OE pin unconnected.
Also we should use 4,7K pull-up resistors to connect SDA and SCL to VCC.

The board can be used without level converters.

No special program/libraries changes needed. So it was a hardware problem.


w5100 and nrf24l01 - SoftSPI - Radio not starting

Issue one:  .printDetails(); uses printh.  If you don't have that included you won't get the information.

Issue two:  The ide gets confused when you have two libraries with the same file.  I compiled my receiver with the softspi file. Once I put the right library in it works.


Arduino Mega Clone CH340G Capacitor Values

The values can be easy found for generic CH340g and ATmega2560 implementations:
C1,C2 = 100nF, C3,C4 = 22pf but depends on the crystal you use, all others excepting C12 are decoupling capacitors.
C12 has no sense where it's placed, it seems that the schematic is a bad combination of schematics, this capacitor should reset the board at power on but it breaks the reset pulse from CH340g so you cannot program the board without pressing manually the reset pushbutton. Don't place C12 at all.
Also place a short instead of R5 and R6 that are not in the CH340g manual (there is a special mention to connect the pins straight to USB bus), remove R8, is not needed for the same reason, R3 makes no sense, don't place-it.
R2,R4 = 1K, R7,R9 = 10K, R10,R11,R12,R13 = 1K, R14 = 10K , R15 = 1M.
Y1 = 12Mhz, Y2 = 16Mhz
A 22 ohm resistor is missing in your schematic between Y2 XTAL1 and ATMEGA XTAL2 but I don't think it's important.
I hope I didn't missed something
The bare minimum is to remove c12 and maybe R3 and check the values you used for R2, R4 against the above values.
If something would be wrong with CH340g the USB connection would fail but I see no mention about that in your post.


You may want to use a boost converter which is a device that can step up voltage.

You can get them from eBay for around $US 2.

As Chris Stratton pointed out in a comment, the boost converter may run your batteries down quite quickly. Let's say you need 200 mA for your Uno, sensor and LEDs. At 5V power that is 1W of power (0.200 * 5).

However to get 1W from 3V you would consume 333 mA (0.333 * 3). Then take into account that the converters are not completely efficient. Let's say the converter has 90% efficiency. Then you need to multiply the current by the inverse of the efficiency, that is: 0.333 mA / 0.9 = 0.37 mA.

Another factor is the battery type. If you use NiCad batteries their nominal voltage is closer to 1.2V than 1.5V, especially after you have been using them for a bit. Ditto for NiMh batteries.

Reworking the above for 2 * 1.2V (2.4V) we see that the current will be:

1W / 2.4V = 0.4167A
0.4167A / 0.9 = 0.463A (allowing for 90% efficiency)

Now it potentially draws close to half an amp when active. Your batteries might not be able to handle that for long.


How to do I2C on Arduino with SDA and SCL pin already used

No, you can't just use it. While I2C itself may work, the screen will keep resetting itself all the time and will be useless.

You may be able to get some luck with a software bit-banged I2C  on other pins. However I would personally choose to modify the TFT screen's PCB and cut the LCD_RST signal from the A4 pin and connect a 10kΩ resistor to +5V, or re-route it to another pin. That way you can then use I2C.


See my answer How the IDE organizes things. There is no easy way to avoid having to put an include in the main .ino file, unless you write your own build process (or perhaps use another toolchain).

I think you could put SPI.h (and other things, like Wire.h) in the main .ino file, even if they aren't used due to your configuration parameters. The linker would strip them out because the modules were not referenced.


Attiny85 not able to understand data from 433Mhz using VirtualWire.h

Have you tried using the Radiohead  library? I know you said you tried different versions of Virtual Wire. The RH_ASK class works on a 328p and a nano for sure and they claim a simple Rx program can run on a ATTiny85. They have documentation under RH_ASK regarding the changes you need make to the library.
Another possible fix is to edit the Virtual Wire library files, they might have variables like "Max_payload" (Radiohead does) whose size can be decreased.
I haven't actually read the Virtual wire library, but I am sure Radiohead should fix your problems.

If this doesn't work, do you have an oscilloscope? Maybe we can try debugging it like that.

Edit: Maybe try commenting out the vw_set_ptt_inverted line first. I don't think you are using the DR3100. Might not make a difference because you haven't actually set a pin for ptt.
Next thing you can try is just connecting the data pin of the Tx to the Rx. You should be able to check if the module is actually connected to the ATTiny with this.


This specific code just refuses to compile?

As Majenko stated in the comments, your use of the println function is not valid as there exists no overload that takes char*, int, int as parameters.

You could get your program to work by replacing your println as following:

for(int i = 0; i < 51; i++){
    Serial.print(notes[i]);
    Serial.print("'s sharp is ");
    Serial.println(notes[i]+(notes[i]*0.05937));
}


The maximum value you can pass to analogWrite() is 255. Anything higher than that will wrap around back to 0.

You should scale your value to fit into 0-255 instead of 0-1024.