Sketch with multiple classes (.h and .cpp) - how to interconnect classes

In RemoteDisplay.cc you are using Remote in the Initiate method.

Also, since you use the voltage property, you need to include "Remote.h" within (as first line normally) in RemoteDisplay.cpp.

Also it is advised to use within every header file the following pattern (example for RemoteDisplay.h):

#ifndef REMOTE_DISPLAY_H
#define REMOTE_DISPLAY_H
...
...
#endif // REMOTE_DISPLAY_H

This prevents problems that two include header files forever include each other.


The SPI.transfer() method is designed to send a byte through
the SPI port and, at the same time receive an incoming byte.
Usage pattern:
uint8_t byte_to_send = ...;
uint8_t received_byte = SPI.transfer(byte_to_send);


How to display an entire incoming string from the serial monitor in arduino ide?

If you really want a string. Try using Serial.readString(). It will return the full string.

The code could look like this:

if(Serial.available()
{
  string message = Serial.readString();
  Serial.println(message);
}


I did fix the problem now.

My mac has USB-C and I was using a single USB-C to USB Dongle. And the serial port never showed up on my mac:

crw-rw-rw-  1 root  wheel   18,   5 Mar  8 10:53 /dev/cu.Bluetooth-Incoming-Port
crw-rw-rw-  1 root  wheel   18,   7 Mar  8 10:53 /dev/cu.Heinz-WirelessiAP
crw-rw-rw-  1 root  wheel   18,   3 Mar  8 10:53 /dev/cu.MALS
crw-rw-rw-  1 root  wheel   18,   1 Mar  8 11:02 /dev/cu.SOC

As soon as I used the Satechi USB Dock the Silicon Labs USB to UART port showed up in the list:

[...]
crw-rw-rw-  1 root  wheel   18,  13 Mar  8 11:04 /dev/cu.SLAB_USBtoUART

I can now communicate with the ESP32:

esptool.py --port /dev/cu.SLAB_USBtoUART read_mac

esptool.py v2.6
Serial port /dev/cu.SLAB_USBtoUART
Connecting........___
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: XXXXXXXXX
Uploading stub...
Running stub...
Stub running...
MAC: XXXXXXX
Hard resetting via RTS pin...

Please note that if you'll need the Drivers for the USB to Serial Chip from Silabs.

If you do not see the device showing up you'll need to load the kernel extension:

sudo kextload /Library/Extensions/SiLabsUSBDriver.kext/

After this you might to confirm the extension in the Privacy section of the mac settings. See this forum post for reference.


Need to filter low voltage from a piezo buzzer circuit

Not every buzzer is a piezo buzzer and not every buzzer does the buzzing by itself. Some buzzers have only a piezo disc and for those a tone signal is needed to make it beep. Other buzzers only need a DC voltage and they start buzzing at a fixed frequency. The actual sound can be generated with a piezo or a electro-magnetic element (like a mini speaker).

I'm not sure which buzzer you have. I think it will not draw a lot of current, therefor a zener diode of 5.6V should work.


Why is the nRF24L01 not working with Arduino Esplora?

Looking at your output either you have a wrong wiring or, more probably, you need a capacitor between the nRF24 positive and negative pins: anything between 10uF and 100uF will do.


You can try software serial communication between the two boards. Any two digital pins of one board can be used as Rx and Tx, and make sure the roles of Rx and Tx are reversed on the other board. See the Software Serial library:
https://www.arduino.cc/en/Reference/SoftwareSerial


What is the purpose of F() and FPSTR() in ESP8266WebServer -> FSBrowser?

The purpose of the PSTR() macro is to configure the string to be used directly from flash memory. The string is then not loaded to dynamic memory at runtime as it would be without PROGMEM specifier set by the macro.
The purpose of the FPSTR() macro is to cast a string to 'dummy' FlashStringHelper type to help compiler choose the right overloaded function if dynamic memory and flash memory version of a function is available. An example would be the print function.
The F() macro combines this two macros. It makes the string a PROGMEM string and casts it to FlashStringHelper.


Read the datasheet.
Figure out which pen mode works for you and which prescaler and top you need.
Set timer1 to that mode.

After that all you need is to load the duty cycle register with the desired value.

For your application leave the top value alone.

Your code is far from that.


How do I set up an Arduino to be a wireless HID?

I'm not sure for Arduino, but it has been done with ESP32. If you have not yet spent the money into a Bluetooth module for Arduino, you'll find that the ESP32 is not expensive either.
You can find the code on Github. The author uses a TinyPico because it's pin compatible with one of his earlier projects. IMHO, any ESP32 should do as well.
The key thing is to
#include <BleKeyboard.h>

the ESP32 BLE Keyboard library that you need to download and install. That library comes with example code that should be easy to adapt to your needs.
You can program the ESP32 in Arduino IDE, but you need to add support for the boards by adding a URL to the board manager.
Have fun with the project. It sounds very interesting. Maybe I try that myself.


Its not FIFO that is the issue, its the FIFO Buffer that you need with an Arduino.  The Arduino can't download the data from the camera at the same speed as the camera can send it.  Adding this extra buffer in lets the camera generate the data and the Arduino download it (in the same order that it was generated) at its own pace.

You might not need the FIFO buffer for faster microprocessors, but you do need it for the Arduinos.  You could get your own buffer and rig that up, but for a few extra bucks let them do it for you.


Attiny45 resets when setting digitalOutput to low

Including the 220Ω resistor with the LED as in the last step?

...

  My LED can handle 5V, so I used it without, but that cant be the issue

The one thing that "can't be the issue" is indeed the issue! Without a resistor the LED will attempt to conduct a lot of current which will damage both it and the output pin of the processor.

See The care and feeding of LEDs. From that page:

  LEDs are not like normally electronic devices in that you can’t just apply a voltage to them and they work, they have to be fed the correct voltage and current to keep them happy.

And then:

  There are several web sites and schematics on the web that suggest you can attach an LED directly to an Arduino output pin with no current limiting resistor. They are wrong, and following them will damage your Arduino.

So, by not using a resistor, when the output pin goes LOW it attempts to "sink" current, in order to turn on the LED. Since you have no resistor, it sinks as much as the output drivers can handle, dropping the supply voltage inside the Attiny, which then goes below the brownout level, and resets itself.

Please, when following a circuit, don't just omit bits of it, and then post a question about why it doesn't work. At least follow the circuit exactly, and then when you have learned more about electronics, you can start experimenting.


How to find out whether an arduino can control a servo motor

An Uno most definitely cannot directly control that motor. According to the specs here,

  They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA

So your motor has needs about ten times the voltage and 200 times the amps that the Uno can supply. Of course, you can always get a driver of some sort for the servo.


Can I directly connect an ESP GPIO pin to the base of the transistor where the arduino is connected?

No. You will effectively be connecting two outputs together, and that is very bad.

Instead you will need to add a second transistor in parallel to the first - one controlled by the Arduino and one controlled by the ESP-01.

  Can I put a relay module between the arduino and the battery pack and connect it to the ESP?

Sure. No problem with that.

  I will connect the relay so that it will disconnect power to the arduino only when powered on. Is this a viable solution for a kill switch?

As long as the kill switch doesn't also shut off power to the ESP-01 - otherwise it will just switch on again straight away...


The ADXL345 has both a FIFO and data rate setting. This allows sampling to be done with a precise frequency without having to use timers, etc, on the MCU. The MCU/Arduino has to fetch data before the FIFO overflows. The max sampling frequency depends on the communication protocol (I2C or SPI), i.e. how fast the MCU can empty the FIFO.

It is possible to use the ADXL345 in stream mode, collect samples at a fixed rate, and get an interrupt when the FIFO has been filled to a specified level (watermark). The samples can then be read in burst mode.

The samples will be on a "precise time-scale".

There are even more advanced usages of the device with tap, double-tap and free fall detect.

Please see Data Rate setting and FIFO control in datasheet.

Cheers!

PS: Using I2C at 100 KHz will take 1 ms just to address the device. Addressing a register will take another ms and a ms per data byte. Reading the data register (six bytes) will take at least 8 ms. Realistic max sample rate with I2C at 100 KHz is 10-100 Hz. There is also limited amount of memory for buffers.


Remove hasSD && from void handleNotFound() function.
It worked for me.


Those print() and println() are just sending text from the client to the server using the TCP/IP connection (which was setup by connect()). What's important though is that those lines of text follow the HTTP specification for request headers.

The HTTP specification defines various pieces of header information which the client can send to a server. Some of the information is mandatory, but there are lots of other optional headers too which can be helpful.

When the server receives these headers, it's nothing more than a bunch of text. There's nothing special about it. It has to assume or detect that it corresponds to the HTTP specification, and parse them appropriately to understand the details of the request. For example, the very first line specifies the resource (file) being requested, i.e. "/abc.txt".

The lines you mentioned are examples of optional information. The User-Agent header simply tells the server what kind of system and/or browser is requesting the information. In many cases, servers basically ignore this information. They might log it for statistical purposes, but they don't actually act on it. However, other servers may use it to decide exactly what information to send, e.g. showing a tablet-friendly version of a website if someone is accessing it from an iPad.

The Accept header can be used by the client to indicate what format of information it expects. Assuming the server honours it, this can be useful to ensure you don't accidentally download a format you can't handle. For example, the Arduino could happily process a little bit of plain text or HTML, but probably couldn't do anything useful with a JPG image.

For more information about the HTTP specification: http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol


Controlling DC motor from Android device

The short answer is "you can't." For the Arduino to do anything useful it needs to have instructions telling it what to do. In your example the Arduino's job is to do something that the Android can't – turn on and off the DC motor. You could even use a wifi or Bluetooth connection from the Android to the Arduino to make it possible to avoid the hassle of the USB cable.

Your project requires a number of small hunks of code on the Arduino to:

Listen for commands from the Android.
Validate the commands received.
Turn on or off the motor.

Roughly speaking your loop() function might look something like this:

void loop() {
  // look for a command
  // validate the command
  if (valid && turn_motor_on) {
    motor_on();
  } else {
    motor_off();
  }
}

Fortunately the Arduino code can be very simple and there is a lot of example code to help you get started.


I think you have a problem with your math here, not with your code. What
you are simulating is very similar to a 1-dimensional random
walk.
According to the linked MathWorld page, for such a process “the most
probable number of sign changes in a walk is 0”.

If, at some point in your program, the loop starts with note == 6, and
then it starts randomly going up, there is a sizable probability for it
to never go back to values below 7.

Edit: One possible solution could be to avoid the random-walk notion
and instead repeat the random choice always from the same starting
point.

int oldNote = note;  // starting point
do
    note = oldNote + random(-2, 3);
while (
    note == loop1[i - 1] ||
    note == loop1[i - 2] ||
    note > 6 ||
    note < 0);
loop1[i] = note;


How does supply voltage affect `analogRead()` on AVR-based microcontrollers?

The ADC measures a voltage ratio. The conversion result is the rounded
value of 1024×V/Vref, where V is the voltage at the input and
Vref is the voltage reference.
In the default Arduino configuration, the reference is connected to Vcc.
This will not fit your use case, as the voltage you want to read does
not vary proportionately to Vcc. You could use an external reference.
However, the ATtiny85 has two internal voltage references at 1.1 and
2.56 V. Either of these may be well suited for you application,
which should save you having to add an extra part.
See the chapter on the ADC in the datasheet for details on
how to select the voltage reference.


How to trigger NodeMCU sketch from Arduino Leonardo Micro Pro?

HW part:
It's like button, simply connect arduino micro pin to nodeMCU pin and GND of arduino to GND of nodeMCU.
It's also good idea to use two resistors as voltage divider because arduino micro works with 5V and ESP8266 (nodeMCU) with 3V3. 5V can destroy ESP8266 but this thing is still not really clear.
Resistor divider connect as in this link link about resistor divider for uart but instead of TX put arduino micro and instead of RX nodeMCU.
resistor divider schematic

Code part:
On the arduino micro part use:

In void setup():
pinMode(PIN, OUTPUT);

In your marked place:

digitalWrite(PIN, HIGH);
delay(100);   //short wait time
digitalWrite(PIN, LOW);

nodeMCU part:

In void setup():
pinMode(PIN, INPUT);

Remove everything from void loop() and put there this:

if(digitalRead(PIN) == 1) pushover("OMG, Yes it works!!!");

In both codes select the PIN according to your choice.


My Ultrasonic sensor is only showing 4cm range?

Looks to me like your powering the SR04 with 3.3v instead of 5v.


using an ESP8266 shield on my Arduino Uno R3 with an unofficial library

That is not a library for the Arduino. That is a core for programming the ESP8266 directly as if it were an Arduino itself.


Does Adafruit PowerBoost 1000 Charger support data transfer?

No it doesn't.

As you can see from the schematic the incoming data lines aren't connected, and the outgoing are wired through appropriate resistors to set the current availability.


WS2812B only works while I measure the voltage

WS2812B LEDs are 5V devices. The NodeMCU is 3V.  Your first 5V supply will probably have been somewhat under 5V once the NodeMCU had taken a big chunk of the current (see Voltage Droop). This would mean that the Logic High Threshold would be within the bounds of the 3.3V output by the NodeMCU.

However, with your new high powered power supply that voltage droop will be less prevalent (added to the fact that it's measuring 5.2V), and so the logic high threshold will be higher. At, or very close to, the 3.3V that is output by the NodeMCU. That makes it rather unstable at communicating, since the logic HIGH may not always be above that required HIGH threshold.

Adding your voltmeter obviously changes that logic signal so that it stabilizes above the required threshold (the volt meter input has capacitance. That will help hold the line higher for longer).

To drive 5V devices from a 3.3V MCU you really need to add a logic level shifter, or ensure that the power supply isn't too high.

The WS2812B has a logic HIGH of 0.7 × Vdd. At 5V that's (0.7*5=) 3.5V. That's close, but not quite there. Your original power supply was probably putting out more like 4.75V under load. That would be 3.325V for a logic high - just about manageable by a NodeMCU.

However at 5.2V the logic HIGH will be 3.675V, which is way above the 3.3V that the NodeMCU outputs.

So you either need to:

Add a 3.3V to 5V logic level shifter, or
Reduce your LED power input voltage to below 4.75V.

The latter can be done by adding a single series diode with a suitable current handling capacity to the VDD connection. That will (depending on the diode) drop around 0.7V taking you to about 4.5V (the actual drop usually depends on the current to a certain extent).  The WS2812B will happily run from 3.5V to 5.3V.


Wiring a potentiometer to control a 9V battery powering 2 LEDs in series

Yes, Arduino is a 5V microcontroller, meaning it can directly control 5V circuits only. You might incur in problems also trying to deal with 3.3V circuits, even if Arduino is pretty friendly to 3.3V counterparts.

That does not mean though you cannot control higher voltage circuits, just not directly. Actually if anything above 6V is connected to an Arduino PIN you will blow that pin and potentially others which are logically connected within the MCU, so be aware.

To control higher voltage circuits you have multiple options, in your case you are probably interested into using a BJT transistor, an 2N2222 might do.

simulate this circuit – Schematic created using CircuitLab

Please note the values of R1 and R2 must be adjusted to the LEDs you are using depending on their Vf (forward voltage drop) and the maximum current you want to provide.


Mysterious RX pulses on UART connect on OS X Arduino Due

Short:

Looking at the ATMEGA16U2 firmware (https://github.com/arduino/ArduinoCore-sam/blob/master/firmwares/atmega16u2/arduino-usbserial/Arduino-usbserial.c) I find that, when you configure/change settings of the USB emulated serial port, the USART is resetted. This happens even when you open the Arduino Serial Monitor (it must configure the serial speed, etc.). This causes your spike.

Long:

Look at function:

void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)

There you'll see that after some lines, it resets the USART, by zeroing its registers:

/* Must turn off USART before reconfiguring it, otherwise incorrect operation may occur */
    UCSR1B = 0;
    UCSR1A = 0;
    UCSR1C = 0;

At page 168, of the current ATMEGA16U2 datasheet, you'll find that, by setting  UCSR1B's bit 3 (TXEN1), you enable the transmitter,  overriding the normal port operation (i.e. it becomes output). Quoting the datasheet:

  Writing this bit to one enables the USART Transmitter. The Transmitter
  will override normal port operation for the TxDn pin when enabled. The
  disabling of the Transmitter (writing TXENn to zero) will not become
  effective until ongoing and pending transmissions are completed, i.e.,
  when the Transmit Shift Register and Transmit Buffer Register do not
  contain data to be transmitted. When disabled, the Transmitter will no
  longer override the TxDn port.

Therefore, by writing UCSR1B = 0; you no longer override the TXD1 pin, which will act as input.

The ATMEGA16U2 TXD is connected to the ATSAM3X8E's RX line. In normal operation, with the UART enabled, that line stays high if no data is being transmitted. If you disable the UART, that particular line is no more driver to 1. Since the initialization code does not set the pull-up on that pin (and neither it's configured as output), the pin becomes a floating input, and any leakage to GND or even the input impedance of your probe (which is between your pin and GND), will slowly bring the logic level to 0.

To override this, problem, you should either:
1) Modify ATMEGA16U2 firmware, by setting that PIN as OUTPUT, with value 1.
2) Modify ATMEGA16U2 firmware, by enabling the pull-up on that pin.
3) (suggested) Enable the pull-up on the RX line on the ATSAM3X8E.


