text:
Arduino reading screen color from device (without light/color sensor)
I am a beginner working on a project in which I have purchased a device that can display 4 colors on the display (blue, green, yellow, or red). I would like the Arduino to read what color is on the display and depending on the color supply power to an attached motor. For example, if the screen is green supply power to the motor, if screen is yellow or red or blue do not supply power to the motor.
On the circuit board of the attached device there are clearly labelled wires connecting the LCD display to blue, green, and red LED solder points.
Is it possible to read the current going through these wires to determine what color would be displayed on the LCD display? If not, are there any other suggestions which could work?
As I mentioned earlier, I'm a complete beginner so anything would help. Thanks.

A rgb lcd display? as the one that adafruit has? https://www.adafruit.com/product/398

Do the colors you are interested in seem like an RGB LED backlight to the LCD?     Please add some pictures.  And can you measure the voltages at the RGB LED solder points when the colors of interest are happening?

The pics look fairly straightforward.  If the voltages while on and off are within the Arduino input limit range range, you should be able to read and decode them easily.   It might be as easy as configuring three digital input pins, and some code like lights = (digitalRead(D1) <<2) | (digitalRead(D2)<<1) | digitalRead(D3) ; switch(lights){ case 1: /* green */ .....

what is the device in the picture? ..... it has a UART port ..... perhaps you can use the serial port to ask it about the color


text:
Why is AREF connected to a capacitor in the Arduino Pro Mini Schematic?
I'm currently looking at the Arduino Pro Mini schematic and have noticed that the pin AREF (analogue reference) is connected to a 0.1uF capacitor as shown below:

I have done some research and read this great explanation into AREF and now understand its purpose as a voltage reference. What I do not understand however is the purpose of the capacitor. Is it as a means of stabilising the pin when an external voltage is applied, or something else?
A full schematic of the Arduino Pro Mini can be sourced from here.

That has clarified part of my question. I will rephrase my post.

On the datasheet for the Atmega328P, in the Analog-to-Digital Converter section, is the sentence:

The voltage reference may be externally decoupled at the AREF pin by a capacitor for better noise performance.

Also:

The internal voltage reference may thus be decoupled by an external capacitor at the AREF pin to improve noise immunity.

Thus the capacitor is there to reduce noise on the AREF pin.

An ideal capacitor presents an impedance of wC (radian frequency * capacitance -- ohms).  Of course ideal capacitors do not exist in real component selections or circuits and all include parasitic losses and inductance. The parasitic components depend on the type of the capacitor, lead length, connecting circuits, etc.  Oscilloscopes, network analyzers and spectrum analyzers serve to identify fundamental performance of voltage reference points.
The decoupling capacitor should be connected using short leads to a ground plane layer and the Aref pin.

Rather than provide a generic answer which may or may not assist the individual using the pin, I added information to guide selection of a capacitor.  Simply adding a 0.1uF capacitor may or may not resolve a specific noise condition and in fact may worsen the issue.

source: Stack Exchange

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

sort: votes


text:
Read the image value pixel by pixel
I need your help in SD card and image. It's been a week since I have involved with this problem, So I wish you can help me.
Here is the problem:
I saved a photo to the SD card and now I want to read the color information of each pixel and put the servo in a definite position based of the pixel color.
I want to read pixel by pixel information in a row and after completing a row reed the next row.
The image has 2000*2000 pixels in BMP format, but I can change the format if it is necessary and the picture consist 100 colors, so it means the servo should have 100 different position.
I can also take photo information as a CSV file with 2000 rows and 2000 columns as int values and save the .csv file to the SD card.
it would be grate if someone can help me.

Please add any code/sketch that you have already written. Also add more details with what specifically you need help with. This is very unclear right now.

https://en.wikipedia.org/wiki/BMP_file_format

are you saying that you would like the servo to be positioned 4 million times?

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


text:
NodeMCU ESP32s can't get Vin to work?
Trying to power the board with a 9V battery through VIN. As the documentation says, it can take input voltage of 6-12 Volts, but when I connect the 9V battery, all it does is power the board on and nothing else happens.
Anyone know what I am doing wrong?
EDIT: I am stupid had the ground connected to the wrong pin thanks for the help everyone.

What kind of 9V battery?

Just a regular 9V E-Block Battery.

Yes, but what chemistry?

Assuming you are using a 9V block battery: They don't deliver the current you need for the esp32 to run/create an access point/act as a client. What you can do is connect 6 AA batteries in a row (6*1.5V = 9V) and they will deliver a higher current than the 9V block.


text:
NodeMCU with JHD162A LCD issue
I have uploaded a program to NodeMCU , to print "hello, world" on JHD162A 16x2 LCD module. But the text doesn't appear on the lcd display. Instead just black blocks appear on the first row on the LCD. I assume it's a hardware related issue since the software worked in simulation. I powered the NodeMCU and the LCD using 5V DC from 7805 voltage regulator IC. The 12v input to the IC is provided using a 230V AC  to 12V DC adapter with 2A max current out. I have placed a 680 ohms resistor to the anode of the lcd back led, also a 1K resistor between the Vss and Vee of the LCD to set contrast. I am using D0, D1, D2, D3 pins of the NodeMCU to the D7, D6, D5, D4 data pins of the LCD. The RW is connected to the gnd pin of NodeMCU. The RS and E pins are connected to the D8 and D7 of NodeMCU.
#include<LiquidCrystal.h>

const int RS= D8, EN = D7, d4 = D3, d5= D2, d6 = D1, d7 = D0;

LiquidCrystal lcd(RS, EN, d4, d5, d6, d7);

void setup()
{
lcd.begin(16, 2);
lcd.print("hello, world!");
}

 void loop()
{
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
}

Avoid using D8 (GPIO15), D4 (GPIO2) and D3 (GPIO0) as they have special boot-controlling uses.

@Majenko That worked ! Thank you so much.


text:
Arduino New Optiboot Bootloader on custom ATMega328p board, ATMEL Studio and AVRdude
I am about to ask a kind of complex question due to the number of system parts involved and the system architecture I am planning to use.
First of all I have a tiny bit of experience with the Arduino Nano and a professional experience with C microcontroller programming.
What I would like is to create a custom ATMega328p board that does something and be able to update whatever firmware is running on it using the UART port.
1) Firmware updating
Since I am not so familiar with bootloaders, I would skip for now writing my own, so I would like to use the newest Arduino Bootloader for ATMega328p to support the firmware updates.
2) Custom program compilation
What I definitely do NOT want is use Arduino Sketch IDE to compile whatever application code. I am using Atmel Studio up to now for whatever bootloaderless applications I was doing and I would like to keep using that with my own project and code structure. The question here is, do I need to make any linker modifications or modifications in the code in Atmel Studio projects in order to be able to "transform" my code into application code so that can coexist with the bootloader?
3) Updated firmware programming
After the board is on the field running with the Optiboot bootloader and an outdated firmware, I would like to use a thirdparty software to communicate with the bootloader and update the application code. Since the optiboot bootloader used by Arduino uses the STK500 communication protocol and functionality, could I use AVRdude to communicate with the bootloader and flash the applications code only through UART?
Do you think this concept could work?
Thank you in advance.
polylogic

your question boils down to asking if it is possible to build an Arduino UNO

ask and discus AVR questions on https://www.avrfreaks.net/forum

Since I am not so familiar with bootloaders, I would skip for now writing my own, so I would like to use the newest Arduino Bootloader for ATMega328p to support the firmware updates.

Even people who do know about bootloaders rarely bother writing their own when there is a perfectly good one with good support and good cross-platform tools available.  Why would you?

The question here is, do I need to make any linker modifications or modifications in the code in Atmel Studio projects in order to be able to "transform" my code into application code so that can coexist with the bootloader?

No. The bootloader resides at a high memory address, and your code at address 0x0000 just like normal.  A fuse is set to say "Boot at the bootloader address", and another lets you set the size of the bootloader area (and thus the bootloader address).

Since the optiboot bootloader used by Arduino uses the STK500 communication protocol and functionality, could I use AVRdude to communicate with the bootloader and flash the applications code only through UART?

Yes. This is what the Arduino IDE does. It just runs avrdude to communicate with the bootloader.  If you turn on verbose mode in the preferences you should be able to see what the exact command is that it runs so you can replicate it in your own program or script.

I would add that the only purpose of the bootloader is flashing over UART.

@Juraj Sure, if you want to state the obvious.

Majenko! Thank you so much for the answer!It seems that this is pretty standard since I managed to compile a custom program in Atmel Studio and load it to the uC via cmd avrdude. Im not sure if I need to post a different question but I was wondering the following; in order to increase security:
I could modify the optiboot code to first receive a predetermined set of chars via UART before it goes into STK500 mode.Would that be doable?Apart from cold-reset, I would like to be able to call the bootloader from the app code. How could I call it and should I reset some registers before I call it?

That would constitute a new question. I'm not going to be able to answer those in comments.


text:
AC dimmer not smooth dimming
I am trying to create a phase control AC dimmer. But I am not able to achieve smooth dimming. I am using this guide for the circuit:
Link
On the zero detection part I am able to detect its zero crossing, but the output of the zero detection circuit is not a perfect square wave, it's kinda sinoidal.
So I have created my own code that when it reaches a value above 900 (very close to 0v) it will trigger the triac. I am using an Arduino Micro:

#define TPulse 10
#define SW 7
#define ldr A0
#define zeroDetector A1

int x;
int delayDuration = 100;
long int count = 0;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH); // pull up
  pinMode(TPulse, OUTPUT);
  pinMode(SW, INPUT);
  digitalWrite(SW, HIGH);
  digitalWrite(TPulse, HIGH);
}

void loop() {

 delayDuration = map(analogRead(ldr), 0, 1024, 0, 9000);

 x = analogRead(zeroDetector);

 if (x <= 900)
    isr();

}

void isr () {
  digitalWrite(TPulse, LOW);
  delayMicroseconds(delayDuration);
  digitalWrite(TPulse, HIGH);
}

I have calculated that in a 60Hz AC it will cross zero voltage 120 times a second thus the delay should be in range of 0 - 8300 microseconds.
But I am not able to achieve a smooth dimming, I am getting either of, flickering, fading (uncontrolled), and so on.
Is there something wrong with my analogy or am I missing something crucial?
I have replaced the LDR with a trimmer pot so I can easily adjust the resistance.
I trying to not use interrupt as of the moment. I am trying to achieve this type of dimming:

you can use a schmitt trigger to make a clean square wave from the analog signal. You might not want to use delays, which can cause sync issues if things get busy.

first sir i will agree with you that it works with interrupt. but i wanted to go with an approach without using interupt, i am confident that with 16mhz micro it can detect every zero cross

