text:
Usage of Crypto Library (Speck)
I really want to understand how can I use this library for my purposes.
I'm trying to encrypt a message that comes through the serial port of the Arduino, and send it through another serial port. But I'm having issues understanding how to use the library.
I have read the documentation of the library, but I still get errors, I need a little help with this.
This is the code I have (without involving the serial ports), initially I wanted to check if I could define my strings and use them in another way instead of using the TestVector Function:
 #include <Crypto.h>
 #include <Speck.h>
 #include <SpeckSmall.h>
 #include <SpeckTiny.h>
 #include <string.h>

 struct EncryptText
 {
     const char *name;
     byte key[32];
     byte plaintext[16];
     byte ciphertext[16];
 };

 EncryptText test ;

   static TestCipher {

   test.name = "Speck-128-ECB";
   test.key = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
                     0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
   test.plaintext = {0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
                     0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20};
  test.ciphertext = {0xa6, 0x5d, 0x98, 0x51, 0x79, 0x78, 0x32, 0x65,
                     0x78, 0x60, 0xfe, 0xdf, 0x5c, 0x57, 0x0d, 0x18};
   }

Speck speck;
SpeckSmall speckSmall;
SpeckTiny speckTiny;

byte buffer[16];

//void testCipher(BlockCipher *cipher, const struct TestVector *test, size_t keySize, bool decryption = true)
void testCipher(BlockCipher *cipher, size_t keySize, bool decryption = true)

{

    Serial.print(" Encryption ... ");
    cipher->setKey(key, keySize);
    cipher->encryptBlock(buffer, plaintext);

    for(byte b=0; b<16; b++)
   {
      Serial.print(buffer[b], HEX);
   }

    if (memcmp(buffer, ciphertext, 16) == 0)
        Serial.println("Passed");
    else
        Serial.println("Failed");

    if (!decryption)
        return;

    Serial.print(" Decryption ... ");
    cipher->decryptBlock(buffer, ciphertext);

    for(byte b=0; b<16; b++)
   {
      Serial.print(buffer[b], HEX);
   }
    if (memcmp(buffer, plaintext, 16) == 0)
        Serial.println("Passed");
    else
        Serial.println("Failed");
}

