texts: ESP32 OTA: Update.begin() leads to infinite reboots

texts:
I'm studiyng the OTA firmware update for ESP32 here.
For my application I cannot use a webserver to upload the firmware, but I'm going to setup an external server to provide an FTP or other download methods.
So I'm trying to understand how the Update library works. I added to my application just two lines of code:
    #include <Update.h>

    void setup()
    {
      Serial.begin(115200);
      Serial.println(Update.begin());
      ...
    }

but when I run this code on my ESP32 board I get an infinite cycles of reboots:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:621 (xQueueTakeMutexRecursive)- assert failed!
abort() was called at PC 0x40089d67 on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x40088c68:0x3ffe39d0 0x40088ee5:0x3ffe39f0 0x40089d67:0x3ffe3a10 0x4011e97d:0x3ffe3a30 0x400848bc:0x3ffe3a50 0x4008436f:0x3ffe3a70 0x4011e4fd:0x3ffe3a90 0x40113432:0x3ffe3ab0 0x401134a6:0x3ffe3ad0 0x400d777c:0x3ffe3af0 0x400d3632:0x3ffe3b20 0x400d250e:0x3ffe3b40 0x400d4c82:0x3ffe3b90 0x400f5847:0x3ffe3bb0 0x40082989:0x3ffe3bd0 0x40082bb8:0x3ffe3c20 0x40079247:0x3ffe3c40 0x400792ad:0x3ffe3c70 0x400792b8:0x3ffe3ca0 0x40079465:0x3ffe3cc0 0x400806da:0x3ffe3df0 0x40007c31:0x3ffe3eb0 0x4000073d:0x3ffe3f20

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

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c:621 (xQueueTakeMutexRecursive)- assert failed!
abort() was called at PC 0x40089d67 on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x40088c68:0x3ffe39d0 0x40088ee5:0x3ffe39f0 0x40089d67:0x3ffe3a10 0x4011e97d:0x3ffe3a30 0x400848bc:0x3ffe3a50 0x4008436f:0x3ffe3a70 0x4011e4fd:0x3ffe3a90 0x40113432:0x3ffe3ab0 0x401134a6:0x3ffe3ad0 0x400d777c:0x3ffe3af0 0x400d3632:0x3ffe3b20 0x400d250e:0x3ffe3b40 0x400d4c82:0x3ffe3b90 0x400f5847:0x3ffe3bb0 0x40082989:0x3ffe3bd0 0x40082bb8:0x3ffe3c20 0x40079247:0x3ffe3c40 0x400792ad:0x3ffe3c70 0x400792b8:0x3ffe3ca0 0x40079465:0x3ffe3cc0 0x400806da:0x3ffe3df0 0x40007c31:0x3ffe3eb0 0x4000073d:0x3ffe3f20

Rebooting...

Looking at the code of the begin() function it should return an error message if something goes wrong.
Is there anything I've missed before use this function?


texts: What is a cheap way to measure co2 or o2 level in air?

texts: I am making an air purifier which also increases o2 level as a school project but facing some difficulties. I plan to run the purifier whenever the co2 level is higher than usual or o2 level is lesser than usual but the sensor available in the market are quite expensive. So is there any cheaper alternative or any other method to detect a change in concentration?


texts:
I'm using ESP32 to read an analog value of a liPo battery (3.7v-4.2v).

Since ESP32 DAC's is 3.3v I'm using a voltage divider ( 2x10K resistors ), to split bat's voltage into ESP's GPIO36. So far nothing new or not well documented on the web.

Using the voltage divider, splits the 4.0v into 1.97v (measured using a volt-meter). Battery's negative pole is connected to ESP's Gnd to get a common ground. GPIO36 is connected to the 1.97v line ( and this value is tested using a volt-meter also on ESP's pin to make sure ).

I was expecting to get a digital value of 1.97 (2444 )

BUT NO!,

when using analogRead(36) I'm getting a digital value of 2180 which correlates to 2180/4095*3.3 = 1.75v.

1) I tried to make a 100 samples over time - to make sure it is not a power up issue. No change.

2) I tried to read its value during loop() and not setup(). No change.

Is DAC's resolution is that poor ( roughly 12% off ), or am I doing something wrong ?


texts: 4 channel relay module reversed? Or is it my code?

texts:
So I am designing a simple project where my Arduino reads analog values from a potentiometer, or rotation sensor, as it is called on EBay, and uses that value to determine how many relays to close. I am connecting 4 digital pins to the relay module, and powering it with a constant digital signal from pin 2.

Here is my code:

//set up the pins for activating each relay on the module
#define in1 13
#define in2 11
#define in3 10
#define in4 9
#define power 2      //set up the power pin for the module

void setup(){
 Serial.begin(9600);
 pinMode(in1, OUTPUT);
 pinMode(in2, OUTPUT);
 pinMode(in3, OUTPUT);
 pinMode(in4, OUTPUT);
 pinMode(power, OUTPUT);
 digitalWrite(power, HIGH);        //for power to the relay module
}

void loop(){
 float rotationValue = analogRead(A0);          //read raw value from potentiometer
 float percentValue = rotationValue / 10.23;       //convert the value to 0%-100%
 Serial.println(percentValue);                  //print it out on screen
 if(percentValue >= 0.00 && percentValue <= 1.00){         //all relays off
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
 }
 else if(percentValue > 1.00 && percentValue <= 25.00){        //relay #1 on
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
 }
 else if(percentValue > 25.00 && percentValue <= 50.00){           //relay #1, #2 on
  digitalWrite(in1, HIGH);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
 }
 else if(percentValue > 50.00 && percentValue <= 75.00){     //relay #1, #2, #3 on
  digitalWrite(in1, HIGH);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
 }
 else if(percentValue > 75.00){             //all relays on
  digitalWrite(in1, HIGH);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, HIGH);
 }
}

Ok, here's the problematic part. After I upload the program onto the board, when I set the potentiometer to the 0 position, all relays are on. And when I twist it to the 100 position, which is maximum, all relays are off. Although it is usable, what's weird is that when I start from 100 and twist it back toward 0, the relays will activate, but in the opposite order. So relay #4 will activate, then #3, then #2, and then #1, and all four are on when I reach 0. Is it something wrong with my code? I've checked and rechecked, and even checked with a different project where I connect the pins to LED's. And they work normally. But when I connect up the relay module, it's reversed. Any ideas?

Here is the relay module: http://www.miniinthebox.com/4-channel-relay-module-with-optocoupler-5v_p903429.html?currency=USD&litb_from=paid_adwords_shopping&gclid=Cj0KEQiAts-kBRCbgrXc1rnXw7MBEiQAnFqTdph_qI5n7rrpW7gZaxafVVkeWitQlN8FUSUJzdsV2JwaAlBA8P8HAQ

And here is the potentiometer: http://www.ebay.com/itm/Potentiometer-Sensor-module-Rotation-Angle-Sensor-Arduino-competible-/251656942542

I mean, right now I'm even thinking that the relay module may be labeled incorrectly, that the numbers are printed the wrong way. But it could be my fault, most likely.

Thanks for any help.


texts: Will the noise from a voltage regulator interfere with IR LEDs and receivers on an Atmega328? (Arduino Uno sketch)

texts:
I have a project which uses an IR LED and receiver to communicate with other Arduinos. I am using the Atmega328 out of the Uno, rather than the whole Arduino board and I need it to be battery-powered, so I need to use a voltage regulator to maintain 5V to the chip.
I want to avoid a linear regulator if I can, as they are inefficient, but I'm worried that the other types will cause too much noise on the output and it will interfere with the IR communication.
Should I be concerned about this or am I making a fuss about nothing, I can always use a linear one if I need to.
Thanks in advance.


texts: Beginner here, trying to start learning arduino, which starter kit should I buy?

texts:
I'm really interested in arduino but I don't know much about it. I want to buy a starter kit to play with, but when I searched it on amazon, there are couple unofficial starter kit and a more expensive official one. So, can some one tell me the major difference between the unofficial starter kit and official starter kit? And which one would you recommend me to buy? Thank you!

Sorry, bonus question: why is the start kit($89) in arduino website is much cheaper than the official starter kit in amazon($120)?


texts: Does delay() pause the counting of millis()?

texts:
If I add a delay for a few seconds, and then will the value given by millis () be equal just before and after delay?

Or to put it in other words, does the internal clock of Arduino stop during delay?


texts: Cannot connect with online arduino editor but I can with Arduino IDE to an Arduino Nano

texts:
As the title says I have a Nano with CH340G and 168 that connects properly to Arduino IDE but not to Arduino online editor, it does not detect the board "Error uploading, check if the board is available"

What can I do?

EDIT: The IDE online I am using is https://create.arduino.cc/ I am using the same computer and exactly the same board model in both IDEs (both of them have the same options available so both of them should be in the same version)

EDIT 2: I can connect correctly from the online IDE to an Arduino UNO. The problem is just with the Nano.


texts: TWI Wire.setClock() on non arduino AVR MCU issue

texts:
Using an Atmega168P - programmed by means of avrdude with the .hex file generated by Arduino IDE.

The following code sets the 8 MHz Atmega's TWI interface to just 15.625 kHz:

  Wire.begin(); // Initiate the Wire library
  Wire.setClock(100* 1000);
  delay(10);

While this one doubles it to 31.25 kHz:

  Wire.begin(); // Initiate the Wire library
  TWBR = (F_CPU/(100*1000) - 16)/2;
  TWSR &= 0b11111100;
  delay(10);

Looking to get 100 kHz clock. What am I missing ?


texts:
I am trying to write a sketch wherein the led brightness increases in increments of 15 until it reaches 255. At that point I want to make decrements of 15 until it reaches 0. The increment part of the program works well but the decrement part goes haywire. It gets stuck between 255 & 240. I am not sure how can I fix it. Could you please tell how can I make it work?

Here is my sketch:

int led = 9; //led pin
int fade = 0; // pwm value

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

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

   analogWrite(led,fade);
   fade += 15;
   Serial.println(fade);
   delay(250);

  if (fade >= 240){
    fade = fade - 15;
    analogWrite(led, fade);
    Serial.println(fade);
    delay(250);
  }

}


texts:
Asking here cause I ran out of options in searching. My Arduino Nano clone isn't recognized by my computer anymore. It was, until I plugged into a Windows machine, that did not recognize it... and now even my Linux Mint distro doesn't detect the Nano at all. Here's the thing, though: the green power LED still lights up and, if I connect my DC motor to it like I used to before, the LED turns off and the motor is powered only a little bit, with less speed than if it were powered by a 1.5V battery.

My voltimeter reads a 2.18V out of the 5V pin.

Here's all I did: uploaded a sketch to power a 5v motor, it worked, unplugged the Arduino, took it home to my Windows machine on the casing I got it from my school, plugged it there, then it didn't detect anything. Go back to the lab today, plug it in, doesn't detect it there either.

