text:
Too few arguments for multiple if statement conditions
I am using the Arduino Uno.  I am attempting to only light a red LED when both a blue LED is on and the push button is pressed.  However, I keep receiving an error message stating too few arguments in my if statement.  I don't know whether I am simply overlooking something in my code.
The code is as follows:
int redLEDPin=7;
int blueLEDPin=3;
int redLEDOn=2000;
int redLEDOff=1000;
int blueLEDOn=2000;
int blueLEDOff=1000;
int leverR=2;

void setup() {
    pinMode(redLEDPin, OUTPUT);
    pinMode(blueLEDPin, OUTPUT);
    pinMode(leverR, INPUT);
    }

void loop() {
    digitalWrite(blueLEDPin, HIGH);
    delay(blueLEDOn);
    digitalWrite(blueLEDPin, LOW);
    delay(blueLEDOff);
    }

  if ((digitalWrite(blueLEDPin) == HIGH) && (digitalRead(leverR) == HIGH)) {
    digitalWrite(redLEDPin, HIGH);
    delay(redLEDOn);
    digitalWrite(redLEDPin, LOW);
    delay(redLEDOff);
    }
  else
  {
    digitalWrite(redLEDPin, LOW);
  }
}

Please include the complete error message in your question.

In function 'void loop()':
24:31: error: too few arguments to function 'void digitalWrite(uint8_t, uint8_t)'

I get the following error: testSE:22: error: expected unqualified-id before 'if'. Please include the error that you are getting (copy and paste it). There's an extraneous } just before your if

The digitalWrite statement in the if statement needs a value to write. It looks like you meant digitalRead, since you're comparing the result to something and the other condition is a digitalRead.
 if ((digitalWrite(blueLEDPin) == HIGH) && (digitalRead(leverR) == HIGH)) {

vs
 if ((digitalRead(blueLEDPin) == HIGH)  && (digitalRead(leverR) == HIGH)) {

I want the arduino to cause the blue LED to blink.  Only when it blinks and the button is pressed will the red LED be activated.  I think that means I need a digitalWrite for the blueLEDPin and a digitalRead for the leverR

Either way, digitalWrite needs 2 parameters: one for the pin and one for the value. digitalWrite also does not return anything so you can't test if it's equal to something.

So would I be able to set another arduino pin as an input channel that corresponds to the output produced by the blue LED?

This is your loop() function:
void loop() {
    digitalWrite(blueLEDPin, HIGH);
    delay(blueLEDOn);
    digitalWrite(blueLEDPin, LOW);
    delay(blueLEDOff);
    }

Your if() statement is outside of your loop. Check your brackets. In the Arduino IDE, if you put your cursor to the right of a bracket, it will highlight which bracket corresponds to that one.
Large Edit:
To blink two LEDs concurrently, you need to get rid of the delays. Please read about using the millis() function: https://learn.adafruit.com/multi-tasking-the-arduino-part-1/using-millis-for-timing
I don't know how to explain this succinctly, so I am providing the code (note that the on and off times for the LEDs are equal -- if you want them on longer than they are off, you can work on that part of it):
int redLEDPin=7;
int blueLEDPin=3;
int redLEDOn=2000;  //not used
int redLEDOff=250;
int blueLEDOn=2000;
int blueLEDOff=1000;  //not used
int leverR=2;

// the following variables are needed for timing and tracking LED state:
long previousMillisBlue = 0;
long previousMillisRed = 0;
bool ledStateBlue = LOW;
bool ledStateRed = LOW;

void setup() {
    pinMode(redLEDPin, OUTPUT);
    pinMode(blueLEDPin, OUTPUT);
    pinMode(leverR, INPUT_PULLUP); //I am using internal pullup resistor
}

void loop() {
    unsigned long currentMillis = millis();

    if(currentMillis - previousMillisBlue > blueLEDOn)
    {
      previousMillisBlue = currentMillis;

      if (ledStateBlue == LOW)
        {ledStateBlue = HIGH;}
      else
        {ledStateBlue = LOW;}

      digitalWrite(blueLEDPin, ledStateBlue);
    }

    //since we are tracking ledStateBlue above, we can reference it here
    if(digitalRead(leverR) == HIGH && ledStateBlue)
    {
      if(currentMillis - previousMillisRed > redLEDOff)
      {
        previousMillisRed = currentMillis;

        if (ledStateRed == LOW)
          {ledStateRed = HIGH;}
        else
          {ledStateRed = LOW;}

        digitalWrite(redLEDPin, ledStateRed);
      }
    }
    else
    {digitalWrite(redLEDPin, LOW);}

}

@ajf444 please take a look at this and let me know if you have questions

A more succinct way to write the ledStateBlue if/else would be: ledStateBlue = !ledStateBlue; (and similar for ledStateRed)

Your if statement is outside of the loop() function.
Remove the } after delay(blueLEDOff);

Thank you for that. I removed the misplaced } but it still gives me an error message of too few arguments.

