Programming many Arduinos simultaneously with a wireless broadcast

TL;DR -
You have the options of either BlueTooth or XBee (amongst others: IR, for example?) for wireless uploading. However, I believe that only one board can be uploaded to, at a time, so you will need to cycle through the boards one at a time, see Programming multiple ATMegas/Arduinos at once.

When uploading a sketch or using a programmer (for sketch or bootloader), the software does not just write the code, it actually communicates with the microcontroller.
You can't program them all at once. But you can program them one by one in some automatic way.

Your question is a very interesting one, and asks a question that I am sure that I would never have thought of, but would be extremely useful and labour saving, especially if one has, as I do, many Arduino controlled sensor points located around the house. Here is one rather inelegant solution that may be worth trying.
Wireless upload hardware
If you use BlueTooth to wirelessly upload your sketches, then this solution might be of use, Wireless upload program to Arduino without USB cable. Note that this solution ties up pins D0 and D1:

But be careful that it maybe not compatible with some projects which need to use the D0 and D1 as hardware UART TX, RX. Because the wireless programmer needs to permanently occupy the two pins.

Looking at it, it employs a custom Arduino Wireless Programmer, to which you may have been referring in your question. However, don't be fooled by the name, it is simply a Bluetooth shield. It is basically a BT HC-05 (or similar) device, bolted onto an Arduino, see also Bluetooth Wireless Upload.
Alternatively, en lieu of BlueTooth, you could use XBee devices, see Wireless Programming of Arduino. The advantage of using XBees is that you would not have to go through the pairing new device loop (see below), that would be required when using BT. Instead you would merely have to cycle through the XBee network IDs.
However, in addition to that, you would need to automate the switching of BT devices, selecting the appropriate port and uploading to each Arduino in turn, as you are not able to broadcast sketches. (If am I wrong, then will someone please correct me).
Selecting the port and uploading the sketch
You could use a script along with the command line version of the Arduino IDE, to select the port that the BT device is connected to, before each upload. How you do this will vary for which ever platform you are compiling upon, see Command line Arduino compiling and downloading? This can be done using the environment variable ARDUINO_COMPORT (see the possibly out of date Windows command line build), or the arduino cmd line option --port <portname> ( see the man page). The sketch would then be uploaded using the option --upload <filename>. You could do this in one fell swoop:
arduino --upload --port <portname> FILE.ino

Note that on Windows you should use arduino_debug.exe.
Or you could use Ino, if you are not using a Windows PC... but that might make the next part, which deals with the looping more complex than it needs be.
Selecting each of the Arduinos (i.e. the BT devices)
Next, you would need to add a loop to the script, that pairs the PC to each BT device in turn and thereafter calls the Arduino IDE, for the port selection and uploading. Unfortunately, this would not be platform agnostic at all, and would require a different solution for what ever platform you are using. Take a look at Bluetooth from the Command Line, but for Windows you would probably require the Blue Tooth Command Line tools suite.
On OS X you may be best off resorting to using AppleScript, see Connect to bluetooth device (iPhone) via command line on MacOSX, as the cmd line tools for controlling BT seem a little scant - there is BlueUtil, see How to control Bluetooth wireless radio from the command line? but that only appears to turn the BT on of off. However, bolting AppleScript on to the rest of the Arduino IDE control script quickly makes things more complex, although you could just put the Arduino command within the AppleScript, I guess.


Output pin low used to complete 12V LED circuit?

No, what you propose will not work. And it risks damaging your Arduino.

Normally you would include a single transistor which the Arduino uses to control the power through the LEDs. This removes the 12V from the Arduino and turns the output into an actual switch.

The problem is that the Arduino's GPIO isn't just a single transistor.  It is (amomgst other things):

