HobbyTronics UNO PRO Board Definition does not work in newer IDE versions

Making your board definition work
What I did was slightly different from their directions, but:
Close any instances of the IDE you have running.
Create the directories along this path:
<sketchbook>/hardware/uno_pro/avr/variants/uno_pro

Where <sketchbook> refers to to where your IDE is saving sketches by default.
Place the following slightly modified boards.txt at <sketchbook>/hardware/uno_pro/avr/boards.txt:
uno_pro.name=Arduino Uno*Pro

uno_pro.upload.tool=avrdude
uno_pro.upload.protocol=arduino
uno_pro.upload.maximum_size=130048
uno_pro.upload.maximum_data_size=16384
uno_pro.upload.speed=115200

uno_pro.bootloader.tool=avrdude
uno_pro.bootloader.low_fuses=0xFF
uno_pro.bootloader.high_fuses=0xDE
uno_pro.bootloader.extended_fuses=0xFD
uno_pro.bootloader.unlock_bits=0x3F
uno_pro.bootloader.lock_bits=0x0F
uno_pro.bootloader.file=optiboot/optiboot_atmega1284p.hex

uno_pro.build.mcu=atmega1284p
uno_pro.build.f_cpu=16000000L
uno_pro.build.board=AVR_UNO_PRO
uno_pro.build.core=arduino:arduino
uno_pro.build.variant=uno_pro

This is the original file with one important modification, and that's the addition of arduino: in the second to last line reading uno_pro.build.core=arduino:arduino
Place the following (unmodified from original) pins_arduino.h at <sketchbook>/hardware/uno_pro/avr/variants/uno_pro/pins_arduino.h:
#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

// ATMEL ATMEGA1284 on Hobbytronics UNO*Pro
//
//
// 2014-01-24 - Modified for Software Serial Library to work
//
//   ATMEGA1284 Pin     Arduino Mapping    Features
//     PA0                   D21  A7
//    PA1                   D20  A6
//     PA2                   D19  A5
//    PA3                   D18  A4
//     PA4                   D17  A3
//    PA5                   D16  A2
//     PA6                   D15  A1
//    PA7                   D14  A0
//
//     PB0                   D4
//    PB1                   D5
//     PB2                   D2
//    PB3                   D3               PWM
//     PB4                   D10                    PWM  SS
//    PB5                   D11                   MOSI
//     PB6                   D12              PWM  MISO
//    PB7                   D13              PWM  SCK
//
//     PC0                   D22                   SCL
//    PC1                   D23                   SDA
//     PC2                   D24
//    PC3                   D25
//     PC4                   D26
//    PC5                   D27
//     PC6                   D28
//    PC7                   D29
//
//     PD0                   D0                    RX
//    PD1                   D1                    TX
//     PD2                   D6                    RX1
//    PD3                   D7                    TX1
//     PD4                   D30              PWM
//    PD5                   D8               PWM
//     PD6                   D9               PWM
//    PD7                   D31              PWM
//

static const uint8_t SS   = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK  = 13;

static const uint8_t SDA = 23;
static const uint8_t SCL = 22;
static const uint8_t LED = 13;

static const uint8_t A0 = 0;
static const uint8_t A1 = 1;
static const uint8_t A2 = 2;
static const uint8_t A3 = 3;
static const uint8_t A4 = 4;
static const uint8_t A5 = 5;
static const uint8_t A6 = 6;
static const uint8_t A7 = 7;

#define NUM_DIGITAL_PINS            32
#define NUM_ANALOG_INPUTS           8

// Macros
#define analogInputToDigitalPin(p)  ((p < NUM_ANALOG_INPUTS) ? (p) + 14 : -1)
#define digitalPinToAnalogPin(p)    ((p) >= 14 && (p) <= 21 ? (p) - 14 : -1 )
#define analogPinToChannel(p)         ((p) < NUM_ANALOG_INPUTS ? NUM_ANALOG_INPUTS - (p) - 1: -1 )
#define digitalPinHasPWM(p)         ((p) == 3 || (p) == 8 || (p) == 9 || (p) == 10 || (p) == 12 || (p) == 13 || (p) == 30 || (p) == 31 )

#define ifpin(p,what,ifnot)     (((p) >= 0 && (p) < NUM_DIGITAL_PINS) ? (what) : (ifnot))

extern const uint8_t digital_pin_to_pcint[NUM_DIGITAL_PINS];

#define digitalPinToPCICR(p)    ifpin(p,(&PCICR),(uint8_t *)0)
#define digitalPinToPCICRbit(p) ifpin(p,(digital_pin_to_pcint[p] >> 3),0)
#define digitalPinToPCMSK(p)    (((p) <= 1) ? (&PCMSK3) : (((p) <= 5) ? (&PCMSK1) : (((p) <= 9) ? (&PCMSK3) : (((p) <= 13) ? (&PCMSK1) : (((p) <= 21) ? (&PCMSK0) : (((p) <= 29) ? (&PCMSK2) : (((p) <= 31) ? (&PCMSK3) : ((uint8_t *)0))))))))
#define digitalPinToPCMSKbit(p) ifpin(p,digital_pin_to_pcint[p] & 0x7,0)

#define digitalPinToInterrupt(p)  ((p) == 6 ? 0 : ((p) == 7 ? 1 : ((p) == 2 ? 2 : NOT_AN_INTERRUPT)))

#ifdef ARDUINO_MAIN

#define PA 1
#define PB 2
#define PC 3
#define PD 4

const uint8_t digital_pin_to_pcint[NUM_DIGITAL_PINS] =
{
  24, // D0  PD0
  25, // D1  PD1 1
  10, // D2  PB2
  11, // D3  PB3
  8,  // D4  PB0
  9,  // D5  PB1 5
  26, // D6  PD2
  27, // D7  PD3
  29, // D8  PD5
  30, // D9  PD6 9
  12, // D10 PB4
  13, // D11 PB5
  14, // D12 PB6
  15, // D13 PB7 13
  7,  // D14 PA7
  6,  // D15 PA6
  5,  // D16 PA5
  4,  // D17 PA4
  3,  // D18 PA3
  2,  // D19 PA2
  1,  // D20 PA1
  0,  // D21 PA0 21
  16, // D22 PC0
  17, // D23 PC1
  18, // D24 PC2
  19, // D25 PC3
  20, // D26 PC4
  21, // D27 PC5
  22, // D28 PC6
  23, // D29 PC7 29
  28, // D30 PD4
  31  // D31 PD7 31
};

// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] =
{
    NOT_A_PORT,
    (uint16_t) &DDRA,
    (uint16_t) &DDRB,
    (uint16_t) &DDRC,
    (uint16_t) &DDRD,
};

const uint16_t PROGMEM port_to_output_PGM[] =
{
    NOT_A_PORT,
    (uint16_t) &PORTA,
    (uint16_t) &PORTB,
    (uint16_t) &PORTC,
    (uint16_t) &PORTD,
};

const uint16_t PROGMEM port_to_input_PGM[] =
{
    NOT_A_PORT,
    (uint16_t) &PINA,
    (uint16_t) &PINB,
    (uint16_t) &PINC,
    (uint16_t) &PIND,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
  PD, // D0
  PD, // D1
  PB, // D2
  PB, // D3
  PB, // D4
  PB, // D5
  PD, // D6
  PD, // D7
  PD, // D8
  PD, // D9
  PB, // D10
  PB, // D11
  PB, // D12
  PB, // D13
  PA, // D14
  PA, // D15
  PA, // D16
  PA, // D17
  PA, // D18
  PA, // D19
  PA, // D20
  PA, // D21
  PC, // D22
  PC, // D23
  PC, // D24
  PC, // D25
  PC, // D26
  PC, // D27
  PC, // D28
  PC, // D29
  PD, // D30
  PD, // D31
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
  _BV(0), // D0  PD0
  _BV(1), // D1  PD1
  _BV(2), // D2  PB2
  _BV(3), // D3  PB3
  _BV(0), // D4  PB0
  _BV(1), // D5  PB1
  _BV(2), // D6  PD2
  _BV(3), // D7  PD3
  _BV(5), // D8  PD5
  _BV(6), // D9  PD6
  _BV(4), // D10 PB4
  _BV(5), // D11 PB5
  _BV(6), // D12 PB6
  _BV(7), // D13 PB7
  _BV(7), // D14 PA7 (A0)
  _BV(6), // D15 PA6 (A1)
  _BV(5), // D16 PA5 (A2)
  _BV(4), // D17 PA4 (A3)
  _BV(3), // D18 PA3 (A4)
  _BV(2), // D19 PA2 (A5)
  _BV(1), // D20 PA1 (A6)
  _BV(0), // D21 PA0 (A7)
  _BV(0), // D22 PC0
  _BV(1), // D23 PC1
  _BV(2), // D24 PC2
  _BV(3), // D25 PC3
  _BV(4), // D26 PC4
  _BV(5), // D27 PC5
  _BV(6), // D28 PC6
  _BV(7), // D29 PC7
  _BV(4), // D30 PD4
  _BV(7), // D31 PD7
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
{
  NOT_ON_TIMER, // D0  PD0
  NOT_ON_TIMER, // D1  PD1
  NOT_ON_TIMER, // D3  PB2
  TIMER0A,      // D3  PB3
  NOT_ON_TIMER, // D4  PB0
  NOT_ON_TIMER, // D5  PB1
  NOT_ON_TIMER, // D6  PD2
  NOT_ON_TIMER, // D7  PD3
  TIMER1A,      // D8  PD5
  TIMER2B,      // D9  PD6
  TIMER0B,      // D10 PB4
  NOT_ON_TIMER, // D11 PB5
  TIMER3A,      // D12 PB6
  TIMER3B,      // D13 PB7
  NOT_ON_TIMER, // D14 PA0
  NOT_ON_TIMER, // D15 PA1
  NOT_ON_TIMER, // D16 PA2
  NOT_ON_TIMER, // D17 PA3
  NOT_ON_TIMER, // D18 PA4
  NOT_ON_TIMER, // D19 PA5
  NOT_ON_TIMER, // D20 PA6
  NOT_ON_TIMER, // D21 PA7
  NOT_ON_TIMER, // D22 PC0
  NOT_ON_TIMER, // D23 PC1
  NOT_ON_TIMER, // D24 PC2
  NOT_ON_TIMER, // D25 PC3
  NOT_ON_TIMER, // D26 PC4
  NOT_ON_TIMER, // D27 PC5
  NOT_ON_TIMER, // D28 PC6
  NOT_ON_TIMER, // D29 PC7
  TIMER1B,      // D30 PD4
  TIMER2A,      // D31 PD7
};

#endif // ARDUINO_MAIN

#endif // Pins_Arduino_h
// vim:ai:cin:sts=2 sw=2 ft=cpp

Open the IDE and your board should be listed.  It should compile with a blank sketch.  I did not test further than that.
MCUDude MightyCore
Your board could also likely be made to work with MCUdude MightyCore.  However, MightyCore will not have your pin mapping.  So, although you could use it, you would need to ignore the normal UNO pin labeling and instead of work out which pin number used by the chosen MightyCore variant routes to which pin on the UNO headers.  It would be annoying to do, but you could do that by comparing entries in your adapter's pins_arduino.h file with the entries in the chosen variant from the MightCore package.  But, the modifications above seem to work fine.  So, I don't necessarily suggest that route; I'm just saying it could be used that way also.
MightyCore could also be modified, but that works out to the same or more work than just using your board definition, I think.


I'm not sure I get what you want, but the A7 module of Ai-Thinker is a good GPRS module with GPS in it.


Is there any way to flash sketches using custom firmware?

I assume you mean you are reprogramming the USB interface chip, which means you no longer have a UART pathway through to the ATMega328P. If so then yes, you can provide your own USB interface in parallel by connecting an FT232 (or similar) breakout board direct to the ATMega328P chip just like you would on a breadboard Arduino:

FTDI TX -> Arduino RX (Yellow)
FTDI RX -> Arduino TX (Blue)
FTDI DTR -> 100nF Capacitor -> Arduino RESET (Green)
FTDI GND -> Arduino GND (Black)

The capacitor is required with later versions of avrdude and newer versions of the Arduino IDE since the DTR signal is now held LOW rather than being pulsed as it used to be.  This is to combat a change in the FTDI drivers that meant that the DTR stopped being driven at all and broke the auto-reset facility.  So now we need a capacitor to convert a constant LOW into a short low-going pulse to initiate a reset without locking it all up.


Task watchdog gets triggered during Bluetooth initialization

SerialBT.begin("ESP32test") is hanging, and because ESP32 doesn't deal well with code that hangs, so it complains about it.
ESP32 runs a Real-Time OS (FreeRTOS).
The fact that it is a real-time OS means that execution of code needs to be guaranteed to finish within a certain time-frame. You'll often see RTOS functions containing the time limit in which that a blocking function should finish executing, such as:
    uart_wait_tx_done(uart_num, 100); // wait timeout is 100 RTOS ticks (TickType_t)

(from ESP-IDF docs)
FreeRTOS comes with a task API. Each task can execute code, but they need to give other tasks the chance to execute code too. I think that when a task blocks, it doesn't allow other tasks to do work on the same CPU. (but I can't find sources to back this up)
setup() runs in one of the RTOS tasks, and when SerialBT.begin() blocks the task for too long, the task watch dog complains that the task is hanging.
If the task is blocked by some kind of looping code, then it generally helps to run vTaskDelay() to yield the task to the task watchdog for a bit.
Because your task is blocked by a single call, there isn't much to do about it, given that SerialBT.begin() doesn't seem allow you to specify when it should time out.