@ajf444: digitalWrite() takes 2 arguments (a pin# and a bool) - your calls only supply one.


text:
Can analog pins be defined as either their analog name (A0) or their digital pin number?
Can analog pins be defined by their digital pin number, and be used for analog purposes?
For example, instead of defining A0 for a pinout with the Uno, it could be 14?
Where is this documented? Is there a PDF type manual related to this, but not so low level to get into the ATmega chip?

https://www.arduino.cc/en/Hacking/PinMapping2560

For example, instead of defining A0 for a pinout with the Uno, it could be 14?

Yes. In fact A0 is just a placeholder for the number 14.
For all these things you should look in the pins_arduino.h file (Arduino\variants\wifio) for any variant you are interested in. That's where most of these symbols are defined. For example:
#define PIN_A0   (14)
#define PIN_A1   (15)
#define PIN_A2   (16)
#define PIN_A3   (17)
#define PIN_A4   (18)
#define PIN_A5   (19)
#define PIN_A6   (20)
#define PIN_A7   (21)

static const uint8_t A0 = PIN_A0;
static const uint8_t A1 = PIN_A1;
static const uint8_t A2 = PIN_A2;
static const uint8_t A3 = PIN_A3;
static const uint8_t A4 = PIN_A4;
static const uint8_t A5 = PIN_A5;
static const uint8_t A6 = PIN_A6;
static const uint8_t A7 = PIN_A7;

Incidentally, on the Uno you can also just use 0 for A0 with analogRead().

You can use 0 for A0 only in analogRead.  If you are using it as a digital pin you still have to either call it 14 or A0.

@Delta_G Good point on the usage distinction.

source: Stack Exchange

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

sort: votes


text:
Checking Arduino 5/3.3V under load
Is there a way to use common/cheap components to put the 3.3V and 5V pins on an Arduino under load, in order to measure if they are giving a correct and stable voltage?  Can I calculate a certain load to test?
Something keeps happening to my boards which causes the 3.3V pin to measure the correct voltage when idle, but to spike when put under load, which kills the component I was powering (XBees, which are previously tested working).

resistors are as cheap as you are going to get.

Arduino 3.3V source is only good for 150mA. The 5V source for 500mA from USB source, and maybe 700-800mA from the barrel jack if the source voltage is up to about 7.5V, and less current as you get up to 9V, and even less with 12V, the poor 5V regulator will heat up and shut down.

When putting too much load on a power source, the voltage will only dip down (to lower voltages). How can this kill other components? More likely it will stop working, until the voltage is sufficient again. Or are you also having motors or such connected to it without proper protection?

why would you power the XBee from an Arduino I/O pin?

Thanks all, I purposefully kept my project specific stuff away to keep this a generic question about testing load.
@ratchetfreak Thanks, I expected testing load to involve resistors, do you have an answer on how to actually reliably test those pins using them... ie if you connect resistors in series equalling X ohms and measure X Ma current across a specific point you know your regulator is handling the load that the arduino is expected to handle?

@jsotola it is powered by the 3.3V pin, and uses I/O pins for communication only

@chrisl Thanks,  do you know what situations could be causing the spikes up to higher voltages?  No motors or other components were connected while testing these spikes, but there were previously several MOSFET controlled LEDs  and other components incl solenoids which the arduino was controlling, powered by 12V VIN.

solenoids and relays can create spikes. The easiest way to mitigate them is using a flyback diode. Though most boards will additionally opto-isolate them from the control pins.

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


text:
LCD Clock Millis Code Issue
I am trying to create a clock on an LCD when I upload the code below, all it displays is a very rapidly flashing 0:00 PM. Please help. This is my first time using Millis.
#include <LiquidCrystal.h>   //includes LCD display library in sketch
LiquidCrystal lcd(27,26,25,24,23,22);   //determines pins of the LCD display
int seconds = 0;    //generates integer storing seconds
int minutes = 0;    //generates integer storing and showing minutes
int hours = 12;      //generates integer storing hours in 24 hour mode
int displayHours;      //generates integer displaying hours in 12 hour mode
unsigned long previousMillis = 0;   //creates a variable to store the amount of milliseconds since last update
const long interval = 1000;    //generates integer to find 1 second interval

void setup()
{
  lcd.begin(16,2);  //determines size of the LCD display
}

void loop()   //runs code repeatedly
{
  updateSeconds();   //runs the updateSeconds function
  clockShown();   //runs the clockShown function
  clockConversion();    //runs the clockConversion function
}

void updateSeconds()   //check to see if it's time to update the seconds integer
{
  unsigned long currentMillis = millis();  //generates the number of milliseconds program has been running
  if (currentMillis - previousMillis >= interval)
    {
      previousMillis = currentMillis; //updates the last time seconds was updated
      seconds = seconds ++;   //adds a second to the counter
   }
}

void clockShown()   //displays the time on an LCD display
{
  lcd.clear();   //resets screen on LCD
  lcd.setCursor(0,0);    //sets the place to start writing at the top left corner of the LCD
  lcd.print(displayHours);  //displays hours
  lcd.print(":");   //displays colon
  if(minutes <= 9)  //if the minute is 1 digit
  {
    lcd.print("0"); //displays 0
  }
  lcd.print(minutes);  //displays minutes
  if(hours < 12)lcd.print(" AM");  //displays AM in the morning
  if(hours >= 12)lcd.print(" PM");   //displays PM at night
}

void clockConversion()  //runs math to convert seconds minutes and hours
{
  if(seconds == 60) //when seconds is 60
  {
    seconds = 0;  //set seconds back to 0
    minutes = minutes ++;  //and add a minute
  }
  if(minutes == 60) //when minutes is 60
  {
    minutes = 0; //set minutes back to 0
    displayHours = displayHours ++; //and add an hour
    hours = hours ++; //and keep track of AM PM
  }
  if(displayHours == 13)  //if the hour being displayed is 13
  {
    displayHours = 1; //make it 1 instead
  }
}

Problem 1
seconds = seconds ++;   //adds a second to the counter

This command grabs the value of seconds, increments the value of seconds, and then assigns the previously grabbed value to seconds. Or rather, it does nothing to change the value of seconds.
This mistake is repeated for minutes, hours, and displayHours in the clockConversion() function.
Instead
seconds++;

That was the main problem. The other problems described below are just for efficiency.
Problem 2
void loop()   //runs code repeatedly
{
  updateSeconds();   //runs the updateSeconds function
  clockShown();   //runs the clockShown function
  clockConversion();    //runs the clockConversion function
}

Why would you display the clock with clockShown() before you run clockConversion() to nice-up the minute and hour carry-over? Since you are running both clockShown() and clockConversion() at a high frequency, it doesn't matter much, but from a program flow point of view, I think it makes more sense to do the conversion before you display the values.
Problem 3
You are only updating seconds every 1000 milliseconds, using the millis() function. This is good.
However, nothing at all changes during the 1000 milliseconds between the incrementing of seconds. Why not pull the millis() parts into loop() and call all 3 functions only once per second?
void loop()   //runs code repeatedly
{
  unsigned long currentMillis = millis();  //generates the number of milliseconds program has been running
  if (currentMillis - previousMillis >= waittime)
  {
    previousMillis = currentMillis; //updates the last time seconds was updated

    updateSeconds();   //runs the updateSeconds function
    clockConversion();    //runs the clockConversion function
    clockShown();   //runs the clockShown function
  }
}

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


text:
Is there a way to put multiple integers in a method?
I'm working on a project that has 3 RGB LEDs. I want to make a simple method that I can call to control the LEDs for example:
showColor(left, 255, 0, 50);

Which would light up the left LED at 100% red, 0% green, and 20% blue. The code I have running for the method is:
 void showColor(int ledPosition, int redIntensity, int blueIntensity, int greenIntensity)
    {
      if (ledPosition == left)
      {
        analogWrite (redPin1, redIntesity);
        analogWrite (greenPin1, greenIntesity);
        analogWrite (bluePin1, blueIntesity);
      }
      else if (ledPosition == middle)
      {
        analogWrite (redPin2, redIntesity);
        analogWrite (greenPin2, greenIntesity);
        analogWrite (bluePin2, blueIntesity);
      }
      else if (ledPosition == right)
      {
        analogWrite (redPin3, redIntesity);
        analogWrite (greenPin3, greenIntesity);
        analogWrite (bluePin3, blueIntesity);
      }
      else if (ledPosition == all)
      {
        for (int index=0, index < 3 ; index++)
        {
          analogWrite (redPins[index], redIntensity);
          analogWrite (greenPins[index], greenIntensity);
          analogWrite (bluePins[index], blueIntensity);
        }
      }
    }

I'm getting tons of errors, like that all of the Intensity variables are not declared and that left, right, all, and middle are not declared. I don't know if this is possible, or what I'm doing wrong. I think I've seen something like this before somewhere else, and I don't want to just use 1 variable to control everything. An answer would be greatly appreciated!

The answer is yes. Beyond that it will be impossible for us to help you with your problem unless you provide a minimal, complete, and verifiable example and the full error messages.

the compiler is telling you to declare variables, so instead of declaring those variables, you post a question here?  ... why?

it is a function, not a method. Classes have methods.

Check your spelling Intensity instead of Intesity.
Consider using switch instead of if-then-else.
Define left, right and middle as [integer] constants somewhere (and probably something more descriptive like rightLED, leftLED and middleLED) because your code is looking for an int, instead you give it something undefined like left, right and middle (and all). I would consider using bitwise operators for identifying the LEDS, instead of a simple integer flag as this gives future flexibility in lighting up combinations without changing your code (the current function would be rewritten to accommodate this).

This answer is slightly off track, but after reading the title my first though was this.
You can have a function that takes multiple integer parameters and there is nothing wrong with that, but there comes a point in your code where you should be looking at better data management.  In this case you have three intensity values that are always going to be related so you could look at a class or struct to hold the data as a single object.
struct Colour
{
    int Red;
    int Green;
    int Blue;
    Colour (const int& r = 0, const int& g = 0, const int& b = 0)
        : Red(r)
        , Green(g)
        , Blue(b)
    {}
}

This would allow you to define an object (called LEDLeft) that held the value for that LED, i.e.
Colour LEDLeft(0xFF, 0xFF, 0x00);    // Define a yellow left LED.

Extending this further you could define a second structure that defined the pins to control the LED, and a third that paired the current colour with the LED.
struct LED
{
    LEDPinout Pins;
    Colour    Colour;
   // Constructor ...
}

Its about this point that using a class rather than a struct would be a better (more conventional*) idea.  i.e.
// THIS IS NOT COMPLETE CODE - IT HAS NOT BEEN TESTED.
class LED
{
    LED (const int& pinRed, const int& pinGreen, const int& pinBlue);
    LED (const LED& other);  // Copy constructor

    void SetColour(const Colour& colour);
    Colour GetColour(void)const;
}

static const Colour RED(0xFF, 0x00, 0x00);
static const Colour BLUE(0x00, 0x00, 0xFF);
enum Positions {Left = 0, Middle, Right, All};
LED TheLeds[] = {LED(2, 3, 4), LED(5, 6, 7), LED(8, 9, 10)};
TheLeds[Left].SetColour (RED);
TheLeds[Right].SetColour (RED);
TheLeds[Middle].SetColour (RED);
delay(1000);
for (int loop = 0; loop < All; ++loop)
    TheLeds[loop].SetColour(BLUE);
delay(1000);

There are two errors in your code:

The word “Intensity” should always be spelled like this, rather than
“Intesity” (missing “n”)
In for (int index=0; index < 3; index++), the separators should be
semicolons, not commas.

Other than that, and provided proper declarations, your function
compiles just fine.

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


text:
LCD Lifespans Constantly Running
I am creating an arduino alarm clock/light sculpture, but I can't for the life of me find any information about the lifespans of LCDs that are running 24/7 for a very long time. If anyone has any information on them, please tell me. Specifically, I am using this one.

Let me turn the question around for you. How long do you want it to last, realistically? A year? 10 years? 100 years?

it should be years and years; i have several going for years now.

The lifespan of the LCD and the electronics is just like any electronics part. When it is bad quality it will last a few years, when it is good quality it is more than 10 years.
A LCD watch from the 1970s might still work today. That is a few decades.
The backlight might get dim. That depends on the quality of the led and how bright it is set. The cheapest leds have only 50% brightness left after a few months. I suppose they didn't put the cheapest led in that display. I expect it to be okay for many years. Don't set it to the highest brightness. A resistor for the backlight of 220 Ω is common, you could start with 470 Ω and see if that is bright enough.
I see sometimes that the backlight display is directly connected to 5V, without resistor. If you have done that, then you have reduced its lifespan.
There are a few weak parts: The potentiometer for the contrast, the large capacitors on the Arduino board (if there are any), and the power supply.
If the display is more or less at the same room temperature, you could replace the potentiometer with a single resistor of 100Ω to 10kΩ from the LCD contrast pin to GND.


text:
Do Arduino Megas Burn Out?
Im building a bedside alarm clock/home assistant. I have a few buttons that input, an LCD display and some RGB LEDs. The LCD and RGBs are only on when commanded to be on. I was wondering if I could leave the mega plugged in and constantly running or if that would burn it out. Im a bit new to this so sorry if this is dumb. If it would burn out, how long is its lifetime?

This has been covered here several times before.

As long as you operate the electronics within specification they will run for years and years. The first thing to probably fail will be the electrolytic capacitors that will dry out after maybe 10 years.
When reading datasheets and specifications the metric you are interested in is the MTBF - the Mean Time Between Failures.


text:
floor( 1.0f ) bugged?
I just displayed the value for floor( 1.0f ) and surprisingly, it's 0.
Anyone knows about that? Is there a fix in libc expected any time soon?
I've been looking at libc::floor.s but it's a bit dodgy and 1) I don't want to break my other existing code and 2) don't have time for that so I'll add an epsilon at the moment (but that defeats the purpose of floor)...
Thanks for posting any fix or idea on how to bypass the issue.

@Patapom Please expand on your question. Please also your code so far. Only then will people consider to re-open the question.

It's not a generic computer problem : this is the way floating-point values are handled by the libc and it can be fixed directly in libc.
As far as I know, arduino boards don't have FPUs so it's a software problem and on my board floor( 1.0 ) returns 0.0...


text:
Arduino industrial 101 digital pins
I don't see anything that has been clear about which digital pins map to which physical ones. If someone could point me in the right direction it would be a big help.
For exampleThrough trial and error, i've found that if i set digital pin 3 in the Arduino IDE, it is mapped to D0 on J6, but surely this is documented somewhere?

We must have different search results, because that was the second thing i did and didn't see what i was looking for, but thanks for looking.

I found what i was looking for on the arduino github repository.
Arduino/hardware/arduino/avr/variants/


text:
Can the Mouse library scroll horizontally?
I'm using the Mouse library with an ATmega32U4 connected to Linux via USB.
I would like to issue horizontal scroll commands, but the Mouse.move() function only seems to accept X movement, Y movement and vertical scroll parameters.
How can I send horizontal scroll commands from the Arduino to the computer?

You need to rewrite the core to provide buttons 6 and 7.

You could combine it with Keyboard to use the Ctrl and Shift keys for other scroll options.

As suggested in the comments, I edited the core libraries to achieve this.
I'm using PlatformIO, so the library files I needed to edit were here:
~/.platformio/packages/framework-arduinoavr/libraries/Mouse/src/

And the required changes (to change a wheel parameter for horizontal (h) and vertical (v) scroll parameters were as follows:
Mouse.h
Change the declaration of move():
...
void move(signed char x, signed char y, signed char h = 0, signed char v = 0);
...

Mouse.cpp
Add the following to the report descriptor after the last INPUT message:
...
0x05, 0x0c,        //       USAGE PAGE (Consumer Devices)
0x0a, 0x38, 0x02,  //       USAGE (AC Pan)
0x15, 0x81,        //       LOGICAL_MINIMUM (-127)
0x25, 0x7f,        //       LOGICAL_MAXIMUM (127)
0x75, 0x08,        //       REPORT_SIZE (8)
0x95, 0x01,        //       REPORT_COUNT (1)
0x81, 0x06,        //       INPUT (Data, Var, Rel)
...

Change the definition of move():
void Mouse_::move(signed char x, signed char y, signed char h, signed char v)
{
    uint8_t m[5];
    m[0] = _buttons;
    m[1] = x;
    m[2] = y;
    m[3] = v;
    m[4] = h;
    HID().SendReport(1, m, 5);
}

The following terminal commands were also useful in testing these changes:
# List input devices
xinput --list

# List device capabilities
xinput --list <device-id>

# Watch for data sent from the device
watch -n 0.1 xinput query-state <device-id>

The NicoHood/HID library https://github.com/NicoHood/HID has a lot for keyboards (media keys and so on), but not everything for mice. I don't know if horizontal scrolling is somewhere in there.

Horizontal Scroll is achieved by holding shift when scrolling vertically.
Do this instead:
Keyboard.press(KEY_LEFT_SHIFT);
    Mouse.move(0, 0, 1);
    Keyboard.releaseAll();


text:
How to use arduino IDE to compile .s files
Hi I'm new to arduino and im using it to learn assembly for my computer hardware 101 class, I read online that I can make the IDE accept .s files and compile them to the board but I dont know how to do this (something about editing the source code and recompiling the IDE?).
Could I get a step by step walk through? Assuming it's relatively simple, or just a link to some relevant documentation that's not a literal reference manual :-).
EDIT
As terrible as it is,I'm working from a macbook pro

