text:
ESP8266-01 system param error
I'm using esp8266-01 connected to arduino nano.
Every time I tried to upload code to the esp8266 chip I get this error in the serial monitor:

system param error

56 45 52 31 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00
00 00 00 00 00 00 00
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00 00 00 ff ff ff ff ff
ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮j
00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff

After this log the chip turns off (how this possible ?)
I'm lost in this problem please help.

This error could occur if you are using the wrong settings, like having a ESP-01 with 512K flash and have the IDE settings to 1M fflash.

wich 512K I need to use there's a 3 options.

Have you tried the 3 different options?

Yes I did try and all of the option failed.


text:
for loop iterated only once
I have written a little project, it works so far as it should but the for loop is only iterated once, then the result is displayed on the LCD.
#include <LiquidCrystal.h>
#include <stdlib.h>
const int Contrast=20;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int led = A5;
const int button = A3;

void setup() {
  Serial.begin(9600);
analogWrite(6,Contrast);
lcd.begin(16, 2);

pinMode(led, OUTPUT);
digitalWrite(led,LOW);
pinMode(button, INPUT_PULLUP);
}

void loop() {

unsigned long mittelwert = 0;

for(int i=0; i<10; i++){
  unsigned long r = random(1,5000);
  unsigned long now = millis();

  digitalWrite(led,HIGH);

  while (digitalRead(button) == HIGH){
    lcd.setCursor(0,0);
    lcd.print("druecken");
  }
  mittelwert = mittelwert + millis() - now;
  digitalWrite(led, LOW);  //LED aus

}

lcd.clear();
lcd.setCursor(0,0); //setze Cursor auf 1.Stelle in der 1. Zeile
lcd.print(mittelwert/1000);
lcd.setCursor(0,1);
lcd.print("Sekunden");

delay(5000);
lcd.clear();

}

It does iterate 10 times, it's just really fast.
You probably want to wait some time to debounce the button, and then wait for the button to be released again.
I don't know why you have to keep printing to the LCD during the loop. Wouldn't printing it once before the loop be enough?
There's something wrong with your math as well. To get an average value, you add up all values, and divide by the number of values. Your variable name mittelwert is confusing, totalTime would be more appropriate.
averageTime/1000 is an integer division, so it floors the result. For example, if the average time is 999 ms, ⌊999 / 1000⌋ ==  0.
Use a floating point division if you want a decimal number.
In your setup, you don't have to use digitalWrite(led, LOW); because it is already initialized to LOW when you start the program.
const int led = LED_BUILTIN;
const int button = A3;

const int numberOfTests = 10; // repeat 10 times

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

  pinMode(led, OUTPUT);
  pinMode(button, INPUT_PULLUP);
}

void loop() {
  unsigned long totalTime = 0;
  for (int i = 0; i < numberOfTests; i++) { // repeat 10 times
    int r = random(1, 5000);
    delay(r); // wait a random number of milliseconds (between 0.001 s and 5 s)

    digitalWrite(led, HIGH); // turn LED on
    unsigned long startTime = millis();

    Serial.println("Press button");
    while (digitalRead(button) == HIGH); // wait for the button to be pressed

    totalTime += millis() - startTime;
    digitalWrite(led, LOW); // turn LED off

    delay(25); // button debounce
    while (digitalRead(button) == LOW); // wait for the button to be released
  }

  unsigned long averageTime = totalTime / numberOfTests;
  Serial.print(averageTime);
  Serial.println(" milliseconds");
  Serial.print((float)averageTime / 1000.0, 3); // print the result of the floating point division with 3 digits after the decimal point
  Serial.println(" seconds");

  delay(10000); // Wait 10 seconds before repeating
}

Your button is configured as an input with a pullup.  Therefore, except when the button is depressed to ground that input, this nested loop
while (digitalRead(button) == HIGH){
   lcd.setCursor(0,0);
   lcd.print("druecken");
}

will endlessly repeat, preventing execution from advancing.
Given that your question fails to state what you are hoping to accomplish it's not possible to make any corrective recommendations.  If you do want to make use of the button, you should probably first search and read the existing questions here having to do with debouncing.

source: Stack Exchange

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

sort: votes


text:
Arduino mega board 5v pin does not gives 5v when 7.5v is applied through external source
I gave 7.5v to the arduino mega board through battery. 5v pin in the board gives me the same voltage as input. Earlier it was working fine now it is giving problem.Please let me know the solution as soon as possible.
Thanks and regards,
Thippeswamy

Where are you applying the power? on the barrel jack? Where are you measuring the voltage? How? (explain it as clearly as possible, example: I put two wires, one in the 5V pin and one in the GND pin, then attach the two wires to the multimeter set in DC with a 20V range and it reads 7.5V). Moreover do you have a cheap USB power bank?

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

It is highly likely that you have destroyed your Arduino. This can happen in a number of ways. Rugged Circuits has a great article on 10 ways you can destroy the Arduino.
The giveaway is that you are measuring 7.5V on the 5V pin. Most likely the voltage regulator has blown. Page 355 of the ATMega2560 datasheet says the absolute maximum voltage for the chip is 6.0V, so this also means that the microcontroller is blown as well. It is most likely unsalvageable.
Go out and buy yourself a new one. Before you turn it on, check the wiring is correct.
We have all let the magic smoke out at some point.

The link to rugged circuits is broken.

Hmm... it worked for me. https://www.rugged-circuits.com/10-ways-to-destroy-an-arduino/

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


text:
Power source for arduino project
The project is to make a 4WD car using arduino uno(clone) and four toy dc motors. I am using a adafruit motor shield v1.2(clone). The car is required to run autonomously, please suggest batteries for the arduino and the shield.
Also when I am using external power connector for arduino, all the motors start at different timing.

You can use anything from a 3V coin cell to a 24V truck battery... And if you want, even generators are fine, even if I'd personally avoid nuclear generators, but that's only because fuel is a bit hard to get (see Doc in Back to the future I). If you want a more precise answer, give more details, such as the power needed, the duration you expect, if you want a "ready to plug" battery or you can add circuitry, what is your experience and so on

5 minutes is the required duration and the motors are 4v each. Ready to plug battrey is required.

4V and.... estimated current consumption?

Sorry I have no idea.

Then, IMHO, it is better if you start thinking at this... Otherwise you'll end up with a heavy oversized battery or a too small battery. In any case, if your motors are pretty small go on with Mikael's solution. If you want a better but harder solution, maybe 2S LiPo batteries are ok for this; just buy a balanced charger for 2S batteries, a LiPo battery big enough to give you enough power (for instance, if your motors draw 1A each and you have two you can get small 1Ah 2S batteries for around 5$ and go for half an hour), then just use a DC/DC circuit to lower the voltage to 5V

Or you can use a 1S cell and a boost DC DC circuit to raise the 3.6V to 5, if you prefer... Cheaper charger, maybe, but some higher currents to deal with

I've been using usb power packs.

Easy to source (can be found in all electronics stores and many general stores).
Come in many sizes (500mAh to 20,000 mAh are common).
Rechargable, usually by using a generic phone changer with a usb micro connector.
Not costly.
Quite roubust.
Most Arduino boards and many motor driver boards are designed to be powered from usb.

Make sure you get one that is rated for enough current for your project.

I usually think about LiPo batteries but I have to admit that USB power packs are usually cheaper and easier to use.. +1

power delivery of the power pack tends to be around 1A or 5W max per pack though (if you are lucky).

It is wonderful to bypass the auto-off circuitry of USB powerbanks.

Car batteries are wonderful, and almost never explode. A badly mistreated Li-{Fe,Po,Ion}, however... ouch. Otherwise use banks of NiMh/NiCd.
If you don’t fear death, use Li-Ion batteries with a TP4056 + DW01A IC, it can handle charging from USB, and provides over-discharge protection, so your batteries don’t die.
https://www.addicore.com/TP4056-Charger-and-Protection-Module-p/ad310.htm
It also has current limiting built-in.


text:
Set clockspeed of Arduino Pro Micro a. k. a. AtMega32u4
Is it possible to change clock speed when running sketch?
Low-power lib drops the current consumption from 20mA to 9.5mA at 8MHz, it is still too much. Is there a way how to set clockspeed (for example) to 1MHz, go to sleep, after interrupt wake up, set clockspeed back to the 8Mhz (for 3v3), do some stuff and then go sleep again?
Thanks

Absolutely. The built-in prescaler can dynamically change the clock speed for most of the systems on the chip (USB still needs to run at full speed in order to operate properly).
#include <avr/power.h>

 ...
clock_prescale_set(clock_div_32);
sleep();
clock_prescale_set(clock_div_1);
 ...

See the datasheet and AVR Libc documentation for more details.

Thanks, I've just tryed this, but it didn't help. The power consumption is the same as before.
clock_prescale_set(clock_div_8);   attachInterrupt(INTERRUPT_PIN, wokenUp, RISING);   LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

Probably because most of the clocks are off in that power mode, so aren't running in the first place.

What should I do then do achieve the lowest power consumption with wake up by interrupt?

Disable unneeded peripherals. Reduce overall clock speed. It's all in the datasheet and application notes.

Also remove the power led from the Arduino board, as that is also using power without doing anything useful.


text:
How to increase SD card write speed in arduino
I'm creating a data-logger system which logs data in SD card at a high speed of about 20000-30000 bytes per second. But the SD library in arduino currently writes data at about 4500-5000 bytes per second which is too slow.
I've read this hack to improve the write speed, but I'm wondering if a more direct approach is possible, maybe by adjusting the SPISettings.

You might try the SdFat library - it's much more efficient than the default SD library.

You might also want to make sure your SD card is of good quality, although 5000 bytes seems too low for any kind of SD card.

