text:
#include <ESP8266WiFi.h> Error with WiFiClientSecureBearSSL.h
I am new to the Arduino world and it seems that this simple problem is keeping me at the start line.

I use the Generic ESP8266 Module as Board
In my sketch I just write:

#include < ESP8266WiFi.h >
void setup(){}
void loop(){}

The ERROR is :
BearSSLHelpers.h:148:34: error: 'virtual const unsigned char* BearSSL::HashSHA256::oid()' marked override, but does not override
 virtual const unsigned char *oid() override;

                              ^

How am I going to solve that? Any help is appreciated.

with esp8266 Arduino core 2.5.2 I can compile it without errors

Well, I can't..

Installed the ESP8266 Arduino core 2.5.2 and tried to run this simple code above

File > Preferences  and on Additional Boards Manager URLs i pasted
http://arduino.esp8266.com/stable/package_esp8266com_index.json

Tools > Board > Board Manager > typed "ESP8266" and installed ESP8266 by ESP8266 Community version 2.5.2

there is virtual const void *hash() override on line 148 in release

Thank you. But what I have to do to fix this?

how did you get parts of the git version? did you download and install the library separately? delete it from your libraries folder

Ok after deleting the library folder from my libraries folder it worked!
Thank you so much!
So just to get this straight, when I install a library, I don't have to have the library folder in my Arduino > libraries folder ??

not the libraries which are part of the boards package

Thank you very much!

You installed the latest git version of the ESP8266WiFi library into your libraries folder and this version is not compatible with the 2.5.2 version of the esp82666 Arduino core.
The ESP8266WiFi library is part of the esp8266 boards package. It should not be installed separately. Delete the library from your libraries folder.


text:
MPU6050 stuck on same values while getting the angle as output
I am trying get the rotation value from MPU6050. I am using an Arduino Uno board.
My connections are:
MPU6050  Arduino

VCC    ->  5V
GND    ->  GND
SCL    ->  A5
SDA    ->  A4
INT    ->  2

The code I am using is:
#include <MPU6050_tockn.h>

#include <Wire.h>

MPU6050 mpu6050(Wire);

void setup() {

  Serial.begin(9600);

  Wire.begin();

  mpu6050.begin();

  mpu6050.calcGyroOffsets(true);

}

void loop() {

  mpu6050.update();

  Serial.print("angleX : ");

  Serial.print(mpu6050.getAngleX());

  Serial.print("\tangleY : ");

  Serial.print(mpu6050.getAngleY());

  Serial.print("\tangleZ : ");

  Serial.println(mpu6050.getAngleZ());

  delay(4000);

}

On my serial monitor I am always getting -35.26, 35.26, -0.0 values. What should I do?

source: Stack Exchange

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

sort: votes


text:
arduino uno freezes
Is there a reason why my Arduino Uno freezes after a few minutes of running with power coming from a usb cable connected to my pc?
#include <GY6050.h>
#include <Wire.h>
#include <VarSpeedServo.h>

#define angle1 20
#define angle2 90

#define Sensor_BL A0
#define Sensor_BR A1

VarSpeedServo servo;

GY6050 gyro1(0x68);
GY6050 gyro2(0x69);

int X = 0;
int Y = 0;

int y1_axis = 0;
int y2_axis = 0;

int sensorBL;
int sensorBR;

int speed = 0;
int angle = 0;

int prev_y1_axis = 0;
int y1_hold = 0;
unsigned long timer;
int start = 1;
byte step = 0;
String steps , laststep;
int freq;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  gyro1.initialisation();
  gyro2.initialisation();
  delay(100);
  servo.attach(8);
  servo.write(90);
}

void loop() {
  y1_axis = gyro1.refresh('A', 'Y');
  y2_axis = gyro2.refresh('A', 'Y');
  sensorBL = analogRead(Sensor_BL);
  sensorBR = analogRead(Sensor_BR);

  //0 right - 90 centr - 180 left

  if (sensorBL > 250) {
    speed = map( sensorBL , 0 , 1023 , 0 , 255);
    if (sensorBL < 700) { //less pressure 90+20=110
      servo.write(95 , speed);
      angle = 95;
    }
    else if (sensorBL > 700) { //more pressre 90+90 = 180
      servo.write(105 , speed);
      angle = 105;
    }
  }
  else if (sensorBR > 250) {
    speed = map( sensorBR , 0 , 1023 , 0 , 255);
    if (sensorBR < 700) {
      servo.write(95 , speed);
      angle = 95;
    }
    else if (sensorBR > 700) {
      servo.write(105 , speed);
      angle = 105;
    }
  }
  else if ((start == 0 || millis() - timer > 800) && y1_axis > -90 && y1_axis < 20 && y2_axis > -90 && y2_axis < 20 && sensorBL < 10 && sensorBR < 20) //flat dead end no servo movement - center position - can we separate on different lines the pressure sensor and accell so that I can set the dead end value separately for the press sens and acc ?
  {
    servo.write( 85 , 15);
    //Serial.println("Servo goes to zero");
    start = 1;
    step = 0;
    angle = 0;
    steps = "0";
  }
  else if ((y1_axis < 60 & y1_axis >40) && (step == 0 || step == 2))
  {
    step = 1;
    steps = "1";
  }
  else if ((y2_axis < 55 & y2_axis > 40) && (step == 0 || step == 1))
  {
    step = 2;
    steps = "2";
  }

  if (!steps.equals(laststep)) {

    if ((step == 1 || step == 2) && millis() - timer <= 700) {
      if (freq > 1) {
        servo.write(70 , 20);
        angle = 70;
      }
      else {
        servo.write(78 , 20);
        angle = 78;
      }
      freq++;
    }
    else if ((step == 1 || step == 2 && millis() - timer > 750)) {
      servo.write(78 , 20);
      angle = 78;
      freq = 0;
    }

    timer = millis();
  }
  //Serial.println("Y1: " + String(y1_axis) + " Y2: " + String(y2_axis) + " S1: " + String(sensorBL) + " S2: " + String(sensorBR) + " Millis: " + String(millis() - timer) + " Step: " + String(steps) + " Last: " + String(laststep) + " Angle: " + String(angle));
  Serial.println("Millis: " + String(millis() - timer) + " Angle: " + String(angle));

  laststep = steps;

}

I am using the pc usb power cable to power on the arduino and 2 accelerometers and one SG90 hobby servomotor. Would the best way power on the 1 servo with its own power supply ?
What power supply would you suggest for 1 servomotor?
When not connected to the pc, I use 9v battery to power on together the arduino and the one servomotor
thanks!

It is the part of the code for moving forward and backward in this locomotion system I came up with
https://github.com/marcob2178/Arduino-Based-Game-Locomotion
https://www.youtube.com/watch?v=OYTlF2GhXpQ
Sensors are mounted on shoes

what does it do when it is working correctly?

Is it possible the servo motors draw too much current?

Is your 9V battery a 9V block battery? If yes, you should move to a different battery type, since 9V block batteries are meant for low power applications. They cannot provide much current and any motor (a servo is also a motor) can draw loads of current (especially when stalled)

yes, it is a 9v block battery. Would a 6AA 9V Battery solution be enough to power the arduino uno or mega + 2 accelerometers + 1 servo motor ?

You haven't said or shown how your servo is powered but both the Arduino power supply is limited and your computer's USB power has a protective limit. You can power an SG90 hobby servo from the Arduino, but any larger servo needs its own supply, with only the PWM signal being taken from the Arduino. If the servo (or any other device or collection of devices) exceeds the capabilities of the Arduino's power supply, its output voltage will fall. One of the consequences of that is that the MCU stops. Or if your computer's USB supply is exceeded, it will shut down protectively.
My guess is you're powering your motor from the Arduino and it's starving the MCU.

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


text:
TIMER1 CTC Interrupts not working with avr-gcc
I am attempting to program my arduino in plain C, and I've come across some very strange behavior. If I load the following code from the Arduino IDE, it works as expected and toggles Pin 6 every 100ms. However, if I compile it with avr-gcc and then load it with avrdude, no interrupts are run.
Here is the C code:
#include <avr/io.h>
#include <avr/interrupt.h>

int main();
void timer1_init();

int main()
{
    // connect led to pin PD6
    DDRD |= (1 << 6);
    PORTD |= (1 << 6);

    // initialize timer
    timer1_init();

    // loop forever
    while(1)
    {
        // do nothing
        // whenever a match occurs, ISR is fired
        // toggle the led in the ISR itself
        // no need to keep track of any flag bits here
        // done!
    }
}

// initialize timer, interrupt and variable
void timer1_init()
{
    /*cli();*/
    /*TCCR1A = 0;*/
    /*TCCR1B = 0;*/
    /*TCNT1 = 0;*/
    OCR1A = 24999;
    TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10);
    TIMSK1 |= _BV(OCIE1A);
    sei();
}

ISR (TIMER1_COMPA_vect)
{
    // toggle led here
    PORTD ^= (1 << 6);
}

And here is the Makefile I'm using to load it onto the arduino:
CC = avr-gcc
CFLAGS = -g -O0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106

SOURCE = test

all: load

$(SOURCE): $(SOURCE).o
    $(CC) $(SOURCE).o -o $(SOURCE)

hex: $(SOURCE)
    avr-objcopy -O ihex -R .eeprom $(SOURCE) $(SOURCE).hex

load: hex
    avrdude -F -V -c arduino -p ATMEGA328P -P /dev/tty.usbmodem1411 -b 115200 -U flash:w:$(SOURCE).hex

clean:
    rm -f *.o *.hex
    rm -f `find . -perm 755 | perl -pe 's/\.\n//g' | perl -pe 's/\.\/(\w+)\n/\1 /g'`

Is there something that the arduino ide automatically adds to it that makes it work? What am I missing?
Edit: Here is the make output:
avr-gcc -g -O0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106   -c -o test.o test.c
avr-gcc test.o -o test
avr-objcopy -O ihex -R .eeprom test test.hex
avrdude -F -V -c arduino -p ATMEGA328P -P /dev/tty.usbmodem1411 -b 115200 -U flash:w:test.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
         avrdude: erasing chip
         avrdude: reading input file "test.hex"
         avrdude: input file test.hex auto detected as Intel Hex
         avrdude: writing flash (196 bytes):

         Writing | ################################################## | 100% 0.04s

         avrdude: 196 bytes of flash written

         avrdude: safemode: Fuses OK (E:00, H:00, L:00)

         avrdude done.  Thank you.

Can we see the full make output?

I'd uncomment the lines TCCR1A=0; TCCR1B = 0; TCNT1 = 0;.

I tried uncommenting them, it didn't change anything

It seems the make output does not match the makefile you posted: how the first avr-gcc got called from your makefile is a mystery to me...

It's automatically generated from the target "$(SOURCE).o

I just tried using arduino-mk https://github.com/sudar/Arduino-Makefile, and it worked, so I guess I'm just going to stick with that.

Personally, I would recommend using a timer library to achieve interrupts. They are object oriented and so much cleaner and memory efficient.

So it was your makefile that was incorrect?

Yes, it was the makefile

The issue is probably not the Makefile per se, but that your ISR must match the name of something listed in a vectors table in a source file placed in a section placed in the right place by the linker map.  Using an arduino-ish Makefile included a setup for such matching the ISR name you used.

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


text:
How can I get the Arduino IDE v0021 running on Windows XP to communicate with the latest Nano v3.0
After reading another post
CH340 Nano avrdude: stk500_getsync() not in sync resp=0xa4
I have discovered that the bootloader on current Nano v3.0 has been upgraded. However, the advice given to overcome this problem is based around a more modern version of the Arduino IDE communicating with an old bootloader. I have the reverse problem. I damaged my Arduino Nano that was working with a laptop running Windows XP and bought a replacement. It obviously has the latest bootloader installed so my version of the Arduino IDE v0021 (recommended to run on Windows XP) can no longer upload sketches to the board.
I have uploaded GRBL v1.1h to the Nano board from an Arduino IDE v1.8.19 installation on a Windows 7 computer but the older version of GRBL Control v0.8.1 running on Windows XP has compatibility issues with GRBL 1.1h. I need to upload an earlier version of GRBL that is compatible with GRBL Control v0.8.1 but the bootloader on the new Arduino Nano v3.0 runs at 115200 and the Arduino IDE v0021 expects a baud rate of 57600 so I get these errors

