Simple serial message not consistent (sometimes jumbled up)

My guess is that an interrupt is occurring during your reading or writing of the counter variables.
Since the variables are bigger than the native size of the registers in the CPU multiple instructions are required to work with them, and an interrupt can occur right in the middle of that work which changes the values it's working on. That can cause a mess (though I wouldn't expect it to make that kind of mess, TBH).
You should wrap all accesses to the counters that aren't in the interrupts inside a critical section. This is a segment of the code where interrupts are not allowed to happen. For obvious reasons you want to keep that code as short as possible.
Also in the code you have given there is no need for your buffers and sprintfs. You can just use multiple Serial.prints to achieve the same result with a much smaller code/memory footprint.
Here's an example:
void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;

    // Copy and reset the counter values in a critical section
    noInterrupts();
    int nowCounter1 = counter1;
    counter1 = 0;
    int nowCounter2 = counter2;
    counter2 = 0;
    interrupts();

    Serial.print("A");
    Serial.println(nowCounter1);
    Serial.print("D");
    Serial.println(nowCounter2);
  }
}

Also your counter variables should be volatile since they are accessed from both the interrupts and the main loop:
volatile int counter1 = 0;
volatile int counter2 = 0;


cast double to long leads to unexpected results

The problem is that float numbers are seldom an exact representation. So the float is stored as the closest number that is exactly representable as a float, namely
10446438 × 2−18 = 39.84999847412109375.

When you multiply this by 100, you get 16322559 × 2−12 = 3984.999755859375.

And than casting to an int or long results in 3984, not 3985.