@dandavis , i dont think there is a work around to that since i will have to delay for a microsecond to chop the ac voltage

it depends on your "frame rate"; how many times loop() fires. I would only check the level-setting input 1 in 5 loop()s to keep the lanes open for your zero-cross.

I apologize sir i could not get what you mean by your last statement. by check level setting you mean the zero cross right?>

looks like you are leaving the triac turned on ...... digitalWrite(TPulse, HIGH); should be followed by digitalWrite(TPulse, LOW); ....... the triac shuts itself off automatically at zero crossing once it is triggered ..... you only need to send it a short pulse to trigger it

Yes, jsotola 30 is right, you leave the triac gate on until next zero crossing but the short delay from real zero to detection might cause the tyristor to open


text:
Servo or motor with manual control
I am searching for a servo or motor with the ability to
easy manually controlling (turning) when power off.
What is the mechanism recommend to use?
Thank you for your answer.

please explain how your question is about the Arduino ....... arduino-uno and arduino-nano tags do not count

Motor that has no gearbox will be easier to manually turn when it is not powered.
Now, I don't know what you categorize as "easy" but this info will give you a starting point.
And I don't get why the use of the "arduino-nano" and "arduino-uno" tag


text:
Will a 12 VDC 1A Power Supply Adapter supply too much power and damage an Arduino Mega 2560?
The specs shown here:

show that it has 54 digital pins with each outputting a DC current of 20mA which makes it 54 * 20 = 1080 mA
Plus the DC current of the 3.3V Pin of 30mA we get a total of 1110mA.
Is this how one should go about doing the computations?
If the adapter is insufficient will a 12 VDC 2A Power Supply Adapter be appropriate or excessive?
Any links to read up on will be greatly appreciated as well.
Links for this question:
https://store.arduino.cc/mega-2560-r3
https://store.nerokas.co.ke/index.php?route=product/product&product_id=567
PS: All I'm planning to connect to the board is: 'a PIR sensor (the first version not Rev B)', a '5V relay' and possibly a 'ESP8266 ESP-01S Relay Module'

You may be able to draw 20mA from a pin, but you cannot draw 20mA from each pin. The absolute max is 200mA for entire package.

Incorrect re: 200mA max. There are 4 VCC/4 GND pins, rated for 200mA each, so the uC chip can potentially support 800mA.  This is straight from Atmel tech support.  Further, there are limits to how much each port can support as seen in the notes of Table 31.1 of the datasheet, page 356, document # 2549Q–AVR–02/2014. There may be a later revision at www.microchip.com (they bought Atmel a while ago and have been re-releasing data sheets).  20mA as a max is good usage, more current than that and highs may drop to <4.2V, and lows may rise to > 0.9V.

No. You have everything wrong there.
First off, a power supply does not provide power. It provides voltage. The device attached to it then draws current. As much current as it needs at any particular moment in time.  The current rating of a power supply is the maximum that the power supply can give.
The same goes for Arduino IO and power pins: The current ratings are the maximum current you can draw from the pin.
Exactly what current it will draw from the power supply depends completely on what is connected to what pins, and even what calculations the Arduino is doing at the time.  To get a ball-park figure of current requirements you need to know the current requirements of whatever is attached. If a device has its own power input that is the current you need to worry about. If a device is powered directly from an IO pin (such as an LED) then that forms part of the Arduino's current (which starts at about 40mA or so for the board itself).
There are many other factors to take into consideration:

The 5V regulator on the Arduino can't give more than 1A maximum, and considerably less than that when powered from a high voltage like 12V.
The DC jack on the Arduino is limited to 1A due to a polarity protection diode.

It is usually recommended to use a separate 3.3V regulator for an ESP8266 module (or 5V if your module has a built-in 3.3V regulator) due to the lack of power capacity in the Arduino's on-board regulators.
As a rough guestimate:

Arduino: 40-60mA
ESP8266: 200mA (when transmitting)
PIR: Negligible
Relay: 50mA when active

So you'd be looking at 300mA as a minimum. More is better. 1A should be more than sufficient. 2A would be overkill but give a big margin of error.
For everything you have there, it would be better to use a 5V power supply, not a 12V power supply.

Good answer, but one comment: It’s my understanding that the Arduino itself is fairly dumb about power management and runs all it’s subsystems at full power, so what it’s calculating doesn’t have a lot of influence on its power consumption (in contrast, modern high end CPUs have sophisticated power management systems, and throttle down subsystems when you’re not using them.)

It is fairly dumb, yes. Maybe calculations isn't the right word. What internal programs are doing what at any given time has a large bearing. You can also shut down portions of the chip, and enter various sleep modes to reduce power. Different instructions do use different amounts of power though, depending on what they do.

I would bet driving the various interface subsystems would have a fairly large influence on power. Those GPIO lines have fairly “stiff” gates, the UARTS and other subsystems, etc. For that matter the LEDs on the board draw not-insignificant power.

In addition to what Majenko told you, some additional information:
The Arudino uses a linear power supply. That type of power supply works by converting all the excess voltage above the output voltage to heat. So if you feed it 12V, at 1A, it has to convert 1 amp of  12V-5V, or 7 watts of power to heat. The heat sink on the Arduino is not up to dissipating 7 watts of heat.
A linear power supply needs a little more than the output voltage. Feeding it 7.5V would be just about right. You should be able to get a full amp of 5V out of the Arduino’s power supply if you feed it 7.5V at the input, although the output voltage will probably droop some as you approach the max output, and it will get hot. Don’t put it in an airtight container.
As Majenko says, you shouldn’t add up the max current output of every pin on the Arduino to get its power requirements. A digital output line will use almost no current unless it is feeding an output that draws current. Think of the power supply as a spring-fed well, and the output as scoops that scoop water out of the well. As long as you don’t scoop water out of the well faster than it can be replace by the spring, you’re ok. If you only use a couple of small scoops, you’ll hardly take any water out of the well. (If you only have a couple of low power outputs connected, you’ll only draw a small amount of current.)
The Arduino draws a moderate amount of current all by itself. See the specs for details.


text:
Arduino powering to control sensors
I would like to know if it's possible to power up arduino by VIN pin (say 9v) and use 5v output pin to connect to a sensor.
Many thanks

Yes. It is. That's why it's called VIN. Voltage INput.

depends on how much current is required by the sensor to function correctly

Hello. Thanks for the replay! The sensor works with 5V but the manufacture says "External power supply (7~12V) is necessary to supply the microcontroller board when you using this CO2 sensor module."


text:
Cannot set MOSI pin low even after ending SPI
I'm building a battery operated device and must shutoff MOSI pin during sleep because it leaks current through the SD card if I don't (about 400 µA).
Problem is, it won't stay off.  I've looked at SPI documentation and as far as I know I just need to call spi.end() then set pinmode to output and finally digitalWrite LOW.  I observe with an oscilloscope that it does go low upon my asking it to but only for about 1 µs (actually it goes low twice within a 5 µs time period).
I've also tried manually setting the pin low using the PORT registers and the behavior is the same... see relevant code:
spi.end();

//pinMode(pin_MOSI, OUTPUT);
//digitalWrite(pin_MOSI, LOW);

//Both above (commented out) and below result in the same behavior -- pin does not stay LOW

DDRB |= B00100000;            //set pin 5 as output
PORTB &= B11011111;           //set output low for pin 5

delay(5000);

...As you can see there is a delay to ensure that it isn't being set high by some other code.
Is there some sort of SPI interrupt that automatically sets the pin high again?
Hardware details:
MCU: ATMEGA1284P;
Programmer: Atmel-ICE

UPDATE (13-Mar-2019):
I didn't realize that SPI is implemented by Atmel in hardware directly (see datasheet page 105):

MOSI/PCINT13 – Port B, Bit 5
  – MOSI: SPI Master Data output, Slave Data input for SPI channel. When the SPI0 is enabled
  as a slave, this pin is configured as an input regardless of the setting of DDB5. When the SPI
  is enabled as a master, the data direction of this pin is controlled by DDB5. When the pin is
  forced to be an input, the pull-up can still be controlled by the PORTB5 bit.

I am currently chasing down this latest information and will hopefully come to a resolution soon.  I will post any progress.

is it a SD module with logic level conversion?

@Juraj: No level shifting, straight 3.3 volts to the SD card.

I thought you using SPI.begin() and SPI.end() to use the embedded hardware from the Arduino IDE. You are bit-banging instead?

@CrossRoads: I'm using SPIClass from <spi.h>.  I'm assuming that is part of the Arduino core but I'm not certain.  I have successfully gotten it to work by clearing the SPI enable bit (SPE) from the SPCR register so I know the library was not doing it for me.

@Juraj: I'm using ATmega1284P which is a 3.3 volt MCU -- doesn't have 5 volts.  Thanks!

my runs at 5V. default here is 5V.

@Juraj: Good point!  I incorrectly assumed the ATmega1284P was a 3.3 volt part but it can go as high as 5.5 volts -- mine is running at 3.3 volts as that is my designed VCC level.

You're not running 16 MHz are you? That could be unstable.  Speed grades: 0 - 4MHz @ 1.8 - 5.5V, 0 - 10MHz @ 2.7 - 5.5V, 0 - 20MHz @ 4.5 - 5.5V per the datasheet.

@CrossRoads: I thought I was running at 8 MHz but upon trying to verify found that indeed I am running at 16 MHz at 3.3 volts!  It had been working fine but no guarantee that there won't be issues!!  Using an external oscillator at 16 MHz -- I've figured out how to add a prescaler to slow the MCU to 8 MHz then changed the F_CPU field in boards.txt so that timing wasn't messed up in the Arduino code.  I think everything is finally working.  Thanks so much for the comment -- it wasn't yet a problem but I'm sure could have become a major issue under certain conditions (like maybe warmer temps)!

Indeed, SPI is hardware implemented.  I was able to get the MOSI pin to operate as intended by clearing the SPI enable bit from the SPCR register as follows:
SPCR &= 0B10111111;  //disable SPI

To re-enable after sleep, I'm assuming I'll just do SPCR |= 0B01000000; ...pretty sure that will work but I'll update here if I have to modify my solution.
.
Perhaps also pertinant information:
I was using an object of SPIClass in SPI.h which is from the Arduino core libraries -- for some reason it wasn't disabling SPI in hardware when calling the spi.end() method, maybe because there was some other SPI object initialized by some other library.  Here is the source from SPI.cpp for the end method:
void SPIClass::end() {
  uint8_t sreg = SREG;
  noInterrupts(); // Protect from a scheduler and prevent transactionBegin
  // Decrease the reference counter
  if (initialized)
    initialized--;
  // If there are no more references disable SPI
  if (!initialized) {
    SPCR &= ~_BV(SPE);
    interruptMode = 0;
    #ifdef SPI_TRANSACTION_MISMATCH_LED
    inTransactionFlag = 0;
    #endif
  }
  SREG = sreg;
}

