text:
How to link a computer processor to an Arduinno on a board?
I am completely new to Arduinno, so please forgive if the question is stupid.
Here is the problem: I have a project where I want an Arduino (or similar microchip board) to handle some sensors and actuators. But I need very advanced "artificial intelligence" to handle the data provided by those sensors.
There are two major obstacles for placing this intelligence on the Arduinno, according to my researches.

First, the Arduinno is coded in a language similar to C: I could of course find a way to write the intelligence, but it will be a time-consuming task for the developper
Second, I might encounter a problem with memory: I will store heavy matrix of data, do complicated calculation, and this might be too much for an Arduinno
Third, I read on stackexchange that there are some ways to compile Python code on Arduinno boards, such as the Arduinno Mega. So I can code this intelligence in Python (which is an easy task), and compile the resulting code on Arduinno. However, I will reach a caveat: some libraries I will use will be entirely compiled, and this will take too much memory on an Arduinno (such as the second issue I mentionned)

So I have another solution, but I am not sure if it is state-fo-the-art, or even a feasible solution:
I would like to separate two tasks:

Write an Arduinno code to handle the sensors and create numeric data
Write a Python code on my computer and compile it as an executable file on my computer
Then somehow, I "extract" the processor of my comouter (Intel, by the way) and I plug it on the Arduinno board. The Arduinno sends the data to the processor, and the processor runs permanently the Python file and gives back data

So question:

Is it possible overall?
Was it ever made?
What communication links are good for exchanging data between processor and Arduinno microchip: USB, Serial, Ethernet?
How can I handle the input of the processor, so that it collects data from the Arduinno and then uses it in the Python code?

Get a pi. That should do everything all in one.