stk500_getsync():not in sync: resp=0x09
stk500_disable(): protocol error, expect=0x14, resp=0x51

Can I upload an older bootloader to a newer Arduino Nano so I can then flash an older version of GRBL that is compatible with GRBL Control v0.8.1 to run on Windows XP?

replace the bootloader. the new Nano has the same ATmega328p MCU as the old

So it is possible to burn an old bootloader to a new Arduino Nano?

in what sense is your Nano "new"? how can the bootloader knew if it is old or new Nano? where would be a difference for the bootloader?

OK point taken. I will make the attempt and report the outcome.

Since at the end of the day it is Avrdude, which talks with the Nano, you can always read its documentation and use an appropriate command line to flash anything you want.

I guess a better advice would be to select Uno as board for the Nano with 'new' bootloader

I agree with Juraj that any bootloader can be uploaded to the newer version of the Nano. However, the process of doing so is not simple. With Windows XP SP3 installed on my laptop I was running Arduino IDE v0021. The process involves connecting an Arduino UNO R3 to the Arduino Nano v3.0 but first you have to communicate with both boards through the Arduino IDE v0021. This requires two different USB drivers. For Device Manager to recognise the UNO R3 I had to copy the "Drivers" folder from my Arduino IDE v1.8.19 installation on my Windows 7 computer to my Arduino IDE v0021 installation folder on my laptop. Inside that drivers folder is a file called "Old_Arduino_Drivers.zip". You need to expand that into the "Drivers" folder.
In Device Manager with the Arduino UNO R3 plugged in you can now update the driver for the "Unknown USB" device by searching in the "Drivers" folder. On my computer it installed it as Arduino UNO R3 on COM7. It may be a different COM port on your computer. NOTE: FTDI and CH340 drivers will NOT work on Windows XP with the Arduino UNO R3.
Now disconnect the Arduino UNO R3 and connect the Arduino Nano v3.0. Once again Device Manager should not recognise it. Search the "Drivers" folder once again and it should find a driver. However, this time it will use an FTDI driver to install the Nano. It showed up in Device Manager as USB Serial Port on COM5.
After both these drivers were successfully installed my Arduino IDE v0021 could communicate with both Arduino boards and it could upload sketches to the Arduino UNO R3 but not the Nano...yet. I connected the Arduino UNO R3 and uploaded, "ArduinoISP" from the menu File >> Examples.
I then unplugged the USB cable from the Arduino UNO R3 and physically connected wires between the UNO and the Nano (see the connection diagram here).
With both boards wired correctly, plug the USB cable back into the Arduino UNO R3. You should see LEDs light up on both boards. Open the Arduino IDE v0021 and from the Tools menu select "Arduino Duemilanove or Nano w/ ATmega328" as the board. NOTE: Do NOT select "Arduino Uno" even though it is the board connected to your computer. You are about to burn a new bootloader to the Nano not the Uno. Next select whatever serial port has been allocated to the device. In my case COM7 was allocated to the UNO.
Now from the "Tools" menu select "Burn Bootloader >> w/ Arduino as ISP". This worked for me and I was finally able to upload sketches to the Arduino Nano v3.0 using the old version 0021 of the Arduino IDE on Windows XP.

btw it is better to use the Nano as Uno. you have then the smaller ('new') Optiboot bootloader and a right fuse setting for the bootloader size leaves more flash memory for the sketch


text:
Just one more pin!
I have an Arduino project to control a motor's speed at 3 levels, indicated by 3 LEDs, so level 1 is speed 1 and LED 1, and so on for levels 2/3.
Also, I added a low-battery voltage indicator to monitor the battery level.
I am going to use an ATtiny45, which has 8 pins(Vcc, GND, 1 analog pin, 5 digital pins). The project needs 6 digital pins and 1 analog pin, so only one more pin is needed.
I do not want to use an expander or I2C, as they will make the project more complex, and it is only one pin!
I can use a larger microcontroller but it would be the last choice.
Here is my project's diagram and code:

//********************************************^************************************************
//  https://forum.arduino.cc/t/control-motor-speed-with-npn-and-push-button-no-driver/1184925
//
//
//
//  Version    YY/MM/DD    Comments
//  =======    ========    ====================================================================
//  1.00       20/23/02    Running code
//  1.10       20/23/03    Added motor and LEDs OFF if switch pressed for >= 3 sec.
//
//
//

#define PRESSED            HIGH
#define RELEASED           LOW

#define ENABLED            true
#define DISABLED           false

#define LEDon              HIGH
#define LEDoff             LOW

#define MOTORoff           0

#define lipo               A0

float lipoV = 0;

//GPIOs
const byte Button        = 2;
const byte ledpin        = 3;
const byte ledpin1       = 4;
const byte ledpin2       = 5;
const byte Motor         = 9;
const byte heartbeatLED  = 13;
const byte Red           = 6;

//Variables
byte lastButton          = RELEASED;
byte currSwitch;

int Speed_Level;

bool bCheckingSwitch     = DISABLED;

//timing stuff
unsigned long heartbeatTime;
unsigned long switchesTime;
unsigned long threeSecondTime;

//                                      s e t u p ( )
//********************************************^************************************************
void setup()
{
  pinMode(Button, INPUT);
  pinMode(lipo, INPUT);

  pinMode(ledpin, OUTPUT);
  pinMode(ledpin1, OUTPUT);
  pinMode(ledpin2, OUTPUT);
  pinMode(Motor, OUTPUT);
  pinMode(heartbeatLED, OUTPUT);
  pinMode(Red, OUTPUT);

} //END of   setup()

//                                       l o o p ( )
//********************************************^************************************************
void loop()
{

  //************************************************              T I M E R  heartbeatLED

  //is it time to toggle the heartbeat LED ?
  if (millis() - heartbeatTime >= 500ul)
  {

    //restart this TIMER
    heartbeatTime = millis();

    //toggle the heartbeat LED
    if (digitalRead(heartbeatLED) == HIGH) digitalWrite(heartbeatLED, LOW);
    else digitalWrite(heartbeatLED, HIGH);
  }

  //************************************************              T I M E R  check switches
  //is it time to check our switches ?
  if (millis() - switchesTime >= 50ul)
  {
    //restart this TIMER
    switchesTime = millis();

    checkSwitches();
  }

  //************************************************              T I M E R  three seconds
  //if enabled, is it time to turn things OFF ?
  if (bCheckingSwitch == ENABLED && millis() - threeSecondTime >= 2000ul)
  {
    //we are finished with this TIMER
    bCheckingSwitch = DISABLED;

    //restart the sequence
    Speed_Level = -1;

    analogWrite(Motor, MOTORoff);
    digitalWrite(ledpin, LEDoff);
    digitalWrite(ledpin1, LEDoff);
    digitalWrite(ledpin2, LEDoff);
    digitalWrite(Red, LEDoff);
  }

} //END of   loop()

//                               c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
  byte state;

  //************************************************              Button
  state = digitalRead(Button);

  //has there been a state change in the switch ?
  if (lastButton != state)
  {
    //update to the new state
    lastButton = state;

    //*******************************
    if (state == PRESSED)
    {
      //enable the TIMER
      bCheckingSwitch = ENABLED;

      //start the TIMER
      threeSecondTime = millis();
    }

    //*******************
    //the switch was released
    else
    {
      //disable the TIMER
      bCheckingSwitch = DISABLED;

      Speed_Level++;
      lipoV = analogRead(lipo);

      //battery checker
      if(lipoV < 680){
        digitalWrite(Red,LEDon);
      }

       else
       {
        digitalWrite(Red,LEDoff);

       }

      //don't go over 3
      if (Speed_Level >= 4)
      {
        Speed_Level = 0;
      }

      //*******************
      if (Speed_Level == 1)
      {
        analogWrite(Motor, 50);
        digitalWrite(ledpin, LEDon);
        digitalWrite(ledpin1, LEDoff);
        digitalWrite(ledpin2, LEDoff);
      }

      //*******************
      else if (Speed_Level == 2)
      {
        analogWrite(Motor, 75);
        digitalWrite(ledpin, LEDoff);
        digitalWrite(ledpin1, LEDon);
        digitalWrite(ledpin2, LEDoff);
      }

      //*******************
      else if (Speed_Level == 3)
      {
        analogWrite(Motor, 100);
        digitalWrite(ledpin, LEDoff);
        digitalWrite(ledpin1, LEDoff);
        digitalWrite(ledpin2, LEDon);
      }

      //*******************
      else
      {
        analogWrite(Motor, MOTORoff);
        digitalWrite(ledpin, LEDoff);
        digitalWrite(ledpin1, LEDoff);
        digitalWrite(ledpin2, LEDoff);
        digitalWrite(Red,LEDoff);
      }

  }

}
}//END of   checkSwitches()

//********************************************^************************************************

Can I use tA0 as input and output at the same time like this?

Or can I reduce the LED pins, meaning use 1 pins for 2 LEDs?

You can combine your button and an LED by switching it in loop between input, reading it, then back to output. As long as you do that 50+ times a second the LED will look normal, and the button will block out the LED, providing visual feedback as a bonus.

@dandavis can you please give an example

Actually, thinking about it more, I would just replace your 3 status LEDs with neopixels, and drive all three+ from one pin. To combine, you take a 1k from 5v to the LED then ground. Button is parallel to the LED. LED on and off is just digitalWrite(x,1),  to read button pinMode(x, INPUT);st=digitalRead(x);pinMode(x, OUTPUT); to switch back to LED viewing.

This will be much complex in coding i think

the adafruit neopixel library or fastLED is pretty easy to use, and lets you change colors and brightness easily, which makes for a snazzier project. The other option does add code complexity, but that's what you need when straightforward hardware runs out.

@dandavis sorry did not catch you, i think my code and led setup have exactly what you are saying, leds are connect 1k to 5v then gnd as in my diagram and the code you said is in my sketch code!

To measure the battery, you need a second resistor from A0 to ground, or you'll still have 9V on the A0 pin, potentially damaging your arduino.

@Tito explore this https://wokwi.com/projects/361190433680191489

As a (slightly hacky and binary :) ) suggestion, you could use just two LEDs and free up a pin with the following...
Level 1 - LED 1 on, LED 2 off
Level 2 - LED 1 off, LED 2 on
Level 3 - LED 1 on, LED 2 on
This is a really simple change to your current set up and code
Alternatively (as suggested by @dandavis) use a set of 3 neopixels and drive from just 1 pin

simple and easy, that what i wanted

You may try charlieplexing your LEDs. Using only 3 digital pins
you can drive up to 6 LEDs. A web search for “charlieplexing
Arduino” should get you started.


text:
ESP32 - resetting BT(classic)-Discovery variables ends in memory chaos
I want to search for bt devices in each loop(), store them and query them one by one. This works fine so far. However, when I try to reset the corresponding variables, I get the following error: "Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled."
This is to ensure that new devices are found rather than iterating over old (no longer existing) devices.
// BT
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
#define BT_DISCOVER_TIME 10000

//BT_DEVICES
BTScanResults* pScanResults;
String** deviceNames;
int numDevices;

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

  //BT
  SerialBT.begin(DEVICE_NAME, true); // device is master
}

void loop() {
  btDiscover();
  requestData();
}

void btDiscover() {
  pScanResults = SerialBT.discover(BT_DISCOVER_TIME);

  if (pScanResults != nullptr && pScanResults->getCount() > 0) {
    for (int i = 0; i < pScanResults->getCount(); i++) {
      BTAdvertisedDevice* pDevice = pScanResults->getDevice(i);
      if (pDevice != nullptr) {
        String deviceName = pDevice->getName().c_str();
        if (deviceName.startsWith(SLAVE_NAME_PATTERN)) {
          addDeviceName(deviceName.c_str());
        }
      }
    }
  }
  SerialBT.discoverClear();

}

bool deviceNameExists(const String& name) {
  for (int i = 0; i < numDevices; i++) {
    if (deviceNames[i]->equals(name)) {
      return true;
    }
  }
  return false;
}