Printing char array from array of structs in progmem to serial

You can use the strncpy_P(char* dest, const char* src, size_t maxLen); function which will copy a zero-terminated string of at max maxLen bytes from PROGMEM into RAM. Then print the string from RAM.

Example code:

//We have global buffer in RAM. +1 for 0 termination
char descBuf[20 + 1];

void setup() {
    Serial.begin(115200);

    //Copy the description string of the first message in the buffer
    strncpy_P(descBuf, MessageTable[0].Description, 20);
    //Print it
    Serial.print("Description: ");
    Serial.println(descBuf);
}

Together with your code above, that prints on my Arduino Nano as:

Description: Tune Knob

If you don't want to have a 21 byte big buffer in RAM (or there are larger strings you wish to print), you can also use the pgm_read_byte function to read and print the string characters byte-wise. Example:

Serial.print("Description: ");
char c = 0;
for(size_t i=0; i < strlen_P(MessageTable[0].Description); i++) {
    c = pgm_read_byte(MessageTable[0].Description + i);
    Serial.print(c);
}
Serial.println();

For further reference, see the Arduino documentation on PROGMEM: https://www.arduino.cc/reference/en/language/variables/utilities/progmem/


Welcome to this site, next time use ctrl-k to align your code.
The problem is in:
Serial.print(mfrc522.uid.uidByte{i} < 0x10 ? " 0" : " ");

To get the value of an array, use [i], not {i}, thus
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");

(similar to other lines).
To give some additional hints:

Try to prevent duplicated code by storing the byte into a variable. Now you can use uidValue in the subsequent lines.
uint8_t uidValue = mfrc522.uid.uidByte[i];

Store 0x10 inside a constant.

So you get:
const uint8_t MAX_HEX_SINGLE_DIGIT_VALUE 0x0F;