It sounds like you need a lot of compute power. You can either put the sensors and AI on one device (and @majenko's suggestion of a Raspberry Pi would be a direction to pursue) or you need two devices, one to manage the data collection - Arduino, perhaps -  and one to do the AI. We don't know enough about your post-processing and AI to make a good recommendation, but, as you already have a PC with Python running on it, an Arduino talking to the PC would be a good start.
You didn't say which Arduino you're considering, but as most people mean "Uno" when the speak of a generic Arduino, I'd just suggest that an Uno is far too under-resourced for the post-processing part of your project, but probably ideal for the data collection. Cross-compiling your Python code for an Uno still doesn't address its processing speed and memory size limitations.
There are, of course, a lot of "Arduino" products, some with considerably more resources, that may approach your needs - I'm thinking of the Arm-based boards, here - but I've no way of evaluating your project needs at that level.
My own first approach would be to use what you have, to start with: an Uno collecting data and sending it to your PC. Once you have something running, you'll understand the needs and issues better and if you still want a stand-alone solution at that point, you'll be much better able to make that choice.

I may handle this case like using pyserial library I just log the data to my laptop and then using python to do your Advance AI code part.

Send the sensor data as a combined String via Arduino serial port.
read it using pyserial library
add a data logging mechanism if you need or parallel process the data you gathered serially by cast them to their own data type.

Hope this may help you.
Thank you

Thank you, I will look out those. A remaining question is: what hardware is needed to run a typical Python script (I don't need the screen of the computer for example, I do need the processor, do I need the GPU?)

@totalMongot I think you can try with some ARM type boards like RPis or Odroid XUs. But in the initial setup, you need a GUI However. About direct flashing the python script to Arduino this will help you>>>> https://arduino.stackexchange.com/questions/49187/running-python-script-using-arduino

Thanks! :) Is it possible to dismantle a computer and take only the core and some USB and serial ports to achieve something similar to the ARM boards, which can communicate with Arduinno? The GUI would be achieved by plugging a computer to the USB port

yes write your python code as try except (for safe the flow of your script) and run the python script as a daemon(Similar to starting an application from the startup sequence) so it will always on working on the background.
I think this link will help you >>>> https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/
"The GUI would be achieved by plugging a computer to the USB port" >> Yeah if there any HMIs or pi display which can able project via USB it's possible.

For AI use there is the K210 based sipeed maix board. Dual core 400MHz, plus an AI coprocessor.

I suggest that you use a different family of processor than the 8-bit AVR chips that are supported  by the Arduino IDE (and please fix your spelling errors, all the double-letter words are very distracting). A good example might the the Teensy 3.2 or Teensy 3.6 offered here  https://www.pjrc.com/  "Version 3.6 features a 32 bit 180 MHz ARM Cortex-M4 processor with floating point unit" Arduino is programmed in C++, see if your code can be exported in C++ and import it into the IDE for compiling for the selected uC.


text:
For what is used an ESC with a PWM?
So I was reading a few questions on drone, and I reach this one.
It said that an ESC is used between the PWM Arduinno's port and the motor. I don't really understand what it means. According to what I understand, a PWM is a varying signal and you just need an electric relay to receive this signal so that the motor receives correct voltage.
However, in other article I read that there are many different ESCs, with firmware and many other parameters to be taken into account. It seems quite overkill for what a relay does, so I am wondering:

What is inside an ESC?
More important, what does it do with PWM signal that could not be achieved with a relay and is essential to command the motor?

An ESC is an Electronic Speed Controller. It's purpose is to control the speed and direction of a Brushless DC Motor.
A Bushless DC Motor ("BLDM") is not like other motors. You can't just provide it power and it will spin. Instead it is made up of three (or multiples of three) electromagnets along with a permanent magnet on the rotor. Energising these electromagnets in the right order at the right time (and the right amount, too) pulls the permanent magnet around in a circle, making the motor spin.
It's the ESC that has the job of controlling these electromagnets.
You provide a PWM signal as a digital speed indication. The ESC then interprets that as an indication of how fast you want the motor to turn, and excites the electromagnets in the right way to make that happen.
Oh, and no, you certainly never want to provide a PWM signal to a relay. A PWM signal switches hundreds, if not thousands, of times per second. A relay is capable of switching, at best, maybe 10 or 20 times per second.  Relays don't drive motors. Motor drivers (or at the bare minimum, MOSFETs) drive motors.

You could get a brushed motor instead of the BLDM, so you don't need an ESC. But you'd still need something like a motor driver or MOSFET, since the Arduinos digital pins can supply enough current for a motor.

Thank you, exactly the answer I am looking for. I just wait for some people to see the question before accepting it. I have a question as a result of your explanation: is an ESC specific to a motor (I suppose the architecture of the electromagnets could influence the timeline of energise)?
And could you explain please the word "MOFSET"?

@totalMongot Metal Oxide Semiconductor Field Effect Transistor. Like an electronic switch. Yes, different motors have different characteristics, but in general they are only minor differences and the only key things you need to consider are the current (select an ESC that is powerful enough) and the maximum acceleration rate (which you control with how fast you change your PWM values).

source: Stack Exchange

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

sort: votes


text:
How to use 5v and 12v addressable led strip together
Hi guys I’m new to this forum and also not much experience about led lights question already asked but didn’t get any detailed answer I want to know can I provide working data signal to 2 different 5v and 12v addressable led strips or what should I do to work them in same patterns at same time it will be really big help please and thanks in advance I’m sure I’m at right forum because usually I get all my answers by you guys without even asking

Actually this is not a forum, but a Q&A site. About what LED strips are we speaking? Can you maybe provide links to the products or provide part numbers?

Welcome! Would you mind to provide some details, like links to data sheets of the LED stripes, and a (simplified) schematic? Or if this is a software problem, show us some code? -- Since you're apparently have been here some time already, you know for sure that you can [edit] your question, don't you?

use a level shifter

Thanks busybee for helping me to make my project at the moment I have little knowledge about 5v strip it’s sk6812 5050 individually addressable but soon I can send you all the information with data sheet because 12v strips still not in my hand but thanks so much helping me I promise as soon as I got the shippment I’ll provide all the details ok dear I’ll get back to you asa I get me strips

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


text:
arduino labview basic serial communication
I am trying to have a 2way serial communication between LabVIEW and Arduino. I tried to make a basic program to grasp the concept but it does not seem to work.
Labview (2 int values) >> Arduino read
Arduino (1 int value) >> Labview read
Here, my LabVIEW program has 2 double variables which I put in numbers (they will later be cast to an int). Then, it is put into an array and converted to a comma-separated integer string. This is then written to the VISA port.
On the Arduino side, the serial port is read using the serial.parseInt function. Then the int is then converted into a 2-byte array which is then written to the serial port.
This is then read by the LabVIEW with VISA read and the string is converted to a byte array and reconstructed into an I16 integer.
Currently, the results are as follows:
The sent number are 80 and 80 and after being received by the Arduino and relayed back, the results displayed is 6961 as a string and 26977 in int form.
The arduino program works with the serial monitor where if the number 19789 was put in, it would output MM.

void setup() {
  Serial.begin(9600);
  while(!Serial){;}
  Serial.println("serial ready");
}

int input;
int input2;
void loop() {
  // put your main code here, to run repeatedly:
  if (Serial.available()>0){
    input = Serial.parseInt();
    input2= Serial.parseInt();
  }

 byte buff[2];
  if (Serial.read() == -1){
    buff[1] = (byte)input;
    buff[0] = (byte)(input>>8);
    Serial.write(buff,2);
  }
  delay(100);
}

labview VI

It's not entirely clear what you're actually sending or receiving. FWIW if you shift 80 (0x50)>> 8 you're going to end up with zero. You're also throwing input2 away, perhaps that was intentional. It might be a good idea to isolate each side of the comms, e.g., test the Arduino code in isolation until it's doing what you actually want, and introduce LabView afterwards.

yes, I know that it will be removed since int is 2 bytes and I would like to split the int into 2 bytes in the array for sending. Then these 2 bytes will be reconstructed later in LabVIEW. this is done in case i am sending a number larger than 256.

It's an int, you can just check if it's > 256 and stuff 0 info buff[0]. The intent isn't particularly clear, though.


text:
Pyfirmata util.Iterator causes serial communications issues with more than one Arduino
I'm using two Arduino Megas in a project to read data from a bunch of analog sensors and then output PWMs on digital pins according to their value. These analog signals are also being plotted on a dash app.
I'm using pyfirmata, and the program runs perfectly with either one of the two boards connected. However, when I connect both boards, The second board (second in terms of its pyfirmata.util.Iterator object being instantiated second), will always report nonetype objects when calling board2_some_analog_pin.read()
I found essentially the exact same problem here
Putting the iterators on separate processes fixed the nonetype issue for me too. However I want to know why this would fix things, because I want to be confident there isn't a threading-based solution to the nonetype problem before I start reprogramming everything to work with processes.
My instinct tells me it has to do with this code:
class Iterator(threading.Thread):

    def __init__(self, board):
        super(Iterator, self).__init__()
        self.board = board
        self.daemon = True

    def run(self):
        while 1:
            try:
                while self.board.bytes_available():
                    self.board.iterate()
                time.sleep(0.001)
            except (AttributeError, serial.SerialException, OSError):
                # this way we can kill the thread by setting the board object
                # to None, or when the serial port is closed by board.exit()
                break
            except Exception as e:
                # catch 'error: Bad file descriptor'
                # iterate may be called while the serial port is being closed,
                # causing an "error: (9, 'Bad file descriptor')"
                if getattr(e, "errno", None) == 9:
                    break
                try:
                    if e[0] == 9:
                        break
                except (TypeError, IndexError):
                    pass
                raise
            except (KeyboardInterrupt):
                sys.exit()

found on the pyfirmata github repo here
I've been searching around for days, but still have no clue why this would cause whichever board is tied to the second instance of the iterator object to only give nonetype objects as analog reads. It's not a serial communications problem, because some_digital_pin.write(pwm) works for both boards when both plugged in.
Any help or insight into this issue would be greatly appreciated, as well as tips on how to bypass this issue to allow both boards to read without using multiprocessing.

Doesn't seem like it'd be this code if it's not a serial comms problem, rather something relating to how values are read or stored locally (if they are). No access to machines at the moment but I may take a look this evening. Does reading a digital pin show the same behavior?

Also, did you try via get_pin? And did you try the solution in the linked post? My current guess is that the issue is solvable with some minor tweaks to pyfirmata but I'll need to get a test env set up.

It is not a serial comms problem, I'm pretty sure. Both arduinos are detected fine. When either one is plugged in, they analog read fine. Only when both are plugged in and I run a program that has two pyfirmata.utils.iterator objects, does the arduino with the second iterator only report nonetypes. It's not an arduino issue either because I can swap the arduinos and it's always the one with the second iterator instance that gives nonetypes. Furthermore, setting PWMs on output pins work fine, suggesting no comms issue.

@DaveNewton I did not try get_pin, but I did try the solution in the linked post. It worked. However, for my application, just printing values to console is insufficient, so I'll have to either rework my entire code + modules to work with multiple processes, or, which I'm really hoping might be the case, there's some threading options or functions I can use to solve whatever is causing this issue with the two arduino iterator threads.


text:
nRF52 non-volatile storage/recall of a variable - is there a simple solution?
I have an Arduino program written for the nRF52 with which runs for a pre-set time-value (i.e. 2 minutes) before shuts off automatically.  The variable time-value can be changed via BLE-write by the user from an external device (i.e. from 2 mins to 5 mins). The problem that it defaults to the pre-set (2 mins) value once the program restarts.  How can I have the program "save" the last used time-value variable (i.e. 5 mins) for the next boot up/restart?
As I understand Nordic's nRF52 does NOT have an onboard EEPROM like AVRs.  I read about a Little File System by Adafruit that creates a sort of persistent storage space, but I hope there is something simpler.

Your options are the internal flash or an external EEPROM. If you're dealing with the internal flash then some sort of FS is likely the easiest choice. External EEPROM/FRAM can be as simple as an I2C chip and library. LFS doesn't create a "sort of persistent storage space", it's an FS abstration. There's also things like https://github.com/d00616/arduino-NVM.

https://www.arduino.cc/reference/en/libraries/arduino-nvm/

Thank you both.  I am digesting the linked information.  Will decide and try.  So far, I gathered that I need to be careful with not placing any write/erase related functions inside the "loop" as not to "wear out" the memory.

Reviewed the options. Just thinking out loud: Adadfuit already has some QSPI libraries and the chip on their boards. But requires 6 wires (normal SPI 4 wires). NVM is a no-external-parts solution, but does interfere with the nRF5's BLE softdevice stack requiring some fancy programming.   I am leaning towards EEPROM and FRAM for ease of addressing/programming, but both require some (small) external real estate.  However only a 1 or 2 wire I2C interface.

One other options is that upon bootup the sketch on my device would read user-selected values on the connected external BLE device app (phone, ectc) and use them as the variables values in the sketch:  for example time-delay selection for auto-off. .

The arduino-NVM library for nRF51 and nRF52 MCU has EEPROM object which emulates EEPROM in the internal flash memory of MCU.
The EEPROM object in arduino-NVM has the same functions as the EEPROM object in the Arduino EEPROM library for classic ATmega.


text:
Stepper motor only rotates once in a loop?
I am quite new to this , I am trying to program two motors , aStepper and bStepper.
I want the program to rotate aStepper then rotate the bStepper and when that is done rotate aStepper again , and then repeat.
The first iteration works fine.However, it only does the loop once and the bStepper doesn't rotate again.
Am I doing something wrong with the loop?
(aStepper is the UNIPOLAR 28BYJ-48 connected to its driver , and bStepper is a Nema 17 connected to A4988)
#include <AccelStepper.h>
#include <Stepper.h>

#define StepsPerRotation 2038

#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1

AccelStepper bStepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
Stepper aStepper(StepsPerRotation, 8, 10, 9, 11);

void setup() {

  bStepper.setMaxSpeed(200);
  bStepper.setAcceleration(30);
}

 void loop() {

   aStepper.setSpeed(20);
   aStepper.step(1016);

   bStepper.moveTo(-6000);
   bStepper.runToPosition();

   aStepper.setSpeed(20);
   aStepper.step(-1016);
}

Thank you in advance

How should bStepper move again after the first time? You directed it to go to position -6000, so it will go to -6000 on the first run. On the second it already is there, so further movement

Oh , I thought after it completes the loop it would just run again. How can i better approach this? with bstepper.runSpeed(); instead?


text:
Interfacing 4 ESCs and an Arduino with a single LiPo battery
I have 4 BLDC motors, and 4 ESCs, one for each motor. But I have one LiPo battery from which I want to power one Arduino Mega and all the 4 ESCs. Can I remove the connectors from the ESCs and put them on a breadboard in a single column/row so that they are connected together, and then connect the + and - of the battery (after removing its connector as well) to the respective breadboard column/row, so that they are essentially connected together to power all the ESCs? Also, I would want to use a jumper from the Arduino Vin and GND pins to the same column/row on the breadboard. Will this method of powering all the 4 ESCs and the Arduino from a single LiPo work?

Yes, but you don't want to use a breadboard for it.

Please edit the post to explain what ESCs and BLDCs are.  These are not obvious acronyms.

Powering all the ESCs from a single LIPO is not an issue.
Using a breadboard to distribute this power is highly unlikely to work, breadboard connectors are usually only good to a few hundred mA, 1A is you want to push your luck.  Most ESCs and BLDC motors are in the 5A to 50A range (each, your power bus has to handle 4 times this current).
Also, ESCs tend to inject a lot of noise into the power bus.  If you connect the arduino to the ESC power bus, you will likely get random resets and really poor noise performance on the ADCs.  Keep in mind that some ESCs actively brake the motors using regenerative braking, which puts the kinetic energy of the motor back into the power bus.  This can increase the voltage on the power bus to more than the nominal battery voltage and can have large voltage spikes on it causing a failure on the Arduino.
If you are prototyping, use a separate power supply/battery for the arduino and connect all the grounds together instead of using a single supply.  If you are building a rover/uav/whatever and don't want a second battery, use a high quality BEC (or the BEC output from a high quality ESC) and remember that the 5V output on a BEC/ESC can be significantly higher than 5V in reality).
ESC = Electronic Speed Controlled
BEC = Battery eliminator circuit (I think, basically a 5V-ish regulator)
BLDC = Brushless DC motor (three phase in this case)


text:
What is the correct folder structure for including local headers in my Arduino project?
I am designing a "project" with 5 Arduino's (each with separate codes), communicating with each other using NRF24. All the 5 codes are different except they share a common header "MyHeader.h". The Arduino IDE forces the .ino filename to be same as the folder-name it is in. I currently have the following structure:
[parentfolder]
    MyHeader.h
    [arduino1]
          arduino1.ino
    [arduino2]
          arduino2.ino
    [arduino3]
          arduino3.ino
    [arduino4]
          arduino4.ino
    [arduino5]
          arduino5.ino

Now, if I use the following, I get an error that the IDE cannot find the header file:
#include "../MyHeader.h"

I am forced to use the above structure due to the IDE folder naming restrictions, whereas I would definitely like to have a structure like the following:
[parentfolder]
    MyHeader.h
    arduino1.ino
    arduino2.ino
    arduino3.ino
    arduino4.ino
    arduino5.ino

How should I organize my project so that I can include my header (without obviously duplicating the file inside every folder)? Thanks.

check out https://uecide.org

put MyHeader.h in Documents/Arduino/libraries/MyHeader folder

Does your filesystem support symlinks?

The reason why you can't reference the parent folder of your sketch when compiling is because the Arduino IDE doesn't compile your sketch in that folder. Instead it writes out the files from the IDE itself into temporary files in a "build" folder and compiles them in there - so the parent folder then does not contain your header file because the IDE has no clue about that.
So you need to put your header file somewhere that the IDE does know about - and the simplest place is where the libraries are.
A library is nothing more than a header file in a folder (both named the same) with optional source and other header files.  If you place your header in a folder in your libraries folder the IDE will see it as a library and you can include it into any sketch.
So you would have:
Documents/
    Arduino/
        libraries/
            MyHeader/
                MyHeader.h
    MyFancyProject/
        NodeOne/
            NodeOne.ino
        NodeTwo/
            NodeTwo.ino
        NodeThree/
            NodeThree.ino


text:
How to retrieve a page from a web-server using ESP8266 with the program running on Arduino instead of the ESP module?
I have connected an ESP8266-01 module to an Arduino as in the following schematic with the RX and TX pins changed to pins 8 and 9 instead of 0 and 1:

I am using the ESP8266wifi library at the following link:
https://github.com/ekstrand/ESP8266wifi
I have looked at the ESP8266HTTPClient library but that is for the ESP8266 board. I want my code to run on the Arduino Uno and not on the ESP8266! I have written the following code:
#include <SoftwareSerial.h>
#include <SerialESP8266wifi.h>

const String API_PASSWORD = "stn1234";

#define RX_PIN          8   // RX of Arduino (connected to TX of ESP8266)
#define TX_PIN          9   // TX of Arduino (connected to RX of ESP8266)
#define ESP_RESET_PIN   12

#define SERVER_IP           "192.168.43.234"
#define SERVER_PORT         "80"
#define WIFI_SSID           "MyWIFI"
#define WIFI_PASSWORD       "myWifiPassword"

uint8_t wifi_started = false;

const char RST[] PROGMEM = "RST";
const char IDN[] PROGMEM = "*IDN?";

#define CHANGE_DELAY        5000

void initializeWifi();
void transmitData(String);
String getResponse();
void transmitStatus();

SoftwareSerial swSerial =  SoftwareSerial(RX_PIN, TX_PIN);
SerialESP8266wifi wifi(swSerial, swSerial, ESP_RESET_PIN, Serial);

void setup()
{
    Serial.begin(9600);
    Serial.println("Initializing...");
    initializeWifi();
    Serial.println("Initialization complete");
}

void loop()
{
    transmitStatus();
    Serial.print("Transmission complete, ");
    int s = (CHANGE_DELAY/1000);
    Serial.print(s);
    Serial.println("s until next cycle");
    delay(CHANGE_DELAY);
}

void transmitStatus()
{
    int a = (int)random(100);
    int b = (int)random(100);
    String url = "/LocalWebProject/api/testConnection.php?a=" + String(a) + "&b=" + String(b);

    transmitData(url);
    String response = getResponse();
    Serial.print("Reply received: ");
    Serial.println(response);
}

void initializeWifi()
{
    swSerial.begin(115200);
    Serial.println("Starting Wifi");
    wifi.setTransportToTCP();
    wifi.endSendWithNewline(false);     // Will end all transmissions with a newline and carrage return ie println.. default is true

    wifi_started = wifi.begin();
    if(wifi_started)
    {
        Serial.println("Wifi started, connecting to AP...");
        wifi.connectToAP(WIFI_SSID, WIFI_PASSWORD);
        Serial.println("Connected to AP");
    } else {
        Serial.println("ESP module not working");
    }
}

void transmitData(String url)
{
    Serial.println("Connecting to server...");
    wifi.connectToServer(SERVER_IP, SERVER_PORT);

    String data = String("GET ") + url + " HTTP/1.1\r\n" +
           "Host: " + wifi.getIP() + "\r\n" +
           "Connection: close\r\n\r\n";

    Serial.println("Connected. Transmitting data...");
    wifi.send(SERVER, data);
}

String getResponse()
{
    while(1)
    {
        Serial.println("Waiting for response...");
        WifiMessage in = wifi.listenForIncomingMessage(6000);
        if(in.hasData)
        {
            if(in.channel == SERVER)
            {
                Serial.print("Reply received from the server: ");
                Serial.println(in.message);
                return in.message;
            }
        }

        delay(1000);
        Serial.print("Retrying, ");
    }
}

I have an Apache server running on Ubuntu 18.10 with a PHP project running on port 80. The testConnection.php page takes 2 GET parameters (integers) and returns the sum.
Problem:
It says that ESP module is not working. The AP in my case is a local hotspot on my mobile.
I have tried running the given example "SerialESP8266_library_test" and confusingly enough, it prints that it has successfully connected to my AP, but on my phone I do not see it connected. Only 1 device is visible as connected, which is my laptop which is running the Apache server and the web project. Also connectToAP returns 1, and connectToServer returns 0.
What am I doing wrong? I know that the ESP module requires power and the Arduino 3V3 is insufficient but I am just testing the code right now and I will do the required changes later on. Due to this, I am placing my Android phone just beside the ESP module so that it has no problems connecting to it.
Any help would be greatly appreciated! Thanks in advance.

https://github.com/jandrassy/WiFiEspAT/blob/master/examples/Basic/WebClient/WebClient.ino

swSerial.begin(115200). I don't think softwareSerial can even run that fast. The library you are using for wifi uses 9600 baud. I'd give that a try.

@Gerben Some modules are 9600, some are 115200 - it depends on the version of the firmware. SoftwareSerial can run at 115200, but it can't react fast enough to incoming bytes to reliably receive a stream of data.

@Juraj The WiFiEspAt requires flashing with AT 1.7, I did not want to do that

@Gerben I tried with 9600 and made some other changes. Now, it correctly connects to the AP (shows up on my phone), also connects to the server. But receives a HTTP 400 Bad request error. Is there any problem in the GET request format? My page is at:  http://192.168.43.234/LocalWebProject/api/testConnection.php

Host header value should be the name or IP of the server

@Juraj as per the examples, etc., the host is the local IP of the ESP module. Anyway, I tried your suggestion by providing the SERVER_IP there but still I get the same problem

the HTTP protocol is not defined by this example

Finally it is working by setting baud rate to 9600 and shortening the GET URL. Maybe there is a length restriction in the library.


text:
Fluctuating voltage coming out of arduino uno 3.3 output pin
Problem with my arduino is when I check voltage of 3.3 volt pin using multimeter , voltage varries a lot from 1.5v upto 5v. Due to which esp8266 wifi module connected to this 3.3v pin gets very hot.
Is the arduino is faulty or can me made to produce steady 3.3 v . Kindly suggest .
Thank you.

Please post your circuit.

The ESP8266's power consumption is higher than the power regulator on the Arduino UNO board can deliver. You have to find another power source!

The Arduino cannot power an ESP8266 directly.
A genuine Arduino has the LP2985 which can provide up to 150mA (about a quarter of what you need for an ESP8266) and will go into "thermal shutdown" when it gets overloaded.
However, a Chinese (or other cheap) clone could use something even less powerful, with or without thermal protection.  In this case overloading the 3.3V pin could irreversibly damage the 3.3V regulator (which may be internal to the USB chip, killing the USB connection in the process) and thus render it unable to regulate the voltage down to 3.3V properly.
If the latter is the case then it is also possible that the higher voltage passed through by the failed regulator could have also killed the ESP8266 chip.

I am sure the voltage is stable without load. Voltage fluctuations are sign of not enough current available.
If you look into the Uno specs, you will find out that the 3.3 V pin can supply max 50 mA.
If you look into esp8266 datasheet in power section you will find out that it needs far more current than 50 mA.
Power the esp8266 from 5V pin over a voltage converter.

Actually that limit of 50mA is a lie. It used to be the case, when the 3.3V was taken from the internal regulator of the FT232 chip (that pin was actually intended to just have a capacitor on it, but Arduino decided to leach power from there too), and that was limited to 50mA. But the LP2985 3.3V regulator used on modern Uno boards can actually provide up to 150mA. Still, that's way below what the ESP8266 needs, so your answer is still correct :)

I have only Uno WiFi and it can 1A from 3.3V pin :).

