Arduino and 127/220 Volts: Relay and Isolation

Do a Relay Shield protects the Arduino board from the current and voltage from the power supply?

A relay provides galvanic isolation in the circuit.  The mains power is electrically isolated from the rest of the circuit since the device that performs the actual switching (the contacts in the relay) have no physical connection to the rest of the circuit - they are merely acted upon by magnetism.

That doesn't mean that it's safe, however.  There are a number of things you still need to deal with:

The Arduino cannot directly drive a relay - it can't provide enough current. You must use a drive circuit.
Back-EMF from the relay coil as the magnetic field collapses can damage sensitive semiconductors - good snubber circuit design is important here.
Mains electricity is dangerous and must be treated with respect.  Proper circuit design is paramount to ensure that the mains is kept away from the rest of the circuit. Proper connectors must be used and exposed high voltage points must be rendered inaccessible, either by the project housing or by the addition of plastic insulating shielding.
Relays as they turn on and off cause sparks. Sparks cause EMI. EMI causes induced currents. Induced currents cause damage to electronics.  Minimizing the spark generation not only prolongs the life of your relay but the life of everything else around. Ensure your relays can switch fast enough for the currents you are dealing with, or consider using solid state relays (SSRs) that don't suffer from this issue.


Arduino ModBus RTU master communication with Power Meter problem

I have made it. Now it is working. I only checks A & B cables (tried a new one) and change address of register from 5000 to 0x5000 and now it works. I thought that this library already give 0x before address, because i didn't see it anywhere with 0x before.
An advice for people with the same problems:
Most of the devices which is using RS485 and ModBus protocol (and have an some kind of display) shows an communication (over 485 & modbus) on display by some kind of mark, for example in my case it was an "dot" which blinks when there's an communication. When this mark is shown, it is sign of that the communication settings is right, so data, parity bit, stop bit & baudrate is OK (data has successfully reached the dest. device).
After that, these devices send you an error message back on its line. So if you have problems with getting data, you should send your message (ask) from the arduino to that device, over an Transmit pin from arduino (of course trough an converter, for example max485) and the Receiving pin (side) connect to your PC through again some kind of converter from UART to USB. (Warning: you should have the same ground potential, so wire all grounds together)
Install some software to communication for modBus on PC (i am using this soft: https://www.simplymodbus.ca/ | you can use demo ) After that let arduino sent an message and receive it by PC. (in simplymodbus look at the "response") read that code and look to the manual for the device you using, where there should be an description of error codes, if not look at this doc.: http://www.simplymodbus.ca/exceptions.htm or THIS).After that you will have an better look on what is going on and where there is a problem.


Trying to send data to the server and AT+CIPSEND not working correctly

Your code looks like you connected the ESP to the hardware serial port, but your comment says otherwise so:

Your sketch isnt working because you're writing to the wrong serial port half the time, and even when you do use the right serial port (softSerial) you're sending garbage along with it.

Serial.println(stringLength); and Serial.find("OK") should be softSerial.println(stringLength); and softSerial.find("OK").

Serial.find( ">" ) should be softSerial.find( ">" ). You should look for '>' in the buffer between the Arduino and the ESP8266 and not the one between the Arduino and the PC.

softSerial.print(">");, softSerial.println("RECEIVED: OK"); and similar statements should not be there at all. They are not commands or arguments to a command so why are you printing them to the ESP? Whenever you write to softSerial, make sure its a command. Dont send your debug messages to softSerial; use Serial instead.

There's no variable called cmds and yet you're printing it to the serial port. Assuming this code compiled, its probably a typo in your question?

Finally, your code structure is unreliable at best, what with all the delays in it and not a single Serial.available() or softSerial.available(), not to mention the abundant usage of Arduino Strings. I suggest you first learn how to read from a serial port and build C strings from the results and then re-design your code again. Majenko's blog is as good a tutorial as any. Or you could download a library like this one that provides an easy API to the ESP8266, shielding you from the mess of AT commands, while providing you with example sketches that already do what you want. Of course, you could choose to go through their library (.cpp and .h files are the place to be) and figure out how they used AT commands with the ESP and then write your own sketch, library or whatever. Good luck.


This works:

int* test = 0;

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

void loop() {
  Serial.println("test");
  if(test != 0){ //c++ delete and new attempt
    delete [] test;
  }
  test = new int[2];
  //test = (int*) realloc(test, 2 * sizeof(int)); //realloc attempt
  //test = (int*) malloc(2*sizeof(int));          //malloc attempt
  test[0] = 1;
  test[1] = 2;
  int answer = test[0] + test[1];
  Serial.println(answer);
  Serial.print(test[0]);
  Serial.println(test[1]);
  Serial.println("test");
  delay(100000000000);
}

In C/C++, you can't add/concatenate Strings and int.


For saturation you should assume hfe to be 10. This gives:

(5V − 0.85V) / ((0.09A ⋅ 3) / 10) = 154 Ω

Consider using a 150-220Ω base resistor instead. And since a fan is an inductive load, don't forget the flyback diode from the collector to the +12V rail. A 1N4000 series diode should be fine for this small a load.


VIP/PID is realized by Atmega16u2 driver which implements USB device driver. Probably all revisions of *Arduino Atmega2560*s has implicitely the same VID/PID. Each piece has unique serial number. But you can upload own firmware into 16u2 to modify USB as you wish (ideally using LUFA library). It's clean solution for production hardware because you cannot use Arduino VID because of USB rules.


Using digital pin 11 for DMDCon and IR remote

The workaround would be to configure the https://github.com/shirriff/Arduino-IRremote library referenced in your question to any available digital input.


I had a quick look into the Schematics of a digisparc board. P1 is hardwired over an LED and a resistor to GND. If you turn on the PULL UP resistor for P1 the LED should light up and the voltage at P1 would be very low (it depends on the voltage divider that is built from the PULL UP resistor and the LED resistor); so the P1 reading should be LOW. If you connected the Button to GND and press it, the voltage at P1 drops to 0. But, that does not affect the LOW state. The program does not react. The LED turns off, because it is not powered anymore.
You could try to connect the button to +5V and do not setup a PULL UP resistor for P1. If you press the button the LED should light up and +5V should be at P1. It should change its state from high to low. (I did not tried that; but I see no reason, why it would not work).


detecting signal coming from another motion sensor that triggers camera's shutter

Sorry I am typing this here coz I don't have enough rep to comment. Anywho, most of the motion sensors involve PIR tech, so the best way is to connect your PIR Signal pin from your sensor to any analog pin of your arduino and test the kind of signal you're getting when the environment is idle and when movement is detected, Keep in mind of the region that the sensor covers too (ROI). That will tell you some things,

If the sensor works or not.
If the sensor value is analog or digital
If the sensor is active high or low
Trial and error on the actual ROI

After all that you can write your code around it.


Right click on the Arduino icon, select properties. Under the compatibility tab, check "Run this program in compatibility mode" and select Windows XP. You might also want to run it as administrator.

This should hopefully solve the issue.

Source


I am unaware of any Arduino-based tools for installing a bootloader on a PIC32. If you are going to work with PIC32 you really should invest in a proper programmer.

I often use (pretty much throw-away) Chinese clones of the PICkit2 programmer. You can find them on eBay nice and cheap.  Genuine Microchip programmers are pretty expensive, so these cheap clones are quite handy...

You will also want to install the chipKIT environment into the Arduino IDE.

When it comes to the bootloader there are no official boards that use those chips. So you will need to compile your own version, which is not trivial. You will need to install MPLAB-X and the XC32 compiler and create a new profile within the project with the right settings for your board.

And then of course you will have to craft a board configuration for your custom board.

All-in-all it's quite a complex task porting a new board / chip to the chipKIT environment, and you would probably be better off directly using MPLAB-X and programming directly in C (although it's harder to get started in that environment). The PIC32 chips are considerably more complicated to work with than little AVR chips.


Why we are using client.flush() in the program code ,when we connect Esp8266 with internet or web server?

This is most likely related to the old usage of .flush() from pre IDE version 1.0.0.
In those old versions .flush() would erase any pending data in the reception buffer. It was the equivalent of:
while (client.available()) {
    client.read();
}

Now though it's used to ensure that all data has been sent before doing anything else. In this situation it's completely meaningless.


Can an accelerometer be used to detect heart sound?

An accelerometer detects motion (acceleration) of the physical device.

If you can convert the sound of the heart into physical vibration then the accelerometer can detect that vibration.

Converting the tiny amount of sound the heart produces into a large enough vibration for the accelerometer to detect would entail (realistically) using a microhone, amplifier, and speaker, with the accelerometer attached to the speaker cone.

So while theoretically yes, you can do it, practically why would you when you can just use the microphone and amplifier that you'd be using anyway. It's pointless.

So in reality: no, you can't.


Can I use GSM and GPS modules at the same time?

Yes.  Use SoftwareSerial for one of them.  That way you can use any pins you like for that module.

I'd recommend using the GPS module on the SoftwareSerial since it's (mainly) half duplex, and SoftwareSerial can't both transmit and receive at the same time like the hardware UART can.

Either that or switch to a different Arduino board that has more than one hardware UART.


First off, you don't want to use a checksum for authentication.

A checksum can be thought of as a hash with a very small size. The smaller the size of a hash the less unique it is. The less unique it is the more likely it is that incorrect data will generate the same hash and authenticate someone it shouldn't.

For instance, a 32 bit checksum (hash) of 1kB data (8192 bits of information) is a 256-fold reduction in the uniqueness of the value. At 32 bits you get 232 unique values. With 8192 bits you get 28192 possible values. I can't calculate how many values that actually is, but as you can imagine there will be many billions of billions of combinations that would all equate to the same checksum.