The line SPCR &= ~_BV(SPE); should have done the job for me but I'm guessing it never got there because initialized was probably still non-zero.

If you didn't have #include <SPI.h> at the top of your sketch, how were you able to use SPI.begin(), SPI.transfer();  etc?

@CrossRoads: I did have SPI.h included -- sorry if that was not clear.

I thought I read something about not using the library, but I don't see it now. Perhaps I had two topics confused.  Glad you got it sorted.

Perhaps the SPI library got improved in the years that passed since this answer was written. spi.end() has the desired effect now. Setting/clearing the bit in SPCR is still faster though.

@DmitryGrigoryev: Take a look at the end() method that I copied from the core source files (above toward the end of my answer).  If the member variable 'initialized' (which is defined as uint8_t) is not zero then clearing the SPI enable bit in SPCR never happens.  I think the issue is that one of the libraries I was using called SPI.begin() but never called SPI.end() which means SPI was never able to deactivate.  I ended up rewriting the code without the other libraries and the problem was solved.


text:
Determine whether Arduino Uno board is faulty or not?
I'm just giving 9V supply to the Arduino Uno but along with its power led,  the transmission one is also blinking. Can anyone please tell me whether the board is faulty or not?

The RX and 'L' leds are off and the TX led is blinking and the power led is on? Then there is probably a sketch in the arduino uno that sends something to the serial monitor.

Use Arduino IDE, connect your Arduino to the PC, load examples -> Blink, program your Arduino and check if it does what supposed to do (if Blink loaded, then LED should blink only)

from the vast depth of information you have given, I can definitely tell you that the two LED's are not faulty

nobody can tell you whether the board is faulty  .... you have to  test it yourself


text:
WS2812B only works while I measure the voltage
I'm going crazy, there is clearly something I'm missing here.
I have a NodeMCU V3.0 and a 5V LED strip WS2812B with 10 diodes.
I tested this first with a 5V 0.3A power supply, only powering 3 diodes, this worked fine.
Than I changed the power supply to a 5V 2A (Measured to 5.2V) and now the colours are way off, they even change everytime its updating, even though nothing is changed. I put my voltmeter across "D3" and "GND" and suddently the LEDs were perfect and stable.
If I remove it again, the LEDs change to random colours again, I tried pulling "D3" to ground with a 10 kOhm resistor, but this doesn't change anything.
What is going on here, why isn't it working, and why does it work with the voltmeter?

Code:
#include <ESP8266WiFi.h>
#include <FastLED.h>

#define LED_PIN     3
#define NUM_LEDS    10

CRGB leds[NUM_LEDS];
int R = 255;
int G = 90;
int B = 10;

//Set up MQTT and WiFi clients
WiFiClient client;

void setup()
{
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  Serial.begin(9600);

  //Connect to WiFi
  Serial.print("\n\nConnecting Wifi... ");
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
  }
  Serial.println("OK!");
  pinMode(D4, OUTPUT);
  digitalWrite(D4, HIGH);
}

void loop()
{
    leds[0] = CRGB(255, 0, 0);
    leds[1] = CRGB(0, 255, 0);
    leds[2] = CRGB(0, 0, 255);
    FastLED.show();
    delay(5000);
}

Have you tried another pin?

Remove the resistor. There is also way way to use one WS2812 as a booster for the rest of the WS2812, check out http://www.elec-tron.org/wp-content/uploads/2015/10/ws2812bconverter.jpg

if the resistor in your DMM (likely 10m) pulls down the signal and makes it work, it stands to reason that you can simply add your own pull-down resistor to make it work the same.

That was my first thought as well, but adding a 10k OHM to pull down the data pin (same spot I measured) did nothing, so I’m still puzzled why measuring didn’t anything