void addDeviceName(const String& name) {
  if (!deviceNameExists(name)) {
    deviceNames = (String**)realloc(deviceNames, (numDevices + 1) * sizeof(String*));
    deviceNames[numDevices] = new String(name);
    numDevices++;
  }
}
void requestData() {
  for (int i = 0; i < numDevices; i++) {
    SerialBT.connect(*deviceNames[i]);
    SerialBT.println("REQUEST");
    delay(100);
    String message = SerialBT.readStringUntil('\n');

    StaticJsonDocument<200> jsonDocument;
    DeserializationError error = deserializeJson(jsonDocument, message);
    if (error == DeserializationError::Ok) {
      serializeJson(jsonDocument, Serial);
      Serial.println();
    } else {
      // Fehler beim Parsen der JSON-Nachricht
      Serial.println("ERROR");
    }
    SerialBT.disconnect();
  }
}

i tried something similar to this:
delete pScanResults;
    pScanResults = nullptr;
  }

  delete[] deviceNames;
  deviceNames = nullptr;
  numDevices = 0;

how can i realize this? i tried vectors instead of String**, but that triggered the problem instantaneously (without the ressetting "function")
I have also tried the library "ListLib.h". When I use the Clear() function of this library, I get no messages after the first 2 lines. (hangs up?)
mh ok... if i use btDiscover() only (without arrays and so), it works as expected. but if i add my requestData() inside of btDiscover(), i get only once message from each client... idk
ok maybe discover and connect/disconnect dont work together?
mh when i use addDeviceName(deviceName.c_str()) with a variable, i get only one time the messages of clients. if replace the variable with a String, then it works as expected.

for now, i have moved the discover part to setup() and every 30minutes the esp is restarted... it's not the best approach, but it works... conclusion: discover and connect do not work together

Welcome to SE/Arduino! Please take the [tour] to learn how this site works, and read "[ask]". -- This sounds like a memory overflow problem. What exception is unhandled? Doesn't the ESP tell you more? Are you sure your memory management is correct? (I do not look through code without knowing the exact error message.) -- Please [edit] your question if you have new information, do not post comments. This is not a forum.

Hi @the busybee, sorry for that misguided post...I will do that again. I was a bit stumped and desperate. My troubleshooting started with the memory overflow (I "fixed" it with delay(XXX)) until I finally came to the conclusion that the discover() function is not usable after a connect(). Because of that i moved the discover()-function to setup() and for the moment I restart the ESP32 regularly. Not nice but it works. The memory overload was not the real problem.


text:
Nodemcu does not connect to phone wifi
All welcome.
I'm trying to connect nodemcu to the phone's wifi.
And nodemcu can't do it. But sometimes after several reboots she does it. Also if i use my old phone - nodemcu connects perfectly! Why?
My "new" phone: Fly FS504 Cirrus 2
My old phone: Fly IQ4504 Quad.
My code:
#include <ESP8266WiFi.h>

const char *ssid =  "Just my SSID";

const char *pass =  "Some password";

WiFiClient client;

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

       Serial.println("Connecting to ");
       Serial.println(ssid);

       WiFi.begin(ssid, pass);
       while (WiFi.status() != WL_CONNECTED)
          {
            // stack here (only with new phone)
            delay(500);
            Serial.print(".");
          }
      Serial.println("");
      Serial.println("WiFi connected");
}

void loop()
{

}

Does it crash? If you're on a breadboard I guess that's the reason. You could try to explicitly WiFi.disconnect() before attempting to connect, the esp8266's wifi is a bit buggy sometimes.

@SimSon, hmm.. Just add Wifi.disconnect() before WiFi.begin()?

@SimSon, thanks! It's working! I spent a lot of time for this problem. Have a nice day :)

glad to hear. So did my workaround "fix" your problem? If yes, I'd form it into an answer so you can close this question

@SimSon, yeah, do it

From my experience the esp8266's wifi is a little bit buggy sometimes. I'm not sure if it has something to do with the esp auto-connecting to known networks, but I managed to work-around this issue by explicitly WiFi.disconnect()ing from any potential network right before calling WiFi.begin().
Another thing that I noticed several times is that the esp can be easily disturbed when connected to a breadboard, in special when wifi is in use (in this case the esp might even crash). There must be some bad interferences, I guess.


text:
Releasing gas from a bottle via Arduino - opening a valve?
I'm looking for a mechanical component that enables me to do two things:

contain a gas in a bottle and if opened, the gas should smoothly flow out (with the same pressure as a child blowing out candles on his birthday cake)
a valve for the bottle that can be opened by an Arduino when powered via USB

I already figured out that there are outlets for CO2 capsules. This could work, but then I'd need to figure out a way to decrease the pressure in order to receive a gentle gas flow.
Do you know any better approaches? Thanks in advance!

You need a regulator to decrease the pressie. A modern 2 stage scuba regulator's 1st stage can decrease 3000psi to 200psi. A power tool compressor can decrease 150psi down to about 45psi.

Per some google searching, CO2 is about 850psi.  I like the air-tool regulator idea (~18$ from Home Depot), since they are adjustable to the 0-200psi range on the low side, if they don't break on the high side.    How much volume are you talking about? 1 child's breath per actuation? 1/7000th of a 12g CO2 capsule?

If you can tolerate a decreasing flow as the pressure in the bottle drops, a simple restrictor (fluidic equivalent of a resistor) will limit the flow but of course, I = E/R; the flow will be proportional to the bottle pressure. If that is acceptable, it is probably the cheapest, simplest, and most reliable way.

You can use the product "electronic expansion valve" to control gas, also you can control valve openness degree this is optional, then put in CO2 capsules closed box also add air pressure sensor in the box, air pressure sensor controls valve to set up gas pressure, make one hole to box the gas out from here thereafter measure the pressure what you want.
Also do you need a mechanic component to control CO2 capsule?

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


text:
Water valve for food
I am working on a project, where i need to control the flow of a liquid made from food.
For example: making chicken curry, I will separate all the liquid from the meat, and run that tough a pipe, where this control pipe is on.
But I have been unable to find a subtle valve for this, as the liquid on all of them will flow tough the mechanics of the valve, and this would not be optimal as it would make it impossible to clean, and it would diffidently get stuck.
Can one of you suggest a valve that would work for this case?

I would suggest, instead of a valve, a Peristaltic Pump.
In short, it comprises a set of rollers that squeeze a flexible tube and push the fluid along. It has good advantages for food use:

Very easy to clean - only the inside of the tube needs cleaning
Pumped fluid is not in physical contact with the pump mechanism so can't be contaminated.

They are used in many sterile environments - medical, industrial, etc., because they are so easy to keep clean and have no way of contaminating the pumped fluid. They are also good with viscous (sticky, gloopy) fluids like soups and sauces.
They can also deliver precisely measured amounts very easily.


text:
PWM on Pin 4 - arduino Micro
I am using Arduino Micro. Is there any way to use PWM on pin 4 instead of Pin3 ?
I tried to change pins_Arduino.h but didnt worked.
//#define digitalPinHasPWM(p)         ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)

#define digitalPinHasPWM(p)         ((p) == 4 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)

and
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    ////////////////////////modified///////////////
    //TIMER0B,      /* 3 */
    //NOT_ON_TIMER,
    NOT_ON_TIMER,
    TIMER0B,        /* 4 */
    ////////////////////////////////////////////////////
    TIMER3A,        /* 5 */
    TIMER4D,        /* 6 */
    NOT_ON_TIMER,

    NOT_ON_TIMER,
    TIMER1A,        /* 9 */
    TIMER1B,        /* 10 */
    TIMER0A,        /* 11 */

    NOT_ON_TIMER,
    TIMER4A,        /* 13 */

    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,

    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
    NOT_ON_TIMER,
};

@Majenko has answered your question.  What many do not realize is that there are many Aruidno boards with a number of different processors.  It is difficult to make them all work alike.  That is, using the "Arduino set of software" (Libraries, boot loaders, ect), it is difficult to abstract the hardware to make all Arduino boards act exactly like the original Arduino Uno.  I think you can do what you want on an Arduino Mega board.

i am willing to modify the abstraction layers. Just want to make sure that it will work if i modify the libraries

The Micro layout: http://www.pighixxx.com/test/portfolio-items/micro/

You need to understand both the hardware and software before starting.  It may be that no matter what you do there isn't PWM hardware on pin 4 of the micro you are using.  However, if you understand what you goals are you may be able to implement a software PWM.  But, likely, you would have to use interrupts for timing.  And that might interfere with other Arduino features / functions.  At some point it may just be easier to use a more feature rich micro.  Especially if this is a one off project.

You cannot. There is no PWM on that pin. PWM is generated by hardware. The hardware simply does not exist.

even something slimier to 'Software Serial' not available?

Software PWM is possible but quite intensive. Servo.h does it but only for very low duty cycles.

my intention is to control a dc motor driver(TB6612FNG)  that needs  PWM inputs

You get glitches is software PWM which makes it a poor choice for motor control.

sad to hear that, and thank you so much for your support

You can get external PWM generating cards.

For a simple and bad quality motor in a toy, then software PWM is possible. Are there ways to free a PWM pin by changing the way the pins are connected ?

It depends what else you want to be doing at the same time.


text:
SIM800L GSM module is not working
I'm testing SIM800L GSM module with Arduino UNO and module is blinking 3 times every 15 seconds or sometime every 45 seconds. Why this is happening?
In serial monitor it shows Message Sent Successfully! but I'm not getting any message.I tried with multiple numbers. Still not getting any message.
I have tested several codes which shows outputs of AT commands. Nothing was working. Power supply is 5V 5A.
/*
 *   Author@ExploreEmbedded
 *   Example to Send messages Interactively using GSM Sim800L
 *
 *   LIBRARY CREDITS:
 *   Thanks to Cristian Steib(steibkhriz@gmail.com) for the library.
 *
 *
 *
 *      PINOUT:
 *        _____________________________
 *       |  ARDUINO UNO >>>   Sim800L  |
 *        -----------------------------
 *            GND      >>>   GND
 *        RX  10       >>>   TX
 *        TX  11       >>>   RX
 *       RESET 2       >>>   RST
 *
 *
*/

#include <Sim800L.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800L Sim800L;  //to declare the library
char text[161]=""; //buffer to store message
char number[11]=""; //phone number to send message
int cnt;
bool error; //to catch the response of sendSms

void setup(){
    Sim800L.begin(); // initializate the library.
    Serial.begin(9600);
}

void loop(){

      //Read the Number
      Serial.print("\nEnter 10 digit Phone Number:");
      while(Serial.available()<=0);
      cnt = Serial.readBytesUntil('\n',number, 11);
      number[cnt] = '\0';
      Serial.println(number);

      //clear the serial input buffer so that no typed characters are pending

      delay(1000); //delay required before clearing the input buffer
      while(Serial.available()>0) //clear buffer
      {
        Serial.read();
      }

      //Read the Message to be sent
      Serial.print("Enter Message:");
      while(Serial.available()<=0);
      cnt = Serial.readBytesUntil('\n',text, 160);
      text[cnt] = '\0';
      Serial.println(text);
      delay(1000);

      while(Serial.available()>0) //clear buffer
      {
        Serial.read();
      }

      //Send the message and display the status
      error = Sim800L.sendSms(number,text);
      if(error)
      Serial.println("Error Sending Message");
      Serial.println("Message Sent Successfully!");

}

I found what's happening. Module was shutdown due to over voltage.


text:
Writing data to a specific address in EEPROM
I'm trying to write two strings to an Arduino Uno's EEPROM. Here, the first code block works fine: it writes string(True/False) at 'address 0'. But the second block, which writes data at 'address 5', is not working as expected.Reading data at address 5 prints a blank line. What am I missing here? Is this the correct way to write two different strings to EEPROM?
First code block:
int state = LOW;
char first_eeprom_value;
if (state == LOW) {
  state = HIGH;
  char example_string[4] = "True";
  first_eeprom_value = EEPROM.read(0);
  Serial.println(first_eeprom_value);
  for (int i = 0 ; i < 5 ; i++) {
    EEPROM.update(i, example_string[i]);
  }
} else {
  state = LOW;
  char example_string[5] = "False";
  first_eeprom_value = EEPROM.read(0);
  Serial.println(first_eeprom_value);
  for (int i = 0 ; i < 5; i++) {
    EEPROM.update(i, example_string[i]);
  }
}
Time = millis();

