text:
Blinking a led using assembly language at different frequencies using two push buttons
I want to blink a led using assembly language and arduino
I want the circuit to have a normal state of 5 hz blinking frequency
Then use two push buttons to increase or decrease the blinking frequency
The up button will increment the blinking frequency by 5 hz step until the led seems to be continuously on
While the down button will decrement the blinking frequency by 5 hz step until the normal state again
Is this achievable ?
And if any one can point me where to start as this the first time i am using assembly language but i am familiar with arduino

Have you seen these Q+As? https://arduino.stackexchange.com/search?q=assembly

Totally achievable. Have you looked into some assembler tutorials for AVR microcontrollers/Arduinos? A short search seems to give promising results. What have you tried so far? Have you tried building the code step by step, starting with turning on an LED, then blinking it, then reading a button?

It is achievable, yes. After all, the C++ compiler turns code into assembly code. But why do you want to do this? Is it a homework exercise?

1-No i haven't looked at the q&a but i will thank you
2- no i haven't tried anything yet since i am total newbie in assembly language and i was looking for guidance
3- yes and no , this is an optional assignment in my course that has no credit but our instructor gave it for our benefit

Here is one example of how to blink an LED in assembly coding on an Arduino UNO. You can attempt to solve your challenge. If you are stuck, please post the code and the connections and I am sure, you will get help again.
The code is here
#define __SFR_OFFSET 0

#include "avr/io.h"

.global main

main:
  sbi   DDRB, 5     ; Set PB5 as output

blink:
  sbi   PINB, 5     ; Toggle PINB
  ldi   r25, hi8(1000)
  ldi   r24, lo8(1000)
  call  delay_ms
  jmp   blink

delay_ms:
  ; Delay about (r25:r24)*ms. Clobbers r30, and r31.
  ; One millisecond is about 16000 cycles at 16MHz.
  ; The inner loop takes 4 cycles, so we repeat it 3000 times
  ldi   r31, hi8(4000)
  ldi   r30, lo8(4000)
1:
  sbiw    r30, 1
  brne    1b
  sbiw    r24, 1
  brne    delay_ms
  ret

Link to the project: https://wokwi.com/arduino/projects/290348681199092237

thank you sir, your help is greatly appreciated