From there, I've replaced USB cables, tried different USB ports, checked with lsusb and dmesg, tried finding it using the FTDI tool (the chip underneath is FTDI), then tried powering it from a phone charger, but the voltage readings at the 5v pin still are around 2.18V with that. Nothing seems to give this little thing an output greater than 2.18V.
The only thing I haven't tested is powering it through the VIN pin.

I came across other questions of similar problems but nothing that seems quite like mine... since they all either are able to detect the device but it is displayed as an unknown device or can't recognize the device at all but their power LED does not turn on.

Any ideas on what is going on?


texts: How can I share one power supply between an arduino and servos?

texts:
I'm trying to power an arduino and a few modules (RF receiver, two servos, and a laser diode) through one power supply.
I get jittery/unresponsive servos when hooked up in the following configuration:

power supply goes to usb breakout, joins with top + and - rails, powers everything (tried
all grounds go to top - rail
black/grey/white wires going off right side are power/ground for the servos
red, green, yellow wires going off left/top side are signals to the servos/laser
purple wire going off left/top is ground for the laser

If I remove the orange wire (usb breakout to + rail) and plug another power supply into the Arduino, the poor performance disappears and everything works nicely.
Since my power supply is 2.5A, I doubt that I don't have enough power for this setup. This leads me to believe that the Arduino/receiver side of the circuit is making the voltage unstable so the servos misbehave. Is there a way I can isolate these two parts of the circuit (diode, capacitor?) so that I can power the whole setup with one cable?
Components:

Arduino pro micro (5v)
RF Link Receiver (WRL-10532, 434 MHz)
Servo (ROB-09065, sub-micro)
Laser diode (5V, 20mA)
Micro USB breakout (1A)
USB Micro power supply (5.1V, 2.5A)


texts: Is it support to use Infrared radiation module in ESP12E?

texts:
I have a IR module -->image as shown

is it possible to use the IR module in esp8266?

how to do(sent and receive)?

what is the packet format of IR module?

please explain.

Thanks


texts:
I'm learning ardino programming.
I have make a multi tab program for printing machine.
But I have an error in the RPM counter:

RPM_COUNTER.h:11:33: error: invalid use of non-static member function attachInterrupt(0,count,RISING); exit status 1 invalid use of non-static member function

Code:

class RPM_COUNTER {

  private:

    volatile int counter = 0;

  public:

    void RPMSetup() {
      lcd.begin(16,2);
      attachInterrupt(0,count,RISING);
    }

    void RPMLoop() {
      delay(999); // Delay almost 1 second.
      lcd.setCursor(8, 1);
      lcd.print(counter*60); // Counter/2 * 60 seconds.
      lcd.println("rpm.");
      counter = 0;
    }

    void count()
    {
      counter++;
    }

};

RPM_COUNTER RPM;


texts:
My Arduino came with a 9V 1A power supply to use with it.  I decided to test it out with my multimeter.  I put the red lead in the connector and the black on the outside.  Sure enough I read 9V.  However when I tested the amps this did not work.  The meter read a low value and the power supply started making a ticking noise and a light started flashing on it.

I did have the multimeter on the correct settings.  Looking online I now realize that you cannot test the amps this way and as I was essentially testing a circuit with no load on it.

What I would like to know is what the power supply was doing when it was ticking and flashing.  It is alive and well so I suppose it was some sort of internal protection.


texts: Simple Script controlled by Raspberry not working

texts:
I can't figure out why the next script is not working. I have attached the Arduino to one USB port of the raspberry pi, in which I've installed pyserial. I just want to turn off/on a led depending of the number I write on the Raspi console (1-> on, 2-> off).

    int led=13;

void setup(){
  Serial.begin(115200);
  pinMode(led,OUTPUT);
}
void loop(){
  if(Serial.available()){
     mode(Serial.read() - '0');
  }
}
void  mode(int n){

    if (n== 1){
         digitalWrite(led,HIGH);
    }
    if (n== 2){
        digitalWrite(led,LOW);
    }
  }

PS: I double checked and the baudrate is configured also at 115200 at the raspi side.
In addition, if I place digitalWrite(led,HIGH) just before  the line  "mode(Serial.read() - '0');" the led turn on when I send some information from the raspi shell (so, works well).


texts: Make Sure \n is the last character in serial string

texts:
I have an Arduino that I've put between a computer and an RS485 device. The job of the Arduino now is just to transmit data but will eventually do data logging and have a small user interface as time goes by.

So far, this serial read code has worked for me to communicate to the Arduino from the computer:

 void serialEvent()
 {
  while(Serial.available())
  {
    // get new byte
    char inChar = (char)Serial.read();
    if (inChar == '\n')
    {
      stringComplete = true;
    }
    else
    {
      inputstring += inChar;
    }
  }
 }

The downside here is that I cannot send the '\n' char to my RS485 unit. Is there a way I can refine the code so I can send an arbitrary string of chars while still having a termination [thing] to turn on the stringComplete flag?

EDIT To clarify this the process by how my message string is being created:

Input: U16 Address, U16 Data, U8 Function Code
U16 Address -> U8 Address Split High, U8 Address Split Low
U16 Data -> U8 Data Split High, U8 Data Split Low

U8 Array of [U8 Address Split High, U8 Address Split Low, U8 Data Split High, U8 Data Split Low, U8 Function Code]

U8 Array -> Message String

Output: Write Message String


texts:
I want to have 6 audio jacks IN waiting for connection to start some WAV/OGG playback as soon as a headphone plugs in. In fact, I'd like to have simultaneous playback in 6 lines.

I've seen in the market some stuff that you can add buttons to different actions (play, pause, stop, etc). So far I believe this might be possible and affordable with Adafruit's Audio FX (which are stand-alone, Arduino-programmable WAV/OGG decoder circuits).

But,

  Is it possible to start audio playback when headphones gets plugged
  in? HOW?

Is that an event? like pressing a button?

Does it need some "hacking" between GND lines maybe?


texts:
In my project, i have some data to save permanently. After some research i got many examples and informations to do that with eeprom. I used it effectively.
After all i decide to deep dive to esp8266 and i got some information about spiffs.
Now i know what spiffs is and what its purpose. But i am wondering what is difference between eeprom vs spiffs?
I know both of them using flash memory as same and we can write and store data with them but why spiffs? Why eeprom ? What are their pros and cons or etc.?


texts: While using Arduino Ethernet shield, do we need to explicitly select/Deselect SD and W5100 in our code?

texts: It has been mentioned here http://arduino.cc/en/Main/ArduinoEthernetShield that corresponding libraries take care of chip select between SD and W5100 in Arduino Ethernet shield. Does it take care properly all the time? What happens if the Chipselect is not properly managed by libraries? Does that cause blocking of code?


texts: Posting Arduino data via ethernet to PHP server problems

texts:
I am currently having difficulties sending data from an Arduino using an ethernet shield to a PHP database in MySQL. My problem is that it appears that the server is receiving the data as there is a time stamp when I send it from the Arduino however, the other values it is receiving are incorrect (see images below). The server says the values of "data", and "serial_number" are 0 but they are supposed to be 10 and 24. Along with that the Arduino is saying that the data has been sent successfully. My code for both the server and the Arduino is listed below. Any ideas on how to fix this or what is going on are much appreciated.

Arduino Code:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x00, 0xAB, 0xBA, 0xBC, 0xDD, 0x02 };
EthernetClient client;
String data;
int t;
int h;

void setup() {
  Serial.begin(9600);
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
  }

  Serial.println("still working here");

}

void loop() {
t = 10;
h = 24;

data = "temp1=";

data.concat(t);

data.concat("&hum1=");

data.concat(h);

  if (client.connect("www.smartwater.x10host.com",80)) {
    Serial.println(data);
    client.print("POST /add.php HTTP/1.1\n");
    client.print("Host: www.smartwater.x10host.com\n");
    client.print("Connection: close\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(data.length());
    client.print("\n\n");
    client.print(data);
    Serial.println("Successfull");

  }

  if (client.connected()) {
    client.stop();
  }

  delay(20000);
}

add.php (Server Code)

<?php
    include("connect.php");

    $link=Connection();

    $temp1=$_POST["data"];
    $hum1=$_POST["serial_number"];

    $query = "INSERT INTO `Main` (`data`, `serial_number`)
        VALUES ('".$temp1."','".$hum1."')";

    mysql_query($query,$link);
    mysql_close($link);

    header("Location: index.php");
?>

connect.php (Server Code)

<?php

    function Connection(){
        $server="localhost";
        $user="smartwat_arduino";
        $pass="*****";
        $db="smartwat_Main";

        $connection = mysql_connect($server, $user, $pass);

        if (!$connection) {
            die('MySQL ERROR: ' . mysql_error());
        }

        mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );

        return $connection;
    }
?>

index.php (Server Code)

<?php

    include("connect.php");

    $link=Connection();

    $result=mysql_query("SELECT * FROM `Main` ORDER BY `timeStamp` DESC",$link);
?>

      <title>Data</title>

Stuff

            &nbsp;Timestamp&nbsp;
            &nbsp;Data&nbsp;
            &nbsp;Serial Number&nbsp;

      <?php
          if($result!==FALSE){
             while($row = mysql_fetch_array($result)) {
                printf("
 &nbsp;%s 	 &nbsp;%s&nbsp; 	 &nbsp;%s&nbsp;
",
                   $row["timeStamp"], $row["data"], $row["serial_number"]);
             }
             mysql_free_result($result);
             mysql_close();
          }
      ?>


texts: My Arduino keeps telling me the button is being pushed

texts:
My code is simple simple for the button.

There is no reason why this shouldn't work... I think. I honestly have no clue what's wrong.

Output:

Code:

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <Bounce2.h>

#define SS_PIN 53
#define RST_PIN 5
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

int led = 13;
int led2 = 12;

Bounce debouncer1 = Bounce();

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

int buzzer = 10;

Servo LockServo;

int ServoPos = 0;

void setup()
{
  debouncer1.attach(buttonPin);
  debouncer1.interval(5); // interval in ms

  pinMode(buzzer, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP); // Push Button as INPUT wiith pullup
  buttonState = digitalRead(buttonPin);
  LockServo.attach(9);  // attaches the servo on pin 9 to the servo object
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  Serial.println();
  pinMode(led, OUTPUT);
}

void loop()
{
  debouncer1.update();
  buttonState = debouncer1.read();
  if (buttonState == HIGH) {
    Serial.println("Button Pushed");
    // turn LED on:
    digitalWrite(led, HIGH);
    ServoPos = 0;
    LockServo.write(ServoPos);
  }
  else {
    digitalWrite(led, LOW);
    ServoPos = 180;
    LockServo.write(ServoPos);
  }

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "20 96 2E A5") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    ServoPos = 0;
    LockServo.write(ServoPos);
    tone(buzzer, 20000);
    delay(500);
    noTone(buzzer);

    tone(buzzer, 15000);
    delay(500);
    noTone(buzzer);
    delay(15);
    delay(3000);
    digitalWrite(led, LOW);
    delay(3000);
    ServoPos = 180;
    LockServo.write(ServoPos);
  }
  else {
    Serial.println(" Access denied");
    tone(buzzer, 10000);
    delay(500);
    noTone(buzzer);

    tone(buzzer, 30000);
    delay(500);
    noTone(buzzer);
    digitalWrite(led2, HIGH);
    delay(3000);
    noTone(buzzer);
    digitalWrite(led2, LOW);
  }
}