The IDE should be able to accept .S files (not .s - the difference is very important: .S will be preprocessed, .s won't).
Just create a new sketch, and create a new tab called whatever.S (obviously rename the whatever to whatever you want to call it.
Then in the main sketch .ino file put something like:
extern "C" void myAssemblyMain();

void setup() {
    myAssemblyMain();
}
void loop() {
}

That will then call the function myAssemblyMain: in your assembly file and not much else.
(Note: I haven't tested this since I don't use the Arduino IDE).

Note that, if you do not rely on the initializations done by the Arduino core library, you can write main() instead of setup() and loop(). You may also write main() in assembly and put something else in the .ino file: a dummy unused function, or maybe nothing at all (though I don't know if the IDE will accept an empty .ino).


text:
Arduino relay power supply question
Hello everyone i got 2 ssr's from here

(link)
Sorry about the long link. My question is what power supply should i use. I was thinking a 12v 2amp. On a side note do i look at the input or the output when choosing a power supply
Thank you

May not be but thats why i am here so people can teach me the right way

it's fine, but a 12v 1A is cheaper and more than enough current for your project.

In the product description it says "DC 12V 8-Channel Relay interface board, and each one needs 15-20mA Driver Current." So 8 times 0.020A is 0.160A per board. I think your 2 amp power supply should work just fine.


text:
How to webClient.write() an image stored on a String?
My application runs on an ESP32-CAM.
It takes pictures and stores to SPIFFS.
Periodically SPIFFS is checked and if images are found:
1- The image is saved to a FTP server
2- The image is summited to a Web Service that returns some informations about the image
3- Values are saved to mySQL
4- The image is deleted from SPIFFS
To read the image from SPIFFS I use the following fragment of code:
String imageName   = file.name();
imageBuffer = "";
while (file.available()){
   imageBuffer += char(file.read());
}

The FTP transfer works perfectly with the following command:
ftp.WriteData((uint8_t*)imageBuffer.c_str(),imageBuffer.length());

The service the image is submited for analizes works OK if I use the command:
webClient.write(fb->buf,fb->len);

But as it is not usable in the current implementation of my project I am trying to work with:
webClient.write((uint8_t*) imageBuffer.c_str(), imageBuffer.length());

I get no errors in return but it just does not work and the web service at the destination returns nothing.
What Am I doing wrong?

What you're doing is treating binary data as text. As soon as you get a 0 byte the string will be truncated.

Your webClient.write() looks fine, but how are you framing this raw data? See How does HTTP file upload work?.

Short knowledge on how to handle this sort of data. "framing raw data"? What does it mean?

@Majenko: A String object does not truncate on the first NUL: it keeps all the bytes you push with +=, and the length() method returns the total number of bytes, including embedded NULs.

Short answer: you can't store raw image data in a String.

"What you're doing is treating binary data as text" Result of internet searchs. As it worked with FTP I tried the same sort or command with webClient but not working. To be honest I do not really understand what I am doing at this binary level. Searching the internet and trying to see what works.

@EdgarBonet I'd expect to end up with a string that has no NULLs in it, since adding a NULL to the end of a string would have no effect.

“framing” is the stuff you put around the data. See the link I provided. @Majenko: yes, you can.

I would like to understand the reason it works with FTP but not with webClient

My poor understanding tells me something to do with spaces and Nulls but do not know how to sort it out.

@EdgarBonet Internally String::concat() uses strcpy(). Ergo it will only copy anything up to the first NULL, replacing any end NULL that's already there.

@Majenko: try it! I did.

I will try it. Thanks

@EdgarBonet I'd rather not, thanks. I stay well away from String and anything to do with it. Never use String for anything. Not only is it generally a bad idea, you just can't trust what it's doing. And regardless: storing raw binary data in a string is asking for trouble.

OK, I got it to work as follows:
Not passing the binary anymore, passing the file name so the FTPPost function will do its own reading of the file on SPIFFS and will post in 256 bytes chunks.
The same strategy works with HTTP post to the WebService.
  File picFile = SPIFFS.open(fileName,FILE_READ);
  const size_t bufferSize = 256;
  uint8_t buffer[bufferSize];
  while (picFile.available()) {
    size_t n = picFile.readBytes((char*) buffer, bufferSize);
    if (n != 0) {
      ftp.WriteData(buffer, n);
    } else {
      Serial.println(F("Buffer was empty"));
      break;
    }
  }
  picFile.close();

You should not use String to store binary data.
Instead allocate yourself an array of uint8_t of the right size.
uint8_t *imageData;
size_t len = file.size();

imageData = alloca(len);
file.readBytes(imageData, len);

webClient.write(imageData, len);

With that said, without knowing what the rest of your program is doing I can only surmise that you're just blasting raw data at the web server and hoping it sticks. That's not how web data transfers work. You have to craft the upload page properly as multi-part mime form data. Read this for more information

Hi, thanks, on one side I am submitting it to the FTP library and assume it will handle the flow. The submission to the web service is HTTP so I do not know, but when I use webClient.write(fb->buf,fb->len); it works so I am assuming it is handling the 24K or so bytes of the image. What do you suggest me to do? Thanks


text:
Voltage divider for 6 non intrusive current sensors
I have an Arduino project where I intend to use 6 non intrusive current sensor model SCT013 (100A/50mA) manufactured by yhdc.com
As reference voltage on examples I find at the internet it is suggested the use of 2 10K resistor connected in series from 5V to ground, the reference voltage is extracted from the middle connection between the resistors (2.5v).
Question:
In the case of six sensors will I have to use 6 independent voltage dividers or can I use a single divider as reference for all sensors?
I am concerned the interference between sensors may cause reading imprecision.
Thanks in advance
Paulo

I assume you refer to a circuit like this:

simulate this circuit – Schematic created using CircuitLab
The "reference" you speak of is not a reference - it is a virtual ground. A ground reference that is at a different potential to the Arduino - in this case 2.5V higher.
Since it is just the ground for the circuit you can use the same one for all the current transformers without problems.
If the offset voltage were applied to the output (as is often done for active devices that create an AC waveform, such as audio signals) then you would require a separate offset voltage for each one, since otherwise you would be connecting all the outputs together, which would be bad.
You can also "reverse" your thinking. The "offset" voltage you apply is ground, and the Arduino's "ground" is 2.5V below that. It's all relative.

Ok, understood. How about the capacitor C1, should I use a higher value, or, does it matter if I use like 100 microF instead of 1?
Thanks Paulo

Not really, no. It's to reduce the impedance of the voltage divider.


text:
Digital Inputs have gone crazy
My digital inputs are behaving as if they were floating, even though I've properly connected them with a resistor.  I've tried the pull-down configuration pictured below, as well as a internal pull-up.
By using digitalRead() and serial.pintln() I've collected the state of each input tested (0 to 10) and they all do the same: random 0's and 1's.  When I change a state (press or release the button), they seem to work for a second or two, then, they go crazy again.  Sometimes, they even work backwards (showing HIGH when it's supposed to be LOW) for a couple of seconds.
Is my two-day old Arduino UNO fried?

Have you confirmed that the signal at the pin-headers are accurate using a known-good test tool, like a multimeter?

Solved it, but here is the solution, so there is an answer available for anyone who might encounter the same problem...
Quality check your protoboards.  This is making me feel stupid.  The protoboard I used had a faulty connection on the blue line I was using, causing an inevitable floating input.  So relieved I found the problem, and yet so annoyed!
Take care you all.

Some solderless breadboards have a split right in the middle of the red and blue lines. These sometimes have an interrupted red/blue line.


text:
WS2812B Led Digital Panel Matrix Flexible Screen 8*8. Some LEDs that are not supposed to, switch on
My project is composed of an ESP32, a level converter and two WS2812B Led Digital Panel Matrix Flexible Screen 8*8 (from Aliexpress) interconnected with the provided cable. My objective is to show a score, no scrolling or any other animation.
The main functionality works ok, I can display any decimal number between 00 to 99 (one digit in each 8x8 panel).
My problem is that apart from the digits printed, some not so aleatory LEDs switch on, not necessarily on the same color as the intended number, nor on the selected luminosity. Changing the number changes this undesirable pattern that seems to repeat for the same number on the same 8x8 matrix. Problem patters does not follow a specific 8x8 matrix, the problem does not seem to be in the hardware.
The level converter converts the ESP32 3.3v to 5v required by the Matrix but even before I connected the level converter the problem was the same.
The code I am using is as below:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            14

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      128

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 10; // delay for half a second

void setup() {
  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  pixels.clear();
  pixels.setBrightness(1);

  boolean N0[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,1,1,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,1,1,1,1,0},{0,0,1,1,1,1,0,0}};
  boolean N1[8][8] PROGMEM = {{0,0,0,1,1,0,0,0},{0,0,1,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,1,1,1,1,1,1,0},{0,1,1,1,1,1,1,0}};
  boolean N2[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,0,0,0},{0,0,1,1,1,1,0,0},{0,0,0,0,0,1,1,0},{0,1,1,0,0,0,1,0},{0,1,1,1,1,1,1,0},{0,1,1,1,1,1,1,0}};
  boolean N3[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,0,0,0},{0,0,1,1,1,1,0,0},{0,0,1,1,1,1,0,0},{0,0,0,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0}};
  boolean N4[8][8] PROGMEM = {{0,0,1,1,1,0,0,0},{0,0,1,1,1,1,0,0},{0,0,1,1,0,1,1,0},{1,1,0,0,1,1,0,0},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,0,0},{0,1,1,1,1,0,0,0},{0,0,0,1,1,1,1,0}};
  boolean N5[8][8] PROGMEM = {{0,0,1,1,1,1,1,0},{0,1,1,1,1,1,1,0},{0,0,0,0,0,1,1,0},{0,1,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,0,0,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0}};
  boolean N6[8][8] PROGMEM = {{0,0,1,1,1,0,0,0},{0,0,1,1,0,0,1,0},{0,0,0,0,0,1,1,0},{0,1,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0},{0,0,0,1,1,0,0,0}};
  boolean N7[8][8] PROGMEM = {{0,1,1,1,1,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,0,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,0,1,1,0,0},{0,0,1,1,0,0,0,0},{0,0,0,0,1,1,0,0},{0,0,1,1,0,0,0,0}};
  boolean N8[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0}};
  boolean N9[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,1,0},{0,1,1,0,0,0,0,0},{0,0,0,0,0,1,1,0},{0,1,1,1,0,0,1,0},{0,0,1,1,1,1,0,0}};

  int counter = 0;
  for(int line=0;line<8;line++){
    for(int column=0;column<8;column++){
      if(N2[line][column]==1){
        pixels.setPixelColor(counter, pixels.Color(0,255,0));
        pixels.show();
        delay(delayval);
      }

      if(N1[line][column]==1){
        pixels.setPixelColor(counter+64, pixels.Color(255,33,255));
        pixels.show();
        delay(delayval);
      }

      counter++;
    }
  }
  while(1){};
}