text:
Relay switch problem: Arduino Nano with a 312 PIR sensor
I am working with a 312 PIR sensor with an Arduino Uno Nano.
When sensing motion Port 13 goes High for Time_A (10 minutes). If I then press a push button on the Arduino board it takes Port D2 LOW, then Port A will be on for Time 2 (A quick 30 second test cycle for testing and/or troubleshooting the code and equipment and a second LED (Port 12 goes high).
So, the sensor turns on the light relay for 10 minutes and the push button makes the light and the LED stay on for only 30 seconds so I can quickly test the system.
I have all the above working perfectly, but I have having difficulty adding another section of code that will turn all of the above off after either the 10 minutes, or the 30 second cycle. Now the lights stay on until I reset and start the cycle over for one of the times determined by the button, or the sensor.
Below is the code :
//Serial.println("TOP OF PROGRAM");
float pressLength_milliSeconds = 0; // value will be recorded in seconds. Define minimum time, in milli-seconds
int optionOne_milliSeconds = 100;
int optionTwo_milliSeconds = 2000;  // the pin your button is attached to
int buttonPin = 2; // pin your LEDs are attached to
int ledPin_Option_1 = 13;
int ledPin_Option_2 = 12;

void setup() {   // initialize pushbutton input pullup. Keep in mind, pin2 has ground voltage applied, we
  Serial.println("Top of SKETCH");
  pinMode(buttonPin, INPUT_PULLUP); // set the LEDS pins as outputs
  pinMode(ledPin_Option_1, OUTPUT);
  pinMode(ledPin_Option_2, OUTPUT); // start serial communications - for debutting   purposes or
  Serial.begin(9600);
} // close set up

void loop() { // record roughly the of tenths of seconds the button is being pressed
  while (digitalRead(buttonPin) == LOW ) {
    delay(5); // if you want more resolution, lower this number
    pressLength_milliSeconds = pressLength_milliSeconds + 100;   //display how long button is has been held
    Serial.print("ms =  ");
    Serial.println("pressLength_milliSeconds");
  } // close while     //Option 2 - Execute the second option if the button is held for the correct amount of time
  if (pressLength_milliSeconds >= optionTwo_milliSeconds) {
    digitalWrite(ledPin_Option_2, HIGH);
  }  // option 1 - Execute the first option if the  button is held long enough
  else if (pressLength_milliSeconds >= optionOne_milliSeconds) {
    digitalWrite(ledPin_Option_1, HIGH);
  } // close if options. every loop - reset  pressLength_Seconds counter
  //if (optionTwo_milliSeconds >= 10000)
  //  delay(10000);
  //digitalWrite(ledPin_Option_1, LOW);
  //digitalWrite(ledPin_Option_2, LOW);
  pressLength_milliSeconds = 0;
}

use button to control the timer, not LED ... use timer to control the LED ... you could separate the control even more by using timer to control a flag, then use the flag to control the LED

So there's two conditions that are supposed to make the light turn on? Within 10 minutes after a sensor signal on pin XX or within 30 seconds after a button press on pin 2?  I'd record the micros() when the button was pressed, and the micros() when the sensor was pressed and do the logic for the LED.

source: Stack Exchange

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

sort: votes


text:
Save Circularbuffer in RTC memory of ESP32
I would like to save my Circular Buffer in the RTC memory of my ESP32 when I use deep sleep. So I have initialized it with RTC_DATA_ATTR but when I go into Deep Sleep I lose the data I've saved. Is there  a way to do this?
Here is my function:
RTC_DATA_ATTR CircularBuffer<Datas, 178> test_SensorsDatas;

void test_RTC_memory(){

    for(int i=1; i<=20; i++){
        test_SensorsDatas.push(Datas);
        ID_msg.value++;
    }

    for(int i=0; i<test_SensorsDatas.size(); i++){
        Serial.println(String(Datas.value));
    }

    esp_deep_sleep_start();
}

Thank you very much! Ask me questions if something isn't clear ;)
EDIT: I tried something much simplier:
RTC_DATA_ATTR sensorsRecord newrecord{20, ID_sensor, ID_msg, epochUnion, ValueUnion, intValue, 30};
RTC_DATA_ATTR CircularBuffer<sensorsRecord, 50> test_SensorsDatas;

void test_RTC_memory2(){
    newrecord.ID_msg.value++;
    ID_msg.value++;
    Serial.println(String(newrecord.ID_msg.value));
    test_SensorsDatas.push(newrecord);
    Serial.println("buffer size: " + String(test_SensorsDatas.size()));
    esp_deep_sleep_start();
}```

But still not working, the ID_msg is incrementing well but not the buffer size even if I push a new value at every wake up.
Any suggestion?

I would guess the object is stored in RTC memory but the memory used by the object isn't. You'll need to apply the RTC_DATA_ATTR to the array inside the object, not the object itself.

Yes tried to define the data using RTC_DATA_ATTR outside of the function and after I push it in the Circular Buffer, I was unable to find it after the deep sleep...

first figure out what is really going on.  test by storing a number- char, int, short etc.  your simpler test case was a good thought but go even simpler.

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


text:
Error compiling arduino sketch to seeduino xiao for RF24 Module
I am trying to get 2 rf24 modules talking to each other. This is my first real arduino project so bear with my ignorance please.  I could get them to work with 2 arduino nano but, when trying to upload the same sketch to a seeduino xiao it won't compile. Not sure how to format this better (please intstruct) sorry<-- Here is a copy of the error message:
Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Seeeduino XIAO, Arduino, On"

In file included from C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:9:0:

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/adc.h:684:34: note: in expansion of macro 'STATUS'

   __I  ADC_STATUS_Type           STATUS;      /**< \brief Offset: 0x19 (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/dac.h:277:34: note: in expansion of macro 'STATUS'

   __I  DAC_STATUS_Type           STATUS;      /**< \brief Offset: 0x7 (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/eic.h:667:34: note: in expansion of macro 'STATUS'

   __I  EIC_STATUS_Type           STATUS;      /**< \brief Offset: 0x01 (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:26:21: error: expected unqualified-id before numeric constant

 #define CONFIG      0x00

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/eic.h:675:34: note: in expansion of macro 'CONFIG'

   __IO EIC_CONFIG_Type           CONFIG[2];   /**< \brief Offset: 0x18 (R/W 32) Configuration n */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/gclk.h:301:34: note: in expansion of macro 'STATUS'

   __I  GCLK_STATUS_Type          STATUS;      /**< \brief Offset: 0x1 (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/nvmctrl.h:346:34: note: in expansion of macro 'STATUS'

   __IO NVMCTRL_STATUS_Type       STATUS;      /**< \brief Offset: 0x18 (R/W 16) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/rtc.h:1000:34: note: in expansion of macro 'STATUS'

   __IO RTC_STATUS_Type           STATUS;      /**< \brief Offset: 0x0A (R/W  8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/rtc.h:1020:34: note: in expansion of macro 'STATUS'

   __IO RTC_STATUS_Type           STATUS;      /**< \brief Offset: 0x0A (R/W  8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/rtc.h:1042:34: note: in expansion of macro 'STATUS'

   __IO RTC_STATUS_Type           STATUS;      /**< \brief Offset: 0x0A (R/W  8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/sercom.h:1419:34: note: in expansion of macro 'STATUS'

   __IO SERCOM_I2CM_STATUS_Type   STATUS;      /**< \brief Offset: 0x1A (R/W 16) I2CM Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/sercom.h:1441:34: note: in expansion of macro 'STATUS'

   __IO SERCOM_I2CS_STATUS_Type   STATUS;      /**< \brief Offset: 0x1A (R/W 16) I2CS Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/sercom.h:1463:34: note: in expansion of macro 'STATUS'

   __IO SERCOM_SPI_STATUS_Type    STATUS;      /**< \brief Offset: 0x1A (R/W 16) SPI Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/sercom.h:1488:34: note: in expansion of macro 'STATUS'

   __IO SERCOM_USART_STATUS_Type  STATUS;      /**< \brief Offset: 0x1A (R/W 16) USART Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/tc.h:621:34: note: in expansion of macro 'STATUS'

   __I  TC_STATUS_Type            STATUS;      /**< \brief Offset: 0x0F (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/tc.h:645:34: note: in expansion of macro 'STATUS'

   __I  TC_STATUS_Type            STATUS;      /**< \brief Offset: 0x0F (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/tc.h:667:34: note: in expansion of macro 'STATUS'

   __I  TC_STATUS_Type            STATUS;      /**< \brief Offset: 0x0F (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/tcc.h:253:14: note: in expansion of macro 'STATUS'

     uint32_t STATUS:1;         /*!< bit:      3  Status Busy                        */

              ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/tcc.h:1799:34: note: in expansion of macro 'STATUS'

   __IO TCC_STATUS_Type           STATUS;      /**< \brief Offset: 0x30 (R/W 32) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/usb.h:1728:34: note: in expansion of macro 'STATUS'

   __I  USB_DEVICE_STATUS_Type    STATUS;      /**< \brief Offset: 0x00C (R/   8) DEVICE Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/usb.h:1759:34: note: in expansion of macro 'STATUS'

   __IO USB_HOST_STATUS_Type      STATUS;      /**< \brief Offset: 0x00C (R/W  8) HOST Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:26:21: error: expected unqualified-id before numeric constant

 #define CONFIG      0x00

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/wdt.h:290:34: note: in expansion of macro 'CONFIG'

   __IO WDT_CONFIG_Type           CONFIG;      /**< \brief Offset: 0x1 (R/W  8) Configuration */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\nRF24L01.h:33:21: error: expected unqualified-id before numeric constant

 #define STATUS      0x07

                     ^

C:\Users\User\Documents\ArduinoData\packages\Seeeduino\tools\CMSIS-Atmel\1.2.1/CMSIS-Atmel/CMSIS/Device/ATMEL/samd21/include/component/wdt.h:296:34: note: in expansion of macro 'STATUS'

   __I  WDT_STATUS_Type           STATUS;      /**< \brief Offset: 0x7 (R/   8) Status */

                                  ^~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::print_status(uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:188:22: error: '_BV' was not declared in this scope

            (status & _BV(RX_DR))?1:0,

                      ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:188:22: note: suggested alternative: '_B'

            (status & _BV(RX_DR))?1:0,

                      ^~~

                      _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:186:3: error: 'printf_P' was not declared in this scope

   printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"),

   ^~~~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:186:3: note: suggested alternative: 'sprintf_P'

   printf_P(PSTR("STATUS\t\t = 0x%02x RX_DR=%x TX_DS=%x MAX_RT=%x RX_P_NO=%x TX_FULL=%x\r\n"),

   ^~~~~~~~

   sprintf_P

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::print_observe_tx(uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:200:3: error: 'printf_P' was not declared in this scope

   printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"),

   ^~~~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:200:3: note: suggested alternative: 'sprintf_P'

   printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"),

   ^~~~~~~~

   sprintf_P

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::print_byte_register(const char*, uint8_t, uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:212:3: error: 'printf_P' was not declared in this scope

   printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);

   ^~~~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:212:3: note: suggested alternative: 'sprintf_P'

   printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);

   ^~~~~~~~

   sprintf_P

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::print_address_register(const char*, uint8_t, uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:223:3: error: 'printf_P' was not declared in this scope

   printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);

   ^~~~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:223:3: note: suggested alternative: 'sprintf_P'

   printf_P(PSTR(PRIPSTR"\t%c ="),name,extra_tab);

   ^~~~~~~~

   sprintf_P

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::printDetails()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:325:3: error: 'printf_P' was not declared in this scope

   printf_P(PSTR("Data Rate\t = %S\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));

   ^~~~~~~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:325:3: note: suggested alternative: 'sprintf_P'

   printf_P(PSTR("Data Rate\t = %S\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));

   ^~~~~~~~

   sprintf_P

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::begin()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:382:25: error: '_BV' was not declared in this scope

   write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

                         ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:382:25: note: suggested alternative: '_B'

   write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

                         ^~~

                         _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::startListening()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:398:50: error: '_BV' was not declared in this scope

   write_register(CONFIG, read_register(CONFIG) | _BV(PWR_UP) | _BV(PRIM_RX));

                                                  ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:398:50: note: suggested alternative: '_B'

   write_register(CONFIG, read_register(CONFIG) | _BV(PWR_UP) | _BV(PRIM_RX));

                                                  ^~~

                                                  _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::powerDown()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:429:50: error: '_BV' was not declared in this scope

   write_register(CONFIG,read_register(CONFIG) & ~_BV(PWR_UP));

                                                  ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:429:50: note: suggested alternative: '_B'

   write_register(CONFIG,read_register(CONFIG) & ~_BV(PWR_UP));

                                                  ^~~

                                                  _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::powerUp()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:436:49: error: '_BV' was not declared in this scope

   write_register(CONFIG,read_register(CONFIG) | _BV(PWR_UP));

                                                 ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:436:49: note: suggested alternative: '_B'

   write_register(CONFIG,read_register(CONFIG) | _BV(PWR_UP));

                                                 ^~~

                                                 _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'bool RF24::write(const void*, uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:468:25: error: '_BV' was not declared in this scope

   while( ! ( status & ( _BV(TX_DS) | _BV(MAX_RT) ) ) && ( millis() - sent_at < timeout ) );

                         ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:468:25: note: suggested alternative: '_B'

   while( ! ( status & ( _BV(TX_DS) | _BV(MAX_RT) ) ) && ( millis() - sent_at < timeout ) );

                         ^~~

                         _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::startWrite(const void*, uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:510:52: error: '_BV' was not declared in this scope

   write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );

                                                    ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:510:52: note: suggested alternative: '_B'

   write_register(CONFIG, ( read_register(CONFIG) | _BV(PWR_UP) ) & ~_BV(PRIM_RX) );

                                                    ^~~

                                                    _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'bool RF24::available(uint8_t*)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:552:28: error: '_BV' was not declared in this scope

   bool result = ( status & _BV(RX_DR) );

                            ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:552:28: note: suggested alternative: '_B'

   bool result = ( status & _BV(RX_DR) );

                            ^~~

                            _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'bool RF24::read(void*, uint8_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:585:39: error: '_BV' was not declared in this scope

   return read_register(FIFO_STATUS) & _BV(RX_EMPTY);

                                       ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:585:39: note: suggested alternative: '_B'

   return read_register(FIFO_STATUS) & _BV(RX_EMPTY);

                                       ^~~

                                       _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::whatHappened(bool&, bool&, bool&)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:594:42: error: '_BV' was not declared in this scope

   uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

                                          ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:594:42: note: suggested alternative: '_B'

   uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

                                          ^~~

                                          _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::openReadingPipe(uint8_t, uint64_t)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:652:57: error: '_BV' was not declared in this scope

     write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));

                                                         ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:652:57: note: suggested alternative: '_B'

     write_register(EN_RXADDR,read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[child])));

                                                         ^~~

                                                         _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::enableDynamicPayloads()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:671:51: error: '_BV' was not declared in this scope

   write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) );

                                                   ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:671:51: note: suggested alternative: '_B'

   write_register(FEATURE,read_register(FEATURE) | _BV(EN_DPL) );

                                                   ^~~

                                                   _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::enableAckPayload()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:700:51: error: '_BV' was not declared in this scope

   write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) );

                                                   ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:700:51: note: suggested alternative: '_B'

   write_register(FEATURE,read_register(FEATURE) | _BV(EN_ACK_PAY) | _BV(EN_DPL) );

                                                   ^~~

                                                   _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::setAutoAck(uint8_t, bool)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:770:16: error: '_BV' was not declared in this scope

       en_aa |= _BV(pipe) ;

                ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:770:16: note: suggested alternative: '_B'

       en_aa |= _BV(pipe) ;

                ^~~

                _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:774:17: error: '_BV' was not declared in this scope

       en_aa &= ~_BV(pipe) ;

                 ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:774:17: note: suggested alternative: '_B'

       en_aa &= ~_BV(pipe) ;

                 ^~~

                 _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::setPALevel(rf24_pa_dbm_e)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:799:14: error: '_BV' was not declared in this scope

   setup &= ~(_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;

              ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:799:14: note: suggested alternative: '_B'

   setup &= ~(_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;

              ^~~

              _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'rf24_pa_dbm_e RF24::getPALevel()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:832:46: error: '_BV' was not declared in this scope

   uint8_t power = read_register(RF_SETUP) & (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;

                                              ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:832:46: note: suggested alternative: '_B'

   uint8_t power = read_register(RF_SETUP) & (_BV(RF_PWR_LOW) | _BV(RF_PWR_HIGH)) ;

                                              ^~~

                                              _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'bool RF24::setDataRate(rf24_datarate_e)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:864:14: error: '_BV' was not declared in this scope

   setup &= ~(_BV(RF_DR_LOW) | _BV(RF_DR_HIGH)) ;

              ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:864:14: note: suggested alternative: '_B'

   setup &= ~(_BV(RF_DR_LOW) | _BV(RF_DR_HIGH)) ;

              ^~~

              _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'rf24_datarate_e RF24::getDataRate()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:907:43: error: '_BV' was not declared in this scope

   uint8_t dr = read_register(RF_SETUP) & (_BV(RF_DR_LOW) | _BV(RF_DR_HIGH));

                                           ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:907:43: note: suggested alternative: '_B'

   uint8_t dr = read_register(RF_SETUP) & (_BV(RF_DR_LOW) | _BV(RF_DR_HIGH));

                                           ^~~

                                           _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::setCRCLength(rf24_crclength_e)':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:933:47: error: '_BV' was not declared in this scope

   uint8_t config = read_register(CONFIG) & ~( _BV(CRCO) | _BV(EN_CRC)) ;

                                               ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:933:47: note: suggested alternative: '_B'

   uint8_t config = read_register(CONFIG) & ~( _BV(CRCO) | _BV(EN_CRC)) ;

                                               ^~~

                                               _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'rf24_crclength_e RF24::getCRCLength()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:957:46: error: '_BV' was not declared in this scope

   uint8_t config = read_register(CONFIG) & ( _BV(CRCO) | _BV(EN_CRC)) ;

                                              ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:957:46: note: suggested alternative: '_B'

   uint8_t config = read_register(CONFIG) & ( _BV(CRCO) | _BV(EN_CRC)) ;

                                              ^~~

                                              _B

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp: In member function 'void RF24::disableCRC()':

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:974:46: error: '_BV' was not declared in this scope

   uint8_t disable = read_register(CONFIG) & ~_BV(EN_CRC) ;

                                              ^~~

C:\Users\User\Documents\Arduino\libraries\RF24-master\RF24.cpp:974:46: note: suggested alternative: '_B'

   uint8_t disable = read_register(CONFIG) & ~_BV(EN_CRC) ;

                                              ^~~

                                              _B

Multiple libraries were found for "nRF24L01.h"

 Used: C:\Users\User\Documents\Arduino\libraries\RF24-master

 Not used: C:\Users\User\Documents\Arduino\libraries\NRFLite

exit status 1

Error compiling for board Seeeduino XIAO.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I suspect I have multiple problems as it took a lot of playing around with the libraries to get the RF24-Master library to work. I may have messed that up somehow (but it was working with the Nano...so...??).
Here is a copy of the sketch being loaded:
[code]
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
int DataMgs[1];
RF24 radio(9,10);
const uint64_t pipe = 0xE14BC8F482LL;
int Relay1 = 5;
void setup()
{
pinMode(Relay1, OUTPUT);
Serial.begin(57600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop()
{
if (radio.available())
{
bool done = false;
while (!done)
{
done = radio.read(DataMgs, 1);
Serial.print("NRF24L01 Receiver: ");
Serial.println(DataMgs[0]);
  if (DataMgs[0] == 1)
  {
    delay(10);
    digitalWrite(Relay1, HIGH);
  }

  if (DataMgs[0] == 2)
  {
    delay(10);digitalWrite(Relay1, LOW);
  }
  delay(100);
}

}
else
{
Serial.println("Waiting for signal...");
}
}
[/code]
Any guidance would be greatly appreciated. Thanks
P.S. If anyone can guide me through this issue I can send some crypto your way- thanks again.


text:
Using arduino framework how many instances of SoftwareSerial can use simultaneously with esp32
Ussing popular library https://github.com/plerup/espsoftwareserial/ can I have multiple softwareSerial ports (for example 6 ports).
I’m the readme say  “ several instances can be active at the same time” but don’t answer a quantity just say several.
Also don’t say if the instances will operate normal or will have some issue.
Ref: https://github.com/plerup/espsoftwareserial/#readme
Will be great to read an answer from someone with experience with the this specific library and arduino framework.

what have you tried?

Third paragraph of the readme that you link to: "The same functionality is given as the corresponding AVR library but several instances can be active at the same time."

I’m voting to close this question because the question links directly to the answer...

@Majenko To be fair "several" is not a good answer to the question "how many". Do you know of any limits on the number of simultaneously listening ports (besides the needed pins)?

@chrisl "several" is the only answer that can be given. You can have more than one. How many will depend on many factors, like what baud rate your are using, how often data is being received, what else the program is doing at the same time, etc. Factors that cannot be predicted by us. So the answer is "yes you can have several" and that's as good as you're going to get.

This is not a question that has an answer. There are far too many variables to say "You can have X ports at once".
How many you can have depends on such things as:

The baud rates you are using: faster baud rates will mean more processing and thus less processing for other ports to run.
How often data is received: A port that's not receiving anything isn't using any processing. You could have lots and lots of ports, but if only one is receiving anything it's not much different to only having one port.
What else your program is doing: You have finite resources. The more you use in your program the less are available for other things. You're running an RTOS, and resources and processing are time-sliced between tasks.

You can maximise your port availability by being crafty and careful with executing certain things on each core - for example if you have two heavily used ports it could be good to have one bound to each of your two cores (assuming a dual core ESP32) so they don't interfere with each other as much.
So a quantity cannot be given. Nor can a prediction about how reliable they would be. From the way it's purported to operate, though, the quantity is likely to be "quite a few" and there should be no problems, as long as you don't have too many.


text:
How does Arduino Servo.h library manage to output PWM when a Servo motor is connected to a non-PWM pin?
While learning more about Servos, the main thing i have learned is that, Servos (SG90) need PWM signal with the frequency of 50Hz. And the duty cycle of the frequency is used to rotate the angle of the motor.
I know generating PWM with variable duty cycle is possible in PWM pins using Timers but i don't understand how the arduino Servo.h library makes digital pins act like PWM too , whenever i connect the servo to any one of the digital pins of the arduino and code accordingly.
So how does Arduino 'Servo.h' Library manage to make a digital pin act like a PWM and what should the native AVR C code for this action look like?
I am trying to avoid third party libraries as much as possible and trying to learn Embedded systems thoroughly.
Please do not suggest big banging PWM method.
Thanks...

The source code for the Arduino libraries is available, just go look there to find out how it does it.

Please do not suggest big banging PWM method ... why do you say that if you do not know how the library does it?

@jsotola Sometimes people advise using alternatives when they too don't have a proper knowledge so, to them only, i would prefer not to be recommended bit banging method (alternative).

@CoderBittu you asked how the library works ... there is no recommendation to be made ... there are no alternatives ... you did not ask for suggestions about how you should do it

I believe the servo library uses one (or more depending on board architecture) inbuilt 16 bit timers (timer1 on the UNO) to produce PWM  directly on a digital pin using a low level equivalent of a digital write. The direct use of the timer prevents the use of that timer for other purposes like analogWrite().
In comparison a frequently used, more user-friendly method of producing PWM on Arduino is to use analogWrite() on designated PWM pins only.
The servo library source code is on github here.
You may have already answered your own question, as you did mention the bit-banging PWM method. That's what it looks like to me, but I'm not an expert on lower level programming.
See also: How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?


text:
i am tying to make a automated parking lot with a gate, sensor, button, keypad, how can i time how long has each car spent inside?
the project requires a automated parking lot, I have been able to connect and function the sensor and button for exit and enter, and the led(red lights when parking is full, green when there is spots). the maximum cars are 5. and the lcd prints the spots available and the spaces taken. the keypad is also connected. now what I need is to make a code that times each car that enters in the order that they enter in and for each car that leaves it has to enter its order of entering to calculate the price it has to pay with this equation: Parking Fee (fils) = time(sec) x 0.29fils
here is the code i have at the moment:
#include <Servo.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Servo myservo;

#define Servo 7
#define exit SDA
#define power 6 // extra
#define ground 10 // extra
#define capacity 5
#define R_led SCL
#define G_led 13
int val;
int n = 5;
int s = 0;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[ROWS] = {A4, A3, A2, A1}; //Arduino Pins
byte colPins[COLS] = {8, 9, 10}; //Arduino Pins

void setup(){
  for(int i=0;i<4;i++){
    pinMode(rowPins[i],INPUT);  //set row pins as inputs
    pinMode(colPins[i],OUTPUT); //set column pins as outputs
  }
  Serial.begin(9600);
  myservo.attach(Servo);
  lcd.begin(16,2);
  pinMode(power,OUTPUT);
  pinMode(ground,OUTPUT);
  pinMode(exit,INPUT);
  pinMode(G_led,OUTPUT);
  pinMode(R_led,OUTPUT);
  digitalWrite(ground,LOW);
  digitalWrite(power,HIGH);
  myservo.write(0);
  digitalWrite(R_led,LOW);
  digitalWrite(G_led,LOW);
}

void loop(){
  if (n>=1){
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("Spots left: ");
    lcd.print(n);
    lcd.setCursor(1,1);
    lcd.print("Cars inside: ");
    lcd.print(s);
    digitalWrite(G_led,HIGH);
    digitalWrite(R_led,LOW);
    delay(30);

  }
  else {
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("The parking is");
    lcd.setCursor(0,1);
    lcd.print("full!");
    digitalWrite(G_led,LOW);
    digitalWrite(R_led,HIGH);
    delay(30);
  }
val = analogRead(A0);
// Serial.println(val);
if (val>950)
{
  if (n!=0){
    n--;
    s++;
    myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
if (digitalRead(exit)==1)
{
  if (n!=capacity){
    n++;
    s--;
      myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
delay(20);
  int keyValue=0;
    digitalWrite(colPins[0],HIGH); //Set column1 as high
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){             //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
            //display either 1,4,7 or *
        Serial.println(keys[i][0]); //display key pressed
        delay(500);
      }
    }

    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],HIGH); //Set column2 as high
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){              //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
        //display either 2,5,8,0
         Serial.println(keys[i][1]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],HIGH);//Set column3 as high
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either 3,6,9,#
         Serial.println(keys[i][2]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],HIGH);//Set column4 as high
    for(int i=0;i<4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either A,B,C,D
         Serial.println(keys[i][3]); //display key pressed
        delay(500);
      }
    }
}

Depends on the required accuracy. You can use millis() to measure time, though it is not very accurate depending on the internal clock. If you need correct time you need to use a Real Time Clock module (RTC). How accurate should it be? What time ranges do you want to measure?

yes I want to use millis(), but I can't figure how to do it on the requirements I mentioned above

the range is when the car enters the parking until it exits

some of your code makes no sense ... it seems that you are not thinking clearly about your program ... why are you scanning the keypad? ... look at Keypad library examples

just do what a real parking lot does, record the arrival time

ok can you please let me know how to record the arrival time ? I would really appreciate it

When using millis(), the arrival time is the return value of millis() at the time of arrival. Thats what millis() does. It gives you the number of milliseconds since startup, thus time. When someone arrives, save the value of millis() in a variable. Later you can subtract that value from millis() and get the time of stay in milliseconds.

yes I understand that but I want to know how to count the time for different cars at the same time, to be more precise 5 cars and each car when it leaves it enters the number of order it entered in to calculate the fee

do this on paper first ... draw the parking lot with 5 spaces ... use pieces of paper to represent vehicles ... write down everything that you need to keep track of ... translate into a program

@FaisalAlrafaei did you write the code that you presented?

firstly about drawing there is no need for it because I am using tinkercad, secondly the code I collected information I found on the internet and edited them

@FaisalAlrafaei With drawing on paper jsotola wanted to guide you to solve the problem yourself. Often programming questions can be solved, when you make yourself clear what the exact steps in a process are. These steps then can be translated to code way easier. Tinkercad doesn't do that for you and you don't seem to have every step of the process in mind.

ok, use toy cars instead, but write down all the information that you need in order to charge for the correct time of each parked vehicle

code I collected information I found on the internet and edited them ... you really need to learn what the code actually does ... the sketch has a lot of un-necessary code

For measuring the time for each parking lot:
Declare an array of unsigned long with one element per parking lot (so 5 in this case) and initialize it with zeros:
#define N_PARKING_LOTS 5
unsigned long timestamps[N_PARKING_LOTS] = {0};

Then go to the place in your code where a new car arrives in its parking lot. You need the number of the used parking lot. Set the corresponding element in the array to millis() (for example here element 3, so the 4th parking lot):
timestamps[3] = millis();

When the corresponding car leaves you can get the time by calculating the difference and by that calculate the price:
unsigned long park_duration = millis() - timestamp[3];
float price = (park_duration/1000)*0.29;

How you know the parking lot depends on your actual process. It is difficult to understand what you want to say in your question. You could guide the arriving car to a parking spot chosen by you.
Btw: The code will get much easier for you when you actually use the Keypad library, instead of just including it. Then your current code will get way shorter.

How do you know which car is which. You could use a long range RFID tag in each one then when sensing you will know who and your clock will tell you when and you hopefully know if it is coming or going. After that you should be able to work the code.


text:
Insufficient RX signal delta when using MKR RS485 + Nano, but not Mega
I'm having an issue where an arduino Mega has been used to communicate with an RS485 bus, using an MKR shield [1] as a breakout board. When I build it with a Mega, the system works fine. I've torn down and rebuilt multiple times, and it works every time, no troubles.
However when I build it with a nano it does not work - rx is faulty. Devices on the bus can hear the nano, and a response pulse train is sent back correctly, so outgoing communication is fine.  However at the RX pin on the nano, the serial signal is present when viewed on an oscilloscope, but ranges between +5V and 4.5V, and the RX LED never flashes.
The layout is a simple wiring, there are no (relevant) external components (there is an LCD, but this works fine), just pin-pin connections.
Why is it the mega seems to work, but the nano not? I'm currently guessing that the /RE pin on the MKR RS485 device (MAX3157 [2]) is not being powered properly, and I am seeing the un-amplified serial output? I can't understand why this would be, though, as both the mega and the nano have the same rated max current per-pin.
I've checked the /RE line alone when disconnected, and it is correctly at 5V when not driven, and drives to 0V when the pin is pulled low.
Is there an alternative fix I could use to bring the +5V-4.5V to +5V-0V ? Do I need to have the
[1] MKR Shield schematic : https://www.jameco.com/Jameco/Products/ProdDS/2294031Schematic.pdf
[2] Max datasheet : https://datasheets.maximintegrated.com/en/ds/MAX3157.pdf

Are you sure that the RX pin is in input mode?

Try removing R5 and R6. You can also reduce R3 to 1K.

OK, answering myself here. It looks like the output of the shield is unable to drive hard enough against the internal pullups of the nano, for some reason. (Yes, its definitely in input mode, you check check the port values, and it is correct)
Leaving the RX output from the shield to float, it works fine, but if connected to an external pullup resistor, then it does not - and I get the same behaviour as when the RX is tied to the nano.
I've been unable to disable the nano's internal pullups in software for some reason. It looks like I will need to add a buffer to increase the drive current. This is a little irritating as it means another breakout board!


text:
Can I get the actual fingerprint data from AS608?
So I own an AS608 fingerprint scanner, and I've been looking everywhere for information on how to get the fingerprint data (raw, processed, or binary) from the scanner itself to use with a database but to no luck.
I've seen some answers on here, but they don't point to anything specific, so I am bubbling asking again. I have intentions of using this with Atmega MCUs, I just need to get any form of data that I can then tie to a user for a system. Thank you!
This is the datasheet, but it doesn't really say if it can do that or not. The datasheet doesn't really talk about its applications.
So this is the fingerprint sensor I have, here is a link to it on a store. It is based on AS608 as RowanP pointed out in the comments.

please provide a link to the manufacturer datasheet for the AS608

An https://server4.eca.ir/eshop/000/AS608/Synochip-AS608.pdf 144MHz 512KB Cortex-M is capable of many things.  You'd have to find out what the code embedded in the scanner is programmed to communicate.

https://server4.eca.ir/eshop/000/AS608/Synochip-AS608.pdf

You’re linking to a microprocessor (AS608) that says it is intended for integration with fingerprint equipment. However after a quick skim of the datasheet it does not seem to have inbuilt fingerprint scanning peripherals. Are you saying it does (if so can you point to the relevant section of the datasheet)? Alternatively are you saying you have it connected to a fingerprint scanner? If so please provide details of the scanner. Or if both of these alternatives are wrong can you provide more information?

As background (and acknowledging the OP question is more specific) there is a general discussion on this topic here https://arduino.stackexchange.com/q/85270/71575

I did some googling and I can see a number of sensors labelled AS608, which is I guess a reference to the embedded chip. What you might do with the module (eg access to internal data) would depend on how much control you have over the code loaded into the AS608 I would guess. Although these all look the same I’d anticipate a fair bit of variation?

The best doco I can find is at Adafruit https://cdn-learn.adafruit.com/downloads/pdf/adafruit-optical-fingerprint-sensor.pdf

The Adafruit guide @RowanP posted shows it is possible to get images. //
https://makersportal.com/shop/optical-fingerprint-sensor-as608 has a pic of their AS608 fingerprint sensor board clearly showing the Synochip AS608 processor on a board silkscreened with "DY50-2V1"  Searching for DY50 leads to Ziantec Fingerprint Module or ZFM Fingerprint module with an english datasheet at https://www.velleman.eu/downloads/29/infosheets/vma329_datasheet.pdf and a chinese one at https://cdn-shop.adafruit.com/datasheets/DY001fingerprint.pdf //  What module do you have? Post pics?

https://github.com/bastianraschke/pyfingerprint/blob/Development/src/files/examples/example_downloadimage.py is a python example from https://github.com/bastianraschke/pyfingerprint for use with ZhianTec ZFM-20, ZFM-60, ZFM-70 and ZFM-100 and several other modules.  It suggests that the Adafruit Library https://github.com/adafruit/Adafruit-Fingerprint-Sensor-Library is the inspiration.  So yes, it seems possible, but the exact interfacing depends on the module, and what you want to do with it. Do you want to do image processing on the ATMega, or pass it through to a computer? Try the python.

I want to collect the data and store it on a database and use it for authentication elsewhere. I'm using the AtMega238.

If you can extract the actual fingerprint data you want from your device with a computer and those python programs, then your device can do it.  If so, then you can look at the python code and maybe adapt/use it or the Adafruit library to accomplish your purpose.  From your Q its hard to tell exactly what device you have or exactly what it is capable of.

@BeulahAkindele Can you show a photo of the PCB at the back of the actual sensor?

The thing is... I am using Cpp on an Atmega microcontroller. I really need to consolidate on an MCU solution right now for the project at hand. The python libraries you listed actually use USB fingerprint scanners, I need a serial/GPIO solution.
Also, @RowanP I added the images.

@DaveX The python libraries you listed actually use USB fingerprint scanners, I need a serial/GPIO solution

The specific device you actually have is still a bit unclear from your Q.  If it is compatible with the datasheet from Adafruit that you linked, then it looks like yes, you can get the image data out.  They demo that use-case with a (DY20 device)
serial/GPIO passthrough to USB rigged on an arduino, and then show the image in a windows app.  If that adafruit library demo works with your device, then the "FINGERPRINT_UPLOAD" Command, 0x08, or "Section 6.3.9 -- Upload Image" in https://www.velleman.eu/downloads/29/infosheets/vma329_datasheet.pdf should get your image.


text:
I am trying to connect ps3 controller to Arduino mega using usb host shield, but it isn't getting?
I tried various method from YouTube and also debugged it. It shows that ps3 controller address was set to local Bluetooth address, after that when I try to connect, it shows that it is receiving request from controller but however the request isn't getting completed
PS3 Bluetooth Library Started
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1A:7D:DA:71:10
Wait For Incoming Connection Request
Incoming Connection Request
Remote Name: Pro Controller
Connection Failed: 08
Connection Failed: 08
Connection Failed: 08
Connection Failed: 08
Connection Failed: 08
Wait For Incoming Connection Request
HCI Disconnected from Device
Wait For Incoming Connection Request
Connection Failed: 13
Connection Failed: 13

when I try to reset ps3 controller address, it shows that address was reset.
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1A:7D:DA:71:10
Wait For Incoming Connection Request
PS3 Bluetooth Library Started
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1A:7D:DA:71:10
Wait For Incoming Connection Request
setAddr: 0E
BTD Init Failed, error code: 0E

Dualshock 3 Controller Connected
Bluetooth Address was set to: 00:1A:7D:DA:71:10
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1A:7D:DA:71:10
Wait For Incoming Connection Request
PS3 Bluetooth Library Started
PS3 Bluetooth Library Started
Bluetooth Dongle Initialized
HCI Reset complete
Write class of device
Local Bluetooth Address: 00:1A:7D:DA:71:10
Wait For Incoming Connection Request
Incoming Connection Request
Remote Name: Pro Controller
Connection Failed: 08
Connection Failed: 08

yes I am trying to connect a ps3 controller only @jsotola. also I have one  old ps3 controller which is getting connected but this one doesn't. can you please suggest something. I am in desperate need of it

@jsotola sorry my mistake, I have made the changes in the question and now it says that I am trying to connect ps3 controller. thank you for suggesting changes. also please do suggest something. thanks

search for arduino ps3 controller


text:
Can I use STL on an Arduino Uno?
I started using an Arduino Uno days ago. I'm an experienced C++ dev and I'm kind of confused.
Is the Arduino compiler different than a C++ one? What C++ version does Aruidno Uno use? Why it doesn't it support STL? Is it possible to use STL?
Also, can I configure their cpp file and use my own main function? The loop / setup thing really does annoy me. Thanks!

turn on verbose output in preferences ... examine the resulting info in the console window

is that an arduino ide things? bcs im using platform io

Yes, there are STL implementations for the Arduino Uno (check the library manager). Note that some of them are unsupported and/or outdated quite a bit. The downside of using STL on the Arduino is also that these classes may use to much memory. Because of it's very limited memory (only 2kb), dynamic memory allocation is quite risky, as memory fragmentation will quickly cause the program to crash.
The Arduino build system uses a pre-build step around the ino files that remove a lot of pain locating header files and setting up build paths from the user. This is a bit confusing at first for an experienced C++ programmer, but it simplifies things a lot, particularly when it comes to using different libraries. This build step automatically locates the include paths for all .h files referenced in the .ino. The system requires that you declare the loop() and setup() methods, but what you do with them is up to you. You can leave either of them empty, or never return from the loop function, calling into whatever main function you want to use.
As a side note: There are other C++ compiler features that are disabled or unsupported on the Uno because they would make the code to big. These include dynamic type casting using dynamic_cast<> and exception handling.

Thanks! i googled the disabled compiler features and i didnt found them, can u tell me more about them or their is only dynamic casting and exeptions?

I have found about these only, but there might be more. The compiler is actually a normal GCC (although a bit an old version) and so supports the full set of C++11 features, but the runtime library is missing some pieces.


text:
When i upload the code to nodeMCU this error comes I have checked libraries ,ports made enviroment for nodemcu but error always come to screen
Arduino: 1.8.7 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Executable segment sizes:

ICACHE : 32768           - flash instruction cache

IROM   : 425200          - code in flash         (default or ICACHE_FLASH_ATTR)

IRAM   : 29829   / 32768 - code in IRAM          (IRAM_ATTR, ISRs...)

DATA   : 1664  )         - initialized variables (global, static) in RAM/HEAP

RODATA : 7200  ) / 81920 - constants             (global, static) in RAM/HEAP

BSS    : 28472 )         - zeroed variables      (global, static) in RAM/HEAP

Sketch uses 463893 bytes (44%) of program storage space. Maximum is 1044464 bytes.
Global variables use 37336 bytes (45%) of dynamic memory, leaving 44584 bytes for local variables. Maximum is 81920 bytes.
esptool.py v3.0
Serial port COM6
Connecting....
Chip is ESP8266EX
Features: WiFi
WARNING: Detected crystal freq 255.46MHz is quite different to normalized freq 40MHz. Unsupported crystal in use?
Crystal is 40MHz
MAC: 44:17:93:11:8c:e4
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 468048 bytes to 339496...
Writing at 0x00000000... (4 %)
Writing at 0x00004000... (9 %)
Writing at 0x00008000... (14 %)
Writing at 0x0000c000... (19 %)
Writing at 0x00010000... (23 %)
Writing at 0x00014000... (28 %)
Writing at 0x00018000... (33 %)
Writing at 0x0001c000... (38 %)
Writing at 0x00020000... (42 %)
Writing at 0x00024000... (47 %)
Writing at 0x00028000... (52 %)
Writing at 0x0002c000... (57 %)
Writing at 0x00030000... (61 %)
Writing at 0x00034000... (66 %)
Writing at 0x00038000... (71 %)
Writing at 0x0003c000... (76 %)
Writing at 0x00040000... (80 %)
Writing at 0x00044000... (85 %)
Writing at 0x00048000... (90 %)
Writing at 0x0004c000... (95 %)
Writing at 0x00050000... (100 %)
An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Are you sure you selected the correct board and partition scheme?

Welcome! I am not familiar with nodeMCU but your error sounds similar to what happens in Linux, the errors are sent to the error out which in your case may be the console. Sorry I do not have the time to get into this further but you have the manuals etc this should give you an idea of what to look for,

You might want to try to upload with verbose compilation on and then post the output, it might give us a better idea of your problem (Look at the preferences in the Arduino environment).


text:
ESP32 heap problem
I wrote a simple C++ program (just main.cpp and corresponding platform.io files & libraries) to get BME280 sensor readings. It worked fine until I decided to use good programming practices, using header files and separating the read function from main.cpp, I get a heap error, stated below:
CORRUPT HEAP: Bad head at 0x3ffb8444. Expected 0xabba1234 got 0x3ffb84c4
abort() was called at PC 0x40083b99 on core 1

ELF file SHA256: 0000000000000000

Backtrace:
0x400857f0:0x3ffb1aa0
0x40085a65:0x3ffb1ac0
0x40083b99:0x3ffb1ae0
0x40083cc5:0x3ffb1b10
0x400d90a3:0x3ffb1b30
0x400d55bd:0x3ffb1df0
0x400d5558:0x3ffb1e40
0x4008a0f1:0x3ffb1e70
0x40081dee:0x3ffb1e90
0x40083a91:0x3ffb1eb0
0x4000bec7:0x3ffb1ed0
0x400e89b5:0x3ffb1ef0
0x400d13ab:0x3ffb1f10
0x400d0f75:0x3ffb1f30
0x400d3ba9:0x3ffb1fb0
0x40086a75:0x3ffb1fd0

Rebooting...

Any ideas on that?
By the way, I also used pointers for both the function and the variable passed to it, to no avail.
I also tried a series of combinations with the libraries I am using - Adafruit BME280 and Adafruit Unified Sensor.
Going back to having all the code in one file works...
Thanks
My code:
//main.cpp
#include <sensor_readings.h>
#include <settings.h>

void refresh_readings();  // Declare in the header so that the compiler knows about it before it is called in loop()

Adafruit_BME280 bme; // I2C

void setup() {
  pinMode(LED_BUILTIN,OUTPUT);
  Serial.begin(9600);
  bool status;

  // (you can also pass in a Wire library object like &Wire2)
  status = bme.begin(0x76);
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}

void loop() {
  void (*fcnPtr)(Adafruit_BME280){ &refresh_readings };
  (*fcnPtr)(bme);
  //refresh_readings(bme);
  delay(4000);
}

;platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
    Adafruit_Sensor
    adafruit/Adafruit Unified Sensor@1.1.4
    adafruit/Adafruit BME280 Library@^2.2.2
upload_port = /dev/cu.SLAB_USBtoUART
monitor_port = /dev/cu.SLAB_USBtoUART
monitor_speed = 9600

//sensor_readings.cpp
#include <sensor_readings.h>
#include <settings.h>

void refresh_readings(Adafruit_BME280 bme) {
  float f_temperature;
  float f_humidity;
  float f_pressure;
  float f_altitude;

  digitalWrite(LED_BUILTIN, HIGH);

  f_temperature = bme.readTemperature();
  f_humidity = bme.readHumidity();
  f_pressure = bme.readPressure() / 100.0F;
  f_altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);

  // Temperature

  Serial.print(f_temperature);
  Serial.println(" °C");

  // Humidity
  Serial.print(f_humidity);
  Serial.println(" %");

  // Pressure
  Serial.print(f_pressure);
  Serial.println(" hPa");

  // Appx altitude
  Serial.print(f_altitude);
  Serial.println(" m");

  digitalWrite(LED_BUILTIN, LOW);
  Serial.println("------------");
}

//sensor_readings.h
#ifndef SENSOR_READINGS_H

    #define SENSOR_READINGS_H

    #include <Arduino.h>
    #include <Adafruit_Sensor.h>
    #include <Adafruit_BME280.h>

    #define SEALEVELPRESSURE_HPA (1013.25)

    void refresh_readings(Adafruit_BME280 bme);

#endif

//settings.h
#ifndef SETTINGS_H
    #define SETTINGS_H
    #define LED_BUILTIN 2   // This is valid for my devkit
#endif

There's a couple problems with your code.
void refresh_readings();  // Declare in the header so that
                          // the compiler knows about it
                          // before it is called in loop()

This is a lie! Don't tell your compiler there's a refresh_readings function that takes no arguments when you haven't defined one. Remove that line, you already have the function declaration in your header.
void (*fcnPtr)(Adafruit_BME280){ &refresh_readings };
(*fcnPtr)(bme);

This is just a very convoluted way of typing:
refresh_readings(bme);

So just use the normal function call syntax.
The main issue as far as I can tell though is that you are copying the bme object when passing it to the readings function, which is not advisable in general for this sort of object (they represent a piece of hardware that you can't really copy). That class in particular has a bunch of pointer members, a destructor that deletes them, but no copy constructor as far as I can tell, which is a bad thing.
Change your function to this signature (both in the header and the C++ file):
void refresh_readings(Adafruit_BME280& bme);
//                 pass by reference ^

And use the normal call syntax (refresh_readings(bme);).

Dear Mat, thank you VERY much for taking your time to answer to my question. It is working now. Regards, Carlos.


text:
How to address arbitray leds (WS2812B) in an already defined leds array?
I want to address the first and last three pixels of a 9 pixel strip and apply a gradient to them using FastLED.  I can successfully address them but the colors displayed are not correct.  Is there something I'm overlooking or misunderstand about the way FastLED works?
#include <FastLED.h>

// the whole strip
#define NUM_LEDS 9

#define LED_PIN 6

CRGB leds[NUM_LEDS];

// Define the indexes of the first and last 3 indexes of a 9 pixel strip
int customLeds[6] = {0,1,2,6,7,8};

// My Palette
DEFINE_GRADIENT_PALETTE (heatmap) {
  0, 255, 0, 0,      // Red
  128, 0, 255, 0,    // Green
  255, 0, 0, 255     // Blue
};

CRGBPalette16 myPalette1 = heatmap;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(20);
}

void loop() {

  for (int i = 0; i < (sizeof(customLeds)); i++) {
   // Each i led get the correct color given their place in the array  - 0, 42.5, 85, 127.5, 170, 212.5, 255
    leds[customLeds[i]] = ColorFromPalette(myPalette1, (i * (255 / sizeof(customLeds))), 255, LINEARBLEND);
  }

  FastLED.show();

}

Sizeof doesn't give the number of elements but the amount of memory used by the array ..

what does this mean? ... colors displayed are not correct

The colors of the pixels needs to follow the pallete but while they are colors from the pallete they are right..they're all over the gradient and not folowing linearly.

I realized my problem...this:(i * (255 / sizeof(customLeds)) - doesn't work because the two arrays are of different lengths! I'm homing in on a solution.

Please replace sizeof(customLeds) with sizeof(customLeds)/sizeof(customLeds[0]) to actually get the numbers of elements in the array instead of the number of bytes

Yes, a slightly more elegant solution.  I just hard coded the total for ease of use.  Later in the project I plan to use this. But given my solution below, that method become moot as I use a boolean array of the total length.  Hence my use of the hard coded total and the increment variable. Thanks @chrisl

So here is the answer I came up with:
#include <FastLED.h>

// the whole strip
#define NUM_LEDS 9

#define LED_PIN 6

CRGB leds[NUM_LEDS];

// Define the indexes of the first and last 3 indexes of a 9 pixel strip
bool customLeds[9] = {1, 1, 1, 0, 0, 0, 1, 1, 1};
int customLeds_num = 6;

// My Palette
DEFINE_GRADIENT_PALETTE (heatmap) {
  0, 255, 0, 0,      // Red
  128, 0, 255, 0,    // Green
  255, 0, 0, 255     // Blue
};

CRGBPalette16 myPalette1 = heatmap;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(5);

}

void loop() {

  FastLED.clear();

  //  Keep track of how many leds have been lit
  int customLedIndex1 = 0;

  for (int i = 0; i < NUM_LEDS; i++) {
    // Each i led get the correct color given their place in the array  - 0, 42.5, 85, 127.5, 170, 212.5, 255

    //lights a specific pixel only if it's in the customLeds truth table
    if (customLeds[i]) {
      // works out where on the gradient a specific pixel is
      leds[i] = ColorFromPalette(myPalette1, (customLedIndex1 * (255 / 5)), 255, LINEARBLEND);

      //increments the index for the next pixels value on the gradient
      customLedIndex1++;

    }

  }

  FastLED.show();

  customLedIndex1 = 0;

}

The solution involved using a boolean array that indicates which leds needed to be on (true / 1) and which off (false / 0) and then create a separate index (customLedIndex) which counted how many of the leds where lit so they could receive the correct color corresponding to their 'place' in the palette


text:
Initializing an object as class member resulting in linking error?
I'm a little dumbfounded as to why this isn't working. I keep getting the following linker error:
In file included from src\ac.cpp:1:0:
src/ac.h:9:21: error: expected identifier before numeric constant
 #define RECEIVE_PIN 0
                     ^
src/ac.h:14:26: note: in expansion of macro 'RECEIVE_PIN'
     static IRrecv irrecv(RECEIVE_PIN);
                          ^
src/ac.h:9:21: error: expected ',' or '...' before numeric constant
 #define RECEIVE_PIN 0
                     ^
src/ac.h:14:26: note: in expansion of macro 'RECEIVE_PIN'
     static IRrecv irrecv(RECEIVE_PIN);
                          ^
*** [.pio\build\esp32cam\src\ac.cpp.o] Error 1
*** [.pio\build\esp32cam\src\main.cpp.o] Error 1

I am simply trying to initialize the IR receiver with static IRrecv irrecv(RECEIVE_PIN);, but the compiler is refusing to link it together.
#ifndef _AC_H_
#define _AC_H_

#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

#define RECEIVE_PIN 0

class IR
{
public:
    static IRrecv irrecv(RECEIVE_PIN);
    static decode_results results;
    void initRecv();
    bool waitForIR();
};

extern IR ir;

#endif

If I do static IRrecv irrecv; it successfully compiles, but I'm unsure if I can pass the pin variable after the fact.

https://stackoverflow.com/questions/5019856/initialize-static-variables-in-c-class

what happens if you use RCV_PIN? ... looks like RECEIVE_PIN is a macro

@Mat It doesn't seem to be possible to change the value after initializing it

@jsotola I've rewritten it in various formats. I've tried all kinds of data types, names, and initializing it as irrecv(0) as well.

Static data members have to be defined outside the class declaration.
The initialization happens at the point where the members are defined:
file ac.h:
//...

class IR
{
public:
    // Static data members are declared only:
    static IRrecv irrecv;
    static decode_results results;
    void initRecv();
    bool waitForIR();
};

file ac.cpp:
#include "ac.h"

#define RECEIVE_PIN 0

// Definitions and initializations of static data members:
IRrecv IR::irrecv(RECEIVE_PIN);
decode_results IR::results;


text:
passing variable to function
I have the following code to turn on or off led. I would like to modify the function to pass the pin as well. what should X be substituted with?
#define BIN_LED 2
#define PIN_LED 3

void led(uint8_t x, bool on) {
 digitalWrite(x, on ? LOW : HIGH);
}

void setup() {}

void loop() {
 led(BIN_LED, true);
 delay(1000);
 led(BIN_LED, false);
 delay(1000);
}

think ..... what is X in digitalWrite(X, on)?

FWIW, consider why you're doing this as well. If you want a shorter function name, consider just aliasing the fn. If you want a more "meaningful" fn, I'm not sure this achieves that.

You've done it. All that's left is to specify a data-type 'X' in the function declaration, just as you've already done for 'on'. 'uint8_t' would be a reasonable choice.

it didn't work. I updated the question with your suggestion.

@motionchannel  It did not work because you have not configured the pin as an output. The answer is correct, the code compiles and correctly passes the pin number. Put pinMode (BIN_LED, OUTPUT); in your setup() function to make your code light an LED. You could look at some example code from the Arduino IDE to see how this works.


text:
Handling non-standard I2C read response lengths with Wire library
I'm trying to read from a Sam&Wing XW12A 12 channel touch sensor IC using I²C. The IC responds to an address read packet with 16 uninterrupted bits representing its state.

However, since I²C usually uses 8 bit bytes separated with an ACK signal, the 9th bit is lost when the controller sends an ACK bit for the first 8 bits.

My current code, using the Wire library, is below:
Wire.beginTransmission(devAddr);
Wire.requestFrom((uint8_t)devAddr, 2);
uint16_t buf;
Wire.readBytes((uint8_t *)&buf, 2);

This will return a 16 bit value, with bits 0-7 correct, then bits 9-15 shifted along with bit 8 missing.
Is there a way to prevent the controller from sending ACK bits and read the continuous 16 bits using the Wire library? And if not, is there any other better approach than just bitbanging the signal manually?

Edit: I've translated the I2C section of the datasheet below.

Edit 2: To prove that there's an issue, I've captured oscilloscope traces while bitbanging the address read header to the IC (but not sending ACKs). I've included a capture for each pad being pressed (and none pressed), you can see that pad 8 occurs on the first clock pulse after pad 7. If the IC was implementing I²C correctly, I would expect a gap of one clock pulse at this point while the IC waits for an ACK from the controller.

what are datasheet sections 4.6.3 and 4.6.4 about?

I've added a translation of the I2C section of the datasheet to the question.

I think the documentation is just somewhat bad in that it doesn't show the an ACK where they almost certainly are.  Not having one there would make this not I2C and not compatible with things that are I2C for no particularly good reason. Did you confirm that is this actually a problem? Or are you just noticing the lack of an ACK in the documentation?

This is definitely a problem - the capture shown in the question is from an actual device using this IC, I can see that the bit representing PAD8 is missing in the response data, and should appear at the same point that the controler sends the ACK. I haven't been able to confirm that the bit value is set correctly by the target when the controller does not send an ACK yet, but it seems more likely to me that the I2C protocol implementation is non-standard than the IC's read data just omitting this pin state altogether.

I've managed to bitbang the address read byte to the IC and I can confirm that it does behave as defined in the datasheet, i.e. sends the 9th bit on the same clock pulse that the controller sends an ACK.

Don't know what to tell you. Section 4.6.3, when machine translated to English, seems to describe standard I2C behaviour for ACK/NAK at each 9th bit. You even received the four padding '1' bits on the end that they described to make the actual data bits, to be padded to 16. Anyway, if you want to do something like I2C but not have the ACK/NAK where it is required by the I2C standard, then yes you'd need to bit-bang. But, I don't see putting that as answer because I don't think it has anything to do with the actual problem. So far as I can tell, your diagram is just a better diagram.

Your translation of the datasheet states "The information is transmitted in bytes (8 bits), and the receiver generates a response at the 9th bit." So that 9th bit IS just the Acknowlegment. So from our perspective this is just plain I2C. We also only can go with the datasheet. Are you really sure that the bit for pad8 the ack bit?

Can you please explain in more detail why you think that the bit for Pad8 is missing? In the question I don't see much supporting your theory that the ack should not be used (besides the last image in the datasheet snippet. And I don't really trust that image)

I've edited my question to add oscilloscope captures for each pad being pressed while bitbanging the header. If the IC was implementing I²C correctly, I'd expect to see a gap of one clock pulse between pad 7 and pad 8 as the IC waits for the ACK signal from the controller, but you can see that pulse for pad 8 follows directly on from pad 7.

Your translation of the datasheet states "The information is transmitted in bytes (8 bits), and the receiver generates a response at the 9th bit." So that 9th bit IS just the Acknowlegment.
I think that the datasheet is just referring to the header here, i.e. the controller sends the 8 bits representing the address and the R/W flag, and the target responds with an ACK at the 9th bit.

Interestingly, I've noticed that the ICman SC12A IC seems to describe the same behaviour in its datasheet. It's a similar IC, but has slightly different functionality and doesn't seem to be a clone. I was initially thinking that there might be a 16 bit variant of I²C that's more common in the Chinese market, but now I'm leaning towards it being a mistake in one implementation that's been copied from manufacturer to manufacturer.

The for(bitnum=0;bitnum<16;bitnum++) loop in your linked ICman SC12A datasheet supports your assertion also. They read 16bits of data without any handling for the ACK/NACK that standard I2C requires in the middle. This seems spectacularly stupid on the chip-makers part. I suppose if you wanted you could use the I2C peripheral to read other things on the bus and then disable the I2C peripheral and bitbang their wacky2C protocol on the same pins, allowing them to coexist on the same lines.  At least, I think that could work.

Ultimately, if this question is properly answerable by anyone, it's probably going to be by you. In which case, you could rewrite it as more of a "How do I use the Sam&Wing XW12A 12 channel touch sensor IC with Arduino", maybe make reference how a conventional I2C reading code fails, and then present what you've learned above cleaned up in an answer. Just so they're not reading the saga.  If you go that route it may make more sense to delete this question and present the your own Q&A in one go under a new question.

As you already have a code for bitbanging it partly I would suggest using this and extend it to read the data bits. That shouldn't be that difficult at this point. It might be possible to get this working with your own changes in the Wire or a Software I2C library (the former is less probable), but probably it is not really worth the hassle. Though you might wanna go the extra mile and make a library specific for reading that sensor, which you could then publish on github for others.

If you happen to be on an AVR with a USI peripheral, this may give some hardware assistance, since it doesn't do I2C outright, but has the building blocks for it and, I think, this non-standard protocol. But, most of the AVR used with Arduino don't and it may not be worth doing this either. However, it is the closest thing that comes to mind for supporting hardware.


text:
On a custom ESP32-based PCB, I can' flash anymore after the first successful firmware flash
I have designed and manufactured a custom PCB, with an ESP32 chip on it.
I use my FTDI cable to upload my firmware.
I have no problem to flash my firmware, and it runs with no problem. So far so good.
But then, any successive attempts to flash again is a dead end as it results into a timeout (of course I still press the boot button on my PCB).
If I take a new PCB, the first flash is OK but I cannot do it again.
Note: to make thing as simple as possible, I simply use the Arduino IDE and my do-nothing code as my firmware replacement:

void setup() {
  Serial.begin(115200);
  //Serial.setDebugOutput(true);
  Serial.println("Yo from SDL!");
}

// the loop function runs over and over again forever
int _loop = 1;

void loop() {
  Serial.print("Loop #");
  Serial.println(_loop++);
  Serial.println();
  delay(3000);
}

[UPDATED] Here is the schematic regarding the ESP32 and the GPIO0, GPIO2:
The schematic of the PCB regarding the boot loader
Do you have any clue?!

Have you properly wired in the GPIOs that trigger the bootloader mode?

@Majenko I did wired the boot loader pin and added a button to turn the chip to boot loading mode. To make it clear, I successfully  download the firmware in the chip the first time. But after that I cannot update.

A "blank" chip will be in bootloader mode by default IIRC. Can you share your schematic and board design?

@Makenlo Oh, I see, I might have screwed up the boot loader schematics? let me share this part with you in a few moment

@Majenko I have uploade the schematics of the PCB regarding the boot loader

IO2 needs to be connected to a pulldown resistor (your buzzer FET has a pulldown on its input which does the job, which is fortunate). I would consider moving the buzzer elsewhere and keeping IO2 just for the pulldown resistor if possible.
IO0 needs a pullup resistor.
You need some way of resetting the ESP32 through pulling the EN pin low when you want to reprogram it.
Both IO0 and the EN pin are usually controlled through a combination of the DTR and RTS pins of the USB to UART adapter to do the resetting automatically. Without that you will have to manually hold IO0 LOW while briefly pulling EN low to reset the chip.

as per the doc the io0 as an internal pull-up: do we really needs to add an external one?  (“Each strapping pin is connected to its internal pull-up/pull-down during the chip reset. Consequently, if a strapping pin is unconnected or the connected external circuit is high-impedance, the internal weak pull-up/pull-down will determine the default input level of the strapping pins.”)

@StéphanedeLuca Interesting - that I did not know. Still, it's good to be explicit in these things I think to avoid uncertainty. But if the internal one works then that's fine. You still need to toggle EN though ;)

So IO0 was OK. But I screwed up the EN (it was attached to a pull up). And how @Majenko pointed out, EN must be briefly set to low. Thanks a lot


text:
Send same telemetry data to two different serial ports?
I'm using a Teensy 3.5 to control a wall-following robot. The robot sends telemetry to my PC via two independent ports - Serial1 & Serial.  Serial is the normal USB port, used when I direct-connect to the robot for troubleshooting, etc. Serial1 is tied to an HC-05 Bluetooth transceiver and it is used to acquire telemetry remotely.
I have to send telemetry to both ports, because I never know which (or either, or both) port(s) are actually active at any one time, so I wind up with lines like the following all over my code:
Serial.printf("\nChecking for MPU6050 IMU at I2C Addr 0x%x\n", MPU6050_I2C_ADDR);
Serial1.printf("\nChecking for MPU6050 IMU at I2C Addr 0x%x\n", MPU6050_I2C_ADDR);

needless to say this gets old after a while, and is error prone (I might edit one line and forget to copy/paste it to the other one).  What I would really like to do is create a function that would accept a printf-style string and send it to both ports, but I'm having trouble figuring out how to do that.
I have tried playing around with strcpy and strcat without much success:
  char quotestr[] = "\"";
  char hellostr[] = "hello";
  char instr[] = "%s\n, hellostr";
  char deststr[40];
  memset(deststr, 0, sizeof(deststr));
  strcat(deststr, quotestr);
  strcat(deststr, instr);
  strcat(deststr, quotestr);
  Serial.printf("quotestr = %s\n", quotestr);
  Serial.printf("instr = %s\n", instr);
  Serial.printf("deststr = %s\n", deststr);
  Serial.printf(deststr);

But the output is wrong because the '\n' gets interpreted as a CRLF pair even though it is in a string with double-quotes.
quotestr = "
instr = %s
, hellostr
deststr = "%s
, hellostr"
"
, hellostr"

It seems like there ought to be a way to do this easily, but I can't figure it out.  Any help would be appreciated.
TIA,
Frank

The \n gets interpreted as a newline, just as it is normal for Linux based OS. I would say it is doing exactly what you told it to do. Where are you looking at this? Why is this a problem? And have you thought about using sprintf() to build the string into a char array, which you can then print on both Serial interfaces?

if you don't want a new line, then remove the \n from the string

Using \\n instead of \n should do the trick.

you can write a simple T output using the base class Print. The standard Arduino Print class doesn't have printf but from your code it looks like the Teense core has printf in Print.
class TeePrint: public Print {

  Print &out1;
  Print &out2;

public:

  TeePrint(Print &_out1, Print &_out2) : out1(_out1), out2(_out2) {}

  virtual size_t write(uint8_t b) {
    out1.write(b);
    out2.write(b);
    return 1;
  }

};

TeePrint log(Serial, Serial1);

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

  log.printf("abcd %d %s", 1234, "xyz");
}

void loop() {

}

Thanks - your TeePrint class is very elegant.  One minor nit - it refused to compile for T3.2 because 'log' was declared in math.h.  When I changed from 'log' to 'myTee', everything worked fine

The simplest method is a variadic macro:
#define PRINTF(...) do { Serial.printf(__VA_ARGS__); Serial1.printf(__VA_ARGS__); } while(0)

Then you can just use PRINTF("foo: %d", bar); and it will expand it out to the two printfs for you.

This will fail on if (bar) PRINTF("foo: %d", bar);. That's why people use the do {...} while (0) idiom.

@EdgarBonet I did consider adding the {} but didn't bother. I should have. I have now. The do and while aren't needed.

The do and while (0) are needed for if (bar) PRINTF(...); else ... to work as expected.

@EdgarBonet No, you only need the {} for that.

That's incorrect. Try it!

Wouldn't that render the output string twice? Might make a huge difference if the user wants to print complicated stuff especially if floats are involved.

@EdgarBonet I do, regularly. I have never used, nor even seen, the do while construct.

@luni64 yes it would, but on a teensy it won't be noticeable as they are so much faster than an Arduino.

Without the do and while (0), if (bar) PRINTF(...); else ... gives error: ‘else’ without a previous ‘if’. Try it, seriously! The do {…} while (0) construct is the standard fix for this problem, and it is a very common idiom.

@EdgarBonet Ah, that'll be the fact that you added a ; after the macro when you used it. Don't do that?

If you remember to not add a trailing semicolon after the macro, then it works. But that is confusing, as the macro looks superficially like a function, yet it has to be used with a different syntax. Would you refrain to add a semicolon after getc() because it may be implemented as a macro?

@EdgarBonet The fact it's all in capitals is a dead giveaway that it's a macro. That's the convention. Sure, if you want to add a do while around it then do (while). It's not in my coding style, so I don't. I write my macro names in all caps so I remember they're macros, and don't need a ; after them. Everyone's coding style is unique.

“Everyone's coding style is unique” is not an excuse for being confusing. You fell in your own trap, as you accidentally added a semicolon in the first two versions of this answer. Imagine how easily someone else using a macro defined by you may fall in this trap.

@EdgarBonet If it'll shut you up I'll add it. I still don't use it personally though.


text:
Serial hangs on Arduino-Uno
I'm having issues with Arduino and RPI3 serial communication, it'll become unresponsive after a little time. Tried increasing BAUD rate and same issue, also happens on Windows as well so RPI is not at fault, and even after increasing the delay the hang still happens.
RPI3 python code
import serial
import time

if __name__ == '__main__':
  ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1, writeTimeout=0)
  ser.flush()
  last = "on\n"

  while True:
    last = "on\n" if last == "off\n" else "off\n"
    ser.write(last.encode())
    print(last)
    time.sleep(0.5)

Arduino code
#define BAUD_RATE 115200
const int LED_PIN = 8;
String command;

void setup() {
  Serial.begin(BAUD_RATE);
  pinMode(LED_PIN, OUTPUT);
  delay(100);
}

void loop() {
  Serial.println("I was written in RPI");

  if (Serial.available()) {
    command = Serial.readStringUntil('\n');

    if (command.equals("on")) {
      digitalWrite(LED_PIN, HIGH);
    } else if (command.equals("off")) {
      digitalWrite(LED_PIN, LOW);
    }
  }

  delay(50);
}

after less than a minute I'll get this exception from python
BlockingIOError: [Errno 11] Resource temporarily unavailable
The Arduino TX and RX led's stay on when it becomes unresponsive rather than flashing like it normally does.

also happens on Windows as well so RPI is not at fault ... maybe, but it does not exclude python problems

what error do you get on the RPi if you run LED blink sketch on the arduino?

Just the resource temporarily unavailable, the Arduino TX and RX led's stay on when it becomes unresponsive rather than flashing like it normally does.

the if (!Serial) { } block belongs in setup()

remove the if (Serial.availableForWrite()) { } block  .... whittle the code to minimum

Adjusted the code to be minimal.

does it still hang up?

Yes, still hangs

Does it help if you remove the Serial.println() from the Arduino code?

Can you try to find out which resource is unavailable?

You are flooding the RPi/PC with "I was written in RPI" and don't read it. Does it work if you read ser regularly?

Does dmesg -w tell you anything at the moment it locks up?

Seems to work fine if all I do is read OR write on the Arduino even without reading from the serial in python.

@thebusybee you were correct, seems to be working with ser.readline() in the python code. Free points if you want to write the comment as an answer will accept.

Also, worth noting I had to increase the delay on the Arduino to be more than sleep in python. For me delay(50) and sleep(0.01) works fine, maybe has something to do with python being slow?

You are flooding the RPi/PC with "I was written in RPI" and don't read it. It will work if you read ser regularly.
On the delays: A message over a serial line has a transmission time, in your case 20 characters at 115200 baud from Arduino to RPi/PC. With the common 8n1 protocol, characters are sent at 11520 per second. With 20 characters this will take nearly 0.002 seconds, or 2 ms. The receiver needs a smaller delay than the sender to avoid overflows.
If the Arduino were using the USB directly (AFAIK it does not, between its USB interface and the actual AVR is a "real" serial line), the baudrate does not matter. A virtual serial line over USB is always really fast, independent of the announced baudrate. I once used 921600 baud with success. ;-) The baudrate is only used if a real serial line is involved.


text:
Continuous servo motor won't stop rotating
I want to use Bluetooth to control my continuous servo motor to rotate 360° once, and I used MIT app inventor for the UI to control it.
My continuous servo motor won't stop rotating even though I tried myservo.write(90).
I was wondering if anything is wrong with my hardware, or whether the problem is in my code as I am a beginner at coding and I put different functions together that I found on the internet (I was trying to make the MIT to send letters to the Arduino code where the letter would activate a command to the servo).
Here's my code:
#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library
Servo myservo; // servo name

int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup() {
  myservo.attach(9); // attach servo signal wire to pin 9
  // Setup usb serial connection to computer
  Serial.begin(9600);
  myservo.write(90);  // set servo to mid-point

  // Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop() {
  // Read from bluetooth and write to usb serial
  if (bluetooth.available() > 0 ) { // receive number from bluetooth
    int servopos = bluetooth.read(); // save the received number to servopos
    Serial.println(servopos); // serial print servopos current number received from bluetooth

    char c = Serial.read();
    if (c == 'a') {
      myservo.write(180);
      delay(1000);
      myservo.write(90);
    }
    else if (c == 'b') {
      myservo.write(90);
    }
  }
}

Would be really great if you could help

I'm not familiar with the Servo class, but what is its default state?  What happens if none of your code in loop() is there?  Does the servo still rotate?  Is there a command that you need to send to tell the servo not to rotate?  If there is then should you be sending this command when the bluetooth is not available, or when c is not a or b?  (Hope that makes sense)

do a sweep through all values ... hopefully the servo will stop for some

A "continuous servo" is one in which it stops rotating when the angle is set to 90 degrees, rotates forward when the angle is more than 90 degrees and rotates in reverse when the angle is less than 90 degrees.  The further from the angle of 90 degrees, the faster the continuous servo will rotate.
You can not control the angle of a continuous servo.  There is no feed back to know when it has rotated, say, 360 degrees.
You can only guess at the timing and send a command like "go to angle 100" to start rotating a continuous servo slowly forward then send a command like "go to to angle 90" to stop it after your "guessed at" time of how log it took to travel, say, a quarter the way around has elapsed.
Here is a similar Stack Exchange question where continuous servos are discussed as well.

Doesn't the angle in the Servo library goes from 0 to 180, so that the stopping value for a continuous rotation servo would be 90, just like the OP did? The main problem seems to be that the Servo doesn't stop, even at the start of the program.

The angle sent to a normal servo controls the position.  But the angle set to a CONTINUOUS servo speed and direction.  For example, you would use a normal servo to control the steering of a sumo bot.  And you would use CONTINUOUS servos to propel a sumo bot.

That wasn't my point. The OP wrote that the servo doesn't stop rotating, but with using Servo.write(90) it should, since that is normally the value for a speed of zero for cont. rotation servos. In your answer it sounds as if doing Servo.write(0) will stop the servo.

Ohh, I see what you are saying @chrisl.  From what I remember, writing a 0 stopped my continuous servos.  Maybe I'm not remembering correctly.  If writing 90 stops a continuous servo, then writing, say 45 would make them go backwards and writing, say 135 would make them go forwards.  Let me know if that is correct and I'll change my answer.  Thanks!

Ah!  Found another Stack Exchange question which agrees w/what you said.  I'll change my answer and refer to the other answer as well.