What's the difference/relationship between Arduino and AVR?

Arduino is a prototiping board, and also the term "Arduino" is used to referr to the IDE and library on the PC side, and all its ecosystem.
AVR is the architecture (developed by atmel) of the microcontroller chip used in all official 8bit board, and almost all clone.
Arduino UNO and 2009, the most used, use the AtMega328P chip.

Many times, Arduino is used to quick test some idea, sensor, and circuitry, then a stand-alone board is builded around the AtMega chip, as it cost 1/10 of the Arduino board, soldered ciurcuit on a stripboard or on a custom PCB are more reitable, and can be optimized on some aspect, like power utlization, space occupied, high current/voltage, and so on.

Newest and advanced arduino board use different chip with very different architecture; the arduino yun use a SAM plus a classic AVR, the due use an ARM (same architecture used by many smartphone), the galileo use an x86 (like a classic pre-multicore cpu)


Arduino hangs on second GSM message (was GSM based led matrix display)

Does nothing clear 'i' at the end of a message?  If not, then long/unexpected/multiple messages can overflow your str[160] buffer.

It also looks like writing to the msg[160] buffer isn't well protected from overflow.


Safely powering a relay from same source as attiny/arduino?

do I have to duplicate that circuit just for the relay?

No, not really, no.

  Is the ATTINY capable of triggering a 12v relay via ground?

The ATTtiny is capable of triggering a transistor - the transistor is capable of triggering a 12V relay.

Unless your relay is incredibly high powered and the coil takes (and generates through back-EMF) massive amounts of current, there really is no problem running it alongside a small microcontroller. Just be sure you have the flyback diode, and maybe a damping capacitor as well to absorb noise.

TBH you're probably going to be getting more noise from contact spark than you are from the relay's coil.


Wiring and Connecting WS2801 to NodeMCU ESP8266

Changing the first line from

 #define FASTLED_ESP8266_NODEMCU_PIN_ORDER

to

 #define FASTLED_ESP8266_RAW_PIN_ORDER

has solved the Problem.


Seems you have to run these serially, but not sure why it's an issue, a due is quick.

seems more programming related... 'detectColor' is a function, and this is run inside the loop i assume.

int taosOutPin1 = 10; //color detector 1
int taosOutPin2 = 2; //Pins are examples, change to actual pin...
int taosOutPin3 = 3;
int taosOutPin4 = 4; //color detector 4

typedef struct {
   float white;
   float red;
   float blue;
   float green;

} color;

void setup() {
  // put your setup code here, to run once:

}

void loop() {

color detectedColorForSensor1 = detectColor(taosOutPin1);
color detectedColorForSensor2 = detectColor(taosOutPin2);
color detectedColorForSensor3 = detectColor(taosOutPin3);
color detectedColorForSensor4 = detectColor(taosOutPin4);

Serial.print(detectedColorForSensor1.red);
Serial.print(detectedColorForSensor1.green);
Serial.print(detectedColorForSensor1.blue);
Serial.print(detectedColorForSensor1.white);

//etc for sensor 2,3,4............

}

color detectColor(int taosOutPin1) {

color detectedColor;

detectedColor.white = colorRead(taosOutPin1,0,1);
detectedColor.red = colorRead(taosOutPin1,1,1);
detectedColor.blue = colorRead(taosOutPin1,2,1);
detectedColor.green = colorRead(taosOutPin1,3,1);

return detectedColor;

}