This is a non optimized code for testing purposes only.
What am I doing wrong?

How are you providing power to the LED matrices?

Computer USB. That is why I set brightness to 1 but even if I set it to 10 the problem remains the same, or, the unwanted leds that switch on are the same.

Just to add, say number 5 when printed comes along two LEDs I did not order on. Say I print a green 5. Then I get this blue faint one in a certain position and a bright red one somewhere else. This pattern will repeat no matter what I do, even if I print the 5 on pink for instance, the faint blue and the bright red will be there, even if I change the 8x8 tile.

If instead of 5 I print one other number, foreign LEDs will be different and curiously number one comes out clean. changing brightness from 10 to 1 makes no difference except for the brightness of those I control.

Found the Adafruit NeoPixel is the reason for the problem (or the way it is implemented above is not the best).
Solved with the fastLED library as below:
#include "FastLED.h"
#define NUM_LEDS 128
#define DATA_PIN 14
#define BRIGHTNESS 10
CRGB leds[NUM_LEDS];
int delayval = 10; // delay for half a second

boolean N0[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,1,1,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,1,1,1,1,0},{0,0,1,1,1,1,0,0}};
boolean N1[8][8] PROGMEM = {{0,0,0,1,1,0,0,0},{0,0,1,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,1,1,1,1,1,1,0},{0,1,1,1,1,1,1,0}};
boolean N2[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,0,0,0},{0,0,1,1,1,1,0,0},{0,0,0,0,0,1,1,0},{0,1,1,0,0,0,1,0},{0,1,1,1,1,1,1,0},{0,1,1,1,1,1,1,0}};
boolean N3[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,0,0,0},{0,0,1,1,1,1,0,0},{0,0,1,1,1,1,0,0},{0,0,0,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0}};
boolean N4[8][8] PROGMEM = {{0,0,1,1,1,0,0,0},{0,0,1,1,1,1,0,0},{0,0,1,1,0,1,1,0},{1,1,0,0,1,1,0,0},{0,1,1,1,1,1,1,1},{0,0,0,0,1,1,0,0},{0,1,1,1,1,0,0,0},{0,0,0,1,1,1,1,0}};
boolean N5[8][8] PROGMEM = {{0,0,1,1,1,1,1,0},{0,1,1,1,1,1,1,0},{0,0,0,0,0,1,1,0},{0,1,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,0,0,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0}};
boolean N6[8][8] PROGMEM = {{0,0,1,1,1,0,0,0},{0,0,1,1,0,0,1,0},{0,0,0,0,0,1,1,0},{0,1,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0},{0,0,0,1,1,0,0,0}};
boolean N7[8][8] PROGMEM = {{0,1,1,1,1,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,0,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,0,1,1,0,0},{0,0,1,1,0,0,0,0},{0,0,0,0,1,1,0,0},{0,0,1,1,0,0,0,0}};
boolean N8[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,0,0}};
boolean N9[8][8] PROGMEM = {{0,0,1,1,1,1,0,0},{0,1,1,0,0,1,1,0},{0,1,1,0,0,1,1,0},{0,0,1,1,1,1,1,0},{0,1,1,0,0,0,0,0},{0,0,0,0,0,1,1,0},{0,1,1,1,0,0,1,0},{0,0,1,1,1,1,0,0}};

void setup() {
  FastLED.setBrightness( BRIGHTNESS );
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
}

void loop() {
  int counter = 0;
  for(int line=0;line<8;line++){
    for(int column=0;column<8;column++){
      if(N2[line][column]==1){
        leds[counter] = CRGB::Yellow;
        FastLED.show();
        delay(delayval);
      }

      if(N1[line][column]==1){
        leds[counter+64] = CRGB::Green;
        FastLED.show();
        delay(delayval);
      }

      counter++;
    }
  }
  while(1){};
}

Well done finding this out by yourself and for answering your own question ;-) FastLED is a very well developed library.


text:
Sending serial data in an interrupt
An ATMEGA328-P chip is used with a toggle switch attached to pin 8 and a momentary switch attached to pin 9. My objective is to send the following information over serial:

The status of pin 8, every second.
Count the number of presses of pin 9, sending the value as the counter increments

I understand that to achieve point 2 I will need to utilise interrupts, but I have become stuck in the way I am trying to use them.
I am familiar with the following code's simple style:

Within the loop...
Poll the status of the input
Send status over serial

Code A:
const int SWITCH_1 = 8;
const int READ_INTERVAL = 1000;

int val_s1 = 0;

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

    pinMode(SWITCH_1, INPUT);
    digitalWrite(S1, HIGH);
}

void loop() {
    val_s1 = digitalRead(SWITCH_1);
    Serial.print("S1:");
    Serial.print(val_s1);
    Serial.print("\n");

    digitalWrite(LED_BUILTIN, HIGH);
    delay(10);
    digitalWrite(LED_BUILTIN, LOW);
    delay(READ_INTERVAL);
}

When introducing the concept of interrupts, I have tried to retain the simplistic style of code A for testing purposes. The next snipped attempts to achieve the following:

Attach an interrupt to pin 9 when the voltage rises
No need for loop function (?)
Within interrupt callback function...
Increment the counter
Send the counter value over serial

Code B:
void c1_rise();

const int COUNTER_1 = 9;
const int READ_INTERVAL = 1000;

volatile int val_c1 = 0;

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

    pinMode(COUNTER_1, INPUT_PULLUP);
    attachInterrupt(COUNTER_1, c1_rise, RISING);
}

void loop() {
}

void c1_rise() {
    val_c1 ++;
    Serial.print("C1:");
    Serial.print(val_c1);
    Serial.print("\n");
}

I've tried to learn where I'm going wrong, but I have become stuck and have decided to ask my questions here.

Observation: I expect to see some data sent over serial when the button is pressed, but actually nothing observable happens.
Problem 1: This might be because the interrupt isn't being attached at all.
Problem 2: This might be because I misunderstand the limitations of interrupt callback functions.

While trying to solve problem 1, Arduino documentation implies that to use the attachInterrupt function, parameter 1 must be an interrupt, from digitalPinToInterrupt, but if I use that function I receive the following error message: error: ‘digitalPinToInterrupt’ was not declared in this scope.
From reading up about how interrupts behave, I found problem 2: it seems that even though I have declared the integer as volatile, using Serial from within a callback function isn't allowed. This is the limit of my knowledge currently, I hope that someone can help me out.

You cannot use Serial inside an interrupt. Transmitting Serial relies on interrupts being available, and from inside an interrupt they aren't.
All Serial communication must be done from loop().
So you need to just count the switch toggles and check to see if that value has changed in your loop.
volatile uint32_t toggles = 0;
uint32_t old_toggles = 0;
uint32_t ts = 0;

void setup() {
    pinMode(2, INPUT_PULLUP);
    pinMode(3, INPUT_PULLUP);
    attachInterrupt(0, toggle, RISING);
}

void loop() {
    if (toggles != old_toggles) {
        old_toggles = toggles;
        Serial.print("C1: ");
        Serial.println(toggles);
    }

    if (millis() - ts >= 1000) {
        ts = millis();
        Serial.print("S1: ");
        Serial.println(digitalRead(3));
    }
}

void toggle() {
    toggles++;
}

May I ask what parameter 0 of attachInterrupt should be set to? Have you set to 0 arbitrarily? I am using 9 as that is the pin the switch is attached to, but using this method still isn't triggering the callback.

I have coded that for the Uno. Pin 2 is interrupt 0. Pin 3 is interrupt 1. Select the right pins for your chosen board.

Your answer is straight to the point, thanks for making it simple for me to understand.

Problem
In essence, attachInterrupt uses a macro called ISR (stands for Interrupt Service Routine) to register a user provided function to handle an external interrupt event.
The issue you are encountering is that ISR also wraps the call to your function with special instructions to clear the global interrupt flag of your microcontroller, and  set it again after your function returns. This is a good idea, and almost always what you want, because it prevents the possibility of infinitely recursive interrupts.
However, this behaviour will prevent Serial from working correctly, since it relies on interrupts being enabled to do its thing.
Solution
Although this is the default behaviour, there is nothing stopping you from enabling interrupts again inside your c1_rise function, as in:
void c1_rise() {
    val_c1 ++;
    interrupts();
    Serial.print("C1:");
    Serial.print(val_c1);
    Serial.print("\n");
}

Alternatively, but perhaps more involved, you can use the ISR macro directly by including avr/interrupt.h, and use ISR(vect, NO_BLOCK) to override the default behaviour.
Of course, you should be careful when overriding the default behaviour --- its there for a reason!
For more details about working with interrupts, I recommend reading this documentation.


text:
Arduino : LCD / POT
how can I make the repetitions stop at 10 ? Also how can I get the lcd to reset when its off/low ?
#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);
const int tiltSensor = 8;
int reps = 0;
int switchState = HIGH;
int prevSwitchState = LOW;

void setup() {
  lcd.begin(16,2); // type of lcd(16 columns and 2 rows)
  pinMode(tiltSensor,INPUT);
  lcd.clear();
  lcd.setCursor(0,0); // the cursor is where on the
  lcd the characters will be placed
  lcd.print("Workout Time"); // print is the characters on the screen
  lcd.setCursor(0,1);
  lcd.print("Lets GO ! ");
}

void loop() {
  switchState = digitalRead(tiltSensor);
  if (switchState != prevSwitchState) {
    if (switchState == LOW) {
      reps = reps + 1;
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Reps:");
      lcd.setCursor(0,1);
      lcd.print(reps/10);
    }
  }
  prevSwitchState = switchState;
}

if (reps < 10)?

how can I make the repetitions stop at 10 ?

use a loop counter:
  if (loop_cnt++ < 10) do_mything();

Would it be possible for you to elaborate as to where in the loop its to be placed ? as I am new to this...


text:
Connection Problems with GPRS Shield
I recently bought a GPRS shield from Seeed Studio but was having issues running the programs described in their documentation.  Here is everything you need to know about my shield:
Documentation for GPRS Shield V2.0
Website to purchase GPRS Shield V2.0
I assumed that there was a connection problem. I used the following code to try to debug my SIM900 and its connections to the sim card and the cellular network:
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7,8);

void setup(){
  gprsSerial.begin(19200); // GPRS shield baud rate
  Serial.begin(19200);
  delay(500);
}

void loop(){
  if(Serial.available()) {
    switch(Serial.read()) {
      case '0': testSIM900(); break;
        // AT OK
      case '1': testSIMCARD(); break;
        // +CPIN: READY
        // +CREG: 0,1
      case '2': testNETWORK(); break;
        // +CGATT: 1
    }
  }

  if(gprsSerial.available()) Serial.write(gprsSerial.read());
}

void testSIM900() {
  gprsSerial.println("AT");
  // AT OK
  delay(100);

}

void testSIMCARD() {
  gprsSerial.println("AT+CPIN?");
  // +CPIN: READY
  delay(100);
  gprsSerial.println("AT+CREG?");
  // +CREG: 0,1
  delay(100);
}

void testNETWORK() {
  gprsSerial.println("AT+CGATT?");
  // +CGATT: 1
  delay(100);
}

When I entered 0, 1, and 2 into the serial monitor, I got the following response:
AT

