text:
Linux avrdude: stk500_getsync()
When trying to flash my genuine arduino micro with avrdude from cmd on a Manjaro system I get the infamous error
avrdude: stk500_getsync() attempt x of 10 ...
Im adding this post to the many other that ask about this error because all of them are trying to use the IDE to flash the arduino, whereas I can use it no problem on both Linux and Windows, but when using avrdude from cmd on Linux I get this error. This confirms that the board is fine and there are no shorts on the reset pin or any other possible physical cause of this issue, something appears to be wrong in the avrdude configuration.
This is my Makefile:
default: build

build:
    avr-gcc -mmcu=atmega32u4 main.c -o main

flash:
    avr-objcopy -O ihex -R .eeprom main main.hex
    avrdude -F -V -c arduino -p m32u4 -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex

Can you suggest anyway to fix this?
EDIT:
Problem Solved!
The error was in the -c parameter, for the atmega 32u4 it's supposed to be avr109 and not arduino.

In the IDE you can set the preference for verbose output on upload, and then watch the log. It might show all commands that the IDE uses.

There are two common ways of resetting an Arduino into the bootloader:

For UART based boards (Uno, Mega2560 etc) just opening the port resets the board
For USB based boards (Micro, etc with the 32u4 chip) you have to manually tell it to reset

Yours is option 2 - unless you tell it to reset the board it won't do anything. The IDE normally handles that for you.
But it's simple: just cause the CDC/ACM port to be opened at 1200 baud and closed again. The simplest method is to use stty to do it for you:
stty -F /dev/ttyACM0 speed 1200

You should find that it then resets the board. Adding a short delay to allow the USB to reset would be good too. So your whole programming routine could look something like:
flash:
    avr-objcopy -O ihex -R .eeprom main main.hex
    stty -F /dev/ttyACM0 speed 1200
    sleep 1
    avrdude -F -V -c arduino -p m32u4 -P /dev/ttyACM0 -b 115200 -U flash:w:main.hex

In Makefiles I find it useful to set the port as an overridable variable:
PORT?=/dev/ttyACM0

Then use ${PORT} everywhere instead of /dev/ttyACM0 - then you can use make PORT=/dev/ttyACM1 if you need to without having to edit the Makefile. Great if you have multiple boards.

I was indeed thinking about the reset, thanks for the explanation! When I run the flash command the I get the following and then it stucks without going any further: avr-objcopy -O ihex -R .eeprom main main.hex \n stty -F /dev/ttyACM0 speed 1200 \n 9600 \n What is this about?

This Arduino Makefile comes with a small script that does exactly this on a Micro, and has different logic for other board types.

@EdgarBonet I'm trying to learn low level programming, thats why I'm doing it with a MakeFile, I don't want to use a python script.


text:
FastLED changing colour at holding state
Basically make a code to guide users through a box breathing exercise (breath in for 4 seconds, hold for 4, release for 4, hold again for 4, repeat) to help relax them.
Right now my code is running APA102's. They're running through 5 "breathing" states; In, ChangingToOut, Out, ChangingToIn, Rest.
My LEDs are just fading in and out in an aqua/green colour.
What I would like to do is to change the colour at every BREATH_HOLD_DELAY. I want the LED display to be easier to follow for people doing the breathing exercise. Right now It's difficult to tell when the "hold breath" part is when the LEDs are at full brightness. I would like the LEDs to fade in green, immediately switch to blue for the 4-second BREATH_HOLD_DELAY, and then immediately switch back to green to fade out and hold at low brightness for 4.
I'm really lost as to how to do this. I've tried doing an "if" statement;

if (BREATH_HOLD_DELAY)

leds[i] = CHSV(HUE2, 255, brightness);

But that just changed the entire LEDs light fade to blue, rather than just the BREATH_HOLD_DELAY parts.
Here's my entire code!
#include <Servo.h>

#define DATA 11                 // Data connected to Digital Pin 11 on the Arduino
#define CLOCK 13                // Clock connected to Digital Pin 13 on the Arduino
#define SERVO_PIN 9              // Pin that the servo is connected to
#define LED_TYPE APA102         // This LED strip uses the APA102 chipset.
#define NUM_LEDS 45             // There are 25 LEDs on this strand
#define HUE 65                  // The colour of the LED's
#define HUE2 10                  // The colour of the LED's
#define LOOP_DELAY 20          // in Milliseconds
#define BREATH_HOLD_DELAY 3000
#define SERVO_INITAL_POSITION 0  // define the initial position value to 0

enum breathingStates { In, ChangingToOut, Out, ChangingToIn, Rest };

//Global Variables
CRGB leds[NUM_LEDS];            // the array of LEDs          assigning one after the other
Servo myservo;  // create servo object to control a servo

/*====================================================================
  setup(): will run only once
=====================================================================*/

void setup() {
  Serial.begin(115200);
  LEDS.addLeds<LED_TYPE, DATA, CLOCK, RGB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.show();
  myservo.attach(SERVO_PIN);
  myservo.write(SERVO_INITAL_POSITION); // Initial position of the servo
}

/*====================================================================
  loop(): will run indefinitely
=====================================================================*/