Is that all? I have the chipKIT Pro MZ (one of only 10 in existence) and it can provide 3A from the 3.3V pin :P  Thanks to the TPS82130SILT (sexxxxiest regulator module ever created...!)


text:
Uno doesn’t get enough power from 5v barrel connector. Why?
I’m using a 5v 20a power supply run through a barrel connector into an Arduino Uno to control an LED strip. When only the barrel is connected, the green light on the Uno comes on but the yellow light lights dimly for a few milliseconds then goes dark. The light strip doesn’t light at all. When a USB is also connected, the board lights up fully (green and yellow LED) and the LED strip runs through its routine.
I’m making this as Christmas lights on a tree outside so I want it to run on the stand alone power supply. Why doesn’t the barrel work on 5v?

because it is not a 5 V barrel jack. the specs says it is for 7 to 12 V

Voltage Drop
Well, if you put 5V into your barrel jack, your UNO's onboard 5V regulator is going to drop that down to 3.5V or so.  You must have more than 5V into the regulator to get 5V out of it.  This is referred to as the regulator's "drop out" voltage.
The specs for an UNO say to power it from at least 7V for that reason.
As an experiment you can power it this way without your lights attached and measure the "5V" header to GND to see this happening.
Power Dissipation
Linear regulators like that found on the UNO are not efficient. They waste energy as heat in proportion to the current through it and voltage dropped by it.
If you provide it with 7V at the regulator and your project draws 0.5 amps from the regulator, you will try to generate 0.5A * (7V - 5V), that is 1 Watt of heat.  Your regulator can probably dissipate half that with how it's mounted on the UNO and normal ambient air temperature.
Note this situation gets worse if you put 12V (for example) into the barrel jack, as you'd be dropping 7V across the regulator.
Many linear regulators have thermal overload protection built into them.  They'll stop producing as much voltage at the output as they heat up to try to survive the event.  And that's likely what you're seeing if you're trying to power your christmas lights from the regulator.
If you want to see this yourself might try very briefly tapping the regulator with your finger; it may be blazing hot.  You might just dampen your finger and hold it near the regulator's surface to feel the heat coming off of it.
You will more than likely need to route power around the Arduino board to your lights to prevent this.

Thanks! That makes sense.

@JohnnyRollerfeet If you have 5V already, you can wire it to the 5V rail (to skip the regulator). But be avare of possible backpowering of USB hub

@JohnnyRollerfeet, you may also want to consider getting a USB breakout or take the B end off a USB cable and use that to power the board.  That will allow you to keep the using the polyfuse that the UNO has connected to its USB jack.  And it will effectively plug the USB jack while you're powering it with 5V more-or-less directly.


text:
How can i draw an electronic diagram of this?

I need help to draw a diagram of this picture
the project include an Arduino nano, dht11 sensor, power module IRF520, 12V power supply and a fan

You already have done, haven't you?

Or do you mean a schematic? That can be done by various tools, for example Eagle ir KiCAD (though that is only a small part of their functionality)

I mean schematic

Do you want to create a schematic that contains the contents of the other modules? Then you need to get the schematics of those modules and copy them, then join them up with lines, just as you have here.

If you don't need the contents of the modules, then the schematic pretty much boils down to a block diagram.  You can do this with Windows Paint, or whatever drawing program you are familiar with... no need for any specialized schematic software with a big learning curve.  Just draw trial sketches with pencil and paper, then when you have the layout you like, create the same in Paint.  Tip: Create a separate Paint image with any symbols you want to use, like upward-pointing power arrow, ground symbol, wire cross. Keep that open and copy/paste into your final drawing.