texts: Issues with Stacking Ethernet shield and USB Host shield

texts:
I want to stack Ethernet shield and USB host together with my Arduino MEGA 2560.
Each of these shields works fine separately.
Is it necessary to contact bootloader pins with each shield and arduino board?
I have connected and tried, but the problem exists.
only one shield works fine at once.(always the sheild that directly connect to the Arduino board).
How do I resolve this problem ? I want to work all 2 shields at once.
these are the sheilds I have used.

Circuits At Home USB Host Shield v2.0
Ethernet Shield v5.0

Thank you


texts: generate and using a precompiled library ESP32

texts:
I would like to ask you how I can generate a dot_a file for a given library for ESP32? I want to replace my .cpp file with a precompiled .a in the Arduino IDE.
Is that possible? Can you please guide me?


texts: How I can divide information stream from bluetooth hc-06?

texts:
All good afternoon or evening. I am having a problem writing a sketch for Arduino using Arduino UNO and Bluetooth HC - 06.

My program does not divide the input stream of information into several variables. No matter how many variables I specify, they are considered as one.

Maybe I do not know all subtleties of the use of Serial.read(). Apparently from a sketch given below I get through Bluetooth two variables of color and var. A microcontroller perceives these two variables as one and as a result does not execute before him task. As a result we will be able to choose the color and change delay of blinking by this color.

If anybody knows how to correct this problem or can point me to a similar project I will be very thankful for any rendered help

const int rPin = 3;
const int gPin = 5;
const int bPin = 6;
int chosed_color;
int val;
int color;

void setup()
{
  Serial.begin(9600);
  pinMode( rPin, OUTPUT );
  pinMode( gPin, OUTPUT );
  pinMode( bPin, OUTPUT );

}

void loop()
{
while(Serial.available()>0)
  {
     color = Serial.read();
   if(color==1)
      {
       chosed_color = rPin;
      digitalWrite( rPin, HIGH );
      digitalWrite(rPin, LOW);
       return chosed_color;
      }
        else if(color==2)
      {
       chosed_color = bPin;
       digitalWrite( bPin, HIGH );
      digitalWrite(bPin, LOW);
       return chosed_color;
      }
         else if(color==3)
      {
        chosed_color = gPin;
       digitalWrite( gPin, HIGH );
       digitalWrite(gPin, LOW);
       return chosed_color;
      }
  }
if(Serial.available()>0)
{
  val = Serial.read();
}

      digitalWrite( rPin, HIGH );
      delay(val);
      digitalWrite(rPin, LOW);
      delay(val);
}


texts: Using SPI and 2 shift registers WITHOUT libraries

texts:
Arduino Mega 2560 board and SN74HC595 shift register(s). I'm working on a school assignment and having issues getting the shift register(s) working without using Arduino libraries.

I know with the libraries you can use functions such as digitalWrite(....); and shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);.

For my project, I've set up my individual pins as inputs and outputs, but I am having trouble converting the library code into basic code.

IE:

digitalWrite(latchPin, LOW);

can be rewritten as

DDRB &= ~(1 << DDB1);

where latchPin is the SCK pin.

At this stage in the project, we're just trying to get 8 LEDs lit up using 1 shift register, then 16 using 2 shift registers. Any help in understanding what I need to do or direction in which to look would be appreciated.

Thank you,

Nic

Edit:

This is what I have converted from the void setup from https://www.arduino.cc/en/Tutorial/ShftOut12 :

void setup() {
  //Clear the shift registers prev data, Need a low input to reset registers
  //PORTL0 to first SReg SRCLR, PORTL2 to second SReg SRCLR
  //* See data sheet for sn74hc595 shift registers
  DDRL &= ~((1 << PORTL0) | (1 << PORTL2)); //Pg 100 - 21.2.3
  //Use port L0/L2 for SRCLR pin on SReg
  PORTL |= (1 << PORTL0) | (1 << PORTL2); //Pg 100 - 21.2.3

  //Set OE (Enable) to 0 until after last bit is sent
  DDRL &= ~(1 << PORTL4); //Pg 100 - 21.2.3
  //TODO SPI DELAY HERE USING SPDR pg 199

  //Enable SCK as output to drive RCLK and SRCLK on SR
  DDRB &= ~(1 << DDB1); //Pg 96 - 13.4.6
  PORTB |= (1 << PORTB1); //Pg 96 - 13.4.5

  //Enable MOSI as output to drive SER Input on SR
  DDRB &= ~(1 << DDB0); //Pg 96 - 13.4.6
  PORTB |= (1 << PORTB0); //Pg 96 - 13.4.5

  Serial.begin(9600);
  Serial.println("reset");
}


texts: Is there a way to detect if Arduino, Stino or another IDE/toolchain is in use?

texts:
I've noticed some irritating differences between the Arduino IDE and Stino (mainly around including certain header files). These are likely bugs that need following up with one or both of the parties, but in the meantime, I would like my code to compile with both of them without editing. This is because I do not want to lock any users out of using my code.

Are there any macros or similar that are readily available (as in, require no modification of the toolchain or IDE) that would allow me to detect which is in use?

For example, in many libraries, there is this snippet:

#if ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif

However both Stino and Arduino define this.


texts: Can i send sensor data from arduino to cloud without sending it via PC

texts:
I am trying to build a GPS tracker. I need to send the data from GPS sensor on the arduino uno board to cloud directly i.e. without sending it via PC or mobile.
Is it possible and if yes, HOW?


texts:
I'm just getting into electronics in general and I'm confused a bit as to why I'd want/need to use a motor driver board instead of just setting up my own transistor/diode/etc when attempting to power and control a DC motor.

Any chance someone could clarify the point to using a motor driver board instead (assuming there is another option as I think there to be)?


texts: How to change the resolution of DS18B20?

texts:
I'm using DS18B20 sensor with this library, the 750ms delay is causing problem in timer part of my code. the code below is from DallasTemperature.cpp:

// returns number of milliseconds to wait till conversion is complete (based on IC datasheet)
int16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution) {

    switch (bitResolution) {
    case 9:
        return 94;
    case 10:
        return 188;
    case 11:
        return 375;
    default:
        return 750;
    }

I'm reading the temperature like this:

#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS A0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {}

void loop () {
    float currentTemp = sensors.getTempCByIndex(0);
    sensors.requestTemperatures();
}

sensor is not connected in parasite mode, and there is only one sensor.

How can i change the resolution from 12 to 9 bit?


texts: Ethernet shield connected to local network, not to internet

texts:
Using the WebServer example file I have been able to confirm that my arduino is connected to my local network and I can open the page in my browser. However any attempt at contacting addresses outside my own network fails. For example this simple script:

    #include <SPI.h>
    #include <Ethernet.h>

    EthernetClient client;

    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    IPAddress ip(192, 168, 1, 25);
    IPAddress gateway(192, 168, 1, 1);
    IPAddress dns(8, 8, 8, 8);
    byte server[] = { 64, 233, 187, 99 }; // Google

    void setup() {
      Ethernet.begin(mac, ip, dns, gateway);
      Serial.begin(9600);
      delay(1000);
      Serial.println(Ethernet.localIP());
    }

    void loop() {
      if (client.connect(server, 80)) {
        Serial.println("connected");
        client.println("GET /search?q=arduino HTTP/1.0");
        client.println();
      } else {
        Serial.println("connection failed");
      }
    }

This consistently returns connection failed. The ethernet cable in the arduino has an active internet connection, albeit via a switch. My board is an arduino uno.


texts:
I have an interesting problem. I want to control ESC and servo with Arduino. I'm using HC-12 to communicate with 2 Arduino and I'm using SoftwareSerial on the nano.

#include <SoftwareSerial.h>
#include <Servo.h>

SoftwareSerial mySerial(2, 3); // RX, TX
Servo esc,servo1;

String okunan;
int escval;

void setup() {
  okunan="";
  esc.attach(9);
  servo1.attach(10);
  mySerial.begin(2400);
  Serial.begin(9600);
}

void loop() {
   while (mySerial.available()) {
    delay(3);  //delay to allow buffer to fill
      char c = mySerial.read();  //gets one byte from serial buffer
      okunan += c; //makes the string readString
   }

  if(okunan.length()>0)
  {
    Serial.println(okunan);
    //escval= map(okunan.substring(0,okunan.indexOf(',')).toInt(),0,1023,,2000);

    servo1.writeMicroseconds(map(okunan.toInt(),0,179,1000,2000));

    okunan="";

mySerial.flush();
  }
  delay(20);
  }

When I use a potentiometer, It works successfully. But When I use with serial and if three digit value(between 0-179, for example, 120) comes from serial(HC-12), motor works and stops continuous and irregular. If the value is under three digit there is no problem.

Also, if I delete the ESC variable(servo) or add a new servo to code, it always starts and stops interestingly(Using or not it doesn't matter. If I add Servo servo2 etc., it is going crazy.

I've tried on Uno. That is the same.

Thanks in advance...


texts: How to get the esp32s2 recognized as USB device?

texts:
I have an esp32-S2 saola and I am trying to use it as a MIDI usb device. I am trying to use this github repository: https://github.com/chegewara/EspTinyUSB. I am able to run the code on the esp32s2 saola and I am connecting to a mac with a USB cable to pins 19 and 20 but don't get any MIDI input in my computer (mac), in fact my computer is not recognizing the device.
So I guess my actual question is about how to get the esp32s2 recognized as a USB device by the mac. Any clues of what might be happening? Or should connecting  to pins 19 and 20 be enough and I am dealing with a hardware bug?
For the usb cable I took a usb only-power cable apart and then rewired it so it was only data (two middle cables connected to pins 19 and 20). As it was not working I then connected also the usb's power and ground cables with no luck:

EDIT: This the documentation for the USB driver on the esp32-S2 and why I think the power cables might not be needed at all (which I tried but didn't work): https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/usb.html


texts: Measuring the speed of an object moving fast through air

texts:
I am new to arduino and am confused about how I would go about doing this: I want to attach a device to a small ball, that will move through the air at speed. The purpose of this device would be to determine the speed of this object as it moves through the air. My ball will always move in the same path because it will be shot out of a tennis ball shooter. My initial intuition would be to use an accelerometer to determine the acceleration at quarter second intervals and then multiply those values by a quarter of a second to obtain the change in speed and then add it to the sum of all the previous change in speed values (starting at 0).

Would this work? Is my reasoning correct? Are there any better solutions?

Thank You!


texts: Compare the new sample in a high sampling rate datalogger

texts:
I am using sdFat library the analog bin logger example,

Github: SdFat/SdFat/examples/AnalogBinLogger/

The program is working fine and every thing but the thing is, this high speed datalogger uses interrupts and timers to make the ADC work at a pre-determined sampling frequency and it DOES NOT use the normal analogRead ()

What I want is, when the input of some analog pin is bellow a pre-determined value, I want to write HIGH or LOW to some digital pin,
my question is, how can I compare the new sample in the analog bin logger example as I simply want to compare the new sample as in:

if ( analogRead() < 256 ) {// do something}

knowing that there is no analogRead() in the program because it uses timers and interrupts.


texts: Does serial speed affect performance of other tasks?

texts:
I have explored Google and the Arduino site and this site and cannot find a mention of this, so my guess is that serial is handled by a separate component to the core processing and so different serial communication rates will not affect code performance.

Is this correct?

Where can I find information about how serial passing is handled? For instance, when I call Serial.prinlnt("test"), how does that get to the serial line?


texts: I want a couple of servos to listen for P.C. input (data from OSC protocol), can I bypass having to use an Arduino?

texts:
...and whack a stripped usb cable straight into a prototype board?

by bypass having to use an arduino I mean any kind of sheild? polulu would be perfect but im trying to avoid needing any of this.

My issue for finding tutorials and documentation on the subject is not quite knowing what keywords to search for, could someone point me in the right direction?


texts: can i configure 2 (XBee series 2) modules using one explorer

texts: Can I configure 2 XBEE modules one then another using 1 XBEE Explorer, or I MUST do this configuration operation for them at the same time and I need 2 Explorer modules?


texts: How do I connect multiple pinhole cameras and take photos and video at the press of a button?

texts:
I am trying to set up a 4 cameras which can take videos/photos at the press of a button.

Things which I will need:

4 micro cameras(the ones which are very small in size) with good
shutter speed and sensor. The cameras will often travel at 20 to
30mph. So I guess good shutter speed is needed.
2 Push buttons. One will start and stop taking pictures really fast, and the other will do the same for video
Battery which can last atleast taking 5 images/1 min of video recording.
4 Microsd cards and the connectors. Is there anyway I would be able to set up a common adapter to all these cards, so when connected to a computer it will show up as 4 different drives?

So I think I can make the set up using this: http://www.arducam.com/
But can it take images really fast. I couldn't see any information regarding this. It should be able to take like 4 images per second. Also it would be awesome if this set up can somehow support taking videos.

Now another thing I need is a push button which will start taking the photos and stop taking it.

This whole thing should operate from a battery.

Mostly I want to know is the list of products which will work or the specs to look for when choosing the products. Also I would like to know if this is the best way to go for  a project like this. This thing will be more like a toy, so I don't want to use really expensive parts for this. Also I don't want a gopro. I want to make this whole set up myself.

Let me know if you need to know more details about this.


texts:
I try to build an automatic roof with rain sensor input, when it's rain the roof then closed pulled by DC motor on the tracks and activate a buzzer. When it reach the end (limit switch pressed) then the motor stopped and buzzer off. And when the rain stopped, motor will turning again to open the roof until the second limit switch pressed to stop the DC motor.

I have try to make my own program but it have an error, when it's has no rain detected the motor spin to close the roof and stop when limit switch pressed (LOW logic), but when rain detected the buzzer turned on but the motor doesn't spin at all. Here is my code, I'm using L293D for motor driver and using its enable pin.

void setup() {
  digitalWrite(enable_motor, HIGH);
  digitalWrite(motor_open, LOW);
  digitalWrite(motor_close, LOW);
  digitalWrite(alarm, LOW);
}

void loop() {
  if (analogRead(rainSensor) < 650){
    digitalWrite(alarm, HIGH);
    digitalWrite(motor_close, HIGH);
    digitalWrite(motor_open, LOW);
  }
  else if (digitalRead(stop_close) == LOW){
    digitalWrite(alarm, LOW);
    digitalWrite(enable_motor, LOW);
  }
  else if (analogRead(rainSensor) > 850){
    digitalWrite(alarm, LOW);
    digitalWrite(motor_close, LOW);
    digitalWrite(motor_open, HIGH);
  }
  else if (digitalRead(stop_open) == LOW){
    digitalWrite(alarm, LOW);
    digitalWrite(enable_motor, LOW);
  }
  else {
    digitalWrite(enable_motor, HIGH);
    digitalWrite(alarm, LOW);
  }
}

Can I use If-Else logic? Or I make a mistake?


texts: Computer not detecting my Arduino MEGA 2560 R3

texts:
I've tried different USB cables, computers, ports and none of them can detect my possibly bricked Mega 2560 R3. Nothing shows up at all in the Device Manager, not even "Unknown Device".

When the board is plugged in via USB, the "L" LED is constantly lit as well as the "ON" LED next the reset button.

I came up on this article here and I gave it a try, which I believe is putting it in DFU mode. However I'm not having any luck with this. http://www.wayneandlayne.com/blog/2011/02/16/fixing-linux-firmware-issues-on-arduino-mega-2560/

Any one have any ideas on where to go from here? I'm very new with Arduino.


texts:
we are using 2 Arduino UNO as a master/slave for this i2c protocol. we used the first Arduino(slave) as a sensor that will input dummy data (in this case, temperature data). the Arduino(master) should be able to output what the slave has input, but every time we run it, the output is always 255 instead of the temperature data. We don't know what is wrong with the code, but we what to read the real data. Can anyone help us? Thank you.
Here was the code we use for the Master.
// Include Arduino Wire library for I2C
#include <Wire.h>

// Define Temp Slave I2C Address
#define TEMP_ADDRESS 9

void setup()
{
  Wire.begin(); // Initialize I2C communications as Master
  Serial.begin(9600); // Setup serial monitor
  Serial.println(">>>MASTER IS READY<<<");
  Serial.println('\n');
}

void loop()
{
//Temperature
  delay(50);
  Wire.requestFrom(TEMP_ADDRESS, 12);
  Serial.print("TEMP ADDRESS: ");
  Serial.println(TEMP_ADDRESS);
  Serial.println("Receive data from TEMP Slave");
  byte MasterReceivedTemp = Wire.read();
  Serial.print("Temperature = ");
  Serial.println(MasterReceivedTemp);
  Serial.println('\n');
}


texts: LSM9DS1 breakout - How to increase speed

texts:
With regards to the Adafruit LSM9DS1 breakout:
enter link description here

And using the Library:
enter link description here

I am trying to increase the sample rate, or speed of this chip.
I am using a Sparkfun Pro Micro 5V

With the adafruit library, you need to request accelerometer, gyro, magnetometer and temperature at once, and all I need is the accelerometer values. I am hoping by figuring out how to request only the accel values it will speed up the loop. But also, there must be another setting that could speed up the sample rate?

Any help would be appreciated!

my code currently:

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS1.h>
#include <Adafruit_Sensor.h>  // not used in this demo but required!
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1();
#define LSM9DS1_SCK A5
#define LSM9DS1_MISO 12
#define LSM9DS1_MOSI A4
#define LSM9DS1_XGCS 6
#define LSM9DS1_MCS 5

void setupSensor()
{
  // 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_2G);
  //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_4G);
  //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_8G);
  //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_16G);

  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS1_MAGGAIN_4GAUSS);
  //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_8GAUSS);
  //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_12GAUSS);
  //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_16GAUSS);

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_245DPS);
  //lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_500DPS);
  //lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_2000DPS);
}

double accelX = 0;
double accelY = 0;
double accelZ = 0;
double rms = 0;

void setup()
{
  Serial.begin(115200);
  // Try to initialize and warn if we couldn't detect the chip
  if (!lsm.begin())
  {
    Serial.println("Oops ... unable to initialize the LSM9DS1. Check your
wiring!");
    while (1);
  }
  Serial.println("Found LSM9DS1 9DOF");
  setupSensor();
  delay(5000);//program stabilization
}

void loop()
{
  lsm.read();
  sensors_event_t a, m, g, temp;
  lsm.getEvent(&a, &m, &g, &temp);
  accelX = a.acceleration.x;
  accelY = a.acceleration.y;
  accelZ = a.acceleration.z;
  rms = (accelX*accelX)+(accelY*accelY)+(accelZ*accelZ);
  Serial.println(rms);
}


texts:
Friends Here is what i want to ask.

I have a midi keyboard that is casio cps7. Its an old model so its not a USB midi keyboard.
I use it with a cheap midi to usb cable.
I just wanted to use my arduino to act like a midi to USB adapter. So, i can use my midi keyboard with that too.
I found some tutorials that uses this arduino like usb serial device. And there is also a code for it. The code itself has a command to play midi notes.
We receive serial signals from arduino and convert them into midi (by using another software that is serial midi converter, there is also virtual midi port for it which is midi-yoke). Thats how i used my arduino board once but the program code for it (what i installed) plays its own notes. I just want to send my midi out (from my keyboard casio cps7) to pc as serial via arduino. Thanks

I hope you guys now understand what i wanted to say :)


texts: I am making a rubber band gun but i cant seem to get the button to work with my code to turn the servo?

texts:
#include <Servo.h>
const int buttonPin = 3;
int buttonState = 0;

Servo myservo;
void setup() {
    myservo.attach(2);
    pinMode(buttonPin, INPUT);
}

void loop() {
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH){ myservo.write(90); }
    else { myservo.write(155); }
    delay(1000);
}


texts: digitalRead() function of Arduino doesn't read Input value sent by sensor after detecting the object

texts:
I'm trying to turn ON the LED(inbuilt/PIN13) when photoelectric proximity sensor(12v) senses any object. Sensor is connected on pin 2. Assigned pin 2 as INPUT, I've got a 12v spdt relay for switching. 12v output from sensor is fed to coil, on the other end 5v supplied to COM pin and "Normally Open"(NO) pin to Arduino (with pull-down resistor). When 'NO' connected to loose LED it works properly (shows 5V on voltmeter when object is detected). But when connected to Arduino digitalRead(), it always returns LOW/0.
//code
int a=0;
void setup() {
  pinMode(2,INPUT);
  pinMode(13,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  a ==  digitalRead(2);
  Serial.println(a);
  if(a==HIGH){
    Serial.println("Object Detected");
    digitalWrite(13,HIGH);
  }else{
    Serial.println("There's no object");
    digitalWrite(13,LOW);
  }
  delay(1000);
}


texts: I want to program multiple arduino at once

texts:
I am aware that using a USB Hub you can attach multiple arduino to one computer and either upload code one by one or use bash script to upload code on all arduinos together. But you can attach only as many arduino to a computer. I need to prgram around 100 arduinos/atmega ICs at once. Is there a way to do so?
There are other methods that I found online like programming ICs over Wifi network. But that require a lot of WiFi chips connected to arduino. I cant setup that. Also that doesn't seems cost effective.
Also Arduino sells their uno and other boards with pre-installed blink program. They must be doing batch programming only (multiple ICs at once). Any idea how they do this?


texts: Can the Arduino Leonardo Read 3.3v digital input?

texts:
I'm having difficulty finding information about the ATmega32U4 logic levels for the digital input ports.
I was wondering if I can hook up the 3.3v output of https://www.amazon.com/dp/B07KBWVJMP/ (HC-SR501 PIR Sensor Infrared IR Body Motion Module for Arduino Raspberry Pi) straight into the digital read ports.
I know this is possible on some chips, as they treat both 3.3v and 5v as logical highs, but I can't find the cut-offs listed for the Arduino Leonardo.


texts: Where is CLKPR located on Ubuntu 16.04 with Arduino 1.8.3

texts:
I would like to see the definition of CLKPR. I guess that similarly to PORTB and other registers, it should be defined by the toolchain? (see Where is PORTB defined? )

Am I right?
Where should I look for this toolchain on Ubuntu 16.04? I tried locate and find commands in terminal with various strings relating to the toolchain expected path / files, but could not find it (tips and tricks on how I may look for such paths in the future would be welcome ;) ).


texts: Reprogram Atmega 16u2 on Arduino Mega with Arduino IDE?

texts:
I had an Arduino mega 2560, suddenly Arduino didn't recognize my computer and I thought the problem is about Atmega 16u2 and I decided to copy hex file from another Arduino Atmega 16u2 and paste to damaged Arduino but it didn't work.
in fact, in our laboratory, we don't have any Linux and other software to reset or reprogram Atmega 16u2 on the other hand I know several methods to solve the problem but I need to know can I use the Arduino IDE to reset Atmega 16u2 without other software.
thanks a lot.


texts: NodeMCU: Wiegand not working for one device, while working for another

texts:
I'm using a NodeMCU, and a working code for reading Wiegand data, with this library.

I managed to successfully read the Wiegand signal from this device.

However, I also have this new AR-721H device, and I can't get the Wiegand to work. This is the manual for the device.

There is absolutely nothing coming to the mcu. Everything is wired identically as the working device.

According to the manual, everything should be working, but I am at a loss.

Can someone please tell me what I might be doing wrong?

The store clerk told me something about needing a controller that converts RS485 to RS232, but I have no idea what that means. I already made it work with another device...


texts: Overlapping text problem with TFT SPI 1.3" ST7789 display

texts: I have a problem with my ST7789.  My display just piles up when I show the current time, or showing some variable value that changes.


texts: What does I/O/T stand for in a pinout diagram? (esp32-s2)

texts: I am looking at the pinout of an esp32-s2 board with LCD Display (see picture below) and I am wondering what I/O/T stands for. I am particularly looking at pin IO46 and wondering if it can be used only as input (in case the "I" stands for input):


texts: How to check if two device has the same address on I2C?

texts:
I start a new project with Arduino UNO and MCP23017 expander. Using this, I can connect 8 chips on Arduino, by selecting different addresses ( from 0x20 to 0x27 ).
My question is, if I connect two MCP23017 chips with the same address, there is any way to see somehow that I have two chips with the same address ?
I am using a standard I2C scanner in Arduino code, but is nt return me if I have multiple chips with the same address, he see only one chip for example !

Can you please help me with some ideas to check how man chips are connected with the same address?


texts: setting output analog/digital pin to ground

texts:
So I need to automaically eject a CD from a Blu-Ray drive, I have a wire welded on the drive's card that if manually connected for a split second (pulse) to the ground of that same card on the drive, will eject the CD. Now in order to do that automatically I'm using an Arduino Nano and I connected that wire to an analog pin "d1" set its mode to Output and connected the grounds of both Arduino and drive together. Here's my code 1

int ds1 = A2; //pin that indicates the existence of the CD inside the drive if HIGH and its inexistance otherwise
int d1 = A3;  //pin connected to the wire that if connected to ground ejects the CD

void setup() {
  Serial.begin(9600);
  pinMode(ds1, INPUT);
  pinMode(d1, OUTPUT);
  while((!analogRead(ds1))) //if the CD isn't inside the drive wait
  {}
}

void loop() {
  analogWrite(d1,0); //eject CD
  delay(500);
  while(!analogRead(ds1)) //if the CD isn't inside the drive wait
  {}
  delay(1000);
}

I'm thinking that maybe setting the pin to 0 doesn't necessarily mean I connected it to the gnd, it's just a possibility if you see anything wrong with the code or have any suggestion please help me


texts:
I have been trying to count pulses from a 12,500 Hz square wave to trigger an output. Here's the code I have so far. When the Arduino is reset it prints 315 to the serial over a 25 ms sample. 315 x 40 = 12600. Which seems to me it's working perfectly.

My only problem is it only returns this number once upon reset of the board. Now if I move that same code down into void loop, it counts consecutively giving me inconstant returns.

I am not understanding what I need to put in the loop section so I can repeatedly and accurately count how many toggles of the input pin I am getting over a period of time so I can do something to the output based off the presence of the 12,500 Hz signal or not.

volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2

void setup() {
   // Put your setup code here, to run once:
  Serial.begin (9600);
  attachInterrupt(pin_irq, IRQcounter, RISING);
  delay(25);
  detachInterrupt(pin);
  Serial.print(F("Counted = "));
  Serial.println(IRQcount);
}

void IRQcounter() {
  IRQcount++;
}

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

Using the above code, every time I press the reset button I get one line in the serial window.

Counted = 441
Counted = 442
Counted = 441
Counted = 441
Counted = 441

Now I want to get the same result, but repeating over and over. That way if the signal drops out I can trigger an output to turn off (LOW). When the signal is present the output will go high.

My attempt was to move the attach interrupt down into void loop, so it would repeat. Here's what it looks like.

volatile int IRQcount;
int pin = 2;
int pin_irq = 0; //IRQ that matches to pin 2

void setup() {
  // Put your setup code here, to run once:
  Serial.begin (9600);
}

void IRQcounter() {
   IRQcount++;
}

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

  attachInterrupt(pin_irq, IRQcounter, RISING);
  delay(25);
  detachInterrupt(pin);
  Serial.print(F("Counted = "));
  Serial.println(IRQcount);
}