WS2812B LEDs are 5V devices. The NodeMCU is 3V.  Your first 5V supply will probably have been somewhat under 5V once the NodeMCU had taken a big chunk of the current (see Voltage Droop). This would mean that the Logic High Threshold would be within the bounds of the 3.3V output by the NodeMCU.
However, with your new high powered power supply that voltage droop will be less prevalent (added to the fact that it's measuring 5.2V), and so the logic high threshold will be higher. At, or very close to, the 3.3V that is output by the NodeMCU. That makes it rather unstable at communicating, since the logic HIGH may not always be above that required HIGH threshold.
Adding your voltmeter obviously changes that logic signal so that it stabilizes above the required threshold (the volt meter input has capacitance. That will help hold the line higher for longer).
To drive 5V devices from a 3.3V MCU you really need to add a logic level shifter, or ensure that the power supply isn't too high.
The WS2812B has a logic HIGH of 0.7 × Vdd. At 5V that's (0.7*5=) 3.5V. That's close, but not quite there. Your original power supply was probably putting out more like 4.75V under load. That would be 3.325V for a logic high - just about manageable by a NodeMCU.
However at 5.2V the logic HIGH will be 3.675V, which is way above the 3.3V that the NodeMCU outputs.
So you either need to:

Add a 3.3V to 5V logic level shifter, or
Reduce your LED power input voltage to below 4.75V.

The latter can be done by adding a single series diode with a suitable current handling capacity to the VDD connection. That will (depending on the diode) drop around 0.7V taking you to about 4.5V (the actual drop usually depends on the current to a certain extent).  The WS2812B will happily run from 3.5V to 5.3V.

I think I understand, thank you
This diode, could it be like this: 1N4001 ? And will it create a loss of power?

I'd probably go for a 1N5402. The 1N4001 is only 1A rated. The 1N5402 is 3A rated. Yes, it will lose some power. But losing some power is what you want - you have too much at the moment ;)

@Yoshidk I think you can lower the voltage for the first chip only. Its output will be up to its power supply voltage

@Yoshidk Or, maybe adding diode between power ground and NodeMCU ground could provide the same service without cutting the LED strip.

I added a diode in series to lower the voltage to 4.6V, and now everything works, thank you


text:
Arduino Nano with Arduin Nano Ethernet shield ENC28J60
I have connected the Arduino Nano with the Arduino Nano ENC28J60, and then I connect the Ethernet cable with the laptop and also the Arduino nano with my laptop to load the code and it works just fine.
I was wondering if I want to disconnect the Arduino Nano with the laptop and run the same code then, how should I put the external power supply on ENC28J60 and what should be, and in general, what should be the right wiring?

use a phone charger

phone charger is not functional, I want to use for example, power supply, is it possible;

phone charger is power supply. why is it "not functional"? you can use the Vin pin of Nano as it is documented on the shop page. https://store.arduino.cc/arduino-nano


text:
Totally unresponsive card with RFID-RC522 Module
I bought an RFID-RC522 module including two attached PICC cards: a blue key chain tag and a white card with the type of MIFARE 1KB. In addition, I bought two other separate cards from the same seller.
I connected the module to an Arduino board and ran some examples of the library MFRC522.
Everything was OK with the two attached PICC cards (blue tag, and white card), BUT NOTHING worked with the other two cards, even they have no UID and NEVER RESPOND to the module. It seems to me that the internal microcontroller is not programmed. The seller doesn’t have any explanation. So, I need to know how to make them work.

so, the card you bought separately don't work ... are they 125KHz or 13.56MHz rfid? because they do look the same, but the MFRC522 only with one of those frequencies

Do you think that the cards bought separately are of the frequency 125KHz, so they don't respond to 13.56MHz  MFRC522 ?


text:
RGB not working properly
My RGB led is not working properly. It should light up red when the ultrasonic sensor detects more than 10 cm and green when it detects less than or equal 10 cm. It is just blinking red and green at the same time. How do I fix this?
#include<Servo.h>
Servo servo1;
int Motor = 3;
int tpin = 7;
int epin = 6;
int red1 = 12;
int green1 = 13;
int pos = 0;
long duration, inches, cm;

void setup() {
    Serial.begin(9600);
    pinMode(tpin, OUTPUT);
    pinMode(epin, INPUT);
    pinMode(red1, OUTPUT);
    pinMode(green1, OUTPUT);
    servo1.attach(Motor);

}

void loop() {
    digitalWrite(tpin, LOW);
    delayMicroseconds(5);
    digitalWrite(tpin, HIGH);
    delayMicroseconds(10);
    digitalWrite(tpin, LOW);
    duration = pulseIn(epin, HIGH);
    cm = (duration / 2) / 29.1;
    inches = (duration / 2) / 74;
    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    delay(100);

    if ((cm > 10))
    {
        servo1.write(pos = 0);
        digitalWrite(red1, HIGH);
        delay(100);
        digitalWrite(red1, LOW);
        delay(100);
        Serial.println("\t RED");
    }
    else if ((cm <= 10))
    {
        servo1.write(pos = 90);
        digitalWrite(green1, HIGH);
        delay(100);
        digitalWrite(green1, LOW);
        delay(100);
        Serial.println("\t GREEN");
    }
}

What output are you seeing in the console?

RGB LED has nothing to do with the issue, so the title is misleading.

blinking red and green at the same time .... that means blinking yellow ..... is that correct?

The ultrasonic sensor scans every 0,1 seconds according to your code. Problem is, sometimes you have "faulty" results. Taking into consideration the frequency of your scans + the "faulty" scans, it could be that your arduino just keeps switching between those two LEDs.
What helped me back then was to make a counter. A variable, that counts how many times in a row the distance to the object is "distance <10cm". If the streak was interrupted, it would reset the variable. This is how a serial output would display it:
distance: 20cm
distance: 16cm
distance: 8cm
count: 1
distance: 9cm
count: 2
distance: 6cm
count: 3
distance: 8cm
count: 4
distance: 11cm
count: 0
distance: 12cm
distance: 20cm

And the moment your counter reaches a certain spot, for example the object is closer than 10cm five times in a row, then you will let an led light up
if(count>=5)
{
  //turn on green led (color may be wrong)
}
else
{
  //turn on red led (color may be wrong)
}


text:
Using a water sensor with a NodeMCU make it less sensitive?
I'm trying to digitalRead from a water sensor (the one in the picture) using NodeMCU v3,when I try the sensor with an Arduino board it works fine, but when I try it with an ESP8266 NodeMCU v3 it becomes less sensitive to water with some pins or doesn't work at all with the others. My question is: Is that normal or I'm doing something wrong ?

 int pin = 14;
 char printBuffer[128];
 int ledPin = 12;
 const int buzzerPin = 13;

  void setup()
  {
    pinMode(pin, INPUT);
    pinMode(buzzerPin, OUTPUT);
    pinMode(ledPin,OUTPUT);
    Serial.begin(115200);
  }

  void loop()
  {
    sprintf(printBuffer,"PIN %d level is %d\n",pin, digitalRead(pin));
    Serial.print(printBuffer);
    if (digitalRead(pin)==HIGH)
    {
      tone(buzzerPin, 100,1000);
      digitalWrite(ledPin, HIGH);
      delay(100);
      noTone(buzzerPin);
      digitalWrite(ledPin, LOW);
      delay(100);
      Serial.println("----------- ALARM ACTIVATED -----------");
    }
    else{
      noTone(buzzerPin);
      digitalWrite(ledPin, LOW);
    }
    delay(500);
   }

The ESP8266 GPIO pins are funny beasts at the best of times. Using an analog sensor like that on a digital pin is bound to be different with different hardware.

So isn't there a way to get more accurate results ?

Define "accurate"...  There's nothing accurate about that sensor in the first place.

I just want it to sense that it is in the water that's all

Do you have a link to the datasheet for the sensor so we can have a clue what the schematic is on it?

I can guess how you're wiring them. Without knowing what it is that you are using, though, we cannot help you. We need to know what the components on the board are, and how they relate to each other.

This is how I'm wiring them: (+) --> v3, (-)  --> G, and S --> D5 that's dor the sensor and the buzzer: G-->G and (+) --> D7

Without knowing what comes out of "S" and how that relates to the water "sensor" portion of the device it's impossible to know what is going on. I do find those "water sensors" very very crude and primitive. Not really worth wasting your time with. Proper water sensors cost hundreds of dollars (I work with these).

I'm using it for a school project actually

Do you even have a link to where you got it from?

doesn't that need an analog input, not a digital one? the only other diff would be 5v vs 3.3v, so feed it Vin (or external 5v if you have a CH340-based nodeMCU) and level shift the signal down to 3.3v.

Ok, I found some decent images online for a similar one and reverse engineered the circuit.

I know a similar sensor and I remeber that applying a constant voltage to + will lead to corrosion due to electrolysis. Therefore the sensor will be destroyed after running only a few hours. The key might be to just activate it for each reading, but I for myself didn't like it anyway and used a different sensor.

You are using it wrong.
That sensor (crude as it is) is an analog sensor. It's not designed to be used connected to a digital pin.
It outputs an analog voltage proportional to the resistance between the tracks in the sensing portion.
By feeding that voltage into a digital pin you are relying on the logic threshold values, plus any other components (pullup resistors, etc), to give you a "wet" or "try" signal.
Since pins differ (some have pullups, some pulldowns, some nothing, etc) and the logic thresholds are only an approximation in any case, it's doomed to failure.
You need to connect the sensor to an analog input and compare the value read to a threshold value of your choosing.  However the ESP8266 is very very poor when it comes to analog - it only has one analog input, and that is only capable of sensing between 0 and 1 volt.

how did you determine that that water sensor is analog Since it's got a + and - input and a third sense line I would expect it to put out a logic level signal. Why would it need power if it's just a variable resistor? (I guess it could be a voltage divider, but the picture looks like it has an IC and a few discrete components.

It has a transistor as an amplifier.

I wanted to use the analog input, but since I'm using it with a soil moisture sensor I decided to use this water sensor in a digital mode, should I just use an multiplexer and use them both in a analog mode and compare the value read to a threshold value as you said ? otherwise I have an arduino uno, can I use it but without changing code (since the code above is just for testing , the actual project is displaying sensors value in a esp8266 webserver)?

reading multiple analog signals on an ESP8266 is simple


text:
.elf and .hex equivalency? (code, eeprom, fuses, and lock bits all in one)
I have all configurations (eeprom data, fuses, lockbits) of my ATMega168A together with the code in my C files. The compilation creates an elf file that I use as an all-in-one programming file for production.
Just as a tryout, I converted the elf file to hex with avr-objcopy and saw that the code and configurations are still there (why wouldn't they).
My question is, if the two files are equivalent in case of using them for all-in-one programming. Is there any critical data stripping taking place between elf-to-hex conversion that could affect the actual programming?
Also, I tried again to convert the hex file to bin and saw again the same thing but of course with zero-padding. Except for the obvious different of file size, is there any practical difference when using the bin file and the hex file? Does this padding create any problems? (For example trying to write 0 to addresses that do not exist).
Thank you in advance.

My question is, if the two files are equivalent in case of using them for all-in-one programming. Is there any critical data stripping taking place between elf-to-hex conversion that could affect the actual programming?

Nothing critical, but data stripping does take place. Everything that is in the HEX file is in the ELF file. That is - all the compiled machine code and data.
Basically everything that gets written to the chip is in the HEX file, and the HEX file can be created from what is in the ELF file - ergo the ELF file contains everything that is in the HEX file.
However, not everything that is in the ELF file goes into the HEX file.
The ELF file contains a huge amount more information. Mostly that information is geared towards debugging. There are things like the names and locations of all the symbols in the code - that is, the functions and variables, etc. There are breakdowns of all the assembly instructions grouped by source code file and line number.
None of that is relevant for the Arduino environment, but when you're using professional tools to do your development you can use them for realtime debugging and tracing of your program while it's running on the real hardware.
None of that is relevant to putting your program on the chip. It's all used by the PC.

Majenko your answers are majestic! Thanks!


text:
What does "Update of OCR1x at" mean in the WGM table of ATMEGA328?
I just finished a reading a couple of online guides on how to use timer registers with pulse width modulation, so I'm still new to its concept.  When I looked in the ATMEGA328 specification sheet, I see this table:

The column that I'm not completely clear on is the "Update of OCR1x at".  I circled row 14 as an example.  If you're operating in mode 14 (ie. setting WGM 13, 12 and 11 to high), then you'll be in Fast PWM.  By setting a value for ICR1, you are effectively setting the TOP value, which will control the period of the pulse waves.  And the overflow flag on the timer will be set when the timer reaches the TOP value.
So does "Update of OCR1x at" mean that only when when the pulse wave form has reached the value of BOTTOM (or the end of a period), that's when the value of OCR1x will be passed on to the OCx pins if COMx bits are set?

The pwm can be changed while it is running. You may write a new value to the OCR1x register without stopping the pwm. That could cause glitches, so it is double buffered. The "update" is when the new value (written by you) is set into the OCR1x register. I don't know how that effects the pwm output, but apparently they have thought this through and have decided which moment is the best.

look for a  diagram  in the datasheet that shows a graphical representation of a sawtooth waveform

So does "Update of OCR1x at" mean that only when when the pulse wave form has reached the value of BOTTOM (or the end of a period), that's when the value of OCR1x will be passed on to the OCx pins...

Yes, that's what it means. To prevent glitches in the PWM output, you frequently do NOT want the PWM waveform to change immediately the instant you update an OCR1A value, for instance, to change the PWM output on output pin A. So, the PWM value you set is double-buffered and only updates the inner buffer used by the output pins once it finishes its current PWM period and reaches the BOTTOM value again, which would be a counter value of 0 in this case. Now, by allowing a previous PWM period to finish before the hardware reads the latest value from the OCR1A/B register (outer buffer) to its inner buffer (which inner buffer actually determines the pin state), you have a nice, clean, glitch-free PWM transition from one value to the next regardless of when you updated the OCR1A or OCR1B output register.


text:
RS485 Arduino Communication Issue
Friends, I am trying to achieve half duplex communication between two Arduinos using RS485 Protocol. The hardware I am using is a MAX485 module and an Arduino Uno. I am using the SoftwareSerial library for Arduino, but I am not be able to transmit data from sender to receiver. The length of the wire between MAX485 modules is 1 meter.
My question is, what wrong I am doing here, please guide me.
The code:
SenderDevice
#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);

String strCmd;
int counter;

void setup()
{

 Serial.begin(9600);
 mySerial.begin(9600);

 pinMode(5, OUTPUT);
 digitalWrite(5, HIGH);
 counter = 0;

}

void loop()
{

  counter++;
  strCmd = "Counter" + String(counter) + "$";
  Serial.println("Sending " + strCmd);
  mySerial.print(strCmd);

  delay(10);
  mySerial.flush();
  Serial.flush();
  memset(&strCmd, 0, sizeof(strCmd));
  delay(2000);

}

ReceiverDevice
#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);

String strCmd;

void setup()
{

 Serial.begin(9600);
 Serial.println("ready");

 pinMode(5, OUTPUT);
 digitalWrite(5, LOW);
 mySerial.begin(9600);

}

void loop()
{

   while (mySerial.available() > 0) {

        char c = mySerial.read();
        if (c == '$') {

           Serial.println("Received " + strCmd);
           memset(&strCmd, 0, sizeof(strCmd));

        } else {

          strCmd = strCmd + c;

        }

  }

}

My Wire Connections are :

(Both Sender & Receiver Device)
Arduino Uno 6 -> Max485 RO
Arduino Uno 7 -> Max485 DI
Arduino Uno 5 -> Max485 DE
Arduino Uno 5 -> Max485 RE
Arduino Uno 5V -> Max485 VCC
Arduino Uno GND -> Max485 GND

Sender Max485 A -> Receiver Max485 A
Sender Max485 B -> Receiver Max485 B

I have quite bad experience with using the software library using MIDI which has a very low baudrate; I advise to at least try with the hardware UART (RX/TX) to see if that solves the problem.

Do you have GND connected between sender and receiver?

@MichelKeijzers : I am already using the hardware UART for someother reasons.

@Matej : I have tried connection the ground of both devices too, But it did not work.
In real time my application is going to be 15 meters away.

I only said to try it, so you know if the problem is in the library/software; if it works with a hardware serial, than at least you know your code is ok.

@Michael : my general rx-tx communication is working. After searching a lot on web i have found this code. Actually modified the example code of the library.

@javabee I never had problem with it and I don't see anything wrong with your code or wiring. Do you have another modules to test it?

@javabee "I have tried connection the ground of both devices too" you absolutely MUST connect ground of both devices. Senders and receivers data lines are flipped? And do you have an oszilloscope to monitor the transfer? Timing is always critical in proticols that don't use a clock line

@Matej : I purchased new Arduinos and Max485 yestrday. Its not also working too.
I don't know why this simple piece of code is not working. Please someone help me.

@SimSon : I dont have oszilloscope. what other way can you suggest to debug.

@javabee So modules are all right. You can try this code:   https://github.com/matrn/RS485protocol    it worked for me but I am not sure if problem is in code. Also as Sim Son wrote you must have gnd of both devices connected.


text:
QMC5883L automatic calibration
I have a QMC5883L magnetometer, and a pretty basic sketch which just prints the values from X, Y and Z axis to the serial monitor.
I want to use it in an application to detect changes in the magnetic field, and the sensor will be in a fixed position. However, it seems that when I start the Arduino, the values from the sensor are all over the place (looking at it in the serial plotter all 3 axis are going from 1 extreme to the other and back). If I move the sensor around a bit, the values calm down and become more steady, and usable to detect metal objects approaching the sensor.
Since the sensor will be installed in a fixed position, I can't move it around to calibrate it every time the Arduino restarts. Can I calibrate it programatically somehow? Note that I don't really need to know which way it is oriented, I simply want to detect when the magnetic field changes (i.e. when a metal object approaches/leaves the sensor).

https://web.archive.org/web/20150214163745/http://hobbylogs.me.pn/?p=17

https://github.com/helscream/HMC5883L_Header_Arduino_Auto_calibration


text:
Unexpected negative values from abs() function inline with analogRead
When sampling from A0 with a 0-5V signal on an arduino micro with the code below I get some negative values.
int sensor = 0;
sensor = abs(analogRead(A0) - 512);

Values:
77
25
-74
-58
46
113
-74
102
-91
-51
-126
47
31

When running the (apparently) mathematically equivalent code below I get exclusively positive values.
int sensor = 0;
sensor = analogRead(A0);
sensor = sensor - 512;
sensor = abs(sensor);

I don't think this is an integer overflow as in this post because when I switch to long sensor = 0 I get the same negative results.
What's going on here?

abs() is defined in Arduino.h as a macro:
 #define abs(x) ((x)>0?(x):-(x))

A macro does not evaluate in the same way as a function.
 sensor = abs(analogRead(A0) - 512);

This statement will be expanded at compile-time to:
 sensor = ((analogRead(A0) - 512)>0?(analogRead(A0) - 512):-(analogRead(A0) - 512));

Now the "error" is easy to understand. The analog pin is read twice. The "error" can be avoided by adding the following line first in your sketch:
#undef abs

This will remove the macro abs() and the standard library function will be used instead.
Cheers!

The error is the abs() macro in Arduino.h

Thanks for the clear answer. I had no idea that macros even existed in the Arduino world. I found a post from 2011 discussing this and a short list of other macros. Do you know of a definitive list? Is it just more "Arduinoesque" and better practice to avoid multiple assignments in a line and stick to one operation per line?

No, it is not more Arduinoesque to use only one operation in one assignment. Sometimes this is done to make it easier to read. Your problem with macros does not have to do much with Arduino. It is more generally about how macros are evaluated by the compiler. The compiler replaces the macro with what is written in it's definition (and puts in the argument). It is not a function. And this is not Arduino specific, but depends on the compiler. You can also use  macros, when programming with other compilers. Macros can be useful, but you have to use them with caution.

@chrisl, there is already a abs and labs function. The arduino abs macro is a ludicrous blunder by arduino. Aaron Ciuffo, click on the link to Arduino.h in the answer by Mikael Patel, there you see the other macros. Another thing is not to use a variable with the name "B1".


text:
How do I supply either (1) dual voltage or (2) negative voltage?
Sorry in advance if this question already exists--I tried to search but my keyword knowledge is shaky. I have created a Colpitts oscillator on breadboard using AA batteries as the power supplies. I want to implement this oscillator with an Arduino. (Once it's set up, I want to use its voltage to do some things, but that isn't part of this question.)
In the image below, I have two voltages, Vcc (positive voltage) and Vee (negative voltage). My simulations indicate I can run the oscillator either with a dual voltage (+5V and -5V), or with one negative voltage (-5V) and the other set to ground. Either provides a 100 kHz oscillation from about -5 to 2 V. So:

Is there a way to provide a dual voltage supply from the Arduino Uno?
Is there a way to provide a single negative voltage supply from the Arduino Uno?

Thanks!

No, but you could use a dedicated IC, for example http://www.ti.com/lit/ds/symlink/lm27762.pdf

After reading the post carefully, I'm confused why this is marked as off-topic.

You can make -5 V if you use an external power source, like in the circuit below (untested).
Connect the GND (-) from the Arduino to the +5V from the External (5V) source, than 0V will be the GND (with respect to the Arduino), but the GND of the external source will be -5V with respect to the Arduino.
I only used the resistors to get no short circuits, you can replace it by your own circuit (connecting the 5V arrow to Vcc and the -5V arrow to Vee).

simulate this circuit – Schematic created using CircuitLab


text:
Component with controllable resistance from Arduino?
I'm new to Arduino and building circuits, and was wondering if there is a type of component, or some other way to do the following task:
I want to control the resistance of a circuit from my computer linked to my Arduino, presumably using an output analog PIN.
Basically what I have is an LED whose brightness I want to control from my computer. I want to be able to control the resistance of the circuit to limit the electricity going to the LED, and I want to be able to do this from my computer (not physically, with a potentiometer) (unless a potentiometer's resistance can also be controlled from a PIN?).
How can I do this?

The easiest way to drive an LED with variable brightness is to use one of the pulse width modulation (PWM) output pins on an Arduino.
A PWM pin takes an input value from 0 to 255 (or is it 0/1023? I don't remember.) and converts it to a ratio of on-time to off-time. At the highest value, the output pin is in the on state, 100% of the time. At the halfway point, the output pin is HIGH 50% of the time, and LOW 50% of the time.
Our eyes average out the flashes and see a variable brightness. It works very well.
If you absolutely must have a variable resistance controlled by a digital value, there are devices known as digital potentiometers. These are variable resistors controlled by digital inputs. For an Arduino, you should think about an I2C or SPI potentiometer, which is controlled by serial port commands. You tell it the resistance you want, and it sets itself to that resistance.
As CrossRoads points out in their comment below, you still need a current limiting resistor to drive an LED from a logic pin, to protect both the LED and the output driver on the Arduino. You want to limit the current to the max current for your LED, and then use PWM to lower the brightness from the absolute max set by the current limiting resistor. CrossRoads explains how to calculate the resistor value.

I'll try all of this, thanks for the help!

See this example: https://www.arduino.cc/en/tutorial/fading

Cool, thankyou for that

A PWM pin takes an input value from 0 to 255.  (analogRead() returns 0-1023).  Don't forget a current limit resistor so you don't damage the IO pin, or the LED.  (5V - Vf)/.02A = resistor.  Say the LED has 2.5V across it when on (measure it, or read its data sheet), then (5V - 2.5V)/20mA = 125 ohm.  20mA with current LEDs will be really bright. 250 ohm or 270 ohm may be plenty bright for the max brightness.


text:
Using NodeMCU D8 (GPIO15), D4 (GPIO2) and D3 (GPIO0) pins
I am using a NodeMCU board and have already used 6 digital pins as output for interfacing with the LCD. I intend to use 2 more digital pins, one as input and other as output for interfacing an ultrasonic sensor.
D8, D4 and D3 are the only digital pins remaining. I understand that D8 (GPIO15), D4 (GPIO2) and D3 (GPIO0) pins of the NodeMCU  have special boot-controlling uses. So how can I use those pins as generic digital pins. Any help is appreciated.

I would recommend to use an I2C LCD display

you can get an I2C LCD controller for well under $1USD on ebay.

I'm aware of this. I was looking for a way to implement D8, D4 and D3 as gpio pins. Thank you.

The boot setup pins have pull-up on board (0, 2) and pull-down (15) to ensure the correct boot. io 0 (D3) is additionally wired to the reset circuit controlled over USB to put the esp8266 into bootloader a.k.a. flashing mode.
io 0 must be HIGH for normal boot, io 2 must not be LOW (can float according to spec).
If you attach a device to this pins, the device must respect the boot state. Some devices will pull-down or pull-up a wired pin. Usually it is not documented. You can't use such devices on boot config pin which requires the other state.
The pull-up and pull-down can influence the attached device or readings from the device. For some elements it can be advantageous.
Best is to use this pins for elements which would need pull-up or pull-down anyway. For example buttons/switches or sensors which behave like buttons or switches.
In my project with Wemos D1 R2 I had signal to relay module on io 0, speaker module (with amplifier) for tone() function on io 2. I could not use a relay or mosfet module on io 2. On io 15 I had a reed relay module control signal, which I didn't want to go HIGH at boot as most esp8266 io pins do.

Thank you for the info. So how can interface an ultrasonic sensor to any of those 3 pins. Obviously both the trig and echo pins change states to high or low.

only the state at startup matters to esp8266. the distance sensor could be disturbed by the pull-ups or pull-downs. you know when you try it. try io 0 and io 15 first.

Not a direct answer to your question, but some other way that solves your problem, is to use a shift register like 74HC595 and control the 6 pins for the LCD with the 74HC595 which only uses 3 (digital GPIO) pins. That saves you 3 pins for others. Actually you can use 8 pins or even 32 when you daisy chain four 74HC595s.


text:
Reading ADS1232 with Arduino
I'm a newbie and I'm trying to read an ADS1232 with an Arduino for a Weight Scale Project.
I read data through the SPI interface, but i don't receive the result.
#include <SPI.h>

#define MISOPIN  50  //DATA
#define SCLKPIN  52  //SCLK
#define PDWN     53  // SS
#define SPEED       5
#define GAIN0       7
#define GAIN1       6
#define CLKIN       10
#define A0          9
#define TEMP        8

uint32_t byte1;
uint32_t byte2;
uint32_t byte3;
uint32_t finaladc = 0;

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

  pinMode(PDWN, OUTPUT);
  pinMode(MISOPIN, INPUT);
  pinMode(SCLKPIN, OUTPUT);
  pinMode(SPEED, OUTPUT);
  pinMode(GAIN0, OUTPUT);
  pinMode(GAIN1, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(TEMP, OUTPUT);

  digitalWrite(GAIN0, HIGH);
  digitalWrite(GAIN1, HIGH);
  digitalWrite(SCLKPIN, LOW);
  digitalWrite(A0, LOW);
  digitalWrite(TEMP, LOW);
  digitalWrite(SPEED, HIGH);//0-->  10SPS ,1-->80SPS
  digitalWrite(PDWN, HIGH);  //0-->  POWERDOWN(SLEEPING -NO CONVERSION) ,1-->WORKING MODE

  reset_adc();

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);

  digitalWrite(SCLKPIN,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(MISOPIN)== LOW) read_adc();

  delay(1000);

}

void reset_adc()  {
  digitalWrite(SCLKPIN,HIGH);
  delayMicroseconds(1400);

}

void read_adc()  {
  drdy_wait();
  uint8_t i;
  finaladc = SPI.transfer(0xff);
  finaladc |= (uint32_t)SPI.transfer(0xff) << 8;
  finaladc |= (uint32_t)SPI.transfer(0xff) << 16;
  Serial.print ("ADC_value:  ");
  Serial.println(finaladc,DEC);
  Serial.println();

}

void drdy_wait()
{
  delayMicroseconds(30);
}

Has anyone worked with this? Can you help me?  Thank you

Welcome to stackexchange. Would you show your code please? It is hard to recognise problems without it.

This is here Google

the ADS1232 doesn't have SPI

I've used SPI with the ADS1232.  You've a lot of problems, but the first one is your reset_adc() is all wrong, among other things reset is via pulling the PWDN pin low for more than 10 uS.  Start there.

I fished out some code I wrote a while back while evaluating the 1232.  SPI is a headache because of the need toggle the clock signal to prevent the last data bit from 'sticking', which will botch repeated reads when the last data bit is high.
If you are absolutely required to use SPI stop reading this answer.
Everything you need to know is on pages 18 and 19 of the ADS1232 datasheet.  Note this is strictly demo material, for example it doesn't take into account settle time when switching channels.
int32_t read_adc(const uint16_t wait_millis) {
   int32_t data = 0;
   // reset ADC
   digitalWrite(ADS1232_PDWN, LOW);
   delayMicroseconds(10);
   digitalWrite(ADS1232_PDWN, HIGH);
   delayMicroseconds(10);

   for (; data < wait_millis && digitalRead(ADS1232_DRDY_DOUT) != LOW;
        delay(1),
        data++);

    if (data == wait_millis) {
        // timeout
        return -1;
    }

   // read in 24 bits, see Page 19 of the datasheet

   data = 0;
   for (uint8_t i = 0; i < 24; i++) {
        digitalWrite(ADS1232_CLK, HIGH); // clock out next data bit
        data <<= 1;
        data |= digitalRead(ADS1232_DRDY_DOUT);
        digitalWrite(ADS1232_CLK, LOW);
    }
    // adjust for sign. See page 18 of datasheet
    if (data & 0x00800000)
        data |= 0xFF000000;
    // avoid having DRDY/DOUT remain in the state of the last bit
    // see page 19 of datasheet
    digitalWrite(ADS1232_CLK, HIGH);
    delayMicroseconds(10);
    digitalWrite(ADS1232_CLK, LOW);

    return data;
}

Thank you!! Ramblin Rose!! I will try and respond to you


text:
Mini ethernet shield pins don't have SI
Please somebody who had the same issue help me.
The question is how to connect this Mini Ethernet shield to an Arduino.
The main problem is the pins that my shield have or haven't; my current connections to the Arduino Mega 2560 are:

5v to 5v
GND to GND
LNT to NULL
CLK to NULL
SO  to pin50
WOL to NULL
SLK to PIN52
ST  to ????
RST to RST
CS to PIN53
Q3 to NULL
GND to NULL

But in all cases when I search the connection diagram every picture has SI, but I don't have it (I tried to connect ST to PIN51 without luck).
What kind of Ethernet shield is that? Or how to connect those pins?
I hope someone can help me; thank you in advance.
/*
  DHCP-based IP printer

  This sketch uses the DHCP extensions to the Ethernet library
  to get an IP address via DHCP and print the address obtained.
  using an Arduino Wiznet Ethernet shield.

  Circuit:
   Ethernet shield attached to pins 10, 11, 12, 13

  created 12 April 2011
  modified 9 Apr 2012
  by Tom Igoe
  modified 02 Sept 2015
  by Arturo Guadalupi

 */

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

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02
};

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
   // Ethernet.init(53);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    } else if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // no point in carrying on, so do nothing forevermore:
    while (true) {
      delay(1);
    }
  }
  // print your local IP address:
  Serial.print("My IP address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  switch (Ethernet.maintain()) {
    case 1:
      //renewed fail
      Serial.println("Error: renewed fail");
      break;

    case 2:
      //renewed success
      Serial.println("Renewed success");
      //print your local IP address:
      Serial.print("My IP address: ");
      Serial.println(Ethernet.localIP());
      break;

    case 3:
      //rebind fail
      Serial.println("Error: rebind fail");
      break;

    case 4:
      //rebind success
      Serial.println("Rebind success");
      //print your local IP address:
      Serial.print("My IP address: ");
      Serial.println(Ethernet.localIP());
      break;

    default:
      //nothing happened
      break;
  }
}

And result is :

16:41:14.242 -> Initialize Ethernet with DHCP:
16:41:14.804 ->    Failed to configure Ethernet using DHCP
16:41:14.848 -> Ethernet    shield was not found.  Sorry, can't run
without hardware. :(

ST is SI. what is the chip? what library do you use? did you init the library for 53 as CS?

I use <SPI.h> and  <Ethernet.h>, Sketch for DHCP Client which is integrated in arduino examples. Ethernet > DHCPAddressPrinter and it shows me on serial monitor Ethernet shield was not found.  Sorry, can't run without hardware. :("

I assigned pin 53 to CS too but still nothing :(

I asked about chip . I suspect you try to use the Ethernet library with the enc28j60 chip

@Juraj Sorry for that. Yes you are right I use enc28j60 Chip.

In my question I added code and result

The "Mini Ethernet Shield" uses ENC26j60 chip. The Arduino Ethernet library is for Wiznet W5100/W5200/W5500 chips. You can't use it with ENC26j80.
With Arduino Mega I would recommend to use the UIPthernet library for ENC26j80. Other option is the EtherCard library.
The UIPEthernet library has the same API as the the Arduino Ethernet library.

I think you are right, I used wrong library and now I tested with UIPethernet.h and it works great. Thank you Juraj.


text:
Servo delay problems
So I had a test last week with the Arduino Uno starter kit. We got a task including the servo. I had to get the servo to go from 0 to 90 degrees and it was supposed to use 4 seconds to do so. Than back from 90 degrees to 0 again. My code is like this:
#include <Servo.h>

Servo myservo;
int pos = 0;
void setup() {
  myservo.attach(9);
}
void loop() {
  for (pos = 0; pos <= 90; pos += 1) {
    myservo.write(pos);
    delay(40);
  }
  for (pos = 90; pos >= 0; pos -= 1) {
    delay(13);
  }
}

As you see the delay should be just 40 and 13 milliseconds, but it used 4 seconds and 1.3 seconds. but since the code was, wrong I didn't pass on this task. So what have I done wrong.

9040ms = 3,6s. 9013ms=1,17s. So you have 3,6s for the first movement and 1,3s for the seconds movement. Please describe further, how this does not comply with the requirements, since you wrote, that it needs to take 4s and you saw 4s. Thats what I understood

90*40ms = 3,6s, but there is also a bit of overhead as myservo.write(pos); and the for loop also take some time to execute (there are also interrupts that could add some additional delays). But I'm guessing that this overhead is negligible. It might be that the examiner wanted you to take that into account. Note that even if you had a delay(44), you'd only get 3.96s, so you'd be 40ms off. The examiner might not like this.

Also your second loop isn't doing anything with the servo...

I would use the millis() function to set up a timing as accurate as possible.
Before starting your operations store the actual value of the millis() timer to a variable time_passed. After finishing your operation, in this case a 1° step of the Motor, wait until the 90's part of your desired time (4s) is reached. Then you increase your time_passed with the 90's part of your desired time bevor going on.
#include <Servo.h>

unsigned long time_passed;
unsigned long timestep = 4000 / 90; // necessary period to reach 4s in 90 steps
Servo myservo;
int pos = 0;

void setup() {
  myservo.attach(9);
}
void loop() {
  time_passed = millis();
  for (pos = 0; pos <= 90; pos += 1) {
    myservo.write(pos);
    while ( millis() - time_passed < timestep) {
    }
    time_passed = time_passed + timestep; // this was time_passed = millis(); at testing, but this should be even more accurate. Hope I made no mistake, since I tested only the previous Version ;-)

  }

  for (pos = 90; pos >= 0; pos -= 1) {
    myservo.write(pos);
    while ( millis() - time_passed < timestep) {
    }
    time_passed = time_passed + timestep; // this was time_passed = millis(); at testing, but this should be even more accurate. Hope I made no mistake, since I tested only the previous Version ;-)
  }
}


text:
Why shouldn't you connect more than one motor directly to either the 5V or 3.3V pins/rails of an Arduino?
Why shouldn't you connect more than one motor directly to either the 5V or 3.3V pins/rails of an Arduino?
What would go wrong otherwise?

In short, the power regulator (or 5V USB) may/can not supply enough current. Overcurrent can cause damage to devices or undefined behaviour.

On an Uno, the barrel jack feeds a reverse polarity diode that can support 1A max, which then feeds a 5V regulator rated for 800mA max (800mA cannot be reached due to lack of cooling - but it does pretty well if barrel jack voltage is kept to 7.5V) which then feeds a 3.3V regulator rated for 150mA.
With too high a voltage or too much current, the 5V regulator either goes into thermal shutdown, or often just severely overheats and fails (sometimes spectacularly).
The 5V can also come from the USB source, which has 500mA PTC resettable fuse, so even less current is available.
So power your motor from another source, and use the Arduino output pins to control a transistor to turn the motor on and off.


text:
Can 2 H-Brides be controlled by one Arduino?
The three motors are from windshield wipers, with one of the brushes disconnected in each. The controllers are BTS7960 43A modules
One Bridge for two drive motors (speed and direction), and the second Bridge for a third [modified servo-like] motor (for Ackerman steering).
Is this possible/recommended?

Yes. Why would you suppose it wasn't?

never seen it before, always one arduino one driver.

That's because for many projects one driver is enough.

@Majenko i see. at the risk of noob-shaming, can you please give an extremely brief review of the project. it's three wiper motors; 2 behind for drive and one front like an RC car servo for steering. input from an on-board ROS computer to the arduino (USB), to each BTS7960 bridge for movement control. and controlling four separated strips of WS2812B smart LEDs
recap: can one arduino work with 1) continuous USB input from a computer 2)controlling 2 separate h-bridges 3) controlling smart LED strips 4)all at the same time

