text:
Need help figuring out how to organise a system to run a stepper motor at low speed without Steps-skipping
TL;DR : How to prevent step-skipping with a NEMA gearbox motor at low speed.
I am in the process of creating a system in which I want an object to turn on a plate and to show a letter depending on the angle of the rotation. The object is quite heavy hence the rotation should be quite slow, this is why I took a Planetary Gearbox NEMA Stepper.
My system consists in:

An Arduino Uno
A NEMA Stepper Motor
A A4988 Driver
Some wires
2 Iron plates
A ball bearing element in between the Iron plates
Screws to fit everything together.

This is the code I ended up with:
// Define stepper motor connections and steps per revolution:
#define dirPin 6
#define stepPin 7
#define stepsPerRevolution 5373
int degree_init = 1;

int mouvement=0;

// create a mapping between letters and degrees
int letterToDegree[33] ;
int degree;
// function to map letters to degrees
int mapLetterToDegree(char letter) {
  if (letter=='.'){
    return letterToDegree[27];
  }
  else if (letter==':'){
    return letterToDegree[28];
  }
  else if (letter=="\'"){
    return letterToDegree[29];
  }
  else if (letter==' '){
    return letterToDegree[30];
  }
  else {
  int letterIndex = letter - 'A'; // get the index of the letter in the alphabet
  return letterToDegree[letterIndex]; // return the degree associated with that letter
  }
}

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
    Serial.begin(9600);
    for (int i = 0; i < 33; i++){
    letterToDegree[i]= degree_init;
    degree_init=degree_init+10;
  }
}

void loop() {
  int p= NULL;
  // Set the spinning direction clockwise:
  digitalWrite(dirPin, HIGH);
  String input= "NOW THE NOW THE AAAAA";
  // loop through the letters
  for (int i = 0; i < input.length(); i++) {
    // get the degree for each letter
    degree = mapLetterToDegree(input[i]);
    Serial.print("Letter: ");
    Serial.print(input[i]);
    Serial.print(" Degrees: ");
    Serial.println(degree);
    // wait for the movement to complete
    delay(1000);

  int p_new= map(degree,0,360,0,5373);
  Serial.print(" position: ");
  Serial.println(p_new);
  if (p!=NULL){
    mouvement=p_new-p;
    p=p_new;
  Serial.print(" mouvement: ");
  Serial.println(mouvement);
  }
  else{
    p = p_new;
  }
  if (mouvement<0){
    digitalWrite(dirPin, LOW);
    mouvement=abs(mouvement);
    Serial.println("change de direction");
  }
  Serial.print(" stepper: ");
  Serial.println(mouvement);

  // Spin the stepper motor 1 revolution slowly:
  for (int i = 0; i < mouvement; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delay(20);
    digitalWrite(stepPin, LOW);
    delay(20);
  }

  delay(1000);
  digitalWrite(dirPin, HIGH);
}
}

I tried following this tutorial and it works in broad terms but sometimes the motor skips steps, especially when changing direction.
I can't seem to understand how torque works within this system and how to minimise the stress I put on the motor.
My hypothesis is that since the system is at equilibrium and the friction is minimised due to the ball bearing, there should be no need for a lot of power from the motor, and that this motor should suffice.
My hypothesis of why steps are skipped:

Too high a speed for the motor
Not enough torque power supplied
Not good enough electricity supply to the motor.

I am not sure how to go about and test these hypothesis and if those are correct.
I am also having a lot of trouble understanding the relationship between the time delay in the code and the movement of the motor.
Especially this bit:
  for (int i = 0; i < mouvement; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delay(20);
    digitalWrite(stepPin, LOW);
    delay(20);
  }

Is it ok to change them as I did? do they need to be symetrical (same delay for high and low)?
I am also looking for an explanation of how to apply acceleration and decceleration algorithms for stepper motor, even though I am not sure it makes sense at this speed.
My questions are:

How to calculate the best speed for such a system and how to implement it?
Is there need for acceleration/ decceleration?
Does microstepping makes sense when using a gearbox?
Are there some obvious flaws in my system/ code that I am missing out?

If the object is heavy instant start/stop/direction change can let the motor skip due to the objects inertia. Do you want to do the acceleration algorithm yourself? If not, try the AccelStepper library, which will do that for you.

you have un-necessary code in the if (p != NULL) { block ... else is not needed ... p = p_new; is always executed ... put p = p_new; after the if block

you have not said anything about the desired rotation rate

A general question: Did you consider using a limit switch (home position) and a rotary encoder (track the steps)?

@jsotola Thanks for noticing it, I changed it. The rotation rate should be really slow.

@chrisl I tried with the Accelstepper but it did not help

@RolandJ. This is the solution I am investigating at the moment, thanks for proposing it.

How to calculate the best speed for such a system and how to implement it?

There is no one best speed. This depends on your requirements, the motor torque with the supplied power and driver and the rotational inertia of the object on the motor axis. You can measure the rotational inertia and set yourself a value for the acceleration (even if you don't write the program for acceleration, it will accelerate on the first steps), that you want to have. Then you can check, if your motor has enough torque for this.
Speaking about the motor: Check the ratings of the motor. A good supplier should also give you information on how much torque your motor has at specific currents. Then check if your driver can handle the current (these small stick drivers often cannot handle much current, like 1 or 2A max). These drivers also have a small potentiometer on board, which controls the motor current. Your supplier should also provide information on how to set it correctly (by checking the voltage on one of the pins). You can even find information about this online, when you search for your type of driver. Setting this wrong can lead to either an underperforming motor or the motor overheating. So when setting the motor current with the potentiometer, check the motor temperature afterwards while it is running. Every motor has its own temperature rating, but I would suggest not letting it get too hot to touch.
Having done all above you can drive a test for checking motor speeds. Forget about your current code for a while. Just drive the motor with specific speeds, starting from only a few steps per second and going up until you notice the motor skipping. Then you know how fast you can drive the motor in your configuration without skipping and acceleration. If that is fast enough for you, you can just stick to that.

Is there need for acceleration/ decceleration?

That depends on the above. If the non-skip speed is not fast enough, you can accelerate by gradually increasing the steps per second (aka decreasing the delay between step pulses). To halt at a specific position you then need to decelerate, so you need to plan the movement and control the steps per second accordingly. If you don't want to do that yourself I would suggest using the AccelStepper library. There you can set the target speed and the maximum acceleration and the library will then handle the motor for you.
You wrote in a comment, that you tried the AccelStepper library and that it didn't help. Though you didn't state how exactly it didn't help and what exactly you tried. Maybe you just didn't use the library correctly.

Does microstepping makes sense when using a gearbox?

With microstepping you can get a smoother movement, though I doubt, that this is the problem here. Activating microstepping will of course mean, that you need to send more pulses to the driver for the same speed. Just keep that in mind.

Is it ok to change them as I did? do they need to be symetrical (same delay for high and low)?

The first delay establishes the pulse for the driver. It needs to be big enough, that the driver recognizes the pulse. 20ms is very long for that. If you look at the datasheet of the your driver chip, there should be some information on that. I used a delay of about 50us in the past (so delayMicroseconds(50)), though you might even get shorter.
The second delay then handles the time between pulses, aka the speed of the motor. Though keep in mind, that the first delay is also still a constant in that equation. The speed in steps per second would then be 1/(delay1+delay2) (ignoring the time for the execution of the rest of the code, because only relevant at high speeds).

Thanks for the detailled response, I eventually chose a bigger, close-loop motor but it helped me understand how to go about it.


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

source: Stack Exchange

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

sort: votes


text:
Esp-now reacting like bloating in Many-to-one setup
I have project which 3 esp01 controller and 1 nodemcu 12-E receiver which gives scores.
Trying to read all input freely from controllers but when i use 3 at same time or pressing button too quickly nodemcu seems to halts and doesn't react or get messages.
Is my simple if algorithm is flawed or did i hit a hardware barrier.
I used working button library for single click event in ESP-01
For fundamental setup i used tutorial.
Esp01 Sender
#include <Button2.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <espnow.h>
#define RED 2
#define BLUE 0

// REPLACE WITH RECEIVER MAC Address
//Esp8266 80:7D:3A:37:C5:66
uint8_t broadcastAddress[] = {0x80, 0x7D, 0x3A, 0x37, 0xC5, 0x66};

// Set your Board ID (ESP32 Sender #1 = BOARD_ID 1, ESP32 Sender #2 = BOARD_ID 2, etc)
#define BOARD_ID  1

// Structure example to send data
// Must match the receiver structure
typedef struct struct_message {
    int id;
    int x;
    int y;
} struct_message;

// Create a struct_message called test to store variables to be sent
struct_message myData;

  // Init ESP-NOW
Button2 buttonA, buttonB;

unsigned long lastTime = 0;
unsigned long timerDelay = 5000;

// Callback when data is sent
void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  Serial.print("\r\nLast Packet Send Status: ");
  if (sendStatus == 0){
    Serial.println("Delivery success");
  }
  else{
    Serial.println("Delivery fail");
  }
}

//void begin(byte attachTo, byte buttonMode = INPUT_PULLUP, boolean activeLow  = true);

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  //pinMode(2,INPUT_PULLUP);
  //pinMode(0,INPUT_PULLUP);

  buttonA.begin(RED);
  buttonA.setClickHandler(click);

  buttonB.begin(BLUE);
  buttonB.setClickHandler(click);
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

  // Init ESP-NOW
  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  // Set ESP-NOW role
  esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER);

  // Once ESPNow is successfully init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

  // Register peer
  esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_SLAVE, 1, NULL, 0);

}

void loop() {
  buttonA.loop();
  buttonB.loop();
}
void click(Button2& btn) {
    if (btn == buttonA) {
      myData.id = BOARD_ID;
      myData.x = 1;
      myData.y = 0;
      esp_now_send(0, (uint8_t *) &myData, sizeof(myData));
      Serial.println("A clicked");
    } else if (btn == buttonB) {
      myData.id = BOARD_ID;
      myData.x = 0;
      myData.y = 1;
      esp_now_send(0, (uint8_t *) &myData, sizeof(myData));
      Serial.println("B clicked");
    }
}