OK
AT+CPIN?

+CPIN: READY

OK
AT+CREG?

+CREG: 1,2

OK

+CREG: 0

+CGREG: 0
AT+CGATT?

+CGATT: 0

OK

What does this tell me about the current state of my shield, sim card, and network connection? Is there anything else I can do to isolate issues?

It seems it can't register on the network, GSM modems are power hungry, are you sure you're powering it up with the external power source (through Vin)? Pretty sure the Arduino isn't enough, but I could be wrong, that's a shield that has those issues in mind.
Also try to see the signal strength using AT+CSQ.


text:
Fool Proofing My Arduino IC Checker
I am creating an IC checker for some high school juniors since a faulty IC can be a nuisance of a bug to find when bread-boarding. These ICs are all simple TTL gating from the 74LS series; the set I am using are all 14-pin and have VCC and GND at pin 14 and 7 respectively.
Thus far my prototype's hardware looks like this:

14 digital pins to connect to the IC inputs/outputs
1 analog pin reading a joystick to navigate through the IC options
1 analog pin set to digital read as a button, which starts the checking process
1 analog pin writing to an LED to indicate whether the IC is valid
2 analog pins (SDA and SCL) as a serial bus to control my display

I actually have the prototype working for a few ICs, but I am concerned that these high school students may test an IC under the wrong selection. Since the digital pins have to dynamically change input/output depending which IC its checking, this allows for inputs and outputs to be mismatched, which could prove fatal to both the IC and the Arduino board.
I want to know if there is a way to check that inputs and outputs are misaligned without having serious electrical failure. Possible some advanced pin control I am unaware of?
Also, if you could answer my question with an example with the 74LS00, whose pinout is diagrammed below and datasheet can be found here.

Just add some current limiting resistors to the Arduino pins. Those shouldn't affect the operation of the device-under-test, but will prevent damage if something isn't connected right. Might I also suggest putting in some sort of protection in case the chip is inserted upside-down.

Perhaps this would be better on electronics.SE

https://hackaday.com/2018/02/15/building-an-arduino-smart-ic-tester-for-25/ might be of interest

The simplest way to "fool proof" your system (i.e., to prevent damage by a fool, not make it so it always works right even with a fool) is to add a resistor to each connection. The resistor should be sized so that if an IO pin is HIGH and it's connected to a LOW output on the chip the current flow is below the maximum allowed by both ends.

simulate this circuit – Schematic created using CircuitLab
If D5 is set HIGH and the output of the NAND is LOW the voltage difference (assuming a 5V Arduino) would be around 5V. I=V/R, so 5/1000 is 5mA - way below the maximum of 25mA (40mA burst) of the Arduino.
It won't tell you that you have connected the wrong chip, but it will protect both the chip and the Arduino in such an event.
Since it now doesn't matter if the wrong chip is selected you could in fact cycle automatically through each of the chips testing each on in sequence until you find one that gives the correct results. No need to select a specific one - if no chip matches then it's a faulty chip.

Won't a resistor set up of this type drop the voltage across the system significantly? TTL ICs tend only to operate between 4.75V and 5.25V.

No. 1: you're not putting a resistor in the supply connections, only the signal paths. 2: The voltage drop is proportional to the current, and the current from an output to an input is minuscule (an input is very high impedance).

Oh duh, sorry for that comment. I tested this out and it works well.

I would connect each of the IC's IO pins to both a digital output and
a digital (or analog) input of the Arduino, like this:

simulate this circuit – Schematic created using CircuitLab
Drive each pin with the digital output, alternatively LOW and HIGH.
While doing this, read the pin voltage through your input:

If the IC pin is an input, you will have no significant voltage drop
through the protection resistor. Your reading should be LOW when
driving the pin LOW and HIGH when driving it HIGH.
If the IC pin is an output, you will have 5 V through the
resistor whenever the IC's output value doesn't match your Arduino
output. The reading on your input will be independent of the level of
your output.

Obviously, an Uno doesn't have enough I/O pins to implement this idea.
You could use a Mega instead. Notice also that with this setup you don't
need the joystick input: you could just test for every known IC type
until you find one that matches the observed behavior, then display the
part number on your LCD.

You can use a shift register instead of directly using arduino outputs.

Alternatively, just one input pin and switch the pull-up resistor on and off.

@PeteKirkham: You probably would want a pulldown also.

Great idea but I only have the arduino uno.

I am tempted to repeat the old engineering trope "You can't make it foolproof - fools are so ingenious".
If you want to proceed, and are prepared for the complexity 2 solutions suggest themselves.

Limit the current supplied by the Arduino output if connected to a pin on the IC configured as output.
Probably less complex is to test each pin by loading it to 0V and 5V to find which are TTL outputs. A TTL input will unable to source any significant current, while an output will be able to draw current to/from either 0V or 5V.

Either will require quite a bit of additional hardware.
This is not strictly an Arduino problem, but an Arduino would be an ideal solution.


text:
Consequences of dynamically changing input/output configurations of digital pin?
I am creating an IC checker for a large chunk of the 74ls series (basic TTL logic chips), which means that I have 14 pins running to the IC to verify its functionality. One pin is power (+5V) and another ground (GND), which are both consistently in the same seven and fourteen pin positions respectively, but the remaining 12 are various inputs and outputs that vary depending on the IC type.
With that stated, will there be any consequences to dynamically reconfiguring a pin from input to output -- or vice versa -- as different IC types are selected? Weird behavior or electrical failure? What if the IC remains plugged in while the the pins reconfigure? What if said IC is powered on and providing power to a pin as it reconfigures?
If you were curious, I am using a joystick and LCD display as an interface to selecting the appropriate IC to check.

There's no problem reconfiguring pins.  It happens all the time.  One example is with ping sensors where the pin is used as an  output to send the ping and then switched to an input to wait for the response.  The only caveat is that you must be sure what you're connected to.  For instance, if you set a pin to OUTPUT and LOW and it just happens to be connected to a HIGH OUTPUT then you just fried your board.


text:
Fill an Array with Values
I have a function in which I change the pinMode on many of my Arduino's pins based on a passed in mode. I first construct an array of bytes specifying each pin to be an input or an output and then I iterate through the array to set all the pins.
void pinout(byte mode) {
  switch(mode) {
    case 0: char pins[13] = {'O','O','I','I','O','I','I','I','I','O','I','I','O'}; break;
    case 1: char pins[13] = {'O','I','I','O','O','I','O','O','I','O','I','O','I'}; break;
  //etc..
  }
  for(byte i = 0; i <= 13; i++) {
    if(pins[i] == 'I') pinMode(i, INPUT);
    else pinMode(i, OUTPUT);
  }
}

However, since the array is defined inside the switch statement, I loose scope of the pins array when I move onto the for loop. I tried defining the pins[] outside of the switch statement, but then I am confused on how to populate it efficiently. These all threw errors when I tried to populate the variable inside the switch statement:
pins[0,1,2,3,...,12,13] = {...};
pins[13] = {...};
pins[] = {...};
pins = {...};

I know I could go through each entry individually, but this could be rather inefficient use of memory and computational power as I add more cases. Any ideas?

Since your values are all constant you can define them all as constant values and just select between them. The simplest way is to add an extra dimension to your arrays:
const char pins[2][13] =
    {'O','O','I','I','O','I','I','I','I','O','I','I','O'},
    {'O','I','I','O','O','I','O','O','I','O','I','O','I'}
};

for(byte i = 0; i < 13; i++) {
    if(pins[mode][i] == 'I') pinMode(i, INPUT);
    else pinMode(i, OUTPUT);
}

(Note: An array of size 13 has entries 0-12.)
However, that is very inefficient.  Since you only have two states, I and O, and there are only 13 entries, you can store each array as a single 16-bit value:
const uint16_t pins[2] = {
    0b0110111101100,
    0b1010100100110
};