There is absolutely no difference between using one and using two drivers. It's just the number of pins of the different types that you need.

many thanks @Majenko


text:
How can write a single data into spiffs?
typedef struct book {
char title[20];
 char author[20];
 int pages[10];

} Book;

Book b1 = {"The Zahir","Paulo Coelho",336,0};

while writing this structure into SPIFFS of ESP8266, I am using function
filename.write( (const uint8_t*)&b1, sizeof(b1));

but how can write a single data like name of book into structure of spiffs?

For this kind of situation it's best to treat your data as records in a database. To change one part of a record you read the entire record, change the value, then write that record back.
int record = 4; // which record you want to change

struct book b; // Temporary storage for editing the data

// Go to the record and read it in
filename.seek(record * sizeof(struct book));
filename.read( (const uint8_t*)&b, sizeof(struct book));

// Change the data
strcpy(b.title, "Winnie The Pooh");

// Go to the record again and write it out
filename.seek(record * sizeof(struct book));
filename.write( (const uint8_t*)&b, sizeof(struct book));


text:
Is NVS storage reset during an OTA update? (ESP32)
I plan to save some settings in the NVS repository of my ESP32, which will also be implemented OTA update.
The question arose, will the data in the NVS storage be reset when the OTA update is launched?

no. why would it?