Well first of all you are trying to name the variable char? which is already a keyword for the variable type of char.   But you can access it by the index of the array. Also not sure if you intended to make the array 8 bytes in length, and then only use 7, but thats what you had done in your example

//define it all at once
// byte byteArray[8] = {B10000,B01000,B00100,B00010,B00001,B11000,B11100};
//or by index
byte byteArray[8];
byteArray[0]=B10000;
byteArray[1]=B01000;
byteArray[2]=B00100;
byteArray[3]=B00010;
byteArray[4]=B00001;
byteArray[5]=B11000;
byteArray[6]=B11100;

//if you need to change one in the code elsewhere
byteArray[3]=B00110;
//or
byteArray[3]=6;
}


You can use the commonly available L298N module to drive four of your LEDs with each module. That means you would need five of them.

Those modules are suitable for driving either one stepper motor, two DC motors (in both directions), or four "unidirectional" loads such as your LEDs.

The input can be connected directly to your MEGA, but you may need additional series resistors depending on the LED you use (though this likely does not apply for LEDs specified as "12V").

There are also LED driver eval boards available which may suit your needs:
https://www.digikey.de/product-detail/de/adafruit-industries-llc/1455/1528-1019-ND/4990768


(just the IC, no resistors or capacitors)

  What might be wrong with my setup?

That's easy: You miss the capacitors ;-)
Check figure 5 of the datasheet and try again.


Using TXD1/RXD1 on ATmega1280 for USB communication

Not directly, no.

The USB interface connects to TX0 and RX0 - you have access to TX1 and RX1. The bootloader is set to look at TX0 and RX0.

You would have to compile and install a new version of the bootloader that is set to use TX1 and RX1.


You are confusing SPI, a de facto standard, with the Arduino/Atmel hardware support for SPI.

SPCR, SPE and SPDR are registers of the Atmel MCU, part of the hardware support.

ISR is Interrupt Service Routine and SPI_STC_vect is the vector that point to that code. That is where the data received from the cable is read finally.


Can't make my stepper motor run clockwise and counterclockwise with AccelStepper Library

The  “Performance” paragraph of the “Detailed Description” section of AccelStepper documentation says:

  The fastest motor speed that can be reliably supported is about 4000 steps per second at a clock frequency of 16 MHz on Arduino such as Uno etc. ...

and the AccelStepper::setSpeed () documentation says:

  ... Speeds of more than 1000 steps per second are unreliable

Try changing your 6400-steps-per-second setting to a some plausible number, eg 500 or 1000.

Actually, it would make sense to start out with moderate destination settings and speeds, like a target position of 200 instead of 16000, and steps-per-second of 100, or whatever count it takes for say exactly two shaft revolutions.  Once you have that working right, then start doubling numbers until it no longer works, after which you can back off by a factor of say four (to allow for variations in load, etc).


What requirements should components have to work with Arduino (UNO in particular)

When it comes to electronics, hypothetically anything can be connected to anything else. The only real barriers are time, cost, and practicality.

Two major things to look out for though are voltage and current requirements.

Most Arduinos operate at 5 volts, so it's often easiest to connect it to other electronic devices which also operate at 5 volts. That certainly doesn't mean you can't connect an Arduino to something that operates at 3.3 volts (for example). However, it means you may need to add some voltage level conversion circuitry (although it's not always necessary, depending on the context).

Regarding current, a critical issue to look out for is how much current something will draw. For example, a motor will often require more current than an Arduino can safely provide. That means you'd need some kind of external power supply which can be switched by the Arduino.

The most valuable thing to do is to learn to find and read datasheets. These give information about electronic components, specifying things like voltage, current, timing and so on. For situations where there's no datasheet available, you may find it useful to learn how to use a multimeter and an oscilloscope to monitor how equipment behaves.


SparkFun Monster Moto Shield current sensing issue

Can you show us how your code is looking like? Please remember that you can not measure current directly, the method that is used to do that is to measure voltage drop on measuring resistor.
Check this image


AVCC and AREF when using a reference voltage lower than 5V?

AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. Note that PC6...4 use digital supply voltage, VCC.

So it should be connected to 5V.


It doesn't sound like you are doing anything wrong as such, it all sounds fine.

However SD cards, certainly some cheap ones, don't like to play nicely with other devices on a shared bus. Also some SD card adapters with level shifting don't play nicely.

By not playing nicely I mean tri-stating the MISO line in a timely fashion (or at all in some cases) which stops any data getting out of other devices, and can even cause damage in some cases.

You should check out the level shifting on the SD card adapter to see if it has tri-stating control of MISO (if it is shifting that line, not all do), try other brands of SD cards, and maybe add your own tri-state buffer to the SD card signals.


Comparing a text string to text output (DHT22)

A "float" number has multiple possible states, besides just being a number (It never, though, can be compared to a string):

A real floating point number
Infinity
Something that isn't a valid number

The latter is what you want - that is, the internal data of the float variable doesn't represent a valid number.

There are two functions in the standard math library that deal with this for you.

Is the number infinity? ininf(x)
Is the number invalid? isnan(x)

To use it:

if (isnan(temp)) {
    lcd.print("Invalid");
}


As Majenko commented, you need to not only connect the data wires together but also the ground wire (from the Arduino to the Pi).

  ... the reading are very unstable ...

Without a consistent "ground reference" the readings would indeed be unstable.


Getting maximum value from HX711 and use it in the code further

We won't write the code for you, since we are not a free coding service, but I will try to give you some hints, how you can do it.

Timing of measurements: The measurements themselves can be done with one of the HX711 libraries, that are available on the web, but you may want to time them to get more regular measurements. This can be done in a non-blocking coding style like in the BlinkWithoutDelay example, that comes with the Arduino IDE. It involves the millis() function to measure the time since the last measurement and act accordingly. This is explained many times troughout the web and on this site.
Saving the data and finding the maximum: This depends on what else you want to do with the data.

Saving all data for later processing: You might want to save all data (the load curve) for later use. In this case you have to define an array of appropriate length (the length depends on the duration and frequency of the measurement). Also define a position variable or pointer, that marks the current position in this array. Everytime when you do a measurement, you save the result to the array element at the saved position and increment the position variable after that. After the end of the measurement, you declare a value variable with the value of the first array element. Then you loop through all the following elements (for(int i=1;i<array_length;i++)). Inside the loop you calculate and save the maximum of 2 numbers: The value of the current array element and the saved variable. This can be done with saved_value = max(saved_value, array[i]);. When the loop is finished, you will have the maximum value in the saved_value variable.
No saving of data: You can also calculate a flying maximum without saving all data. Declare a variable (max_value), that will hold the maximum value, and set it to zero. Then, everytime when you do a measurement, you execute max_value = max(current_value, max_value); which calculates the maximum of the two numbers (current measurement and the previously calculated maximum). At the end of the measurement you will have the absolute maximum in the max_value variable.

Sensing the end of measurement: You need to sense the end of the measurement (when the specimen breaks) (though this can be done manually if you like). For this I would suggest to calculate the speed in which the load changes. During the measurement the load will increase slowly. In the moment of breaking the load will decrease very fast. The speed between two load measurments is calculated by (value(x) - value(x-1))/measurement_interval. You can define a threshold of negative speed, so that every speed below it (faster negative decrease of load) will be sensed as breaking of specimen. You can check this on every measurement with a simple if statement, or you can calculate the speed over more than 2 consecutive measurements. That depends on the actual speed of load change and the frequency of load measurements.
Calculating the tensile strength: This is just writing your formula into the code using the variable names, that you used in the previous code. Be sure to use the correct variable type for your needs. Most likely you would want to use float.
Getting input from user: This depends largely on your planned means of interaction with the user. Is the Arduino connected to a PC and you use a serial terminal program? Then you can use this for user input (You might want to look at the SerialEvent example of the Arduino IDE, which shows how to work with messages and delimiter characters). Do you want to add a keypad and a LCD display? There are library available for these too, so it should not be very difficult to learn how to use then to get user input.


The microcontroller is executing one command at a time from..where?

Flash memory directly. The AVR core can only execute instructions from Flash memory. It uses a two-bus system known as Harvard Architecture, where the Instruction Bus is connected to Flash and is used to execute instructions, and the Data Bus is connected to SRAM, EEPROM, all the peripherals, GPIO pins, etc.

It is possible to jump to any location in memory in a similar way as you have depicted, but in order to know where you first need to know the functions you want to call.  You can get the address of any function and assign it to a pointer, and then call that pointer as a function, but what would that achieve? You may as well just call the function directly and save time. Unless you want to store the addresses of those functions in an array or something to maybe associate them with a command to trigger the execution of that function. In which case you don't need anything "fancy", just pointers to the functions you want to use.


RFID-RC522 Cannot read from MIFARE Ultralight

In the first lines of code there are two lines that say:

#define RST_PIN 9
#define SS_PIN 10

They define the RESET pin to be on the D9 pin and the SDA on the D10 pin.
So you have an connection error try connecting like shown and you should be good to go.


Adafruit_LSM303 tilt compensated compass

The sin() and cos() functions expect their arguments to be in
radians. If you feed them with anything else, be it degrees, percent
slope, or whatever, expect the result to be just crap.

Edit: The OP changed the question, invalidating my answer. So here
comes a new answer...

You have mistaken eventA.acceleration.y for cos(tilt),
eventA.acceleration.x for sin(tilt), and so on. They are not the
same. You may think they are the same up to some multiplicative factor,
and that's right. However, the factor doesn't cancel out as soon as you
do computations like sin(roll)*sin(tilt). Don't rush your math: if you
want to transform known-good formulas to more practical ones, check every
step of the transformation carefully.


Trying to use a 7 segment display to count 0/9 with a potentiometer

You miss the break statement at the end of each case. e.g.:

  digitalWrite (SegmentF, LOW);
  digitalWrite (SegmentG, HIGH);

  delay(1000);

  break;

case 4:

This causes each case to perform, and continue with the next case. However, since there is a delay of 1 second, it looks like it is counting.

Actually, I would expect it counts from a certain value depending on the pot meter to 7, since there is no digit 9 implemented, and the delay for the 8 digit is missing too.

To further improve your code, you can add the delay not in every case but at the end, since I assume there always will be one digit selected.