void loop() {
  static int8_t theta = 0;
  static breathingStates breathingState = Rest;

  switch(breathingState)
  {
      case Rest:
        Serial.println("This is the first time the loop has run");
        // Do any further setup not done in setup function here, but this is redundant
        breathingState = In;
        break;

      case In:
        theta++;
        if(theta >= 90){
          breathingState = ChangingToOut;
        }
        break;

      case ChangingToOut:
        delay(BREATH_HOLD_DELAY);
        breathingState = Out;
        theta--;
        break;

      case Out :
        theta--;
        if(theta <= -90){
          breathingState = ChangingToIn;
        }
        break;

      case ChangingToIn:
        delay(BREATH_HOLD_DELAY);
        breathingState = In;
        theta++;
        break;

      default:
        Serial.println("It should never have come to this... :(");
  }

  // Now that theta is set, we do somethign with it in this section of the loop() function

  //Serial.print("The value of theta is: "); Serial.println(theta);

  float thetaInRadians = float(theta) / 57.295;
  double dblBrightness = sin(thetaInRadians);      // LED brightness
  uint8_t brightness = (dblBrightness * 127) + 128;
  Serial.print("The value of brightness is: "); Serial.println(brightness);

  //Set the  hue and brightness of each LED
  for (int i=0; i < NUM_LEDS; i++){
    leds[i] = CHSV(HUE + i, 255, brightness);  // Set the colour and brightness of the LEDs

  }

  //Show the next frame of the LED animation
  FastLED.show();

  myservo.write(theta + 180);

  delay(LOOP_DELAY);

} ```

Would love any help or guidance. I'm very new to coding and Arduino!

Is it intentional that the color of the LEDs is slightly different? Or should they all have the same color at a certain point in time?

All the same colour ideally when the LEDs are holding for 4 seconds at full brightness! I think that's the BREATH_HOLD_DELAY section

Your color scheme seems weird, float thetaInRadians = float(theta) / 57.295; uses an angle (from a HSV color scheme?) and then converts that into a brighness. The brighness however is the second parameter in a HSV, which you apparently want to control separately. I would change the switch statement such that in every step, the desired color/brighness is selected and then, in a separate step, you fade to that. That way, you can control the desired target color/brighness independently of how fast the colors change.

is it possible to put something like if (brightness = >255) and change the colour that way? Tell the code that when it hits full brightness it needs to be blue instead of green?

Sure, it's all software. You can do whatever you like.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Read SD card on ATMEGA328 from ESP826
I have a ATMEGA328 with ESP826 (like this http://arduinolearning.com/hardware/atmega328-esp8266-arduino-board.php) and can successfully send information from the ATMEGA328 to the ESP826 via serial.
I can also record information from the ATMEGA328 to SD card.
What I would like to do is read data from the SD card with the ESP826 so I can upload it to a server..
When I try to connect directly:
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <SD.h>

File myFile;

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

  Serial.print("Initializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    return;
  }

  myFile = SD.open("/");

  printDirectory(myFile, 0);

  Serial.println("done!");

}

void loop(){
}

void printDirectory(File dir, int numTabs) {
  while (true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}

It doesn't find the card. This is regardless of whether I have pins 1&2 ON or not.
Is there any way to write to the SD card using the ATMEGA328 and read that from the ESP826 (to send the files to the cloud)?

you can't. SPI pins of the esp8266 are not accessible on Uno+WiFi. you can't wire an SD card to the esp8266.

You can't. There's no connection between the ESP8266 and the SD card.
However you can program the ATMega328 to read the SD card then send that data to the ESP8266 for forwarding to the internet.

Thanks! What's the best way to send data from the ATMega to the ESP8266? The file on the SD card will be a sound file.

Have you consider something like nodeMCU?
Is there a reason why you using such a complicated board?
This would enable you to connect your SD card reader directly to nodeMCU, which can read the data  from same inputs as atmega328 (watch for voltage differences) including the sensors which has the capability of uploading data to the cloud without the need of additional MCU, while making debugging far easier.
I know that I am going to get dislikes here, but it looks to me like one of those cases when you connect two things that would work better of alone, making something does doesn't do either ones job very well.
Maybe you can get a refund...
If not contact your card issuer for "Cardholder not present" claim that bot VISA and Master card have.
Is there any reason why wouldn't standard nodeMCU be enough for your project? (probably superior)
If its not enough:
If you connect node-mcu (5-15 Eur/Pounds/Dolars) and a nano (About half of the price) on a breadboard and connect them together via (software) serial pin, (using jumper cables and resistive divider), you can program them without messing with pointless dip switches  and learn something usefull for future projects. latter you can replace nano for 3V3 pro miny to remove even the divider.
There is this absurd idea from Arduino core team developers of using superiour Esp32 MCU as a secondary tool to inferiour ATMEGA328, while logically you should do the opposite.
This is amplified by the fact that I would personaly consider Esp8266 core arduino libraries superior to those made for atmel...
You might even find that the 2-3MB FS you can create on ModeMCU might be enough without the need of SD card.
I had a quick look through the site and a combination defaulting to http and nonstandard hardware, combined with low standard of explanation, But what I find really imoral is harvesting excessive number of domain names on a similar subject which could have been used for other projects makes me think if these tutorials are designed to increase the sales of badly designed boards... I would recommend you to change the tutorial source...

point taken , comment deleted

Can you tell me what this statement has to do with the question: "BUT EVEN WORSE STEALING EXCESSIVE NUMBER OF DOMAIN NAMES"? Using all capital letters, with a bold and italic font, is NOT going to send the message you think it will to the community.

I think pointing out the immoral action of the website designers, is relevant in pointing as additional reasons to point asker towards better tutorial, or source for board. I have rephrased, the sentence (not sure how did caps happened)

So now, you change the irrelevant text to this "But what I find really imoral is harvesting excessive number of domain names on a similar subject domain names" with a bold font.Can you tell me how that statement applies to the OP's question?

I am unable to explain you mine reasoning any better then in mine previous comment. maybe once I think how to rephrase explanation for mine reasoning. Otherwise we may have to differ in opinion and I will get mine expected down-vote. I accept that you are better at programming then me, just disagree with you on this point. Good night

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Help with reading data from ADXL373 Accelerometer (I2C)
I am using ADXL373Z accelerometer with Arduino Uno for a project.
When I run the code, I am getting incorrect values which are probably not even acceleration data. I am thinking it might be a wiring problem, I attached circuit diagram below. This is my first Arduino project, and I couldn't find any other applications with the sensor I am using so any help would be much appreciated. Thanks in advance.
Datasheet for sensor : https://www.analog.com/media/en/technical-documentation/data-sheets/adxl373.pdf
Code ( for x-axis data only) :
// ADXL373 Accelerometer Test

#include <Wire.h>

/* -------- REGISTERS -------- */
#define ADDRESS_ADXL373 0x53 // sensor adress (assumes MISO pin high)
#define ADDRESS_POWER_CTL 0x3F // power control
#define ADDRESS_MEASURE 0x0E // measurement control
#define ADDRESS_TIMING 0x3D // output data rate and extarnal timing triggers
#define ADDRESS_XDATA_H 0x08 // x-axis acceleration data [11:4]
#define ADDRESS_XDATA_L 0x09 // x-axis acceleration data [3:0]
#define ADDRESS_YDATA_H 0x0A // y-axis acceleration data [11:4]
#define ADDRESS_YDATA_L 0x0B // y-axis acceleration data [3:0]
#define ADDRESS_ZDATA_H 0x0C // z-axis acceleration data [11:4]
#define ADDRESS_ZDATA_L 0x0D // z-axis acceleration data [3:0]
/* -------- REGISTERS -------- */

#define SCALE_FACTOR 0.2f // 200 mg per LSB scaling factor
#define GRAVITY_EARTH 9.80665f // gravity of earth in m/s^2

void setup() {
  Serial.begin(115200);
  while(!Serial);
  Serial.println("ADXL373 Accelerometer Test");
  Wire.begin();
  Wire.beginTransmission(ADDRESS_ADXL373);
  Wire.write(ADDRESS_POWER_CTL);
  Wire.write(0x03); // activate full bandwith measurement mode
  Wire.endTransmission(true);
  delay(50);
  Wire.beginTransmission(ADDRESS_ADXL373);
  Wire.write(ADDRESS_MEASURE);
  Wire.write(0x04); // set output signal bandwith to 2560 Hz
  Wire.endTransmission(true);
  delay(50);
  Wire.beginTransmission(ADDRESS_ADXL373);
  Wire.write(ADDRESS_TIMING);
  Wire.write(0x80); // set output data rate to 5120 Hz
  Wire.endTransmission(true);
  delay(50);
}

void loop() {
  byte xAxisH, xAxisL;
  Wire.beginTransmission(ADDRESS_ADXL373);
  Wire.write(ADDRESS_XDATA_H);
  Wire.endTransmission(false);
  Wire.requestFrom(ADDRESS_ADXL373, 1, true);
  xAxisH = Wire.read();
  Wire.beginTransmission(ADDRESS_ADXL373);
  Wire.write(ADDRESS_XDATA_L);
  Wire.endTransmission(false);
  Wire.requestFrom(ADDRESS_ADXL373, 1, true);
  xAxisL = Wire.read();
  int16_t xAxisFinal;
  xAxisFinal = (uint16_t) xAxisH << 8 | xAxisL; // bit shift and combine two components
  xAxisFinal = xAxisFinal >> 4; // 12-bit resolution
  float xAccel;
  xAccel = xAxisFinal * SCALE_FACTOR * GRAVITY_EARTH;
  Serial.print("Xa = "); Serial.println(xAccel);
  delay(200);
}

Circuit Diagram :

Results from Serial Monitor (in m/s^2) :

xAxisFinal = xAxisH << 4 | xAxisL; I think you mean << 8.

According to the datasheet, the 12 bits of the X acceleration are stored
into the registers XDATA_H and XDATA_L as follows:
XDATA_H:   b₁₁b₁₀b₉ b₈ b₇ b₆ b₅ b₄
XDATA_L:   b₃ b₂ b₁ b₀ x  x  x  x

where x means “reserved”.
Now, there are two issues with this code:
xAxisFinal = xAxisH << 4 | xAxisL; // bit shift 12-bit output data

The first issue is that, by shifting xAxisH by four places, the bits
b₇–b₄ end up in the same positions as the bits b₃–b₀ in xAxisL. Then,
when those values are combined with |, the bit b₇ gets mixed with b₃,
b₆ with b₂, etc. If you really want to shift xAxisH left by four
places, you should also shift xAxisL right by four places.
The second issue is that the x data is a signed number represented as
two's complement, and the sign bit (b₁₁) ends up in the wrong place. For
example, if the measured value is −16 (XDATA_H:XDATA_L = 0xff:0x00),
you end up reading 4980 (0x0ff0). In order to avoid this issue you could
sign extend the 12-bit number to 16 bits.
I would suggest, though, a completely different approach. The number is
left justified in the sensor registers, so just keep it like this:
xAxisFinal = (uint16_t) xAxisH << 8 | xAxisL;

The intermediate cast to uint16_t is here to avoid an undefined
behavior, the final result is signed. If there is some risk that the
reserved bits are non-zero (the datasheet is not very clear in this
respect), you could
xAxisFinal &= 0xfff0;  // clear last 4 bits

Note that now the unit of the acceleration is 1/16 of the resolution of
the sensor, and all values you get are multiples of 16. I don't expect
this to be an issue. If you really want to use the sensor resolution as
your unit, you could now shift xAxisFinal four places to the right,
which would automatically perform the sign extension.

Edit: Addressing the edited code from the OP:

I modified the code according to your suggestions. But I am still
getting incorrect values from serial monitor.

What I see in your post is very small values, around ±3 LSBs of the
sensor. This could very well be sensor noise. But then, there is the
occasional larger value. Interestingly, those larger values seem to be
very close to ±16 LSBs, hinting at some kind of communication
problem.
I guess the answer is in this warning from the sensor's datasheet:

Always read acceleration data using multibyte transfers to ensure that
a concurrent and complete set of x, y, and z acceleration data is
read.

Imagine the sensor is outputting only noise, and the noise fluctuates
between −1 and +1 LSB. What you expect then is:
value  XDATA_H   XDATA_L
  −1   11111111  11110000
  +1   00000000  00010000

If you read XDATA_H and XDATA_L in two different transactions, you
may well read 0b11111111 for XDATA_H (as the sensor is reading  −1),
then read 00010000 for XDATA_L (as it is getting +1). When you
combine these two readings together, you get
value  XDATA_H   XDATA_L
 −15   11111111  00010000

I suggest you follow the recommendation from the datasheet and read both
registers in one go:
Wire.beginTransmission(ADDRESS_ADXL373);
Wire.write(ADDRESS_XDATA_H);
Wire.endTransmission(false);
Wire.requestFrom(ADDRESS_ADXL373, 2, true);
xAxisH = Wire.read();
xAxisL = Wire.read();

Heh. Your answer came in about when my comment did.

Thanks, I modified the code according to your suggestions. But I am still getting incorrect values from serial monitor. I edited the code and results in my post. If you have any other suggestions I would appreciate it.

@Maxxie: See expanded answer.


text:
Serial port /dev/cu.usbmodemfa131 vs /dev/cu.usbserial-A702NY8S
On Mac OSX Mavericks, why does Arduino Uno uses serial port named /dev/cu.usbmodemfa131 while Arduino Nano uses /dev/cu.usbserial-A702NY8S?
Are they using different FTDI drivers?

Which revision of the Arduino board do you have?

@AsheeshR Arduino Uno R3 and Sainsmart Arduino Nano v3

To throw another spanner in the works, have you ever noticed what happens to the serial port identifier when you put the Arduino Uno R3 into a different USB? For me 131 <--> 121. But if you change the Nano between ports, the identifier is the same!

Drivers are different. On older boards, such as Duemilanove you may need to actually download serial drivers to talk to them at all in Lion, Mountain Lion, Mavericks.
There's some discussion of that problem here.

It's really down to the manufacturer and what they identify their USB side as. I have found that Arduino(tm) provide a more meaningful (to me) identifier, eg /dev/cu.usbmodemfa131 Whilst the boards that use the FTDI chip have the more serialised numbers /dev/cu.usbserial-A702NY8S.

The Uno is not using FTDI drivers at all, since it does USB through an ATmega16u2, not an FTDI chip.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Arduino USB Power vs External Power Supply
Why is the Arduino able to accept ~5V from the USB, but requires a min of 7V when using an external power supply?

The design assumes USB provides a regulated 5v so no further regulation is necessary. The power connecter is meant to accept a wider range of voltage and regulate it to 5v, and the kind of regulators used on the Arduino board need that much higher voltage to provide regulation. If you already have a regulated +5v source you can supply it to the 5v pin. You'll bypass the on-board regulator this way, so just know that it will then be up to you to provide clean power.

Brilliant answer without getting into technical details that can confuse members that are not experienced in electronics.

Above is an AA Battery voltage curve. Many people assume that 5* 1.5V AA batterys would be enough to power the Arduino. As you can see the 1.5 is the maximum voltage and it quickly drops. Different brands have different values and sometimes this can drop below the value of the voltage regulator input. I usually tend to aim between 7 and 9 Volts for  running from batteries, ie the nominal voltage of the batteries, eg 6 x 1.5V = 9V.
For wall socket charges, Buy a cheap one and hook it up to a volt meter, Many that say 5V actually have a range of values. Raspberry Pi users often have problems with power caused by manufacturers saying its 5v and it actually delivering something like 4.85 and fluctuating beacuse of the power demand of the pi

If you want to run from batteries, using the built-in voltage regulator is a really bad idea. Best case you are dropping 2.5V when the batteries are fresh - at 0.5A this is 1.25W wasted. The regulator will start to drop out at 6V, which is 1.2V per battery. This isn't very far into the discharge at all. Bypass the regulator and design the system to deal with varying voltage, or use a good boost converter.

I've edited your text to clarify that you mean to aim for a nominal* voltage between 7 and 9V. I assume thats what you meant?

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Can Arduino Mega2560 Use this 24VDC Relay?
Can a Arduino MEGA 2560 R3 provide enough current out of its pin to activate the Songle srd-24vdc-sl-c relay? Will powering the Arduino with an external power supply help?

Please avoid proving links (for the datasheet) that will require people to download and run an executable for viewing, it's the open door for virus and spams! I have found the same datasheet as PDF here: http://www.datasheet4u.com/download_new.php?id=720559

possible duplicate of How can higher current devices (motors, solenoids, lights, etc.) be controlled by an Arduino?

I don't consider this question a duplicate as the problem here is voltage-related in fact. However, the solutions may be similar.

As I know there is a 5Vdc one from the same manufacturer....

The 5V relay is a better/simpler option, but still requires an extra transistor (and flyback diode) to switch the relay current.

This relay cannot be directly commanded by any Arduino because its coil require 24V voltage to be able to switch the contact; Arduino Mega pins output voltage is 5V.
Regarding current, the relay coil needs 15mA ("high sensitivity" model) or 18.7mA (standard model), that would be OK for an Arduino Mega pin (max current = 40mA).
Anyway, you would have to add some circuit to adapt voltage between the Arduino pin and the relay. For this, first of all you will need to get a second power supply (in addition to the Arduino 5V supply used for Arduino) that can supply 24V.
Then you could use a MOSFET transistor between the Arduino pin and the relay. A MOSFET is often used in so-called Solid State Relay (SSR) because it can almost do the same as a coil relay but is 100% electronic-based (no moving parts); however, contrarily to a coil relay, it does not provide galvanic isolation between the input and the output circuits.
You can check out this question to find out further information on MOSFET.
Personnally, I would rather replace that relay with a 5V relay model, as that would make the circuit simpler, and would remove the need for a second power supply.

No, a MOSFET is never called an SSR, these are entirely different devices. A MOSFET has no galvanic separation between input and "output".

Well according to wikipedia (http://en.wikipedia.org/wiki/Solid-state_relay), it's not obvious an SSR has to provide galvanic separation. Also, it mentions a "A SSR based on a single MOSFET, ..., works well for DC loads.". I think we might argue about it, but I admit that provided SSR examples don't look like MOSFET :-) I'll update my answer.

I had a chat at EE.SE and apparently a single MOSFET called SSR is uncommon, but it does sometimes appear in literature.


text:
Is it possible to run 2 functions, that communicate with 2 different serial devices, in parallel using FreeRtos library?
This might seem like a very broad question but that's what i want it to be for multiple ways of implementation.
I've an Arduino UNO communicating with 2 Serial devices interfaced using SoftwareSerial flawlessly. I've used [SS_Object].listen() function to switch between the two. Right now, the entire code works sequentially meaning that, once it's work with the 1st Serial device is done, only then it will switch to the 2nd Serial device and work with it. Can i communicate with the 2 in parallel (Multitasking) using FreeRtos? I've heard that the scheduler switches between tasks when it encounters a delay. So may be a small useless delay is required, only for the scheduler, to switch between the two. May be! or May be things will be better if i use more advanced Arduino like Mega or Due.
Thanks for taking your time to read this. Please answer the question the way you've understood it as i am sure different people with different experiences will interpret this differently.
Thanks in advance!

You really should pick a chip with multiple hardware UARTs for that.

Yep. that's what i thought. Thanks! @Stratton

It is unlikely that FreeRTOS will allow you to do that. SoftwareSerial uses busy loops with interrupts disabled, which means it cannot be interrupted or preempted by the RTOS (or by anything for that matter).
If you want two serial connections in parallel, at least one of them should be done in hardware.


text:
Servo not moving with PIR motion sensor
I am working on this code to turn a servo when the PIR motion sensor detects no motion, but it is not working.
Some symptoms include:

Servo is turning extremely slowly
PIR is not turning the servo
Servo is turning to incorrect angles

I have tried test programs, and when I type in the serial monitor, the servo turns (slowly and inaccurately) (I coded the serial monitor to do this). I have input from the PIR sensor but it is constantly high, even after waiting 2 minutes for it to initialize. My code and schematic are shown below.

My code:
#include <Servo.h>
Servo servo;

void setup() {
  // put your setup code here, to run once:
  servo.attach(13);
  pinMode(2, INPUT);
  Serial.begin(9600);
  Serial.println("Please wait");
  delay(60000);
}

void ifMos() {
  if (digitalRead(2) == HIGH) {
    int USER = 270;
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  int USER = Serial.parseInt();
  servo.write(USER);
  Serial.println(USER);
  ifMos();
  delay(10000);
}

firget about the servo for now ... write the simplest code that lights an LED when motion is detected

firget about the servo for now ... write the simplest code that lights an LED when motion is detected –
-jsotola

It worked! Thank you so much.
All I had to do was add the servo library, write to the servo and upload it. Only 21 lines of code! Final code:
#include <Servo.h>
Servo servo;

void setup() {
  // put your setup code here, to run once:
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  servo.attach(13);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(2) == HIGH) {
    digitalWrite(3, HIGH);
    servo.write(270);
  }
  else {
    digitalWrite(3, LOW);
    servo.write(0);
  }
}

Thank you to everyone. This was my first time posting on stack exchange, and it was a huge success. Thank you again!


text:
Stepper motor and blink LED
I connected a LED stick to a stepper motor. Is it possible to blink the LED without stopping the motor rotation?
I am using SparkFun RedBoard Plus, Qwiic LED Stick - APA102C, Adafruit Stepper motor - NEMA-17 size - 200 steps/rev and Adafruit Motor Shield V2
Thanks
Script:
#include <Adafruit_MotorShield.h>
#include <Wire.h>
#include "Qwiic_LED_Stick.h"

LED LEDStick;
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);

void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial);
  Serial.println("Stepper test!");

  if (!AFMS.begin()) {
    // if (!AFMS.begin(1000)) {
    Serial.println("Could not find Motor Shield. Check wiring.");
    while (1);
  }
  Serial.println("Motor Shield found.");
  myMotor->setSpeed(25);  // 25 rpm

  if (LEDStick.begin() == false) {
    Serial.println("Qwiic LED Stick failed to begin. Please check wiring and try again!");
    while (1);
  }
  Serial.println("Qwiic LED Stick ready!");
}

void loop() {
  Serial.println("Single coil steps");
  myMotor->step(200, FORWARD, SINGLE);

  LEDStick.setLEDColor(10, 10, 10);
  delay(1000);
  LEDStick.LEDOff();
  delay(1000);
}

Have you seen this tutorial? https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay

delay(1000); stops everything for one second

try using onestep instead of step

Often, the solution to most simultaneous software delay problems is a state machine. Generally, a state machine is an infinite loop with no or few delays.  The state machine's job is to keep track of all the possible state the software is to control.
In this case we might try to implement:

LED on & motor active.
LED off & motor active.
LED on & motor is not active.
LED off & motor is not active.

The library Adafruit_StepperMotor you have chosen might be blocking.  This text from the Arduino reference step library admits this similar function is blocking:

This function is blocking; that is, it will wait until the motor has finished moving to pass control to the next line in your sketch.

If so, and the call to step() blocks the LED action for longer then is tolerable, consider calling step() with fewer step such that the blocking delay is tolerable.  For example, 100 steps are desired, consider calling step 10 times only advancing the motor 10 steps each time.
Back to the state machine.  To keep track of the above 4 state you need 2 flags.  An LED flag and a Motor flag.  Control the LED flag using mills() not delay().
mills():

Returns the number of milliseconds passed since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.

Consider writing the state machine code to immediately turn the LED on and save the current value returned from mills().  Each subsequent time through the state machine check if mills() returns a value 1000 more than the value saved (do consider that mills() will eventually overflow and start over at zero).  When it does toggle the LED, save the new mills() returned value and start checking each subsequent time through the state machine.
As we are running the state machine over and over again as fast as the processor can manage, we can also test an externally set flag to run the motor.  We need to determine if the call to step() is blocking.  If it is we need to determine the maximum number of steps / delay tolerable by the LED feature.  If we discover this is, say, 10 step, we need to devise code to divide the desired number of steps into individual calls of 10 or less steps. If this approach is desired, control the state machine's motor flag by activating it when the number of steps is > 0.  Subtracting 10 from the number of steps every iteration through the state machine.  And setting the state machine's motor flag to deactivate when steps is = 0.


text:
Using ESP32 GPIO, Serial.printf(...) prints weird characters when input is larger than 12 characters
Learning C with the Freenove WSP32-WROVER starter kit and there's an issue I cannot find an answer to. Using the provided code to input some data with UART, it would seem to have a strange behavior whenever I input string that is larger than 12 characters. Under 12, everything is fine.
/**********************************************************************
  Filename    : SerialRW
  Description : Use UART read and write data between ESP32 and PC.
  Auther      : www.freenove.com
  Modification: 2020/07/11
**********************************************************************/
String inputString = "";      //a String to hold incoming data
bool stringComplete = false;  // whether the string is complete

void setup() {
  Serial.begin(9600);
  Serial.println(String("\nESP32 initialization completed!\n")
                + String("Please input some characters,\n")
                + String("select \"Newline\" below and click send button. \n"));
}

void loop() {
  if (Serial.available()) {         // judge whether data has been received
    char inChar = Serial.read();         // read one character
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
  if (stringComplete) {
    Serial.printf("inputString: %s \n", inputString);
    inputString = "";
    stringComplete = false;
  }
}

The output of any larger than 12 characters string is sometimes a little bit different, but always seems to follow a similar pattern. For any 13 characters long string, I get :

⸮⸮?

The ouput changes if I add characters, for example 20 characters is this :

D⸮⸮?

I assume the unprintable character is a new line.
The baud rate is set at the same value both in the code and in the serial monitor and I get the same results if I change the baud rate.
Any explanation regarding this behaviour and how to avoid it would be most welcomed.

Change:
Serial.printf("inputString: %s \n", inputString);

to:
Serial.printf("inputString: %s \n", inputString.c_str());

%s expects a const char * which is not what inputString yields.
What you're seeing in the difference between strings larger and smaller than 12 characters is down to whether or not small string optimization is in use and how structures are passed in the ESP32's calling convention.

Thanks a lot, this did solve the issue <3

As a rule, it is better to use char array thhen string. While string might be smaller then your maximum size of array, its variable nature makes it very hard for memory allocation to guess a right size.
While it is not a problem in a simple program like this when you get to larger projects where your functions are used within libraries, variable nature of string makes memory alocation within gaps in memory fragmentation too unreliable. (I have solved many crashes simply by changing strings to char arrays)Its well worth getting into a habit of char arrays rather then strings

I have tried to remove "in  fragmentation" unfortunately 5 minute edit rule for comment is too low for dissgraphic person"


text:
Adding Serial2 ends up blocking nano rp2040
Background Info
I want to have two serials in my arduino nano rp2040 connect, in order to be able to communicate using the following scheme. (μC is a microcontroller).
μC1 <--> μC2 <--> μC3<-->....<-->μCn
So i tried changing the core and upload a sketch to test if it is possible. However, i ended up blocking the arduino, and

it disappears from the COM port,
the arduino red light is constantly blinking,
the serial port of my computer freezes,
the whole arduino application is not responding.
The arduino disappears from the device manager and it ends up as a USB device.

I want to understand what causes it, in order to avoid doing it in the future.
I usually reset the board, and then i upload a Blink.ino.elf.uf2 i have previously compiled. The application gets unstuck, the arduino runs the blink programm, and it appears at COM4.
Changes i made to the core:
1st change
In
C:\Users\<user>\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.2.0\variants\NANO_RP2040_CONNECT

i changed the defines.txt and i changed the line:
-DDEVICE_SERIAL=1

to
-DDEVICE_SERIAL=2

2nd change
In the same folder, i changed pins_arduino.h in the following way:
// Serial
#define PIN_SERIAL_RX (0ul)
#define PIN_SERIAL_TX (1ul)

#define PIN_SERIAL2_RX (3ul)
#define PIN_SERIAL2_TX (4ul)

and
#define SERIAL_HOWMANY      2
#define SERIAL1_TX          (digitalPinToPinName(PIN_SERIAL_TX))
#define SERIAL1_RX          (digitalPinToPinName(PIN_SERIAL_RX))
#define SERIAL2_TX          (digitalPinToPinName(PIN_SERIAL2_TX))
#define SERIAL2_RX          (digitalPinToPinName(PIN_SERIAL2_RX))

My programm:
#define led LED_BUILTIN
char c;

void setup() {
  pinMode(led, OUTPUT);
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial);
  digitalWrite(led,HIGH);
  delay(1000);
  digitalWrite(led,LOW);

  Serial2.begin(9600);
  while(!Serial2);
  digitalWrite(led,HIGH);
  delay(1000);
  digitalWrite(led,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available() ){
    c = Serial.read();
    if (c != '\n'){
      Serial.print("Master wrote : ");
      Serial.println(c);
      Serial2.print(c);
    }
  }

  if (Serial2.available() ){
    c = Serial2.read();
    if (c != '\n'){
      Serial.print("Slave wrote : ");
      Serial.println(c);
    }
  }
delay(1000);
}

Edit I uploaded the same sketch with earlephilhower's core (you can find it here ) and the IDE showed this message:
Resetting COM4
Converting to uf2, output size: 136192, start address: 0x2000
Flashing D: (RPI-RP2)
Wrote 136192 bytes to D:/NEW.UF2
Board at COM4 is not available
Board at COM4 is not available

The last 2 messages were from me trying to open serial monitor. So i think the sketch has the problem, and not the modiffications i made to the mbed os core.

RP2040 has 2 UART peripherals. the datasheet has which pin can be used with which UART and in what direction. note that the datasheet has RP2040 pin numbering not the Nano pin numbering

I even used the phillower core without modifying anything, and i still faced the same problem. Also, the pinout or arduino rp2040 connect has one uart, so i do not know how to access the second uart that the rp2040 CPU has. From a link you sent me to another question, i understood that the second uart may not be accesible.


text:
Arduino cannot connect to port (arduino nano rp2040)
My arduino cannot connect to any port of my computer. So far i tried the following, without any luck:

Using another arduino to check the usb, and it worked. So no problem with usb cable.
Resetting the arduino (double tap the reset-button)
Inserting deleting and updating the drivers from the device manager
Deleting the drivers, and then inserting the arduino while pressing the reset button.
Connecting the arduino to a different pc and it still doesn't work.
I followed everything listed here. (Resetting, uploading a uf2 blink file). I even compiled my blink uf2 file, with the newest version of mbed os for rp2040. And i even tried with older versions of the mbed os.
I tried uploading a flash_nuke.uf2 file

Is there something else i can do? Or is it permenantly damaged?
When i connect to to the computer, this comes up:

In my device manager, i see the following:

Also, in the IDE, i cannot select any port.

Extra info : I was trying to use Serial2 from another arduino to this, so i was changing some jumper wires while they were powered. So it is possible it is damaged.  I also tried uploading some sketches to use a second serial with some modifications to the core of the OS. The changes were on the spirit of this post, but not necessairily the same.

the upload copies the bin to that drive. did you try the Upload? and double reset should activate the bootloader which should create a port.

I tried both double pressing the reset botton (a red light is not blinking, if it should) and uploading blink.ino. Nothing worked

please post the message text, not a picture of message text

The RP2040 doesn't have a USB serial port unless you program it to have one.
Unlike "traditional" Arduinos the RP2040 uses the UF2 bootloader system. This involes the RP2040 pretending to be a USB flash drive, and then uploading code is as simple as copying the .UF2 file to that drive.
If you are seeing that drive then the chip is ready and waiting for you to upload code. You don't need to select a port in the IDE to upload the code since the port is not used for uploading (only for resetting the board to enter the bootloader mode, which you don't need since you are already in bootloader mode).
If the IDE is struggling to find the virtual flash drive then just find the .UF2 file that the IDE created and manually drag and drop it to that drive and it will program the code onto the drive for you.

I upload the Blink.ino.elf.uf2 from arduino help (https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-01-technical-reference?_gl=1iu9w36_gaODM4NTQ0ODcuMTY1Nzc4MTAyNA.._ga_NEXN8H46L5*MTY2MTQxODM1NC41OS4xLjE2NjE0MTg0ODIuNjAuMC4w#board-not-detected), and still nothing happens. The arduino does not blink as it should, nor is there a COM port in the ide and device manager. Also, how can i manually create .UF2 files from the ide? (I got just a bin file from the option " Export compiled binary")

You create .UF2 files when you hit the compile ("verify") button in the IDE. You just have to find them - it's not always obvious. Check the verbose output for hints. Do you have a link between REC and GND to always force the bootloader? If so, remove it.

It seems the IDE has a problem creating uf2 files. Actually, i have 2 arduino rp2040. One that works and one that doesn't. If I connect the problematic one, or i compile the programm without any rp connected,  the IDE doesn't create a UF2 file. If i have the working one connected, it still doesn't create uf2 files until i press upload from the IDE. I tried using that uf2 file, but still the problem wasn't fixed.

I had the same issue, even after following all the possible RESET/HARD RESET/BOOTLOADER procedures. I have found a solution for this board to regularly work under Windows, and this involves reintalling it as a DIFFERENT board.
What I became aware of, is that my Win OS (8.1) was not properly installing the Arduino Nano RP2024 driver, for reasons unknown. So, I was first trying to manually reinstall the driver after searching for the proper .inf driver file, which is located in "C:\Users<USERNAME>\AppData\Local\Arduino15\packages\arduino\hardware\mbed_nano\3.2.0\drivers". Unfortunately this come up with the same issue.
So I went for a "fake" manual install of the device, by selecting "Manually choose from a list of device drivers in your PC".  I then selected "Ports (COM and LPT)", because this is how you would like your board to behave under your OS. THIS STEP IS ESSENTIAL. As far I could see, if you simply chose the Nano RP2024 .inf file located in the above folder, the boards will continue in not showing up in the COM ports list.
After this step, I went through a list of vendors, finding several Arduino-like entries. Among these, I selected "Arduino SA", which ws containing "Arduino Nano 33 BLE" as a device, which I found to be a working option. The board is now regulary showing up into the IDE, even after several connect/disconnect cycles, and also the serial monitor works.
NOTE: in case you select a different working mode of the board (e.g. HID peripheral such as mouse, keyboard or similar) you may have to reinstall it following the procedure above.
Hope this helps!
Cheers
Attila


text:
Controlling ESC with Arduino
I want to control these motors: hexTronik DT750 Brushless Outrunner 750kv with this battery: Turnigy 2200mAh 3S 25C Lipo Pack and these ESCs: TURNIGY Plush 18amp Speed Controller.
I am new to this field of driving brush-less motors. Can someone tell me if I need anything else? Will this set-up work without anything getting destroyed?

This looks like shopping advice, which is off-topic for ee.se. See the [help] for advice. "Can someone tell me if I need anything else?" What do you actually want to do? The motor specification (spec) describes the max current 18A for a specific propeller, but only repeats the same value for its maximum current, which seems an odd coincidence. The ESC has a maximum continuous current of 18A, with a burst of 22A, but the specification doesn't say the burst duration. So it looks okay for some uses, but might not be for others.

I 've been working on an autonomous arduino quadcopter for about 7 months now and I have a few tips for you.
1) your setup seems fine as long as your motors aren't going to draw more amps than your ESC can supply, but It is always a good idea to buy ESCs with a higher "max amps" than your motors draws. I would choose 25 amp max ESCs or higher.
2) In order to control the motors via PWM, I use the Servo library because you get a resolution from 700-2000 as opposed to "analogWrite" which gives a default resolution of 0-255.
3) your ESC probably has a minimum pulse width value before it will start. I would recommend writing a program that gives you the ability to plug in values from 700-2000, and use the program to slowlly find that arming pulse width value. Mine is 1110 for reference.
If you have anymore questions, I will glady answer them.
May I ask, what is your project?

Thanks for the feedback. I too am working on a quad. I essentially started this project to learn as much as I can about electronics, since I have just gotten into the hobby.

Nice, I have been learning a lot about quads and electronics. Message me with a question when you have one. I had a successful test flight 2 weeks ago so I can help you up to that point. I'm now on altitude hold.

@Trexter you are awesome. So glad to see a community member be so helpful, it's what makes these SE sites great. I didn't see any blog information on your profile. Do you have any examples of your autonomous arduino work you can show off?


text:
Balancing pendulum using PID

Dear all, referring to the video at here on how to make a PID balancing pendulum as shown in the picture and the author also provided the arduino code in the video description. May I ask whether this arduino code can be used on my MPU6050 gyroscope without any modifications because the author in the video does not provide the model of the gyroscope used. I have also searched countless of arduino code on web on balancing pendulum using propeller PID with a DC brushless motor (not 3 phase) and MPU6050 gyrocope, but couldn't find any and I hope someone could show me some examples code.
Thank you and have a nice day!!
// Chuong trinh dieu khien cân bang thanh ngang Nguyen Duc Sang 24/05/2018
//---------------------------------------------------------------

//875=0
//530=90 do
#define SENSOR A1
#define CONTROL 6
#define dongco 7

   void setup() {
       Serial.begin(9600);
       pinMode(SENSOR,INPUT);
       pinMode(CONTROL,OUTPUT);
       pinMode(dongco,OUTPUT);
   }
   double error = 0;
   double realAngle;
   double lastrealAngle;
   double
     kP = 1,
     kI = 0.005,
     kD = 0;
   double
     P = 0,
     I = 0,
     D = 0;
   double PID;
   double setPoint = 90;
   int controlPwm = 85;
   long lastProcess = 0;
  void loop(){
     realAngle = map(analogRead(SENSOR), 1023, 0, -39.73, 229.47);
     //Serial.println(analogRead(SENSOR));
     //Serial.println('gia tri goc realAngle la');
     Serial.println(realAngle);
     Serial.println(setPoint);
    //PID
    error = setPoint - realAngle;
    //thoi gian lay mau
    float deltaTime = (millis() - lastProcess)/100.0;
    lastProcess = millis();
    // P
    P = error * kP;
    // I
    I += (error * kI) * deltaTime;
    // D
    D = (lastrealAngle-realAngle) * kD * deltaTime;
    lastrealAngle = realAngle;
   // Sub pid
  PID = P + I + D;
  if (PID>255){
   PID=255;}

  controlPwm = (PID + 80);

    analogWrite(CONTROL,controlPwm );

  }

Is that all your code?

This cannot be all of your code. Nearly everything important is missing. I guess you had a copy and paste error. But I guess the answer is no. It seems the code is using an analog sensor. From the video I would guess it has a potentiometer at the axle of the arm. So it doesn't use a gyroscope. For the MPU6050 you would see either a corresponding library being imported or the Wire or SPI library being used (since the MPU communicates through I2C or SPI). I can write an answer once you have included the complete code in your question

@chrisl, hi sir, these codes are from the video dessciption. May I ask if there are any code that do balancing pendulum using propeller PID with a DC brushless motor (not 3 phase) and MPU6050 gyrocope ? Have a nice day :)

Either way you have to include the full code in the question, because questions on this site should be self contained. So please copy the full code into the question

@chrisl, done :),  May I ask if there are any code that do balancing pendulum using propeller PID with a DC brushless motor (not 3 phase) and MPU6050 gyrocope ?

The shown code does not use the MPU6050. Instead it uses a sensor with an analog output signal. From the image and the video I suspect, that this sensor is a potentiometer attached to the axle of the arm. So the analog value basically gives you a measure of the angle.

have also searched countless of arduino code on web on balancing pendulum using propeller PID with a DC brushless motor (not 3 phase) and MPU6050 gyrocope, but couldn't find any

That's not really surprising to me, since that is a very specific search request. That assumes that someone did exactly what you want to do and also described it with the same words. Finding a ready-to-use code that way is highly unlikely and I don't have such a code either.
What to do now? You will have to develop the code yourself. First you should divide up your project in individual parts, like: Getting readings from the MPU6050, calculating a stable angle value from the readings (by combining gyro and accelerometer values), driving the DC brushless motor and controlling its speed, implementing a PID feedback loop.
When you are able to implement each individual part by itself you can put them all together to make your project. Each individual part can be researched way easier, because there are many people, who have done these things in their own projects. Also try searching for Arduino libraries for these parts. For example: There are libraries for using the MPU6050, which will handle all the communication to the sensor for you. A good way to find libraries is search for "Arduino library MPU6050" (replace "MPU6050" by whatever single thing you wanna implement, like PID or similar). And such libraries are often hosted at Github, so it is often also good to search for something like "github arduino MPU6050". Try keeping your search request short. Look at the results and assess, if the found libraries are fitting for your situation.
And as help and inspiration you can search for similar projects. A quick search for "Arduino mpu6050 balancing robot" did show promising results and a balancing robot is very similar to your project.


text:
Can't convert string to UTF-16LE for MD5 calculation on an Arduino
TLDR
I need to convert text from a website into UTF-16LE format so that I can get the proper MD5 checksum but can't figure out how to go about doing that. This is all happening on an Arduino to log in to a router.
Background
I want to read values from a smart home device connected to a Fritz!Box router using an Arduino with an ethernet connection. The router has an open API and I'm using HTTP (EN|DE) to get the values. C++ programming is not my strong point.
I have been basing my attempts on BASH and javascript examples. For MD5 calculation I'm using tzikis' ArduinoMD5 library.
Steps
Based on the manual, you need to do the following:

Contact the router to get a challenge string (router sends XML)
Generate a response by calculating an MD5 checksum using the challenge string and password: <challenge>-<password>
Send the response, <challenge>-<response>, via POST
Receive the XLM answer from the router containing the SID
Use SID to request data or control a smart home device

I'm stuck on step 2. I have the challenge but cannot calculate the correct checksum.
The manual states:

The MD5 hash is generated from the byte sequence of the UTF-16LE
coding of this string (without BOM and without terminating 0 bytes).

Attempts
So far I can request the challenge: 70067288 for example. The reponse appears to always be alphanumeric. My password is also alphanumeric.
unsigned char* hash2 = MD5::make_hash("1234567z-äbc");
char *md5str2 = MD5::make_digest(hash2, 16);
free(hash2);
Serial.print("MD5: ");
Serial.println(md5str2);

This was my attempt at confirmation. The manual gave 1234567z as a challenge example with äbc (the a in the example does indeed have umlauts) as a password. The response shown for this example was 1234567z-9e224a41eeefa284df7bb0f26c2913e2 but my checksum from the above code was 935fe44e659beb5a3bb7a4564fba0513.
I tried "manually" generating UTF-16LE and calculating the MD5 but that didn't work either.
byte rawTest[] = {0x3100, 0x3200, 0x3300, 0x3400, 0x3500, 0x3600, 0x3700, 0x7a00, 0x2d00, 0xe400, 0x6200, 0x6300};
char buffer[12] = {};
unsigned char* hash2 = MD5::make_hash(&buffer[0]);
char *md5str2 = MD5::make_digest(hash2, 16);
free(hash2);
Serial.print("MD5: ");
Serial.println(md5str2);

It gave me d41d8cd98f00b204e9800998ecf8427e.
I am not entirely sure the example given was correctly calculated. Using their example in the API documentation with BASH code from the site mentioned above, I get a different answer: 1234567z-bb6e5b7c7d4d485590f4e084ad3da989.
#!/bin/bash
# -----------
# definitions
# -----------
FBF="http://192.168.178.1/"
USER="root"
PASS="äbc"
AIN="AINOFYOURFRITZDECTDEVICE"
# ---------------
# fetch challenge
# ---------------
CHALLENGE="1234567z"
# -----
# login
# -----
MD5=$(echo -n ${CHALLENGE}"-"${PASS} | iconv -f ISO8859-1 -t UTF-16LE | md5sum -b | awk '{print substr($0,1,32)}')
RESPONSE="${CHALLENGE}-${MD5}"
echo $RESPONSE

Any help getting it working is greatly appreciatet.

Working Example (with caveats)
Requirements:

Password using only characters found in ASCII
Password at least 17 characters long

The password must use only ASCII characters due to the simple way it's being converted to UTF-16LE.
I can't explain why the password must be at least 17 characters long though. My code checks the length of the actual password programmatically.
With a password at least 17 characters long I get something like this:

Challenge: 6c607ee5
Challenge Pass (26): 6c607ee5-01234567890123456
Challenge Pass Preallocation Length: 26
MD5 (UTF-16LE): 3b26241ae4aab8eaf71d5c1599932178

Any password short and I get something like this:

Challenge: 621611e1
Challenge Pass (26): 621611e1-0123456789012345�
Challenge Pass Preallocation Length: 25
MD5 (UTF-16LE): 30a163ab8a267adfbb524b2b7412e81b

Please excuse any poor coding, C++ is not my strongpoint.
void fritzboxSID() {
  EthernetClient fritzBox;
  const char* pass = "01234567890123456";  // 17 ASCII character minimum
  const char* user = "fritz3456";  // Account on router, randomly generated or user created
  const size_t passLength = strlen(pass);  // Password length
  char c;
  uint8_t xml = 0;
  char challenge[9] = {0};  // Challenge
  char challengePass[8 + 1 + passLength];  // challenge-password
  uint8_t challengeCount = 0;

  if (fritzBox.connect("192.168.200.1", 80)) {
    // Send login request
    fritzBox.println("GET /login_sid.lua HTTP/1.1");
    fritzBox.println("Host: 192.168.200.1");
    fritzBox.println("Connection: close");
    fritzBox.println();

    while (fritzBox.connected()) {
      while (fritzBox.available()) {
        c = fritzBox.read();  // Read a single character from the router response
        if (c == '>') {
          xml++;
        }
        if (xml == 5) {
            // Challenge starts after the fifth >
            if (challengeCount > 0 & challengeCount < 9) {
                // Save the challenge, character by character
                challenge[challengeCount-1] = c;
                challengePass[challengeCount-1] = c;
            }
            challengeCount++;
        }
        Serial.print(c);  // Print HTTP response
      }
    }
    challengePass[8] = '-';
    for (size_t i = 0;i < passLength; i++){
      // Copy password into the combined challenge-password string
      challengePass[i+9] = pass[i];
    }

    // Show challenge and pass, checking lengths
    //      If the strlen(challengePass) doesn't equal the preallocation length then the MD5 will be incorrect
    Serial.println("");
    Serial.print("Challenge: ");
    Serial.println(challenge);
    Serial.print("Challenge Pass (");
    Serial.print(strlen(challengePass));
    Serial.print("): ");
    Serial.println(challengePass);
    Serial.print("Challenge Pass Preallocation Length: ");
    Serial.println(8 + 1 + passLength);

    // Convert to UTF-16LE (only works for standard ASCII characters)
    const size_t length = strlen(challengePass);
    char buffer[2*length];
    for (size_t i = 0; i < length; i++) {
      buffer[2*i] = challengePass[i];
      buffer[2*i+1] = 0;
    }

    // Generate MD5
    unsigned char* hash = MD5::make_hash(buffer, 2*length);
    char *md5str = MD5::make_digest(hash, 16);
    free(hash);
    Serial.print("MD5 (UTF-16LE): ");
    Serial.println(md5str);
  } else {
    Serial.println("Cannot connect to 192.168.200.1");
  }
}

If it helps, the response from the router for the initial login request is this:
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: close
Content-Type: text/xml
Date: Fri, 16 Sep 2022 08:21:27 GMT
Expires: -1
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Security-Policy: default-src 'none'; connect-src 'self'; font-src 'self'; frame-src https://service.avm.de https://help.avm.de https://www.avm.de https://avm.de https://assets.avm.de https://clickonce.avm.de http://clickonce.avm.de http://download.avm.de https://download.avm.de 'self'; img-src 'self' https://tv.avm.de https://help.avm.de/images/ http://help.avm.de/images/ data:; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; media-src 'self'

<?xml version="1.0" encoding="utf-8"?><SessionInfo><SID>0000000000000000</SID><Challenge>621611e1</Challenge><BlockTime>0</BlockTime><Rights></Rights><Users><User last="1">fritz3456</User><User>UserName</User></Users></SessionInfo>

The iconv option -f ISO8859-1 looks suspicious. Are you sure you are using this old, legacy character set? Your bash script gives me the expected output if I remove that option. 2. Can you manage to have an ASCII-only password? If so, the translation to UTF16LE would be practically trivial.

Good find. My password is ASCII only. The example provided in the documentation was not. How would you convert it to UTF-16LE in Arduino C++ in that case? I still need to programmatically convert the challenge as well. Thanks for the quick answer.

byte rawTest[] = {0x3100, 0x3200,..... this is not doing what you think it does. I'm assuming you weren't looking for a creative way to fill your array with 0x00 values.  Probably you meant 0x31, 0x00, 0x32, 0x00,.....

Good to know. If I ever get around to expanding the code from ASCII passwords I'll try that out. Let's see how hard it is to complete the login process and get data first.

You have to convert the string "<challenge>-<password>" to
UTF-16LE. If the whole string is plain ASCII, the conversion is trivial:
you just have to add a zero byte after each ASCII byte.
// ASCII string to be hashed.
const char* text = "1234567z-abc";  // umlaut removed

// Convert to UTF-16LE.
const size_t length = strlen(text);
char buffer[2*length];
for (size_t i = 0; i < length; i++) {
    buffer[2*i] = text[i];
    buffer[2*i+1] = 0;
}

// Compute and print the hash.
unsigned char* hash2 = MD5::make_hash(buffer, 2*length);
char *md5str2 = MD5::make_digest(hash2, 16);
free(hash2);
Serial.print("MD5: ");
Serial.println(md5str2);

Note that I use the two-parameter version of MD5::make_hash() in order
to pass the length of the buffer. The one parameter version of this
method would stop at the first zero byte.

Edit: Regarding your extended question (the new section “Working
Example”), this is a problem completely unrelated to the previous one.
It is about string termination.
In C and C++, strings are arrays of characters terminated with a NUL
ASCII character (numeric value zero). The terminating NUL is not part of
the string per se, but it should be stored in the array holding the
string. String literals are interpreted by the compiler as
NUL-terminated arrays of characters. Every function that expects a
string as an input expects it to be NUL-terminated.
In this particular instance, you failed to NUL-terminate
challengePass. When this array is given to strelen(), this function
scans the memory until it finds a zero byte. If that zero byte happens
to be right after the end of the array, your code will work as expected.
Otherwise, any non-zero byte coming after challengePass in memory will
be interpreted as being part of the string. The program behavior is
unpredictable, because you do not know what will be stored in memory
right after challengePass.
The solution is to NUL-terminate the string. Start by allocating one
more byte:
char challengePass[8 + 1 + passLength + 1];  // challenge-password

Then, right after copying the password, add a zero byte to terminate the
string:
challengePass[8 + 1 + passLength] = '\0';  // terminate the string

Note that '\0' means “the character with numeric value zero”.
Alternatively, you can terminate the string right after adding the dash,
then use strcat() to concatenate the password. strcat() will take
care of terminating the string:
challengePass[8] = '-';
challengePass[9] = '\0';  // temporarily terminate the string
strcat(challengePass, pass);  // append password

That actually works, but for some reason I generate text it fails. If I then manually type the new challenge and same password into const char* text... it gives the correct MD5.
C++ character/string operations are profoundly confusing.

@Jeremy: What do you mean by “I generate text it fails”? In what manner does it fail? I should not matter whether the text is typed in the source or generated programmatically.

I tried posting code in a comment but it was a complete mess.
const char* pass = "myPassword";
const size_t passLength = strlen(pass);
char challenge[9] = {0};  // Challenge
char challengePass[8 + 1 + passLength];  // challenge-password

Using the ethernet module I then read in the XML from the router, copying it character by character to challenge and challengePass. After that I tried strcat to build the challenge-password string to feed into the MD5 function. The MD5 was always wrong though. Is it because strcat adds a null-terminator to the end?

@Jeremy: The question about string concatenation in your last comment is: 1. Unrelated to the current question, which is about ASCII → UTF16-LE conversion. 2. Impossible to answer without seeing how you are actually trying to concatenate the strings.

This entire question is in the context of assembling a string to not just generate any MD5 checksum but the correct MD5 checksum. The particulars are very important. I understand this is Stack Exchange and tangential questions should be asked on their own. Now to see if I can figure out the other steps required. Thanks again for the help. If I, or someone else, figures out the password length caveat I'll update the solution.

@Jeremy: See extended answer.

I don't know if it's worth changing anything in the answer for this, but it may be good to know that you seemingly have the option of using a lower level set of features (MD5_CTX, MD5Init, MD5Update, MD5Final) that provide for avoiding the temporary buffer, dynamic memory allocation, and concatenation. The various concatenations, including those of 0x00 being done to up convert ASCII to UTF-16LE, become separate calls to MD5Update.

Thanks for the tip. I'm slowly in the process of converting it all to useable functions. Once I get to optimization I'll give it a shot. No doubt there are plenty of ways to optimize my C++ code.


text:
Rising and falling edge on GPIO_STM32G4
I am working with STM32G491RE.I am giving pulse to GPIO pin from function generator. That pulse will be 2 msec on time and 8msec off time.I need to make flag high if the signal from function generator lost.
Can anyone suggest me how to do this?
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin==detect_Pin){
if(HAL_GPIO_ReadPin(detect_GPIO_Port,detect_Pin)==GPIO_PIN_SET){
 HAL_UART_Transmit(&huart2, (uint8_t *)"rising:",7, HAL_MAX_DELAY);
 }
else if(HAL_GPIO_ReadPin(detect_GPIO_Port,detect_Pin)==GPIO_PIN_RESET){
 HAL_UART_Transmit(&huart2, (uint8_t *)"falling:",8, HAL_MAX_DELAY);
 }
else
{
 HAL_GPIO_WritePin(led_GPIO_Port,led_Pin,GPIO_PIN_SET);
}

I tried with EXTI interrupt but If input is there from generator its detecting both rising and falling edge and if there is no signal from generator I am not getting  in to else condition.

1.If I want to make flag high for no signal from function generator,above image offtime also it considering as no signal.
can anyone suggest how to do?
Thanks

I do not know how to use the HAL API you are using. I will instead
suggest an approach based on the Arduino API, which is more suitable for
this site.
Take note of the current time on every transition you detect. When the
time since the last detected transition is longer than a predefined
timeout, you know the pulse train has stopped:
const uint8_t pulse_pin = 2;
const uint32_t pulse_timeout = 10;  // milliseconds

volatile uint32_t last_input_change;  // last time we detected a change

void on_input_change()
{
    last_input_change = millis();
}

void setup() {
    Serial.begin(9600);
    attachInterrupt(digitalPinToInterrupt(pulse_pin),
            on_input_change, CHANGE);
}

void loop() {
    // Avoid a data race while reading last_input_change.
    noInterrupts();
    uint32_t last_input_change_copy = last_input_change;
    interrupts();

    if (millis() - last_input_change_copy >= pulse_timeout)
        Serial.println("The pulse train stopped.");
}

Note that, for this to work, your whole code should be non-blocking,
which is a good practice in any case.


text:
Ultrasonic Sensor scanning too often resulting in a whirring noise
I am using an HC-SRO4 ultrasonic sensor for a wall-avoidance, maze-solving robot. However, I have recently run into an issue where I am getting a whirring noise from the sensor because it is taking measurements way too often.
This is the code I have right now:
const int serialPeriod = 250;       // only print to the serial console every 1/4 second
unsigned long timeSerialDelay = 0;

const int loopPeriod = 20;          // a period of 20ms = a frequency of 50Hz
unsigned long timeLoopDelay   = 0;

// specify the trig & echo pins used for the ultrasonic sensors
const int ultrasonic2TrigPin = 8;
const int ultrasonic2EchoPin = 9;

int ultrasonic2Distance;
int ultrasonic2Duration;

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

    // ultrasonic sensor pin configurations
    pinMode(ultrasonic2TrigPin, OUTPUT);
    pinMode(ultrasonic2EchoPin, INPUT);
}

void loop()
{
    debugOutput(); // prints debugging messages to the serial console

    if(millis() - timeLoopDelay >= loopPeriod)
    {
        readUltrasonicSensors(); // read and store the measured distances

        timeLoopDelay = millis();
    }
}

void readUltrasonicSensors()
{
    // ultrasonic 2
    digitalWrite(ultrasonic2TrigPin, HIGH);
    delayMicroseconds(10);                  // must keep the trig pin high for at least 10us
    digitalWrite(ultrasonic2TrigPin, LOW);

    ultrasonic2Duration = pulseIn(ultrasonic2EchoPin, HIGH);
    ultrasonic2Distance = (ultrasonic2Duration/2)/29;
}

void debugOutput()
{
    Serial.print("timeSerialDelay: ");
    Serial.print(timeSerialDelay);
    Serial.println();

    if((millis() - timeSerialDelay) > serialPeriod)
    {
        Serial.print("ultrasonic2Distance: ");
        Serial.print(ultrasonic2Distance);
        Serial.print("cm: ");
        Serial.println();

        timeSerialDelay = millis();
    }
}

and my wiring:

Link to product
Does anyone know why the scanning is happening constantly? It should only be happening every 1/4 of a second, not constantly. The weird thing is that this wasn't happening earlier before I started using the cable.
I believe it has something to do with the 8.5" extension cable I have (needed because I can't mount three sensors, one facing to each side and one in front, on a single breadboard). This is because when I mounted the sensor directly onto the breadboard, the delay was correct and the whirring was not present. However, as I just mentioned, I need the extension cable to be able to have the three sensors.
Does anyone have a solution for this?
Thanks!

If loopPeriod = 20 then it should be sampling at 50Hz, like the comment says

Change loopPeriod to 250 for a quarter second sample rate

Okay, did that. It did slow down the rate, but I could still hear a faint clicking which got louder as it got closer to an object and it will pause if the value reaches 0cm. Why is this?

Most ultrasonic sensors emit a bit of sound in the audible spectrum. I have noticed this a lot in the Maxbotics EZ line.

So, it is just something I have to put up with? Okay. I suppose I can survive that. But why is the scanning pausing (and dropping to 1/4 second rates) when it reaches 0cm? Thanks for the quick response!

I guess. It is probably louder if it is closer because of the reflection of sound.

That would make sense. Again, why is the scanning pausing at 0cm and (if I keep it at 0cm) dropping to 1/4 second rates?

Probably because the sound is bouncing back too fast for the sensor to comprehend

Ah, that makes sense. Or, in the case that is looking at nothing the signal never returns. Anyways, thank you very much! I will mark that as answer as soon as I can :)

If you want to sample at 4Hz (4 times per second), you need to change your headers accordingly:
const int serialPeriod = 250;       // only print to the serial console every 1/4 second
unsigned long timeSerialDelay = 0;

const int loopPeriod = 250;          // a period of 250ms = a frequency of 4Hz
unsigned long timeLoopDelay   = 0;


text:
Arduino DUE Bossac Lockup after Ubuntu Upgrade
I already asked my question in the Arduino Forum here: https://forum.arduino.cc/index.php?topic=353846.0 but got no answer so far. Thus I hope here might be people who have a hint for me.
Since I introduced some Ubuntu patches I suspect these patches are to blame. But frankly I have no clue.
Here is what I got:
If I connect the programming port then Arduino IDE 1.6.5 properly recognizes it as the programming port. Thus I assume that the cable is properly plugged in and the Arduino powered. In addition I get
> lsusb
...
Bus 003 Device 019: ID 2341:003d Arduino SA
...

> dmesg
...
 2074.703747] usb 3-3: USB disconnect, device number 18
[ 2076.678150] usb 3-3: new full-speed USB device number 19 using xhci_hcd
[ 2076.696405] usb 3-3: New USB device found, idVendor=2341, idProduct=003d
[ 2076.696407] usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[ 2076.696409] usb 3-3: Product: Arduino Due Prog. Port
[ 2076.696409] usb 3-3: Manufacturer: Arduino (www.arduino.cc)
[ 2076.696410] usb 3-3: SerialNumber: 55437333537351F0F1D0
[ 2076.696501] usb 3-3: ep 0x82 - rounding interval to 1024 microframes, ep desc says 2040 microframes
[ 2076.697270] cdc_acm 3-3:1.0: ttyACM3: USB ACM device
...

So I assume the device is definitely connected.
> ls -l /dev/ttyACM3
crw-rw---- 1 root dialout 166, 3 Okt 17 09:56 /dev/ttyACM3

> grep dialout /etc/group
dialout:x:20:udo

So I assume that my user "udo" is authorized to access the device. Everything as it should be and as it used to be.
The patches that were applied are:
> grep "2015-10-16.* upgrade " /var/log/dpkg.log
2015-10-16 09:25:29 upgrade udev:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:30 upgrade libudev1:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:31 upgrade libpam-systemd:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:32 upgrade systemd-services:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:32 upgrade libsystemd-daemon0:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:33 upgrade libsystemd-login0:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:34 upgrade chromium-codecs-ffmpeg-extra:amd64 45.0.2454.85-0ubuntu0.14.04.1.1097 45.0.2454.101-0ubuntu0.14.04.1.1099
2015-10-16 09:25:35 upgrade libgdk-pixbuf2.0-0:amd64 2.30.7-0ubuntu1.1 2.30.7-0ubuntu1.2
2015-10-16 09:25:35 upgrade libgdk-pixbuf2.0-common:all 2.30.7-0ubuntu1.1 2.30.7-0ubuntu1.2
2015-10-16 09:25:36 upgrade google-chrome-stable:amd64 45.0.2454.101-1 46.0.2490.71-1
2015-10-16 09:25:41 upgrade libgl1-mesa-dri:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:42 upgrade libgbm1:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:43 upgrade libgl1-mesa-dev:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:43 upgrade mesa-common-dev:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:44 upgrade libgl1-mesa-glx:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:45 upgrade libgles2-mesa:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:45 upgrade libwayland-egl1-mesa:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:46 upgrade libegl1-mesa-drivers:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:47 upgrade libglapi-mesa:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:48 upgrade libopenvg1-mesa:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:48 upgrade libegl1-mesa:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:49 upgrade libgudev-1.0-0:amd64 1:204-5ubuntu20.14 1:204-5ubuntu20.15
2015-10-16 09:25:50 upgrade libhunspell-1.3-0:amd64 1.3.2-6ubuntu2 1.3.2-6ubuntu2.1
2015-10-16 09:25:51 upgrade libspice-server1:amd64 0.12.4-0nocelt2ubuntu1.1 0.12.4-0nocelt2ubuntu1.2
2015-10-16 09:25:51 upgrade libxatracker2:amd64 10.1.3-0ubuntu0.4 10.1.3-0ubuntu0.5
2015-10-16 09:25:52 upgrade linux-image-3.13.0-65-generic:amd64 3.13.0-65.105 3.13.0-65.106
2015-10-16 09:25:55 upgrade libsystemd-journal0:amd64 204-5ubuntu20.14 204-5ubuntu20.15
2015-10-16 09:25:55 upgrade ubuntu-release-upgrader-gtk:all 1:0.220.7 1:0.220.8
2015-10-16 09:25:56 upgrade ubuntu-release-upgrader-core:all 1:0.220.7 1:0.220.8
2015-10-16 09:25:57 upgrade python3-distupgrade:all 1:0.220.7 1:0.220.8
2015-10-16 09:25:58 upgrade update-manager:all 1:0.196.13 1:0.196.14
2015-10-16 09:25:59 upgrade update-manager-core:all 1:0.196.13 1:0.196.14
2015-10-16 09:26:00 upgrade python3-update-manager:all 1:0.196.13 1:0.196.14
2015-10-16 09:26:01 upgrade firefox:amd64 41.0+build3-0ubuntu0.14.04.1 41.0.1+build2-0ubuntu0.14.04.1
2015-10-16 09:26:04 upgrade firefox-locale-en:amd64 41.0+build3-0ubuntu0.14.04.1 41.0.1+build2-0ubuntu0.14.04.1
2015-10-16 09:26:05 upgrade flashplugin-installer:amd64 11.2.202.521ubuntu0.14.04.1 11.2.202.535ubuntu0.14.04.1
2015-10-16 09:26:06 upgrade gir1.2-gdkpixbuf-2.0:amd64 2.30.7-0ubuntu1.1 2.30.7-0ubuntu1.2
2015-10-16 09:26:06 upgrade gir1.2-gudev-1.0:amd64 1:204-5ubuntu20.14 1:204-5ubuntu20.15
2015-10-16 09:26:07 upgrade linux-headers-3.13.0-65:all 3.13.0-65.105 3.13.0-65.106
2015-10-16 09:26:12 upgrade linux-headers-3.13.0-65-generic:amd64 3.13.0-65.105 3.13.0-65.106
2015-10-16 09:26:15 upgrade linux-image-extra-3.13.0-65-generic:amd64 3.13.0-65.105 3.13.0-65.106
2015-10-16 09:26:21 upgrade linux-libc-dev:amd64 3.13.0-65.105 3.13.0-65.106
2015-10-16 09:26:22 upgrade thunderbird-locale-en:amd64 1:38.2.0+build1-0ubuntu0.14.04.1 1:38.3.0+build1-0ubuntu0.14.04.1
2015-10-16 09:26:23 upgrade thunderbird:amd64 1:38.2.0+build1-0ubuntu0.14.04.1 1:38.3.0+build1-0ubuntu0.14.04.1
2015-10-16 09:26:26 upgrade thunderbird-gnome-support:amd64 1:38.2.0+build1-0ubuntu0.14.04.1 1:38.3.0+build1-0ubuntu0.14.04.1
2015-10-16 09:26:27 upgrade thunderbird-locale-en-us:all 1:38.2.0+build1-0ubuntu0.14.04.1 1:38.3.0+build1-0ubuntu0.14.04.1
2015-10-16 09:26:27 upgrade liboxideqt-qmlplugin:amd64 1.9.1-0ubuntu0.14.04.2 1.9.5-0ubuntu0.14.04.1
2015-10-16 09:26:29 upgrade liboxideqtquick0:amd64 1.9.1-0ubuntu0.14.04.2 1.9.5-0ubuntu0.14.04.1
2015-10-16 09:26:30 upgrade liboxideqtcore0:amd64 1.9.1-0ubuntu0.14.04.2 1.9.5-0ubuntu0.14.04.1
2015-10-16 09:26:33 upgrade oxideqt-codecs-extra:amd64 1.9.1-0ubuntu0.14.04.2 1.9.5-0ubuntu0.14.04.1
2015-10-16 09:26:33 upgrade python-tz:all 2012c-1build1 2012c-1ubuntu0.1

I checked with Arduino 1.6.0 (which worked till yesterday) and then installed Arduino 1.6.5. Arduino 1.6.5 also fails to upload but definitely recognizes the port. What I get though is the message "Forcing reset using 1200bps open/close on port /dev/ttyACM3..." and then the upload is stuck. To be more precise bossac gets stuck and puts 100% load on one of my cores.
I also installed bossash. If I issue a "scan" command bossash will properly detect the correct port. However I will also lockup with 100% load on one of the cores. So the issue is probably not related to the IDE at all but to bossa.
Has anyone a hint how I might fix this? That is why bossac lock up and how to get it to upload again as it did before?


text:
Is it possible to power this 12V Wind Speed Sensor with a 5V battery?
I have a battery pack used to charge mobile phones. It's capacity is 13,000mAh and it has two output ports. Both are 5V but one is 1A and the other 2.1A
It also has an Input port of 5V 1A. (To which I will connect a solar panel).
I want to be able to power this Adafruit Feather M0 as well as this Wind Speed Sensor Wind Speed Sensor Voltage Type(0-5V) SKU:SEN0170. Is it possible and if it is how?

Not directly, no. They don't put "9-24V" on it just for fun - specs are specs. They are to be taken note of. You will have to find some way of increasing the 5V to more than 9V (google "Boost Regulator").

If you have a circuit diagram for your 13,000mAh 5V battery, check whether there are internal connections at higher than 5V.  Because 5V is not a common battery voltage, there probably are cells in a higher-voltage series connection, being converted to 5V output via a step-down (buck) circuit.
An item like a “5V DC to 9V DC Converter DC-DC Isolated Power Supply Module” as in picture below [from ebay seller bidcenter] might do the job.  Also available are less-expensive not-potted adjustable boost regulators.

Because 5V is not a common battery voltage, there probably are cells in a higher-voltage series connection, being converted to 5V output via a step-down (buck) circuit. -- More likely 3.7V LiPoly stepped up through a boost converter. Makes the charging the pack simpler off a 5V USB connectoin.

@Majenko, possibly some  charge packs do it that way.  The teardowns of such units that I've seen usually have at least 2 LiPoly cells in each series string.  Frequently, buck (stepdown) conversion is slightly more efficient than boost.

All the USB charger battery packs I own are boost - that includes solar charged Li-Poly packs and 4xAA batteries (yes, 4xAA boosted - it runs with just 2xAA in there).


text:
SoftwareSerial error
I have arduino , upon arduino I have Arduino GSM shield (Tx-2, Rx-3, Modem reset-7) and upon it, I have the Adafruit GPS Logger shield. I am trying to send sms of Latitude  from the GPS Logger shield to my numer through GSM shield. I am getting a error ..
SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)':
/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/SoftwareSerial/SoftwareSerial.cpp:335: multiple definition of `__vector_3'