Second code block:
char first_eeprom_value1;
if (state1 == LOW) {
  state1 = HIGH;
  char example_string1[4] = "True";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 5 ; i < 11 ; i++) {
    EEPROM.update(i, example_string1[i]);
  }
} else {
  state1 = LOW;
  char example_string1[5] = "False";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 5 ; i < 11 ; i++) {
    EEPROM.update(i, example_string1[i]);
  }
}

Time = millis();

//reading data at address 5
int addr = 5;
char value = EEPROM.read(addr);
Serial.println(value);// this prints blank line

is not working as expected - what do you expect, and what is actually happening?

Nothing is getting written when using 2nd code block.

How do you know? Can you please amend your question to include the output from the serial prints that you have in your code?

I have edited the question and 2nd code block.

remove the if ... then ... else statements ... minimize the code as much as possible ... do just a write and then a read ... do you still have the same problem?

you do not terminate the strings with 0. for a string with 4 chars allocate an array of 5 chars and write 0 at the end after reading from eeprom.. otherwise the print doesn't know where the string ends

@Juraj Let me try that.

"you do not terminate the strings with 0"- Can u help me with code?

@Juraj he is reading just one char from the eeprom, not a string, so a terminator is not required

@frarugi87, true. the code is so chaotic

You are cycling outside the string, thus creating undefined behavior.
Try replacing the second block with this:
char first_eeprom_value1;
if (state1 == LOW) {
  state1 = HIGH;
  char example_string1[4] = "True";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 0; i < sizeof(example_string1); i++) {
    EEPROM.update(i + 5, example_string1[i]);
  }
} else {
  state1 = LOW;
  char example_string1[5] = "False";
  first_eeprom_value1 = EEPROM.read(5);
  Serial.println(first_eeprom_value1);
  for (int i = 0; i < sizeof(example_string1); i++) {
    EEPROM.update(i + 5, example_string1[i]);
  }
}

Please note that this is not optimal; I suggest you to use fixed-length strings, and fill the unused spaces with blanks or 0s, so you can read back all the bytes you wrote in a safe way


text:
Make lights come on and off depending on which button is pressed
Imagine a strip of LEDs with O being HIGH and X being LOW.
X O X O X
Now if I pressed the button below the second O and wanted it to switch the last two LEDs (4th one to LOW and 5th to HIGH or any opposite value of what it was), but if I pressed the first X wanted it to switch that one HIGH, the second one LOW, and the third HIGH.
I want to continue this type of pattern where each button press will result in two or three of the LEDs changing their effective state.
How might I achieve this? I have researched using the modulo function and can only get it to work every other click of a button. I have also tried using a pullup function and couldn't get it to work at all.
Can someone please just point me in the right direction?

Show your work please :)

I am working on it still.  So far I can get one to change and when I work on a second button it changes the first back to the original state.

I want to continue this type of pattern where each button press will result in two or three of the LEDs changing their effective state.

I'll assume there are nLED LEDs and buttons, and that the buttons are momentary buttons and need debouncing.  I presume you have one button beneath each LED, numbered say 0 to nLED-1, and that the two or three LEDs that will change when button k is pressed have numbers  k, k+1, and possibly k+2.
To simplify the coding, create an array (or a bit map), say Lsts, with nLED entries, to represent the current state of LEDs, and a similar array, say Bsts for button statuses, and an array of bytes bounce to track debouncing status.
On each pass through loop(), use a for loop to read each eligible switch.  A switch with a nonzero bounce entry is debouncing and doesn't get read.  If a switch is read and it changes, update the LED statuses in  Lsts and at ports.  For example:
enum { nLED=5, debouncePasses=50 };
byte Lsts[nLED]={0}, Bsts[nLED]={1,1,1,1,1}, bounce[nLED]={0};
const byte Lpins[nLED] = { 3,4,5,6,7 };
const byte Bpins[nLED] = { 8,9,10,11,12 };
//... etc

void setup() {
  for (byte i=0; i<nLED; ++i) {
    pinMode(Lpins[i], OUTPUT);
    // Buttons will have negative logic, hi for open, lo for pressed
    pinMode(Bpins[i], INPUT_PULLUP);
  }
  // ... any other initialization ...
}
void loop() {
  for (byte i=0; i<nLED; ++i) {
    // See if button is eligible for reading, and if it changed
    if (bounce[i]) {
      --bounce[i]; // Decrease bounce pass counter
    } else {
      if (digitalRead(Bpins[i]) != Bsts[i]){
        // Yes,  it's eligible and it changed
        bounce[i] = debouncePasses; // Set button's debounce counter
        if (Bsts[i]) { // Test if switch was pressed vs released
          // Toggle the button's light and the next one or two lights
          for (int j=i; j<nLED && j<i+3; ++j) {
            Lsts[j] = !Lsts[j];
            digitalWrite(Lpins[j], Lsts[j]);
          }
        }
        Bsts[i] = !Bsts[i]; // Toggle button state
      }
    }
  }
  // ... any other stuff
  delayMicroseconds(500); // Delay for bounce-pass timing
  // alternately, instead of delayMicroseconds, sleep until timer tick
}

Edit 1:  If there are more LEDs than buttons, then use separate constants for the counts, adjust the initializations, etc.  For example:
enum { nButton=5, nLED=6, debouncePasses=50 };
byte Lsts[nLED] ={1,0,1,0,1,0};
byte Bsts[nButton]={1,1,1,1,1}, bounce[nLED]={0};

//... etc

void setup() {
  for (byte i=0; i<nLED; ++i) {
    pinMode(Lpins[i], OUTPUT);
    digitalWrite(Lpins[i], Lsts[i]);
  }
  // Buttons will have negative logic, hi for open, lo for pressed
  for (byte i=0; i<nButton; ++i) {
    pinMode(Bpins[i], INPUT_PULLUP);
  }
  // ... any other initialization ...
}

In loop(), change the initial for from for (byte i=0; i<nLED; ++i) to for (byte i=0; i<nButton; ++i).  This will work ok if there is an extra LEDs after the LEDs that line up with buttons.

Edit 2:

Why when using an array doesn't the arduino recognize the HIGH or LOW state of an led? I tried adding this simple code:
if (42 && 44 && 46 && 48 && 50 == HIGH){
digitalWrite (ledWin, LOW); } else {digitalWrite (ledWin, HIGH);}

Evidently you want to test if all the LEDs are on, and apparently the numbers 42, 44, ... 50 are supposed to somehow represent LED states.
However, numbers like 42, 44, ... are constant values and cannot properly represent the value of something that varies.  The condition in that if statement will always evaluate to the same value, false, as follows.
According to the C/C++ standard, a condition like 42 && 44 && 46 && 48 && 50 == HIGH consisting of a series of terms separated by && operators will be evaluated left to right until either one is false (making the whole expression false) or all are true (making it true).  (For example, see the Remarks section of Logical AND Operator: &&.)
In this case, 42 is non-zero, hence true.  Next, 44 is true, 46 is true, and 48 is true.  But 50 == HIGH is false – the value of HIGH is 1, and 50 is not equal to 1.  Therefore the whole expression is false.
A better approach to finding out if all the LEDs are on or off is to test the values of Lsts[] entries.  For example, you could add them up, and then see if the sum is equal to 0 (all off) or equal to nLED (all on):
byte nOn = 0;
for (byte i=0; i<nLED; ++i) nOn += Lsts[i];
digitalWrite (ledWin, nOn < nLED);

That will set the ledWin pin if not all of the LEDs are on, else will clear it.

Can an array be declared as something else later in a sketch?  ie; When Lsts[nLED]= {1,1,1,1,1}, can that be used to set one additional pin to a high state rather than declaring new variable for the same purpose?

@upstartlilevil, yes, you could treat an extra LED and LED initialization as shown in edit 1 of answer.  However,  re “Can an array be declared as something else later in a sketch?”, it can be used as something else (which can make code difficult to understand and maintain) but cannot be re-declared as something else in the same scope as the original declaration.  Note, if the additional pin gets treated about the same as other LED pins, it makes sense to handle it via the loops and code for other LED pins; but if it's treated differently, just set up a simple var for it.

@jwpat7 I understand how to do that and had actually already made it 5 buttons and 6 leds, I want a "prize" so my kids can see that when they get it correct something happens, a green led comes on and a relay for a magnet release a matchbox car down a track or something like that.  Adding an led in this way just makes it an additional led.  My question is then; Why when using an array doesn't the arduino recognize the HIGH or LOW state of an led?  I tried adding this simple code:  if (42 && 44 &&  46 && 48 && 50 == HIGH){
digitalWrite (ledWin, LOW);
}else{digitalWrite (ledWin, HIGH);}

@upstartlilevil, see edit 2

Can someone please just point me in the right direction?

what is "right" is highly subjective. I would consider a good solution to be one where the functionalities desired is broken down into natural modules that are then integrated to perform the desired functions. By that (highly subjective) standard, the solution posted earlier would be a poor one -> due to its tightly coupled / inter-mingled approach.
if I were to take a shot at this, I would consider the implementation below:
  key_state = read_keys(); //read keys / buttons, with or without debouncing
  led_process(key_state);  //process the key_state, and light up / off leds based on key_state

Essentially, you scan the keys / buttons, and based on that, turn on / off the leds.
All you need to do after that is to implement the individual functions based on your particular hardware design, or even software approaches: for example, read_keys() can be implemented in the isr, as can led_process().
A solution like this is highly portable: it works on pretty much anything that supports a C compiler, and is implementation-independent: the logic holds true, and all you do is to change the two functions to perform different kinds of lighting.
To me, modulizing your code is a huge advantage for a high-level language like C, and vital in taking on a real life project of moderate complexity.


text:
7 segment displays arduino mega 2560
I'm trying to use an Arduino Mega 2560 to use 7-segment displays, 6 displays... I use 3 CD4543B to pilot the 6 displays.
It works very well for 4 displays as you can see in this video.
But when I want to use the same circuit for 5 or 6 displays, there is some bug as you can see on this video for 5 displays.
Here is the code that works fine for 4 displays:
//définition des broches du premier décodeur
const int bit_A=8;
const int bit_B=9;
const int bit_C=10;
const int bit_D=11;
//définition du brochage du deuxieme decodeur
const int bit_E=22;
const int bit_F=24;
const int bit_G=26;
const int bit_H=28;
//définition du brochage du 3ième décodeur
const int bit_I=40;
const int bit_J=42;
const int bit_K=44;
const int bit_L=46;
//définition des broches des transistors

const int alim_millier=3;
const int alim_centaine=4;
const int alim_dizaine=5;
const int alim_unite=6;

void setup() {
  //les broches sont toutes des sorties
  pinMode(bit_A,OUTPUT);
  pinMode(bit_B,OUTPUT);
  pinMode(bit_C,OUTPUT);
  pinMode(bit_D,OUTPUT);
  pinMode(bit_E,OUTPUT);
  pinMode(bit_F,OUTPUT);
  pinMode(bit_G,OUTPUT);
  pinMode(bit_H,OUTPUT);
  pinMode(bit_I,OUTPUT);
  pinMode(bit_J,OUTPUT);
  pinMode(bit_K,OUTPUT);
  pinMode(bit_L,OUTPUT);
  pinMode(alim_millier,OUTPUT);
  pinMode(alim_centaine,OUTPUT);
  pinMode(alim_dizaine,OUTPUT);
  pinMode(alim_unite,OUTPUT);
  //les broches sont toutes mises à l'état bas
  digitalWrite(bit_A,LOW);
  digitalWrite(bit_B,LOW);
  digitalWrite(bit_C,LOW);
  digitalWrite(bit_D,LOW);
  digitalWrite(bit_E,LOW);
  digitalWrite(bit_F,LOW);
  digitalWrite(bit_G,LOW);
  digitalWrite(bit_H,LOW);
  digitalWrite(bit_I,LOW);
  digitalWrite(bit_J,LOW);
  digitalWrite(bit_K,LOW);
  digitalWrite(bit_L,LOW);
  digitalWrite(alim_millier,LOW);
  digitalWrite(alim_centaine,LOW);
  digitalWrite(alim_dizaine,LOW);
  digitalWrite(alim_unite,LOW);
}

