text:
Unable to use RGB matrix and the serial monitor at once
Recently I bought the following matrix:
https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/overview
I own an Arduino Uno for those who are interested.
I got the 32x32 variant and I am very happy with it. I managed to connect all the wires correctly and get the examples of the library working.
The problem I am facing right now is I can't get it to work properly for a personal project of mine. Somehow I am unable to use the serial functions and the matrix library functions in one project.
Currently my project looks like this:
My Arduino is connected like this:

And the code I wrote is:
#include <gamma.h>
#include <RGBmatrixPanel.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>

#define CLK 8
#define OE  9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define D   A3

RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
String incomingCommand = "";

void setup() {
  Serial.begin(9600);
  matrix.begin();
  matrix.fillRect(0, 0, 32, 32, matrix.Color333(0, 0, 0));
}

void loop() {
  if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    char receivedChar = (char) incomingByte;
    incomingCommand += receivedChar;
  }

  if (incomingCommand.indexOf('#') > - 1 && incomingCommand.indexOf('%') > - 1) {
    String rawCommand = incomingCommand.substring(incomingCommand.indexOf('#'), incomingCommand.indexOf('%') + 1);
    rawCommand = rawCommand.substring(1, rawCommand.length() - 1);
    Serial.print("Following command received: ");
    Serial.println(rawCommand);
    if (rawCommand == "turnledon") {
      matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
    }
    incomingCommand = "";
    rawCommand = "";
  }
}

The idea is that a command gets sent from the serial monitor. Based on the command one led on the matrix will turn on. An example of a future command will look similar to this: "#drawPixel_X1_Y2%", hence the part that checks on "#" and "&".
The problem is that the functionality of the serial monitor isn't working with line 14 and 48 of the code. As soon as I remove those lines, the serial monitor works perfectly and I can receive and write to the serial monitor. I have no idea what is causing this.
I was wondering if someone ever faced a similar problem or knows what I am doing wrong right now.
Thank you in advance!

Please format the code so that it is possible to read. If you need to reference a line please add line numbers or better add a comment in the code.

Possibly you are running out of RAM. Your use of String is very inefficient. I suggest collecting the incoming data into a char array.

According to Adafruit https://learn.adafruit.com/32x16-32x32-rgb-led-matrix/overview these led matrixes require active scanning. It means that the RGBMatrixPanel will set up some scanning interrupt to refresh the screen periodically.
This can very much interfere with serial receive, as according to Adafruit, the panels require a serious data transmission all the time.
Try the followings:

have one byte serial commands, e.g. N for "on" and F for "off" (I know you will need more complex commands, but this is just to verify the theory)
remove all debug Serial.printlns (those also consume some time)

So try this:
void loop() {
  if (Serial.available() > 0) {
    char incomingByte = Serial.read();
    if (incomingByte=='N') {
       matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
    }
    if (incomingByte=='F') {
       matrix.drawPixel(0, 0, matrix.Color333(0, 0, 0));
    }
  }
}


text:
Image from Arduino with camera ov7670 to Raspberry pi
i am stuck at sending picture to Raspberry pi from Arduino , how can i do this ? One way that i am using now is saving the picture on SD card module on the arduino , how to transfer that image to Raspberry pi? One problem is that the image on the SD card is in very "Raw format" which means , it needs to be converted to HEX and then we need to Add (bmp)headers or something i am not even sure, i have the python scripts that do this but the problem is it will slow down pi , and for my project its not acceptable that way. One other option is if i can stream the video that will be great . Some suggestions ?
Thank yoin
EDIT
About the process of Opening with HEX edtior:
The image data that Arduino is going to write to the SD card is raw image data i.e. just plain byte data-one byte for one pixel. If you try to open it as an image file then it won’t work. It is not in proper format to be read as an image. That’s why you need to write a bmp file with proper headers and use the raw image data to fill in for the pixel data in the bmp file. Now, here is the part where I cheated a little bit. I just opened up the file containing raw image data that Arduino wrote and opened it in a hex editor.
LINK: https://hkalasua.wordpress.com/2017/09/11/ov7670-arduino-sd/

I edited my question , you can check

you are misunderstanding what HEX means ... it is a human readable representation of a number, specifically a binary number ... it is easier to read FE23 than 1111111000100011 ... the file you mentioned is binary ... there is no hex conversion involved

send the image data to the RPi and use a python script to generate the bmp or png file

source: Stack Exchange

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

sort: votes


text:
Tx Rx Arduino uno
first of all let me thank you all , you have been of great help.
So, my problem is the next , i have note counter machine i need to read the data from the machine to the arduino , as bytes or ascii , just some readble data .
The machine is connected on the arduino via 2 pins , tx and rx and the data i am getting is not readble and kind of wierd , and one more question do i need some kind of serial shiled or no ?Because right now it is connected with just 2 wires . Thank you
#include <AltSoftSerial.h>

// AltSoftSerial always uses these pins:
//
// Board          Transmit  Receive   PWM Unusable
// -----          --------  -------   ------------
// Teensy 3.0 & 3.1  21        20         22
// Teensy 2.0         9        10       (none)
// Teensy++ 2.0      25         4       26, 27
// Arduino Uno        9         8         10
// Arduino Leonardo   5        13       (none)
// Arduino Mega      46        48       44, 45
// Wiring-S           5         6          4
// Sanguino          13        14         12

