text:
FlexyStepper: set current position leads to reach the old target
I'm using the FlexyStepper library.Unfortunately there's no way to write an issue to the author so I'm going to ask my question here.
The documentation says about the setCurrentPosition*() functions:

set current position of the motor in millimeter, this does not move the motor

But I see a different behavior.
Looking at the code, it seems it just update the current position, leaving unchanged the target position. This leads to an expected movement of the motor. Example:

set the target position to, say: 1000
the motor reach that position
set the current position to, say: 1500
now the motor come back to 1000

Instead, I want the current position from now is 1500, but because it has already reached the target, it shouldn't move further.
Of course a workaround is to set both current position and target to the same value.
I wonder if I'm wrong about the documentation or this might be considered a bug.

Use the workaround--stepper1.setSpeedInRevolutionsPerSecond(0); setCurrentPositionInSteps(1500); setTargetPositionInSteps(1500);

The point of setCurrentPosition() is to calibrate the stepper. It would normally be used in association with a limit switch of some form.
If you set the motor to go to 1000 and then tell it that the motor is actually at 1500 then of course it will then try and go back to 1000 - you have told it that is where you want it, but you also told it that's not where it is.
The normal usage would be:

Step the motor constantly in one direction until it hits a limit switch or similar
Set the current position to whatever that actual position is
Start going to actual positions that are relative to that reference point.

For example

Move the motor anti-clockwise
Motor triggers limit switch
Stop moving the motor
Set the current position to 0
Start using the motor normally

Thanks, but not all projects use motors in such a "normal" way. I need, sometimes, to set a different current position rather than the actual one. I've ended to set both target and current positions. It seems to work. The misleading sentence here is "does not move the motor" until a target was defined before.

What exactly are you trying to achieve by changing what the system thinks the position is all the time?

where did you read all the time? I said sometimes :-) I want to achieve exactly what it literally means: I need the system changes the references on-the-fly. It's a set up for theatrical effects that moves balloons and other stuff. There are no homing switchs, etc...


text:
Can the ESP-1 use SPI to communicate with sensors?
I wonder if I can use SPI to communicate between ESP-1  ESP8266 module and SPI sensors and other slaves.
If so, do I need to install a library?

sure it can - do you know how to use a soldering iron? esp8266 arduino framework comes with SPI library, so, you won't need to install one

ESP-01 was designed as WiFi network adapter, not as a controller board. The are 4 pins on esp-01. RX (io 3), TX (io 1), io 0 and io 2.
SPI requires 3 pins: clock, MISO, MOSI plus one pin for every device connected to the bus. So you could in theory use one SPI device on this 4 pins. The esp8266 Arduino SPI library works only with hardware SPI on esp8266 pins io 12, 13, 14 so you would have to use some software SPI implementation for esp8266.
To connect sensors, actuators or display to the esp-01, I2C is a feasible option. It requires only two digital pins and the esp8266 Arduino Wire library can work on any pair of io pins.
To use esp8266 as MCU with Arduino, there are many development boards with all usable pins broken out (9 pins) and USB chip for simple connection to computer and flashing (Wemos, NodeMCU). Or you can use an esp8266 module with more or all pins of the esp8266 (esp-07, esp-12).

Thanks. Do you know any software spi library that might work?

source: Stack Exchange

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

sort: votes


text:
Why does my circuit work only when I do not use the Serial port?
I am a newcomer to working with Arduinos (and circuits in general) so when I was tasked with making a simple push-button circuit to control an LED's state, and to send a message back using Serial.println() to show the button had been pressed, I noticed that the LED is dimly lit when I press the button to give it power. However, when I do not use the Serial port at all in my code, then it works perfectly as expected.
My code:
const int ledPort = 8;
const int detPort = 7;
void setup() {
  pinMode(ledPort, OUTPUT);
  pinMode(detPort, INPUT);
  digitalWrite(ledPort, HIGH);
  Serial.begin(9600);
}

void loop() {

  if (digitalRead(detPort) == HIGH) {
    digitalWrite(ledPort, LOW);
    Serial.println("9");
    delay(500);
  }
  else {
    digitalWrite(ledPort, HIGH);

My circuit:
https://i.stack.imgur.com/mYUYf.jpg
My Board: MEGA2560

Your circuit makes no sense whatsoever. Can you draw out how it is actually all connected together as a proper schematic rather than photos that make it hard to see what goes where?

Please [edit] your question so that the image can be seen, without the need to follow a link.

Your circuit is wired improperly.
It will be easiest for you to simply follow this official tutorial that will show you how to use a push button to turn on an LED. Even though you have a mega, it will work fine for you.
You will see a wiring picture there that is simplified:

Plus, the correct code is there:
/* Basic Digital Read
 * ------------------
 *
 * turns on and off a light emitting diode(LED) connected to digital
 * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
 * concept of Active-Low, which consists in connecting buttons using a
 * 1K to 10K pull-up resistor.
 *
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
 *
 */

int ledPin = 13; // choose the pin for the LED
int inPin = 7;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON
  }
}

Schematic Is Quite Important
also, as you attempt to look at the picture and build the circuit you discover how difficult it is to see how things are connected.
That leads you to understand how important a simple schematic can be.
I've attempted to turn the pic from the arduino site into a schematic and my interpretation may be wrong or the actual circuit that the Arduino site has built may be wrong.  If anyone has comments I will take them into account.
Trying to build from a picture of a circuit is terribly difficult and trying to debug your circuit from a picture is also. That's why when you submit a question you should submit a drawn schematic of how you have wired it up.

simulate this circuit – Schematic created using CircuitLab

There‘s no series resistor for the led...

@SimSon Yeah, it's a bit odd that the circuit from the Arduino site doesn't add one.  It's because they simply pushed one LED pin into GND and the other into PIN13 on the Arduino header.

Oh, I see. They use a green/blue led, so it might be fine in this case. Not your fault...

Your circuit doesn't make sense to me, either :) I can't see where the LED is getting its ground from, in particular.
Try starting with the circuit shown here and report back!
Good luck!

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


text:
Help with tachometer programme
This is my first programme, which is to control a brushless ESC motor and an IR sensor to read the props' RPM. However I can't seem to figure out why it's not working. The reading keeps giving me 0, and after I edited the programme by changing while (millis()-start < 60000);to while (millis()-start < 1000);, it feeds me expected ';' before '{' token on if (start > millis(){, which makes no sense whatsoever. Here's the programme:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

//Display&sensor
#define Backlight_Pin 13
int initial=0;
//int REV=0;
//int prevtime=0;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//ESC
Servo ESC;     // create servo object to control the ESC
int potValue;  // value from the analog pin

//Calculation
int sensorvalue;
int state1 = HIGH;
int state2;
float rps;
float rpm;
long prevMillis = 0;
long interval = 200;
long currentTime;
long prevTime = 1;
long diffTime;
int sensorthreshold = 1;
int Sensor = 8;
int photoPin = 2;               //
int val = 0;
int valold = 0;
int start;
unsigned int count = 0;

void setup() {
  pinMode(Sensor,INPUT);
  valold = digitalRead(photoPin);
  lcd.begin(16, 2);
  lcd.clear();
  ESC.attach(9, 1000, 2000);
  Serial.begin(9600);
}
void loop() {
  if (initial==0)
  {
    lcd.setCursor (6,0);
    lcd.print("RPM:");
    lcd.setCursor (0,1);
    initial=1;
  }
  //REV= digitalRead(Sensor);
  //lcd.print(REV);

  //Calculation
 start = millis(); // take the start time
 count = 0; // reset couter
 // do the following loop for 60000ms = 1min
 while (millis()-start < 1000);
 {

    if (start > millis(){
      start = millis();
      count = 0;
    }
   val = digitalRead(photoPin);
   if (val==LOW)
   {
     digitalWrite(ledPin, LOW);
   }
   else
   {
     digitalWrite(ledPin, HIGH);
     if (val <> valold) {
       count ++;
       valold = val;
     }
   }
 }

      lcd.print("RPS = ");
      lcd.setCursor(7,1);
      lcd.print(count);
      delay(1000);
      lcd.setCursor(0,1);
      lcd.print(" ");

//ESC
  potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
  potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)
  ESC.write(potValue);    // Send the signal to the ESC
}

And if I put ";" in front of "{", I get this error

expected primary-expression before '{' token

How could I fix this? Any help is appreciated. Thanks!
p.s. I had a rig holding the sensor and rotor stationary and waited 5 minutes for results, no luck, so I thought I would change the time to 1 second and measure RPS, then manually time the result by 60, but then the code broke. I don't think it was hardware failure as almost all joints are soldered, and the wires are solid copper.

You habe a missing closing bracket ) in the first if condition inside the while loop. Likely that caused the problem. Remove the extra semicolon, that you put in.

When the compiler is giving you errors, it has absolutely nothing to do with hardware. If the compiler shows an error, the sketch doesn't even get uploaded to the board


text:
What is the correct way to interpret the built-in Analog-to-Digital Converter output?
When using the built-in analog to digital converter of the Arduino Uno Rev 3's Atmega328P with a reference voltage of 5V, what is the appropriate function to interpret the output? There is conflicting information on the Arduino website and in the datasheet for the Atmega328P (Arduino Uno Rev 3's chipset).
A lot of code examples on the internet indicate that the appropriate conversion factor is 5V/1023 (including the Arduino website: float voltage= sensorValue * (5.0 / 1023.0);).
Per the Atmega328P's datasheet, it indicates the conversion factor is 5V/1024:

If Vin and Vref are 5V, then the ADC reading would need to be 1024 in order to have a true reading of 5V, which is not possible since 1023 is the max output of the ADC. The closest reading to 5V we can get from this equation is ~4.9951 (5V*1023/1024).
With the Arduino example's conversion factor of 5V/1023, we get 5V for an ADC output of 1023.
Additionally, since the information from both sources is in conflict, it got me thinking a little more: The ADC is inherently sampling, and I am not sure if the ADC rounds up/down to the nearest value, so perhaps the closest approximation of Vin is an equation like the following that splits the difference:
Vin = (ADC+(ADC+1))/2 * 1024/Vref
Using the above equation, an ADC reading of 0 with Vref=5V would give Vin = (0 + (0+1))/2 *1024/5V = ~0.00244. This equation never gives a reading of 5V or 0V, but rather a value that splits the difference between samples.
Perhaps I am splitting hairs since the absolute accuracy of the ADC is "±2 LSB absolute accuracy", but I would still like to know which is the best equation to convert an output from the ADC into a voltage measurement.