It is often the case in professionally done schematics to "block" sub assemblies.  For instance your phone likely contains a GPS receiver and in some cases this is OEM'ed from a different manufacture who doesn't provide a schematic of the insides. Also, schematic capture programs are used to generate PCBs, 3D Board Models and BOMs.  MSPaint can't do that.

See Rules and guidelines for drawing good schematics on electronics.stackexchange.com.
I'm no expert but perhaps some of what I have found will be of help.
To produce a clear easy-to-read useful schematic it doesn't really matter what tools you use. This website has a reasonable schematic editor so I suggest you could try that to start with.
Other tools I have tried include KiCAD, EasyEDA and Fritzing. KiCAD is maybe a bit hard to start with and Fritzing I find is very troublesome - It's good for the kind of breadboard layout diagram it was originally designed for. I have really enjoyed using EasyEDA. Other notable tools include Eagle. All these are free or have free versions for hobbyists. Beyond that are more capable and sophisticated professional tools.
Drawing a good schematic is an art and taking care of small details makes a big difference to how useful the diagram is.
The main features that I find make schematics for me to read are

Ground connections at bottom edge of diagram.
Positive voltage connections at top edge of diagram.
Left to right flow for signals and power (e.g. battery at left, microprocessor in middle, LEDs, motors etc at right)
Avoid having wires cross. Adjust the pin positions on an IC symbol to make this possible.
Label everything clearly but don't let text overlap with anything else.

simulate this circuit – Schematic created using CircuitLab
The way you appear to be powering these modules seems a bit eccentric but this would be how I might draw that as a block-level schematic.


text:
MAX31865 and PT100 readings problem
PT100 (3 wire) is connected to arduino uno as i believe i have them connected properly, i have checked other forums such as changing the capacitor to ferrite core, and probably changing up to 4 breakout boards to get the same result (getting crazy). I also tried switching 3,3v to 5v repeatedly and hence i would get various errors such as the following:
I am using the example from the adafruit example available from adafruit library with the instances:
Adafruit_MAX31865 thermo = Adafruit_MAX31865(10, 11, 12, 13);

// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000
#define RREF      4300.0
// The 'nominal' 0-degrees-C resistance of the sensor
// 100.0 for PT100, 1000.0 for PT1000
#define RNOMINAL  1000.0

void setup() {
  Serial.begin(115200);
  Serial.println("Adafruit MAX31865 PT100 Sensor Test!");
  thermo.begin(MAX31865_3WIRE);  // set to 2WIRE or 4WIRE as necessary
}

and the error i always got:
RTD value: 0
Ratio = 0.00000000
Resistance = 0.00000000
Temperature = -242.02

Might not very an engineering way to troubleshoot things but i ordered the original adafruit MAX31865 breakout board instead.  Here is my setup

It looks like everything is hooked up correctly (assuming the trace cut and blobs on the sensor breakout are solid), but it'd be easier to understand the wiring with a schematic. You say you're using the PT100 but you're using the resistance value for the PT1000, which might matter. Hard to say if the sensor is wired to the board correctly. AFAIK you'd need to use only 5V power so the data aligns w/ the Uno's expected input ranges.

Thank you, would it be better to put some info that i knew about connecting the pt100 with the board? and yes apparently i forgot to change the RNOMINAL  1000.0 to RNOMINAL  100.0 but i would still get the same results: error.  As far as i know i have tested the pins of the pt100 with a multimeter to measure its resistance, between the blue-colored ones they are 2 ohm resistance. and between the red and the blues, they have around 109 ohm resistance, and this should be the part of the difference of the temperature measurement.

I would remove private: from the class and use the now available readRegister functions to see if the the chip is communicating correctly at all.  E.g. read the configuration register mentioned in the datasheet with readRgeister8 after the begin() call and see if the contents of it make sense.  Use of the writeRegister function to change one, and then read it back and see if it comes back.

I have a very similar issue - I actually ordered 12 of these boards and am only getting correct readings from 2 of them - the other ones (configured identically) just read "Temperature = -242.02, Fault 0x40, RTD Low Threshold." I've spent considerable time messing around with them to the point where I think it must be the breakout boards are just randomly faulty. I too will buy the adafruit version (10X the price is worth it if they work). Did you have any luck with the original?

Dear Philip C, yes apparently the original ones are worth the price, and it works instantly without even changing ferrite beads or others.


text:
Maximum distance for sensor
I'm creating a project with some ESP32's running off PoE and I need to add some temperature/humidity sensors up to 5m away from the ESP chip
I assume there is a maximum cable distance?
What is the best way to overcome this distance, preferably without having to inject power or use WiFi?

What sensor do you have exactly?

I haven't picked one for this project yet, thought I should work out the limitations first

The limitations are defined by how the device communicates. How the device communicates is defined by what the device is. You need to look for a device that fits your criteria. FYI: digital is often more reliable over long distances than analogue, and different digital protocols have better long distance reliability than others.

Thinking about these
https://www.aliexpress.com/item/4000125526434.html?spm=a2g0o.productlist.0.0.18cf23fcVrprv3&algo_pvid=c1feb228-eb55-4733-8f4d-98797185eb30&algo_exp_id=c1feb228-eb55-4733-8f4d-98797185eb30-2

That could do the trick, although I don't know what exact type that is. Something with an I2C interface (like BMEXXX/BMPXXX) should work reasonably with 5m of cable. I would rather not try DHT11's.

Also, please frame your project.  For instance, if you are making 100s I2C temper sensors products, some will certainly not work over meters distance as I2C was designed to be used between chip on the same PCB.  Maybe in the same case.  For that matter, if you are willing to spend the money and convert I2C or enhance it with additional HW you can get many meters out of the physical layer.

FWIW SparkFun has an I2C extension system based on NXP's PCA9615.

I have successfully tested different I2C devices with 10m of cable. So it can work, but probably is not guaranteed to.

I would use an lm334 as a temp-dependent constant current source, then measure the voltage it produces on a fixed resistor with the ADC; cable length is then completely irrelevant to the equation (could be a mile) as series circuits have identical current at all node points. You could also use a PTC or NTC thermistor as a divider to feed a BJT's base as a very simple dynamic current source.


text:
FastLED and Adafruit Gemma M0 - Getting started
I just bought a Gemma M0 and I'm trying to use it with FastLED. There are several forums that discuss the same errors I get when I try to upload my code, but they all involve editing .h files, something I'm not comfortable doing without understanding the reason behind the change. Is there a place where I can get a basic starting point for using FastLED with the Gemma M0?
I tried the Quick Example in the FastLED Overview:
#include "FastLED.h" CRGB leds[1];

void setup() {
  FastLED.addLeds<NEOPIXEL, 6>(leds, 1); }

void loop() {
  leds[0] = CRGB::White; FastLED.show(); delay(30);
  leds[0] = CRGB::Black; FastLED.show(); delay(30); }

and I get these errors:
Arduino: 1.8.13 (Mac OS X), Board: "Adafruit Gemma M0, Small (-Os) (standard), Arduino, Off"

In file included from /Users/jaireaux/Documents/Arduino/blink/blink.ino:1:
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/FastLED.h:14:21: note: #pragma message: FastLED version 3.004.000
   14 | #    pragma message "FastLED version 3.004.000"
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/jaireaux/Documents/Arduino/libraries/FastLED/src/FastLED.h:65,
                 from /Users/jaireaux/Documents/Arduino/blink/blink.ino:1:
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/fastspi.h:135:23: note: #pragma message: No hardware SPI pins defined.  All SPI access will default to bitbanged output
  135 | #      pragma message "No hardware SPI pins defined.  All SPI access will default to bitbanged output"
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/jaireaux/Documents/Arduino/libraries/FastLED/src/FastLED.h:48,
                 from /Users/jaireaux/Documents/Arduino/blink/blink.ino:1:
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/fastpin.h: In instantiation of 'class FastPin<6>':
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/fastpin.h:242:29:   required from 'class FastPinBB<6>'
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/platforms/arm/d21/clockless_arm_d21.h:10:54:   required from 'class ClocklessController<6, 12, 30, 18, GRB, 0, false, 50>'
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/chipsets.h:578:7:   required from 'class WS2812Controller800Khz<6, GRB>'
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/FastLED.h:92:34:   required from 'class NEOPIXEL<6>'
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/FastLED.h:314:28:   required from 'static CLEDController& CFastLED::addLeds(CRGB*, int, int) [with CHIPSET = NEOPIXEL; unsigned char DATA_PIN = 6]'
/Users/jaireaux/Documents/Arduino/blink/blink.ino:4:60:   required from here
/Users/jaireaux/Documents/Arduino/libraries/FastLED/src/fastpin.h:210:24: error: static assertion failed: Invalid pin specified
  210 |  static_assert(validpin(), "Invalid pin specified");
      |                ~~~~~~~~^~
exit status 1
Error compiling for board Adafruit Gemma M0.

Thanks in advance for your help.

starting point... example code in the arduino IDE

The Arduino IDE Examples don’t cover the difference between types of hardware.

The Gemma does not have a pin 6. FastLED.addLeds<NEOPIXEL, 6>(leds, 1); I changed to pin 2 and it works. FastLED.addLeds<NEOPIXEL, 2>(leds, 1);


text:
Using Serial Plotter with Visual Studio Code
I'm using the Visual Studio Code extension to develop for Arduino which works great.
It doesn't have a Serial Plotter like the regular Arduino IDE, which I need to debug this project. I can run the Arduino IDE's Serial Plotter alongside Visual Studio Code without too much of a problem.
However, if I try to compile and upload from Visual Studio Code while the Arduino IDE is running, the port is busy (not a surprise):
avrdude: ser_open(): can't open device "/dev/cu.usbmodem14201": Resource busy
An error occurred while uploading the sketch

So I have to keep exiting and relaunching the Arduino IDE every time I build.
Anyone have a suggestion for how to work around this? Using an iMac as development environment.

isn't it enough to close Serial Monitor window?

this does work, but is still kind of annoying... Thanks!