Also you can make a function void showDigit with a parameter for each of the possible segment states and replace all (almost) duplicated code by that function call, or send the digit and use showDigit to set internally the states of each segment (by using a boolean array[nr_of_digits][nr_of_segments], somewhat like Nic Hartley proposes below.


I don't think that will be an option. The NeoPixel parts need very tight control of the timing in order to work, if the pin timing is wrong by 100 us the wrong data will get latched in.

Can you move some other functions / pins onto the IO expander and then drive the neopixels directly from the processor?


1 - If A1 do Serial.print each 50ms and A2 reading serial each 100ms which value will get A2? For example A1 send "1" and after 50ms send "2". Considering A2 will read serial after 100+ ms it will get "2" ?

The Arduino has a 64 byte (software) buffer.  You will get the numbers in sequence up until that buffer overflows. Then it's not easy to predict what the results will be.

Probably something like:

121212121[...]2121212121212111111111111111

  2 - If A1 send data each 100+ms and A2 read at 50ms which value will get A2 between? For example A1 send "1" and A2 read "1" when read at 50ms but when it read again after 50ms (during that time A1 didn t sent anything ) will read again "1" ?

If there is nothing in the buffer the read function returns -1.  That can be mapped (IIRC) into ASCII (depending on your software) as ÿ so you would get:

1ÿ1ÿ1ÿ1ÿ1ÿ...

You should read my tutorial on reading serial on the Arduino.


Your description (“Servo goes to one end, and immediately travels back without a 2s delay... After it travels back there is a 2s delay before it loops”) implies an overall cycle time of 2 seconds, which appears to be inconsistent with the overall 4-second cycle implied by the code shown.

Here are things you can do to debug the problem:

Turn on an LED before one writeMicroseconds() call, and turn it off before the other.  For example, add pinMode(13, OUTPUT); in setup(), and revise loop() as follows:

void loop() {
    testservo.writeMicroseconds(700);
    digitalWrite(13, HIGH);
    delay(2000);
    testservo.writeMicroseconds(2300);
    digitalWrite(13, LOW);
    delay(2000);
}

This may allow you to find out which end the servo is going to.

Besides adding LED signals, try slightly-less extreme times in the writeMicroseconds() calls; eg 1000 and 2000 microseconds rather than 700 and 2300.
See if a neutral servo setting works, eg via code like the following.

enum { LEDpin=13, dtime=2000}
void stest(angletime, tHi, tLo) {
    testservo.writeMicroseconds(angletime);
    digitalWrite(LEDpin, HIGH);
    delay(tHi);
    digitalWrite(LEDpin, LOW);
    delay(tLo);
}
void loop() {
    stest(1000, dtime-50, 50); // Go CCW
    stest(1500, 50, dtime-50); // Middle
    stest(2000, 50, dtime-50); // Go CW
}

When this code runs, the LED should stay on about 2 seconds with the servo fully (or nearly so) counterclockwise.  Then the LED should blip and the servo should move to center position and stay there about 2 seconds.  Then the LED should blip and the servo should stay fully clockwise about 2 seconds.  This three-part cycle should repeat every six seconds.  If it works ok, then try modifying it, eg by changing 1000 us to 700, 2000 to 2300, etc, or by decreasing the dtime value to see how quickly the servo can respond, etc.


ESP8266: Multiple analog inputs using software

1) nope it's not possible "in a straightforward way". you should use analog muxes.

2) the statement "Each digital or analog pin on an Arduino can be configured as digital or "analog" (e.g., PWM software)." means for PWM or the so called "analog output". not intended the ADC unit.

3) the link provided uses software tricks to measure 2 signals in a muxed fashion. it's up to purpose.

workarounds :

1) use CD4066 CMOS bilateral switch. it works with analog signals.

2) use GPIOs to supply voltage to measurement units. like the link you provided. it works for passives like photoresistors and for devices like LM35 temp sensor. but can't be used for devices like 3 channels analog-out accelerometers.


How to fix error line number offset in Sublime Text when compiling for Arduino

The #line preprocessor directive is used to tell GCC both what the next line should be numbered as and what filename should be reported, and the plugin is not generating them properly. This is therefore a Stino bug.


The problem with driving the ADC faster is that the S+H circuit won't have enough time to reach the final value before the conversion is performed, meaning that precision will be lost.

The best thing to do would be to use an external ADC from e.g. TI or Microchip that has the capabilities you're looking for.


How do I connect a vibration sensor/switch to a breadboard?

It appears from this information source:
http://www.electrodragon.com/product/vibration-switch-sensor-sw-18020p/
that the sensor is an electrical contact on the firmer side surrounded by a very sensitive spring within the enclosure. The coil spring is by design made of a smaller diameter wire to provide sensitivity to movement. Rather than manufacture a translation to a heavier piece of material, the thinner lead is brought out of the enclosure.

I suspect that it will not work on your breadboard, due to the flimsy end being too small to make solid contact within the breadboard. You could resolve that aspect by soldering on a heavier segment.

Because it is designed as a simple switch, there is no plus or minus.


How do I connect 4 or more Arduinos to a single shared GSM Module?

You should consider connecting one Arduino to the GSM module, and connect the 4 Arduinos together using SPI, I2C, or any other inter-hardware comms protocol. Before I knew these options existed, I once wrote a bit of code to send data between Arduinos by having one pin represent the data being sent and another pin changing every time a new bit was available. You could do something similar with an extra line per pairing, so an Arduino could tell the primary that it had new data to send.
Anyway, check out the "Wire Library" - it's basically for this kind of work. I think you'll be happier trying to have one Arduino "in charge" and connected to the CSM while the rest vie for its attention.


Can I change VCC pin to 3.3V on a 5V Arduino Pro Micro?

No. If you change the voltage to 3,3 Volt you also have to change the crystal to 8MHz and reprogram the ATmega32u4 to meet the new frequency.


On 32 bit systems, uint32_t is usually the same as unsigned int and unsigned long. You should be able to parse the number using strtoul(), which is quite standard and returns an unsigned long.


Arduino IDE not handling library code correctly?

Header files are parsed by the preprocessor and the compiler wherever they are included.

There's nothing weird about that.
One can avoid multiple inclusions by using header guards.
That's pretty standard too.

I have not looked at the library, but, for example,  a typical error is to not declare variables as extern in the header and instead leave the real declaration in the header, which will lead to multiple instances, possibly clashing at link time.
Variables that are part of the library API should be declared as extern in the header and the real declaration should be done only in the .C/.CPP file.

Interrupts are an even more special case: the AVR gcc relies on very specific names to identify interrupt handlers and each of them can be present at most once.
So there are even more chances for having linker problems, if not declared correctly.


Adafruit Neopixel Library- only the first 16 LEDs respond

When something works, but not completely, it's often due to power issues.

Embedded things, microcontrollers/Arduino are fairly robust and "logical".
Hence, if your Arduino program works today, it'll work tomorrow.

Analog devices, or electricity is (in my eyes) often a bit vague. A chip can get enough power to run, but not enough to work properly.

The NeoPixel

Adafruit has an extremely elaborated tutorial/userguide.

  Powering the NeoPixels

This also seems to fit your problem.

You could try powering the strip from the middle.
Since your voltage isn't stable, your amperage might not be as high and the resistance may be a little big. It's actually quite impressive that it works.

  Each NeoPixel can draw up to 60 milliamps at full brightness.

2000mAh does not mean it can (always) deliver 2000mA. It depends on the "C" or discharge rating of the battery. So if your battery is rated 0.5 C it'll only be able to supply 1000mA (for 2 hours).

60*21 would be well over 1000mA, actually 60*16 is just below 1mA, so this would fit your problem.

  The voltage of a battery depends on how much charge it has.

Check google for: "LiPo voltage drop"

  If all else fails

There is a chance that that particular LED is broken. The signal will not continue to the other LED's and thus the light of the strip will end there.
Try to drive the LED's behind the LED that fails. (With the power supply closer).

I'm also not sure if you can supply 3.7V and then use 5V logic. Things like that would often break a microcontroller (when running on 3.3V, you usually can't receive 5V?)


Can I port a project built on Arduino Uno to a standalone ATmega328 using the exact same code?

Almost all of my projects are roll-your-own-duinos with Atmega 328p chips, with code generated for an "Arduino/Genuino Uno" board. Many of them use an ESP8266-01 board as a WiFi interface. I either run the entire board at 3.3v or use a daughter-board that interfaces the ESP to a 5v environment.

If you're porting code from an actual Arduino Uno, there is nothing to do except to make sure your pinouts are the same between the Arduino and the RYO-duino. Otherwise, make all your pin definitions constants and group them together in such a way (e.g. with #ifdef / #else / #endif) that you can easily enable one or the other group just before you compile.

Update:

  There's a bit more required, for example, the clock rate needs to
  match or the timing will be off ...

I did gloss over the power & clock since the question hadn't asked about departures from the Uno's design. But yes, a RYO will need a compatible power supply and a matching clock rate, to be able to assume an arbitrary sketch could be run on it successfully. To make the RYO look like an UNO, it will need 5v power and a 16 MHz crystal, just as the Uno design provides.

If a RYO is designed be other than like an Uno, considering power source, clock rate, fuse options, DIP instead of an SMT, then there is nothing to support the supposition that a port from an Uno could succeed without modifying the code for those differences.


I have an Arduino Uno which works on my Mac running 10.11.3 this uses the Serial Port /dev/cu.usbmodemFA131.

It is 18 months since I installed this (on a previous OS) and I can't recall whether I had to install a driver

ioreg -p IOUSB shows this as

  | | +-o IOUSBHostDevice@fa130000  <class AppleUSBDevice, id 0x100000955, registered, matched, active, busy 0 (40 ms), retain 13>

system_profiler SPUSBDataType shows this as:-
            Communication Device:

          Product ID: 0x0043
          Vendor ID: 0x2341
          Version: 0.01
          Serial Number: 5543434373335120A2B0
          Speed: Up to 12 Mb/sec
          Manufacturer: Arduino (www.arduino.cc)
          Location ID: 0xfa130000 / 3
          Current Available (mA): 1000
          Current Required (mA): 100
          Extra Operating Current (mA): 0


Send numbers to arduino via serial port using python

// save some unsigned ints
uint16_t SIZE, *inputList, cont = 0;
boolean inputsReady = false;