I'm getting the error: "exit status 1 'TestCipher' does not name a type"
EDIT: The full error that I get is:
 Speck_4-08-2017:27: error: 'TestCipher' does not name a type    static
 TestCipher {
           ^ Speck_4-08-2017.ino: In function 'void testCipher(BlockCipher*, size_t, bool)': Speck_4-08-2017:62: error:
 'key' was not declared in this scope
      cipher->setKey(key, keySize);
                     ^ Speck_4-08-2017:63: error: 'plaintext' was not declared in this scope
      cipher->encryptBlock(buffer, plaintext);
                                   ^ Speck_4-08-2017:70: error: 'ciphertext' was not declared in this scope
      if (memcmp(buffer, ciphertext, 16) == 0)
                         ^ Speck_4-08-2017:80: error: 'ciphertext' was not declared in this scope
      cipher->decryptBlock(buffer, ciphertext);
                                   ^ Speck_4-08-2017.ino: In function 'void perfCipher(BlockCipher*, const TestVector*, size_t, bool)':
 Speck_4-08-2017:104: error: 'key2' was not declared in this scope
          cipher->setKey(key2, keySize);
                         ^ Speck_4-08-2017.ino: In function 'void setup()': Speck_4-08-2017:158: error: 'testVectorSpeck128' was not
 declared in this scope
      testCipher(&speck, &testVectorSpeck128, 16);
                          ^ exit status 1 'TestCipher' does not name a type

Any guidance would be very helpful.

Hello and welcome to Arduino SE! Could you please provide the full error message?

I just made an edit adding the full error message I get.

Which version of the library are you using? (Github link would do just fine)

Sorry, I should have included it: https://github.com/rweather/arduinolibs/tree/master/libraries/Crypto

Does the TestSpeck example included with the library compile without errors?

Yes, it does, and the encryption is done correctly, but I wanted to try a way of manipulating the strings that will be encrypted. This way I could read a serial port and make the encryption.

Okay, that proves the library and IDE is installed correctly. You don't want to spend time debugging your code when the library or IDE itself is broken. Please see my answer how to start fixing your code.

The first error looks like this
 Speck_4-08-2017:27: error: 'TestCipher' does not name a type    static
 TestCipher {

Further errors are basically all caused by that one wrongly written declaration. It could be fixed by declaring the first struct properly.
Compare this example code you have
struct TestVector
{
    const char *name;
    byte key[32];
    byte plaintext[16];
    byte ciphertext[16];
};

static TestVector const testVectorSpeck256 = {
    .name        = "Speck-256-ECB",
    .key         = {0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
                    0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
                    0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
                    0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00},
    .plaintext   = {0x65, 0x73, 0x6f, 0x68, 0x74, 0x20, 0x6e, 0x49,
                    0x20, 0x2e, 0x72, 0x65, 0x6e, 0x6f, 0x6f, 0x70},
    .ciphertext  = {0x41, 0x09, 0x01, 0x04, 0x05, 0xc0, 0xf5, 0x3e,
                    0x4e, 0xee, 0xb4, 0x8d, 0x9c, 0x18, 0x8f, 0x43}
};

and your code
struct EncryptText
 {
     const char *name;
     byte key[32];
     byte plaintext[16];
     byte ciphertext[16];
 };

 EncryptText test ;
   static TestCipher {

   test.name = "Speck-128-ECB";
   test.key = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
                     0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
   test.plaintext = {0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
                     0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20};
  test.ciphertext = {0xa6, 0x5d, 0x98, 0x51, 0x79, 0x78, 0x32, 0x65,
                     0x78, 0x60, 0xfe, 0xdf, 0x5c, 0x57, 0x0d, 0x18};
   }

You wrote EncryptText test; by specifying the type EncryptText you defined before and a name test, but now, you can assign to test by just using test. + variable name and nothing else (no static TestCipher{}). Or you could use what the example does, it basically just skips the EncryptText test; part and puts it on one line, like static TestVector const testVectorSpeck128 = { and assigns inside the curly brackets just using . + variable name (without test or testVectorSpeck128).
Now, the second error
 'key' was not declared in this scope
      cipher->setKey(key, keySize);

is that the variable key is not defined in the function testCipher just like the error says, you have to define that variable or use the right one, in the example it was done using a function parameter (you commented out) TestVector *test, it was dereferenced and accessed with test->key. I assume you've properly defined that struct now, there's no need to deal with pointers and with direct reference to the data you can use it elsewhere by just using something like this
cipher->setKey(test.key, keySize);

rest of the errors are of similar fashion and can be fixed by just adding test. like I showed. If you fix those errors rest should be simple already.
As you are just learning, take small steps modifying the examples and use the Verify button as often as possible, Arduino IDE also has a button to autoformat code, use it, makes your code more readable for you and everyone else.

I managed to compile my code without errors, but now the encryption is not working as it should. Should I create another question for that or edit this one?

@LuzA I guess you can ask a new question, but maybe you can fit it here into the comments?

I think I will ask a new question, because I would need to include the code I have right now and well, it's also a different situation that the one I asked in this one.

It looks like you want to create a struct and initialize it. Like this:
struct EncryptText
{
    const char *name;
    byte key[32];
    byte plaintext[16];
    byte ciphertext[16];
};

EncryptText test = {
    "Speck-128-ECB",
    {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
                     0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00},
    {0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
                     0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20},
    {0xa6, 0x5d, 0x98, 0x51, 0x79, 0x78, 0x32, 0x65,
                     0x78, 0x60, 0xfe, 0xdf, 0x5c, 0x57, 0x0d, 0x18}
};

Then it appears you want to use that object. Note that to access each member of the struct you have to use dot notation (ex: test.key):
void testCipher(BlockCipher *cipher, size_t keySize, bool decryption = true)
{
    Serial.print(" Encryption ... ");
    cipher->setKey(test.key, keySize);
    cipher->encryptBlock(buffer, test.plaintext);

    for(byte b=0; b<16; b++)
    {
        Serial.print(buffer[b], HEX);
    }

    if (memcmp(buffer, test.ciphertext, 16) == 0)
        Serial.println("Passed");
    else
        Serial.println("Failed");

    if (!decryption)
        return;

    Serial.print(" Decryption ... ");
    cipher->decryptBlock(buffer, test.ciphertext);

    for(byte b=0; b<16; b++)
    {
        Serial.print(buffer[b], HEX);
    }
    if (memcmp(buffer, test.plaintext, 16) == 0)
        Serial.println("Passed");
    else
        Serial.println("Failed");
}


text:
Access denied when Uploading
I went to upload my sketch to my Uno (r3), but unusually, the Upload Console returned this error:
avrdude: ser_open(): can't open device "\\.\COM4": Access is denied.

Just started seeing this, cannot upload.

I had Ultimaker Cura open, this seemed to be hogging the com ports. Make sure your other apps aren't using them.

I can confirm here that for me it was also Ultimaker Cura. Once closed, COM port was free again. I think it's worth a try, if all the other things look ok (i.e. checking the device manager).

There might be another device has already connected to that port. It could even be a terminal emulator which is left connected from last debugging session.
Otherwise, make sure that your UNO is really presented on COM4 by checking with "Device Manager". if not, change the port where it is available.

Mine was locked down by Cura - a program that will (among other things) control 3D printers via serial. Closing it fixed the problem

@Chris thanks a lot, same problem

Yes - be careful Cura seems to do this.

same thing here with Cura, that is way wrong I don't even have a 3d printer plugged in so .. I'm going into Slic3r then

In my case, I simply forgot to close "Serial Monitor" window for another Arduino sketch, and that was it.

I'm using a windows 10 and had this happen randomly. I closed several other applications and it started working again.

How did you find out what other applications are using this port?

I guessed. I was using my USB drive for some other things and just started closing stuff.

Worked for me by just closing File Explorer and Cura not sure which one was the problem.

You have selected the wrong COM port. Go to Tools -> Port -> Select the right port. If you do not know the port number disconnect the Arduino, open the same menu again and look what is listed there, write down if you can't remember, now plug your Arduino back in and select the option that wasn't there before.

source: Stack Exchange

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

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

sort: votes


text:
Problems with reacting to joystick button press
I am trying to use a joystick in a project for device control. Pressing a joystick button should cause incrementing a variable. INPUT_PULLUP mode is used for internal button.
As I understand it, when the button is not pressed there is a HIGH level on the GPIO pin, and there is a LOW level when the button is pressed. The signal read from the button in thd sketch is inverted to HIGH when the circuit is closed.
I used some sketches for eliminating debounce, but in all cases when the button is pressed a stream of incoherent symbols occurs on the serial port. It happens both in the simulator and the IDE.
What can cause this stream on the output when waiting for the message that button is pressed? The symbols also occured when I put a count-variable on the serial port. Does the button debounce look correct?
int Joystick_Y = A0;
int Joystick_X = A1;
int Joystick_but = 1;
int X;
int Y;
int X_prev = 0;
int Y_prev = 0;
int butt_flag = 0;
int butt;

const unsigned long debounceDelay = 50;
unsigned long last_press;

void setup() {
  Serial.begin(9600);
  pinMode(Joystick_but, INPUT_PULLUP);
}

void loop() {
  butt = !digitalRead(Joystick_but);

  if (butt == 1 && butt_flag == 0 && millis() - last_press > debounceDelay) {
    butt_flag = 1;
    last_press = millis();
    Serial.println("Button was pressed!");
  }

  if (butt == 0 && butt_flag == 1) {
    butt_flag = 0;
  }

  Y = analogRead(Joystick_Y);
  X = analogRead(Joystick_X);

  if (X < 512 && X > 485) {
    X = 512;
  }
  if (Y < 512 && Y > 485) {
    Y = 512;
  }

  if ((Y != Y_prev || X != X_prev) && (X != Y)) {
    Serial.print("X: ");
    Serial.print(X);
    Serial.print(" Y: ");
    Serial.println(Y);
  }

  Y_prev = Y;
  X_prev = X;
  delay(500);
}

What Arduino are you using exactly? On Uno/Nano pins 0 and 1 are used for the Serial interface. And the debouncedelay of 50ms won't work, when you delay for 500ms at the end of loop().

As was mentioned in @chrisl 's comment: pin 1 on an Arduino Uno/Nano is the TX (transmit) pin for the Serial port. See here. This is the pin that is used to transmit serial data to the host.
When the same pin is also used as the joystick button, pressing it will interfere with serial output, causing the incoherent symbols you see to be transmitted.
Solution: Use a different (unused) pin.
Another potential problem is the delay (500) at the end of your loop() which, as @chrisl also noted, interferes with your debounce and will cause your code to react to button presses and joystick movements very slowly.

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


text:
Continuous servo not setting speed correctly
I have two continuous servos connected to my Uno, and I'm running this code on it:
leftServo.write(91);
rightServo.write(102);
delay(3000);

leftServo.write(112);
rightServo.write(81);
delay(3000);

leftServo.write(91);
rightServo.write(102);
delay(3000);

int i;
while(1) {
  i++;
}

When I run the code, the wheels stop for three seconds (91 and 102 are the zero values for these servos) then they spin for three seconds, then the left servo stops, but the right one only slows down about half way, it doesn't stop, even though the exact same number is used as before.
I can't figure out why this is?

My first piece of advise would be to dump that function (without the "while(1)" part) into the end of setup() and see what happens.

Same effect unfortunately

Have you swapped the motors round to check it's not the hardware? If that's the same try swapping the order of the final leftservo/rightservo commands.

I have added a delay of 100 ms between servo writes, and that seems to have helped, the zero point for the right servo seems to have moved now though, 106 moves slowly counter-clockwise, and 107 moves slowly clockwise

I'm leaning toward the conclusion that the problem is with the hardware, probably some noise effecting the servo. Are the motors running on a different supply to the Uno? Have you made sure the grounds are tied together? Have you tried some decoupling caps on the servo power supply? If you have access to one take an oscilloscope to the circuit and check for unwanted noise.

This is for an assignment, we are given a pre-made shield which we aren't allowed to modify. I'm using a 3A mains adaptor to power the board. Grounds are tied.

Any chance of getting a scope on the board to check the noise theory? If it's confirmed as definately not noise related I'm running out of ideas. I should be able to spend some more time on this evening, if I find anything relevent I'll get back to you.

It is possible your zero values are incorrect, but still manage to stop the motors under some circumstances if coming from a previous value which causes the servo amp to decide it is in an anti-hunting "dead band".  Another possibility could be heating from running the motor moving the neutral point, though it seems less likely.  Fundamentally, these continuous-run modifications can be temperamental, as they take something that is supposed to be closed loop and cut the loop open.

Issue was fixed by adding a delay of 100ms between servo writes, smaller values may work, but I haven't tried yet

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


text:
PC cannot access HC-06 Bluetooth COM port
I have an HC-06 Bluetooth module connected to an Arduino Uno board to allow for the data received by the Ultrasonic sensor to be transferred to my PC via Bluetooth and serial communication.
I am using the PuTTY program to view the data. The thing is, my PC says that it has paired with the Bluetooth and I was able to see the COM number, but when I opened PuTTY and entered the COM number while choosing the option 'serial' an error box appeared saying: "Unable to open serial port."
The way I am currently connecting my b
Bluetooth to the arduino board is:
RX->pin 10
TX->pin 11
GND->GND pin
VCC-> 5V VCC
I am sure that the sketch in the Arduino for serial communication via Bluetooth is right as I have tested the system yesterday and it worked.
Only after a time (say like 5-10 min) the connection breaks and I can't seem to figure out the problem. The Arduino is being powered by USB, if that matters.

If you have powered the BT module from 5v you may have fried it, I recall that the hc-06 module is 3.3v and 3.3v signal too.

The HC-06 vcc needs minimum power 3.6 to 6V, but it's the rx, tx pins that need 3.3 v output from the arduino


text:
Arduino + HC-05 Problem: AT Commands are not working
Device: Laptop, HC-05, Resistor 2.2k and 4.7k, Arduino Uno R3
So im trying to rename and change password of my HC-05. for full detail schematic diagram. Here(the difference is, i also used the STATE Pin from HC-05 then connected it to Pin 9
since according to Instructubles it is used for activating AT Mode):
Now for coding, i got it from Instructables.com and here: https://www.instructables.com/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/
or
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11);
#define Key 9
void setup()
{
  pinMode(Key, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(Key, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}

void loop() {
  // put your main code here, to run repeatedly:
  if(BTSerial.available()){
    Serial.write(BTSerial.read());
  }

  if(Serial.available()){
    BTSerial.write(Serial.read());
  }
}

The problem: i tried to follow the instructuble's instruction. but it didnt work. then i tried doing my own from what several tutorials i have read:
for the details,

i set my circuit and do the necessary wiring as shown in the picture + STATE Pin -> Arduino Pin 9.

I then connected my Arduino Uno to my Laptop, the HC-05 is blinking per half second, if you need the detail. Then uploaded the code...then finally, I opened the Serial Monitor(note that my HC-05 is not Paired to any devices in the first place. i "Forgot" them just incase).

then go to 9600 Monitor and enter simple command like AT, AT+NAME? or AT+PSWD? but nothing appeared in my terminal.

i also checked the 38400 monitor and did the same things. nothing happened.

then just maaaaybe it was just not showing but actually working, I tried AT+NAME=JULIE trying to rename my HC-05 to JULIE for each Terminal, going back and trying at 9600 then 38400. nothing happened at any Terminal. my HC-05 is still HC-05 name and the LED in my HC-05 are still blinking per half sec.

Then a bit annoyed, i then do a try-and-error. i tried to upload the code, then Paired it now, this time with my Phone. Then enter AT Commands in my Bluetooth Terminal App(from Playstore) and try to AT Command there. but still, nothing works.

My HC-05 is working as intended when i used it a simple LED on and off, and Servo using my Phone wirelessly few hours ago. But when i tried to do AT Command codes, nothing appears in my Serial Monitor such as the OK() or other AT Command replies.
so i would like to know where i did go wrong and why i cant use AT Command whether 9600, 38400 or even trying to do AT Command in my Phone's BT Terminal App? if you think i have missed an important details that i should mention, feel free to let me know.

check the connections ... on transceivers the TX is usually the outgoing data being transmitted over the air, not transmitted to the controller over the wires connection

Take a look at this blog post I did on this some time ago. I think it will answer most of your questions.

I know the topic is a bit old, but I'm curious to know the version of your BT module: AT+VERSION? I have often used the EN pin for AT mode but putting it to ground, not to the most!

Ok, MAYBE I solved it^^ so the thing is, i noticed that my LED is still blinking intense instead of 2 sec light off and on. which means that i am still not in AT Mode.
but the thing is if i followed Instructables and other website tutorial. I SHOULD be able to be in AT Mode. im not exactly sure why im still not in AT Mode. So tried something:
the wiring/circuit is still THE SAME. but add something:
I took another wire, connect the EN Pin of HC-05 -> 5V of Arduino.  since days ago i was trying to do tinker my HC-05 here and there and i remember that i tried to put EN in 5V then it start blinking differently. so i tried the same thing today. then i went back and Forget Paired Device, connect my Arduino to my Laptop, then reupload my code, then go to Serial.Monitor 9600 set No Ending Line -> Both NL & CR. then i reenter the AT Commands.
AT+NAME? then AT,then AT+PSWD?
all worked. the AT+Name shows the name of my HC-05, and the AT+PSWD shows the password. so then i decided to finally rename my HC-05.
AT+NAME=USER_FAIZ and AT+PSWD=ARDUINO individually in the Serial Monitor...and now my HC-05 has different name which is USER_FAIZ and password which is ARDUINO. i then went to my Phone, scan for bluetooth device and there it is. USER_FAIZ and password is ARDUINO.
^^what im not really sure if it is the solution im searching for. i searched some tutorials again but none of them mention of using EN Pin and most of them use STATE Pin of HC-05.So because of that, i wont "Check" this Answer as maybe this is not the best solution out. maybe just not yet. but it did solve MY problem so it may solve other users problem too so ill add it here to inform.

please do not post pictures of text ... some people cannot view images ... copy the content of the serial monitor and paste it into your answer ... there is a button in serial monitor for the copy function ... format text as code

i have deleted the photo instead. just a screenshot/visualize example of my solution and i closed my IDE few hrs ago so i cant copy it back now. i have written the result anyway and the point that it shows a proper response such as Bluetooth Module's name and password is written anyway so wont really affect if i keep i there or not. anyway, the point is there and it is now working as intended. will follow what you just said nextime if i will make a post here thumbs up


text:
How does while(analogRead(A0)) function in this code?
A sine wave is being fed to A0 and I would like to calculate the frequency. If a certain threshold is crossed, start the timer.....count 5 such crossings.....then stop the timer. The code is attached. Even though I understand while() with logical operators such as while(State<5) (shown in code), I do not understand the use of while(analogRead(A0)). I would like to know how it functions in relation the code? The program runs fine as it is. Tested this in Tinkercad, and got erroneous readings when while(analogRead(A0)) was commented. Thank you so much for reading my question ^_^.
void loop()
{

  while(State<5)
  {
    val=analogRead(A0);
    if(val>200)
    {
      Serial.println("Threshold Crossed");
      if(State==0)
      {
        Start_Time=millis();
      }
      State++;
      while(analogRead(A0)); //I DON'T UNDERSTAND THIS
    }
  }

End_Time=millis();

Period=(Start_Time-End_Time)/5;
Frequency=1000/(Start_Time-End_Time)
Serial.println(Frequency);

State=0;
}

print the value of analogRead(A0) ... that will tell you when it exits the while loop

Can you fix the indentation of the code?

Re "A sine wave is being fed to A0": What is its amplitude and DC offset? What is the output impedance of the signal generator (what kind of signal generator is it)? How is it coupled? AC coupled?

As you correctly note, while typically takes a bool as argument. However, mainly for historical reasons, C/C++ don't really differentiate between int and bool, and therefore conditions can be of integer type. Any condition, be it in a while or an if, can be of int type. The condition evaluates to true if it is not zero. So the condition while(analogRead(A0)); loops (doing nothing) until analogRead returns 0.

I think I get this now, this line just works as some sort of delay. Without while(analogRead(A0)), just after the first threshold is crossed (say val is now 202), state becomes +1 and the program loops to "val=analogRead(A0)" again. The val is now 210, so state will get incremented again.........and until state>5, val probably reaches upto 250. This will certainly give the wrong time period. On the other hand while(analogRead(A0)) keeps looping until false (0), gives enough time for val to cross threshold and then become less than threshold, so that the crossing can be detected again. Thanks!

@Nawaz Not a delay, rather a “keep checking the value until it’s what I’m looking for”. It has nothing to do with time, but value.

Yes, but analogRead() may never return identical 0 (an offset of 20 mV would prevent it). Or only occasionally due to random noise. This is the equivalent to comparing floats with fixed values. Perhaps address that in your answer?

What you have implemented, perhaps unknowingly, is called
hysteresis. Your program spends most of its time in either of these
two states:

It is continually running the outer while loop, and the value read
is ≤ 200. It gets out of this state as soon as it reads a value
larger than 200.
It is continually running the inner while loop, and the value read
is > 0. It gets out of this state only when analogRead()
returns zero.

Hysteresis is a good way to reject noise when you want to detect a
signal crossing a threshold. I would, however, recommend you use it in a
more controlled manner. Specifically, the second threshold should
probably be greater than zero, otherwise it won't be crossed unless the
signal goes all the way down to ground level. At a minimum, you can
replace the inner while loop with something like:
while (analogRead(A0) >= 100)
    /* wait until the signal gets low enough */;

For the record, this logic can be implemented in a non-blocking
fashion, which would let the program do other things, like responding to
button presses, while waiting for the transitions. For this, you need a
variable to record the current state of the signal (say, LOW or
HIGH) and record the state changes when the corresponding thresholds
are crossed.
The sketch below implements this non-blocking technique in loop(),
whereas setup() does block while waiting for the first LOW → HIGH
transition:
const int LOW_THRESHOLD  = 100;
const int HIGH_THRESHOLD = 200;

uint8_t state;      // either LOW or HIGH
uint8_t count = 0;  // count the LOW -> HIGH transitions
uint32_t start_time;

void setup() {
    // Wait for the first LOW -> HIGH transition.
    while (analogRead(A0) >= LOW_THRESHOLD)
        /* Wait for the LOW state. */;
    while (analogRead(A0) < HIGH_THRESHOLD)
        /* Wait for the HIGH state. */;
    state = HIGH;

    // Record transition time.
    start_time = millis();
}

void loop() {
    // Record transitions.
    uint8_t val = analogRead(A0);
    if (state == HIGH && val < LOW_THRESHOLD) {
        state = LOW;
    } else if (state == LOW && val >= HIGH_THRESHOLD) {
        state = HIGH;
        ++count;
    }

    if (count >= 5) {
        // Report measured frequency.
        uint32_t end_time = millis();
        int frequency = 1000 * count / (end_time - start_time);
        Serial.println(frequency);

        // Prepare for the next round.
        start_time = end_time;
        count = 0;
    }
}

Re "Specifically, the second threshold should probably be greater than zero, otherwise it won't be crossed unless the signal goes all the way down to ground level.". Indeed. And perhaps add a more general statement about comparing for equality (with fixed values) for such ADC output (noise, rate of change of the input signal, etc.)?

@PeterMortensen: This is generally quite relevant. However, the reasons why one should normally not compare an ADC value for equality do not quite apply to the special case of comparing to zero.


text:
Can't stop the 3 pin active buzzer
I was simply trying to program a buzzer with the ultrasonic HC SR04 and 128x64 OLED display. The buzzer is an active buzzer (3 pin) on a small board. The problem is that, once on, it never stops buzzing. I have used the following code which is working fine except the buzzer.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define trigPin 9
#define echoPin 8
int buzzer = 12;//the pin of the active buzzer
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
display.clearDisplay();

}

void loop() {
float duration;
float distance_cm;
float distance_in;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance_cm = (duration/2) / 29.1;
//distance_in = (duration/2) / 73.914;

display.setCursor(30,0); //oled display
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Distance");

display.setCursor(30,10); //oled display
display.setTextSize(1);
display.setTextColor(WHITE);

if(distance_cm<2.9)
 {
      noTone(buzzer);
      display.println("Too Close");

  }
else if(distance_cm>30)
 {
      noTone(buzzer);
      display.println("Out of Range");

  }
else if(distance_cm>2.9 && distance_cm<3.5 )
{

display.println(distance_cm);
display.setCursor(80,10);
display.setTextSize(1);
display.println("cm");
display.setCursor(30,20); //oled display
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Reading Data");
tone(buzzer,329);
delay(20);
noTone(buzzer);
}

else
{
 noTone(buzzer);
 display.println("Too Far");

}

display.display();

delay(500);
display.clearDisplay();
Serial.println(distance_cm);

}

I am a beginner in Arduino programming ( Although have basic knowledge in C and python). You can make any optimization of this code if you feel so. Please help.

Comments are not for extended discussion; this conversation has been moved to chat.

Temporarily solved by replacing the active buzzer with a 2 pin passive buzzer. the behavior of the active buzzer remained mysterious to me.

often they are high to silence.


text:
Arduino MP3 Player
I want to make a MP3 player with arduino. My problem is what board should I use? There is the SparkFun MP3 Player Shield, SparkFun Audio-Sound Breakout - WTV020SD. Then I want to attach a 2.8 TFT touch screen to control volume,change track etc. Can I attach it to for example on top of MP3 player shield?I'm thinking in this one https://www.adafruit.com/products/1651. And finally what speakers can I use with which board? I want some good small speakers, two to be exact.
I don't really need help with electronics and programming. Just need to know wich are the best components that can work with each other without spending a lot of money. Thank you.
Best Regards

If you don't need help with electronics then you'll already know that you should be reading datasheets and schematics.

I would recommend you do not use speakers but instead send the output to a 3.5mm stereo plug, so you can use headphones or speakers.
Is a 2.8" inch display really necessary?  You could probably get away with a 1" display and at a guess that would use less power.
Another idea may be to look at a Bluetooth interface for sending the sound to the headphones or speakers.
You could also look at a WIFI interface to provide additional control interface and to allow downloads straight to the device.  (ESP8266 would probably be the easiest interface).
Something you didn't mention was the power source.  Are you going to have internal batteries with a USB charging and power socket, so you can hook it to a PC or Batter Pack.

I would recommend you the VS1003 chip ($2.30 on ebay) or module ($7 on ebay). It can play MP3, WMA, MIDI, WAV and can record and encode ADPCM. It's even programmable (own filters etc). See this project.


text:
Lighting up LED lights on Arduino tank using Arduino transmitter
I am making an Arduino tank using the motor shield, more of a recon tank as it has no gun. And I'm using one Arduino board as the receiver and controller of the tank and the other as the transmitter. I'm thinking of adding lights to the build and want to remotely operated them. I don't know where to look at or start. Can someone help me?

I'm voting to close this question as off-topic because we are not a free code writing service.

I am very sorry gre_gor I didn't know that you would take this the wrong way. I am just new to this Arduino thing and wanted since guidance. If you wish, I will delete this question

You said, "Can someone just send me the code".  So I don't think he took that wrongly.  We are not a free code writing service.

@Ronitbal - Change the last line of you question to "I don't know how to start, please can some one tell what I need to look at?" and people should be OK with it.

Well, Im going to see your question with good eyes and help you out giving you the properly guidance. With no sarcasm.
First of all you just would do some google searchs using the correct words.
To achieve the correct words you need to enumerate important things just doing the following quastions.
What do I have?
Arduino, Led

What do I want?
Controlling Led Remotely

So with these couple of question I could achieve the following sentence:
controlling led arduino remotely

This gave me the following good and usefull link with source code:
http://www.instructables.com/id/Arduino-Control-LEDs-with-a-Remote-Control/
Now you can improve your serach and come back here, bringing us what you have done so far with a far more accurated techinical question like:
What is the best way to controlling LED remotely in the given situation?

And go on.
The most important thing to know is how to separate requirements from impediments. I think now you are fair well introduced about how to use this very good resource.

Before you can operate LEDs remotely, do you know how to write a program to make a switch turn on a LED on the same board?  Then the next step is make the switch on board 1 turn on the light on board two.


text:
High-range obstacle detection system
I am making a high-range and fast obstacle detection system.
The HC-04 is too slow for that, other sensors don't have the range, and Lidar is too costly.
Any idea how to make a long range (more than 10 m) high-speed obstacle detection system?

https://www.adafruit.com/products/3316 isn't the range, but is probably a lot faster. I don't think there is a solution that fits all your requirements.

Thanx for the reply but the rank is too short .

Is the sensor to be put on a mobile device or could you use a light sensor and shine a laser into it from the other end and detect when the laser beam is broken?

You can Use PIR Sensor which is Cost Effective and covers upto 10 Meters

Thanx for reply, but they doesn’t really detect the presence of an object, but rather the motion
Offers no distance sensing capabilities
Does not detect stationary objects


text:
Arduino Uno + cc3000 breakout board - read DOM instead of HTML
Is there a way to make the CC3000 read the DOM of a website instead of the HTML on the file?
I'm using the WebClient file which works fine and prints the HTML of the webpage, but the website I'm trying to read from has its HTML different from its DOM (ie: Javascript modifies the HTML once the page loads).
Can I use something other than www.read()?

To get a (programatically changed) DOM you need an HTML parser to construct the initial DOM (and something that runs Javascript to modify it).
The server only sends a file and does not store or send a DOM; a DOM is built by the receiving application, usually a browser.

The DOM is something related to browsers. A web server merely serves up stored HTML and any accompanying JS to the client CC3000. It's up to a browser to parse the document, execute any JS to construct the DOM tree and finally render the webpage based on the DOM--not something an Arduino is built for.
I'm not an expert but you will have to forward the HTML from your Arduino to a browser and then somehow scrape the results after it renders the page. Or use a website that implements server-side rendering.


text:
Is it possible to preform VIO from two cameras/IMUs on a dual-core ESP32?
Like the title says, I want to take in the synchronised data from two NXP breakout boards and two Ueye 1220LE cameras, and use VIO to fuse their data and get positions for both setups.
A lot of people have suggested running things like SLAM, which is similar to VIO, on something stronger than an Arduino, some specifically suggested using a version of a Raspberry Pi.
Now, I know that Raspberry Pis are stronger than an ESP32, but ESP32s are stronger than Arduinos, and since Pis are more expensive than an ESP32s and I need WiFi capabilities, before I buy a Pi, I was wondering if it would be possible to perform this on my dual-core ESP32.
And if the Pi isn't overkill and I needed all the processing power I could get, what version should I use? The Zero? The 3.0? The 4.0? Do let me know.

I haven't worked with the ESP-32, but it seems to me you're quibbling over pennies. Pis are cheap and very powerful. They run Linux, so there are tons of open source libraries available for them. You could install OpenCV, for example, and do computer vision quite readily.
I'd recommend at least a PI 3.
If you used an ESP-32 based system, would you run it as an Android device? The Arduino "OS" (And that the term OS is quite a stretch) is really just a setup function and a run loop. You should use a device with a real OS, including a file system, etc.


text:
RFM95 digital io to control mute on PAM8403 to get rid of hiss while receiving
I am building a solution with an ESP32, a PAM8403 amp, a parallel TFT display, and a RFM95 LoRa module. All works great but I want to get rid of the noise that is generated when Lora is in receive mode.
I can do this by pulling pin 12 low on the PAM8403, which mutes all sound. However I have ran out of output pins on my ESP32, and it's too late to use a IO expander as the PCB has been built.
My initial idea was to use the RX/TX pins on the ESP32 when the unit was out of diagnostics mode. However if I can avoid this then that would be great. In my code when I issue Lora.sleep() / Lora.idle() the hissing goes away.
So I started to wonder if I could just trigger the mute function through another logic state that goes low when LoRa is idle and high when sleeping (allowing the mute to deactivate).
I am using the LoRa library by Sandeep Mistry, and I was wondering if I could use DIO1, DIO2, etc. as an IO PIN to control mute. If not, is it possible to use any of the already connected pins to behave in the desired way?
Thanks all in advance!

It looks like not. The DIO pins can be set to indicate specific events, none of which are sleep / idle.

Thanks @Majenko - would there be any events that can be spoofed from the user side (ESP32 / programatically) that would hold one of the pins Low? During the mute period I do not want to use the lora board, just use it to change states...

Actually what if I disconnect the reset pin and connect it to the ESP32, would this not free as PIN up? or are there issues down the road in not having a dedicated reset pin for the RFM95..

Yes, it looks like you could re-purpose reset. The library only uses that in begin() and there is a special case checking to see if the reset pin has been set to -1 in which case it ignores it. So you could tie nRESET to +3.3V and use your reset GPIO pin for another purpose if you use the setPins() function to change nRESET to -1.

Thanks @Majenko I knew there would be a way somewhere.... so I have my TFT Reset and capacitive touch Reset connected together. Should I connect the Reset for rfm to these or is there actually no need to have a reset connection? Or even the esp32 reset...

Reset can put things into a known good state, so it's handy to have. Sure, one big master reset to reset all your peripherals at startup is good. I'd avoid the ESP32's reset though as that is fiddled with when uploading code.

No, there is no way you can use the DIO pins to indicate sleep mode. They can only be set to indicate certain events, and sleep/idle is not one of them.
However the nRESET pin is optional, and you can use the setPins() function in the LoRa library to change which pin it's connected to - and one option is to set it to -1 in which case the library ignores it (this must be run before .begin() is called) as it's only used during begin() to initially reset the LoRa module.
You could either tie nRESET HIGH (to 3.3V) to never reset it, or couple it with the reset signal of another peripheral so it gets reset at the same time - just be careful with your initialisation order in this case so you don't reset the module after configuring it...

Ah good to know that’s what reset actually does. I have since implemented ad sound effects are now sound much better without the surrounding hiss.


text:
Static IP for ESP8266 based on gateway
I'm new to Arduino programming. I want to make my ESP8266 get a static IP address based on the gateway's IP address.
I mean if the gateway is at 192.168.0.1 then the ESP8266 should get 192.168.0.15 as a static IP address. And if the gateway is at 192.168.1.1 then it should get 192.168.1.15 as an IP address.

Isn't that the role of DHCP? Your Access Point / Router should be handing out that IP address. If you want it to be static then configure your router to allocate a static IP for the MAC address. If you're getting the gateway by DHCP then you will also be getting an IP through DHCP.

I'm wondering why you would want to do that. You run the risk of IP collissions and network problems that are hard to diagnose. I would not want such a device in my network ;-) A (Static) DHCP Address reservation is the mechanism you should be using.

You can either set the router to allocate a static IP address based on your ESP8266's MAC address, or go the DHCP-way first, read the gateway IP address you got, and then do a WiFi.config(), something roughly like this (untested):
WiFi.begin(ssid, password);
IPAddress ip = WiFi.gatewayIP();
IP[3] = 15;
IPAddress dns(8, 8, 8, 8);
WiFi.config(ip, WiFi.gatewayIP(), dns, WiFi.subnetMask());

It is a bit of a trick, and not pretty, and you don't get to set the DNS as provided by the DHCP, because there is no getDNS(), for some silly reason, hence the use of Google's DNS server.
Note that when doing this, you run the risk of setting the ESP8266's IP address to an address already taken by another device on the same router.

Here is the idea that I have not implemented yet.

Connect to the wifi and let the router assign the IP to it.
After getting the IP from the router save that IP to eeprom
Now next time you want to connect to the wifi use this code.

// Set your Static IP address
IPAddress local_IP(192, 168, 1, 184);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 1);

IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);   //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional

if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
  }

  // Connect to Wi-Fi network with SSID and password
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);