NodeMCU 12-E Receiver
#include <ESP8266WiFi.h>
#include <espnow.h>
#include <Arduino.h>

#define  LED0 D0
#define  LED1 D1
#define  LED2 D2
#define  LED3 D3
#define  LED4 D4
#define  LED5 D5
#define  LED6 D6
#define  LED8 D8
#define  LED7 D7

// Structure example to receive data
// Must match the sender structure
typedef struct struct_message {
    int id;
    int x;
    int y;
} struct_message;

// Create a struct_message called myData
struct_message myData;

// Create a structure to hold the readings from each board
struct_message board1;
struct_message board2;
struct_message board3;

// Create an array with all the structures
struct_message boardsStruct[3] = {board1, board2, board3};

// refree
/*
void ref1(int x, int y){

  if (x == 1 ){
      digitalWrite(LED7, HIGH);
      delay(5);
      digitalWrite(LED7, LOW);
    }
  else  if (y == 1 ){

      digitalWrite(LED8, HIGH);
      delay(5);
      digitalWrite(LED8, LOW);
    }

}

void ref2(int x, int y){

  if (x == 1 ){
      digitalWrite(LED6, HIGH);
      delay(5);
      digitalWrite(LED6, LOW);
    }

  else if (y == 1 ){

      digitalWrite(LED2, HIGH);
      delay(5);
      digitalWrite(LED2, LOW);
    }

}

void ref3(int x, int y){

  if (x == 1){
      digitalWrite(LED0, HIGH);
      delay(5);
      digitalWrite(LED0, LOW);
    }

  else if (y == 1){

      digitalWrite(LED1, HIGH);
      delay(5);
      digitalWrite(LED1, LOW);
    }

}
  */

// Callback function that will be executed when data is received
void OnDataRecv(uint8_t * mac_addr, uint8_t *incomingData, uint8_t len) {
  char macStr[18];
  Serial.print("Packet received from: ");
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
  Serial.println(macStr);
  memcpy(&myData, incomingData, sizeof(myData));
  Serial.printf("Board ID %u: %u bytes\n", myData.id, len);
  Serial.println(myData.id);

  if (myData.id==1 ){
    ref1(myData.x, myData.y);
  }
  if (myData.id==2 ){
    ref2(myData.x, myData.y);
  }
  if (myData.id==3 ){
    ref3(myData.x, myData.y);
  }

  // Update the structures with the new incoming data
  boardsStruct[myData.id-1].x = myData.x;
  boardsStruct[myData.id-1].y = myData.y;
  boardsStruct[myData.id-1].id = myData.id;
  Serial.printf("x value: %d \n", boardsStruct[myData.id-1].x);
  Serial.printf("y value: %d \n", boardsStruct[myData.id-1].y);
  Serial.printf("id value: %d \n", boardsStruct[myData.id-1].id);
  Serial.println();

}

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED0, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  pinMode(LED7, OUTPUT);
  pinMode(LED8, OUTPUT);

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();

  // Init ESP-NOW
  if (esp_now_init() != 0) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Once ESPNow is successfully Init, we will register for recv CB to
  // get recv packer info
  esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
  esp_now_register_recv_cb(OnDataRecv);

}

void loop(){

}

don't print inside ISRs ... set a flag instead ... move message printing to inside loop() ...print a message if flag is set

what it the meaning of ISR ? and can you give and example snip of pseudocode.

I set it up with flags but no hope. Still stuck now trying to RingBuffer.

ISR - interrupt service routine ... it is the callback function

take out the delay() and print() lines, and see if it works then.

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


text:
Megaboard Problems about pySerial Communication from Python to Arduino
I asked same question on another forum, but i need more opinions and advices.
I wrote a simple Python code and Arduino code.
In my code, the Excel matrix data is loaded into Python,
then converted into a numpy form of matrix data in Python,
and then extracted the values of each element of the matrix converted into numpy.
Each extracted element value is a screw lead value.
These screw lead values are calculated and converted to the number of revolutions of each screw.
These converted screw rotational speed values are now transferred to Arduino using pySerial.
Once the values of the screw revolutions are transmitted to Arduino,
rotate the step motor connected to Arduino by the number of revolutions of the screw.
So here's my Python code.:
import csv
import pandas as pd
import numpy as np
import os
import serial
import time

py_serial = serial.Serial(
    port="COM5",
    baudrate=9600
)

Location = 'C:/Users/KIMWONKI'
File = 'excel_example.xlsx'

data_pd = pd.read_excel('C:/Users/KIMWONKI/excel_example.xlsx',
                        header=None, index_col=None, names=None)

data_np = pd.DataFrame.to_numpy(data_pd)

start = 2
pitch = 3
lead = 0

for i, row in enumerate(data_np):
    for j, element in enumerate(row):
        lead = data_np[i][j]
        rotation = lead/(start*pitch)
        reverse_rotation = - rotation
        rotation = round(rotation, 6)
        if rotation > 0:
            print(f'motor rotates in the forward direction at {abs(rotation)} times.')
            rotation = str(rotation)
            py_serial.write(rotation.encode())
            time.sleep(8)

And next is my Arduino code.:
int DIRM=8;
int PULM=9;
int DIRP=10;
int PULP=11;
float rot_number = 0;
float sig;

void setup() {

  Serial.begin(9600);
  pinMode (DIRM, OUTPUT);
  pinMode (PULM, OUTPUT);
  pinMode (DIRP, OUTPUT);
  pinMode (PULP, OUTPUT);
}

void loop() {
  while(Serial.available()){
    sig = Serial.parseFloat(); // sig is rotation number inputted from python
    if(sig > 0){
      rot_number = sig; // rotation number
      rotate_CW(rot_number);
      delay(1000);
      rot_number = 0;
      break;
    }
    else if(sig < 0){
      rot_number = sig;
      rot_number = abs(rot_number);
      rotate_CCW(rot_number);
      delay(1000);
      rot_number=0;
      break;
    }
    else{
      break;
    }
  }
}

void rotate_CW(float rotation_number)
{
  int numberOfRounds = int (rotation_number * 4000);

  for (int i = 0; i < numberOfRounds; i++){
    digitalWrite(DIRM,LOW);
    digitalWrite(DIRP,HIGH);
    digitalWrite(PULP,HIGH);
    digitalWrite(PULM,LOW);
    delayMicroseconds(100);
    digitalWrite(PULP,LOW);
    delayMicroseconds(100);
  }
}

void rotate_CCW(float rotation_number) // reverse rotation function
{
  int numberOfRounds = int (rotation_number * 4000);

  for (int i = 0; i < numberOfRounds; i++){
    digitalWrite(DIRM,HIGH);
    digitalWrite(DIRP,LOW);
    digitalWrite(PULP,HIGH);
    digitalWrite(PULM,LOW);
    delayMicroseconds(100);
    digitalWrite(PULP,LOW);
    delayMicroseconds(100);
  }
}

I connected four input/output cables attached to the step motor driver to Arduino. I wrote the code accordingly. DIRM stands for DIR-pin and DIRP stands for DIR+pin PULM means PUL-pin and PULP means PUL+ pin.
I first connected the Arduino Uno board, ran the Arduino code, and then ran the Python code.
Here is the terminal output appears in the Python program.:
motor rotates in the forward direction at 0.5 times.
motor rotates in the forward direction at 1.166667 times.
motor rotates in the forward direction at 1.333333 times.
motor rotates in the forward direction at 1.5 times.
motor rotates in the forward direction at 0.833333 times.
motor rotates in the forward direction at 0.666667 times.
motor rotates in the forward direction at 1.333333 times.
motor rotates in the forward direction at 1.333333 times.
motor rotates in the forward direction at 0.666667 times.
motor rotates in the forward direction at 0.333333 times.
motor rotates in the forward direction at 1.666667 times.

When using the Arduino Uno board, the motor actually 'rotated' to match the output of this terminal, with 0.5 turns, 1.166667 turns, 1.333333 turns, etc.
But now I changed the board from Arduino Unoboard to Mega Board, and the motor didn't work.
It's not like there was an error message in particular, or the code didn't execute at all. Only the output message came from the above terminal output window, and the motor did not rotate.
I checked where the problem occurred. Through the serial monitor of the Arduino IDE, I directly entered the screw revolution value into the Arduino code and found that the motor rotated normally regardless of whether it was using the Arduino Uno board or the Arduino Mega board.
However, the attempt to run Python and transfer the screw revolution value data to Excel->Python->Arduino was only possible on the Arduino Uno board. When the Arduino Mega Board was used, the Python terminal output window still says 'N times' but the motor did not actually rotate.
I checked all the board rates and port names. Board rate settings and port settings were correct, but still motor does not rotate. I don't know where the problem is.
The megaboard I used is 2560 megaboard. My code is a mess, but I'd appreciate it if you could help me.

write a simple arduino sketch that runs the motor for one second, stops for one second, reverses motor for one second, stops for one second and repeats