text:
Wire.h missing - Failing to upload I2C 16x2 LCD sketch
I am total newbie in Arduino and for the last 3 days I am trying to figure this out.
I would like to use an I2C display for a project. I have installed the LiquidCrystal_I2C, but when I try to upload it I get this wire.h missing message.
Could anyone please help me to understand and fix this?

+1 for saying help me to understand ......  too many people only want finished code

Please post code and error as text, not picture.

How do I post codes here?

That library is special. It expects to be placed in the same location as the Wire library.  You need to find the location of the Wire library and place this library alongside it.  So you have:
.../Wire/Wire.cpp
.../Wire/Wire.h
.../LiquidCrystal_I2C/LiquidCrystal_I2C.cpp
.../LiquidCrystal_I2C/LiquidCrystal_I2C.h

etc

Thank you for the reply.
I seems I have two copies of wire.cpp and wire.h in two different locations. Attached is a screenshot of their locations with respect to the LiquidCrystal_I2C.h and LiquidCrystal_I2C.cpp - is this the problem?
Screenshot: https://i.imgur.com/n7m8UTR.png

Just pick one. If they're all the same then it won't matter which.

how can I pick one? (sorry if it's a stupid question)


text:
NodeMCU with HC-SR04 ultrasonic sensor
How can I interface an ultrasonic sensor with a MCU with 3.3 V GPIO like the NodeMCU? I tried powering the sensor with both 5 V and 3.3 V from the MCU. Both failed to show any results as the distance appeared to be 0 V. In both cases the trig pin of the sensor was given 3.3 V input from the GPIO pin. I assume I need to level shift the echo pin output from 5 V to 3.3 V. How can I do that? Or is something else the issue? The code I used is fine as it works with Arduino.

The datasheet I found says the logic is TTL, which as far as I know is 2 V - Vcc, so 3.3 V should be fine. Is Trig just constantly given 3.3 V? According to the datasheet, it needs a 10 us pulse. Perhaps that is your issue? Code or schematics could help if that isn't it.

I have given trig pulse High and Low at 10us interval. The code is not the issue as I have used the same code with Arduino and it works fine.


text:
GPS module Ublox Neo 6M issue
I using the above mentioned GPS module with Arduino UNO. I find that I cannot receive the Latitude and Longitude values in the $GPRMC string in the NMEA data, as I used the module inside a concrete building. I got the values when I placed the module just outside the window. But I have noticed that the phones we use can get the location data just fine through their in-built GPS after waiting for just some time. How is this possible? Any way I can achieve this using the Ublox Neo 6M module?

Mobile phones use the mechanism of assisted GPS.
In contrast to your Arduino U-Blox module it uses the cell tower data your phone can provide to determine your location. This is especially helpful to get a quicker first fix and to get a fix even when you have poor satellite signal conditions.
That said, this will not be possible using only your GPS module connected to your Arduino.


text:
Adafruit Feather ESP32 - GPIO power drain during deep sleep
I have an Adafruit Feather ESP32 whose GPIOs I use to control an external device. I don't want the device to drain the power of the ESP32 sometimes, so I set the GPIOs to INPUT. When I go into deep sleep though, the GPIOs suddenly get some random voltages and start drawing power. A few GPIOs are 3.3V, others are 0.7V, and some are near 0V.
What is the correct/standard way to make the microcontroller not leak any power to that external device.
One way is obviously physically disconnecting that device, but I want an automated way. Is it solvable by software or do I need special hardware to achieve my goal?

measure the current flowing at the GPIO pins when the ESP32 is in deep sleep .... measuring the voltage tells you nothing about the current, unless you know the value of the resistance

the board has a pull-up on some pins

@jsotola Certainly I also measured the current. When I disconnect the external device, the current drops significantly.

@Jurai that is true. So I moved away from those pins. This does not entirely solve my problem though. I want the current to the external device be the same as when I disconnect the external device: 0A. How can I achieve this?

Please provide some more information. What is the external device? How do you power this device? How is it connected? PS setting a pin to input, means it's now "floating" so it could be any voltage.

Sorry I'm not expert in the ESP32, but I know it can come out of deep sleep based on inputs from the pins. Maybe that's what's happening. The Espressif IDF at least has a way to read the reason the chip came out of deep sleep. Are you using the arduino image or micro/circuitpython?


text:
WiFi connection times out if credentials retrieved via serial terminal
I've implemented a small WiFi connection procedure into my ESP32 project.
The available networks get printed with index, then I'm entering the index and retrieve the network name from it. The password is entered via serial in clear text.
Before connecting, I'm printing the credentials and thus could confirm they are read into const char * strings properly.
Unfortunately when using this procedure the connection to my AP times out. I've also tried to override the strings with hardcoded values and then the connection works as expected.
while (!Serial.available()) {
    // (timeout is implemented here)
}
String index_s = Serial.readStringUntil('\n');
long index = index_s.toInt();

// { same while as above }
String passw = Serial.readStringUntil('\n');

const char *ssid = WiFi.SSID(index).c_str();
const char *pass = passw.c_str();

// with this it works:
// ssid = "my_network";
// pass = "my_password";

Serial.printf("connecting to %s using %s", ssid, pass);
WiFi.begin(ssid, pass);

removing comments now, as they are not necessary :p

Possible duplicate of String compare when using Serial

As you can see, I don't do string compare. So what do you think how I could've found the question you mentioned? Yes, it's the same reason. No, it's not the same issue.

The answer was quite simple but of the kind you need some time get find out. The issue was a hiding carriage return.
passw.trim();

Did the trick. String.trim() removes the \r and thus the password gets accepted.


text:
VNH2SP30 Motor Driver not working in reverse
I bought 2 new VNH2SP30 Motor Drivers because i thought the first one was broken but they are both giving me the same issue, they run in forward direction but not reverse...
When the motor is unplugged the forward led is bright green, when the code executes the reverse direction, the reverse led is lit very dimly and multi meter measures no voltage.
I have tried:

changing power source and voltage
using different cables and pins
using different motors
using different code
using different VNH2SP30 Motor Driver
using different arduino

here is the code:
  #define INA 5 // outputs arduino
 #define INB 7
 #define EN 8
 #define PWM 11

 int motorSpeed = 255 ;  // motor speed

 void setup ( ) {
  pinMode ( INA , OUTPUT ) ;
  pinMode ( INB , OUTPUT ) ;
  pinMode ( EN , OUTPUT ) ;

  digitalWrite ( EN , HIGH ) ;
 }

 void loop ( )
 {
  digitalWrite ( INA , LOW ) ;  // turn the motor in one direction
  digitalWrite ( INB , HIGH ) ;
  analogWrite ( PWM , motorSpeed ) ;
  delay ( 1000 ) ;

  digitalWrite ( INA , HIGH ) ;  // turn the engine in the opposite direction
  digitalWrite ( INB , LOW ) ;
  analogWrite ( PWM , motorSpeed ) ;
  delay ( 1000 ) ;

  digitalWrite ( EN , LOW ) ;  // turn off
  delay ( 1000 ) ;
  digitalWrite ( EN , HIGH ) ;

 }

Heres the wire diagram but my outputs are just on different pins.

posting an incorrect wiring diagram is pointless

documentation on the web indicates that there are two EN pins

there are two variations of this driver, there is another that drivers 2 motors, this drives only one

There appears to be quite a few faulty drivers such as this one currently on Aliexpress. Of the 4 I have bought, only one works - the other three function exactly as you described.
Same program, same motor, same control wiring as the one which works.
I can only suggest try to buy from a different seller on ebay or ali; or of course pay top dollar for a chip from a reputable source.


text:
Reasons Flash Page is Locked Due
Using the Arduino Due on a project, I have found that I commonly run into the issue Flash Page is Locked when attempting to upload.
I have used the library write functions of DueFlashStorage that lock and unlock addresses on each write. I believe a combination of this locking/unlocking and power loss during writes has caused my woes. This lib has added functions that avoid locking/unlocking memory on each write so this problem could be averted in that way.
My question is, are there other common actions that can cause the flash to lock? If I ran blink on a Due for a long period of time power cycling it randomly would the same error eventually occur? This seems to be a common issue with the due but beyond this library I have not found other causes.

the count of writes to flash si limited. with the flash library you can write data to flash. did you do many writes to flash?

For my current setup I do write to flash but not close to 10,000 times before the flash page locks and it becomes complicated to reprogram the due. I'm using 10,000 as a conservative maximum. If I did not write to flash in my program is there any reason why the flash would become locked?


text:
Is it possible to connect many (20+) SPI sensors to an Arduino Mega?
I am making a system for measuring whether or not there is vacuum present in big steel containers. They are located up to 100 meters from the control cabinet.
The question is, how many SPI sensors can I successfully use at the same time with an Arduino Mega?
I have two main concerns, and there are probably more things I didn't think about.
Signal strength
The shared lines for CLK, MOSI and MISO will need to be split up at several junction boxes and led to the different sensors. Since the voltage out from the Arduino is fixed, I'm fearing instability because the signal is weaker for some sensors, has someone done something similar? What is the greatest acceptable voltage loss for these lines to an ordinary sensor?
Processing
Will the SPI library be fine coping with this many sensors?
The refresh rate can be set to extremely low, thinking 0.3Hz.
The alternative to all this is to go for 4-20mA sensors and have a 0-5V converter circuit for each sensor, near the controller.
Any inputs would be greatly appreciated!

The spi bus is ment to be used on the same board, or else for a very short distance. The i2c bus is also for short distances (because of its weak pullup signals). The rs485 is for longer distances. Which board to you use? The arduino mega 2560 is not the same as the esp8266. The 4-20mA sensors will work but when such long cables are connected to the arduino, that might damage the arduino. Do you use shielded cables? Perhaps there is a module for multiple 4-20mA isolated inputs and with a digital interface to the arduino.

I'm thinking of using the Arduino Mega 2560 to receive and convert all signals, and then transmit data lines to an ESP8266 ESP07, which sends all data via MQTT over Wifi. I haven't bought the cables yet, but I was thinking to use individually shielded cables, yes. The supplier says the 4-20mA sensors will be fine for 100m. The arduino is the digital interface here really, if there's something else better suited, let me know. I'd like to use the Arduino IDE to program in, because I know it well already.

the user has declared that he is no longer interested in the question and did not upvote any of the answers.   it is a noteworthy subject which should get community attention regardless.

You can control as many SPI devices as you can set the CS line for. You can even control all the CS lines from a SPI device. A SIPO register will help a lot there.
However you are probably better off using a proxy board to actually connect to the sensors and then connecting the mega to the proxy to communicate the measurements using a connection that is more robust over long distances.

Since the Arduino Mega 2560 has a lot of DI/DO, that's why I wanted it to control many CS lines. I'm new to SIPO, is that a good solution for communicating over several cables? A proxy board can be a solution, wires need to be run anyway... but I would of course want to keep the complexity as low as possible. What kind of board would be suitable for that, another arduino, and which cable between them?

Relevant suggestion, UPVOTED.  :)