void loop() {
  //fonction principale
  for(int i=0; i<10000; i++) {
    //boucle qui permet de compter de0 à9999(=10000 valeurs)
    afficher_nombre(i);//appelde la fonction affichage avec envoi du nombre à afficher
  }
}

//fonction permettant d'afficherun nombre sur quatre afficheurs
void afficher_nombre(int nombre) {
  long temps;//variable utilisée poursavoir le temps écoulé
  int unite=0,dizaine=0,centaine=0, millier=0;//variable pour chaque afficheur
  millier=nombre/1000;//on récupère les milliers
  centaine=(nombre-1000*millier)/100;//on récupère les centaines
  dizaine=(nombre-(centaine*100)-(millier*1000))/10;//on récupère les dizaines
  unite=nombre-(millier*1000)-(centaine*100)-(dizaine*10);//on récupère les unités
  temps=millis();//on récupère le temps courant
  //tant qu'on a pas affiché ce chiffre pendant au moins 500 milliseconde
  //permet donc de pouvoir lire le nombre affiché
  while((millis()-temps)<500) {
    //on affiche le nombre
    //d'abord les milliers pendant 5ms
    digitalWrite(alim_millier,HIGH);
    afficher_CD(millier);//on appelle la fonction qui permet d'afficher le chiffre millier
    digitalWrite(alim_centaine,LOW);
    digitalWrite(alim_dizaine,LOW);//le transistor est bloqué
    digitalWrite(alim_unite,LOW);//le transistor est bloqué
    delay(5);
    //d'abord les centaines pendant 5ms
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,HIGH);//le transistor de l'afficheur des centaines est saturé, donc l'afficheur est allumé
    afficher_CM(centaine);//on appelle la fonction qui permet d'afficher le chiffre centaine
    digitalWrite(alim_dizaine,LOW);//le transistor est bloqué
    digitalWrite(alim_unite,LOW);//le transistor est bloqué
    delay(5);
    //ensuite les dizaines pendant 5 ms
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,LOW);// transistor est bloqué
    digitalWrite(alim_dizaine,HIGH);//transistor saturé
    afficher_CM(dizaine);
    digitalWrite(alim_unite,LOW);//transistor bloqué
    delay(5);
    //on affiche les unités 5 ms
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,LOW);//transistor bloqué
    digitalWrite(alim_dizaine,LOW);//transistor bloqué
    digitalWrite(alim_unite,HIGH);//transistor saturé
    afficher_UD(unite);
    delay(5);
  }
}

//fonction écrivant sur les premiers afficheurs
void afficher_UD(int chiffre) {
  digitalWrite(bit_A,LOW);
  digitalWrite(bit_B,LOW);
  digitalWrite(bit_C,LOW);
  digitalWrite(bit_D,LOW);
  if(chiffre>=8) {
    digitalWrite(bit_D,HIGH);
    chiffre=chiffre-8;
  }
  if(chiffre>=4) {
    digitalWrite(bit_C,HIGH);
    chiffre=chiffre-4;
  }
  if(chiffre>=2) {
    digitalWrite(bit_B,HIGH);
    chiffre=chiffre-2;
  }
  if(chiffre>=1) {
    digitalWrite(bit_A,HIGH);
    chiffre=chiffre-1;
  }
}

//fonction écrivant sur le second afficheur
void afficher_CM(int chiffre) {
  digitalWrite(bit_E,LOW);
  digitalWrite(bit_F,LOW);
  digitalWrite(bit_G,LOW);
  digitalWrite(bit_H,LOW);
  if(chiffre>=8) {
    digitalWrite(bit_H,HIGH);
    chiffre=chiffre-8;
  }
  if(chiffre>=4) {
    digitalWrite(bit_G,HIGH);
    chiffre=chiffre-4;
  }
  if(chiffre>=2) {
    digitalWrite(bit_F,HIGH);
    chiffre=chiffre-2;
  }
  if(chiffre>=1) {
    digitalWrite(bit_E,HIGH);
    chiffre=chiffre-1;
  }
}

void afficher_CD(int chiffre) {
  digitalWrite(bit_I,LOW);
  digitalWrite(bit_J,LOW);
  digitalWrite(bit_K,LOW);
  digitalWrite(bit_L,LOW);
  if(chiffre>=8) {
    digitalWrite(bit_L,HIGH);
    chiffre=chiffre-8;
  }
  if(chiffre>=4) {
    digitalWrite(bit_K,HIGH);
    chiffre=chiffre-4;
  }
  if(chiffre>=2) {
    digitalWrite(bit_J,HIGH);
    chiffre=chiffre-2;
  }
  if(chiffre>=1) {
    digitalWrite(bit_I,HIGH);
    chiffre=chiffre-1;
  }
}

And here the code for 5 displays with "bugs" :
//définition des broches du premier décodeur
const int bit_A=8;
const int bit_B=9;
const int bit_C=10;
const int bit_D=11;
//définition du brochage du deuxieme decodeur
const int bit_E=22;
const int bit_F=24;
const int bit_G=26;
const int bit_H=28;
//définition du brochage du 3ième décodeur
const int bit_I=40;
const int bit_J=42;
const int bit_K=44;
const int bit_L=46;
//définition des broches des transistors
const int alim_dm= 3;
const int alim_millier=4;
const int alim_centaine=5;
const int alim_dizaine=6;
const int alim_unite=7;
void setup() {
  //les broches sont toutes des sorties
  pinMode(bit_A,OUTPUT);
  pinMode(bit_B,OUTPUT);
  pinMode(bit_C,OUTPUT);
  pinMode(bit_D,OUTPUT);
  pinMode(bit_E,OUTPUT);
  pinMode(bit_F,OUTPUT);
  pinMode(bit_G,OUTPUT);
  pinMode(bit_H,OUTPUT);
  pinMode(bit_I,OUTPUT);
  pinMode(bit_J,OUTPUT);
  pinMode(bit_K,OUTPUT);
  pinMode(bit_L,OUTPUT);
  pinMode(alim_dm,OUTPUT);
  pinMode(alim_millier,OUTPUT);
  pinMode(alim_centaine,OUTPUT);
  pinMode(alim_dizaine,OUTPUT);
  pinMode(alim_unite,OUTPUT);
  //les broches sont toutes mises à l'état bas
  digitalWrite(bit_A,LOW);
  digitalWrite(bit_B,LOW);
  digitalWrite(bit_C,LOW);
  digitalWrite(bit_D,LOW);
  digitalWrite(bit_E,LOW);
  digitalWrite(bit_F,LOW);
  digitalWrite(bit_G,LOW);
  digitalWrite(bit_H,LOW);
  digitalWrite(bit_I,LOW);
  digitalWrite(bit_J,LOW);
  digitalWrite(bit_K,LOW);
  digitalWrite(bit_L,LOW);
  digitalWrite(alim_dm,LOW);
  digitalWrite(alim_millier,LOW);
  digitalWrite(alim_centaine,LOW);
  digitalWrite(alim_dizaine,LOW);
  digitalWrite(alim_unite,LOW);
}

void loop() {
  //fonction principale
  for(int i=0;i<100000;i++)//boucle qui permet de compter de0 à 99999(=100000 valeurs) {
    afficher_nombre(i);//appelde la fonction affichage avec envoi du nombre à afficher
  }
}

//fonction permettant d'afficherun nombre sur quatre afficheurs
void afficher_nombre(int nombre) {
  long temps;//variable utilisée poursavoir le temps écoulé
  int unite=0,dizaine=0,centaine=0, millier=0, dm=0;//variable pour chaque afficheur
  dm=nombre/10000;//on récupère les dm
  millier=(nombre-(10000*dm))/1000;//on récupère les milliers
  centaine=(nombre-1000*millier)-(10000+dm)/100;//on récupère les centaines
  dizaine=(nombre-(centaine*100)-(millier*1000)-(dm*10000))/10;//on récupère les dizaines
  unite=nombre-(dm*10000)-(millier*1000)-(centaine*100)-(dizaine*10);//on récupère les unités

  temps=millis();//on récupère le temps courant
  //tant qu'on a pas affiché ce chiffre pendant au moins 500 milliseconde
  //permet donc de pouvoir lire le nombre affiché
  while((millis()-temps)<500) {
    //on affiche le nombre
    //d'abord les dms pendant 5ms
    digitalWrite(alim_dm,HIGH);
    afficher_CD(dm);//on appelle la fonction qui permet d'afficher le chiffre dm
    digitalWrite(alim_millier,LOW);//le transistor bloqué
    digitalWrite(alim_centaine,LOW);//le transistor est bloqué
    digitalWrite(alim_dizaine,LOW);//le transistor est bloqué
    digitalWrite(alim_unite,LOW);//le transistor bloqué
    delay(10);
    //d'abord les millier pendant 5ms
    digitalWrite(alim_dm,LOW);
    digitalWrite(alim_millier,HIGH);//le transistor de l'afficheur des centaines est saturé, donc l'afficheur est allumé
    afficher_CM(millier);//on appelle la fonction qui permet d'afficher le chiffre centaine
    digitalWrite(alim_centaine,LOW);//le transistor est bloqué
    digitalWrite(alim_dizaine,LOW);//le transistor est bloqué
    digitalWrite(alim_unite,LOW);//le transistor bloqué
    delay(10);
    //ensuite les centaine pendant 5 ms
    digitalWrite(alim_dm,LOW);
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,HIGH);// transistor est bloqué
    afficher_CM(centaine);
    digitalWrite(alim_dizaine,LOW);//transistor saturé
    digitalWrite(alim_unite,LOW);//transistor bloqué
    delay(10);
    //on affiche les dizaines 5 ms
    digitalWrite(alim_dm,LOW);
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,LOW);//transistor bloqué
    digitalWrite(alim_dizaine,HIGH);//transistor bloqué
    afficher_UD(dizaine);
    digitalWrite(alim_unite,LOW);//transistor saturé
    delay(10);
    //on affiche les unités
    digitalWrite(alim_dm,LOW);
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,LOW);//transistor bloqué
    digitalWrite(alim_dizaine,LOW);//transistor bloqué
    digitalWrite(alim_unite,HIGH);//transistor saturé
    afficher_UD(unite);
    delay(10);
  }
}

//fonction écrivant sur les premiers afficheurs
void afficher_UD(int chiffre) {
  digitalWrite(bit_A,LOW);
  digitalWrite(bit_B,LOW);
  digitalWrite(bit_C,LOW);
  digitalWrite(bit_D,LOW);
  if(chiffre>=8) {
    digitalWrite(bit_D,HIGH);
    chiffre=chiffre-8;
  }
  if(chiffre>=4) {
    digitalWrite(bit_C,HIGH);
    chiffre=chiffre-4;
  }
  if(chiffre>=2) {
    digitalWrite(bit_B,HIGH);
    chiffre=chiffre-2;
  }
  if(chiffre>=1) {
    digitalWrite(bit_A,HIGH);
    chiffre=chiffre-1;
  }
}

//fonction écrivant sur le second afficheur
void afficher_CM(int chiffre) {
  digitalWrite(bit_E,LOW);
  digitalWrite(bit_F,LOW);
  digitalWrite(bit_G,LOW);
  digitalWrite(bit_H,LOW);
  if(chiffre>=8) {
    digitalWrite(bit_H,HIGH);
    chiffre=chiffre-8;
  }
  if(chiffre>=4) {
    digitalWrite(bit_G,HIGH);
    chiffre=chiffre-4;
  }
  if(chiffre>=2) {
    digitalWrite(bit_F,HIGH);
    chiffre=chiffre-2;
  }
  if(chiffre>=1) {
    digitalWrite(bit_E,HIGH);
    chiffre=chiffre-1;
  }
}