void setup()
{
 // initialize serial communication at 9600 bits per second:
 Serial.begin(9600);

 //free dynamic array memory
 free(inputList);

You are freeing a NULL pointer which is an undefined operation not necessary here, since it was never allocated.

  if (Serial.available() > 0) {
    delay(100);
    // look for the next word
    int cmd = Serial.parseInt();
    clearBuffer();

This is going to just throw data away, I'm not surprised stuff goes missing.

Read this: How to process incoming serial data without blocking - you need to get rid of the delay, and the clearBuffer() for a start.

Example code for reading from Serial without blocking and without using delay:

// how much serial data we expect before a newline
const unsigned int MAX_INPUT = 50;

void setup ()
  {
  Serial.begin (115200);
  } // end of setup

// here to process incoming serial data after a terminator received
void process_data (const char * data)
  {
  // for now just display it
  // (but you could compare it to some value, convert to an integer, etc.)
  Serial.println (data);
  }  // end of process_data

void processIncomingByte (const byte inByte)
  {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  switch (inByte)
    {

    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte

      // terminator reached! process input_line here ...
      process_data (input_line);

      // reset buffer for next time
      input_pos = 0;
      break;

    case '\r':   // discard carriage return
      break;

    default:
      // keep adding if not full ... allow for terminating null byte
      if (input_pos < (MAX_INPUT - 1))
        input_line [input_pos++] = inByte;
      break;

    }  // end of switch

  } // end of processIncomingByte

void loop()
  {
  // if serial data available, process it
  while (Serial.available () > 0)
    processIncomingByte (Serial.read ());

  // do other stuff here like testing digital input (button presses) ...

  }  // end of loop

In process_data in my example is where you would call atoi to convert the incoming string into an int (or atol if it is going to be longer).


How can I understand the circuit diagram for Arduino Starter Kit Project 4?

The important thing to remember, which will help you understand everything else, is that voltage is measured with respect to another point.

In this (and almost every) case it is measured with respect to ground. So when you say the voltage at point X is Y volts you are actually saying that the difference in voltage between point X and GND is Y volts.

So on your schematic A0 measures the difference in voltage between it's IO pin (the junction between the 10KΩ resistor and the LDR) and ground. And looking at it, what is between its IO pin and ground? The 10KΩ resistor. So it is actually the voltage across that resistor that you are measuring.

Doing the sums:

Assume there is enough light falling on the LDR to make it have a resistance of 5KΩ.  Current flows through both the LDR and the 10KΩ resistor in series, so it has a total resistance of (10,000 + 5,000) 15KΩ. With 5V across the whole lot (5V -> LDR -> 10KΩ -> GND) you get:

I = V/R = 5/15,000 = 0.000333... or 333µA.

333µA flowing through 10KΩ drops how much voltage?

V=RI = 10,000 × 0.000333... = 3.333...V

So A0 would be measuring 3.333V at that point.

Now, you turn out the lights, and the resistance of the LDR rises to, say, 50KΩ. What happens to those sums now?  Well, let's look:

Total resistance = 50,000 + 10,000 = 60,000Ω
I=V/R = 5/60,000 = 0.00008333...
V=RI = 10,000 × 0.00008333... = 0.8333...V

The formulae can be simplified into just the ratio of the two resistances:

           R2
Vout = --------- × Vin
        R1 + R2

So that is, with the lights on:

        10,000
Vout = --------- × 5 = 0.666... × 5 = 3.333...
        15,000

And with the lights on:

        10,000
Vout = --------- × 5 = 0.1666... × 5 = 0.8333...
        60,000

From that measured voltage, of course, you can then calculate what the resistance of the LDR must have been at the time. Rearranged the formula looks like:

      R2 × Vin
R1 = ---------- - R2
        Vout

Plug in the numbers for the voltage with the lights on:

      10,000 × 5              50,000
R1 = ------------ - 10,000 = -------- - 10,000 = 5,000Ω
       3.333...              3.333...

The kind of circuit is known as a Voltage Divider or Potential Divider and you can read more about them here: https://en.wikipedia.org/wiki/Voltage_divider


Load Adafruit GFX bitmap fonts on desktop for pixel-level design

As explained here and here the font format in the GFX-library is GFXglyph, you can use the free tool from the second link adafonteditor v1.0.3 on the desktop.EDITOk so its actually decompile the gfx header file to something on the desktop. Take a look at the Adafruit GFX Font Customiser Source can be used as basis for own projects or compiled to the designated OS.


Your problem looks similar to mine. It is possible that your module is a GNSS module and therefore doesn't work with standard AT commands, which are used in "gps.h".

First check that the GPS Module receives enough current, at least 5V -- 2A from an external source like a battery.

Then try sending AT commands in the serial monitor to check if your GPS module works properly:

#include <SoftwareSerial.h>
SoftwareSerial SIM808(2,3); //(RX-Pin,TX-Pin)

void setup() {
  Serial.begin(19200);
  SIM808.begin(19200);
}

void loop() {
  if (SIM808.available())
    Serial.write(SIM808.read());
  if (Serial.available())
    SIM808.write(Serial.read());
}

Upload this to the board an then open the serial monitor and send these commands:

AT+CGNSPWR=1

This should return OK.

After that input:

 AT+CGNSINF

This should return OK and your GPS Location in this format:

1,0,<time>,<your latitude>,<your longitude>,..........

If you get the following output:

1,0,19800106001337.000,,,,0.00,0.0,0,,,,,,0,0,,,,,

It means your GPS is not set. Try to put GPS antenna outside your room, on open space.

For more information about GNSS modules go to  http://www.elecrow.com/wiki/images/0/05/SIM800_Series_GNSS_Application_Note_V1.00.pdf


You need two spare digital pins to use the IR-library. These pins can be set to whatever you like. Pins D3 to D7 are free on the Moteino so the library will be OK to use if you connect the IR LED and receiver to two of those pins.


Can I use string and int in Serial.println together?

The answer by canadiancyborg is fine. However, it is always better to avoid using String objects if at all possible, because they use dynamic memory allocation, which carries some risk of memory fragmentation. Simple and safe:

int answer = 42;
Serial.print("The answer is ");
Serial.println(answer);

The only drawback is that the constant string ("The answer is ") takes some RAM. This can be avoided by embedding it in the F() macro, which means “keep this in Flash memory only”. Then, the most memory-friendly idiom is:

int answer = 42;
Serial.print(F("The answer is "));
Serial.println(answer);


There is no simple "yes" or "no" answer to this.

You need to check the datasheets and libraries for your chosen devices and see what is available.  Many libraries will have begin() function, which may, or may not, return whether the device is working.

Many may just lock up waiting for communication, and there's not a lot you can do with that short of reprogramming the library to work differently.

Some (especially analog sensors) will return values from their reading functions that are far outside a tolerable range that you could assume indicated a malfunction.

For I2C based sensors you could use a variant of the I2CScanner sketch to look at what addresses are in use before attempting to use the sensors themselves.

Other protocols may have a similar system you can use to examine what is on the bus.


To send values to Android App you need some medium either it is wireless (Bluetooth, which you don't want to use, or via internet by using a web server on Arduino or PC, through which the Arduino is connected) or wired through Serial communication.


There are very weak internal pullups, but they are not strong enough to be considered compliant with I2C specs. Supply your own external 2.2k-10kohm pullup resistors.


What is the call to cli(); routine in interrupt service routine for SPI?

Interrupts are normally turned off automatically when an ISR is called.

There are two instructions that allow software to turn off (cli) and on (sei) interrupts to create a sequence of non-interruptable instructions, i.e. an atomic operation or critical section.

In some MCU there are several levels of interrupt priority and an ISR with lower priority may be interrupted by an ISR with higher priority. An atomic operation may also be required in an ISR with lower priority.

There are also cases where an ISR may allow interrupts (with the same or lower priority) to occur after the critical section of the ISR.

Normally an ISR should not contain cli()-sei() especially for the AVR. The hardware will automatically turn off interrupts during the execution of the ISR.

Cheers!


Fried two Arduino Nano's but works when powered

Judging by your list of observations:

Cannot power through USB
Can power from external source
Can program through USB

it is most likely that the power feed from the USB to the +5V rail has been interrupted.  There is only one component in that link - the diode D1 (an MBR0520).  That is rated at an absolute maximum constant forward current of 0.5A and most USB ports these days are capable of providing far more than that.  A short circuit on the +5V to ground would draw considerably more current than that diode can handle and the Magic Smoke™ would escape.

The diode is on the underside of the Micro and close examination may show a small crack in the surface of it.  That is if it's still there.  I have used a similar PIC32 based board with 0.5A rated diodes on it, and a short of the power rail when powered from USB caused the diode to completely vaporise (at least I could find no trace of it afterwards).


Serial.print() is slower than it should be

I need a sample rate of 6 kHz

OK, so that means you need to sample and send every 1/6000 seconds (167 µs).

I have a lengthy discussion about the ADC hardware. Amongst other things is a table of conversion times for the different ADC prescalers, assuming a 16 MHz clock:

Prescaler
    2    * 13 * 1/16E6  = 0.000001625 (  1.625 µs)
    4    * 13 * 1/16E6  = 0.00000325  (  3.25  µs)
    8    * 13 * 1/16E6  = 0.0000065   (  6.5   µs)
   16    * 13 * 1/16E6  = 0.000013    ( 13     µs)
   32    * 13 * 1/16E6  = 0.000026    ( 26     µs)
   64    * 13 * 1/16E6  = 0.000052    ( 52     µs)
  128    * 13 * 1/16E6  = 0.000104    (104     µs)

If you go for maximum resolution (10 bits) you need a prescaler of 128, which takes 104 µs. The number of conversions you can do a second (taking the inverse of the above) is:

Prescaler  Conversions/sec
  2           615,385
  4           307,692
  8           153,846
 16            76,923
 32            38,462
 64            19,231
128             9,615

You also need to take into account the transmission time. At 115200 baud you can transmit one byte every 1/11520 seconds (86.8 µs) so therefore two bytes (16 bits) would take 173.6 µs.

If you sample then transmit you will therefore take, per sample:

104 + 174 = 278 µs

This is too slow if you want to achieve it inside 167 µs.

You can sample asynchronously (in the background) so you transmit one sample while taking the next one, but you are still limited by the transmission speed of serial, so it would still take 174 µs per sample.

In fact, fiddling with the prescaler isn't really the issue here because the serial transmission time is the limiting factor.

Forget about the ADC and how it works for the moment. At 115200 baud you can't transmit 2 x 6000 bytes per second. That is simply because the maximum is 11520 bytes per second.


Servo library unable to control more than 11 servos

It sounds to me like you're exceeding the current limits of your power supply. Add up the current drawn by your servos (and their controller(s), and also the current drawn by your Arduino and any other circuits you have. I bet you'll find that at 12 servos, you go over the current limit of your regulator. You might need a higher current regulator or a second one.


To do it in the form you have, you would want to use a pointer.

void ManualJog(int Dir, int Spd, int axis)
{
  int i;
  AccellStepper *thisAxis = NULL;

  if (Dir == 0) {
    i = 1;
  } else {
    i =- 1;
  }
  setSpeed(i * Spd);
  switch(axis)
  {
    case 1:
      thisAxis = &X_Axis;
      break;

    case 2:
      thisAxis = &Y_Axis;
      break;

    case 3:
      thisAxis = &Z_Axis
      break
  }

  if (thisAxis != NULL) {
    while (!Serial.available()) {
      thisAxis->runSpeed();
    }
  }
}

Briefly: the & before the name of a variable in assignment means "Give me the address of this variable".  A * before a variable when declaring that variable means "Make this variable hold the address of another variable of this type".  You then have the address variable hold the address of your chosen axel, and then "dereference" that with the "poiner dereference operator" -> (instead of using .).

A check is added to see if thisAxis has actually been assigned anything or not, although you could use the default: case in your switch to abort on an invalid axis number instead.

Depending on how the rest of your program works, though, it may be possible to not use the "axis" integer at all, but pass a reference to the correct stepper to the function:

void ManualJog(int Dir, int Spd, AccelStepper &axis) {
  int i;
  if (Dir == 0) {
    i = 1;
  } else {
    i =- 1;
  }
  setSpeed(i * Spd);
  while (!Serial.available()) {
    axis.runSpeed();
  }
}

In this example the & before the axis variable in the function prototype means "Pass me the address of the variable", and a new variable is created located in the same memory space. This is the pass by reference operator in C++.


How to map integer values and round to a count of tens/thousands?

I didn't yet compiled it, but something like this should work:

#include <Math.h>

int converter(int x)
{
    if(x <= 5000)
        return 1000;
    else
        return (int)(round(x / 10000.0) * 10000.0);
}


Ping IP address using ESP8266 connected to Arduino

From what I could find, it seems theres a command for pinging a server. It returns the number of milliseconds taken for the server to respond. The command is: AT+PING="web site" or AT+PING=<ip addr>, from 2 separate sources. You'll have to test them to see which (if not both) is correct.


This is actually something I have been meaning to try but never got around to it.
My idea is to drive the LED with PWM with a 50% duty cycle. The frequency isn't really that critical, but you don't want it too high for the next part.
Now you sample the receiver at a fixed frequency that is at least 2x the frequency of the PWM into a buffer.
Then you perform FFT on that buffer.
The bucket that contains the frequency of the PWM should have a power value that is proportional to the distance.
Other light sources will be unlikely to affect the same bucket as the PWM frequency - most will only affect the lowest (0Hz+) bucket.
Or that's the theory that I came up with. I have yet to try it in practice.


This is a bad strategy in general. You should not be issuing print calls for things you don't want to print and relying on the lcd library to filter for you because they're out of bounds.

Call print for only the choices you want to display.

char* menu[] = {
    "choice 1",
    "choice 2",
    "choice 3",
    "choice 4",
    "choice 5",
};
const int numMenuItems = sizeof menu / sizeof *menu;
const int numLcdRows = 2;

// start out at the top of the menu
int scrollPos = 0;

void drawMenu() {
    for (int i=0; i < numLcdRows; ++i) {
        lcd.setCursor(0, i);
        lcd.print(menu[i + scrollPos]);
    }
}

To scroll up or down, just adjust the scroll offset:

inline void scrollUp() {
    if (scrollPos > 0)
        scrollPos--;
}

inline void scrollDown() {
    if (scrollPos < numMenuItems - numLcdRows)
        scrollPos++;
}

Note this is untested code written for a library I've never seen (just inferring how it works from your post); it's for illustration purposes only.


Instead of using below in handleTest()

else if (server.method() == HTTP_POST)

try using below in setup()

server.on("/test", POST, handleTest);


Yes you can. One of the options is using Visual Studio if you are Windows user (using built in library is enough to meet your 'option to turn off' needs). There so many examples of serial communication using either C# or C++ with Arduino, so you can do communication between Laptop - Arduino via serial cable or even built in bluetooth in laptop (with extra bluetooth module for Arduino).

The most simple setup is your laptop act as master and arduino as slave. Arduino does not need any information about what program is running, instead just waiting command from Laptop wether to turn off or turn down the fan

You can read  information from your PC (for Windows), such as temperature or battery level


Solid-state relay boards: Can they be used to switch audio signals?

A solid-state relay seems to be the totally wrong tool for the job. The image you posted shows it is intended to switch 240V AC. So it is designed to switch something like a 240V light on and off.

Relays in general are things designed to connect one thing to another (eg. power to a light). They just aren't designed to switch audio signals.

  I need to multiplex some audio signals in a mixer board, and I was already planning on using those solid-state relays before I learned all this

The expression "when the only tool you have is a hammer, everything looks like a nail" springs to mind.

There are chips designed to multiplex analog signals (as I describe on this page). That would be closer to what you need.

However that chip (the 74HC4067) is a "choose one input from many" sort of design. It isn't going to let you fade one audio signal in or out (neither would the relay for that matter).


Can I connect a camera without a shield?

Judging by the photo (below) it is specifically designed to plug into the SPI ports on a Uno or similar (that is, pins 10 to 13). The other two wires are going to the ICSP header, presumably to pick up +5V and ground.

So yes, most certainly you can use it like that. With the pins done like that it even points horizontally.

  It wasn't clear to me that I should bend the camera pins as such (mine has 8 pins pointing downward).

You can buy pins with a 90° angle. If yours are not already soldered on, I would use the bent connector. If the pins are already soldered on, then the camera would lie flat, so just rotate the Arduino itself to point to where you want it to.

However you would need to do something with the +5V and Gnd pins, so that they can be rerouted to the correct place.

Looking at another photo on that site.

The pins would match most of the pins on a Uno, like this:

The only one that is wrong is AREF - you need +5V into that pin, not AREF, which is why they bent those two pins outwards (+5V and Gnd) and ran wires to the ICSP header.

If you mean all your pins are at right-angles already, then you really only need to fix the +5V one (you can probably bend it up). This is the pin-out for the ICSP header (view from above):

As you can see, you can pick up +5V from pin 2 (Vcc). Alternatively, run the +5 wire over to where +5 is marked on the Uno on the other side.

Another possible approach would be to not bend anything, but solder on a wire to the +5V pin and leave it plugged into AREF. AREF is just an input (analog reference voltage) and it won't hurt to have it left at +5V.


The standard C function printf print to stdout. Arduino doesn't has a stdout. You can print to Serial, but must prepare/format the string first.

Instead of printf, use snprintf. It prints to a char array, which you later can use with Serial.print, or whatever other function that take a string.

void setup() {
  Serial.begin(9600);
  while(!Serial);

  char buffer[4];
  snprintf(buffer,sizeof(buffer), "%03d", 3);
  Serial.println(buffer);
}

void loop() {

}

Note: all the comments apply to this answers.


Where can I know voltage between GND(ground) and each port of UNO R3?

5[V] is ideal EMF(electromotive force) of arduino UNO R3.
Since I stated "ideal" ,the actual EMF be slightly lower than 5[V].
In this instance , EMF can be assumed as voltage between GND and port of UNO R3 as ports are connected only by a wire.


Connect Bluetooth remote control with Arduino

This should be a comment, but..

For starters, you'll need to do the pairing from the Arduino with the HC-05 in master mode.

Check this out.


How to ensure electronic components make good connection with breadboard

Sounds like you may not be pushing the leads into the board,I find long nose pliers handy for components with thicker leads.


Arduino as Slave | SPI | Answers too late

Because of the way SPI works, the slave cannot respond to the first byte in a meaningful way. It can send something (eg. 0x00) but not a response.

See my page about SPI. During an SPI transfer each bit is sent, and a bit received, simultaneously, as in this graphic:

You can see that as the first bit is received by the slave, it also has to send a response. There is no way that this response can react to the 8 bits, 7 of which haven't been received yet, by the time it has to send the first bit of response.

  But i always have to send 2 bytes for the correct response.

You don't have to send 2 bytes all the time. For example, you can send one byte (eg. "send me the temperature") and then send zeroes after that, while you read back a (say) 4-byte temperature. So in this case you send 5 bytes to get a 4-byte response.


Not possible without changing the library code. Because the current library code is written intended for only one SD card, ie not intended for multiple SD cards because it will be complicated to do so. The SPI library also uses FatFS library, which is a bottleneck in this scenario.

Worth a try.

sdfatlib is library written for Arduino. I have never used it, but you can give a try on ESP.

Let us know if it works.


Using Raspberry Pi to Receive Float from Arduino using NRF24L01

If you say you only need one digit, why not multiplying your value with 10 (with rounding), transmit it as a 4 byte (unsigned?) integer, and divide by 10 after receiving.

You only need to check if you have little or big endian conversion needed (swapping MSB/LSB 2 byte or single byte). But you see this very fast if you print the values in hex format.


the Yún doesn’t have a real time clock IC on board, so it can’t keep time when is powered off. Instead, it synchronizes with time servers automatically when it powers up and connects to a network using NTP.

(Arduino Blog)

Therefore, the Yun does not have a onboard RTC.

  If there there is no RTC, can I connect a DS1307 to the Atheros AR9331?

Probably not. It comes in a LPCC package, which has the solder joints on the bottom. This needs to be soldered by reflow. The Yun does not have any pins connected directly to that chip. You're probably thinking of the ATmega32u4, the actual Arduino chip. The other one is for a router.

To get the time, you have two options:

Use the time from the time server

A few notes:

  The Yún must be connected to a network to get the correct time. If you used the web-based WiFi interface to configure the Yún for the network, make sure you've selected the proper time zone.

Connect it to a DS1307 (I find this Adafruit tutorial helpful) You'll need only two pins to use this board. One note: there is a way to connect up to 121 I2C devices using these two pins. However, that gets a little more complicated.


I am sorry, but I may not have understood your post, but I think the problem is your code doesn't work and you don't know why.  I think the problem is with this line:

if(val.m_y,2 >2 ||val.m_y,2<0){

It is because it is not valid code, I suspect its a cut and paste error and should be

if(val.m_y > 2.0 || val.m_y < 0.0){

the ,2 you use in the print statements specifies the number of digits to print after the decimal point (I think).


Why is the constrain function used after the map function?

From the official Arduino site:

  [The map function] does not constrain values to within the range, because out-of-range values are sometimes intended and useful. The constrain() function may be used either before or after this function, if limits to the ranges are desired.

EDIT: Example.

You can try this by yourself with this code:

int val = 20;
val = map(val, 0, 10, 0, 100);

Although you set the upper bound of the value's range to 10, you passed an higher value than that and the function will linearly map it accordingly, resulting in an output of 200.


It is hard to help you improve your library or code if you don't tell others what your code pieces are trying to do.

In general, you will have a piece of code that sets up the whole thing, a piece of code that will be executed in the isr, and other helper code pieces, like getting status and clear status, as appropriate.

I often use a function pointer that the user can hook to the user handler so my isr portion of the code is fixed. Just hook to different functions in the user space and you are ready to go.

Obviously other ways exist, each with their pros and cons.


Propane injection software compiles, uploads, doesn't work

I can see two things wrong with your code at first glance.  First is the kind of interrupt you're using:

attachInterrupt(digitalPinToInterrupt(interruptPin), shot, LOW);

A LOW interrupt keeps triggering over and over again all the time the input is low.  It's a special interrupt type that is seldom used for anything except waking up the MCU or handling external peripherals with persistent interrupt indication.  Instead you should be using FALLING which will trigger once and once only when the input transitions from HIGH to LOW.

attachInterrupt(digitalPinToInterrupt(interruptPin), shot, FALLING);

Secondly you have two variables that seem to be intended to do the same thing - store the delay time for your output pulse.  And that's caused confusion:

injValue = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//

... and then later ...

delayMicroseconds(inj); //delay the calculated value  in microseconds//

In your comments you reference the second variable, but the code uses the first one. Change that so it uses just one (volatile) variable:

inj = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//

Alternatively, and perhaps much safer, is to assign the result of the calculation inside a critical section, in which case having two variables is useful:

injValue = (tpsValue + mpValue + tuneValue) * 4; // add the three sensors together and assign the value to inj//
noInterrupts();
inj = injValue;
interrupts();

This will prevent your interrupt triggering whilst the value is being calculated and placed into the inj variable which could result in the inj variable containing gibberish, which could cause your engine to explode.


i need to speed up the comm to fast mode how to make this

Wire.setClock(400000);

and the line of code where to put it in the code

Just after Wire.begin() in setup().  Wire.begin() sets the speed to 100,000 and you need to then override that afterwards to set it to 400,000 (or whatever speed you want to run at).

and in the master or slave ?

In the master, since it's the master that generates the clock.

what about the pull-up resistors ? does arduino uno includes built in pull-up resistors ?

Yes, but they're too high for reliable I2C operation. You should add your own resistors in the region of 1kΩ.

does it needs to disable it and put my own pull up resistors ?

No, yours will just be in parallel with them, with the net result of a small reduction of overall resistance.


As Chris says, you should never plug a high current device like a motor directly into a pin on your Arduino. That motor is rated at 800 mA, which is more than you can draw from the entire 5V supply on the Arduino!

The digital pins are rated for 40 mA max, if I remember correctly. You tried to draw 20 times that much. There is a decent chance that you burned out the driver for that digital pin. I would try hooking an LED through a 220 ohm resistor and to ground and see if it still lights up when you send it a HIGH logic signal.

For a simple DC motor you should be able to use a high current transistor and an external power supply to drive it.

Edit:  If I were doing this I would use a logic-level MOSFET to drive the pump directly, plus a flyback diode. To use a relay, you will still need a transistor to power the relay coil, AND a flyback diode. Your circuit might look like this:

(Note that I made no attempt to pick the RIGHT kind of diode and transistor. Ignore the part numbers shown in the schematic. I just used the defaults.)


DFPlayer Mini with its standard library does not being initialized

Please check if the RX/TX pins are messed up. In my case, simply RX and TX wires' places' switching did help!


When the TX and RX pins for Bluetooth are connected the LCD screen will not update. Why is that?

You connected the LCD module to serial hardware pins 0 (RX) and 1 (TX).

When you receive the data from the Bluetooth module, through the software serial, you send it to the hardware serial.

if(BTSerial.available()){
      recvChar = BTSerial.read();
      Serial.print(recvChar);
...

This messes up the communication with the LCD module. Remove Serial.print(recvChar); and it should work.

A more sensible solution would be to use hardware serial for the Bluetooth module and the other pins for the LCD module.

Software serial should only be used, if you really can't use the hardware serial, e.g. you need the hardware serial to communicate with another device (a PC or some other module).


Send information (such as a string) over digital pins

The RaspberryPi is a fairly complete linux computer.  As such it can be a USB Host to many USB Devices.  If you need more serial ports simply buy FTDI equipped USB to serial cables, plug them into a USB hub and plug that into the RaspberryPi.


Getting error ets jan 8 2013,rst cause:4,boot mode(1,6) wdt reset

Your loop():

void loop() {
  Serial.println(String(WiFi.status()));
  if (WiFi.status() != 3)
  {
    WiFi.begin("VENTURE", "12345678");   //WiFi connection
    while (WiFi.status() != 3)
    {
      Serial.println("Waiting for connection");
    }
  }
  else
  {
    // Other code...
  }
}

While waiting for the connection, you are creating String objects at a very high rate, since your delay(20000) is in the else clause.

This means you are possibly running out of memory, as you are creating the String objects with every iteration, which is in the Megahertz range.

You likely don't need the String(...) wrappers, as the Serial.println() function can work with C-style strings returned by the WiFi library. Then, your program won't be allocating memory to hold the result of WiFi.status() millions of times per second, which you don't use later on in your program.


Best way to obtain angular velocity from a 9 DoF sensor

Consider building on Sebastian Madgwick's PhD IMU research.  A GitHub Arduino project based on Madgwick's work can be found here.


Programmer only uploading with its own power source

There's no problem with supplying a separate power supply to the ESP8266 but you always need to connect the grounds between the "programmer" and the ESP8266.


Internally those little tactile switches look like this:

That means that the two pins on the same long side are connected together.  So you can use, when you hold the switch vertically as in the image on the page you link to the two left-hand pins are linked together, and the two right-hand pins are linked together.

So you can use either both the top pins, both the bottom pins, or the top left and bottom right or the top right and bottom left.

Using either both left hand pins or both right hand pins will be as if you were sat on the button and it was permanently pressed.


From the specs:

  The first byte in each 32-bit USB-MIDI Event Packet is a Packet Header contains a Cable Number (4 bits)
  followed by a Code Index Number (4 bits). [...]

  [...]

  The Cable Number (CN) is a value ranging from 0x0 to 0xF indicating the number assignment of the
  Embedded MIDI Jack associated with the endpoint that is transferring the data. The Code Index Number
  (CIN) indicates the classification of the bytes in the MIDI_x fields. The following table summarizes these
  classifications.

  CIN | MIDI_x Size | Description

  [...]

  0x9 | 3 | Note-on

  [...]

No rationale is given why the CIN is required if the full message is also included, but it could be used for quicker routing of the event to the routine that will process it.


Arduino communication protocol with python - beyond pyserial and Arduino example

Ok, after quite some time looking for something that would allow me to easily control an arduino with the raspberry pi, I found the FIRMATA protocol which allows one to communicate with the arduino through many languages. (a snippet from the github page for SEO purposes is shown at the end of this message).

From there I looked for through the python frameworks, and had a long chat with MrYsLab who helped me integrate the arduino Due to his pymata and pymataExpress frameworks. They work quite well and enable you to have a script that quickly and efficiently communicates with the arduino. I'm sure proper frameworks from ros.org or gobot are better. But pymata worked for me hence my answer to my own question.

processing

https://github.com/firmata/processing
http://funnel.cc

python

https://github.com/firmata/pyduino
https://github.com/lupeke/python-firmata
https://github.com/tino/pyFirmata
https://github.com/MrYsLab/PyMata
https://github.com/MrYsLab/pymata-aio

perl

https://github.com/ntruchsess/perl-firmata
https://github.com/rcaputo/rx-firmata

ruby

https://github.com/hardbap/firmata
https://github.com/PlasticLizard/rufinol
http://funnel.cc

clojure

https://github.com/nakkaya/clodiuno
https://github.com/peterschwarz/clj-firmata

javascript

https://github.com/jgautier/firmata
http://breakoutjs.com
https://github.com/rwldrn/johnny-five

java

https://github.com/4ntoine/Firmata
https://github.com/kurbatov/firmata4j
https://github.com/reapzor/FiloFirmata

.NET

https://github.com/SolidSoils/Arduino
http://www.imagitronics.org/projects/firmatanet/
https://github.com/wbadry/FirmataCSharpClientClass

Flash/AS3

http://funnel.cc
http://code.google.com/p/as3glue/

PHP

https://bitbucket.org/ThomasWeinert/carica-firmata
https://github.com/oasynnoum/phpmake_firmata

Haskell

http://hackage.haskell.org/package/hArduino

iOS

https://github.com/jacobrosenthal/iosfirmata

Dart

https://github.com/nfrancois/firmata

Max/MSP

http://www.maxuino.org/

Elixir

https://github.com/kfatehi/firmata

Modelica

https://www.wolfram.com/system-modeler/libraries/model-plug/

golang

https://github.com/kraman/go-firmata

Qt/QML

https://github.com/callaa/qfirmata

Android/Kotlin

https://github.com/xujiaao/android-firmata

Smalltalk

https://github.com/pharo-iot/Firmata


No, you can't. The WeMos boards operate at 3.3V, and so does the SD card. If you want to use a 5V Arduino with a 3.3V SD card, you'll need voltage level shifters.

The schematic of the WeMos SD shield will tell you what SD connections go to what pins. Then just google how to use an SD card with Arduino to connect those pins to the correct Arduino pins.


The AT command set for the ESP8266 is implemented through custom firmware which has to be flashed to the chip to use.

If you've written your own software which is running on the ESP8266 then that's what's flashed to it - the AT command set will not be available because you've overwritten it with your own software. So there's no way to send AT commands to yourself because if you've written software that could do that, then it's present and the AT command-interpreting software is not.

In that case you should look deeper into the Arduino core for the ESP8266 to find the equivalents to the AT commands you wanted to use. This is the code that calls setup() and loop() and implements Arduino-compatible functions like pinMode(). It also provides libraries like ESP8266WiFi. There are many un- and under-documented functions in the code. You can almost certainly find the equivalents to anything that you can do with an AT command in here.


Let's take a look at a typical function for reading this sensor. This is from the Adafruit_VCNL4010 library and is for reading the proximity:

uint16_t  Adafruit_VCNL4010::readProximity(void) {
  uint8_t i = read8(VCNL4010_INTSTAT);
  i &= ~0x80;
  write8(VCNL4010_INTSTAT, i);

  write8(VCNL4010_COMMAND, VCNL4010_MEASUREPROXIMITY);
  while (1) {
    //Serial.println(read8(VCNL4010_INTSTAT), HEX);
    uint8_t result = read8(VCNL4010_COMMAND);
    //Serial.print("Ready = 0x"); Serial.println(result, HEX);
    if (result & VCNL4010_PROXIMITYREADY) {
      return read16(VCNL4010_PROXIMITYDATA);
    }
    delay(1);
  }
}

So let's tot up all the I2C transactions in that one function:

read8
write8
write8
{repeated
    read8
    [read16]
    delay(1)
}

So in a best case scenario, assuming it's in a "ready" state, that's the minimum number of transactions, and the delay doesn't occur.  So what is in each of those transactions?

read8:

Begin the transaction, write the address, end transaction, delay 170µs, begin request, read 1 byte, end transaction.  Total 4 bytes plus 170µs

write8:

Begin transaction, write address, write data. Total 3 bytes.

read16:

Begin the transaction, write the address, end transaction, begin request, read 2 bytes, end transaction.  Total 5 bytes (I notice this one has no delay...?)

So now we can see a best case scenario total of bytes transferred:

4 read8 *
3 write8
3 write8
{repeated
    4 read8 *
    5 [read16]
    delay(1)
}

4+3+3+4+5 = 19 bytes, plus 2x170µs delay.

The default clock speed for I2C on the Arduino is 100kHz. We have 19 bytes, plus start/stop/ack bits. So 19 * 8 for the data bytes (152 bits) plus 19 ACK bits (171 bits) and 5 * start + 5 * stop. That's 181 bits in total.

181 bits, at 100kHz, takes 1.81ms to transfer. Add to that the 2*170µs delay, and we are up to a best case scenario of 2.15ms transfer.

Double that up for reading the ambient light as well, and we're up to 4.3ms transfer. That's a theoretical absolute maximum of about 230Hz readings.

Remember: that's a best case scenario.  If the sensor isn't ready to return a reading at the time that there will immediately be a 1ms delay imposed and the number of transactions will increase.

So why would it not be ready to send a reading? The simplest explanation is that it's not set to a suitable sampling rate.

The library doesn't appear to change the sampling rate for the proximity from the default 1.95 samples per second, nor the ambient light sampling rate from the default of 2 samples per second - so unless you are using a different library, or manually changing these settings through your own Wire calls, even at a reduced triggering speed you'll not be getting anywhere near the kind of information you are after.

The fastest you can get for ambient light sampling is 10 samples per second. Proximity caps out at a more respectable 250 samples per second. But only if you tell it to...


Unsure if my NEMA 14 stepper motor wiring is correct

I would first check with a multimeter which pins from the the shield have voltage. Draw on a piece of paper the sequence of pin activated by the driver and check your motor connection. Probably you have just inverted two wires, this would also explain the whirring sound.


"ARDUINO_SHIELDNOHOLES" is a connector in the SparkFun EAGLE libraries which is basically, well, an Arduino shield. It provides the schematic symbol as well as the PCB landing pattern for such.

The pins on the top right of the schematic are two sets of 3, which should have jumpers connecting either 1 and 2, or 2 and 3. To use hardware serial to connect the Arduino to the SM5100B you connect 2 and 3 of the "top" one and 1 and 2 of the bottom one. This connects D0 (RX) and D1 (TX) of the Arduino to TXD0 and RXD0 of the SM5100B. If you want to use software serial instead, connect the other pairs. D2 will then be connected to TXD0 (and will become the software RX), and D3 will be connected to RXD0 (and will become the software TX).

As for "TXD0" and "RXD0" themselves, those are net names, and all wires with the same net name, such as those and the ones connected to pins 19 and 20 of the SM5100B, are considered to be the same wire even if they aren't connected in the schematic.


Arduino Leonardo - Using ICSP pins for serial

From packages/arduino/hardware/avr/1.6.*/variants/leonardo/pins_arduino.h:

// Map SPI port to 'new' pins D14..D17
#define PIN_SPI_SS    (17)
#define PIN_SPI_MOSI  (16)
#define PIN_SPI_MISO  (14)
#define PIN_SPI_SCK   (15)

static const uint8_t SS   = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK  = PIN_SPI_SCK;

Those are the pin names and numbers you can use. Note that SS/17 is connected to the RX LED.


ESP8266 + DHT11 AWS IOT Thing not updating thing shadow - was working before

I was facing a similar problem: trying to update a thing's shadow on AWS IoT with no success. After some research, I found out that I was using an outdated library. In this question they advise to use heskew's aws-sdk-arduino, on iot-get-shadow-and-cleanup branch:

https://github.com/heskew/aws-sdk-arduino/tree/iot-get-shadow-and-cleanup.

Additionally, I think you have a little error on your code. As far as I know, AWSPath, it should look like:

iotClient.setAWSPath("/things/esp8266/shadow");

At least that works for me, and they use it this way on this video.

That's all I can tell... I am learning at this moment as well.
Hope it helps!!


How do I communicate with a sensor via an Arduino's RX/TX ports?

You don't mention the sensor brand or a datasheet so this will be a very general answer to the problem.

Firstly, how you have the sensor connected now should just spool info into the Serial monitor of the Arduino IDE without any code on the Arduino.

What are the data speed and the exact way the Serial comes out from the sensor?

If you want to interpret the data as it is coming through you should use Software Serial as you can't relay info to the PC with an Arduino's RX TX lines connected to something else.

What you can do is below(Untested):

#include <SoftwareSerial.h>

SoftwareSerial mySer(3, 4); //RX TX

//these are char areay because its from Serial
char accel[3] = {'0'};
uint8_t place = 0;

// array to print in sync with the accelerometer values array
const char* SerialText[3] = {
   "\nX Axis: ",
   "\nY Axis: ",
   "\nZ Axis: ",
};

char inData = '0';
char separator = ','; // separator you described

void setup(){
//set to the normal baud, mines for the example
     Serial.begin(9600);

     mySer.begin(9600);

}//~ end setup

void loop(){

    if(mySer.available()){

     inData = mySer.read(); // get the value at the instance of the serial data being there

        if(inData != separator){
          accel[place] = inData;
          Serial.print(SerialText[place]); // print the current values identifier
          Serial.print(accel[place]); // print value
          place++; // increment for the next time
     }
   }

if(place >= 3) place = 0;
}//~ end loop

The above gives this output at the moment, with an input of $CSACC,-0156.4,-0226.3,+0981.2*49

X Axis: $
Y Axis: C
Z Axis: S
X Axis: A
Y Axis: C
Z Axis: C
X Axis:
Y Axis: -
Z Axis:
X Axis: 0
Y Axis: 1
Z Axis: 5
X Axis: 6
Y Axis: .
Z Axis: 4
X Axis:
Y Axis: -
Z Axis:
X Axis: 0
Y Axis: 2
Z Axis: 2
X Axis: 6
Y Axis: .
Z Axis: 3
X Axis: +
Y Axis: 0
Z Axis: 9
X Axis: 8
Y Axis: 1
Z Axis: .
X Axis: 2
Y Axis: *
Z Axis: 4
X Axis: 9
Y Axis:
Z Axis:
X Axis:

The code doesn't filter this the way it should but is a stepping stone. I will update it to do it properly when I have a chance.


Print string from arduino to serial monitor

String.concat() takes a String as the second argument. Serial.read() returns an int. The compiler creates code that converts the int into a String similar to this:

input.concat(String(Serial.read()));

This is not what you want.

Let's tell the compiler what you really want instead:

input.concat((char)Serial.read());

This will tell the compiler to do the following:

input.concat(String((char)Serial.read()));

We are now having the compiler call the correct String constructor, and the code will work as we expect.


Sorry guys, I made a very silly mistake here, i was using Serial.print here in ISR, following the Slave_Receiver example in the Arduino examples. I got a bit carried away with the use of those Serial debug messages and added lots of them,

I got this info from
https://stackoverflow.com/questions/17985830/arduino-using-interrupts-freezes-processing-and-serial-output

checkout answer by elias

The code does not freeze now. Sorry for the troubles, i hope this helps someone else in return.


Suggestions for a program for drawing simple schematics

A compilation of possibilities mentioned the comments. I'll add to this as I try out the suggestions.

From @Gerben, "kind of in order of complexity":

circuitlab.com - online schematic capture and simulator (analog, digital, and mixed signal). Licensed for professional, student/educator, and hobbyist (free) usage. Officially runs in Chrome and Firefox, and they report users having success with Safari and Opera which are not officially supported.
Fritzing - cross-platform (Mac, Windows, Linux). Has Breadboard View mode with built in Arduino support that allows you to create diagrams like this one:

From there you can click on the Schematic view to route wires and convert the breadboard into a traditional schematic.
CircuitMaker - Windows only, requires creating an account.
Eagle - cross-platform (Mac, Windows, Linux), paid and free versions.

Component library collections (thanks to Marko Mackic for the idea):

Adafruit
Element14 Arduino library - requires registration, lots of other libraries as well
Sparkfun

KiCad - cross-platform (Mac, Linux (with packages for several distributions), Windows, and source code), open source and also on GitHub.

Found Autodesk's 123D Circuits in a question on Arduino Simulators (and emulators).


How to run a timer every 12 hours (exceeding the max size of int) without an RTC?

Set the timer for every hour, which is within the limit. In your action, keep a static int, initialized to zero, which you increment each time. When it ==12, do the thing you want to do and reset your int back to zero.


You can do Serial.swap() in setup() to swap Serial away from RX/TX pin. Serial is then on D7 as RX and D8 as TX (and you can wire some serial module there).

Bridge with jumper wire D4 pin with TX pin. the Serial1 output will go over the USB chip to Serial Monitor and you will see the prints to Serial1.

This will not disturb the flashing mode, because bootloader will still listen on standard Serial pins.