AltSoftSerial altSerial;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor to open
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
}
byte rx_byte =0 ;
char text ;
char hex;
void loop() {
  if (altSerial.available()) {
    // get the byte from the software serial port

   rx_byte = altSerial.read();
    // send a byte to the software serial port
    //altSerial.println(text);
  Serial.print(rx_byte, HEX);

}
     //Serial.println("TUKA SUM");
      //text = altSerial.read();

    //hex=(text);

  //Serial.print(text);
    //Serial.write(text);
  // Serial.println(text);

What is the code? And what is the weird output?

Please provide a link to the note counter you are using.

Why are you using soft serial and not 'hardware' serial? What is the output? And are you sure 9600 is the correct speed?

AltSoftSerial Test Begin
00FE0F00000000000000000000000000000140B50000000000000000009C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083000830000B4AFB400002F90008000007F0042000091000E700E2FF00000F001E00FE0080000000000007DFC00F0000000008000FF

This is what i am getting , and link is http://souqmega.com/product/nc3500-ma-value-counting-machine/

and yeah i am sure because i can set the baud rate in the machine ,

A picture is of no use. Is there a manual or datasheet you can link to?

Is the connection to the machine UART or RS-232?

baud rate of what? the RX and TX pins are for external display

https://manualzz.com/doc/6360685/nc-3500-series-multi-currency-banknote-counter

Are you using the 9 pin or the 5 pin port?

try interchanging tx and rx pins it worked for me after interchanging those pins

I am using the 9 pin port , and from the tx and rx on the serial cable i am conecting them to the rx and tx on arduino , or 8 and 9 in the sketch , there is no shiled on the arduino for serial cable , just two wires .

You are still just printing human readable hexadecimal characters, just like in your earlier questions. And your output consists only of characters, that are used to represent hexadecimal values in human readable form. So what output were you expecting from it? As I see the code, you cannot get other output than this hex represetation.

The 9-pin port is designed for connecting to a printer. It uses the RS-232 protocol, not UART.
You cannot connect it directly to an Arduino - you must connect it via a MAX232 adaptor board.
Disconnect the cable immediately - the voltage levels of RS-232 are likely to do permanent damage to the Arduino.

Yeah i saw it somewhere , i disconeteced it , so in conclusion there is no way just two wires from serial cable to tx and rx on arduino ?

Nope. You need to transform the voltage levels from -10V/+10V to +5V/0V.

So without MAX232 adaptor board i can do the thing i want , Okey , thank you a  lot .

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


text:
Detecting how many button presses(single tap, double tap etc) with two simultaneous buttons
noob here
So what I am trying to do is output a different number depending on the number of button presses e.g. for 1 button press it should output 1 and so forth. After that I only really want the outputs for 1 to 4 presses. I am using these inputs for a game.  Right now, it does work and counts up until 4 and then resets back to 0. The problem that I am having is it continues after 1 click to 2 clicks; what I want it to do is count 1 click when its clicked once, twice when its clicked twice etc. I am trying to use a debouncing code to distinguish between single tap, double tap, triple tap etc
@VE7JRO kindly provided a great solution to this problem, albeit it was for one button. I am trying to adjust the code to accommodate 2 separate buttons (on separate pins), but it is giving me an error.
This is the code:
#include <Bounce2.h>

// Connect both buttons in series with one connection
// to GND and the other to a digital pin.
const int buttonPin1 = 2;
const int buttonPin2 = 3;

class Button
{
  private:

    int m_buttonPin1;
    int m_buttonPin2;
    int m_counter;
    unsigned long m_buttonPressTimeout;
    unsigned long m_previousMillis;

  public:

    Button(int button):
      m_buttonPin1(buttonPin1),
      m_buttonPin2(buttonPin2),
      m_counter(0),
      m_buttonPressTimeout(1500), // Button press timeout 500 ms.
      m_previousMillis(0){}

    void Update()
    {
      int valA = digitalRead(button1); // read button stateint
      int  valB = digitalRead(button2); // read button state
       if (valA == LOW &&valB == LOW)
       {
      if(m_counter > 0 && millis() - m_previousMillis >= m_buttonPressTimeout)
      {
        Serial.print("Count from Update() just before it's re-set to 0 = ");
        Serial.println(GetCounter());
        m_counter = 0;
      }
    }

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

    byte GetCounter(){
      return m_counter;
    }

};

Bounce button1Debouncer = Bounce();
Bounce button2Debouncer = Bounce();
Button MyButton(buttonPin1);
Button MyButton(buttonPin2);

void setup(){

  Serial.begin(9600);

  pinMode(buttonPin1, INPUT_PULLUP);
  button1Debouncer.attach(buttonPin);
  button1Debouncer.interval(5);
  pinMode(buttonPin2, INPUT_PULLUP);
  button2Debouncer.attach(buttonPin);
  button2Debouncer.interval(5);

}

void loop(){

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

  // Button pressed.
  if(button1Debouncer.update() && button2Debouncer.update())
  {
    if(button1Debouncer.fell() && button2Debouncer.fell()){
      MyButton.IncrementCounter();
      Serial.print("Count from Button Debouncer = ");
      Serial.println(MyButton.GetCounter());
    }
  }

}
}

The error is: "'buttonPin1' is not a type", I do not understand this error as it didn't give that error for when a single button was used.

You write that you want it for a game. So probably you do not want count the presses but just see which button was pressed right? Do not call "digitalRead" many times if you want be fast. A better solution would be to read 7 pins with a single call with PIND, so you read pin 0 to 7 (advanced). Or, when I analyze your code, you just want to be notified of changes, you can use interrupts.

@Adriano I actually do want the number of presses. I think I should make it a little clearer: Fair point...I never really explained it
So, I have a player that needs to jump onto different platforms to collect coins and in each level the platform and coin numbers differ and because I am using the input device as a clicking distraction so in each level the amount of clicks needed to make the character move, changes
So in one level you need to press the buttons twice, thrice in the next level etc

I don't understand the problem you are trying to solve. How many separate buttons do you have? Is each button on a separate pin, or do you have a matrix of buttons? Can the user press more than one button at a time, and you want to detect how many are pressed at the same time? Let's call that numberOfButtonsPressed. Then are you also looking for the user to single-tap, double-tap, triple-tap, etc, some number of buttons? So you both have the number of buttons being pressed, and the number of times they are pressed?

You will need to handle "slop" in the input, where the user presses the different buttons at slightly different times. If they are trying to press 4 buttons, you might detect first one, then 2, then 3, then 4 buttons pressed. And because of bounce, you might see some of those button inputs switch rapidly between not-pressed and pressed for a few milliseconds before settling down.

You might try 20-50 mS. If you don't detect any change in button state for that long, you can consider the button state as stable and take a reading.

@DuncanC I have 2 buttons that are connected on separate pins, but the user has to press both buttons at the same time to register one push. So, the problem I am having is how to distinguish between one push and two pushes etc. So, you suggest that I handle "slop" in this instance?

You need to debounce your buttons. That can be done pretty easily in software. Do a google search, but the basic idea is that when you detect a button press (or a 2-button press, in your case) you record the value of millis(), and ignore changes in the digital inputs for some constant waiting period. (20-100 mS is a good range to work with, depending on the situation.)

@DuncanC I was actually thinking I could get away without debouncing this (as it works well without that till this point), but it seems like I have to delve into that. Thank you

Writing your own debouncing code is actually pretty easy. You just need to record the millis() reading when a first button changes state, and ignore further state changes for a small interval.

@DuncanC I have tried a debouncing code today but now the serial monitor isn't outputting anything. Could you take a look at my updated code?

If it’s possible to connect the 2 buttons in series, then this sketch may give you the desired results.
#include <Bounce2.h>

// Connect both buttons in series with one connection
// to GND and the other to a digital pin.
const byte buttonPin = 2;

class Button{

  private:

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

  public:

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

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

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

    byte GetCounter(){
      return m_counter;
    }

};

Bounce buttonDebouncer = Bounce();
Button MyButton(buttonPin);

void setup(){

  Serial.begin(9600);

  pinMode(buttonPin, INPUT_PULLUP);
  buttonDebouncer.attach(buttonPin);
  buttonDebouncer.interval(5);

}

void loop(){

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

  // Button pressed.
  if(buttonDebouncer.update()){
    if(buttonDebouncer.fell()){
      MyButton.IncrementCounter();
      Serial.print("Count from Button Debouncer = ");
      Serial.println(MyButton.GetCounter());
    }
  }

}

EDIT
Based on your last update to the question:

I am trying to adjust the code to accommodate 2 separate buttons (on separate pins), but it is giving me an error.

I have updated the sketch to use 2 buttons on separate digital pins.
#include <Bounce2.h>

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

class Button{

  private:

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

  public:

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

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

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

    friend void IncrementCounter(Button&);

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

    byte GetCounter(){
      return m_counter;
    }

};

Bounce buttonOneDebouncer = Bounce();
Bounce buttonTwoDebouncer = Bounce();
Button ButtonOne(buttonPin);
Button ButtonTwo(buttonPin2);

void setup(){
  Serial.begin(9600);
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  buttonOneDebouncer.attach(buttonPin);
  buttonTwoDebouncer.attach(buttonPin2);
  buttonOneDebouncer.interval(25);
  buttonTwoDebouncer.interval(25);
}

void loop(){

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

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

  // Button two pressed.
  if(buttonTwoDebouncer.update()){
    if(buttonTwoDebouncer.fell()){
      if(digitalRead(buttonPin) == 0){
        ButtonOne.IncrementCounter(ButtonTwo);
      }
    }
  }

}

thank you, I will try this. Does this use an external library? @VE7JRO

Yes, the Bounce2 library. It's available in the IDE library manager.

Ah okay, I will try this out thank you @VE7JRO

Thank you; it works rather well...now just have to figure out how to connect two separate buttons on two separate pins @VE7JRO

@user19964 - It's easy to add another button. Define another variable such as buttonPin2, then do something like this Bounce buttonDebouncer2 = Bounce(); and this Button MyButton2(buttonPin2);. A bit of copy / pasting should get 2 buttons working quickly. The most difficult part will be to change the logic in the loop() to work with two buttons.

for the loop() couldn't you just add something like: if(button1Debouncer.update() && button2Debouncer.update())
{
if(button1Debouncer.fell() && button2Debouncer.fell())}} ? @VE7JRO

@user19964 - I think you could do something like that. Perhaps, when one of the buttons is pressed, "it's" function in the loop() could also do a digitalRead on the "other button". That piece of information could be useful to determine if both buttons are actually pressed at the same time, at that very moment in time.

Let us continue this discussion in chat.

@VE7RO I have only seen this now and I tested it immediately. As I hadn't seen this, I had still been struggling for days with this question :(. THANK YOU SO MUCH!! Just tested it and it works well; I really do appreciate all the help that you've given me with this question :). Have an awesome day!

Your updated code has lots of problems. To do button debouncing, try something like this:
//Adjust debounceTime as desired. Shorter times will make fore faster button
//response, but make the debouncing less effective. 50 is 1/20th of a second.
#define debounceTime 50

unsigned long nextButtonCheckTime = 0;
bool buttonAState = false;
bool buttonBState = false;

void loop() {
  //Only check the buttons if the debounce time has passed
  if (millis() > nextButtonCheckTime)
    bool newButtonAState = digitalRead(buttonAPin) == LOW;
    bool newButtonBState = digitalRead(buttonBPin) == LOW;
    //If one or both buttons have changed state
    if  (buttonAState != newButtonAState || buttonBState != newButtonBState)) {
      nextButtonCheckTime = millis() + debounceTime;
      buttonAState = newButtonAState;
      buttonBState = newButtonBState;
      //Handle change of button state
    }
  }
}

That is pseudocode. It almost certainly contains syntax errors. You should use it as a guide, and rewrite it to suit your needs. Do not say "I copied your code into my sketch and it won't compile."

Thank you; this does help as a guideline indeed. I will use it accordingly @DuncanC

You SHOULD pay attention to the following issues:
1. Floating input problem:
Symptom: the reading value from the input pin is not matched with the button's pressing state.
Cause: input pin is NOT used pull-up or pull-down resistor.
Solution: Use pull-up or pull-down resistor. See Arduino Button (with pull-up/pull-down)
2. Chattering phenomenon
It should be considered in only some application that needs to detect exactly number of the pressing.
Symptom: Button is pressed one, but Arduino code detects several times.
Cause: Due to mechanical and physical issues, the state of the button (or switch) is quickly toggled between LOW and HIGH several times
Solution: Debounce. See Arduino Button Debounce

Thank you for the tips. I Have a pull up resistor on both my buttons and I had implemented a debounce code in this code. I am getting pretty much the same thing as before @Rozona Zoro

It is likely you are experiencing problems associated with button contact bounce. This is where the processor is so fast that it "sees" the button make several contacts when the user only intends for 1 contact to be seen by the program. Consider using this button de-bounce library instead of reading the state of the buttons directly in the sketch.
The code for the above debounce Arduino library is hosted here at github.com. In general, people using github.com will have an "example" folder along with the source code and documentation folders.  The debounce Arduino library example folder is here.  There are about half a dozen Arduino sketch examples including this 2 button example which might be used as the starting point for the project in the question.
There may be a logic problem in the code when interpreting the number of button presses into "a", "b", "c" & "d".  The modulo operator "%" is used.  And in the first test, the number of button presses % 1 is tested. If the result is zero the test is true.  As any number % 1 has no remainder this test will always be zero and therefor always true.  As all other tests are nested inside "else" statements none of the other tests will be executed.  Instead consider using a switch / case statement where the code switches on the number of button presses and the case statements are "case 1:", case 2:", "case 3:" & "default:".  It is good coding practice to always have a "default:" case in a switch statement.  Here we use "default:" instead of "case 4:". After using the value representing the number of button presses, always remember to clear this value before the next iteration.  Remember, any "global" values (values defined outside a function) will retain their values between calls to that function. Any "local" value (values defined inside a function) will not retain their values and need to be initialize each time they are used.

are there any examples showing how to implement this library...I have it imported to my project but am not sure how to implement it @st2000

I'll add where to find examples in my answer.
Also, I appreciate you editing your question to make it better.  I added text to your question to make it clear more information was added and what that information is showing.

yes, I see that you've edited my question: thank you...it reads much better now. Yes, those examples would be much appreciated @st2000

@st2000just thought to mention that the counter is working now, but it isn't working exactly how I would like it to.

You are using the Modulo "%" operator.  I do not think that is what you want.  For instance, you can divide any integer by 1 and not get a remainder.  So 1 % 1 is 0, 2 % 1 is 0 anything % 1 is 0.  That statement is always true and nothing below it will execute.  You will always print out "a".  Do you want me to alter my answer again?

ah yes, this makes sense...so much sense. When I used if(buttonPushCounter ==1) etc, it didnt work either l. Yes, i would appreciate that @st2000

Thank you very much for your extensive answer. I did go through the solutions there and added it to my own solution. As required. The counter works now, it outputs as it should and it resets when it should too: all as intended. I have edited my question accordlingly @st2000