void afficher_CD(int chiffre) {
  digitalWrite(bit_I,LOW);
  digitalWrite(bit_J,LOW);
  digitalWrite(bit_K,LOW);
  digitalWrite(bit_L,LOW);
  if(chiffre>=8) {
    digitalWrite(bit_L,HIGH);
    chiffre=chiffre-8;
  }
  if(chiffre>=4) {
    digitalWrite(bit_K,HIGH);
    chiffre=chiffre-4;
  }
  if(chiffre>=2) {
    digitalWrite(bit_J,HIGH);
    chiffre=chiffre-2;
  }
  if(chiffre>=1) {
    digitalWrite(bit_I,HIGH);
    chiffre=chiffre-1;
  }
}
//Fin du programme

I've been trying for weeks to understand the problem. All displays work fine, and if I adapt the code for 4 displays and try to use any 4 of the 6 displays it works fine (I have tried a combination such as displays: 1, 2, 3, 4 or 2, 3, 4, 5 or 3, 4, 5, 6 or 1, 2, 5, 6, everything works).
Thanks to a conversation on the Arduino forum, I also tried this code for 5 displays but I still have the same problem:
//Da
const int bit_A=8;
const int bit_B=9;
const int bit_C=10;
const int bit_D=11;
//Db
const int bit_E=22;
const int bit_F=24;
const int bit_G=26;
const int bit_H=28;
//Dc
const int bit_I=40;
const int bit_J=42;
const int bit_K=44;
const int bit_L=46;
// transistors
const int alim_dizainemillier= 3;
const int alim_millier=4;
const int alim_centaine=5;
const int alim_dizaine=6;
const int alim_unite=7;
void setup() {
  pinMode(bit_A,OUTPUT);
  pinMode(bit_B,OUTPUT);
  pinMode(bit_C,OUTPUT);
  pinMode(bit_D,OUTPUT);
  pinMode(bit_E,OUTPUT);
  pinMode(bit_F,OUTPUT);
  pinMode(bit_G,OUTPUT);
  pinMode(bit_H,OUTPUT);
  pinMode(bit_I,OUTPUT);
  pinMode(bit_J,OUTPUT);
  pinMode(bit_K,OUTPUT);
  pinMode(bit_L,OUTPUT);
  pinMode(alim_dizainemillier,OUTPUT);
  pinMode(alim_millier,OUTPUT);
  pinMode(alim_centaine,OUTPUT);
  pinMode(alim_dizaine,OUTPUT);
  pinMode(alim_unite,OUTPUT);
  digitalWrite(bit_A,LOW);
  digitalWrite(bit_B,LOW);
  digitalWrite(bit_C,LOW);
  digitalWrite(bit_D,LOW);
  digitalWrite(bit_E,LOW);
  digitalWrite(bit_F,LOW);
  digitalWrite(bit_G,LOW);
  digitalWrite(bit_H,LOW);
  digitalWrite(bit_I,LOW);
  digitalWrite(bit_J,LOW);
  digitalWrite(bit_K,LOW);
  digitalWrite(bit_L,LOW);
  digitalWrite(alim_dizainemillier,LOW);
  digitalWrite(alim_millier,LOW);
  digitalWrite(alim_centaine,LOW);
  digitalWrite(alim_dizaine,LOW);
  digitalWrite(alim_unite,LOW);
}

void loop() {
  for(int i=0;i<100000;i++) {
    afficher_nombre(i);
    delay(5);
  }
}

void afficher_nombre(int nombre) {
  long temps;
  int unite=0,dizaine=0,centaine=0, millier=0, dizainemillier=0;
  dizainemillier=nombre/10000;
  millier=(nombre-(10000*dizainemillier))/1000;
  centaine=(nombre-(1000*millier)-(10000*dizainemillier))/100;
  dizaine=(nombre-(centaine*100)-(millier*1000)-(dizainemillier*10000))/10;
  unite=nombre-(dizainemillier*10000)-(millier*1000)-(centaine*100)-(dizaine*10);
  temps=millis();
  while((millis()-temps)<500){
    afficher_CD(dizainemillier);
    digitalWrite(alim_dizainemillier, HIGH);
    delay(5);
    digitalWrite(alim_dizainemillier, LOW);
    afficher_CM(millier);
    digitalWrite(alim_millier, HIGH);
    delay(5);
    digitalWrite(alim_millier, LOW);
    afficher_CM(centaine);
    digitalWrite(alim_centaine, HIGH);
    delay(5);
    digitalWrite(alim_centaine, LOW);
    afficher_UD(dizaine);
    digitalWrite(alim_dizaine, HIGH);
    delay(5);
    digitalWrite(alim_dizaine, LOW);
    afficher_UD(unite);
    digitalWrite(alim_unite, HIGH);
    delay(5);
    digitalWrite(alim_unite, LOW);
  }
}

void afficher_UD(int chiffre) {
  digitalWrite(bit_A,chiffre & 1);
  digitalWrite(bit_B,chiffre & 2);
  digitalWrite(bit_C,chiffre & 4);
  digitalWrite(bit_D,chiffre & 8);
}

void afficher_CM(int chiffre) {
  digitalWrite(bit_E,chiffre & 1);
  digitalWrite(bit_F,chiffre & 2);
  digitalWrite(bit_G,chiffre & 4);
  digitalWrite(bit_H,chiffre & 8);
}

void afficher_CD(int chiffre) {
  digitalWrite(bit_I,chiffre & 1);
  digitalWrite(bit_J,chiffre & 2);
  digitalWrite(bit_K,chiffre & 4);
  digitalWrite(bit_L,chiffre & 8);
}

Any clue is very welcome! Thanks!

I think it's because I use int and I should use long to avoid overflow... for the number I want to display:
void loop()
{
 for(int i=0;i<100000;i++)
 {
   afficher_nombre(i);
   delay(5);
 }
}

should be :
void loop()
{
 for(long i=0;i<100000;i++)
 {
   afficher_nombre(i);
   delay(5);
 }
}

And also a parentheses problem solved thanks to cattledog on this forum

on Arduino int is 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 while long is 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647

exactly :) ! I'm use to code for 64bits or 32bits on computer, and forgot that arduino is 16bits....

Here is the code that works fine for 4 displays:

both code pieces suffer from the use of "delay()".
here is what I used - https://dannyelectronics.wordpress.com/2017/06/30/a-more-flexible-driver-for-7-segment-leds/
it is written so the leds can be driven by individual pins so porting to  arduino requires no change to the source code - just a few macros to remap the IO operations.
also running it from a timer isr is the (only) way to go.
edit: here is to show how the code above gets to work here. I expanded it to cover 8 digits but only the first 6 digits effective. three macros are all it takes to repurpose it for arduino.
displaying a fixed "123456".

all the user code does is to dump the content to be displayed into the display buffer and the display routine, led_display() takes care of the rest.


text:
Accessing two MPU-9250 DMP
I want to use both IMU at the same time using the Sparkfun Library on a SAMD21 mini breakout board. Can anyone help?
The begin function is :
inv_error_t MPU9250_DMP::begin(void) {
  inv_error_t result;
  struct int_param_s int_param;
  Wire.begin();
  result = mpu_init(&int_param);
  if (result)
    return result;
  mpu_set_bypass(1); // Place all slaves (including compass) on primary bus
  setSensors(INV_XYZ_GYRO | INV_XYZ_ACCEL | INV_XYZ_COMPASS);
  _gSense = getGyroSens();
  _aSense = getAccelSens();
  return result;
}

Have you tried to do it?

yes i tried but when connecting them togher i got the same data for both,actually i'm trying to modify the library to have to imu with two adresse 0x68 and 0x69

I have the same problem now. the function is burried in 3rd lvl of libraries..
Where did you change the code?

Sorry, but I'm not 100% sure of what you are trying to do, I don't understand 'both imu the' in your question.  I think you are trying to use two identical boards at the same time.  (If not tell me so I can edit my answer)
You will need to modify the library so the begin function takes a parameter.
That parameter for MPU9250_DMP::begin then identifies the address of the device, this will need passing to Wire.begin() I think (you'll need to check the Wire.begin() function, I can't).
That should let you create two different instances of the class.
MPU9250_DMP apple;
MPU9250_DMP banana;
apple.begin(0x68);
banana.begin(0x69);

yes i want to use this but in the begin function there is no parameter to pass

Erm, whoops, I missed a line out of the answer.  You need to change the library so begin() takes a parameter.  Sorry for the confusion.

thank you, i'm trying to modify it, now i'll test it and i'll give you the response

i changed the library,the problem is there is no data displayed ,when debugging even when i Print Something in the serial nothing displayed


text:
Expected unqualified ID before numeric constant
After debugging and having some conflicting declarations about analog pins, I finally thought it was done, after compiling I got this error:
32:0,
1:
31:12: error: expected unqualified-id before numeric constant

2:5: note: in expansion of macro 'B1'

I can't understand what this means. What's wrong with my code down here?
// don't judge me if it's too long and overcomplicated :P I'm still new xD
int AA1 = 0;
int B1 = 1;
int C1 = 2;
int D1 = 3;
int AA2 = 4;
int B2 = 5;
int C2 = 6;
int AA3 = 8;
int B3 = 9;
int C3 = 10;
int D3 = 11;
int B4 = 12;
int C4 = 13;
int sec = 0;
int min1 = 0;
int min2 = 0;
int hour1 = 8;
bool hour2 = 0;