The return I get is self-updating, but the "count" instead of starting from 0 each time starts from the previous count. So it gets larger and larger. I am looking to return a constant value that represents my 12500 Hz signal so that, and only that, will trigger my output.

Counted = 442
Counted = 886
Counted = 1330
Counted = 177
Counted = 2221
Counted = 2667
Counted = 3112
Counted = 3557
Counted = 4002
Counted = 4448
Counted = 4893
Counted = 5338
Counted = 5784
Counted = 6229
Counted = 6674
Counted = 7120
Counted = 7565
Counted = 8010
Counted = 8456
Counted = 8901
Counted = 9347
Counted = 9792
Counted = 10237
Counted = 10683
Counted = 11130
Counted = 11576
Counted = 12022
Counted = 12469
Counted = 12915
Counted = 13361
Counted = 13808
Counted = 14254
Counted = 14700
Counted = 15147
Counted = 15593
Counted = 16040
Counted = 16486
Counted = 16932
Counted = 17378
Counted = 17825
Counted = 18271
Counted = 18717
Counted = 19164
Counted = 19610
Counted = 20056
Counted = 20503
Counted = 20949
Counted = 21395
Counted = 21842
Counted = 22288
Counted = 22735
Counted = 23169
Counted = 23616
Counted = 24062
Counted = 24508
Counted = 24955
Counted = 25401
Counted = 25730
Counted = 25756
Counted = 26200
Counted = 26646
Counted = 27093
Counted = 27539
Counted = 27985
Counted = 28432
Counted = 28878
Counted = 29324
Counted = 29770
Counted = 30217
Counted = 30663
Counted = 31110
Counted = 31556
Counted = 32002
Counted = 32449
Counted = -32641
Counted = -32195
Counted = -31748
Counted = -31302
Counted = -30855
Counted = -30408
Counted = -29962
Counted = -29515
Counted = -29069
Counted = -28622


texts:
I was wondering what I would need and what I should do, to make a Smart Light Bulb, like the Hue one from Philips.

I know these light bulbs can be controlled by their Apps from the smartphone, is there a way I can achieve this too?
What components would I need to purchase?
Is there a reference or a tutorial on how I should program this light bulb?


texts:
I've been trying to write a small i2c lib in C over the past week. I managed to get writing to slaves working (for example I can write to an ssd1306 oled) but reading (for example date/time from an ds3231) never works as my slaves don't seem to set SDA high when I request bytes.

uint8_t
i2c_read(uint8_t ack)
{
    uint8_t i, val;

    val = 0;
    cbi(SCL);
    DDRB &= ~(1 << SDA); /* Use SDA for input. */
    cbi(SDA); /* We need to pull down SDA to receive input. */

    /* Read 8bit from the slave. */
    _delay_us(DELAY);
    for (i = 0; i < 8; ++i) {
        sbi(SCL); /* Request one more bit. */
        _delay_us(DELAY); /* Wait a little so the slave can send his answer. */
        if (PORTB & (1 << SDA)) { /* Here the slave should have set SDA to 1 but it never does. */
            PORTB |= (1 << PB4);
            val = (val << 1) | 1;
        } else {
            val = (val << 1);
        }
        cbi(SCL);
        _delay_us(DELAY);
    }

    /* Send back an ACK or NAK. */
    DDRB |= 1 << SDA; /* Use SDA for writing. */
    if (ack)
        cbi(SDA); /* Set SDA to 0 to send ACK. */
    else
        sbi(SDA); /* Set SDA to 1 to send NAK. */

    sbi(SCL);
    _delay_us(DELAY);
    cbi(SCL);
    cbi(SDA);

    return val;
}

I set PB4 with to 1 when a slave actually sends a 1. Apparently that never happens.
I also had a look at how the various other libs out there do it but I didn't spot anything that would make a difference.

Any clues on what I migth be missing? Before reading my program sends the slave address to the bus. Also: please don't tell me to use other libraries since this is a learning project.


texts: How to control motor in trapezoidal manner using arduino

texts:
I am Working on a project in that i have to control motor in a Trapezoidal motion profile. on Y-axis is the velocity and X- axis as a time.
Velocity increases linearly for a certain time, then constant velocity for certain time and then Linearly decreasing the velocity and stop the motor


texts: Are the output pins on the 74HC595 shift register protected against shorting?

texts:
In the following schematic you can see that Q1 and Q4 both are connected to a Arduino's Digital Input Pin. So if Q1 is high and Q4 is low, would there be current flowing from Q1 through Q4 (and through the chip) to Ground - or is there already some protection inside?

Are the output pins on the 74HC595 shift register protected from connected voltages in the realms of their own VCC? Or do you need to put a diode in?

I feel like this is a very basic question, which makes it very weird that I didn't find an answer to this, already... :-( Am I looking into the wrong resources? I had a look into the provided datasheet, but couldn't find any information. Didn't get any results from searching for existing posts on Stack Exchange or other sites.


texts:
Sorry for the newbie question (just started learning electronics).

I just saw a tutorial that says that the 5V output pin on the Arduino delivers more amps (if needed) when connecting more voltage to the board (connecting to the 9 - 12V instead of 5V).
Does that mean that the 5V pin then delivers more than 5V as well?


texts: Using software Serial for Adafruit Thermal library and more general cpp question

texts:
I'm working on a proof of concept for using the Adafruit_Thermal printer library with an ATTiny85.