text:
Library not found when using the arduino-cli command (although working with the Arduino IDE)
I have a sketch which I can upload without problem with the Arduino IDE. I installed the arduino-cli  Version: 0.28.0 Commit: 06fb1909 Date: 2022-10-18T15:53:04Z. I want to compile and upload a code on an arduino uno and use the command line
arduino-cli compile --fqbn arduino:avr:uno mysketch.ino

but get the following error:
/path/to/mysketch.ino:44:10: fatal error: LiquidCrystal.h: No such file or directory
 #include <LiquidCrystal.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.

Used platform Version Path
arduino:avr   1.8.5   /Users/user/Library/Arduino15/packages/arduino/hardware/avr/1.8.5

Error during build: exit status 1

how could I proceed to debug?

/path/to/mysketch.ino looks like an invalid path

@jsotola. Thank you for your comment. It is indeed not the real path. I edited it for the question. But it is the path where the .ino file is

how to debug? ... if your OS is Windows ... download process monitor from Microsoft ... use it to figure out where the program is looking for the file ... https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

The LiquidCrystal library is bundles with Arduino IDE 1 so it is not installed in your sketchbook folder's libraries folder so CLI can't find it.
Install the library with Arduino CLI or simply copy it from Arduino IDE 1 installation folder into libraries folder of your sketchbook.

many thanks for your answer @Juraj. what would be the command to install it with the Arduino CLI?

@ecjb you work with CLI and you don't know the commands? https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_lib_install/

The command is: arduino-cli lib install LiquidCrystal for future visitors' convenience.


text:
Arduino Nano ESP 32 board (ABX00083) SD library not working
I am working on a simple code to write data to a MicroSD card using Arduino nano ESP32 (ABX0083) and Df robot SPI MicroSD card module(DFR0229). I am not able to write to the SD card. I get the error condition "Error opening dta.txt for writing.".

All pins are connected correctly.  SD.h module is used. Pins are connected according to arduino nano-ESP pinout https://docs.arduino.cc/resources/pinouts/ABX00083-full-pinout.pdf

The default pinout used is"Arduino". The code works well with Arduino UNO. Following is the code.
#include <SPI.h>
#include <SD.h>

// Define the chip select pin for the SD card module
const int chipSelect = 10;

void setup() {
  // Start the serial communication
  Serial.begin(9600);
  //pinMode(chipSelect, OUTPUT);
  pinMode(chipSelect, OUTPUT);

  while (!Serial) {
    // Wait for the serial port to connect (needed for Leonardo and Micro)
  }

  Serial.println("Initializing SD card...");

  // Initialize the SD card
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // Don't do anything more
    while (1);
  }
  Serial.println("Card initialized.");

  // Open the existing file for writing
  File dataFile = SD.open("dta.txt", FILE_WRITE);

  // Check if the file opened successfully
  if (dataFile) {
    Serial.println("Writing to dta.txt...");

    // Write some example data
    dataFile.println("Appending new data");

    // Close the file
    dataFile.close();
    Serial.println("Data written to dta.txt successfully.");
  } else {
    // If the file didn't open, print an error
    Serial.println("Error opening dta.txt for writing.");
  }
}

void loop() {
  // Nothing to do here
}

At first make sure that the chip select (CS) pin is correctly defined and connected. The pin numbers might be different for the Arduino Nano ESP32.

The code work for Arduino Uno because it is the API for Arduino Uno's SD library. For Arduino Nano ESP32, it is an ESP32, so you should check the example for the ESP32 instead of the one for Uno. There are subtle differences, 1) unless you are going to reassign the SPI port, you don't need to pass-in the CS to SD.begin(); 2) For the ESP32 SD library, it is expecting a path instead of a filename when calling SD.open(), so it should be SD.open("/dta.txt", FILE_WRITE); instead of just dta.txt. See ESP32 SD library.

@hcheung turns out the problem was in declaring the file path.  It worked after putting "/ " as you suggested. Thanks.

The code work for Arduino Uno because it is the API for Arduino Uno's SD library. For Arduino Nano ESP32, it is an ESP32, so you should check the example for the ESP32 SD library instead of the one for Uno.
There are subtle differences:

unless you are going to re-assign the SPI port, you don't need to pass-in the CS to SD.begin();
Unlike the Arduino Uno SD library, which is expecting to pass in a filename, the ESP32 SD.open()is inherited from ESP32 FS library, which is expecting a path instead of a filename when calling SD.open(), so it should be SD.open("/dta.txt", FILE_WRITE); instead of just dta.txt.


text:
Can RX pin(s) be used as TX instead?

Title question. I do not need any receive communication pins, only transmission.

Actually, I need as many transmission pins as possible on any Arduino besides a Mega2560 (to re/write the EEPROM of slave devices). A Mega2560 has 23 TX/RX pin pairs.
Maybe I'm misunderstanding serial communication. And maybe some sort of multiplexing deal can work like One-Wire temperature sensors...such as softwareSerials[x].write()...

SoftwareSerial serialOne(2, 3); // Software Serial ONE
SoftwareSerial serialTwo(8, 9); // Software Serial TWO
                     // RX, TX

Is there a way to make all the pins using SoftwareSerial TX? Or do half need to be RX?

"Just take a better microcontroller, and that is all." - user1829200

What off-the-shelf microcontroller is geared for serial communication?

what are you trying to build?

@jsotola Two to 20 motor modules controlled by Arduino slave devices (such as Nanos) running simple equations are sent variables from a master device (such as an ESP32).

Are you aware that the Arduino (Uno, Mega2560) do not allow more than one instance of SoftwareSerial? are you sure, because one of the two example sketches uses two SoftwareSerial instances. Only one instance can receive at a time. Maybe that's what you were referring to, but OP only needs TX.

As far as I can see, you can use the same RX pin on all your SoftwareSerial instances. You'd only have to "sacrifice" one pin.

You could also have single serial connecting that's shared with all the Nanos, and add an id to each message. For example, "turn motor 3 on", where only the third Nano would take action on that message.

Ah, yes, thanks Gerben. (The ID approach is what I meant by the One-Wire analogy.)

You might wanna google for a transmit-only software serial library. That will also make the code smaller, as no receive code is included.

One way to communicate Arduino to Arduino device is UART (and Software Serial for additional pins). For the ESP32, it seems this allows 28 TX pins using Majenko's method (in their answer). In other words, slave 28 devices.
After further research, isn't I2C the clear route to go?

With more slave devices the less times per second to talk to them all
The application needs to have all the slave devices execute commands synchronously:

At least, the slave devices need to start functioning at the same time.

How many slave Uno's/Nano's can be connected to an ESP32?

Each device on an i2c network has a 7-bit address, so a single network theoretically supports up to 128 slave devices. In practice though, the limit is much lower. i2c slave chips often support only 8 different bus addresses, no more than 8 of that chip can be attached to the same i2c network.

https://mindbleach.com/words/2012/10/23/i2c-and-device-limits
Unclear answer:

https://forum.arduino.cc/index.php?topic=159860.0
https://forum.arduino.cc/index.php?topic=367961.0