so whenever you cast a value from a float or double to an int or long, you always should add 0.5 (so all values from [x - 0.5, x + 0.5) are rounded to x assuming x >= 0, thus:

val_long = int(a + 0.5);

Beware of negative values, see therefore https://www.cs.cmu.edu/~rbd/papers/cmj-float-to-int.html

Better is to use the round function, see comment of Edgar Bonet below.

UPDATE

See comment of Lightness Races with Monica

In case it's not wanted to round up, but you still want 39.84999847412109375 to be 39.85, than you have to add a value that has the value of the least significant bit (actually slightly less but that is impossible to define). In most cases, it's best to add half the significance you want. So if you need two decimal accuracy, add 0.005.


Motor isnt spinning when using L298N motor controller

You need two supply voltages for this board to work: motor supply, which goes directly to your motor (up to 35V for this L298N board, depends on what your motor needs), and logic supply of 5V, which powers the board's logic chips. If the motor supply voltage is between 7V and 12V, you can derive 5V logic supply from motor supply by enabling this board's built-in linear regulator.

The actual motor power supply should be connected to the VCC terminal of the L298N board you have in your picture. This is the leftmost terminal in the block of 3 in the picture (sometimes it is labeled +12V instead of VCC). In your case it is not connected to anything at all. This is already wrong.
It is not clear what the purpose of the red wire is in your picture.

In your comments you mention different voltages of motor power supply (6V in one place, 9V in another...). If you are feeding this board 9V through the red wire, you are doing it wrong. The rightmost terminal in the block of 3 is the 5V pin. Don't attempt to feed more than 5V to that pin.

If you'll be using the red wire to supply 5V logic power to the L298N board from an external source, then you need to disable this board's own linear regulator - remove the jumper that is shown above the 3-terminal block.

If you'll decide to use it to supply 5V logic power from the L298N board (e.g. to your Arduino), then you have to keep the jumper.

In any case, the leftmost terminal has to be connected to motor power supply.


I am not sure how you are sampling the frequency because you have not shown us your code.

At work we use a ATMega328P to sample frequency. This is done in 2 different ways:

We use the pin that counts (using an internal counter) every time it transitions (ie from low to high and from high to low). After 1 second that counter is read and then that counter is cleared. With the number read in, it is divided by 2 to get the frequency.
We use another pin that counts every time it transitions from low to high. From memory the counter is not very large so we count the number of times it overflows. When the 1 second interrupt fires we multiply out the number of overflows by the counters capacity. Lastly the remainder from the counter is added to the result to get the frequency. Again the counter is cleared.

The above examples use the AVR's internal counters. A less efficient way of getting the frequency is to have an interrupt to count the number of times a pin changes. Again this can be read and reset at one second intervals. This slows the overall execution of the program down when very high frequencies ( > 40K Hz) are being presented on the input.


Brand new to Arduino, and can't even make an LED blink

Other than what what Nick Gammon said that you need the resistor from the board to led, as that will cause your microcontroller pins to get damaged.

The other possible problem is the two breadboards you have put together, the power rails have not been bridged between the two boards. This means that the switch is not providing any logical state to the microcontroller.

Also the only reason why the led is show in the book as a separate thing is that it is meant as an educational exercise to make you build something, the L led will do the same thing.


Analog multiplexers are one way, but they tend to have a significant resistance when on, and this could cause the protocol not to work.
For 80 channels you need 7 bits addressing. Say you have an 8-input multiplexer, then a 3-bit address indicates which of the 8 inputs is selected. Use 10 of these, all with the three address lines connected, and you have 10 outputs from 80 inputs.
Next, use a 16-input multiplexer to select which of the 10 inputs you want to use. For this multiplexer you need 4 address lines. Together with the other 3 address lines you have 7 address lines, enough to select 1 of up to 128 sensors. But I repeat, this approach may not work if the multiplexer's resistance is too high.

A more robust (albeit more expensive) is to use analog switches to connect/disconnect each sensor. Analog switches (Analog Devices has a lot of them) have on-resistances down to < 1 ohm, so the sure should be OK for the application.
To control the long series of switches you could use a daisy chain of 74HC595 shift registers, which only requires a couple of I/Os on your controller, but gives you virtually unlimited outputs.


ESP-01 wakes up from deep sleep and then hangs

Not necessarily an answer, but something to look at: check the Manufacturer ID of the Flash on your board.  My suspicion is that when some Flash chips come out of suspend, they're in lower drive mode than on initial power-up.  At least one person fixed his 'zombie mode' by replacing the Flash with a different vendor.  Nobody else has attempted it yet.
I have an Inland ESP-01S that's reporting MID = 0x5E (supposedly Zbit) and it comes out of Deep Sleep repeatedly.  Here's all of the Manufacturer IDs I know of or have seen:
Winbond EF
GigaDevice C8
Puya 85
Bright Moon 53
BergMicro E0
XMC 20
XTX 0B
Eon 1C
Shanghai Fundan A1
Macronix C2
Hua Hong Zhixin 68
ISSI 9D
Paragon E0 (same as Berg - oopsie or clone?)
Zbit 5E
Zetta BA
esptool.py --port /dev/ttyUSB0 flash_id   (linux)
esptool.py -p COMx flash_id    (Windoze)
Note: the cheap D1 Mini boards with no-name ESP-12F modules flooding eBay, Aliexpress and other places report XTX Flash, and they have a 5.6K pull-up on EXT_RSTB which will shorten the RST pulse from GPIO16, as well as making it hard to hit the level to be detected as a LOW due to the series 470 ohm resistor.  We're unsure whether it's the Flash or the low value pull-up (typically 10 or 12K on other boards/modules) that's causing issues with those boards.  Normally if RST isn't seen as LOW after Deep Sleep then you'll get an "ets_main.c" message at boot before it hangs.
I have a clone D1 Mini Pro that has a Flash that reports MID = EF (Winbond), although the marking on the Flash is nothing I can find on Winbond's site, only on places selling cheap Flash.  Luckily the D1 Mini Pro also exits Deep Sleep successfully.


Is it possible to combine a HC-05 Bluetooth module and a shrinked arduino ATtiny45/85 to control a motor, LEDs, or other components?

The ATTiny has 5 usable pins (6 if you decide to reuse the Reset pin). Since it doesn't have UART hardware, you need to use a SoftwareSerial library to communicate with the HC-05. This takes 2 pins. To drive a motor, you need at least 1 pin. If you need to control it's speed (instead of just on and off), you would need to generate a PWM signal. Either through hardware timer or by code. (The ATTiny has 2 timers. When you want to use PWM with hardware timer, you need to make sure, that the SoftwareSerial library doesn't want to use the same timer). For the servo it's similar. The servos position is encoded by pulse lengths. (Make sure, that the used library doesn't want to use an already used timer)

Unless you use techniques as multiplexing or matrixes (which are not that useful for a small number of LEDs), you need 1 pin per LED.

Depending on what exactly you want to achieve, you will pretty fast run out of pins. Since you are a beginner you should start with a chip with more pins. If you don't know, how exactly your project will be in the end, better by a chip with maybe double the pins, that you think you need. Develop, until you really know, what functionality your project should have, what not and what you need to achieve that. Based on this you can choose the correct chip, that is as small as possible. Also consider using SMD parts in the finished version. There are mostly much smaller, but also more difficult to solder.


Your circuit drawing seems very wrong, but it is not helpful since, as
you say, it doesn't represent the real circuit. Please, add a proper
diagram of the actual circuit.

As for your reliability problem, I did not dig into the logic of the
code you posted, but I suspect it may be caused by the lack of
debouncing. You could add you own debouncing code but, for the sake
of simplicity, I suggest you instead use a ready-made library, like
Bounce2.

For the kind of program you are trying to write, I find that the logic
becomes way easier to grasp if you think think of it as a finite state
machine. This is program construct based on the idea that the
system can be in any of a predefined set of possible states, and that
its behavior and the possible state transitions depend on what
particular state it is in. In this specific case, I would use three
states:

In the LOCKED state, the lid is locked and you need to press the
button twice in order to unlock it. Once you press the button once,
it transitions to the WAITING state.
In the WAITING state, the lid is still locked, but the first
button press has already been registered. If you press the button
again, the system transitions to the UNLOCKED state. If not,
after a timeout it transitions back to LOCKED.
In the UNLOCKED state the lid is unlocked. After another timeout it
transitions back to the LOCKED state.

Once you have this logic written down, it can be translated into code in
a very straightforward way:

#include <Bounce2.h>

const uint8_t  switch_pin = 2;
const uint8_t  relay_pin  = 4;
const uint32_t wait_interval = 10000;  // 10 s
const uint32_t lock_interval =  4000;  //  4 s

Bounce button;

void setup() {
    button.attach(switch_pin, INPUT_PULLUP);
    pinMode(relay_pin, OUTPUT);
    Serial.begin(9600);
    Serial.println("Ready.");
}

void loop() {
    static enum { LOCKED, WAITING, UNLOCKED } state = LOCKED;
    static uint32_t last_change;  // not used in the LOCKED state

    button.update();
    uint32_t now = millis();
    switch (state) {
    case LOCKED:
        if (button.fell()) {
            Serial.println(F("Waiting for second button press."));
            state = WAITING;
            last_change = now;
        }
        break;
    case WAITING:
        if (button.fell()) {
            Serial.println(F("Unlocking."));
            digitalWrite(relay_pin, HIGH);
            state = UNLOCKED;
            last_change = now;
        } else if (now - last_change >= wait_interval) {
            Serial.println(F("Wait time out."));
            state = LOCKED;
        }
        break;
    case UNLOCKED:
        if (now - last_change >= lock_interval) {
            Serial.println(F("Locking."));
            digitalWrite(relay_pin, LOW);
            state = LOCKED;
        }
        break;
    }
}


When GPS can't see satellites, how can I continue to tick off a smooth-ish time?

What you want, namely something to “smooth the received (GPS) time”,
is called a GPS disciplined oscillator. Obviously, you are not
after the high accuracy of commercial GPSDOs, but the working principle
of what you are describing is essentially the same.

  what do I do when the GPS can't find a signal?

In GPSDO lingo, this is called the “holdover” state. At this point you
rely solely on your local oscillator (here, millis() or micros()),
and steer it to correct for is natural drift, as determined while the
GPS reception was good. Or you can go fancy, measure the chip
temperature, and apply a temperature compensation.

  I'm somewhat aware of DIP methods, but I'm not sure how to apply them
  here

I guess you mean “PID”.

You apply this to the phase of the oscillator. If the local oscillator
is ahead of the GPS (positive phase error), you lower its frequency. For
example, you could increment the seconds count every 1,000,100
microseconds (as measured by micros()), instead of every 1,000,000.
This will make your clock a little bit slow, and resynchronize it with
the GPS. Conversely, if your clock is behind the GPS, you slightly
increase its frequency to make it run faster.

In other words, the error value of your PID is the phase error of your
clock, and the control variable is the frequency adjustment. By
applying the PID technique this way, you are building what is known as a
phase-locked loop, or PLL. This is the standard way of
implementing a GPSDO.

  It seems that someone must have solved the problem for the sake of
  syncing internet time

Sure, but NTP implementations can be quite complex, as they have to deal
with multiple servers having different round-trip delays and different
levels of trust. I am not aware of any Arduino library that does
anything similar. You may search for “time synchronization” or “PLL”. If
you don't find any, you can pick a PID library and apply it to your
oscillator.

A couple of final remarks:

You wrote “speed up and slow down by several percent over the course
of a few minutes isn't uncommon”. This shows there is something
awfully wrong with either your Arduino or your code. Over a few
minutes, you expect frequency variations of the order of one part
per million on an Arduino clocked off a ceramic resonator, and a few
parts per billion if yours is clocked off a crystal. See this
experimental study on the stability of an Arduino clock.
This stability problem is the very first thing you should investigate
and fix.
Many GPS modules have the option to give you a 1PPS (one pulse per
second) signal. If you can use this signal, you may get a quite
accurate measurement of your phase error. Relying on the NMEA
sentences will give you lots of jitter, which you would then have to
compensate for by setting the time constant of the PLL to a very long
value.


Is it possible to see a graphical view of digital and analog pin values?

The Arduino Dashboard project sounds promising but quite likely it loops through the I/O pins periodically and uploads the results to your PC. I'm guessing you want live monitoring (as opposed to snapshots) while your own program (not the Dashboard sketch) is running. In that case, you'd need to isolate the relevant parts of the Dashboard sketch and integrate them with your code, and unless your are looking for fairly low frequency signal changes, have a timer interrupt function that runs the Dashboard frequently, which will have an impact on your own code. If the signals are fairly low frequency you might get away with putting a call to Dashboard in your loop() function instead of running it from a timer interrupt. If you're looking for program bugs that are changing your outputs, once per loop() may be fairly useless. A timer-interrupt would be necessary, and might have to analyze the stack and output the names or addresses of functions that had run recently. At that point you'd be on your way to implementing a debuggerand may want to consider an in-circuit emulator or a bus analyzer to capture the event. Or get smarter about isolating the code responsible for the event until you have a manageable, printf-debuggable code segment.


Arduino serial communication synchronisation

I suspect you problem stems from the use of delay's in your code. for example,

if (data=='1')
 {
  digitalWrite(13,HIGH);
  delay(4000);
  digitalWrite(13,LOW);
  delay(4000);
 }

Those delays prevent any computations from happening for 4 seconds each. Your arduino will not read another character after it sees a '1' for 8 seconds. If you send too much data in that 8 seconds to fit in the serial buffer, the extra characters are lost.

The behavior you seem to want will require separating the code that reads serial from the code that runs the output, and making sure neither section ever stops execution with delays. Your blinks will need to be timed with something else, like frequent comparisons against the current time with millis()


2 SPI Slaves with 2 different SPI modes on one Arduino Mega

For anyone who has a similar issue with the SPI Bus, SdFat library has a Software SPI option built in (example here).
You need to modify your SdFat/SdFatConfig.h file, but that is minimal. Once you have the microSD card module on a separate bus, it will not corrupt the main SPI Bus.
Switching the SD Card module to it's own bus rectified the issue. Keep in mind that Software SPI comes with a speed penalty.


There's one part of your code conspicuous by its absence:

pingRange(2);
pingRange(3);

You're calling the functions, but you're not doing anything with the returned value.  I think you meant to print that value to the serial interface...

Serial.println(pingRange(2));
Serial.println(pingRange(3));


How can I define a port extender MCP23s17 pin in Arduino

If you use this arduino library:

#define LED_PIN 15

mcp.pinMode(LED_PIN, LOW); //set led pin on the MCP23S17 to an OUTPUT

mcp.digitalWrite(LED_PIN, LOW)


Leonardo - always on power, status remains between computer reboots?

Is it possible to power a Leonardo to be always on, separate from the power from the USB host

Yes, that is what the barrel jack is for.

  I've tried with a full size Leonardo and a power adapter but for some reason the code didn't run when I did that.

Then your code is wrong. Are you using while (!Serial); or something similar near the top of your code?

  For a start avoid it's boot up time

The most certain way of doing that is to not use the bootloader. Instead program the board directly with a hardware programmer disabling (or erasing) the bootloader.

  Obviously that means the Arduino will see it's USB host disappear then come back online, will that automatically reset it and thus start it from the beginning again, or can I set it so that with always on power it will carry on doing what it is, irregardless of it's connecting to the host?

The Leonardo only reboots if you open the serial port at 1200 baud, or toggle the RESET pin / button.

  Do I need to change code, or libraries to achieve any of this?

It sounds like you may need to, yes - since it's not working at the moment when if the code were correct it should work.

IMPORTANT

Most computers will not recognize the Leonardo until the operating system is fully booted. This means you cannot use the Leonardo to interact with the BIOS or boot menu. The Leonardo does not implement the "Boot Protocol" keyboard which is required to interact with the BIOS or other pre-boot environment.


Stopping a countdown timer when it hits 0

In this line you are calculating the time you are going to display.   You could use that same calculation in an if statement to put you into the FINISHED state in your state machine.

printDigits (timeOne - startTime);
if(timeOne - startTime >= someInterval) {
    timer = FINISHED;
}

where someInterval is the number of milliseconds you want the timer to run for.


So I plug the JST connector to the Vin and GND pin and the LED doesn't light up. I noticed that I had plugged it in the wrong way and I immediately unplugged it. Next I make another attempt and this time I plugged the pins entirely somewhere else, again I disconnect quickly. The third time I connect it properly and the power LED lights up (phew...)

Unfortunately Vin on an Arduino Nano does not have a reverse polarity protection diode such as the Arduino Uno PWRin

  Did I burn my board?

Very probable. For more details please see "10 Ways to Destroy an Arduino".

Cheers!


Connecting six stepper motors to Arduino Uno

To answer your question, probably not.  But don't let that stop you.

Connecting two identical shields to a single Uno isn't going to work unless they explicitly support it, because the pins will clash.

So can you find yourself a CNC shield that is 'stand alone', if it had either an I2C or SPI bus interface then that would be even better?

Or can you find 6 stepper motor controllers that can be controlled from a smaller number of pin (or bus)?

Or can you find yourself an alternative processor with more grunt or more pins, such as a Mega or ESP8266 or ESP32?

Do a bit of research, get a few possible solutions and then ask on here for advice on why not to choose them.  Of course the more details and links you can provide the better informed peoples advice will be.


Ultrasonic sensor and ledstrip color problem

I believe your mistake is in this part of your code:

  yellow = distance <= YELLOW_THRESHOLD && distance > RED_THRESHOLD;
  red = distance <= RED_THRESHOLD;
  green = distance > YELLOW_THRESHOLD && distance <= GREEN_THRESHOLD;

  if (red) {
    setRed();
  } else if (yellow) {
    setYellow(distance);
  } else if (green) {
    setGreen(distance);
  } else {
    setGreenStandby();
  }

In particular, you are defining three boolean variables independently and then switching based on their values.

Assuming you are seeing the right values output on serial monitor (like 90 cm, 60 cm, etc...), which is something I'm unsure of as I'm not getting how you are determining the distance, then the following should be easier to follow/understand:

if (distance > GREEN_THRESHOLD) {
  setGreenStandby();
} else if (distance > YELLOW_THRESHOLD) {
  setGreen(distance);
} else if (distance > RED_THRESHOLD) {
  setYellow(distance);
} else {
  setRed();
}

You have only one variable determining the led strip configuration, no need to go to 3 and then try to reduce again ;-)

Please note that your YELLOW_THRESHOLD is defined as 140, if you don't ever see a message in the serial monitor greater than that value you don't have a chance of seeing any colour other than red.... I'm asking because you mentioned I also want a longer distance greater than 1 meter that might imply your sensor is unable to go farther than 1 meter...

With the code above I'm checking the distance in a greater to smaller order: the first matching is the only one activated and it's impossible for the distance variable to match more than one condition. Generally speaking, simpler is better.


Not seeing frames returned from client when using ESP8266 Wifi Shield

So I figured out the answer to my own question.

It turns out there must be a mistake in the example sketches that come with the ESP8266 shield I bought, as the function to begin Arduino/ESP8266 communications didn't have any arguments when the function expected parameters. So it appeared to be trying to set their baud rate to 0!!

I edited the library to have a hard value of 57600 and now it seems to work far more reliably.


Arduino - stepper motor wrong steps number

You're driving the stepper too fast, unintentionally though.

The while loop you use to delay is likely optimized out by the compiler:

while (tmp2++<Speed);

Easiest way to fix would be to declare tmp2 as a volatile variable when you declare it up in the top of your program.  Thusly:

volatile unsigned int tmp2;

This will inform the compiler that tmp2 might possibly change at any time and not to optimize it away. It's more complicated than that really, but it'll fix your issue in a single tweak.

Better, would be to use the delay() function, to pause execution for some specified milliseconds, much like you're attempting to do with the empty while loop.

You're using an UNO, so probably running at 16Mhz, so your delay of 7500 loops is technically about 5 instructions long, multiplied by 7500... so 37,500 instructions executed, and at approximately 16,000,000 instructions per second, that's (37500/16M) that's about 2.34 milliseconds.  So maybe a delay() of 3-5 milliseconds would be useful.

Basically, you're trying to step the motor too fast, and it can't keep up.  Mass, inertia and all that stuff are involved too.

Try replacing the while statements with delays, start with big delays (25 or so), and work lower as long as stepper motion is consistent.  As you said, 200 steps should be 180°.

replace:

while (tmp2++<Speed);

with:

delay(Speed);

and change Speed to an appropriate value (25 or so to begin with, play with it!).

There are many improvements to your code which could be discussed, but you need to crawl before you walk, before you run.  Get THIS code working, then finesse it.


How do I properly convert a pointer (uint8_t* or void*) to a "normal" integer?

Assume the following declarations:

uint8_t* nextPointer;
uint8_t* currentPointer;
size_t currentSize;

Then the expression is valid:

size_t freeMemSize = nextPointer - currentPointer - currentSize;

If any of the pointers are void* the compiler cannot calculate the expression (pointer or size).

Cheers!


My RTC DS1307 isn't returning any information. It seems to be stuck in the isrunning() function. Does anyone have debugging tips?

First thing I see is the Serial setup seems a bit backward:

  while (!Serial); // for Leonardo/Micro/Zero
  Serial.begin(57600);

First, begin Serial; then wait for it to become ready:

  Serial.begin(57600);
  while (!Serial); // for Leonardo/Micro/Zero

Next, is this while(1); inside the if statement:

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

Which says "if !rtc.begin(), then println and go into an infinite loop that does nothing".

Try:

while (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    //delay(500);  // depending on how fast you want this thing to retry/print
}

the final thing I see, is the next section of code appears like it might be "work code" but is in the setup() function and is missing any kind of a loop.  So it's going to run the if statement once, then setup() exits (and loop() starts getting called).

Either replace the "if" with a "while" and wait for "rtc.running()"

while (!rtc.running()); // Waiting for RTC to be running
// Set the clock time

or move it out of setup() and put it inside loop()

void loop() {
  if (! rtc.isrunning()) { //// **Where I think my code errors.**
    Serial.println("RTC is NOT running!");
    // Perhaps try and fix it?
  } else {
    // If the time hasn't been set; set it; then move on
  }
}


Is the device on the other side of the bluetooth connection running at 9600 baud too ?

You say you transmit the state of the sensor - which BTW is only ever a space ' ', and never changes.

So that value gets written out via the bluetooth connection.

But then you read data in from the other party to the bluetooth communications.

It sounds like you expect the data written to the bluetooth output serial line to also be echoed back from the bluetooth input.  The serial transmit and receive are separate channels.  You are receiving on the bluetooth.read() whatever the device connected to it is sending, not what you write yourself.

What you are sending goes only to the other side of the conversation.  The remote device would need to echo whatever it sees back for it to work how you describe.


Keyboard.press() expects a character, but you are passing a character array. Also Keyboard.press() only presses but does not release the key. Keyboard.releaseAll() can be used to release all keys.

I would try:

Keyboard.press('A') ;  //note the ' instead of "
Keyboard.releaseAll();

or preferably:

Keyboard.write('A');   //handles press and release of basic keys


Seeing consistent serial data loss over USB, have ruled out hardware and rx/tx software. What's left?

The driver board for your "Lasersaur" appears to be based around the Adafruit Trinket Pro.

That board, on Adafruit's website, is deprecated, with the following warning:

  Deprecation Warning: The Pro Trinket bit-bang USB technique it uses doesn't work as well as it did in 2014, many modern computers won't work well. So while we still carry the Pro Trinket so that people can maintain some older projets, we no longer recommend it.

So basically the USB interface is naff. It's too slow to keep up with modern computers (hence your old laptop works but your new one doesn't), and you lose data.

You should look into the possibility of upgrading the controller board to something a little more modern and capable.

For UNO R3 based boards there is another fundamental flaw: there is a 64 byte receive buffer and no flow control.  That means if you send data too fast - faster than the board can process it - data will be lost.


Communication between ESP01 Arduino NANO and using External Interrupt in Arduino NANO for other than communication program same time

D2 and D3 Pins on Arduino nano support external Interrupt. Hence, you have to use one of those for the interrupt.
Since you are using softwareSerial() you can easily remap it to other digital pins of the Nano.
Pins from D4-D12can be used for communication.
You just have to change the parameters in the softwareserial() as below:
SoftwareSerial mySerial(4, 5); // RX, TX;;for example


Serial.read(): Value changes to ASCII when I input from Serial Monitor

When you send the character 1, Serial.read() returns the integer 49.
 Serial.println(i) then sends the characters 4, 9, carriage return and a newline.

If you want to get back the same characters that you sent, change the type of i to char.


Movement and storage of servo positions via bluetooth

The character '⸮ ' was given everytime there was a power outage. So, it is enough to use an external power supply to power bluetooth and servos (Arduino cannot power all those modules simultaniously).


How do I make the HC-05 bluetooth module take data from the HC-SRO4, and then send it to my Android app?

First, it will read the values from the serial monitor. Then, I would like the HC-05 module to take these numbers and continuously send it to my Android app, which will then process what to do with the numbers.

No. What you do is you connect your Bluetooth module to two digital pins, which you'll use, along with the SoftwareSerial library, just the way you are using currently the Serial object. Look at the SoftwareSerial examples in the IDE.

Before you use the HC-05 module, and transmit data, you'll have to make sure it is set up properly (baud rate, name, PIN code, etc). Plenty of code and tutorials on Google about that.


This is one of those cases where the solution is simply to implement a
finite state machine. Consider a state machine with these three
states:

LIGH: light has been detected by at least one of the sensors, the
LEDs follow the light sensors
SHORT_DARK: neither sensor sees light, both LEDs are off
LONG_DARK: it has been at least three seconds since neither sensor
saw light, both LEDs are on.

The transitions between those states can be depicted by the following
state diagram:

where “darkness detected” means that no sensor sees light, and “light
detected” means that at least one sensor sees light.

As a general rule, it is a good practice to always draw a state diagram
before you start writing code. Once you are sure your diagram describes
the desired behavior, it is almost trivial to translate it into code.
Here is how I would code it:

void loop()
{
    bool light_k = analogRead(IN_K) >= 1000;
    bool light_d = analogRead(IN_D) >= 1000;

    static enum { LIGHT, SHORT_DARK, LONG_DARK } state;
    static uint32_t darkness_start;
    switch (state) {
    case LIGHT:
        digitalWrite(OUT_K, light_k ? HIGH : LOW);
        digitalWrite(OUT_D, light_d ? HIGH : LOW);
        if (!light_k && !light_d) {
            darkness_start = millis();
            state = SHORT_DARK;
        }
        break;
    case SHORT_DARK:
        if (light_k || light_d) {
            state = LIGHT;
        } else if (millis() - darkness_start >= 3000) {
            digitalWrite(OUT_K, HIGH);
            digitalWrite(OUT_D, HIGH);
            state = LONG_DARK;
        }
        break;
    case LONG_DARK:
        if (light_k || light_d) {
            state = LIGHT;
        }
        break;
    }
}


Arduino Wire communication with MCP23008 GPIO pin expander to turn on an LED with a button press

I see one major thing wrong at first glance:

  Wire.write(00000010);           //set all pins as output, except for #2 as input

That doesn't set GPIO 1 (which you call number 2 - counting starts at 0 not 1) to be an input, that sets GPIO 3 (number 4) as an input.  Numbers starting with 0 are octal, not binary. For binary the prefix is 0b:

  Wire.write(0b00000010);           //set all pins as output, except for #2 as input

And then you read using:

bitRead(inVal, 1)

which would have read GPIO 1 which is configured as an output.

So you have a switch on GPIO 1 which is an output, which you then drive high (causing a short internally which can damage the pin), and as a result you drive the pin HIGH internally. Now it's always high, so a read of the pin sees the HIGH you are driving from it. Hence it gets stuck at 1.

Fixing your IODIR write should help solve that problem.


Can I power a LilyPad with an iPhone lightning port?

If the phone has an accessible battery you could conceivably use the battery terminals to power a device such as Arduino. However, I think current smartphone batteries have complex monitoring circuits so this wont work.

If it doesn't, you'd be looking at using the USB/charger port on the phone.If your phone supports USB On-The-Go, I know that it allows phones to act as USB hosts, and according to USB-OTG specifications, the host must be able to supply at least 8mA of current between 4.4V and 5.25V.

If that's enough for you it could work.


Soft debouncing from an interrupt during stand-by

You don't update last_millis.
Also, you don't know whether SELECTOR_BTN went from HIGH to LOW or whether another pin fired the interrupt while SELECTOR_BTN was low. Remember the previous state to solve this.

const unsigned long debounceTime = 50;
volatile bool ir_selector_pressed = false;

ISR (PCINT2_vect) { // handle pin change interrupt for D0 to D7 here
  static unsigned long previousStateChangeMillis = 0;
  static bool previousPinState = HIGH;

  bool pinState = digitalRead(SELECTOR_BTN);
  if (pinState != previousPinState) { // ignore pin changes of pins other than SELECTOR_BTN
    if (pinState == LOW) { // only falling events
      if ((millis() - previousStateChangeMillis) > debounceTime) { // debounce
        ir_selector_pressed = true;
      }
    }
    previousPinState = pinState;
    previousStateChangeMillis = millis();
  }
}


My Arduino UNO turns LED ON forever when I connect it to my Laptop

When you connect the device, if you hear the Windows "found device" sound, then you need to check your COM port driver, as it's very likely that the COM port number may have changed. On your Desktop or in File Manager, right click "This PC" or "My Computer", and select "Manage" from the submenu.  That will bring up the Computer Management console. On the left, select "Device Manager".  That will bring up your list of devices. In the list look for "Ports (COM & LPT)".

If you don't see, "Ports", then click "View" and check "Show hidden devices".  If this is the only Arduino that you've ever used, you should only see one listing. Make note of the COM Port Number the driver is using. It's possible that the port number may have changed since you first used the device. Plug-n-play will do this if you plug the cable into a different USB port that may be using a different USB controller, etc.

Then in your Arduino IDE, click "Tools", then expand "Boards" and select "Arduino/Genuino UNO" board, then re-click "Tools", and hover over "Port", and select the port number that is assigned to the Port that you found in Device Manager.

If that doesn't work, then you may have a problem with your driver.  Some of the "cheap chinese board" use a different FTDI chipset, so the plug-n-play windows driver may not work. In that case, the manufacturer should point you to the correct driver. Download their provided driver, then you can update the driver in Device Manager.


What type of relay will handle a 51 amp 10 hp motor and a 75 amp 15 hp motor?

A very very very large one, by normal standards :-).
That is a substantial requirement and  needs a relay specialist to check what you are doing.

