Not receiving the complete messange sent by SIM900

change the test sketch to

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

void loop() {
  if (Serial2.available()) {
    char c = Serial2.read();
    Serial.write(c);
  }
}

or use the SerialPassthrough sketch from examples

or

void setup() {
  Serial.begin(9600);
  Serial2.begin(9600);
  Serial2.setTimeout(100);
}

void loop() {
  if (Serial2.available()) {
    String s = Serial2.readString();
    Serial.println(s);
  }
}


Stepper motor is only moving one step at a time with an IR sensor

As chrisl said, you need to call run repeatedly.

I tried to rewrite the code you've given, though I'm not entirely sure what it is you try to achieve.

void loop()
{
  stepper.run();  // Actually makes stepper move
  stepper2.run();

  int curr_state = digitalRead(pin_ir_in);
  if (curr_state != prev_state)
  {
    if (curr_state == 0) // Motion sensor activated
    {
      stepper.moveTo(100);
      stepper.setMaxSpeed(200);
      stepper.setAcceleration(100);
      stepper2.moveTo(100);
      stepper2.setMaxSpeed(200);
      stepper2.setAcceleration(100);
    }
    prev_state = curr_state;
  }
}


What do you do when you finish a project?

There are many options, so it all ends up depending on your personal
preferences:

You could indeed dedicate this Arduino to this project, and buy a new
one for the next project. This may be the simplest solution, if not
the cheapest. Just make sure you are not using a breadboard for the
other parts. A “proto-shield” may be a good option for soldering the
rest of your circuit in a permanent form.

You may replace the Uno with a smaller Arduino, like the Micro (but
beware it uses a different MCU) or a Pro Mini clone (same MCU). These
smaller boards can then be soldered onto a PCB using standard 0.1” pin
headers.

You could buy a cheap clone, test it to make sure it works as intended
on this particular project, and dedicate the real one for further
prototyping.

You could get a bare ATmega328P plus crystal and caps and put them,
together with the rest of your circuit, onto a perf-board or a
strip-board. C.f. Michel Keijzers’ answer. Note that if your program
can run happily off a somewhat inaccurate 8 MHz clock, you can
use the MCU's internal oscillator instead of a crystal.

If your program is far from using all the resources of the Uno, you
may consider a smaller MCU. The ATtiny85 is a popular “minimalistic”
choice. Make sure an Arduino core is available for it, unless you want
to program all low-level.

For the most professional result, you could design and order a real
PCB for your whole circuit, including the MCU.


If it runs on electricity it definitely consumes power, its only how much the real question is.

Since you are working with electronics I am going to assume that you have a multimeter, if you dont have one. Its about time you did, doesnt cost much and will save you a ton of time debugging.

Nearly every multimeter has an onboard ammeter (the accuracy will be mentioned in the instructions manual). You can use this to determine the current consumed, have a look at a tutorial from sparkfun on how to do this


exit status 1 'mySerial' does not name a type

simple mistake mySerial.begin(4800);
  mySerial.println("Hello, world"); lines was out of void {}

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

uint16_t buf[256];

void setup() {
  Serial.begin(9600);
  while(!Serial);
  for(int i = 0; i < 256; i++)
    buf[i] = (uint16_t)i;
   mySerial.begin(4800);
  mySerial.println("Hello, world"); //printLn  L, not I
}

void loop() {
  Serial.write((uint8_t*)buf, 512);
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}


How to connect RedBearLab BLE shield (Or how to find Nordic_nRF8001.h)?

I used Arduino Create Web Editor to load the SimpleChat example. It loads with these libraries, and it works perfectly:

#include <SPI.h>
#include <EEPROM.h>
#include <boards.h>
#include <RBL_nRF8001.h>

Thanks,
Andi


Arduino IDE display DEBUG PORT Serial1 output

Serial1 (on most Arduino boards that have Serial1) is connected to a pair of pins on the GPIO headers and nowhere else.

To get it to your computer you will have to feed those TX and RX pins through a USB to TTL UART (FT232, CP2102, etc) adaptor.

From there on in it's exactly the same as using Serial but of course with a different device name.


NodeMCU ESP8266 Ver 0.1 not powering on with VIN

Interesting problem. The input range for Vin is 5.5 to 10 volts. This link will give you more information: https://www.make-it.ca/nodemcu-arduino/nodemcu-details-specifications/
I would not venture to guess that your board is OK, since you short pins all kinds of nasties can happen. Also you do not state your reference point for your voltage measurements so I assume it is ground but the readings do not appear correct. How are you 100% sure that the USB charger is working, providing 5V, and that the ground and VIN are connected to the right positions. Did you measure it with the load connected? Can the charger output the voltage at the current you require?


Can only write 5V or 0V, not something in between

The PWM pins output a square wave from 0 to 5V. If you want something more like a DC level, then run the signal thru a Resistor-Capacitor (RC) Lowpass filter.
1K and 10uF should work well to smooth the squarewave.
http://sim.okawa-denshi.jp/en/CRtool.php

On an Uno, pins 3,5,6,9,10,11 are the PWM pins and output at a frequency of ~ 490 Hz or 980 Hz, with a duty cycle from 1 to 254. 0 is full off, 255 full on.


Analog input draws current when Arduino is turned off

Yes, it is normal behaviour, and it's called back-powering.

The current is flowing into the input pin and then flowing up through the ESD protection diode inside the chip to VCC.  It's bad, because the ESD protection diode can't take much current and is easy to damage.

simulate this circuit – Schematic created using CircuitLab

You can prevent it from happening by adding some isolation into the input:

simulate this circuit

MOSFET M1 will be ON when VCC has power, but off when it doesn't. The 100kΩ resistor pulls the gate to ground when VCC is off so it doesn't float. The diode is the body diode of the MOSFET added for clarity. You don't need to add a diode there.


How to power on Arduino a few seconds later after GSM module initialization?

It sounds like your problem is that the GSM module needs time to initialize before it is ready to be talked to by the Arduino.

A crude way of providing this would be to use the delay() function in the Setup() of your sketch.  The argument to that is an unsigned long number of milliseconds (thousandths of a second) so it can produce delays far longer than you need.

But a more sophisticated solution would be to repeatedly try to talk to the module and check for an expected response.  Apparently, with at least some of these, if you disable baud rate detection they will announce themselves with a prompt when they are ready - you could wait for that.  But I think repeatedly trying until you get a response is going to be the most robust.


Is DateTime from RTClib giving garbage dates/times?

You are experiencing the consequences of code that doesn't do sanity checking. The library allows for dates that do not make sense (in addition to giving us all a new reverse-Y2K bug of assuming only dates later than year 2000.

When you create DateTime(0, 0, 0, 0, 0, 0);, you are saying to use Month 0 and Day 0. Those have no meaning in date calculations, which always assume that the first month is 1 and the first day is 1.

The rest of the library's code assumes valid dates, so when you give it invalid dates, unexpected behavior is to be expected!

Of you only modify your zero assignment to DateTime(0, 1, 1, 0, 0, 0); you will see behavior that is more expected.


It is perfectly safe.

The Arduino will see the voltage reduced by the divider you have. It will see whatever current it needs to see in order to sense the voltage - which is a tiny amount.

Remember: Current is drawn on demand by the load. It is never pushed by a supply.


Can I use these cheap GSM module with arduino?

The SIM900A won't work in the UK, it's dual band.
The SIM800L is cheap as there is no power regulation on board. IIRC it requires 3.4V - 4.5V, min 2 amp supply. Check the data sheet to be sure.


You can't. The C++ language doesn't support arrays of
references. You have the choice to either create an array of
objects:

timeOUT TO[] = {timeOUT("SW0",TIMEOUT_SW0), timeOUT("SW1",TIMEOUT_SW1);}

or an array of pointers:

timeOUT *TO[] = { &timeOut_SW0, &timeOut_SW1 };


How to generate two pulses one with 60 and other 66 duty cycle at same instant in 2 pins?

I proposed a few approaches in generating 100kha pwm pulse trains here in response to someone's ask a couple of days ago. The identical code would work for your purpose as well.

It should come up quickly if you do a scan of topics here.

edit: to make it a little bit easier, here is the code I used to generate 50Khz pulse train with 60% and 66% duty cycles.

void setup() {
  // put your setup code here, to run once:
  //pinMode(led1, OUTPUT);                      //led1 as output
  //pinMode(led2, OUTPUT);                      //led2 as output
  pwm1topr(F_CPU / F_PWM);                      //set tmr1/pwm frequency to F_PWM
  analogWrite(led1, F_CPU / F_PWM * 60 / 100);  //led1 @ 60% duty cycle
  analogWrite(led2, F_CPU / F_PWM * 66 / 100);  //led2 @ 66% duty cycle
}

void loop() {
  // put your main code here, to run repeatedly:
    //digitalWrite(led, HIGH);  // turn the LED on (HIGH is the voltage level)
    //delay(100);               // wait for a second
    //digitalWrite(led, LOW);   // turn the LED off by making the voltage LOW
    //delay(100);               // wait for a second
}

and a quick sim confirms its functionality.

enjoy.


What speaker can you drive with output pin?

The Arduino can supply 5V at max 20mA so 5/0.02 ⇒ 250Ω (if you can find such a beast).

NOTE you should use a capacitor to prevent DC flow if using a conventional speaker.

In general the larger the speaker the better. Tiny speakers are inefficient transducers. Hi-Fi speakers are not a good choice, as they are often inefficient, trading efficiency for linearity.

An alternative, if you are a scrounger, is to scavenge a transformer from an old transistor radio - this should give the best match.


int n = wire.read();

"Wire" should be capitalized.

Amplifying on Ken's reply, you have two variables called "n", and the global one should be declared volatile. Also, I2C deals in bytes, not ints, so preferably do this:

#include <Wire.h>