If you must use a checksum then make it an actual recognised hash. For instance an MD5 (considered weak by today's standards) has 128 bits. SHA-256 has, as you would imagine, 256 bits.

However calculating these hashes on an Arduino is not a simple matter owing to a lack of memory. Not impossible, but not that easy.

If you're going as far as to use such large amounts of data for authentication and using heavy mathematical routines to create a hash you may as well go the whole hog and use a proper cryptographic key pair.

One method would be to encrypt the UUID of the card off-line and store the encrypted result on the card - that data would then be unique to that card and tied to it - you wouldn't be able to clone the card unless you could clone the UUID as well.

Then either the UUID is read by the Arduino and also encrypted using the same key and if the results match authentication succeeds. Or the encrypted value is decrypted by the Arduino and compared to the UUID to see if they match. Which you choose depends on if you have asymmetric or symmetric encryption (the former is more like a hash but requires the encryption key to replicate it whereas a hash doesn't).

You can also include other information with the UUID, such as the name of the card owner (for identification purposes), etc - as long as you are able to already know that data to create the cryptographic has to compare with what is on the card.


Determining state of charge using current sensor (ACS758) with arduino uno

Instead of using a separated component for each thing you can use a proper solution that is itself already a combination of both: the DS2438's integrated current accumulator. This link explain it pretty well, also here is a library to use it with arduino. They are pretty cheap (a few dollars) and will perform very well!

Although, in your place I would consider choosing a different approach. I don't know which kind of battery (Li-ion, LiPo, Lead-acid..) you are using, but in many cases if you monitor the battery voltage, you can have enough information about the battery state. I can't ask you in comment yet beause I'm new here and don't have enough reputation, but if you can describe better the kind of battery you are using and what you intend to monitor which your circuit, I can edit this post to offer you a better solution.


The DS3231 library you are using works (for some bizarre reason) exclusively with its own internal bit-bang implementation of I2C. This cannot be used on the same pins as the hardware Wire library which the MPU6050 uses.

Either move the DS3231 to a different pair of pins, or find a better DS3231 library that uses the Wire library for communication.


Hi Welcome to Arduino StackExchange
You can build your own LCD characters if you spend some time with the datasheet and user manuals available
Arduino has a dedicated function here
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

byte smiley[8] = {
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

void setup() {
  lcd.createChar(0, smiley);
  lcd.begin(16, 2);
  lcd.write(byte(0));
}

void loop() {}

here is one example:  from our tool here

From the datasheet:

here is one example where a Heart symbol is created using the built-in Arduino LCD library:
You can play here at our LCD1602 simulator to get a hang of it.  Please leave a message or comment if you have any questions :)


Arduino potentiometer example: what limits the current?

A0 input is high impedance, so very little current is flowing into A0. The value is so small that you can simplify that it flows only from +5V through the potentiometer to GND.

For some applications, when you are measuring high-impedance sources (a source that can deliver very little current) this simplification may not be correct.

You can find more detailed explaination in Atmel application note:

http://www.atmel.com/images/atmel-8456-8-and-32-bit-avr-microcontrollers-avr127-understanding-adc-parameters_application-note.pdf


You could try with a direct TCP connection (in this way you skip the HTTP layer) but you need to prepare also a small TCP server (in any language comfortable to you) that accepts the client connection, sends the data, waits the ACK and close the connection.


Common Wire sizes for connecting peripherals to arduino

Depends what you’re doing.

For low power (< 12v, 500mA) peripherals and digital signals:

If you’re going to use breadboard (and you really should start with breadboard) you’ll need solid core hook up wire. You can find pre-cut, pre-stripped sets with a variety of lengths and colours if you’re looking for neatness and simplicity.
(An example can be found at: http://www.maplin.co.uk/p/jump-wire-kit-fs65v)
Usually it’s 22AWG wire, so you could get a reel and cut it yourself if you’re going to need a lot or are going to solder it in place.

After you’re done breadboarding and want to make something more permanent you should look at rainbow cable. You can tear it to get anything from 2 to 32 way cables, and it’s almost impossible to get the wrong way around. You can solder it directly to a PCB or crimp connectors onto the ends for more flexibility.
(You can find this stuff everywhere, but Sparkfun is always there if you can’t: https://www.sparkfun.com/products/10649)

For higher power (> 12v, 1A):

Keep it away from the Arduino! Use switching transistors, relays, or MOSFETs and use cabling that meets, or preferably exceeds, the power that you’re going to put through it.

I don’t know where you’re going to buy this, but in the UK I use Mouser, Farnell, and RS for most of my electronics supplies. Never buy cabling off Ebay, a lot of it is counterfeit and won’t meet the claimed spec.

Hope this helps.


Issue with adding a library: No such file or directory

That library is for the older version of the Arduino ide. To fix this you need to open Morse.h and change WProgram.h to Arduino.h.


20x4 LCD will write but then won't update

Ah ha.   I solved it by using lcd.clear() and simply repainting the entire display with every change.  I have much simpler LCD programs that don't require doing this, but it worked in this instance.

Same code as above, but with this before each power notification:

lcd.clear();
lcd.setCursor(2,0);
lcd.print("PV Control 3.9");

etc...

UPDATE:
  Now that I have two 20x4 LCD screens showing readings from two separate Arduinos (PV Controls and Weather station) I have discovered that it is very important to keep the screen writes to a minimum.  No time delays in between writing parts of the screen, for instance (like when I had Serial.print statements in there for debugging), doing all the readings and calculations before writing the screen, and timing the screen updates to be infrequent, like on the order of 65 seconds for weather and 10 minutes for the PV.  I2C does not have collision detection so it is important to try to prevent the two screens from being updated at the same time.  The I2C&Power arrangement is working great.  One source of power is all it takes to activate the entire network.


Burn bootloader into Arduino UNO from Arduino Duemilanove

Yes, Nick Gammon has a page on doing that here  https://www.gammon.com.au/bootloader


Since you have already tried SoftwareSerial, also try inverting the serial protocol via SoftwareSerial.  Sometimes a device uses inverted serial protocol and you don't know it.

So initialize inverted add 1 to the end of the contructor like so :

SoftwareSerial mySerial(RXPIN, TXPIN,1); // RX, TX, inverted


If a Timer is used, disabling some PWM pins, can I still use those pins for Digital write?

If I enable Timer 5, does that mean that I can't use these pins for anything else? Or does it only mean I can't use those pins for AnalogWrite, and that I can still use those pins for DigitalWrite.

You can view the connection between the Timer and the pins as programmable. The connection is enabled by, for instance, analogWrite(). The Timer control registers have a setting for both the connection and control logic of the pin (clean, set or toggle on timer value match).

You can use the Timer to generate interrupts without connecting a pin. This is the case with micros() and millis() which get their values from a counter which is updated by an ISR on Timer 0 (overflow). analogWrite() on pin 5 and 6 connects to Timer 0 value match logic.

analogWrite() uses the Timer value match and connects the pins. Enabling only the Timer (as you suggest) will allow you to use the pins with digitalWrite(). You can also use the Timer ISR for overflow. The Timer prescale is set for analogWrite().

Cheers!


I had accidentally commented out the SD initialization along with the serial initialization. After uncommenting it it works correctly


Is it possible to use ESP8266 modules interchangeably?

yes they are interchangeable since they all use the same chip (esp 8266). However the pin outs of the different modules can (and will be) laid out different. So you have to watch out that your wires are connected to the correct pads on the module.

Also mind that different esp8266 modules can be (stock) loaded with different firmware. If you are using the AT firmware in your current arduino project it can be necessary to flash your new esp8266 module with the same firmware. If you are not sure how to do this you might have a look to the esp8266 forum


Use Adafruit 16-Channel 12-bit PWM/Servo Shield to switch relays

That will work. Just make sure you are not using Servo part of the library, but only the PWM part, and set the duty cycle to 100%. The relay should still work, even if the duty cycle is slightly lower, as the magnetic field takes a bit of time to collapse. Just make sure you don't forget to add a (flyback) diode to the relay.

Looking at the datasheet I think you need to use the following code

pwm.setPWMFreq(1000);//put this in setup()
...
// enable relay at channel 15
pwm.setPWM(15, 1, 0);
...
// disable relay at channel 15
pwm.setPWM(15, 1, 1);


[Turning my comment and other peoples replies into an answer to make it easier to read]

You are using two different power supplies? (PC + 12V or USB Charger + 12V) Have you connected the grounds from the two power supplies?

I have a limited understanding of why, but I know that unless the two power supplies have a common ground level the values for 0V and 5V may not be the same across the two feeds and you get odd and unpredictable behaviour.

Gerban explained that the reason it works on your PC is that most PC Power supplies reference Gnd from the Earth.  If you 12V supply is an ex-PC PSU, or similar, that will be doing the same which is why that setup works, they share a common ground via the mains earth.  The 5V phone charge probably has a plastic earth pin, which means it doesn't do this and therefore the Gnds are not tied to each other.

Majenko's blog will provide a more detailed, less hand wavey explanation:
https://hackingmajenkoblog.wordpress.com/2016/12/06/the-importance-of-sharing-grounds/


Powering Arduino Uno R3 with battery packs

Power sources like batteries and wall warts are voltage sources: they will deliver a fixed voltage, more or less. The current that they supply will be determined by the load you attach to them.

The "Amps" listed on a power supply is not how much current it will put out, it is the maximum current that the manufacturer has decided it can put out safely, without acting funny or overheating. So when you read that the USB port on a computer supplies 5V and 500mA, that means that it will supply 5V and up to 500mA. If you draw more than a 500mA current from your USB port, you would exceed the max current rating of the USB port. USB ports usually have an emergency shut-off mechanism built in, so they would just turn off if you drew more than 500mA out of them. I wouldn't try it though :). Your battery seems to have pretty similar safety features: "Super protection: overshoot, over-discharge, short circuit, over voltage, leakage, and many other protective functions".

If you had a 5V 20 Amp power supply, it will act the same as the USB port power supply, except it will be able to handle putting out much more current. As long as you don't exceed a voltage source's max current rating, the amount of current that a voltage source puts out depends on how much current the load draws, not on the voltage source. For example, a resistor will draw a current in Amps equal to the voltage supplied to it divided by the resistance (I=V/R), via Ohm's Law. For microcontrollers, you can often find their current draw on their datasheet: your MPU 6050 with the Gyro + Accel running has an operating current of 3.8mA when you give it ~3.3V. An Arduino Uno draws about 80mA by itself, though I don't think this includes the 3.3V power regulator on the 3V3 pin. So you're looking at somewhere a little over 84mA (=0.084A) in total. Your battery can supply 2.5A or 1A depending on which of its ports you use, so you are nowhere near exceeding the battery's max current rating, which is a good thing.

There are no fuses built in to the Arduino Uno R3. If you exceed its maximum current limitations, you will mess it up. There's a ruggedino available with more safety features if you're worried about frying your arduino. But as long as you're careful you should be fine with a standard R3.


Burn normal bootloader onto Atmega328P configured to use internal 8MHz clock

I have a sketch that will upload the Optiboot bootloader - that will work perfectly well on the Duemilanove.

The latest version will be available on GitHub.

This particular sketch is in the "Atmega_Board_Programmer" subdirectory.

You need to run this sketch on another Arduino (like a Uno) and connect it up like this:


Receive an array of characters using SIM900 module

#use this code and then inform me"
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

void setup()
{
    pinMode(3,OUTPUT);
    Serial.begin(19200); // for serial monitor
    SIM900.begin(19200); // for GSM shield
    SIM900power(); // turn on shield
    delay(20000); // give time to log on to network. `
    SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
    SIM900.write(0x22);
    SIM900.write(0x0D);
    SIM900.write(0x0A);
    delay(100);
    SIM900.print("AT+CNMI=2,2,0,0,0\r");
    // blurt out contents of new SMS upon receipt to the GSM shield's serial out
    delay(100);
}

void SIM900power()
// software equivalent of pressing the GSM shield "power" button24
{
    digitalWrite(9, HIGH);
    delay(1000);
    digitalWrite(9, LOW);
    delay(7000);
}

void loop()
{
    // Now we simply display any text that the GSM shield sends out on the serial monitor
    if(SIM900.available() >0)
    {
        char *in = SIM900.read();
        if (in =="abcd") digitalWrite(3,HIGH);
        if (in == "00") digitalWrite(3,LOW);
    }
}


Does 12v 5A power supply is okay to operate motor shield external power

The shield will "burn". You need a shield that can provide minimum 5A per channel to run a 5A motor.

However, your motors aren't 5A. They have a stall current of 300mA, which is well within the capabilities of the motor shield, and the 5A power supply you have would barely even notice they were there.


millis and micros always returns 0 (or other constant)

millis and micros appear to use timer 0 internally. Using that timer to also generate a PWM signal messes with their ability to function properly.
The solution is to either use a different timer to generate the PWM signal, or to roll a custom equivalent of those functions.

Why does the official arduino documentation not specify that millis and micros occupy timer 0?
Why are there no Google results mentioning timer 0 when searching for "arduino millis returns 0", "arduino millis constant", "arduino millis not counting" and the like? (There are results with the same symptoms, but for different reasons.)
Who knows.


No, that will not do what you want. That will continuously rotate the stepper round and round and round.

The clue as to why is in the name of the function you put the myStepper.step call: "loop". That function repeatedly loops around over and over again, so your step function will be called over and over again.

There is one piece of information lacking from your thinking at the moment, and that is when do you want the stepper to rotate? If it's just once when you turn the power on then it's as simple as doing everything (including calling myStepper.step) in setup() and leaving loop() empty. If not, then you will need to add appropriate logic to only run the step function when the required conditions are met.


Bluetooth module vs wireless module Arduino

what is the main difference between HC-05 Bluetooth module and NRF24L0 wireless module?

The main difference is the protocol they use. While some attempts have been made with varying success to get the nRF24L01+ to emulate Bluetooth it is not designed for that. You can only really get rudimentary beacon mode working and that only partially.
nRF24L01+ modules can only communicate with other nRF24L01+ modules. They use their own proprietary protocol that is incompatible with any other system. That's not to say they're bad - they're great modules, and the same RF core and protocol is used in many many other devices by Nordic that are used all over the place - the most notable of which is wireless keyboards and mice.
The HC-05 though is a Bluetooth module which is designed to talk to anything else that also talks Bluetooth - such as your phone or computer. It presents an "SSP" profile and gives "master" mode operation to emulate a serial port connection between your Arduino and any other device that knows about Bluetooth and SSP.
The biggest difference in how they work though is when it comes to connecting devices together. Bluetooth devices have to be "paired" before they will communicate. nRF24L01+ devices don't. This means that getting Bluetooth devices to talk to each other takes a certain amount of time and effort, but nRF24L01+ devices are ready to go the moment they are powered on. It's then just down to your software to set up addresses and such to target the communication.
For Arduino-to-Arduino communication the nRF24L01+ is far less trouble as you set everything simply in your code. There are "LNA+PA" variant boards available that include an amplifier and antenna for longer range communication (I have had 300m+ out of those quite happily).
If you want to communicate with anything else, like your phone or computer, then you will want Bluetooth. Otherwise you will have to add an nRF24L01+ to your computer or phone through USB and (probably) another Arduino, which just gets messy.


Do addressable RGB's need to be programmed differently from normal RGB's?

These are much different than "normal" RGB LED: they use the WS2812 chip, which is the same as the chip used in famous Adafruit "neopixels" strips, rings...

Wiring is simple. For all LEDs:

GND to 0V
VDD to 5V

For the first LED (connected to Arduino):

DIN to any Arduino logical output pin
DOUT to the 2nd LED you want to address (on its DIN pin)

For all but the first LED:

DIN to the previous LED DOUT
DOUT to the next LED DIN (or left floating for the last LED)

Programming neopixel is quite hard because timing of sent commands must be very precise.

I highly suggest to use Adafruit libraries for that.


Where to find the attribution name for a certain board?

The Arduino defines to identify a board are in form of ARDUINO_<board>, where <board> is the value from <x>.build.board from boards.txt for board <x>

For example for Arduino AVR boards, in the boards.txt file is uno.build.board=AVR_UNO so the define is ARDUINO_AVR_UNO.

And Arduino has 'architecture' identification define too. This has form of ARDUINO_ARCH_<arch.name>. The <arch.name> is the uppercase version of the folder name with the boards package version. For example AVR for packages/arduino/hardware/avr/1.6.21.


Arduino voltage drop while communicating with another Arduino

the line DDRD |=_BV(PB0); should be DDRB |=_BV(PB0); currently PB0 is set as an input so when you set it high it is just turning on the pull-up resistor, which is basically adding another ~10k in series with the LED, hence the dim light.


What kind of antenna should i use for my esp8266 module?

You must use a WiFi (2.4 GHz) antenna. From the picture in your post, you have one of the esp8266 modules with a "built-in" antenna implemented via traces on the PCB. You cannot add an external antenna without removing the old one first, and even that will be very dodgy - you'll likely render your esp8266 useless for any purpose.

Instead, you could get an esp8266 that is made for connecting an external WiFi antenna. See the Wikipedia article for details. It specifically mentions model # ESP-WROOM-02U as having a connector for an external antenna.


Sending multiple data with SPI interface monitored by an Osciloscope

SPI.transfer(&test[i],4);

The SPI.transfer() transmit one byte each time and therefore expecting a pointer to a byte (i.e. uint8_t) while you are passing in an address of an uint32_t. What you need to do is to cast the address of uint32_t into a pointer of uint8_t before passing it into the SPI.transfer.
uint8_t *ptr = (uint8_t *) &test;

SPI.beginTransaction(SPISettings(20000000,MSBFIRST,SPI_MODE0 ));
digitalWrite(SPI_CS,LOW);
for (i = 0; i < sizeof(test); i++) {
  SPI.transfer(*ptr++, 4);
}
digitalWrite(SPI_CS, HIGH);
SPI.endTransaction();

Please also note that Arduino is a little endian machine, so if you have a data as 0x41424344, the first byte get transmitted will be 0x44.
One more thing, it is always good to call SPI.endTransaction(), it free up the SPI bus to allow other SPI devices to use the data bus.


How to upgrade ESP8266 NodeMCU SDK from V2.5.2 to V3?

The SDK is linked into every Arduino application you flash to the ESP8266 - it's not flashed separately.

Presumably you've already followed the instructions to put the URL for the ESP8266 Arduino Core in the preferences for the Arduino IDE.

Once that's there, to update the ESP8266 Arduino SDK, go to the Tools menu, select Board, then select the Boards manager (the first item in the menu).

That will bring up a dialog listing all the board families your Arduino IDE knows how to build for. You can limit the list to those with updates available by selecting "Updatable" in the "Type" field. Or just scroll down or search till you find the ESP8266 entry. Click it and if there's an update available you'll see an "Update" button appear on it. You can also reinstall older versions by choosing a version and clicking the "Install" button.

However, there is no version 3 as yet. At the time that I'm writing this, 2.5.2 is the most recent release of the SDK.


Seamlessly loop through LED's - Shift Register

You mean something like this? (untested):

void loop() {
  // use static or global variables to remember positions (these are initialized only once):
  static uint8_t hi_pos = 0;  // where HIGH should be set
  static uint8_t lo_pos = 21; // where LOW should be set

  setRegisterPin(hi_pos, HIGH); // turn on led in head
  setRegisterPin(lo_pos, LOW);  // turn off led in tail
  writeRegisters();             // update registers

  // ensure it won't overflow:
  if (++hi_pos == 24) hi_pos = 0;
  if (++lo_pos == 24) lo_pos = 0;

  // or:  hi_pos = (hi_pos+1) % 24;  // but divisions are slower on AVR

  delay(100);
}

It will go in sequence:

ON  OFF
 0   21
 1   22
 2   23
 3    0
 4    1
...
22   19
23   20
0    21
...

forever


Part of Board exploded when Peltier Plate was wired t(o Board

You did a pretty good job of nuking your board. Gratz.
Basically what has happened: you connected 19V to the input of the 5V regulator (rated at 800mA max) and connected a 12V 50W device to the output.
I have no idea what a peltier will do when under powered, but at 12V it's going to want about 4A. That's 20x more than the 5V regulator can provide (also exacerbated by the massive amount of heat needed to be dissipated to drop 14V) - so it went pop.
In going pop it short circuited. That meant that 19V (or just short of) ended up going into the rest of your Arduino. The 3.3V regulator didn't like that (the bit that looks toasted), and neither will any of the rest of the components on the board.
In short: probably almost every component on the board has been nuked.
The moral of this story: don't connect high powered 12V devices direct to the Arduino. Things like peltier devices need their own dedicated power supply which can be controlled (as you would a motor or relay) through a power MOSFET.


No, connecting it backwards shouldn't do any damage, it just won't work.  The clue is in these two connections:

NC      -|-  GND
GND     -|-  NC

With it backwards the ground connection doesn't go anywhere.  Without that ground connection there's no circuit.  With no circuit, no current flows.

The only possible danger is to the protection diodes in the IO pins when you try and operate the programmer.  The lack of a ground connection could cause some current to flow the wrong way through the circuit (in through the ATMega's MISO pin and out through the MCU's Vcc pin) through the ESD protection diode.  That could cause damage to that diode and maybe the rest of the MISO pin's logic, but it's not that likely since the currents involved would be somewhat limited by the route the power then takes through the MISO pin of the programmer.


The easiest method I know to do this would be to use a "C"-style wrapper for the member function call. This is in fact done to interface C callbacks with C++ objects.
You could do it like this:
struct Blinky {
  //state etc.
  bool isOn() { return /* something useful */ true; }
};

// The "C" wrapper for the callback
bool Blinky_callback(void *vblinky)
{
  return static_cast<Blinky*>(vblinky)->isOn();
}

struct MyClass {
  void add_callback(void *obj, bool (*callback_method)(void *), byte behaviour) {
    // ...
    bool result = callback_method(obj);
    // ...
  }
};

// Globals
MyClass c;
Blinky b;

void setup() {
  c.add_callback(&b, Blinky_callback, 0);
}

A slightly tidier way with a static member (functionally identical):
struct Blinky {
  //state etc.
  bool isOn() { return /* something useful */ true; }

  static bool callback(void *vblinky) {
    return static_cast<Blinky*>(vblinky)->isOn();
  }
};

// ...
c.add_callback(&b, Blinky::callback, 0);

Other variants would be using inheritance and virtual functions.
// Abstract base class
struct Sensor {
  virtual bool do_check() = 0;
};

struct Blinky : public Sensor {
  bool do_check() override { return true; }
}

Then you can have your add_callback look like:
void MyClass::add_sensor(Sensor *sensor) {
  // ...
  bool result = sensor->do_check();
  // ...
}

This is relatively nice to code with, and the compiler has a fighting chance at keeping your code typesafe, if all the "things" you want to control can conform to the same interface. The virtual dispatch won't cost much more (if anything) than the static wrapper in the previous example. You "pay" a few bytes per class and one pointer per instance for the virtual table though.
More modern techniques would involve templates and/or lambdas, or perhaps std::function, but all that seems overkill if your need is as described (and might generate a lot more code than you're expecting, or do dynamic allocations for std::function which is best avoided in context).

Remark: if you want to do it with (non-static) member function pointers, it is possible but the syntax is hairy:
void add_callback(Blinky *obj, bool (Blinky::*callback_method)(), byte behaviour) {
  // ...
  bool result = (obj->*callback_method)();
  // ...
}

And you're tied to that class. Unless you make add_callback a template, but beware extra codegen.


wifi failled connection with yun and after upgrading openwrt

Find out if the Linux system is running. Maybe you mistyped your WiFi password.
Try the Following:

connect via Ethernet check your router to see if the Yun request an IP via DHCP
If unsuccessful connect via USB and install this sketch to see if you get a command prompt maybe your network settings are messed up

Still no success?

Press the WiFi reset button for at least 30 seconds to do a reset to
factory defaults.


How to calculate required amperage of multiple motors?

I don't know if the amperage is additive with each additional motor

Yes, amperage is additive.

the Arduino cannot handle over one amp but 0.24*5>1

That is correct. But the stepper motors should never be powered through the Arduino. You should connect a fitting power supply directly to the stepper drivers. That way the needed current flows past the Arduino, not through it.

What voltage and amperage I need to supply to my Arduino for everything to run properly?

The Arduino runs at 5V, though you can provide 7-12V to Vin/barrel jack. When your motors are rated for 5V, you should provide them with 5V. So it would be fitting to buy one 5V power source to power the Arduino (through the 5V pin or USB) and the stepper drivers.
For the current: A good measure is the stall current of a motor, so the current, that flows, when the motor is driven, but cannot move (due to being physically stuck). Add a bit headroom to this. The mentioned motors are often badly documented, so that you might not be able to find a stall current value. Add more headroom in that case. So I would suggest adding up all the amps and then multiply this value with 1.5 or even 2. Let's take 250mA per motor (for ease of calculation) with 5 motors gives 1.25A. Take at least a 2A power supply. When you want to make sure go directly to 3A. The price difference in that range isn't that much anyway.


Try without

- '0'

You read your data and save into in int. then print that int, when you pass only the int, you get the int as an ASCII-encoded decimal.
Why r u doing

- '0'

?


I fixed the issue by swapping pin D4 and D8, and then setting up the MFRC522 at the very start of the program. I originally set it up before I started using it, which caused the color to change during the first scan.


I'm unable to provide a complete answer yet but my research so far into a similar quest to use a similar remote can at least answer why you are getting two values for the same button on the remote. This is by design: the Nokia-32 RCMM protocol of this remote uses toggling codes that flip between one value and another on alternating presses of the same button.

My quest and the challenges of decoding this remote are documented in this thread: https://github.com/bengtmartensson/harctoolboxbundle/issues/97 where I discover that my IR remote uses Nokia 32 protocol but with mark and space timings slightly different from what most Arduino libraries are programmed for requiring a tweak to the signal in order to enable other libraries to decode it successfully.

Further information here: http://www.avsforum.com/forum/93-remote-control-area/1517341-theater-master-mx-500-remote-won-t-learn-bell-fibe-remote-any-help.html#post24345872 where we learn:

  it is different from most IR signals, because it has 4 different off durations, denoting zero, one, two , or three, while traditionally IR protocols have used just two off durations signifying zero or one.


Using TFT with hardware SPI and speaker with tone()

You are getting your wires crossed in your brain and imagining a problem where there is none.

Both PWM on pins 3 & 11, and tone(), use the Timer2 device. Only one of those can use Timer2 at a time, and they both want to use it in different ways, so there is a conflict between them.

Timer2 has nothing to do with SPI. So tone() has no effect on SPI, and nor does PWM have any effect on SPI (other than the fact that only one can come out of pin 11 at any time), since there is no internal resource conflict.


What are the AREF, IOREF, and the unlabeled pin next to IOREF on the Uno R3?

AREF:

This is the voltage reference analog-to-digital converter (ADC). It can be used instead of the standard 5V reference for the top end of the analog spectrum – for example, if you wanted to use the ADC to monitor a signal that had a 0-1.5 volt range you could get the full scale of the ADC by connect AREF to a 1.5V signal. DO NOT CONNECT A SIGNAL OUTSIDE THE 0V TO 5V RANGE!

Note that in order for this to work, you must run analogReference(EXTERNAL); before using analogRead(). Also:

  After changing the analog reference, the first few readings from analogRead() may not be accurate.

Fore more information, see AnalogReference.

IOREF:

This is a voltage corresponding to the i/o of that board, for example an Uno would supply 5v to this pin, but a Due would supply 3.3v. Sending a signal to this pin does nothing.

Unlabeled pin:

This pin is unused, but is there to ensure compatibility with future products. It is not connected to anything on any R3 boards I have seen.


How to troubleshoot the Arduino Mini and Arduino usb2serial?

As always, it makes sense to check the parts in isolation, if possible.

Host system (Linux):

Tail the system log for errors
Check that ModemManager does not occupies the /dev/ttyACM0 device

USB2Serial:

Connect it via USB to the host without anything else connected -> the ON-LED should be on, the RX/TX LEDs should be off, the system log should display some udev progress messages (including vendor ids), the system should have a new serial device, e.g. /dev/ttyACM0
Open the serial port with a terminal (e.g. via minicom -D /dev/ttyACM0 [-b baudrate], disable local echo and type something -> nothing should be displayed
Connect the RX/TX pins to each other with a jumper cable -> typing in the terminal session should now result in rapid flashing of the TX/RX LEDs and the echoing of the text

Arduino Mini:

Connect just the minimum, e.g. just power from a 9V battery/5V power supply and the reset pin to +5 (with a 10KOhm resistor in series) -> the power-on led should turn on
The chance is high that the device comes with a pre-flashed blink examples that either uses pin 12 or 13 -> connect external LEDs to pin 12 and 13 (in series with 220 Ohm resistors) -> one LED blinks after power on
Hit the reset button on the mini -> any LED blinking should stop for a while and then continue

Arduino Mini with USB2Serial:

Make sure that both RX/TX pairs are crosslinked (like a nullmodem cable), i.e. RX <-> TX and TX <-> RX.
Follow the mini guide on arduino.cc or arduino.org it includes a picture of the cabling
Verify that the capacitor connected between the USB2Serial 'ext reset' pin and the Mini reset pin has a capacity of 100 nF, otherwise, the auto-reset might not work
In case the automatic reset does not work, press the on-board-reset-button just before the upload
In case the error persists, check for dodgy cables with a multi-meter

IDE:

Make sure that it works with 'easier' stuff, e.g. flashing to a Uno (the Uno is easier because the USB-2-Serial part is integrated)
Enable verbose logging during upload (in the preferences)
Update the IDE in case it is very old


No, it's not possible as you describe it.

The Arduino's main chip, the ATMega328p, is what is known as Harvard Architecture.  This means that the Flash memory and RAM both occupy completely separate memory address spaces.  The CPU in the chip is only able to fetch its instructions from the memory space the Flash is connected to (the Instruction Bus) and not the memory space the RAM is connected to (the Data Bus).  This means it can only run instructions that are in Flash and not RAM.

It is possible to re-program the flash on the fly - after all, that's what the bootloader does, and while the actual act of reprogramming flash is fairly trivial, generating the instructions in the right way is far from trivial.

There are other options though.

Use an interpreted language.  I believe there are versions of BASIC available for the Arduino that would allow you to upload a program through the serial port and execute it.
Define a protocol (or use an existing protocol) to send pre-defined control commands to the Uno.  Firmata might be of use here.


This will effectively connect the pin to ground. Note that the connection is
made by a transistor that has a finite resistance. This output resistance is
not really specified, but from the curves on the “typical characteristics”
section of the datasheet you can infer that the typical value is about
26 Ω.

The only hard specification states that the OUTPUT LOW voltage
should be no larger than 0.9 V, as long as the pin is not sinking
more than 20 mA. C.f. the table “DC characteristics” of the
ATmega2560
datasheet.


How can I upload a sketch remotely from a distant location onto an arduino that is power by a battery

Battery powered devices need a system where the device checks over Internet connection (WiFi, mobile) if a new firmware bin file is available on a specific location on a server. If the bin file is available the device can download it and apply.

One option how to apply the new bin is to use SD card and SD bootloader (Zevero avr_boot) The sketch saves the downloaded file on SD card and resets the MCU. The SD bootloader then loads the binary from the SD card to flash.

Other option if enough free flash memory is available is to use the InternalStorage object from ArduinoOTA library. It uses the upper half of the flash memory to store the uploaded bin and then activates a modified Optiboot to copy the bin to run location and reset the MCU.


Connect to Arduino 2560 using a RS232 Connection

Yes, perfectly possible.  You need an RS-232 interface chip - the most common and well-known of these is the MAX232. You can get them as breakouts on eBay.

That interfaces between the DB9 and pins 0/1 (or other UART comms pins) on the Arduino.

If you are wanting to program the board through it you will also need to connect (after converting the voltage through the MAX232) the DTR line to RESET through a 100nF capacitor.

... Exactly like you would with a breadboard Arduino.


Issues on Arduino, LiPO battery and two mottors setup

If the load on the two motors rise, could the Arduino be damaged by this current increase?

No, the motor current doesn't pass through the Arduino. It is completely separate.

  Is the voltage too high for the Arduino handle?

Borderline. The regulator (a lowly 7805) may well get very hot at that voltage (depending on the Arduino's current draw) and go into thermal shutdown.

  Is there any more issues that this setup can have?

Maybe add a small buck regulator to the 5V pin instead of using the on-board linear regulator. That will not overheat and will be far more efficient making your batteries last longer. Often marketed as "UBEC" (Universal Battery Elimination Circuit) and used throughout the model vehicle industry these are very easy to get hold of and are ideal for powering things like Arduinos from batteries like this.


I would like to control 16 motors with a servo shield

The code in loop is called repeatedly. Thus it does this:

Go from SERVOMIN to SERVOMAX very rapidly (I measured 72 ms)
Pause half a second
Repeat the above

To make it pause at SERVOMAX you need to either not repeat the loop, or put it all in setup, eg.

#include <Adafruit_PWMServoDriver.h>
#include <Wire.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define SERVOMIN  150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  600 // this is the 'maximum' pulse length count (out of 4096)
void setup()
{
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++)
  {
    pwm.setPWM(0, 0, pulselen);
  }

}

void loop()
{
}


This is completely acceptable for your intended purpose.

By itself it will act as a light on/off trigger as others have noted.
An Arduino could be added if you wish to add extra features when the PIR is triggered. In it's most basic light-switching form using an Arduino is overkill.

By itself it will act as a light on/off trigger as others have noted.
An Arduino could be added if you wish to add extra features when the PIR is triggered. In it's most basic light-switching form adding an Arduino is overkill.

When it comes to playing overkill can be good :-)

To use it to provide input to an Arduino and NOT to a mains level light:

NB relay contacts may only be connected to mains for light switching OR to the Arduino. NEVER to both at the same time.

Connect it's DC supply input to your Arduino (or other) power supply.
As long as the supply can provide 40 mA when needed it will work OK.
40 mA is a power supply rating This is unrelated to the Arduino pin loading.

Connect the output to an Arduino digital pin configured as an input.

The output is a relay, activated when an object is sensed.
When inactive the centre pin is probably connected to the right pin - Check with Ohm meter.

When activated the left pin in connected to the centre pin (see their diagram)

Connect ground to right pin.
Connect Arduino digital input to centre pin.
Connect a "high" level to left hand pin.
OR as Majenko suggests, just set the pin to have pullups enabled.

If connecting to V+ as shown then V+ can be Vcc  (=5V for a 5V Arduino, 3v3 for a 3V3 Arduino)
DO NOT set V+ to higher than Arduino's Vcc.
You can connect a say 1k to 10k resistor from V+ to the voltage source bur still do not set V+ above Vcc.
OK - just have pullups enabled:-)

eg (untested)

  int ADCMode = 0;
   int PIRPin = 6;                 // PIR connected to digital pin 6
   void setup()
   {
     pinMode(PIRPin, INPUT_PULLUP); // set PIRpin as input with pullup
   }
   void loop()
   {
    ...
     ADCMode  = digitalRead(PIRpin);   // $Read PIR status
   ...
   }

When the circuit activates digitalRead() will return a high.
When the circuit is not activated digitalRead() will return a low.

See here re Arduino pin modes


Serial communication and Arduino program in C

When using the Arduino core library, you normally do not write a
main() function. Instead, you write setup() and loop() and rely on
libcore's provided main() for calling them.

If you nevertheless want to provide your own main(), then you should
call init(); (with no arguments) before you try to use the library.
Adding this single call makes your program work on my Uno.

However, since it does not seem to be officially documented, this trick
may not be safe against upgrades in the core library. Writing setup()
and loop() should be more future-proof.


All the interrupt does is count. It has no concept of time.  For instance:

volatile uint32_t revolutions = 0;
void count() {
    revolutions++;
}
....
attachInterrupt(0, count, FALLING);

will just count up 1 every time the interrupt triggers.

To be able to convert that count into something meaningful you have to manually introduce the concept of time - that is, the count of "revolutions" (for example) between two points in time.  And it's up to your sketch to implement that.

The simplest way may be:

// For anything more than an 8 bit value on an 8 bit machine
// make a critical section to save and reset the count
cli();
uint32_t savedResolutions = revolutions;
revolutions = 0;
sei();

Serial.print(savedRevolutions);
Serial.println(F(" revolutions per second"));

// Introduce the concept of time - this will
// make it get the count once a second.
delay(1000);

Of course, instead of delay() you can use millis() in much the same way as the BlinkWithoutDelay example in the IDE.

It is possible (as long as you're not counting too fast) to incorporate the time element into the interrupt routine by keeping track of the time in a variable:

volatile uint32_t rps = 0;

void count() {
    static uint32_t revolutions = 0;
    static uint32_t timestamp = millis();

    revolutions++;

    if (millis() - timestamp >= 1000) {
        timestamp = millis();
        rps = revolutions;
        revolutions = 0;
    }
}
....
attachInterrupt(0, count, FALLING);

Then you can just reference the rps variable at any time to get the revolutions per second. Again it should really be queried inside a critical section to prevent the value being changed while you're actively reading it...

cli();
uint32_t myRPS = rps;
sei();

Serial.print(myRPS);
Serial.println(F(" revolutions per second"));


Can I run 3 devices on Arduino Uno with different power sources?

Your question is 2 fold:

Power requirements: The actual power requirement depends on the devices, but the Arduino will certainly not be able to provide power for a heating lamp. It just cannot provide that much current (you would fry the Arduino). But the Arduino is also only powered from outside. I guess you have a power source, that can provide enough power for all the devices. Then you can connect these devices in parallel to the power source (meaning + and - of the heating lamp power goes directly to the power supply). That way the current for the devices doesn't flow through the Arduino. The Arduino will only use control signals, which don't have high current. Sensors are normally either analog sensors (which connect to the analog pins with only neglectable currents) or use communication interfaces, which are also ok. The current hungry output devices (humidifier and heat lamp) either have a digital control pin, a communication interface, or they must be controlled via a relay (depends on the actual devices).
Controlling all the devices: The Arduino can only do 1 thing at a time. But that is no problem, since you can do things sequentially very fast. For example write one function for every device, that you want to control. In that function you communicate with/control the device according to some variables (like the measured temperature). The loop() function can then look as simple as:

void loop(){
    measure_temperature();
    measure_humidity();
    measure_soil_hydration();
    control_humidifier();
    control_headlamp();
}

If you want to only do this periodically (not all the time), you can either add a delay() or - better - use millis() like in the BlinkWithoutDelay example (there are also many tutorials about millis() on the web). Make sure, that the individual functions are not blocking. They should do, what they need to do, and exit quickly. No long staying in loops or waiting for an event there.


How can I wire a 12V LED switch so that it is powered, but my Arduino only receives a 5V signal?

You need a voltage divider:

The formula is:

V1 = 12V

R2 = 5V max

R1 = The rest (V1-R2)

And then you have to calculate max current. If you use 1/4watt resistors, you have to convert watt to current, P = U x I.

Pmax = 0,25W

R1volt = 7 volt

Imax for R1 = P/U = 0.25/7

Imax for R2= P/U = 0.25/5

Now you have the current and voltage for R1 and R2

And the relation between R1 and R2 is:

R1 = 7/12 x Rtotal

R2 = 5/12 x Rtotal

Rtotal = R1 + R2

simulate this circuit – Schematic created using CircuitLab


This issue has been resolved.  There was an issue with the parity and stop bits.

When setting up for arduino comms, remember, baud rate, 1 stop bit, 0 parity bits.


How can I run the arduino IDE 1.8.9 on debian testing as regular user?

It turned out, that the current Arduino IDE is using a directory ~/.arduino15 for data. I was not aware of the existence of it. The comments to my question made that clear. I tried to delete the ~/Arduino and ~/.arduino direcory several times, but to no avail. Deleting ~/.arduino15 indeed fixed the issue.


ESP8266 spend 10mA, even though It is in the deep sleep mode

ESP.deepSleep(60e6, WAKE_RF_DEFAULT); Try this code, it should decrease it a bit.


Just check the sourcecode

for (;;) {
    loop();
    if (serialEventRun) serialEventRun();
}

So it does a check if serialEventRun is True, and then a jump back to the beginning of the for-loop. And then a call to loop.

Also note that Serial.print is blocking if the TX-buffer is full. So you might want to add a delay somewhere to ensure the buffer is never full.


Since your values are all constant you can define them all as constant values and just select between them. The simplest way is to add an extra dimension to your arrays:

const char pins[2][13] =
    {'O','O','I','I','O','I','I','I','I','O','I','I','O'},
    {'O','I','I','O','O','I','O','O','I','O','I','O','I'}
};

for(byte i = 0; i < 13; i++) {
    if(pins[mode][i] == 'I') pinMode(i, INPUT);
    else pinMode(i, OUTPUT);
}

(Note: An array of size 13 has entries 0-12.)

However, that is very inefficient.  Since you only have two states, I and O, and there are only 13 entries, you can store each array as a single 16-bit value:

const uint16_t pins[2] = {
    0b0110111101100,
    0b1010100100110
};

for(byte i = 0; i < 13; i++) {
    if((pins[mode] & (1 << i)) pinMode(i, INPUT);
    else pinMode(i, OUTPUT);
}

(Note: the data is stored backwards - pin 0 is on the right, pin 12 on the left.)


This adds some end of string characters.

if(Xstr[XstrLength-1] != '|'){
    Xstr[XstrLength] = '|';
    Xstr[XstrLength+1] = '\0'

First it checks if Xstr last character is a '|', if not:
   Place a | directly after the last character
   And append a '\0', which is a symbol to 'end' a string

A string in C/C++ is normally build up like this, e.g. "Hello" contains of the bytes:

'H', 'e', 'l', 'l', 'o', \0

Where each of the above are ASCII characters/values and the last \0 a 0 byte.

char Xstr[60]; defines a character array (string) that can contain 60 characters. Note however, that the ending \0 also needs to be in this string, so you can actually only put 59 characters inside.
itoa(Yint,Ystr,10); converts Yint which is an integer value to a string (where each digit has each own byte), and 10 is the length.


Is there anything special about Arduinos?

This is Google Trend of Arduino (blue) versus four other boards: STM32 (red), Teensy (green), MSP430 (yellow) and PIC32 (magenta).

That means lot of people using Arduino, making hardware and software, writing blogs, answering questions. That's the biggest plus of Arduino.


To do this, you essentially have to code up a version of the Arduino serial monitor within Java (i.e. write Java code to listen to a serial port and recieve bytes from it).

I found an example that might help you-https://playground.arduino.cc/Interfacing/Java


Program crashes when I use Serial.println()?

You should have provided your full Arduino code. Without setup() part of Arduino code, we can not exactly tell what might be wrong. Please provide it and I'll revise my answer as well.

Check if you have this code in your setup() function:

Serial.begin(9600);

9600 is baud rate and it could be any other supported baud rate(you can see those by opening a Serial monitor and clicking on 9600 baud rate on bottom right edge).

Related to to comments above, from experience and it can be easily "counted", RAM shouldn't be a problem in such short code.


DFROBOT I2C 16x2 Arduino LCD Display Module I2C communication interface

Here is schema how to connect it and example how to use it, also link to needed library. Hope this helps.

https://www.dfrobot.com/wiki/index.php/I2C/TWI_LCD1602_Module_(SKU:_DFR0063)

Anyway - I2C is prettty standardized interface, so googling any I2C schema for your type of Arduino will work as for connection - just connect SDA (A4) to SDA, SCL (A5) to SCL, GND to GND and VCC to VCC as writen on the module interface.

There are also lots of correct results for googling the module name - just google SKU:DFR0063 and you get many of correct links. On first page every second link contains link for the library, those others just refers to the manufacturer in text.


How to create a log file document which is not editable by a word processor on SD card

There is no such thing as a file that cannot be edited.

If a file can be read it can be edited.

However, there are ways of making it possible to know if a file has been edited - i.e., to integrity check the file. To make it hard to edit a file and maintain the intrinsic integrity of the file.

The simplest method is to create a checksum of the data in the file and store that in the file as well. If the data is, for example, a CSV file, you could include in each row a checksum of the data in that row as an extra column. If the data gets changed the checksum will no longer match. Of course, that doesn't preclude someone calculating the new checksum and entering that.  So maybe adding a checksum of all the checksums at the end of the file as well so you know if any checksums have changed.

Again, it's possible for someone to recalculate that checksum as well.

The most secure method is to digitally sign the file (in the way the PGP or GnuPG does). Without the private key, it's impossible to re-sign the file after modification. However, that kind of operation is comparatively heavyweight and not something an Arduino is particularly suited to doing (I'm not sure if it's even physically possible given the lack of resources an Arduino has).


Ethernet.begin() conflicts with build-in LED on Arduino Nano

No, you can't.

The LED is on pin 13. Pin 13 is the clock pin for SPI. The ENC28J60 is an SPI device.

You either have control over pin 13, or you have SPI. You can't have both.


Trouble reading LM35 with long (?) Ethernet connection

The LM35 has trouble driving any kind of capacitive load, so the long runs of cable are generally not a great idea if you are relying on a voltage signal. The datasheet for it (The one I have is from the Texas Instruments website), has a few strategies to reduce this problem somewhat.

The approach that I have used successfully, is to use a current signal, rather than a voltage signal. This has the advantage that you only need a two wire twisted pair cable (I made my own twisted pairs - it is easy for relatively short runs).

The idea is that you connect the LM35 output to the ground pin with a known resistor value (the datasheet example has a 200 Ohm resistor). Since the voltage is 10mv per degree, the current wil be 10/R mA per degree. There will be an additional small current from the LM35 device itself, but this is small, and almost constant. Then connect the supply and ground to one end of your twisted pair.

At the other end, it is necassary to convert the current signal back to a voltage so that your Arduino can read it. Simply put a resistor (again, 200 Ohms is that used in the datasheet example) between the low side of the twisted pair to OV, the high side connected to 5V, and measure the voltage across this resistor.

Figure 17 in the TI datasheet is the one to follow.

Other things that help to get more stable, acurate readings;

Choose a time to take readings when you are not running anything else that might interfere (wireless comms, ultrasonic sensors, motors, solenoids, etc).

Take several readings. Ignore the first two.

Take the median value of the remaining readings (eg take 5 readings, ignore the first two, and sort the others in order. Then take the middle value.).

Hope this helps.


How to measure resistance of TFT Touchscreen

As pointed out in other answers and comments, step one was trying to get a datasheet for this component. I couldn't find a datasheet for the shield, but here is the link from the vendor I bought it from, and they provided with some articles were they explained how to perform the resistance measure. However, I then noticed the answer was in the example code itself.

Btw, the shield it's indeed based on SPFD5408 as correctly suggested by user Michel Keijzers on his answer.

So, in turns out the hint to which pins were X+ and X- was actually in the example code I'm using. Here the Touchscreen object is initialized:

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Notice the usage of constants XP and XM. The names stand for "X-plus" (X+) and "X-minus" (X-). Now if we look a couple of lines above where these constants are defined, we see this:

#define YP A3
#define XM A2
#define YM 9
#define XP 8

In particular, we see that XM (i.e. "X-") is mapped to analog pin A2, and XP (i.e. "X+") is mapped to digital pin 8.

Now, by looking at how the shield couples with arduino, we can see that analog pin A2 of the Arduino board, connects with pin labeled "LCD_RS" in the shield, and that pin 8 connects with pin labeled "LCD_D0".

This is a picture (found online) of the bottom side of the shield, were we can see the labels for each pin:

Finally, with a multimeter at those pins, I measured the resistance and it was 292 Ohms. Not so different from the default of 300 in the library, but it's still a good thing to have the correct value.


Why does my servo twitch and turn on its own?

If it does what you expect when the button is pressed, but behaves unpredictably when released, you almost certainly have a floating input.

See Switches tutorial.

In particular, this is a no-no:

Random fluctuations in voltages will make the switch read HIGH and then LOW, and your servo will chase around trying to change positions.

The simplest fix (without changing anything else) is to add a pull-down resistor between the pin and ground, so now the pin reliably reads LOW when not pressed.

Other methods are discussed on that page, including debouncing.


Issue with CD74HC4067 MUX on high values

I don't think you should leave s2 and s3 floating. A floating pin does not mean nor 0 nor 1.

Connect them both to ground.


Is it possible you connected the 12V to the 5 volt pin. This would probably blow the port on windows and destroy the arduino but it appears you got lucky with the arduino. Try something else not related to the Arduino stuff after powering down and restarting the windows computer. If that does not work the odds are high the Windows port is blown. If it now is working try again you may be all set.


Any good C manual will tell you the result type for each basic math operation on given types. But briefly, the basic math operators return a result as wide as the widest operand, with the narrower operand being widened to match the wider one, if they differ. The same with assignment: assigning a result of a given type to a variable of the same type will not involve any conversion.

tl;dr: No, you're not missing anything. You don't need any casts in your example.

PS: One thing you do need to be aware of is whether any of your intermediate results will overflow the arithmetic type you're using. For example, the final result may be not exceed an unsigned long but the expressions (burnTime + curBurnTime) must also not exceed it. This is a greater concern with smaller data-types, of course.

PPS: Good on you for tackling fixed point arithmetic rather than just reaching for the floating-point library!


How to split a binary data to form two split binary data?

You can use the bit shift and and operator, like:

uint32_t data = 0xFFFF0001;

The following line will shift all bits 15 places to the right, meaning the least significant 15 bits will be removed, and the other bits shifted to the right.

uint32_t dataLeft = data >> 15;

11111111111111110000000000000001
>>>>>>>>>>>>>>>11111111111111110000000000000001
| Bit shift   || orig. bits    ||Removed bits |

For the other 15 bits,  you can use the and operator, which just makes all 1's 0's for those bits not in the bit mask (0x7FFF).

uint16_t dataRight = data & 0x7FFF;

value:              11111111111111110000000000000001
bit mask (0x7FFF):  00000000000000000111111111111111
                    -------------------------------- & / AND
                    00000000000000000000000000000001


Cheapest and easiest Arduino board for 12 bit ADC, thinking of M0

Use a Teensy 3.x. Those have 13 bit ADCs


How can I read the data stored in EEPROM although is powered OFF based on the simple code I wrote?

increase is a global variable and will implicitly initialized with the value zero. Then you are reading the EEPROM data into the variable storagedata in setup(). And then in loop() you are increasing increase from zero to one and write that to EEPROM. This value then gets read back into storagedata. So now increase and storagedata have the same value: one. So the counting begins on every reset at 1.
It is unclear, why you even have 2 variables for this. One would be enough (unless you want to test the EEPROM for some reason). In setup() read the data into increase. Then the counting starts with the number in EEPROM.


Stepper motor driver not working properly

The "metal screw" is a "trim potentiometer" that is used to set the current used to drive the motor. It sounds like you may be altering the current when you push against it. Try turning it to different angles to see what effect that has on the motor.
Alternatively if it only ever works when you push on it then it could be that you have a faulty potentiometer on your board.


POWER_MODE_IDLE wake on any input change?

As I mention on my page about interrupts you can use pin-change interrupts on the Atmega328P to wake from the deepest sleep mode (SLEEP_MODE_PWR_DOWN).

Example code:

#include <avr/sleep.h>

const byte LEDLOOP = 8;
const byte LEDWAKE = 9;

ISR (PCINT1_vect)
 {
 // handle pin change interrupt for A0 to A5 here

 // toggle LED
 digitalWrite (LEDWAKE, !digitalRead (LEDWAKE));
 }  // end of PCINT1_vect

void setup ()
  {
  pinMode (LEDWAKE, OUTPUT);
  pinMode (LEDLOOP, OUTPUT);
  digitalWrite (A0, HIGH);  // enable pull-up

  // pin change interrupt
  PCMSK1 |= bit (PCINT8);  // want pin A0
  PCIFR  |= bit (PCIF1);   // clear any outstanding interrupts
  PCICR  |= bit (PCIE1);   // enable pin change interrupts for A0 to A5

  }  // end of setup

void loop ()
{

  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  sleep_mode ();

  // flash to indicate we got out of sleep
  digitalWrite (LEDLOOP, HIGH);
  delay (100);
  digitalWrite (LEDLOOP, LOW);
  delay (100);

  } // end of loop

This has the advantage of consuming very little power while asleep, and also waking on any pin (of an Atmega328P).

Running on 5V at 25°C you should only consume around 150 nA of current while asleep (on a "bare bones" board without USB chip, voltage regulator or power LEDs).

Other sleep modes may use more power but wake more quickly.


Which of the clock sources are actually internal to the ATmega328P?

If it requires a crystal, as the ones in question clearly state, then obviously you need to connect a crystal (and load capacitors).  Or use a ceramic resonator.

Only those labelled as internal are internal. Everything else is external.


Do some variables not hold their value when a while loop is exited?

variables declared outside of a loop will be accessible inside the
  loop, modifiable within the loop, and hold their value when exiting
  the loop

This is correct.

  in this case that doesn't seem to be happening.

It is happening. The reason it looks like it doesn't is that
book[bookNum] is a pointer: the address of some data in memory. You
can check that the pointer does hold its value by printing it:

Serial.println((uintptr_t) book[bookNum]);

However, the statement you used:

Serial.println(book[bookNum]);

has a different meaning. It doesn't print the value of the variable
(i.e. the pointer): it prints the characters that are stored at the
pointed-to address, up to and excluding the first NUL.

Your problem comes from the fact that when you declare

File entry =  root.openNextFile();

you have a variable that is local to the loop. Then, when calling the
method

entry.name()

you get a pointer to an array of characters that belongs to the entry
object. This pointer is only valid as long as the object is in scope. As
soon as it gets out of scope (at the end of each loop iteration), the
entry object is destroyed and all memory belonging to it is released.
At this point the pointer you saved is a “dangling” pointer: it points
to an area of memory that has already been deallocated.

The proper fix is to allocate yourself the memory you need to hold the
character arrays, as in:

for (int bookNum = 0; bookNum < amtBooks; bookNum++) {
    File entry = root.openNextFile();
    if (!entry) break;
    const char *name = entry.name();
    book[bookNum] = (char *) malloc(strlen(name) + 1);
    strcpy(book[bookNum], name);
    Serial.println(book[bookNum]);
}

If you know in advance the maximum length of a book name, you could
follow the advice of Jot and Juraj and statically allocate the maximum
space you may need. That would be safer in terms of memory management.


decomposition long number to byte and recomposition With FRAM

There is one very obvious error in your code: You are writing the long
number LSB (least significant byte) first: the LSB goes at address 3 of
the FRAM, while the MSB (most significant byte) goes at address 6. You
reconstruct the number with

longRicomposto = ((longPt4 << 0) + (longPt3 << 8) + (longPt2 << 16) + (longPt1 << 24));

which puts longPt1 (contents of address 3) as the most significant
byte. Thus you are swapping all the bytes around.

Then there is a more subtle error. longPt1 is a byte. According to the
C++ promotion rules, it is implicitly promoted to int before any
arithmetic or logical operation. But since an int is 16-bits, you are
shifting all the bits out when you do longPt1 << 24. You should cast
the numbers to a 32-bit type before shifting, as follows:

long longRicomposto = (uint32_t) longPt1 <<  0
                    | (uint32_t) longPt2 <<  8
                    | (uint32_t) longPt3 << 16
                    | (uint32_t) longPt4 << 24;

Note that I am casting to an unsigned type. Shifting a 1 into the bit
sign of an integer is undefined behavior in C++: the shift must be done
with an unsigned type, then, if needed, cast to a signed type.


How to light up all LEDs of a 7x5 LED matrix?

You don't need an Arduino for that, and one will give you no benefit.

Connect all anodes to power, and all cathodes to the appropriate resistors, then ground.


Can I connect a NEO-6M GPS Module and ESP8266 to the same Arduino?

You can use Software serial for this.

and assign pins like
SoftwareSerial mySerial(2, 3); // RX, TX

This is a link for better understanding https://www.arduino.cc/en/Tutorial/SoftwareSerialExample


There is no easy solution. The Arduino you are using does not support
double precision floating point. The type double is just an alias for
float, which has 24-bit accuracy.

Your program is actually giving you the correct result, as the float
closest to 4815.98450 is exactly 4815.984375.


Should I use motor driver or Motor driver shield?

The right driver module or shield depends on the motor. Do you know the voltage and the stall current of the motors ?

The L293D uses bipolar transistors for the output stage inside the chip and can only drive 600mA. It has a large voltage drop: the motor gets less voltage than the power voltage applied to the driver. Therefor it can be used with small 12V motors, but it does not work very well with 6V.
The L298N also uses bipolar transistors and also has a large voltage drop.
A mosfet driver like the DRV8833 works better with 6V, because it has a low voltage drop.

In small RC toys with four AA batteries, sometimes a H-bridge is made is transistors instead of using a special driver chip.

The very cheap motor shield with two L293D chips (originally designed by Adafruit) can drive four motors, but it uses many pins.

Bottom line: Everything depends on your motors. I suggest to use a mosfet driver.


Classes and objects: how many and which file types do I actually need to use them?

How the IDE organizes things

First thing, this is how the IDE organizes your "sketch":

The main .ino file is the one of the same name as the folder it is in. So, for foobar.ino in foobar folder - the main file is foobar.ino.
Any other .ino files in that folder are concatenated together, in alphabetic order, at the end of the main file (regardless of where the main file is, alphabetically).
This concatenated file becomes a .cpp file (eg. foobar.cpp) - it is placed in a temporary compilation folder.
The preprocessor "helpfully" generates function prototypes for functions it finds in that file.
The main file is scanned for #include <libraryname> directives. This triggers the IDE to also copy all relevant files from each (mentioned) library into the temporary folder, and generate instructions to compile them.
Any .c, .cpp or .asm files in the sketch folder are added to the build process as separate compilation units (that is, they are compiled in the usual way as separate files)
Any .h files are also copied into the temporary compilation folder, so they can be referred to by your .c or .cpp files.
The compiler adds into the build process standard files (like main.cpp)
The build process then compiles all the above files into object files.
If the compilation phase succeeds they are linked together along with the AVR standard libraries (eg. giving you strcpy etc.)

A side-effect of all this is that you can consider the main sketch (the .ino files) to be C++ to all intents and purposes. The function prototype generation however can lead to obscure error messages if you are not careful.

Avoiding the pre-processor quirks

The simplest way of avoiding these idiosyncrasies is to leave your main sketch blank (and not use any other .ino files). Then make another tab (a .cpp file) and put your stuff into it like this:

#include <Arduino.h>

// put your sketch here ...

void setup ()
  {

  }  // end of setup

void loop ()
  {

  }  // end of loop

Note that you need to include Arduino.h. The IDE does that automatically for the main sketch, but for other compilation units, you have to do it. Otherwise it won't know about things like String, the hardware registers, etc.

Avoiding the setup/main paradigm

You don't have to run with the setup/loop concept. For example, your .cpp file can be:

#include <Arduino.h>

int main ()
  {
  init ();  // initialize timers
  Serial.begin (115200);
  Serial.println ("Hello, world");
  Serial.flush (); // let serial printing finish
  }  // end of main

Force library inclusion

If you run with the "empty sketch" concept you still need to include libraries used elsewhere in the project, for example in your main .ino file:

#include <Wire.h>
#include <SPI.h>
#include <EEPROM.h>

This is because the IDE only scans the main file for library usage. Effectively you can consider the main file as a "project" file which nominates which external libraries are in use.

Naming issues

Don't name your main sketch "main.cpp" - the IDE includes its own main.cpp so you will have a duplicate if you do that.
Don't name your .cpp file with the same name as your main .ino file. Since the .ino file effectively becomes a .cpp file this also would give you a name clash.

  Declaring a C++-style class in the same, single .ino file (have heard of, but never seen working - is that even possible?);

Yes, this compiles OK:

class foo {
  public:
};

foo bar;

void setup () { }
void loop () { }

However you are probably best off to follow normal practice: Put your declarations in .h files and your definitions (implementations) in .cpp (or .c) files.

Why "probably"?

As my example shows you can put everything together in one file. For larger projects it is better to be more organized. Eventually you get to the stage in a medium to large-size project where you want to separate out things into "black boxes" - that is, a class that does one thing, does it well, is tested, and is self-contained (as far as possible).

If this class is then used in multiple other files in your project this is where the separate .h and .cpp files come into play.

The .h file declares the class - that is, it provides enough detail for other files to know what it does, what functions it has, and how they are called.
The .cpp file defines (implements) the class - that is, it actually provides the functions, and static class members, that make the class do its thing. Since you only want to implement it once, this is in a separate file.
The .h file is what gets included into other files. The .cpp file is compiled once by the IDE to implement the class functions.

Libraries

If you follow this paradigm, then you are ready to move the entire class (the .h and .cpp files) into a library very easily. Then it can be shared between multiple projects. All that is required is to make a folder (eg. myLibrary) and put the .h and .cpp files into it (eg. myLibrary.h and myLibrary.cpp) and then put this folder inside your libraries folder in the folder where your sketches are kept (the sketchbook folder).

Restart the IDE and it now knows about this library. This is really trivially simple, and now you can share this library over multiple projects. I do this a lot.

A bit more detail here.


System voltages: Can I use a 5V touchscreen shield on a 3.3V arduino?

You'll probably need a fairly common device known as a logic level converter.  One such example, in breakout board form, can be found here: https://www.sparkfun.com/products/12009

There are tons of other options depending on what exactly you need.


How to program arduino due without arduino ide

The standalone program for most arduinos is avrdude: http://www.nongnu.org/avrdude/

However, for the Due, it is BOSSA:

  Unlike other Arduino boards which use avrdude for uploading, the Due
  relies on bossac.
   -- Arduino Due Overview


Using pushbutton to make Stepper motor rotate 90 degrees

I edtied few things in your code. I am not sure if LOW value is correct, so I replaced it with HIGH. Second thing is timing. I removed all delay() functions instead of it you can see usage of millis(). That's for handling interval between button press and button release - second part of if will check if last time of button press is bigger than 200ms, if yes, move stepper. Last things is stepping. You can see here stepper.step(STEPS/4);. STEPS is variable which you declared on the top of code. It's called steps per revolution, one revolution is 360° so 90° will be STEPS/4.

Here is the code, read it and test it:

#include <Stepper.h>;

// pushbutton pin
const int buttonPin = 2;

const int STEPS = 32;
Stepper stepper(STEPS, 8, 10, 9, 11);

//create a variable to store a counter and set it to 0
int counter = 0;

unsigned long last_button_time = 0;   //for aving last millis

void setup(){
  pinMode(buttonPin, INPUT);
  stepper.setSpeed(1000)
}

void loop(){
  bool buttonState;   // local variable to hold the pushbutton states

  //read the digital state of buttonPin with digitalRead() function and store the           //value in buttonState variable
  buttonState = digitalRead(buttonPin);

  //if the button is pressed increment counter and wait a tiny bit to give us some          //time to release the button
  if(buttonState == HIGH && millis() - last_button_time > 200){ // light the LED
    last_button_time = millis();
    counter++;
    stepper.step(STEPS/4);    //90° degrees
  }
}


ATTiny85 Interrupt id vs pin when programming with Arduino

You can setup interrupts on the Attiny with some different code, but it works the same way. It's important to note that PIN Change Interrupts are triggered at BOTH Rising and Falling Edge

Pins:

Using the Arduino-Tiny Cores

Below is a sample code which used a Pin Change Interrupt on PB1 which switches an LED on and off on PB4.

//Includes
#include <avr/io.h>
#include <avr/interrupt.h>

#define INTERRUPTPIN PCINT1 //this is PB1 per the schematic
#define PCINT_VECTOR PCINT0_vect  //this step is not necessary
#define DATADIRECTIONPIN DDB1 //Page 64 of data sheet
#define PORTPIN PB1 //Page 64
#define READPIN PINB1 //page 64
#define LEDPIN 4 //PB4

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) //OR
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) //AND

/*
 * Alias for the ISR: "PCINT_VECTOR" (Note: There is only one PCINT ISR.
 * PCINT0 in the name for the ISR was confusing to me at first,
 * hence the Alias, but it's how the datasheet refers to it)
 */

static volatile byte LEDState; //variable used within ISR must be declared Volatile.

void setup() {
    cli();//disable interrupts during setup
    pinMode(LEDPIN, OUTPUT); //we can use standard arduino style for this as an example
    digitalWrite(LEDPIN, LOW); //set the LED to LOW
    LEDState = 0; //we use 0 for Low state and 1 for High
    PCMSK |= (1 << INTERRUPTPIN); //sbi(PCMSK,INTERRUPTPIN) also works but I think this is more clear // tell pin change mask to listen to pin2 /pb3 //SBI
    GIMSK |= (1 << PCIE);   // enable PCINT interrupt in the general interrupt mask //SBI

    DDRB &= ~(1 << DATADIRECTIONPIN); //cbi(DDRB, DATADIRECTIONPIN);//  set up as input  - pin2 clear bit  - set to zero
    PORTB |= (1<< PORTPIN); //cbi(PORTB, PORTPIN);// disable pull-up. hook up pulldown resistor. - set to zero
    sei(); //last line of setup - enable interrupts after setup

}

void loop() {
  // put your main code here, to run repeatedly:
  //If you connect a debounced pushbutton to PB2 and to VCC you can tap the button and the LED will come on
  //tap the button again and the LED will turn off.

}

//this is the interrupt handler
ISR(PCINT_VECTOR)
{
  //Since the PCINTn triggers on both rising and falling edge let's just looks for rising edge
  //i.e. pin goes to 5v
  byte pinState;
  pinState = (PINB >> READPIN)& 1; //PINB is the register to read the state of the pins
  if (pinState >0) //look at the pin state on the pin PINB register- returns 1 if high
  {
   if (LEDState == 0)
   {
    digitalWrite(LEDPIN,HIGH); //you can use Arduino Code or LowerLevel Code to write to the register
    LEDState = 1;
    }
   else
   {
    digitalWrite(LEDPIN,LOW);
    LEDState = 0;
    }
  }

}

If you're going to be using the ATTiny85, I highly suggest you read through the data sheet to understand better how to program these chips at a lower level of code....It took me a while for it to start to make sense.


Upload of sketch with avrdude stuck only outside of IDE

@per1234 was correct:

  Note that the auto-reset is initiated when the computer opens the serial port at 1200 baud and then closes it

From Arduino.cc

In practise, this means that avrdude first has to be executed like so:

$ avrdude -patmega32u4 -cavr109 -PCOM6 -b1200

Where COM6 is the same serial port the arduino is being displayed on in the Arduino IDE. The exit code of this will not be 0 and display a lot of error messages (even with -q -q), but it does exactly what it should.

After a short delay (in a makefile, use sleep 1), the Arduino will reconnect, ready to be programmed. That's when the actual programming command has to be issued:

$ avrdude -v -patmega32u4 -cavr109 -PCOM10 -b57600 -D -Uflash:w:mysketch.ino.hex:i

Notice that the serial port is now a different one! That's why the Arduino IDE actively searches for a new Arduino instead of using the same serial port set in the "Tools" menu, as I pointed out in my question.


You call atoi() with a char. Parameter of atoi is const char*. To convert ASCII code of digit to the digit use

int digit = IncomingData[i] - '0'


You may need to do some additional research. I'm debugging some I2C problems myself at the moment. Happy to share what my research has turned up:
Guiding Ideas - What could break?

Physical Layer

Unintentionally switched connections (SDA<>SCL)
Incorrect Pins selected on Microcontroller
Pull-up Resistors

Too many

Devices often have pull-ups installed by default. Only one set is needed per bus. Rule of parallel resistors applies to calculate effective resistance.

Too big (too high resistance)
Too small (too low resistance)

Voltage Conversion / Mismatched  devices
Spikes or noise on SDA, SCL or Vcc
Parasitic Capacitance

wire / trace design
bus too long

Protocol Layer

Bus Addresses incorrect / collisions
No ACK received from slave  (ref. TI article "Troubleshooting I2C Bus Protocol" below)

Timing
Missing / Unexpected SCL pulses
Incomplete 8 bit block
Missing Bytes
False slave address
Unsuccessful address change

NACK signal meaning ambiguity
Clock speed mismatch (should be running at the speed of the slowest slave on the bus)
Blocked bus (i.e., a device has reset or dropped during transmission putting the bus into an invalid state. There is no timeout.)
Multimastering (too many masters on bus?) - if more than one all must support multi-master mode
Clock stretching (a slave is holding the clock low)
What part of the message is missing? Is the initial ACK from the slave received?

Code Layer

For boards with multiple I2C ports, correctly passing the desired port to the relevant library.
Use of interrupts causing timing problems
Use of blocking code structures causing timing problems

Testing Methods

Bus Pinging / Bus Scan (like Arduino Multi-speed scanner https://forum.arduino.cc/index.php?topic=197360)
Connect additional devices to the bus and see which combinations work to identify the failing item
Multimeter checks

Stable Vcc?
Common Ground?
(Open Drain) pull-up resistance from SDA & SCL to Vcc

Test devices like Bus Pirate
Oscilloscope Analysis / Decode (references below)
Sifting out which device is causing the problem. (See Hackaday article) Put different-value resistors on the output of all chips on the bus. The low voltage values will be slightly different for each chip, allowing you to see on a scope which chip is talking at any given time, and diagnose when they’re talking over each other.
install I2C multiplexor to seperate bus into a single connector for each device (i.e., from bus to star topology) (e.g., PCA9544A)

References
I2C General

For Arduino Programming Arduino Next Steps - Going Further with
Sketches Chapter 7
For ESP32
https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/

I2C Debug Advice

I2C Primer (I2C-bus.org) - a good reference for everything discussed here https://www.i2c-bus.org/i2c-primer/

Common Problems https://www.i2c-bus.org/i2c-primer/common-problems/
Obscure Problems https://www.i2c-bus.org/i2c-primer/obscure-problems/ Analysing Obscure Problems https://www.i2c-bus.org/i2c-primer/analysing-obscure-problems/

WHAT COULD GO WRONG? I2C EDITION (Hackaday) https://hackaday.com/2016/07/19/what-could-go-wrong-i2c-edition/
How to design and debug a custom I2C master-slave system? (Stack Exchange) How to design and debug a custom I2C master-slave system?
Troubleshooting I2C Bus Protocol  https://www.ti.com/lit/an/scaa106/scaa106.pdf

Oscilloscope Analysis of I2C

How to debug I2C through waveform analysis (Texas Instruments) https://www.ti.com/lit/an/slyt770/slyt770.pdf
Using an oscilloscope to debug the I2C protocol https://www.electronicproducts.com/using-an-oscilloscope-to-debug-the-i2c-protocol/


Different voltage sources across Vin and DC jack

wouldnt that then send current through the Vin pin and back to the coin cell battery? Is that what would happen in this instance?

Yep, that's right.

  shouldn't there be a design feature to prevent users from damaging it like that? Fool/fail safe?

No. VIN can also be VOUT. You can use it to power other things that want a higher voltage.


you have not put your code here so i can not understand it properly.From what i understand you must have put your code for rotating the servo motor 5 times in void loop. Don't do that put loop for rotating servo 5 time in setup.
void loop run continuously so it must be rotating 5 time then again 5 time and so on.


Removing and using programmed Atmega 328 of Arduino UNO on customised PCB

Yes, it can. Your board will need to provide +5v and ground, a reset signal, and a crystal for the chip's programmed clock frequency (unless you reprogrammed it to use its internal clock). The power and clock signals will need filter capacitors. You can even re-program it on the board with an FTDI (USB-TTL Serial) cable.

There are lots do-it-yourself instructions to build an Arduino board, which is a good place to start, even if what you eventually want is a larger system board with an Arduino integrated into it. This is one I can vouch for; I built Mr. Alves' Version-1 as my only Uno-like board and have been using it for several years.


Arduino Keyboard starts lower case (but it shouldn't)

I am not sure I have the answer to your problem, just a collection of
observations that hopefully steer you in the right direction.
According to your nopaste link, when you send "ON", the first four
keyboard events received by xev are: press(Shift_L), press(O),
release(Shift_L), release(o). One may notice that there is no point in
releasing the Shift key if it's going to be pressed again right away,
but let's assume that simply holding Shift is not such a useful
optimization. The detail that strikes me is that the last two events
look backwards: you usually release the letter before releasing Shift.
As a result of releasing Shift first, the release event for the O key
reports lowercase "o" as a keysym. I tried this backward way of
releasing the keys on a real keyboard, but both gnome-terminal and gedit
correctly registered the uppercase letters.
Another detail apparent in the xev dump is that the two key presses
(Shit and O) happen at the exact same time. Ditto for the corresponding
key releases. Looking at the source of the Keyboard library, it appears
that both key presses are sent to the PC as a single "key report". Same
for the key releases. This is contrary to what a real keyboard does:
actuations on the Shift keys are reported immediately, irrespective of
whether other keys are actuated.
You may try to modify the Keyboard library so that the actuations on
Shift are sent in their own reports. Maybe something like this
(warning: completely untested):
diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp
index 4a948f6..9fbf7b6 100644
--- a/src/Keyboard.cpp
+++ b/src/Keyboard.cpp
@@ -239,6 +239,7 @@ size_t Keyboard_::press(uint8_t k)
        }
        if (k & 0x80) {                     // it's a capital letter or other character reached with shift
            _keyReport.modifiers |= 0x02;   // the left shift modifier
+           sendReport(&_keyReport);        // send the shift key by itself
            k &= 0x7F;
        }
    }
@@ -270,6 +271,7 @@ size_t Keyboard_::press(uint8_t k)
 size_t Keyboard_::release(uint8_t k)
 {
    uint8_t i;
+   bool has_shift = false;
    if (k >= 136) {         // it's a non-printing key (not a modifier)
        k = k - 136;
    } else if (k >= 128) {  // it's a modifier key
@@ -281,7 +283,7 @@ size_t Keyboard_::release(uint8_t k)
            return 0;
        }
        if (k & 0x80) {                         // it's a capital letter or other character reached with shift
-           _keyReport.modifiers &= ~(0x02);    // the left shift modifier
+           has_shift = true;
            k &= 0x7F;
        }
    }
@@ -295,6 +297,10 @@ size_t Keyboard_::release(uint8_t k)
    }

    sendReport(&_keyReport);
+   if (has_shift) {
+       _keyReport.modifiers &= ~(0x02);    // the left shift modifier
+       sendReport(&_keyReport);            // release shift after releasing the letter
+   }
    return 1;
 }

Alternatively, as suggested by @jstola in a comment, you may try to
press the Shift key by itself. Maybe you don't need to care about the
key release, or about any character but the first one (as it is the only
one that seems to cause problems). A minimal workaround to try would be:
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.println("ON");