for (byte i = 0; i < mfrc522.uid.size; i++)
{
    uint8_t uid_byte = mfrc522.uid.uidByte[i];
    Serial.print(uid_byte < LOW_VALUE <= MAX_HEX_SINGLE_DIGIT_VALUE ? " 0" : " ");
    Serial.print(uid_byte, HEX);
    content.concat(String(uid_byte < MAX_HEX_SINGLE_DIGIT_VALUE ? " 0" : " "));
    content.concat(String((uid_byte, HEX));
  }

I assume the Serial lines are only for debugging, otherwise you can combine them too.


There is a whole concept you need to learn:

Matrix

By using a matrix arrangement you can, using (8 + 9 = ) 17 IO pins you can create a grid of 8 × 9 buttons, which is 72 buttons.

This method is used all the time for keypads, and you can read more here: http://playground.arduino.cc/Main/KeypadTutorial

To further reduce the number of IO pins used you can replace the 8 IO pins for one dimension of the matrix with a 3-to-8 decoder, since only one pin is ever active at a time.  That reduces it down to just 12 IO pins for the whole shebang.


How can I implement sensor fusion using a gyroscope and a magnetometer to find the orientation?

The magnetometer will be very difficult to use because you have no idea what the local magnetic field will look like around the user.

The gyroscope can help you keep track of angular orientation data during accelerations, but unless you know exactly how this is going to be attached to the human it will not help because you cannot orient the relative angles to the subject. A person can fall with or without rotating in the air as well, so I don't see it helping much anyway.

Kalman filters are great, but overkill; you are not doing inertial navigation over long distances, so don't bother. Simple averaging will suffice.

The accelerometer should be able to detect falls by itself. The only way it will ever "Zero out" is in freefall, and if that zeroing is long enough and then followed by a very hard acceleration against the direction of gravity (the crash) you can call it a fall. Unless the person has some kind of engine to produce thrust, or is going so fast air resistance is a factor, there will be no accelerations in the air. Simplely calibrating of the threshold for being in freefall, the time necessary to call it a fall, and the necessary strength of the following crash should be able to detect falls or jumps with almost no false positives.

For instance if you want to track short falls where the object is never fully off the ground, a large dip in acceleration data will still be seen, so just set the "zero" threshold high.


The Electronics Stackexchange question avrdude error - stk500_paged_write() protocol error has answers that suggest three different tactics for protocol errors:

• Upgrade the Arduino IDE from 1.00 to 1.05, or install "AVR-GCC Toolchain" via Homebrew;
• Disconnect everything from TX / RX (Arduino digital pins 0 and 1);
• Use shorter or different USB cables, hooked to a USB port on computer instead of on a hub

I've seen dozens of answers here on arduino.stackexchange with such suggestions, as well as webpages elsewhere with ideas like those in an answer to AVRDUDE Error (Arduino Leonardo).

You could go through this list of programmer-is-not-responding arduino.stackexchange questions, and report back on what works and what doesn't:

• "avrdude: stk500_getsync(): not in sync: resp=0x00," aka Some Dude Named Avr Won't Let Me Upload My Program,
• How do I resolve "avrdude: stk500_recv(): programmer is not responding"?,
• avrdude: stk500_recv(): programmer is not responding after serial,
• avrdude: stk500_recv(): programmer is not responding + avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x47,
• avrdude: stk500_rcv :programmer is not responding,
• Arduino Nano Update failure - avrdude: stk500_recv(): programmer is not responding,
• avrdude: stk500_getsync(): not in sync: resp=0x00,
• Arduino Uno cannot upload any sketch: avrdude: stk500_recv(): programmer is not responding,
• "avrdude: stk500_recv(): programmer is not responding" when uploading sketch,
• Arduino not working / not uploading [duplicate],
• Problems uploading sketch to Arduino Due,
• FTDI stdk 500k not responding,
• Arduino Prototype on Breadboard: "avrdude: stk500_recv(): programmer is not responding",
• Arduino Nano - programmer is not responding,
• How do I resolve "avrdude: stk500_recv(): programmer is not responding"?,
• Arduino not in sync unique error,
• Arduino nano stopped working,
• Not in sync: resp=0x00,
• How to troubleshoot the Arduino Mini and Arduino usb2serial?,
• Atmega328P-PU: Programmer is not responding,

Note, click the “see more linked questions…” link in the sidebar to get a nice webpage with the above list and the opening lines of each question.


Serial Communication over Desktop to Arduino

I have a USB 2 Serial adapter...I have connected the TX0 pin of Arduino to DB 2 pin (read pin) of the adapter.

You must not connect Arduino pins directly to a D-SUB connector of a USB-Serial adapter, as those connectors traditionally carry higher voltage, opposite sense RS232 signals.

The voltage is too high, and likely to cause damage to your Arduino's processor
The signal is inverted in sense from the logic-level signaling used by your Arduino's processor.

If you actually needed to make this connection, you would need to either use a "logic level" USB serial adapter (sometimes informally called a USB-TTL adapter).  These terminate in various types of connections such as bare wires or header pins/sockets - but basically never in an D-SUB connector.  Or you can use an inverting line driver and receiver such as the MAX2232 type devices, or even an old 1488/1489 pair.

But it's not clear that you should be doing this at all - an Arduino Mega already has a USB-serial converter onboard - that is the interface you use to program it, and it would ordinarily be simplest to use that for runtime communication as well.


You might get away with powering a PIR sensor from a logic line. Check the specs. If it draws less ≤20mA you'd be fine. If you nee to drive more current than that you can use a CMOS TTL Driver or a properly selected N-channel MOSFET. Adafruit sells these, for example.

A relay is another matter. If you this is one of those optically isolated relays and all you're driving is the optioisolator then you might get away with that too if you only need ≤20mA. If you're looking to actually power the relay coils with your Arduino, forget it. it's a bad idea to even have the relay driven from the 5V line on the Arduino. Relays take quite a bit of current, and their load is quite "dirty" and likely to cause problems.

As to "which resistor I might require for the motion sensor & relay", I'm not sure what you mean. You shouldn't need any resistors. If the relay draws more current than the Arduino can supply, a current limiting resistor might protect the Arduino from damage but the relay won't work correctly.

What resistors are you referring to?


Button state changes despite not being connected?

You are setting button pins with INPUT_PULLUP mode, which activates internal resistor connected to supply voltage. In this way, your input pins are in state HIGH if disconnected or if button is not pressed.

To fix this, you need to compare your button state with LOW. Also, make sure that one side of your buttons is connected to ground. Then, pressing the button will connect the button to ground and will bring your button pin to LOW.


Does anyone know how to connect 2 digipots to Arduino? (MCP4141)

Try to read the datasheet and get a basic understanding of how the device works. in this case, it consists of 16 bits transfer (2 bytes).

Try to write a set of routines that communicates with the chip over the spi.

After that, it is all about using the _CS pin to select a particular chip.

edit: if this helps you, here is my code driving two mcp41010 - slight different from your digit pot but very similar.

//write to the device wiper0
void mcp41xxx_write0(uint8_t dat) {
    spi_write(MCP41XXX_P0 | MCP41XXX_CMD_WRITE);    //send the command byte
    spi_write(dat);                                 //send the data byte
}

//write to the device wiper1
void mcp41xxx_write1(uint8_t dat) {
    spi_write(MCP41XXX_P1 | MCP41XXX_CMD_WRITE);    //send the command byte
    spi_write(dat);                                 //send the data byte
}

the actual writes to the devices will differ -> mine is specific to the mcp41010 devices. It supports two wipers, P0 and P1. No increment or decrement on my digit pots.

the way to drive two digit pots are below:

//first pot
spi_select(MCP41XXX_CS1);           //deselect cs1 -> idles high
mcp41xxx_write0(i + i);             //send the data
spi_deselect(MCP41XXX_CS1);         //select hte device

//second pot
spi_select(MCP41XXX_CS2);           //deselect cs1 -> idles high
mcp41xxx_write0(i++);               //send the data
spi_deselect(MCP41XXX_CS2);         //select the device

as i'm using a single pot device, writing to the 2nd pot means writing to its wiper0.

I looked at your digit pot and the only thing you need to change are the wiper-specific routine(s), as your transmission is slightly different in the msb.

the spi_write() routine can be replaced / mapped to the shiftOut() routine under arduino.

here is the above code, without any change, running on an arduino:

I also took a brief look at your device's datasheet (mcp4141) and I think this is all you need to change:

//send data on wiper0 of mcp4141
void mcp41xx_write0(uint16_t dat) {
    dat = dat & 0x03ff;                             //10-bit data
    spi_write(MCP41XX_CMD_WRITE | MCP41XX_WIPER0 | (dat >>  8));    //write the msb
    spi_write(dat);                                 //write the lsb
}


help connecting atmega32 micro-controller to LAN

There are quite a few diagrams and tutorials on the web that will help you achieve this.  I think the obvious choice would be to use SPI to interface to either a W5100 or ENC28J60 based board since your chip supports that.

You might be able to get smaller boards that would be better suited to your needs, but before you buy you should check that there is a library that will suit your needs.


How to read RPS for fast rotation with status change method in Arduino?

For one channel I'd use Input Capture capability on Timer/Counter 1. Without debouncing it'll be pretty easy.

If you want to read 8 inputs simultaneously, you can use Pin Change interrupts and Timer/Counter 1 as a timebase. If you don't use Serial communication, you can use whole PORTD, otherwise you can use for example 4 channels on PORTC and 4 channels on PORTD. But again, debouncing will be little bit challenging.


What could cause AdC Reading only to get stucked?

You appear to have a difficult problem.  One of the rules I use is never power the arduino with 5V power, always use the barrel connector and go with about 8 volts. The additional filtering etc the on board power supply does is amazing. The external 5V is ok for most of the other devices. Another option would go to the local electrical store and purchase a metal junction box and mount the electronics in that complete with a metal cover. Be sure it is grounded to earth. The reason for this is your prototype assembly has a lot of antennas that will pick up just about all of the electrical noise in the area. Remember all grounds must be connected. Arduinos are not hardened for industrial or commercial controller applications.


Make a struct containing the name and id.

struct device{char[MAX_ID_LENGTH] id; char[MAX_NAME_LENGTH] name; }

Then store the those pairs in an array which you can have sorted by one field or the other. That way you can binary search on that field.


'crash' when using pin change interrupts

Your onPinChange() function is called with interrupts disabled.

For you what it means is this function should:

last as short as possible (because NO interrupts are handled during its execution, that includes timers that are used by several Arduino core libraries)
not use Serial functions as these functions are slow and sometimes wait on interrupts (that could thus mean wait forever)

You can read further advice about these so-called Interrupt Service Routines (ISR) here and there.

If you want to trace all calls to onPinChange() then you will have to use some kind of circular buffer as a global volatile variable, which will be written into by onPinChange() and read from by loop().

Accessing that buffer from loop() should be protected against concurrent write by ISR.

Here is sample code I have just written (disclaimer, I have not checked that it compiles but I think it should work correctly) that uses such a circular buffer as described above, and ensures all shared variables accesses are protected against concurrent write by ISR:

#include <PciManager.h>
#include <PciListenerImp.h>

// Structures and function to manage circular buffer of changes
struct Change {
    int i;
    byte kind;
};

// We allow max SIZE changes in the buffer; if onPinChange() is called more often
// than loop(), then at one time the buffer will be overwritten.
const int SIZE = 100;
volatile Change changes[SIZE];
volatile int start = 0;
volatile int end = 0;

// Get the next change recorded by onPinChange()
Change* nextChange() {
    static Change change;
    Change* result = 0;
    // Disable interrupts as we are accessing variables modified by onPinChange
    cli();
    if (start != end) {
        change = changes[start];
        start = (start + 1) % SIZE;
        result = &change;
    }
    // Re-enable interrupts before leaving the function
    sei();
    return result;
}

#define INPUT_PIN 3

PciListenerImp listener(INPUT_PIN, onPinChange);

// No change necessary in setup()
void setup() {
    Serial.begin(9600);
    PciManager.registerListener(INPUT_PIN, &listener);
    Serial.println(Ready.);
}

void loop() {
    // Get the next change recorded by onPinChange (if any)
    Change* change = nextChange();
    if (change != 0) {
        // One change occurred since last time, trace it to Serial
        Serial.print("pci : ");
        Serial.print(change->i);
        Serial.print(" : ");
        Serial.println(change->kind);
    }
}

void onPinChange(byte changeKind) {
    // i does not have to be visible outside this function
    static int i = 0;
    i++;
    // Write information to the end of the circular buffer
    Change& change = changes[end];
    change.i = i;
    change.kind = changeKind;
    // Prepare for the next call (write to the next item of the buffer)
    end = (end + 1) % SIZE;
}


Who makes this cool Arduino display shield, and what model is it?

That will be an SSD1306 based blue OLED display with SPI interface. There's lots of them around by lots of different people. Some are I2C interface, and some of those have a "broken" I2C interface that doesn't send ACKs (especially cheap ones on eBay) and need a special ACK-less Software I2C implementation.

The SPI ones, of course, won't suffer from that problem.

They are generally 0.96" diagonal, and that one, I think, is 96x39 pixels (or it may be 128x64).


nrfl2041, WIFI, bluetooth, xbee, zwave, other wireless communications

Nrf24l01 with mesh or star setup is the best sollution for you. Other modules are expensive. Also bluetooth doesnt support over 7 nodes.  you can solder 8cm wire to nrf modules to get better signal and increse range. Alternatively you can use "nodemcu". Xbee-zigbee has hibernate function to increse battery life. You can apply enable-disable technique to improve the battery life but it is not preffered beacause of network performance. it is diffucult to assign addresses, setup network topology, and establish routing tablet for every hibernation period. You can choose cheaeper zigbee modules like microchips mrf24j40ma.


Controlling DC motor using the Servo pins

No. A servo motor has its own built-in driver and you just send a low-level PWM signal to control it. That cannot directly drive a DC motor.

If you want more DC motors you will need more DC motor driving hardware.  For simple speed control in one direction that could be as simple as a NPN transistor (or N-channel FET), a base resistor, and a flyback diode (just like driving a relay). For direction control you will need a H-bridge like the L293D (which incidentally is a very poor choice of driver by today's standards - very inefficient and lossy. I wish people wouldn't persist in selling it.)


Adafruit Motor Shield V2 itself generates signals that are required for motor control.

ULN2003 motor driver module requires signals at the input. This is a significant difference.

Example of use this driver with MATLAB. Not need to flash Arduino any libraries.

a=arduino('com3','uno);

pins={'D8', 'D9', 'D10', 'D11'};
steps={'1100', '0110', '0011','1001'};

steps_size=size(steps,2);                        %steps = 4

for i = 1:50

    step = steps{mod(i,steps_size)+1};      % step=1,2,3,4

    for j=1:4
        writeDigitalPin(a, pins{j}, str2double(step(j)));
    end

    %pause(0.01);

end

Wiring example (Copied from CheapStepper v0.2)


Have an array with fixed size, and have two indexes. One pointing to the first/current item in the queue, the other to the last item in the queue.

(It actually better/easier to have the second index point to where the next item has to be written)

To add an item to the queue:

Check that that the queue isn't full (second index is the same as the first)
If not write to second index.
Increment second index, and modulo array/queue size, so it wraps around.

To read from the queue

Read value at the first index
Increment first index, modulo array/queue size


Industrial pressure/vacuum sensors are sturdy and rigid. They have extra protection, for example to use it submersible. The manufacturer often make them for certain voltages (for example 24v) and with different outputs (0..5v output, or 5-20ma output, and so on).
There are cheap versions of those sensors. They are between 5 and 20 dollars on Ebay and Aliexpress.
The manufacturers do not tell which sensor they use inside, and it can be hard to find a sensor that is exactly the one that you need.

The bare sensor is often a piezoresistive sensor in a wheatstone bride configuration. The output voltage span of those sensors is very low and not suitable to connect directly to an arduino board.
The advantage can be that they do not have a operating voltage. Only a maximum voltage.

The ideal pressure/vacuum sensor has a temperature compensation and a gain and a output span that is near 5v. You find most of them at nxp.com.
Luckely they have also a vacuum sensor with a large range, for example the MPXV6115V.

Those sensors are ratiometric. Power them with the arduino 5v and use the arduino 5v as analog reference (that is the Arduino default setting). When the 5v changes, the resulting measured pressure does not change and is still accurate.

Never solder something to the unused pins. Those pins can be connected to something inside.

There are a few ways to calculate the pressure. One way is to use the formula from the datasheet, the other way is to map the output voltage span to the pressure span and correct for the offset of the output voltage.


Your picture shows a holder for two AA cells, yielding something in the neighbourhood of 3v.  That is far too little for an L293D.  (This isn't really your fault, as it appears you got this erroneous idea from following a bad tutorial, but it does demonstrate that not everything you read on the Internet is sensible.  Using a 9v "transistor" battery is also a bad idea).    3 cells would be about the minimum, but even there it would not work well, as that chip has two bipolar transistors in the path yielding a voltage drop of over a volt.

To use a an L293D you really want at least a 5 or 6 volt system, and a motor wound for low to moderate current at that voltage.

If you want to use a lower voltage, look at a more modern MOS-based H bridge chip - the TB6612FNG is an often used example.  You will however still want to choose motors wound for moderate current at a 3- or 4- cell voltage - those intended for 2-cell usage typically draw more current than is ideal for an IC driver chip.

It is entirely possible that there are additional issues with your attempt as well.  Normally, a question such as this would require a complete and accurate schematic diagram, which you have not provided.


What datatype is the names of the analog inputs?

They're uint8_t:

static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;

Those are defined in the pins_arduino.h file in the board's variant folder.


How to keep a pin LOW for a small amount of time after pushing a button and while device is booting?

A simple RC network should do the job.

simulate this circuit – Schematic created using CircuitLab

Ok. A quick explanation of what we have here.  C1 and R1 are the same as you have at the moment for your reset circuit. R1 is the existing pullup resistor in the Wemos. R3 recharges the C1 when the button is released. It's effectively the pullup for the button.

D2 is to separate the two parts of the circuit. It prevents R3 from charging the capacitor C2.

The magic happens with C2 and R2. Pressing SW1 discharges C2, and the GPIO goes low.  When you release SW1 C2 charges up again through R2.  When the voltage across C2 rises to the VIH of the GPIO the GPIO will go high.

D1 is to protect the GPIO from the negative pulse you can get from C2 as it discharges.

Here's a simulation. Top line is the GPIO, bottom is RESET.

VIH for the ESP8266 is 0.75VIO, so 75% of 3.3V, or 2.475V.

The charge time of the capacitor C2 is calculated as T=RC, where T is the time taken to charge up to 63% of the supply voltage (2.08V)

With the shown values the time taken to rise to 63% of 3.3V will be 10,000 x 0.0001 seconds, or 1 second.  So to get to 75% it will take a little longer than 1 second.  75% is about 1.4T, so if T is 1 as in the above equation then it will take 1.4 seconds (1 * 1.4) to rise enough for the GPIO to register as HIGH.

Note these times are all from the moment you release the button. Reset has already happened before that time.

Also the internal pullup of the GPIO should be disabled otherwise it will also charge the capacitor and the charge time will be reduced. Since you don't know that resistor value it then becomes impossible to calculate what the charge time will be. Simplest to just disable it and only use the external resistor R2.


How to use potentiometer on one Arduino to control servo on another Arduino via WiFi?

(Yes, I only have links in my answer. And they tend to rot. But in this case it shouldn't be too hard to find those tutorials, nor is the content very specific. I also somewhat feel there should be some help to this person before his question gets closed)

Try to focus on one thing at a time.

Follow the steps below, they should be self explanatory. If you run into trouble, you can always create a question based on that particular problem.

Doing so, you'll learn much more about programming/Arduino as by copying code (and having no idea how to). Sooner or later you'll run into the problem that people will not give you "ready to use code".

Get an Arduino to read out a potentiometer. There are lots of tutorials about that.

https://www.arduino.cc/en/tutorial/potentiometer

Get an Arduino to run a servomotor

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

Combine these two.

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

Make a wired link between two arduino's

http://robotic-controls.com/learn/arduino/arduino-arduino-serial-communication
https://www.arduino.cc/en/Tutorial/MasterWriter

Make the potentiometer control the servo over the wired connection.
Make a wireless link.
Port the wired link to the wireless communication.


SOLVED!
 i've tried many solutions to make it work but it just didn't and here are the solutions i tried
a) to use  0.1µf or 10µf between VCC and ground pin of the 74hc595 .
b) to set the clockPin and dataPin zero before sending data .
c) replacing the resistors from 220 ohm to 470 .

however,  i connected pin13 of the 74HC595 to an arduino pin and drive it to zero so the 8 output are ready to go then digitalWrite(out_enable_Pin, HIGH) ,send data as shown in the following code then digitalWrite(out_enable_Pin, LOW) again .

int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
int out_enable_Pin=13;
int resetPin=5;
char leds = 0;

void setup()
{
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(out_enable_Pin, OUTPUT);
  pinMode(resetPin, OUTPUT);
}

void loop()
{
  digitalWrite(out_enable_Pin, LOW);
  digitalWrite(resetPin, HIGH);

  for (int i = 0; i <255; i++)
  {
    leds=i;
    updateShiftRegister();
    delay(1000);
  }
}

void updateShiftRegister()
{
    digitalWrite(out_enable_Pin, HIGH);
   digitalWrite(latchPin, LOW);
   shiftOut(dataPin, clockPin, MSBFIRST, leds);
   digitalWrite(out_enable_Pin, LOW);
   digitalWrite(latchPin, HIGH);
}


Basically you need to get rid of the delay and any other blocking loops. Here is a way to do it.

Define this variable globally.

unsigned long lastTime = 0;

Then in your first loop, add the following code either to the beginning or the end:

if (millis() - lastTime >= 1000 || !lastTime) {
    lastTime = millis();
    tone(TICK_PIN,1000,2);
}


Increasing analogread speed on the Arduino Uno

It sounds like you could benefit from interrupt handled free running sampling, doing that should get you sampling rates up to the maximum listed on the 328's datasheet, 76.9 kSPs. Although, that's at a reduced resolution. This site explains better, under the section "Free running sampling".


I have a 2.4A USB power supply. Is that enough?

Not by a long way, no.
NEMA 17 motors are typically 12V, not 5V, so a USB power supply is not even close.
You will need a decent 12V power supply with a lot of current.
My 3D printer has 3 NEMA 17 motors and uses a 200W 12V power supply. Most of that goes to the motors with only a comparatively small proportion to the hot end.
You need to know the current draw of the motors you are using (note: NEMA 17 defines the physical size, not the electrical characteristics).  Sum all those up for all your motors, and that's the absolute minimum you'll need from your power supply. Add some more on top for losses in the motor drivers and to power the Ardiuno.
And I'm not even considering the dremel in any of this...
So yes, an ATX power supply is probably a good choice.


You can print the value as it is:
Serial.println(state);

This will print the the ordering number of the enum, but you can specify the value as any number or char.
enum States
{
  SLEEP = 'S',
  AWAKE = 'A',
  CRAZY = 'C'
};

Now if you print it with cast to char Serial.println((char) state); it will print a character, which in my opinion is much better then some number.
If you want to convert the enum values identifiers to strings you can do it with a preprocessor macro.
enum States
{
  SLEEP,
  AWAKE,
  CRAZY
} state;

#define IDNAME(name) #name
const char* stateNames[] = {IDNAME(SLEEP), IDNAME(AWAKE), IDNAME(CRAZY)};

I don't think this is better then to print the char values. To do a pretty print it is better to use descriptions.
const char* stateStr[] = {"Sleep", "Awake", "Undefined"};
Serial.println(stateStr[state]);


ESP8266-12E as WiFi interface for Arduino Mega

If you know how to write code for the esp8266, then write the networking part in the esp8266 and exchange data and commands with the sketch in Mega over Serial.

Other option is to use AT firmware with the WiFiEsp library or WiFiLink firmware with WiFiLink library.

Or you can connect the ESP-12 to Mega over SPI and use the WiFiSpiESP firmware with WiFiEsp library.

All mentioned libraries are 'clones' of the WiFi library.


Measure lipo voltage while powering arduino

The reference voltage for analogRead should be from the regulated 5V line, not from the unregulated input to the Arduino.

The real problem is that the voltage out of the battery will drop with current load. You're supposed to measure either the unloaded battery, or under a known, controlled load.

You ask "Should I use a step up module to 5V?" The answer is yes, but that's unrelated to your voltage measurement question. An Arduino requires a source of regulated 5V. The internal voltage regulator is a linear regulator that requires somewhat more than 5V as input (7.5V is about right.) You can't power the internal voltage regulator with a single 3.7V lipo battery. You'd need a step-up regulator, and with that, you could bypass the internal regulator on the Arduino (assuming your step-up regulator puts out 5V.)


How can I rename how my Arduino shows up on the computer?

This string is contained in the FT232 USB to UART interface chip and the manufacturer has released the FT_PROG tool to reprogram it. But do take note of the warning on their website: "PLEASE NOTE - The use of some of these utilities by an end user may result in a device being rendered useless". Another word of warning is to ensure there is only one device connected with an FTDI-chip.

Here is a screenshot of the MProg tool:


Is possible to set a pin faster than digitalWrite?

Yes, it is possible

The atmel chip at the core of the arduinos can set or clear individual pin output levels in a single operation. There are special instructions to do so SBI and CBI- you just need to figure out what C compiles down to those instructions.

Each pin is represented by one bit of a port byte, for pin 11 it's bit 3 on port B.  So you can toggle it with

PORTB ^= _BV(PB3);

or set it with

PORTB |= _BV(PB3);

or clear it with

PORTB &= ~_BV(PB3);

Probably the last two will compile to a single SBI/CBI instruction while the toggle one may or may not, depending on the code and how the compiler optimises it.


How to do weigh scale zeroing (tare weight)?

You start out with a variable named Tare initialized to zero float Tare = 0.0; put in a conditional like if (millis() > 2000 & Tare == 0.0) Tare = voltage; and always report voltage - Tare.

float Tare = 0;

void loop() {
  // Nothing to do unless data ready is asserted.
  if (digitalRead(ADS1262_DRDY_PIN) == HIGH) return;
  // Get a reading and convert to voltage.
  uint8_t *buffer = (uint8_t *) PC_ADS1262.ads1262_Read_Data();
  signed long reading = (uint32_t) buffer[1] << 24
    | (uint32_t) buffer[2] << 16
    | (uint32_t) buffer[3] <<  8
    | (uint32_t) buffer[4] <<  0;
  float voltage = VREF / (1UL<<31) * reading;
  if (millis() > 2000 & Tare == 0.0) Tare = voltage;
  // Report a smoothed-out reading.
  Serial.println(voltage-Tare, 8);
}

If you want to make it smarter, add a button for tare and maybe if you have a calibration weight, add a button for calibrating.

float scale= 1.0;
const float calib_weight = 500.0; // grams?
...
if(tareButton | (millis() > 2000 & Tare == 0.0)) Tare = voltage;
if(calibrateButton) scale = calib_weight / (voltage-Tare) ;
...
Serial.println((voltage - Tare)*scale,8);
...


I imagine Code Gorilla's given you the proper, specific answer you needed. I simply wanted to address your first (more general) ask,

  Am I able to send instruction from my computer, from another compiler, via the Arduino USB port?

... and mention some other ways I've done this before. As long the Arduino's listening to the serial port for some specific (or any) input coming in, you can use whatever you'd like to send a message to the COM port your Arduino's using.

You absolutely are not hemmed into using solely the Arduino IDE (or it's serial monitor) for serial communication.

For instance, I wrote a Python script that communicated with an Arduino R3 (Rx/Tx) via the COM port it was assigned via the PySerial library - before coming to Python, I'd been doing this through a MS Visual C# WPF that was connected to the COM port and communicating with the Arduino (Rx/Tx) (you might need to adjust baud rates here or there, if I recall). Just to give you some ideas.


Convert my if loop code into a switch/case statement

A switch can only select different discrete values from a single variable. Since you have multiple variables and aren't looking for discrete values you have to use if not switch.


Wiring Diagram to Pin 13 for a single relay? This might help.


Serial devices should be connected RX to TX and TX to RX.

When you connected the RX to RX you connected the esp8266 to USB chip on Nano. Because the USB chip is connected to Atmega on Nano RX to TX, so if you connect the esp8266 to the same line, the it is connected RX to TX to USB.

On this picture esp8266 is connected to Atmega and not accessible from USB:

Communication from Serial Monitor over USB to esp8266 on pins 10 and 11 of the Atmega could work only with SerialPassthrough sketch resending data between Serial and SoftwareSerial on pins 10 and 11.


Arduino Uno Keeps Resetting (Power issue)

How much current takes your board with all components? Maybe the 5V power supply can not give you the wanted current.

You can use a oscilloscope to see what is happening with the 5V when you use your board (maybe not enough current) for example interruptions on your connection or the voltage is not stable.
Maybe you can find a datasheed for the power supply for more information
try your board with another power supply to see if this is a problem of the board or the power supply

I just recognized in the third picture that the transformers output have 5V and 200mA. Your speaker will maybe have 8 Ohm (please write us the resistance). This means it will take 5V/8 Ohm this equals a current of 0,625 or 625mA. This current is 3 times higher than the output current of the transformer.

My theory 1 is:

Your circuit worked on your computers USB because you have got usb 3.0 and the max current for it is 900mA wich is much greater than 625mA and enough for leds, speaker and arduino. Your speaker is not connected directly to a pin and gnd. Some seperate electronics manages the pulses and takes directly the 5V of the USB.

My theory 2 is:
You used USB 2.0 (500mA) or USB 3.0 (900mA) and the speaker is connected directly to a pin (the resistance is ok or you added some resistance). The sound was probably not loud because the power was low. The current for both USBs were enough for leds, speaker and arduino.

Now to your problem with the resetting.

The solution:

Switch off the speaker and test your circuit without it. (I think it will work fine).

If it works: You took too much current and this current heated the pin and  influenced the charecteristics of the pin and finally the voltage at your pin (weird fuzz). Add a variable resistor in series to your speaker an try it.

If it not works: Measure the output voltage of the transformer and wirte us the value.


The problem is most likely EMI (electromagnetic interference) from the switching of the inductive load by the relays.

The fact that you have your setup on a breadboard means that each and every pin of the ATMega328 is connected to a little antenna. That massively increases its susceptibility to falling prey to EMI.  Add to that the fact that there is absolutely no decoupling of the power supply (thanks to Arduino producing shoddy worthless tutorials) makes the whole chip very fragile.

When running with a real Arduino board you have decoupling on the power which helps to reduce induced power rail bounce which can cause the chip to fail.

There are two things that can help mitigate this:

Add decent decoupling to the ATMega328

This means adding capacitors between each VCC pin and ground. At the bare minimum a 100nF capacitor on each VCC pin is needed. Additionally a 1nF capacitor can be beneficial. A 10µF capacitor should also be added on the breadboard's power rails to act as a board-level reservoir.

Snubber networks on the switching

A snubber network, in its most simple form, is a resistor and capacitor in series.  It is placed across the switching terminals of a device that is switching an inductive load to absorb the sudden spike of back-EMF from the collapsing magnetic field whenever the load is switched off.

simulate this circuit – Schematic created using CircuitLab

Note that the capacitors here should be rated for at least 400V since the voltages involved are quite high.


You have set Pin 2 to HIGH, which is 5V. You have set Pin 4 to INPUT_PULLUP, which means if no signal is driving it, it will be HIGH.

You have connected a button between Pins 2 and 4. So, if you don't press the button, the input is pulled HIGH. And if you do press the button, Pin 2 is driving it HIGH.


Arduino /dev/ttyUSB0 permission denied even when user added to group "dialout' on Ubuntu 18.04

After some struggle I figured out that I need to add my user to "tty" group as well.

There's another approach that involves udev rules modification for certain vendor:device and update of device's ownership but this seems more sane approach.

To recap:

Add your standard user to the group "dialout'

sudo usermod -a -G dialout your-username
Add your standard user to the group "tty"

sudo usermod -a -G tty your-username
Logout/Login

Hope this helps


HTTP post via GPRS (SIM808) to Azure http endpoint logic app is failing

Juraj's comments put me on the right track, for SSL you need to do more then just select the port.

I did some searching and got it to work using a different GSM library that also supports SSL:
tinyGSM

in combination with ArduinoHttpClient

Jeroen

EDIT: It works, but there is a big downside. It looks like there is major overhead, each message seems to uses 13Kb of data...? I suspect this comes from the data that is returned by the endpoint.
This is way too much over GPRS so now looking into MQTT.


Are all Arduino shields compatible with all Arduino boards?

When you want to choose a shield for your board you should check:

1- Pin-out, this one is the least concerning one , Most arduino boards are Shield pin-out compatible and you can verify it visually, for others, normally there are some converter boards (e.g for NANO), and in the worst case, building a converter board or wiring the shield to board is trivial in most situations.

2- Shield operating voltage should match your board's, most shields operate at 5V, 3.3V or both. Normally AVR-based boards (e.g. UNO, Mega, ...) operate at 5V and ARM based ones (e.g. Due, ...) operate at 3.3V, So we should choose the shield accordingly (just keep in mind that most shield are designed with Arduino UNO in mind so it's more likely that your shields operate at 5V).

3- Library, Lots of Libraries for Arduino shields bypass Arduino library abstraction (mostly for performance reasons) and use hardware specific features (e.g directly write on specific ports), here is source of some incompatibilities between your board and the shield, for example there are handful of TFT LCD shields in the market which their library only supports UNO boards, in these cases you should either port it to your board's (based on micro-controller model and it's architecture, sometimes its as easy as changing some pin/port definitions and sometimes as hard as writing the library from scratch).