What voltage are you using and is it AC or DC.
1 HP = 746 Watts, so 10 HP = 7460 Watts
V = W/I = 7460/ 51A = 146V.
Which may mean you have a 110 VAC system with an allowance for starting, or ...?

That spec will allow a reputable relay supplier to ask you whatever other questions are necessary to fine tune what they offer. Things like:

AC or DC makes a HUGE difference.
Voltage makes a difference.
Whether you have any sort of on-line starter or if this IS the online starter makes a difference.
Whether the motors start loaded or are run up to speed and then loaded can make a large difference.
N/C or N/O operation makes some difference (which may not be intuitively obvious)
Other ... the specialist will ask questions.

What is the application?

Serious question: What sort of answer did you expect?.


int isn't guaranteed to be the same size across platforms. Use fixed width integer types instead.
https://en.cppreference.com/w/cpp/types/integer
struct TransmitData
{
  int32_t a;
  int32_t b;
  int32_t c;
  int32_t d;
  float e;
  float f;
  float g;
  float h;
};


Arduino-Pyserial communication on Python 3, Windows machine: Pyserial.write() doesn't seem to do anything

What do you think should come out?

I'm no expert with Python but you seem to be using struct pack, which I think prepends a number of bytes to the data to generate a 4 byte word.  You are using NULL, 0 to pack the structure.  When Serial.println() encounter a NULL it will assume that is the end of the string.  So you seem to be printing a zero byte string.