Without very specialized software that can create two new devices with the correct "teeing" policy, it's not going to be possible.  Only one program can open a serial port at a time (certainly and have it get anything intelligible out of it...)
I would suggest you may want to add a second serial port.  Use an FT232 adaptor to communicate on another serial connection (or a SoftwareSerial connection at a pinch) for your debugging information.  You really want a board with more than one serial port for this - or a board with a native USB for programming and a hardware serial port for data communication.
Another alternative is to ditch the serial for programming altogether and program your board through a dedicated programmer, thus leaving your serial port free for data communication.

Try teleplot extension in vscode

Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Please edit so you can expand on your answer. As it currently stands, you answer does not meet the quality standards for this site. EG. Add a link, provide a summary of teleplot, answer how this extension solves the problem the OP was having.


text:
What pins can be used for chip select (CS, CC) on the Arduino nano every?
I’ve checked the nano’s tech specs but I can’t seem to find any information regarding it. I’ve tried setting it to pin 26 (digital output)

the Nano Every doesn't have pin 26

The following answer assumes the Arduino is the master.
You can use any pin for that (at least any GPIO pin).
Multiple SPI devices can be connected to a SPI peripheral on an Arduino (in principle).
Every SPI device should have their own CS/CC pin, and is mandatory when you use multiple SPI devices.
For this reason, there is no single pin the SPI can define for being used as CS/CC pin. However, it should give a GND or VCC value, thus a CS/CC pin should typically be configured as a digital input pin (as master) for each slave.
(See remark of KIIV too); as slave the CS/CC pin should be a digital output pin.
For the other pins (MOSI, MISO, CLK), the Arduino uses a fixed set of pins because all SPI devices will be connected to these pins.
So the CS pin is configurable, and the other spi pins are fixed.

I am not familiar with the chip on that board, but if it's like the other AVR based boards the "primary" CS pin must be set to output (pin 10 on Uno - no idea what it will be on that board off hand). Otherwise SPI won't work.

However don't forget about SS (select slave) pin on AVR based Arduinos. It must be set as output (or at least used as output). Otherwise low level on this pin causes switching SPI to slave mode. Even left unconnected (as an input) it can be source of weird deadlocks in noisy environment.

@Majenko I thought that pin 10 was only primary because of shields using that pin to make the layout easier. Afaik it always can be set to any (GPIO) pin.

@KIIV I mention this: thus a CS/CC pin should typically be configured as a digital output pin.... a nontypical situation could be to connect it to GND or VCC (forgot which exactly) in case of a single SPI device.

The SPI peripheral in the chip has two modes of operation: one is Master and the other Slave. Which mode is selected depends on the DDR setting of the primary CS pin. It's a stupid way of doing it, but that's what Atmel's designers chose to do...

@MichelKeijzers I though it's general name for signal. Anyways /SS is active low, so as an input it should be held to the Vcc. The SPI supports multi-master mode and this pin is used to archieve it (only possibility to disable it is use it as an output)

@Majenko Thanks for mentioning this (so far I always used the Arduino as master, I added it in my question).

@KIIV you are right, I should adapt it in my answer.

@Majenko this is not ATmega328 or 2560. it is 4809. it has a flag in control register for master/slave mode and the flag is set by the SPI library. the SS pin can be used as input with SPI master mode. The peripherals of the 4809 are more like the SAMD peripherals then classic ATmega MCU peripherals

Wow, there is a board called Arduino Nano Every. (I though it's just meant like "on every pin?"). Anyways ability of /SS input pin to change mode from master to slave stays, but at least it can be disabled by setting SSD bit in SPIn.CTRLB register. That depends on pretty much on SPI library.

@KIIV, https://github.com/arduino/ArduinoCore-megaavr/blob/d2d1a2a7bc4654b907427cfb8d1003134fa6b340/libraries/SPI/src/SPI.cpp#L52

"However, it should give a GND or VCC value, thus a CS/CC pin should typically be configured as a digital input pin (as master) for each slave. (See remark of KIIV too); as slave the CS/CC pin should be a digital output pin." I don't understand this. CS pins are outputs.


text:
Blew my arduino pro mini s4 named component
While working on my project I supplied 12v to my pro mini through raw input and then a s4 named component smoked and my pro mini  stopped working . It didn't turn on either through vcc or raw. The voltage regulator seems completely fine. Can I repair my pro mini. Please help.

S4 is most likely a Schottky diode. You could try replacing it (in the correct orientation) and hope nothing else is damaged. Don’t run it at 12V in the future I guess. The fact that it doesn’t start up with just Vcc is not a good sign but you might have to remove S4 from the board first. Do you have a data sheet or schematic  of your particular Pro Mini clone? Is it a 3.3V or 5V version?

Sorry but i can only tell you that it's a 5 v version.

How do you konw if the voltage regulator is completely fine? Is that purely based on visual inspection or have you tested it? Since the failure, is it regulating the voltage to 5V (measured with a multi-meter)?

Many Arduinos have a Schottky diode between the power connector and the voltage regulator as a protection against accidental reverse polarity connection. The official Pro Mini, or the Sparkfun variant, does not.
So you can either de-solder the diode or break it off the board using diagonal cutters and then replace it with either a similar diode -- or with a solder-bridge if you are confident about never connecting power the wrong way around.
It's possible (likely even) that other components that look OK visually are actually damaged. Especially if you can't power the board by connecting a regulated 5V supply to the VCC pin.

Once you have removed the diode as described in @RedGrittyBrick's answer, you will need to replace it with another. Note you don't have to replace it with a SMD version if you can't get your hands on one. Most electronics shops sell a 1N4004 or 1N4007 diode which would be a suitable replacement.
If worst comes to worst, you could solder a blob of solder across the diode's pads - which would mean you lose the reverse polarit protection - but it would provide a path for your voltage input to go into the regulator.

The defective component is a Schottky diode. 4001 or 4007 are not Schottky diodes and have much higher Vf. A better replacement would be 1N5817 or an SMD equivalent.

It doesn't matter in this instance as it is just for reverse polarity. A normal diode is fine, a Schottky diode would be better if you can get one.


text:
Using MCP23017 with 5 rotary encoders, WITHOUT missing a single step from any of them?
I have recently followed the instructions in the answer to this question:
Reading several rotary encoders
posted by maximilian-gerhardt
I've wired everything up, and am using the interrupts example that can be found here:
https://github.com/maxgerhardt/rotary-encoder-over-mcp23017/tree/master/examples/Interrupt
Everything seems to work as expected, except that my assumption was that since this was an interrupt-based solution, that I wouldn't be missing any steps of any of the encoders. There are a total of 5 that will move at the same time, and it is clear that while it almost works, there are many steps that are missed.
I'm guessing that is because while one interrupt is being handled, all other interrupts are disabled?
Is there any way where I can ensure that every single motion (step CW or CCW) is registered on all 5 encoders?
Thanks!
Brian

Interrupts are no garant for missing no steps. The steps need to happen only as fast, as the interrupts need to execute. The reading of the MCP over I2C alone would take 100us min (assuming 1 byte of data. With 2 bytes you would have 150us min). And then the executing time of the logic how fast are your steps coming in?

I would use a different approach. Consider setting a flag when an interrupt occurs, a different flag for each interrupt then processing that in the main loop rather then the ISR (Interrupt Service Routine). Connecting with the SPI  in the 1.7 MHz mode will allow you to get in check the interrupt set the flag and leave the ISR. This will be a bit difficult to write but I think it would work very well. Taking a quick scan of the data sheet the MCP23917 should be the correct part to accomplish this. Also do the debouncing externally, will save a lot of code and speed up the process.

Interrupts don't mean that you can do lots of things at the same time. All they mean is that something can be responded to rapidly, as long as nothing else is being responded to of an equal or higher priority.
And coupling that with an IO expander which will inevitably slow things down means that you really can't do what you are trying to do.
If you want to respond instantly to every single pulse of every single encoder then each encoder has to be attached to something that can itself respond to those pulses.
I would be inclined to have a small microcontroller attached to each individual encoder (or maybe two encoders if you have enough interrupt pins) and deal with each separately - that way one encoder cannot interfere with any other. The small MCU can then keep track of position or count (depending on what it is you are trying to do) and you communicate that to a "master" controller (the Arduino for example) over some other bus, asynchronously to the encoder's pulses.
If you want more rapid response to the encoder movements then it could be possible to implement your own interrupt signal from the small MCU to the Arduino to say "My encoder has been moved", at which point the Arduino can collect the data. It won't matter how long that takes to happen as the small MCU will be keeping track of any other changes. The ATTiny85 using Pin Change Interrupts could be a good low-cost choice for this.


text:
Speaker-dependent Voice Recognition
I would like to install speaker-dependent voice recognition in a robot equipped with Arduino Uno compatible boards.
Specifically, I want to record the robot's name beforehand and have it respond when I call the robot's name.
Although it is not an Arduino, there is a person who has developed a function that I would like to realize with the M5StickV.
This person used isolated_word.py, a library published by Sipeed, as a reference.
【K210】マイク搭載版M5StickV,Sipeed Maixシリーズで音声認識をする
After some research, I found Maix_Speech_Recognition in the library of Maixduino, which can use Arduino IDE.
Apparently, it uses Mel-frequency cepstrum coefficients analysis of speech input, and then uses dynamic time stretching to find the similarity.
The MFCC uses the K210 FFT on the Maixduino.
Arduino Uno does not have an FFT accelerator, but it can do FFT.
Therefore, I thought it would be possible to use Maix_Speech_Recognition for specific speaker speech recognition on ArduinoUno compatible devices.
Question

Is it possible to use Maix_Speech_Recognition for speaker-dependent voice recognition on Arduino Uno compatible boards?
What part of Maix_Speech_Recognition should I modify to make it work on Arduino Uno compatible boards?

Why don't you try it out? I doubt the UNO has enough processing power for voice recognition, but I might be wrong.

The UNO has way too little RAM to do an FFT big enough to be useful for this... only 2K.  And since it doesn't have a math coprocessor in hardware to compute all the trig factors on the fly, it would have to store those in the same limited RAM space or else your FFT would slow to a crawl.  I think you should consider another approach.

Is it possible to use Maix_Speech_Recognition for speaker-dependent voice recognition on Arduino Uno compatible boards?

No. It's not.

What part of Maix_Speech_Recognition should I modify to make it work on Arduino Uno compatible boards?

Don't even think about it. The UNO cannot do anything even remotely like speech recognition of any form without adding extra specific speech recognition hardware.
Just get a K210 board - they're cheap enough.


text:
Arduino wont start up and it wasnt succesfully booted in any time it was downloaded
I know the title sounds stupid but I never found a question like mine so I wanted to be specific because I downloaded the Arduino IDE to start my first project and I never managed to boot it because nothing happens when I try and I also tried every kind of thing to make it work I could think of. I reinstalled it, downloaded from another link like the zip version and also tried the windows repairtool. I also tried to boot it as admin several times but nothing changed anything. I did all of that yesterday and today when I started the Pc and retried I atleast saw something of a bootingscreen of the app so I thought I just had to restart but then it just went off again and the pain from yesterday began once again.
´´
I own windows 7 64 bit
´´
and tried every download except the one for windows 8.1 and 10
I saw a question about Arduino IDE not starting but this person atleast got any response from the program and the tipp they suggested with the folder in
´´
AppData/Lokal where you delete broken data to reinstall doesnt work too because the arduino folder doesnt even excist in the whole appdata section.
´´
´´
Windows repair tool said the program is not compatible, only in Windows xp (service pack 2) version but in compatibility mode nothing changes
´´
Ok thew this question is really long but I gave my best to explain everything I could about my problem so I really hope somebody could help me on my problem so I didnt waste my 45 Euro and time on tech stuff that I cant use
one thing to meantion I have left is that i bought my stuff from a teacher (Erik Verbene) on the internet
but that doesnt matter because it is your program that is not working so
yeah
hope somebody can help me out on this dilemma

run arduino_debug.exe in installation folder

there only starts up a black box that instantly closes again....

start it from command line

The Arduino IDE is written in Java. It's 100% platform independent, so the version that you download makes no real difference.
The most likely culprit is the version of Java that is installed in your computer.  I am not sure off hand what versions of Java the Arduino IDE works with, but for certain version 8 will be your best bet.  Make sure that you have the latest version of Java 8 installed.  If you have any older version installed you should uninstall it and replace it with Java 8.  I'm not sure how the IDE works with newer versions than 8, but removing anything newer than 8 and installing Java 8 may be a good idea.

Arduino IDE has Java bundled in installation

I already own the newest version of java and I also checked if java itself is running and it does so that isnt the problem it seems


text:
ESP32 access point code not compiling
I'm trying to use the ESP32 board to control an LED, buzzer, and motor (ABA) through an access point.
I got some code from this page:
https://lastminuteengineers.com/creating-esp32-web-server-arduino-ide/
Which is amazing! I changed some names here and there and evrything okay (to control ONLY 2 things).
Now that I wanted to add the 3rd device, the code is not compiling.
I get this error:
exit status 1

too few arguments to function 'String SendHTML(uint8_t, uint8_t, uint8_t)'

With the line in bold marked.
server.send(200, "text/html", SendHTML(ABA1status,false));
#include <ETH.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <WiFiUdp.h>

#include <HTTP_Method.h>
#include <WebServer.h>

/* Put your SSID & Password */
const char* ssid = "ESP32DeltaSolutions";  // Enter SSID here
const char* password = "deltasolutions123";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,1,2);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);