load the saved ip, gateWay and other information saved in the eeprom before passing to wifi.config function.


text:
The analog read is not giving the correct waveform as that of an oscilloscope
I have code that fetches analog input values from terminals A0, A1 and A2 of an Arduino Mega 2560. When I plot the data, it does not give the desired waveform.
The desired waveform is also measured with a the digital storage oscilloscope.
I was thinking to make use of an Arduino Mega 2560 as an oscilloscope that can have 16 channels, because the DSO has only 4 and for a project, I urgently need 16 channels. Would be great if the community people suggest something.

Below is the desired data from the oscilloscope that is measured in parallel to avoid any confusion about the circuit.

%This is a script that will plot Arduino analogRead values in real time
%Modified from http://billwaa.wordpress.com/2013/07/10/matlab-real-time-serial-data-logger/
%The code from that site takes data from Serial

clear all
close all
clc

%User Defined Properties
a = arduino('Com5')             % define the Arduino Communication port
arduino=serial('COM5','BaudRate',9600);
s1 = serial('COM5');                                                       % Define here YOUR serial port
s1.BaudRate=9600;

plotTitle = 'Arduino Data Log';  % plot title
xLabel = 'Time (s)';     % x-axis label
yLabel = 'Voltage (V)';      % y-axis label
legend1 = 'Voltage 1'
legend2 = 'Voltage 2'
legend3 = 'Voltage 3'
yMax  = 5                           %y Maximum Value
yMin  = 0                       %y minimum Value
plotGrid = 'on';                 % 'off' to turn off grid
min = 0;                         % set y-min
max = 5;                        % set y-max
delay = .01;                     % make sure sample faster than resolution