void setup()
{
  Wire.begin(2);
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

volatile byte n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{
  n = Wire.read();
}

In addition, the address 2 is a reserved address.

  Address 0 is reserved as a "broadcast" address, addresses 1 to 7 are reserved for other purposes, and addresses 120 to 127 are reserved for future use.

You should choose an address in the range 8 to 119.

Reference

I2C - Two-Wire Peripheral Interface - for Arduino
Official I2C specification


Convert character to Integer while leaving encoded

OK, so after the lengthy requests for clarifications, it appears that
you are receiving a number in ASCII decimal ("12") and want to parse
it into an integer.
You may use the parseInt() method of the serial object, like:
int c = SerialBT.parseInt();

This can however make you program quite slow, as parseInt() uses a
timeout to know when to stop expecting more digits.
If you already have read the bytes, you can combine them with simple
arithmetics:
int c = 10 * (a - '0') + (b - '0');

Note that '0' is the same as 48, only it makes more explicit the
intent of your code.


I have two 6 volts DC motors connected to L298N motor Driver. Do I need to use 12 Volts battery?

No, you need to use a (roughly) 6V battery. They are 6V motors, so they need a 6V battery.

However, you do need to sum the currents not the voltages. The battery must be able to provide at least the current required by both motors together.


Converting from Float to Int yielding weird results. What am I doing wrong?

On an Arduino board with the 328 processor, an INT is stored as a 2 byte value, so the max number is 32,767.
You want to use a LONG which is a 4 byte number which has a max of 2,147,483,647.
When the variable you are using is not big enough, the number rolls over, which is why you end up getting a negative number.


How to send 2 data to processing from Arduino

If you mean sending multiple integers, floats, or strings, you can use a CSV format.
CSV Format:
sentData = variables,variables,variable3
You can then decode it with things similar to substring on the Processing side.


Programming Arduino with FTDI via Tx and Rx pins

It's exactly the same as for a breadboard Arduino.  That is, connect the DTR pin of your breakout board through a 0.1uF capacitor to the RESET pin. TX and RX then connect to the RX and TX pins of the Arduino respectively, along with of course the ground connection.


My_Decoder.value doesn't change inside obstacle_avoiding(). Hence, while is running infinitely.

I think you have to delete the while, and let loop() take care of controlling the execution.

Addendum

The intent of the loop() is to read some IR data in value. I under the impression that getResults() sometimes block, acording to this:

  However the IRrecvLoop is not interrupt driven and so when you call
  GetResults it sits in a tight loop and does not release control back
  to you until the complete signal has been received.

I also want to check that value doesn't change if getResults() return nothing with this loop()

void loop() {
bool r = My_Receiver.GetResults(&My_Decoder)
Serial.print("getResults()=");
Serial.print(r);
Serial.print(" value=");
Serial.println(My_Decoder.value);

if (r) {
    //Restart the receiver so it can be capturing another code
    //while we are working on decoding this one.
    My_Receiver.resume();
    My_Decoder.decode();
} else {
    if (My_Decoder.value == 0xFF807F && My_Decoder.value != 0xFF0AF5) {
        obstacle_avoiding();
        }
    }
}

I hope this works!


Using RFID and fingerprint sensor together

Get rid of the Serial.begin(9600). You're accidentally changing the Serial baud rate without doing the same in the serial monitor so you'll probably see gibberish, if anything.


Quectel L80-R does NOT have periodic mode, while the L80 does.


Is it possible to get middle grounds with solenoids?

No.  The solenoid will be all or nothing.  If you have used a magnet, you have seen that the force decreases rapidly with distance.  As you move something closer, it will typically snap to a magnet at one point.  The same thing happens in a solenoid valve: once you apply enough voltage to start motion, the motion will complete.

Side note: that is actually a common trick to saving much power with solenoid valve.  You might apply 12 V to actuate, but then you can reduce the voltage very low (maybe 2 V or lower) and the valve will still say actuated.

So if you want flow, you need a flow control valve.  A common 1/4 turn ball valve will provide the fractional flow you seek.  You should be able to hook a servo or gear motor to that.

A typical ball valve will not provide a constant change of flow with angle.  That means the change in flow between the first 5 degrees opening will be large while the last 5 degrees of motion will have little effect.  If the application is not critical, that would be fine.

If you want more precise flow control, valves are made with a particular cutout in the ball that makes the flow control more linear.  You can get a commercial type valve with motor attached in cost range of 100 $US.  For hooking up to an Arduino, a Belimo flow valve (one example vendor) only seems appropriately named

These are commercial type valves used to control water in heater systems and such.  They take a 0 - 10 V input signal as control and will rotate the vale.  The keyword search is "motorized flow control valve" and that will find you many.  These are not exotic, you will find many in all sorts of sizes.  You may even find from a local plumbing supplier where you can pick one up at will call.


Having some trouble incrementing counters

Make CTR static or place it in the global scope. As it stands you set it to 0 every time you go through loop.

The line:

int ctr = 0;

literally means "Create a new variable on the stack called 'ctr' and give it the value 0", and that happens every time loop() is executed.

Instead making it static will change it so that it only happens the first time loop() is executed so it retains its value across successive executions of loop().

static int ctr = 0;


How to upload Arduino sketches to Atmel chips

First thing you need to do in this situation is to crank up the verbosity level on the invocation of avrdude. You do this by adding one or more -v flags to the command line. With -v -v -v -v, you get maximum verbosity.

From your two logs, it appears that the initial handshake with the microcontroller was successful (which would indicate that your connections were good), but then the signature reading turns out quite badly. This is a rather unusual combination which makes me wonder whether you may have misidentified what microcontroller you have.


Does an Arduino 101 come with bluetooth HID capabilities?

The Arduino 101 has HID capabilities. I found example code for using the Arduino 101 as a keyboard, as well as some other discussions saying that the Arduino 101 has HID capabilities.

Here is some example code on GitHub.


A beginner lost at sea, Arduino looking at the sun

You'd better post also the schematic, but I'm pretty sure you just messed up the circuit.

I think you just put the ground connection for the LED strip in the wrong pin (AREF). If you look, the top-most blue wire goes to the third pin from above in the right connector (which is AREF) instead of the fourth one (which is GND). Move this and it should work

Otherwise, put the schematic on the question


Question #1: Can a change on pin 7 wake from sleep?
Yes. The lowest power mode for this chip is Power-down, and you can wake from this state with a pin change interrupt. Assuming that the soft-serial code you are using already enables interrupts on the pin for its own purposes, then you should just be able to sleep and the part will wake on the next pin generated interrupt.
Depending on what compiler/libraries you are using, something like this...
include <avr/sleep.h>

...

set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
//We will only reach this line after an interrupt has occured

...should work. Note that an interrupt when waking from sleep takes longer than when already running, so you'll need to check your soft serial library to see if it will possibly garble the first bit received- it will depend on how they do their timing.
If you really want the lowest power possible, you could write your own soft serial code that drops the processor to idle in between serial bit transitions. Depending on how much time you will be spending actually receiving data this could drop overall power consumption dramatically.
For low baud rates, I could imagine writing serial receive code that woke on an interrupt from the start bit, and used the timer running at a very low clock speed to wake up in the middle of each data bit and very quickly sample and shift the bit in before going idle again. Done right, this could dramatically drop the power used while receiving.
Question #2: Is there a possibility to change CLKPR when Attiny starts receiving?
Yes. You can change the prescaler any time, but note that...

The clock is not running at all during power-down mode, so there is no reason to scale back before going to sleep - it will just mean that it takes you longer to wake up when a change happens.

Sometimes scaling back the clock can actually use more power, especially when sleeping is envolved. A processor running 1/2 as fast uses more than 1/2 as much power, so it is often more power efficient to wake up at full speed, do what you have to do as fast as possible, and then get back to sleep.

The best option for you will depend on factors like how often will you be receiving data compared to waiting for data, and how much work you wan to put into getting optimal power usage. This chip can be extremely power efficient, but it can take work to take advantage of it.


How Master and Slave concept works with Bluetooth?

Well, master/slave concept for Bluetooth resides on the protocol, not in the communications. On few words, this means Bluetooth Master is who has the ability to initiate connection with a peripheral (or slave), but onces connected both master and slave basically can interchange information without restriction (limited by application). If your bluetooth module or implementation has a SPP (serial port profile https://developer.bluetooth.org/TechnologyOverview/Pages/SPP.aspx) once the master finds and connect to the slave, information can flow in both ways like a chat (actually, chat application is the most common usage example of bluetooth modules)


How esp8266 gets response from server..?

There's two things to know here:

You're seeing corruption in your output because SoftwareSerial is not capable of working reliably at 115200 baud. You need to reconfigure your ESP8266 to operate at a lower baud rate (such as 9600) to be able to use it with an Arduino that doesn't have enough physical UARTs.
The response +IPD,4,41 is telling you about the response. It's not itself the response.

It means "IP Data on channel 4 of length 41". It is then your responsibility to request that data from the ESP8266 using whatever AT command the ESP8266 requires.
Personally I would scrap the AT firmware and program the ESP8266 directly. That way you solve both problems: you can choose what baud rate to communicate at (if you even need to communicate to an Arduino at all), and you have no AT commands to parse or craft. It is a far more efficient way of working with the ESP8266 that trying to fudge things with the AT firmware and an Arduino.


Programming an Arduino using Python, rather than C/C++

It's going to be extremely difficult to get any kind of Python script running directly on the Arduino. The reason is that it's an interpreted language, so you would need the interpreter on-board in addition to the plain text script. There's probably not going to be enough memory for all of that.

Your best bet would probably be finding a way to compile a Python script to native machine code (which is how C/C++ works). I believe there are projects around to do something like that for other platforms, but (as far as I know) none which does it successfully for Arduino yet.

You might find some more useful information on this question at Stack Overflow: Is there a way to "compile" Python code onto an Arduino (Uno).


The rocketscream low power library looks like it supports the ATSAMD21.


What happens to serial output when no-one is listening?

Theoretically, nothing should happen to serial data if nothing is listening.

For a traditional UART the data is just sent regardless. It doesn't need someone listening for that to happen.  Like a light doesn't need someone to see it for it to be on.
For USB CDC/ACM the data should be discarded even before it's attempted to be sent.

The latter, though, does rely on the host computer "playing ball" and cleanly closing the port properly.  On most operating systems that is handled by the OS and happens automatically. However on Windows it is handed off to the driver, and I guess the driver may even hand it off to the terminal software.

So in Windows there is a chance that when you disconnect your serial port it's not cleanly closing the connection and the USB thinks it's still connected, thus blocking waiting for the serial data to be collected.


Is the Arduino bootloader really the Atmel bootloader? Can I use Flip to upload?

Arduino uses a different (second) bootloader, next to the DFU one that build into the 32u4.


Arduino UNO + ESP8266 WiFi Relay by LC Technology

Serial connection requires connecting transmit TX pin to receive RX pin. Your SoftwareSerial pins ar pin 6 RX and pin 7 TX. So your wiring should be esp8266 TX to Uno pin 6 and esp8266 RX to Uno pin 7.

Connect 5 V and ground to the pins header, not to screw terminals. The IN terminals are for powering the relay coil.

Call read readRx() in the loop(). Add delay before sending "AT" in setup to let the esp8266 time to boot.


Relays just switch ON and OFF on delay(), not on millis()

Check the values of pompa1, pompa2, and pompa3 to see if they are always smaller than 20000 (I suspect they are).
The delay(20000) (why is it there anyway?) could well be messing up your timing of the toggling of the pump_states by always delaying longer than the values in pompa1, pompa2, and pompa3.
This would make the relays toggle every 20s (on every loop).


Unfortunately the DFPlayer cant write that data to the SD card. The Arduino has some non volatile memory of its own built in though. Theres 1K of EEPROM for the UNO. Notes on how to use it here: https://www.arduino.cc/en/Reference/EEPROM
If you can get what you need to done in 1K and its not important to your project that you be able to unplug the SD card and put it in another reader, then perhaps thats a nice, simple solution...


Student Code: map function not functioning

As Edgar Bonet pointed out,  “chosenColor = 3 means 'let chosenColor take the value 3'”.  That is, your  potVal = analogRead(pot);  chosenColor = map(potVal, 0, 1023, 1, 3); sequence may very well be working, but by the time you get to Serial.println(chosenColor); you have changed chosenColor to 3.

First, the statement if(chosenColor = 1) {...} changes chosenColor to 1. Then the statement if(chosenColor = 2) {...} changes chosenColor to 2.  Finally, if(chosenColor = 3) {...} changes chosenColor to 3, just before you print out the current value of chosenColor.

When you wish to compare two numeric values for equality, use == instead of =.


static public int recordings[99999999] = {NULL}

This is not valid C code. Remove the word public.
Also you cannot create such a big array. The Arduino has only 2 KB (SRAM) memory and also since it is static you have to fill it with values directly, like:

static int recordings[5] = { 0, 1, 2, 3, 4 };

How many values you want to store?

In case you need quite a lot (like hundreds), I would use a different solution for the state array as it only stores values 0 or 1. For example, you can use arrays of uint8_t which cost only 1 byte per element, but even better would be to store 8 0 or 1 (boolean) values in one byte each, but that means you have to get/set the values in the correct indices yourself.


how do i connect my Arduino Nano to my Linux Laptop

In the Arduino IDE, the mcu will show up in Tools > Port.
Your Arduino Nano will probably be visible at /dev/ttyUSB0 or /dev/ttyUSB1 following whatever is already plugged on USB. Make sure to select it.

Select Nano in Tools > Board.

Last step is  Verify/Compile your code (^R), then Upload (^U).

This link sounds to be a good read to start.


If Arduino connected to computer and opened up Serial Monitor, will Tx and Rx pin still be working?

Suppose one connected two of the Arduino Uno boards through Rx and Tx
  pins.

I assume you will connect the TX of one Arduino to the RX of the other
one and vice versa, which is the right way to connect them. As
theSealion explained in his answer, you shouldn't connect two TX Pins
together.

  if one or both of the Arduino boards were connected to computer, and
  possibly opened up Serial Monitors

If you do that, the Arduino won't even notice.

Well, to be more accurate... there is a small chip on the Uno, near the
USB connector, labeled “MEGA16U2”. This chip is used as a USB/serial
converter, and it will notice when you connect the USB link and when
you open the port. However, the main chip (the big PDIP28), which is the
microcontroller that runs your sketch, will neither know nor care.

  will Tx and Rx pin still be working?

Absolutely.

  will Arduino still communicate through Rx and Tx pin when it's
  communicating to computer?

The RX will not communicate with the computer. What will happen is:

Whatever your Arduino writes to its serial port will be received by
both the other Arduino and the serial monitor.
Whatever you send through the serial monitor will be lost.
When you Serial.read(), you will get whatever was set by the other
Arduino.

The reason of this behavior is a 1 kΩ resistor that sits between
the Mega16U2's TX and the main microcontroller's RX. When you connect
this RX to the other Arduino's TX, which is low impedance (≈ 25 Ω),
that TX will “win”: a low impedance output overwhelms a high impedance
one.


Trying to print text on LCD display from Arduino trinket

Warning: I do not have a ATtiny85 nor the lcd so this is purely based on what I found after some reading up on this mcu.

What I would do in your situation:
As the trinket is using a ATtiny85 it does not have hardware serial. So a software variant is needed.
You opted for software serial (which is the most obvous in Arduino world) but which seems to be the hardest solution.
According to this source Serial communication with the Tiny's is is possible (And I quote)

  you might have to tune the internal oscillator to get a stable
  connection.

Assuming your lcd does not need to send data back; I would try the TinyDebugSerial.


Can an ultrasonic sensor differentiate b/w objects?

No. No, you can't. All they sense is the "time of flight".

The closest you would come would be to have a sensor which can detect physical properties of the target.  That could be colour, sound absorption, etc.  You'd need something that sends out a "broad spectrum" signal (white light, white noise, etc) and detects the reflected spectrum (colour sensor, wide-band microphone) and do spectral analysis of it.  The signal would also have to be fairly tightly focussed to exclude signals from the environment.

All-in-all not something for a little Arduino to consider without lots of extra expensive hardware.


Lighting LED with Arduino Uno from PC keyboard

Firstly, you can't just make up the term "keypressed" because the programming language is unable to understand it (unless you assign it as a variable but it's purpose then would just be to store and retrieve values). Secondly the arduino itself is unable to detect keystrokes from the computer by itself. It needs a program on the computer to be able to detect keystrokes from the keyboard then send it to the arduino.

So how would one do this?

Assuming you use Windows, learn Python (A not-so-hard programming language on the computer), then look up the msvcrt library and from there learn how to get key strokes (this only works if you are currently selecting the running program). Then in arduino and python, learn how to use serial. For Python, you need to download this library and learn how to use it. For Arduino it's already in there you just have to learn how to use it. Then you can do the rest and make it turn on your LED.

I hope this helps.


Using micros() to measure analogRead() time varies based on Serial.print location?

Not sure if it is related to your problem but... if I were to try such a
measurement, I would use local variables, like

unsigned int start = micros();
int value = analogRead(sensorPin);
unsigned int end = micros();
sensorValue[ind] = value;
starts[ind] = start;
ends[ind] = end;
vals[ind] = end - start;

This way you would be measuring the time it takes to call both
analogRead() and micros(), and very little more. If you do something
like

sensorValue[ind] = analogRead(sensorPin);

then you are also measuring the time taken by the pointer arithmetic and
the memory access.

I generally program AVR-based Arduinos. These have a load-store
architecture, where saving to a local variable costs essentially
nothing, as the variable is typically assigned a CPU register by the
compiler. Saving to a global takes more time because of the RAM access.

I have no experience with ARM-based Arduinos, like the Zero, but I
believe it's also a load-store architecture, thus the same
considerations should probably apply.

Update: I tried the following experiment on my Uno:

#define PRINT_WHILE_READING

#define READ_COUNT 100

void setup() {
    unsigned int starts[READ_COUNT];
    unsigned int ends[READ_COUNT];
    unsigned int vals[READ_COUNT];

    Serial.begin(57600);
    Serial.println("Ready to begin");

    // Take the readings.
    for (int i = 0; i < READ_COUNT; i++) {
        starts[i] = micros();
        analogRead(A1);
        ends[i] = micros();
        vals[i] = ends[i] - starts[i];
#if defined(PRINT_WHILE_READING)
        Serial.print(i);
        Serial.print('\t');
        Serial.print(starts[i]);
        Serial.print('\t');
        Serial.print(ends[i]);
        Serial.print('\t');
        Serial.println(vals[i]);
#endif
    }

#if !defined(PRINT_WHILE_READING)
    // Print them now.
    Serial.println("All data taken");
    for (int i = 0; i < READ_COUNT; i++) {
        Serial.print(i);
        Serial.print('\t');
        Serial.print(starts[i]);
        Serial.print('\t');
        Serial.print(ends[i]);
        Serial.print('\t');
        Serial.println(vals[i]);
    }
#endif
}

void loop() {}

If PRINT_WHILE_READING is defined as above, I get times that fluctuate
between 108 and 116 µs. If I comment out the line
#define PRINT_WHILE_READING, I get mostly 116 µs and,
occasionally, 124 µs. In both cases, the first reading takes longer
(208 and 212 µs respectively).

The fact that the first reading takes longer is explained in the
datasheet: the ADC does some initializations in that first reading. All
measured times are multiples of 4 µs because that is the resolution
of micros().

Now, trying to understand the differences between the two cases:

With PRINT_WHILE_READING the times are shorter on average. This is
because the numbers are not stored in RAM, as the compiler figured
out the arrays starts[], ends[] and vals[] are not really
needed and optimized them away. When PRINT_WHILE_READING is not
defined, I can see the “store in RAM” instructions in the generated
assembly.
With PRINT_WHILE_READING the numbers fluctuate more. I guess this
is due to the printing through the serial port taking a variable
amount of time depending on the numbers being printed, and thus
creating timing inconsistencies.

The last point deserves some explanation. The ADC is clocked by a
prescaler that divides the frequency of the main clock by 128. This
gives a clock period of 8 µs. When an ADC conversion is started,
the ADC waits for the next rising edge of its clock, which can take
anywhere between 0 and 8 µs, then it does the conversion in
13 cycles of its clock. This means the whole process can take
anywhere between 104 and 112 µs depending on the exact time the
conversion is started relative to the phase of the prescaler. If the
conversions are started at irregular intervals, you expect to see
roughly 8 µs of fluctuation in the measured times.

All these observations have been done on an Uno, which is based on an
AVR clocked at 16 MHz. I know the Zero is quite different. You will
have to look at the datasheet of the ATSAMD21G18 to see whether anything
of the above can be extrapolated to the Zero.


Ahh, was just able to solve it. Essentially, do not use TW_REPEATED_START. Just keep sending data 8 bit at a time. 1 bit at the beginning of each 8 bit will be lost, so make sure you shift them first.

Wire library uses a very similar concept for use with arduino.

uint8_t I2C_write_register(uint8_t device, uint8_t address, uint8_t value, uint8_t value)
{
    device <<= 1;

    uint8_t ret = I2C_start(device | TW_WRITE);
    if (ret)
        return 1;

    if (!ret)
        ret = I2C_write(address);
    if (!ret)
        ret = I2C_write(value);
    if (!ret)
        ret = I2C_write(value2);
    I2C_stop();

    return ret;
}


Googling "4g shield arduino" gave this. It will need a 4G LTE capable SIM, but I guess "it depends" if any 4G LTE SIM will work..


Generating 200 kHz pulse on Arduino Uno in normal mode

That's simple enough - you forgot that everything takes time.

Your timeline is:

Configure timer
Set count
Wait for count to overflow (33 ticks)
Toggle pin
Do something with T1 (why...?)
Clear overflow bit
Go back to 1.

Here's how that looks as assembly:

90: 3b ef           ldi r19, 0xFB
92: 42 e0           ldi r20, 0x02
94: 23 e0           ldi r18, 0x03
96: 91 e0           ldi r25, 0x01

while (1) {
98: 36 bd           out 0x26, r19   ; TCNT0 = 0xFB;
9a: 14 bc           out 0x24, r1    ; TCCR0A = 0X00;
9c: 45 bd           out 0x25, r20   ; TCCR0B = 0x02;

while ( (TIFR0 & 0x01) == 0 );
9e: a8 9b           sbis    0x15, 0
a0: fe cf           rjmp    .-4         ; 0x9e <setup+0xe>

PORTB ^= 0x03;
a2: 85 b1           in  r24, 0x05
a4: 82 27           eor r24, r18
a6: 85 b9           out 0x05, r24

a8: 10 92 80 00     sts 0x0080, r1
ac: 10 92 81 00     sts 0x0081, r1
b0: 95 bb           out 0x15, r25

}
b2: f2 cf           rjmp    .-28

So assuming that the waiting for the timer overflow takes 8*4+
1=33 clock cycles, and referencing the datasheet for how long each instruction takes, we can add up everything in the main while loop:

while (1) {
98: 36 bd           out 0x26, r19   ; 1
9a: 14 bc           out 0x24, r1    ; 1
9c: 45 bd           out 0x25, r20   ; 1

while ( (TIFR0 & 0x01) == 0 );
9e: a8 9b           sbis    0x15, 0 ; 2 (at end)
a0: fe cf           rjmp    .-4     ; 33 (while running)

PORTB ^= 0x03;
a2: 85 b1           in  r24, 0x05   ; 1
a4: 82 27           eor r24, r18    ; 1
a6: 85 b9           out 0x05, r24   ; 1

a8: 10 92 80 00     sts 0x0080, r1  ; 2
ac: 10 92 81 00     sts 0x0081, r1  ; 2
b0: 95 bb           out 0x15, r25   ; 1

}
b2: f2 cf           rjmp    .-28    ; 2

You can see that takes 48 clock cycles (We don't care about what is in the inner while except when it comes to finishing, and that's just the SBIS instruction). For 200kHz you want 40 clock cycles. You have 48. 16000000/48 = 333333. Divide by two for your pin toggling, and you get 166666Hz.

If you want to use this kind of method you need to ensure that the timer is completely free running and the overflow flag gets set at a regular interval, not just at 32 ticks after you start it.

You should be operating in CTC mode so it counts up from 0 to your target value and then resets back to 0 whilst setting the overflow flag. Your loop then looks like:

while (1) {
    if ((TIFR0 & 0x01) == 0x01) {
        PORTB ^= 0x03;
    }
}

All the timer configuration is done before the loop and it just runs and runs until you say otherwise.


To illustrate the reasons better let's look at the actual content of the data.

0x80 is 0b10000000 in binary. A char is a signed variable, which means that the most significant bit is the sign bit, with two's complement representation

So in 8-bit signed representation the value 0b10000000 is a sign bit and zero value - which is -128 in decimal notation, which is "-128 + the 7 least significant bits", or -128 + 0 in this case.

When you print a signed value on the Arduino as HEX there is no 8-bit specific function for it. Neither is there a 16 bit function. However there is a 32-bit signed function, which is the closest match available. So the compiler performs type promotion to 32-bit signed, then represent it as hexadecimal.

Now -128 in signed 32-bit is calculated in the same way - take the value of the most significant bit, negate it, and add the value of all the other bits to it.  With 32-bits the value of the most significant bit, in decimal, is 2147483648, so negate that into -2147483648. Now we need to make that into -128, so we need the difference between the two to add to it. That's 2147483520.

So you get the MSB + 2147483520, which in hexadecimal, is 0xFFFFFF80.

Of course, the compiler doesn't go through that whole routine - instead it uses something called sign extension. This method basically means copying the sign bit from the original smaller (char) type into every bit to the left of it in the larger type:

                           10000000 8 bit signed
                  11111111 10000000 16 bit signed
11111111 11111111 11111111 10000000 32 bit signed

All those are -128 in two's complement, just stored in different size variables. So when you come to print it, that is just what you get - the two's complement representation of -128 in the variable size that has been accepted by the print function.

You might find this site useful for experimentation and furthering your understanding of variable data storage.


It fires after a single byte has been sent or received (the two are one and the same). This is because there is only room for one byte in the buffer, so you need to get it out of that buffer (or put a new one in) after each 8-bit transfer.


How to connect HC-05 to an arduino Galileo?

This might answer your questions about the Serial mapping on Galileo. Seems like you should use Serial1 for UART0 and Serial2 for UART1.

Cheers!


As long as you operate the electronics within specification they will run for years and years. The first thing to probably fail will be the electrolytic capacitors that will dry out after maybe 10 years.

When reading datasheets and specifications the metric you are interested in is the MTBF - the Mean Time Between Failures.


Switch MPU6050 to send SCL data through A4 and SDA through A5

The pin definition is in hardware. There is nothing you can do to change it. However you could try to reprogram it to use a software i2c library instead of the hardware wire library.


Calculate burden resistor value of current transformer and measure ac current with arduino

There is no "You need X resistor for Y transformer". The resistor you choose depends on what current range you are working with and what voltage range you want that to be expressed as.

That transformer is a 100:5 (or more properly a 20:1) ratio.  That means for every 20A going through it you get 1A out.

That output current is then passed through a burden resistor and you measure the voltage across that resistor.

If you are, for example, working with sensing up to 1A current then the maximum current you'd get out of it would be 1/20A, or 50mA.  If you want that to be expressed reliably within the range of a 5V ADC then you would:

Work from the mid-range of the ADC as 0V to give ±2.5V (assuming AC)
Calculate the resistor that gives 2.5V across it when 50mA is passed through it
Pick the next-lowest common resistor value.
Reverse the calculation to get the voltage range you now have.

In this example, R=V/I, so 2.5/0.05 = 50Ω.  50Ω resistors aren't common, but 47Ω ones are, so you'd pick that.

Then reversing it gives V=IR = 0.05 * 47 = ±2.35V

Give it a 2.5V offset to the ADC and you can now read points on a sinewave between 0.15V and 4.85V at 1A sensed current.


No. Not even remotely. Android runs on a powerful computer not a tiny embedded microcontroller.


Measuring .7 volts on pin 2 and 0.0 on the rest when setting all pins low

For future reference, thanks to Majenko: these values fall within the expected voltage output range of 0-0.9V, and you cannot be certain it will stay this way. See the datasheet page 313.


Problem with connecting pins on an Arduino board with an L239D shield

That's a common problem that has many solutions.

The cheapest way is to solder the wires directly as many comments said. Though this is quite dirty, it should work for you.

The more professional way is to use these Arduino stackable header. They can even let you have a shield on top of your shield. This is the best choice in my opinion.


Problem with Arduino driver! Port option not visible. How to resolve it?

Sometimes Windows will disable a given USB port if it think's the attached device is malfunctioning.  Try using a different USB port on your PC.  If that does't work try
rebooting your PC.


"avr/io.h: No such file or directory" while compiling for board Generic STM32F103C series

More specifically, for a variety of historical reasons, if FastLED can't determine the hardware platform/board being built for, it falls back to avr - and this particular STM chipset isn't directly supported in FastLED at the moment - there's a fork running around that has added support for it, but I haven't had a chance to pull it back into the main library.


Audio stops playing after rtc is connected

The problem is

repeat:
if(digitalRead(ProxSensor==LOW))
  goto repeat;

ProxSensor==LOW is false so 0. you read the pin 0 and the outcome is random. The surrounding wiring can affect that. If digitalRead(0) is zero the wav starts playing immediately again. At least use

while (digitalRead(ProxSensor) == LOW);


Shield board with holes, do I need to solder?

Since there are two grounds, a 2-pin terminal block of the type already on the board may fit. Or, since the shield doesn't obscure the far end of the Mega (the end with the high numbered I/Os), you could pick up 5V and Gnd there. The ends of the double-row female header have respectively, 2 each 5V and Gnd connectors. You would pick those up with breadboard wires, though it is admittedly less secure.


int latchPin = 12;

You use pin 12 as the latch pin. Once you activate SPI the hardware takes over control of the pins MOSI, MISO and SCK. Pin 12 is MISO and thus attempting to change it in your code will have no effect.

You should use some other pin as the latch pin (pin 10 is often used).

  And shiftOut using SPI is working when I use first code

shiftOut is a software-based method of clocking out bits. It doesn't use hardware and thus it doesn't take control of pin 12.

Note: Answered originally on the Arduino Forum


You're adding the ASCII value of each char to your string, hence you get numbers. See the various String constructors at:
https://www.arduino.cc/en/Tutorial/StringConstructors

Either cast the read byte to a char:

stringOne = String(stringOne + String((char)incomingByte));

or consider receiving characters as chars, instead of ints:

char incomingByte;

There is a perfectly valid one-method call which does all of this hassle easier and more efficiently: https://www.arduino.cc/en/Serial/ReadStringUntil

Note that you'll sooner or later anyhow have to add a framing prototcol. For example, you're sending down text commands to Arduino, and each command is separated by a new line character. ReadStringUntil will handle that very nicely.


Two-wire Conductivity Sensor and Arduino Hook-up?

It depends on the conductivity of the liquid which it is going to be placed/submerged to. For example if the liquid is highly conductive(ex. saltwater), then a 10k Ohms resistor should be fine. But if the liquid conductivity is low(ex. tap water), then its best to measure the output voltage of one lead with respect to the Arduino's ground to be sure what value of resistor to apply to or if there is no resistor needed at all.

But generally if you are going to supply it with 5 Volts, it should be fine to connect it with the Arduino's Analog inputs directly as the operating voltage of the Arduino itself is also 5 Volts.

Cheers!


Format hour and minute integers to HH:MM format (char*)

You don't want a char *, you want a character array, i.e. you have to
allocate the memory for the string, not only for a pointer. That being
said, you can build the string one character at a time like this:

char timestr[6];
timestr[0] = '0' + _hour / 10;
timestr[1] = '0' + _hour % 10;
timestr[2] = ':';
timestr[3] = '0' + _minute / 10;
timestr[4] = '0' + _minute % 10;
timestr[5] = '\0';

Then you can use timestr just as you would use a char*.

Edit 1: If you are not too short on RAM, you could allocate the string
statically, and have the C runtime initialize the characters ':' and
'\0' at program startup. Then you just have to set the four remaining
chars on each conversion:

static char timestr[] = "--:--";  // initialized only once, with template
timestr[0] = '0' + _hour / 10;
timestr[1] = '0' + _hour % 10;
timestr[3] = '0' + _minute / 10;
timestr[4] = '0' + _minute % 10;

Edit 2: Maybe the “simplest”, in the sense “closest to what you had
in mind”, would be to use a String object:

String timestr = String() + (_hour < 10 ? "0" : "") + _hour
    + ':' + (_minute < 10 ? "0" : "") + _minute;

You could print() that String directly, or retrieve the internal
char* with the c_str() method.

I added this method only for completeness. Although simple in the source
code, it would not be my first choice: it uses more memory, it is more
CPU-intensive and – what worries me most – it uses heap allocation,
which carries the risk of memory fragmentation.


Reference voltage inputs are usually high impedance requiring little current.  So you can get by with simple circuits like a resistor and zener diode.  Here is just one I happened across:

Do some research to find out more about this.

For your specific case, you should read the ADS1115 specification sheet.  As this ADC chip has it's own built in voltage reference.

In the Arduino paradigm, tasks that are to be executed once at the beginning of a program are placed in the setup() method.  Tasks which are to be executed repeatedly are placed in the loop() method.  As setting the gain of the ADC appears to only be done once (consult the ADS1115 PDF linked to above), it appears to fall into the former category.

Added later...

I changed the circuit diagram after I realized it was a bad example for creating an Analog to Digital Converter voltage reference.


FastLED fill_rainbow - Unexpected red pixel

I just copied your exact code and ran it with 600 of my LEDs. I have WS2812B as well, and using the same data pin coincidentally.

I haven't experienced your red LED issue. I then ran it again on my LEDs after adding

 hue++;

at line 33.

Only problem I can see is that the last 30 LEDs at the end of the rainbow kind of flicker. Groups of 10 LEDs spontaneously flicker at once, then another 10, and so on. This could be a problem with my LEDs though because they were the cheapest one's I could find on ebay 2 years ago. The code seems to work fine for me though!


Just guessing but looks to me like you read the CAN message and print it character by character to the Serial console but you don't save those characters in a buffer as you get them from CAN.read().
So when you then try to display.print((char)CAN.read()); at that point there are no more characters to available for the CAN.read() to read so nothing is printed by the display.print().
So what you need to do is to read the characters into a buffer so that you save them after reading them so that you can use the text string for other purposes.


Protecting your computer from stupid (arduino) mistakes

Both the arduino and a USB port do have some protection against wrong connections and such. The arduino has a diode to prevent wrong polarity to reach your power supply, it also have a resetable fuse (the kinda big, often green SMD part close by your USB connection on your Arduino) that should protect your USB port pretty good from its side of the cable. Your USB port also have some good protections going on as far as i know, so basically it should be hard to break a USB port by accident.

That was the theoretical part, In real life things aren't always what they claim to be, so I use a cheap powered USB hub, that i always use as a first line of defense.


Set avrdude transfer baud rate in Arduino IDE

Update the boards package for the AVR hardware. That will give you new options in the tools menu.

Then you should just select the right CPU variant.

From top to bottom those are 115200, 57600 and 19200 baud.


First Atmega Pin, Arduino Reset -> 10 kOhm Resistor (Brown, Black, Black, Red, Brown) -> Ground (not GND pin);

So it's permanently in RESET mode then? How can it ever do anything if you're holding it in RESET all the time?

RESET should be pulled UP by the resistor, not DOWN.


what will be the sampling frequecy of my arduino Mega 2560 code. How would I calculate it?

On the Arduino Mega, the ADC is clocked at F_CPU/128 =
125 kHz (period = 8 µs). Except for the very first one,
each ADC conversion takes 13 ADC clock cycles, i.e. 104 µs. If
you run analogRead() in a tight loop, like

for (;;)
    analogRead(A0);

the CPU has to do some work in between the conversions, and since the
ADC always starts by waiting for a rising edge of the ADC clock, you
loose at least one full ADC cycle in between the conversions. You then
get one conversion every 14 ADC cycles, which results in a sampling
period of 112 µs, and the corresponding sampling frequency of about
8.93 kHz.

The code you showed does a little bit more than an analogRead() per
iteration: two digitalRead(), a test, and a Serial.println() that
involves a binary to decimal conversion. I am not sure the CPU will be
able to handle all that in a mere 8 µs. You might end up using
15 ADC clock cycles per iteration (13 for the conversion,
2 for the computation), which would result in 120 µs
(8.33 kHz) sampling period. Maybe even more. You will have to test
if you want to know for sure. The sampling period is not even guaranteed
to be constant: the code will take longer to run whenever it's
interrupted by the timer interrupt, which the Arduino core uses for
timekeeping purposes...

All this applies as long as the serial output buffer is not full. Once
you have 64 bytes waiting to be sent, the buffer will be full, and
Serial.println() will start delaying the output, effectively
throttling down your loop to the speed of the serial connection. C.f.
the busybee's answer for the details. Note that the sampling period is
still not constant, as sending a 1-to-4-digit number through the serial
port can take anywhere between 3.125 and 6.25 ms.

If you want a constant sampling period, you have to take control over
the timing yourself. A straightforward example would be:

const uint32_t SAMPLING_PERIOD = 6500;  // 6.5 ms

void loop() {
    static uint32_t last_sample;
    if (micros() - last_sample >= SAMPLING_PERIOD) {
        last_sample += SAMPLING_PERIOD;
        Serial.println(analogRead(A0));
    }
}

You could go faster with a higher baud rate, but you have to always keep
SAMPLING_PERIOD consistent with your chosen baud rate. The code above
will still produce some jitter in the sampling, mostly due to the timer
interrupt. If this is not acceptable for your application, you will have
to read the datasheet of the microcontroller and learn how to set the
ADC to be “auto-triggered” from a timer.


Watchdog timer stuck in restart loop? (green led flashing)

One of the most obvious issues here is that you are enabling the watchdog timer with a delay of 1S and then you are asking the micro controller to sleep for 2S, printing something and then going back into the loop. This, in theory, should be fine(your wdt should trigger a reboot during the 2 second wait) but I've seen it cause issues.

Additionally some bootloaders(notably the Optiboot bootloader on Uno and newer boards) can have issues with watchdog timers causing the wdt to remain enabled after reset even though the setup loop disables it. To start with - try increasing the wdt time to something greater than 2S(you should be able to do WDTO_8S) and see if the issue persists.

EDIT - The OP is using an Arduino Pro Mini clone. The included bootloader on the Arduino Pro Mini does not support system restarts by the WDT. Essentially, on a device with a bootloader that does not support WDT restarts, the board will restart but the timer / reset will not causing the board to continuously reset on reboot. There are alternative bootloaders for Arduino boards that may resolve this issue. Another solution is to use a different method to reboot the board.


However, the loop keep repeating.

That's the whole point of loop(). If you want some code to run only once after the program starts put it in setup():

int motor = 9;
int fadeValue = 5;

void setup() {
  pinMode(motor, OUTPUT);

  for (int fadeValue = 5 ; fadeValue <= 245; fadeValue += 10) {
    analogWrite(motor, fadeValue);
    delay(100);
    if (fadeValue == 245)
    {
      fadeValue = 255;
      break;
    }
  }
}

void loop() {
}


Well, assuming cancelling a download == incomplete download == client disconnected before server was done, you could create a flag like this at the top of the function:

bool dload_cancel = false;

Change the IF block, below the innermost WHILE loop, to this:

if (count){
  if (client.connected())
    client.write( buffers, count);
  else {
    dloadCancel = true;
    break;
  }
}

The flag will be set once your server checks and discovers that the client has been disconnected. You can check the state of the flag outside the DO-WHILE block to know if the download was completed or not.

if (dloadCancel){
  // client was disconnected; download did not complete
}

dloadCancel is also a better indicator of a completed download than your fileDownload flag.

You should also know that this:

if (0 > c)
    done = true;

is redundant. Its already taken care of by webFile.available().


Can I use the PWM pins as regular digital input/output pins?

Yes you can use them as ordinary digital io pins. PWM is essentially a normal digital output pin that is repeatedly turned on and off at a high rate.

The magic is that the turning off and on is done in the hardware according to the duty cycle  (I.e. there is no need for software to perform the on/off operations) . This is why only some pins can do h/w PWM, because the PWM hardware is not added on to all pins.

If you are not using the pin for PWM, it is available for you to use as required.


Disable Reset when Com Port Connected/Disconnected

If you review the Uno schematic, you can see the circuitry that enables an automatic reset when serial communication starts.  The circuitry is intended to allow easy program downloading.

There are two or three ways to prevent that reset:  add a 10 μF capacitor from ground to reset;  use a much-lower resistance for the pullup on reset; cut a trace from the serial-interface pin (eg CTS) that pulls reset.

The first method is relatively easy to implement, and easy to remove whenever you want to install a new program.

References:  Disabling AutoReset On SerialConnection and ArduinoISP on Uno requires 10uF cap -- WHY?, both at Arduino.cc.


Find which WiFi device quiries a network?

There are some cheap modules out there called ESP8266, they have the ability to connect to WiFi Networks. A Serial communication is used to talk to this WiFi module.

Edit: For monitoring purposes, that's beyond the capacities of ESP8266(and maybe not), so I would recommend going for a router instead of modules or shields. You may try TP-Link TL-WR703ND for this task. It has serial and it can run OpenWRT.

By using the router, you can configure it to be in Monitor Mode and therefore, you will be able to capture active probe requests (scans) sent by WiFi devices around the router.


Sending data to UART using Atmel Studio with Attiny84

The ATTiny84 does not have a hardware UART peripheral. Instead it has a USI (universal serial interface), which does not have all the capabilities needed for UART ("serial") interface.

You don't need to burn the Arduino bootloader to use libraries, that were written for the Arduino IDE. You only might need some of the definitions, which you can get by including the arduino.h file.

I think your best bet is to use existing libraries, like the SoftwareSerial library. There are also lots more libraries, that provide bit banged serial interfaces. You can also get them running in Atmel Studio, by including the source files. This is the easy way.

If you want to go the hard way, you might be able to program a hybrid software/hardware UART interface by utilizing some functions of the USI. In a search I found this site, which is about implementing UART with the USI. They also link to Atmel's Application Note  AVR307, which is a good source for understanding this. From this starting point you might also find a ready to go implementation for the USI. If not, you will have to do the work yourself.


Arduino mega board 5v pin does not gives 5v when 7.5v is applied through external source

If you apply 7.5V to the power barrel jack and the 5V pin is 7.5V then your Arduino board is broken. Don't connect it to a computer. Don't use it anymore.


Compilation error using arduino-mk on arch Linux (undefined reference to __dso_handle)

I can't say I fully understand what is going on, but it seems that if you add:

void * __dso_handle;

You may be able to eliminate one of the problems. You might try the same trick with __cxa_atexit as well.

I found the idea by searching on:

  arduino __dso_handle

This is the webpage that I found that suggested the void * hack.


How to power Arduino Uno from L298N motor driver's 5v terminal?

Clearly, your design (last image) won't work, because as you expected, the Arduino won't have power. It is a feasible design however, if you use it while still developing and you have the USB cable connected. Because then the Arduino will draw the power for itself from there.
Vin expects 7-12V, but allows an unregulated input (which is fine for connecting a battery). You can use the 5V pin to supply power from a regulated output as well. Since (pressumably) the output of the motor driver is regulated, that could work, however I would not advise it and directly connect the battery to the VIn pin.
Connecting the 5V output of the motor driver to the VIn pin might work. While this will likely not destroy anything, it may be to low to drive the internal regulator, which might cause the Arduino to run on undervoltage levels. You might see weird behavior in that case (pins not correctly recognizing high from low, incorrect measurements on analog inputs or even software crashes).


Use a GPIO of an Arduino and check (at the speed you need) the HIGH/LOW state.

Depending on the speed at which is sent, you can check the dots and dashes being sent, e.g. by keeping a timer since the last change checking if it is a short or long 'HIGH'.

You have to sample often enough to check if there is a drop (between dots/dashes).


Leonardo clone being recognized by Windows as a broken Linino One - wtf?

USB associates a driver, and thus what it calls a device, with the VID and PID that the device announces. Arduino PIDs are in a horrible mess, and there are many different devices that use the same PID. On top of that you have other makers also using the same VID/PID pairs and providing their own re-named Arduino driver files for their devices.

And then of course you have the problem that it is down to the firmware ("sketch") installed on the Leonardo that determines what VID and PID is shown to the computer.

So you have a set of possible scenarios - the main two being:

You have a driver installed that identifies the VID/PID pair of the Leonardo as something else
You have firmware installed in the Leonardo that gives the wrong VID/PID pair for your drivers

Check 2 first by installing the Blink example into the Leonardo (you can still upload firmware since it goes to bootloader mode at first as you have seen). If it changes the shown driver then you had some broken firmware installed. If it doesn't then you may be running a patched installation of the Arduino AVR core that gives a different default VID/PID pair, or you may just have the wrong board selected in the menu.

If you still have trouble then uninstall whatever driver is associated with the detected device and reinstall the official Arduino drivers that come with the IDE.

You can also delete the IDE and its associated downloaded packages and reinstall the latest version to ensure that you don't have strange patches and settings in there corrupting things.


How to monitor 12 V LiPo charging from Arduino

If you want to buy something off the shelf that will provide power for an Arduino, try a power bank - they have USB out, and are also charged via USB. I found that I had to put a 100 Ohm resistor to stop mine going to sleep, but it's +5V native.

A 100 ohm resistor (0.25 watt at least!) draws 50mA, so a 5200mAH powerbank like http://www.dx.com/p/universal-5200mah-external-li-ion-battery-charger-power-bank-w-led-indicator-usb-cable-pink-362725#.VQneCnWjlIc would leak it empty in 104 hours. If you use at least 50mA at all times, then this isn't needed - I think an Arduino draws 35mA already, so you should get away with a 300 Ohm resistor, drawing 16mA. Some experimentation might be needed.


Arduino servo acts weird with photocell (lightsensor)

Servos accept a signal from 0 to 180, with 90 being the center point on the servo. analogRead() will output a number from 0 to 1023. The arduino "map" function makes a conversion easy to do. just replace

int newAngle = reading / 2;

with

int newAngle = map(reading, 0, 1023, 0, 180);

you can read more about the map function here: http://arduino.cc/en/reference/map

It is hard to tell from the picture that everything else is wired correctly, but this should fix up your code.


Did I break my new Arduino Leonardo Eth by restarting it?

You should be able to use my board detector sketch on one of your other Arduinos to check out the problem board.

See also Have I bricked my Arduino Uno? Problems with uploading to board

Also my bootloader uploader sketch will reflash bootloaders on quite a few devices. I'm assuming that the "Arduino Leonardo Eth" has the same bootloader as the Leonardo.

Hmmm - I see that the "Arduino Leonardo Eth" is from Arduino.org, not Arduino.cc. The bootloader is probably slightly different. I'm really not an expert on what those boards use.

Before worrying too much, try the approach of holding down Reset and then uploading a sketch, letting go of Reset as the sketch starts to actually upload.

Comment by William Hilsum

  I didn't realise there was a difference between .org and .cc, and, I guess by using the leonardo template from .cc, I broke "something". The moment I downloaded the IDE from .org, & uploaded with the eth template , it worked flawlessly. I guess there are some changes between leonardo and leonardo eth. I wanted an arduino with ethernet, so I didn't need a separate shield. No idea if I picked the right "side" after reading all the crap with cc vs org!

That is very annoying that the split of the Arduino camps now produces a support nightmare for people who just want to use their virtually identical products, but have to go through this.

Thanks for the update.


Adafruit RTC begin() not returning false

If you look at the library source code it will be clear why begin() returns true.

From https://github.com/adafruit/RTClib/blob/1.2.0/RTClib.cpp#L434-L437:

boolean RTC_DS3231::begin(void) {
  Wire.begin();
  return true;
}

I suppose they plan to eventually make the return value of begin() mean something but for now it does not.


As far as I know, you have to choose variant with FMC module (Flexible Memory Controller) with SDRAM support - that means you have to use 144pin version STM32F730Z8. The 100pin version does have FMC but doesn't support SDRAM.
After resolving this issue, it should be about configuring FMC module for using SDRAM (in STM32CubeMX for example) and the RAM will be available at some memory location according to the MCUs memory layout.


Yes, the NodeMCU can connect to a temperature sensor and forward that on to your WiFi access point to send to the internet.

Yes, the NideMCU can run from batteries.

Can it do it off one battery for many years? Only if that battery contains a small nuclear reactor.

Running something from battery for many years requires incredibly close attention to detail and incredibly tight component specifications, even down to the precise battery chemistry used. It's a very very difficult task for which people are very highly paid.

When you start looking at periods like that you begin to run up against the problem of battery self-discharge. Getting your power consumption down to an absolute minimum is a must, but even then if you have near zero power consumption the battery is still going to go flat by itself. So you have to invest time and effort into selecting a battery technology with a very low self-discharge.

All that is pretty moot though with the NodeMCU since:

WiFi is a power hungry technology. You can expect hundreds of mA while transmitting, and doing that once a minute for, say, 10 seconds (reconnecting to the WiFi takes time) will give you quite a high average power consumption just from the WiFi
The NodeMCU is far from optimised WRT power consumption. Linear voltage regulators, poor choice of components for low power consumption, etc, abound.

So yes you can run it from batteries, but be prepared to replace the batteries very often. By "very often" I mean every couple of days.

That means you basically have two options:

Don't use the NodeMCU but instead use something designed to be incredibly low power and run for long periods on battery (typically it won't use WiFi but something more efficient like nRF24L01+)
Don't use batteries. Hard-wire your NodeMCU into a mains-connected power supply.