uint8_t LED1pin = 25;
bool LED1status = LOW;

uint8_t BUZZ1pin = 32;
bool BUZZ1status = LOW;

uint8_t ABA1pin = 35;
bool ABA1status = LOW;

void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(BUZZ1pin, OUTPUT);
  pinMode(ABA1pin, OUTPUT);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);

  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/buzz1on", handle_buzz1on);
  server.on("/buzz1off", handle_buzz1off);
  server.on("/aba1on", handle_aba1on);
  server.on("/aba1off", handle_aba1off);
  server.onNotFound(handle_NotFound);

  server.begin();
  Serial.println("HTTP server started");
}
void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, HIGH);}
  else
  {digitalWrite(LED1pin, LOW);}

  if(BUZZ1status)
  {digitalWrite(BUZZ1pin, HIGH);}
  else
  {digitalWrite(BUZZ1pin, LOW);}

  if(ABA1status)
  {digitalWrite(ABA1pin, HIGH);}
  else
  {digitalWrite(ABA1pin, LOW);}

}

void handle_OnConnect() {
  LED1status = LOW;
  BUZZ1status = LOW;
  ABA1status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,BUZZ1status,ABA1status));
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED1status));
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED1status));
}

void handle_buzz1on() {
  BUZZ1status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(BUZZ1status,true));
}

void handle_buzz1off() {
  BUZZ1status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(BUZZ1status,false));
}

void handle_aba1on() {
  ABA1status = HIGH;
  Serial.println("GPI35 Status: ON");
  server.send(200, "text/html", SendHTML(ABA1status,true));
}