Ways to turn a knob with a stepper motor and an ATMEGA32u4

Looks to be a screw driven by a motor through a set of greats. It doesnt matter if the motor is a regular (dc) motor or a stepper.


volatile long rawTacho[2];      // interrupt 0 & 1 tachometers

ISR(MotorISR1)
{
    int b = digitalReadFast(8);
    if (digitalReadFast(2))
        b ? rawTacho[0]-- : rawTacho[0]++;
    else
        b ? rawTacho[0]++ : rawTacho[0]--;
}

ISR(MotorISR2)
{
    int b = digitalReadFast(9);
    if (digitalReadFast(3))
        b ? rawTacho[1]-- : rawTacho[1]++;
    else
       b ? rawTacho[1]++ : rawTacho[1]--;
}

void setup()
{
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    pinMode(8, INPUT_PULLUP);
    pinMode(9, INPUT_PULLUP);

   attachInterrupt(PCINT0, MotorISR1, CHANGE);  // pin 2
   attachInterrupt(PCINT1, MotorISR2, CHANGE); // pin 3
}

something similar to that - it was extracted from bigger code so you will have read it and understand it as opposed to copy paste.

Update note: This is not complete in a pure form - the cpu doesnt tell you what pin had an interrupt - thus some underlying Arduino code figures that out for me, but it is fairly efficient, and I used it as is. Also if it is not obvious, this is reading encoders from 2 motors. 1 interrupt is assigned to each motor, the second phase of each is on a non-interrupt pin. Never lost a reading to my knowledge.