The ATTiny85 does not come with hardware serial capability, so I started looking into using SoftwareSerial to create the serial port necessary. I started down this path and ran into an error in the thermal library's constructor:

// thermal-printer.ino example file

#include "SoftwareSerial.h"
#define TX_PIN 3
#define RX_PIN 4

SoftwareSerial mySerial(RX_PIN, TX_PIN);

#include "Adafruit_Thermal.h"

Adafruit_Thermal printer(&mySerial); // Pass addr to printer constructor

// Adafruit_Thermal.h

class Adafruit_Thermal : public Print
{

public:
    // IMPORTANT: constructor syntax has changed from prior versions
    // of this library.  Please see notes in the example code!

    Adafruit_Thermal(Stream *s = &Serial, uint8_t dtr = 255);

  Documents/Arduino/libraries/Adafruit_Thermal_Printer_Library/Adafruit_Thermal.h:125:33: error: 'Serial' was not declared in this scope
     Adafruit_Thermal(Stream *s = &Serial, uint8_t dtr = 255);

If I understand correctly, the verification process is failing because the compiler is looking for a global Serial value in the Adafruit_Thermal.hfile that doesn't exist because the ATTiny85 does not have HardwareSerial.

But, going by the Adafruit_Thermal class' constructor signature the reference passing of Serial is just a default value (right?) so I should be able to remove it and pass in my software serial reference. The SoftwareSerial class inherits from Stream, so it should still be a valid reference pass:

// this:
Adafruit_Thermal(Stream *s = &Serial, uint8_t dtr = 255);

// changes to this:
Adafruit_Thermal(Stream *s, uint8_t dtr = 255);

But when I do that, I start getting verification errors that make it look like the thermal instance wasn't constructed, like:

  undefined reference to `Adafruit_Thermal::begin(unsigned char)'

and

  undefined reference to `Adafruit_Thermal::Adafruit_Thermal(Stream*, unsigned char)'

Does this mean the class isn't getting constructed?

I looked at the underlying constructor definition to see if something was blowing up in there, but there doesn't seem to be anything fancy at the constructor level:

// Constructor
Adafruit_Thermal::Adafruit_Thermal(Stream *s, uint8_t dtr) :
  stream(s), dtrPin(dtr) {
  dtrEnabled = false;
}

This should still work with the software serial reference pass, right?

I'm a bit lost on how to debug this now. Any ideas?

Update

After a reply from Majenko I pulled up the cpp file and looked at the header reference:

So this means the cpp file was still referring to the include path header file instead of the lib version?

I updated my cpp file to use:

#include "lib/Adafruit_Thermal.h"

and I still get undefined reference errors, so it may still be something else, but I wanted to share this additional info.


texts: Arduino IDE - scope of the pre-processor "#define"

texts:
I'm creating an Arduino library and have 3 files - a "test.ino" program, and two library/class files: "testLibrary.h" and a "testLibrary.cpp".
The library makes use of some hardware-specific resources such as registers and ISRs that depend upon which I/O pin is used, and this should be done at compile time.
I would like to #define a pin number in the main program which, at compile time, is used in the library to determine which code sections are activated. Since this will be a standard Arduino library for use by others, it should compile and run without users having to change their compiler or #include path to make it work.
But it seems that the scope of #define in the main program/sketch does not extend to the library.
test.ino
#define PIN_NUMBER 3
#include "testLibrary.h"
void setup() {}
void loop() {}

testLibrary.h
#ifndef _TESTLIBRARY_h
#define _TESTLIBRARY_h
#ifndef PIN_NUMBER
#error PIN is not defined
#endif
class test {
public:
  test();
  ~test();
};
#endif

testLibrary.cpp
#include "testLibrary.h"
test::test(){}*
test::~test(){}

Compiling the above branches to "#error" using the Arduino IDE 1.8.13 and also using Visual Studio with Visual Micro.
Is there a way for me to have an Arduino library use a "#define" from the main sketch?


texts: Connecting an Arduino to a telephone line?

texts:
I would like to connect my Arduino Uno to a telephone line in order to answer a call, record a sequence of DTMF tones, generate a DTMF tone in response, and hang up.

The telephone line uses a standard RJ11 connector. When a touch-tone phone is connected to the line, it receives one of two rings:

a standard ring, which signals an incoming call
a shorter "two-ring" sequence which signals a call from a local intercom

I would like my Arduino to listen for the "two-ring" sequence and only answer those calls.

How would I go about connecting my Arduino to the telephone line? Is there a shield designed for this purpose? I know I can use the tone() function to generate the DTMF tones, but I'm assuming I would need to perform some form of Discrete Fourier transformation in order to "read" the DMTF tones from the other end of the line.

Any suggestions would be appreciated.


texts:
Arduino USB
I want to write an Arduino Sketch (if there is no other possibility it can also be plain c) , to grab keyboard inputs from my ordinary USB keyboard. Preferably without expensive hardware, but as mentioned, if there is no other possibility, this will do it too.
Is this possible with V-USB? I looked a their website, but it seems like this only supports being slave and to imitate a keyboard.


texts: Arduino Mega read of serial encoder read at 1,024,000 baudrate?

texts:
Reading a 1.024m baud rate 77 bit stream from a serial encoder- begin.serial1(1024000); is accepted - but no idea if UART can actually run there.

In the screen grab, channel 7 is a 8 microsecond clock pulse generated by the Arduino, channel 6 is the encoder response - always begins 13 microseconds after rising edge of clock pulse, first part is always 10101101, after that it's pretty random as encoder rotates.

I tried unsuccessfully to read the pins at that speed, no way, then tried reading the repeating data at synchronous microseconds +1 to try reading one bit at a time through sequential 77 bit words while not rotating - but clocking varies in Arduino program by up to 8 microseconds over the 2 millisecond repeating patterns though.

I tried the serial read through serial1 port, getting some data, but random... with no terminator to rely on, wondering if anyone has a suggestion as to how to clear/load serial buffer after a long pause (long being almost two milliseconds) followed by the 10101101 that always starts the next read (but could possibly repeat inside of it).

I'm a newbie to these things, just tinkering around thought decoding a serial encoder would be fun... many many many hours later, have learned a bit about them and more so learned how little I know about them :)


texts: How to change the topic_name string to PROGMEM?

texts:
I'm trying to save SRAM on my Arduino pro mini by going through some libraries. I've noticed that to use my Arduino as a ROS node the library stores the topic name and message type as constants.

class Publisher
{
public:
  Publisher( const char * topic_name, Msg * msg, int    endpoint=rosserial_msgs::TopicInfo::ID_PUBLISHER) :
    topic_(topic_name),
    msg_(msg),
    endpoint_(endpoint) {};

  int publish( const Msg * msg ) { return nh_->publish(id_, msg); };
  int getEndpointType(){ return endpoint_; }

  const char * topic_;
  Msg *msg_;
  // id_ and no_ are set by NodeHandle when we advertise
  int id_;
  NodeHandleBase_* nh_;

private:
  int endpoint_;
};

How can I store the constants to PROGMEM? Thank you


texts: Sending 5 Led pixel values to arduino , is this a good way?

texts:
I wanted to install a 5 LED strip underneath my PC's front panel. I want to send color over PC so it can change when i open different apps, with temperature or etc!

So all I think the best way to do this is to just use Arduino to set the LED Values!

But I have had some troubles creating a good communication protocol for this, I've been just simply sending 45 digits (15 3 digit numbers) to my Arduino with serial. here's code:
Arduino :

#include "Adafruit_NeoPixel.h"
#include "WS2812_Definitions.h"

#define PIN 4
#define LED_COUNT 5

struct pixel {
  int R = 0;
  int B = 0;
  int G = 0;
};

Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800);

char count = 1;
int pixelNumber = 0;
struct pixel tempPixel;
//struct pixel Pixels[LED_COUNT];

void setup()
{
  Serial.begin(9600);
  Serial.println("Init");
  leds.begin();  // Call this to start up the LED strip.
  clearLEDs();   // This function, defined below, turns all LEDs off...
  leds.show();   // ...but the LEDs don't actually update until you call this.
}

void loop() {
  if(Serial.available() > 0) {
    if(count == 1) {
      tempPixel.R = PC_Receive();
    } else if (count == 2) {
      tempPixel.G = PC_Receive();
    } else if (count == 3) {
      tempPixel.B = PC_Receive();
      count = 0;

      setPixelColor(pixelNumber, tempPixel);
      Serial.println(pixelNumber);
      leds.show();
//      Pixels[pixelNumber] = tempPixel;
      if(++pixelNumber >= LED_COUNT) {
        pixelNumber = 0;
      }
    }
    count++;
  }

//  if(pixelNumber == 0) {
//    for(int i = 0; i < LED_COUNT; i++ ) {
//       setPixelColor(i, Pixels[i]);
//    }
//
//    leds.show();
//  }
}

void setPixelColor(int a, struct pixel P)
{
  leds.setPixelColor(a, P.R, P.G, P.B);
}

char PC_Receive() {
  int result = 0;

  while(Serial.available() == 0);
  result += ((int)Serial.read() - '0') * 100;

  while(Serial.available() == 0);
  result += ((int)Serial.read() - '0') * 10;

  while(Serial.available() == 0);
  result += ((int)Serial.read() - '0');

  Serial.println(result);
  return result;
}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue) {
  for(int i = 0; i < LED_COUNT; i++) {
    leds.setPixelColor(i, red, green, blue);
  }
  leds.show();
 }

And here's PC's dirty code in python:

import serial
import time
import random

class Pixel:

    def __init__(self, R, G, B):
        self.R = R
        self.G = G
        self.B = B

def clearAll():
    for i in range(0,5):
        ser.write("000000000")

def sendPixel(pixels):
    for i in range(0,5):
        ser.write(str(pixels[i].R).zfill(3))
        ser.write(str(pixels[i].B).zfill(3))
        ser.write(str(pixels[i].G).zfill(3))

ser = serial.Serial('/dev/ttyACM2', 9600)

little = [0,0,0,0,0]

for i in range(0,5):
    little[i] = Pixel(0,255,50)
sendPixel(little)

time.sleep(0.5)
clearAll()

the problem is it isn't stable, i think i should just use an \n at end or send back OK or something to confirm it, but that would make it slow if i did it for each value! (and checking only once after all 5 leds are send would mean sending more values until i receive the ok and clearing and sending them again!)

Can you recommend me a better way?

Thanks!