OK. So, I tried the SDFat lib. This library is definitely better than the default SD library that comes with adruino.
But that is not how I solved my problem of low data-rate.
I followed the instruction of the author of SDFat library from this post.
According to fat16lib, to increase the data rate we need to use flush() wisely. We would want to write() the data in each cycle, but we only need to flush() once every 100 cycles or so depending on how much data is being written in each cycle. Also, be sure to keep the flag in SD.open() as 'O_WRITE | O_CREAT' instead of 'FILE_WRITE'.
This sure increased the speed by a great factor. But I needed more!
Storing the data in binary (check out this blog) improved the performance even more.
My current speed is approximately 100-120 KBps (that's kilo bytes) with a class 4 SD card!
Finally, I want to thank you guys for your help.

Avoid the handshake getting a buffer!
Use
SD.write(buf,size);
Hi every one, I'm working in a project with the same issue. I was following the same steps of yours and got exactly the same numbers. I've just fixed it out. The problem is the handshake when you call the SD.write().
Instead:
//for each loop, it is going to make a handshake
while(<yourCondition>){
    SD.write(<yourValue>);
}

Do:
char buf[length];
while(yourCondition){
    buf[index] = yourValue;
}
SD.write(buf,index);//only one handshake

In my project the first one I got 4100 bytes, and the second one using a buffer with 128 (buf[128]) I got 145408 bytes in my project. Good enough.

I don't know what you mean by handshake, because AFAIK SD uses a (512 kB) buffer internally anyway. But I also observed that writing individual bytes with File.write is extremely slow and the compiler doesn't seem to be able to optimize it (after all it's just copying one byte to the internal bufffer and checking if buffer is full and SPI transmission should start). Using my own buffer outside and File.write(buffer,size) brought extreme performance improvement also in my application.

Many factors would decide if you can reach this wanted speed. Only some of these.

1. Your Software
The SdFat Library is faster than the standard SD Library of the Arduino IDE. It also has an easy to use compatibility function with the standard SD Library. Try it out.
2. Your Hardware
You should use a high class SD Card. As you maybe know SD Cards are sorted into performance classes. Most people in the internet recommend a SanDisk SD Card.

I will try this in a few days and let you know the results. Thanks.

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


text:
Benchmarking String.toInt() vs Checking individual characters gives unexpected result
I'm trying to check whether the input string contains all digits or not. I achieved this using 2 different algos. One is to convert the string to integer using String.toInt() and then checking if its value lies between the integer of length of the input string.
e.g. If input string is "123". The corresponding integer must lie between 100-999.
Second, I wrote a function that iterates over each character of the string and checks if its ASCII values lies between 48-57. If not, it returns false.
When I bench marked these two algos, I found that when the string contains only digits, the 2nd algo is about 9 times faster than the 1st one. But when the string contains even a single non-digit character, the 1st algo takes ~1ms, but the 2nd algo always takes ~5ms. Why is this? I've not been able to figure this out.
The code:
unsigned long start;
unsigned long middle;
unsigned long end;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // send an intro:
  Serial.println("String toInt():");
  Serial.println();
}

void loop() {
  // Read serial input:
  if (Serial.available()) {
    String r = Serial.readString();

    start = micros();
    unsigned long rInt = r.toInt();
    int rLen = r.length();

    if ((rInt >= floor(pow(10, rLen))) || (rInt < floor(pow(10, rLen-1)))) {
      Serial.println("Please enter valid integer value!");
    } else {
      Serial.println(rInt+1);
    }

    middle = micros();

    bool isInt = doesContainInteger(r);
    if (isInt) {
      Serial.println(r);
    } else {
      Serial.println("Please enter valid integer value!");
    }

    end = micros();

    Serial.println(middle-start);
    Serial.println(end-middle);
  }
}

bool doesContainInteger(String s)
{
  int sLen = s.length();
  for (int i=0; i<sLen; i++) {
    char sChar = s.charAt(i);
    if (sChar<48 || sChar>57) {
      return false;
    }
  }
  return true;
}

Instead of "Please enter valid integer value!", just print "Invalid int". You will get somewhat less unrealistic timings.

You were right! I replaced "Please enter valid integer value!" with "!", and it took just 80us to print.

Including the serial output in your calculation timing is just plain stupid. Your timing should start before your test routine and finish immediately afterwards.

Oh, and pow() is a horrendously slow routine. Avoid it at all costs.

@Majenko Thanks. Your feedback is always valuable!

1 ms means easy calculation.
2 ms means more time spent in calculation.
5 ms means far more time in message printing to Serial buffer.
I calculated the error message passes serial line in 20-30 msec, so that is why I think there has to be a little bit faster buffer in between there.

As pointed out by Majenko in his (slightly annoyed) comment, you need to change your timing code to time only the calculations you want benchmark, not the I/O or other irrelevant code. For checking the conversion using toInt(), for example, try:
// time our conversion
unsigned long start = micros();
unsigned long rInt = r.toInt();
bool invalid = rInt == 0;
unsigned long end = micros();

// print the result
if (invalid) {
    Serial.print("in");
}
Serial.print("valid conversion took ");
Serial.print(end - start);
Serial.print(" microseconds.");

Note that your assumption that a three-character input that's a valid integer will be between 100 and 999 is wrong; "003" and "-17" are both three-character inputs that should be correctly converted.
According to the toInt() documentation, 0 is returned on failure to convert, so I check for that in the code above. But since one can't tell the difference between a successful conversion of "0" and unsuccessful conversion of "abc" or some other non-integer, you really should be sure before you call toInt() that you've got a valid integer int the string.

authors: Убийца Карасей


text:
Where is the definition of system_adc_read() in the esp8266 Arduino code?
Where is the definition of uint16 system_adc_read(void) in the esp8266 Arduino code?
I can see it being declared in Arduino/tools/sdk/include/user_interface.h, however there seems to be no definition of this. system_adc_read() gets called in analogRead() in Arduino/cores/esp8266/core_esp8266_wiring_analog.c
I suspect system_adc_read() calls system_adc_read_fast() to read the ADC, but can't actually find it in the code! Could somebody please point me to this? I've been struggling for quite some time.
Purpose: To manipulate the system_adc_read() in ESP8266 to get higher ADC sampling rates. Right now ADC sampling rate is 10ksps. I want it to be more than 30-40ksps.

esp8266 sdk is not open source

Oh my god! Thanks for telling me this. So, what are my alternatives here? I've searched for ways to improve the sampling rate, but couldn't get to the desired (30-40 ksps) level.

try ESP8266 Non-OS SDK API Reference here http://espressif.com/en/support/download/overview?keys=&field_type_tid%5B%5D=14

The "definition" of uint16 system_adc_read(void) is inside the compiled archive/object file libmain.a inside one of the NONOSDK folders which is located in /tools/sdk/lib/ . The version is selected in platform.txt. For example in my platform.txt:
# default SDK for all boards
# (generic board overrides this variable)
build.sdk=NONOSDK22x_190703
#build.sdk=NONOSDK22x_191024
#build.sdk=NONOSDK22x_191105

Running the xtensa-lx106-elf-objdump.exe -d on this file I can find this section inside:
00000258 <system_adc_read>:
     258:   020c                    movi.n  a2, 0
     25a:   f0c112                  addi    a1, a1, -16
     25d:   0109                    s32i.n  a0, a1, 0
     25f:   fffc01                  l32r    a0, 250 <system_pp_recycle_rx_pkt+0x18>
     262:   0000c0                  callx0  a0
     265:   fff901                  l32r    a0, 24c <system_pp_recycle_rx_pkt+0x14>
     268:   f42020                  extui   a2, a2, 0, 16
     26b:   1b1207                  beq a2, a0, 28a <system_adc_read+0x32>
     26e:   b30c                    movi.n  a3, 11
     270:   902220                  addx2   a2, a2, a2
     273:   1122e0                  slli    a2, a2, 2
     276:   fff701                  l32r    a0, 254 <system_pp_recycle_rx_pkt+0x1c>
     279:   0000c0                  callx0  a0
     27c:   f42020                  extui   a2, a2, 0, 16
     27f:   00a402                  movi    a0, 0x400
     282:   013027                  bltu    a0, a2, 287 <system_adc_read+0x2f>
     285:   020d                    mov.n   a0, a2
     287:   f42000                  extui   a2, a0, 0, 16
     28a:   0108                    l32i.n  a0, a1, 0
     28c:   10c112                  addi    a1, a1, 16
     28f:   f00d                    ret.n
     291:   00                          .byte 00
     292:   00                          .byte 00
     293:   00                          .byte 00
     294:   ff ff 00 00
    ...

000002a0 <system_adc_read_fast>:
     2a0:   e0c112                  addi    a1, a1, -32
     2a3:   11c9                    s32i.n  a12, a1, 4
     2a5:   21d9                    s32i.n  a13, a1, 8
     2a7:   31e9                    s32i.n  a14, a1, 12
     2a9:   5129                    s32i.n  a2, a1, 20
     2ab:   41f9                    s32i.n  a15, a1, 16
     2ad:   0109                    s32i.n  a0, a1, 0
     2af:   03fd                    mov.n   a15, a3
     2b1:   fff901                  l32r    a0, 298 <system_adc_read+0x40>
     2b4:   0000c0                  callx0  a0
     2b7:   4fbc                    beqz.n  a15, 2ef <system_adc_read_fast+0x4f>
     2b9:   fff6e1                  l32r    a14, 294 <system_adc_read+0x3c>
     2bc:   0c0c                    movi.n  a12, 0
     2be:   51d8                    l32i.n  a13, a1, 20
     2c0:   90dcd0                  addx2   a13, a12, a13
     2c3:   001d32                  l16ui   a3, a13, 0
     2c6:   1a13e7                  beq a3, a14, 2e4 <system_adc_read_fast+0x44>
     2c9:   902330                  addx2   a2, a3, a3
     2cc:   1122e0                  slli    a2, a2, 2
     2cf:   b30c                    movi.n  a3, 11
     2d1:   fff201                  l32r    a0, 29c <system_adc_read+0x44>
     2d4:   0000c0                  callx0  a0
     2d7:   f44020                  extui   a4, a2, 0, 16
     2da:   00a402                  movi    a0, 0x400
     2dd:   003d                    mov.n   a3, a0
     2df:   013047                  bltu    a0, a4, 2e4 <system_adc_read_fast+0x44>
     2e2:   043d                    mov.n   a3, a4
     2e4:   005d32                  s16i    a3, a13, 0
     2e7:   cc1b                    addi.n  a12, a12, 1
     2e9:   f4c0c0                  extui   a12, a12, 0, 16
     2ec:   ce9fc7                  bne a15, a12, 2be <system_adc_read_fast+0x1e>
     2ef:   11c8                    l32i.n  a12, a1, 4
     2f1:   21d8                    l32i.n  a13, a1, 8
     2f3:   31e8                    l32i.n  a14, a1, 12
     2f5:   41f8                    l32i.n  a15, a1, 16
     2f7:   0108                    l32i.n  a0, a1, 0
     2f9:   20c112                  addi    a1, a1, 32
     2fc:   f00d                    ret.n
     2fe:   00                          .byte 00
     2ff:   00                          .byte 00
     300:   ff ff 00 00
    ...

Cool detective work. Thanks! I was able to achieve my use case using this: https://arduino.stackexchange.com/a/52854/25931

@loadingnow can anyone clarify whether system_adc_read returns 0-1023 or whether it returns 1-1024?

@S.Imp I am not sure, but you should ask a separate question to clarify. It would be much more helpful for others who have the same question.


text:
SD card shield not working on 3.3v
My SD shield works nicely on 5v supply, but does not detect SD card on 3.3v. Could someone explain the possible reason behind this? Could you also provide a solution for this?
I've worked with it on Arduino Uno. Now I want to use SD card directly with ESP-12E to read its contents using SPI by doing something like this. Since ESP8266 operates olny on 3.3v, I need SD card to work on this voltage.
I've used two separate SD card shields without any luck! Photos of the two shields and micro-SD card are attached.

Are we supposed to guess what your circuit is doing? The only info you provided was a few pictures of the readers. What are the wires connected to?
Are you saying you connected 3.3V to the "3V3" pin and left the "5V" pin open?

How do you know it's the card reader and not your code that is at fault?

The circuitry is actually a pretty straight-forward SPI (MOSI-MOSI, MISO-MISO, SCK-SCK, CS-chipSelectPIN, GND-GND, VCC-VCC).
Yes, I connected 3.3V to the 3V3 pin and left the 5V pin open.

It's probably the fault of shield because it works when I supply 5V to it.

@AshishRanjan "VCC-VCC"? That's not helpful either. What is the other VCC? Realize that it's important to document what is going on. You're asking for help, it's best to give us as much info as possible.

@AshishRanjan That being said, 3.3V connected to the "3V3" pin should be sufficient. Try measuring the current being used on that pin, maybe that could show something interesting.

Sorry if I seem too vague. VCC could be anything from 3.3V to 5V. What I meant was, when I connect 5V to VCC, I am able to read the contents of SD card, but if I supply 3.3V to VCC, I'm not able to read or even detect the presence of the SD card.

@AshishRanjan I understand your issue, I do not understand what you connected to VCC! Where is the wire going!?

The VCC wire is going to the 5V of Arduino Uno (or the 3.3V). The GND wire is going to GND of Uno. Similarly
MOSI - pin 11
MISO - pin 12
CLK - pin 13
CS - pin 4

I believe the 3.3V rail also uses current from the 5V rail on arduous. Perhaps there is simply not enough current on the 3.3V rail.

I'll measure the current in 3.3V as well as the 5V line tomorrow, and let you know the results. Perhaps that would help us!


text:
How to measure free RAM on an Arduino Due in Runtime?
I use this Library to measure my free RAM on a Mega in runtime. But this Library does not work on the Due.

Try this library https://github.com/mpflaga/Arduino-MemoryFree

As mentioned by Mikael Patel in a comment, the library from Arduino-MemoryFree
 should do it. A minimal sketch that seems to work on the Due:
extern "C" char* sbrk(int incr);

int freeMemory() {
  char top;
  return &top - reinterpret_cast<char*>(sbrk(0));
}

void setup ()
{
  Serial.begin (115200);
  Serial.println ();
  Serial.print ("Free memory is: ");
  Serial.println (freeMemory ());
}  // end of setup

void loop () { }

I'm not totally convinced that this gives the correct figure. The figure returned by the library above for my Uno was too high (2297 bytes).

It seems to work fine after a call to malloc(), which is needed to initialize __brkval. I would return &top - ( __brkval ? __brkval : &__heap_start); in order to have something that works also when not using malloc().

I thought it might be something like that. After all, not everyone uses malloc.

Try to use this method:
int freeRAM() {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

The question was about a Due. When I tried your code on my Due I got -28 bytes of RAM, which is hard to believe.


text:
How can I concatenate multiple byte Arrays into one Array
I have three byte arrays. I first change their values during runtime and after that I want to combine them into one bigger 4th array.
byte a1[] = { 0x01, 0x00, 0x01 };
byte a2[] = { 0x00, 0x11, 0x01 };
byte a3[] = { 0x11, 0x00, 0x01 };

byte c1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

I first tried this, but it did not compile.
c1 = a1 + a2 + a3;

I also tried strcat() and I did got a error.

the answer depends on what you meant by "concatenate". you may be able to clarify by showing what you expect to be in c1[].

If any of the answers solved your problem, you should accept it.

You can concatenate with memcpy. You just need to set the pointer at the right place inside the c1 array.
memcpy(c1, a1, sizeof(a1));
memcpy(c1+sizeof(a1), a2, sizeof(a2));
memcpy(c1+sizeof(a1)+sizeof(a2), a3, sizeof(a3));

They should also be careful that they use this method (with sizeof(), I mean) only when in the same scope where the arrays are declared. If the pointers to the arrays are passed to a function concat(), for instance, this will fail since sizeof() would return the pointer size and not the array size.

You can do it like this
byte c1[] = {0x01, 0x00, 0x01, 0x00, 0x11, 0x01,0x11, 0x00, 0x01 };
byte *a1 = c1;
byte *a2 = c1+3;
byte *a3 = c1+6;

Note that This does not make a copy byt you can access the C1 and a1 a2 and a3 as you liked.

I have a problem with jantje answer. As any array (c1) is a pointer to the array. So when you attempt to byte a1[] = c1; You are attempting to place the address of c1 into the 'byte'. More likely without an index attempting to change the location of a1. This will not compile. All of these are doing just what gre_gor suggested (memcopy) and is the accepted way of copying or moving data. :)

You are right on byte a1[] = c1; I changed the answer.
You are not right on stating this is the same as gre_gor suggested.
In my case only 9 bytes of memory are used for data (I don't count the pointers). In other words there is only 1 copy of the data where in gre_gor there are 2 copies.
Note that the question is very unclear about what is needed so for now we don't know a copy or simple reference is needed.

My suggestion about gre_gor was that it was the proper way to do it.  Any changes will be fixed during a compile, your code will not.  gilhad is virtually the same.   This new version will not compile either as you didn't change the problem.  Also, his code moves it from a to c, the opposite of yours, but the original source has the same value as does the destination.  Where is the 'other' copy? But you are correct, more information is needed for a good answer.

This is really a comment, not an answer. With a bit more reputation, you will be able to post comments. For the moment I've added the comment for you, and I'm going to delete this answer. Thanks for your understanding and cooperation!

byte *src;
byte *tgt;
tgt=c1;
src=a1;
for (int i=0;i<3;i++) *(tgt++)=*(src++);
src=a2;
for (int i=0;i<3;i++) *(tgt++)=*(src++);
src=a3;
for (int i=0;i<3;i++) *(tgt++)=*(src++);


text:
How to turn I2C Sensors on and off with an Arduino Mega 2560?
I want to turn on and off I2C Sensors with the Arduino Mega 2560.

I use one max. 0.4A NPN Transistor, which controls the Vcc line to the sensor.
When I plug my Arduino into my laptop and the sketch begins working everything is fine. The sensor is turned on and is working.
But when I set the Transistor Base to Low and cut the Vcc the sensor acts weird.
The LED on the sensor breakout board shines very weak. So the sensor/breakout board is getting electricity from somewhere else; probably from the I2C connections.

Same results with this small experiment:

Breakout board directly connected to the Arduino (without Transistor)
Vcc-3.3V pin wire disconnected from the Arduino female pin

How can i properly turn on and off an I2C sensor with an Arduino?
Do I have to use additional transistors for every I2C line? Are better circuit solutions available or maybe a software solution?
How should I design my circuit and my software if I have multiple I2C sensors connected to my Arduino and I want to use them independently from each other?

Used hardware: Arduino Mega, Sensor Breakout Board

Software excerpt for power control:
void setup() {

    pinMode(7, OUTPUT);
    digitalWrite(7, HIGH);

    ...

    delay(10000);
    digitalWrite(7, LOW);

    ...
}

Why not use MPU6050 low power mode? The power LED and power regulators on the Arduino board draws more current.

Remove the LED
and put it into low power mode as suggested.

Trying to understand your real requirement I believe what you wish to achieve is not power down the sensor but to share the same I2C line among multiple ones: am I correct? If that's the case please update your question accordingly, because otherwise you'll keep getting the same answers over and over: power your sensor down, don't turn it off

The Question is: "How to turn I2C Sensors on and off with an Arduino Mega 2560?" How to cut off their electricity, how to turn them completely off and on, controlled by the Arduino. How to turn multiple different I2C Sensors completely on and off,  independent from each other, using the Arduino.

The SDA and SCL pins have pull up resistors on them. So their voltage is 5V. By disconnecting Vcc on the sensor you are running the sensor out of spec. since the voltage on the SDA and SCL pins exceed Vcc.
Most chips have clamping diodes. So the chip is clamping the 5V on the I2C pins to Vcc. So you are powering the chip through the pull-up resistors on the I2C pins.
This would explain why the power led is lit, but not as bright.

if your sensor does not consume more that 20ma, you can power it's GROUND pin with an arduino pin by using pinMode(sensor, OUTPUT), analogWrite(sensor, 255) : at that stage no power flows to the sensor since all its pins are high. When you want to power back the sensor, you need to lower the value of "255" to 0 , if your sensor uses 5v or to around 40 , if your sensor uses 3.3v. I have been using this system for a while without any problem.    You might need a small delay(50), to give time for the sensor to power up.


text:
Set EEPROM to initial values when flashing ESP8266
I have a variable uint8_t a_ram which needs to be initialized from the EEPROM variable a_eeprom when the ESP boots up. Whenever a_ram changes, the new value has to be stored to the EEPROM (a_eeprom), so that the ESP will initialize a_ram to this new value after the next reboot.
The problem I have is to understand, how the value of a_eeprom can be initialized for the very first boot. If a_eeprom has not been set before (that means, that a_ram has not been stored to EEPROM yet), my variable will be initialized to 0, which must not be the case.
I could introduce an extra variable to the EEPROM (kind of a flag), which tells me whether a_ram has been stored to EEPROM or not and only initialize a_ram to a_eeprom if that is the case. But as I don't want to spend this memory if it isn't neccessary, I'd like to know if there is a possibility to set an EEPROM value when flashing the ESP.
Btw, I'm using the arduino IDE.

First you should probably research how EEPROM is approximately emulated on a system that doesn't actually have any.

it is written to flash.to location after SPIFS

@Juraj unfortunately I'm not very familiar with this topic. Could you give me a hint about what I should update myself if I did not understand your comment? ;)

@ChrisStratton as far as I understand the ESP, it has an EEPROM onboard and does not only emulate it

@SimSon - you are mistaken.  The ESP8266 has no on-chip EEPROM, and most boards pair it with an SPI flash, not an EEPROM.

I was answering Chris. read the docs http://esp8266.github.io/Arduino/versions/2.0.0/doc/libraries.html#eeprom


text:
String.format("%i",i) equivalent
How do I format an arduino String when I do not want to print it?
I know that one can use printf() or other methods to print a formated string and unfortunately that's all I find with google.
But that's explicitly not what I'm looking for, I want to assign the formated string to a variable instead.
There are itoa, etc. which I could use, but if there is a standard function to use like String a=format("an integer: %i",myinteger); I would really prefer this one.

The answers to the below question link might help - https://stackoverflow.com/questions/34775168/get-formatted-string-to-a-variable

see Rohan's link for sprintf. I recommend not to use Strings, but if you must: String s(32); s += "an integer: "; s += myinteger;

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


text:
Arduino weather vane
My little weather station is run on a Nano and has the anemometer and the temp/humidity sensor.  A smoke detector is on the way because I live where wildfire is a big concern.
I would like to build a simple weather vane without spending a lot to buy the commercial solutions.  Rotary potentiometers have dead spots and using a bunch of hall effect sensors would use up too many digital inputs to be useful, afaik.
Question:  How can I build a simple direction sensor?

There are two-axis analog hall sensors that detect the orientation of a magnet, but they cost a bit more.  You could probably make yourself a low resolution absolute optical encoder with hand tools or a 3d printer.

Use two pots with the dead-spots at opposite ends.

Not sure but I think you should be able to use a magnetometer (compass). 5US on Amazon.com could afford you something good enough. https://www.amazon.com/HiLetgo-HMC5883L-Electronic-Compass-Magnetic/dp/B00UAIY698/ref=sr_1_2?ie=UTF8&qid=1477482294&sr=8-2&keywords=gy+271

Thank you for your pointer.  Here is the one I just ordered:  https://www.amazon.com/gp/product/B00SDTFI1Q/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1

I decided to go with 4 reed sensors.  With experimentation I found I can successfully detect 8 distinct directions using 4 reed switches since the rare-earth magnet will switch two on at once when it is in between.
Thank you all for your answers.  Upvotes for everyone for the discussion.

Its a long time since I looked at this and the details are a bit misty, so sorry for the inaccuracies, but I'm sure people will correct them for me :)
I originally brought one of these http://www.maplin.co.uk/p/maplin-replacement-wind-direction-sensor-for-n96fyn96gy-n81nf and then decided to take it to bits, like you do.
The vane spins a magnet around and this triggers 1 of 8 reed switches as it passes around.  The read switch is connected to VCC and a resistor and the resistors feed into a common wire back to the microprocessor.  The 8 resistors all have different values, so the result is a differing output voltage depending on which reed switch has been triggered.
So what you need is:

A magnet
A number of read switches positioned far enough apart so only one is triggered at a time
A number of different resistors

Supply 5V from you Nano and read the result on an analogue pin, then come up with a calibration table to work out the direction.
I hope that makes sense.
(Sorry I can't draw you a circuit diagram)

Another option (similar to reed switches) is to do it optically.
The vane is on an axle. The axle has a disc attached to it. The disc has a small notch out of the edge.
Positioned around the edge are a whole series of photo-interrupters. The disc spins between the infra-red beams and the notch allows only one of them to pass light at a time.
Make the notch the right size so that as one interrupter turns off the next one turns on - you need one on all the time. You could over-compensate slightly so that on occasion two adjacent interrupters are on at once, in which case you can say it's between the two.
A similar system is to use a disc with a series of special slots cut in it (see Gray Code) which allow light to pass through onto a line of photodiodes. In different rotations different combinations of photodiodes are on, and that gives you your direction.

The Arduino has plenty of pins (unless you're using lots and lots of them already). Think KEYPAD.


text:
Use Arduino Yun Shield as ISP for bootloaded ATMega328-PU
My question is how do I replace the Aarduino Uuno board in this circuit:

...With an Arduino Yun shield? I can setup the hardware - ICSP configuration is easy enough - but how do I go about using the IDE to do this? Cheers

It's highly unlikely you will be able to do it from the IDE. Instead you will have to do it from the Yun's command line (SSH) using avrdude and the linuxgpio driver, or the handy run-avrdude script.
$ sudo run-avrdude bootloader.hex

where bootloader.hex is the bootloader file found somewhere in the IDE that you need to copy over to the Yun with scp.
You may find you need to tweak the fuse settings in the script to get the bootloader to work. I am not familiar with AVR fuses, but IIRC there is one that tells it to run the bootloader instead of the sketch. Just copy the values out of the boards.txt in the IDE and place them into a copy of /usr/bin/run-avrdude in your home directory.

The ATMega came with a bootloader intalled, so is the procedure the same for any other sketch? I've tried migrating the hex file onto a usb host and launching run-avrdude command - I was thrown an error message... Is that the correct-ish procedure though?


text:
Arduino FFT library - Open Music Labs installation help
I downloaded the zip file of the FFT library from the below link
http://wiki.openmusiclabs.com/wiki/ArduinoFFT
and it now as I implement the example codes, it gives out a message which says
"Error compiling for Mega or Mega2560".
I have an Arduino Mega2560 and I want to know how to use this library for my board for frequency analysis of sound. Any help on this will be much appreciated.

How about sharing the rest of the error message?

E:\Setup files\arduino-1.6.10-windows\arduino-1.6.10-windows\arduino-1.6.10\libraries\FFT/FFT.h:181:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
"ldi r16, "STRINGIFY(FFT_N/2)" \n" // prep loop counter
^
E:\Setup files\arduino-1.6.10-windows\arduino-1.6.10-windows\arduino-1.6.10\libraries\FFT/FFT.h:74:10: error: 'prog_int16_t' does not name a type
PROGMEM  prog_int16_t _wk_constants[]  = {
      ^      These are the two types of errors being shown. Is there something wrong with the library? @Majenko

Works only on earlier versions of the IDE. That was the reason for the error.


text:
Can't reprogram atmega328p chips using nano as ISP
Using nano clone as an ISP on a breadboard- as shown here - http://www.martyncurrey.com/arduino-nano-as-an-isp-programmer/
Previously, it worked great.  However, recently, chips that I have bootloaded and programmed have, when added to the breadboard for reprogramming, caused the USB connection to drop.  The heartbeat LED on the nano also dims slightly which makes me wonder if it's a power issue?
Either way, this means that I can't program the chip.
Does anyone know how to fix this?  The breadboard circuit will happily program new chips.
The programs on the chips that aren't working often include blink on pin 19 on the DIP chip (D13) - and when I disconnect the link from this to D13 on nano, the USB connection is restored.
But otherwise I am very confused, have got about 7 chips with the same issue and would be great to fix it.
Ideas?  Thanks

When you put a chip-to-program on your programming breadboard, are any of that chip's pins connected other than SCK, MISO, MOSI, RESET, VCC, GND, and crystal?

Aref and avcc also connected to +5v.  But other than that, no.

After replacing naked wire from D13 nano to SCK on chip with a 330ohm resistor, I was able to program 3/7 of the chips.  The others still exhibit the problem of not being recognised.  Ideas?

I don't know what the problem is or why the 330Ω resistor made a difference.  If you have a storage scope, verify that Reset is staying pulled low and that SCK transitions are clean.  See diagrams and discussion on pp. 2,3 of Atmel's AVR910: In-System Programming document.  Note, the resistors in figure 3 there are between the device being programmed and its SPI peripherals, not between the device and the programmer, so are not the same as adding a resistor like you did.  Also, have you tried any other values in series, like 100Ω or 1000Ω?


text:
How can the SAMD21 chip knows when the on-board NINA W102 restarts
I am building a project that requires the SAMD21 microcontroller to send a resetToFactory signal to the NINA W102 on Arduino Nano 33 IoT. My plan is that, once the W102 receives the signal will do NVS formatting and restart itself, and then I need the SAMD21 to restart afterward by an event triggering from the W102(W102 needs to finish the restart cycle first), see the figure.

The communication protocol is SPI as the WIFININA lib does.
I have few attempts by trying to read the GPIO voltage from W102, however, it doesn't work because SPI on SAMD21 side will just hang until the W102 finished the restart even though I remove the waitForSlaveReady() for receiving the reply, so I can't get any event triggering.
By the way, I can't simply use the RESET_N because the program won't know to do the NVS formatting first.
Does anyone have related experience or ideas? Thank you very much.
Best regards,
Edwin Lu

I have solved this later I post the question.
The solution is using the fact which SPI on the SAMD21 will hang while W102 restarts, so I just set the SAMD21 restart immediately after the program continues.
Best regards,
Edwin Lu


text:
ATMega32u4 - Sending and receiving data through TX and RX

Hi everyone,
first time here on the forum, so, apologies if I'm doing anything incorrectly.
Long story short, I built a device that takes voltages in and transform them into midi data. I used an ATMega328P PU and midi data exit through the TX pin of the chip, into an optoisolator and then go to a jack. Everything works great.
I decided to make the next step, switching to an ATMega32u4, my main goal is to have those midi data exiting simultaneously out from the jack and from the USB which also act as a power source for the device.
The device is now recognized by my laptop as a usb device, so I assume all the USB wiring are correct, however, I have no midi data exiting from any of the jack or usb and I don't understand why. Of course I changed all the pin assignment according to the ATMega32u4 datasheet.
I use Arduino IDE for programming and the device is recognized by the IDE as "Arduino Leonardo": it has to be said that I've always used Arduino UNO and Nano, so I don't know if there are any differences in terms of code when it comes to different boards.
My assumption is that, for some reason, TX pin remains silent. I guess there must be something wrong with my code setup: I simply typed
Serial.begin(9600);

Are there any specific Leonardo libraries I have to be aware of?

Serial is the USB CDC/ACM port, not the TX/RX pins. You need Serial1 for that.

We can't really help you properly unless you show us your code. Without that we're only guessing.

Also, for what it's worth, MIDI carried over USB uses its own device class; it's not normally carried over USB via "Serial" (CDC) class.

https://arduino.stackexchange.com/tour


text:
LCD randomly goes one character further in the ascii table
Here's my code:
#include <LiquidCrystal.h>
int rs = 11;
int rw = 10;
int en = 9;
int d0 = 1;
int d1 = 2;
int d2 = 3;
int d3 = 4;
int d4 = 5;
int d5 = 6;
int d6 = 7;
int d7 = 8;
LiquidCrystal lcd(rs, rw, en, d0, d1, d2, d3, d4, d5, d6, d7);

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  Serial.begin(4800);
  lcd.setCursor(0,0);
  lcd.print("Loading...");
  delay(3000);
  lcd.setCursor(1,1);
  lcd.print("waht");
}

void loop() {

}

And here's the output:

Also note the first line of text starts in the second column. I've tried with a different LCD and the same issue occurs. It seems to go one character further in ascii (ex: the '.'s become '/') if that's any clue to what's going on. In a separate program (exact same setup) I can print "Hello World" on the first line no problem. Anyone know why it's doing this and how to fix it? Thanks

Looks like it gets one or two least significant bits wrong. So check wiring and so

Btw, Arduino pins 0 and 1 are wired to USB serial (on many boards) - so you can try it without Serial.begin and if it works, just move pin(s) to not use arduino pin 1

Your Least Significant Bit is always 1 (Check the ASCII table to see this).
You might have a problem with your wiring, double check the pin you use and that the continuity is good.
Also, as KIIV said in comment, depending on the board you use, you might have a conflict with the serial port (Which pull the line high when not transmitting, explaining the result you get). Try moving pin 1 to another one.


text:
What is the overhead of a saturated serial connection at 256k baud?
I have am putting together multiple arduinos on a RS485 network (connected to Rx/Tx on the arduino and using Serial - connection via one of these https://www.ebay.co.uk/itm/272929871278) - RS485 because it is spread over quite a distance - total linear wiring approx 200m.
My question is: If I have Master, Slave1 and Slave2 on the bus, and the link is running at full speed in comms between Master and Slave1 - then what is the expected interrupt handler overhead on Slave2 in putting the incoming traffic into the ring buffer? (since as it is RS485 all devices not sending see all the traffic)
My "finger in the air" estimate is around 5%-15% at 256k baud and would scale fairly linearly with baud rate.
Does anyone have a definitive answer on this or can point to any profiling done on this?

A lot depends on your software. I have no information on the part you are using, can you post a link showing technical information not sales information.

@Gil the technical isn’t really relevant. Just treat it that everything sent by any Arduino hardware serial on the link is received by every other Arduino via hardware serial

@Gil as for the software. It doesn’t really matter. Let’s assume loop is just a busy loop doing simple mathematical operations and counting how many times it goes round the loop in 10 seconds.

@Simm Count the clock cycles used by the ISR in different situations (buffer usage percentage - empty, half full, overflow, etc). Calculate the number of clock cycles that would pass during one byte's transmission period. Do some math. There's your answer.

So I decided a little empirical testing was in order. This is using a nano (328P)
Using a simple for loop in loop() (calculating the squares of 0 to 255) over 10 seconds with and without there being serial traffic and at different speeds.
Note: this is without any inspection of the ring buffer on incoming data - just measuring the overhead of there being traffic on the wire. The traffic on the wire was the maximum an arduino mega was able to send at that baud rate.
No load: 2600462 iterations
256k: 2381219 iterations
2M: 1349142 iterations

256k takes 8.5% of the runtime
2M takes 48% of the runtime

Code block as requested for the unit doing the timing (it includes calls to the libraries I am using for my environment, but I am sure you can abstract those away to something else and should not be significant to the stats)
uint32_t start_time;
void setup() {
    init_serial();
    start_time = millis();
}

uint32_t count = 0;
uint16_t foo;
void loop() {
    byte buff[MESSAGE_BUFFER_SIZE];
    if (millis() - start_time < 10000){
        for(int i = 0; i<256; i++) {
            foo = i * i;
        }
        count++;
    }
    else {
        if (getMessage(buff)) {
            char msg[30];
            sprintf(msg, "Count: %lu ---", count);
            send_debug_message(msg);
        }
    }
}

code would tell us what the test really meant in greater detail than the note.  would also make the test results easier to repeat and verify


text:
How can I read the Timer direction in phase correct PWM?
I have had to use Timer0 with phase correct PWM and a prescaler of 1. This results in a 32khz PWM frequency and obviously impacts millis, delay and micros. (Timer1 and Timer 2 are also in use so changing to those is not an option)
millis() is trivial to work around - multiply by 32 as the TOV0 interrupt handler is called 32 times more frequently (subject to overflow of course)
micros() is somewhat trickier - as normally it is the Timer0 overflow count (as used in millis() though shifted in this case) plus the current value of TCNT0. That works great when TCNT0 is increasing only and resetting to 0 after MAX - but in phase correct PWM it could be going upwards or downwards.
I think what I need to do is find the direction the Timer is currently using - but pouring over the datasheet for the ATmega328P I can't seem to find a way to do so...
Is there a way of reading this, eg from a register I can interrogate for it?
Alternatively can anyone else think of a way to get microsecond (or close - 10 microsecond would be good enough) resolution when all timers are in phase correct mode?
I'm considering a fall-back of reading TCNT0 twice and deriving it from that - with a prescaler of 1I am assuming it is not possible to read it twice faster than it could change - however I'd prefer a neater solution if there is one.

I'm afraid that this not simple, or possible at all. Since every code to check for the direction takes some clocks, you need to count them and take them into account. Additionally, if you use interrupts, you would need to disable them in this critical part. -- Do you really need micros()?

Your fallback solution is the best one, and your assumption is correct: with the prescaler at one, you can't read the counter twice faster than it changes.

Maybe you can use the OC0x register. I don't have an atmega328p at hand now, but you can test it out. The relevant part in the datasheet: In non-inverting compare output mode, the output compare (OC0x) is cleared on the compare match between TCNT0 and OCR0x while upcounting, and set on the compare match while downcounting. In inverting output compare mode, the operation is inverted. (header 14.7.4 Phase Correct PWM Mode)

Use a flag to keep tabs on it

You could sidestep the problem and use _delay_us instead. The only downside is that _delay_us doesn't account for time spend inside ISRs, as it just does a bunch of NOP instructions.

@Swedgin, this question had been asked on another stackexchange site and I had the same thought.  Or same so far as I can tell.  I experimented with this idea yesterday, except using timer1 with prescaler 1024, because this gives about 4 seconds to a swing from one end of the range to the other.  For whatever reason it didn't seem to be setting output compare interrupt flags.  But, I got interrupted by something else before looking into why.

I decided to go with the inspect method and modified wiring.c accordingly - may not fit everyone's use case but solves mine (along with a couple of tweaks changing the #define's to volatile variables and adding a setter for them.
micros updated to:
unsigned long micros() {
  unsigned long m;
  uint8_t oldSREG = SREG, t1, t2;

  cli();
  m = timer0_overflow_count;
#if defined(TCNT0)
  t1 = TCNT0;
  t2 = TCNT0;
#elif defined(TCNT0L)
  t1 = TCNT0L;
  t2 = TCNT0L;
#else
  #error TIMER 0 not defined
#endif

#ifdef TIFR0
  if ((TIFR0 & _BV(TOV0)) && (t1 == timer0_phase_correct ? 0 : 255))
    m++;
#else
  if ((TIFR & _BV(TOV0)) && (t1 == timer0_phase_correct ? 0 : 255))
    m++;
#endif

  SREG = oldSREG;

  if (timer0_phase_correct && t1 > t2){
    t2 = 510 - t2;
  }

  return (m * us_per_timer0_overflow) + (clockCyclesToMicroseconds(timer0_prescale * t2));
}

Note: that won't work with just that change - but changing wiring.c is not a topic I want to go into discussion of and anyone capable of that can easily infer the other changes from what I've put above. Here be dragons.

Where is timer0_phase_correct defined?


text:
Understanding HC-05 and HC-06 usage
I am looking to make some wireless motor controllers, and am going to use an Arduino connected to an HC-05 module as a master controller, with a potentiometer as the speed controller input. There will then be another arduino connected to an HC-06 module as a slave, with the arduino outputting to a PWM motor controller.
I am happy with programming of a single arduino with a potentiometer and the PWM motor controller as an all in one device, however what I would like to understand is how the HC-05 and HC-06 devices are spliced into the scheme. I want to be clear that I don't want someone to come up with the sketch for me as I will not learn anything that way!
I have studied lots of online tutorials about using these devices, and unfortunately they all go straight into using it for an LED blink or something like that, and as a result to my 54 year old brain I am unable to deconstruct the sketch sufficiently to understand which bits of the sketch pertain ONLY to the HC06/05 usage.
For me to understand it I am hoping that someone can point me to (or maybe do) a step by step tutorial that takes the process in three steps;
Firstly a sketch that does something (say you press a button and a buzzer sounds, all on one arduino
Secondly, a completely basic sketch that shows the minimum necessary to connect the master and slave without any actions, buttons, LED's buzzers etc.
Lastly, a sketch that combines the two, where the button is on the master, the buzzer is on the slave, and the sketches that show where those spliced in bits of code go.
In that way, I will be able to differentiate in my head which bits belong to which part of the system. I know it is not a conventional way to learn, but for me it will then allow me to attempt to construct the correct master / slave sketches required for my project. I used this method successfully for making sketched for LCD displays so I am hoping it will work again!
Happy to explain more but as I say, I want to learn for myself and would appreciate tutorials an old git can follow!
Cheers
Les

Any button tutorial should resolve the first ask--it's a common button tutorial topic. Most HC05/06 examples/tutorials firat show how to send or receive data as their first step. It might be helpful to include info on what specific issues you're running in to or provide links to the tutorials/examples you're looking at that are causing confusion. IIRC there should be examples of both buttons and comms included in the IDE examples as well.

I think you misunderstand - yes, I can get an individual button / buzzer sketch, but as for the basic HC-05 / HC06 sketches, I am not certain that they are just 'blank' sketches. The third part is that I want the first sketch to be integrated with the second sketch so that I can see the logical progression from one to another - if those sketches are not all in the same site, I can't be sure that the last sketch is indeed an amalgam of the two.

please add a program listing of the 'blank' HC05 sketch that you are talking about

Hi all, I had someone external to this site direct me to this link http://www.martyncurrey.com/connecting-2-arduinos-by-bluetooth-using-a-hc-05-and-a-hc-06-easy-method-using-cmode/ which has some follow on pages that progress the use, so I am going to go through that and see if this is what I need


text:
How to sue Arduino Nano to control Stepper motor with Firmata
I have a stepper motor and at present it is controlled by a sketch all working fine. I need now to add it to a Win32 app to control it in circuit with existing Servo Motor. The servo Motor is working well via Firmata from Win32 app as follows
in setup part
arduino.pinMode(9, Arduino.SERVO);

In loop
 private void btn_set_servo_Click(object sender, EventArgs e)
        {
            int angle = Convert.ToInt32(Math.Round(numupdwn_degrees.Value, 0));
            arduino.servoWrite(9, angle);//tell the servo motor go to the position
        }

How do you drive the stepper motor using Firmata has anyone got an example I can see please?

You're saying it's working fine. So what is your problem?

The servo motor is working fine but the stepper motor is not working at all. A Servo motor and a Stepper motor are two different animals. I need both to work from the same Win10 controller.

I don't have any of these, so I can only guess. I think you need the AccelStepper firmata module. What client library are you using on the PC?

Thanks for help and understood but that is a library for a sketch not running Firmata protocol that will allow me to run from C# Win32 app with the other items.

Update: I have created a C# .Net App to connect and control the stepper Motor. The code and a Readme file is available at
https://github.com/zizwiz/Arduino_Projects/tree/main/FirmataStepperMotorTest

Initial Answer:
After a bit of thinking time I have managed to start the stepper motor running with Firmata protocol from my C# Win32 app. This post is just a basic outline I use to get it running I need lots more thinking and tinkering till I get what I need but in case this is helpful here it is.
Create a button to press to start.
Create a thread when the button is clicked
   private void btn_stepper_start_Click(object sender, EventArgs e)
        {
           var thread = new Thread(() =>
           {
               while (true)
               {
                   RunStepper();
               }

           });

            thread.IsBackground = true;
            thread.Start();

        }

In the function RunStepper() create the following
 private void RunStepper()
        {
            while (true)
            {
                arduino.digitalWrite(7, Convert.ToByte(255));
                arduino.digitalWrite(8, 0);
                arduino.digitalWrite(9, 0);
                arduino.digitalWrite(10, 0);
                Task.Delay(10);
                arduino.digitalWrite(7, 0);
                arduino.digitalWrite(8, Convert.ToByte(255));
                arduino.digitalWrite(9, 0);
                arduino.digitalWrite(10, 0);
                Task.Delay(10);
                arduino.digitalWrite(7, 0);
                arduino.digitalWrite(8, 0);
                arduino.digitalWrite(9, Convert.ToByte(255));
                arduino.digitalWrite(10, 0);
                Task.Delay(10);
                arduino.digitalWrite(7, 0);
                arduino.digitalWrite(8, 0);
                arduino.digitalWrite(9, 0);
                arduino.digitalWrite(10, Convert.ToByte(255));
                Task.Delay(10);
            }
        }

As mentioned this small basic example is just a start to prove I may be able to do what I need.


text:
Why when I try to connect my ESP8266 to my node sever in my localhost it keep getting disconnect and connect?
I think the issue is within the library because I have try to implement this code according to the tutorial that I found in YouTube Youtube. The discussion of this tutorial is the first they implement the node js server for listening to specific event from socket io, second part they build a simple iOS application using swift to control an RGB light on the ESP8266 and the last part they make ESP8266 to listen to the event that have payload as RGB values. However, in my implementation, I use angular web application to control ON-OFF light on the Arduino but the problem when I try to listen to event that on and off, my ESP8266 don't connect to my server and print all of that message on the serial.
Here is the code for my ESP8266 to connect to my node server.

#include <SocketIoClient.h>
#include<ESP8266WiFi.h>
#include<Arduino.h>
#define USER_SERIAL Serial

SocketIoClient socket;
const char* ssid = "bunvath_guest";
const char* pass = "*************";
void setup() {
  USER_SERIAL.begin(115200);
  searchWifi();
  initWiFi();
  socket.on("message", handleMessage);
  socket.on("light_on",handleMessage);
  socket.emit("message","hello from esp");
  socket.begin("192.168.0.102",3000);
}

void loop() {
  socket.loop();
}
void handleMessage(const char* message, size_t length){
  USER_SERIAL.println(message);
}

  void initWiFi(){
      WiFi.mode(WIFI_STA);
      WiFi.hostname("ESP-host");
      WiFi.setPhyMode(WIFI_PHY_MODE_11G);
      WiFi.enableInsecureWEP(true);
      WiFi.begin(ssid,pass);
      while(WiFi.status() != WL_CONNECTED){
        USER_SERIAL.print(".");
        delay(1000);
      }
      USER_SERIAL.print("");
      USER_SERIAL.println("WiFi connected");
      USER_SERIAL.print("IP Address: ");
      USER_SERIAL.println(WiFi.localIP());
      WiFi.setAutoReconnect(true);
      WiFi.persistent(true);

  }
 void searchWifi(){
  int numberOfNetwork = WiFi.scanNetworks();
  USER_SERIAL.println("-----");
  for ( int i = 0; i< numberOfNetwork;i++){
    USER_SERIAL.print("Network name: ");
    USER_SERIAL.println(WiFi.SSID(i));
    USER_SERIAL.print("Signal Strength: ");
    USER_SERIAL.println(WiFi.RSSI(i));
    USER_SERIAL.println("-------------");
  }
}

Here is my node server code for receiving all connection from client and print the client id when new client is connecting. Moreover, this node server will listen to all the event that client emit and broadcast to other client.

var port = process.env.PORT||3000
const http = require('http')
const app = require('./app')

const cors = require('cors');
let message = ''
const server = http.createServer(app)
const io = require('socket.io')(server,{cors:{
    origin:'http://localhost:4200',
    credentials: true
}}
    )

server.listen(port,()=>{
    console.log("server run on ", port)
})

io.on("connection",(socket)=>{
    console.log(socket.id)
    socket.on('message', data =>{
        // console.log(data)
        socket.broadcast.emit('message',data)
    })
    socket.on('open_light',data=>{
        socket.broadcast.emit('open_light',data)
        console.log(data)
    })

})

Here is the message that I got from serial monitor, I feel like my Arduino has already connected to my server but it keep getting reconnect. Moreover, in my sever I did not see any new client connect to server so I am really what going on with this. Plus, I am sure that my node server is working perfectly fine because I have implement angular web application to emit event, and I saw that event printing in server.
12:57:13.083 -> Network name: Meas Nakry
12:57:13.083 -> Signal Strength: -85
12:57:13.083 -> -------------
12:57:13.083 -> Network name: bunvath_guest
12:57:13.083 -> Signal Strength: -57
12:57:13.083 -> -------------
12:57:13.083 -> Network name: BLaNKxD
12:57:13.083 -> Signal Strength: -89
12:57:13.121 -> -------------
12:57:13.121 -> Network name: Tuy vanny1
12:57:13.121 -> Signal Strength: -85
12:57:13.121 -> -------------
12:57:13.121 -> ....WiFi connected
12:57:17.165 -> IP Address: 192.168.0.100
12:57:17.165 -> [SIoC] add packet 42["message",hello from esp]
12:57:17.269 -> [SIoC] Disconnected!
12:57:17.269 -> [SIoC] event disconnected not found. 2 events available
12:57:17.787 -> [SIoC] Disconnected!
12:57:17.787 -> [SIoC] event disconnected not found. 2 events available
12:57:18.376 -> [SIoC] Disconnected!
12:57:18.376 -> [SIoC] event disconnected not found. 2 events available
12:57:18.992 -> [SIoC] Disconnected!
12:57:18.992 -> [SIoC] event disconnected not found. 2 events available
12:57:19.633 -> [SIoC] Disconnected!
12:57:19.633 -> [SIoC] event disconnected not found. 2 events available
12:57:20.217 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:20.217 -> [SIoC] packet "42["message",hello from esp]" emitted
12:57:20.251 -> [SIoC] Disconnected!
12:57:20.251 -> [SIoC] event disconnected not found. 2 events available
12:57:20.771 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:20.771 -> [SIoC] Disconnected!
12:57:20.771 -> [SIoC] event disconnected not found. 2 events available
12:57:21.435 -> [SIoC] Disconnected!
12:57:21.435 -> [SIoC] event disconnected not found. 2 events available
12:57:22.044 -> [SIoC] Disconnected!
12:57:22.044 -> [SIoC] event disconnected not found. 2 events available
12:57:22.596 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:22.596 -> [SIoC] Disconnected!
12:57:22.596 -> [SIoC] event disconnected not found. 2 events available
12:57:23.178 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:23.178 -> [SIoC] Disconnected!
12:57:23.178 -> [SIoC] event disconnected not found. 2 events available
12:57:23.798 -> [SIoC] Disconnected!
12:57:23.798 -> [SIoC] event disconnected not found. 2 events available
12:57:24.403 -> [SIoC] Disconnected!
12:57:24.403 -> [SIoC] event disconnected not found. 2 events available
12:57:24.945 -> [SIoC] Disconnected!
12:57:24.945 -> [SIoC] event disconnected not found. 2 events available
12:57:25.533 -> [SIoC] Disconnected!
12:57:25.533 -> [SIoC] event disconnected not found. 2 events available
12:57:26.201 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:26.201 -> [SIoC] Disconnected!
12:57:26.201 -> [SIoC] event disconnected not found. 2 events available
12:57:26.792 -> [SIoC] Disconnected!
12:57:26.792 -> [SIoC] event disconnected not found. 2 events available
12:57:27.380 -> [SIoC] Disconnected!
12:57:27.380 -> [SIoC] event disconnected not found. 2 events available
12:57:27.894 -> [SIoC] Disconnected!
12:57:27.894 -> [SIoC] event disconnected not found. 2 events available
12:57:28.711 -> [SIoC] Disconnected!
12:57:28.711 -> [SIoC] event disconnected not found. 2 events available
12:57:29.426 -> [SIoC] Disconnected!
12:57:29.426 -> [SIoC] event disconnected not found. 2 events available
12:57:30.131 -> [SIoC] Disconnected!
12:57:30.131 -> [SIoC] event disconnected not found. 2 events available
12:57:30.655 -> [SIoC] Disconnected!
12:57:30.655 -> [SIoC] event disconnected not found. 2 events available
12:57:31.254 -> [SIoC] Disconnected!
12:57:31.254 -> [SIoC] event disconnected not found. 2 events available
12:57:31.787 -> [SIoC] Disconnected!
12:57:31.787 -> [SIoC] event disconnected not found. 2 events available
12:57:32.375 -> [SIoC] Disconnected!
12:57:32.375 -> [SIoC] event disconnected not found. 2 events available
12:57:33.171 -> [SIoC] Disconnected!
12:57:33.171 -> [SIoC] event disconnected not found. 2 events available
12:57:33.731 -> [SIoC] Disconnected!
12:57:33.731 -> [SIoC] event disconnected not found. 2 events available
12:57:34.435 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:34.435 -> [SIoC] Disconnected!
12:57:34.435 -> [SIoC] event disconnected not found. 2 events available
12:57:34.978 -> [SIoC] Connected to url: /socket.io/?transport=websocket
12:57:34.978 -> [SIoC] Disconnected!
12:57:34.978 -> [SIoC] event disconnected not found. 2 events available
12:57:35.581 -> [SIoC] Disconnected!
12:57:35.581 -> [SIoC] event disconnected not found. 2 events available
12:57:36.180 -> [SIoC] Disconnected!
12:57:36.180 -> [SIoC] event disconnected not found. 2 events available

Hope anyone can find what is the issue in these codes, I am really frustrated about this for 3 days already.

I think you need to allow all origins, at least to begin with. At the moment, only connections coming from the machine running node can access the sever.
Removing credentials as a next step, which I can't see being used, may also move your testing along.
const io = require('socket.io')(server,{cors:{
    origin:'*:*',
    credentials: true
}}


text:
How to difference hardware reset and software reset?
I have an arduino code with an SD card where I save some data. When I load a new code, The SD must update with the new data that I put in the code, but if I reset the Arduino by the reset button, I don´t want the SD data to change.
To sum up, I want to reload SD data only when I update the code, and not with hardware reset
Any ideas?

Which Arduino do you have?

I´m trying with Arduino Uno, but the code should work for Nano and Mega too

Then I'm sorry, you can't. There is no "software reset". Uploading code triggers a hardware reset through "pressing" the reset for you.

Ah, so there isn´t real difference between both reset

You can't. There is no "software" reset. When you upload new code a hardware reset is triggered by the DTR pin of the USB interface chip.
Instead I would suggest maintaining a "data version number" on the SD card. Read it on startup and, if it differs from the expected version number (which you update in your code manually) it creates the data for you and sets the version number.

Well, I didn´t think about that, sounds like a good solution. Thanks!


text:
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
Heres my code:
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

const char* ssid = "wifiSSID";
const char* password =  "wifiPassword";

int sleepTime = 0;
HTTPClient http;

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

  Serial.println("START WIFI");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }

  http.begin("http://ip-address:3000/start?appid=1%2B6vIswDqSmXONCjq4rLtTMd9O2CHEQ4Oe");
  int httpCode = http.GET();
  String payload = http.getString();

  StaticJsonDocument<256> doc;
  deserializeJson(doc, payload);
  sleepTime = doc["sleep"];

  if (sleepTime > 0) {
    Serial.println("Sleeping for: " + sleepTime);
    delay(sleepTime);
    sleepTime = 0;
  }
}

void loop() {
  // Sensor stuff
}

Heres the error:
START WIFI
.........Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC      : 0x4000c271  PS      : 0x00060034  A0      : 0x8008a48c  A1      : 0x3ffb1c60
A2      : 0x3ffb0058  A3      : 0x3f41ae58  A4      : 0x00000014  A5      : 0x3ffbfea0
A6      : 0x3ffbfee8  A7      : 0x00000001  A8      : 0x00000001  A9      : 0x3f41ae59
A10     : 0x000000a5  A11     : 0x30303030  A12     : 0x8008b043  A13     : 0x3ffbfe70
A14     : 0x00000008  A15     : 0x00000001  SAR     : 0x00000012  EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffa

ELF file SHA256: 0000000000000000

Backtrace: 0x4000c271:0x3ffb1c60 0x4008a489:0x3ffb1c80 0x4008c034:0x3ffb1ca0 0x4008bfea:0x3ffb1cc0 0x400d5e5c:0x3f725c88

Core 0 register dump:
PC      : 0x40165582  PS      : 0x00060634  A0      : 0x8015196e  A1      : 0x3ffbc120
A2      : 0x00000000  A3      : 0x00000001  A4      : 0x80084032  A5      : 0x3ffbf870
A6      : 0x00060d20  A7      : 0x00000000  A8      : 0x801503f6  A9      : 0x3ffbc0f0
A10     : 0x00000000  A11     : 0x00000001  A12     : 0x80084032  A13     : 0x3ffbf870
A14     : 0x00000000  A15     : 0x3ffbc218  SAR     : 0x00000000  EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000

ELF file SHA256: 0000000000000000

Backtrace: 0x40165582:0x3ffbc120 0x4015196b:0x3ffbc140 0x4008b031:0x3ffbc160 0x40089882:0x3ffbc180

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

What should I do?

I got this problem too with the latest IDF version..
check the IDF version as it seems the problem with RTOS handling both cores together.
The solution was for me to downgrade the IDF version to 3.0.0

I suppose your are using Arduino IDE (maybe 1.x.x), if so, you should install the exception decoder so your can read such hex codes. They will give an more useful hint about the error location.
Here the link:
https://github.com/me-no-dev/EspExceptionDecoder

"Decode Failed"

Which Arduino core version are you using? Remember you have to compile and upload aging your sketch, then when the exception happens, copy and paste all those code in exception decoder

ooooh I pasted in the actual exception


text:
ATtiny85 and MPU-6050 Gyroscope
I'm doing a project that involves sending MPU-6050 gyroscope data via serial communication to the laptop. Is ATtiny85 micro-controller suitable for this job? Is it powerful enough to do it? I was thinking of using an Arduino nano instead. please give me your opinion.

The attiny85 doesn't (really) support USB. So you'd need to add something like usb-to-serial converter. Just save yourself a lot of headache and just use a Nano.


text:
How does arduino pro micro reset via USB?
The pro micro has no hardware reset circuitry that would allow host PC to cause a reset via USB.  But when programming using the bootloader, the host PC must have a way to reset the pro micro to allow it to enter bootloader mode and then upload code.
How is it reset?  Is the pro micro sensing the serial rate in some kind of way?  And if so, what is it looking for?  Or does the PC just disconnect the USB and then reconnect (but surely this would not work if the board was externally powered)


text:
Do I need an Arduino for BLE?
I have built a prototype that uses RedBear Lab's Blend micro board (http://redbearlab.com/blendmicro/). The board combines Arduino and a BLE chip (Nordic nRF8001). The application is fairly simple

iPhone finds and connects to BLE chip
When user presses a button on iPhone a message is sent to the Blend Micro board
Based on the message (3 choices) the Arduino reads analog input from one of the pins
The reading is passed back to the phone via BLE

Everything works well. My question is

If I were to evolve this into something that can be taken closer to production, do I need the arduino? Seems like the Arduino is only adding a small amount of value in interpreting the message from phone and transmitting the reading
If I don't need Arduino, how do I program the BLE chip (Nordic nRF8001) directly? I have seen some kits on the internet and they all seem much more complex than programming Arduino.

I am a newbie to H/W - deep background in S/W engineering - but definitely motivated and interesting in making my project a reality. Advice and guidance are appreicated.

The nRF8001 can not run custom code, so you need an external microcontroller to use it. However, the nrf5 series (for example nrf51822) has a microcontroller and can run custom code.
Nrf5 is Arduino compatible thanks to sandeepmistry's nrf5 arduino core.
You will need a programmer though, since the nrf51822 uses swd programming. References to recommended programmers are available here.


text:
Enable BLE pairing on request
I have a prototype using RedBear Lab's Blend micro platform (http://redbearlab.com/blendmicro/). I am able to discover the BLE chip on my iPhone and connect / control the unit. However, the device is constantly advertising - how do I enable advertising only on user request.
For example, if I use my bluetooth headphone, it pairs only when I press a button to enable pairing. Can I do the same with this BLE chip?

Voting to close this question as it is not related to Arduino.

The RedBear Lab uses an Arduino @ Heart..

It uses an Atmel at heart, not an Arduino. However, your question relates to the BLE chip.


text:
Using Atmel Studio with Arduino Starter Kit (Uno MCU)
Can someone tell me if it's possible AND safe to use Atmel Studio with Arduino Starter Kit?  I'm a newbie to firmware in general and I don't want to "brick" my Arduino Uno Microcontroller.  I don't quite know if the micro controller has been programmed in read only or special memory to make it Arduino compatible and me messing with Atmel Studio could mess it up.  In other words, I want to know I can get back to programming through the Arduino IDE and continue working on the projects in the starter kit book.  I've done about half of them.
1)  Can someone tell me if it's doable, safe and WHY?
2)  Any hints or gotchas or examples on how to do it?
My motivation is that I'm taking a job as a C# Windows programmer but will be exposed (I believe) to AVR and Atmel Studio and wanted to get familiar with it by just playing a little bit.  Arduino libraries seems to hide a lot of the messy details (such as setting a pin output) which is fine, but it would probably be good to do those messy details myself and be familiar with the actual tools they will use at work.
I have searched for a "tutorial for dummies" that says what settings to pick, etc. to no avail.
Thanks Dave
P.S.  If the answer is NO WAY is it safe or desirable, perhaps a recommendation for an AVR development kit (cheaper is better!).  Actually, this is probably not a bad idea anyhow.
Many Thanks!

There are many tutorials on programming Arduino boards (or any other AVR MCU) with Atmel Studio:
Creating new project:
https://asensar.com/blog/2013/how-to-setup-atmel-studio-for-arduino-development/
Configuring Avrdude for firmware upload:
https://asensar.com/blog/2013/how-to-integrate-avrdude-with-atmel-studio/
http://www.instructables.com/id/How-to-Load-Programs-to-an-Arduino-UNO-From-Atmel-/
Please see this post too:
Atmel studio 7 - my own libraries
Nothing to afraid of, just don't mess with lock fuses (relevant only if you decide to play with ISP programmer and arvdude/avrdudess). Use Arduino USB virtual COM port connection for firmware uploading, just like in Arduino IDE.
With Atmel Studio you don't have rich libraries available like in Arduino platform, instead you will have to program MCU, its peripherals (and other devices connected, if any) by directly accessing MCU registers. This requires some knowledge on MCU hardware (but it is a natural choice if you want to learn that). Eventually you can build your own wrapper libraries similar to one in Arduino.
Check Procyon AVR library too - much better choice than digging Arduino library sources (a bit old but still relevant, I always recommend it as a starting point for AVR library development:)
http://www.procyonengineering.com/embedded/avr/avrlib/

You are fairly mistaken in the library claim, atmel studio comes with the large ASF library

Thank you very much Flanker for your answer (which is marked as such)  It's good to know that I can't mess it up!  I got a surprise looking at Atmel Studio ... it won't work with my Mac without jumping through a bunch of hoops.  I'm trying CrossPack ( https://www.obdev.at/products/crosspack/download.html )  which does work on Macs.  Any experience with it?  Luckily, I also have an old PC kicking around, so I can download Atmel Studio (if PC will actually boot up :))  Thanks again.

@Chris Stratton yes but ASF seems more suitable for ARM based MCUs.

@Dave - Atmel Studio is for Windows only, maybe you can use Parallel Desktop or Virtualbox virtualization tools to "run" Windows inside MacOS. Another option would be to setup avr gcc toolchain in MacOS - http://maxembedded.com/2015/06/setting-up-avr-gcc-toolchain-on-linux-and-mac-os-x/

If you have installed the Arduino IDE, you already have a working avr-gcc that you can use in a more traditional manner with the Arduino overhead, too.  And you can download the atmel ASF library or anything else you want to use in stand alone form.  An IDE and a compiler are ultimately two different things.


text:
Dropping a 75V power supply to power an Arduino Mega
I'm looking to power an Arduino Mega using this IPC-5 power supply from Teknic since I will have a free port (the other powers a servo). I would like to use this extra port to power my Arduino rather than draw power from another source. The problem is that this is 75V coming out which would eat up the Arduino.
Is it as simple as hooking up a resistor in series with the Arduino to bring the voltage down to about 7V for the Arduino? If that's the case, then how can I determine the unknowns to find the appropriate resistor?
Correct me if I'm wrong, but if I apply Ohm's Law and Kirchhoff's Rules, I can set up this relationship: 75V = IR + 7V. Can I make an assumption for the current to solve for the resistance?
This is my first real Arduino project, so my knowledge of many things that y'all may consider common knowledge is lacking.

The short answer is NO, you can't do that. Consider the size of the resistor needed to dissipate all that wattage and the fact that the current is not stable so it is practically impossible.
What you need is a DC to DC converter.

Thanks for your answer! I believe this is the solution to my problem.

Is it as simple as hooking up a resistor in series with the Arduino to bring the voltage down to about 7V for the Arduino?

No, it certainly is not.

Can I make an assumption for the current to solve for the resistance?

No, you cannot. You never assume anything in electronics without a very very good reason.
You require a suitably rated voltage regulator (a switching DC/DC regulator for those kind of voltages) to convert the voltage properly.

Are there any options out there for a 75V to 7-12V drop? My initial search is telling me that this drop is huge.

Yes, there are options out there. Here's an example of 75v to 5v: https://www.distrelec.de/en/dc-dc-converter-industrial-18-75v-5v-15w-xp-power-dtj1548d05/p/30183412


text:
Unable to acquire AP network IP and DNS on a ESP32 MCU
I'm getting the following error on serial output (verbose mode) when my smart device , ESP32 S3 tries to connect over WIFI to the Access point (AP). The SSID is TheScientist
Below is the serial output:
Connecting to TheScientist
[  1064][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 0 - WIFI_READY
[  1098][V][WiFiGeneric.cpp:338] _arduino_event_cb(): STA Started
[  1099][V][WiFiGeneric.cpp:97] set_esp_interface_ip(): Configuring Station static IP: 0.0.0.0, MASK: 0.0.0.0, GW: 0.0.0.0
[  1099][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 2 - STA_START
.......[  4750][V][WiFiGeneric.cpp:360] _arduino_event_cb(): STA Disconnected: SSID: TheScientist, BSSID: 3c:cd:5d:a7:f1:13, Reason: 15
[  4750][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 5 - STA_DISCONNECTED
[  4758][W][WiFiGeneric.cpp:950] _eventCallback(): Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT

Although the verbose debug serial output shows a
Reason: 15 - 4WAY_HANDSHAKE_TIMEOUT
in reality the timeout is due to usage of a password longer than the 32 char allowed on ESP32 MCUs . In summary, any ESP32 MCU to successfully connect to any WIFI Access Point , the Network password must not exceed 32 char long.

it also can't be shorter than 8 chars...


text:
Arduino Uno won't connect when using USB-C to USB adapter
So I just got my first Arduino which is an Arduino Uno. I have a newer MacBook Air which doesn't have any USB ports so I thought I'd just use one of those USB-C to USB adapters.
I plugged it in and then searched for the Board in the Tools > Port menu. It was nowhere to be seen, only the /dev/cu.Bluetooth-Incoming-Port showed up.
To be clear, the Arduino did show signs of connectivity, it just didn't show up under the Port list. I'm also not 100% sure if it's an Arduino Uno since the company I bought it from said I should select Arduino/Genuino Uno in the Board menu which isn't an option anymore.
Is it a problem with my Arduino, my Laptop or my adapter?

Maybe it is not original, and it uses different usb-serial chip than the original one. Popular converters for Arduino Uno clones are CH340 and CP2104. You may try to install the driver for these 2 chips.

It now shows up in the Ports tab after installing the CH340 driver. Thanks a lot!


text:
Changing single bit in byte array
So I have a byte-array representing the display attached to my Arduino:
byte theDisplay[8] = {
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000,
    B00000000
};

Now I want to flip a single bit at an arbitrary position:
theDisplay[3][6] = 1;

This (probably) faulty method produces these errors:
In function 'void setup()':
sketch_sep14c:13:18: error: invalid types 'byte {aka unsigned char}[int]' for array subscript
   theDisplay[3][6] = 1;
                  ^
exit status 1
invalid types 'byte {aka unsigned char}[int]' for array subscript

Is there an easy way to flip a single bit working with indexes like shown above?

https://www.arduino.cc/reference/en/ Bits and Bytes section

@Juraj I was aware of that, but I couldn't figure out how to set the 6th bit of the 3rd item in the array to 1.

The error occurs, because you try to use the syntax for a 2 dimensional array with a 1 dimensional array (since you have an array of bytes, not bits, and a microcontroller always works with at least one byte). For accessing the individual bits you need to use bitwise operators. For example this:
theDisplay[3] |= (1 << bitnumber); // for setting the bit
theDisplay[3] &= ~(1 << bitnumber); // for clearing the bit

with bitnumber being the number of the bit to change counted from least significant bit (in the binary representation in your code the rightmost digit) to most significant bit (the leftmost digit).
If you want to know, what exactly this does, you can google for bitwise operators in C++.

Arduino way is the bitSet function https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitset/

Thanks for your answer. Do I understand correctly that the top one sets the bit to 1 and the lower one sets the bit to 0?

There is also theDisplay[3] ^= (1 << bitnumber); for toggling the bit.

@gurkensaas Yes, that is what "setting" and "clearing" means.


text:
Read bytes from PROGMEM array
Disclaimer: I just started using C++ and I'm a bit of a beginner. Keep that in mind as your answering.
So I recently bought my first Arduino. It's a customized one and it has an 8x8 display attached to it. To display something on the display, the company I bought it from recommends storing the instructions for the display in a two-dimensional byte array.
I now have a longer animation I want it to play, so I researched and found PROGMEM which lets me store much more data. So I write something along the lines of:
const byte frames[2][8] PROGMEM {
  {
    B10000100,
    B10000100,
    B10000100,
    B10000100,
    B10000100,
    B10000100,
    B10000100,
    B10000100,
  },
  {
    B10010100,
    B10010100,
    B10010100,
    B10010100,
    B10010100,
    B10010100,
    B10010100,
    B10010100,
  }
};

void setup() {
  arduino.begin();
}

void loop() {
  arduino.printImage(frames[0]);
  delay(1000);
  arduino.printImage(frames[1]);
  delay(1000);
}

After compiling, it throws a few errors at me:
warning: invalid conversion from 'const byte* {aka const unsigned char*}' to 'byte* {aka unsigned char*}' [-fpermissive]
   arduino.printImage(frames[0]);
                      ~~~~~~~~^

This did not worry me as much and I just ignored those. After uploading, however, the display just showed arbitrary patterns instead of the lines I told it to draw.
After I removed the PROGMEM, it worked flawlessly, however, the memory wasn't big enough to store the array (not the one I provided as an example).
I could think of two reasons:

In the official documentation of PROGMEM, it states that you have to get the variables back into memory. However, none of the methods they provided worked for me.
In a similar question on ASE, both answer and comments state that nested arrays aren't supported, but my knowledge of C++ isn't good enough to understand the answer.

@Juraj It's downloadable through the IDE. It's called Gamer.h.

@Juraj In the "Arrays of strings" it tells me to do something like this: strcpy_P(buffer, (char *)pgm_read_word(&(frames[1])));   arduino.printImage(buffer);
However, it just tells me that 'buffer' was not declared in this scope

On the question you are referencing, the accepted answer suggests
to modify the library. This could be the most efficient option. A less
invasive solution, however, would be to copy the data from the flash
memory to RAM, and use the printImage() function as is.
Obviously, copying everything to RAM defeats the purpose of PROGMEM. But
you only need to copy one frame at a time, and only hold it in memory
for little more than the duration of the call to printImage():
void printProgmemFrame(const byte flashFrame[8]) {
  byte ramFrame[8];
  memcpy_P(ramFrame, flashFrame, 8);
  arduino.printImage(ramFrame);
}

void loop() {
  printProgmemFrame(frames[0]);
  delay(1000);
  printProgmemFrame(frames[1]);
  delay(1000);
}

I tried your approach and it sadly still just displays arbitrary patterns. Do I need to do anything else except for inserting your printProgmemFrame-function and replacing the loop function?

@gurkensaas: In principle you need nothing else. I cannot test this, as I do not have the hardware. It works for me, however, with a mock of the arduino object.

The code compiles fine, it uploads fine, but the problems of the arbitrary patterns stay the same.

I think you are returning ramFrame which is allocated on the stack when you call printProgmemFrame. Try again adding static to the variable declaration:
static byte ramFrame[8];

@EugenioPace It generated another random pattern.

Shouldn't there be something extra in the declaration of printProgmemFrame()? Something like void printProgmemFrame(const byte flashFrame[8] PROGMEM)?

@PeterMortensen: Alas, no. Unlike the __flash keyword, which works like a type qualifier (like volatile or const), PROGMEM is really only a kludge to get the compiler allocate the variable in a specific program section. This works only when the variable is actually declared: it makes no sense for a pointer to be declared as “pointer to PROGMEM data”. It's a pity __flash is only supported in C mode (not in C++).