for(byte i = 0; i < 13; i++) {
    if((pins[mode] & (1 << i)) pinMode(i, INPUT);
    else pinMode(i, OUTPUT);
}

(Note: the data is stored backwards - pin 0 is on the right, pin 12 on the left.)

Just out of curiosity, how does marking a variable as const improve performance and/or memory? Is it similar to making a set-byte buffer array in other languages?

On a little 8 bit Arduino it doesn't unless you also start working with PROGMEM. On 32-bit systems though it generally means the array takes no RAM.

I know I could go through each entry individually, but this could be
  rather inefficient use of memory and computational power as I add more
  cases.

The compiler produces assembly/machine code that takes the same effort to load the array, so it's not that inefficient. The bracket arrangement is just a construct for easier to read code.

So, are you saying that filling my array like this: char pins[13]; pins[0] = 'I'; pins[1] = 'O'; ... would be similar in memory footprint to this: char pins[13] = {'I', 'O',...};?

Pretty much, though @Majenko has suggested a very memory efficient solution, using a bit array (i.e, a single 16-bit value) rather than an array of 12 bytes with only two possible values.

@BenjaminBrownlee: char pins[13] = {'I', 'O',...} only works as a global (or static) initialization. It's more efficient than the alternative, as the copying is handled by the __do_copy_data routine of the C run time, which copies the whole program's data section from flash to RAM in one go.


text:
Parsing sd card file to polymorphic objects
I am trying to read a file from sd card and parse them to polymorphic objects, then have an array of pointers to them so i can access them later.
I was wondering what the best format would be to save these objects in, i was looking at https://github.com/bblanchon/ArduinoJson but i don't know if it's possible to deserialize them to the right object.
Is this even possible?

There is no such thing as serialization/deserialization in C++. You can read the data values from an object, and you can write data values to an object, as long as you either expose the properties as public, or create "getter" and "setter" member functions.
It is then up to you to store and retrieve that data in whatever form you like.
You could store the raw RAM data that corresponds to an object, however if there are any pointers in that object they will be stored as just that - a pointer - which will be meaningless when reloaded. So it's better to store the data values manually.
How you store the data depends on what the data is. Yes, you can use JSON format if you so choose - it has good abstraction for storing strings, escaping special characters, etc. So it would be quite convenient - however, it's quite a heavyweight arrangement. A lighter method would be to store binary data directly, but that is inflexible and can't easily store different types of data in different ways for different objects.
CSV format is quick and easy to parse, but you have to manually deal with things like commas in data strings, etc.


text:
Robotdyn esp8266 interrupt from arduino timing
I use a Robotdyn, uno+wifi r3 atmega328p+esp8266. I need to control motor speed and operate few servos. Since the uno has a single timer, I use the esp8266 pin 2 to control motor speed, while the arduino pins to control servos.
I've used the serial channel for uno to send a list of speeds to operate the motors to the esp.
Now I need to trigger esp to change from one speed to another, and I was considering using one of the uno pins to trigger an interrupt for the esp, for this notification. I need the speed change as instantaneous as possible. I am using I2C 5v to 3.3v logic level converter for raising the interrupt from uno pin to pin 4 of esp.
Now the question, how long should I hold the uno pin high for the interrupt to be detected? A quick filp;
digitalWrite(outGoingIntrPin, HIGH);
digitalWrite(outGoingIntrPin, LOW);
seems to sporadically work. I think I need to introduce a delay between these statements, but I do not know how much should that delay be.
Any suggestions to improvise is welcome.

The Uno has 3 Timers in total. Considering that Timer0 is used for delay()/millis() and another timer for the servo library you have still one Timer left to operate your (I suspect 2) DC motors


text:
CD rom stepper getting warm
I'm trying to run a SPS-15RF stepper motor from an old cd rom drive. I'm using a CNC shield and a4988 driver with a 6v power supply. The motion is smooth and fine. I know it has 18 pulse/revolution and works with 5v but It gets quite unexpectedly hot. It feels that it can burn my fingers if I keep it running.
What is wrong with it? is it related to micro-stepping or sth else!?

Those motors are not designed to be constantly driven. They are designed to move to one position and then "release" (that is, the power is removed and active driving ceases).

there are many DIY projects on the web, using these motors for CNC applications which are somehow constant driven! there should be a solution.

Maybe you need to trim down the motor current at the driver. When the motor gets hot at continous use with the normal current, you could lower it, so that it doesn't get hot anymore

don't forget to "release" - disable driver when not actively moving (pin is called EN)

@chrisl How can I trim down the motor current?

Normally a stepper driver gas a little potentiometer on it, that you can rotate with a small screwdriver. That is used to set the motor current

Ok. I got it. current limit=Vref*2.5


text:
Reset Button not working + Can't Upload code , What is wrong?
I was testing and debugging a code I wrote for a robot with 3 stepper motors on  (Arduino Uno + CNCShield V3 + a4988 stepper drivers). I want to disable drivers at will. so I bypassed EN pin on 2 of a4988s to pin12 and pin13 of Arduino. (by defalut all EN pins of drivers are are connected to pin8 ) everything was ok but suddenly the Reset button is not working and I can't upload new codes to Arduino! I get this error:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x83
.
.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x83
Problem uploading to board.

but Arduino still is working with the last code that was uploaded to it!!! have I fried my Arduino? and Why is this happening?

Quick thought:  Did you try a different COM port on your computer.  (It may not be an Arduino problem at all.)  If your OS is Linux try "lsusb" to see where the Arduno is connected.  If Windows there are utilities you can install to see better what USB devices are connected.

I tested another Arduino Uno with my code and computer (windows 10) . It was OK. Somethings are wrong with my new wiring (pin 12 @ 13). I'm afraid It will fry the other board too.

Try manually resetting the board:

Before uploading, run Verify.
Hold the reset button and click Upload.
Release the reset button.

If that worked, your board's reset isn't fried, it just isn't receiving a reset via the serial cable. If it failed, either part of the board or MCU may be damaged; something attached to the board may be inhibiting the reset signal; or the software may have disabled the board's reset pin. In the latter case, see the Arduino StackExchange article, How do I repurpose Arduino's reset button, for how this can happen and how to undo it if it has.

Is here anything wrong with using pins 12 and 13?

I'm not familiar with stepper driver, but at a quick glance at its data sheet, and it's logic being 3.3v & 5 v compatible, I don't see any problem with connecting any of its logic to any of Arduino's logic pins (almost all of them). Since the driver also has a motor drive-voltage input for driving your motors, accidentally connecting an Arduino pin to a driver pin (or anything else) carrying the drive-voltage could - probably would - damage at least the connected pin driver in the MCU, and possibly other parts of it as well.
If your Arduino has a socketed Atmega chip, and since you already know another Arduino works as you expect it to, replacing the Atmega chip will be the quickest, cheapest & easiest fix. Just go over your wiring and make sure no motor drive voltages are connected to the Arduino board.

I tried it. Holding reset button didn't work. Is here anything wrong with using pins 12 and 13? I guess this is what made my Uno fry!


text:
AccelStepper library advanced codes!
I was trying to find out how this library can run multiple stepper motors at the same time, and I saw this important function called...
void AccelStepper::setOutputPins(uint8_t mask)
{
    uint8_t numpins = 2;
    if (_interface == FULL4WIRE || _interface == HALF4WIRE)
    numpins = 4;
    else if (_interface == FULL3WIRE || _interface == HALF3WIRE)
    numpins = 3;
    uint8_t i;
    for (i = 0; i < numpins; i++)
    digitalWrite(_pin[i], (mask & (1 << i)) ? (HIGH ^ _pinInverted[i]) : (LOW ^ _pinInverted[i]));
}

why is it using uint8_t? and what is a mask? and Is this line:
digitalWrite(_pin[i], (mask & (1 << i)) ? (HIGH ^ _pinInverted[i]) : (LOW ^ _pinInverted[i]));

sending a step signal to multiple stepper?

How to use multiple steppers depends on your needs. You can sinply define multiple AccelStepper objects and call their run method sequentially. Or you can use the multistepper class, which is also a part of the AccelStepper library

I need to edit the library to get what I want... I want to get feedback of my motors, show encoder real time data on serial monitor... try and test different control methods... I have to know how these codes work.

So your question is not about running multiple steppers, but about understanding that function?

Exactly. I have used the library... I want to customize it.

The setOutputPins() function sets the pins for a pulse for a single stepper. Depending on the used stepper motor a different number of pins has to be set (normal stepper drivers have 2 pins, the ULN2003 and its siblings have 4) in a different way. For that the function first determines the number of pins to use via the _interface member variable of the class.
The mask parameter contains the states of the pins. Each bit represents one pin. If the corresponding bit is set to 1, the pin will be set to an active state. If not, it will be set to an inactive state. Normally an active state (like I have called it here) is HIGH, an inactive state is LOW. But when working with different stepper drivers, some pins might work with an inverted logic. Thus the value (LOW or HIGH) is inverted, if the pin is marked as inverted in the _pinInverted array. This logic is in the line
digitalWrite(_pin[i], (mask & (1 << i)) ? (HIGH ^ _pinInverted[i]) : (LOW ^ _pinInverted[i]));

The idiom condition ? expression : expression represents an embedded if condition. If the condition evaluates to true, the first expression is used, else the second expression. With mask & (1 << i) we are checking, if the ith bit in mask is set. If yes, we use the next expression: HIGH ^ _pinInverted[i]. Here the ^ bitwise XOR operator is used to invert the value, if _pinInverted[i] is set to 1 (and thus marked the pin as inverted). If _pinInverted[i] is zero, the value will stay as it is. The handling of the LOW value is similar.
For understanding that better, you might want to read more about bitwise operators, if you haven't already done so.

why is it [the mask parameter] using uint8_t?

uint8_t is the smallest type, that could be used: 1 byte. As each bit represents one pin, and the library supports steppers with up to 4 pins, only 4 bits are needed at max. Thus using the smallest type with 8 bits is sufficient.

Is this line sending a step signal to multiple stepper?

No, it is setting the pins of a single stepper motor. Each instance of the AccelStepper class represents a single stepper motor. Thus every function in it also only talks to one single motor. You haven't really explained, how you want to add the feedback functionality. But you should not change the AccelStepper class to handle multiple motors. That does not make sense to me. Each motor has to be controlled individually and this class is there to capsule the work behind that. Thats the idea behind making a class for this.
I guess you want to drive multiple motors, each with it's own feedback loop. So then you first need to change the AccelStepper class for supporting that feedback loop. How this is done depends very much on your type of feedback loop. Also the setOutputPins() method is not a good place for that. It is a very low level function. You need to start further up in the call chain, maybe in the step() method or the runSpeed() method (this really depends on how you want to handle the feedback). Also you need to write methods to set up and handle the encoders input. You may need to configure timers and/or interrupts for reading them correctly.
For then supporting multiple stepper motors, you could still look into the MultiStepper class. You could change it to fit with your changes in AccelStepper or write your own wrapping class. That mostly depends on how you want the multiple steppers to behave.


text:
Error with pointer in array
I am currently learning pointers. I am following a book (Says Teach Yourself "Arduino Programming") in which there is an exemple about pointer and array.
void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  char string1[] = "This is my test string";
  char string2[]="This is another string test";
  char *ptr2 = string2;
  char *ptr1 = string1;

  while (*ptr1 != '\0') { // not "\0"
    *prt2 = *prt1;
    ptr1++;
    prt2++;
  }
  Serial.println(string1);
  Serial.println(string2);
}

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

}

I get an error "ptr2 was not declare in this scope."
I don't know what is wrong...
That for your help.

Are you sure the error says ptr2 and not prt2?

"ptr2" != "prt2"
You have a typo there.

the classical ptr vs prt, cmd vs cnd, cnt vs cmt, cmt vs cmd and so on... :)

It's teh typical typo :)

haaa.... Thanks.  I have spent 4 days in a row learning Arduino.... I must be tired. thanks again and sorry for such stupid question. it is working just fine now :-)


text:
Hall Sensor (Fluid Flow) "Noise"
Kind of a fringe question here, but could not find anything concrete so figured I would throw it to this great community.
I have 2 DS80 flow meters (Hall Effect Sensor type flow meters - nothing special about them except they are bigger for 3" pipes), and they work fine, wired, code, etc and get decent readings and all that so no issues there.
During my bench prototyping, I noticed that sometimes, in spite of no "flow", I would detect "pulses" from the sensor. Because they are sitting on a workbench, with no pipes connected, I assume this is either:

Random transient voltage, maybe bleed from its neighbors in the wiring or what not
Maybe the magnet on one fin is parked at the sensor and vibration is causing it to bounce

The second one is what it is, but the first one feels like something I could iron out. The question is, should I have a cap/resistor/something on the data line from the sensor to smooth out readings? Because it is PWM I do not know what to put there that wouldn't interfere with the signal itself (if anything). Absolutely NOT critical, as I said it works fine under load and I do not need hyper-accurate readings. More of a "could I do this better" question.

this is not a question about an arduino

I can't find any clear results when trying to search for those meters. Could you provide a link, and a more specific part nr. and/or manufacturer name?

Is there any electrical equipment nearby? Flowing electricity can create magnetic fields that could interfere with the hall effect sensor.

@Gerben - Other than the other sensor nothing else nearby, although good to check that too. As for the part number, it came from Ali Express and I have never been able to find it anywhere but there. The "data sheet" as it is is pretty terrible and contradictory and it is possible it is just slightly flaky.
jsotola - you are correct! I am using arduinio for the MCU and since there is not a "sensors" Stack Exchange, I posted here. I will happily edit the question to say that it is taking readings from an Arduino if it will make you feel better about it being here?


text:
ESP8266 - Garbled output when using serial Swap
I want to use two serial ports
Serial1 - for debugging - No RX needed
Serial - to read from a different device
I receive garbled output instead of valid characters
Here is code for NodeMCU
#define LED D0

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  Serial.flush();
  Serial.swap();
  Serial1.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0)
  {
//    digitalWrite(LED, HIGH);
//    delay(500);
//    digitalWrite(LED, LOW);
//    delay(500);
//    digitalWrite(LED, HIGH);
//    delay(500);
//    digitalWrite(LED, LOW);
//    delay(500);
    Serial1.print(Serial.read());
  }
}

and here is the code for Arduino mega which is emulating a send and receive
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial1.begin(9600);    //Transmit
  Serial2.begin(9600);    //Recieve
}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()>0)
    Serial1.print(Serial.read());

  if(Serial2.available()>0)
    Serial.print(Serial2.read());
}