You're overthinking things here. It really doesn't matter if you use 1024 or 1023 - the ADC isn't that accurate anyway.

Besides, you divide by the maximum value, not the number of steps - so 1023 is the correct one. The two would be the same if counting started at 1, but it doesn't - it starts at 0

@Majenko Even if the ADC isn't that accurate, I would still like my readings from it to be as accurate as possible and not introduce unnecessary error by use of the wrong equation. Also, if you are confident that 1023 is the correct value, then you are confident it is just a persistent typo that it appears in multiple AVR chipset datasheets (including ATmega2560, ATtiny85, ATmega1284)?

It's an argument that has been raging for years and years. The difference between the two is so minor that it is dwarfed by the inaccuracy of the ADC. It really is pointless. Use whichever you feel happiest with.

@Majenko Unfortunately, my research prior to asking this question did not turn up any such arguments. Can you provide some insight into the arguments as an answer? Microchip claims  ±2 LSB accuracy and the difference between  ±2 LSB and +1 LSB/-3LSB (or +3LSB/-1LSB) is important enough for me in my application to understand as part of tolerance stackup. Therefore, choosing the correct equation is important. I am using the ADC as a gross-check of a value, but I would like to understand all sources of the tolerance stack-up so I can shrink my expected error bounds as much as possible.

Well, it can also be argued that both results are perfectly valid and correct. Since each LSB covers a range of voltages the question arises: do you care about the upper bound or the lower bound of the quantisation? Either is as accurate or inaccurate as the other.

I am not sure I follow, the step size of the quantization is not the same in this case between the two methods, 5/1023 != 5/1024. With regards to the question "do you care about the upper bound or the lower bound of the quantisation?", I care about minimizing the error in my measurement to attain the stated absolute accuracy of ±2 LSB.

Here's one thread of the argument. As I say, it's been raging for years. https://forum.arduino.cc/index.php?topic=303189.0

the Atmega328P's datasheet, it indicates the conversion factor is
  5V/1024 [...]

Indeed. And the datasheet is the only authoritative source. All the
other sources are second-guessing.

If Vin and Vref are 5V, then the ADC reading would need to be 1024 in
  order to have a true reading of 5V

You can't get a true reading of 5 V. As per the datasheet (emphasis
mine): “0x000 represents analog ground, and 0x3FF represents the
selected reference voltage minus one LSB”.
Any input voltage larger that the maximum representable voltage will
read as 0x3ff (i.e. 1023), just like any negative voltage (within
the forward voltage of the protection diode) will read as zero. Thus,
reading either 0 or 1023 should be interpreted as a saturation
of the ADC, meaning the actual voltage is unknown.

The ADC is inherently sampling, and I am not sure if the ADC rounds
  up/down to the nearest value

In principle it should round to the nearest value. The transition in the
reading from 0 to 1 should ideally happen at
Vref/2048. C.f., again, the datasheet, subsection “ADC
Accuracy Definitions”: “Offset: The deviation of the first transition
(0x000 to 0x001) compared to the ideal transition (at 0.5 LSB).”
A little bit further in the page it is stated that the ideal position of
the last transition (1022 to 1023) is “at 1.5 LSB below maximum”.

Perhaps I am splitting hairs since the absolute accuracy of the ADC is
  "±2 LSB absolute accuracy"

Indeed. If you really care you should probably calibrate your ADC. See
Response of the Arduino ADC.
Edit: in a comment you mention that the factor 1024 could
conceivably be “a persistent typo that it appears in multiple AVR
chipset datasheets”. It may be an error, but certainly not a typo, as
the datasheet contains multiple independent statements that confirm the
factor 1024.

The calibration curves are interesting -- looks fairly straight, but the slopes differ.  On could do much of the calibration by looking for the ratio that gives ADC==1 and ADC==1022 and fitting just those points.

As others have said, the difference between 1023 and 1024 is quite small.
However, the fact is that your input range for the ADC is 0 to 1023. (That's 1024 steps, but since it starts at 0, it won't go up to 1024)
You'll get 0 at the minimum input, and 1023 at the maximum value.
If you're using a 5.0V reference voltage and no voltage dividers, that means you will get 1023 at 5V (ignoring measurement error.) If you want your output value to be the VOLTAGE measured, you would want Vin / 1023.0 * 5.0. That would give you a value of 5.0 at the max input of 1023 (representing 5.0 volts) and 0 at 0 volts input.
Edit:
Since my posting, I read the threads on this, and there is a raging debate on the subject. I am now less clear that there is "right" way to do this.
The issue is that the ADC value doesn't give you a certain reading, it indicates a range. When you get a value of 1024, the ADC is tellling you that the measured voltage is in the top 1/1024th of voltages, from about 4.995V to 5V (or above, for that matter.)
The steps are actually in 1024ths. That argues that you should divide the measured value by 1024, and then return a range of possible voltages:
value = analoglRead(pin);
float lower_value = value / 1024.0 * 5.0;
float upper_value = (value + 1) / 1024.0 * 5.0;

For an analog reading of 0, that would give you a range of 0.0v. to 0.0048828125v.
For an analog value of 1023, that would give you a range of 4.9951171875v to 5.0v

After reading through various arguments for use of different transfer functions, this is my summary:
In order to achieve the manufacturer-stated absolute accuracy of ±2 LSB, you should use the manufacturer's equations and published guidelines on usage to ensure that accuracy (e.g. ensuring appropriate ADC clock speed / sampling time and implementing noise reduction techniques).
It may be possible to achieve better results using another transfer function by calibrating specific to each individual circuit. If you go this route, all of the responsibility of ensuring accurate calibration across the range of expected operating conditions (including offset/gain drifts due to environmental factors) are your responsibility to characterize and account for when developing the transfer function. This is where the transfer function Vin = 5V/1023 * ADC fits in. This transfer function may in fact be a better representation of the actual outputs for a specific chip. However, use of this transfer function shifts responsibility onto its user to verify that it actually produces better results.
A couple of important notes:

Manufacturer's claims are not always accurate. However, they are likely based on a large statistical sample size and if the manufacturer's published statements are wrong, this potentially opens the manufacturer up to lawsuits depending on the impact of an incorrect published specification. For this reason, I tend to trust manufacturer datasheets from large chip makers until proven otherwise.
The question assumed a perfect 5V reference for simplicity of discussion, however the actual value of a real voltage reference is almost impossibly a true 5V and has some degree of noise affecting its stability which should also be considered when attempting to read a true voltage value. Ideally, if you are trying to read a sensor value and can create a circuit in which the voltage reference cancels out of the final measurement, that will help with accuracy of the sensor reading.


text:
Arduino Temperature Sensor
We are doing a project and we need to build a thermo sensor and read the voltage and the temperature but we also have to have the temperature correspond to LEDs that will give a blue for cold green for mild and red for hot we are using a DS18b20 thermo sensor.
How should we write the code or where could we find code that would work for this purpose?
We both have a very surface level understanding of code at the moment, however our time constraints have made learning it difficult.

Please show us the code you've written so far.

What is the reason for your time constraint? Is this a school project? Is it for CS? What resources do you have for the class? Do you understand how to set up the hardware, and just need help with the software? What's your background?

This forum isn't great for detailed solutions to vague problems. If you don't have much experience with programming, you'll have a lot to figure out. It will take you a while (realistically probably a couple of weeks if you work at it every day, and have a knack for it, assuming you're starting from scratch.)
The first step is to define your problem. It sounds like you want to build a project that uses colored LEDs to indicate the measured temperature in different ranges.
So lets say you want:
Temp <10°C light Blue LED
Temp 10°C - 30°C light green LED
temp >30°C light red LED.