void setup() {
  pinMode(AA1, OUTPUT);
  pinMode(B1, OUTPUT);
  pinMode(C1, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(AA2, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(C2, OUTPUT);
  pinMode(AA3, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(C3, OUTPUT);
  pinMode(D3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(C4, OUTPUT);
}

void loop() {
  OutputOn();
  delay(1000);
  sec++;
  if(sec == 60) {
    sec = 0;
    min1++;
      if(min1 == 10) {
      min1 = 0;
      min2++;
        if(min2 == 6) {
        min2 = 0;
        hour1++;
          if(hour1 == 10) {
          hour1 = 0;
          hour2 = 1;
        }
        if(hour2 == 1, hour1 == 3) {
          hour1 = 1;
          hour2 = 0;
        }
      }
    }
  }
}

void OutputOn() {
  digitalWrite(B1, LOW);
  digitalWrite(C1, LOW);
  digitalWrite(D1, LOW);
  digitalWrite(A2, LOW);
  digitalWrite(B2, LOW);
  digitalWrite(C2, LOW);
  digitalWrite(A3, LOW);
  digitalWrite(B3, LOW);
  digitalWrite(C3, LOW);
  digitalWrite(D3, LOW);
  digitalWrite(B4, LOW);
  digitalWrite(C4, LOW);
  if(min1 == 1) { digitalWrite(AA1, HIGH); }
  if(min1 == 2) { digitalWrite(B1, HIGH); }
  if(min1 == 3) { digitalWrite(B1, HIGH); digitalWrite(AA1, HIGH); }
  if(min1 == 4) { digitalWrite(C1, HIGH); }
  if(min1 == 5) { digitalWrite(C1, HIGH); digitalWrite(AA1, HIGH); }
  if(min1 == 6) { digitalWrite(D1, HIGH); digitalWrite(B1, HIGH); }
  if(min1 == 7) { digitalWrite(D1, HIGH); digitalWrite(AA1, HIGH); digitalWrite(B1, HIGH); }
  if(min1 == 8) { digitalWrite(D1, HIGH); }
  if(min1 == 9) { digitalWrite(D1, HIGH); digitalWrite(AA1, HIGH); }
  if(min2 == 1) { digitalWrite(AA2, HIGH); }
  if(min2 == 2) { digitalWrite(B2, HIGH); }
  if(min2 == 3) { digitalWrite(B2, HIGH); digitalWrite(AA1, HIGH); }
  if(min2 == 4) { digitalWrite(C2, HIGH); }
  if(min2 == 5) { digitalWrite(C2, HIGH); digitalWrite(A2, HIGH); }
  if(min2 == 6) { digitalWrite(C2, HIGH); digitalWrite(B2, HIGH); }
  if(hour1 == 1) { digitalWrite(AA3, HIGH); }
  if(hour1 == 2) { digitalWrite(B3, HIGH); }
  if(hour1 == 3) { digitalWrite(B3, HIGH); digitalWrite(AA3, HIGH); }
  if(hour1 == 4) { digitalWrite(C3, HIGH); }
  if(hour1 == 5) { digitalWrite(C3, HIGH); digitalWrite(AA3, HIGH); }
  if(hour1 == 6) { digitalWrite(C3, HIGH); digitalWrite(B3, HIGH); }
  if(hour1 == 7) { digitalWrite(C3, HIGH); digitalWrite(AA3, HIGH); digitalWrite(B3, HIGH); }
  if(hour1 == 8) { digitalWrite(D3, HIGH); }
  if(hour1 == 9) { digitalWrite(D3, HIGH); digitalWrite(C3, HIGH); }
  if(hour2 == 1) { digitalWrite(B4, HIGH); digitalWrite(C4, HIGH); }
}

It's supposed to be code for a clock (if it wasn't obvious enough) hooked up to 4 7-segment decoders, also connected to 4 7-segment LED displays.

In general when writing in C,  “macro” should be a big hint that you have a problem involving #define.  Bizzare errors saying things that are not what you wrote: problem involving #define.

Bad luck. There is a file within Arduino called "binary.h", and it contains a define called "B1". Which means you may not use "B1" as a variable. In my opinion, that file "binary.h" is totally unnecessary.
In the preferences you can turn on extra output for the compiler and turn on line numbers. The compiler will tell what is wrong, but you have to know how the compiler does that. The first compiler error is the most important.
".../hardware/arduino/avr/cores/arduino/binary.h:31:12: error: expected unqualified-id before numeric constant #define B1 1" means that the compiler was reading the file "binary.h" and at line 31 it noticed something it did not understand and it has to do with "B1".

So I just have to not use B1?

Correct. The leading B with 0's and 1's is used for binary constants: https://www.arduino.cc/en/Reference/IntegerConstants Since it is a pin number, you can call the variable "const B1Pin = 1;" or even "const TheyToldMeAtStackExchangeNotToCallThisB1 = 1;"

I ment: "const int B1Pin = 1;". Sorry, I forgot the 'int'. The 'const' keyword is not needed, it tells the compiler that it is a constant number and does not change.


text:
Having trouble uploading sketch to Nano
I have a few cheap Nano clones that I bought online that have worked for the past couple of months. They were working fine today until suddenly the Arduino IDE had trouble uploading sketches to them.
Here is the full error message:
Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

Sketch uses 2080 bytes (6%) of program storage space. Maximum is 30720 bytes.

Global variables use 212 bytes (10%) of dynamic memory, leaving 1836 bytes for local variables. Maximum is 2048 bytes.

An error occurred while uploading the sketch

avrdude: ser_open(): can't set com-state for "\\.\COM5"

I have tried troubleshooting multiple ways, but none of the following worked:

unplugged/replugged in nano
restarted computer
swapped to another nano clone
changed USB cables
changed USB ports
tried uploading other code
downloaded the CH340 drivers

I tried uploading to an Arduino Mega and that DID work, however, I would like to be able to use the Nano.
I am using version 1.8.19
Thanks for the help.

Did you update windoz or the Arduino IDE?

@VE7JRO No, one minute it was working fine and the next I try to upload and it doesn't work

are you saying that you were able to upload a sketch, and then a few minutes later, you were not able to upload a sketch? ... it could be caused by the sketch that uploaded successfully

@jsotola yes, that is exactly what happened, I am looking into issue with the watchdog timer but any other ideas would be helpful

You posted an answer saying it was a problem with the USB driver, which you then deleted. Was that the problem or not? Knowing this saves other people from trying to solve a problem which is already solved.

In short: fake CH340 + latest drivers stopped being compatible (but unlike FTDI few years ago they didn't brick the fakes, it's just not working)

The cheap Nano requires you to use the old bootloader. I use them without problems most of the time. When it fails to upload I first check tools and validate the bootloader it is running. If it is correct I then close the IDE, power down the Nano and then reopen and repower it, between the two it usually solves the problem.

See Have I bricked my Arduino Uno? Problems with uploading to board.
I know you mentioned Nano, but it is the same concept.
If a sketch you previously uploaded sets up the watchdog timer to fire too quickly the new sketch may not upload.
Try holding down reset while you start the upload process and then release reset when the upload starts. See the part of the linked answer headed "Watchdog timer problems".


text:
A peristaltic pump with pH sensor and web based output project
Good day to you all, I am asking here to confirm that my project is feasible. I have low knowledge of Arduino and other components. Please help me in achieving this project.
I already have the peristaltic pump and pH sensor working with Arduino uno. Now I want the output of the pH sensor to be displayed in a webpage or web app, In the webpage I will also make a formula on how much volume is released from the peristaltic pump.
So there are two things on my webpage output: the acidity of the liquid and the volume released. I want a wireless setup, so I guess I would use ESP32 (notsure)? Now I kind of getting hard on how to put it on a webpage and the important part is, how to pass the data from the arduino to the ESP32?. Any ideas? or things that I would do?
OR
I  would use the ESP32 alone since I have not so many components and I think the ESP32 can cater for the pHsensor (analog signal) and pwm (motor Peristaltic pump). Correct me if I'm wrong. By this, I won't be having problems about the communication to the arduino and esp32 (UART).
Additional Info:
Current Set up-
Arduino - controls the pump and pHsensor
ESP32 - Webpage or webserver
Is there any way that I could do this with ESP32 alone? so that I won't be having problems with UART.
I want to thank you in advance for giving me insights.
Update:
by this I decided to use ESP32 alone for the whole project. I just need to rewire all. I'm hoping the ESP32 has PWM pins to control the pwm peristaltic pump and pHsensor(analog signal) pins. Please confirm if you know that ESP32 has these pins(for pwm and analog). By the way I'm using the ESP32S where the TXD0 is in pin 35 which is the GPIO1 and the RXD0 is in pin 34 which is the GPIO3. –
Johannes Remotigue
2 days ago   Delete

Not knowing what you have you first need to determine if it will be wired or wireless. Then narrow it down, wireless could be wifi, bluetooth, etc. After that you then need to determine if you want it on one arduino such as an ESP32 or use shields/modules..

start by learning how to display "Hello World" in a web page ... forget about the pump and the pH sensor for now

@Gil Thank you, my question is now updated.

@jsotola Thank you, I already know the html and css in making a web page. What else do I need to learn? like the backend, on how to get the data?

Is this web server going to be on the Arduino or ESP32?

@NickGammon you mean if it is going to be on the Arduino, I should have an ethernet shield right?
I'm actually adjusting my set up to which is more doable for me.

I was just asking. Where do you intend the web server to be? You could conceivably send data to a PC, and have the web server there. To do it on the Arduino, yes you would need an Ethernet shield. It has to accept incoming TCP/IP connections somehow.

Thank you @NickGammon, by this I decided to use ESP32 alone for the whole project. I just need to rewire all. I'm hoping the ESP32 has PWM pins to control the pwm peristaltic pump and pHsensor(analog signal) pins. Please confirm if you know that ESP32 has these pins(for pwm and analog). By the way I'm using the ESP32S where the TXD0 is in pin 35 which is the GPIO1 and the RXD0 is in pin 34 which is the GPIO3.

@JohannesRemotigue how to get the data? ... that's what I'm talking about ... learn how to send "Hello World" from arduino to webbrowser

This isn't a forum. Please edit your question to clarify what you are asking, don't ask additional things in comments.

Yes. You will need to add a solid state switch or similar to power the motor. The ESP32 has the radio needed to connect to your wifi so that part is already there. The ESP can be configured as a client or server so take your pick. There is a lot published on the web about doing this with code even posted. The device also has a lot of computing power so it could become a stand alone device which reports the results to the web server or works in conjunction with it.
All you will need to add is mainly code.  This should get you started. Just be cautious as the Arduino is generally 5V and the ESP is 3.3 volt so some voltage translation may be needed and if using 5V modules and/or MOSFETS. If MOSFETs are involved be very careful of the Vgs ratings to be sure it is on with 3V.


text:
How to fix UnicodeDecodeError when using Serial.println
I am using an Arduino Uno R3 to send instructions to a serial monitor in a Python program with Serial.println.  But when I send a specific line, I get a a UnicodeDecodeError.
The line in the Arduino code that causes this error is:
Serial.println("Press '1,2,3,4,5' to run motor at 10%, 20%, 30%, 40%, 50% for 2 seconds");

My Python code to read the serial data is:
def get_serial_data(self):
        while 1:
            try:
                serial_data = self.serial_connection.readline().decode('Ascii')
                filtered_serial_data = serial_data.strip('\r\n')
                self.serial_monitor.insert(END, filtered_serial_data)
            except TypeError:
                pass

and is called from a thread:
thread1 = threading.Thread(target=self.get_serial_data)
        thread1.daemon = True
        thread1.start()

But I get the following error:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x85 in position 36: ordinal not in range(128)

Can anyone help why this is happening or how to fix, I saw a stackoverflow post to use a try, except block to get it to ignore this line, but I want to print it out, and I want to understand why I get this error.

As a newcomer to the Arduino community, it would be good to know why this and my answer got downvoted.  It was a genuine issue that took me a while to solve, and wasn't obvious from the docs.  Without any reasoning for the downvotes makes this community come across as unfriendly

I solved the issue.  It was a memory issue not a decoding issue.  Because the dynamic memory was mostly used up, it affected the encoding of the data.  Reducing the amount of memory my code was using resolved the issue.
I also discovered, that Serial.println("some text") uses a lot of dynamic memory.  So by reducing the amount of text I was encoding helped, but also by wrapping the the text in F(), like this:
Serial.println(F("some text"))

Which stores the string in flash memory not sram.  Heres a helpful link on the F function:
https://arduinogetstarted.com/faq/what-is-serial.println-f


text:
Unable to upload to Arduino Uno after changing port number
I recently changed my port number for the arduino USB from COM8 (what it defaulted with) to COM256 (attempting to see if that will work).
However, whenever I try to upload it gives

'avrdude: ser_open(): can't open device "\.\COM256": The system cannot find the file specified.'

Is there a way to fix this or do I reset the port back to COM8?

What operating system? How did you change the port number? Why did you do this?

why do you say that post 8 is standard? ... that would be COM8, not just 8

I did not say that port 8 is standard. I just said that it is what the computer assigned when I plugged in the Arduino.

In short, disconnect and reconnect the board after you change the COM number.

I tested with Windows 10. But this part of Windows has not changed is a very long time.
In testing I changed an UNO R3 to port 256 through Device manager, device properties, Port Settings, Advanced..., COM Port Number and it gave the error mentioned when trying to upload.
Only changing the port number down to 99, 31, and 9 made no difference. However, physically disconnecting and reconnecting the board after each instance of changing the COM number allowed it to upload again, even when that was COM256.
I haven't looked into why reconnecting the board matters where Device Manager listing reflected the change immediately. But I'm also not surprised.

I reuploaded it and it works! I kind of did what you suggested.


text:
Arduino Servo with temperature sensor (TMP36)
The essence of the program is to measure the temperature, and if the temperature is higher than 26 degrees, the servo rotates by 45 degrees, and if it's lower, it rotates by 179 degrees. However, a short circuit is occurring. At the moment of the first servo rotation, the temperature jumps to 40 degrees (the temperature is calculated from voltage), and after that, the servo continuously rotates back and forth because the temperature is fluctuating between 40 and 20 degrees. What could be the cause of this issue?
My code:
#include <Servo.h>
Servo myServo;
const int sensorPin = A0;
const float baselineTemp = 20.0;
int angle;
void setup() {
  myServo.attach(9);
  Serial.begin(9600);
}

void loop() {
  int sensorVal = analogRead(sensorPin);
  Serial.println("Sensor Value: ");
  Serial.print(sensorVal);
  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.println("Volts:");
  Serial.print(voltage);
  Serial.println("Celcius:");
  float temperature = (voltage - .5) * 100;
  Serial.print(temperature);
  if (temperature < baselineTemp) {
    myServo.write(179);
  } else {
    myServo.write(45);
  }
  delay(800);
}

Output in terminal:
sensorVal: 149
 Volts:0.73
 Celcius:22.75
 sensorVal: 192
 Volts:0.94
 Celcius:43.75
 sensorVal: 154
 Volts:0.75
 Celcius:25.20
 sensorVal: 188
 Volts:0.92
 Celcius:41.80
 sensorVal: 150
 Volts:0.73
 Celcius:23.24
 sensorVal: 184
 Volts:0.90
 Celcius:39.84
 sensorVal: 151

Are all GNDs connected?

What could be the cause of this issue? ... the servo

@SimSon I have just one GND and it's connected to "-"

upvote for removing the picture and posting text

@jsotola Can you tell me why it happens?

maybe the power supply voltage changes when the servo runs

You need to power the servo through a separate power supply. High power devices such as motors etc. should not be powered via the Arduino's regulator.  That is surely affecting the analogRead() and therefore also the temperature reading as already noted by @jsotola.
Secondly, you need to add some hysteresis here to prevent continuous thrashing when the temperature is around the baseline:
if (temperature < baselineTemp) { myServo.write(179); }
else { myServo.write(45); }

Maybe try something like :
if (temperature < baselineTemp - 1.0 ) { myServo.write(179); }
elseif (temperature > baselineTemp + 1.0 ) { myServo.write(45); }

You could also try adding a capacitor across the power rails of the temperature sensor say 10uF very close to the sensor itself.


text:
Arduino not responding while trying to flash over BLE
I'm working on wireless uploader for Arduino from iOS devices. I'm using HM-10 BLE module which seems to work ok. PIO 2 is used as DTR for resetting (see A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 1 [0x31] and A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 0 [0x30] below)- using 0.1uF capacitor and 10K resistor wired to MCU reset pin. Reset seems to be done correctly as i'm getting ready output (in 'setup()' body in uploaded sketch).
For some reason i'm getting 0x14 0x10 for 0x30 0x20 request (to ping bootloader) but not getting response for A [0x41] . [0x81]   [0x20] within almost 1 second.
Uploading over BLE:
2015-07-04 19:24:10.955 xctest[54864:5122867] [TRACE  ] [OUT]: Send: A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 1 [0x31]
2015-07-04 19:24:10.955 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 8
2015-07-04 19:24:11.106 xctest[54864:5122867] [DEBUG  ] [OUT]: Sending 8 bytes
2015-07-04 19:24:11.106 xctest[54864:5122867] [TRACE  ] [OUT]: Send: A [0x41] T [0x54] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] 0 [0x30]
2015-07-04 19:24:11.106 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 8
2015-07-04 19:24:11.148 xctest[54864:5122867] [DEBUG  ] [   ]: Draining for 230 ms ...
2015-07-04 19:24:11.148 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.323 xctest[54864:5122903] [TRACE  ] [IN ]: Rx value received 9 bytes: O [0x4F] K [0x4B] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] : [0x3A] 1 [0x31]
2015-07-04 19:24:11.323 xctest[54864:5122903] [TRACE  ] [IN ]: Rx value received 9 bytes: O [0x4F] K [0x4B] + [0x2B] P [0x50] I [0x49] O [0x4F] 2 [0x32] : [0x3A] 0 [0x30]
2015-07-04 19:24:11.381 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:11.381 xctest[54864:5122867] [TRACE  ] [IN ]: Ble clear buffer
2015-07-04 19:24:11.381 xctest[54864:5122867] [DEBUG  ] [IN ]: Drained 18 bytes
2015-07-04 19:24:11.381 xctest[54864:5122867] [DEBUG  ] [OUT]: Sending 2 bytes
2015-07-04 19:24:11.381 xctest[54864:5122867] [TRACE  ] [OUT]: Send: 0 [0x30]   [0x20]
2015-07-04 19:24:11.382 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 2
2015-07-04 19:24:11.382 xctest[54864:5122867] [DEBUG  ] [IN ]: Reading 1 bytes ...
2015-07-04 19:24:11.382 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.746 xctest[54864:5122914] [TRACE  ] [IN ]: Rx value received 1 bytes: . [0x00]
2015-07-04 19:24:11.747 xctest[54864:5122914] [TRACE  ] [IN ]: Ignoring single 0x00 char
2015-07-04 19:24:11.747 xctest[54864:5122914] [TRACE  ] [IN ]: Rx value received 2 bytes: . [0x14] . [0x10]
2015-07-04 19:24:11.748 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:11.748 xctest[54864:5122867] [TRACE  ] [IN ]: Receive: . [0x14]
2015-07-04 19:24:11.749 xctest[54864:5122867] [DEBUG  ] [IN ]: Read 1 bytes, actually received 2 bytes
2015-07-04 19:24:11.749 xctest[54864:5122867] [TRACE  ] [IN ]: 1 bytes in incoming buffer remaining for next receive
2015-07-04 19:24:11.749 xctest[54864:5122867] [DEBUG  ] [IN ]: Reading 1 bytes ...
2015-07-04 19:24:11.750 xctest[54864:5122867] [TRACE  ] [IN ]: Having current receive buffer: . [0x10]
2015-07-04 19:24:11.750 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.750 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:11.751 xctest[54864:5122867] [TRACE  ] [IN ]: Receive: . [0x10]
2015-07-04 19:24:11.751 xctest[54864:5122867] [DEBUG  ] [IN ]: Read 1 bytes, actually received 1 bytes
2015-07-04 19:24:11.751 xctest[54864:5122867] [TRACE  ] [IN ]: Ble clear buffer
2015-07-04 19:24:11.752 xctest[54864:5122867] [DEBUG  ] [OUT]: Sending 3 bytes
2015-07-04 19:24:11.752 xctest[54864:5122867] [TRACE  ] [OUT]: Send: A [0x41] . [0x81]   [0x20]
2015-07-04 19:24:11.752 xctest[54864:5122867] [TRACE  ] [OUT]: BLE sending bytes range from 0 length 3
2015-07-04 19:24:11.752 xctest[54864:5122867] [DEBUG  ] [IN ]: Reading 1 bytes ...
2015-07-04 19:24:11.753 xctest[54864:5122867] [TRACE  ] [IN ]: Start reading
2015-07-04 19:24:11.821 xctest[54864:5122914] [TRACE  ] [IN ]: Rx value received 1 bytes: . [0x00]
2015-07-04 19:24:11.821 xctest[54864:5122914] [TRACE  ] [IN ]: Ignoring single 0x00 char
2015-07-04 19:24:12.721 xctest[54864:5122903] [TRACE  ] [IN ]: Rx value received 5 bytes: r [0x72] e [0x65] a [0x61] d [0x64] y [0x79]
2015-07-04 19:24:12.722 xctest[54864:5122867] [TRACE  ] [IN ]: Finish reading
2015-07-04 19:24:12.722 xctest[54864:5122867] [TRACE  ] [IN ]: Receive: r [0x72]
2015-07-04 19:24:12.723 xctest[54864:5122867] [DEBUG  ] [IN ]: Read 1 bytes, actually received 5 bytes
2015-07-04 19:24:12.723 xctest[54864:5122867] [TRACE  ] [IN ]: 4 bytes in incoming buffer remaining for next receive
2015-07-04 19:24:12.723 xctest[54864:5122867] [ERROR  ] [   ]: STK500:getParameter: protocol error #1, expected [0x14], received [0x72]

When uploading over usb it's ok:
2015-06-29 16:34:10.829 xctest[36585:3703900] [TRACE  ] [   ]: DTR/RTS supported by Serial, resetting
2015-06-29 16:34:11.140 xctest[36585:3703900] [DEBUG  ] [IN ]: Draining ...
2015-06-29 16:34:11.392 xctest[36585:3703900] [DEBUG  ] [IN ]: Drain done
2015-06-29 16:34:11.392 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 2 bytes
2015-06-29 16:34:11.392 xctest[36585:3703900] [TRACE  ] [OUT]: Send: 0 [0x30]   [0x20]
2015-06-29 16:34:11.393 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.531 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.531 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.532 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.532 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 3 bytes
2015-06-29 16:34:11.532 xctest[36585:3703900] [TRACE  ] [OUT]: Send: A [0x41] . [0x81]   [0x20]
2015-06-29 16:34:11.533 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.535 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.536 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.536 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x04]
2015-06-29 16:34:11.536 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.536 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.537 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 3 bytes
2015-06-29 16:34:11.537 xctest[36585:3703900] [TRACE  ] [OUT]: Send: A [0x41] . [0x82]   [0x20]
2015-06-29 16:34:11.537 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.540 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.540 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.540 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x04]
2015-06-29 16:34:11.540 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.541 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.541 xctest[36585:3703900] [DEBUG  ] [   ]: STK500:initialize: n_extparms = 4
2015-06-29 16:34:11.541 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 22 bytes
2015-06-29 16:34:11.542 xctest[36585:3703900] [TRACE  ] [OUT]: Send: B [0x42] . [0x86] . [0x00] . [0x01] . [0x00] . [0x01] . [0x01] . [0x01] . [0x03] . [0xFF] . [0xFF] . [0xFF] . [0xFF] . [0x00] . [0x80] . [0x04] . [0x00] . [0x00] . [0x00] . [0x80] . [0x00]   [0x20]
2015-06-29 16:34:11.542 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.548 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.548 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.548 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.548 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 7 bytes
2015-06-29 16:34:11.549 xctest[36585:3703900] [TRACE  ] [OUT]: Send: E [0x45] . [0x05] . [0x04] . [0xD7] . [0xC2] . [0x00]   [0x20]
2015-06-29 16:34:11.549 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.552 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.552 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.552 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.553 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 2 bytes
2015-06-29 16:34:11.553 xctest[36585:3703900] [TRACE  ] [OUT]: Send: P [0x50]   [0x20]
2015-06-29 16:34:11.553 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.556 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14]
2015-06-29 16:34:11.556 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 1 bytes
2015-06-29 16:34:11.556 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x10]
2015-06-29 16:34:11.569 xctest[36585:3703900] Reading |                                                    | 0% 0ms
2015-06-29 16:34:11.570 xctest[36585:3703900] [DEBUG  ] [OUT]: Sending 2 bytes
2015-06-29 16:34:11.571 xctest[36585:3703900] [TRACE  ] [OUT]: Send: u [0x75]   [0x20]
2015-06-29 16:34:11.571 xctest[36585:3703900] [DEBUG  ] [IN ]: Receiving 5 bytes
2015-06-29 16:34:11.572 xctest[36585:3703900] [TRACE  ] [IN ]: Received: . [0x14] . [0x1E] . [0x95] . [0x0F] . [0x10]
2015-06-29 16:34:11.572 xctest[36585:3703900] Reading | ################################################## | 100% 2ms