%Define Function Variables
time = 0;
data = 0;
data1 = 0;
data2 = 0;
count = 0;

%Set up Plot
plotGraph = plot(time,data,'-r' )  % every AnalogRead needs to be on its own Plotgraph
hold on                            %hold on makes sure all of the channels are plotted
plotGraph1 = plot(time,data1,'-b')
plotGraph2 = plot(time, data2,'-g' )
title(plotTitle,'FontSize',15);
xlabel(xLabel,'FontSize',15);
ylabel(yLabel,'FontSize',15);
legend(legend1,legend2,legend3)
axis([yMin yMax min max]);
grid(plotGrid);

tic

while ishandle(plotGraph) %Loop when Plot is Active will run until plot is closed

%          dat = readVoltage(a,'A0')* 0.48875855327; %Data from the arduino
%          dat1 = readVoltage(a,'A1')* 0.48875855327;
%          dat2 = readVoltage(a,'A2')* 0.48875855327;

         dat = readVoltage(a,'A0')* 1; %Data from the arduino
         dat1 = readVoltage(a,'A1')* 1;
         dat2 = readVoltage(a,'A2')*1;

         count = count + 1;
         time(count) = toc;

         data(count) = dat(1);
         data1(count) = dat1(1)
         data2(count) = dat2(1)

         %This is the magic code
         %Using plot will slow down the sampling time.. At times to over 20
         %seconds per sample!
         set(plotGraph,'XData',time,'YData',data);
         set(plotGraph1,'XData',time,'YData',data1);
         set(plotGraph2,'XData',time,'YData',data2);

          axis([0 time(count) min max]);

          %Update the graph
          %pause(delay);
  end

delete(a);