The problem with your code is probably the print in the interrupt as pointed out in a comment.


XBee on Arduino Fio - how to read the status of a local digital XBee output pin?

You cannot read the state of output pins via an AT command, you can only read the state of input pins using the ATIS command.

See: http://ftp1.digi.com/support/documentation/90000982_S.pdf


First off you need a basic understanding of TCP/IP networking. One you have that you need to:

Allocate yourself a new subnet - one that's not your normal local network (say 192.168.1.0/24)
Assign an IP in that subnet to your Arduino (say 192.168.1.1)
Assign a different IP in that subnet to your PC (say 192.168.1.2)
Configure your Arduino's sketch with it's IP address and netmask
Configure the PC's Ethernet interface with it's IP address and netmask
Connect the two together with a suitable cable.  If the PC's Ethernet port doesn't have auto-direction sensing you will require a special cross-over cable where TX+/TX- and RX+/RX- are swapped over.


You aren't crazy. I had a similar thing happen when an external hot-water system turned on at midnight (someone was having a shower) and one of my systems detected input unexpectedly (and rang a bell right next to my ear while I was trying to sleep).

My solution was to have something like this:

The diodes clamp the input to acceptable ranges, and R1 is a current limit for the diodes. R2 and C1 are a filter that slows down the incoming signal (and thus eliminates sudden spikes). R3 is a pull-up resistor. In my case I had active-low. If you have active-high you could use a pull-down resistor instead.

Also see https://arduino.stackexchange.com/a/13128/10794

Further reference material:

10 Ways to Destroy An Arduino
Protection
Microcontroller Input Protection Techniques


The simplest and crudest method:

int val1 = analogRead(A0);
delay(5);
int val2 = analogRead(A0);

if (val2 > val1) {
    // It went up (for example).
}


Is there a library to use Amazon IoT services on any Arduino?

You can try the AWS IoT Embedded C SDK, that is for more general devices.
Other Arduinos requires a crypto library and a device powerful enough, maybe PI, to support the authentication process...
At this time they have no crypto library like the YUN SDK, for other Arduinos...

Try it...


There must be a difference between a LOW reading and no connection, correct?

No, the input circuitry measures a voltage. The exact details are in the datasheet, but how could it know there is nothing connected? There is not some sort of sensor that detects the insertion of a wire into the input. Therefore it is trying to read a voltage all the time.

With nothing connected then stray voltages from nearby circuitry will influence the reading.

  ... and just really finicky when i moved the board ...

Yep, you are influencing the voltage by capacitance from your hand.

You need to have a definite voltage for "no switch pressed" which can be a resistor to ground (eg. 10k) or a resistor to +5V.

I have a tutorial on this.

It sounds like you have wired your switch like this:

Because you don't have a definite voltage there, the input could "randomly" switch between LOW and HIGH.

You could add a pull-down resistor:

Or a pull-up resistor:

Or use the INPUT_PULLUP mode to create a pull-up resistor in the processor hardware. (There is no INPUT_PULLDOWN mode).

Then you will get consistent results.


ZS-040 (HC-05) blueetooth module Arduino Mega

Solution

Connection:

Bluetooth RXD to Arduino Mega pin 11
Bluetooth TXD to Arduino Mega pin 10
Bluetooth VCC to Arduino Mega 5V
Bluetooth GND to Arduino Mega GND

I used this code:

#include <SoftwareSerial.h>

#define RxD 10
#define TxD 11

SoftwareSerial BTSerial(RxD, TxD);

void setup(){
  // replace BAUDRATE as suggested
  BTSerial.begin(BAUDRATE);
  Serial.begin(9600);
  BTSerial.print("AT\r\n");
}

void loop(){

  if (BTSerial.available())
    Serial.write(BTSerial.read());

  if (Serial.available())
    BTSerial.write(Serial.read());

}

after setting AT mode as described in the tutorial above.

I tried running the code with BAUDRATE starting from 9600 to 460800:


Does MFRC522 supports native SPI of Arduino Due?

There is no reason why it wouldn't support the Due's SPI. It just uses the default SPI.h library as the interface.

The resetPowerDownPin can be anything you like. It is not part of the SPI protocol but specific to that library. It is just controlled with digitalWrite() internally.

If you don't want to use the functionality you can set it to MFRC522::UNUSED_PIN and it will be disabled.


You are witnessing button bouncing. You need to incorporate a "button debounce" in your code. What is happening is when you press the button your code continues to loop (e.g. cycle). The Arduino detects the button is pressed every cycle. If your arduino has a 16 mhz crystal oscillator its means 16 Million cycles per second. Thats fast, much faster than you press and release the button.

There are number of why to solve this. One is using an interrupt instead of polling, but you will still need to incorporate a debounce.

Google Arduino Button Debounce.


Using #include <Arduino.h> in your myheader.h will also include <stdint.h> and probably solve this.

The Arduino IDE automatically includes Arduino.h in the sketch itself, but apparently not for external stuff.


Many fields will empty until the unit can get a lock. $GPGSV messages will tell you how many satellites it currently sees, and how strong the transmissions are. The first lock can take several minutes, and it can be very difficult to get a lock indoors.


I found, that the pin mapping printed at the board of the nodeMCU does NOT match the pin mapping in the library/software.

Check out this issue/solution. It states the correct pin mapping (e.g. pin 2 is "D4" at the board) and provides also an according workaround. My DHT22s are working now... :-)