Insert time.sleep(2) following  py_serial = serial.Serial(.... It may or may not have anything to do with your actual problem, but it is something you should do anyway, if nothing else to eliminate it as a question as to whether not it matters.


text:
Problems using HC-SR04 with LED displays
I'm having problems using an HC-SR04 ultrasonic sensor in conjunction with an LED display module. The sensor appears to work fine when outputting values to the serial monitor, measuring distances up to the rated maximum of around 3m. However when I connect the display module the maximum distance displayed drops to about 50 or 60cm.
I've tried both a TM1637 four-digit seven-segment display module using the TM1637Display library and a Max7219 eight-digit seven-segment display using the LedControl library. Using the NewPing library's ping_cm() function for distance measurement instead of the pulseIn() function makes no difference.
I'm tending to think it's either something in the LED module libraries that interferes with the measurement of pulses, or possibly noise and ripple on the power supply.
I tried twisting the longer power and data wires together. I've also added a 0.1uF ceramic capacitor across the power connections to the ultrasonic sensor and a 0.1uF ceramic and 2.2uF electrolytic capacitor across the power rails at the point of connection to the display module. This appeared to improve the reliability of the Max display, which previously showed a garbled display from time to time, but didn't make any difference to the range problem.
I've tried powering the Arduino with a 9V wall adapter and well as the USB supply from my PC. This makes no difference. As far as I can trust my multimeter, the supply voltage to the sensor is adequate; between 5.02V and 4.95V depending on the distance the sensor is measuring (the voltage reduces slightly when sensing longer distance). Unfortunately I don't have access to an oscilloscope so I can't see what's happening at a higher frequency. I had hoped the electrolytic capacitor would help smooth out voltage fluctuations.

My current work-around is to disable the display while the sensor measures distance. With the LedControl library, I can do this immediately before reading the pulse duration. With the the TM1637Display library I found I had to clear the display before triggering the sensor. In both cases, the display will then show the correct distance but flickers in proportion to the measurement distance (the longer the distance the longer pulseIn() has to wait for the echo).
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 7
#define DIO 6
#define ECHO 5
#define TRIG 4

TM1637Display display(CLK, DIO);

void setup(){
  pinMode(TRIG, OUTPUT);
  pinMode (ECHO, INPUT);
  display.setBrightness(7, true);
}

void loop(){
  long duration; // duration in us
  long distance; // distance in cm

  display.clear();
  // This is the workaround described above; without this line
  // the sensor cannot measure any more than about 50 or 60cm.
  // With this line, the sensor measures up to about 3m but
  // obviously the display flickers every time around the loop.

  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  duration = pulseIn(ECHO, HIGH, 20000);
  // a 20ms (20000us) timeout corresponds to the maximum sensor range (3.4m approx)

  // Since the speed of sound is approx 340m/s, i.e. roughly 29 us/cm
  // we can divide duration (us) by 29 and again by 2 (pulse travels
  // out and back) to obtain a distance from sensor in cm:
  distance = duration / 29 / 2;

  display.showNumberDec(distance, false); // true shows leading zeros
  delay(250);
}

Any suggestions?

try commenting out display.clear()

Please check the voltage drop across HC-SR04, anything below 4.5v would provide inaccurate readings.

@jsotola: the display.clear() is the only way I can actually get a decent reading (code commented to clarify). @arcube: I've measured the voltage to be between about 4.9V and 5.0V (paragraph on voltage measurement added).


text:
Why is my analog output limited to 2.7V?
I have an MKR WIFI1000 (v2.0 [Arduino:XYZ]) with a "real" analog output pin (DAC0/A0/PIN15). According to the documentation, this is a 10 bit DAC, so I assume I can write analogWrite(15, 1023) to have an output of 3.3V on that pin.
However, I don't seem to get it higher than 2.7V, which is already reached well before a value of 256.
This is my code:
#include <Arduino.h>

#define AN_OUTPUT 15

int counter = 0;

void setup()
{
  pinMode(AN_OUTPUT, OUTPUT);
}

void loop ()
{
  counter++;
  if (counter > 1023) {
    counter = 0;
  }

  analogWrite(AN_OUTPUT, counter);
  delayMicroseconds(1);
}

And this is the corresponding signal:

Did you explicitly set A0 to be an output? Read this text about analog output on A0? Also remember the maximum value for a 10-bit DAC is not 1024 but 1023 (2^10-1).

Well, part of it is just that it's in 8-bit mode. And just to telegraph this for anyone that wants to get stupid about it: no that's not an answer. It doesn't explain why the graph output isn't closer to 3.3V or rather 250/255 * 3.3. If more code was in the question it be clear why it isn't a sawtooth shape even. Assuming there's a good reason for that, if this were my project just to sanity check I would measure the 3.3V pin and see that it really is 3.3V and not something closer to 255/250 * 2.7. Are you running from a low battery?

@StarCat I set it with pinMode(DRIVE_PIN, OUTPUT) and DRIVE_PIN is set to 15.

@timemage I power the board from a USB port on my laptop.

Well, I have a samd21 board that isn't what you have but does use the arduino:arduino core for samd for its board definition. I tested with core version 1.8.13. I did analogWrite of 255 for the default 8-bit resolution to the DAC pin and it got within a few tens of mv of 3.3V. Just for the hell of it I did it on a PWM rather than DAC pin and it also gets pretty much right to the rail. If I use 250 it gives 3.22 V. My regulator is pretty much spot on 3.30. Not sure what to tell you other than to include more. All code and wiring information, all versions information, etc.

@timemage I updated my question

It's good that you added the code. I don't know what "v2.0 [Arduino:XYZ]" refers to.

@timemage that 's what I get for "Version" when I upload the program....

Well, it seems like you've answered it yourself, so I guess I'm just not going to worry about what it means. You didn't have the code in the question at the time I did my testing and I just didn't use pinMode / OUTPUT because there's no reason to. So, I'm curios to see if I can replicate the problem now that I know what it is using my own board.

This link had the answer, you have to remove the pinMode(PIN, OUTPUT) line.


text:
Tools > Board settings: how are they captured?
In the Arduino IDE, the Tools menu can be used to make some board-specific settings like this:

... such as Processor Version = "Atmega168P", Processor Speed = "16MHz Crystal Resonator" and so on. These end up choosing fuses when burning a bootloader.  They may or may not also set constants that influence library behavior, I'm not sure.
What I'd like to know is how such settings stored, as they don't seem to be stored in any file associated with the sketch. And that being the case, they seem to be lost when using different boards or settings for subsequent projects.
So what files store these settings, at least temporarily, and how might one associate those settings more permanently with the project/sketch, so that they are repeatable later?

The board settings from Tools menu are stored in the IDE preferences file.
You can open the file from the Preference dialog of the Arduino IDE. The path to the file is shown at the bottom of the dialog and it is clickable.

Thanks for that good clue! And do you know of a way to associate those settings permanently with the project/sketch to which they pertain, so they can be repeated later?

@gwideman https://arduino.stackexchange.com/questions/91305/is-it-possible-to-save-and-restore-the-arduino-ide-tools-settings-somehow

the link to preferences file is missing in IDE 2.0.3


text:
Strange Character In Tempurture Reading
Can anyone identify this character?

Thats an A with a circumflex. Does that answer your question? If you want to know why it is there you need to provide way more information, including your code

Everything @chrisl said. Plus you should know that there are multiple, at least two, Unicode sequences that will generate that same representation.

The degree sign (°) is Unicode character U+00B0 (i.e. code point 0xb0).
In UTF-8, it is encoded as the two-byte sequence 0xc2 0xb0. Your browser
is not aware that the page is encoded as UTF-8, and for some reason it
believed it is ISO-8859-1. This two-byte sequence, interpreted as
ISO-8859-1, represents the two characters “Â” and “°”.
The simplest solution might be to add
<meta charset="utf-8">

at the top of the <head> element of the Web page.

… or use the ° html entity.

OUTSTANDING!
Edgar's single line suggestion solved the problem! The ESP32 page looks perfect now.

@RachelR And Grimaldi's suggestion is the Only Right solution. ;-) Please mark the answer you see fit best as "accepted". You might want to take the [tour] to learn how this site works.

@thebusybee: Do you mean there is something Wrong™ in encoding Web pages in UTF-8?

It depends. ;-) Say you want to support the most systems, not only Win, Mac, and Linux, then you need to assume that not all of them know UTF-8. As someone living in a country with non-ASCII characters in written language, one of the more annoying problems is the lack of encoding such characters as HTML entities. Anyway, it's alright, if you accept rare cases of "strange characters".

@thebusybee: You know of a Web browser that understands ° but not ° written in UTF-8? Is that Mosaic, or some other retro-computing thing? It's 2023 now. UTF-8 has been around for 30 years, and is the undisputed de facto standard encoding of the Web over the whole planet. I firmly believe it's time to move on and leave pre-UTF-8 browsers to computer history museums.

Oh, it's not about web servers, but web browsers. And (without having tried) there are a lot of old and small computers still in use that cannot run a full-fledged browser like Firefox or Chromium. For example, I have an old (20+ years) notebook running Void Linux just fine on the work bench. It is perfect for most development tasks, but not for "modern" web surfing. Not to speak of hobbyists still working with their ZX81. :-D Yes, there are such, but granted, their number is small.

And the OP's use case is apparently something like environment values provided by a web server, well in the realm of IoT. To use limited devices as "display" is quite common with this. -- Final line: If a standard is more compatible, even old, why should one use a less compatible standard, just because it is newer? Both work with modern browsers. But only the old one works with limited browsers.

@thebusybee: I do understand it's about browsers. It would be interesting to test ° vs. ° on your old notebook. What browser does it run? Note that parsing UTF-8 requires less computing resources than parsing named references. IMO, the value of UTF-8 lies in the readability of the source, which I do value a lot.

Let us save the time, I cannot afford to investigate this detail. I just made a general remark targeting the usage of old standards compared to new standards just because of its broader support . It does not make your answer wrong, and I suggested to accept it.

@thebusybee: Only tangentially related to this discussion... I just stumbled on WebOne, a HTTP proxy that makes old browsers usable in the modern Web. Looks like a cool project, and I thought it may be of interest to you.


text:
What is the raw value & scale value functionality of analog read() of ESP32 ? (Provided for UNO for reference)
What is the difference between ESP32 Dev kit & Uno for analogread() Function?
As Uno -0 to 1023
As Esp 32 Dev Kit -0 to 4095
So what will be the raw val & scale val ?
For UNO -
int Rawval = analogRead(analogPin);
Serial.print("Rawvalue from Analog input =");
Serial.print(Rawval);
Scaleval = map(Rawval, 0, 675, 0, 20);
Serial.print(" Scaled Value =");

What will be for ESP32 Dev Kit?
Ref UNO-
// For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
/// === RELAY code ===
// raw value 675 correspond to 20%, so for 5% we will get 169
  if ( Rawval < 169) digitalWrite(RELAY_pin, HIGH);
  else  digitalWrite(RELAY_pin, LOW);
}

What will be for ESP32 Dev Kit?

Look in the help section under the question mark  in the editor about code quoting. I'd use the triple-backtick method for you, but you've got something weird around For UNO -int Rawval and I don't want to break things as much as fix them.

one is 10 bits of data and the other is 12 bits of data ... it appears that the question is not about analogread() at all, but about something else ... please update your question and ask about the real focus of your question

what is raw val and scale val?

QUESTION IS CLEAR?