So when uploading over USB DTR/RTS and similar schematic is used.
I think the problem is in resetting approach - wiring to reset does not work when trying to upload. Am i right? Is it bootloader issue?
PS. Arduino sketch uploaded:

void setup() {
  Serial.begin(115200);
  Serial.print("ready");

  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() {
  // put your main code here, to run repeatedly:

}

I forgot to say i've tested with Arduino Uno r3. i've just tested uploading to Arduino Mega2560 and it works - Mega's bootloader replies as expected and uploading succeed. What's wrong with Uno?


text:
Running C for arduino
Is there a compiler that I can use to run C on an arduino or any other way so that I can upload C programs to my arduino?

What do you mean by "run C"?  You can just compile them into your sketch.

How can I do that? I'm not very familiar with arduino software.

You basically do that every time you compile a sketch. The Arduino compiler is C++, which is backward compatible with C for the most part.

*!!!** :-)

Perhaps you should look into here
https://github.com/arduino/Arduino/wiki/Build-Process
Arduino uses avr-gcc compiler. Basically, it is a C compiler.
There is an step by step on how to customize this process using an avr-gcc compiler of your own here
http://www.wikihow.com/Write-Arduino-Software-in-C
But I best recommend you downloading the arduino IDE on the official website to get things going. It has all the serial pairing stuff you don't really need to know to get started.
Hope it helps.

GCC is a C++ compiler? Anyway, most/any C++ compiler can compile C-code as C is basically a subset of C++ (Don't quote me on this though, it'll work, but it's not that trivial)