Problem with String& argument of a function

The function prototype in sms.h is

char SendSMS(char *number_str, char *message_str);

if number is String, you should have

sms.SendSMS((char*) number.c_str(),"Text message");

c_str() is a function of the Strinng class. It returns a pointer to internal char array of the String object.

The cast to char* is necessary because the author of the library didn't make the parameter constant with const char*. (It is a good practice, to declare pointers and references as constants.)

The error message no matching function for call to 'SMSGSM::SendSMS(String&, const char [27]); shows the arguments you try to use. String& is reference to some instance of the String type


Using a phone battery as a power source possible?

Sounds like a good solution.

Just note that most cellphones use Lithium batteries. Those are typically around 3.7 volt. They require some special way of charging, or they may explode or catch on fire. They also get damaged if discharged too much.

These batteries may have some protection circuitry inside them. This would be ideal in your case, as it protects against over-discharge, and accidental shorts.

An alternative would be the cells used in notebooks called 18650s. These are available with protection and without. The advantage is that you have a standard size. You can buy battery holders for them. That way you can easily exchange batteries. You can also combine cells to create higher voltages.

As for the runtime; you can make a rough calculation of it.


Switch off:
reg02h = reg02h & ~RDA5807M_FLG_ENABLE;
setRegister(RDA5807M_REG_CONFIG, reg02h);

Switch on:
reg02h = reg02h | RDA5807M_FLG_ENABLE;
setRegister(RDA5807M_REG_CONFIG, reg02h);

EDIT: (to answer a comment of Антон)
Nastroika (настройка) means "tuning". Is that right? Then I would use this method only for tuning. Create two methods one for switching off and one for switching on.
void switchOff()
{
   reg02h = reg02h & ~RDA5807M_FLG_ENABLE;
   setRegister(RDA5807M_REG_CONFIG, reg02h);
}

void switchOn()
{
   reg02h = reg02h | RDA5807M_FLG_ENABLE;
   setRegister(RDA5807M_REG_CONFIG, reg02h);
}

In the Nastroika Method you should only perform the tuning and let the module of. If you insist to switch on at the same time you could use your old version.
Example:
void Nastroika(uint8_t volume, uint16_t freq)
{
   // !!!!! This is the wrong place for Wire begin
   // move it to the setup method.
   // Wire.begin();
   reg02h = reg02h | RDA5807M_FLG_DHIZ | RDA5807M_FLG_DMUTE;
   // or if you insist / you want to keep the module be started here
   // reg02h = reg02h | RDA5807M_FLG_ENABLE | RDA5807M_FLG_DHIZ | RDA5807M_FLG_DMUTE;
   setRegister(RDA5807M_REG_CONFIG, reg02h);
   reg03h = (freq - 870) << RDA5807M_CHAN_SHIFT;
   setRegister(RDA5807M_REG_TUNING, reg03h | RDA5807M_FLG_TUNE);

   reg05h = getRegister(RDA5807M_REG_VOLUME);
   reg05h &= ~RDA5807M_VOLUME_MASK;
   reg05h |= volume << RDA5807M_VOLUME_SHIFT;
   setRegister(RDA5807M_REG_VOLUME, reg05h);
}

Usage:
void setup()
{
   Serial.begin(9600);
   Wire.begin();
   Nastroika(4, 1077);
}

void loop()
{
  switchOff();
  delay(5000);
  switchOn();
  delay(5000);
}


Yes, there's the Arduino Ethernet. Available from Sparkfun for example


Driving conveyor belts using Arduino Unos

In regards to time control use the mills() function.  You start by creating an:

unsigned long lastTime = millis();

Then later in the program create another variable:

unsigned long currentTime = millis();

Next Compare the two:

unsigned long elapsedTime = currentTime - lastTime;

For the most part I normally just shorten the last two lines into one:

unsigned long elapsedTime = millis() - lastTime;

Stepper motors are not needed if you are just doing timed control, but the advantage of stepper motors are you can move them with pin point accuracy based on the number of steps per rotation.  If there are 60 steps per rotation then 360 degrees per rotation/ 60 steps per rotation and you get that each step is 6 degrees.  So in order to turn the motor 6 degrees you would turn it 6 steps.  This also allows you to keep track of angular velocity.

When I control motors I normally create an array of the different parts of the cycle then loop through the array.


How to send an email with Arduino and a WiFi shield?

What you're looking for is a SMTP (Simple Mail Transport Protocol) library. A Google search finds 2 for the Arduino:

SMTPClient
This seems to be a minimal-capability SMTP-only library that piggybacks on top of a connection library.

FullIP
This seems to be a full IP package for the Arduino that works with select network devices which includes SMTP capability.


Is there a way to upload precompiled code to an arduino?

Is there a way to compile arduino code without automatically uploading it, so that I can put the pre-compiled binary up for download on a website?

Yes, you can save the .hex file produced by the compiler. If you turn on verbose output from the compiler you can find the temporary directory where it is stored. Simply copy from there to a folder for download on the website.

  And then after this how would I go about manually uploading it (To the arduino)?

You can do that with the command line tool avrdude but as that is somewhat complex with a lot of parameters it might be easier to use a graphical front-end. One such tool is xloader. There are several. This depends on your end-users and the host machine that they will be using.

You can find some more info here.

Cheers!


Only the leakage current on the input itself is constantly consumed if there is no external connection. This is usually much less than the waste caused by having the input floating.

  If a voltage between 0.8 V and 2 V is applied to the input for a prolonged period of time, this situation becomes critical and
  should not be ignored, especially with higher bit count and more dense packages [...]. For example, if an 18-bit
  transceiver has 36 I/O pins floating at the threshold, the current from VCC can be as high as 150 mA to 200 mA.


In your onReset() function you have an assignment instead of a comparison:

if (i = 1) // This is always true
{
encoder0Position = 0;
}

i = 1 should be i == 1


As far as I know, you can connect multiple keypads of this type to a single set of 8 pins.  However, it seems like a lot of wire needs to be strung to get this to work, for each switch, 8 wires for the keypad, and two, or more, for power control.

Were I to do this project.  I would likely handle each switch independently, embedding a Pro Mini in each switch box along with an HC-12, or some such.  This means no wires are needed, any pad could control any switch, and expansion is much easier.

Of course, this is only what I would do, and you understand your own requirements far better than I.


Implementing DES or AES Encryption with DateTime Synchronization on Uno

We have no experience with the byte[] objects and whatnot.

Might be time to do a few tutorials. You won't get far programming if you don't learn how to use arrays.

The string class is part of the STL (Standard Template Library) which does not come pre-installed on the Arduino (however you can download it if you want to).

The Standard Template Library (STL) for AVR with C++ streams

Briefly, however you could do something like this:

char key [20] = "This is a key";
char keypadInput [16];  // whatever they entered

char plain[80];

strcpy (plain, "This is the keypad input");
strcat (plain, keypadInput);
strcat (plain, "and some other random stuff");

The example code doesn't have any size checking. You would want to make sure that you don't put more than 79 characters into "plain" (to allow for the terminating 0x00 character). For example, look up strncat.

  Can you please elaborate on how DES or AES as described in the question can be implemented?

Have you done much research? Have you Googled Arduino AES encryption like I just did? I got this as the first hit:

Topic: new AES library - Arduino Forum

  I've written an AES (Advanced Encryption Standard) library for Arduino.  It supports 128, 192 and 256 bit key sizes.  Code space overhead is about 4KB I think, each instance requires 240 bytes RAM for subkeys.  Fairly tightly coded and checked against official test vectors for ECB mode.  Also CBC mode supported.

  It seems that if value of plain is larger than 16 characters the library will encrypt the first 16 characters only... Is this an Arduino Uno limitation?

I don't want to seem unhelpful, but you really should do some research before asking these questions. From Wikipedia - Advanced Encryption Standard (AES):

  AES is a variant of Rijndael which has a fixed block size of 128 bits, and a key size of 128, 192, or 256 bits.

A "fixed block size of 128 bits" means you encrypt 128 bits at a time, that is, 128/8 = 16 bytes.

So no, it is not an Arduino Uno limitation, it is the way AES works.

Also see Wikipedia - DES.

  In the case of DES, the block size is 64 bits.

So DES does 8 bytes at a time.

What you can do with a password is to hash it, for example: Secure Hash Algorithm or MD5 (amongst others). These algorithms take a variable length string and return a fixed "hash". In the case of MD5 the output is a 128-bit field.

You could then encrypt that 128-bit hash, if you want to keep it a secret.

  Would encrypting the 16 bytes and then append the next 16 bytes and so on result to the same output as if the whole plain text was encrypted in the first place in one go?

The suggestion by @BrettAM was, if you want to encrypt more than 16 bytes, do them 16 bytes at a time, padding if necessary the final block.

eg.

AAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBB CCCCCCCCCC000000
      encrypt        encrypt          encrypt
LLLLLLLLLLLLLLLL MMMMMMMMMMMMMMMM NNNNNNNNNNNNNNNN
      decrypt        decrypt          decrypt
AAAAAAAAAAAAAAAA BBBBBBBBBBBBBBBB CCCCCCCCCC000000

In this example the final block was padded with zeros. Now the receiving end decrypts in 16-byte blocks.


Is it possible to power up Arduino upon serial transmission without dropping data?

I never tried myself, but afaik you can define an wake up/interrupt from USART, meaning that if you get a receiving byte from the UART it will wakeup the Arduino.

When powered up, you can read continuous data. I would be surprised if they make an UART wakeup signal, that bytes would be lost (i.e. that powering up would take too long to miss more UART bytes).


First off, I would recommend  strtok or even getline to parse comma delimited strings.

Secondly, I'm pretty sure no PWM is responsive enough for 1000 updates per second. But for other purposes this data rate might be needed.

To do this, build a custom cache that does the following:

Reads 1000 characters per go, if available, or less.
Parses on the go. From this set up callbacks to you PWM class, so that you can set PWM values while parsing.

Why this? I am not convinced that the sluggishness is due to the for parsing data. More likely, it's because you are processing every instruction as you get it.

1000 serial reads with 6 length for loops over strings (your case) will be significantly slower than 1 serial read and a 6k length for loop.


How to include a file from another (parent) directory

This is definitely on the hacky side and not a proper solution to the problem, but it works nevertheless so I'm sharing it.
After making a symlink in the /usr/share/arduino/libraries directory you must make sure that there is a header file with the exact name of the directory, apparently that's how arduino is set up to include them.
In my case my symlink was named GAVR, so I had to create a GAVR.h file inside my lib directory, which would then go ahead and include my i2c.h file and possibly any other file that I'd need.
Also in test.h or anywhere I need to use i2c.h I must include <GAVR.h> instead.
Turns out Also 1 is false, you just need to include <GAVR.h> once in the .ino file and its members will be available everywhere, just like any other library.
Also 2, now that ARDUINO_LIBS is not empty in the Makefile you will need to manually declare all libraries that your code is using.


I²C with ATTiny85 at 8MHz using TinyWireM library

You really just need to scope the signals, even if it's with a DSO Nano-type scope.

Without downloading the datasheets:

I would guess your pull-up is probably too small, but possibly too large (scope it)
Slew rate may be either insufficient or too steep (scope it)
Be aware that the ATTiny runs at "8MHz", and not 8.00MHz. The timing error can be off enough to cause communication issues at high speeds while working well at lower speeds (scope it, and/or start at default and incrementally increase speed by 0.5MHz until it stops working)
MMA may not support a typical protocol feature being used, i.e. 'repeated start', burst transfers, etc. (datasheet register/programming section)

Edit: Both the ATTiny and the MMA should have bypass capacitors near the power pins.


Please format your code.  I know it takes longer, but the payoff is in readability and maintainability.  It's well worth the extra effort.

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

const int sensorPin = A0;
int switchState = 0;

double Thermistor(int RawADC)
{
    double Temp;
    Temp = log(((10240000 / RawADC) - 10000));
    Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp);
    Temp = Temp - 273.15;
    return Temp;
}

void setup()
{
    Serial.begin(9600);
    lcd.begin(16, 2);
    pinMode(sensorPin, INPUT);
}

void loop()
{
    switchState = digitalRead(sensorPin);
    int readVal = analogRead(sensorPin);
    double temp = Thermistor(readVal);
    Serial.print("Temp. : ");
    Serial.print(temp);
    Serial.println(" Celsius");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print(temp);
    lcd.print(" C");
    delay(500);
}

I think the problem is the

lcd.print(temp);

Try casting it to a float from a double (and two decimal places).  Maybe you just need the decimal places.

lcd.print((float)temp, 2);


Can I use the nRF8001 Bluefruit LE Breakout on 3.3V instead of 5V on my Arduino Uno?

Yes. That nRF8001 board runs on 3.3V. And do make sure that using it with a 5V-Arduino, they put a regulator that steps down 5V to 3.3V. Which is why if you have 3.3V already, you connect it to Vin, and you're good to go.


HTU21 on GY-21 breakout board I2C problem

Yes the setup runs completely. I found out that the bus hangs if I terminate communication by uploading new code to the board. I found a piece of code that releases the bus which works. See below:

#if defined(TWCR) && defined(TWEN)
  TWCR &= ~(_BV(TWEN)); //Disable the Atmel 2-Wire interface so we can control the SDA and SCL pins directly
#endif

  pinMode(SDA, INPUT_PULLUP); // Make SDA (data) and SCL (clock) pins Inputs with pullup.
  pinMode(SCL, INPUT_PULLUP);

  boolean SCL_LOW = (digitalRead(SCL) == LOW); // Check is SCL is Low.
  if (SCL_LOW) { //If it is held low Arduno cannot become the I2C master.
    return 1; //I2C bus error. Could not clear SCL clock line held low
  }

  boolean SDA_LOW = (digitalRead(SDA) == LOW);  // vi. Check SDA input.
  int clockCount = 20; // > 2x9 clock

  while (SDA_LOW && (clockCount > 0)) { //  vii. If SDA is Low,
    clockCount--;
    // Note: I2C bus is open collector so do NOT drive SCL or SDA high.
    pinMode(SCL, INPUT); // release SCL pullup so that when made output it will be LOW
    pinMode(SCL, OUTPUT); // then clock SCL Low
    delayMicroseconds(10); //  for >5uS
    pinMode(SCL, INPUT); // release SCL LOW
    pinMode(SCL, INPUT_PULLUP); // turn on pullup resistors again
    // do not force high as slave may be holding it low for clock stretching.
    delayMicroseconds(10); //  for >5uS
    // The >5uS is so that even the slowest I2C devices are handled.
    SCL_LOW = (digitalRead(SCL) == LOW); // Check if SCL is Low.
    int counter = 20;
    while (SCL_LOW && (counter > 0)) {  //  loop waiting for SCL to become High only wait 2sec.
      counter--;
      delay(100);
      SCL_LOW = (digitalRead(SCL) == LOW);
    }
    if (SCL_LOW) { // still low after 2 sec error
      return 2; // I2C bus error. Could not clear. SCL clock line held low by slave clock stretch for >2sec
    }
    SDA_LOW = (digitalRead(SDA) == LOW); //   and check SDA input again and loop
  }
  if (SDA_LOW) { // still low
    return 3; // I2C bus error. Could not clear. SDA data line held low
  }

  // else pull SDA line low for Start or Repeated Start
  pinMode(SDA, INPUT); // remove pullup.
  pinMode(SDA, OUTPUT);  // and then make it LOW i.e. send an I2C Start or Repeated start control.
  // When there is only one I2C master a Start or Repeat Start has the same function as a Stop and clears the bus.
  /// A Repeat Start is a Start occurring after a Start with no intervening Stop.
  delayMicroseconds(10); // wait >5uS
  pinMode(SDA, INPUT); // remove output low
  pinMode(SDA, INPUT_PULLUP); // and make SDA high i.e. send I2C STOP control.
  delayMicroseconds(10); // x. wait >5uS
  pinMode(SDA, INPUT); // and reset pins as tri-state inputs which is the default state on reset
  pinMode(SCL, INPUT);
  return 0; // all ok
}

Thanks for pointing me in the right direction!


Can I use arduino to generate 8mhz frequency ultrasonic pulses in piezo discs?

With 8 Mhz pulse, I assume you mean a pulse of 0.125 µs duration every second. "Frequency" may be misleading here.

Since the ATmega328 in the Arduino Uno is only clocked at 16 Mhz, you only have one extra cycle before having to turn it back off. Debugging and developing at this sort of speed absolutely requires a good oscilloscope.

I would attempt setting your output pin via register, and then turning it off again right after. Use cli() to prevent interrupts during your desired pulse.

void setup() {
  DDRC |= (1 << DDRC0);   //Set PC0 as output (Analog Pin 0)
}
void loop() {
  cli();                  //Disable interrupts
  PORTC = 0b00000001;     //Set Analog Pin 0 HIGH
  PORTC = 0b00000000;     //Set Analog Pin 0 LOW
  sei();                  //Enable interrupts again
  delay(1000);            //Delay for 1000ms until next pulse
}

Beware that this would also set all other pins on Port C (Analog Pins 1 through 5) LOW.

This

  PORTC |= (1 << PORTC0);     //Set Analog Pin 0 HIGH
  PORTC &= ~(1 << PORTC0);     //Set Analog Pin 0 LOW

would be cleaner and only affect Analog Pin 0, but it may take more than one clock cycle to execute.
Unfortunately, I don't have a quick enough oscilloscope to try this out.
If it is too fast (e.g., you get a pulse of duration 0.06125 µs, you may want to insert another PORTC = 0b00000001; before turning it off again. It is not unlikely that compiler optimization might just remove this when compiling, so you may have to set some other register to waste that one clock cycle.


LCD display not working properly + inconsistent results

I re-soldered the pins. Also, I used a small resistor between my PWM signal and the VO port. Now it works perfectly.


Can I use this pinhole camera with arduino?

No, you cannot use this with an Arduino without additional hardware in between, and even with it, not as more than a still camera (or maybe low quality video for one of the ARM- rather than ATmega-based boards).

The first problem is that this camera has a high speed analog output called composite video.  It is basically what would be fed into a modulator to produce an old-style analog TV signal.  Capturing this digitally requires an Analog to Digital converter (ADC) capable of several million measurements per second, while that on the classic ATmega-based Arduino tops out at around ten thousand.

But let's say you had an additional Analog-to-digital converter to put in between this and your arduino.  The next problem is that the data rate out of the camera will be too high, and the Arduino won't have enough RAM memory to buffer it.

In theory, you could get a "frame grabber" consisting of an ADC and its own buffer memory, which would take a still snapshot of the video and allow the arduino to read it out more slowly.  But you can buy cameras which already do that with their onboard electronics, and allowing something like an Arduino to read the still image data out over a moderate speed serial interface.

Even the ARM-based arduino boards would be taxed to keep up with the output of a video ADC and do much of anything useful with the results - typical digital cameras do not record raw images to SD card, but do JPEG compression within a frame.  When cheap digital cameras operate in video mode, they compress each frame of the video before storing it (just as with stills - they do not compress between frames in the manner of real video recorders), and are able to get that processing done in time because the actual computing hardware is optimized for it in a way that none of the Arduinos are.

If you want to experiment with a camera on a development platform, there is one with a high speed digital interface sold as an add-on for the Raspberry Pi board.  Or you can use a more inexpensive USB webcam with that.


Drawing 20A on 12V means 240W which on 110V is 1A and a bit (a bit more once you consider efficiency of the conversion).

The spec sheet of the power supply you linked says that it will draw 2.7A max on a 115V input.

The power supply will convert the high voltage low amps into low voltage high amps.


Replace mechanical switch with electrical switch or relay

I would unsolder the switch then solder in a FET in the configuration shown below. The FET will act as a switch and may be controlled with any digital output from your Arduino board. When selecting a FET makes sure you find something that will fit the foot print you have to work with on your board, and the gate-source threshold voltage is rated to handled 5V.


Can send AT+ commands, but can't upload sketch to ESP8266 via Arduino Uno

You mention:

  connecting GPIO0 and GPIO2 to to Vcc or ground

I've had success with this sequence:

GPIO0 to gnd (and hold momentarily)
RST to gnd (then let go, while holding GPIO0 to gnd)
let go of GPIO0 from gnd (e.g. let it float again)

To do a firmware flashing, you need to hold GPIO0 to ground for the duration of the flashing process, so the sequence would be slightly different.

You can do this just prior to "build and upload" in the Arduino IDE—provided the build process doesn't take too long.  It will sometimes still fail, in which case reset the ESP8266 (RST to gnd momentarily) and restart the sequence.

I've found a little test/development harness (like this one http://www.buildcircuit.com.au/esp8266-test-board) is very handy for doing this repeatedly.


I would add a delay(100); to the bottom of your loop()

I'm betting even odds that solves it.


Cannot start Arduino IDE after playing with several versions of it

You do not need to install Arduino at all. In fact I have never had it work right due to things not being found.

All you need to do is, from a terminal, run the arduino command in the extracted directory:

fred@computer:~/arduino-1.8.5 $ ./arduino

Any errors that then throws will be a clue as to why it doesn't want to work.


How does use an arduino like a A/D converter for convert 3 analogue signal from 3 poteciometer to a raspberry?

It is not clear what you mean by “digital port”. The simplest mean to
communicate from the Arduino to the Raspberry is to use the Arduino's
serial port, which gets into the Raspberry Pi through USB. Just like you
would do if you had a PC instead of the Raspberry:

/*
 * Continuously report the analog readings on pins A0 through A2.
 */

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

void loop() {
    Serial.print("0 "); Serial.println(analogRead(A0));
    Serial.print("1 "); Serial.println(analogRead(A1));
    Serial.print("2 "); Serial.println(analogRead(A2));
}

This program will continuously output a text stream like this:

0 145
1 220
2 865
0 142
1 223
...

where the first column is the analog channel number and the second
column is the ADC value. How you handle this stream on the Raspberry
side is up to you.


Will 5V 2A current input to the power port kill my Arduino?

"I want to power my arduino with mobile charger the out put is 5v 2apms will it kill my arduino?"

No! It won't. Even tough the reason has been already explained in this other post, I want to add something.

First of all, your question is really common among the ones who, like you (and me), have little/none electrical/electronic knowledge: if you ask such a question, it means you lack the "basic". This is perfectly ok, as we're here to learn "Arduino"... and this (typically) means we're here as the first step towards the electronic world. This is the very reason why I'm writing this answer. So... back to your question....

You're missing a key point, here: the maximum current that your power supply can provide.... is a maximum! And this does NOT means that such a maximum will be given always, and regardless of the devices connected to it!

In other words:

if you have a device that requires a very little amount of current to properly operate (as an example, this DHT22 sensor, requires as little as 2.5mA, or 0.0025 A) and connect it to your 2A power supply, what will happen is that along the wire from your power-supply to the DHT22 will flow only 0.0025 A of current;
if you have 100 (one hundred) DHT22 connected in some exoterical network/schematic, each one requiring 2.5mA of current, in order to power the all of them, concurrently, you need 2.5mA * 100 = 0,25A (or 250mA), that means that again, your power-supply, will be more than enough (to power the all of them, concurrently);
if you have 1000 (one thousand) DHT22, than you'll need 2,5A (or 2500 mA) and... if you need to power the all of them, concurrently, and if you need to stick with your power-supply (capable of "only" 2A)... you'll have problems, as your power supply will not be able to provide the amount of current required by your equipments (Which kind of problems you'll encounter is a matter for a different question!)

To be more specific:

a common/base Arduino MEGA, without any external component connected, requires around 170mA of current;
an common/base ethernet shield, requires 180mA of current;

So, if you plug your 2A power-supply to the USB socket of a MEGA which has an Ethernet shield mounted on its top, than your power-supply will have no problem at all in powering such two devices (as they jointly requires 350mA of current).

you'll be able to power up to 6 of those MEGA+EthShield, as 6 x 350 = 1900mA, which is lower than 2A. Anyway, it's common practice to not require the maximum! It's good-style to not exceed 75/80% of the maximum, as sometimes, based on the quality of your power-supply, some "strange" things start happening when reaching the top!

In the above discussion we talked about "current", without taking into account the "voltage". Anyway, "voltage" is another key-point as "voltage" and "current" are strongly related.

In your OP you mentioned "mobile charger ... 5V" so I bet that you've an USB power-supply, rated at 2A/5V.

People starting playing with Arduino, should use such 5V power-supply to power Arduino trough the USB socket: it has been designed exactly to be connected to a 5V power source, being it an ad-hoc power-supply (with an USB termination) or an USB cable connected to a computer. As for this last case (a computer), please note that:

as for the USB2 specification, every USB2 "host" should be able to provide at least up to 500mA of current at 5V;
as for the USB3 specification, every USB3 "host" should be able to provide at least up to 900mA of current at 5V;

So, supposing you have an USB2 port on your PC and that you connect an USB "simple hub" (an hub without an explicit power-socket) to such port, you can connect only one MEGA+EthShield as this will require 350mA (of the 500mA available). If you have an USB3 port, you can connect 2 of them (and you can also try with three... but with unexpected results).

As for voltage, please note that you can power a tipical Arduino (eg: UNO or MEGA) also via a barrel-jack, providing a voltage inline with what specified by official documentation:

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

The above statement introduce the "voltage regulator". This is another key-component that you should be familiar quite soon. At a very high-level, think to the "voltage regulator" as a magic box that:

from one side (the external world) receive a not-so-stable-and-clean current, flowing in the range 7V-12V;
apply some "magic" to such a current and bring it down _to_a_very_precise_ 5V flow;
provide the resulting 5V potential to the "internal world" of Arduino.

In other words, the voltage-regulator is responsable for providing the exact/constant 5V required by Arduino components, by relying on some "unstable" external current.

You might wonder how is possible to "lower" a 12V "input" to a 5V "output". I really don't know (and, actually, I don't care!). Anyway, a fundamental concept to be kept in mind is that such a reduction will produce "heat"! And the more you lower... the more heat it will produce! And the more current you'll "transform", the more "heat" it will produce! ...and if such heat will not be dissipated properly, chances are high that... something will stop working quite soon!

Having said all the above, please note that I'm well aware that lots of other concepts should have been discussed/introduced and that I have done some big oversimplification in the above description. Anyway, I really think that.... should someone had told me those concepts when I did my first steps in Arduino, my experience would have been shorter (...and easier). Nevertheless... don't blame me if you'll discover that those above will result mostly useless once you'll get slightly expert :-)