no, it is not ... the code is also not formatted properly, so it is difficult to read ... please format the code ... as @timemage already said, put ``` on a separate line before the code and also after the code

Raw value is analogous sensor value..
Scale value is after mapping using the map function of raw value of the sensor.

I want exactly the same functionality at ESP32 dev kit as reference of UNO

When the read voltage is maximum that is 3.3V digital output is equal to 4095 for ESP32

Well then, go ahead. Use your transfer power to compare that with the 1023 maximum of the Uno. -- And, please, format your question.

Confusion! Here also, As you said that code for UNO was provided by someone expert.

As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

How to map for ESP32 (As 4095 for 3.3v)? Enclosed Logic is for uno.
''' // For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
Scaleval = map(Rawval, 0, 675, 0, 20); '''
''' // raw value 675 correspond to 20%, so for 5% we will get 169'''
Kindly modify this for ESP32 (4095)-- Enclosed Logic is for uno.
If you can enclose logic behind that will also fine for me based on calculations
Also for 0.1%


text:
How to compile Arduino-ESP32 core with ESP_LOGx
Why?
In Arduino IDE you can set the core debug level, however, this only sets debug level for files in Arduino-esp32 but the core which is distributed as a precompiled library in .sdk files, located in your Arduinio installation folder, is unaffected - the debug level remains the default “error”.

What?
If you want to change the core code or debug level, you need to clone the repo: https://github.com/espressif/esp32-arduino-lib-builder, make the modifications there, compile and apply the changes (automatically by the build script).
How?
There are 2 basic approaches. Both of them involve editing file esp32-arduino-lib-builder/configs/defconfig.common.
The first option is to edit the file directly and then build.
Later you can git restore configs/defconfig.common to go back.
The second option is to copy the file cp configs/defconfig.common configs/defconfig.debug, edit the debug version and then compile.
Open the defconfig file
vim configs/defconfig.common or vim configs/defconfig.debug
Edit line 45 containing by default CONFIG_LOG_DEFAULT_LEVEL_ERROR=y to one of the following lines depending on your desired log level:
CONFIG_LOG_DEFAULT_LEVEL_NONE=y # No output
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y # Errors - default
CONFIG_LOG_DEFAULT_LEVEL_WARN=y # Warnings
CONFIG_LOG_DEFAULT_LEVEL_INFO=y # Info
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y # Debug
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=y # Verbose - All of the above

Then simply build the libs for all SoCs or one specific SoC. Note that building for all SoCs takes a lot of time, so if you work only with one specific SoC, build only for that one.
If you have copied the defconfig file and the debug settings are in file configs/defconfig.debug add flag debug
example : ./build.sh debug
Build all SoCs: ./build.sh
Build only selected SoC: ./build.sh -t <soc>
The exact text to choose the SoC:

esp32
esp32s2
esp32c3
esp32s3
Example: ./build.sh -t esp32
A wrong format or non-existing SoC will result in the error sed: can't read sdkconfig: No such file or directory


text:
variable 'LiquidCrystal_I2C lcd' has initializer but incomplete type
I have a problem with lcd, I have  NUCLEO64 L746RG , I have Lcd Display and I2C connected to it.
When I verify code it gives me and long error and I can not find the solution or cause of this error:
In file included from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h:149,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/stm32/stm32_def.h:48,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/stm32/clock.h:19,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/wiring_time.h:23,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/wiring.h:38,
                 from C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\cores\arduino/Arduino.h:36,
                 from C:\Users\User\AppData\Local\Temp\arduino-sketch-B028C48DF91C28F6EAA5B0CE34D27EE2\sketch\Displaylcd1.ino.cpp:1:
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:29: error: expected identifier before '(' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                              ~            ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ~             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:29: error: expected class-name before '(' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:29: error: expected '{' before '(' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                              ~            ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.4.0\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l476xx.h:1326:43: error: expected ')' before '*' token
 1326 | #define LCD                 ((LCD_TypeDef *) LCD_BASE)
      |                             ~             ^
c:\Users\User\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:38:34: note: in expansion of macro 'LCD'
   38 | class LiquidCrystal_I2C : public LCD
      |                                  ^~~
C:\Users\User\Documents\Arduino\Displaylcd1\Displaylcd1.ino:2:22: error: variable 'LiquidCrystal_I2C lcd' has initializer but incomplete type
    2 | LiquidCrystal_I2C lcd(0x27,16,2);  /*I2C scanned address defined + I2C screen size*/
      |                      ^
Multiple libraries were found for "LiquidCrystal_I2C.h"
  Used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal
  Not used: C:\Users\User\Documents\Arduino\libraries\LiquidCrystal_I2C
exit status 1

Compilation error: variable 'LiquidCrystal_I2C lcd' has initializer but incomplete type

This is my code:
#include <LiquidCrystal_I2C.h>  /*include LCD I2C Library*/
LiquidCrystal_I2C lcd(0x27,16,2);  /*I2C scanned address defined + I2C screen size*/
void setup() {
  lcd.init();  /*LCD display initialized*/
  lcd.clear();     /*Clear LCD Display*/
  lcd.backlight();      /*Turn ON LCD Backlight*/
  lcd.setCursor(2,0);   /*Set cursor to Row 1*/
  lcd.print("I2C LCD Nano"); /*print text on LCD*/
  lcd.setCursor(2,1);   /*set cursor on row 2*/
  lcd.print("Linuxhint.com"); /*print message on LCD*/
}
void loop() {
}

I do not know why, I am not including anything else so why is it giving me this error?
PLEASE HELP, I AM WORKING ON IT for 8 hours AN I STILL COULD NOT FIGURE OUT WHAT IS THE PROBLEM, PLease help

WHY ARE YOU SHOUTING?

please format the error log same as code

Normally I wouldn't answer this, but the error is not exactly in your code but (seemingly at least) in two common things in the Arduino ecosystem.
Roughly speaking, the library you're trying to use is incompatible with the STM32 board support you're using.
The error message sort of tells this. It may help to read it backwards:
<sketchbook>\libraries\LiquidCrystal/LCD.h:169:7: note: in expansion of macro 'LCD'
  169 | class LCD : public Print
      |       ^~~

So, it is in your installed LiquidCrystal library trying to process the definition of the LCD class, and having a problem with LCD, or rather in expansion of macro 'LCD'.  So, there's macro called LCD that it's trying to expand at that point, which should be a red flag.
The top part is where the compiler proper is having issues with the macro expansion where it causes a more fundamental error, error: expected identifier before '(' token  This is because it is trying to insert the macro definition directly into where it has found it resulting in this code effective after preprocessing:
class ((LCD_TypeDef *) LCD_BASE) : public Print

which is gibberish. It's pointing to the first open parenthesis there and saying expected identifier, the identifier being the class name it expected to see, not this cast and other stuff that follows. Whoever wrote your LiquidCrystal library did not expect LCD to already be defined as something via macro. This is one of a number of reasons why macros are hated.
The bulk of this is indicating the how the macro got to where it came from to where it wound up. The macro started in stm32l4xx.h in CMSIS and wound it's way into the LiquidCrystal header through Arduino.h and everything in between:
In file included from <Arduino15>\<STM32boardSupport>\system/Drivers/CMSIS/Device/ST/STM32L4xx/Include/stm32l4xx.h:149,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/stm32/stm32_def.h:48,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/stm32/clock.h:19,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/wiring_time.h:23,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/wiring.h:38,
                 from <Arduino15>\<STM32boardSupport>\cores\arduino/Arduino.h:36,
                 from <Temp>\arduino-sketch-B028C48DF91C28F6EAA5B0CE34D27EE2\sketch\Displaylcd1.ino.cpp:1:

To oversimply a bit CMSIS is the semi-standard header files that ARM chip makers are supposed to provide that among other things define hardware registers. Although I haven't investigated it, it seems likely that whatever chip you're using has a built in LCD driver, and so there are things, macros namely, that have "LCD" in the name. Unfortunately for you, one just called LCD.
You could try renaming all of the uses all of the uses of LCD within the LiquidCrystal library that you have to some other name. Or you could try inserting #undef LCD after the include of Arduino.h in the LCD.h header in an attempt to undefined the macro so that the LCD in the class definition is not expanded. But, I would be looking for different versions of the library and making sure the library is even the one you think it is, because everyone and their dog seems to have made some library called LiquidCrystal at some point or another. It would be a pity if you went through all trouble to find out you weren't even looking at the right library.


text:
Why won't IP mode change to 1 in ESP01 using the AT commands?
I was trying to send some data to a webpage using an Arduino Uno R3 connected to an ESP01. I simply uploaded the BareMinimum and started sending AT commands through the Serial Monitor. It worked fine for the first time, but now its IPMODE is stuck to 0 (Single IP mode). Everytime I try to set it back to 1 (Multiple IP mode), it throws an error "IPMODE must be 0". I tried resetting the ESP01 but that didn't work.

you mean AT+CIPMODE? set AT+CIPMUX=0 first

I'm doing that, for AT+CIPMUX=0, I get "OK" as response, which means that the IP mode is set to 0. But whenever I send AT+CIPMUX=1, it returns "ERROR IP mode must be 0". I don't understand why it MUST be 0, when I have already used this feature once.

CIPMODE 0 is normal mode and CIPMODE 1 is "passthrough mode".  CIPMUX is : 0 single connection, 1: multiple connections. And multiple connections can only be set when transparent transmission is disabled (AT+CIPMODE=0).


text:
Bluetooth Serial is unavailable `SerialBT.available()` returns False on Macbook after a successful bluetoooth connection
I am trying to send and receive messages between my mac and esp32 board. I am currently using the Bluetooth classic interface. After a successful connection. I however have observed that there is no data being received on my Macbook.
#include "BluetoothSerial.h"

BluetoothSerial SerialBT;

void setup()
{
  Serial.begin(9600);
  SerialBT.begin("ESP32test");
  Serial.println("Setup initalised");
  delay(1000);
}

void loop()
{
  String inputFromOtherSide;
  Serial.println("Loop has started");
  if (SerialBT.available())
  {
    Serial.println("SerialBT is available");
    inputFromOtherSide = SerialBT.readString();
    SerialBT.println("You had entered: ");
    SerialBT.println(inputFromOtherSide);
  }
}

The above-attached images show the output that I currently receive. After some debugging, I noticed that
SerialBT.available() returns false. I am not sure how to proceed from here.
I do know that this above code should work as I have tested this on windows and it works.

I however need to replicate this on the MacBook any guidance on the reason why this fails here would be appreciated. Or is there a way for me to create a Bluetooth serial link on a mac

available returns count of characters available to read.

Does this mean that if I type something in the serial then it would later fill the buffer for me to read from? which then gets printed again?

SerialBT.available() will be more than zero only if something is received over SerialBT (which I guess is not connected to Serial Monitor). in this version of the sketch you have no reason to condition printing to SerialBT. (I saw your post om Arduino forum with a different version of the sketch, which first reads the received cata)


text:
WS2812b - Interpolate pixels on neopixel matrix with mask
simplified my goal is to display a transitional Background and some shapes. This shapes are not moving hard rasterized by 1 pixel, more like .1 each cycle. So I need a way to interpolate the movement between the surrounding Neopixels.
Background works fine, so it's not relevant for now.
For the shapes the first try was to show a smooth movement of a square hardcoded. This works suitable, even its not bug free. I put the Code of the first attempt at the very end.
After that I wanted to implement an bitmap mask to show something more complex . That's where I am at currently. First of this attempt is to assume the whole mask is completly filled (again hardcoded).
The LEDs mostly keep completely on or off.
How do I get them fade them in an out at the outer sides?
I use an AI Thinker ESP 32 and 200 WS2812Bs.
Please ask any more infos that are required. Of course if you spot that my approach is unsuitable to begin with, pls tell me.
Infos for the Code: don't get lost on the "circle" variables. At the eary steps I showed a circle and soon realized its easier to step back to a Circle while working at the interpolation.
My Code with the bitmap
#include <Adafruit_NeoPixel.h>

#define PIN_NEO_PIXEL  13
#define NUM_PIXELS     400
#define num_row 20
#define num_col 20
#define circle_size_body 4
#define circle_size_border 5
#define circle_size_corona 7
#define DELAY_INTERVAL  100

float circle_PosX = 10;
float circle_PosY = 10;
int circle_direction = 1;
enum eIntersectingPart { None, Body, Border, Corona };

Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);

void setup()
{
  NeoPixel.setBrightness(100);
  NeoPixel.begin();
  Serial.begin(115200);           // set up Serial library at 9600 bps
}

float backgroundShift = 0;
float worldSpeed = .05;

void loop()
{
  if(circle_PosY <= 0 && circle_direction < 0
     || circle_PosY >= 10 && circle_direction > 0)
    circle_direction *= -1;
  circle_PosY += worldSpeed * circle_direction;
  circle_PosX += worldSpeed * circle_direction;
    Serial.print("circle_PosX ");
    Serial.print(circle_PosX);
    Serial.print(", circle_PosY ");
    Serial.print(circle_PosY);
    NeoPixel.clear();
    //Hintergrund setzen
    // setBackgroundColor();

    //Kreis malen
    drawCircle();

  // Serial.print("bgShift: ");
  // Serial.flush();
  NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
  // Serial.println(backgroundShift);
  backgroundShift += worldSpeed;
  delay(100);     // off time
}

uint32_t setBackgroundColor() {

  for(int led = 0; led < NUM_PIXELS; led++) {
    int coordinates[2];
    coordinateByLed(coordinates, led);

    byte ambientColors[3] = { 0, 0, 255 };
    int ambientCcolorS = (int)( sin( 0.3 * coordinates[0] + backgroundShift) * 127.0 );
    int ambientCcolorC = (int)( cos( 0.3 * coordinates[1] + backgroundShift) * 128.0);
    int amberC = (ambientCcolorS + ambientCcolorC + 255) / 2;

    NeoPixel.setPixelColor(
        led,
        NeoPixel.Color(amberC, amberC ,255));
  }
}

bool firstIteration = false;
void drawCircle() {
    //          x                   y                           Anteil
    byte bitmap[circle_size_corona + 1][circle_size_corona + 1];

    float startPositonX = circle_PosX - .5f * (float)circle_size_corona;
    float startPositonY = circle_PosY - .5f * (float)circle_size_corona;

    int lowerStartX = floor(startPositonX);
    int upperStartX = ceil(startPositonX);
    int lowerStartY = floor(startPositonY);
    int upperStartY = ceil(startPositonY);

    float proportionForLowerX = abs(upperStartX - startPositonX);
    float proportionForUpperX = 1 - proportionForLowerX;
    float proportionForLowerY = abs(upperStartY - startPositonY);
    float proportionForUpperY = 1 - proportionForLowerY;

    firstIteration = true;

    for(byte x = 0; x < circle_size_corona; x++) {
        for(byte y = 0; y < circle_size_corona; y++) {
            float proportion = 0;

            int lowerLedX = lowerStartX + x;
            int lowerLedY = lowerStartY + y;
            int upperLedX = upperStartX + x;
            int upperLedY = upperStartY + y;

            if(lowerLedX >= 0 || lowerLedX < num_col
                &&
                lowerLedY >= 0 || lowerLedY < num_row) {
                byte currentX = x;
                byte currentY = y;
                proportion = proportionForLowerX * proportionForLowerY;
                bitmap[currentX][currentY] += (byte)(proportion * 100);
                bitmap[currentX][currentY] = min(bitmap[currentX][currentY], (byte)100);

                if(lowerLedX == 6 && lowerLedY == 6) {
                    Serial.print(", x ");
                    Serial.print(x);
                    Serial.print(", y ");
                    Serial.print(y);
                    Serial.print(", partialProportion ");
                    Serial.print(proportion);
                    Serial.print(", newBitmapVal ");
                  byte newBitmapVal = bitmap[currentX][currentY];
                    Serial.print(newBitmapVal);
                    Serial.print(" || ");
                }
            }
            if(upperLedX >= 0 || upperLedX < num_col
                &&
                lowerLedY >= 0 || lowerLedY < num_row) {
                byte currentX = x + 1;
                byte currentY = y;
                proportion = proportionForUpperX * proportionForLowerY;
                bitmap[currentX][currentY] += (byte)(proportion * 100);
                bitmap[currentX][currentY] = min(bitmap[currentX][currentY], (byte)100);
                if(upperLedX == 6 && lowerLedY == 6) {
                    Serial.print(", x ");
                    Serial.print(x);
                    Serial.print(", y ");
                    Serial.print(y);
                    Serial.print(", partialProportion ");
                    Serial.print(proportion);
                    Serial.print(", newBitmapVal ");
                  byte newBitmapVal = bitmap[currentX][currentY];
                    Serial.print(newBitmapVal);
                    Serial.print(" || ");
                }
            }
            if(lowerLedX >= 0 || lowerLedX < num_col
                &&
                upperLedY >= 0 || upperLedY < num_row) {
                byte currentX = x;
                byte currentY = y + 1;
                proportion = proportionForLowerX * proportionForUpperY;
                bitmap[currentX][currentY] += (byte)(proportion * 100);
                bitmap[currentX][currentY] = min(bitmap[currentX][currentY], (byte)100);
                if(lowerLedX == 6 && upperLedY == 6) {
                    Serial.print(", x ");
                    Serial.print(x);
                    Serial.print(", y ");
                    Serial.print(y);
                    Serial.print(", partialProportion ");
                    Serial.print(proportion);
                    Serial.print(", newBitmapVal ");
                  byte newBitmapVal = bitmap[currentX][currentY];
                    Serial.print(newBitmapVal);
                    Serial.print(" || ");
                }
            }
            if(upperLedX >= 0 || upperLedX < num_col
                &&
                upperLedY >= 0 || upperLedY < num_row) {
                byte currentX = x + 1;
                byte currentY = y + 1;
                proportion = proportionForUpperX * proportionForUpperY;
                bitmap[currentX][currentY] += (byte)(proportion * 100);
                bitmap[currentX][currentY] = min(bitmap[currentX][currentY], (byte)100);
                bitmap[currentX][currentY] = min(bitmap[currentX][currentY], (byte)100);
                if(upperLedX == 6 && upperLedY == 6) {
                    Serial.print(", x ");
                    Serial.print(x);
                    Serial.print(", y ");
                    Serial.print(y);
                    Serial.print(", partialProportion ");
                    Serial.print(proportion);
                    Serial.print(", newBitmapVal ");
                  byte newBitmapVal = bitmap[currentX][currentY];
                    Serial.print(newBitmapVal);
                    Serial.print(" || ");
                }
            }

            firstIteration = false;
        }
    }

    firstIteration = true;
    for(int x = 0; x < circle_size_corona + 1; x++) {
        for(int y = 0; y < circle_size_corona + 1; y++) {
            int lowerLedX = lowerStartX + x;
            int lowerLedY = lowerStartY + y;
            int upperLedX = upperStartX + x;
            int upperLedY = upperStartY + y;

            if(
            // firstIteration
                lowerLedX == 6 && lowerLedY == 6
                  ||
                    upperLedX == 6 && lowerLedY == 6) {
                Serial.print(", startPositonX ");
                Serial.print(startPositonX);
                Serial.print(", x ");
                Serial.print(x);
                Serial.print(", y ");
                Serial.print(y);
                Serial.print(", lowerLedX ");
                Serial.print(lowerLedX);
                Serial.print(", lowerLedY ");
                Serial.print(lowerLedY);
            }

            if(lowerLedX >= 0 || lowerLedX < num_col
                &&
                lowerLedY >= 0 || lowerLedY < num_row) {
                setLedColorWithProportion(lowerLedX,lowerLedY, .01f * bitmap[x][y]);
            }

            firstIteration = false;
        }
    }

    Serial.print(" ");
    Serial.println();
}

void setLedColorWithProportion(
    int coordX, int coordY,
    float proportion)
{
    int led = ledByCoordinate(coordX, coordY);
    uint32_t ledColor = NeoPixel.getPixelColor(led);
    uint8_t partialColor = (uint8_t)((proportion ) * 255.0f );

    uint8_t white = (ledColor>>24) & 255;
    uint8_t red = (uint8_t)((1.0f - proportion) * ((ledColor>>16) & 255))
        + partialColor;
    uint8_t green = (ledColor>>8) & 255;
    uint8_t blue = ledColor & 255;

    if(
    // firstIteration
    coordX == 6 && coordY == 6
    ) {
        Serial.print(", prop ");
        Serial.print(proportion);
        Serial.print(", redValOld ");
        Serial.print(((ledColor>>16) & 255));
        Serial.print(", redValNew ");
        Serial.print(red);
    }

    ledColor = white;
    ledColor = (ledColor<<8) + red;
    ledColor = (ledColor<<8) + green;
    ledColor = (ledColor<<8) + blue;
    NeoPixel.setPixelColor(
        led,
        ledColor);
}

int ledByCoordinate(byte column, byte row) {
  return (row  * num_col) + (column);
}

void coordinateByLed(int coordinates[2], int led) {
  coordinates[0] = led % num_col;
  coordinates[1] = led / num_col;
}

First attempt without bitmap
#include <Adafruit_NeoPixel.h>

#define PIN_NEO_PIXEL  13
#define NUM_PIXELS     400
#define num_row 20
#define num_col 20
#define circle_size_body 4
#define circle_size_border 5
#define circle_size_corona 7
#define DELAY_INTERVAL  100

float circle_PosX = 10;
float circle_PosY = 10;
int circle_direction = 1;
enum eIntersectingPart { None, Body, Border, Corona };

Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);

void setup()
{
  NeoPixel.setBrightness(100);
  NeoPixel.begin();
  Serial.begin(9600);           // set up Serial library at 9600 bps
}

float backgroundShift = 0;
float worldSpeed = .01;

void loop()
{
  if(circle_PosY <= 0 && circle_direction < 0
     || circle_PosY >= 10 && circle_direction > 0)
    circle_direction *= -1;
  circle_PosY += worldSpeed * circle_direction;
  circle_PosX += worldSpeed * circle_direction;
    // Serial.print("circle_PosX ");
    // Serial.print(circle_PosX);
    // Serial.print(", circle_PosY ");
    // Serial.print(circle_PosY);
    NeoPixel.clear();
    //Hintergrund setzen
    // setBackgroundColor();

    //Kreis malen
    drawCircle();

  // Serial.print("bgShift: ");
  // Serial.flush();
  NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
  // Serial.println(backgroundShift);
  backgroundShift += worldSpeed;
  //delay(100);     // off time
}

uint32_t setBackgroundColor() {

  for(int led = 0; led < NUM_PIXELS; led++) {
    int coordinates[2];
    coordinateByLed(coordinates, led);

    byte ambientColors[3] = { 0, 0, 255 };
    int ambientCcolorS = (int)( sin( 0.3 * coordinates[0] + backgroundShift) * 127.0 );
    int ambientCcolorC = (int)( cos( 0.3 * coordinates[1] + backgroundShift) * 128.0);
    int amberC = (ambientCcolorS + ambientCcolorC + 255) / 2;

    NeoPixel.setPixelColor(
        led,
        NeoPixel.Color(amberC, amberC ,255));
  }
}

bool firstIteration = false;
void drawCircle() {
    float startPositonX = circle_PosX - .5f * (float)circle_size_corona;
    float startPositonY = circle_PosY - .5f * (float)circle_size_corona;

    int lowerStartX = floor(startPositonX);
    int upperStartX = ceil(startPositonX);
    int lowerStartY = floor(startPositonY);
    int upperStartY = ceil(startPositonY);

    float proportionForLowerX = abs(upperStartX - startPositonX);
    float proportionForUpperX = 1 - proportionForLowerX;
    float proportionForLowerY = abs(upperStartY - startPositonY);
    float proportionForUpperY = 1 - proportionForLowerY;

    // int endX = lowerStartX + circle_size_corona;
    // int endY = lowerStartY + circle_size_corona;

    firstIteration = true;

    for(int x = 0; x < circle_size_corona; x++) {
        for(int y = 0; y < circle_size_corona; y++) {
            int lowerLedX = lowerStartX + x;
            int lowerLedY = lowerStartY + y;
            int upperLedX = upperStartX + x;
            int upperLedY = upperStartY + y;

            /*if(firstIteration) {
                Serial.print(", startPositonX ");
                Serial.print(startPositonX);
                Serial.print(", x ");
                Serial.print(x);
                Serial.print(", y ");
                Serial.print(y);
                Serial.print(", lowerLedX ");
                Serial.print(lowerLedX);
                Serial.print(", lowerLedY ");
                Serial.print(lowerLedY);
            }*/

            if(lowerLedX >= 0 || lowerLedX < num_col
                &&
                lowerLedY >= 0 || lowerLedY < num_row) {
                    setLedColorWithProportion(lowerLedX,lowerLedY, proportionForLowerX * proportionForLowerY);
            }
            if(upperLedX >= 0 || upperLedX < num_col
                &&
                lowerLedY >= 0 || lowerLedY < num_row) {
                    setLedColorWithProportion(upperLedX,lowerLedY, proportionForUpperX * proportionForLowerY);
            }
            if(lowerLedX >= 0 || lowerLedX < num_col
                &&
                upperLedY >= 0 || upperLedY < num_row) {
                    setLedColorWithProportion(lowerLedX,upperLedY, proportionForLowerX * proportionForUpperY);
            }
            if(upperLedX >= 0 || upperLedX < num_col
                &&
                upperLedY >= 0 || upperLedY < num_row) {
                    setLedColorWithProportion(upperLedX,upperLedY, proportionForUpperX * proportionForUpperY);
            }

            firstIteration = false;
        }
    }
    // Serial.print(" ");
    // Serial.println();
}

void setLedColorWithProportion(
    int coordX, int coordY,
    float proportion)
{
    int led = ledByCoordinate(coordX, coordY);
    uint32_t ledColor = NeoPixel.getPixelColor(led);
    uint8_t partialColor = (uint8_t)((proportion ) * 255.0f );

    uint8_t white = (ledColor>>24) & 255;
    uint8_t red = (uint8_t)((1.0f - proportion) * ((ledColor>>16) & 255))
        + partialColor;
    uint8_t green = (ledColor>>8) & 255;
    uint8_t blue = ledColor & 255;

    ledColor = white;
    ledColor = (ledColor<<8) + red;
    ledColor = (ledColor<<8) + green;
    ledColor = (ledColor<<8) + blue;
    NeoPixel.setPixelColor(
        led,
        ledColor);
}

int ledByCoordinate(byte column, byte row) {

    /*if(firstIteration) {
        Serial.print(", column ");
        Serial.print(column);
        Serial.print(", row ");
        Serial.print(row);
        Serial.print(", ergebis ");
        Serial.print(((row  * num_col) + (column)));
    }*/
  return (row  * num_col) + (column);
}

void coordinateByLed(int coordinates[2], int led) {
  coordinates[0] = led % num_col;
  coordinates[1] = led / num_col;
}

What exactly do you mean with bitmap and mask here? Have you tried interpolating by moving the each component linearly with the position of the rectangle? Where exactly do you have problems?

it may be easier to develop code for single row first .... for example, if there are 5 fully lit pixels, and the motion is from left to right, then the 1st pixel must fade out and the 6th pixel has to fade in ... the other 4 pixels remain unchanged

It kind of sounds like you're asking about "anti-aliasing".

Probably not related to your problem, but setLedColorWithProportion() is a quite unconventional way to do alpha compositing: the foreground object is transparent in all channels but red. The usual expectation is for the opacity to be the same for all channels.

thanks for your advice. I stepped back to a 1D model, simplified, altered and it worked, with complex models (in 1D XD), a hard coded Array. So finally I went on for 2D and extended the code. Now it works.
Yes, it's kind of anti-aliasing.
For next I am thinking how to display multiple Elements with transparency (caused by anti aliasing or pregiven transparency).
Thats all for now.
For all who may be interested, heres my current Code.
#include <Adafruit_NeoPixel.h>

#define PIN_NEO_PIXEL  13
#define NUM_PIXELS     200
#define num_col 20
#define num_row 10
#define DELAY_INTERVAL  100

float circle_PosX = 6;
float circle_PosY = 6;
int circle_direction = 1;

Adafruit_NeoPixel NeoPixel(NUM_PIXELS, PIN_NEO_PIXEL, NEO_GRB + NEO_KHZ800);

void setup()
{
  NeoPixel.setBrightness(255);
  NeoPixel.begin();
  // Serial.begin(115200);           // set up Serial library at 9600 bps
}

float worldSpeed = .01;

void loop()
{
    if(circle_PosX <= 0 && circle_direction < 0
     || circle_PosX >= 20 && circle_direction > 0
     || circle_PosY <= 0 && circle_direction < 0
     || circle_PosY >= 10 && circle_direction > 0)
    circle_direction *= -1;
    circle_PosX += worldSpeed * circle_direction;
    circle_PosY += worldSpeed * circle_direction;

    NeoPixel.clear();

    //Kreis malen
    drawCircle();

    NeoPixel.show(); // send the updated pixel colors to the NeoPixel hardware.
    // delayMicroseconds(500);     // off time
    // readInput();
}
uint8_t bitmap[5][5] = {
    {0,0,1,0,0},
    {0,1,0,1,0},
    {1,0,0,0,1},
    {0,1,0,1,0},
    {0,0,1,0,0},
};

void drawCircle() {
    for(uint8_t pixelX = 0; pixelX < 5; pixelX++) {
        for(uint8_t pixelY = 0; pixelY < 5; pixelY++) {
            if(bitmap[pixelY][pixelX] == 1) {
                writeCircleToLEDs(
                    pixelX + circle_PosX,
                    pixelY + circle_PosY);
            }
        }
    }
}

uint8_t writeCircleToLEDs(float circlePosX, float circlePosY) {
    int lowerLedX = floor(circlePosX);
    int upperLedX = ceil(circlePosX);
    int lowerLedY = floor(circlePosY);
    int upperLedY = ceil(circlePosY);

    float upperLedXAmount = circlePosX - lowerLedX;
    float lowerLedXAmount = 1.0 - upperLedXAmount;
    float upperLedYAmount = circlePosY - lowerLedY;
    float lowerLedYAmount = 1.0 - upperLedYAmount;

    float amountLowerXLowerY = lowerLedXAmount * lowerLedYAmount;
    float amountUpperXLowerY = upperLedXAmount * lowerLedYAmount;
    float amountLowerXUpperY = lowerLedXAmount * upperLedYAmount;
    float amountUpperXUpperY = upperLedXAmount * upperLedYAmount;

    setColorOfLed(lowerLedX, lowerLedY, amountLowerXLowerY);

    // if(lowerLedX != upperLedX)
    {
        setColorOfLed(upperLedX, lowerLedY, amountUpperXLowerY);
    }
    // if(lowerLedY != lowerLedX )
    {
        setColorOfLed(lowerLedX, upperLedY, amountLowerXUpperY);
    }
    // if(lowerLedY != upperLedY )
    {
        setColorOfLed(upperLedX, upperLedY, amountUpperXUpperY);
    }
    /*
    Serial.print("circlePosX ");
    Serial.println(circlePosX);
    Serial.print("lowerLedX ");
    Serial.println(lowerLedX);
    Serial.print("lowerLedXAmount ");
    Serial.println(lowerLedXAmount);
    Serial.println("--------------------");*/

}

void setColorOfLed(uint8_t ledX, uint8_t ledY, float amount) {
    int ledNumber = ledByCoordinate(ledX, ledY);
    uint32_t  baseColor = NeoPixel.getPixelColor(ledNumber);
    uint8_t newRedColor = ((baseColor >> 16) & 255);
    newRedColor += (255 * amount);

    baseColor &= ~(255 << 16);
    baseColor |= (newRedColor << 16);

    NeoPixel.setPixelColor(
        ledNumber,
        baseColor);
}

uint8_t ledByCoordinate(uint8_t coordinateX, uint8_t coordinateY) {
    return coordinateX + num_col * coordinateY;
}

uint8_t rowReadPosY = 0;
void readInput() {
    bool changed = false;
    uint8_t rowReadPosX = 0;

    while(Serial.available() > 0) {
        char input = Serial.read();

        if(!isDigit(input)) continue;

        bitmap[rowReadPosY][rowReadPosX] = atoi(&input);

        rowReadPosX++;
        if(rowReadPosX >= 5) {
            rowReadPosY = ++rowReadPosY % 5;
            rowReadPosX = 0;
        }

        changed = true;
    }

    if(changed) {
        Serial.println("Ergebnis: ");

        for(uint8_t pixelX = 0; pixelX < 5; pixelX++) {
            for(uint8_t pixelY = 0; pixelY < 5; pixelY++) {
                Serial.print(bitmap[pixelY][pixelX]);
            }
            Serial.println();
        }

        Serial.print("Aktueller Cursor: (x,y) {");
        Serial.print(rowReadPosX);
        Serial.print(", ");
        Serial.print(rowReadPosY);
        Serial.println("}");
    }
}


text:
RGB LED randomized colors and LDR fading at the same time
Im trying too make an RGB LED that keeps changing color's randomly, and makes the brightness fade at the same time with an LDR, yet I keep getting an error that says too many arguments to functions.
could anyone possibly help me?
EDIT:
(this is the correct code sorry)
 const int LED_D_RGB_G_PIN = 11;
const int LED_D_RGB_B_PIN = 10;
const int LED_D_RGB_R_PIN = 9;
const int LDR = A1;

int inputval=0;
int outval =0;

void setup() {
  pinMode(LED_D_RGB_R_PIN, OUTPUT);
  pinMode(LED_D_RGB_G_PIN, OUTPUT);
  pinMode(LED_D_RGB_B_PIN, OUTPUT);
  pinMode(LDR, INPUT);

}

void loop() {
    inputval = analogRead(LDR);
    outval = map(inputval, 0, 380, 255, 0);

    int lightval = constrain(outval, 0,255);

    analogWrite(LED_D_RGB_R_PIN, lightval, random(0,255));
    analogWrite(LED_D_RGB_G_PIN, lightval, random(0,255));
    analogWrite(LED_D_RGB_B_PIN, lightval, random(0,255));
    delay (50);
}

If you get an error during compilation, please include the full error (including the information where the error happened) in the question. Also: Doing two analogWrite calls on the same pins directly after another will not work. Only the second call for each pin will have any effect.

you have a logic error in your code ... you want to choose a random color, and then adjust the brightness of that color ... that is not what happens in your code ...  the code sets the three LEDs to random brightness... that sets a random color and random brightness at the same time ... you have to  choose a random full brightness color and then adjust the brightness without changing the color

I want it to keep changing colors randomly with the RGB while at the same time adjusting the brightness with an LDR. I just dont know how to make them do it separately. also I accidently unloaded the wrong code. sorry. The code I had the problem with was  with this at the end:
analogWrite(LED_D_RGB_R_PIN, lightval, random(0,255));
analogWrite(LED_D_RGB_G_PIN, lightval, random(0,255));
analogWrite(LED_D_RGB_B_PIN, lightval, random(0,255));
delay (50);

}

You need to put that code into your question, not into the comments where we cannot read it easily. So is there still a compilation error? Please inprove your question by editing it

analogWrite() accepts two arguments ... analogWrite(LED_D_RGB_R_PIN, lightval, random(0,255)); has three arguments ... that's why you received the compiler error message

like I already said, choose the color ... then adjust the brightness ... then output the value to the analog pins ... if you set the color directly, as in analogWrite(LED_D_RGB_G_PIN, random(0,255)), then you will have to replace the 255 with an LDR dependent value

I will assume that you can correct any errors in your code and I want to get at a suggestion for a possibly better approach to what I think that you are trying to do.
When you are setting the "color", you are setting the brightness of each of the LEDs; R,G,B, or at least you are trying to do that when you generate a random PWM using analogWrite https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/.
Then, you are trying to set the brightness again, presumably based on the ambient light value from the LDR AND it is set for the combined output of the 3 LEDs which are likely at different intensity values, since intensity was randomly chosen. The problem is, how can you scale the values perfectly so that you get the same color but at a lower intensity? I think that is much more difficult than you might believe...for a bunch of reasons.
I would suggest you try something along these lines, but keep some low expectations....

Use a variable called maxb, which changes the maximum possible value used in the analogWrite() values so that it it not always 255. You can adjust that value based on reading the LDR. You will have to do some experimenting and don't expect a huge range of values. Now, your color will still be picked at random, but with an adjustment for intensity.

You "should" try to use resistors on each of the RGB LEDs that will produce something close to equivalent brightness. This will vary somewhat between RGB LEDs. Below is a graph of where I looked at this for a color fader project many years ago. I used an old BH1750 ambient light sensor to get the lux values. That dashed line is for the equivalent brightness of the individual LEDs by resistor value (ohms) used [220-Red, 750-Green, 470-Blue]. This is not an ideal way, but it is easy.

That might get you near where you want to be, but for "extra credit", note that brightness scaling is not an equal interval scale. So, a PWM value of 250 is NOT 10 times brighter than a PWM value of 25. Brightness is, more or less, on an exponential scale except for very dim values, which are, again, more-or-less, linear. Look into the CIE 1931 perceived lightness formula and Weber and Stevens and so on. Since this is not a psychophysics lab, let me cut to the chase. The array below represents an intensity scale as I have described and includes values of 0 and 255 as per an 8 bit width (which is what analogWrite uses). You could use a minimum value of 4 or 8 instead of 0 if you wanted to guarantee a visible output every time. Test that out, but for the sake of discussion, let's assume you are using all values in the array.

A[13]{0,1,2,4,8,17,32,51,75,106,145,194,255};
You would scale your LDR range to 13 possible values (0-12) and then get your maximum value for analogWrite from the array. Then, you would pick a random value for 0 to maxb for each of your analogWrites to the RGB.

I don't know how brightness is represented by your LDR and you should consider that when you are determining your ambient light intensity values - ideally, you would want 13 equal intensity values from your LDR - right?. I suppose something about that is probably in the data sheet.

That is how I would do it anyways :)

Thank you! this helps a lot! I didn't think it would be easy from the start but this helped me understand just how difficult it is. I will definitely start to experiment with the code some more and hopefully ill get a satisfactory result!


text:
Can the Arduino Uno use a negative supply voltage (0V & -5V)
I acquired a bread-making machine. See control board image.
I want to use the machine for other purposes and control the buttons, paddle, heater & 7-segment display with an Uno.
As it stands, the machine provides 0V, -5V & -11V to the control board.
Is it possible to connect 0V to Uno VIN and -5V to Uno GND pins?
My initial idea was to replace the PENTALPHA-BV30K with an Uno and mapping the pins accordingly. I couldn't find any datasheet for the BV30K, however I'm reverse engineering the control board anyway.
Control board findings:

-11V is used to drive the A/B/C/D/E/F/G/DP segments of the LED display
BV30K only uses 0V & -5V

I added an image of the transformer based power supply board so that I could check the supply there. The larger heatsink is for the 7905 IC and the smaller heatsink is for the BTA06 Triac.

"0V, -5V & -11V" How do you know your meter probes aren't just swapped?

Voltages measured with Black (COM) meter probe connected to 0V & Red meter probe connected to -5V  & -11V on the larger white header on the control board. The header is also labelled as such.

I saw the - on the header silkscreen. It looks just as easily like a poor choice of punctuation. This is part of why I asked. Is there an ground plane in this thing? Is there a place that strapped the metal parts are strapped together that cross checks as showing -5 when you put your positive probe on the thing that says "5V" or "-5V" depending on how you look at it. If there isn't scarcely makes a difference if your UNO is running in the same system, because -5 to 0 is still 5V. The UNO doesn't much care what you label ground as long as whatever it's talking to agrees with it.

I ask mostly because it may just be a matter of perception and there's much of a question here. I wouldn't expect -5V and -11V in that thing unless maybe it's from the 70s and I guess, for that time, very high end.

I originally thought  that the "dash" was just bad punctuation.
I then started to reverse engineer the control board circuit. Those switching transistors are A1015, PNP. The emitter (in most) is strapped to (what is labelled) 0V. The collector is strapped, through a resistor, to (-)5V. The base is connected, through a resistor to a control pin on the IC BV30K. That's when I realised it must be negative 5V, relative to 0V. Otherwise the switching circuit would not work.
When testing with a meter there does not appear to be a connection between the metal earthed chassis and 0V on the board.

!! CAUTION !! ... the bread maker board may have powerline voltage on it, relative to earth ground

I'm not really sure what would make decent answer to this. What can be said about the Arduino in this context is just true of electronics generally. That circuits, independent of any other concern, care what what voltage difference is applied across them. The UNO is not somehow an exemption to this. So if you have any two voltage numbers that are 5V different, say -7805 VDC and -7800 VDC (to pick something absurd) you can put them in the right order to make a 5V "positive" difference. The thing is I get the sense from your comments you're at least that far along in your understanding.

Thanks for your comments guys. I normally would have just tried it after satisfying my own doubts - I just didn't want to cremate the Uno just yet. Anyway, I connected 0V to Uno VIN and -5V to Uno GND pins and all is well ;) I guess I'll put "yes" as the answer but really not sure why it was designed with the negative supply.

Has this device got a transformer in its power supply to isolate it from the mains voltage? If not, then it will be using some sort of transfomer-less power supply which will probably not be able to supply much more current to drive the Uno and any connections to that board risk bringing mains voltages outside. If in doubt, use optocouplers for any connections and a separate power supply for the Uno. Optocouplers would anyway make the +5v / -5v issue irrelevant.

How far have you reverse engineered the circuit now? What is the -11V good for? As long as all pins of the BV30K are in the 0V to -5V range, I would go on.

@6v6gt It's a transformer power supply - see updated images. I notice there's an optoisolator there too.

@thebusybee The -11V is used to drive the A/B/C/D/E/F/G/DP segments of the LED display. The BV30K only uses 0V & -5V.

The image of the power supply board suggests that there is no separation between powerline and the low-voltage parts. Make sure to protect yourself. However, you can connect the Uno directly. Just prohibit connections to PCs or humans during operation. -- BTW, please add requested information to the question. Down here in the comments other visitors will not read it. ;-)

@thebusybee - Added info to the question. I'm interested in what you said about the powerline separation. There is a large air gap on the underside, there is a transformer and there is an optoisolator, which I haven't looked at yet but will do. Granted, the separation could be better. Once finished the boards will be housed exactly as they were before in the bread machine, separated by about 15cm and a metal plate. Interaction with humans will be the only way the machine will work ;) The make/model is a Ronson 9110. This may be sliding off-topic a bit but it all helps build a good answer.

@thebusybee - Also, I was thinking that I could use the -11V supply instead of the -5V supply and connect the USB to program in situ, overriding the USB power supply. Thoughts on that?

As you describe the system, you can connect the system's ground to 5V of the Uno, and the system's -5V to Uno's ground.
Please note that you cannot reverse-feed 5V through the pin with the same label, it is an output. You can use the USB connector. You might want to solder wires at its pins instead of cannibalizing an old USB cable. Alternatively you can try VIN, as there is a LDO, but measure the resulting voltage. The specification demands at least 7V there.
If you want to power the Uno during development by the USB connection, you can disconnect any of -5V or ground, but not both, because you need a reference connection.
In contrast, you cannot use the -11V supply and use VIN and GND of the Uno, because the Uno's voltage regulator uses the lower level as reference and will set Uno's "high" (5V) to about -6V with reference to the system's ground. See:

Concerning the separation of power-line and the controller: Well, I'm just worrying about your health.
If you are sure that all is done well, go ahead. With a working separation you can even dare to connect the development PC to your Uno while the power-line is connected.


text:
Grove LCD display not working with arduino rev 2 wifi (Unknown error at address 0x3E)
I am trying to connect Grove 16x2 LCD (White on Blue) to my Arduino uno rev 2 wifi.
So far, I've tried hd44780 library's ioClass examples, but nothing worked. I've then decided to scan ports and when LCD was connected to rev 2 SDA/SCL pins I've got (Unknown error at address 0x3E). So it recognizes that something is connected, but doesn't recognize the LCD. I've also tried to run I2CexpDiag, which also returned "Unknown error at address 0x3E".
I tried the same LCD with Arduino UNO and mkr1010, both work flawlessly. I've also tried connecting the SDA/SCL pins to A4/A5, but nothing there either.
Any ideas what could be the problem?

https://wiki.seeedstudio.com/Grove-16x2_LCD_Series/ > Step 1. Download the Grove-LCD RGB Backlight Library from Github.

Just tried it, tried a couple of examples, but nothing comes up on the screen.

Uno WiFi has some on-board I2C devices. run the I2CScanner sketch

Yes, it does recognize something on 0x60

does the scanner show the address of the LCD?

Yea, like I've mentioned, I get an error "Unknown error at address 0x3E", which is the address of the LCD. However the LCD works with other boards flawlessly

You are not alone https://forum.arduino.cc/t/issue-with-i2c-between-arduino-uno-wifi-rev2-and-grove-16x2-lcd/609423/2 Except for the base shield switch, no answer is there. Here https://forum.arduino.cc/t/surenoo-rgb-i2c-lcd-unstable-i2c-communication-solved/666902/67 a VERY long thread on a similar LCD/problem. Maybe worth trying this library https://werner.rothschopf.net/202009_arduino_liquid_crystal_wire_en.htm with the Grove settings.

Yea, have tried that library, but no luck


text:
Setting pinmode() in header file
I am trying to have a header file to handle all my pin definitions and pinmodes.
This is the header:
#ifndef __HEADER_TESTER__
#define __HEADER_TESTER__

#include <SoftwareSerial.h>
const byte rxPin = 2;
const byte txPin = 3;
SoftwareSerial mySerial(rxPin, txPin);

pinMode(LED_BUILTIN, OUTPUT);

#endif

However, when I compile this, I get an error on the pinMode(LED_BUILTIN, OUTPUT); line:
expected constructor, destructor, or type conversion before '(' token

try including the header file from inside setup()

@jsotola I got the same error...

Except for the preprocessor directives, none of this belongs to a header.

The pinMode() statement is executable code and can not be executed outside of a function - setup(), loop(), or some other function defined by you. One could imagine defining a function in your header (.h) file to set your pin modes but defining code in a header will cause a different kind of problem (multiple definitions) if you ever add another code module, a .cpp file, for instance, that also includes this same .h file.
Pin modes are usually set in the setup() function, once per execution of the sketch. There really isn't much value to having them in the .h file. If it is for documentation purposes, you could #define in the .h file, a symbol that expands to all of the pinMode() calls you need, then write that symbol at the appropriate place in your setup() function where it's expansion will be syntactically correct. This would accomplish the documentation, but at the cost of a reader of your code having to search for the definition of that symbol to find out what code is being executed there. That's pretty roundabout for what seems like little to no gain.


text:
How to connect Arduino Nano to Thermal Printer via serial connection
I have a generic Arduino Nano board that uses the old bootloader. I have the printer and the Arduino connected like so:

This is my code:
#include "Adafruit_Thermal.h"

// Here's the new syntax when using SoftwareSerial (e.g. Arduino Uno) ----
// If using hardware serial instead, comment out or remove these lines:

#include "SoftwareSerial.h"
#define TX_PIN 5 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 6 // Arduino receive   GREEN WIRE   labeled TX on printer

SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor
// Then see setup() function regarding serial & printer begin() calls.

// Here's the syntax for hardware serial (e.g. Arduino Due) --------------
// Un-comment the following line if using hardware serial:

//Adafruit_Thermal printer(&Serial1);      // Or Serial2, Serial3, etc.

// -----------------------------------------------------------------------

void setup() {

  // This line is for compatibility with the Adafruit IotP project pack,
  // which uses pin 7 as a spare grounding point.  You only need this if
  // wired up the same way (w/3-pin header into pins 5/6/7):
  // pinMode(BUILTIN, OUTPUT); digitalWrite(7, LOW);

  // NOTE: SOME PRINTERS NEED 9600 BAUD instead of 19200, check test page.
  mySerial.begin(9600);  // Initialize SoftwareSerial
  //Serial1.begin(19200); // Use this instead if using hardware serial
  printer.begin();        // Init printer (same regardless of serial type)

  // The following calls are in setup(), but don't *need* to be.  Use them
  // anywhere!  They're just here so they run one time and are not printed
  // over and over (which would happen if they were in loop() instead).
  // Some functions will feed a line when called, this is normal.

  // Font options
  printer.setFont('B');
  printer.println("FontB");
  printer.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  printer.setFont('A');
  printer.println("FontA (default)");
  printer.println("ABCDEFGHIJKLMNOPQRSTUVWXYZ");

  printer.sleep();      // Tell printer to sleep
  delay(3000L);         // Sleep for 3 seconds
  printer.wake();       // MUST wake() before printing again, even if reset
  printer.setDefault(); // Restore printer to defaults
}

void loop() {
}

When I run my code or reset no prints get sent to the print.
Here's what I've tried.

Ensure power is on on both devices
Try baud rate 19200
Swop Tx and Rx cables around
Tried D5 and D6 for Tx and Rx

Any help would me much appreciated.

the printer cannot detect the data signals because it has no ground reference ...connect grounds together

Sorry I didn't show that in my diagram but I did connect ground and 5vcc together with the Arduino and the thermal printer. Is there anything else I can try?

the Vcc should no be connected ... the printer should have its own power supply

Tell what printer that is! It does not look like having a serial interface.

Your additional info about your printer tells me that it has a Bluetooth and a USB interface - but I can not see any other serial connection port.
So there is no way connecting this printer as-is to the arduino nano by some digital port pins.
You may decide to either buy the Thermal printer offered by Adafruit our search for a Thermal printer that clearly states that is has a "Serial Interface" or "Serial RS232 Interface" - no matter if that comes with "TTL" or not like the Adafruit printer.
The printer is intended to be connected to a USB host port (of an PC or RPi or so) or via Bluetooth (to an PC or Android phone).
It may offers a virtual serial interface over both USB and Bluetooth, but that is a speculation.
It may be possible to hack your printer. I think the Adafruit printer was modded by Adafruit. They may have bought a stock-printer and added the connector for the TTL interface. This may also be possible with the printer you have, but that is not in the scope of your question and highly speculative.

Sorry man, it's a Chinese machine I can't find a datasheet for it. It's made by Andowl. This site has the most information I've seen: https://www.electromannsa.com/products/goojprt-58mm-wireless-bluetooth-thermal-receipt-printer