You need to drive SCK, MOSI, and 20 chip select lines long distance, and then receive MISO back long distance.
The number 20 for slaves is not a problem.
Long distance and maintaining signal integrity will be a problem.
I would suggest a bussed newtwork and send serial data to/from 20 slaves (like ProMini) and let the slaves do the SPI data gathering and then pass that data back to the Master Mega in a polled fashion: #1 send your data, #1 here it is. #2 send your data, #2 here it is. Etc.
Then you just need to connect up a 3 wire bus  (RS485+, RS485-, Gnd) from device to device to device with termination resistors at the end of the run. Power each device seperately vs running power to all of them.
Maxim has some nice tutorials on connecting up RS485.

Hi and thank you for your reply, however this was half a year ago, and I've since completed the project using 4-20mA sensors with separate wires. It turned out to be a flexible and rugged way of doing it, despite using many cables.

I would recommend using multiplexer(s) for the task.

Originally from this tutorial.

Or this tutorial by Sparkfun


text:
Where can I find the source codes for the various classes and methods used in Arduino Primo?
I am new to Arduino development. I am trying to connect a BLE device (Arduino Primo) with my iOS app. From the Arduino BLE examples, I understand how to initialize the BLEperipheral class and then call the setValue method to pass value to be transmitted. However I do not want to be dependent on example codes, rather I want read the source code and definitions to know about the available classes and their methods, what argument types passed etc.(not precompiled libraries with .o extension).
For my current issue, I want to know what type of arguments does the setValue take in the BLEperipheral class. Can I pass an int value(4 bytes) or it has to be a char only? These questions can be answered by reading the source code of these inbuilt libraries.
Any direction would not only help me with the current project, it would also help to tackle and understand any projects in the future, where I might use inbuilt library calls.
I have searched the internet, however not much information is available for newcomers like me.
Below is a similar question link but outdated and does not solve what I am looking for.
How can I get the source files for Arduino libraries?
Thank you for any suggestions.