Break the problem into bite-sized pieces and solve them one at a time.
Pick an Arduino model. Install the IDE. Run a sketch that will blink the built-in LED. Then do a google search on "Arduino Blink without delay" and rewrite your blink code to not use the delay() function. Forget the delay() function exists and never use it again, since it will usually get in the way of what you need to do.
Then figure out how to wire separate LEDs (including current limiting resistors) to 3 separate pins. Make your code blink all 3 LEDs at the same time by toggling the appropriate pins' output states.
Modify your app to blink first one LED, the 2nd, and then the third. Now get tricky and modify your app to blink the first LED on and off once a second, the next LED once every 1/3 of a second, and the fourth LED to blink once every 1/4 second, all at the same time. (That will force you to really understand how to do timing without delay.)
Now look up a sample project that uses your temp sensor. (Try this one I found, for example) Run that and get it to send the temp to your serial port once every few seconds. (again not using delay().)
Now write a loop that reads the temp sensor, decides which range the temp is in, and lights the appropriate LED based on those ranges. Note that you may only be able to read the temp every 2 seconds or so (the DHT22 and DHT11 temp sensors I've used have that limitation.)


text:
ESP32 documentaiont for "time.h"
I am working from the example sketch in that installed with the ESP32 Dev Module into the Arduino IDE.  It includes <WiFi.h> and "time.h".  I have a number of questions about how to use the clock that is set up with configTime using NTP. I am trying to find the documentation, but I'm having difficulty identifying exactly who is providing me the "time.h" header file, and of course, there are a lot of different time.h header files out there so googling is difficult.
Where can I find the documentation for this particular header?

Example questions:

Can the time be set manually without a WiFi connection?
Can the timezone be changed without connecting to NTP again?
Can I get the time as a Unix Time Stamp?  (Yes)
Can I arrange for a function callback at a certain time? (I'm aware I can use the timer library for this but I'm hoping for something like a callback at 4:20p every Saturday)

have you checked in the library for documentation?

time.h is provided by the compiler (more specifically the C library in use in the compiler).
I believe the xtensa-esp32 compiler uses newlib as the C library. If that is the case, the documentation is here: https://sourceware.org/newlib/libc.html#Timefns

So, time.h is not where configTime(...) is defined then?

No. configTime() is part of the ESP32 core.  https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-time.c#L47


text:
Migrating an Arduino Project to Beetle Bluno
So I have a working project with Arduino Uno. I now want to migrate it to the Beetle Bluno. I tried running the code on the Beetle and it does work. I cannot seem to get the Bluetooth to work though. The code is below:
#include <Bounce2.h>
#include <SoftwareSerial.h>
//#include <Wire.h>
//SoftwareSerial bluetooth_port(10, 11);

// Connect each button with one connection
// to GND and the other to a digital pin.
const byte buttonPinBLE1 = 2;
const byte buttonPinBLE2 = 3;

class Button{

  private:

    byte m_buttonPin;
    byte m_counter = 0;
    unsigned long m_buttonPressTimeout;
    unsigned long m_previousMillis;

  public:

    Button(byte buttonPin):
      m_buttonPin(buttonPin),
      m_counter(0),
      m_buttonPressTimeout(1500), // Button press timeout in ms.
      m_previousMillis(0){}

    void Update(){
      if(m_counter > 0 && millis() - m_previousMillis >= m_buttonPressTimeout)
      {
        //Serial.print("Count from Update() just before it's reset to 0 = ");
        Serial.println(GetCounter());
        m_counter = 0;
      }
    }

    void IncrementCounter(){
      m_counter++;
      if(m_counter > 4){m_counter = 4;}
      if(m_counter == 1)
      {
        m_previousMillis = millis();
      }
    }

    friend void IncrementCounter(Button&);

    void IncrementCounter(Button&){
      IncrementCounter();
    }

    byte GetCounter(){
      return m_counter;
    }

};

Bounce buttonOneDebouncer = Bounce();
Bounce buttonTwoDebouncer = Bounce();
Button ButtonOne(buttonPinBLE1);
Button ButtonTwo(buttonPinBLE2);

void setup(){
  //Serial.begin(9600);
  Serial.begin(115200);
  pinMode(buttonPinBLE1, INPUT_PULLUP);
  pinMode(buttonPinBLE2, INPUT_PULLUP);
  buttonOneDebouncer.attach(buttonPinBLE1);
  buttonTwoDebouncer.attach(buttonPinBLE2);
  buttonOneDebouncer.interval(25);
  buttonTwoDebouncer.interval(25);
}

void loop(){

  // Call the Update function as fast as possible.
  ButtonOne.Update();
  ButtonTwo.Update();

  // Button one pressed.
  if(buttonOneDebouncer.update()){
    if(buttonOneDebouncer.fell()){
      if(digitalRead(buttonPinBLE2) == 0){
        ButtonOne.IncrementCounter();
      }
    }
  }

  // Button two pressed.
  if(buttonTwoDebouncer.update()){
    if(buttonTwoDebouncer.fell()){
      if(digitalRead(buttonPinBLE1) == 0){
        ButtonOne.IncrementCounter(ButtonTwo);
      }
    }
  }
  if(digitalRead(buttonPinBLE1) == 0 && (digitalRead(buttonPinBLE2) == 0))
  {
  Serial.println("9");
  }

}

Does anyone know how I can get the device to communicate with my computer via Bluetooth? I have no experience with the Beetle and I cannot seem to find much help online.

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

@VE7JRO Hello. You helped me with the single tap, double tap question (https://arduino.stackexchange.com/questions/69897/detecting-how-many-button-pressessingle-tap-double-tap-etc-with-two-simultane). Thank you so much for that once more. However, it isn't accurate and sometimes if i press the buttons once, it outputs a 2, sometimes it outputs a 4 when i press it twice. Do you know how I can fix this issue?

The original code I provided in the linked Q+A worked perfectly on a Arduino Uno. The sketch you are using in this question is different. I do not have a Beetle Bluno to test with, so I'm sorry, but I can't help you. If I can't test the sketch on the "same" hardware, then I'm just guessing, not answering.

@VE7JRO the code I am using is on an Arduino Uno...it isn't working accurately for some reason on my side. I haven't started using the Beetle as yet so still testing on the Arduino Uno


text:
ESP web server calling Javascript function
Is there a way to call Javascript functions from an ESP?
I don't want to call AJAX requests every few seconds; I want to update my values only when they change.
Can it by done?

much simpler: you can connect both the browser and the mcu to a real server. the browser connects to it via websocket, and the MCU pushes updates to the server as data becomes available.

Do you want to access the JavaScript from a browser or do you want the esp to call a server which provides JavaScript?

First thank you for the answers. I have the esp as a server and it runs a website that i am using as GUI for my esp program. Now i use XMLHttpRequest so that the browser gets data every 5 seconds and updates values in the gui. And i want to call the update function in the page whenever the values in the esp change. That's posible with the server-push or server send event? I need to google this first. Thanks for now.

@Tomas Did you see my comment on my answer? It might help you understand

Thank you all. Yes i read it and it helped. I understand it now. Sorry that i write you only now but this is my first night shift with no real work, that means that i had time to read all of your sugestions.

If you want server-push, you can use Server Sent Events or a Websocket instead of polling with XMLHttpRequest.
So yes, it can be done, and I have implemented both using a Nano 33 IoT at one end and Javascript in a browser on the other. Some example code is here: https://github.com/ocrdu/arduino-webinterface-sse and here: https://github.com/ocrdu/arduino-webinterface-websocket.
I don't know if there are convenient libraries for the ESPs to do this, though.

I am gonna Google it. Thanks

I assume that you misunderstand how JavaScript works. JS is executed on the client side and therefore the esp can easily serve JS code the same way it would provide any html content. Take a look at the Webserver examples and embed your JavaScript code into the html content that the examples use.
The important thing to note is that the esp does not execute JavaScript, from its perspective the content is just an ordinary string without functionality.
The easiest and fastest way to update values on a web interface is probably using a websocket: the esp is a websocket server (using link2004‘s websocket library) and the JavaScript binds to the esp‘s websocket as a client (this has nothing to do with the esp/arduino/C++, but you’ll find examples out there).

I am a beginner in this stuff. I know or think that my esp is a websocket server. But what that means i have no idea. To build the website gui i learned about spiffs, and little bit of html, css and javascript. It is more complex that i firstly hade in mind when i started this project. I try to learn only what i need directly for my needs. I learn mostly from examples and Google is my best friend but all the examples i found used the XMLHttpRequest. Or maybe i asked Google the wrong questions.

Well, I can‘t make you understand that within a second, but an important hint: you still need the Webserver to provide the client with html/JS code. And beside that you also need the esp to be a websocketserver. Once the websocket client (JavaScript, executed by browser, provided by esp-Webserver) has connected to the websocket server, you have a full-duplex connection in which both devices can send at any time. In the JavaScript you have to parse whatever the server sends and update the relevant values. I’ll add an example for a JS websocket client.

https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_client_applications

Here, exampleSocket.onmessage() is where all messages sent by the server arrive

This was a big help. Thanks


text:
Will bootloader communicate via TX0 / RX0
I'm fairly new to Arduino programming but have a good deal of experience with  low-level programming early processors, having originally cut my teeth on Z80, 8088, etc. I'm looking at developing a sizeable project using a Mega 2560. The project includes quite a lot of off-board logic, leds, and an RPi. Thus I don't want to overload the 2560 voltage regulator and really want to use common rail 5v power with a switch-mode supply. However, I also need debugging / console access, so this gives me the immediate problem of direct 5v driving whilst the board is being driven with 5v from the USB port, which is a no - no. The solution appeared to be fairly simple - use a CH340 - based USB to serial converter and connect it to RX0, TX0 and Reset (DTR output connected via a blocking capacitor) but with its 5v output disconnected. With this setup, the Arduino communicates quite happily with the IDE-based serial monitor (the sketch was downloaded via the on-board usb port), but on trying to download a new sketch via this route, AVRDude fails with a timeout. At the commencement of the download the processor is being reset, but the bootloader doesn't appear to hansdshake with AVRDude (properly). Is this a known feature or have I missed something?

the bootloader listens on RX0/TX0. the on-board USB chip is connected to this pins

Problem solved. The standalone CH340-based converter for whatever reason isn't man-enough to reliably pull down the RX0 line when connected to the Mega 2560 (also with a CH340 converter on board). I've seen suggestions posted in various places that this can be a problem with respect to DTR (though I don't have a problem with it). My solution is to insert a 7417 open-collector non-inverting buffer between the output of the stand-alone converter and the RX0 input on the 2560 board. I've not been able to find a schematic for the Mega 2560 board to determine its pull-up resistor size but imagine it must be relatively small. Thanks to those who made suggestions.


text:
Adafruit Circuit Playground Express fails to upload
When uploading code to the Adafruit Circuit Playground Express, I have found that most of the time it fails to upload saying that the port is busy. There seems to be no logical reason behind this, as it uploads perfectly to an Arduino Uno (Yes, I did switch the board types). What am I doing wrong?
Here is the error:
processing.app.debug.RunnerException
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:152)
    at cc.arduino.UploaderUtils.upload(UploaderUtils.java:77)
    at processing.app.SketchController.upload(SketchController.java:732)
    at processing.app.SketchController.exportApplet(SketchController.java:703)
    at processing.app.Editor$UploadHandler.run(Editor.java:2075)
    at java.lang.Thread.run(Thread.java:748)
Caused by: processing.app.SerialException: Error touching serial port '/dev/ttyACM1'.
    at processing.app.Serial.touchForCDCReset(Serial.java:107)
    at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:136)
    ... 5 more
Caused by: jssc.SerialPortException: Port name - /dev/ttyACM1; Method name - openPort(); Exception type - Port busy.
    at jssc.SerialPort.openPort(SerialPort.java:164)
    at processing.app.Serial.touchForCDCReset(Serial.java:101)
    ... 6 more

Operating system: kubuntu linux 64 bit
EDIT: Never mind. In the end I used chmod a-x /usr/sbin/ModemManager to remove execute permissions from every user, and that worked without any noticeable repercussions to my system. For anyone who wants to do the same, make note of the original permissions, so you can change it back if you have to.

The actual error part of that stack trace is:
Port name - /dev/ttyACM1; Method name - openPort(); Exception type - Port busy.

You have something else using /dev/ttyACM1.  If you don't yourself have something open, such as a serial terminal or the Arduino serial monitor, then the most likely culpret is modemmanager.

https://majenko.co.uk/blog/diagnosing-arduino-problems-linux


text:
Is there an Arduino library that uses ARP to get list of connected devices on network?
I have been looking for a library that can execute an ARP (Address Resolution Protocol) command to return a list of connected devices on the network. The idea is that it would send the request to the gateway and get a list of MAC addresses of currently connected devices as a sort of "who's home" request.
I have searched around Arduino's libraries and have not found any that specifically perform this type of functionality so I was hoping that maybe it was available in a function within a broader networking library.
The particular networking interface (wifi via ESP8266/ESP32 or Ethernet) does not matter as I have not chosen a specific board for the job yet. I'm interested in any library solution that would allow me to poll the gateway to see which devices are currently online without having to buy a special device like FingBox.
Any recommendations for a library that includes this functionality or an approach that would allow me to send ARP commands over the network?

the way i do this is by looping from 0 to 255 and scanning each local IP.

@dandavis, I feel like that's what the DOS arp command and apps like Fing do as well. I'm thinking something like WiFi.ping()

ARP isn't generally used the way you described. Per the spec, to resolve an IP address into a MAC address, you broadcast an ARP request for the IP address, and receive  a unicast response from the host whose address it is - not a router. It also only resolves a single IP address in one request; it doesn't return the contents of the entire ARP cache.
While you could potentially unicast ARP requests to a router, it's anybody's guess as to whether the router would respond - it's not required to. By spec only the computer who's IP address is being queried should respond - so a router should not unless you've sent it an ARP request for its IP address. You'd also have to send one request for each IP address in the range specified by the LAN's network mask.
You're better off using SNMP, if the router supports it. SNMP can read the router's entire ARP cache with very little overhead (and very few packet exchanges).
The are SNMP implementations for the ESP32 and ESP8266, but they're likely to be difficult to use. Googling will find them for you.

Thanks, I'll take a look for SNMP libraries. I thought ARP was the name of the protocol that returns the routing tables as that is the DOS command that returns the list of connected devices. MAC addressing would be most useful as device IPs are generally subject to change.

It is the name of that command, but what it returns isn't a routing table, it's the MAC address translation table of the computer you run it  on, not the router. The protocol is different from the command.

I was searching for the same function but I think you don't need to query the gateway.
My idea is to loop through all the valid ip addresses, send a ping to each one (it does not matter if they don't answer the ping), and we should have the MAC for this ip. Then check if this MAC is in a list saved in some non volatile space (may be an sd card) and if it's not in the "known peers" list, add it and send a message warning about a new device added to the network.
Using the MAC address instead of the ip for identifying the devices should avoid problems with dynamic ips recognized as new.


text:
Recommended way to fork a library
I want to extend a library, available on github to add some features I need.
Of course I will made available the new source code as well.
Because it's the first time I do this, I'm not sure how to do.
My idea:

fork the original repository
create a new branch
make the changes
commit them locally
push the new branch on another (mine) repository (of course, to avoid messing up the original one)

Is it correct?
How to test the library while developing it? I mean, in which folder I have to clone the repo?

Almost.

Fork the library to your account
Check out your fork
Edit as needed
Commit locally
Push back to your fork

Your fork is yours to do with as you wish. Github makes it easy, should you wish, to then pass those changes back up to the original repository (make a "pull request"). But you don't have to do that (and probably don't want to).
You can make a new branch if you like, but that's pointless - your fork is, in effect, a branch itself (well, it's an entire new tree really).