You should be (though I haven't tested it) be able to set the RX pin to an unused pin number, such as 255.  Then the RX pin will do nothing.
#include <SoftwareSerial.h>

SoftwareSerial s0(255, 2);
SoftwareSerial s1(255, 3);
SoftwareSerial s2(255, 4);
SoftwareSerial s3(255, 5);
SoftwareSerial s4(255, 6);
// ... etc ...

The "can't have more than one instance" thing is to do with reception. You can't have more than one SoftwareSerial instance receiving at once - but you don't care about that, since reception is not being used.


text:
How can I use separate power source for the Arduino and the motors
How can use a separate power source for powering Arduino, and another battery for powering the motors?
How can I make connections through the motor driver module L298N? I know how normally we use one battery to power the Arduino as well as the motors. But I am facing the problem while using different power sources.

make sure all ground pins are connected together. And please edit your answer and insert a photo of your setup so others can spot your problem

I added the Image and want to know how the pins are connected when separate power source are used

please edit the image so it's clearly visible which cable goes to which terminal, especially on the arduino and the L298 module

That's what I want to know

seems correctly connected ... two control signals and ground connected between the arduino and the motor driver

Read the documentation of the motor driver module. If it doesn't seem to answer your question, update the question with a link to that documentation.

You already are powering the motor with a separate power source - the 9V battery (poor choice, btw). The Arduino is powered by the 5V from the Pi.

@Majenko Ya I know it's already connected but I want to know the actual connections of the pins, The connections made in the diagram are not properly visible

@AmitNikhade your post only asks about separate power supplies ... if you want to ask about control lines, then you should open a new post ... document exactly what module you have and how it is connected (pin numbers, signal names) ... give details about what you are trying to do

That motor driver has an optional on-board 5V regulator. It can be enabled / disabled with a jumper.
With that regulator enabled you just need to connect a ground and your control signals (ENA/IN1/IN2 or ENB/IN3/IN4).
If you disable that regulator (remove the jumper) then you need to provide power from the Arduino's 5V pin to the +5V screw terminal.
The ENx pin(s) (after removing any jumpers that may be on them) connect to any PWM capable pin (this is the speed control pin). IN1/IN2 or IN3/IN4 connect to any IO pin since these are just used to set the direction or control the braking modes.  ENA controls the speed of motor 1, and IN1/IN2 control the direction of motor 1. ENB and IN3/IN4 are likewise for motor 2.

You mean to say that do not remove the jumper of the 5v regulator and then connect the ENA/IN1/IN2  And It's ready.

PLus ground, but yes. That's right.

And the battery connections

Well, yes, of course. Without those there will be no power...

So I will be able to power the arduino with a separate battery or through USB. And what about the motor driver connections with the other battery for motors.

What about them? You connect them. You connect the battery to the connections for the battery.

It worked, Thank's

I completed the circuit as you said but my raspberry pi suddenly start booting and Now only showing a red light

Maybe your Pi's power supply is not good enough to power the Arduino as well as the Pi. They can be very picky.

It's working now. My god everything working well now


text:
How can I use Arduino Analog Uno pins as Digital pins?
How can I use Arduino Uno Analog Pins as Digital pins, So that I can Attach more components like sensors to the Arduino? My 13 pins are preoccupied and I want more.

with digitalWrite and digitalRead. what is your question? https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/#_notes_and_warnings

For Arduino Uno

yes for Uno. you tagged the question with [arduino-uno]

Can you provide me any code sample as an instance

Any of the analog pins (with exception of A6 and A7) can also be used as digital pins, just like any other pin of the Arduino. Just use pinMode(), digitalWrite() and digitalRead() on them, as you like.

Thank you Juraj and chrisl


text:
How do I control a conveyor to start and stop in same location using optical rotary encoder
I am a complete novice at arduino. I just want to know if this is possible before I start investing in components. I need to start and stop a chain drive conveyor {can't slip} powered by a 12 volt motor in the exact same place each time I manually start the cycle. I want it to stop automatically. The controller would have to power a relay to power the motor due to high amp draw of motor. This is on a piece of equipment without access to any other power supply but a 12 volt battery. I am looking at an optical rotary encoder to count the revolutions of the shaft. I would count the revolutions the shaft makes between my start and stop point and I assume enter that in the program. Is this possible?
Thanks

definitely possible .... it would be more reliable to sense the conveyer belt itself, in case there is slippage between the drive and the belt

That sounds fine. Just note that when powering up the system, you don't know the position of the conveyor. If you need that, you'd have to add something to manually "home" the conveyor, or add another sensor to find the "home" position of the belt. Ffor example adding a magnet to the belt, or a piece of reflective tape, and using a hall-effect sensor/photo-reflective sensor to find the "home" position. After that you only need to count rotations of the rotary encoder.

Would a hall sensor work in a dirty or wet environment?

Although your solution would work, it seems open to problems such as missed clicks, starting at a different place etc.
A better, more robust and error free solution might be to use a hall sensor.
Essentially what a hall sensor does is close a switch when a megnetic force is applied. So all you have to do is add a magnet to your conveyor/chain. This way, you can easily control where you want it to stop just by moving the magnet, and it doesn't matter what the starting position is because it will always stop as soon as the megnet reaches the sensor.


text:
How do I measure watts without a CT clamp?
I'm trying to build an "IoT" project for home that will in effect create a smartplug. I'd like to add the capability to measure the watt usage of the plug (and whatever's connected to it). I'd like to not use a CT clamp for this purpose, and I was hoping someone here can help.
I have a 220 V mains connection and I'd like to measure the watts used by a connected appliance to the smart plug is a small as possible form. CT sensors are too big for this purpose.
Thanks.

You don't need a clamp if you are building the plug.  What's wrong with a Current Transformer? Mouser sells a 1000:1 CT for less than 6$ that you could put in-line with one of your plug's leads.

I've seen a lot of people connect an Arduino to an existing power-meter, like e.g. a Kill-A-Watt meter.

You can't use a CT sensor to measure power.  CT sensors measure current.  Measuring Watts is the correct unit if you want to know the rate of energy consumption (power) from an outlet.
Response to a Comment: There are consumer devices that cost only $12.95 that might be ideal, if the only usage scenario is to compare various devices for steady state power draw and you are fine with 3% (1.5 digit) accuracy.  For the 220 VAC (whether split phase or single phase) you would need to gang two of them together appropriately.  These plug-outlet designs are nicely miniature, but will not support checking past values, providing feedback to a control system, or Wattage plotting against date, time of day, or tay of week.
Measuring of Wattage accurately (to two or three significant digits) is not trivial if the 220 Volt source is an AC power grid, thus the length of this answer.
The basic EE formula for power is P=IV for DC, meaning power is the product of current and voltage.  But you can't just go with Watts = 220 X current and expect any more than one significant digit of accuracy.  Grid Voltage may not be a clean sine wave and may vary five or ten Volts under normal conditions.
If you want more than one digit of accuracy, you'll need to calculate RMS (root mean square) power in Watts by sampling both Voltage and current and using the AC principles that extend the simple P=IV relation.   I don't know if you have knowledge of what electrical engineers call RMS.  In case you don't, the articles in the result set of This Search [1] may be helpful.
Let's hypothetically say you are considering doing the work necessary to get the two or three significant digits of accuracy in determining power consumption.  To get a sense of what that would entail, here's some information on doing that properly.  You will want to consider line voltage fluctuation, reduce your noise levels, protect your Arduino board from over-voltage, and follow electrical code reasonably well.
The below measurement fixture design is not small, but it could be miniaturized.  Unfortunately the design of a miniaturized version is large project FAR outside of the scope of an answer in this forum.  You may be one of those that likes the challenge, so I'll share a design for a larger version and leave it to you or other answering parties to think of a miniaturization that meets all these other reasonable goals.
Off the shelf parts to fabricate a full sized power measurement fixture to interface with an embedded board like the Arduino Due, for example:

Two electrical boxes
A length of electrical conduit at least 50 cm long
Electrical hardware to connect the two boxes and secure the AC cord leading to the plog and to the devices being powered.
Two lengths of 2-conductor 18 AWG shielded twisted pair cable with at least 500V rating
Code compliant AC cabling
Wire nuts
Box for the buffering circuit
A good quality digital Voltmeter with RMS AC as one of the options

Fabricate this way, but using proper code-compliant electrical practices in addition to these basic instructions for the main circuits:

Connect the plug to one of the boxes with properly rated AC cord.
Connect the two boxes with the conduit and properly rated power and return wires (white and black).
Connect the second box to the device
In each box, connect the 2 conductors of the shielded twisted pair in parallel to the AC circuit passing through the box with the wire nuts.  You must leave the shields of the two twisted pair lengths isolated (not connected to the box or the ground wire in the AC circuit.
Bring both twisted shielded pairs into the buffering circuit box.

The buffering circuit would condition each of the two AC voltage in three stages.

Surge protector
Resistor divider (see other Arduino articles for this)
Zener diode to further protect the A-to-D converter on the board

The Zener diode and the resistor divider would drop the voltage from 400 V down to below the max voltage of the Arduino board, which any of the voltages might be relative to the ground potential on the Arduino board under certain conditions.  The Arduino Due might be a good choice, because of multiple built in true A-to-D channels and the higher accuracy (digits resolution) than most other Arduino options.
The output of the box for each of the FOUR voltages would be connected to FOUR analog inputs.

Vph = the hot (black) coming from the plug
Vpr = the return (white) coming from the plug
Vlh = the hot (black) going to the load (devices to be powered)
Vlr = the return (white) going to the load

In the software you would probably want to measure the above four voltages in immediate succession (no delay between the four analogRead calls) every millisecond for a second, which will capture 60 cycles of data in 1,000 samples, enough to get three significant digits of accuracy in your power measurement.  The 60 samples of 4 channels can be thought of as 1,000 vectors of 5-dimensional data.  The fifth dimension is the time offset in milliseconds.
The software goal would be to calibrate the conversion of the 4 by 1,000 element array of analogRead integers to a 2 by 1,000 element array of doubles that represent instantaneous Voltage and current. Then power in Watts can be calculated from the Voltage-current data set.
When dealing with the 1,000 sample vectors, your loops will start with "for (int index = 0; index < 1000; ++ index) { ...".
You will need to convert your digital values representing the Voltages coming from your resistor divider to physical units.  These are the operations you would do on each sample.

V = Cv * (Vph - Vpr)
I = (Cih * (Vph - Vlh) - Cir * (Vlr - Vpr)) / R

V and I are the doubles that represent instantaneous Voltage and current respectively.
Cv, Cih, Cir, and R are also doubles. They are the calibration constants to convert the analogRead values to line voltages and currents.  A typical way to calibrate their values is to measure the RMS voltages across the three node pairs represented by each subtracted voltage pair in the inner parentheses above and the current, using some constant load.  A good load option would be some non-digital device that is fully warmed up and in some steady state.
From the voltages and currents and the digital values acquired from the four analog channels in the Arduino, with some algebra skill, one can determine the scaling factor C for each of the three cases, by dividing: (V1 - V2) / V, where V1 and V2 are the RMS values measured with the digital Voltmeter and V is the calculated RMS voltage from the samples.
R can be calculated by dividing the Voltage and current values V/I in accordance with the principles discussed in the articles referenced above.
Once you have calibrated your measurements for V and I in your block of 60 samples, the articles above give you some direction as to how to calculate your power in Watts RMS in a loop.
[1]: Search for "calculating rms watts from samples of voltage and current" via Google.

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


text:
Can I use a mobile charger (output 5V) to power an Arduino Uno?
I have made a home automation Arduino project using an HC-05 Bluetooth module. I want to power my Arduino from the main AC supply. Can I use a mobile charger/adapter to power it? Or should I buy a 12v adapter, and solder it to a barrel connector that fits the Arduino input?

Yes, you can. Both options are valid.

Yes you can use any options that you have mentioned in your question. One can say your question is your answer.

Can I use a mobile charger/adapter to power it?

The answer is almost yes: I use a phone charger myself.
Two reasons that it may not work out:

There are lots of unsafe, non-isolated, cheap phone chargers out there. Stay away from them. Use a brand name one that came with your phone.
Try to stay away from the QC2.0 or QC3.0. they are intelligent and negotiate the output voltage on the phone, up to 9 or 12v. They are compatible with non smart load but you don't want to run the risk.

Yes you can,
I tried with a sony 5V 850mA batery, it works.
I recommend you a multimeter if you haven`t had one before.

I am in the middle of this problem now and it seems the two out of three chargers I tried attempt to negotiate the voltage with my Arduino system. Those are Huawei and Meizu ones designed to be used with multiple devices of their respective brands. The multimeter reads solid 5.2V output before I flip the switch to Arduinos. Once I flip the switch the multimeter starts jumping hectically from 1.8 to 2.6v and all the LEDs on Arduinos and other components start flashing like a Christmas tree. Browning out, I assume. The adapter that works is a really cheap nameless one that I got for free in some package.
Plugging Arduinos into the battery bank and the charger into that battery bank seems to be a very stable and versatile solution that hasn't created any problems for me yet. Except that most battery banks have trouble producing over 2 amperes of current if your system needs that much.

Yes you can, simply connect the 5V VCC wire directly to VCC and connect GND to GND.
If using a 12V charger, then connect VCC to Vin.
DON'T FORGET GND TO GND

Or use a USB cable.

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


text:
I can't receive a letter using UART
I wrote a simple program where I transmit and receive a letter via UART. The transmit function works 100% but the receive interrupt function doesn't work at all... Can someone adjust the receive interrupt function so I can receive a string instead of a char?
#define FOSC 16000000 // Clock Speed
#define BAUD 9600
#define MYUBRR FOSC/16/BAUD-1

void setup() {
  USART_Init(MYUBRR);
  interrupts();
}

void loop() {
}

void USART_Init(unsigned int ubrr) {
  /*Set baud rate */
  UBRR0H = (unsigned char)(ubrr>>8);
  UBRR0L = (unsigned char)ubrr;
  UCSR0B = (1<<RXEN0)|(1<<TXEN0);
  //Enable receiver and transmitter */
  UCSR0C = (1<<USBS0)|(3<<UCSZ00);
  /* Set frame format: 8data, 2stop bit */
  UCSR0A |= (1 << RXCIE0);
  UCSR0C=0;
}
void USART_Transmit(unsigned char data) {
  /* Wait for empty transmit buffer */
  while(!( UCSR0A & (1<<UDRE0)));
  /* Put data into buffer, sends the data */
  UDR0 = data;
}

ISR(USART__RXC_vect) {
  char ReceivedByte;
  ReceivedByte = UDR0;
  // Fetch the received byte value into the variable "ByteReceived"
}

How do you know you can't receive it since you aren't doing anything with it if you do receive it?

under ReceivedByte = UDR0;
i put USART_Transmit(ReceivedByte);
but still i didnt receive anything at the serial monitor

Does the serial monitor still work if you are intercepting the data via interrupts?

no it didnt work
i dont know whats wrong with my code
i using termite , but still i didnt receive anything
how can i receive a letter via uart by interrupt ? and how to receive a string via uart

ISR(USART__RXC_vect)
{
  char ReceivedByte;
  ReceivedByte = UDR0;
// Fetch the received byte value into the variable "ByteReceived"
}

USART__RXC_vect is not the name of the interrupt vector, USART_RX_vect is.
If you don't get the name right there is no compiler warning, however the interrupt routine is not called.

UCSR0A |= (1 << RXCIE0);

That line is wrong. RXCIE0 is in UCSR0B not UCSR0A. If you set the bit in the correct register you will get an interrupt.

hey Nick .. i changed the name of the vector but still the interrupt function didnt work... ( i transmitted the received value )

Can you please edit your question to show the exact code you are currently using?  One thing you could do it turn on an LED (eg. digitalWrite (13, HIGH);) inside the ISR to test whether or not the ISR is called. Perhaps the transmitting of the received value is not working.

See amended reply.

thx a lot nick the code is now working ..
but whats the size of UDR0 because it can hold a whole string received via UART ,i thought it was 8 bits and can contain only a letter

UDR0 will hold one byte. I think the hardware has a double buffer (that is, it can receive the next byte while you are retrieving the most recently-received one).


text:
Why isn't DigiSpark automatically recognized on other computers?
I bought a DigiSpark (it is a development board based on the ATtiny85 microcontroller) yesterday and I wrote my first script.
I have no problems to run it on my personal PC (which I am using to program my DigiSpark). The problem is when I try to plug my DigiSpark to another PC, which doesn't have DigiSpark drivers installed. I tried to run it on two different PCs (Windows 7) and Windows just can not find DigiSpark drivers so my script does not run.
Of course I tried to plug in to different USB ports - unfortunately it did not help.
Any ideas what can I do to make my DigiSpark run on other PC without installing drivers by myself?
Thank you.

my script does not run. What do you mean by that?

I mean that DigiSpark is just not recognized by other PC. I have to install drivers manually first to make it working.

Make what working? What is your sketch doing that requires the PC to have the correct drivers?

Just open "CMD".

So you're running a keyboard emulation sketch, and your PC isn't recognizing it as a keyboard. So you don't really need the digispark drivers, but the keyboard "driver". Are you sure it's not being recognized? I've had similar problems, that it took too long for my PC to register it as a USB keyboard, and my code had already send the key commands. Try adding a few seconds of delay before sending the + keyboard-command.

Don't cross post

the digi spark make use of a bitbanged usb. (emulated usb).
because of this a new pc wont see a HID keyboard but a digi spark. only when the driver is installed it will automaticly switch to the HID driver for the emulated usb stack.
they pro micro has a hardware usb stack. this wil directly show a HID keyboard and work right away.

You will need to install the drivers before you can use it on other computers.
The drivers tell a Windows PC how to talk to the device.  The device is not a generic device so Windows can't use a fall back driver, like it could with a keyboard or monitor.

So there is not any way to make it install drivers automatically right? I am suprised because I saw on YouTube that it should work.

not true, https://www.reddit.com/r/arduino/comments/5ii5mv/why_digispark_is_not_automatically_recognized_on/
Yes, I try to get the DigiSpark to look like a keyboard to a host PC and execute a series of keystrokes. Here is my script: http://pastebin.com/dY05nbGY
permalinkembedparent
[–]cptskippy 3 points 5 months ago
Ok, you're using the DigiKeyboard library so that should make the Digispark show up as HID device. When you plug the DigiSpark into a PC where you haven't installed the drivers, does a "HID Keyboard Device" appear in the Device Manager under the Keyboards branch?
The Digispark powers up and executes the program immediately. My guess is that you probably need a delay in your code to allow the host PC to setup the interface.
#include "DigiKeyboard.h"

void setup() {
    DigiKeyboard.delay(5000);  // Wait 5 seconds before proceeding
}

int limit = 1;
int current = 0;

void loop() {
    DigiKeyboard.update();

    if (current < limit) {
        DigiKeyboard.sendKeyStroke(0);

        DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
        DigiKeyboard.delay(100);
        DigiKeyboard.println("ipconfig");
        current++;
    }

    DigiKeyboard.delay(5000);
}

permalinkembedparent
[–]readerpl[S] 2 points 5 months ago
You are the best!!! IT WORKS!!!!!

I faced the same issue when I first time used DigiSpark. After searching on the internet I found the solid answer that worked for me.
Arduino IDE from 1.66 to onward have not driver for DigiSpark so you have to install the driver manually when you will use Arduino IDE 1.66 or latest. But Arduino IDE 1.65 and some lower versions have support for DigiSpark.
When you will use say Arduino 1.65 and connect DigiSpark to USB port, then your PC/Laptop will automatically install the driver for DigiSpart.

did you read the question and other answers? sensai's answer explains it

Yes sensai's give the answer but I provided the answer that is not hear and it works. There maybe multiple solutions for a single problem and everyone must be discussed if you know it. That's why I shared my opinion.

but in the Question is that it is not about development computer with IDE, but about the target computer where the device is used as HID. so why do you write about IDE versions?

Sir, this is the question. "The problem is when I try to plug my DigiSpark to another PC, which doesn't have DigiSpark drivers installed. I tried to run it on two different PCs (Windows 7) and Windows just can not find DigiSpark drivers so my script does not run."
I answered it. I think now you can understand.


text:
How do I repurpose Arduino's reset button
Is there a way to repurpose the reset button for the code, like an on-board button? I don't need it to reset, but it would be useful to make it run through a list of RGB LED cycles.

You can store the current state in EEPROM, and detect when the board has been reset (there is a special register for it). So at startup you load the state back from the EEPROM and see if a reset has occurred. If so select te next pattern (and save that to the EEPROM).

If you just want the reset button to change the program mode, the
simplest thing would be to let the button reset the Arduino and switch
modes each time your program restarts. Then you do not need to change
the fuses or get a high voltage programmer. The code would look like
this:
void setup()
{
    // At startup, switch to the next mode.
    if (++mode >= NUMBER_OF_MODES) mode = 0;

    // etc...
}

There is just a small issue here: when the program starts, all the
global variables (like mode above) are supposed to be initialized by
the C runtime. This can be avoided by using a non-standard feature of
gcc: if you request the variable to be stored in the special .noinit
section, then it will not be initialized. Here is the program I used to
test this idea:
const unsigned int NUMBER_OF_MODES = 5;

__attribute__((section(".noinit"))) unsigned int mode;

void setup()
{
    // At startup, switch to the next mode.
    if (++mode >= NUMBER_OF_MODES) mode = 0;

    Serial.begin(9600);
    Serial.print("Current mode: ");
    Serial.println(mode);
}

void loop() {}

Now, each time I press the reset button, it goes to the next mode among
(0, 1, 2, 3, 4). The main drawback compared to using a regular input is
the delay added by the bootloader, which is slightly more than one
second.
A word about the cold boot initialization: the RAM is not initialized
by the hardware and contains essentially random bits. This means you
cannot count on mode having initially a valid value. This is why:

I am testing for ++mode >= NUMBER_OF_MODES rather than
++mode == NUMBER_OF_MODES, as the initial mode could be way larger
than NUMBER_OF_MODES
mode is an unsigned integer, otherwise I would need to also test for
it being negative.

As noted in other answers, if you re-purpose the reset pin, PC6, by programming the RSTDISBL fuse, then some of the usual methods of loading a program into flash memory are made unavailable.  Specifically, the usual serial-port programming using Arduino's Optiboot depends on the chip resetting upon demand.  So does ISP programming, as done for example using a USBasp or similar device.
However, parallel programming remains available.  This requires an STK500 or similar, or can be simulated using another Arduino.
Here are a couple of references from Atmel's doc8271 datasheet for ATmega48A/PA/88A/PA/168A/PA/328/P:

§14.3.2 Alternate Functions of Port C
  “When the RSTDISBL Fuse is programmed, this pin [PC6] functions as a normal I/O pin, and the part will have to rely on Power-on Reset and Brown-out Reset as its reset sources. ...”
§28.6 Parallel Programming Parameters, Pin Mapping, and Commands
  (Describes Parallel Programming wiring and protocol)

As it can be inconvenient having to hook up a parallel programmer to load new programs, instead of programming the RSTDISBL fuse you could modify the hardware.  You would cut the trace from the reset switch close to the switch (for example, lightly touch the trace with a fast-spinning 1-mm drill bit, using a small Dremel or drillpress), then run a fine jumper wire from the switch or its trace to an input pin.
This method leaves all the other reset-circuit stuff (pullup resistor to 5V, capacitor to DTR) in place so that ISP programming would work without change.

I concur with everything Maximus has said.
It is possible - you can change the reset pin to be a normal I/O pin.
To do so you will need to program one of the ATmega328P's fuse bits. For that you will need an ISP programmer like the AVRISPmkII or Atmel ICE. You will also need a program such as Atmel Studio or AVRdude.
The reset disable fuse is part of the high byte fuses. First you will need to calculate high fuse. I use eleccelerator Fusecalc for this
Based on my boards.txt file, the default for the high fuse on the Arduino Uno is DE. Adding the reset disable fuse makes it 5E.
Program the fuse using Atmel Studio or AVRdude using your ISP programmer.
Complete Fusecalc settings

The other answers weren't working for me (on an ATmega168), but I found this solution:
const unsigned int NUMBER_OF_MODES = 5;
int * mode;

void setup() {
    mode = (int *) malloc (sizeof (int));

    // At startup, switch to the next mode.
    if (++(*mode) >= NUMBER_OF_MODES) (*mode) = 0;

    Serial.begin(9600);
    Serial.print("Current mode: ");
    Serial.println((*mode));
}

output:
Current mode: 0
Current mode: 1
Current mode: 2
Current mode: 3
Current mode: 4
Current mode: 0


text:
Can I use the nRF8001 Bluefruit LE Breakout on 3.3V instead of 5V on my Arduino Uno?
I have an nRF8001 Bluefruit LE Breakout module and when I check images on how to wire it, the schematic looks like this with the 5V connection:

I was wondering whether it was possible to use the 3.3V instead. I looked at the documentation, it says this:

By connecting 5.0V on the VIN pin, all of the signals will be level shifted between 5V for the Arduino and 3.3V for the nRF8001, meaning you don't need to worry about damaging the IC by providing logic levels that it can't safely handle.

And this, which confirms that it works, right?

If you are using 3.3V logic, simply connect 3.3V from your development board to the VIN pin on the nRF8001 breakout.

I am pretty new, so I want to make sure, so I do not destroy any modules.
https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/hooking-everything-up

Yes. That nRF8001 board runs on 3.3V. And do make sure that using it with a 5V-Arduino, they put a regulator that steps down 5V to 3.3V. Which is why if you have 3.3V already, you connect it to Vin, and you're good to go.

Ok I use a standard arduino uno board. So i if i understand correctly and to make sure: Vin of the nRF8001 to the 3.3V of the arduino uno with a cable and i am good to go?

Yep. And don't forget the ground pin :-)

Awesome :) Yes exactly!! Thanks. Will upvote answer (can do it in 6 min stackoverflow says)

Yes will do it asap!

Seems to be working very well! I get connection in the serial monitor :) Awesome. I am very close to finish my first robot!


text:
Reading values from SQL Arduino ethernet
I'm about to do this project where I will make some lights flash up depending on some values that are in an SQL database on a server. I have already bought my Arduino and waiting for it to arrive. But I've been stuck at how to read the SQL data from the Arduino, connected to ethernet only.
Is there a library where I can select from the database directly or do I have to make a web service, in which I can make a http request to when needed?
If it's a web service, can I be directed to some examples of this being used with Arduino? I've been looking around the past few days but haven't been able to find a decent example.
Best regards and thanks a lot in advance for your time! :-)

I would make a small http REST API on your SQL server. The Arduino could use the API to get the data.
The API can easily be done in php, ruby or whatever.

Connecting to an SQL database from the Arduino would be the hard way. Creating a simple web page that can read data from your database and display said data would be the easier way. You could then access this data on the Arduino via an http request.
Here's an example of how to write such a web page in PHP: https://www.w3schools.com/php/php_mysql_select.asp
And here's the Arduino example for an HTTP request with an ethernet shield: https://www.arduino.cc/en/Tutorial/WebClient


text:
Does SoftwareSerial use hardware timer?
I'm asking this because I'm using a timer to generate a 38KHZ signal to drive an IR diode, and I also need to use SoftwareSerial to talk to an HC-12 radio using serial communication.
The code I'm using was written by Nick Gammon and is here:
//Setup Conter/overflow to create 38KHZ drive for IR38KHZ
//38khz, no interrupts
#define IR_CLOCK_RATE 38000L
// toggle on compare, clk/1
TCCR2A = _BV(WGM21) | _BV(COM2A0);
TCCR2B = _BV(CS20);
// 38kHz carrier/timer
OCR2A = (F_CPU/(IR_CLOCK_RATE*2L)-1);
pinMode(IR38KHZ, OUTPUT);

I'm not quite up-to-date on the timer use on an Arduino (I'm using a Nano), plus I've no idea what the SoftwareSerial library uses.

No. It uses pin-change interrupts to trigger reception, and both reception and transmission use calibrated delay loops.  However, interrupts are disabled during both transmission and reception so that the calibrated delay loops remain always the precise length - so if you do anything with any other interrupts they will not work at the same time as SoftwareSerial.

The SoftwareSerial uses almost all cpu time. The AltSoftSerial uses less cpu time, but it does use Timer1 : https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
Since you use Timer2, you still have the option to use AltSoftSerial.
Even when all three timers are used, it is still possible to add a speaker to your Nano with TimerFreeTone: https://bitbucket.org/teckel12/arduino-timer-free-tone/wiki/Home

When I try to link to altsoft serial, I get this:The owner of www.pjrc.com has configured their website improperly. To protect your information from being stolen, Firefox has not connected to this website.
This site uses HTTP Strict Transport Security (HSTS) to specify that Firefox may only connect to it securely. As a result, it is not possible to add an exception for this certificate.

I was able to get a copy of the library directly from github......now to try it out.....THANKS.


text:
Global variables with C++ in multiple files
I'm not a C++ programmer (but I have used regular C code for implementing low-level machine language equivalent SW for some time), and after trying to modify an existing cC+ program to do what I need (and failing), I've decided to rewrite parts of the code in plain C code.
But to be able to use the data, I need to create some variables that have to be accessible to parts of the existing C++ code.
When I declare a global variable (extern int variable name;) outside the main program, the compile fails because the references to the global variable aren't within the scope of the cpp parts of the program.
I don't program with multiple files myself, so I was wondering if I need to globally declare the same variables as part of each cpp program that needs to have access to the variables? Is there a another/better way?

How do I use extern to share variables between source files?

Why not just write C code but still name the file .cpp and let the C++ compiler compile it.

So you know, using global variables is not best way to compose object oriented code.  And I know where you are coming from (embedded processors with little room for extravagant C++ constructs).  But contemporary embedded processors are way more powerful than the venerable 8051 of yesterday.  And C++ is a great way to compartmentalize and isolate features to the extent they really only need to be tested once.  Then reused over and over again.  Give it some thought before you force old methods where newer approaches are starting to make sense and save money.

I just deleted my 3rd attempt to answer your question.  There are just too many assumptions that need to be made about your existing C++ code as well as your attempts to bring it all together using ordinary C.  I keep coming back to it would be better if you just learned C++.  I'll just say this, if the existing C++ classes still work for you, you should be able to use them using only formally passed values.  Why do you need to use global variable on top of that?

First, I haven't written the c code yet, just declared the new global variables, but it won't compile.

I understand the reusability of object orientated code, but I've never written any.....I really don't want to learn right now, just make some mods if possible, but because that was not successful, I thought I'd write one of the c++ parts in c code, but the global issue is stopping me. I'd really love to learn c++, but I need to get this code  modified for a project, and can't delay it for likely some months of learning......BTW, I'm 70+ years old, and have been a computer professional since 1968, mostly doing HW design......something about old dogs and new tricks, I think.

When using multiple source files you need to use header files to share things between them.
myproject.h:
#ifndef __myproject_h__
#define __myproject_h__
extern int aGlobalVariable;
#endif

myNewCode.c
#include "myproject.h"
int aGlobalVariable;

modifiedOldCode.cpp
#include "myproject.h"

This way the header file defines the variable as an extern in all of your c / cpp files so that it is visible to all of them but the variable is only actually declared and memory allocated for it in one place, in the .c file.
Similarly any functions that you want to be visible in both files should be declared in the headerfile (e.g. void myfunction(int x);) but the actual definitions should be somewhere in the .c or .cpp files.
The #ifndef and #define lines in the header as there so that if the header somehow gets included twice you don't get lots of redefinition errors.
There is nothing strange about c++ and globals, a global defined this way is global to everything, it doesn't matter what object you're in or how things are scoped. This can however have some strange effects since there is only ever one copy of a global while you can possibly have multiple instances of the c++ class that uses it. This can cause some consistency related issues if you aren't careful. Whether you need to worry about this or not depends very much on the nature of the code.

Thanks.....that's the information I needed.....hopefully I'll be able to implement it.....


text:
ArduinoHTTPClient POST multipart/form-data from SD card returning 400 Bad Request
I have been having trouble trying to send a small txt file to my server using the following function with TinyGSM. I know I am connected to the internet and reaching the web server, however, I keep receiving a 400 Bad Request code. I think something is wrong with my PostHeader, but I have no clue where or what it could be... I know I am connecting to my server as I try a default get and return webpage text...
TinyGsm modem(SerialAT);
TinyGsmClient client2(modem);
HttpClient client(client2, server, port);

void fileUpload(String filename){
  if(!initSD()){
    return;
  }
  File dataFile = SD.open(filename.c_str());
  Serial.println("Uploading File...");
  if (!client.connect(server, port)) {
    Serial.println("Failed connecting to Server");
    return;
  }
  String fileType = "text/plain";
  String content = "--boundary1\r\n";
  content += "Content-Disposition: form-data; name=\"fileToUpload\"; filename="+String(filename)+"\r\n";  // the fileToUpload is the form parameter
  content += "Content-Type: "+fileType+"\r\n\r\n";
  //after this, post the file data.
  String closingContent = "\r\n--boundary1--";
  //Serial.println(content);
  client.println(String("POST ") + "/upload.php" +" HTTP/1.1\r\n");
  client.println(String("Host: ") + server + "\r\n");
  client.println("Content-Type: multipart/form-data; boundary=boundary1\r\n");
  client.println("Connection: close\r\n");
  client.println("Content-Length: "+String(content.length()+dataFile.size()+closingContent.length())+"\r\n");
  client.println(content);
  client.println();
  if (dataFile) {  // start sending file content
    while (dataFile.available()) {
      char c = dataFile.read();
        client.print(c);
      }
    dataFile.close();
  }
  client.println(closingContent);
  Serial.println("File Sent.");
    // read the status code and body of the response
  int statusCode = client.responseStatusCode();
  String response = client.responseBody();

  Serial.print("Status code: ");
  Serial.println(statusCode);
  Serial.print("Response: ");
  Serial.println(response);
}

remove \r\n. you have println. move client.println(); before client.println(content);

@Juraj I solved a couple issues... this was one of them. Will post solution soon. Thanks for your help :)

There were a couple issues that I finally managed to solve... I was able to get it to work by not using ArduinoHTTPClient. Here is working code for anyone else who stumbles here.
TinyGsmClient client(modem);

void fileUpload(String filename){
  File dataFile = SD.open(filename.c_str());
  Serial.println("Uploading File...");
  if (!client.connect(server, port)) {
    Serial.println("Failed connecting to Server");
    return;
  }
  String fileType = "text/plain";
  String content = "--boundary1\r\n";
  content += "Content-Disposition: form-data; name=\"fileToUpload\"; filename="+String(filename)+"\r\n";  // the fileToUpload is the form parameter
  content += "Content-Type: "+fileType+"\r\n\r\n";
  //after this, post the file data.
  String closingContent = "\r\n--boundary1--\r\n";
  //Serial.println(content);
  client.println(String("POST ") + "/upload.php" +" HTTP/1.1"); // or wherever you need to call/print to.
  client.println(String("Host: ") + server);
  client.println("Content-Length: "+String(content.length()+dataFile.size()+closingContent.length()));
  client.println("Content-Type: multipart/form-data; boundary=boundary1");
  client.println();
  client.println(content);
  if (dataFile) {  // start sending file content
    String data = "";
    while (dataFile.available()) {
      char c = dataFile.read();
      data += c;
      //write every line break...
      if(c == '\n'){
        client.write(data.c_str());
        data = "";
      }
    }
    dataFile.close();
  }
  client.print(closingContent);
  unsigned long timeout = millis();
  while (client.connected() && millis() - timeout < 50000L) {
    // Print available data
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
      timeout = millis();
    }
  }
  client.stop();
}


text:
ESP32 captive portal not working with private IP address for android
For the initial settings of WiFi cerdentials and configuration on a standalone device (ESP32), I try to implement a captive portal using the CaptivePortal example for ESP32 DNSServer (see original source). I'm using Arduino IDE 1.8.13 and ESP32 core 1.0.4.
Different from the cited source, the example reads (as often seen in posts for that):
IPAddress apIP(192, 168, 1, 1);

This works well when connecting my laptop and opening firefox, which the tells me I'ld have to sign in by opening a signin-page.
This does not work with my android phone. It always tells me "no connection to internet".
In the latest version of the ESP core as cited above, the IP address is modified to
IPAddress apIP(8,8,4,4); // The default android DNS

This in fact works, even with android device.
I now tried different IP addresses (192.168.4.1, 8.8.8.8, 142.250.186.131, which is connectivitycheck.gstatic.com in real life, and some more). What did happen:

Using an address out of the private pool (192.168.x.y) did lead to "No connection to the internet"
Using any of the public addresses did open the portal page.

I updated the DNSServer library to version 1.0.5 of the core, as that allowed for debugging the dns server. Additionally, I added some Serial prints for debugging. Using 192.168.1.1, the output reads:
dhcps: send_offer>>udp_sendto result 0
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 18 - AP_PROBEREQRECVED
DNS responds: 192.168.1.1 for epdg.epc.mnc002.mcc262.pub.3gppnetwork.org
DNS responds: 192.168.1.1 for north-america.pool.ntp.org
DNS responds: 192.168.1.1 for mtalk.google.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for alt4-mtalk.google.com
DNS responds: 192.168.1.1 for gstatic.com
DNS responds: 192.168.1.1 for android.googleapis.com
DNS responds: 192.168.1.1 for google.com

 --- Begin http request ---
GET / HTTP/1.1
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M)
Host: 192.168.1.1
Connection: Keep-Alive
Accept-Encoding: gzip

 --- End http request ---

DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for android.clients.google.com
DNS responds: 192.168.1.1 for google.com
DNS responds: 192.168.1.1 for service.game-mode.net
DNS responds: 192.168.1.1 for play-lh.googleusercontent.com
DNS responds: 192.168.1.1 for play.googleapis.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for gld.push.samsungosp.com
DNS responds: 192.168.1.1 for googleapis.com
DNS responds: 192.168.1.1 for ssl.google-analytics.com
DNS responds: 192.168.1.1 for beacons.gvt2.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for connectivitycheck.gstatic.com
DNS responds: 192.168.1.1 for google.com
DNS responds: 192.168.1.1 for yahoo.com

 --- Begin http request ---
GET / HTTP/1.1
Connection: close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,en;q=0.4
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M)
Host: www.yahoo.com

 --- End http request ---

and some more of these.
Using e.g. 142.250.186.131, this reads different:
dhcps: send_offer>>udp_sendto result 0
[D][WiFiGeneric.cpp:337] _eventCallback(): Event: 18 - AP_PROBEREQRECVED
DNS responds: 142.250.186.131 for epdg.epc.mnc002.mcc262.pub.3gppnetwork.org
DNS responds: 142.250.186.131 for connectivitycheck.gstatic.com
DNS responds: 142.250.186.131 for connectivitycheck.gstatic.com
DNS responds: 142.250.186.131 for north-america.pool.ntp.org
DNS responds: 142.250.186.131 for capi.samsungcloud.com
DNS responds: 142.250.186.131 for mtalk.google.com
DNS responds: 142.250.186.131 for alt2-mtalk.google.com

 --- Begin http request ---
GET /generate_204 HTTP/1.1
Host: connectivitycheck.gstatic.com
Connection: close
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,en;q=0.4

 --- End http request ---

DNS responds: 142.250.186.131 for connectivitycheck.gstatic.com
DNS responds: 142.250.186.131 for android.googleapis.com

 --- Begin http request ---
GET / HTTP/1.1
User-Agent: Dalvik/2.1.0 (Linux; U; Android 7.0; SM-A310F Build/NRD90M)
Host: 142.250.186.131
Connection: Keep-Alive
Accept-Encoding: gzip

 --- End http request ---

DNS responds: 142.250.186.131 for service.game-mode.net
DNS responds: 142.250.186.131 for android.clients.google.com

 --- Begin http request ---
GET /generate_204 HTTP/1.1
Host: connectivitycheck.gstatic.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Linux; Android 7.0; SM-A310F Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/87.0.4280.101 Mobile Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
X-Requested-With: com.android.captiveportallogin
Accept-Encoding: gzip, deflate
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

 --- End http request ---

So, the HTTP requests are
GET / HTTP/1.1
Host: 192.168.1.1

(and some other hosts) if using private network address, and
GET /generate_204 HTTP/1.1
Host: connectivitycheck.gstatic.com

if using public network address.
My question:
Is there any reason that android systems act different on addresses from the private address space than from the public one? And if so, is it safe to use e.g. 8.8.4.4 for all kinds of client systems (android, ios, linux, windows, ...)?
Edit:
I tried 10.0.0.1 and 172.16.0.1 (the other two private network spaces), but android does not like them as well; @dandavis seems to be right. Now I use 192.9.200.1 which works well.
Why that address?
Some history: When in the late 1980s and early 1990s companies began to use IP networks in combination with SUN computers, many "network administrators" followed a documentation by SUN how to configure those networks. In that documentation, the address range 192.9.200.0/24 was used as an example; it was part of SUNs own network range. So many (if not all) of those people used this address range, not knowing that they should use other (private) addresses.
The address range 192.9.0.0/16 nowadays is owned by Oracle, but they seem not to use 192.9.200.0/24. If you search for "192.9.200.0", you may still find lots of documentation containing exactly those example addresses.

#2 is a yes. #1 might be that 192.168... looks like a "regular ass wifi" that should be providing internet, whereas 8.8... isn't typical, so this could be a stupid user optimization for the 99.9% of times that 192... provides internet.

Thank you for your comment. I really don't like using addresses from internet routed networks for private purpose. But here this might be the only solution - will try 172.16.0.0/12 and 10.0.0.0/8 as well and report on success.

I would suggest doing a bit of reading on rouotable and non routable IP addresses.  It appears your Android is not on the same network and it is being rejected as it should.

@Gil: Every IPV4 Address is "routable" - there are no "non routable" IP addresses. Addreses out of the "private" address space are not routed in public networks, but that is a different thing (see RFC1918 or https://en.wikipedia.org/wiki/Private_network). "My Android" gets its Address via DHCP from the Soft-AP, and thus is "in the same network" as the AP, which is also DNS server and default router, as I can see from the Android information.


text:
Problems connecting to WiFi101 access point
I currently have two Arduino Zero boards (using the SAMD21 microcontroller), each with an ATWINC1500 wifi module attached. I have established one of these units as a wifi access point with a server running on it, while the other unit is a client that attempts to connect to the access point and then send some data to the server.
As far as I can tell, the access point and the server on the first unit are created correctly. I am able to use telnet on a separate Android device to connect to the access point and send data to the server. Unfortunately, when I attempt to connect to the AP/server using the other Arduino board, it is never successful.
Here is the code I am using on the first board to create the access point and server:
WiFiServer server(23);
WiFiClient client;

void LaunchAccessPoint ()
{
    uint8_t begin_ap_status = WiFi.beginAP(access_point_name);
    if (begin_ap_status == WL_AP_LISTENING)
    {
        server.begin();
    }
}

void HandleClientConnection ()
{
    String result;
    client = server.available();
    if (client && client.connected() && client.available())
    {
        while (client.available())
        {
            result += (char) client.read();
        }

        client.stop();
    }

    SerialUSB.println(result);
}

void setup()
{
    /* ... some code in this function has been cut for clarity ... */
    LaunchAccessPoint();
}

void loop()
{
    /* ... some code in this function has been cut for clarity ... */
    HandleClientConnection();
}

Meanwhile, here is the code for the client that attempts to connect to the AP/server:
bool ConnectToWifi ()
{
    uint8_t wifi_connection_result = 0;
    wifi_connection_result = WiFi.begin(wifi_ssid);
    return (wifi_connection_result == WL_CONNECTED)
}

void PublishData (const char *json_string)
{
    WiFiClient client = WiFiClient();
    int client_connect_success = client.connect(IPAddress(192, 168, 1, 1), 23);
    if (client_connect_success)
    {
        int client_bytes_written = client.println(json_string);
        client.stop();
    }
}

void setup ()
{
    /* some code cut for clarity */
    ConnectToWifi();
}

void loop()
{
    /* some code cut for clarity */
    PublishData(some_string);
}

As I said before, if I try using telnet on a computer or phone, it is able to successfully connect to the server and send data. But when I attempt to use my Arduino board to act as the client, the socket gets closed by the server, as if it's actively refusing the connection.
EDIT: On the server side, the line client = server.available(); never returns a client object if server ATWINC is AP and client is the other ATWINC.
Any suggestions? Is there something I am missing or doing wrong? Thanks!
[edit]
After doing some testing, it seems as though the server works if it is not also acting as an access point. This is unfortunate, because I need it to act as the access point and a server.
If anyone has experience getting two ATWINC1500s to talk to each other, where one is both an AP and a server, and the other is a client, any help would be appreciated!
[/edit]

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

The bug seems to be that the server must be started after the wifi has moved into the WL_AP_CONNECTED state. I am not sure why this is, but apparently sockets are invalid (or become invalidated) when the wifi access point is not in this state (or moved out of this state).
So basically, I wrote a couple small functions to handle the state of the server, and then incorporated them in my main loop like so:
bool is_server_launched = false;

void LaunchServer_IfDeviceConnected ()
{
    if (!is_server_launched)
    {
        uint8_t wifi_status = WiFi.status();
        if (wifi_status == WL_AP_CONNECTED)
        {
            server.begin();
            is_server_launched = true;
        }
    }
}

void StopServer_IfDeviceDisconnected ()
{
    if (is_server_launched)
    {
        uint8_t wifi_status = WiFi.status();
        if (wifi_status != WL_AP_CONNECTED)
        {
            is_server_launched = false;
        }
    }
}

void loop()
{
    LaunchServer_IfDeviceConnected();
    StopServer_IfDeviceDisconnected();
    HandleClientConnection();
}

I know I could have written those functions differently to be in one single function, but I'll do that at another time.
The core of this answer comes from reading the following discussion on the Arduino forums: https://forum.arduino.cc/t/mkr1000-server-in-ap-mode-socket-connection-problem/465719
In that thread, the OP had a similar issue as me. One of the people responding gave the following reply:

Once the AP connection is lost, the server socket is no longer valid.

That person then suggested adding the following code to the OP's sketch:
if (status == WL_AP_CONNECTED) {
  Serial.println("Device connected to AP");
  server.begin(); // <- NEW LINE
} else {

After implementing that idea in my code (as I displayed above), it began to work properly.
EDIT: After doing some more digging, I also found this related issue posted in the WiFi101 Github repository:
https://github.com/arduino-libraries/WiFi101/issues/46

Sandeep Mistry ("the person") worked at that time for Arduino and maintained the WiFi101 library


text:
Can't upload code to Arduino board on Mac
I'm using a MacBook Pro with 10.13.6, an Official Arduino Uno Board and Arduino 1.8.13 IDE.
I'm having troubles uploading code to the Arduino Board.
I have 5 ports available:

dev/cu.-AvnetaSPPPort
dev/cu.Bluetooth-Incoming-Port
dev/cu.SRS-BTX300-DataInteract
dev/cu.RS-XB41-BluetoothSeria-1
dev/cu.UEMEGABOOM-LWACP-2

I'm not sure if any oh these ports is the correct one but I've already tried all of them and I keep getting errors like: "avrdude: ser_open(): can't open device "/dev/cu.-AvneraSPPPort": Resource busy"
Some weeks ago I was trying Arduino on the same computer and all went good but right now I can't get it to work, however I don't remember wich port was selected.
In the IDE the board I have selected is "Arduino Uno" and as Programmer option I have "AVRISP mkll".
Does anyone know how to solve this?

@timemage the board is an official UNO

@timemage done!

From what little I can tell, on a Mac it should show up with usbmodem in the name.  For my part unless you want me to "it's not on that list" as an answer, you're going to have to add some extra detail.  What exactly I'm not sure.  I guess whatever you can say about what if anything appears in the mac device manager and what your usb connection from the mac to the uno usb port looks like.

which sketch did you load last time it worked? ... that sketch runs when you plug the UNO into a USB port and may be interfering somehow

There's not much the sketch can do, short of activating some external circuitry that causes the board to brown out, that will drop an UNO off USB.

@timemage the OP may have modified the ATmega16u2

I finally solved the problem.
Although the Board has no information about being a clone (it only says "Uno" and was provided by the faculty so I think it is official), I was looking on the web for similar problems and found out that installing CH340 Driver was working for a lot of users.
So that was what I did and now it works like a charm.

List the ports again, with- and without the Arduino plugged in: open the built-in Terminal app (usually in Applications/Utilities) and type 'ls /dev/tty.*'. The difference will tell you the Arduino's device name.
"Resource Busy" generally means something else has already connected to that port.  Is a terminal-emulator program running and connected to that port? If you're using a terminal-emulator other than the one built in to the IDE, you have tell it to disconnect before you can upload to the Arduino.


text:
Arduino lcd displays random chracters
I have connected arduino nano every to my lcd display. It works perfect when i put all my code in setup() part. But when i put the code in loop() it does werid things. I have to put my code in loop(), because i am reading from load cell and displaying the values that are constantly changing. The delay can't be more than 250 ms.
This works well.
#include <LiquidCrystal.h>
int Contrast=30;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
    analogWrite(6,Contrast);
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("testing");
}

void loop(){

 }

When I do this next thing it works well for few seconds and then it starts to display random weird characters and stops displaying anything after some time.
#include <LiquidCrystal.h>
int Contrast=30;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
    analogWrite(6,Contrast);
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);

}

void loop(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(millis()/1000);
  delay(250);
 }

I have tried removing lcd.clear() it didn't help.
I thought it was a problem with wiring first, but it's not.
What am I doing wrong?
Any help would be great, thanks.

What am I doing wrong? ... you are not debugging the code in a logical way ... first, display fixed text, such as hello world and increase the delay time to something like 2 seconds ... that way you eliminate the possibility that the value of millis() is somehow messing up the displayed values ... it also allows you to use a stopwatch to determine how many iterations run before the problem occurs

lcd.setCursor(0, 0); - you dont really need this funtion. lcd.clear() will always bring the cursor into the (0,0) position, automatically.

check your wiring. The code seems to be correct

Increase the delay to 500 ms or more. You don't have to write faster than 1 seconds to the LCD anyway


text:
Decoding of data received using the WL-101 433 MHz radio module
Good afternoon! This question is still relevant to me. I use the receiver module in conjunction with arduino. I want to use my own transfer protocol and now I need to accept it. I tried to use various libraries, but all without success. I need to somehow select a sequence of pulses and then determine their values (zero or one) by the duration of the pulses.
But first, I need to determine the beginning of the signal from the preamble (12 pulses at the beginning). I wrote a program that draws a graph where you can see the entire sequence.
Is it possible to define this preamble without using libraries, for example, to make a cycle that will measure the length of the pulses, and there are 12 times the duration of the pulses will be the same, then this is the preamble, followed by digital data.
#define IN_PIN 2
void setup()
{
  Serial.begin(115200);
}

void loop()
{
  bool s = digitalRead(IN_PIN);
  Serial.println(s);
}

it is not possible to guess what is wrong ... we do not know what you connected, how you connected it, and what code you ran

I am trying to plot a graph and see the low and high levels there, which I transmit with my transmitter. To do this, I use the program to read data from the analog port of the arduino, to which the 433 MHz receiver module is connected.
However, nothing is accepted.

It is not working because of:
SPEED
Consider the frequency of the 433Mhz device vs. the speed of the serial monitor. The device sends signals with pulse width in the range of tens of microseconds while the serial monitor can't display that fast.
Your code should analyze the signals, clean the noise (the output of the device is very noisy) and figure out the protocol. All that is done by dedicated libraries such as rc-switch which is very extensive and robust compared to just reading a pin and plotting the output.
DIGITAL
The recover device is outputting a digital pulse which based on it's pulse width changes one can figure out the sequence of numbers sent by the remote control. Each such ASK protocol has it's timing characteristics which you should follow in order to decode the code.
If you want to experiment with that vs. using a ready made library you should start with a code similar to the example below.
void setup() {
  Serial.begin(6000000);
  attachInterrupt(digitalPinToInterrupt(1), handleInterrupt, CHANGE);
}

void loop() {
}

void handleInterrupt() {
  bool s = digitalRead(1);
  Serial.println(s);
}

Just pay attention to the timing issue, this code will show a lot of data but not necessarily (almost for sure) not all the data, but you can avoid the serial print and use the data for analysis.

Thank you. But unfortunately I can't get absolutely anything with your code.
I tried to figure out the library, but I didn't get any data. As I understand it, the library works strictly according to a certain protocol, and the pulses that I send, it takes for noise, maybe.

Also the module you are using is limited to ASK so if you are sending anything else it will not be detected. As for code sample, not that it's listening on interrupt pin 1 (PA23_TC4-W1 on MKR 1010 WIFI), check with your Arduino what pin number it should be showing in order to work and transmit from a compatible device or remote control.

Как то мне здесь помог человек при решении подобной задачи, он поделился кодом, который из частот уровня лишь частоту 1 кГц и уже на ней сигнал анализировался. Это было Гомодинное обнаружение.
Сейчас я не знаю заранее точной частоты, которую нужно построить, пробовал использовать код, на обнаружение 1 кГц, но он не обнаруживает мой сигнал.
Мне нравится этот код тем, что он позволяет установить АЦП ардуино в режиме прямого преобразования, то есть обрабатывать сигнал очень быстро.
Подскажите, как можно оставить этот режим работы АЦП, но убрать выделение сигнала 1 кГц?

@Edgar Bonet, I used your code to detect a 1 kHz harmonic signal.
Tell me how I can use it to detect a rectangular pulse with a duration of 640 μs?