GSM/GSM3SoftSerial.cpp.o:/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/GSM/GSM3SoftSerial.cpp:148: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)':
/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/SoftwareSerial/SoftwareSerial.cpp:335: multiple definition of `__vector_4'

GSM/GSM3SoftSerial.cpp.o:/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/GSM/GSM3SoftSerial.cpp:148: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function `SoftwareSerial::SoftwareSerial(unsigned char, unsigned char, bool)':
/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/SoftwareSerial/SoftwareSerial.cpp:335: multiple definition of `__vector_5'

GSM/GSM3SoftSerial.cpp.o:/home/thiyagu/Downloads/arduino/arduino-1.0.5/libraries/GSM/GSM3SoftSerial.cpp:148: first defined here

What is the meaning of this error ? what should I do to solve it?

This error means, that there is library overlapping on a vectors. To solve this error, you need to modify your Library file :
STEPS :

Remove the Softserial Library
Download AltSoftSerial library
if you have shield then you need to replace AltSoftSerial in place of SoftwareSerial in both .cpp as well as .h files.
Import AltSoftSerial library in place of SoftwareSerial in the sketch.

Execute .


text:
Problem with NFC on Arduino MEGA
My Objective :
I am trying to send my Mifare's unique number with some other parameters to my server database. As soon as the tag come closer to NFC, it detects, and some additional details are passed to the server Database.
Steps done :

I have Arduino UNO, Arduino GSM shield and Adafruit NFC shield . I had tried my test with UNO and works well. But to add some more features, due to memory salvation it could not be achieved through UNO. Then we moved to MEGA.
There are some changes need to be done with MEGA to make [url]http://arduino.cc/en/Guide/GSMShieldLeonardoMega[/url] GSM shield coordinate with the microcontroller[Take the Pin 2 out from GSM shield and with jumper connect Pin 2 with Pin 10]. Then we did and we tested it with GSM web client example and worked fine.
Now to accomplish our goal, when we placed NFC shield above the GSM shield and executed same GSM web client example, it is not working. And Suddenly once in a blue moon it connects to the GSM network and works . But often, it fails.

[code]
/*
  Web client

 This sketch connects to a website through a GSM shield. Specifically,
 this example downloads the URL "http://arduino.cc/asciilogo.txt" and
 prints it to the Serial monitor.

 Circuit:
 * GSM shield attached to an Arduino
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe

 http://arduino.cc/en/Tutorial/GSMExamplesWebClient

 */

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN       "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN     "login"    // replace with your GPRS login
#define GPRS_PASSWORD  "password" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP

void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while(notConnected)
  {
    if((gsmAccess.begin(PINNUMBER)==GSM_READY) &
      (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD)==GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, port))
  {
    Serial.println("connected");
    // Make a HTTP request:
    client.print("GET ");
    client.print(path);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.println("Connection: close");
    client.println();
  }
  else
  {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected())
  {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for(;;)
      ;
  }
}

What is the problem? and where is the problem ?

It is likely that placing the GSM shield between the Arduino Mega and the NFC shield is interfering with the GSM antenna.  Antennas react in strange and usually less useful ways when large conductors are placed nearby.
You could try reversing the order of attaching the shields, or you could try spacing the shields further apart using "stackable Arduino headers" (you can do a web search for suppliers).  If there is an option for an external antenna, that would be even better.
If you get GSM working, you might still have some trouble with the NFC shield, as it's possible that the GSM transmitter being so close could interfere with the NFD's circuitry - not because they use the same frequences, but just because any conductor so close might pick up electrical noise, and there will be various sensitive circuitry in the NFC electronics.

Power usage might be another aspect. It won't hurt trying to decouple the power supply.

if your design allows , the NFC is available on a module rather than a shield allowing you to separate the GSM and NFC. like this on ebay


text:
client.connect() fails except the first time
I am communicating with the Web server's database via Arduino GSM shield + GPRS connectivity
void loop()
{
  if (client.connect(server, port))
     {
       .......
      }
  else
     {
      Serial.println("Server not found");
      }
  delay(1000);
}

The first time when the loop() runs in the serial port, the code works perfectly and stores in my server's db. The second time when the loop() runs after some delay, It is unable to connect to the server and results "server not found" . I don't know what is the problem.
Please let me know if there is a way to connect continuously. Thank you

You need to provide a bit more information in your question: what is client? How has it been initialized? In which library (header file name and link to library) is it defined? Also, it might be interesting to describe what you do (not necessarily with all the code, it depends how much that is) in the the first block of the if (...) statement.

Welcome to Stack Exchange! I've noticed that in two of your three questions on the site are "cross posted" with Stack Overflow. Those are both closed. Next time if it's closed, flag for a moderator to "migrate" it to a different site if they feel fit. Thanks!

You have to disconnect before being able to connect again otherwise the controller will crash due to memory starvation. Every connect you do takes some memory to register state information. Not sure of the exact commands involved, but it'd look a bit like this:
   if (client.connect(server, port))
     {
       .......
       client.disconnect( .... );
      }
  else
........

Alternatively you can check if you are already connected, and only do a reconnect when necessary, but I don't know which library you are using, let alone if there is a proper check available in it.

void loop()
{
 if (client.connect(server, port))
 {
   .......

   client.stop();
  }

 else
 {
  Serial.println("Server not found");
  }
 delay(1000);
 }

Can you please add some explanation to this code? Thanks!

Are you sure about the closing } before the client.stop?

Sorry, Its mistake in the code. It will be inside the parenthesis .. Thanks for correction i have updated the code..


text:
What is the advantage of using a motor shield if I want to use a stepper motor?
I know that it is possible to connect a stepper motor directly to an arduino (as displayed here). I know that another option is to use a motor shield (for example the Arduino Motor Shield or the Adafruit Motor Shield).
What I would like to know: What are the actual advantages of using a motor shield?
Is it just a question of convenience? Or does a motor shield do something that could not easily performed without a shield? Does it allow me to connect more motors than I could connect directly without a shield (power supply comes to mind)?

The example you linked to isn't actually connecting the Arduino directly to a stepper motor. It's going via a ULN2003A driver. That's a very common Darlington transistor array, which basically just lets you use a small current to switch a larger load.
That's necessary because the Arduino pins can't safely source enough current to drive the stepper motor directly. It might work for a while, but it would damage your Arduino sooner or later.
Motor shields usually have a similar driver in them, but can also provide additional functionality which you might find useful. For example, the Adafruit shield you linked to is controlled by the I2C bus, and has its own on-board PWM. That means you can control several motors without needing any extra output pins on your Arduino.
In short, motor shields aren't necessary. They can be helpful though, especially if you aren't familiar with the underlying electronics, or you don't want to build it yourself.

Mechanical stability of the whole thing is probably the main advantage. I'd personally opt for a generic module or loose components. The main disadvantage of shields is pin conflicts when using more than one shield.

I'm using a adafruit motorshield v2 for my solar tracker project with two stepper motors atm.
i'm quite a new to arduino and coding and i think the shield made it a lot easier for me to get a hang of it - easy to code and nicely stack able on the ardiuno (little soldering to assemble but not too difficult).


text:
Arduino ADC Reference Voltage if it is Battery Powered
I am looking to possibly monitor battery power to the Arduino using its ADC.  This is fairly straight forward and simple (especially if using the Arduino API); however, if the battery is powering the Arduino and is unregulated externally, won't the ADC reference voltage constantly be dropping with the battery?  In other words, wouldn't the ADC value would constantly read the same value (the max value) even though the battery would actually be decreasing in voltage?
If this is the case, it would be both inefficient and pointless to measure the battery voltage.

... won't the ADC reference voltage constantly be dropping with the battery?

Yes, which is why you either use or measure an internal bandgap reference instead.
Use the analogReference() function to select a reference appropriate for the board in use. Note that you will need to use a voltage divider to reduce the battery voltage to a value below that of the selected reference if you wish to measure it.
To measure the bandgap voltage instead (using AVCC as a reference and working "backwards") you will need to set MUX[3:0] in ADMUX to 0b1110 and then perform an ADC reading directly (set ADSC in ADCSRA and wait until it resets, then read from ADC[H:L]).
As always, see the MCU datasheet for details.

Great information, now I think I can proceed on my own.  I was hoping there was some sort of internal reference that could be used.  As you suggested, I will need to voltage divide the power voltage down below AVccref, however, I am looking to maximize battery life in all possible aspects so I was going to use a large equivalent resistance for the divider to ensure I have less than a uA of leaking current.  Do you see any issues with this?

The ADC impedance is only 100Mohm. Consider measuring the internal reference instead.

FYI I found this awesome blog after the answer @Ignacio posted:  link

@ryeager's link to http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/#comment-71836 has this code for reading the Arduino's battery voltage:
long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0);
  #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    ADMUX = _BV(MUX3) | _BV(MUX2);
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #endif

  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring

  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
  uint8_t high = ADCH; // unlocks both

  long result = (high<<8) | low;

  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

The trick here is that it measures its internal reference of 1.1V using the battery voltage, and then inverts it to calculate the unknown reference voltage.
The ADMUX magic in this code can enable other interesting ADC readings, such as differential measurements, and differential ADC measurements with gain, depending on the component and datasheet.