you have them on your computer in arduino15 folder

Sir, i have checked all the folders in my computer and even my neighbours computer too. hehe. There is no such folder called ardunio15 nor any reference to the information i am looking for.

The Arduino Primo is supported by Arduino nRF52 boards package. The boards packages can contain libraries special for boards handled by the package. The BLE library for Arduino Primo is included in the board package.
The location of boards packages on Windows is in hidden folder AppData in user's home directory. On my Windows computer it is
C:\Users\andrassy\AppData\Local\Arduino15\packages\arduino\hardware\nrf52\1.0.2\libraries\BLE

On Linux the 'Arduino 1.5' folder is .arduino15 in users home folder.


text:
Create a device to detect object and voice alert what kind of object it is
Here is what I want to do (since I'm not a embedded guy)

create a prototype with an Arduino to detect objects using camera(object classification?)
that prototype will detect objects and alert that object's name

My questions are....

Is it possible? :)
What things should I use to create a prototype?
What camera should I use?
Is it related to image processing?
Connection between object detection and voice alert?

I don't think arduino is sufficient for this. Maybe with camera which can detects objects itself and voice recognition module.

The Arduino is not the ideal platform for you since it is more "lightweight" and can't really meet the demand that your application is expecting.
A platform like for example Raspberry Pi that has a full-blown operating system and a lot of tools that fulfils your application needs.

Thank you so much sir!!


text:
Mapping segments and memory allocation on a segment LCD driver
I've just configured a segment LCD and driver, everything works fine, but because I decided to not use vias on the PCB, the connections between the two are mixed.
To be more precise, in order to display the number 12, both memory addresses should be accessed.
So right now it's impossible to display a single digit without mapping all the segments.
In static mode, this is how RAM memory is allocated to SEG0-SEG7 and SEG8-SEG15 respectively:

What I've tried was to create two multidimensional arrays and map possible combinations of the two digits, like this:
// 01 to 09
const byte map1[10][2] = {
  {B01110111, B111111 },
  {B01110001, B100111},
  {B01111011, B011111},
  {B01111011, B110111},
  {B01111101, B100111},
  {B01111110, B110111},
  {B01111110, B111111},
  {B01110011, B100111},
  {B01111111, B111111},
  {B01111111, B110111}
};

// 10 to 19
const byte map2[10][2] {
  {B00010111, B111100},
  {B00010001, B100100},
  {B00011011, B011100},
  {B00011011, B110100},
  {B00011101, B100100},
  {B00011110, B110100},
  {B00011110, B111100},
  {B00010011, B100100},
  {B00011111, B111100},
  {B00011111, B110100}
};

If there is no way to mix or map them in a dynamic way so any possible combination between 00 and 99 can be achieved, the only solution is to add vias on the PCB and rewire everything as explained in the datasheet.
Any ideas?
Thanks

please explain how this post is about an Arduino

Have a lookup table, to map each segments to a bit in LCDs memory (14 (or 2x7) segments, mapping (probably easiest) a uint16_t for the bit). Then another lookup table for numbers (0-9) to segments. There's multiple ways to do this. I've done this myself, where having an easier layout meant some additional abstraction in my code to fix the weird pinout choice. What I've done sometimes was write some separate code that generated the 0-99 array; copy-paste that into my sketch. This makes the code run really fast, as it's just a lookup. To save RAM I've used PROGMEM, to keep the table in flash.

The trick here is to employ both a local memory buffer, and digit masking.
Step one: create a pair of masks that define which bits of the memory are associated with which digit.
Imagine you have your digits wired in this order in memory. For simplicity I am working with 16-bit values, but there is no reason why you can't split them into two 8 bit values each if you find that easier (P is the decimal point. Lower case is the left digit, upper case the right digit):
      MSB                         LSB
      a C d g E B p A c D f b e G F P

You would then create a pair of corresponding 16-bit values that represent which bits are associated with each digit.
      MSB                         LSB
      a C d g E B p A c D f b e G F P
Left  1 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0
Right 0 1 0 0 1 1 0 1 0 1 0 0 0 1 1 1

The right is just the inverse of the left, so for right you can actually use ~left and save yourself 2 bytes.
So that would end up as:
uint16_t leftDigit = 0xB2B8;
uint16_t rightDigit = 0x4D47;

Now you create yourself a table of which segments create which numbers. Now the magic here is that you don't want individual digits. Not yet. What you want is a table of 16-bit values that represent the numbers 00, 11, 22, 33, 44, 55, 66, 77, 88, 99 (and optionally two spaces, but that's just 0x0000, so you may not need to store that explicitly).
You may end up with something like:
uint16_t digits[] = {
    0b1110110111111010, // 00
    0b0100010010010000, // 11
    0b1011110101011100, // 22
    // ... etc ...
};

Now the real magic happens.
You need a memory buffer that mirrors the contents of your driver memory.  You don't directly modify the driver memory - you modify your memory buffer, and then send both bytes of it to the display driver at once, updating all the segments together.
uint16_t buffer = 0;

Now to set a digit you first need to erase whatever is in the bits that correspond to the digit you want.  Let's say we want to display the number 12.  We'll start with the left digit.
// Step one, erase the left digit
buffer &= ~leftDigit;
// Step two, place into it the bits for 1 with the left digit mask imposed:
buffer |= (digits[1] & leftDigit);

// Step three, erase the right digit
buffer &= ~rightDigit;
// Step four, place into it the bits for 1 with the left digit mask imposed:
buffer |= (digits[2] & leftDigit);

That is actually quite a long winded way. But it does allow you to just change one digit without affecting the other.  If you want to just replace the entire content of the display (both digits at once) then you don't need as much work:
buffer = (digits[1] & leftDigit) | (digits[2] & rightDigit);

I'll just dismantle that for you so you can see what it does.
            MSB                         LSB
            a C d g E B p A c D f b e G F P
 digits[1]: 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 0
 leftDigit: 1 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0
       AND: 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 // b and c enabled

 digits[2]: 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0
rightDigit: 0 1 0 0 1 1 0 1 0 1 0 0 0 1 1 1
       AND: 0 0 0 0 1 1 0 1 0 1 0 0 0 1 0 0 // A B D E and G enabled

OR of ANDS: 0 0 0 0 1 1 0 1 1 1 0 1 0 1 0 0 // b c A B D E G enabled

And map those segments on to the standard layout of a 7 segment display:

And you form the number 12.
Then you take the buffer value and write it out to your display memory.  You can split the 16 bit value into 8 bit values with bit masking (& 0xFF) and bit shifting (>> 8).
uint8_t b1 = buffer & 0xFF; // Lower byte of memory
uint8_t b2 = (buffer >> 8) & 0xFF; // Upper byte of memory

An excellent answer, thank you so much for your time and effort. I'll give it a try today and get back to you with updates.


text:
How to Compile Different Sketches in Different Visual Studio Code Workspaces
I'm using Visual Studio Code with the Arduino extension. I have two workspaces each with a different sketch file loaded - Sketch_1 and Sketch_2. Sketch_1 will verify and upload properly. When I click on the Verify to compile or Upload buttons for Sketch_2 in its workspace, VS Code verifies and uploads Sketch_1, not Sketch_2. Am I doing something wrong, or is it not possible to separately Verify and Upload different sketches in different workspaces?

The first time you verify your sketch you are confronted with a list of available sketches (INO's). As soon as you select one of these it gets stored under "sketch" in .vscode/arduino.json.
If you zero this, "", you'll once again be asked which sketch to set as "main sketch".
This "device context" is stored per workspace so you might consider narrowing your scope when opening a folder. I know this is no fun when exploring, and the will to switch and try different examples is big, but currently there are nothing that facilitates a smoother alternative.