EDIT: Just wanted to say! it's almost done! It does change color when i open chrome, and i think at 115200 baud rate it's fast enough to not notice a delay (although at 9600 i felt like it's slower then my (xxx/xxx/xxx....) protocol but it's better and works at 115200

i will add some basic functions to my python side and add a rainbow effect
I will also add GPU temperature and etc... it's not going to be really hard on linux but windows, im not sure :D


texts: Getting a truly random number in Arduino

texts:
What is the best method to get a truly (as opposed to pseudo) random number in Arduino, or at least the best possible approximation? From my understanding, the function randomSeed(analogRead(x)) it's not random enough.

If possible the method should leverage the basic Arduino setup alone (no additional sensors). Solutions with external sensors are welcome if they improve significantly the randomness over the basic setup.


texts: OTA update - sodaq board (arduino M0 compatible)

texts:
I am trying to perform a firmware update from an SD card, on a Sodaq Sara AFF board. If i use the SDU.h library in my sketch, it fails the board check. See this link please.
I have edited the SDU.cpp myself to force the selection of ARDUINO_SAM_ZERO. It is now :
__attribute__ ((section(".sketch_boot")))
unsigned char sduBoot[0x6000] = {
  #include "boot/mzero.h"
};

I have increased the size to 6000 otherwise it was complaining too many initializers.
I also have changed the SD_SS_PIN to match my pin on the SDUboot.ino, under extras. Afterwards, i recompiled it with build.sh in the same folder.
But I am unable to perform the firmware update. After power cycling the board (original code: the blink example, target update: blink with a faster rate) - the original firmware remains.
I exported the firmware using arduino IDE -> export compiled bynary, and tested both versions with and without bootloader.
Any help would be appreciated.


texts:
how does an 8bit MCU handle 16bit output?
How does an 8bit MCU store values higher than 8bits?
I am using an attiny, on an adafruit trinket. and other 8bit MCUs.
http://www.atmel.com/devices/attiny85.aspx
I was doing some things with uint32_t datatypes, when it hit me, that it would seem like uint32_t would be an incompatible datatype. Even 2Byte data type like int seems peculiar. "int stores a 16-bit (2-byte) value"
considering the MCU is 8bit.

I saw this link, that sounded like it would have more info, but its pages are incomplete. http://playground.arduino.cc/Code/DatatypePractices

So how does that work?
How does an 8bit MCU make use of data-types over 8bits?


texts: How can I set two PWM at two different frequencies?

texts:
I'm using the arduino uno hooked up to two LEDs. One is in pin 3 and the other one in pin 5. I know that pin 3 is controlled by timer3 and pin 5 by timer 1. I've tried a lot of things to have two independent frequencies. I really don't care about the PWM, I have it to 50% (constant).

There are resources to set the frequency (http://playground.arduino.cc/Main/TimerPWMCheatsheet), but these are predefined frequencies. I need to have one PWM at 650Hz and the other at 850Hz.

Any recommendations on how to approach this problem?


texts: Sending wav file on ESP32 to flask server

texts: I'm just starting to learn about ESP32, and recently I'm trying to send a SPIFFS wav file to a flask server. does anyone know how to do it. I would love to thank and appreciate your every answer.


texts: ESP32: interrupt error (The following tasks did not reset the watchdog in time)

texts:
My system includes 2 ESP32 devices, communicating over ESPnow protocol. The slave device (connected to a Joystick)  is transmitting only when a changes occur, yet there can be several changes in a short time. The Master receives the transmission and executes upon. It starts running OK, but from time to time the master gets the following error and reset:
6429) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
The master loop is empty, so to my understanding it runs endlessly (like NOP?) until an interrupt is received. However, the function registered with
esp_now_register_recv_cb(OnDataRecv);

is not very short. So perhaps this is the cause for the error.
I guess I could use a handling routing to collect the messages from the slave, but in this case it doesn't matter if a packet of data will be lost from time to time. I prefer losing old data rather than responding to it late.
Any ideas how to solve this problem? perhaps stop registration of the OnDataRecv when the master is working on the service routine? and re-register it when ready?
the relevant code:
struct_message myData;
// callback function that will be executed when data is received
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
my_tank.tank_go_vector(myData.x_val,myData.y_val,myData.button_state,range);
} // of OnDataRecv()
The registration within setup:
esp_now_register_recv_cb(OnDataRecv);

The routine that executes:
void tank_go_vector(int _x, int _y,int _button,int _range) {

    Serial.print("  >> in tank_go_vector: x/y/button/range ");
    Serial.print(_x);
    Serial.print("..  ");
    Serial.print(_y);
    Serial.print("..  ");
    Serial.print(_button);
    Serial.print("..  ");
    Serial.print(_range);
    Serial.print("..  ");

    // go by vector recieved from joystick;

    int x_speed = abs(_x);
    int y_speed = abs(_y);

    x_speed = map(x_speed,0,_range,0,SERVO_RANGE); // 255 for 8 bits
    y_speed = map(y_speed,0,_range,0,SERVO_RANGE);

    Serial.print("   x_speed / y_speed: x/y ");
    Serial.print(x_speed);
    Serial.print("..");
    Serial.print(y_speed);

    if (_x==0 && _y==0) {
      Serial.println("  stop");
      left_motor.stop();
      right_motor.stop();
      return;
    }

    if (_x==0 && _y>0) {
      Serial.println("  forward");
      Tank_forward(y_speed);
      return;
    }

    if (_x==0 && _y<0) {
      Serial.println("  backward");
      Tank_backward(y_speed);
      return;
    }

    if (_x>0 && _y==0) {
      Serial.println("  Right Pivot");
      Tank_right_pivot(x_speed);
      return;
    }

    if (_x<0 && _y==0) {
      Serial.println("  Left Pivot");
      Tank_left_pivot(x_speed);
      return;
    }

  // now deal with vector moves TBD

  } // of tank_go_vector


texts: Fastest way to read an array of numbers from python

texts:
I'm trying to send an array of numbers from python to Arduino over the serial connection. I can reliably read a small incoming set of numbers (for example 123435678) from python, which I can then parse since I know how many digits are supposed to be in each number (for example, 1, 23456, 78). I do this with my Arduino code:

void getInput() {
     char buff[9];
     int field1;
     char field2[6];
     char field3[3];

  Serial.readBytes(buff, 8); //read 8 bytes from the Serial port
  buff[9] = '\0'; //null terminate the string we just read
  Serial.println(buff); //check that we got it
  for(int i=0; i<buff_len;i++) { //now we divide up the string into separate numbers
    if(i==0) {
      field1 = buff[0] - 48; //turn it into an int using ASCII
    }
    if(i>=1 && i<6) {
      field2[i-1] = buff[i];
      field2[5] = '\0';
    }
    if(i>=6) {
      field3[i-6]=buff[i];
      field3[2] = '\0';
    }
  }
  for(int i=0;i<buff_len;i++) { //clear the buffer
    buff[i]=0;
  }
}

But if I wanted to send a whole array whose contents I don't know in advance, for example like this:

for i in range(200):
    ser.write(i)

What's the best way to get these numbers to Arduino and file them away in an int array? Should I make the array in python first as a numpy.linspace() and send that?


texts: How do I convert 0-5v PWM to a 0-12v PWM

texts:
I have a Arduino which I would like to use to control a 12v PWM fan for speed control.
I know about the 0-3.3v to 0-5v logic level shifter, is there a similar option for 0-5v to 0-12v? Or is there a circuit using a IC that I need to make?
Thanks in advance for your help.


texts: How does Arduino UNO deal with bit shifting?

texts:
Explanatory comment: I'm a beginner. I'm examining the feasibly of bit shifting to the right 6 places to divide up the range of the Arduino ADC (has a range of 0 to 1023) to something much smaller. Such that any number in the ADC registers, between 0 and 63 produces a value of 0, a number between 64 and 127 a 1, between 128 and 191 a 2, between 192 and 255 a 3, etc. There is a change every 64 increase in the initial number.

I think this is possible to do. But some doubt has been expressed I think.

As far as I have determined, after right shifting 6 places to the right the following values of numbers are resident in the ADC registers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15.

I wish you to consider, is there anything in the way Arduino's IDE works, or with the nature of the initial number in the register (signed/unsigned) that makes the results I have indicated false.  I think, that the initial number will be unsigned, just guessing.


texts: How to make MEMS IR Thermal Sensor - D6T-44-L06 work with Arduino?

texts:
I am working on project that my team need to detect the presence of the people. At first, we tried with motion sensor but it wasn't the way that we want it to work. We want to detect presence of the people even they don't move.

We decide to go with Omron Thermal Sensor D6T-44-L06. However, there lacking of tutorial or simple code online that actually show how to connect that Omron thermal sensor with Arduino. How can I interface this with Arduino?


texts:
Recently, I have been working on a project involving 8 Tower Pro sg90 servos and an Arduino Uno. The issue I am running into is that the servos will randomly move when connected, without even receiving a signal from the
Arduino.
Specifically, sometimes the servos will work perfectly and the input move the servos fine, but then all of the sudden the servos will start twitching and moving erratically back and forth. Then I disconnect power and plug it back in and I will sometimes work again or sometimes not.
I don't think power is the problem because I am powering the servos externally with a 5.5v power supply which can provide 2.5 amps. I also made sure to have a common ground between the Arduino and the power supply. Additionally I don't think this is an issue of a broken servo because I have this problem with all eight. In my code I have input pins to control the servos which are just buttons. These buttons also have pull down resistors, so I don't think the input is the problem either. I am using the Arduino servo library.
The only other thing I can think of is external frequency interference, because some of the circuitry and wiring is close together, but none of the wires are very long and I even tried putting a ferrite bead on the servo cables but to no avail.
If anyone has any ideas about a solution to my problem which I have not tried yet that would be amazing!
Thanks - Xander
#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
Servo servo7;
Servo servo8;

void setup(){
  pinMode(5, INPUT);
  pinMode(4, INPUT);
  pinMode(3, INPUT);
  pinMode(2, INPUT);
  pinMode(1, INPUT);
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(A2, INPUT);
  servo1.attach(13);
  servo2.attach(12);
  servo3.attach(11);
  servo4.attach(10);
  servo5.attach(9);
  servo6.attach(8);
  servo7.attach(7);
  servo8.attach(6);
}

void loop(){
  if(digitalRead(5)==LOW){
    servo1.write(120);
    delay(20);
  }
  else{
    servo1.write(50);
    delay(20);
  }
  if(digitalRead(4)==LOW){
    servo2.write(110);
    delay(20);
  }
  else{
    servo2.write(200);
    delay(20);
  }
  if(digitalRead(3)==LOW){
    servo3.write(120);
    delay(20);
  }
  else{
    servo3.write(50);
    delay(20);
  }
  if(digitalRead(2)==LOW){
    servo4.write(110);
    delay(20);
  }
  else{
    servo4.write(200);
    delay(20);
  }
  if(digitalRead(1)==LOW){
    servo5.write(120);
    delay(20);
  }
  else{
    servo5.write(50);
    delay(20);
  }
  if(digitalRead(A3)==LOW){
    servo6.write(110);
    delay(20);
  }
  else{
    servo6.write(200);
    delay(20);
  }
  if(digitalRead(A2)==LOW){
    servo7.write(120);
    delay(20);
  }
  else{
    servo7.write(50);
    delay(20);
  }
  if(digitalRead(A1)==LOW){
    servo8.write(110);
    delay(20);
  }
  else{
    servo8.write(200);
    delay(20);
  }
}


texts: What is arduino_debug.exe for IDE 1.5.6r2?

texts: After installing IDE 1.5.6r2, there are two .exe files, arduino_debug.exe and arduino.exe (which is same name as previously installed IDE 1.0.5).