If he plans to make a pull request, then creating a new branch will make things easier.


text:
Lolin NodeMCU V3 and 5V sensors
I am new to Arduino and electronics so please correct me if I made a mistake.
Many sensors and actuators require 5V. The Lolin NodeMCU V3 has outputs of 3.3V. I want to have them working together.
I have read that the VIN pin outputs the voltage of the USB power source, which is around 5V. I bet that many sensors and actuators can be connected to VIN.
I guess that the main difference with the VCC pin of other boards is the accuracy and stability of the potential.
1) What about the amperage? (I guess that the max amperage of the USB power supply is divided between the board and sensors/actuators connected). How does it compare with the VCC output of, let say, an Arduino UNO?
2) How important is in most practical cases not having exactly 5V? (clearly, I am not considering using the sensors for extremely accurate measurements). I am interested in things like movements/distance/light/accelerometers/humidity etc. sensors and LCD displays, relays, small motors, etc..
I have seen that many sensors have a not so narrow range of working voltages. That makes me think that small oscillations in the USB voltage may not be significant.
3) Is there a better yet simple way to connect 5V devices to this board?
Thank you in advance.

I fear you lost your bet. ;-) As the name VIN suggests the Vin pin is used to supply your nodemcu with an external power (up to 20V). That's if you do not want to connect the USB port, or need more power than your USB supply can handle. There is a VU pin that provides the power 5V from the USB connection. See the following link for more details: http://henrysbench.capnfatz.com/henrys-bench/arduino-projects-tips-and-more/powering-the-esp-12e-nodemcu-development-board/ It would be more practicable, if you power the sensors and use that power also for the nodemcu.

Also, be careful if you connect 5V sensor pins with the 3.3 V nodemcu pin (IO pins). That could (sorry would) kill your nodemcu.The maximal current you can draw from the nodemcu power pins is defined by the voltage regulator (~ 800 mA) and the capabilities of your power supply (which we do not know).  That is valid for the USB port and VU pin too.

nodemcu's vin is more like 4.4v than 5.0v. the nodemcu's IO is generally 4.4v tolerant. i use lots of 5v sensors with mine just fine, running at 3.3v or 4.4v. if in doubt you can level shift, but i've only had to do that once (of dozens+dozens) fwiw.

@PeterPaulKiefer, Thank you!

@dandavis, Do you connect your sensors to VIN? The Peter's comments seems to suggest connect them to VU

i've not seen a nodemcu with a "VU" pin. not saying they don't exist, but indeed all the ones on amazon seem to mark that slot "RSV". if your board has it, and you don't need the inline diode, then go for it.

@dandavis The OP told us about a Lolin NodeMCU. I have some of them at home. I confess I'm careless like you and often thought "Can 1 and a halve Volt make a difference" Unfortunately I had not the luck you had and grilled two of my little friends. I know, I will be careless in the future too, but here on SE I can not give an advice, that probably kill the MCUs.

@user1420303 Sorry I might not be exact/clear enough. I don't advised you to use the VU pin ( that can also have different names ). I just mentioned it, as the pin where you have access to the USB power.  My advice would be use an external 5 Volt power supply to power the sensors and the NodeMCU with it. To power the MCU use the Vin pin.  In case you want to drive motors or servos or power LEDs, it's even better to use separate power supplies for them. My PC has USB ports that can only drive 500mA. That wouldn't be enough to drive the NodeMCU and a couple of motors.

You've mentioned projects that use the Vin Pin to access the 5Volt line of the MCU. I don't know what projects you've seen. But the ones I know have routing nets that are named "5V", that are connected to the Vin pin and the sensors VCC pins. But they are also connected to a e.g 7805 Regulator or a LM317 or some more efficient ones. So effectively they power the NodeMCU and the Sensors with that external supply. (As I advised you in the last comment.)

What about the amperage? (I guess that the max amperage of the USB power supply is divided between the board and sensors/actuators connected). How does it compare with the VCC output of, let say, an Arduino UNO?

The 5V pin is connected directly to the 5V of the USB. Whatever your USB port can provide the 5V can provide, minus the current used by the ESP8266.

How important is in most practical cases not having exactly 5V? (clearly, I am not considering using the sensors for extremely accurate measurements). I am interested in things like movements/distance/light/accelerometers/humidity etc. sensors and LCD displays, relays, small motors, etc..

That all depends on the device. Read the datasheet. Look at the Electrical Characteristics. It will tell you the recommended (and the absolute maximum) voltage range.

Is there a better yet simple way to connect 5V devices to this board?

Again, it all depends on the devices. Many many devices that are marketed as 5V are in fact "anything from 2.8V to 5.5V" or something like that. Read the datasheets!
The NodeMCU is a tricky board to use with 5V because there is no isolation between the USB power and the 5V pin's power. You can't power the board through the 5V pin and still be able to use the USB port or you risk destroying the USB port or computer that the NodeMCU is plugged into.  If possible you really want to be running as many 3.3V devices as you can, or to keep any external 5V supplies completely separate (except ground, of course) from the 5V of the NodeMCU.

the 5v pin isn't directly connect to usb, it's a misnomer; there's a diode in series. a rather measly current capability diode too, imho, which makes it tougher to run 5V RGB LED strips...

@dandavis Not according to the schematic I saw. The diode was between both the USB and the 5V pin and the input to the regulator.

On my amica boards I see ~4.5 volts, and can pull up to half an amp or so. on my lolin boards, the voltage is actually somewhere under VCC: I can't power anything from it, not even a DHT-11. I suppose there may be several designs being sold as "nodemcu" though, so we could all be right.

@dandavis There is a lot of Chinese crap out there now with zero documentation, yes.

nodemcu gives 3.3 V output voltage. This output voltage is not considered sufficient by many components. So my recommendation is logic converters. The most logical solution to convert 3.3V voltage to 5V. Thus, the elements used with 5V will work stably.


text:
When connecting, client.connect() returns 0
I'm using an arduino UNO with ethernet shield. When following a few guides online for a school project I came across this issue. First code sample:

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

    EthernetClient client;

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

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

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

This doesn't work, unfortunately. We successfully connect to our network, but client.connect() doesn't work and returns 0. Expected result:

SUCCESS: 1
TIMED_OUT: -1
INVALID_SERVER: -2
TRUNCATED: -3
INVALID_RESPONSE: -4

According to the documentation it shouldn't be able to return this. Why wouldn't this work? Thanks in advance.

dosen't work is not very useful because it does not describe the observed behavior ... what were you expecting client.connect() to return?

one of the values specified in the documentation, which would be: 1, -1, -2, -3 or -4.