Oh and Serial.read() only reads one byte of data, so there is an issue with that too. I suspect that the write call has a similar issue, you normally need to supply a size parameter because its binary data.

Does that make sense?


Seems to me you first need to establish a protocol.  Could just be a simple one you make up,  with it you will eventually find that repetition and retransmission will need to be explored, and you may want to include things such as a CRC if the application suits it; or not...

As part of the thought process you need to look at your sensors, see how they put out their data, you seem to indicate analog, so that would be read on an a to d converter and that d value might be directly sent as the data part of your chosen protocol.

Or some joysticks packages might have have a I2C or SPI driver built in to which the A to D wouldn't be required.

But using IR you will find timing and validation very important so that the receiver knows where the beginning and end of data is at.

Thinking about it there must some libraries out there already.
Or entirely completed projects to study.

Now you didn't ask but if reliable communication is desired you might want to go wired serial or use a managed protocol like an Ethernet peripheral.


Something is wrong with your setup. I don't have a Nano to hand to test, but it would consume similar current to a Uno (probably less) which is around 50 mA. Thus, using a 2800 mAh battery you should have a life of 2800/50 = 56 hours.

Li-ion batteries come in multiples of cells, where individual cells have a nominal voltage of 3.6V (thus you probably have three cells giving 10.8V). Deeply discharged they will have a voltage of 3.0V per cell (a total of 9V for your three cells). If you started at 9.8V as you stated, then the cells would have been 90% discharged already which probably accounts for the short running time.

Assuming you haven't wired it in a strange way (and it would help to show the wiring and possibly a photo) I suggest you try with a fully-charged battery.

Another helpful thing to do would be to measure the current consumption of the battery using a multimeter. Make sure you read up on how to measure current with a meter or you may damage something (example here).

The basic idea is shown in this photo:

The meter is placed in series with the battery and the Arduino. The negative side of the battery goes to the Arduino in the usual way. The positive side of the battery goes into the "milliamps" input of the meter (which is set to 200 mA range in my case) and then the common (black) lead from the voltmeter goes to the positive (Vin) side of the Arduino.

You can see that in this particular case, with a 9V battery, the Arduino is consuming 57.7 mA.  I don't quite believe that reading as re-measuring with a more expensive meter gave a reading of 51.1 mA. Still, that gives you a ball-park figure. And it shows that spending a bit more on a better meter gives you more accurate results. :)

I have a page about power saving and you can also refer to the Wikipedia page about Li-ion batteries.

  my volt meter read 9.8v and 1 hour later 2.8v. causing the Nano to go off.

For a 12V Li-ion battery get down to 2.8V there is something seriously wrong with its protection circuitry. It should cut the battery out at 3V per cell, that is at 9V if you have 3 cells in series.


What is the memory expense of creating a String from a char array?

What would be the best-practice in this kind of situation?

To not use String.

I also want to allow the end user to use the String functions (like indexOf) to search for particular content in emails.

There's nothing wrong with providing an indexOf function in your API.  But you don't have to use String to implement that function when called.  You can just use the strstr function on char arrays (reference here).
I should also point out that most Arduinos do not have enough RAM for storing an email.
UPDATE 07-01-2016:
To answer the titular question, the fixed cost of using String is at least 1600 bytes of program space, more if you use more than a few methods.  The linker can throw out methods you don't use.
Then for each String variable you declare, the recurring cost is 8 bytes for the variable itself, plus the variable-size memory chunk for your character data.  This chunk is allocated from the heap, and is the size of your string plus 4 more bytes to manage the chunk within the heap.  That's a total of 12 extra bytes per String instance.
However, I did not originally answer that question because you explicitly asked about the memory expense.  This ignores other expenses that should not be ignored:

execution time - Allocating memory from the heap is really a search for a chunk of the requested size.  At the beginning it can be quick, but as the heap gets fragmented (small chunks build up) it takes longer to find a chunk.  And when the String is emptied or destroyed, the memory chunk gets put back into the heap and (possibly) merged with adjacent chunks.  Reducing the size of a String does not free up any memory.  The String maintains its maximum size until it is emptied or destroyed.
long-term stability - Embedded Systems are supposed run forever.  A primary characteristic of a system that can run forever is "deterministic."  For whatever inputs it receives, it has a predictable response and end state.  When you use the heap via String, the heap gets fragmented according to the data it handles.  This is not predictable, and it may get into a state where no memory chunk of the requested size is available.  Choke.
maintenance - because the heap state depends on the processed String data, finding the cause of the failure can be difficult.  It can fail at different times because the input data is different, and it can fail at different places in the program.

Because of these expenses, String is rarely used by an experienced developer.  Unfortunately, String is tempting to the beginner because it is easy to understand.  What is difficult to understand is the complicated, non-deterministic behaviour under the hood that inevitably leads to system failure, rending of garments and gnashing of teeth.


TinkerCAD may have mislead you on the pinout for the transistor

TinkerCAD

PN2222A


Using the DHCP (Dynamic Host Configuration Protocol) you can obtain an IP address dynamically from a DHCP server (which a router usually also is), without having to hardcode it into the firmware of the Arduino, thus enabling it to work on different networks.

There is also a library for that: http://www.arduino.cc/en/Tutorial/DhcpAddressPrinter. It's an extension of the official Arduino Ethernet library, written for the Arduino Ethernet Shield, but you'll likely find implementations of DHCP in many Ethernet libraries (I am using the EtherCard library) because it's an important feature to be able to connect to a network without a statically assigned IP and "only" requires UDP (on top of IP).

For e.g. the Ethernet library you call the begin function either with only the MAC address of your device or with MAC and IP address:

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

In the first case it will use DHCP to obtain an IP address dynamically, in the second case it will use the static IP address you provide. Be warned that the second case, due to the needed implementation of DHCP, will increase the size of the compiled binary significantly.


What is the typical form for a finished Arduino project?

I'm in the same boat as you (SW engineer by trade who likes to tinker with electronics, and is a "maker" at heart.)

I think the answer to your question is "it depends." For a one-off, a breadboard might be fine.

For half-a-dozen, you might want to get project cases and perf-boards, and solder up your design. (For the Mega, there is a very nice prototyping "shield" that brings all the pins from the Mega up on headers and has quite a bit of working room for soldering up circuits.) If you want to make more than a handful, though, you'd probably want to create a custom PC board. You can either create a design in a CAD program and send it off to be small-batch manufactured, or you can buy the equipment to do it yourself. If you make hundreds of units, you should think about ditching the Arduinos and designing a completely custom board using the AVR-family microcontroller and only the components you need.

(I'm still at the breadboard/hand soldered perf-board stage myself, and haven't created any custom PC boards yet, just read about it.)


When uploading a sketch to an esp8266, isn't that the same as "flashing firmware"?

Uploading a "sketch" is indeed "flashing firmware".

  why does the esp8266 WiFi still visible in available connections?

I'm not sure what you mean by that.


ESP8266 ESP-07 does not respond to commands

The esp8266 is without AT firmware. Even with SoftwareSerial at 115200 baud you should see "ready" from AT firmware and get some response to AT commands.

This esp8266 module adapter is simple to flash. It makes the 5 V to 3.3 V conversion for power and RX pin and has a program switch (io 0) and a reset button to put the esp8266 into flashing mode.