When I Send an Charater(Single) I receive something like this
for "s" - 5257525753515257534952575256
for "d" - 5257525652565257534952575256
Kindly help

use Serial.write to write a character returned by read

That does work. Thanks @Juraj

Serial.swap() function swaps the Serial to pins 15 and 13


text:
Does the Arduino pro-micro 3.3v use an 8MHz crystal or a 16MHz crystal with a clock divisor of 2?
I am trying to convert some 5v Leonardo-compatible boards to run at a lower 3-3.7v voltage, so that I can power my project using LiPo batteries.
As far as I can tell, the default Leonardo settings (and pro-micro settings) will not run at this voltage. When I power the boards (which expect 5v) from a lithium battery, typically the system does not start at all. My two theories are that either the 16 Mhz xtal oscillator does not start resonating, or that the brown-out detection of the boards precludes booting at the lower voltage.
I would like to modify the boards to run on lower power. Since the pro-micro exists in a 3.3v variant, I presume there is some way to get the Atmega32u4 chip working at lower voltages. I have reviewed the Atmega32u4 datasheet and schematics from sparkfun, as well as examined the fuse bit differences between the 3.3v and 5v versions of the pro micro. As far as I can tell, the only difference in configuration is the brown-out detection. The clock source settings are configured for a crystal between 8Mhz and 16Mhz, so this could be the same for both boards.
I wasn't quite able to understand the build system for the Catarina bootloader, which might give hints as to how the clock is handled. It seems like both the 3.3v and 5v boards bootloaders are built from the same source, but with a different "CPU frequency" variable. However, there are quite substantial differences in the .hex file outputs and I wondering if there is something fancier going on.
As far as I can tell, it's possible to get an 8MHz clock on the Atmega32u4 either by using a 16MHz xtal with a clock divisor of 2, or using an 8MHz xtal with a clock divisor of 1.
Since the pro-micro 3.3v is the "mainstream" supported board using the Atmega32u4 at a lower voltage, I would like to configure my project to be compatible. Which means I need to build in a compatible clock source, if possible.
Does anyone know more details of the pro-micro 3.3v/8Mhz configuration that might help clarify how to set this up?

When a 16MHz xtal is used with a clock divisor, then the clock part of the atmega32u4 is still running at 16MHz. I doubt if it is documented what it will do with lower voltages. You need a 8MHz xtal (or the internal resonator) to run it at 8MHz. The bootloader is described in the file 'boards.txt'. Not every atmega32u4 bootloader at 8MHz needs to be the same. Adafruit has an atmega32u4 at 8MHz as well: https://www.adafruit.com/product/3675 Try to use the official arduino boards if possible for the best and long lasting support.

So the pro-micro 3.3v uses an 8MHz external crystal?

I'd assume Adafruit uses different crystals. Not doing so would be weird. When building the bootloader, the compiler knows the crystal's speed by the F_CPU constant. It uses this to set F_USB, and (make the leds blink in the same interval](https://github.com/adafruit/Caterina-Bootloader/blob/917e066d83eef0d56222b5e2b518db4805637ce5/Caterina.c#L216). I think, before building these, some Adafruit employee changes the makefile to have the correct F_CPU, PID, and fuses for either the 3V of 5V version.

I have a partial solution: one can simply overclock (i.e. allow the Leonardo to run at 16MHz despite the lower power). Presumably this is risky and could lead to bad things eventually. (I've bricked one board actually by not setting a slower baud rate for writing fuses). One must simply set the brown-out detector for the lower voltage. The fuse configuration for this is E:CE, H:D8, L:FF. This is the same fuse configuration used on the pro-micro 3.3v, with an 8MHz XTAL. It turns out that the same clock fuse settings work with both the 8MHz and 16MHz xtals.

On the schematic of the Sparkfun Pro Micro 3.3V/8 Mhz (here) a resonator of 16 MHz is drawn. But also is stated there: "Board is marked with combination of resonator frequency and regulator voltage". From this you can deduct that the 3.3V/8MHz and the 5V/16MHz versions don't have the same resonator and that the 3.3V/8MHz version most probably has a 8MHz resonator.


text:
Moving a character around an LCD screen - is there a better way?
I have some basic programming experience but I am a novice at both C and Arduino.
I messed around with the example LCD code to try to move a character around with the onboard keypad. I also wanted the actual move to occur only once the button is released, like you would expect from a keypad.
The code works, but I have a feeling all the empty WHILE loops inside the main loop() function I used are not the best practice.. :)
How did I do? Is there a more convenient/elegant solution I missed and can learn from?
Thanks, and sorry for the messy code!
void loop()
{
  lcd.clear();
  lcd.setCursor(posCol,posRow);      //initialized beforehand
  lcd.print("O");                    //random char to move
  lcdOld = btnNONE;

  while (read_LCD_buttons() == btnNONE)     //do nothing while nothing is pressed
  {
  }

  lcdOld = read_LCD_buttons();

  while (read_LCD_buttons() == lcdOld)     //do nothing while button is down
  {
  }

  switch (lcdOld)               // depending on which button was pushed, we perform an action
   {
   case btnRIGHT:
     {
     posCol++;
     break;
     }
   case btnLEFT:
     {
     posCol--;
     break;
     }
   case btnUP:
     {
     if (posRow == 1)
     {
        posRow = 0;
        break;
     }
     else
     {
     break;
     }
     }
   case btnDOWN:
     {
     if (posRow == 0)
     {
        posRow = 1;
        break;
     }
     else
     {
     break;
     }
     }
   case btnSELECT:
     {
     break;
     }
     case btnNONE:
     {
     break;
     }
 }
}

This is fine, as long as you don't want you program to do anything else at the same time (like blinking an led for example). If you want that, you could just make the code remember the last button states, and only run the switch part of the code when any button goes from not being pressed, to being pressed. (PS remember to take button bounce into account, as that can mess things up. Not sure if read_LCD_buttons() already takes care of that)

I know it is been a while since you post this post but is there any way you can repost the whole source code?

You could encapsulate the logic of detecting a button release into its
own function:
// Return the button that was just released, or btnNONE.
int releasedButton()
{
    static int last_button = btnNONE;
    int previous_button = last_button;
    last_button = read_LCD_buttons();
    if (last_button == btnNONE)
        return previous_button;
    else
        return btnNONE;
}

Then the logic in the loo gets simplified:
void loop()
{
    switch (releasedButton()) {
        ...
    }
}


text:
Lost AT+ commands on ESP8266 after flashing with "blink" sketch
I set my ESP8266 ESP-01 to flash mode and uploaded the example blink sketch on the arduino IDE esp example options. I know can no longer communicate with the ESP8266 using AT+ commands. I also cannot flash the device and can only receive the following message under baud 74880
"
 ets Jan  8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x0f
csum 0x0f
~ld
"
Anyone know how to fix this? Thanks.

Thank you Juraj!
I had attempted to update the firmware multiple times and after 6hrs of trying was giving up. I really thought I had trashed my ESP-01. My post here was my last attempt to resolve the issue. I tend to have a problem of not asking for help until I'm frustrated. I saw your comment, and even though I had already attempted to reflash with new firmware I realized that you knew something I did not, and hopefully I could still salvage the ESP-01. So I downloaded documents about the esp8266 and decided to give it another try. What I found is my ignorance had let me believe that the esp-01 was broken when it was functioning as it should. Anytime you upload new firmware it will replace the old (including the at commands, but that's what it suppose to do). I then found this page that brought to my attention the mistake I was making. I was flashing the files to the wrong address, and there are multiple locations where the "blank" file needs to be flashed to.     So all is back to normal. At commands have returned. Now I have to remove them again to upload my program :).
https://www.allaboutcircuits.com/projects/flashing-the-ESP-01-firmware-to-SDK-v2.0.0-is-easier-now
I almost forgot to mention, I also had to hard wire my GPIO0 pin to ground before flashing. I was originally pulling GPIO0 to ground with a button. However, even though the serial console showed that I had booted in flash mode the flash tool failed. Only after hardwiring the GPIO0 to ground would the flash tool work.

This has been flagged as not-an-answer, however the OP is allowed to answer his/her own question, and this answer seems to me to be helpful for future people with similar issues, so I'm going to decline this flag.

on Windows use Espressif Flash Download Tool to flash the AT firmware. Everything is on Espressif's site


text:
Difference between 3.3v & 5v
 Im quite new to arduino in general and i'm sorry for the beginner question.
could someone explain what the 3.3v and 5v on boards do? I know their voltages. but can you run one on the other? whenever i try to search about it i see people saying that most newer modules are running on 3.3v so they convert their 5v arduino to 3.3v. something about if you run one on the other it could break it.

the arduino I bought looks like it has both! is that even possible?
 I also purchased this LED matrix as I wanted to make a wifi enabled scrolling text display. the matrix says it requires 5v. since this arduino says vin is 5-12v the two should connect and work properly, right?

The first link is to Amazon and shows a dev board with ESP-12F and USB connector. the other link is a dot matrix with max7129.

the main question here is "will the 3.3 V clock and data signal be read by the 5 V max7129 chip?"

I was not sure if I understand the max7129 datasheet, so I didn't write an answer. CrossRoad gives you an answer. It will not work. You must use logic level conversion.

The difference for different voltage boards lies in the parts, that are soldered on it. Often microcontrollers support more than one supply voltage, but impose different performance limits on the system. Take for example the Arduino Uno: It uses the Atmega328p, which can run both on 3.3V and 5V. But on the UNO there is a 16MHz quartz, which generates the controllers clock signal. The Atmega328p cannot run 16MHz with only 3.3 volts. To run a board on a voltage, for which it wasn't directly build, mostly requires you to resolder it with the correct parts.

whenever i try to search about it i see people saying that most newer modules are running on 3.3v so they convert their 5v arduino to 3.3v

There are special chips, called voltage regulators/converters. They come with various working principles, but basically they are converting one voltage to another. The Arduino Uno has one connected to Vin, so that you can apply between 7V and 12V to Vin and the Arduino itself will only see the 5V it get's from the regulator. Some modules also have a voltage regulator, but not all. Be careful not to provide more than the specified voltage to any board or you may destroy it.

the arduino I bought looks like it has both! is that even possible?

First, as Juraj wrote, this is not an Arduino. It is an ESP8266, a totally different chip and board. But you can also program it through the Arduino IDE, without it being an Arduino. Second: When they write, that you can provide it with either 3.3V or 5V, they mean, that you can provide 5V through the USB jack and a voltage regulator will convert it to 3.3V for the ESP, which runs completely on 3.3V. You should not connect 5V to any other pin.

since this arduino says vin is 5-12v the two should connect and work properly, right?

As stated above the 12V is only, what you can at maximum provide at Vin. The ESP8266 runs on 3.3V, so you will have to provide 3.3V (or more over the Vin pin). The LED matrix runs at 5V, as you stated. So you need a 5V source and a level shifter for the 2 lines between the ESP8266 and the matrix. If you connect them directly, you would damage the ESP8266. So: No, you cannot use it directly. It is up to you, if you want to use a level shifter or buy another matrix display, which can be controlled by a 3.3V signal.