The documentation is wrong. The connect function only returns 1 on success and 0 on fail. All examples have if (client.connect(host, port)) { (0 is false, 1 is true).
Try the WebClient example provided in the IDE Examples menu for the Ethernet library. It has better diagnostics of Ethernet link.
You can try the WebServer example. It doesn't need Internet connection.
You can try ping the IP address of the Ethernet shield.
The shield should be connected to a router or switch and the gateway IP address should point to a device routing the network traffic to Internet.

Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
connecting to www.google.com...
connection failed
disconnecting.
Received 0 bytes in 0.0000, rate = 0.00 kbytes/second is the response im getting

this tells us that the shield is detected and the link is active. did you set the IP address and dns server address?

Yes, I set the ip, dns, and gateway to my own

To a switch yes. Ping returns 0% loss.

ok. try the WebServer example. it doesn't need Internet connection

That works. I can connect to the arduino and it shows a webpage

in WebClient example change the server to "arduino.cc" and client.println("GET /asciilogo.txt HTTP/1.1"); as here https://github.com/jandrassy/WiFiEspAT/blob/a2176889757be3fc3cf9c09a1512081864b39111/examples/Basic/WebClient/WebClient.ino#L57

That returns connection failed

use the router's IP address as a gateway. it must be a gateway to Internet

Using the routers IP as a gateway doesnt fix the problem

@SimonV., what are the IP settings of your computer? why your network doesn't have DHCP?

You need to provide more than just the IP address. The Arduino also needs to know the default router address in order to send packets to the right place.
Unfortunately there isn't a way of giving it that information without also giving it a DNS address, so you have to do that as well.
You need to have:
IPAddress gateway(192, 168, 1, 1);
IPAddress dns(8, 8, 8, 8);
IPAddress ip(192, 168, 1, 25);

And then in setup:
Ethernet.begin(mac, ip, dns, gateway);

Alternatively you can rely on DHCP to give you all the details, and just use:
Ethernet.begin(mac);

Unfortunately this does not resolve my issue

I am assuming that your router is 192.168.1.1 - it may not be. You should make sure to use the right IP address there for your network.

the library defaults to gateway and dns calculated from provided IP (last number changed to 1) and net mask 255.255.255.0

I have checked and I am indeed using the correct gateway. Would a powerline adapter influence this? I am using the gateway of the powerline adapter I'm connected to.


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

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

    EthernetClient client;

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

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

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

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

Find a server that doesn't automatically switch modes to https as google does.  If you put 64.233.187.99/search?q=arduino%20HTTP/1.0   in your browser you'll see that it switches to https.
If make the same request via the wget terminal app it fails.
--2020-01-17 11:42:26--  http://64.233.187.99/search?q=arduino%20HTTP/1.0
Connecting to 64.233.187.99:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://www.google.com/search?q=arduino%20HTTP/1.0 [following]
--2020-01-17 11:42:26--  http://www.google.com/search?q=arduino%20HTTP/1.0
Resolving www.google.com... 172.217.4.132, 2607:f8b0:4007:80c::2004
Connecting to www.google.com|172.217.4.132|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2020-01-17 11:42:28 ERROR 403: Forbidden.

There should also be an error returned to the client object which you can print out for debugging the conection.
Change your code to print out the return value of the client.connect call like so
void loop() {
      int result = client.connect(server, 80);
      if (x) {
        Serial.println("connected");
        client.println("GET /search?q=arduino HTTP/1.0");
        client.println();
      } else {
        Serial.println("connection failed");
        Serial.println(x);  // print out the error
      }
    }

One last thing, you set your dns server to 8.8.8.8 which should generally be set to your gateway / router of 192.168.1.1.


text:
Powering an rc car motor with arduino
I have a weird problem. When I power an rc car motor through the 5v or the 3.3V arduino's outputs everything goes fine, while powering it through digitalPins does not work.
I'm testing digitalPins with a simple led Blink example. Leds work, the motor does not move. Shouldn't digitalWrite(pinNumber, HIGH) output 5volts? What is the difference between digitalWrite voltage and 5v board output voltage? It seems crazy to me that leds light up without problems but the motor remains motionless...

Do you know how much current a digital pin can provide? Do you know how much current the motor draws? Please update your question with those details.

I deserve these answers ;)

Never ever power a motor or anything, that needs that much power, through a digital output pin. The maximum rating is 40mA, though you should not draw more than 20mA continuously from it. Also there is an overall limit of 100mA over all digital pins together. If you are drawing more from the pins, first the voltage will drop immediately, since the pin cannot provide what you ask for. Then you can easily destroy the pins output hardware or the whole Arduino. For an LED you normally use a current limiting resistor, so that it does not draw too much current from the pin.
For anything with more current demands, you need some kind of driver, which will take the big current load of the microcontroller. The easiest driver is a transistor or MOSFET (to switch the motor on and off or to have different speeds). If you want the motor to spin in both directions, you need an H-bridge driver (effectively 4 transistors/MOSFETs).
Note: I'm talking about simple DC motors here. Other types of motors need other types of drivers.

Good answer. Note that you probably also need a flyback diode to protect the transistor from the inductive motor coils

It's also not a great idea to drive anything but the smallest motors from the 3.3V or 5V outputs on the Arduino board. Those have very modest current output, and the noisy load of a motor will likely cause the power to everything else to bobble, even if it doesn't exceed the low current limits of those supply lines


text:
Does RFID-RC522 supoort tk4100 chip protocol ISO18000-2C 10 digital ID card?
I have ordered a starter kit and received RFID reader is

RFID-RC522

module with one card and tag now I need more RFID card for my project and I can't find the supported card type for my project please can any one tell me supported card types and if this card supports my device this is the card type

tk4100 chip protocol ISO18000-2C 10 digital ID number

The MFRC522 on your kit is designed to communicate with ISO/IEC 14443 A/MIFARE and NTAG cards.
Search for Mifare Classic or Mifare Ultralight or NTAG213, NTAG216 ... cards.

Thank you very much


text:
SSD1306 recognized in I2C scaner, can't get it to display
The gist of my issue is in the title. I have a cheap ebay SSD1306 128x64 display which I hooked up to my arduino, and checked the wiring at least 50 times and the address is correct, the display has the jumper set to 0x78 and the arduino (Nano with ATmega168) sees it on an i2c scanner as 0x3C which is expected.
Now I installed Adafruit's SSD1306 and GFX libraries and an OLED i2c library I found somewhere (can't find it, sorry. In the IDE it's called OLED_I2C) and ran both example codes (shortened Adafruit's to fit on a 168) and I can't get it to show anything. I've tried many things including trying the 128x32 code with no luck, not even missing every other line. I think the display works since it shows up in the scanner, does anyone have any idea what could be wrong? Thanks in advance
My shortened Adafruit code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

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

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  // display.display() is NOT necessary after every single drawing command,
  // unless that's what you want...rather, you can batch up a bunch of
  // drawing operations and then update the screen all at once by calling
  // display.display(). These examples demonstrate both approaches...

  testdrawline();      // Draw many lines

  testdrawrect();      // Draw rectangles (outlines)
}

void loop() {
}

void testdrawline() {
  int16_t i;

  display.clearDisplay(); // Clear display buffer

  for(i=0; i<display.width(); i+=4) {
    display.drawLine(0, 0, i, display.height()-1, SSD1306_WHITE);
    display.display(); // Update screen with each newly-drawn line
    delay(1);
  }
  for(i=0; i<display.height(); i+=4) {
    display.drawLine(0, 0, display.width()-1, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=0; i<display.width(); i+=4) {
    display.drawLine(0, display.height()-1, i, 0, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=display.height()-1; i>=0; i-=4) {
    display.drawLine(0, display.height()-1, display.width()-1, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=display.width()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, i, 0, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=display.height()-1; i>=0; i-=4) {
    display.drawLine(display.width()-1, display.height()-1, 0, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  delay(250);

  display.clearDisplay();

  for(i=0; i<display.height(); i+=4) {
    display.drawLine(display.width()-1, 0, 0, i, SSD1306_WHITE);
    display.display();
    delay(1);
  }
  for(i=0; i<display.width(); i+=4) {
    display.drawLine(display.width()-1, 0, i, display.height()-1, SSD1306_WHITE);
    display.display();
    delay(1);
  }

  delay(2000); // Pause for 2 seconds
}

void testdrawrect(void) {
  display.clearDisplay();

  for(int16_t i=0; i<display.height()/2; i+=2) {
    display.drawRect(i, i, display.width()-2*i, display.height()-2*i, SSD1306_WHITE);
    display.display(); // Update screen with each newly-drawn rectangle
    delay(1);
  }

  delay(2000);
}

The scanner (?) finds the display at address 3C but you configure the lib for address 3D. Also the Adafruit code is not specified for a 168. That could be a problem.  I also would not expect to find the device at 0x3C if the jumper is set to 0x78, What did I miss? And where do you use the mizzterious  OLED I2C library? I don't seen an include. You mentioned "both examples" but showed only one. Perhaps I do not know enough to understand your question (or at least the facts) but I'm complete confused. ;-)

Yeah i only showed the adafruit one because i felt it was enough to show where my error was. I didn't use that library in my adafruit code, I tried using its example separately. From online tutorials apparently if the display is at 0x78 it shows up at 0x3C. can you show me where i set it to 0x3D? much appreciated

@Xilog Yeah it's probably an adressing problem, the Oled display you are using , the SSD1306 has an IIC interface, and IIC interfaces have around 127 adrsses as much as I know, the possible two address for such a display are 0x3C and 0x3D, but since it showed in the I2c scanner that it's at 0x3C you should declare that in the 19th line in the code you provide instead of 0x3D change it to 0x3C.

We know the address is 3C, so why want you to change it to 3D? You just can access it at the already configured address like @ShamsEl-Deen  proposed. Another thought: Are you sure the 0x3C is your OLEAD display? Perhaps you have another I2C device with address 0x3C connected the "scanner"'s I2C bus and your OLED at 0x78 is invisible, for some reason.

Thanks, I found it on line 19 and changed it but it didn't fix anything. I am sure that the display is 0x3C. When i disconnect it the scanner says no devices found.

I tried researching a while after asking this question. Turns out changing OLED_RESET to -1 fixed it.

I have some experience with the the screen you are using and I hope these tips can solve your problem.

Changing the Address in the code

The OLED display you are using uses what is called I2c or IIC protocol which is the abbreviation of "Inter Intergrated Circuit", here is it's Wikipedia page to read about it.
The IIC communication has 7 bit address space, that means there is 127 distinctive address for example 0x3C,0x3D,0x38 etc....
Your display might have either the address 0x3C or 0x3D so you might try changing theses values until anything would show up.

Unhooking any other IIC device

Although you can hook many IIC devices but as was said in the comments it's better to unhook everything except it, to troubleshoot.

Correct voltage ?

You might know that some displays uses 3.3v or some uses 5v, but as it showed in the IIC scanner, I don't think  that is the problem in your case but you should consider it.

Try using other sketches

Well, I think that 99% of the problem lays in your code (sometimes happens to me), so I suggest using other library examples or completely other libraries, or if you would like to take the challenge open the datasheet for the ssd1306 and make your own library and codes.
I hope these tips will help you or any other viewer.
As a side note I am a student, so I completely will appreciate anybody editing the answer to make better or more clear.

this is not an answer nor a solution.

Thanks so much i'll try your tips. Much appreciated

The confusion about I2C address really comes from whether it's treated as a byte or 7-bit (MSB).
For example, on the OLED PCB, it's stated address I2C =  0x78, which is 0b_0111_1000 (I2C address write).
In the Adafruit Arduino SSD1306 library, it uses 7-bit I2C address, that 0x78 becomes 011_1100 (taking the 7-bit MSB) = 0x3C

I copied your code and load to my display. It doesn't show anything. Here is the code that I had run successfully.
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);

void setup() {

  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32

  display.display();
  delay(2000);

  display.clearDisplay();      //this line to clear previous logo
  display.setTextColor(WHITE); //without this no display
  display.print("Hello World!");//your TEXT here
  display.display();            //to shows or update your TEXT
}

void loop() {

 }

Good Luck,
Aung Myo Oo

Thanks, however I fixed it with something else. Check my answer if you need details


text:
How to control segments with SevSeg library
The SevSeg library by Dean Reading seems to have a keyword to control individual segments on SSD's. I am using four common cathode, single digit displays. Does anyone know how to program individual segments?
#include "SevSeg.h";

SevSeg sevseg;

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

  byte numDigits = 4;
  byte digitPins[] = {2, 3, 4, 5};
  byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12, 13};
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_CATHODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false; // Use 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]

  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins,
    resistorsOnSegments,
    updateWithDelays, leadingZeros, disableDecPoint);

}

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

  sevseg.setSegments();
  //sevseg.setNumber(1234,0);
  //sevseg.setChars("");
  //sevseg.blank();
  sevseg.refreshDisplay();

}