texts: How to create a Arduino socket server to receive messages

texts:
From linux I can send a socket message using netcat

echo "Hello" | nc 88.109.110.161 100

But I don't know how to setup the socket server for listening incoming messages using the ethernet shield.

What I have so far is one from a lot of examples I tried but still not showing anything

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetServer server(1000);

void setup() {
  Ethernet.begin(mac);
  Serial.begin(9600);
// Check for Ethernet hardware present
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // listen for incoming clients
 EthernetClient client = server.available();
 if (client) {
   Serial.println("Client");
   // an http request ends with a blank line
   boolean currentLineIsBlank = true;
   while (client.connected()) {
     while(client.available()) {
       char c = client.read();
       // if you've gotten to the end of the line (received a newline
       // character) and the line is blank, the http request has ended,
       // so you can send a reply
       if (c == '\n' && currentLineIsBlank) {

// Here is where the POST data is.
         while(client.available())
         {
            Serial.write(client.read());
            //Serial.println(c);
         }
         Serial.println();

         Serial.println("Sending response");
         // send a standard http response header
         //client.println("HTTP/1.0 200 OK");
         //client.println("Content-Type: text/html");
         //client.println();
         client.println("OK");
         client.stop();
       }
       else if (c == '\n') {
         // you're starting a new line
         currentLineIsBlank = true;
       }
       else if (c != '\r') {
         // you've gotten a character on the current line
         currentLineIsBlank = false;
       }
     }
   }
   Serial.println("Disconnected");
 }
}


texts: How to converte EPOCH time into time and date on Arduino?

texts:
I have a question on how to convert EPOCH timestamps, which I receive as char*, into DD.MM.YYYY and HH:MM:SS format seperately?

Here are more information to my Arduino project: The Arduino is receiving through an ESP8266 module three different EPOCH timestamps from the OpenWeatherMap API for sunrise,sunset and the current date. I want these 3 informations to be displayed on an 1,3" OLED display, the date in DD.MM.YYYY and the other two timestamps in HH:MM format.

I was looking in several time libraries like TimeLib and RTC for a solution, but I wasn't able to find one.

That's my code fragment on receiving the timestamps:

DynamicJsonBuffer jsonBuffer(4096);
JsonObject& root = jsonBuffer.parseObject(client);

const char* date = root["dt"];
const char* sunrise = root["sys"]["sunrise"];
const char* sunset = root["sys"]["sunset"];

How to convert those timestamps?


texts:
I'm getting back up and running with microcontrollers after about 5 years of hibernation time, and I am trying to understand a lot of different things. I have been experimenting with Arduinos for the past few weeks and am having a ton of fun. I'm a software engineer by day and a hardware hacker / manufacturer by night. At my day job, I write scripts and applications that are thousands of lines long and highly complex, using external libraries of thousands more lines of code, etc. These are full-fledge, professional software applications.

So, here is my question. Is the Arduino capable of running full-fledged robotics and other large, complex hardware applications, or is it more of a tinkering, hobbyist tool?

How big of a project can be built using Arduino? Are there memory concerns? Can an Arduino run thousands and thousands of lines of code out of the box, and if not, is there a way to add more memory for larger, more complex projects?


texts:
When compiling I get the error
'as: unknown option »-mmcu=avr5« exit status 1'

I succeeded now using your piece of advise. Thank you so much.


texts: Why Windows 10 does not see Nodemcu device?

texts:
I am using a Windows 10 laptop. Behind the nodemcu it says that download CH340G driver.
I already had arduino ide and the esp libraries were already
installed because i was using a esp8266 01 device before.
I bought a Nodemcu i downloaded the driver for it CH340G driver.
When i install the driver it says that The drive is successfully
pre-installed in advance!
When I plug my Nodemcu to my computer with a new cable blue lights
come from the board and it stops. And windows doesn't make a sound
which indicates that it sees the device.
I don't think the nodemcu is the problem. How do i fix this?


texts: Is there an Arduino motor shield library?

texts:
I have an old motor shield but can see the revision 3 is still being sold: https://store.arduino.cc/arduino-motor-shield-rev3

When I follow the link for "Getting Started section" the page lists a lot of shields but not the motor shield.  I must be missing something really obviously but I can't find a library for the motor board.

I'm trying to drive 2 DC motors.


texts:
I am writing a wav file to an SD card on a ESP32 and that requires that every time I append data to the the end of the file I modify the header to set the right size in some fields.

I cannot find how to replace a value inside a file, I tried to write the new values with the seek function but unless I'm missing something looks like this deletes everything after the new value added.

I do not want to create a new file and to delete the old one as I will storing potentially large wav files and looks like wasting resources.

Is there a way to overwrite one value inside a file. I'm using SDlib but I'm open to others too.

Here the code I use to create the file and to update it:

#include "WavFileWriter.h"

void WavFileWriter::createFile(char const* filename, WavFileHeader* wavFileHeader)
{
  byte headerBuffer[44];
  wavFileHeader->getHeaderData(headerBuffer);
  File file = SD.open(filename, FILE_WRITE);
  file.write(headerBuffer, 44);
  file.close();
}

void WavFileWriter::appendData(char const* filename, WavFileHeader* wavFileHeader, byte* data, int dataLength)
{
  File file = SD.open(filename, FILE_WRITE);
  file.write(data, dataLength);

  byte headerBuffer[44];
  wavFileHeader->setFileSize(file.size());
  wavFileHeader->getHeaderData(headerBuffer);

  file.seek(0);
  file.write(headerBuffer, 44);
  file.close();
}

After calling appendData I end up with a file with just the header size (with the right header for a file with data but the data is gone).


texts: I'm new to arduino and electronics. I've been trying to use the MPU6050 with my arduino but I'm having difficulty understanding the code. I'm referring to the code put up on the arduino website (http://playground.arduino.cc/Main/MPU-6050#short). Is there any way I could get a line by line explanation of the code?


texts: Servo PWM Pin seems to be interfering with Wire.onRequest i2C function

texts:
A newbie here. I am thinking of interfacing Raspberry Pi with Arduino via I2c to control a few servo motor (as RPi have limited PWM pins). Meaning I would send input from RPi to Arduino to allow to the Arduino to control the servo.

The problem is this: When I was testing the I2C communication alone, it worked fine. The RPI can send a char, and the Arduino Uno can receive and recognize it.

However, when I added in the function to get the Arduino to send PWM signals to the servo, then the program becomes wonky (e.g. when I send over "0x1", the Arduino led should light up, when I send "0x2", the led should turn off. However, once I tried to PWM the servo, it flickers a while and does no light up when I send the signals, and the servo just vibrate a bit, instead of turning to intended position).

And the funny thing is, the code runs (meaning the LED turns on/off accordingly) as long as I do not plug in the servo's signal pin to the Arduino.

What am I missing? Why does the PWM seems to interfere with the I2C, and is there a way to get around this?

My code is below, do pardon me if anything is unclear, I will be more than happy to clarify.

Thanks guys!

#include <Wire.h>
#include <Servo.h>

Servo myservo_1; // create servo object to control lift servo
Servo myservo_2; // create servo object to control entry servo
Servo myservo_3; // create servo object to control exit servo
// twelve servo objects can be created on most boards

int statusLED = 0;
int statusServo = 0;
int pos;

const int ledPin = 13; // onboard LED
const int servo_1 = 3;
const int servo_2 = 5;
const int servo_3 = 9;

static_assert(LOW == 0, "Expecting LOW to be 0");

void setup() {
  Wire.begin(0x8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent);   // register event
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);     // turn LED off

  myservo_1.attach(servo_1);  // attaches the servo on pin 3 to the servo object
  myservo_2.attach(servo_2);  // attaches the servo on pin 5 to the servo object
  myservo_3.attach(servo_3);  // attaches the servo on pin 9 to the servo object

  //Serial.begin(9600);
}

void loop() {

  if (statusServo == 1){
    myservo_1.write(90);
    delay(15);
  }

  else if (statusServo == 2){
    myservo_1.write(0);
    delay(15);
  }

  else {
    myservo_1.write(45);
    delay(15);
  }

}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {

  int c;

  while (Wire.available()) { // loop through all but the last
    c = Wire.read(); // receive byte as a character
  }

  //Serial.println(c);

    if (c == 0x1){
          digitalWrite(ledPin, HIGH); // turn it on
          statusServo = 1;

    }

    else if (c == 0x2){
          digitalWrite(ledPin, LOW); // turn it on
          statusServo = 2;
    }

}


texts: Arduino: incorrect calculation of long integer

texts:
I'm doing a simple calculation with integers (on Arduino with ESP8266 12E), but I can't get the expected result and can't find the error. Can someone guide me?

#define A      200
#define B      A * 62
#define C      500

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

   unsigned long aux = 0;

   aux = (B * 500) / C;    // (12400 * 500) / 500 = 12400
   Serial.printf("aux = %d\n", aux);
   aux = aux * C;          // 12400 * 500 = 6200000
   Serial.printf("aux = %d\n", aux);

   // ERROR: Should result in "500", but is resulting in "1922000"
   aux = aux / B;          // 6200000 / 12400 = 500

   Serial.printf("aux = %d\n", aux); // It's printing "1922000"
}


texts: I always asumed it was a different option to power the board, but it seems to act more like a 5V supply. What then is the difference between this pin and the 5V pin?


texts: Question on pin management using PCA9534PW IO Extender

texts:
There is an IO expander PCA9534PW, Arduino UNO. I don’t really understand how I can manage this expander using UNO over I2C.

I found an example, but here is the reading mode.

What I need:
Set the IO0 pin to exit mode,
set the HIGH / LOW level to IO0.

In the datasheet, I just realized that to enter the settings mode - you need to write Wire.write(0x03).
How can I do it?


texts: Understanding the relationship of Pulse and Stepper RPM

texts:
This may be a better question for the Physics StackExchange so tell me if I should move the question.

I have a pretty simple script that I'm using to control the RPM of my stepper motor:

void loop(){
  digitalWrite(PIN, HIGH);
  delayMicroseconds(wait);
  digitalWrite(PIN, LOW);
}

as you can see it's just producing a pretty standard pulse, I have my Arduino connected to a driver that manages the motor. The wait variable comes from a second order equation I derived from measuring the RPM with a Tachometer and tweaking the value.

// From data RPM = 31729/x + 17.327 thus x = 31729/(RPM-17.527)
wait = M/(RPM-C);

It works pretty well, I get readings consistently within only 1 - 2 rotations off. But the slope and intercept seem completely arbitrary to me. Is there a chance it has to do with the clock speed of the Arduino? I'm using an Uno and from playing around with the numbers I can't seem to find a relationship. From what I can tell, the driver looks hardwired so I don't think it has much to do with the equation.

Any idea what these values, the slope/intercept mean?

Equation: RPM=31729/wait + 17.327 M:31729 and C:17.327


texts: Is it possible to bit-bang multiple SPI ADC, 12 bit sampled at 100khz? This would translate to a GPIO speed of about 1.2 Mhz.