Two complimentary transistors (that's the C in CMOS) for HIGH and LOW switches
ESD Diodes
Input buffer

By just adding the one transistor like this:

simulate this circuit – Schematic created using CircuitLab

the 12V is kept well away from the Arduino. Setting the output HIGH will turn on the transistor, allowing the current to flow to ground. Setting it LOW with turn it off, blocking the flow of current and switching the LEDs off.

Further: the Arduino's GPIO has a maximum sustained current of 25mA. Ideally you don't want to even come anywhere near this. By adding the transistor it acts as a buffer and allows you to deal with much higher currents - and hence more, and brighter, LEDs.

Incidentally, R1 in that schematic is there solely to keep the transistor off when the Arduino is not actively driving the output - e.g., when it's either unpowered or is running the bootloader - or you happen to have the GPIO in INPUT mode (as it defaults to).


Until the buffer is full, Serial.write is asynchronous.  You just have to avoid filling the buffer up.

Fortunately, there is the function Serial.availableForWrite() which returns the number of bytes available in the buffer. You can use that to see if there's room in the buffer for what you want to send, and if there is then send it (i.e., just placing it in the buffer).

By re-writing the UART handing to call your own interrupt routine to send a byte as and when needed you are basically doing exactly the same as the Arduino's HardwareSerial class is doing - just with your own buffer instead of the one in the HardwareSerial class.

There is no hardware buffer in the Arduino. It only has a single byte shift register for sending UART data. Any buffering has to be done in software, so either you implement that yourself, or use the existing buffering, or only ever generate and send one byte at a time, which is fairly useless.

If you really want to re-write it then all the information you need is in the datasheet for the MCU on your chosen development board.

The terms "synchronous" and "asynchronous" when applied to situations like this are better replaced with "blocking" and "non-blocking", since "synchronous" and "asynchronous" when applied to serial communications imply different styles of data transmission, not software implementation.


Arduino IDE documentation for WiFi.connected()

You'll find it defined in WifiClient.h. The version I am using is, in WifiClient.cpp:

uint8_t WiFiClient::connected() {
  if (!_client)
    return 0;
  return _client->state() == ESTABLISHED || available();
}


Any serial terminal emulator application can connect to the Arduino. Select one that has log-to-file capability and open its log file after you've connected it to your Arduino's /dev/tty... device.

Start the Arduino and let it collect & send the data to your terminal program. Close the terminal app's log file (easy step to forget - ask me how I know :) and there's your data.


Can a function be called automatically when an input changes?

You can do this using external interrupts. Most Arduinos only support this on a limited number of pins though. For full details, see the documentation on attachInterrupt().

Assuming you're using an Uno, you could do it like this:

void pinChanged()
{
    //...
}

void setup()
{
    pinMode(2, INPUT);
    attachInterrupt(0, pinChanged, CHANGE);
}

void loop()
{
}

This will call pinChanged() whenever a change is detected on external interrupt 0. On the Uno, that corresponds to GPIO pin 2. The external interrupt numbering is different on other boards, so it's important to check the relevant documentation.

There are limitations to this approach though. The custom pinChanged() function is being used as an Interrupt Service Routine (ISR). That means the rest of the code (everything in loop()) is temporarily stopped while the call is executing. In order to prevent disrupting any important timing, you should aim to make ISRs as fast as possible.

It's also important to note that no other interrupts will run during your ISR. That means anything relying on interrupts (such as the core delay() and millis() functions) may not work properly inside it.

Lastly, if your ISR needs to change any global variables in the sketch, they should usually be declared as volatile, e.g.:

volatile int someNumber;

That's important because it tells the compiler that the value could change unexpectedly, so it should be careful not to use any out-of-date copies/caches of it.


The problem here is that the variables you declare in your function are not static. The rest of the code works as expected.
Where you declare the variables at the beginning of your function is correct. There is only one variable in question though as it is the cause of the error you are seeing.
What you need to do is change the variable
unsigned long pMillis;

to
static unsigned long pMillis = 0;

By not having the pMillis as a static variable, each time the function is called the value of pMillis is undefined, which means it is unpredictable whether  (cMillis - pMillis > interval) will be true or false. But with the static declaration the Arduino knows to keep the previous value for the next time you call the function.
An excerpt from Wikipedia:

In computer programming, a static variable is a variable that has been allocated statically—whose lifetime or "extent" extends across the entire run of the program....
A static local variable is different from a local variable. It is initialized only once no matter how many times that function in which it resides is called.


It's not just the SPI what limits overall speed. You also need some proccessing power, and AVR based Arduinos lacks of it. It all depens what do you want to do with data.

If you need some serious processing power, it might be better to use something much more powerfull, like raspberry PI with real operating system. You can even run some web server at the speeds you can't even imagine with Arduino with the ethernet shield


You can use your USB/Serial adapter to program the 2560 as the Arduino uses the 16u2 as the same thing to program the mega. You shouldn't remove the 16u2, just wait till you get the programmers and reflash the 16u2 with its firmaware and it will work, I actually had the same problem where the DFU didn't work and the 16u2 stopped responding, after reflashing the firmware it worked. The firmaware can be found under(as of 1.6.0):

...\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2\MEGA-dfu_and_usbserial_combined.hex

You need to connect the Serial pins on the FTDI and Mega in the below fashion:

 FTDI           MEGA
 GND<----------->GND
 CTS<----------->GND
 VCC<----------->VCC
 TXD<----------->RX0
 RXD<----------->TX0
 RTS/DTR<---||-->RST

The Capacitor between the DTR pin and RST pin are needed this should be 100nF.

  I have bought an I |SP programmer but it will take 3 weeks to reach and no I dont have another arduino, TBH I'm scared to buy another one... –  echo_salik

If you are buying clones, those will more than likely give issues as they will be cutting back on costs in places, i.e. QC checks.


What makes a board "Arduino Compatible"?

The problem here is that "compatible" can mean so many things in different contexts and to different people.  For instance, it may mean any of the following:

Can be used with the Arduino IDE without any need for additional board installation of other modifications
Can be used with the Arduino IDE after modification (boards installed)
Uses the same (or very similar) API to the Arduino system
Has the same footprint as an existing official Arduino board
Is a device which will work with an Arduino board and has software available to operate it

All very different meanings.

Point 1 could be a board that is based on the design of an existing Arduino board (say the Uno) but built into a new form factor, maybe with additional hardware and peripherals added.  It is still treated as if it was the board the design was based on though.

Point 2 would be a board that is similar, though not the same, as an existing board.  A different board definition may be required to map the IO pins properly, for instance.  It could use a slightly different chip in the same supported family. You still use it as an Arduino, but it's not the same as an existing Arduino board.

Point 3 may mean it's based on a completely different chip.  The programming environment may be almost the same, but it's hard to get 100% API compatibility.  Arduino sketches and libraries may work out of the box, or may not.

Point 4 could be a board that, internally, is completely different to the Arduino, uses a different programming language, IDE, etc, yet the layout of the board is the same as, say, an Arduino Uno.  A good example is the Mecanique Firewing - an Uno footprint, but a PIC32 chip instead of an Atmel, and Basic instead of C++.  Most Arduino shields would just plug in and work though, software permitting.

Point 5 is from the completely opposite direction.  This is a device which "is compatible with" in that "it will work with" and Arduino.  That could be on an electrical level (it's a 5V device and will connect to the Arduino) or that it has full software support ("Download our Arduino library...").  It has nothing to do with how the device works or what it is though.

I prefer to use specific terms, respectively:

Based on the Ardino UNO
Programmable with the Arduino IDE
Compatible with the Arduino API
Footprint compatible with the Arduino UNO
Suitable for use with Arduino boards

That way it states exactly in what way this device relates to the official Arduino boards.


The RH_ASK library uses timer0, which is also used for millis and delay.

Quick workaround is to use the standard AVR delay instead.

#include <util/delay.h>

...

_delay_ms(500)


I think the question is still relevant.
You should keep the maxsonar powered from Uno power if you don't want to burn it. Even if you use 9v Battery, Arduino Uno have internal 5v regulator. So it would be safer to supply the sensor from Arduino 5V (not Vin) pin.


Carry out two consecutive tasks when a button is pressed

I assume pressing the button results in msg[0] == 111 every time you do the radio.read (i.e. it will continue sending that while the button is held).  If so, the first issue I see is that after 500ms has elapsed, you will call CandStop(), and then it will loop back and immediately call CandPush(), essentially cancelling the second state.

I think you should create a state variable and state machine, so for example it does a different operation when/while the button is pressed depending on whether it is in the 'home', 'push', or 'stop' state.  In the first ('home') state it is waiting for the button to be pressed, in the second ('push') state it is waiting for the time to elapse, and in the third ('stop') state it is only waiting for the button to be released.  It would also allow you to avoid repeatedly calling CandPush() and Home() when it only needs to be called once (when the button is pressed).

EDIT:
I am adding the code below.  This hasn't been tested so there may be some bugs but it should give an idea of what I mean.  It could probably also be optimized somewhat, but I tried to make it do what I think you wanted it to do based on the code you attached.

There are parts in there that I doubt work as you wanted, aside from the button handling, for example how Home() is called whenever there is no radio available and how nothing appears to happen when the button is released.

Should the Home() call really set B to full output?  I added a call to StopAll which I assumed you would use to stop A and B when the button is released.

Also radio.read doesn't return anything, so done = radio.read(...) is pointless.

// State machine states
enum {
    STATE_INIT,
    STATE_HOME,
    STATE_PUSH,
    STATE_STOP
};

unsigned long previousMillis;
bool buttonPressed = false;
bool radioAvailable = false;
int state = STATE_INIT;

void loop()
{
    //Check for new radio input every cycle
    if (radio.available()) {
        radio.read(msg, 1);
        buttonPressed = (bool) (msg[0] == 111);
        radioAvailable = true;
    } else {
        radioAvailable = false;
    }

    //State machine
    switch (state) {
    case STATE_INIT:
        //first cycle after boot-up, add any desired initialization
        //wait here until the first time the radio is available
        if (radioAvailable) {
            state = STATE_HOME;
        }
        break;

    case STATE_HOME:        //Wait for button to be pressed
        if (radioAvailable) {
            if (buttonPressed) {
                //button was pressed, reset timer and move to PUSH state
                previousMillis = millis();
                CandPush();
                Serial.println("STATE_PUSH");
                state = STATE_PUSH;
            }
        } else {
            //no radio input, go to HOME state
            Home();
            Serial.println("STATE_HOME");
            state = STATE_HOME;
        }
        break;

    case STATE_PUSH:        //Wait for timer to elapse
        if (millis() - previousMillis >= OnTime1) {
            //OnTime1 has elapsed, move to STOP state
            CandStop();
            Serial.println("STATE_STOP");
            state = STATE_STOP;
        }
        break;

    case STATE_STOP:        //Wait for button to be released
        if (radioAvailable) {
            if (!buttonPressed) {
                //button was released, stop all motors?
                StopAll();
                state = STATE_HOME;
            }   //else still waiting for button to be released
        } else {
            //no radio input, go to HOME state
            Home();
            Serial.println("STATE_HOME");
            state = STATE_HOME;
        }
        break;
    }
}


What boards have integrated USB charging?

The Feather mainboards are fairly small and have integrated LiPo/Li-ion charging. They're not as small at the Trinket but if you don't need the space on the proto boards then you can examine the design files to see what can be cut away.


Voice recognition without module, is it possible?

No, it's not possible. The Arduino is not powerful enough to run the algorithms needed.

You need something with far more processing power, memory and storage. Something like a Raspberry Pi, maybe, or a desktop PC.

Or just use one of the many commonly available VR modules you can buy on the internet for next to nothing.


LED and MOTOR "ON" when A BLE DEVICE APPROACH ESP32 MICROCONTROLLER DFR0575

It is generally very dangerous to drive any motor directly from a digital output pin. Motors often need way more current, than the digital pin can provide. Based on the answer to this question, an ESP8266 can provide 20mA or 12mA depending on current direction (may be a bit different for an ESP32, but not substantially). Drawing more current, than the pin can provide, can lead to the destruction of the output hardware of the pin. It is not easy to say, when this will happen, because it depends not only on the current draw, but also on time and fabrication variation.

Also a motor is an inductive load, which means, that fast changes (for example turning on and off) will induce a reverse voltage in the motor coils. These can easily be very high relative to the supply voltage and thus destroy you output pin or even the complete microcontroller.

I cannot give you a full reasoning, why it works with the first board, but not with the second. I think, it has to do with the above.

You should always do 2 things, when driving motors with a microcontroller:

Use a motor driver circuit: You can either buy a ready to use motor driver or you can build one yourself. If you only want to turn the motor in one direction (as with a vibration motor), all you need is a MOSFET, which will act as a switch between the motor and the power supply. This switch get's controlled by the Arduino's output pin (which only needs to supply a very low current for switching). You can google "MOSFET as a switch". Be sure to use a MOSFET, that can provide the needed current and that is good in saturation for the used gate voltage (the working voltage of the microcontroller).
Use a flyback diode: The reverse induction voltage can also hurt MOSFETs. You want to let these voltage spikes quickly plenish by letting the current flow to ground. You can do this with a flyback diode. That is a diode, that bridges drain and source of the MOSFET. It is oriented so that block for normal operation (the normal positive supply voltage). When the MOSFET get's turned off, a great negative voltage will build up in the motor, but since the diode is conducting in this way, the voltage will safely flow to ground, so that the induction voltage cannot hurt the other electronic parts.


avrdude: stk500_recv(): programmer is not responding after all tries

It eventually worked by using upload / ctrl+U (what I didn't try... smh) instead of  upload using programmer / ctrl+shift+U.

So i know now where it comes from, though I don't know what's wrong with AVR ISP.


unable to install usbserial driver for GPRS shield with mac air vs. 10.9

The USB serial connection is provided by the Arduino, not the shield, and the naming pattern for an Uno on OSX will not be tty.usbserial### but rather something else (tty.usbmodem### perhaps?).

If I recall correctly, an Uno does not require a driver on OSX though older/unofficial FTDI based boards (as well as unofficial boards based on yet other fixed function chips) do require drivers.

(On Linux it is typically /dev/ttyUSB# for fixed function and /dev/ttyACM# for an Uno, both using kernel module drivers shipped with most distributions.  On Windows they are all COM# and drivers are typically required)


I have no opinion about this hardware (I don't own it) so please treat my answer as information only. When I was searching through web I found M5Stack

It looks like hardware made for IoT development.
It has a LCD and 3 buttons and think it can be programmed using ArduinoIDE.
It's designed that you can design any hardware you want and "stack" the device on top of it. Found if available to buy from China for below 30USD.

https://www.youtube.com/watch?v=U2es-l4z2Zg


You can use an Arduino Yun: it has a 32u4 microcontroller coupled with a cpu running linux. The linux side already has a webserver: together with the Bridge library, you can use REST-like APIs to control a sketch, or build a web app that uses that APIs.

One example of remotely control an Arduino (although using an Android app instead of html+js) is this. Here is its source code.


Which sensor i can use to transmit some values from Arduino Uno to phone using bluetooth?

It's not a sensor, its a module. A quite popular module is the HC-05. It's a very simple to use module with a lot of support by the community. Cheap and great for projects.


What do I do about a compiler error " variable 'font' must be const"

The problem is you're using an old version of the Adafruit GFX Library, which was written for a previous version of the Arduino IDE. You just need to install the latest version of the library and your problem will be solved:

Download https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip
Unzip the downloaded file.
Rename the unzipped folder Adafruit_GFX
Replace /home/Harry/Arduino/libraries/Adafruit_GFX with the folder.

If you run into any other problems after doing that I recommend trying the latest version of the Arduino IDE. The version you're using is very outdated.


Operating AD5780 EVAL Board Via MicroController

Where in the drivers am I performing Slave Select and where am I determining Clock Speed? I have looked through the C in the drivers library, and it seems that each command, whether reading or writing selects the Slave/Master each time? I see no reference to which pins on my microcontroller it is reference though so I do not know if any of this is right.

The slave select is controlled within the SPI_Write() function.  It uses the PinMgt_PinWrite() function to do the slave select control, which in turn selects a pin from the pinMapping[] lookup table.

The clock speed is set in AD5780_Init().

  Why do I need to be reading in the Control Register or anything from the DAC at all? Why does this matter? All I want is to output a voltage

You don't. The code is just for demonstration purposes. It shows you how you could query those registers. If you don't need to, then don't.

  How do I perform the right conversion to a voltage that I want? The command " AD57XX_SetDacValue() " takes a long, but I do not understand how that relates to a float value of voltage. Say I want 2.35 Volts, or a Sine Function from -2 to 2 Volts, how do I do this conversion?

That value is the raw value to set the DAC to. You refer to the DAC datasheet to know what that value equates to.  In this case the range is from \$V_{REFN}\$ to \$V_{REFP}\$.  Divide that range by 218 and you have the voltage per bit.

  I don't know how to debug the system in general. When I run the example code, which is supposed to output a triangle wave function, I get a sin function, which seems to just be noise.

You need some debugging tools. Things like a logic analyser to be able to acually see what the IO pins of your MCU are doing.  An oscilloscope can be used to see if a signal is present, but to see all the SPI signals together you really want a logic analyser.


How would I establish a serial connection with python without using the serial monitor?

This question is about Python not Arduino... Before asking here please ask GOOGLE

Anyway...

This is the answer Arduino and Python

Python code:

## import the serial library
import serial

## Boolean variable that will represent
## whether or not the arduino is connected
connected = False

## open the serial port that your ardiono
## is connected to.
ser = serial.Serial("COM11", 9600)

## loop until the arduino tells us it is ready
while not connected:
    serin = ser.read()
    connected = True

## Tell the arduino to blink!
ser.write("1")

## Wait until the arduino tells us it
## is finished blinking
while ser.read() == '1':
    ser.read()

## close the port and end the program
ser.close()

Arduino code:

// Open a serial connection and flash LED when input is received

void setup(){
  // Open serial connection.
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  Serial.write('1');
}

void loop(){
  if(Serial.available() > 0){      // if data present, blink
    digitalWrite(13, HIGH);
    delay(500);
    digitalWrite(13, LOW);
    delay(500);
    digitalWrite(13, HIGH);
    delay(500);
    digitalWrite(13, LOW);
    Serial.write('0');
  }
}


There's two aspects to what you want to do - one (relatively) easy, and one (comparatively) hard.

The first thing you will need is some way of getting your program into RAM. That would mean some software running on the chip that will accept the program and place it into RAM then execute it. You will have to write your own bootloader-like program that runs in Flash that will perform the task.

The second, harder, thing is to compile your program in such a way that it will execute from RAM. And that's no easy task.

Ideally you want to compile the code as position independent code (with the command line flag -fPIC), but that depends on the compiler being able to do that for this chip. If not, you will have to compile it so that the code expects to reside in RAM with all addresses used for jumps, etc, going to the right location. And that brings me to the second aspect of compiling, the linker script.

If you have your code in RAM you can't also have your variables in the same place in RAM. You will have to subdivide the RAM into two sections - the code execution section and the variable storage section. This is done through the construction of a custom linker script which is used during the linking phase of compilation. It tells the compiler where in memory to place everything - code, variables, etc. You will need to craft your own linker script to divide the RAM up in a suitable manner to give you enough room for your code while at the same time not starving it of variable storage space. This will also make sure all jumps, etc, in your code use the right addresses in case you can't (or don't want to) use -fPIC.

So, given all that, do you still really want to execute code from RAM?


I don't know how this lib works. But I'm pretty sure that you have to pass a pointer onto the data variable into the twi_readFrom method.

uint8_t mcp23017_read( uint8_t add_reg )
{
    uint8_t data;
    twi_writeTo( MCP23017_ADD, add_reg, 2, 1, 0 );
    // I inserted an & below
    twi_readFrom( MCP23017_ADD, &data, 1, 1 );

    return data;
}

Or in case of the second function:

// I removed the star operator
uint8_t mcp23017_read(uint8_t add_reg)
{
    uint8_t data[1];

    twi_writeTo( MCP23017_ADD, add_reg, 2, 1, 0 );
    // you pass the pointer to the array element 0
    twi_readFrom( MCP23017_ADD, data, 1, 1 );

    // I returned the element 0
    return data[0];
}

Update:

Just for completeness: The OP found also a failure on the write function. He had posted a separate answer, I voted up to mark it. Because this is the accepted answer, I also copied his post to here for completeness and the readers convenience.

Original post by R1S8K:

  OK, I found a the answer and it was a good lesson in dealing with
  functions that receives pointers.

  I forgot that the writeTo function also receives a pointer and I have
  to pass an array for both read/write functions.

void mcp23017_read(uint8_t *add_reg, uint8_t *buffer){
    twi_writeTo(MCP23017_ADD, add_reg, 1, 1, 1);
    twi_readFrom(MCP23017_ADD, buffer, 1, 1);
}


Arduino uno + XBee Shield Not transmitting when under battery power?

Using a multimeter you can confirm your theory by looking for a voltage drop on the power connections to the XBee and into the UNO.

9V batteries don't store much charge, nominally 563mAh according to wikipedia. It is possible that the fairly new batteries are not that new after all.

Depending on the XBee, power consumption varies. 40mA for a normal XBee (ZigBee), 200mA for pro, and 309mA when transmitting for the new XBee WiFi. If the battery is low, the high current draw plus internal battery resistance may drop the 9V output to below the 7V needed for the UNO's voltage regulator to function correctly.


3 AC current sensors using one Arduino Uno board measuring at 200Hz

Is the sampling speed enough?

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

Ref.: https://www.arduino.cc/en/Reference/AnalogRead

Is the USB port fast enough?

The serial speed over USB is maximum 2Mbps and a fast calculation (200 samples/s x 3 sensors x 10 bit) 18kbps, so 2Mbps should be enough.


There's plenty of options on ebay, you will have to add a DC motor driver and optionally, sensors, but these are a good starting point.


Even with an external supply, you must still have a common ground reference between the ATmega being programmed, and the Arduino/ATmega doing the programming.  According to your comment this was the critical issue.

Also keep in mind that the specifications of most ICs including the ATmega prohibit applying signal voltages when the chip itself is unpowered.  To stay within that specification, you would need to turn on the external supply first, and insure that all of the pins were in their high impedance state and not driving the programmer's ATmega when it is unpowered.

Your pullup resistor on the target's reset would weakly drive pin 10 on the programmer, but a 10K resistor should limit the current to within what the protection diode on the corresponding ATmega pin can tolerate (even such a weak current can however cause problems with clean startup, though the ATmega is less sensitive than some other devices).

If you can't be sure power is going to be applied correctly, putting 1K (maybe even 2.2K) series resistors between the two chips can help a little, but there's a balance between keeping the signals strong enough to work well, and keeping illicit currents weak enough to avoid stress.


Is it possible to setup a CAN-BUS Arduino Shield to communicate with SocketCAN for UNIX?

Yes. Normally you would write a linux kernel driver to communicate with your device (arduino) following your own protocol, but SocketCAN provides by default a way to interface with Lawicel dongles, whose communication protocol is publicly available: CANUSB / CAN232 protocol.

Many people have built arduino sketches that implement this protocol so you can use your arduino with SocketCAN in Linux (candump, cansniff...) as if it were a Lawicel dongle.

You may find this useful:

https://github.com/autowp/arduino-canhacker

https://github.com/kahiroka/slcanuino


How do I use two PulseIn() functions simultaneously in Arduino?

You can't use pulseIn() if you want to use both ultrasonic sensors at the same time.

So either:

don't use pulseIn, and instead do that part yourself using
eg. digitalRead,
use the ultrasonic sensors sequentially, one then the other, or
use pin-change interrupts to sense the signal pulse return.

The easiest approach is to use the ultrasonic sensors sequentially. In that case use the form pulseIn(PIN, value, timeout);, where timeout, in microseconds sets the maximum time to wait for a pulse.

This is practical if you know the realistic range is within a couple of metres. The speed of sound is 343.2 metres per second, or 0.3432 metres per millisecond. So if timeout is set to 3000 microseconds (3 milliseconds), then it will wait for an echo up to (roughly) 0.5 metres away.

Edit:  The distance to the object, measured by timing the delay, is half the total distance travelled because the sound travels to the object, then bounces back to the sensor.
Ie. distance to object = total distance travelled by sound / 2

An alternative is to do what pulseIn does, but for more than one pin.
This is simpler than the real pulseIn code, but illustrates the idea:

int inPin1 = ...;
int inPin2 = ...;

void setup() {
  // ... other stuff, then set up the pins
  pinMode(inPin1, INPUT);
  pinMode(inPin2, INPUT);
}

void loop() {
  // start ultrasound 1
  // start ultrasound 2
  // wait for ultrasound 1 to send pulse
  // wait for ultrasound 1 to send pulse
  long startTime = micros();
  while (digitalRead(inPin1)==LOW && digitalRead(inPin1)==LOW) {
    ; // do nothing
  }

  long stop1st = micros();
  int firstBack = -1;
  while (digitalRead(inPin2)==LOW) { // wait for the other if it was 1 first
    firstBack = inPin1; // remember pin 1 returned first
  }
  while (digitalRead(inPin1)==LOW) { // wait for the other if it was 2 first
    firstBack = inPin2; // remember pin 2 returned first
  }
  long stop2nd = micros();

  // now have the two return times, and the pin which returned first
}

You could read the source of pulseIn() and write better code than this.

The third option, to use external or pin-change interrupts, depends on which Arduino you are using. A normal ATmega328 has a couple of pins, 2 and 3, which have their own 'external' interrupt service routines (ie. each pin has a 'function' which is called when the hardware detects a signal change on a pin). To see how to attach them, see attachInterrupt.

Other pins can also be used with a 'pin change' interrupt, but each interrupt has to figure out which of a port (up to 8 pins) has triggered it, so it isn't as quick and simple.

The idea here is to start the ultrasonic sensors exactly as before, save the time they are started, exactly as before, but let a short interrupt routine capture the time that the returning echo pulse triggers the pin.

There is a little bit of care in making sure the times are captured and the main loop signalled.

You might choose to dedicate a timer to measuring the ultrasounds round trip, if you want higher resolution and lower jitter than the normal 4 microsecond timer. A microsecond is about 0.34mm, so 4 microsecond is about 1.3mm error.


Unable to connect Arduino Uno to Ubuntu 16.04

You may have to add yourself to the dialout group in Ubuntu so that your user account can access the serial ports.

Then, in the Arduino IDE, the Tools->Port menu should show you options. Right now, the screenshot you gave shows that it's set for COM1, which is a Windows-style serial port naming and definitely won't work on Ubuntu.


Arduino Mega reading from external sensor Issue

the RX1 or Arduino mega to the TX1 of the sensor (pin2) and

That will not work. These pins are for RS232, which uses the same communication protocol (UART) as the Arduino, but it uses different voltage levels. But fortunately your sensor has also RX and TX pins at TTL level (Transistor-Transistor-Logic). You want to connect these to the Arduino.
One thing to keep in mind: The sensor logic seems to work at 3.3V (voltage on the RX and TX lines). If you also want to send data to the sensor, you may need to step down the 5V of the Uno to the 3.3V of the sensor on its RX line (since 5V might damage the sensor). You can use a simple voltage divider with 2 resistors or a proper level shifter (which uses transistors) (voltage dividers limit the communication speed, though 115200baud should not be a problem).


How to use -F option while Burn bootloader for ATtiny 85 using Arduino IDE

For what I know there is no easy way to pass custom options to avrdude via the Arduino IDE, but Sloeber (to which I'm a contributor) does.

Beware though, the -F option of avrdude command doesn't solve the problem, just forces to skip the device signature verification, but if your Attiny is returning such signature something else is wrong and you'll end up with a failed firmware upload anyway.

If the device was working and suddenly stopped it's more than probably a wiring issue, as already suggested in the comments. The second most probable cause, in my experience, would be a hardware issue: you might have accumulated some static charge and then touched the Attiny or any wire connected to it, destroying one of the ISP pins...

My bet is on the former: my experience with the latter is you get changing signatures in the form of 0xFFFF00, 0x0000FF and 0xFFFFFF but, luckily for me, this didn't occur so often to accumulate a true knowledge.


Schematic interpretation, where to put resister?

Neither are shown in that schematic, as described in the text.

Calibration Circuit: The weight calibration circuit is shown in figure 2. [...]
[A schematic that includes a 4.7kohm resistor]

...

Note: Cathode and Anode pin of LCD (pin 15 and pin 16) is not shown in circuit diagram. Connect +5 volt to pin 15 with current limiting resistor (generally 100-ohm) and pin 16 of LCD to ground.


As @timemage stated, strcmp returns 0 for equal. Sincerely in the provided code, while you send a message, which contents are not COMMAND, the LED will be turned on.
To get what we need, we must compare strcmp return value with 0! If it equals, then the strings match, and your suggested code is being executed:
void stringCallback(char *myString)
{
  if (strcmp(myString, "COMMAND") == 0) {
    digitalWrite(13, HIGH);
  }
  Firmata.sendString(myString);
}


This can be done with the existing board. LCD can be driven by only with the digital pins. Check the below link for the wiring diagram.

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

Since there are 6 Analog pins available, all flex sensors can be easily connected.


Do I need more voltage to close this circuit?

The Trinket really doesn't want to see 15v across one of its I/O pins. You'll do better using a solid-state (SSR) or mechanical relay to close the 15v motor-start circuit, one that can be activated by the 5v output of the Arduino pin.

Update:
A relay has 4 specs that you need to consider up front:

The coil (or switching input of a SSR) voltage, and
The coil (or switching input) current;

These are what the Arduino or an add-on switching circuit will have to drive. And:

The contact max voltage, to limit arcing when they open
the contact max current, to limit them heating,

Or, in the case of an SSR, to prevent letting out the Magic Smoke that makes them work.

If you use a relay you'll need a driver circuit between the Arduino pin and the relay, with a snubber - a diode that grounds the reverse voltage "kickback" from the relay coil when you open its circuit - also to protect the Magic Smoke in your Arduino.

You're hacking into your remote "clicker", not the garage-door tractor itself, right? If that's the case, just about anything with a 5v coil 15v+ contacts will do. The remote button only has to switch a tiny transmitter on/off. If you do need to hack into the tractor, you'll want to find out what's behind its receiver terminal. It's probably not the motor but another relay, but....

A ready source of such a relay is your/another garage door remote receiver. It has a relay in it that is already doing that job.


I'll release a new WiFiManager_Generic_Lite, with functionality similar to WiFiManager_NINA_Lite, to provide support specifically to MKR1000 using WiFi101, as well as other generic boards (nRF52, SAMD, SAM-DUE, STM32, Teensy, AVR, etc.) using generic WiFi Shields (AT-command, WiFiNINA, etc.) within several days.
Please hold on,

The new library has just been released : WiFiManager_Generic_Lite in GitHub as well as Platform.io WiFiManager_Generic_Lite in PIO.
The following 2 examples are created specially for you to use and test

MKR1000_WiFi101
MKR1000_WiFi101_MQTT

Please test and post your feedback here. Post issues, certainly many with this new library, on WiFiManager_Generic_Lite issues
Cheers,


ttyACM0 no such file or directory On Ubunutu 14.04

Ok, it sounds like there is an issue with the ATMega(8/16)U2 chip or its surroundings.  It might just need its firmware refreshing (which can be done with another Arduino as a programmer) or it might be plain dead.

Another possibility is the USB socket itself.  I have two UNOs, one which is perfectly fine, and one where I need to hold the cable at just the right angle for it to connect properly.  You can try using a fine needle to try and raise the four metal strips in the USB connector a fraction to make better contact.


Program to run two motors with Motor driver

check this one

void loop()
{
  // turn on motor A
  digitalWrite(In1, HIGH);
  digitalWrite(In2, LOW);
  // set speed to 150 out 255
  analogWrite(EnA, 150);
  // turn on motor B
  digitalWrite(In3, HIGH);
  digitalWrite(In4, LOW);
  // set speed to 150 out 255
  analogWrite(EnB, 150);
  delay(2000);
   digitalWrite(In1, LOW);
  digitalWrite(In2, HIGH);
   digitalWrite(In3,LOW);
  digitalWrite(In4, HIGH);
  // now turn off motors
  delay(5000);
  digitalWrite(In1, LOW);
  digitalWrite(In2, LOW);
  digitalWrite(In3, LOW);
  digitalWrite(In4, LOW);
  delay(2000);
}


How to use AT+CFTRANTX command in SIM7100

When having trouble in getting started with a modem, it's usually best to connect to the modem in "interactive mode", to verify that you're sending the right commands and getting the right responses.

Have you made sure that your modem/module's UART is at the right logic level to interface directly with your Pro Mini? How about the supply voltage? (Post a link to the product). If you're done with all that, then connect only the modem to the Pro Mini:

5V/3.3V -> Vcc (depending on the module's supply voltage)
D6 -> Modem TX
D7 -> Modem RX
Gnd -> Gnd

Then, upload the following to your Pro Mini:

#include <SoftwareSerial.h>

SoftwareSerial fserial(6, 7);

void setup(void)
{
    Serial.begin(57600);
    // I assume this is the default for your modem
    fserial.begin(115200);
    Serial.println("Starting.");
}

void loop(void)
{
    while (fserial.available())
        Serial.write(fserial.read());
    while (Serial.available())
        fserial.write(Serial.read());
}

This should basically transfer everything you send from your Serial Monitor to the modem, and in the reverse, transfer everything the modem sends to your Serial Monitor.

After uploading the sketch, in the Serial Monitor, set the Line Ending at the bottom to Carriage Return. Then you can first send the simple AT and should receive OK from the modem, to confirm that your setup works. Then to test your file reading code, send your command AT+CFTRANTX="c:/data.txt" and see what you get.

If you can confirm this works, writing code to do this automatically should then be much clearer. Or at the very least, you'll have ruled out a whole bunch of possible problems.

(Note: the Arduino may not work reliably with 115200 baud on Software Serial. So you may want to change the modem's baud rate quickly with AT+IPREX=9600. And then modify your sketch accordingly and re-upload.)


Increasing stability will increase the (usable) range. At least a bit. You could try decreasing the packet size, to make it even more reliable. There is no way to increase the output-power (only decrease).

You could try different channels, and see which one gives you the best range in your application.

After that you have to get NRF24 modules, with external antennas and amplifiers.


Has anyone used an Arduino to transfer software to an Apple IIe?

You need to adapt the levels. Arduino Due operates on 0 - 3.3 V. Apple IIe is either on 0 - 5 V or +/- 12 V (depends which port you are using). There are standard ICs to do the level adaptation.


Try this:

First: you must find the COMx used for your "Arduino Leonardo" in the "Device Manager" of Windows.

Second: make double click to see the properties of the device, and go to the "Port configuration tab"

Third: enter in "Avanced Options" and deactivate "Use FIFO buffers", and accept all changes.


Second item in array not gets assigned from struct object, ArduinoJson

ArduinoJson stores strings differently depending on their types:

for const char*, it saves a pointer;
for other types (char*, String...) it copies the string.

Because ArduinoJson stores the copy of the string in the JsonDocument, you must increase the capacity of the JsonDocument.

In your case, you pass Peripheral::current_state, which is a String, so ArduinoJson makes a copy in the JsonDocument. Increasing capacity by a few bytes should solve the problem.

Note that the ArduinoJson Assistant also computes the number of bytes required to store all the strings. Look for "Additional bytes for strings duplication" on the right panel.


I have a NodeMCU Esp8266 v3 (Lolin) and it works fine conecting Vin and G to my cell phone power supply rated 5.1V, 1000mA. This develop board has a aprotective diode (the closest to Vin), if you have a Multimeter o multitester you can check it measurement continuity. If your diode is damaged the power applied to Vin never be enough to power up the nodemcu.


Why my arduino board does not blink properly?

There are a couple of issues here.
One of them has already been raised in a comment:

 int main()
 {
-    ddrB = (port_type) 0x20;
+    *ddrB = (int8_t) 0x20;

     while(true)
     {

The more serious issue is in the command line you used to compile the
program. When compiling for an Uno, you should add the option
-mmcu=atmega328p. This way the compiler knows which version of the C
runtime it should add to your program. Otherwise the compiler will
include no runtime at all.
The C runtime does some important initializations. For example, it
clears the register r1, which is required by the ABI, and assumed
to be the case by the compiler. For example, when you write *portB = (int8_t) 0x00;, the compiler copies r1 to the port, without first
clearing it. Another important role of the C runtime is to call
main(). Without it, the program will start by executing whichever
function happens to be at the start of the flash. Unless you program in
assembly, you have no control over that. If the first function happens
to be main(), the program may work as expected. If it is another
function, that function may then return to the bootloader. Any seemingly
innocuous change in the program can then change the behavior.
Then a few minor issues, that should not prevent the program from
working:

int8_t is meant to be a signed type. If you want the unsigned
version, use uint8_t instead. Sure, these are your own type
definitions, but creating a type that conflicts with a standard type
can only create confusion. Best option is to drop the definition and
include <stdint.h> instead.

Whereas port_type should certainly be a “pointer to volatile” data,
there is no point in making the pointer itself volatile. That can only
hinder valid optimizations.

portB and ddrB should be const, and that may allow the compiler
to better optimize them. But why not use PORTB and DDRB from
<avr/io.h>?


Can Ultimate GPS module use arduino micro instead of UNO?

Your photo shows the GPS connected to pins 0 and 1 (RX and TX) on the UNO.  But you don't show the sketch you are running.  Do you have it set that way in the sketch?

It turns out the micro and UNO are different in the way those pins work.  From http://arduino.cc/en/Main/arduinoBoardMicro

  Serial: 0 (RX) and 1 (TX).  Used to receive (RX) and transmit (TX) TTL
  serial data using the ATmega32U4 hardware serial capability. Note that
  on the Micro, the Serial class refers to USB (CDC) communication; for
  TTL serial on pins 0 and 1, use the Serial1 class.

This suggests to me that you'd need to change the code to read pins 0 and 1.

Easier is probably to wire it up to pins 2 and 3 and use the defaults in the sketch

// If using software serial, keep this line enabled
// (you can change the pin numbers to match your wiring):
SoftwareSerial mySerial(3, 2);


Connecting an arbitrary number of pins to pin holes without soldering?

As you already have seen, there are not many options to contact such boards without soldering, because they are meant to be soldered. Those hammer headers are an option. When you find a seller for your country, it should also have these in different sizes/numbers of pins.
Though contacting the board with the pins is not the only problem, you may face. As long as you are experimenting, the typical breadboard is often enough. But when you want to make something more permanent, reliable, current thirsty or noise sensitive, a breadboard is a bad choice. In that case you would also need to solder. Soldering is just a very integral part of electronics.

As others have wrote in the comments, I would also consider soldering as a hobbyist as safe, especially, when you take some precautions. A "well ventilated area" can be a simple room with the window open and a small fan directed to the working place, so that the fumes don't directly go up your nose. That is already a very big improvement, which is also rather cheap. That's also about what the woman does in the video, that you linked. And washing your hands after soldering is also a good measure. (I'm doing soldering the described way for about 15 years now, without any health issues)
In the video, that you linked, they say, that the fumes are toxic and their effect adds up. Letting aside, that they don't back it up with any data and I cannot either, they also don't talk about the amount of solder work, that they consider here. As an electronics beginner you most likely will just solder very rarely for getting pin headers on boards or maybe contacting a motor. The main work most likely will still be done on the breadboard. So here the exposure is so small, that you don't need to consider more than the above safety measures. These will also last rather long, as you get more profound in electronics. And when keeping up that hobby, you maybe wanna invest in a more professional filter system, as you are doing more solder work.
Doing electronics while being that scared of soldering will not be much fun. For the start you might get away by only buying presoldered boards. But very fast you will run against walls with this. Not a good start for a beginner.
But in the end it's your own decision. You have all right to be afraid of solder fumes, though that just might disqualify electronics as a hobby for you.

if I installed hammer pin headers (seems like one has to hit it with an actual hammer to install it), can I un-install (remove) the headers?

That depends on the pin headers, but most likely no. You would need physical force to get them off. And the pads on a PCB are not very strong. They are made to be soldered, not for tearing the pins off without any damage. But why would you want to remove the headers? You only very rarely solder wires directly to the board for connecting with other parts. Either you solder it onto another PCB (where the pin headers come in handy), or you use a female header on a PCB or a cable for making the connection temporary. For example all my small Arduinos get pin headers soldered to them, so I can put them onto my own PCBs via female headers on the PCB. With that I can also disconnect or replace the Arduino if I need to.


How many modules can an Arduino Nano v3 support (in code)?

The devices will require some code to make them work and there is a chance, depending on how you write the code, that this may consume all the available RAM on the chip.  However I doubt you will go to more than 60% if you use the standard libraries for those devices, but there is only one way to find out...

Get the libraries for the devices and look at the examples for each device.  You should be able to hack an "example" of your own that calls all 4 examples in the main loop().  This should give you an idea of how much memory you are going to use.

If you use too much it might be possible to snip pieces away from the libraries, the LCD will probably have font tables that you don't need for instance.  Or you could use an alternative Arduino.


Merge two 8 bit arrays to one 16 bit array

It's better to avoid dynamic memory allocation on an Arduino, with only 2 KB of SRAM memory.

Note that your arrays cost 2 (bytes/int) * (8 + 8 + 16) = 64 bytes.
And it seems you are only storing booleans, which could be stored in one bit. So consider another alternative (I will not work that out, since maybe memory consumption is not a problem).

However, an easy solution is to use uint8_t.

Also, I would use a simple memcpy. Very naively it would look like:

uint8_t summand_one[8];
uint8_t summand_two[8];
uint8_t summand[16];

void setup()
{
}

void loop()
{
  memcpy(summand, summand_one, 8);
  memcpy(summand + 8, summand_two, 8);
}

Using some constants for the sizes, you get more flexible/readable and maintainable code:

static const uint8_t SummandOneSize = 8;
static const uint8_t SummandTwoSize = 8;

uint8_t summand_one   [SummandOneSize];
uint8_t summand_two   [SummandTwoSize];
uint8_t summand_merged[SummandOneSize + SummandTwoSize];

void setup()
{
}

void loop()
{
  memcpy(summand_merged                 , summand_one, SummandOneSize);
  memcpy(summand_merged + SummandOneSize, summand_two, SummandTwoSize);
}


How to read analog pins from a second Arduino

Yes that is possible, you can even use as many Arduino's as you want and send the information to one 'master' Arduino to process the data.

What you need is a way to communicate between them. Depending on distance, speed and reliability, you can chose for Serial, I2C, SPI or more 'exotic' solutions like CAN(bus), RS485 or even wireless methods (with nRF modules).

Some have a simple protocol, for others you might have to make it yourself.

Also think of the processing, you want to do the processing on the main device, or to process as much as possible on the 'slave' Arduinos and send it to the main device.

(Btw, I talk about Master/Slaves), these are not official terms, but meant as example. For example, with CAN, you can send message from any Arduino to any other. With Serial, you can send from 1 Arduino to 1 other.

If you have 2 Arduino's, probably Serial is the easiest.


It can take a while to register - sometimes several minutes. Have you left it after power-up for enough time?
If your operator has no signal in your area it will never register. National roaming is normally disabled. If you have national roaming available you will have to manually connect to another operator.
Check that your modem can see your operator with AT+COPS=?


ATmega328P - Problem using timer 2 for tone generation

I tried the code on an Uno and as you say, it does sound odd.

By my calculations, the frequency is 40kHz (16MHz/(200 x 2)), which is above the threshold of hearing. The sound we are actually hearing is probably the 3rd or 5th harmonic, at a reduced intensity and perhaps subject to jitter.

I tried changing

TCCR2B = _BV(CS20);   // clk/1

to

TCCR2B = _BV(CS21);   // clk/8

which should mean that the frequency is now 5kHz (16MHz/8/(200 x 2)).

It sounds cleaner.


Your code has a number of problems:

Don't put #include statements for header files in the middle of your code. They belong at the top, before any other code. (What is the header file elapsedMillis.h?)

Another thing: Your for loop is a mess. It should read something like: for (int i = 0; i < 20; i++) (That would cause the for loop to run 20 times, with the value of i ranging from 0 to 19.) However, what do you want to happen in your for loop? Without braces after that code, the ONLY line that will execute 20 times is the int BPM = BPM + 10; line (which doesn't make any sense.)

You really shouldn't use time-based while loops inside your main loop function. That defeats the purpose of using timers instead of delay statements. And you should get rid of your calls to delay() and use millis() to manage all your timing. Do a search on "Arduino blink no delay" and study the examples for information on how to restructure your code.


Good book/reference for AVR coding in pure C/C++?

First, let's make this clear: The Arduino environment does not provide a
“simplified language”: it provides a simple hardware abstraction layer
through its core library. The language is plain C++.

Like Talk2, I don't have good book recommendations. The basics of
low-level programming are covered in the Arduino tutorial on port
manipulation[]. Past this you will have to dig into the datasheet of
your MCU. Look also at the doc of the avr-libc and the tutorials in
Nick Gammon's microprocessors pages.

I would suggest you try to develop your program like this:

Do the initial prototype of your idea on an Arduino Uno (or similar)
using the Arduino libraries. It just makes things easier, and you are
more likely to get a working prototype pretty fast.
Once the initial idea works, optimize it for the limited resources of
the ATtiny85. This may involve replacing some call to the Arduino
libs with avr-libc and/or direct port access.
You may then want to remove all references to Arduino core, but you
don't have to: there are some ATtiny cores available that you can use
if you want.
If it now fits in less than 8 K, port to the ATtiny.

The thing I love about the Arduino environment is that you can very
easily mix and match abstraction levels: you can have, in the same
program, calls to Arduino core, to avr-libc, direct port access, and
even inline assembly if want to. You don't even need to stick to the
setup() and loop() method: you can write your own main() if you
prefer, just remember to call init() to initialize the Arduino core if
you are going to use it. Oh, and you don't have to use the Arduino IDE
either if you don't like it (I don't).

As for the optimization tips, I would recommend :

Use direct port access instead of digitalRead(), because that
function is pretty big and slow.
analogRead() may not be that bad, size wise, but it has a serious
shortcoming: it's a blocking function which spends 104 µs in a
spin loop, just waiting for the ADC result. If your CPU has better
things to do, you may want to implement a non-blocking read instead.
For debugging output, the most efficient option is likely to be the
USI port. You will have to search for a driver or implement your own
based on the Atmel application note AVR307: Half Duplex UART Using
the USI Module. Alternatively, you could use something like
AltSoftSerial. Do not use SoftwareSerial: it blocks interrupts for
insanely long amounts of time.
Use the command avr-nm --size-sort -Crtd my_program.elf to get a
listing of the functions of your program sorted by flash usage. This
will help you choose good targets for size optimization.


Is there any way to detect MIDI messages that does not require the additional circuit and just uses the USB cable?

You could probably do it with a "USB Host Shield", though I have no experience of them and don't know if they can handle MIDI - you'll have to research this.

  Although in theory control of the LEDs should be easy in the program, I am concerned that the delays in the serial communication and hardware interrupts would make it difficult to simultaneously receive the MIDI messages and control the LEDs.

Highly unlikely. You'd have to be doing something very wrong to make it so slow to respond that you'd see any delay.

  I am not sure, however, if MATLAB is suboptimal compared to the standard Arduino IDE.

I cannot comment, I have never used MATLAB. If you don't use a USB Host Shield then you will certainly require something that runs on a PC to forward the MIDI information over serial.  Whether you create that in MATLAB or some other programming language is neither here nor there as far as the Arduino is concerned - you'll still need to program the Arduino itself, and that can be done in the IDE and still use MATLAB for the PC portion of your setup.


You could use an Arduino with an ethernet shield to store the data to a MySQL server on the local network. See this blog post for an introduction to a library.

The tellstick is designed to be plugged into a USB host, so it doesn't make much sense in combination with an Arduino. You can get a USB host module but it's an expensive solution and you are using way more hardware than necessary.

Instead you could get 433 MHz receivers dirt cheap on ebay, but I'm afraid they only work on one channel, and there are a bunch of channels in the 433 MHz spectrum. So they might not work with the sensors you are talking about.

Another option would be to use eg. Arduino Pro Mini's in combination with a 433 MHz transmitter, powered by a battery. You could get the temperature reading from the internal sensor, or use an external one. The internal sensor takes quite a bit of calibration work to give a precise reading though.
You can get Pro Mini clones on ebay for a few dollars. You would have to dive into sleep modes and such, if you don't want't the batteries eaten away in a short time. To program it, you'll need an FTDI cable, or another Arduino programmed as an ArduinoISP (In System Programmer).
As an alternative to the Pro Mini board you could use a plain AVR chip, but it will be more work.


How can I fix stuttering motors that are connected to ESC's [Arduino Uno]?

It isn't clear from your diagram or the video what wire thicknesses you've used or precisely how currents are being routed, or how big your battery is.

Let BPG denote the ground terminal on the battery pack, and BP+ the battery's positive terminal.

There should be heavy wire from BPG to the ground pin of each ESC.  There should be a signal wire (that is, heavy or light, makes little difference as long as motor currents have their own heavy wires to follow) from BPG to an Arduino Gnd pin.

There should be heavy wire from BP+ to the positive voltage pin of each ESC.  There should be a signal wire from BP+ to Arduino Vin.

There should be signal wires from Arduino PWM outputs to ESC PWM inputs.  There should be heavy wires from ESCs to motors.

Also, in your code try changing 100 on up to 200 or 250 (or near whatever the ESC maximum setting is) to see if problem persists at higher levels of PWM drive.  Also if your battery pack is small, add some more packs of the same voltage in parallel, or try a heavier-duty pack.

Edit 1: Check whether each of the motors can work ok by itself.  That is, either comment out three at a time, or use if-statements that check button or jumper settings.  If all the motors work ok singly, try them in pairs or triples.  There are six different combinations of motor pairs, so rather than trying all six of those you might first try the four different sets of three motors at a time, and if that reveals a combination of three motors that fails, try the pair combinations among those three to see if there is some interaction between two motors.  If problems occur when testing with fewer than four motors, try swapping motors on to different ESCs, to find out if the problem is due to a motor, an ESC, or the battery.  (You can also swap motors on ESCs and test all four at once, but testing with fewer motors going should provide a more systematic problem solving method.)


Does RFID-RC522 supoort tk4100 chip protocol ISO18000-2C 10 digital ID card?

The MFRC522 on your kit is designed to communicate with ISO/IEC 14443 A/MIFARE and NTAG cards.

Search for Mifare Classic or Mifare Ultralight or NTAG213, NTAG216 ... cards.


Avrdude can't connect to butterfly programmer

I found a post of somebody with a similar issue. His solution fixed my issue!

https://stackoverflow.com/questions/46813157/avrdude-command-line-cant-connect-to-programmer-for-leonardo


How Programing the nodeMCU Through OTA using GPRS?

Yes, it is possible, but it takes some work on your part.

I recently had to implement OTA updates for the ESP32 over an RS-485 link, and it's actually pretty simple to manage. The hard part (for you) is the communication connection.

Performing an update (assuming the flash is already partitioned and set up right for OTA updates) is a case of "starting" the update, passing the update manager the flash data, then "ending" the update:

Update.begin(size) - This starts the upgrade process. You need to provide the expected size of the flash data at this point.
Update.write(*data, length) - Pass a block of flash data to the updater for writing.  An alternative is to read directly from a Stream class, which will try and read the number of bytes specified in the size parameter to begin.
Update.end() - This will finish it all off and switch the bootloader to load from the new flash. If it worked fine it will return true, otherwise, it will return false.

Assuming the above worked, you can no reset the board with ESP.restart()

For added security you can also pass an MD5 hash of the data to Update.setMD5(md5) and the updater will check that the uploaded data matches that MD5 hash.

Of course, all this needs implementing in your program that is running on the target device before you try and do any OTA updates. And, of course, you need to arrange the actual upgrade channel to get the commands and data through to the target in the first place.

So:

Implement a method of getting the data to the target
Implement the updater code
Go to the device and upgrade the firmware
From that point on you should be able to use OTA updates through your own chosen mechanism.


How to send a number to Arduino via Python over serial?

The python code

j = text[i + 5]
print (j)
arduino.write(j)

Is sending a single text character between '0' and '9', ascii values 48 to 58.

The c code

rx_byte = Serial.read(); //reading serial
switch (rx_byte) {
  case 0:

is looking for absolute values between 0 and 9.

There are two easy options to fix this, option 1 change the case statement to look for the correct values:

rx_byte = Serial.read(); //reading serial
switch (rx_byte) {
  case '0':

or option 2, rely on the fact that the ascii for the numbers is always 48 more than the number represented and subtract that:

rx_byte = Serial.read() - '0'; //reading serial
switch (rx_byte) {
  case 0:

-'0' and -48 would have exactly the same effect here only by using '0' it makes it clear we are offsetting by the ascii value of a 0 rather than by some other randomly created number. It also saves you having to remember what the correct value is for 0.

Generally since you are using the value in a case statement I'd recommend the first option, it's a little more intuitive and avoids an extra calculation that can look a little odd if you are new to programming.
The reason I mentioned the second option is that this is the method you would use if you wanted to use the rx_byte value as the index in an array for any reason.


options for wireless data broadcasting to hundreds of nodes

In terms of Radio, the RFM69 is a good option for range, speed and reliability at low cost. A board like this one https://talk2.wisen.com.au/product-talk2-whisper-node-avr/ would have all ready to go, just add your sensors.

The link can run on 433MHz, 868MHz or 915MHz band, which cover 99% of unlicensed/open frequencies worldwide.

For the protocol/software you need to reduce the message as much as possible. As you mentioned, you could have 9 bytes for the payload if you "share" some bytes, which is the correct approach in this tight network. Add some 2 extra bytes for "operation/command", "sender" and "receiver". Additional to that, you need to consider the bytes added by the radio itself, like Preamble, Sync-word, Network ID, Length, CRC, etc.

The biggest challenge in my opinion would be to not have the RF network flooded with messages, causing multiple radios to transmit at the same time and messages being lost.

Let's suppose you have a total of 20 bytes for all headers+payload per message. If your network is running at 80Kbits/sec (or 10KBytes/s), that would allow a maximum of 500 message/second (2ms per message) in a perfect scenario, without considering any kind of delay between messages.

Bring down to the real-world a 1/3 link utilization is a bit more realistic, giving you a bit over 150 messages of 20 bytes per second. In other words, if the network had an evenly message distribution a node would transmit a 2ms message followed by 6ms of silence.

Now, you can't count that 100 nodes would have perfect synchronization to send a 2ms message and stay quiet for exactly 998ms before sending a message again. There are so many variables which require you to have some sort of control.

One way of doing that is by using a pooling mechanism, where you have a "tick" or "clock" node, which is the only one allowed to talk without being asked. This node will be sending "pooling" requests, a small message with 1 or 2 bytes, containing a command and the destination address, for example: 0x99 0x0A, where 0x99 is the address of the node being polled and 0x0A is the command, like "send me the instrumentation readings, you have 2ms".

Now, instead of the node 0x99 start reading the sensors, it already have it all stored in memory and ready to go, sending the broadcast message to everyone interested. The node 0x99 will also start collecting the new sensor data and preparing the message, so as soon it'll be asked it's ready to go again.

This way you can control how noise the network is and also implement other commands to capture additional information if necessary, etc.

Another implementation would be similar to the old "Token-Ring", but I believe having a master would be more beneficial in this case.

Notes:

The RFM69 can go over 200Kbp/s, but only tests would tell the maximum reliable speed. I use 80Kbp/s to make maths easier.
Design your system so it would survive if a message is lost, like UDP packages, send it and "pray". Adding Ack and re-transmission is probably worst as it would slow down the whole cycle.
The radio also offers encryption, but it might take a few uS extra
If one node will be expected to receive every single message, bear in mind that it would have only a few milliseconds available to process the message and do whatever it needs to do before another message arrive. If you need to perform lots of processing/logs/control actuators you might need to delegate this task to other MCU(s)

Cheers,


How can I set up a watchdog interrupt vector timer on the Arduino Redboard/Uno?

Two errors:

The watchdog interrupt vector is named WDT_vect, not WDT_vec.
The statement _WD_CONTROL_REG = 0; serves no useful purpose, and
will likely mess up with the timed sequence for changing the watchdog
setting. Just remove it.


When the I2C scanner stops, it halts in the function Wire.endTransmission. The cause is a hardware problem of the I2C bus. For example the SDA or SCL are shortcut to something or pull-up resistors are missing (as already mentioned by TisteAndii) or the sensor module is not powered.

I assume that the IMU module has already pull-up resistors for SDA and SCL on the module. Which IMU module is it ? How did you connect it ? Do you have other I2C modules to test the I2C bus ?


From the image in the question, the jumper across pins J5 (in the
below schematic) or JD as on the silk screen on the PBC is missing.

Using the above schematic, a choice to power the Ardino and the relays off of one 5V power supply can be made.  This appears to be done by connecting the 5V to the VCC pin, Ground to the GND pin & placing a jumper across J5.  However, it appears that the relays can be isolated from the Arduino if desired.  This appears to be done by connecting the Arduino's 5V to pin 2 of J5.  That should be enough to light up the LED indicator and therefor the optical isolator when the Arduino's output to IN1, 2, 3 or 4 is low.  Then, connect the 2nd power source 5V to pin 1 of J5 and the ground from the 2nd power source to pin GND.  This last step should provide the power to close the relays when the Arduino takes IN1, 2, 3 or 4 low.
Lastly, make sure the polarity of the 2nd power supply (if one is used) is correct.  The output side of the optical coupler and the transistor driving the relay only work when the current is passing in the proper direction. Not to mention, the reverse bias flyback diode (D1, 2, 3 & 4) would short out the power supply if connected in the reverse direction.  However, this catastrophe is avoided here as the transistors (Q1, 2, 3 & 4) would not pass current in the reversed direction.


What is the necessity of "Prototyping Shield" for an arduino UNO R3?

A prototyping shield allows you to create your own circuit that can sit neatly on top of an Arduino.  Its main advantage is the pins/holes to connect to the Arduino, as these aren't evenly spaced so they are difficult to replicate with strip-board.
Do you need one? I doubt it very much, stick to the bread board and leave the soldering iron alone until you know what you are doing.


I think this is your problem (from the full code snapshot)

(acc2 >= 20 && acc2 >= 40))

I believe it should be (like your first snapshot)

(acc2 >= 20 && acc2 <= 40))

Note that the first is greater than or equal to 40 rather than less than or equal to. Also note you've done this when determining whether or not acc2 is between 41 and 60 in the else if part of that same if statement.

I have no idea why the code differs between your first and third snapshot. Potentially you have spotted this already and failed to update the full code being run?


How to display extended ASCII characters, e.g., the standard degree symbol, DEC 167, on the Serial Monitor [not LCD]?

The Arduino serial monitor uses UTF-8, per the discussion at http://forum.arduino.cc/index.php?topic=172814.0 --

For the U+00B0 degree symbol, you'd send the bytes UTF8 0xC2 0xB0 like this:

Serial.print("°");


ESP8266 module cutting connection with PC via USB

At which pins you connected the ESP8266?
The pins pin 0 (RX) an 1 (TX) are connectet internaly to the FTDI USB-to-TTL Serial chip.
If you using Serial.begin() to communicate with the ESP8266, you can't communicate with the pc at the same time.
Use SoftwareSerial to communicate with the ESP8266 an Serial to PC.

It is also recommed to feed the ESP8266 with an external 3.3V power supply and stabilize with an capacitor. This could  produces the sounds of ejecting and inserting a USB.


Playing a pcm file through a speaker with arduino

You are right that the values in a wav file are amplitudes. 16 bit signed values to be precise.

And that amplitude is just a voltage. Negative values are normally a negative voltage, but they don't have to be. They can be just a voltage below a pre-determined mid voltage around which the wave swings (known as a DC offset).

To play the waveform you just have to generate the corresponding voltages at the right times. That is usually done using a timer so you get the frequency right. For instance a 44100Hz file has to have a sample voltage generated 44100 times per second. 44100 samples will be a sound clip lasting 1 second.

But of course the Arduino cannot generate a voltage, so instead PWM is used instead. Filtered through a low-pass filter it turns into a voltage. It also uses 50% duty cycle as "zero" for the waveform, which is scaled to fit into the resolution of the PWM.  The PWM has to be running at a considerably higher frequency than the sample frequency of the waveform so it has a chance to represent a voltage before it is asked to change again.


Getting different numbers after sending an unsigned int 8-9 times between Arduinos via Serial

There's no flow control on the Uno and Nano serial and you are sending fast enough that bytes are being dropped, and there's no way your protocol or lack of one demarcates separate messages (separate numbers).
This will become more clear if you write your numbers in hexadecimal:

Dec
Hex

61805
0xf16d

61937
0xf1f1

28013
0x6d6d

61937
0xf1f1

Adding a delay between messages can serve to separate the messages if the receiving side makes use of a timeout and can prevent the receiving side from being overwhelmed with data.
If you don't want to use time to slow down and separate your data, you can change what is sent instead.  One idea is to have the receiver actively request data when it's ready to receive some. The receiver should expect only entire messages between requests, and if anything gets garbled, it can just read whatever data has come in and throw it out before the next request.
Your messages can also be separated by some characters that aren't part of the messages themselves.  A common way to do that is just to encode your numbers as separate text lines, the line terminator \n serving as the separator between messages.
I have not tested these yet, but here are some very minimal modifications to your code that approach having a protocol with fewer of these problems:
Sender:
void setup () {
  Serial.begin(9600);
}

void loop() {
  // await message request
  while(Serial.read() != '.') {
  }

  //
  const unsigned int s = 61805;
  Serial.write(highByte(s)) ;
  Serial.write(lowByte(s));
}

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

void loop () {
  // request message
  Serial.write('.');

  // await two-byte response
  const unsigned long request_sent = millis();
  while (Serial.available() < 2 && millis() - request_sent < 1000) {
  }

  if (Serial.available() != 0) {
    if (Serial.available() == 2) {
      // two byte response receive
      const unsigned upperByte = Serial.read();
      const unsigned lowerByte = Serial.read();
      const unsigned r = (upperByte << 8) + lowerByte;
      Serial.println(r);
    }  else {
      // Something went wrong, too or too few bytes received;
      // throw them out and start over.
      delay(100);
      while (Serial.read() != -1) {}
    }
  }
}

It's a long way from doing it properly, but it should behave at least better than what you started with.  There's a lot to designing even simple protocols.  Typically there are start and end frame bytes, a checksum or CRC, a message number counter, etc.


How to prepare data structures and classes?

The problem is that the lines saying foo = ... etc. are assignment operations. C++ lets you declare and immediately initialise variables at global scope, but after that you can only assign to them inside a function. In your original program, all your declarations/assignments were inside main(), which is why it worked there.

For your Arduino program, you could change the assignments to initialisations instead (in global scope):

Rectangle obj (3, 4);
Rectangle * foo = &obj;
Rectangle * bar = new Rectangle (5, 6);
Rectangle * baz = new Rectangle[2] { {2,5}, {3,6} };

Alternatively, you could leave the declarations in global scope and move the assignments into setup():

Rectangle obj (3, 4);
Rectangle * foo, * bar, * baz;

void setup() {
    foo = &obj;
    bar = new Rectangle (5, 6);
    baz = new Rectangle[2] { {2,5}, {3,6} };
}


Arduino Disconnects after router password changes

Routers have multiple "passwords".  I assume you are talking about your wireless encryption key (i.e. WPA/WPA2 key).  When the encryption key is changed, you are correct: you have to re-program the ESP8266 with the new key, because it can't learn this information on its own.  If this key were broadcast, then your network would not be secure as everyone would be informed of the encryption key.

Why is the key changing?  Is there really a need to change the encryption key often?

MAC addresses can be spoofed, so permitting a specific MAC address to "always connect" is not secure.


I don't fully understand your program, but I hope to give some guidelines/tips:

Instead of using all kind of different variables, with hour, minutes and seconds, with with only one variable that keeps the time. E.g. a long integer value that contains 24 * 60 * hours + 60 * minutes + seconds as one value. E.g. 12:34:56 will be 24 * 60 * 12 + 60 * 34 + 56 = 19,376.
Subtracting one or 10 seconds will be as easy as subtracting a value 1 or 10.
To calculate back to seconds, minutes and hours, use 3 formulas (assuming time is the time value):

int hours   = (int) time / 60 / 24;
int minutes = (int) (time - hours * 60 * 24) / 60;
int seconds = time % 60;

Keep the code to display the LCD separate, probably it's easier to update every digit every second. You probably change it every second, or when the button has been pressed, which is very slow for a MCU.
When using a button (you already put it in a variable), just remove 10 seconds, and update the time.
However, check also the Blink Without Delay example on the Arduino website, since when you press a button, high likely the button will bounce and one press may result in several times 10 seconds will be subtracted.
And as said above, use good and English variable names, and English comments (except the GUI text to be displayed... O zi buna).


Can't use base class and derived class functions

Any functions that the base class needs to call that will be defined in the child class must also be defined in the base class.  They should be defined "virtual" so they can be overridden, and can even be "pure virtual" so they have to be defined in the child class.

So for any function in the child class that the base class needs to access, add this to the base class's definition (print.h):

virtual void write(unsigned char data) = 0;

The = 0 bit defines it as pure virtual, and any classes than inherit this class without defining their own copy of the void write(unsigned char) function will thrown an error.

Instead of pure virtual you can provide a default function that a child can override if they want to, which can be useful if most classes will work the same way (define it in the parent) but some want to do it differently (override it in the child), in which case you treat it like a normal class function but add the virtual tag.

The whole topic is called polymorphism and is an incredibly powerful system.  It's discussed in detail here: http://www.cplusplus.com/doc/tutorial/polymorphism/


Depends, and probably better to use C strings:

If you know the number is always the same amount of characters, use the C function strncpy.
You can also split on a delimiter (char), with strtok, but in your case this is not possible since you don't know the delimiter character.
If the number has a variable length, start copying character by character through the string, until you find a character that gives false for the isdigit condition and copy the remainder (with strncpy) to the other string.

Update after the question's edit

Since the number of text to be copied is know, strncpy can be used with the following prototype:

char *strncpy(char *dest, const char *src, size_t n)

In your case put the text in a normal text string:

char text[80]; /* Assuming max length of text */

Copy it where needed:

strcpy(text, "77953505HELLO THIS IS A MESSAGE");

Note: it can be done in once like this:

char text[] = "77953505HELLO THIS IS A MESSAGE";

Than you can copy the items by:

char number[9]; // Add 1 for \0
char message[81]; // Assuming max length of message;

strncpy(number, text, 8);
strncpy(message, &(text[8]), strlen(text) - 8);

(Note not checked with compiler).

Improvements: use instead of 8 a define e.g.

#define NUMBER_LENGTH 8

char number[NUMBER_LENGTH + 1];

strncpy(number, text, NUMBER_LENGTH);
strncpy(message, &(text[8]), strlen(text) - NUMBER_LENGTH);

You can do similar for MESSAGE LENGTH

#define MESSAGE_LENGTH 80

Also, another improvement is not to copy the message, but just set the pointer to the correct place:

char* message = &(text[8]);

message will point to "HELLO THIS IS A MESSAGE"

like below

"77953505HELLO THIS IS A MESSAGE"
|        |
+-- text |
         +-- message

In an Arduino 80 bytes can be a lot of memory, using two buffers cost 160 bytes, and this way you save at least one buffer.


Receiving two values over serial port using servos

Your problem is that you aren't providing anything to split the data on. You just send the X and y coordinates with a : between X and y. There's nothing between the y and the next X.

By changing the line

port.write(x+":"+y);

To

port.write(x+":"+y+"\n");

You then get the linefeed character to split your data on.


Arduino Nano periodic reset under program control?

Why do you want to reset you board?  The reason affects the answer.

Do you want to reset the board because your program crashes after n hours?  If so its probably better to fix the memory leak that you have in the code.

Is it because some global variables need to resetting every now and again?  If so could you place them in a class and store a pointer to them as your only global.  When you want to 'reset' the board delete the instance of the class and recreate it.

What happens if the software crashes?  Have you got it configured to restart on a crash?  If so could you just crash the code deliberately?

Because you have size constraints then it may be worth a bit of lateral thinking to see what the code can do for you.


[Arduino UNO]Receive Serial Data from multiple sources

This answer summarizes the possibilities:

1) HardwareSerial is always best.  You are using that for WiFi.

2) AltSoftSerial is the best software serial library, but it requires pins 8 & 9.  Very efficient and non-blocking!  Strongly recommended for the GPS connection.

3) NeoSWSerial is next best, but it supports only 9600, 19200 and 38400.  It is non-blocking on receive, so it could be used for the GPS connection.

4) SoftwareSerial is the worst.  :P  Not suitable for the GPS connection, as you have discovered.

I'll also mention my GPS library, NeoGPS.  It is smaller and faster than other libraries, and there are examples that show how to make it run during the RX character interrupt, saving even more time.  It can also be configured for just the messages and fields that you actually use, saving RAM, program space and execution time.


Setting the frequency of a timer interrupt

I second BrettAM's comment. The Arduino IDE sets most of all the timers up for PWM, and I had to comment out a section once to use my own ISR with Timer 3 on a 32u4, because no matter where or how I set it, the CTC interrupt never went. The WGM50 and CS51 are set at the start of the Arduino files basically, so that messes with your settings.

You will need go into the Arduino core files. This is $install_path/arduino-1.x.x/hardware/arduino/avr/cores/arduino/, and under that directory you need to find file wiring.c. This file contains all the setup of the timers for PWM and the millis() or micros() functions.

Go to line 342. Located there is this:

#if defined(TCCR5B) && defined(CS51) && defined(WGM50)

  sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
  sbi(TCCR5B, CS50);
  sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

#endif

Here you can place another #if defined() macro around this, resulting in:

#if !defined(doNotSetTimer5)

  #if defined(TCCR5B) && defined(CS51) && defined(WGM50)

    sbi(TCCR5B, CS51);           //set ter 5 prescale factor to 64
    sbi(TCCR5B, CS50);
    sbi(TCCR5A, WGM50);         // put timer 5 in 8-bit phase correct pwm mode

  #endif

#endif

Now when you want to use your custom settings, you will put the following at the top of your .ino file:

#define doNotSetTimer5
#include <wiring.c>

That does not block the Arduino environment from setting up Timer 5 when compiled with other code, but only when you want to use custom settings (changed because of @Gerben's suggestion). When you change these settings you will lose PWM on 3 pins: 44 45 46. But you will be able to make use of setting your own PWM up or a CTC ISR().

This doesn't mess with anything else and is the easiest way to do it.


Connection Pro-Mini & ESP8266 using Serial

A) is that true that at boot Serial has to be disconnected?

No, that is not true. However if you are using Serial to communicate on the Pro Mini you will need to disconnect the ESP8266 in order to program the Pro Mini as it will interfere with serial communication to the PC.

B) is there a way that 2 MCU can be connected at all times, including reboot when needed ( such as power failures ) ?

Given that A) is a no, then B) is irrelevant. It will just boot.
The only caveat is that the ESP8266 will squirt some boot messages out of serial as it boots at 74880 baud, so you have to be able to cope with that noise in whatever protocol you design between the two boards.


Supplying power to arduino by 5V and 2A adapter

Amps are not "forced" through a circuit like volts are. A closed circuit draws as much power (in amps) as it needs, so the only problem you could ever have is having too little current and not too much. Seeing as your module draws 200ma 2 amps to power it is plenty.


Dynamically create functions for AccelStepper that use Adafrut_StepperMotor.oneStep methods?

I ended up just inheriting AccelStepper, and extending the
AccelStepper::AccelStepper  (   uint8_t interface = AccelStepper::FULL4WIRE,uint8_t pin1 = 2,uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5, bool enable = true ) constructor to add my own Adafruit_StepperMotor instance variable and using it in an overridden step0 (which is the only function those callbacks were used in).

class MyAccelStepper: public AccelStepper
{
   public:
       MyAccelStepper(Adafruit_StepperMotor *myStepper):AccelStepper(0,0,0,0,0,false)
       {
         //MyStepper(0, 0, 0, 0, 0, false);
         _myStepper = myStepper;
       }
   protected:
       void step0(long step){
          (void)(step);
          if(speed() > 0){
            _myStepper->onestep(FORWARD, DOUBLE);
          }else{
            _myStepper->onestep(BACKWARD, DOUBLE);
          }
       }
    private:
       Adafruit_StepperMotor *_myStepper;
};


Use LED on pin 13 again after using the SD library

It is possible to use the LED on pin 13 again by disabling the SPI bus that is used by the SD library to read/write data to/from the SD card. To disable the SPI bus, simply call SPI.end() after closing the file on the SD card.


Very interesting stuff. As you are new to this kind of stuff i can suggest you, instead of explaining ( because videos are cool), to watch this video that explains very clearly how to use the lm386 with some filters. That video is a project about controlling the arduino through whistling. Hope that helped.


"port" is greyed out in 1.6.13, running win 10 for an Uno R3

When the port is greyed out its not available (I know you had worked that out) so you have a problem with you serial to USB drivers.

Looking at the kit I think you are connecting the UNO to a USB port on your PC/laptop using a blue cable.
 1. Please can you check that the cable is connected properly.
 2. Can you try a different USB port on the PC (don't use a USB hub - some don't work).
 3. Does Windows recognise a device has been plugged?
 4. Are you running it as administrator, you will need to be to install the drivers.
 5. Can you try connecting it to a different PC?

If these don't fix it then, please comment and well go through looking at the device manager.

Hope it works, it looks like fun.


Could you tell me what is wrong with this Arduino code?

Arrange your code like this:

Servo servo1, servo2;

void setup() {
    servo1.attach(41);
    servo2.attach(2);
}

void loop()
{
    int pos;

    for (pos = 0; pos <= 180; pos++) {
        servo1.write(pos);
        delay(15);
        servo2.write(180 - pos);
        delay(15);
    }

    // 2nd loop here

}

It's rather inefficient to detach a servo after each write and then attach it again for the next write. Simply keep it up all the time.


That adapter is not suitable. Not only is it the wrong gender on the large end, but it is designed for a completely different purpose.

That is an "On The Go" adapter which is designed for connecting things with a USB A plug (such as a memory stick, etc) to a mobile phone's USB socket.  It is not suitable for connecting things to an Arduino.

I have never heard of an adapter like you want, but I have heard of Arduino-like boards that plug direct into a computer like you want. One example is the Digispark from Digistump which is an ATTiny85 on a USB plug.


SPP-C and HC-05 are they the same thing or something else?

In theory they are the same and have the same capabilities. Practically they are not. With SPP-C you get twice the headache for half the price as for HC-05. In had to find it out the hard way Sending data using Bluetooth SPP-C Module without a Breakout-Board. I tried both SPP-C and HC-05 with and without breakout boards finding the same issues. So if you are willing to spend time, risk your project and save some money then use SPP-C. Otherwise use the well known HC-05.


Pressing reset button restarts program only seconds latter

The first thing that happens when you apply power to a board or press reset, is the bootloader executes. That waits for a short time to accept a new sketch over the serial port. If nothing arrives it terminates and executes the existing sketch.

On the Uno that delay is only 2 seconds. However on the Leonardo the delay is much longer (around 5-8 seconds) owing to how the serial port is implemented: it has to allow time for the host computer to re-enumerate the USB device after a reset, and that takes a second or two.

If you don't want that delay you will need to remove the bootloader (i.e., ignore it) and program the board through a hardware programmer and the ICSP pins (which will disable the bootloader for you). You lose the convenience of programming through the USB connection though.

Alternatively choose a different board that doesn't have such a delay for the bootloader - one that uses a different programming method.


How to connect HC-06 with HC-08 with the HC-06 as master and HC-08 as slave?

You cannot. The HC-06 is a slave only device.
So you need to use a device as master, that is actually capable of it. I don't know, if the HC-08 can do it. Another typical bluetooth master device is the HC-05. Just like HC-06, but can also be a master.


Some tips:

Don't use String.
Use char * and slice the string in-place.
Pass a pointer to an array of pointers and fill that with pointers to the portions of the string you have sliced.
Return the number of entries in the array you used.

I do something similar in my CLI library.  I use a custom "getWord" function, but similar can be done with strtok().

You can read more about working with C strings here.


How to get average of 16bit ADC readings?

You forgot to initialize ambient to zero, so it got whatever happened to be in that place of memory when it got instantiated. Some unpredictable, seemingly random data.


Can I safely connect my original Arduino Uno to a 19V adapter?

According to the page you linked:

  The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts.

So, yes. You can use the 19V external power supply to power the board. However, be aware that the voltage regulator can overheat over time and damage the board.


This sounds, to me, like a job for CAN.  It's the current de-facto standard for industrial inter-MCU cabled connections. It's used, not only in automobiles, but also to control elevators and almost all other modern industrial distributed applications.

Note that CAN is designed to only support up to 30 nodes, so you would need to split your network into sections and have groups of nodes amalgamated together into a single sub-network.  For 200 nodes you may want 10 subnetworks - that is, 20 nodes connected together to one super-node, which is then connected to the "backbone" CAN bus.

However, CAN can be run at lower baud rates than normal, and that increases the number of nodes you can have on any one network segment. It potentially (bus capacitance permitting) support thousands of nodes.

Another option is to use CAN to connect multiple "master" nodes together into a backbone, and then those "master" nodes connect to a number of sub-nodes using LIN (which is cheaper to implement than CAN).

LIN can support a maximum of 15 nodes (plus one master node) per network, so you can get a theoretical maximum of 29*15 (assuming 1 CAN node is the connection to the PC), or 435 nodes.

You could also use RS-485, but that is also limited to around 30 "unit loads", and the number of nodes you could put on one segment is dependent on the "load" each node imposes. In practical terms it's rare to go over 30-40 nodes on a single segment, and grouping nodes together into sub-networks (as above with CAN/LIN) would be needed. So you may as well use the current standard for this kind of communication, and use CAN/LIN.