Use an USB-to-TTL-Serial adapter or an Arduino with USB chip to connect the adapter to PC. Then switch to "program" and reset it and it will be in flashing mode.

You can download the AT firmware here. I recommend ESP8266 NonOS AT Bin V1.7.1. Don't try 2.0, it is very different (ESP32 AT firmware build for esp8266).

To flash it, use esptool

The command to flash the AT firmware binaries to any module with at least 1 MB flash memory is:

esptool.py write_flash --flash_size 2MB-c1 0x0 boot_v1.7.bin 0x01000 at/1024+1024/user1.2048.new.5.bin 0x1fb000 blank.bin 0x1fc000 esp_init_data_default_v08.bin 0xfe000 blank.bin 0x1fe000 blank.bin

don't wonder about the 2MB-c1 setting and don't change it. The AT binaries are build for 2MB-c1 partitioning. On 1 MB flash it will not support AT firmware OTA update.

If you want to use the Espressif Flash Download Tool, use the same settings as on esptool command line.


How to add numbers to a position when controlling a seven-segment display

In your code, you call:

newPos = encoder.getPosition();

which grabs the absolute position of the encoder. When you rotate this one step, the value of newPos goes up (or down) by one.

Then, you make pos = newPos + 4, which simply adds 4 to the value that is going up or down by one step at a time.

newPos: 1    pos: 5
newPos: 2    pos: 6
newPos: 3    pos: 7
newPos: 4    pos: 8
newPos: 5    pos: 9

Instead, it sounds like you wish the display to always read 5 times the encoder position. If so, then you should write pos = newPos*5.

newPos: 1    pos: 5
newPos: 2    pos: 10
newPos: 3    pos: 15
newPos: 4    pos: 20
newPos: 5    pos: 25

Then, when you write to the display, you do so as:

display.showNumberDec(newPos, true); // Expect: 1234

But newPos is not the newly calculated value. Instead, call

display.showNumberDec(pos, true); // Expect: 1234


How to power my Arduino mini using wall socket?

I have connected the Relay and IR receiver directly to the Arduino
  mini. Pin 10-14 are used for the relays Ins and PWD 3 for IR output.

I hope you don't mean that you have connected the coils of the relays directly to the Arduino pins. If that's the case, the surprise won't be the regulator blowing up, but the MCU surviving. Please edit the post and add complete schematics and/or photos of your prototype.

  The mini works with these 5V mobile chargers but the amount it heats
  up scares me. Any suggestions on what I should do.?

Use a small heatsink if you're concerned about the regulator heating up. But it really shouldn't be a problem unless you're driving too much current from it. Have you actually measured the temperature it reaches?

Also, don't feed the coil through the regulator, but directly from the 5V adapter (presuming your relays are 5V). This will save a lot of dissipation in the regulator. NOTE: don't do this if you use a higher (> 5) voltage adapter!!

  Also how much current consumption would be needed. I have tried using
  a 5V 300mA charger and 5V 700mA charger. Both work almost the same.
  Why?

Those current ratings are maximum values, not constant values. So, if your circuit draws let's say 290 mA, both adapters will be able to do the job.

EDIT: additional information

To safely and properly use relays with arduino, you need some interfacing electronics like this:

Full article from the source, here. Flyback diode: 1N4148. You can use almost any "logic-level" N-channel MOSFET.

If you're using instead a relay module similar to the shown below, all the required interfacing electronics are already built into it and your digital pins won't suffer any overcurrent condition.

However, the regulator will (probably) still suffer from excessive current through it. In some of these relay modules you can optionally use a different power line (JD-VCC, see below) for the relay coil. If you own one of these, feed it directly from the 5V adapter, skipping the regulator.

If the relay module doesn't have a separate power line, it may still work when connected to the 5V adapter if the dropout in the regulator is not too big (i.e., the "high" level from the digital pins is not too far away from the adapter voltage).


Assembling a float from an array of bytes

Just cast the pointer.

float conAck = *((float*)(bufferBytes + 9));


Using an Arduino to switching a grounded load powered by a 12 Volt supply

In your existing arrangement.
Swap to P Channel FET
Swap drain and source leads (right hand two).
This will work for up to 5V feed to LEDs.
To get 12v operation you will need to add a driver between the FET gate and the Arduino.
see circuit diagram below.

To operate with FET on the HIGH (V+) side when V+ is greater than the rduino's supply voltage, the FET must either

Be P Channel with FET source to +12V and FET drain to load+ or

An N Channel with gate drive above V+.
The gate drive to the FET must go to about +12V to turn it off.
The Arduino will only drive it to +5V.

As you are unlikely to want to provide an extra high side drive the P channel option is preferred. This could be eg:

A "jellybean" bipolar transistor or small FET worth a few cents) and a few resistors, or a small N Channel MOSFET and one resistor

or

An opto isolator.

Transistor driver:
Bipolar transistor NPN (BC337 / BC817 or similar)(ANYTHING NPN will work).
R1 = 10k resistor Arduino out to base.
R2 = 10k FET gate to +12.
If an N Channel MOSFET is used for Q1 then R1 is not needed.
This could be a  5LN01SP IF you can get them - no stock Digikey.These have a very low Vgsth (turn on voltage)
Otherwise you can use a 2n2222, VN2222, BS108 or similar logic-gate N channel MOSFET.
eg VN2222. Many variants of these are widely available and low cost.

simulate this circuit – Schematic created using CircuitLab


You have to use the begin command. Instead of:

SDS011(byte pin_rx, byte pin_tx)

...

SDS011 my_sds;

Use

SDS011 my_sds;

(Thus remove the first line: SDS011(byte pin_rx, byte pin_tx)).

And in setup add:

my_sds.begin(0, 1);

This follows the library function of SDS011:

void begin(uint8_t pin_rx, uint8_t pin_tx);

Other errors: because you forgot the ; in

SDS011(byte pin_rx, byte pin_tx)

the next line:

float p10,p25;

is misinterpreted, and p10 and p25 are not known. Therefore errors are shown while trying to use p10 and p25.

These errors will go when changing the begin code as described earlier.


Run multiple function with different argument/return structure by one function pointer

I assume, that the fun_ptr points to the different service functions to do some kind of animation other other long running tasks on your display, thus you want to repeatedly call them in a structured way.
What you are currently doing will not really work. When you call a function, you need to provide its arguments. That's the same for a function pointer. You cannot call a function, that demands parameters, without any parameters. While you can still set a function pointer of type (void (*)(void*) to a function of type (void (*)(uint8_t)), the compiler warns so, because you still cannot call the function without any parameter. If you are trying to do so, you will still get an error of too few arguments to function ....
I see 2 ways to go from here:

You could overload your functions, so that a version without any parameters exists. Like this:
  void foo(uint8_t i){Serial.println(i);}
  void foo(){foo(10);}

With 10 being the value, with which the function should be called, when you provide no parameters. You can of course also use variables or function calls here, to actually get that value for the parameter i. Then you can use the pointer to call that function:
  void (* p)(void);
  p = &foo;
  p();

The assignment of the pointer will choose the version of the function without any parameters out of the overloaded pool of this function, since that matches the type of the pointer. Note, that I removed the * from the void parameter definition. I don't understand, what that would mean anyway (pointer to void?). The function pointer p() can now be called without any parameters, since it points to a function without any parameters.

You could ditch the function pointer and use a simple switch case statement with a state variable (which holds some identifier for the corresponding function), to call the correct service function. I won't go into detail here, since that is already basically, how an FSM can be programmed in C++, which is covered on this site and on the web numerous times.

If I were you, I probably would go with the first option, though that might also depend on the overall logic, that I currently don't really understand (too few information).


Mike, After looking at the question you are referring to (Convert to and from Unix Timestamp) your question makes a lot more sense.

That code is incomplete and its difficult to be certain what anything is for.  My best guess is days[][] would look like this:

byte days [4][13] =
{
    {366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
    {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
}

I derived this from:

  for (year=3; year>0; year--)     // 3 to 0 is a 4 year cycle, which looks like leap year checking.
  {
      if (epoch >= days[year][0])  // Checking the epoch against the first element in the array, which implies that's number of days per year.
          break;
  }

And the other elements in the array I guess from this

  for (month=11; month>0; month--)
  {
      if (epoch >= days[year][month])
          break;
  }

However The above way trades storage for performance, it uses 52 bytes to hold the days[][] rather than use extra CPU cycles.  A less storage intensive version would be:

byte daysInMonth = 31;
if (month == 2)
{
  if (year%4 == 0)
    daysInMonth = 29;
  else
    daysInMonth = 28;
}
else if (month == 4 || month == 6 || month == 9 || month == 11)
{
  daysInMonth = 30;
}


Why is Arduino STINO upload function not working?

I finally found it: Problem was solved after commenting those three lines in */Arduino-like IDE/app/uploader.py:

if force_to_reset:
    pre_serial_port = serial_port
    wait_for_upload_port = self.args.get('upload.wait_for_upload_port', 'true') == 'true'
    serial_port = resetSerial(pre_serial_port, self.output_console, wait_for_upload_port)
    # if self.args['cmd'] != 'avrdude':
    #   if serial_port.startswith('/dev/'):
    #       serial_port = serial_port[5:]
    if serial_port:
        for cur_command in self.command_list:
            command_text = cur_command.getCommand()
            command_text = command_text.replace(pre_serial_port, serial_port)
            cur_command.setCommand(command_text)


Using SoftwareSerial library with EnableInterrupt

SoftwareSerial uses all PinChange interrupts.
EnableInterrupts uses all PinChange interrupts.

You can see the conflict.

All you can do is to modify both libraries to remove support for the interrupts you don't need it to support - that way you share out the responsibility for handling the different interrupts between the two libraries.


I want to make mesh network with nodemcu (esp8266)

there are libraries for this already, i have used this one, but i have not tested the mesh function yet


I was stuck in a similar scenario. I managed to exit programming mode by floating GIPO0, then grounding RST for ~3 seconds, then floating it. If you power off the esp, and now turn it on, it should have exited programming mode. Powering it off is actually optional.


Arduino command line vs. Arduino builder

The Arduino IDE command line predates arduino-builder and was made available when the source pre-processing and compiling was implemented by a Java class (deeply) embedded in the IDE.

The current IDE uses arduino-builder behind the scenes to process and compile the code so if you use arduino-builder you avoid having to load the whole Java IDE. Try it out it does some pretty cool stuff


How to create objects with their own variables?

I was tempted to re-write your code (I am quite rusty on c++), but you may be better to start with an existing class.

There is a Button class on the Arduino site. See https://playground.arduino.cc/Code/Button

You could use this or study to see a more usual c++ implementation and adapt your code.

Virtually ALL c++ classes include a constructor. I would use instead of SetupButton

void button::button(int pin) {
  this->_pin=pin;
  pinMode(pin, INPUT_PULLUP);
}

and add uint8_t previousReading; and unsigned long time; to your class as private variables.


An Arduino Uno doesn't have a Real Time Clock, but you could contact a NTP time server on the internet using the WiFi shield you mention, and get the time from there, and then keep track of time using millis(). Every so often, you should adjust the time with a new call to the NTP time server, because the Arduino's clock isn't all that accurate.
The easiest way would be to get a RTC module (I think the most accurate and still affordable at the moment are DS3231-based). They have a slot for a backup battery so they keep time even when there is no power supply.
Connect the module using I2C to your Arduino, install the appropriate library, and ask it every second (or however accurate you want to be) in your loop() for the exact time.
These modules usually also have an interrupt pin and can generate an interrupt when an alarm time is reached; you could use that also.


So I do not need any special equipment on PC side right, I can even connect to the ESP's AP with mobile, right?

If you set the ESP8266 in AP you can connect to it with every wifi capable device.

You can control an ESP8266 with just an Arduino, but you I would not recommend using your Arduino as the power supply. If I remember correctly the mega's VCC pins are rated for 200mA which may or may not be enough for your ESP8266 I'm not sure, but I would recommend using another power supply for the ESP8266.

  Is it possible for the ESP to be WIFI client and connect to regular WIFI SSID

Yes that is possible.

  Is it possible to communicate bidirectional somehow?

I am not exactly sure what you want, but it is possible to communicate in both directions. Assuming you know the local IP address of your ESP8266, you could for example send an HTTP request to it using any browser to which the ESP8266 can reply with anything.

Your ESP8266 can also send data to your computer, but it would require some program on your computer listening for incoming connections. Also possible, but more difficult.

At last I would like to tell you that driving an ESP8266 with an Arduino is like driving a Ferrari with the engine from a tuk tuk. It will move, but you will never use all of it's features. I don't know which version of the ESP8266 you have, but there are versions out there that can be programmed via USB just as your Arduino and you can just use the Arduino IDE and all of it's features like the Arduino language.


Can you connect more sensors of the same type to a single board while not using up more pins than if you were to use a single sensor?

If the connection is a digital sense pin then you can use a parallel-in serial-out IC to read them all simultaneously and then shift it in. Takes up 3 pins on the arduino a latch a clock and a data pin.

If the connection is SPI then you can connect the clocks and MISO pins together and then need a slave select for each. you can control many of them with a serial in parallel out IC or a decoder.

If the connection is with the I2C protocol and each device has a different address then you can simply connect them all in parallel.

If the sensor has an analog output then you can use an analog to digital converter (ADC) which can have multiple inputs and often have a serial interface.


How to create large progmem arrays and not annoy the linker

Include Guards only protect against inclusion of a header file multiple times within the same translation unit.  This is important.  If you include a header file (1) in a source file, then include another header file (2) in the same source file, said header file also including the previous header file (1), then the include guard will perform its function.

If you have two source files and you include the same header in both, then the include guard will do nothing.

If you have a variable or function defined in a header file and you include that header into two different source files, when you link those source files together you will get a multiple definition error, since you have two translation units that have the same thing in them, and the linker doesn't like that.

The only time you should ever define variables or functions in a header file are if they are simple constant types, like a const int or a const char - something where the compiler can replace it verbatim in the code and optimize out the symbol completely (arrays of any kind are not simple), or if the symbol is declared "static", where it will be forced to remain "within" the translation unit and not get exported for linking.

Normally you will only declare your complex constants in the header file, and define them once and once only in a single source file. That way there is only one instance of the symbol in one translation unit.

For example, in the header file you would declare your constant:

extern const char foo[] PROGMEM;

And in your source file define the constant:

#include "foo.h"
const char foo[] PROGMEM = {0xDE,0xAD,0xBE,0xEF};

And in answer to the question "what's the difference between #include <...> and #include "..." - when it comes to Arduino, nothing whatsoever.

Officially it denotes a separation between "system" and "local" headers. That is, headers that are installed in the OS as part of the compiler, and headers that are contained within the project.  However there isn't that distinction with Arduino, and the two mean the same thing - just a header.

And finally a note on terminology - a glossary if you will:

Translation unit - One compilable source file (and any included headers) that forms a single file of object code to be linked.
Declaration (Declare) - The indicating of a symbol's type and any attributes, but not the content of that symbol
Definition (Define) - Associating a symbol, whilst declaring it, with the content of that symbol.
Symbol - the name of any variable, function, class, etc.


Help connecting ILI9341 LCD SPI Display to arduino uno

You can get it working by two methods

using a voltage divider e.g to shift from 5V to 3.3V you could use two resistors, 100k and 200k respecfully and between both resistors there is voltage of 3.3. One for each pin that needs it.
Using 10K resistors in series between the LCD and the arduino. I really don't know how is working but it works fine that way.

I tested both methods, also the MISO pin from the LCD can be connected directly to your arduino.


Digital Reading from a array without using the exact element

In your question you wrote

  and turn [the LED] off when [the corresponding button is] released

and yet you never turn the LEDs off in your code. Then, I assume the
code in your question is irrelevant, and you just want the LEDs to show
the states of the buttons at all times. This can be done by writing to
the LEDs the values you read from the buttons. Do this for each
button/LED pair, and loop over the pairs:

void loop() {
    for (int i = 0; i < 5; i++)
        digitalWrite(myLEDArray[i], digitalRead(myButtonArray[i]));
}


HC-SR505 PIR Sensor only outputting HIGH

The PIR sensor has delay of 8 seconds. So when you turn on arduino, take care that no movement is on the PIR, and then after 8 seconds it should detect no movement. And it has always this delay,every time when detects movement.


I would suggest:

Use a library (TinyGPS++ for example) to read the GPS data and extract just what you want.
Use a struct to craft a packet that you can send over bluetooth, or send the data as a textual representation, depending on your needs.

For a struct you can:

struct packet {
    uint8_t id;
    float latitude;
    float longitude;
};

struct packet myPacket;
myPacket.id = 32; // Unique ID
myPacket.latitude = gps.getLatitude(); // Whatever function call here
myPacket.longitude = gps.getLongitude(); // or whatever
rf95.send((uint8_t *)&myPacket, sizeof(struct packet));


Changing type of one variable dramatically changes compile size

Without being able to proof it (since I don't have your libraries and you gave only a small part of the sketch), I think this is what happens:

user3629249 is half right. If you change c to type uint8_t it only has 8 bits (hence the Name), so its maximum value will be 255. When you add 1 to it at this value, the variable will overflow and going back to 0. Thats normal overflow behavior, like used with the Arduinos Timer registers. (No undefined behavior there) So the maximum value c can reach is 255.

When compared to a bigger literal the value of c gets promoted to the correct type, so that the two values can be compared. But a variable that is at maximum 255 is always lower than 128*8. So you have an infinite loop there. The compiler can see this and doesn't include the functions from the rest of clearScreen(), since that is unreachable code.

All in all your code won't work as intended with uint8_t. You need a bigger type, that can hold the full range, that you operate. And this optimization is not strange, but very reasonable, since you really don't need the rest of clearScreen() in that case.


Everything is ready for project . I have one doubt! I am using transmitter + Arduino *Uno*..and receiver + arduino *nano* will it work?

Yes, it will work, in much the same way that you can send an email from a Mac to a Windows PC. The type of PC doesn't matter as long as they use the same protocol. As you haven't shared any details in that direction, I would say that if you have coded correctly, then it will work.


Replacing BT module with 433 MHz transreceiver module

Yes, use VirtualWire or RadioHead. You might need to "evolve" your protocol to handle message fragmentation and loss. RadioHead has support for that.

Cheers!


Is there a method of figuring out whether or not my stepper drivers are dead?

Most surefire way to tell if your drivers work is to wire them up CORRECTLY and try them out.  You should not be frying them if you have the correct setup (including current limit) for your conditions.  That said, conditions include your heat sink install and the environmental temperature.
The usual gotchas:

Note that DRV8825 and A4988s may have different pin locations so be sure to orient them correctly (check their EN pin location) if using a shield.
Also note that the gains from the voltage to the current limits will be different for the different model #s.  Be sure to use an appropriately sized screw driver and attach the meter to the screw driver as you turn to adjust the current limit.


You need to tell the sensor to send their pulse using the trigger line.  So triggering isn't a problem.
The problem is that you might get an echo returned on both sensors, but you know which sensor sent the pulse so you can ignore the return that was received by the 'wrong' sensor in your code.
So

While(1)
{
  SendPulse(SensorTx1);
  GetEcho(SensorRx1);
  SendPulse(SensorTx2);
  GetEcho(SensorRx2);
}

Is that what you mean?  If not please can you expand you question?


Unable to flash Arduino when TXD pin of HC-6 Bluetooth module is connected to Arduino RXD pin?

Most* Arduino devices are flashed through a bootloader which communicates over the serial pins. If you've connected another device to those pins, that communication may fail. You may need to disconnect the device while you flash the Arduino.

(*: The exceptions are the 32u4-based devices, like the Leonardo and Micro. These communicate directly over USB.)


Which board to select in PlatformIO for ESP Wroom 32?

The ESP WROOM32 is an ESP32, not an ESP8266. You have PlatformIO configured for an ESP8266, specifically the ESP12e, and there's no way that's going to work.
You'll want something more along these lines:
[env:espwroom32]
platform = espressif32

To choose the board - if you're using a breakout board, you'll need to be more specific about it - what model is it? ESP WROOM32 is just the name of the CPU module; PlatformIO needs to know the size of the flash storage in order to upload properly. Your link is to the entire Espressif ESP32 site. Otherwise, look through PlatformIO's list of ESP32 boards and find one that matches the amount of flash storage your board has.
You might want to read PlatformIO's ESP32 documentation.


How to use ESP8266 for wireless communication?

I'm not very clear on what you are asking but I think you are saying how do you connect an ESP8266 to an Arduino so the Arduino has wireless(WIFI) access.

I'm sure there are tutorials out there so I won't go in to detail (also I don't know the details), but hopefully you will get some better terms to search with.

The basic idea is you connect the serial connection of the ESP8266 to the serial of the Arduino (via a level shifter and connect Tx to Rx).  You then write a series of AT commands to configure the ESP8266 so that what ever is receives over the serial it sends to a TCP endpoint via WIFI (and what it receives is sent to serial).

You can program the ESP via the Arduino IDE, so you could write a 'smarter' version that did all the setup for you, etc.  In fact since the ESP8266 is a faster processor with more RAM you could do a lot more on it.

If you are using an UNO or Nano you might want to look at the software serial library to let you keep the main serial port for debug messages.  If you are using a Mega then you can use one of the secondary serial ports.


Programming ATmega2560 processor with FTDI instead of ATmega32

In fact, the basic Arduino Mega (with the ATmega 1280) utilizes an FT232RL, so yes, it will work if you connect it correctly.

It is only the newer Mega2560 (along with the similar-generation Uno, etc) which utilizes an ATmega16u2 or similar as the USB bridge.

Generally speaking, the bootloader doesn't care - you should be able to use either target chip with either USB bridge (or others).


Detect DS18B20 sensors and correctly assign them to relays

If you can easily disconnect the sensors one at a time then your way is fine.

If you can't easily disconnect them then you can maybe use readings to set the order, although this depends on the environment. If, for example, all the sensors are generally room temperature then you have the code check the temp of all the sensors at start up. If it finds one sensor at less than 0C then assign that sensor to the least-recently-replaced relay index (also stored in EEPROM).

Then when you want to put a sensor into the working set, hold an ice cube on it for a few seconds before powering up the controller. There are other combinations of this technique you can imagine that use a button or jumper wires to specifically set the index of the out-of-range-at-startup sensor.

Alternately if you have an extra pin on the Arduino, then you can make a procedure where you connect a new sensor to that pin before attaching it to the string. You can make a rule like "if you ever see a sensor on pin X then remember its device ID and assign it to relay Y". There are lots of UI ways to pick Y. Note that you do not even need any extra hardware for this.


Arduino unstable analog reading when using power supply

I solved a similar issue by adding a pin from supply to AREF and it's now stable. This fixed a frustrating pH meter issue on my Mega that every time I plugged USB in it would be right, but as soon as I dropped the USB cable it changed the readings.


ESP32 AsyncWebServer SPIFFS problem loading page

I don't have an ESP32 to test with.  Though, I tried to make your code run on an ESP8266, but it's a bit of an effort to validate what is ultimately a wild guess on my part.
And that is: perhaps you have some uppercase letters in your filename such that "/image.png" does not match perfectly and furthermore maybe SPIFFS is case sensitive.  That is, your file could be named Image.png or IMAGE.png and that might matter.
UPDATE:
In my exploring this on the ESP8266, I'd forgotten to execute SPIFFS.begin().  And I see no counterpart to it in your code.
At least one example of ESPAsyncWebServer I've seen does call SPIFFS.begin()
I found that the filenames are case sensitive, again at least on the ESP8266; so that can be a source of problems.
Also checked that if the SPIFFS size is changed through menu selections, I did indeed need to reupload the SPIFFS image.
I know these are different systems; in fact the code I'm using to test doesn't compile for ESP32, but I suspect a lot of the code is shared, and so maybe the problems are as well.


How can I analyse large packets on an Arduino?

All you need to do is analyse the packet on-the-fly using a state machine.

http://www.gammon.com.au/statemachine

You certainly don't need to hold the entire packet at once, however you do need room for the information the packet contains.

Say, for example, that the packet, although wordy, contains 4 x 32-bit numbers of interest. All you need memory for is those 4 numbers, plus a minor extra amount for the current data you are processing (eg. the current state, and the current number being assembled).

Conceptually it is like streaming a movie to your PC. The PC doesn't need to hold the whole movie, it just needs to hold the current frame, and a few seconds in advance, just to keep things running smoothly.


ESP-01 adapter and logic level converter

The module has a 3.3V voltage regulator circuit and 5v-3.3v onboard level conversion circuit.

Yes, the module can be used with Arduino UNO R3 or compatible board without needing an additional level converter, as it is integrated in the module.

The module has Vcc, GND, TX and RX, so it means it uses a serial protocol for Arduino communication (and you will need two pins in the Arduino). Other pins in the ESP-01 are not needed in this scenario, but you still have access to them via the 8-pins female connector on the module.

It's totally plug and play.

Addendum: The old way

This how you connect a standard ESP-01 with an Arduino. The module you are looking at include all the resistors and also connect the CH_PD pin to Vcc. You only need to connect four pins. It saves you time, money and space.


pulseIn() returns an unsigned long (32 bits) not an int (16 bits), so you may have some truncation occurring in your program leading to a 0 value.

Hence you should modify your program as follows:

int pulsepin = 8;
unsigned long value = 0;

void setup()
{
  pinMode(pulsepin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  value = pulseIn(pulsepin, HIGH);
  Serial.println(value);
  delay(1000);
}

Also beware that pulseIn() has a timeout (it will not wait forever).
This timeout is used for the whole completion of the pulse, i.e. first waiting for the signal to get HIGH, then waiting for it to get back LOW. If no pulse is detected and complete (LOW -> HIGH -> LOW) within this time, then pulseIn() will return 0.

Default timeout value is 1 second, but you can set any value (in microseconds) you want that can hold in an unsigned long:

e.g. if you need 10 seconds, then:

  value = pulseIn(pulsepin, HIGH, 10000000UL);

I am not sure why you use delay(1000) in your loop(), I would remove it as a pulse may occur during that time and it would not be seen by your program.

Here is a suggested update (I also used const where it made sense but that won't change program behavior):

const unsigned long PULSEIN_TIMEOUT = 10000000UL;
const int pulsepin = 8;
unsigned long value = 0;

void setup()
{
  pinMode(pulsepin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  value = pulseIn(pulsepin, HIGH, PULSEIN_TIMEOUT);
  Serial.println(value);
}

You may also want to avoid printing 0 values since they mean no pulse was detected:

void loop()
{
  value = pulseIn(pulsepin, HIGH, PULSEIN_TIMEOUT);
  if (value > 0)
    Serial.println(value);
}


Which component is described as a "jumper" (NOT jumper wire) when working with a motor shield?

It's one of these (or similar). It connects two adjacent male header pins.


Getting individual outputs from 4 load cells

For this purpose there are 'simple' interface boards like the HX711 (google on HX711). A guy named Bogde has written an Arduino library to manage this board which you can find on GitHub (https://github.com/bogde/HX711). There you can also subscribe to the corresponding email group, which is rather lively and also handles similar questions as yours.

Also Sparkfun sells these sort of interface boards and has very good and extensive documentation and tutorials on the site (see comment from VE7JRO below your question).

You can manage 4 load cells with one Arduino depending on the frequency with which you want to read them. If all 4 load cells are used to weigh one platform then Sparkfun sells an interface board to combine them in one "weight sensor" making it even more simple to interface with the Arduino.


It depends on the exact model of LCD you are using. Or more exactly, on the Dot Matrix Liquid Crystal Display Controller/Driver, like the Hitachi HD44780U that is used in many 16x2 LCD.

For that driver, you have a table of native chars, like this:

In this table, the char "°" is at col 0b1101, row 1111, (0xDF, or 223). But, you have to cast that value to a char before displaying, otherwise you will get the value (223), not the symbol.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  lcd.print("temp 27");
  lcd.print((char) 223);
  lcd.print(" ");
  lcd.print(223);

}

void loop()
{
}


How to make XBee module interrupt/wake arduino

The pin number 9 and 13 on the Xbee are DTR/RTS used for hardware handshaking. You can connect it to the interrupt pins on the Arduino and program the arduino to wake when the pulse changes. Enable the DTR/RTS feature from X-CTU and it should work. Check this for more information.


Run 5V/2.3W water pump on Arduino Pro Mini 5V

Hi Florian you can take power from USB fro both Arduino and the water pump.This is the schematic you have asked for your project. An arduino Pin can give maximum 20mA current that's why we need a limit resister to limit the current below 20mA and also this current should be such a way that it can drive the switching transistor. So the challenging thing is choosing the correct resister
I have taken the value 1K
So the current at Arduino Digital pin is Current I = 5V/1k = 5mA which is below of 20mA and sufficient to drive the Transistor. you can use BC548 transistor also.

simulate this circuit – Schematic created using CircuitLab


Arduino connection with the server failed

I don't know of this library, but you're using the connection code twice, once in the setup() and later again in the loop().

You're already checking whether the client exists:

if (client) {

Why are you asking a few lines down again to connect?

if (client.connect(server, 80)) {

My guess is, that this if()-Clause is not necessary. Or the connection in the setup() should be removed.

If this isn't the source of the error, first test whether the server on 192.168.0.11 is running and that you can connect (from a different device) to the port 80.


How to convert this prototype to finished product?

First, you should read this this question here.

The reasonable answer here varies a lot depending on how involved you want to get, and what volumes you want to sell at.

Fortunately, you're not using any breakouts with truly exotic parts. The nRF8001 is just a QFN part, which can be soldered by hand without too much trouble.

Speaking loosely, the process would look like this:

Design a PCB layout that contains everything.
(Optional) - Figure out if you want to put it in a enclosure of some sort.
(Optional) - Determine how you're going to have the enclosures produced or modified from an existing product. You can have a contract machine-shop do the work, but again, $$$$.
Send out to have PCB prototypes manufactured. I like OSHPark, but there are LOTS of options.
Assemble your boards.
Find out your prototype doesn't work.
Go back to step 1 (expect this to happen a few times)
Rent/Beg/Borrow some equipment to do EMC pre-qualification testing (for FCC).
Realize you have an EMC disaster.
Respin boards a few more times (e.g. go back to 1 again) to fix the pre-qualification EMC issues.
Feel like you have a decent layout, have it FCC tested.
Pay $10K+ for FCC testing.
If you're lucky, you passed, you now have a proper, FCC certified product.
Nope, go back to 1 again if you failed.
Do lot assembly, either manually (major time investment), or contract out (expensive!).
Sell your widget!

Note that you can contract out the prototype assembly, but doing so is expensive, even if you do it in china. The magic (or cursed, really) term here is "NRE", or non-reoccurring expenses/engineering. Colloquially, it's the "setup cost" of doing a production run. Sure, you may only pay $5-50 per-widget to have them assembled, but there will be a $1000+ base charge. This reflects the fact that the primary time-cost on the part of an assembly house to build your widget is setting up the production line, working up and debugging a pick-and-place routine, building test-setups, etc... Once everything is up and running, the actual per-unit cost is fairly marginal.

This is also why commercial electronic devices can be so cheap. They're made in truly enormous volumes, and that lets the companies amortize the NREs across the entire production run. NREs are basically the bane of any small electronics business. They're also basically the reason specialty widgets are so expensive. Places like spark-fun can get away with fairly cheap products because they have their own complete assembly line in-house, and even there, you're often paying 4X+ the cost of parts for just the IC on a PCB with a few cents worth of passives.

Since you seem to be new to PCB design, this is possibly not a great first project. It's doable, but expect it to cost 4X+ what you expect, and take 2X+ the time you planned. There are a LOT of facets to designing a proper product, and they each contain an entire field.

It'd probably be better off to start out with some simpler boards, maybe a through-hole-only arduino clone, or similar (though SOIC can be soldered without a hot-air station or anything).

Some assumptions I'm making:

If you're serious, you will have to lean SMT assembly practices. Through-hole only is not a viable stance anymore.
Expect to buy a lot of tools, and burn a lot of money in failed prototypes.
Expect 3 board revisions. At minimum, before you have something you can get tested. I could maybe do it in 2, if I got really, really lucky, but I doubt that would happen, and this sort of thing is my day-job.

Hardware is HARD, and worse, it's completely unforgiving. If you're coming from a software engineering background, you basically have to discard all your assumptions, as they will actively hurt you.

Imagine a software project where "compiling" can take 4 weeks. That's hardware development.


It is unclear to me, where you flashed what, so I will describe some basics.
The Uno cannot act as a keyboard/HID device, since the microcontroller on it (the Atmega328p) doesn't have native USB capability. For connecting to USB the Uno has a USB-to-Serial chip on it (actually another microcontroller, the Atmega32u4 I think). So with the Uno you only have a serial connection, unless you hack the Atmega32u4 and program it with your own firmware (firmware is a term for software, that runs very near to the hardware, in this case directly on the microcontroller, in contrast to normal software running on an operating system on a computer; so in the middle between hard- and software, thus firmware).
Flashing is the same as programming a microcontroller. It has this name, because the program is saved in flash memory on the microcontroller (that is a specific type of memory technology; the same technology, that USB sticks use for storing your data). Flashing the HC-06 means programming it with a different firmware.
All bluetooth devices use the same base technology (thought to be clear, BLE is a different technology). The role of the device depends on the characteristic/profile, that it exposes to the host. There are profiles for HID, Serial, Audio, ... .
The HC-06 is a bluetooth slave device, which acts as a bluetooth-serial-bridge (like the Atmega32u4 acts as a USB-serial-bridge). But this is a software limitation. The HC-06 has standard bluetooth hardware, but the firmware on it just gives you the Serial profile (in fact a HC-06 is mostly the same like the master device HC-05, just different firmware and corresponding breakout boards can break out other pins). So by flashing (programming) it with a different firmware, you can get different profiles. If you find a firmware, that gives you HID functionality, you can flash that to the HC-06 and use it. Though this is a bit hacky I think (haven't done it myself), so it might be a bit too much for a beginner.
Bluetooth Slave/Master: The bluetooth protocol uses fixed roles for the two connected devices. One is the master and one is the slave. The master controls, if the communication is really happening. For example a bluetooth headset is a slave device. You cannot connect the bluetooth headset to your bluetooth keyboard, because both are slave devices. You always need one master and one slave. The HC-05 is basically the same module as the HC-06, but it's firmware enables it do be master or slave (configurable by you). So some devices support both modes, but still in any specific connection they can only have one of the modes (need to either master OR slave at any time).

Anyone know would making that macro pad BT compatible be possible or not ?

Possible, yes. But I suggest you invest in buying a ready to use bluetooth HID controller (immediately found this one from adafruit, though you might might cheaper versions). That will be way easier, than directly jumping into flashing a HC-06. Though that is still a possible path to go.
Another way to go would be to just use the serial functionality and write a small program for your PC, which reads from the Serial interface and issues key strokes according to the serial data. Then you don't need to reflash the HC-06.


First, the Arduino Uno has 32 KB of flash, but only 1 KB of RAM. So, to be able to store the new program in a string means your new program can only be, at most, 1kb.

Secondly, only the bootloader can write to flash. So you could write a new bootloader that downloads the new program (in parts) and writes it to the flash. You would however need quite a big bootloader, leaving less space for actual code. Also the main program still needs to access the server to see if it needs to "reboot" so the bootloader can run the update process.

An example of an OTA bootloader can be found at https://www.rotwang.co.uk/projects/bootloader.html which might be a good starting point. Similar idea https://ncrmnt.org/2014/02/27/rf24boot-a-universal-over-the-air-bootloader-for-all-those-ucs/

Another option is to write the new firmware to an external EEPROM. Then your modified bootloader only has to read the new firmware from EEPROM, making it a lot simpler and smaller. There is some useful info in the question OTA updates for Arduino using nRF24L01+

MySensors.org already made such a bootloader: https://www.mysensors.org/about/bootloader

I know there exists another bootloader that does just that, but I can't seem to find it.


Arduino Uno unable to detect serial port on MAC os Mojave 10.14.2

If you are using a genuino or genuine Arduino, the most common cause of this is using a USB power only cable to connect rather than a data cable. (You only need the CH34x_Install_V1.4.pkg if you are running an Arduino clone based on that chipset)

If I ran the world, the USB standard would include some way to distinguish whether it's power only or power and data without having to test it with a multimeter. I know, I know, that's crazy talk.


Using Arduino's hardware serial to control SIM900

2.8V is not high enough to register as a high on an AVR input. You will need to use a level converter to raise the TX line of the SIM900 from 2.8V to 5V.


Adding a common activation pin to a group of buttons

You can connect all the buttons to a single interrupt pin by ORing them via diodes (like Gerben wrote in the comments). That would look like this:

simulate this circuit – Schematic created using CircuitLab
The diodes isolate each input pin from the other, but allow the buttons to pull down the interrupt pin.
Though that is not the way, that I would suggest. Instead you could simply use the PinChange interrupt. That is a different type of interrupt, which can react to all pins of a port in a single ISR for the whole port. You can mask unused pins of the port away, so that the interrupt doesn't trigger for them. Nearly every pin is usable that way.
If you want to use the Arduino framework for this, you can just use the attachInterrupt() function, which can use the PinChange interrupt in the background.
If you want to go more down into the hardware side and configure the interrupt yourself, you should look into the corresponding sections of the datasheet. The Uno uses the Atmega328p. From 12.2.4 on you see the registers used for the PinChange interrupt (aka PCINT).

With the bits in PCICR you can enable the PinChange interrupt for the ports (3 distinct interrupts for the Uno).
The PCMSKn (n meaning number between 0 and 2) is used to mask unused pins of the port away. You should set the bits for the used pins to 1, the others to zero.

Then you need to define the actual Interrupt Service Routine (ISR) in your code:
ISR (PCINTn_vect) // handle pin change interrupt for D8 to D13 here
{
    ...
}

Here again substitute the n for the number of the PinChange interrupt, that you are using. Inside the ISR you need to read all the input pins of the buttons, that are connected to this PinChange interrupt, and execute your code accordingly. Note: As the name states, the interrupt is triggered on every change of the pin. Inside the ISR you need to sort out, what change that was. It comes down to just reading the pin, but you should keep that fact in mind.
Also make sure to never do long things inside an ISR; it has to be as short as possible; Do long things inside the main code, which can get triggered via a flag variable from the ISR)
If you google for something like "Arduino pin change interrupt" you can find detailed tutorials for this, which can go way deeper, than I can on this Q&A site.

Will this also work while in CPU sleep mode from the avr/sleep.h
library?

According to Table 9-1 in Chapter "9.1 Sleep Modes" in the datasheet, the PinChange interrupts are on the same level as the External Interrupts INTn in regard of sleep modes. So this should work just like with the INTn interrupts.


Stuck in While loop when case is activated. Arduino

The problem is that calling Serial.parseInt() does not remove data from the buffer. So, Serial.available() will not decrease in your case, but increase with every input you give.
You will need to call Serial.read() and then convert the received bytes to a number.

@Majenko generally you're right, but it's okay to use a while loop in this situation. If there is data in the buffer, this data has to be handled. And as the arduino is not capable of multitasking it will need to take the required time, no matter if in the main loop or in a subfunction.


How to access 315mhz signals from household devices, with an arduino 315mhz kit?

The Short Answer:

In theory it is possible to do what you are asking.
There are examples of using an Arduino to send and receive messages at 315 MHz. Such as this example.

Although these devices might not even be compatible with the ones you are using. They may be modulating their signal differently or framing their data differently or at different baud rates or encoding bits differently or a number of other fundamental differences that would make them incompatible.

The Long Not Quite An Answer:

There is more to the problem than just being able to get bits at 315 MHz.

For one you would need to know how the bits are encoded. See some of the answers on this post.

Even if it was a simple high low stream of even width bits. You also need to know what baud rate the bits are being transmitted at so you can sync with it. (Consider 4800 vs 9600 baud, slow I know but just an example. You just got a bit stream, was it 1010 at 4800 baud or 11001100 sent at twice the speed of 9600.)

Not to mention that the lowest level of data is probably not just a stream of bits, but is probably framed in some way and grouped into a byte/bytes. Or has a leader to help lock onto the signal.

Even once you are getting reliable data you would need to know the data structure. Is the data arranged in packets? Do they have a packet header? Does the header contain these packet destination address? Where in the header is this data? How is  the data apart from the header structured? What does it mean?.

Knowing the answers to these questions defines, or is defined by, the protocol that is being used by the transmitter (as others are saying in comments.) But these are only a few simple questions that start to define a protocol. Often this information is difficult to come by. Often in the case of proprietary protocols it is very very difficult.