why did you not put a parameter into the setSegments() function call?

Because i don't yet know what parameter to put, or how to use the function.

tried that. displays a bunch of gibberish.

It is always the same if you just enter 1, or 2, or 25 etc.. I don't think that's how the function works. Displaying numbers with the setNumber function works perfectly however, so my displays are wired correctly.

what is unclear here https://github.com/DeanIsMe/SevSeg/blob/9cdc6d03d820ffbc18174921fb7bd0a3d030fd8b/SevSeg.cpp#L435

You can't with that library. The author has not provided any public methods that will do the job.
There are private methods (segmentOn and segmentOff) that might be usable, but you would have to modify the library to be able to access them.

Are 4 and 2 just arbitrary numbers you chose?

Yes. They are the segment number you want to turn on or off.

How would you specify which digit?

Probably with different numbers. Experiment and find out.

Last question.. Where should those functions be placed within the code? I'm getting "private within this context".

Actually, that looks like that might be the case. I have never used this library, so I was just reading the source code. It looks like the actual answer might be "You can't with that library". Damn.

The simple answer is probably to use a different library.

I wonder why he included the setSegment() function then. And yeah using a different library doesn't seem like a bad idea either.

He probably uses it internally.


text:
Is there an alternative to strtok_r in extracting words from char?
The task, in char, I get some data that I have to parse into parts.
In this case, I use strtok_r, which finds identifiers like

"=", " ", "&"

Code:
char payload[70] = "GET /wifi?ssid=MyWiFi&pass=123456789 HTTP 11";
char *p;
char *i;

void setup() {
  Serial.begin(15200);
  Serial.println("Load");

  p = strtok_r(payload, "=", &i);
  // Get SSID
  p = strtok_r(NULL, "&", &i);
  Serial.println(p);

  p = strtok_r(NULL, "=", &i);
  // Get PASS
  p = strtok_r(NULL, " ", &i);
  Serial.println(p);
}

void loop() {}

Result:

Load MyWiFi 123456789

This works, but as soon as I add the characters strtok_r works on to the ssid = or pass = value, it stops working, outputting the cropped data.
These characters can be in the name of any WiFi network or the generated password.
Tell me, are there strtok_r analogues, where instead of a single character I can insert a whole phrase?
For example, so that he finds the beginning of ssid by the tag "ssid=", and finishes before "pass=".
Resolved.
Thank you all for your help!
I studied both options from @Majenko and @user7761803. All of them came in handy in various parts of the code.
Perhaps someone will use the Regexp library to parse such data. Here is example:
    #include <Regexp.h>

    char payload[60] = "ssid=MyWifi&pass=ukLPm&I*uwlm HTTP";
    char ssid[25], pass[25];

    void setup() {
      ms.Target(payload);
      char match_result = ms.Match("ssid=(.*)&pass=(.*) H", 0);
      if(match_result == 1) {
       // Get SSID
       ssid = ms.GetCapture(regexp_var.buffer, 0);
       // Get PASS
       pass = ms.GetCapture(regexp_var.buffer, 1);
      }
    }

    void loop() {}

If you're running on an ESP the https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer library has an arg() parser for HTTP GET request strings.

@Dougie, Thank you!

The function you are looking for is strstr(), which takes two strings, and returns a pointer to where the second string appears in the first (or NULL if it doesn't appear).
You could use it something like this:
void setup() {

    Serial.begin(15200);
    Serial.println("Load");

    char *p = strstr(payload, "ssid=");
    char *q = strstr(payload, "pass=");
    char *r = strstr(payload, " HTTP");

    char *ssid = NULL;
    char *pass = NULL;

    if (p == NULL || q == NULL || r == NULL) {
        // One or other (or both) missing - what to do?
    } else {
        *r = '\0';  // Terminate the last string

        // If this really is an HTTP query string, we don't know
        // if ssid or pass will be first
        if (p < q) {    // Terminate the first string
            *(q - 1) = '\0';
        } else {
            *(p - 1) = '\0';
        }

        ssid = p + 5;
        pass = q + 5;

        Serial.println(ssid);
        Serial.println(pass);
    }
}

Note, however, that your payload string looks like an HTTP query string.
These are defined so that they are split at the & characters, and if a & needs to appear in one of the values, it should be percent encoded (where the & would appear as %26, and would need to be decoded afterwards).
However, that wasn't your question...

Thank you for the help!

The normal way of parsing such complex strings in any language is to use Regular Expressions.
Normally these are pretty heavy-weight to use, but thankfully Nick Gammon has written an Arduino implementation of regexp.

Thanks for the help! I figured out this library.


text:
Arduino Obstacle Avoiding Shield controlor motor L293D
I am a beginner with Arduino. I wanted to make an Arduino obstacle avoiding. So I ordered last week an L293D Shield Motor Driver and I don't know if what I receive is a good item. The first picture is how it looks on the site and the second picture is what I got.

I saw that if you search for this motor you get results for both motors, but they are not the same. And I saw in this tutorial, this person using a motor like mine https://www.youtube.com/watch?v=ydDvoknlJ9M and then he switched to the motor in the first picture.
Questions: Are these motors the same? Should I request a return? If they are the same, how can I add the pins (as shown in the third picture?

Again, I am a beginner and I would appreciate if someone can help me.

Looks exactly the same, except for that some pin headers are missing. You could buy and solder them yourself.

Thank you so much ! I find this pins from a old kit that I commanded , but they didn't mentioned that it comes without and in the image pins appear .

do you actually need those pins?

Yes , I want to make a obstacle avoiding robot and I saw that more people use them

To complete @chrisl answer: Yes you need these pins to make the same robot as in the video. You can order them online and solder them (if you know how to solder and if you have the soldering material). Be careful with soldering ;)
For your information, the pins you circled in red are used to communicate with the Arduino pins A0 to A5, and provide +5V and GND. In the video, they are connected to the ultrasound sensor.
And please clarify what is your motor??? Do you mean the Shield motor driver? It is not the same. A shield is an eletronic board that you plug to your Arduino to do a specific task (control a motor, connect to wifi...). A motor driver is the electronic to control the motor. On your pictures, they are mainly the 3 components with 16 legs each.

Thanks ! It's a shield motor driver

@AnaNiorba - if this worked for you then you should tick it to indicate that it was the correct answer.


text:
Using ESP32 to measure vbat
I'm using ESP32 to read an analog value of a liPo battery (3.7v-4.2v).
Since ESP32 DAC's is 3.3v I'm using a voltage divider ( 2x10K resistors ), to split bat's voltage into ESP's GPIO36. So far nothing new or not well documented on the web.
Using the voltage divider, splits the 4.0v into 1.97v (measured using a volt-meter). Battery's negative pole is connected to ESP's Gnd to get a common ground. GPIO36 is connected to the 1.97v line ( and this value is tested using a volt-meter also on ESP's pin to make sure ).
I was expecting to get a digital value of 1.97 (2444 )
BUT NO!,
when using analogRead(36) I'm getting a digital value of 2180 which correlates to 2180/4095*3.3 = 1.75v.
1) I tried to make a 100 samples over time - to make sure it is not a power up issue. No change.
2) I tried to read its value during loop() and not setup(). No change.
Is DAC's resolution is that poor ( roughly 12% off ), or am I doing something wrong ?

Did you measure the actual supply voltage of the ESP32? It's not necessarily exactly 3.3V. Also, the ADC in the ESP32 can be off by + or - 6%, IIRC, and it isn't linear either; it needs calibrating before using.

@ocrdu - Yes, it measures 3.29v on ESP (close enough ). Do you think 12% is a calibrations error ? seems to me a bit too much ( 5% sounds reasonable ).

try connecting the GPIO pin to the supply voltage of the ESP32 (3.3V) through a resistor and see if it becomes the maximum value. Maybe there is some flux left on the pin or something that affects it's response to voltage.

@Coder_fox - Did already connect directly 3.3v pin directly to 36 pin (not using a resistor though ), and got 4095 as expected.

it looks like it should be about 2200 to hit 1.97v: https://i2.wp.com/randomnerdtutorials.com/wp-content/uploads/2018/08/ADC-non-linear-768x474.png?resize=768%2C474&ssl=1  The absolute accuracy actually doesn't much matter, you just have to figure out what your MCU spits out. feed the ADC 1.00v and 2.50v, take the readings, then calc the code/volt slope. you can then read any battery voltages quite accurately between 2 and 5 volts: it's pretty linear in the middle range like that.


text:
How to quit flash mode on HM-10?
I have an HM-10 BLE module connected to Arduino Leonardo. It forwards UART from my computer:
#define btSerial Serial1

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

    while (!Serial) {
        delay(50);
    }

    Serial.println("Initialized on 9600");

    btSerial.begin(9600);
    while (!btSerial) {
        delay(50);
    }

    Serial.println("BT initialized on 9600");
}