void handle_aba1off() {
  BUZZ1status = LOW;
  Serial.println("GPI35 Status: OFF");
  **server.send(200, "text/html", SendHTML(ABA1status,false));**
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t LED1status,uint8_t BUZZ1status,uint8_t ABA1status){
  String ptr = "<!DOCTYPE html> \n";
  ptr +="<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="\n";
  ptr +="\n";
  ptr +="\n";
  ptr +="
ESP32 Web Server
\n";
  ptr +="
Using Access Point(AP) Mode
\n";
  ptr +="
Delta solutions
\n";

   if(led1stat)
  {ptr +="
LED1 Status: ON
OFF\n";}
  else
  {ptr +="
LED1 Status: OFF
ON\n";}

  if(buzz1stat)
  {ptr +="
BUZZ1 Status: ON
OFF\n";}
  else
  {ptr +="
BUZZ1 Status: OFF
ON\n";}

  if(aba1stat)
  {ptr +="
ABA1 Status: ON
OFF\n";}
  else
  {ptr +="
ABA1 Status: OFF
ON\n";}

  ptr +="\n";
  ptr +="\n";
  return ptr;

Any suggestions?
Thanks!

SendHTML has 3 parameters, but you only provide 2. Its clear  that the compiler gives you that error

The syntax of six SendHTML you use with true and false is actually wrong.
By defining a function like this String SendHTML(uint8_t LED1status,uint8_t BUZZ1status,uint8_t ABA1status), you mean that first, second and third input to this function are Status of LED1, Status of BUZZ1 and Status of ABA1.
So try replacing all six SendHTML with true and false functions to this SendHTML(LED1status,BUZZ1status,ABA1status)


text:
ISD 1820 using Arduino UNO
I have to play audio files using an isd1820 sound module. I am using arduino uno microcontroller but I am able to play only one file. Is there a way I can play different audio files according to need?

how are you playing one file?

Please provide a link to the exact sound module, that you have.


text:
Made a light controller for the holidays
I am a new the world of Arduino. I found on YouTube, how to build a light controller (https://www.youtube.com/watch?v=WvG9c84ApFA&t=39s). I follow every step but it doesn't work. Here are some pictures and a rough schematic. (I don't have a Arduino, it is a Egeloo mega 2560)enter link description here

Could you be more specific as to what doesn't work? Where do the orange and black dashed lines go to? What relay boards are you using? What power supply are you using for the relay boards? What code did you use? You might want to try testing with only a single board.

"It doesn't work" is a poor problem description, like asking "my car doesn't work. Whats wrong?". Please describe, what you did, what you expected and what happend instead. Also remove the images of your big wiring (we cannot see anything on that). Include a link to the used relay boards and your code.


text:
Write faster on AT24C32
I'm using AT24C32 EEPROM chip from ATmel. I found code that will write and read bytes from chip.
Code writes and reads bytes correctly and without any problem.
But I have to write few 8-byte values often(every 10-15 seconds). I did "cut" those variables to 48 bit(so 6-byte variable) and with that I speeded up saving but it's still slow.
Is there any chance to speed up saving proccess? Code is below
void EEPROMClass::write48(int16_t address, uint64_t value)
{
    uint8_t byteValue = (value & 0xFF);
    write8(address, byteValue);

    byteValue = ((value >> 8) & 0xFF);
    write8(address + 1, byteValue);

    byteValue = ((value >> 16) & 0xFF);
    write8(address + 2, byteValue);

    byteValue = ((value >> 24) & 0xFF);
    write8(address + 3, byteValue);

    byteValue = ((value >> 32) & 0xFF);
    write8(address + 4, byteValue);

    byteValue = ((value >> 40) & 0xFF);
    write8(address + 5, byteValue);
}

void EEPROMClass::write8(int16_t const address, uint8_t const value)
{
    Wire.beginTransmission(AT24C32);

    Wire.write(highAddressByte(address));
    Wire.write(lowAddressByte(address));

    Wire.write(value);
    delay(2);
    Wire.endTransmission();
}

delay of 2ms is required otherwise EEPROM will write different value. Code has 4 "6-byte" variables(total of 24 bytes). Every byte is minimum 2ms, so total time to save only "6-byte" variables is 48ms(round to 50ms). That is too slow for me. How to speed up write function?

What type of speed do your application require? Please see benchmarks; https://github.com/mikaelpatel/Arduino-Storage

after writing a value to EEPROM, and terminating the I2C connection with a STOP, the EEPROM enters a self writing mode to write what you have sent to it, to it's internal memory. (you don't actually write the values to the memory section; you write them to a buffer, and then the internal controller writes them to its memory section).
this "self writing mode" takes about 5ms, and you cant do nothing about it. but you can use "page writing" instead of byte writing. that 32K model, has a 32 bytes page buffer. you have to send all the bytes (as long as they are under 32 bytes) at once in one I2C transaction. this time, the chip fills its page buffer and then after a STOP, writes it all at once on its memory. in your code, you just write one byte in your buffer each time in a single transaction. like sending a bus with just one passenger at a time.
remember in this mode, you only set the address of the first byte. the next bytes automatically settle in the next addresses.

Does exists "readpage" way to read faster?

And does read action requires delay?

the reading doesn't have the limitation of "page". you can read all the chip in one transaction (it can even rollover the memory bank and resend it). and it doesn't need a delay neither (it's as brief as microseconds so it's negligible). @SilvioCro

Can I write 18 bytes of data starting from eg. address 24? It will pass 32 byte. Will it corrupt data?  And, how much bytes I can use? Is all 32 bytes for data or 30 bytes for data and 2 bytes for address?

the 32 bytes is all data. the address is set the way you set it before, but only for the first item. and remember, in the page write mode, you write to a whole page. as your chip has 32bytes pages ( 128 * 32 bytes = 4096 bytes = 32Kbits), you can write a whole 32 bytes at one of the pages (1~128). to write properly, first 32 bytes settle to address 0 to 31, the next batch at 32 to 63 … .

and in the case you write to 18 bytes to address 24 (you don't have to send exactly 32 bytes. as I said, a maximum of 32 bytes), your data will rollover.
byte0 -> 24
/byte1 -> 25
/byte2 -> 26
/byte3 -> 27
/byte4 -> 28
/byte5 -> 29
/byte6 -> 30
/byte7 -> 31
/byte8 -> 0 (still in the first page. it does not go to next page)
/byte9 -> 1 (still in the first page. it does not go to next page)

Thanks a lot for help

Mostly the best speed you get, is if you use the 'page' size, which is 32 bytes. It will take longer than 4 bytes, but less then 4 times 8 bytes.
You could do a check to see if using one page write (of 32 bytes) is faster than 6 times a one byte write.
However, it depends if you can change your design so it writes 32 bytes at a time.
E.g. by writing 60 seconds 4 times 8 bytes (32 bytes) in one page write, instead of every 15 seconds 8 bytes. This will be much faster.

I never let processor wait a process to finish. I call a procedure do whatever could be done put a mark where I got and return to do other stuff. Next scan I pick up from where I left and continue if the conditions allow, if not i leave it for the next scan. I would never put a waiting time in a loop. In your case I would open the communication, send as many bytes as I can, put a mark how far I got, close the communication and return. Next scans(when the data are transferred from the buffer to the EEPROM) I would repeat the same process for the rest of the data. At any scan I invest a few hundreds of microseconds.

This is so old I even don't use Arduino anymore. But thanks!


text:
digitalWrite on Trace SWO pin
I'm using STM32(generic board) and I want to control bi-color LED(common anode). STM32 pin layout and scheme is below, so please see it.
Now, in theory scheme Works, but in practice it Works halfway. Red LED is connected with PB8 pin and green LED is connected with PB3 pin.
Code is simple so I think that problem is not in the code. Red LED Works, but green doesn't work. If I connect green cathode with GND manually, then it Works, otherwise(with STM32) it doesn't.
Later I found that pin PB3 has Trace SWO mark(see pin layout below). I'm not completly sure what Trace SWO means, just found that it some kind of debugigng protocol(I guess) but I can't find info can it be used for digitalWrite purposes. Is there any way to habilitate PB3 pin for digitalWrite? All other pins are in use.
Code:
// DOWN
digitalWrite(PB3, HIGH);
digitalWrite(PB8, LOW);
delay(750);

// UP
digitalWrite(PB8, HIGH);
digitalWrite(PB3, LOW);
delay(750);

STM32 pin layout

R4 doesn't exist, it's mistake in scheme

did you solder the headers?

Don't understand you?

usually the Blue Pill is sold without pin headers soldered

@Juraj really? I didn't know that. Thanks for info! ♂

how can you don't know that? did you get it with pin headers soldered or without pin headers? https://cdn.instructables.com/F46/4FA4/JM8A987M/F464FA4JM8A987M.LARGE.jpg

Are you troll or? Of course I soldered pins. STM32 is on breadboard. How could I use STM32 without headers and breadboard?! Btw. I fixed the problem. Just deleted line in boards.txt file.

I didn't ask if you SOLDERED the headers.  I asked if YOU soldered the headers. :-) If I solder the headers then I test the pins and sometimes I must fix the soldering. I always first ask basic things, because many times they are the problem.

like here https://arduino.stackexchange.com/questions/57370/sd-card-failed-to-initialize/57387#57387


text:
Controlling LEDs with bit bang method
I'm doing a research for RGB LED chips that MCU can control with one pin. I found this LED chip and it seems controlling LEDs is not as I've tought. I understand hardware part, software side is a problem.
In chip's datasheet, on page 6, you can find chapter four Data Transfer Format.
My questions are: Why D2 has only second 24 bit, third 24 bit while D3 has only third 24 bit and why D4 has no bits? What should I do when I'm done with "updating LEDs"?
I thought controlling LEDs can be done like this:

Lets say I have five LEDs to control. Every LED has Red, Green and Blue and every color is 8-bit. Five times three is 15 bytes array.
First three bytes in array are for last LED chip. While sending the data, highest bit(bit 7) will go first.
After first three bytes, MCU will stop for X microseconds. After delay, new three bytes will push old three bytes to second LED chip.
After MCU is done with sending data, it will leave data pin low.

Thanks!

first 24 bits are for the first LED chip .... each LED chip does the same thing ... after reset, it takes ownership of the first 24 bits of data arriving at its input pin and passes the rest of the bits to its output pin

This protocol looks an awful lot like the protocol of the WS2812 chips. There are libraries for driving those. Search for “Neopixel”.

@EdgarBonet Yes, but I want to make own lib for that since Neopixel and FastLED are too heavy for my needs.

You need to send the 5x24 bits out without a pause. If you then keep the line low for over 80us, that is interpreted by all LED drivers as the reset signal. It is not stated explicitly in the datasheet (at least I haven't found it), but I guess the reset signal means, that at that time all drivers will output the received values on the LEDs. That way you can light up all LEDs at the same time with their respective data.
The picture, that you refer to, explains the automatic data cascading. The first row is what you actually send from your microcontroller and also what is seen by the first LED driver in the row. That driver will then consume the first 24 bits, that it sees. After that, it will forward the rest of the data to the next LED driver. That will now consume the first 24 bits that it sees (thus the second 24 bits, that you have send). The third LED driver will do the same. But since in that example you only send data for 3 LEDs, no data is forwarded. Then the reset pulse happens and at some point in time you send a new set of data.
So each row represents, what the corresponding LED driver will see of the data, that you send. D1 sees all the data. Each following LED driver will see 24 bits less. D4 will see nothing, since you send only 3x24 bits in that example.

Why they using pause after every 3x24bits?

Because the example only has 3 LEDs. You do a pause, when you have send all the data, because a pause of more than 80us will set cause the LEDs to actually activate the values, that you send it. You can send how much data you like, but at the end you need to do a pause to actually output the data on the LEDs


text:
Nano Every clone with ATMega4808 not recognized
I've bought an Arduino Nano Every clone/compatible (not a standard Nano V3) that uses an ATMega4808 instead of the ATMega4809 the official Nano Every uses. This rather insignificant change of chip is detected by the Arduino IDE (v. 1.8.13) which tells me that the chip is wrong when I select "Nano Every" from the boards list and try to upload a sketch. The seller (link to the product) does not answer to my help requests. Does anybody own one of these and knows how to make it run?
Below a photo of the board. Note the small difference in pinout (4 extra pin, D22, D23, D24 and UPDI)

Probled solved, it turns out to be a Thinary Nano Every.
Instructions for installing on the Arduino IDE are on Github here: https://github.com/Thinary/ThinaryArduino


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

It's my understanding that duplicate I2C addresses prevent the master from communicating from the slaved devices, so the answer is no.
Instead, connect the devices one at a time, run the I2C scanner, note the address for each, and take note of any duplicate addresses.

If both devices are the same, are configured the same, and respond the same, then it is impossible to tell if there is one, two, or four hundred.
However if there are differences between the two devices you will get corrupt data.
I2C is an open-drain protocol. For a device to send a 0 it pulls the data line low. For it to send a 1 it lets the pullup resistor pull the line high.
So if you have two devices and they both send a 1 you get a 1. If they both send a 0 you get a 0. But if one sends a 1 and the other sends a 0 then the 0 will "win" and you will see a 0.
Since most devices, when powered up, revert to some pre-defined default state, chances are you will always see multiple devices of the same type on a single address as just one device.
One possible way around it is to have some control signal that is unique to each device which will cause them to only respond one at a time. For example, you might choose to pull all the RESET pins of the slaves LOW and raise each one in turn to see what address the device is on. If you then see two that respond on the same address then you know you have a conflict and can report it as such.
Another possibility is to connect the address control pins to IO pins and communicate with all the slaves on the same address - but you only set one slave's address to the "live" address at a time. That also gives you the ability to have far more than just 8 slaves.


text:
Basic doubt regarding encoders with Arduino
I created a program that measures the pulses set out by the encoder (part of the dc motor with encoder inbuilt), and uses the ppr value (pulses per rotation) to calculate the rotations per minute (rpm)
However, the serial monitor continuously shows 0 for the variable "pulsecount", that maintains the total pulses sent.

code:
float ppr=512.0;
int encpin=3;
volatile long pulsecount=0;
float revs;
float rps;
float rpm;
unsigned long time;

void setup()
{
  pinMode(encpin,INPUT);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING); //when pulse is detected
                                           //interrupt triggered,
                                           //function callled
}
void function(){
  pulsecount+=1;
}

void loop()
{
 revs= pulsecount/ppr ;
 time=millis()/1000;
 rps=revs/time ;
 rpm=revs*60;
 Serial.println(pulsecount);
}

Why are you defining function() inbetween setup() and loop()? If it compiles it might be OK, but I have never seen that... Try to print every value to Serial Monitor and maybe you can see the variable which causes this behavior.

What happens if you use INPUT_PULLUP rather than INPUT?

You code counts pulses just fine when tested here.
Fan/motor tachometer outputs and encoders frequently are set to switch your signal contact to ground, either with a transistor or mechanically.  When the ground contact is not being made, the signal connection is floating and not reliably HIGH.  So, you need a pullup resistor on the pin, just like you do for a typical push button switch configured to switch to ground.
My comment on the question:

What happens if you use INPUT_PULLUP rather than INPUT?

was referring to doing this in your code:
pinMode(encpin, INPUT_PULLUP);

At higher frequencies, higher RPM, you may need to use an external resistor to get a lower resistance value than the 20k-50k of the internal pullup resistor that INPUT_PULLUP enables.
It is best to turn off interrupts when you retrieve your volatile pulse counter variable so that there's no tearing of the value where the ISR interrupts your code mid-read and updates the latter half of the value.
e.g.:
// Note I've switched your pulsecount variable
//  to unsigned long for this example.
unsigned long get_pulsecount() {
  noInterrupts();
  const auto r = pulsecount;
  interrupts();
  return r;
}

Note you can probably avoid float usage altogether, and should if you can.

It is hard to find the error in these TinkerCad examples, because I do not know where to find the datasheet of the components used there and I am never sure, what am I debugging, the program or Tinkercad?
Anyhow, the encoder simulated there needs to be connected with a pull-up resistor. Arduino has a built-in pullup and you can activate via the pinmode() function:
void setup()
{
  pinMode(encpin,INPUT_PULLUP); //  before here was pinMode(encpin,INPUT);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING); //when pulse is detected
                                           //interrupt triggered,
                                           //function callled
}

But notice: your types are all over the place and I expect that you get some bugs due to this. Avoid to divide float and int variables without converting, especially this can cause trouble, because you might divide by 0:
 time=millis()/1000;
 rps=revs/time ;

Also it is a long shot to have basic doubts regarding encoders and arduino, just because some code does not work. Many people are using encoders all the time and countless libraries of encoders have been published for arduino.


text:
Unexpected output for simple code involving calculating a time interval of 10ms
I had written some code that involved doing something after 10 milliseconds had elapsed, however it was performing unexpectedly. Upon debugging, I think I have identified the error, and I wrote some code with just that block:
unsigned long int newtime=0;
unsigned long int prevtime=0;
int time;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
newtime=millis();
time=newtime-prevtime;
if(time==10){
  Serial.println(prevtime);
  prevtime+=10;
}

}

The serial monitor "freezes on 150. it shows the values 0,10,20...as expected but it freezes on 150...and then nothing happens.
What exactly is causing this?

You should not relay on that if statement to be called once ever millisecond. Check for >= instead

i didnt properly understand your first comment...

In my original program, I was doing something when exactly 10 milliseconds had elapsed..

Your sketch requires that the if statement is called ever millisecond. If timeis 9 in one iteration and 11 in the next iteration, then the code in the if block will never be executed.

"when exactly 10 milliseconds" - you can't do it this way, you have to check if at leaest 10 ms have elapsed. If you need exact timing you have to use interrupts.

10 not 1. and also, since i am resetting the value of prevtime, the value of the variable time cannot exceed 10

I would say with a frequency of every 10ms you fill up the Serial buffer pretty fast. You could try using a higher baudrate (for example 115200)

just to add on, the code works perfectly fine when I replace 10 with 100.

If (for whatever reason) your loop takes slightly more than 1 millisecond, then there is a chance that the if statement misses the moment when time==10 and the if clause will never become true. At least not before millis() ran over.

@chrisl You are right...it works with that baud rate

The problem is, that you are filling up the Serial buffer rather fast, because you try to send ASCII numbers every 10ms at only 9600ms. When the buffer is full, Serial.println() will wait, until there is enough space free in the buffer for the current data. That makes your loop lasting significantly longer.
In that case the time, where the time is exactly 10 is missed. Thus the code does nothing at that point, until time rolls over and gets 10 again (48 days I think).
While you can mitigate the problem by using a higher baudrate, the main problem is still
if(time==10){

You have only provided an example code. Your real code might sometimes take longer than 10ms out of some other reason (actually this already gets critical, when the loop takes longer than 1ms, since it then might already miss the one moment, where time is 10). To futureproof your code and make sure, that you don't hunt down the same bug again and again, you should do, what you were told in the comments, and use
if(time>=10){

Depending on your code the event will still happen after 10ms the absolute most of the time. But this variant also doesn't break, if the loop takes longer than 10ms sometimes.

"might sometimes take longer than 10ms" - actually the if(time==10) version becomes critical as soon as loop() takes longer than 1 ms, because it has to compare time with ever tick of millis() ;)

@SimSon You are totally right. I will add that to the answer

your logic is just tricky to confuse. It is repeatable because along as you not change the if logic, the code is going to run till it displays 150. then it will stop. You can also check the same behaviour here
Once the time difference is not exactly equal to 10, the if part will not be executed. Hence, the prevtime will not catch up with the newtime anymore. newTime will soon grow to be bigger and the difference will always be greater than 10.
I suggest visiting https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay to get some hints on tracking time in a safer way.


text:
Simple LCD countdown timer
I tried to modify the basic "hello-world" sketch for the LCD that is a part of the examples section in the IDE. I intended to make a countdown timer using the LCD.
The original code simply prints "Hello World" in the first line, and then makes use of the millis() function to print the time elapsed in the next line.
So I tried a simple modification to make it count down from 20. Instead of printing millis()/1000 , I printed 20-millis()/1000, and also added a while() to only print till millis()<=20,000. (so that it does not go beyond 00)
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

  lcd.begin(16, 2);

  lcd.print("time left");
}

void loop() {

  while(millis()<=20000){

    lcd.setCursor(0, 1);

    lcd.print(20- millis() / 1000);
  }

}

It seemed to work till 10. but instead of 9, it printed 90, and likewise 80,70.. for 8,7...etc till 00.
How can I get rid of these extra zeros?

lcd.print(' ');

where do I put this?

instead of 9, it printed 90

No, it didn't: it printed “9”. However, it did not erase the previous
value before printing “9”. Before printing the 9, the LCD had:
┌────────────────┐
│time left       │
│10              │
└────────────────┘
 ^cursor position

When you printed “9”, that character replaced the “1”, and you end up
seeing “90”.
The fix, as pointed out by Juraj, is to add a space after printing the
numbers.
An alternative is to prepend a space (or a zero), but only when the
number to be displayed is less that 10:
int count = 20 - millis() / 1000;
if (count < 10)
    lcd.print(' ');  // alternatively: '0'
lcd.print(count);


text:
Serial communication of strings
I used this simple code to understand the basics of serial communication. This achieves simple communication between the computer and arduino:
String receive_buffer;
void setup() {
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0)  //check for any data received
  {
      receive_buffer = Serial.readString();  //read received data
      Serial.print("received data is: ");
      Serial.println(receive_buffer);        //display received data
  }

}

This works. Now, my next idea was to try communicating between two arduinos. I used this code for the reciever arduino.
The sender arduino contains a motor fitted with an encoder, and using the ppr value I  calculate the rpm of the motor. The code for rpm works perfectly. I now want to communicate this data to the receiver.
Wiring: (RX,TX) of sender connected to (TX,RX) of receiver, and GND is made common.
Now, on arduino.cc, it says that Serial.write() can have String as an input. So, I tried typecasting the rpm value (which was int), into a String, and then send that string to the receiver through Serial.write().
float ppr=512.0;
int encpin=3;
volatile long pulsecount=0;
float revs;
float rps;
int rpm;

extern volatile unsigned long timer0_millis;

void setup()
{
  pinMode(encpin,INPUT_PULLUP);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(encpin),function,RISING);
                                        //when pulse is detected
                                           //interrupt triggered,
                                           //function callled
}
//increments pulse by one
void function(){
  pulsecount+=1;
}

void loop()
{
 revs= pulsecount/ppr ;
 if(millis()>=1000)
  {
    rps= revs;
    rpm=rps*60;
    pulsecount=0; //resets pulsecount

    String strrpm= (String)rpm;

    //Serial.println(rpm);
    Serial.write(strrpm);

   // Serial.println("string rpm");
    //Serial.println(strrpm);

    noInterrupts ();  //resests millis() to 0
    timer0_millis = 0;
    interrupts ();
  }
}

However, I get an error:
43:24: error: no matching function for call to 'HardwareSerial::write(String&)'

The issue is not with typecasting. I tried to simply print strrpm and it worked fine. When tried Serial.write() with a different and simple string, i.e Serial.write("abcdef"); , it still gave the same error.
How then should I should I send my strrpm (string rpm) value to the receiver?

Serial.write() is meant for sending binary data. So if you want to send a string with it, you need to provide a c-string, not the Arduino implementation of the String class. That's done easily with a member function of that class:
Serial.write(strrpm.c_str());

That compiles successfully for me.
Though you should not do it like this. The String class is generally bad on small microcontrollers, especially on the AVR microcontrollers with little memory (like Uno, Nano, Mega, ...), because it causes memory fragmentation (see Majenkos "The Evils of Arduino Strings").
Instead you should just use the corresponding print() functions of the Serial class. They are made for sending human readable strings. No need to first build up a String object. Just do
Serial.println(rpm);

And it will do the string conversion itself without using the String class.

Besides that I have some notes on your code:

The way you use millis() is a bit weird. There is no need to actually reset the millis() value itself. Normally you would hold a timestamp in a variable and then only calculate the difference between millis() and the timestamp. That is also overflow safe. Like this
  unsigned long timestamp = 0;

  ...
  if(millis()-timestamp >= 1000){
      ...
      timestamp+=1000;
  }

That doesn't use an extern variable, it is not resetting the millis() counter (which might mess with other things too, that rely on it) and is somewhat the standard way to do it.

You are using an atomic section for resetting the millis() counter, but not for accessing pulsecount. That is actually the place, where you absolutely need this. pulsecount is of type long, so it will need many instructions to do the calculation for revs. The your interrupt service routine can easily mess with the data in that moment, resulting in garbled data. Move  the calculation into the if statement and use an atomic section like with the millis() counter to read it into a local variable then you can do the calculations. That will keep the time, where interrupts are turned off very short. You can also - instead of turning all interrupts off - just detach the pin interrupt for that time, so that other things are not affected. Like this code:
  void loop(){
      if(millis()-timestamp > 1000){
           // deactivate our pin interrupt, so it cannot mess with the data
           detachInterrupt(digitalPinToInterrupt(encpin));
           // copy pulsecount to local variable for further calculation
           long local_pulsecount = pulsecount;
           // reactivate our pin interrupt
           attachInterrupt(digitalPinToInterrupt(encpin),function,RISING);
           // Do calculation and print the value
           ...
           timestamp += 1000;
       }
   }

" Instead you should just use the corresponding print() functions of the Serial class. They are made for sending human readable strings. No need to first build up a String object. Just do Serial.println(rpm)"  But I dont see how this makes the arduinos communicate?

Also, your initial suggestion: the code ccompiles succesfully, and prints the values on the serial monitor of the sender: but the serial monitor of the receiver is blank

Serial.println() will already send the data in human readable form via serial. Thus it is already communication. Please try using Serial.readStringUntil('\n') instead of Serial.readString(). The latter has a 1s timeout. Since you are sending every second there is less than 1s inbetween each transmission. This might cause that function to never exit. The former function call will read only until the newline character, which is automativally added by the println() function