Arduino acts odd when disconnected from computer

What seems is that you are facing an power shortage while working with on board power supply.
While running DC motors and Arduino on same battery set your Arduino is not getting enough power.

Try switching to a better power supply which can maintain a constant EMF, as eventually you'll always run out of power.
Try an adaptor to use wall socket current.
This way you'll not lose any functionality of Arduino project.


The AVR pocket programmer should work fine. Sparkfun has a good guide for doing this.

Here's the pinout of the Atmega328:

You'll want to connect your programmer as follows (note, these are the pins for the bare Atmega328 chip only. The pin numbers on an Arduino board are different.):

Programmer Pin		Atmega328 Pin
5V			Vcc (7)
GND			GND (8)
MOSI			Digital 11 / Physical 17
MISO			Digital 12 / Physical 18
SCK			Digital 13 / Physical 19
Reset			Reset (1)

Note that the physical pins on the chip are numbered differently than the logical pins. In the table above the "Digital" pin numbers are those colored yellow in the figure, while the "Physical" pins correspond to the black-on-white numbers around the edge.

If you already have the ICSP header connected to those pins (it's not completely clear in the schematic if that is the case), you can connect the programmer to those pins instead. This can be easy if you have a 6-pin ICSP cable with your programmer.

Also, if you are already powering your Atmega328 from some other 5V power supply you can omit the 5V-Vcc pin. However, the programmer and the Atmega328 must share a common ground, so be sure the GND pins are connected.

Connect your programmer to the computer using USB, open the Arduino IDE, select the correct serial port of the programmer, and pick "Arduino Uno" in the "Board" menu. You can program the bootloader by selecting "Burn bootloader" in the Tools menu, or you can simply write your program by selecting "Uploading using programmer" in the File menu.


Arduino clone with ch340G and correct w7 x64 driver cannot connect to IDE

Solved:
The issue was due to an USB Hub which I have at my desktop.
After I connecting the arduino directly to an USB port at my desktop everything was fine.
Unfortunately there is no hint about this in the arduino troubleshooting guide. A hub is only mentioned in conjunction with a MAC.


How do I check if a password is right? (keypad input)

Without knowing how the pass.* works, it will be impossible to pinpoint the problem.
'key' gets an ASCII value. Is that would you are expecting?
Does pass.* reset (start over) once 4 digits?
Just a guess, but I believe that *.waitForKey() does not consume the key.
The algorithm only gets the key four times; then, it checks.


Using SDA and SCL with analog inputs at the same time

No. You can't. Not unless you could come up with some way of disconnecting one set of devices and connecting the other.

Instead you could add an I2C ADC chip to the existing SCL/SDA bus to expand the number of ADC channels you have available. Or use an analog MUX chip on one of the other ADC pins to expand the number of devices you could connect to it. Or you could add an SPI ADC chip to pins 10-13 (SPI bus) to give you more analog inputs.


Arduino Due: ADC gain adjustment problem

Well, the solution was very simple. We just need to call adc_enable_anch() before changing gain or offset of the ADC. I improved my setup and the sketch works as expected now:

void setup() {
  analogReadResolution(12);

  // Configure ADC gain
  // Arduino/hardware/arduino/sam/system/libsam/include/adc.h
  adc_channel_num_t ch = (adc_channel_num_t)(g_APinDescription[aPin].ulADCChannelNumber);
  adc_enable_anch(ADC);
  adc_set_channel_input_gain(ADC, ch, ADC_GAINVALUE_3);

  Serial.begin(9600);

  // Delay for serial stabilization
  Serial.println("Begin.");
  delay(2000);
}


Digital map in A* search algorithm in Arduino

first off, you need 2D array to store map segments.
then you have to update them according to the real map.
you have to implement a few measures:

a series of sensors to qualify adjacent segments. e.g. walls/road. map edges are considered walls.
an array (list) of current adjacent segments. (just a 4 member array, containing the up/down/left/right location. this array stores the index of the mentioned segments in the main 2D array.)
a beacon or something like that at the goal position. you can evaluate the segments based on the distance from beacon. (the simplest method, cartesian distance).
run a iteration of A* alg to find out which adjacent segment is suitable for next move.


Why does the Pro Mini 5 v and 3.3 v version have different clock frequencies?

The ATMega328p is not rated to operate at 16 MHz on a 3.3v supply.

In practice it may sometimes work, but cannot be considered reliable.

The data sheet will show the actual clock rate vs. voltage tradeoffs, so there might be an intermediate value that is workable for you.

The Arduino toolchain needs to know the CPU clock frequency for the serial baud rates, timing delay code, and any time-based use of the timer peripherals to come out right.

There is a special case where if the configured clock rate and the actual clock rate differ by a factor of two, you may be able to cover that by selecting a similarly wrong baud rate - however, the baud rate in the bootloader was set in comparison to the expected clock frequency when it was compiled before flashing, and the baud rate expected of the bootloader is set in the boards file, so less readily changed than it is in something like the serial monitor.


Two serials can't work on the same speed

I spent some time playing with your code and it seems your code actually loops the serial therefore if they are both set at 9600 as example and you print what the other one is sending like in your code you end up in a loop if you want to read what your serial is sending it is better put that values in a variable and send it

if you load your code you will get the following message in the arduino IDE once you try to connect to the serial monitor:

Error opening serial port 'COM8'. (Port busy),

your port is busy because the one serial port is reading the other all the time

one more thing I would use the following if you want to repeat a serial port:

  if (mySerial.available())
  {
    //char c = mySerial.read();
    Serial.write(mySerial.read());
  }

Hope this hels you


You probably want to use two SPI busses. If you absolutely need to use one bus, attach a digital out pin to each of the CS pins, one on the 1262 and one on the SD card. When you need to talk to one of the deviced, pull its CS line low to enable it.


What difference between readString and while loop read

Your while loop reads all the characters up until it reaches character 0 (it also has a timeout, although the timeout has been coded wrong since it can't deal with clock rollover). The .readString() method reads characters until no characters arrive within a timeout period (1s if memory serves me correctly).

Your while loop is the more reliable method since it uses a specific delimiter to identify blocks of data (strings) rather than assuming that:

The string will all arrive with no delays greater than the timeout
The strings will be sent with a gap of at least the timeout length between them.

Personally I would never recommend using any of the "helpful" functions provided for reading from a Stream object other than the basic .read() function.


The cause of the problem is that you have a corrupted library index file. The solution is to delete the file, which will force the Arduino IDE to download a (hopefully) uncorrupted fresh version from the Internet:

Open the C:\Users\JK\AppData\Local\Arduino15 folder
Delete the file library_index.json
Try starting the Arduino IDE again

For anyone encountering this problem who is using an operating system other than Windows, the location of library_index.json is different:

On Linux:

/home/{username}/.arduino15 (a.k.a. ~/.arduino15)

On macOS:

/Users/{username}/Library/Arduino15

If using the Arduino IDE in portable mode:

{Arduino IDE installation folder}/portable

The issue of a corrupted library index file preventing the Arduino IDE from starting has been reported to the Arduino developers and they are already working on a fix:

https://github.com/arduino/Arduino/issues/7937