void loop() {
    if (btSerial.available()) {
        Serial.write(btSerial.read());
    }

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

In general, it works fine, but I've decided to flash it and sent AT+SBLUP command to it, and it's in flash mode now.
Later I've realized that I can't flash it because Parallels Desktop's COM forwarding does not work fine (I work on macOS).
And now I can't quit from the flash mode — it just does not respond to AT commands (however, btSerial is alive).
I've tried to reset the Arduino, disconnect BT for several minutes — it's still in flash mode. How to quit this mode?

you must flash some firmware

If you disconnected power from the HM-01 and it's still in flash mode the next time you power it, I would guess, that entering flash mode erases the firmware. Thus you would have to burn a new firmware to it. But thats just a guess


text:
Why is this RISING interrupt repeatedly triggering?
I've set up an ISR to trigger on the RISING edge of pin #2, but I find that if pin 2 is held high, the ISR triggers repeatedly.
Here's a trace of the voltage measured right at the pin:

I can see a little bit of noise, but it shouldn't be enough to trigger multiple pulses. I've tried both INPUT and INPUT_PULLUP modes for the pin; behavior is the same.
constexpr byte kClockPin = 2;
constexpr byte kReadWritePin = 3;
constexpr byte kLedPin = 13;
constexpr int kNumAddressPins = 16;
constexpr byte kAddressPins[] = {/* MSB */52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 30, 28, 26, 24, 22};
constexpr int kNumDataPins = 8;
constexpr byte kDataPins[] = {/* MSB */45, 43, 41, 39, 37, 35, 33, 31};

volatile bool dirty = false;
volatile uint8_t data = 0;
volatile uint16_t address = 0;
volatile bool read = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(kClockPin, INPUT_PULLUP);
  pinMode(kReadWritePin, INPUT);
  for (byte pin : kAddressPins) {
    pinMode(pin, INPUT);
  }
  for (byte pin : kDataPins) {
    pinMode(pin, INPUT);
  }
  pinMode(kLedPin, OUTPUT);
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(kClockPin), OnClock, RISING);
}

void loop() {
  // digitalWrite(kLedPin, digitalRead(kClockPin));
  if (!dirty) return;
  char output[15];
  sprintf(output, "%04x %c %02x", address, read ? 'r' : 'w', data);
  Serial.println(output);
  dirty = false;
  // digitalWrite(kLedPin, digitalRead(kClockPin));
}

void OnClock() {
  read = digitalRead(kReadWritePin);
  data = 0;
  for (byte pin : kDataPins) {
    data = (data << 1) + (digitalRead(pin) ? 1 : 0);
  }
  address = 0;
  for (byte pin : kAddressPins) {
    address = (address << 1) + (digitalRead(pin) ? 1 : 0);
  }
  dirty = true;
}

Turns out the short answer is that I'm still not great at using an oscilloscope.
Longer version is that the noise was very visible at smaller time scales. A filter capacitor had come disconnected from the breadboard in a way that was hard to see, and that was causing a whole bunch of noise. Replacing it fixed the problem.


text:
How to get char array's length
I use a LCD display to display a not known size of text ( changes over time ). I wish to display it at the center of LCD ( 2X16 ).
I declare:

  char t[16];
  char h[16];
  sprintf(t, "%.1f%cC %.0f%%", temperature,223, humidity);