Why bootloader sizes differs from 0.5 to 8 kilo bytes for different boards?

Bootloader of the Mini and Uno are pretty much the same. (I can't find the source-code but the hex files are only slightly different).

The 2k is because they haven't updated mini328.upload.maximum_size in boards.txt. Probably because that would break the board for users that haven't updated the bootloader yet.

The 2560 is using a stk500v2 compatible boot loader instead of Optiboot (uno and mini), because optiboot only supports upto 64kb addresses. Not sure why it is that much bigger though.


How to change ArduinoOTA upload timeout?

The only timeout I can find is in the espota.py script itself. That is riddled with such lines as:
sock.settimeout(10)

You would need to scour that program and change them all.
However
ArduinoOTA uses UDP for communication. Because of that it is unreliable (yes, that's a technical term). It doesn't have any form of retransmit / retry, so if a packet is lost it's lost for good. No amount of increasing of timeouts will make that packet reappear.
So increasing your timeouts most likely will just make it wait longer before failing.
You should consider switching to a more reliable update system which uses TCP instead of UDP - such as downloading an update from a website using ESP8266httpUpdate.
Update:
ArduinoOTA uses a combination of both UDP (to initialise and authenticate the connection) and TCP (to make a "back channel" connection back to your computer) to download the actual binary.
The same still applies: you will need to alter the espota.py program to change its timeouts (sock2 is the back-channel object), but there is also one line in ArduinoOTA.cpp that will need to be altered to increase timeouts.  Line 294:
int waited = 1000;

This is not strictly the number of milliseconds to wait for incoming data, but it's not far off - it's a 1 millisecond delay in a loop while looking for incoming data.  Increasing that will allow more time for the ESP8266 to wait for data to arrive.
But of course, with an unstable WiFi connection YMMV...


Controlling a servo motor with a touch sensor

To solve your problem, you need to take a tiny step into real time programming.  Most Arduino programs deal with one issue or action at a time.  Your simple twist to interrupt and action "i want it to be such that if you remove your finger before the servo reaches 90 degrees that's where the servo stops" requires you to continuously monitor your input (touch switch) while changing your output (next servo position).

You can go about this 2 ways.  You can use interrupts to inform you when the state of the touch switch changes. This is challenging.  Many find it difficult to conceive of what might happen if their program were to be interrupted at any and all possible points in its execution.  A mistake here can lead to unexpected results.

Or you could take turns polling the state of the touch switch then making a small adjustment in the position of the servo.  When the state of the touch switch changes from active to not-active, exit the loop you are using to change the servo position.


Can I stack an Arduino to another Arduino?

No, I don't think that is a good idea. You would basically short the pins of each of them together, plus their power supplies. The only way it might conceivably work was if one Arduino had all its pins as inputs and the other as outputs, otherwise they would be "fighting" each other to drive a pin high or low. You would also have connected together their Reset pins so they would both reset at the same time. And doing serial comms would be problematic as the serial ports would be fighting each other.

Also, uploading sketches would be virtually impossible, as when you started the upload, both would be reset, both bootloaders would try to read the incoming data, and reply at the same time. Plus, the Mega and the Uno have different uploading protocols. So at the very least, you would have to separate them every time you uploaded new code, to either one.


The Arduino IDE is quite idiosyncratic. It won't let you work on a
project that doesn't have a file with the extension “.ino”. On the other
hand, it doesn't care about how much code is in that file, and you can
keep it happy by creating an empty .ino file. I recommend however that
you put at least a comment block in that file, in order to make things
less confusing for other people who could see your project. Then you can
put your assembly code alongside this empty file, in files of their own
ending with the “.S” extension. These files will be preprocessed before
being assembled, so you can #include <avr/io.h> and use the macros
defined therein for the IO ports, bits, etc.

The project would look like this:

my_project/         # containing directory
├── my_project.ino  # comments only, to keep the IDE happy
├── my_project.S    # main assembly file
└── some_extras.S   # possibly more assembly files...

If the whole project is pure assembly, one of your assembly files should
define a symbol called main, which is the entry point of the program:

.global main
main:
    ; code starts here

If you are going to mix assembly and C++, then you can define main()
in the .ino file, and call from there your assembly routines, which
should be declared as extern "C":

extern "C" void my_assembly_routine();

int main()
{
    my_assembly_routine();
}

Mind the calling conventions when mixing asm and C++ though.

If you are going to use the Arduino core library, then you should define
setup() and loop() instead of main(). The Arduino core will then
provide it's own main(), which takes care of its initialization.

If you are going to write mostly C++, with only some assembly sprinkled
here and there, inline assembly could be a better option. C.f. Michel
Keijzers' answer.


Why does an Arduino Uno have 2 microcontrollers

Atmega328P is a microcontroller which are the heart of Arduino Uno, where the Atmega8U2 is the USB to serial convertor for arduino communicated with computer.

You can refer to this link for more information about this.


For version 1 VIN is connected, through a Schottky diode, to the 5V rail.  That means you can only provide, at absolute most, 5V plus a little bit for the diode drop into VIN.  The 5V pin can only source power on the Yun, since it is also connected to the 5V rail through a Schottky diode.

In effect the two pins form the "In" and "Out" of the 5V power.

However in version 2 the 5V pin's diode has been removed, and the VIN's diode has been reversed.  VIN is now known as "5V_OUT".

So the 5V pin can be used for both in and out, and what was VIN can only be used for power out.

To provide more than 5V to the Yun you will have to first pass the voltage through a regulator of some form.  Since you want to use 7.4V it sounds like you are using 2S Li-Ion (or similar) batteries.  Because of that I'd recommend a switching regulator, rather than a linear one.  I commonly use 5V UBEC modules from my favourite RC model supplier.

For version 1 you will provide it to VIN.  For version 2 you will provide it to 5V.  Quite why they'd change something quite so fundamental as the power pin arrangement from one version to another is beyond me.  It would cause havoc with compatibility between versions with certain shields.


Reverse DC motor direction every second automatically

Consider code of the following form.

// Declare some globals
byte direction=0, second, prev=0;

void loop() {
  second = millis()/1000;
  if (prev != second) {
    prev = second;
    direction = second & 1; // Direction is 0 or 1
    OutputTheNewDirection(direction);
  }

More generally, suppose you want to make a pattern of clockwise for j time units, alternating with counterclockwise for k time units.  Suppose a time unit is m milliseconds long.  You can use code as in the following example, where m is 500, j is 10, and k is 1.

// Declare some globals and constants
byte direction=0, tunit, prev=0;
enum { m=500, j=10, k=1 };

void loop() {
  tunit = (millis()/m) % (j+k);
  if (prev != tunit) {
    prev = tunit;
    direction = tunit < j; // Direction is 0 or 1
    OutputTheNewDirection(direction);
  }


How to use a potentiometer to access data within a 2 dimensional array?

Using the Arduino map() function seems a reasonable approach to this, however you have a problem with the indexing.

if (numScales == 3); {

Is probably not what you want, as that condition can never be true since you set it to something in the range of 0-2 before you reach this check.

Considering only the relevant dimension, you a 3-element array, which will have legal elements numbers 0, 1, and 2

You call map(analogRead(A2), 0, 1023, 0, 2); which can produce an output in the range of 0-2, so far so good.

But then check for a value 3 which is not only illegal as in index to a 3-element array, but unable to be produced by your code.

Additionally you should probably stop trying to use the numScales variable to do double duty holding both the initial size and later also the current index.  And you should probably pass that as an argument, rather than make it a global variable.

You are also failing to ever use the current scale as an index into the notes array.  The syntax of double array indexing would be notes[x][y] but of course this should only be done with indicies to elements that exist.

It would probably also be a good idea to add some debug output of the internal logic, for example print both the raw ADC reading and the result of mapping that to the selected "scale".


For Arduino Uno it is possible to use the digital pins with PWM to read analog data, is this also possible with the Wemos D1 Mini?

There is one way you could measure analogue voltages using a PWM output: Use it as a DAC to build your own Successive Approximation ADC:

The PWM is filtered through a low-pass filter to create an analogue voltage
That is compared to an incoming voltage using a comparator
The output of the comparator is recorded for different reference voltages using a "divide and conquer" method.

You can read more about how Successive Approximation works here.

However, doing that would be overly complex and needlessly expensive. It is far better to just add an ADC chip using I2C or SPI. It's cheaper, easier, and the results will be far superior.

But as a learning exercise to discover how ADCs work, it could be kind of fun.


The MCP23017 (and it's sister the SPI-based MCP23S17) can have their interrupt pins set to "mirror" mode. In this mode both pins are internally joined so when an interrupt occurs on any port both pins activate.  This is done using the MIRROR bit of the IOCON register.  Using this will turn your 4 interrupt pins into just 2, one for each Arduino INT pin.

Should you want to add more in the future, or if you find you want to use one of the interrupt pins on the Arduino for something else, there is also the ODR bit in the IOCON register. This sets the interrupt pins to be open drain, which means that all of them can be wired together into just one INT pin on the Arduino. Add a pullup (or enable the internal pullup) and you have have many IO expanders on one INT pin. Of course, that then means that you have to poll all the expanders to find which of them triggered the interrupt, so could slow things down somewhat depending on how you are using it.


How can an Arduino Mega 2560+Wifi Shield 2.0 (SeeedStudio) receive data from database in a XAMPP server on my PC?

You should forget about the $_SESSION["ID"]; on PHP side, because you are working stateless without any session!
You should give a parameter for identifying your variable from arduino to php script - is this the temp=0? If so you need to exchange

$sql="SELECT temp FROM perfil, client WHERE perfil.ID ='$id'";

with

$sql="SELECT temp FROM perfil, client WHERE perfil.ID =" . $_GET["temp"];

assuming that perfil.id is only an integer - if it is a string, then add "'".


Programatic FOTA (Firmware-Over-The-Air) upgrades with Uno R3

There's two ways you can go about this - hardware and software.

To do it in software would mean writing a new bootloader that supported whatever wireless medium you chose.  The bootloader might end up quite large and thus restrict the size of sketch you are able to support.  It may also require advanced programming techniques in order to fit it into memory.  Not a task for a beginner.

Doing it in hardware is easier but more restrictive.  You need a wireless medium that can emulate a serial device including the ability to perform a reset of the Arduino.  There are bluetooth interfaces for the Arduino that can perform this kind of functionality, but I am not aware of anything WiFi or Ethernet that even remotely comes close.

There are Arduino boards available with this kind of bluetooth interface built in.

A possible third option is something in between - you have two Arduinos (or some other external MCU based system, like an ATTiny for instance), the "target" and the "programmer".  The "programmer" is what is connected to the wireless and accepts instructions and commands over the air.  It is then capable of putting the "target" into bootloader mode (reset it) and pass data through to its serial port for programming.  It does mean the "target" isn't directly connected to the wireless though, so it is up to the "programmer" to support whatever wireless functionality is needed and communicate properly with the "target" to get it to do everything it should.  There is no way to do FOTA to the "programmer" though, so you're back at square one if you want to reprogram that...


Schematic for the adafruit motor shield v2.3

Everything can be found out by reading the schematic which, incidentally, is the first hit on Google when you search for "Adafruit motor shield 2.3 schematic":

  What are the pin holes above and below the Arduino pins? Are they secondary positions for the pins?

Yes. They're just there to make it easy to solder wires and jumpers to.

  What is the PWMs 0,1,14,15?

They are connected to PWM pins 0, 1, 14 and 15 of the PCA9685.

  How is the big empty board in the center setup?

It's just holes. Known as a "matrix prototyping board" for you to solder your own components and things into. Nothing there is connected to anything at all, it's up to you to make the connections with solder and wires.

As you can see from the schematic the only Arduino pins used are SDA/SCL (A4 and A5) and two PWM pins D9 and D10. Everything else comes from the on-board I2C PWM chip.


I am looking for the source and/or proper definition for the int() function

int(x) is not a function but another way to perform an explicit cast of x to an int. It is part of the C++ language itself, that is why you could not find it in a library.

This is not Arduino-specific.

In C and C++ you can cast a value to an int by doing this:

int y = (int) x;

C++ has extended this notation by allowing to do it this way, which is equivalent:

int y = int(x);

You can find this in more details in C++ language reference.


Where Can I Find a 12v Solder-less Breadboard Power Supply?

There is nothing special about a "breadboard power adapter" that isn't served by a normal regulated supply. Simply use wires or a barrel jack or some other connector to connect any regulated supply to the breadboard as desired.


How to download files from a user/password protected web server (user:passw@ip:port)

use the http.setAuthorization(user, passw) method.


You need split the reading into two processes - storing the characters and checking if they are the right message.

To store the characters for example:

String message = "";

void loop()
{
while(Serial.available()) {
    char b = Serial.read();

    if (b == '\r') {
        processMessage();
        message = "";
    }
    else {
        message += b;
    }
}
}

The process might look like

void processMessage() {

    if (message == "fb") {
         foo();
    }
    else if (message == "bf") {
         bar();
    }
}

I just use the Messenger library usually. But note you have to change WProgram.h to Arduino.h in Messenger.cpp to get it to work.


Compatibility between Particle Photon and Arduino

You can use the new particle dev platform to do this https://www.particle.io/dev


How to: Connecting 4-pin Joystick to Arduino board

If the link that Mark Smith provided is correct, that is a “dual-axis mini xy joystick module PSP 2-Axis Analog Thumb Joystick Module Thumb Joystick for Arduino”, with (as other comments suggested) pins labeled on back of board as GND, X, Y, VCC.

To use it, attach GND to Arduino ground; connect each of X and Y to analog inputs, like A0 ... A7; connect VCC to (typically) 5 V.  Then read results on your analog input lines.

Note, it makes sense to test the device using a DVM beforehand.  Measure resistance from GND to VCC to find out overall resistance, so you can decide if 5 V is appropriate or if you should use a lower voltage.  (For example, if overall resistance is several thousand ohms, 5 V is ok; if only a few hundred, add one or two thousand ohms in series and take analog readings using a 1.1 V reference instead of 5 V reference.)  Also measure resistance from GND to X as you move the thumb control, and from GND to Y.


Instead of the two delays of one second, have the program check if the current time is an even or odd number of seconds.

int prPin = A0;

void setup()
{
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(prPin,INPUT);
  Serial.begin(9600);
}

void loop()
{
    int prVal = analogRead(prPin);
    Serial.write(prVal);
    if(prVal>450)
    {
      if( (millis()/1000)%2 == 0 ) // check if even or odd number of seconds have passes since the program started
      {
        digitalWrite(5,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(7,HIGH);
        digitalWrite(8,LOW);
        digitalWrite(9,HIGH);
        digitalWrite(10,HIGH);
      }
      else
      {
        digitalWrite(5,LOW);
        digitalWrite(6,HIGH);
        digitalWrite(7,HIGH);
        digitalWrite(8,HIGH);
        digitalWrite(9,HIGH);
        digitalWrite(10,HIGH);
      }
    }
    else
    {
      digitalWrite(5,HIGH);
      digitalWrite(6,HIGH);
      digitalWrite(7,LOW);
      digitalWrite(8,HIGH);
      digitalWrite(9,HIGH);
      digitalWrite(10,LOW);
      delay(10);
    }
}


The alarm is always on because you are setting it to be always on.  You code should say:

 if (_server.arg("alarm1") == "on") {


Power 4 leds with max7219 and LedControl.h

No it shouldn't matter that you are using separate LEDs, but you will have to connect them in a way that is acceptable to the 7219, they will have to share either a common anode or cathode (can't remember which of the top of my head).

I find its always best to check the basics (Based on personal experience)

Have you got the LEDs the correct way around?
Are you using the correct voltage for everything?
Do the LEDs work when controlled directly by the Arduino, try "Blink"?
Have you tried changing the intensity?
Have you got the required resistors in?
Try inverting the index of the LEDs, i.e. led(x=0,y=0) might be wired (x=7,y=7)?

You loop() is not pausing, so all it is going to be doing is calling that one statement repeatedly.  Now that might not be a problem or the second call may be blocking the first from completing.  So I suggest add a delay for a second or so and see if that changes anything.  Also to prove you are running you Loop() code flash the LED on the board (pin13?).

Hope that helps.


Burning arduino generate hex file to blank atmel chip

Yes. The binary generated by the Arduino IDE in no way requires the presence of the Arduino bootloader in order to operate. Note that certain characteristics such as the MCU and clock rate are set at build time and cannot be changed in the final binary.


Where can I find beginner resources on using voltage regulators with Arduino circuits?

In order to get a smooth signal to your power regulator you should use some capacitors before and after the voltage regulator. It will look something like this when you use the 7805 voltage regulator.

Note: This schematic is from a dutch website. Uin means Vin and Uuit means Vout. C2 and C3 are bipolar capacitors.

It's also smart to put a diode before the voltage regulator to make sure the voltage flows only to one direction. The values of C1, C2, C3 and C4 and pretty standard and coul be used for the other Voltage regulators as well.

The voltage Regulators come in different fixed values and tey have a minimum and maximum voltage they can handle. Here's a small table of the most common VR's with their minimum input voltages.

Part Number     Output Voltage (V)      Minimum Input Voltage (V)
7805            +5                      7.3
7806            +6                      8.3
7808            +8                      10.5
7809            +9                      11.5
7810            +10                     12.5
7812            +12                     14.6
7815            +15                     17.7
7818            +18                     21.0
7824            +24                     27.1

Also note that the output currents of these Voltage Regulators listed above is max 1A. When they're called like 78S05 or 78S09 it'll be a 2A Voltage Regulator.

Another thing that could be important when you're using the minimum input voltages. If you put a diode before the Voltage Regulator there will be a small voltage drop. For a 1N4007 the voltage drop will be around the 0.5V. The voltage drop will only occur before the voltage regulator though, so when you don't use the minimal input values you don't have to mind about it.


ble_write slows down my sketch causing problems (Blend Micro & NRF8001)

I've solved it by overclocking my blend micro to 16mhz (done in the Arduino IDE). Not a perfect solution but works. :)


How do I use ultrasound to track a moving object?

Yes you can use ultrasound to track a moving target, but I really doubt it could be done with an Arduino.

You need to be able to ping the object at least 3 times in the time it takes to move your beam width.  3 times because if you know where it is with the centred ping you need to calculate the direction of travel by pinging either side of the centre to see if it is there.

You then need to track it in three dimensions.  To do this you will need multiple sensors ideally at least 3 for 2D and 3 for 3D, so at least 6.  3 sensors in a plane will give you a reasonable degree of accuracy, but you beam width is key to this, the narrower the better.

Now you have to triangulate the position of the object, well actually work out the area of probability (for both planes) you never 'know' where it is really.

Oh and all 6 sensors need to have different frequencies to prevent interference, you then need to add in reflection processing to reduce false signals.

Its just much easier to buy a Pixy camera and download the software that they have for visually tracking your balls.


Fast PWM with Arduino, the inputs outputs don't work

This line:
TIMSK = (1<<OCIE1A) | (1<<TOIE1);

enables a couple of interrupts generated by Timer 1. Whenever you
enable an interrupt source, you should make sure that the matching ISR
has been defined. Otherwise, the interrupt request is routed to
__bad_interrupt(), which by default jumps to the reset vector, thus
resetting your program.


How do I read addresses on multiple DS2413 1-Wire GPIO Breakouts, using the Adafruit sketch?

You have two detection loop in your setup function.
This one can be safely deleted as for each detected device it will print the error message

while (oneWire.search(address)) {
   printBytes(address, 8);
   Serial.println(F("No device found on the bus!"));

}


How to count the time until the next day of the week?

The key to working with time is to have a known "base" time to calculate everything relative to.  This is called the epoch.  Different systems use different epochs, and each has advantages and disadvantages.

I generally use the UNIX epoch in my programming (chiefly because I am a UNIX nut), which is the first of January, 1970 (01/01/1970).  This is year, month, day, hour, minute and second 0.

From that you can then calculate the number of seconds between the epoch and any other time you choose as long as it is later than the epoch.

To calculate the day of the week for any given date you first need to know the day of the week for the epoch (for UNIX that's a Thursday) then work out how many days there are between the epoch and the target time.

Calculating real times in terms of seconds can be somewhat tricky due to leap years and daylight savings, but there are plenty of algorithms in the public domain, and many RTC libraries include functions to convert to/from epoch times.

For instance, the Arduino Time Library has functions to calculate weekdays, and to convert to "time_t" format (seconds since epoch) which can be used to work out differences in times.  For instance, if you know that it's Tuesday and you want next Friday then you know that Friday is 3 days in the future - so you can get the current time in seconds from the epoch then add to that 3 days' worth of seconds (3 × 60 × 60 × 24) to that time to get the same time of day next Friday.


XL335B accelerometer reports false readings

You are assuming here that 3g will result in the maximum voltage of 3.3v. This is not correct. The datasheet says it's 0.3v/g so; 0g-voltage + 3 x 0.3v => 1.65 + 3*0.3 = 2.55volt.

To get the g value use (analogRead(0)-337.92)/61.44 (337.92 is the 0g voltage in steps; 61.44 is 0.3V is steps).

To get the acceleration is m/s² just multiply by 9.81; so (analogRead(0)-337.92)/61.44*9.81

Like you stated in the comments, the result isn't that accurate. Just have a look at the datasheet. e.g. Volt per G is typically 300, but can be anything from 270 to 330. Same thing goes for the 0g voltage; 1.35V to 1.65V. So quite a bit of difference can occur between one chip and the next. Even between the 3 axis inside one chip.

So the best thing is to calibrate all 3 axis. For the Z axis; just lay the sensor flat, and get the analogRead value (-1g value). Flip the sensor upside down and get the analogRead value (+1g value). Optionally place the sensor on it's side to get 0g value or just calculate the value in the middle of the above two value. The steps-per-g will be the difference between the two divided by 2 (+1g - -1g = 2g). Put this value and the 0g step-value into the formula. Repeat the procedure for the other 2 axis.


The Pro Micro, like the Leonardo, cannot automatically reboot into the bootloader like boards such as the Uno and Mega.  Instead it relies on the sketch running on it listening for a special combination of events (open the serial port, set the baud rate to 1200 baud, close the serial port) to activate the bootloader.

If, for whatever reason, you don't have a working sketch installed on the board (such as you aborted the upload part way through) then there will be nothing there to listen for the "reboot into bootloader" instructions.

So you need to manually enter the bootloader. Fortunately it should be easy enough, but timing is all important.

When you first plug the board in, or when you press the reset button, you get a few seconds where the board is in the bootloader.  On the Leonardo that is signified by the LED glowing and pulsating - I don't know off hand what is shown on the Pro Micro.

As long as you press the reset button just before you compile and upload your sketch, and as long as the upload portion doesn't take too long to start (tip: compile it before uploading, it makes it faster) it should then install the sketch into the board and from then on the auto-reboot should start working.

(Note: I haven't used a Pro Micro - this is all from my experience with the Leonardo which I believe uses the same bootloader.)


Convert string plus hexadecimals to array of hex:

How can I parse this string in the arduino to get an array of hex values:

There are a few standard library (stdlib) functions that can help you with that. Below is a snippet:

char buf[] = "0x0F 0x2C 0x98 0xBD";
uint8_t val[4];

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

  char* bp = buf;
  int i = 0;
  do {
    char* ep;
    val[i] = strtol(bp, &ep, 16);
    Serial.println(val[i], HEX);
    bp = ep;
    i += 1;
  } while (*bp != 0);
}

void loop()
{
}

Cheers!


You can't drive LEDs from a source greater than 5V as a low-side switch with an Arduino directly. To do so you need an "open drain" output.
You can create them on the Arduino by adding a single transistor (N-channel MOSFET with "logic level" threshold, or NPN BJT) which the Arduino switches:

simulate this circuit – Schematic created using CircuitLab
R2 just exists to keep M1 turned off when the Arduino's not actively driving it (i.e., while the bootloader runs, etc).


Nodemcu stops sending the messages to the API

Remove the return in setup function and check. And set regular yield () statements to ensure smooth running of background tasks. And use if statement in the loop for !client.connected()


42 pixels in the strand all set to bright white.

This exceeds the power supply capability of either a USB port or the Arduino's regulator.

Likely the circuit starts out working, then once the LEDs are all on drawing high power either a protective device such as a polyfuse / PTC fuse activates trips or the supply simply sags under load.  At this point the circuit either shuts down or starts misoperating, the ATmega may go into brownout protection mode, etc.

Disconnect power to your LEDs and you will probably find that the Flora is fine.

You will need to use a suitable higher current power supply if you want to light more than a few pixels of this type at any given time.


Looks similar to:
"8 Channel 5V/3.3V IIC UART SPI TTL Logic Level Converter"

Image above was screen capped from: https://www.aliexpress.com/item/32977711795.html