in the last section you assume Uno. OP wants to connect the matrix to esp8266. the matrix has a control chip which communicates over 2 pins clock and data. will the 3.3 V signal be good for  max7129?

Ah, I misread the question and didn't know, that he already has an ESP8266. I will edit my answer

the esp8266 will not be destroyed. it can tolerate 5 V communication over digital pin. and I doubt there is any  from the max chip to esp. but the 5 V chip will not understand the 3.3 V as HIGH

As seen in the OEM data sheet for the MAX7219
https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf
the MAX7219 needs a supply voltage of 4 to 5.5V.
with a minimum signal voltage for High of 3.5V when Vcc = 5V.
Folks often get counterfeit parts from e-bay or elsewhere, with unknown characteristics.
For best results, I would power the '7219 from 5V, and use a buffer chip powered from 5V, such as 74AC125,
http://www.onsemi.com/pub/Collateral/MC74AC125-D.PDF
which will take ~ 2.5V with Vcc = 5V
to boost the ~3V output from the ESP2855 to 5V levels.

who and why down-voted this answer? (it zeroed my upvote)


text:
rotary encoder spamming output
im building my second arduino project. Im very new to this all so I could certainly use some help fixing everything.
Im trying to make a controller for a pc port of an arcade game. It uses two rotary encoders, something I never heard about before going into this project

 I had found some code on github that works perfectly in my case, but the code has the rotary encoders move the mouse. something that dosent work for the games controls unfortunately (i tried)

so i attempted to change them and now they do spit out text like i need them but when i rotate them instead of getting the needed out put of
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

i get something more along the lines of
babababababababababababababababbabb

like if im turning the knob both ways at the same time when im just turning it one direction.
heres the code im working on
/*
* By Daniel Tam (daniel@danieltam.net)
============ NOTES ============
This will create a SDVX Controller using an Arduino Leonardo.
You will hook up one wire of the button to the Arduino pin and the other to Arduino's ground. When pushed, the button should go to ground.
You will need to download the encoder library and use it in your project for this to work (ww.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino)
===============================
*/

// buttons
#include <Mouse.h>
#include <Keyboard.h>
#define BT_A 2
#define BT_B 3
#define BT_C 4
#define BT_D 5
#define FX_L 6
#define FX_R 7
#define BT_ST 8

// encoders
#include <Encoder.h>
Encoder enc1(15, 14);
Encoder enc2(16, 10);
float knob1 = 0;
float knob2 = 0;
float old_knob1 = 0;
float old_knob2 = 0;

void setup()
{
  // set pins to read, and output high
  // when the pins read low, we know that the buttons have went to ground (aka, pushed down)
  pinMode(BT_A, INPUT);
  pinMode(BT_B, INPUT);
  pinMode(BT_C, INPUT);
  pinMode(BT_D, INPUT);
  pinMode(FX_L, INPUT);
  pinMode(FX_R, INPUT);
  pinMode(BT_ST, INPUT);

  digitalWrite(BT_A, HIGH);
  digitalWrite(BT_B, HIGH);
  digitalWrite(BT_C, HIGH);
  digitalWrite(BT_D, HIGH);
  digitalWrite(FX_L, HIGH);
  digitalWrite(FX_R, HIGH);
  digitalWrite(BT_ST, HIGH);

  Mouse.begin();
  Keyboard.begin();
}

void loop()
{
  // read encoders
  knob1 =  (float)(enc1.read());
  knob2 = (float)enc2.read();

  if(knob1 != old_knob1)
  {
    // if there's a difference in encoder movement from last pass, move the mouse
    if(knob1 < old_knob1)
    {
     // Mouse.move(0, -5);
      Keyboard.press('a');
      delay(100);
      Keyboard.release('a');
    }
    else
    {
    //  Mouse.move(0, 5);
      Keyboard.press('b');
      delay(100);
      Keyboard.release('b');
    }

  // we count the difference in the encoders, but we must not go over arduino's int limit
    if(knob1 < -255)
    {
      enc1.write(0);
      old_knob1 = 0;
    }
    else if (knob1 > 255)
    {
      enc1.write(0);
      old_knob1 = 0;
    }
    else
    {
      old_knob1 = knob1;
    }
  }

  if(knob2 != old_knob2)
  {
    if(knob2 > old_knob2)
    {
     // Mouse.move(-5, 0);
      Keyboard.press('c');
    }
    else
    {
     // Mouse.move(5, 0);
      Keyboard.press('d');
    }

    if(knob2 < -255)
    {
      enc2.write(0);
      old_knob2 = 0;
    }
    else if(knob2 > 255)
    {
      enc2.write(0);
      old_knob2 = 0;
    }
    else
    {
      old_knob2 = knob2;
    }
  }

  // read the buttons for low, if it's low, output a keyboard press
  if(digitalRead(BT_A) == LOW)
  {
    Keyboard.press('f');
  }
  else
  {
    Keyboard.release('f');
  }

  if(digitalRead(BT_B) == LOW)
  {
    Keyboard.press('b');
  }
  else
  {
    Keyboard.release('b');
  }

  if(digitalRead(BT_C) == LOW)
  {
    Keyboard.press('c');
  }
  else
  {
    Keyboard.release('c');
  }

  if(digitalRead(BT_D) == LOW)
  {
    Keyboard.press('d');
  }
  else
  {
    Keyboard.release('d');
  }

  if(digitalRead(FX_L) == LOW)
  {
    Keyboard.press('z');
  }
  else
  {
    Keyboard.release('z');
  }

  if(digitalRead(FX_R) == LOW)
  {
    Keyboard.press('x');
  }
  else
  {
    Keyboard.release('x');
  }

  if(digitalRead(BT_ST) == LOW)
  {
    Keyboard.press('n');
  }
  else
  {
    Keyboard.release('n');
  }
}

Your aren't using the recommended pins to attach the encoders. Because of this the library isn't using interrupts, but depends on you calling encX.read() often enough, to not miss any changes. This, combined with the 100ms delay in your code, will almost guarantee that you will miss some changes, making the library think you are rotating the other way around.
Change the pins to 0, 1, 2, 3 (or at least one of those for each encoder).
Otherwise lower the delay to for example 1ms. I couldn't find whether this delay is even necessary, or how long it needs to be, so you'd have to experiment a bit, and see what works.
Lastly; why are you using float to store the position? Try using long instead, as that's the type enc.read() returns.

was there a first part that got cut off?

Sorry, I had to change the order around. Nothing missing.

changing pins to 0,1 seems to do exactly what i need!
I had the delay in as a test as im still learning and as for the floats that's part of the original guys code so im not too sure.

actually i seem to intermittently get the old result, seems to work sometimes.

nvm seems most of my issues stem from a wonky breadboard thats connecting the pins or something.


text:
How to prevent optocoupler to activate when resetting the arduino?
From various example on how to use optocouplers ( eg 4N25)  I gathered that they
work in inverted way meaning that for the optocoupler to output a signal,
the input LED must be OFF.
This is very easy to process by code as I just need to use digitalWrite LOW
instead of digitalWrite HIGH to activate the output of the optocoupler.
My problem is that when I reboot the arduino, the optocupler LED goes OFF and thus activate the ouput of the optocoupler for a few seconds until the code is loaded on the arduino.
How can I prevent this behavior ? Should I connect the optocoupler in a non inverted way ? ( And if so how ? ). Should I use an inverter ?

An optocoupler has no "default" way of working - inverted or non-inverted. It all depends on how it is wired up.

Thanks for the answer Majenko. It seemed to me that most of the time they were presented as inverted though. Is there a reason for this ? Practicability ? Performance ? Or maybe I got the wrong impression.

What controls optocoupler in your case? https://electronics.stackexchange.com/a/219882/141930

Show your circuit or we cannot help you.

The Fairchild datasheet for 4N25 shows this diagram:

describing the (or 'an') operation of the device. If this is how yours is operating, and if the input side is connected between an output pin and ground, then yes, on reset, the LED will go out and the switched output will go high. If you connect the device's input between the pin and +5v, the LED will light on reset, taking the switched output low. Plus, the switched output will now have the same sense as the Arduino output pin: i.e., digitalWrite(PIN, HIGH) will turn the switched output on, and vice-versa.


text:
ESP8266 Missing data from Serial
I'm trying to read all the available access points nearby with an ESP8266 module.
Whenever I try to read all the available data from the ESP module and write it to the Monitor Serial it truncates text. Text often also a bit messed up.
I'm using an Arduino Uno with the following scheme (I'm using pins 2 & 3 NOT 1 & 0):

#include <SoftwareSerial.h>

SoftwareSerial esp8266(2, 3);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);

  esp8266.begin(115200);
}

void loop() {
  while(esp8266.available()) {
     Serial.write(esp8266.read());
  }

  while(Serial.available()) {
    esp8266.write(Serial.read());
  }
}

The code prints something like the following:
AT+CWLAP

+CWLAP:(3,#SBanaan",-73,"4c:09:d4:d5:d6:f2",1,,2,0)
+CWLAP:(3,"UPC24923"CH7"0,L5-:d6Ai0:,
,,f5
44"f"CZ7f1
4-"6:0:4-95
,5-3d0

As @JoseCanUC has mentioned SoftwareSerial is not reliable at 115200 baud. This is because the bytes are sometimes too close together for the Arduino to start receiving a new one when the start bit arrives, and so the byte starts being received part way through, thus corrupting it.
You should investigate setting the baud rate of the ESP8266 to 9600, although this itself comes with its own set of pitfalls. You should be prepared to re-flash the AT firmware to reset the baud rate if it all goes wrong.  I would seriously suggest investing in one of the many cheap USB programming adaptors for the ESP-01 on eBay, since it makes working with these devices so much simpler.  It also opens up the possibility of creating and installing your own firmware for the ESP8266 instead of using the somewhat clunky AT firmware interface.

Even better might be to look at the Wemos D1 mini or NodeMCU products, which break out a lot more GPIO pins from the ESP8266, and have an on-board USB-TTL converter.

Indeed - though they are physically bigger. If you want to get into programming them then yes those are far more convenient. However if all you want is a small WiFi interface for an Arduino or similar board then the small size of the ESP-01 is quite convenient - just hard to program without an adaptor.

Thanks for the detailed explanation and suggestions, it helped a lot! The following command did the trick including changing the baud rate in code ass well: AT+UART_DEF=9600,8,1,0,0

For SoftwareSerial, at 115200 bps data rate is not going to be reliable. Try 9600 bps.

I'm a bit confused by your diagram showing no ATmega chip on the Uno board, but you posted Uno code that should properly communicate with your ESP (except for the baud rate being too high for SoftwareSerial).
See my answer to another ESP question for how to change the ESP's baud rate, especially the code fragment at the bottom of that answer.
Changing the ESPs parameters is not difficult as long as its AT firmware is intact (which it will be if you haven't attempted to re-flash the device). Changing baud rate is only slightly tricky, in that once the Uno has told the ESP to change its baud rate, the Uno must also change its baud rate to match before you can re-establish communication with it.

You are right, everything worked except the baud rate. That was the problem. Setting it to 9600 worked.