Now, since I want to add additional data on a specific line and center it, I need to know it size. When using:
sizeof(t)/(sizeof(t[0])

I get 16 which is the size determined and not its actual size.
How can I get the exact number of chars used?

The function I think you are looking for is strlen - STRing LENgth.
It counts the number of characters in a string up until it finds the "NULL" end of string marker.
Serial.println(strlen(t));

well my guess was it refers to String only

strlen is for C strings (NULL-terminated character arrays).  For String you want String.length().

@Guy.D the code you posted is using char arrays, not String objects. Majenko's answer is what you need, not String.length(). Note that you need to be careful not to overflow your char array. That will cause undefined behavior (read "bugs.")


text:
Parallel communication between multiple Arduino
Here's a post which explained the communication standard.
I need to establish communication between multiple Arduino nano board. I have used SPI bus on one of the Arduino board for wireless communication and I2C bus for another device. It appeared that both I2C bus and SPI bus support multiple device. However, since I have used both I2C and SPI for different purpose, establish parallel communication with RX TX pins seemed to be the preferable choice.
Question 1:
This post provided a nice set up for I2C bus as master and slave. However, can one adjust the code in step 2 of master device with
 Wire.begin(n);

and change all the Arduino boards as master&slave devices, thus achieve parallel communication?
Question 2: I read this post where people mentioned RS 485. However, can one achieve parallel communication with RX and TX pin like the one used in Question 1, without using RS 485?

please explain what you mean by parallel communication

@jsotola like 10 arduino nano board get together and send data to each other, the topology of the network is fully connected.

google arduino cluster and arduino node network

@jsotola That's too big. The whole point is to use the on board technology, with expanse the energy and mass of the project would be too much.

I think the term you need is "multi-drop bus", not "parallel". Parallel communication refers specifically to a completely different interfacing standard.

parallel communication is possible using arduino you need to use the ports for example port A and then a rx tx pins.
#include <Wire.h>
#include <Arduino.h>

byte i = 0;
int intpin = 44;
int rcv_ready = 45;

void setup() {
  DDRA = B11111111; // Output
  DDRC = B11111111; // Output
  pinMode(intpin, OUTPUT);
  pinMode(rcv_ready, INPUT);
}

void loop() {
  transmit();
}

void transmit() {
  PORTA = i++
  PORTC = i;
  digitalWrite(intpin, HIGH);
  while (rcv_ready == LOW) {}
  digitalWrite(intpin, LOW);

  delay(299);
}

Here we set up the two ports DDRA and DDRC to be output ports by using the   mask B11111111; We set the interrupt pin to port 44 and set it is an output and we set the receive pin to be 45 and an input.
Then we call transmit in the loop. Where we then set port A and port C to equal i++ and i respectively. And then toggle the signal to say we have transmitted a new message. This will get picked up by the Slave-input.
Slave input
#include <Arduino.h>

byte x = 0;
byte y = 0;
int rcv_ready = 45;

void setup() {
  DDRA = B00000000; // Input
  DDRC = B00000000; // Input
  Serial.begin(19200);
  attachInterrupt(5, blink, RISING);
  pinMode(rcv_ready, OUTPUT);
  digitalWrite(rcv_ready, LOW);
}

void loop() {}

void blink() {
  x = PINA;
  y = PINC;
  delay(100);
  digitalWrite(rcv_ready, HIGH);
  delay(100);
  digitalWrite(rcv_ready, LOW);
  Serial.print(x);
  Serial.print(" , ");
  Serial.println(y);
}

Here we set up the two ports DDRA and DDRC to be input ports by using the   mask B00000000;
We then set the baud rate as 19200 which matches the rate set by the master
Here we set the interrupt to be 5 which is pin 18 and tell it to call blink on an interrupt.
We then read the values from PORTA and PORTC and then we output it to the serial monitor screen. We also send back the acknowledgement of receipt to the master using pin 45

Please post your code in text format.


text:
Topic: How to draw a circle on LCD128x64?
I want to know what's the default or recommended arithmetic to draw a circle on the LCD128x64 using ST7920 driver.
I've done the following functions:

drawing a pixel at any point on the LCD
sending an image
drawing a vertical, diagonal and horizontal lines
send CGRAM chars

But I can't draw a circle.
Here's my code:
/*  Project name:       lcd128x64
    Author:             r1s8k
    Date:               22/12/2019, 12:25 AM

    Project specs:      This is the source file of the lcd128x64 driver that uses
                        MCP23017 as the lcd driver using SPI interface

*/

#include <avr/io.h>
#include <Arduino.h>
#include <SPI.h>
#include <avr/pgmspace.h>
#include <math.h>
#include "lcd128x64_spi.h"

////////////////////////////////////////////////////////////////////////////////////////////
// global variables
static uint8_t graphics, horizontal,y_pre,p_dr_act,block_pre;
//static uint16_t p_buf;
static uint16_t p_pre;
uint8_t p_hi,p_lo,p_block,p_pos,p_bit;

////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// control functions

// init
void lcd128x64_init(void){
    pinMode(CS_PIN, OUTPUT);
    pinMode(CLK_PIN, OUTPUT);
    pinMode(MOSI_PIN, OUTPUT);
    digitalWrite(CS_PIN, LOW);                          // disable CS_PIN
    SPI.begin();
    _delay_ms(100);                                     // trying initial delay
    digitalWrite(CS_PIN, HIGH);                         // enable CS_PIN

    _delay_ms(50);                                      // datasheet says > 40ms
    lcd128x64_cmd(FUNCTION_SET_BASIC);  //_delay_us(28);// datasheet says > 100us - 72 = 28us
    lcd128x64_cmd(FUNCTION_SET_BASIC);  //_delay_us(28);// important for going to / coming back from graph mode
    lcd128x64_cmd(DISABLE_V_SCROLL);                    // if you have extended list to scroll
    lcd128x64_cmd(DISPLAY_CONTROL);     //_delay_us(28);// display = 1, cursor = 0, blink = 0
    lcd128x64_cmd(ENTERY_MODE);                         // cursor = right, display shift = 0

    lcd128x64_cmd(DISPLAY_CLEAR);
    lcd128x64_cmd(RETURN_HOME);
    graphics = 0;
    horizontal = 0;
}
// command tx
void lcd128x64_cmd(uint8_t cmd){
    SPI.transfer(CMD_MSK);
    SPI.transfer(cmd & 0xf0);
    SPI.transfer(cmd << 4);
    if(cmd == 0x01)_delay_us(1600); else _delay_us(72);
}
// data tx
void lcd128x64_data(uint8_t data){
    SPI.transfer(DATA_MSK);
    SPI.transfer(data & 0xf0);
    SPI.transfer(data << 4);_delay_us(72);
}
// move cursor
void lcd128x64_move_cursor(uint8_t row, uint8_t col){
    if      (row == 1)lcd128x64_cmd(0x80 + (col - 1));
    else if (row == 2)lcd128x64_cmd(0x90 + (col - 1));
    else if (row == 3)lcd128x64_cmd(0x88 + (col - 1));
    else if (row == 4)lcd128x64_cmd(0x98 + (col - 1));
}
// clear lcd
void lcd128x64_clr(void){
    uint8_t y,x;
    lcd128x64_graphics_set_mode(1);
    for(y=0;y<32;y++){
        for(x=0;x<8;x++){
            lcd128x64_cmd(0x80+y);lcd128x64_cmd(0x80+x);
            lcd128x64_data(0x00);lcd128x64_data(0x00);
        }
    }
    for(y=32;y<64;y++){
        for(x=0;x<8;x++){
            lcd128x64_cmd(0x80+y-32);lcd128x64_cmd(0x88+x);
            lcd128x64_data(0x00);lcd128x64_data(0x00);
        }
    }
}
// graphics mode
void lcd128x64_graphics_set_mode(uint8_t mode){
    lcd128x64_cmd(FUNCTION_SET_EXTENDED);
    if(mode){
        lcd128x64_cmd(GRAPHICS_ON1);
        lcd128x64_cmd(GRAPHICS_ON2);
        graphics = GRAPH;
    }
    else{
        lcd128x64_cmd(GRAPHICS_OFF1);
        lcd128x64_cmd(GRAPHICS_OFF2);
        graphics = TEXT;
    }
}
// write chars
void lcd128x64_write_chars(uint8_t row, uint8_t col, uint8_t *str, uint8_t w){
// row1: 80H~8FH // row2: 90H~9FH // row3: 88H~AFH // row4: 98H~BFH
    if(graphics){lcd128x64_graphics_set_mode(0);}

    if      (row == 1)lcd128x64_cmd(0x80 + (col - 1));
    else if (row == 2)lcd128x64_cmd(0x90 + (col - 1));
    else if (row == 3)lcd128x64_cmd(0x88 + (col - 1));
    else if (row == 4)lcd128x64_cmd(0x98 + (col - 1));

    uint8_t i;
    for(i=0; i<w; i++){lcd128x64_data(str[i]);}
}

////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////
// draw functions

// pixel set
void lcd128x64_pixel_set(uint8_t y_axis, uint8_t x_axis){
    uint16_t p_buf;
    if(!graphics){lcd128x64_graphics_set_mode(1);}

    p_block = x_axis / 16;              // calculate x_axis block
    x_axis ^= 127;
    p_pos = (x_axis % 16);              // calculate the position of pixel in 16-bit
    p_buf = (1 << p_pos);               // set the bit

    if(!p_dr_act){
        p_dr_act = 1;                   // set pixel draw activate flag
        y_pre = y_axis;                 // copy y_axis current position
        block_pre = p_block;            // store the first block
    }

    if(block_pre != p_block){           // if block changed
        p_pre = 0;                      // clear global pixel buffer
        block_pre = p_block;            // store new block,
    }                                   // to disable triggering this check

    if(y_axis == y_pre){
        p_pre |= p_buf;                 // put current pixel in global buffer
        p_buf |= p_pre;                 // put previous pixels in local buffer
    }
    else{                               // when changing the row,
        y_pre = y_axis;                 // copy new row position
        p_pre = 0;                      // clear global buffer
        p_pre = p_buf;                  // store the last pixel position
    }

    if(y_axis<32){
        lcd128x64_cmd(0x80+y_axis);
        lcd128x64_cmd(0x80+p_block);
        lcd128x64_data(p_buf>>8);
        lcd128x64_data(p_buf);
    }
    else{
        lcd128x64_cmd((0x80+y_axis)-32);
        lcd128x64_cmd(0x88+p_block);
        lcd128x64_data(p_buf>>8);
        lcd128x64_data(p_buf);
    }
}
// pixel clear
void lcd128x64_pixel_clear(uint8_t y_axis, uint8_t x_axis){
    uint16_t p_msk;
    if(!graphics){lcd128x64_graphics_set_mode(1);}
    p_block = x_axis / 16;
    x_axis ^= 127;
    p_pos = (x_axis % 16);
    p_msk &= ~(1 << p_pos);

    if(y_axis<32){
        lcd128x64_cmd(0x80+y_axis);
        lcd128x64_cmd(0x80+p_block);
        lcd128x64_data(p_msk>>8);
        lcd128x64_data(p_msk);
    }
    else{
        lcd128x64_cmd((0x80+y_axis)-32);
        lcd128x64_cmd(0x88+p_block);
        lcd128x64_data(p_msk>>8);
        lcd128x64_data(p_msk);
    }
}
// draw image
void lcd128x64_img(unsigned char *img){
    uint8_t y,x;
    if(!graphics){lcd128x64_graphics_set_mode(1);}

    for(y=0;y<32;y++){
        for(x=0;x<8;x++){
            lcd128x64_cmd(0x80+y);
            lcd128x64_cmd(0x80+x);
            lcd128x64_data(pgm_read_byte_near(&img[(y*16)+(x*2)]));
            lcd128x64_data(pgm_read_byte_near(&img[(y*16)+((x*2)+1)]));
        }
    }
    for(y=32;y<64;y++){
        for(x=0;x<8;x++){
            lcd128x64_cmd((0x80+y)-32);
            lcd128x64_cmd(0x88+x);
            lcd128x64_data(pgm_read_byte_near(&img[(y*16)+(x*2)]));
            lcd128x64_data(pgm_read_byte_near(&img[(y*16)+((x*2)+1)]));
        }
    }
}

// draw line
void lcd128x64_line(uint8_t y0, uint8_t y1, uint8_t x0, uint8_t x1){
    uint8_t ih,iw,j,h,w,div;
    h = y1 - y0;
    w = x1 - x0;
    if(w>h){
        div = w/h;
        for(ih=y0,iw=x0;iw<x1;iw++){
            lcd128x64_pixel_set(ih,iw);
            if((iw%div)==(div-1)){ih++;}
        }
    }
    else{
        div = h/w;
        for(ih=y0,iw=x0;ih<y1;ih++){
            lcd128x64_pixel_set(ih,iw);
            if((ih%div)==(div-1)){iw++;}
        }
    }
}

// draw circle
void lcd128x64_circle(uint8_t y, uint8_t x, uint8_t r){
    uint8_t py,px,d,f;
    if(y>x){
        //d = y/x;
        f=1;
        for(px=x,py=y-r;px<x+r;px++){
            lcd128x64_pixel_set(py,px);
            if(((px%f))==(r%f)){py++;f++;}
            //if((py%(d%f))==1){px++;f++;}
        }
    }
    else{
        d = x/y;
        for(py=y-r,px=x;px<x+r;px++){
            lcd128x64_pixel_set(py,px);
            if(((px%d))==(d-1)){py++;}
        }
    }
}

This is the function I use in DisplayCore. Feel free to use it.

Considering you already can put a pixel at any position of the display you can try and use something like described here: http://www.softwareandfinance.com/Turbo_C/DrawCircle.html

Yep! Absolutely worked like a charm. But it's a bit slow and uses a relatively big memory .. these lines used 1.7kb of program memory! `double i, angle, x1, y1;
for(i = 0; i < 360; i += 0.1){
angle = i;
x1 = r * cos(angle * PI / 180);
y1 = r * sin(angle * PI / 180);
lcd128x64_pixel_set(x + x1, y + y1);
}`

This is what I got https://i.ibb.co/r4z4pxM/20200120-002911.jpg

@Majenko, that is a nice and efficient algorithm! By comparison the Turbo C example, to be honest, is a waste of processing power. It's not optimized at all (for example, by using symmetry) and uses expensive floating point functions.

@StarCat Yes I know it's a waste of memory! I think it's not for microcontroller stuff. I'm still working on finding the function that would work perfectly with the most optimized memory usage.


text:
Weather API Arduino
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {my mac };
char serverName[] = "api.weather.gov";

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

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

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  int ret = client.connect(serverName,443);
  if (ret==1) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /stations/KGSO/observations/latest");
    client.println("accept: application/geo+json,*/*");
    client.println("user-agent: arduino, mymail@asdf.com");
    client.println("host: api.weather.gov");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
    Serial.println(ret);
    Serial.println(client.status());
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:

  if (client.available()) {
    Serial.print("\ngotsome\n");
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}

When I run this I get:
connecting...
connected
disconnecting.
Why don't I get data? I thought it was about the header info. But I looked at https://www.weather.gov/documentation/services-web-api#/ and it doesn't say it needs much.

what happens if you remove the last if block?

connecting...
connected

Yes I think Juraj has the answer (thanks): Can't get there from here. Maybe that's an excuse to get a raspberry pi.

The Ethernet library doesn't support secure connection (so called SSL, but TLS now). To connect to a secure HTTP transport HTTPS the secure connection is necessary. The AVR MCU don't have the computing power to compute the security keys. And for less popular 32bit MCU nobody created a 'SSL' implementation for Ethernet library yet.
esp8266, esp32, MKR1010, Uno WiFi, Nano 33 IoT can do HTTPS, but all only over WiFi as far as I know.


text:
Get image from Fingerprint module
I want to get the image from the fingerprint module (https://makeradvisor.com/tools/fingerprint-sensor-module/) as a result of scanning. It is enough to have a single frame image. it would be good if the computer can get image the output image from the serial port (as in linescan camera example: https://www.youtube.com/watch?v=welv4w8B88g https://www.tindie.com/products/ap_tech/tsl1401cl-linescan-camera/)
I am open to your suggestions if it can be done in another module.

Since all of these cheap fingerprint readers are similar you can find a compatible datasheet and just find the commands and descriptions there. However, I couldn't find a datasheet that would include a good description of the protocol. So the other option is to look at the protocot through the software SFGDemo which is apparently capable of getting an image of a fingerprint. Or to use this python package which apparently also can download the image.


text:
How many PIR Motion Sensors can I connect to my Arduino-Uno R3?
I am doing a school project where I intend to measure the cafeteria line with motion sensors and the send that information with a WiFi module to a server. This is my first time using Arduino and I am not sure how many motion sensors does it support.

for both simple and good, use one per GPIO you have that supports interrupts. for simple and not as good, use one per GPIO. you can eventually add more with port expanders, charlie plexing, even shift registers.

Most PIR sensors provide a simple relay output. That means they are nothing more than a switch as far as the Arduino is concerned.
You can connect hundreds of switches to an Arduino. With judicious use of diodes and a matrix arrangement you can hundreds with not many IO pins.  For example an 8x8 matrix of switches gives you 64 PIR sensors with just 16 IO pins.  For n pins you can have (n/2)² switches with a balanced (n/2 by n/2) matrix.


text:
GSM+GPS modules
Say, I need to track a vehicle using Arduino and a (GPS+GSM) module.  Though GPS can be used to get Location of the Vehicle(and then sent using GSM), why would we even do it using GPS if we already have a GSM module. Can't GSM do both these tasks(getting location and sending it) . What's the use of using an extra module there?
I am new to network stuff, help me!

Only a few GSM modules also include a GPS module. Without that all you could possibly get is the cell ID, which is pretty pointless.

Did you mean that GSM technology alone cannot find out its location?

That is correct. GSM can only get you the cell ID (rough location) and signal strength (could be used to approximate distance from tower?) It certainly can't get you a lat/long. Only a "You're in the south west of Fort Worth"...

Well thanks! That answers my question!

The GSM module can estimate it's location based on cell tower triangulation but if you want a more accurate location then you need to use a GPS.