disp('Plot Closed and arduino object has been deleted');`

What sketch are you using on the Arduino? Are you using something like Firmata? Where does the readVoltage() function come from? It isn't anywhere in the link, where you modified the code from. From your images it is obvious, that you are sampling way too slow for seeing the wave form.

You are trying to sample at ≈ 12 samp/s a waveform that is around 3 kHz. You must read about the Nyquist–Shannon sampling theorem.

why are you sampling 3 channels?  ... first determine if one channel can capture the data, then try two channels, etc.

Your sampling rate is far too low for the signals you are looking at; you're not getting enough data points for drawing something that looks like the original signal.
The Arduino library's analogRead(), while slow, can do better, up to about 9000 samples/s; the ADC in the atmega2560 in free-running mode can do about 75000 samples/s at 8 bits resolution. This would require programming it at the register level.
There is only one ADC, so if you want 16 channels, this leaves about 4700 samples/s for each channel. In that configuration, however, the first measurements aren't valid and the second ones should be used, further reducing the sample rate per channel to about 2300 samples/s.
With a perfect reconstruction filter, this would limit you to measuring signals up to only 1150 Hz.
All this doesn't even consider the time it takes to store or transmit the results.
So, an Arduino Mega 2560 will not do for making a usable 16-channel oscilloscope for your signals; it's not even close.


text:
Arduino Nano + RC522 + w5500 Ethernet Module
has anyone had any experience wiring up an arduino nano with an RC522 RFID module and a W5500 ethernet module? i can get each of them to work individually, but i cannot get them to work together. i am not super experienced, but this seems to be some sort of SPI collision
The RobotDyn Ethernet Module i am using:

The RFID Module i am using:

If both modules use SPI then they should each have a separate pin connected to the slave select.
This lets you select which module you are talking to every time you start a communication. If the modules are well behaved then its MISO pin will be in high impedance when it is not selected instead of pulling it low or high trying to send data.
If it is not well behaved then you will need to add a buffer.

thanks for your comment @ratchet-freak, it turned out the RC522 is not well behaved (as you indicated) and i have to set the SS pin HIGH before the Ethernet module would work properly


text:
6 V high-torque servo won't function with motor shield

I have only ever been able to get this servo to “somewhat” work when connected to the 5 V pin on the shield, the ground on the shield, and the signal line attached to whatever pin.
But 5 V is not enough and 9 V is too much. I'm trying a million different ways to power this thing, but I don't understand that when I give it an appropriate voltage from a source (while still having the signal line connected of course), it doesn't want to move at all.
Currently my Arduino is powered via USB. The shield/motor is powered from a 12 V, 2 A power supply, which with a simple voltage divider circuit gets me 6.29 V. The multimeter seems to show this works. Also the “Vin Connect” jumper on the back was cut to make the screw terminals a dedicated power line for the motor, as per the Arduino website. I tried this set-up without cutting the jumper too; same - no result.
Can anyone help me out? All I want to do is power my Arduino with the shield and motor, however that has to happen, and be able to run the "Servo Sweep" example code.
https://docs.arduino.cc/hardware/motor-shield-rev3
https://www.amazon.com/ANNIMOS-Digital-Voltage-Stainless-Waterproof/dp/B07KTSCN4J

Hints: ohms law, voltage divider without and with load (also take into account different modes of operation).  For example expected impedance when servo takes 2A ->  R = U/I = 6V/2A = 3Ohm. Your voltage divider ratio 2000 : 2.9955 ( (12V / 2002.9955) * 2.9955 = 17.9mV (if you just replace servo with "equivalent" resistor, not with real servo)

Voltage dividers make bad power supplies.
Basically, there is a 2 kΩ resistor between the power supply and the motor board. Assuming a 3 Ω resistance of the servo in parallel with the 2.2 kΩ resistor, the latter is negligible.
Maximum current through the servo will then be about I/R = 12/2000 = 6 mA, and the servo will see about 0.006 x 3 = 18 mV across it. The rest of the 12 V drops across the 2 kΩ resistor.

It may pay to think about current required as well as voltage. Looking at a data sheet I found online (data sheet link) it refers to a stall current of 3.5A when running at 6V.
What do you mean by “somewhat”? Can you give more detail on the behavior you see? It may be useful to hook your multimeter up as an ammeter to get an idea of whether current draw is approaching the limit of the wall plug (2A) used.

The gauge of wire and the power rating of the resistors used in the voltage divider will also impact the available current.

It would be useful to add photographs or a circuit diagram; as well as your code; and observed behavior to your question.

I’m not sure what function you’re expecting from the Motor shield? I believe it may be extraneous. My understanding is that you need connections of: 6V 4A supply + and - to servo. Shared ground and PWM signal from Arduino to servo, separate USB power to Arduino. Motor shield not required. Any comments from other readers?

Thank you for all your ideas. Yes perhaps the Amperage is the main culprit here. The wires are quite thin also, something that never occurred to me. - "a stall current of 3.5A when running at 6V" does this mean that I need more than 3.5A to move it at all? That makes sense to me EXCEPT the fact that it does perform a 180 degree sweep with the 5V onboard plugin, powered soley through USB. I would just naturally assume the USB does not have that kind of amps. When I say "somewhat" I mean, I can get it to move, but it lacks the advertised torque - by a lot. Can't lift nearly enough.

Stall current is the maximum current drawn, when the motor is applying its maximum torque, either because it is being prevented from moving entirely or because it can no longer accelerate given the load it is under. https://robotics.stackexchange.com/questions/613/what-is-stall-current-and-free-current-of-motors#:~:text=Short%20answer,the%20load%20it%20is%20under.


text:
ESP32 cam and MB code uploaded but nothing in Serial Monitor

The code works successfully but nothing happens in the serial monitor, what do I do as I've tried almost everything.

Your serial monitor's baud rate isn't set to 115200

No longer an issue.
Any fully released version of the 2.X IDE including the original 2.0.0 release should work. If you're having a problem these days it is probably because you've selected the wrong board causing problems as explained below.
At the time the original answer was given the 2.0-rc9.1 release candidate was current. IDE version 2.0-rc9.3 bundled arduino-cli version 0.27.0-rc.1 which contains code to make the relevant settings work. So every version form the official 2.0.0 release to current (version 2.1.1 as of this update).
Original Answer
In short, use the 1.X series IDE instead of the 2.X series IDE. As of writing, this would be IDE version 1.8.19.

In version 1.8.4 support for a board properties called .serial.disableDTR and .serial.disableRTS were added.
Certain boards, like the ESP32-CAM combined with the ESP32-CAM-MB require this feature in order for the Serial Monitor to see traffic (actually it's worse than that, which I'll explain below). The current 2.X series IDE (2.0-rc9.1 as of writing), which has a completely different code base, appears not to have re-implemented this feature. Presumably they will eventually.
When you install the 1.X series IDE, make sure you test the Serial Monitor with the ESP32-CAM selected. It may be counterintuitive that testing an Arduino UNO as your selected board wouldn't just work, given that you're only using the Serial Monitor and not actually compiling or uploading. But it will, no kidding, fail to work as this board's definition does not specify these .serial.disableDTR and .serial.disableRTS properties that the ESP32-CAM board description does.
In case you're wondering, ESP32 upload tool controls DTR and RTS itself irrespective of these board definition properties that affect the Serial Monitor and Serial Plotter. That's why your uploading works but your Serial Monitor fails under the current IDE 2.0 release candidate.
Without going into detail on what DTR and RTS are supposed to do, and what they can be made to do, etc, typical operating configurations for a serial port are such that when the port is open these signals are going to go active. The ESP32-CAM-MB board design is such that having both active DTR and RTS both active is effectively pushing down both the GPIO0 and rather crucially the EN/RESET buttons. In other words, without this additional fiddling that the 1.X series IDEs (with correct board selected) and esptool do, opening the serial port has the effect of holding your ESP32-CAM in reset (or NOT-enabling it if you like). So not only are you not getting any serial traffic, the board is simply not executing any code at all.

You have other options also, but each kind of requires an explanation in its own right. But, I can give you hints as to what they are:
It is possible to continue using the 2.0 IDE to do your development and upload but use something else instead of the 2.0 IDE's Serial Monitor. But it will introduce complexity, confusion, and annoyance into your setup. Whatever that "something else" is must allow for the disabling for DTR and RTS. Note that disabling DTR and RTS is not merely turning off flow control; that will not manipulate them and it will ignore their counterpart signals, but it will also leave them in the wrong state.  One candidate is IDE 1.x's Serial Monitor.  Another is RealTerm, which will allow you to clear DTR and RTS (in that order) to then work as a serial monitor. In any case you will need to close the serial connection yourself prior to each upload as the 2.0 IDE will be unable to do that on your behalf as it would normally do its own internal monitor.
You can also interrupt the DTR an RTS signals in hardware before the get to the ESP32-CAM board. Having done that, it no longer matters whether any software controls DTR and RTS, but you then need to manually operate GPIO0 and EN/RESET yourself to enter the bootloader. To accomplish that you'll either need to use a mess of jumpers and the ESP32-CAM-MB (or any other 3.3V serial transceiver) not mounted to the ESP32-CAM and construct push button circuits for GPIO0 and EN/RESET.  Alternately you can physically modify the ESP32-CAM-MB in a way that interrupts DTR and RTS from the transceiver but keeps operational buttons. This can be done by desoldering a pair of diodes or cutting the traces on the way to the buttons and headers.
It may also only take a few well placed lines in one of the 2.0 IDE's javascript/typescript to crudely hack in a disabling of DTR and RTS, if you don't care what else it breaks. If I get bored maybe I'll look into that. Doing it properly in response to the correct board properties is a more involved project though.

If you use the command line, you can use this command to open a serial console to the esp32:
arduino-cli monitor -p /dev/ttyUSB0 --discovery-timeout 60s --config 'rts=off' --config 'dtr=off' --config 'baudrate=115200'

If you use the IDE, see the answer of timemage.

My answer was out of date so I've added that this should be a non-issue in non-release candidate 2.X version IDEs.  With respect to ardunio-cli, if you're using 0.27.0-rc.1 onward, you should be able to specify esp32:esp32:esp32cam : whatever in --fqbn and that would make it so you didn't need the --config 'rts=off' --config 'dtr=off' options. But what you have should be good for dealing with old arduino-cli versions in any case.

I needed these parameters with the arduino-cli version 0.33. I have not tested 0.33.1 yet.

Odd. I've just tested with the 0.27.1 out of the 2.0.0 IDE package and it behaves in line with how I'd thought: arduino-cli monitor --port /dev/ttyUSB0 pulls RTS/RST low. Adding --fqbn esp32:esp32:esp32cam causes it not to do that per disableRTS. As does the --config options you've suggested without the --fqbn specified.  -cli version 0.32.3 out of the latest IDE 2.1.1 behaves the same way. I don't have your exact version. I'll keep it in mind though. Maybe I've missed something.

I'm using platformIO and had the same issue. Disabling the RTS and DTR solved my problem too!
monitor_dtr = 0
monitor_rts = 0

I've barely touched PlatformIO. I'm just guessing these go a project config file. It would be better if this were filled out a bit so that someone running across it had that guidance.


text:
SIM808 does not support SSL related AT commands

I am using a SIM808 module. It's working fine with normal MQTT over TCP, but does not work when trying secured MQTT.

I sent AT+SSLSETROOT="C:\USER\HENRY_SSL.CRT" to set the root certificate (see this document: "SIM800 Series_MQTT_Application Note_V1.03"). The response I'm getting from the GSM is: +CME ERROR: unknown.

When I try AT+SMSSL=1, I get the same error. I checked with HTTP commands and it's working fine, but the AT+HTTPSSL=1 command does not work. The SIM808 does not respond to SSL related commands.

But as per the Simcom website, the SIM808 does support SSL. Do I need to upgrade any firmware?

could you send me that firmware version (1418B05SIM808M32)? or could you tell me the site that you download it?
Also, is there any newer firmware now?

I updated the firmware version: 1418B05SIM808M32. Now all commands are working fine.

please send link of download firmware version: 1418B05SIM808M32


text:
HTTP POST maximum speed at command SIMCom A7672
I'm trying to build a device for my startup IoT-related, using an A7672S.
Here is the code:
mySerial.println("AT+HTTPINIT";
checkresponse("OK\r\n");

mySerial.println("AT+HTTPPARA=\"URL\",\"http://" + host + resources + "\"");
checkresponse("OK\r\n");

mySerial.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
checkresponse("OK\r\n");

String st = "AT+HTTPDATA=";
int pdl = postdata.length();
st += String(pdl);
st += ",15000";
mySerial.println(st);
checkresponse("DOWNLOAD");

mySerial.println(postdata);
checkresponse("OK\r\n");

mySerial.println("AT+HTTPACTION=1");
checkresponse("+HTTPACTION: 1,200");

if (BuildINString2.indexOf("+HTTPACTION: 1,200") != -1) {
  Serial.println("POST DONE");
} else
  Serial.print("ERROR POST: ");
  Serial.println(BuildINString2);
}

mySerial.println("AT+HTTPTERM");
checkresponse("OK\r\n");

// In the check function, we pass the check variable to check different possible responses of sim like ok, error, etc

void checkresponse(String check) {
  int start = millis();
  BuildINString2="";
  while (true) {
    if (mySerial.available() > 0) {
      inData =mySerial.read();
      BuildINString2 = BuildINString2 + char(inData);
    }

    if (BuildINString2.indexOf(check)! = -1) {
      delay(100);
      return;
    }

    if (millis()-start > 3000) {
      delay(100);
      Serial.println("SIM TIMEOUT");
      return;
    }
  }
}

How can we speed up the POST time? Because in my last module (SIM7600), I used CHTTPACTION which was POSTing in less than 500 ms, but on the A7672s, it's taking more than 1 s.
Can someone confirm possible issues or any other method for the fast posting of data?
Also, in this HTTP method, is HTTPTERM required for every POST or change in URL point or when it's required?

your code does not compile

It's unclear whether the part that you're asking about is the collection of statements (takes over a second to go over that loop) or whether a specific AT command you send takes over a second (from the MySerial.println to checkmyresponse return). You need to provide some more information for us to be able to help.

takes over a second to go over that loop ( i wrote Data was posting in 1 second in old simmodule, as old sim module - Sim7600 support Chttp action that simA7672 doesn't support so had to use normal HTTP command but not CHTTP so wondering ways to make posting faster if possible)


text:
STK8231 accelerometer, getting two axis (x & y data) but not z, also in 0-255
Here is the datasheet I followed: https://lcsc.com/product-detail/Motion-Sensors-Accelerometers_SENSORTEK-STK8321_C966924.html
We are trying the following code:
#include <Wire.h>

int ADXLAddress = 0x0F; // Device address in which is also included the 8th bit for selecting the mode, read in this case.

#define X_Axis_Register_DATAX0 0x03 // Hexadecima address for the DATAX0 internal register.
#define X_Axis_Register_DATAX1 0x02 // Hexadecima address for the DATAX1 internal register.

#define Y_Axis_Register_DATAX0 0x05 // Hexadecima address for the DATAX0 internal register.
#define Y_Axis_Register_DATAX1 0x04 // Hexadecima address for the DATAX0 internal register.

#define Z_Axis_Register_DATAX0 0x07 // Hexadecima address for the DATAX0 internal register.
#define Z_Axis_Register_DATAX1 0x06 // Hexadecima address for the DATAX0 internal register.

int X0, X1, X_out;
int Y0, Y1, Y_out;
int Z0, Z1, Z_out;

void setup() {
  Wire.begin(); // Initiate the Wire library
  Serial.begin(115200);
  Wire.beginTransmission(ADXLAddress);
  Wire.endTransmission();
}

void loop() {

  ArduinoOTA.handle();

  Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
  //Ask the particular registers for data
  Wire.write(X_Axis_Register_DATAX0);
  Wire.write(X_Axis_Register_DATAX1);
  Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers

  Wire.requestFrom(ADXLAddress, 2); // Request the transmitted two bytes from the two registers
  if (Wire.available() <= 2) { //
    X0 = Wire.read(); // Reads the data from the register
    X1 = Wire.read();
  }

  Serial.print("\n   X0= "); Serial.print(X0); Serial.print("         X1= "); Serial.print(X1);

  delay(100);

  Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
  Wire.write(Y_Axis_Register_DATAX0);
  Wire.write(Y_Axis_Register_DATAX1);
  Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers

  Wire.requestFrom(ADXLAddress, 2); // Request the transmitted two bytes from the two registers
  if (Wire.available() <= 2) { //
    Y0 = Wire.read(); // Reads the data from the register
    Y1 = Wire.read();
  }

  Serial.print("   Y0= "); Serial.print(Y0);  Serial.print("       Y1= "); Serial.print(Y1);

  delay(100);

  Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
  Wire.write(Z_Axis_Register_DATAX0);
  Wire.write(Z_Axis_Register_DATAX1);
  Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers

  Wire.requestFrom(ADXLAddress, 6); // Request the transmitted two bytes from the two registers
  if (Wire.available() <= 6) { //
    Z0 = Wire.read(); // Reads the data from the register
    Z1 = Wire.read();
  }

  Serial.print("    Z0= "); Serial.print(Z0); Serial.print("         Z1= ");  Serial.print(Z1);

  delay(200);
}

Please help us to get the final X, Y, and Z.
Raw values of X and Y are somewhat correct, but Z always shows - 0.
Also, we are not able to calculate correctly X, Y, and Z to get the final G-force value.
Main point of datasheet :

The acceleration data of STK8321 is 12 bits and is given in two's complement format. The MSB in each axis will be stored in register XOUT2/YOUT2/ZOUT2 (0x03, 0x05, 0x07) individually, and the LSB will be stored in register XOUT1/YOUT1/ZOUT1 (0x02, 0x04, 0x06) individually. The NEW_X/NEW_Y/NEW_Z bit in register XOUT1/YOUT1/ZOUT1 (0x02, 0x04, 0x06) is used for new data flag, and it will be set to 1 if the data is updated, and reset if either the corresponding MSB or LSB is read. Reading the acceleration data registers shall always start with the LSB part due to the data protection function. When data protection function is enabled, the content of an MSB register will be updated by reading the corresponding LSB register.

pls ignore OTA handle line , ArduinoOTA.handle();

why don't you remove it from the code listing instead of writing a comment about it?

if (Wire.available() <= 2) {X0 = Wire.read(); X1 = Wire.read();} typo here, I think (<= vs >=). Mirrored in other places in the code. I would fix them in the code in the question on the assumption that it is not actually just a typo you're encountering.

Thanks, guys, i the got correct values by shifting 4 bit left & 4 bit right of each axis for both frames


text:
Why 0 devices, but not 1?
I have found a sketch in Wokwi where a MAX7219 LED matrix is used. The sketch subject is to display 0 using <LedControl.h>. I don't understand why it's nessesary to send 0 unlike 1 in fourth parameter in library-object initialization.
LedControl(int dataPin, int clkPin, int csPin, int numDevices=1);
It seems it should be 1 there, but the sketch isn't working in that way.
#include <LedControl.h>

int DIN = 12;
int CS =  11;
int CLK = 10;
LedControl lc=LedControl(DIN,CLK,CS,0);

void setup(){
  lc.shutdown(0,false);
  lc.setIntensity(0,15);
}

void loop(){
  byte zero[8]= {0x00,0x1c,0x22,0x22,0x22,0x22,0x22,0x1c};
  printByte(zero);
}

void printByte(byte character []) {
  int i = 0;
  for (i=0;i<8;i++) {
    lc.setRow(0,i,character[i]);
  }
}

Yes, I agree 0 is not correct. On this page it says: "The fourth argument to LedControl(dataPin,clockPin,csPin,numDevices) is the number of cascaded MAX72XX devices ... only values between 1..8 are allowed here.".  Please add a link to the source of your code. Perhaps there is an explanation there why 0 was chosen.

https://wokwi.com/projects/373210641309244417
Here is that project.
It's working with 1.

On this page it says: "The fourth argument to LedControl(dataPin,clockPin,csPin,numDevices) is the number of cascaded MAX72XX devices ... only values between 1..8 are allowed here.".
Examining the LedControl source code at GITHUB, we see in file LedControl.cpp in function LedControl() code which checks for unexpected values for the number of MAX7219 LED Matrix devices used:
LedControl::LedControl(int dataPin, int clkPin, int csPin, int numDevices) {
...
  if(numDevices<=0 || numDevices>8 )
    numDevices=8;

We can see if the number is less than or equal to 0 or is greater than 8 the code defaults to 8 devices.  So when passing a 0 the code will detect an unexpected value and create 8 devices by default.

Thanks. Now it's clear.
Unfortunately, I don't understand why the project isn't working with 1 device.

Make sure you have the latest version of the LedControl code.  Check for updated in your Arduino IDE.

The problem was when I put 1 device in initialization and then in shutdown, setIntensity, setRow also used 1. But there must be 0, because it's the address of the 1 device.
Thank you so much for help


text:
Trying to use Serial to communicate between two D1 Mini's
I'm trying to connect two D1 Mini's together as a POC.
There is a switch on one and a 7 segment display on the other
I have the pins setup from TX>RX and RX>TX
First ESP8266:
int SWITCH_PIN = D5;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(SWITCH_PIN, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
}

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

  if(digitalRead(SWITCH_PIN) == HIGH)
  {
    Serial.println(1);
    digitalWrite(LED_BUILTIN, HIGH);
  }
  else
  {
    Serial.println(0);
    digitalWrite(LED_BUILTIN, LOW);
  }
}

Second ESP8266:
#include "DigitLedDisplay.h"
DigitLedDisplay ld = DigitLedDisplay(D6, D5, D0);

void setup() {

  Serial.begin(115200);

  ld.setBright(10);
  ld.setDigitLimit(8);

  for (long i = 0; i < 100; i++) {
    ld.printDigit(i);
    delay(25);
  }

}

void loop() {
  delay(1000);
  if(Serial.read() == 1)
  {
    ld.printDigit(11111111);
  }
  else if (Serial.read() == 0)
  {
    ld.printDigit(22222222);
  }
  else
  {
    ld.printDigit(33333333);
  }
}

As far as I can tell the second ESP8266 isn't getting anything from the first. What am I doing wrong?
Thanks in advance for the help

You forgot to ask a question.

updated with a questions now

Serial.println(1); sends '1', not 1, so use Serial.read() == '1'

Sigh...
Thanks for that
I actually get the correct data back sometimes, but the output seems to swap between correct and the "else" status constantly

Thanks to Juraj it was an easy fix
Missing quotes around the text and changing some code
void loop() {
  if (Serial.available() > 0)
  {
    // read the incoming byte:
    incomingByte = Serial.read();
  }
  if(incomingByte == '1')
  {
    ld.printDigit(11111111);
  }
  else if (incomingByte == '0')
  {
    ld.printDigit(22222222);
  }
}

adding "if (Serial.available() > 0)" works to make it only update when the serial buffer is full
The delay was also causing issues with where it was located so just removed that

this will ld.print every loop if incomingByte is '0' or '1'


text:
Can I support all these sensors? Will I have enough pins?
So i'm new to arduino and i'm working on a project that will require 3 modules/sensors.
I wanted to know, can all of the following modules work with the arduino mega 2560 that comes with this
touch display?
The other modules (apart from the touch display) would be:

Fingerprint scanner
9g servo

If its not possible, please tell me what hardware I would need to run all these sensors together. Thanks :D.

Yes, easily....

@Majenko Are you sure? because it seems like the display is taking all of the pins, especially the power supply ones.  Also, it says that the fingerprint scanner needs a 12v power supply but as far as im aware arduino can only output 5v

No, the display only uses a tiny handful of the pins. It only plugs into the "Uno" footprint area pins and leaves all the rest blank. You can use power pins for more than one device at a time. If you need a higher voltage power supply then you have to get a higher voltage power supply. That has nothing at all to do with the Arduino.

@Majenko Okay thanks! So all of the other digital pins that come with the mega2560 can be configured to whatever output/input i need?

For simple IO, yes. For analogue there are more than 6 analog inputs. For serial communications there are more UART pins that aren't used, etc.

@Majenko Thank you so much!

if you run out, you can add a nano or pro mini using two serial pins, then have it talk to 1+ sensors.


text:
Elegoo remote code program only running once
I want this program to receive multiple signals from the elegoo ir remote and produce different tones using the passive buzzer. I have attempted to add onto the basic example provided by adding a makeSound() function.
The serial monitor outputs different values for a button if I hit it multiple times. Is there a way to make it so that each button will give a consistent value so I can keep the pitch the same for each button?
#include "IRremote.h"
#include "IR.h"
#include "pitches.h"

IRrecv irrecv(RECEIVER);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

void setup() {
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode");
  irrecv.enableIRIn();
}

void loop()
{
  int tmpValue;
  if (irrecv.decode(&results)) // have we received an IR signal?
  {
        tmpValue = results.value;
        Serial.println(tmpValue);
        makeSound(tmpValue);
    }
    irrecv.resume(); // receive the next value
  }

void makeSound(int tmpValue) {
Serial.println(tmpValue);

  if (tmpValue > 0) {
    Serial.println("In if statement");
    tone(8, NOTE_D5);
    delay(500);
    noTone(8);
  }
  if (tmpValue < 0) {
    Serial.println("In if statement");
    tone(8, NOTE_G1);
    delay(500);
    noTone(8);
  }

}

If you separate out the problem into having something to do with the remote code or the tone code, you remove the other from the question and you're more likely to get useful help.

simplify the code ... receive data and print it ... nothing more ... do not decode ... do not activate buzzer ... when that works as expected, then decode


text:
Is it possible to program Arduino UNO with USB/TTL adapter withouth connection Vcc
For some strange reason my Arduino UNO clone board occasionally cause my Mac to reset, when I connect the usb cable. Possibly a power problem in Arduino or the USB hub.
Is it possible to program Arduino UNO with USB/TTL adaptor withouth conncecting the Vcc and GND pins (RX/TX and DTR only.)

Which Mac do you have? I'm pretty sure recent Macs have protection on the USB ports - I recently got an error message when I had accidentally shorted Vcc and gnd on an uno. My laptop (2014 15" rMBP running Yosemite) shut off the USB port until I reconnected the USB cable (after fixing the short, of course).

It is an iMac 21.5" late 2013

Is it possible to program Arduino UNO with USB/TTL adaptor without connecting the Vcc and GND pins (RX/TX and DTR only.)

No.
As a minimum you need to add ground as well - even if the Mac is battery powered.  Serial port signals are ground referenced so removing the ground would prevent operation.
Operation is possible without deriving Vcc from the USB port, but you will then need to derive Vcc from some other source.
If connecting ground alone causes your Mac to reset you have a serious system problem which may damage your Mac and which possibly may be dangerous to you.
Presumably you are NOT using an external power supply for the UNO.
In case you are: If the power supply for the UNO is AC mains powered it should be connected to the same mains outlet as the Mac. If the programmer powerpack is intended to be grounded but is not powered from a grounded socket AND using a 3 wire mains lead (ie with a ground pin and wire) then it s possible in some cases for the programmer to float at half mains voltage with a high impedance capacitive connection to mains. This is not usually dangerous to people but can cause minor nuisance shocks. It can destroy equipment (ask me how I know :-( .)
If you have a DMM (digital multimeter) set it to an AC voltage range greater than your local mains voltage and measure the AC voltage from a known ground (such as a water tap in most cases) and the programmer power supply (either wire or jack terminal). If you measure a voltage of about 50VAC with 100 VAC mains or about 115 VAC with 230 VAC mains then the power supply MUST be operated with a 3 wire mains cord and grounded power socket OR a ground lead from mains ground to power supply output ground.
If the Mac is battery powered and you have reset problems then something is wrong with connections or signal levels. You may be feeding voltage back onto the USB lines or loading the too heavily or ... ?

It is a bit of work, but it is possible to use a couple of optoisolators to build a circuit that will electrically isolate the MCU from the serial adapter.

You should still figure out why your computer resets though, as it may not be related to the Arduino at all (e.g. maybe the cable is bad).

It's possible the reboot isn't a hardware issue, short circuiting, but some kind of operating system issue such as a faulty driver, or conflicts... Best to have a look at the Console after a reboot to see if there are any notes here, or try the same Arduino on another Mac or PC.

When I check the panic report, last loaded kext is always wch.usb so I assume the problem is caused by this driver.

At this point you probably want to look at Apple Support, or a fresh reinstall of the OS and then reimporting your data from a Time Machine backup.

If you power the board with an external source of electricity (e.g. a battery), it's possible. But as it can force your Mac to reset, it will possibly damage your battery.

At first, I though it was a power problem, like you.  But now I'm pretty sure the problem is caused by the CH340G driver. When I check the panic report, last loaded kext is always wch.usb.


text:
Simple LED circuit is not working
This is my first circuit ever (!) and so I'm hoping that I'm just making an easy-to-spot rookie mistake. I am trying to power an Arduino Due with a 9V battery and then have the Due in turn power a red LED. No blinking. No sketchpad/C program flashed to the chip. Just straight up electricity:

When I connect the battery, several things happen:

There is a green power LED on the Due that lights up; and
Right next to it is an orange LED (on the Due itself) that blinks every few seconds (not sure what this LED is or what the blinking means, but providing that detail for good measure); and
The red LED on the breadboarrd does not light up

This is a 2V/15mA LED, and as you can see I'm powering it from the 5V power jack on the Due. So a 220 ohm resistor should be perfect for it (R = (Vs - V) / I = (5V-2V) / .015A ~= 220 ohms).
So, for the first time ever, I busted out my multimeter, set it to the voltage setting, and started testing the circuit. First I tested Vin and GND on the Due (that is, the connection between the battery and the Due), and the multimeter lit up and hovered (correctly) around 5V. So far so good. Next I tested the power and ground connections on the breadboard power rails (indicated in green above). Again, the multimeter reported a roughly 5V power supply. Then I tested the connection from the power rail to the row (purple in pic above) feeding power to the resistor, and to my surprise, the multimeter reports no power at those two purple locations.
My understanding was that the power rail will power the entire column its connected to (in my case, the left-most column), and then any rows connecting to a power rail/column will also be powered. So I'm not understanding why there's voltage on my power rail/column, but not on the wire connecting my power rail to the resistor. Any ideas?

Update:
Here is my corrected circuit per initial feedback. Please note this is still not working, but I think I'm getting close:

The LED is shorted out - both leads are connected together - as shown here

What connects the resistor to the LED?

Absolutely nothing.
It's hard to work out which holes the LED is plugged into, but I think your current circuit looks something like this:

You need to connect that resistor and LED together.
For your edit:
Now your circuit looks like this:

Behind the 5 pins in that column with the ground wire there is a big chunk of metal connecting them all together.  It's no different to if you'd taken the LED and twisted the pins together into one.  There's no way the power can get up one and down the other when they are connected together like that.  You need to separate them into different columns.
And this is how the (black) connections inside are laid out, and how your (red) electricity is flowing:

And here is how the circuit should look, using a program called Fritzing.  It's a pretty basic design tool, but great for showing wiring.

You can see how the green highlighting shows the columns that are connected.

Thanks @Majenko (+1) - please see my update a new pic. I did my best to follow your advice but the LED is still not lighting up. I think I'm closer but I'm still missing something. In that 2nd picture, you'll notice that I've placed the LED and the wire going back to the GND rail on the same row as the resistor's "cathode" end. Any ideas where I'm going awry now? Thanks again!

I have edited my answer to cover your edit.

I totally get it now, makes perfect sense! Thanks again!

Glad you have it :)  I've added another picture and comment to my answer. You might like to check out the software "Fritzing" (free) which I used to draw it. It can be a big help when learning.

Oh,and your next exersize... move the +5V connection wire from the +5V pin on the Arduino and connect it to pin 13 instead - you'll then see the LED blinking at the same time as the one on the Arduino.

I can see I should have put my "The LED is shorted" comment 1st and then edited the picture :)

@RussellMcMahon Heh :)

It looks like you've got confused between columns and rows.
You are correct that the power rails run the length of the breadboard -- these are seen as the top and bottom pairs of rows in the diagram below (ignore the middle row). However, the rest of the board is connected up as separate columns. Each column is independent of its adjacent columns.

This means your red wire going from the power rail to the resistor is connected correctly. However, the other end of your resistor is currently going nowhere. It needs to be in the same column as the anode of your LED.

Thanks @Peter R. Bloomfield (+1) - so I don't think it's that I'm misunderstanding how the breadboard is organized (as columns and rows), perhaps I'm so new to electricity that I'm just misunderstanding the very flow of power itself! Let's call the two rows that the resistor is "living on" the resistor anode row and resistor cathode row, respectively (although I understand resistors have no polarity). So you're saying that I have the resistor anode row wired correctly, meaning I am correctly powering the resistor from the power rail...

However, you are then saying that the resistor cathode row is "going nowhere". I would have expected the voltage/power coming into the resistor (via the anode row) to provide power to the resistor cathode row. Is this not the case?!? In any respect, how should I be wiring the resistor and the LED so that the circuit is correct? Perhaps once I see how it should look, everything will make sense to me. Thanks again!

Also @Peter R. Bloomfield please see my update and my comment underneath Majenko's answer - I have the same question for you!

@smeeb The line which your resistor anode is on is not connected to the line the resistor cathode is on (except by the resistor itself). That's vital because the power has to flow into a component and then out. If they were connected by the breadboard itself then virtually no power would go through the resistor (electricity always takes the path of least resistance).

@smeeb In your updated image, that's exactly the problem. Your LED anode and cathode are on the same column, so they're directly connected to each other by the breadboard. That means the electricity won't flow through your LED at all. The LED's anode and cathode need to be on different rows.

@smeeb Here's an example of a similar circuit which may help you: http://apps.usd.edu/coglab/psyc770/images/bboard-circuit-653x425.jpg


text:
What is the minimum value for ESP.deepSleep(n)?
I noticed that when calling ESP.deepSleep(1), the ESP8266 sometimes does not wake. Why am I entering such a low value? I want to sleep for the minimum amount of time so that I can restart with WiFi back on using WAKE_RF_DEFAULT (I previously turned it off with WAKE_RF_DISABLED to save power).
I believe that a value of 0 will permanently sleep, but a value of 1 seems to make it sleep unreliably.
To solve this, I used ESP.deepSleep(1e6) (1 second), but I was curious to know if there was a known minimum value.

so, as you've discovered, 1 is too low ... have you tried 2? :p

Haha, no, I had the initial thought of slowly working my way up, but I would have no idea of knowing if it worked by a fluke or not. A value of 1 seems to work in some cases, but not in others. Would be interesting to learn why! :)

If the ESP32;s sleep feature is similar to an ESP8266, it is just an internally generated pulse that goes out one pin and into the wake-up pin.  Maybe the implementation is such that setting a delay of 1 doesn't always give the software enough time to setup the processor to wake up after entering sleep mode. My guess is that setting it to 2 will almost if not always work.  But keep in mind the ESP8266 wake up pulse varies a lot with temperature.  So it may be prudent to pick an even longer delay like 4 or 5.

@st2000 Sounds logical, thanks for the insight!


text:
ATtiny85 (Digispark) with 433mhz RF transmitter not working
I have the following components:

ATtiny85 Digispark
433mhz Mini Low Power RF Transmitter

I got a communication flow transmit/receive working between two Wemos D1 and like to outsource the transmitting part now to a ATtiny85. I used the same code as for the Wemos:
#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  pinMode(1, OUTPUT);
  mySwitch.enableTransmit(2);
}

void loop() {
    mySwitch.send("000110110001010100010001");
    digitalWrite(1, HIGH);
    delay(250);
    digitalWrite(1, LOW);
    delay(250);
}

But the serial monitor for the Wemos does not receive any communication. I went so far that I built up the communication between the two Wemos again and connected only the data pin of the transmitter to the ATtiny85 in order to exclude any voltage problems (ATtiny gets 5V, transmitter likes <3.6V).
Now I am out of ideas. How can I debug the problem or what else can I try?
Requested setup:

And your ATtiny runs at 8MHz, while the Wemos runs at 80 or 160MHz? What are the used supply and logic voltages? The seller page says you should use 2.0-3.6V for the transmitter. Does the transmitter still work when you re-attach it to a Wemos? IMHO the next low-level debugging step (after checking voltages) would be use a logic-analyzer to compare the timing diagrams for the TX pin between the boards, as these are timing-ciritcal in the microsecond range (https://github.com/sui77/rc-switch/blob/master/RCSwitch.cpp#L523)

@MaximilianGerhardt The ATtiny runs on 16.5Mhz and Wemos on 80Mhz. Didn't know that it is critical to have the same timing - how do I do that? The transmitter is working fine (i power it by the second wemos and only connect the data pin to the ATtiny)

Timing analysis would be done with a logic analyzer (e.g. salae logic clone, extremely cheap, https://www.youtube.com/watch?v=rR5cEFRO9_s). So even if you feed 5V I/O Levels to the transmitter from the ATTiny but use the 3.3V supply from the weemos (and common GND I suppose) it works? Can you edit your question to include the working Wemos and non-working ATTiny circuits (with power supplies included)?

Nice to see it resolved, you should mark your answer as correct. Side note: Your right circuit is wrong in the sense that you don't have common ground between them. It might be just by chance that your two power supplies (if they come from the same computer, e.g.) have the same GND, but in general these can be at different potentials;the "3.3V" with respect to the GND of the 1st power supply might be a compeletly different voltage with respect to the GND of the 2nd pow.supply. That's why you should connect the GNDs of the power supplies together (https://www.youtube.com/watch?v=vhZQbFeEfPM)

But it seems like the transmitter just didn't like 5V I/O levels (as the datasheet said), which you have successfully resolved by making your ATTiny run on 3.3V. Another solution would be to add a level shifter (example) from 5V to 3.3V, but you'd still need a 3.3V supply for the transmitter. So I think you're overall better off with running on 3.3V entirely.

@MaximilianGerhardt I need to wait one day to mark it as resolved ;)

I got it to work. The last comment of @Maximilian Gerhardt about I/O output got me thinking and I read up on it. So if I use 5V to power the ATtiny the I/O output voltage representation for 1 and 0 are significantly higher then with 3.3V. So now I underclocked the ATtiny to 8Mhz in order to use a 3.3V power supply. This way the I/O output matches the transmitters expectations. Now the communication is working.
Thanks for your help Max!


text:
What image formats are accepted for displays?
Sorry if there is information missing, im new to the topic.
I have an ESP32 connected to a Waveshare 7,5" RWB display, and i can display images by converting them to .xbm and including the hex code in the sketch.
So far, so good.
But heres my question: What exactly are the requirements? Because when looking at the .xbm image code, i see that its a pattern like this:
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00
But when i used a python script
import binascii
filename = 'test.png'
with open(filename, 'rb') as f:
    content = f.read()
print(binascii.hexlify(content))

to convert an image to hex code, i got this:
b'89504e470d0a1a0a0000000d4948445200000280000001800802000000b2...'(continues for thousands of characters, didnt want to paste all of that here
However, when trying to run the sketch that successfully displayed the first hex code with the second image code, i got this error(cut out the big string clutter again):
...0000000049454e44ae426082};

^

C:\Users\Administrator\Desktop\SPI_test_example\SPI_test_example.ino: In function 'void loop()':

SPI_test_example:167:21: error: 'showBitmapExample' was not declared in this scope

   showBitmapExample();

                     ^

SPI_test_example:171:51: error: 'showFont' was not declared in this scope

   showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);

                                                   ^

exit status 1
'showBitmapExample' was not declared in this scope

So, i would like to know - does the image code have to have exactly the format i mentioned first? This is very important for me because i want to automate the process from inputting any image to using the resulting code to feed the display.
Thanks in advance!
EDIT: As far as my understanding goes, both formats are the same data, just that the first one is displaying a white pixel as 0xFF,0xFF,0xFF and the second one as FFFFFF.

This is not a question of image format but of what format c accepts data in.
What you have is a python representation of binary data in hexadecimal encoding. That can only be used with python.
C represents hexadecimal values by prefixing them with 0x.
You will have to change your python code to output each byte individually and prefix it with 0x and separate each one with a comma. That can then be wrapped in an array structure.

This makes so much sense, i didnt expect it to be bound to programming language! Converting should be easily doable - that leaves a few questions open for me:
First, why does gimp, or rather the .xbm file, use C++ syntax (0x00)? Second, isnt one colored pixel displayed with 6 digits(000000 Black, FFFFFF White etc.) - how can i possible display the same range of colors with just 0x00?

It's all just numbers.  0xFFFFFF is the same as 0xFF, 0xFF, 0xFF.  Three bytes is all 0xFFFFFF is. That is, 0xFF red, 0xFF green and 0xFF blue.  An XBM file is a piece of C source code. Other formats aren't. If yuo save a file as XBM you get C source code.


text:
How to slowly change direction of the stepper motor with AccelStepper?
I know that direction can be changed with
.setSpeed(speed);
... //check input
.setSpeed(-speed);

I need to slowly decelerate and accelerate backwards, so I have to use
.setAcceleration(200);
...
.setMaxSpeed(speed);
... //check input
.setMaxSpeed(-speed);

but documentation told that .setMaxSpeed argument Must be > 0.
So how to properly change direction with deceleration? Probably I have to use .moveTo with some very big values

have you looked at the example code that is included with the library?

The library defines speed as steps per second. It doesn't care about the direction the steps are in. Just like you can't get out of a speeding tickets by always driving in reverse ;-).

I have tested it on real motor, and it works as I want with function .moveTo . Speed slowly changed from +maxSpeed to -maxSpeed acording to Acceleration
#define maxSpeed 1000
#define Acceleration 500
............
void setup(){
  stepper.setMaxSpeed(maxSpeed);
  stepper.setAcceleration(Acceleration);
}
void loop() {
 ............
 if(bDirection!=bDirection_last)
 {
  stepper.moveTo(bDirection?6000000:-6000000);
  ...........
 }
 stepper.run();
}


text:
Issue with uploading Arduino sketch on Ubuntu 20.04
I'm encountering an issue while attempting to upload an Arduino sketch on my Ubuntu 20.04 system. Despite ensuring that the correct board is selected and the USB port is recognized properly, I consistently encounter the following error message:
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Failed uploading: uploading error: exit status 1

I have tried various troubleshooting steps, including changing the board, reinstalling the IDE, and resetting the settings, but none of them have resolved the issue.
Could anyone please provide guidance on how to troubleshoot and resolve this problem? Any assistance would be greatly appreciated.

Which Arduino model do you use?

When I have this problem, holding down reset on the board until uploading starts often works