text:
Stuck reading an XBM image from JSON (U8g2lib)
What I'm trying to achieve is very simple, I'm using ArduinoJson lib to load a JSON from SPIFFS and trying to inject the image values in an Array to feed the small Oled display of the ESP32:
// This is the format the library expects
static const unsigned char image[] U8X8_PROGMEM  = {
0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x17 }

This is the JSON File:
   https://github.com/martinberlin/esp/blob/master/oled-128x64-xbm/data/1.json
The goal is to be able to generate little thumbnails after uploading an image for example, and display them in this Monochrome small display.
The problem is to convert this Json array into the format the library expects. And I tried many different ways and readed about it, without finding the right way to do it. So I though to share this here as a challenge and see if someone is also interested to get dynamic image thumbnails working in this display.
This is my sketch: (Needs /data upload since json example is there)
https://github.com/martinberlin/esp/tree/master/oled-128x64-xbm
#include "FS.h"
#include "SPIFFS.h"
#include <U8g2lib.h>
#include <ArduinoJson.h>
#include <Wire.h>

/*
  U8glib Example Overview:
    Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
    Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
    U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.

*/
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);

static const unsigned char image[] U8X8_PROGMEM  = {
  0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x17,
  0xFC, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
  0xFF, 0xFF, 0xFF, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF,
  0xFF, 0x7F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x14, 0xFD, 0xFF, 0xFF, 0xFF,
  0x00, 0xF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, 0xFF, 0x03, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1C, 0x00, 0x0C, 0x00, 0x0C, 0x4E, 0xFE,
  0xFF, 0x33, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3C, 0x00, 0x06,
  0x00, 0x0C, 0x77, 0xFF, 0xFF, 0x33, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0x7F, 0x7F, 0x00, 0x23, 0x00, 0xCE, 0xFF, 0xFF, 0xFF, 0x16, 0xF8, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x85, 0x01, 0x00, 0x1E, 0xFE, 0xFF,
  0x7F, 0x10, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0x01,
  0x80, 0x0F, 0xFF, 0xFF, 0x3F, 0x10, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0x67, 0x00, 0xD8, 0x1F, 0xFF, 0xFF, 0x7F, 0x10, 0xFE, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF};

const char* xtemp[1024]; // Temporary array to store JSON incoming Hex as string
const unsigned char* xbm[1024] U8X8_PROGMEM;

void setup(void) {
  Serial.begin(115200);
  // Read xbm from  json
  SPIFFS.begin();

   if (SPIFFS.exists("/1.json")) {
    Serial.println("1.json found in SPIFFS");
    File configFile = SPIFFS.open("/1.json", FILE_READ);
      if (configFile) {
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        //json.printTo(Serial);

        if (json.success()) {
          Serial.println("json.success");
          JsonArray& arr = json["xbm"];

          // using C++11 syntax (preferred):
          int c=0;

          for (auto value : arr) {
            // Assign the json array to xtemp
            xtemp[c] = value.as<char*>();

            //Serial.println(String(c)+":"+value.as<char*>()); // Right value
            c++;
          }

        } else {
          Serial.println("ERR load config");
        }

        configFile.close();
      }
   }
  u8g2.begin();
  u8g2.setDrawColor(0);
  u8g2.clearBuffer();

  Serial.println("cross_block_bits size:");
  Serial.print(sizeof(image));
  Serial.println(image[1]);

  //xbm = xtemp;

  Serial.println("xbm:");
  Serial.println(xtemp[1]);

 // Should be xbm (coming from json)   xbm
 // u8g2.drawXBM( 0, 0, 128, 64, xtemp); // Does not work since requires  'const uint8_t* {aka const unsigned char*}
  u8g2.drawXBM( 0, 0, 128, 64, image);

  u8g2.sendBuffer();
}

void loop(void) {

}

post the code directly in your question, don't link it.

Done, thanks! I though that an alternative way to do this would be to make my own loop and draw pixel per pixel, but anyways would be interesting to know if I can read a JSON array and give it to the library in the expected format.

u8g2.drawXBM( 0, 0, 128, 64, (const uint8_t *)xtemp);

Great idea Majenko, casting it to a uint8_t works. I still need to convert:
0xC0  Coming as string to it's int value

uint8_t val = strtol(stringval, NULL, 16)

Perfect. Now I have a last issue that I don't get why it's counting this way. I'm iterating this 1024 elements and storing them in a long unsigned int xbm[1024] (to mach strol type. At the end if I do a :
Serial.print(sizeof(xbm)); // Returns 4096. Still do not understand why
Reference after your recommendation: https://github.com/martinberlin/esp/commit/404814013c49b66338017164a2f36ed02676663b

Thanks @Majenko this let me understand much better how to transform. I will go back to the book on C++ variable types, since coming from PHP and the web world are difficult to understand for me

Found a solution, don't know if it's the right one, but re-writing an existing image array seems to be the key. Very strange, but it works correctly and now the JSON can be loaded and the image rendered. If you are interested to see how, the update is here in this location: https://github.com/martinberlin/esp/tree/master/oled-128x64-xbm

const char* xtemp[1024]; is array of 1024 pointers to char. const char xtemp[1024]; is array of 1024 chars

Thanks and credits to Majenko. Sorted it out, still I don't know why addressing an existing image works but targeting a new array doesn't. Anyways as proof-of-concept that an XBM Icon can be loaded from JSON it works. For anyone wanting to achieve this, here is the code, make sure to upload some JSON to Spiffs first:
/*
  GraphicsTest.ino
  Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
*/
#include "FS.h"
#include "SPIFFS.h"
#include <U8g2lib.h>
#include <ArduinoJson.h>
#include <Wire.h>

/*
  U8glib Example Overview:
    Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
    Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
    U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.

*/
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 15, /* data=*/ 4, /* reset=*/ 16);

static unsigned char image[] U8X8_PROGMEM  = {
  0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x17,
  0xFC, 0xFF, 0xFF, 0xFF, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00,
  0xFF, 0xFF, 0xFF, 0x14, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xF0, 0xFF, 0xFF,
  0xFF, 0x7F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x14, 0xFD, 0xFF, 0xFF, 0xFF,
  0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x8F, 0xFF, 0x10,
  0x7E, 0xFF, 0xFF, 0xFF, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00,
  0xFE, 0x8F, 0xFF, 0x90, 0x7F, 0xFF, 0xFF, 0xFF, 0x00, 0xFE, 0xFF, 0xFF,
  0xFF, 0xFF, 0x03, 0x00, 0xFC, 0x0F, 0xFF, 0x90, 0xFF, 0xEE, 0xFF, 0xFF,
  0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0xFF, 0x0F, 0xFF, 0x90,
  0xFF, 0xCC, 0xFF, 0xFF, 0x00, 0xFE, 0x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7F, 0x10, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC7, 0x01,
  0x80, 0x0F, 0xFF, 0xFF, 0x3F, 0x10, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0x67, 0x00, 0xD8, 0x1F, 0xFF, 0xFF, 0x7F, 0x10, 0xFE, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF};

// Using this new array I could not get it work. Rewriting image works
long unsigned int xbm[1024];

void setup(void) {
  Serial.begin(115200);
  // Read xbm from  json
  SPIFFS.begin();

   if (SPIFFS.exists("/1.json")) {
    Serial.println("1.json found in SPIFFS");
    File configFile = SPIFFS.open("/2.json", FILE_READ);
      if (configFile) {
        size_t size = configFile.size();
        // Allocate a buffer to store contents of the file.
        std::unique_ptr<char[]> buf(new char[size]);

        configFile.readBytes(buf.get(), size);
        DynamicJsonBuffer jsonBuffer;
        JsonObject& json = jsonBuffer.parseObject(buf.get());
        //json.printTo(Serial);

        if (json.success()) {
          Serial.println("json.success Size of xbm array");

          JsonArray& arr = json["xbm"];

        Serial.print(sizeof(arr));
          // using C++11 syntax (preferred):
          int c=0;
          const char* tempx;
          for (auto value : arr) {
            // Assign the json array to xtemp
            tempx = value.as<char*>();

            image[c] = strtol(tempx, NULL, 16);

              //Serial.print(strtol(tempx, NULL, 16)); //Thx. Majenko
              if (c<10) {
              Serial.print("i:");Serial.print(image[c]);Serial.print(" ");
              }
            c++;
          }
          Serial.print("Final c count:"+String(c));

        } else {
          Serial.println("ERR loading JSON");
        }

        configFile.close();
      }
   }
  u8g2.begin();
  u8g2.setDrawColor(0);
  u8g2.clearBuffer();

  Serial.print("image size:");
  Serial.print(sizeof(image));Serial.println();  // Here is 4096 also 4 times bigger, if I use a new array (WHY?)
  // Send the JSON array to oled display
  u8g2.drawXBM( 0, 0, 128, 64, (const uint8_t *)image);
  u8g2.sendBuffer();
}

void loop(void) {

}

why long unsigned int xbm[1024]; and not byte xbm[1024];, which would be the same as new char[size] for the existing file?

Yes that will work. But the issue is that I'm not even using this new one, but filling the already declared image. Using the new one, at the end of the 1024 pixels loop, you end up having 4x more (4096) and I still don't know why.

Also it sounds to me that using this: long unsigned int xbm[1024]
It's reading somehow the 4 chars from every pixel ( 0x00 ) but that would be impossible since we are transforming this HEX into an integer. But well cool thing is that it works just overwriting a previous image

a hex number with two hex digits fits into one byte. FF is in binary 11111111. 0F hex is 00001111 binary. that is way hex is used


text:
Running ESP8266 at 3.78V to work with ATMEGA328P at 16 MHz
I have a project that is powered by 2x 18650 battery and feeds it to a step down switching voltage regulator that is configured to give a steady output of 3.78V to both esp8266 and atmega328p.
The esp8266 only sends an HTTP post request to an API every 30 mins and on standby mode whenever it does not do anything.
I have tested it for 1 hour and the esp8266 seems to work fine and does not warm. I intend to use the esp8266 in an airconditioned office 24/7 or until the battery runs out. I know it is not safe to give 3.78V because its supposed to have only a maximum of 3.6V but I am asking if anyone has ever had the same application and did not experience any problems?

Whether or not it works reliably over time is a gamble.   The 3.78V output of your regulator will vary by 10's (or 100's) of millivolts as loads change.  Why not simply use a 5V step down DC-DC buck converter for the 328P and a cheap 5V to 3.3V linear regulator for the ESP8266?

connect VCC with a big diode instead of a wire; it should drop about half a volt, and while the "transconductance" will vary with load, it should keep the voltage around 3.2v, give or take a few 100mv, which is within spec. A 470u cap would help keep it stable if you run into issues, and isn't a bad move even without the added "jank" of a rectifier diode

@JeffWahaus Yes, it is the original plan but the 3.3v linear regulator is unavailable in our area.

@dandavis Thanks for the suggestion. The circuit is already on PCB so I do not think this would be an option now.

Other possibilities include:

Running the Atmega328p at 8MHz and powering at 3.3v. Both devices would be operating within spec.
Running the whole system at 3.3v but without changing the clock on the '328. The advantage here is you'll get the full throughput from the '328, assuming you need it. The disadvantage (assuming a 16MHz Atmega328p) is that it will be running out of spec (overclocked) but they seem to be conservatively enough speced that most chips do fine. I have built two boards this way for the same reason: to put both a 328p and an ESP8226-01 on one board. I ran some rather rudimentary tests on the Atmega chips I put on those boards to find out if they would work at that voltage. I didn't see any issues and I haven't discovered any since.

Update:

Would it be possible to run the ATmega at 8 MHz using a 16 MHz
  external oscillator by simply uploading a new sketch?

It may be possible to use its internal resonator and ignore the connected crystal; I haven't tried this. Could you clip off the external crystal if you needed to?
This article talks about setting the fuses that control the clock frequency. One thing to keep in mind is you'll need to replace the bootloader with one appropriate for the new clock frequency. You may find an 8Mz bootloader ready to upload, or recompile it yourself from source. Optiboot is a good choice: open source, has a small footprint, and you can set its upload baud-rate. You can upload a new bootloader using another Arduino as an ISP programmer - there are lots of articles about doing this and the code for the Arduino-as-programmer is one of the Arduino IDE example-programs.

There appears to be quite a few reports of people successfully running a 328p at 3.3V running at 16MHz.  If you split the difference between the two chips at about 3.6v you should have a good chance at success.

Would it be possible to run the ATmega at 8 MHz using a 16 MHz external oscillator by simply uploading a new sketch? I have tried running at 3.3V with the 16 MHz and it does not work properly. So, I might switch at 8 MHz but my problem is the 16 MHz external osc is already soldered.

source: Stack Exchange

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

sort: votes


text:
How to send an integer through pyserial with Python to an Arduino and get back the same result?
There has been similar questions all over the internet but none of them seem to answer my question, so can anybody tell me what is wrong with this code and how I can fix it?
Python code:
import serial

arduino_linux=serial.Serial("/dev/ttyACM0",9600)
while True:
    print('write:',str.encode('90')) #print the sent value through the serial to check it with the readed value
    arduino_linux.write(str.encode('90'))#send the following value
    print('readed:',arduino_linux.read())#read the same value back from the arduino

my arduino code is as follows
void setup() {
  Serial.begin(9600);

}

void loop() {
  Serial.write(Serial.read());

}

this is a simple sample of a project, my aim from this code is to send the integer number 90 from the pyserial and make sure the value the Arduino is reading is the same integer.
In case if necessary my project is an object follower with object detector and after calculating all the angles and everything it sends them to the Arduino so the Arduino can act up on the servo's.
This is the result I am getting:

But I would like something like:
write:b '90'

readed:b '90', not b'9' or b'0'
I would also like to know how I can change these bytes to integers before I write them to a servo.

what version of python and the pySerial library you use?

Use Serial.write() on Arduino to send raw bytes. print converts them to text.
read is not blocking, it doesn't wait for a byte and returns -1 if the receive buffer is empty. Check if read returned -1 or use Serial.available() to get the number of bytes in the RX buffer.
Serial 'echo':
void loop() {
  if (Serial.available()) {
    Serial.write(Serial.read());
  }
}

i have seen it and used Serial.write().  but i dont seem to quit understand what you said for the second problem. give me some specific example. Thanks

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


text:
ESP8266 GET method error
I am working on ESP8266 and I want to send a GET request with AT command to my localhost but I failed every time. Can you help me solve this problem please? Thank you for interest!
I attached my terminal code and my code:

#define ag_ismi "SUPERONLINE_WiFi_8022"
#define ag_sifresi "rC5YGNYebuCf"
#define IP "192.168.1.9"

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

  Serial.begin(115200);
  Serial.println("AT");
  delay(3000);
  if(Serial.find("OK")){
    Serial.println("AT+CWMODE=1");
    delay(2000);
    String baglantiKomutu=String("AT+CWJAP=\"")+ag_ismi+"\",\""+ag_sifresi+"\"";
    Serial.println(baglantiKomutu);
    delay(5000);
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(60000);
  Serial.println("AT+CIPMUX=1");
  Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.9\",8000");
  delay(1000);
  String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1";
  //model+="Host: 192.168.1.9:8000\r\n\r\n";
  model+="r\n\r\n";
  Serial.println("AT+CIPSEND=" + String(model.length()));
  Serial.println("\r\n\r\n");
  delay(1000);
  Serial.println(model);
  Serial.println("\r\n\r\n");
  delay(1000);
  Serial.println("");
}

problem is, that you connected the esp8266 to Serial. now your Serial debug prints go to esp8266 and disturb it. use SoftwareSerial

It should be
String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1\r\n";
model+="Host: 192.168.1.9\r\n\r\n";

remove Serial.println("\r\n\r\n"); before Serial.println(model); it is send before GET line
Serial.println("AT+CIPSTART=\"TCP\",\"192.168.1.9\",8000");
String model = "GET /kanbanDB/arduino?model=1 HTTP/1.1\r\n";
model+= "Host: 192.168.1.9\r\n\r\n";
Serial.print("AT+CIPSEND=");
Serial.println(model.length());
delay(1000);
Serial.print(model);
delay(1000);

EDIT:
Remove debug prints to Serial or use SoftwareSerial to connect the esp8266 to Uno. Now the debug prints are sent to esp8266 mixed with AT commands and data. For SoftwareSerial change the default baud rate of the AT firmware.

I tried this code but its also not working. when I run GET /kanbanDB/arduino?model=1 HTTP/1.1 code, if I send first time wifi module waiting 30 second and send requets but second time I run this code it failed. that failure is about power supply ?

how do you power it?

I used arduino with USB power


text:
I have the code printing the data I need but don't know how to connect the data on ESP8266 IP web server

   #include "DHT.h"
   #include "NewPing.h"
   #include <SoftwareSerial.h>

   #define DEBUG true
   SoftwareSerial esp8266(11,10);
   #define DHTPIN 2        // DHT-11 Output Pin connection
   #define DHTTYPE DHT11   // DHT Type is DHT 11 (AM2302)
   #define TRIGGER_PIN 4
   #define ECHO_PIN 3
   #define MAX_DISTANCE 400

    NewPing sonar(TRIGGER_PIN,ECHO_PIN,MAX_DISTANCE);
float hum;
float temp;
    DHT dht(DHTPIN, DHTTYPE);

void setup() {

   Serial.begin (9600);
   dht.begin();

   pinMode(TRIGGER_PIN, OUTPUT);
   pinMode(ECHO_PIN, INPUT);

   sendData("AT+RST\r\n",2000,DEBUG);
   sendData("AT+CWMODE=2\r\n",1000,DEBUG);
   sendData("AT+CIFSR\r\n",1000,DEBUG);
   sendData("AT+CIPMUX=1\r\n",1000,DEBUG);
   sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG);

 }

 void loop()

 {

 delay(2000);  // Delay so DHT-11 sensor can stabalize

   hum = dht.readHumidity();  // Get Humidity value
   temp= dht.readTemperature();  // Get Temperature value

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

   long duration,distance;
   duration= pulseIn(ECHO_PIN,HIGH);
   distance = duration/58.2;

   Serial.print("Humid: ");
   Serial.print(hum);
   Serial.print(" %, Temp: ");
   Serial.print(temp);
   Serial.print(" C, ");
   Serial.print("Distance: ");
   Serial.print(distance);
   Serial.println(" cm");

   delay(50);

  if(esp8266.available())

   is sending a message
 {
   if(esp8266.find("+IPD,"))
 {
 delay(1000);

 int connectionId = esp8266.read()-48;

  /* We are subtracting 48 from the
  output because the read() function returns
  the ASCII decimal value and the
  first decimal number which is 0 starts at 48*/

  String webpage = "
IOT Garbage Monitoring System
";
  webpage += "

";

  if (distance<5)
 {
  webpage+= " Trash can is Full";
 }
   else{
   webpage+= " Trash can is Empty";
    }
   webpage += "

";
   String cipSend = "AT+CIPSEND=";
   cipSend += connectionId;
   cipSend += ",";
   cipSend +=webpage.length();
   cipSend +="\r\n";

   sendData(cipSend,1000,DEBUG);
   sendData(webpage,1000,DEBUG);

   String closeCommand = "AT+CIPCLOSE=";
   closeCommand+=connectionId;
   closeCommand+="\r\n";
   sendData(closeCommand,3000,DEBUG);

   }
   }
   }

   String sendData(String command, const int timeout, boolean debug)

   {

   String response = "";
   esp8266.print(command);
   long int time = millis();

   while( (time+timeout) > millis())
   {
   while(esp8266.available())
   {
   char c = esp8266.read();
   response+=c;
   }
   }
   if(debug)
      {
     Serial.print(response);
      }
     return response;
      }

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

The esp-01 is in AP mode. To access the web page on the IP address 192.168.4.1 show in Serial Monitor you must connect to the WiFi network created by the esp-01.
If you click the WiFi icon in the bottom right corner of Windows, you will see a list of WiFi networks.


text:
Synchronous communication between two Arduino boards using two ESP8266 modules
I am trying to establish communication between two Arduino boards to send data from sensors through a WIFI module. The problem is that I need them to connect to each other whenever they are in range of each other and send the sensor data.

The esp8266 WiFiMulti system allows to configure more access points and with the rigth code in loop it always searches the best AP.
Configure one of the esp8266 as AP and setup the other with WiFi Multi only for this one  access point.
You can then use events like onStationModeConnected to handle data exchange if the connection is established.


text:
ESP8266-12F accelstepper wont boot
If I use 9, 10, 7, 6 , 8, 11 pins for accelstepper, ESP8266 wont boot
If I use other pins, all good.
What is the problem?
I use accelstepper and Arduino latest versions.
sketch which won't boot -
    #include <AccelStepper.h>
#include <MultiStepper.h>

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "wiflya";
const char* password = ".........";

#define HALFSTEP 8

// Определение пинов для управления двигателем
#define motorPin1  13 // IN1 на 1-м драйвере ULN2003
#define motorPin2  12 // IN2 на 1-м драйвере ULN2003
#define motorPin3  14 // IN3 на 1-м драйвере ULN2003
#define motorPin4  16 // IN4 на 1-м драйвере ULN2003

// Определение пинов для управления двигателем
#define motor2Pin1  6 // IN1 на 2-м драйвере ULN2003
#define motor2Pin2  3 // IN2 на 2-м драйвере ULN2003
#define motor2Pin3  5 // IN3 на 2-м драйвере ULN2003
#define motor2Pin4  4 // IN4 на 2-м драйвере ULN2003

// Инициализируемся с последовательностью выводов IN1-IN3-IN2-IN4
// для использования AccelStepper с 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motor2Pin1, motor2Pin3, motor2Pin2, motor2Pin4);

void setup() {
  //Serial.begin(115200);
  //Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    //Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  stepper1.setMaxSpeed(1300.0);
  stepper1.setAcceleration(400.0);
  stepper1.setSpeed(1300.0);

  stepper2.setMaxSpeed(1300.0);
  stepper2.setAcceleration(400.0);
  stepper2.setSpeed(1300.0);

  //stepper1.moveTo(20000);

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  // ArduinoOTA.setHostname("myesp8266");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

  ArduinoOTA.begin();
}

void loop() {
    // Изменяем направление, если шаговик достигает заданного положения
  //if(stepper1.distanceToGo()==0)
  //  stepper1.moveTo(-stepper1.currentPosition());
  stepper2.runSpeed();
  stepper1.runSpeed();
  //stepper2.runSpeed();

  ArduinoOTA.handle();
}

Pins 6 to 11 of the esp8266 are QIO SPI pins connected to flash memory of the esp8266. You can't use them.

Thank. I'm finding more info about this. can't use 6-11 pins, cant use gpio1 - if i'm connect to uln2003 - esp wont boot.. cant use gpio0 - wont boot if i'm connect to uln2003.   And what we have - only 3,5,4,12,13,14,16 i'm can use (with uln2003) and cant connect two bipolar motor - so very bad.

this is for NodeMcu, but it applies https://electronics.stackexchange.com/questions/402066/esp8266-free-gpios-for-relay-switching/404845#404845

or here https://tttapa.github.io/ESP8266/Chap04%20-%20Microcontroller.html


text:
ESP8266 is not responding to AT commands and showing mem_failed on every code
I was using Arduino Uno with ESP8266-12E. Today I was reading an article to blink LED using Webpage. The code wasn't uploading so I connected all the pins connected to 3.3V to 5V. Then the code was uploaded successfully. After that I switched off my laptop and Arduino. After 2-3 hours when I got back to work, the module wasn't responding to AT commands even after reconnecting it to 3.3V. The wifi is working fine since it automatically connects to the WiFi I have configured earlier. I used same settings and connections prior to that messing up. Also on every code upload it shows mem_failed. So, how can I get my WiFi to work?

The code wasn't uploading so I connected all the pins connected to 3.3V to 5V. What on earth made you do that?

I don't know. I thought I should give it a try. And I don't know why it was uploaded then.

@jsotola The pins were Vcc, RST, CH_PD.

I'd suggest you go and buy a new ESP8266 - and this time keep it away from 5V.

Buy a little development board and learn how to use the ESP8266. Either a NodeMCU or a WEMOS board. They have a USB to serial adapter on the board and a proper regulator.
The initial problem you encountered was most likely caused by insufficient power for the ESP8266. The power supply must be capable of supplying a minimum of 400mA. It needs to have close short wires to the Vcc and ground on the ESP module. It helps to also have a capacitor across Vcc and ground of the ESP module with short leads.
There are some horrible examples on the internet that show the ESP being powered from and Uno's 3.3v power connection. This will never be reliable if it does even work. There is not enough power.
The ESP8266 typically uses about 80mA. This is an average value. When transmitting the peak current is a lot hight. The worst case happens to be when the ESP starts after a reset. I then does an analog power calibration. (for the RF section) Expressif states this, plus the digital power requirements, will equal above 500mA.
The GPIO pins are not 5 volt compatible. A lot of internet examples show the ESP rx and tx lines connected to the rx and tx of a 5 volt Arduino board, without level converters. This is not acceptable. The RX line of the ESP8266 can be damaged.
Powering the ESP module with 5 volts can damage all or parts of the two chips on the module. (the CPU and the external Flash memory chip) Other sections may still work. That is likely what you are seeing.


text:
Arduino pow() making 9's
I am having a temporary lapse of judgement, or not understanding how the power method works, but when I put 10 to the power of a number, it is that value -1.  So:
10*10 = 100

Then I would assume, 10^2 = 100
So if I had a variable i, that was equal to 2, and I asked arduino for 10 to the power of i, I would expect it to do 10^2, and then give me 100, but instead I get 99.  What am I missing?
void setup() {
Serial.begin(9600);
}

void loop() {
for (int i =0; i<5; i++){
   int power = i;
   Serial.print(power);
   Serial.print(":");

   int multiplier = pow(10,power);
   Serial.println(multiplier);

  }

}

^ is not power operator in C and C++. it is bitwise XOR

https://stackoverflow.com/questions/4843304/why-is-my-power-operator-not-working

pow() works with floating point numbers.
Floating point numbers are just an approximation.  You will very rarely get precise results using floating point numbers.
Instead you could write your own little integer-based ipow() function.

I put this code into the IDE, and for n>=2, I got 99, 999, 9999 etc. The catch is that Arduino uses floating point arithmetic to implement the pow() function, and some of your values are being truncated as ints. If you change:
   int multiplier = pow(10,power);

to
   float multiplier = pow(10,power);

The results should be as expected.
(The brief reason why floats are used is related to the fact that it is very easy to calculate the pow() function using logs, and this makes it easy to pow() non-integers too. This also means that it may not be as exact as you would hope).


text:
Using timer classes within classes
I am trying to develop a class for a pump that works on a stepper motor, it should be simple but its not working the way I thought it would. Once I move the timer object into the class the code wont compile I have tried a lot of things but nothing seems to work correctly. The goal of this whole thing is getting the stepper motor to step on its own based off of the calls from the timer object.
pump.h
#include "TimerObject.h"`
#ifndef Pump_h
#define Pump_h

class Pump
{
  public:
     Pump(char pin_, char dir_);
    void pumpstep(void);
  private:
    char pin;
    char dir;
    TimerObject *pumptimer;
};

#endif

pump.cpp
Pump::Pump(char pin_, char dir_)
{
    pin = pin_;
    dir = dir_;
    pumptimer = new TimerObject(100, &this->pumpStep); //PROBLEM IS HERE

  pinMode(pin, OUTPUT);
  pinMode(dir, OUTPUT);
}

void Pump::pumpstep(void) {
     Serial.println("Stepping");
}

my .ino simply creates the class passing in the needed parameters but everything binds up when I try to compile because of the callback in the constructor for the timer, for some reason It wont let me use the address of a non-static method here but I cant make the method static each pumpstep() method must be separate depending on which pump is running.
I have tried using &Pump::pumpstep, &(Pump::pumpstep) and many more pointers but cant seem to get the one I need.
outside this class the timer was working great I used this line below:
pumptimer = new TimerObject(100, &pumpStep);

The library for the timer can be found here:
https://playground.arduino.cc/Code/ArduinoTimerObject
Any help would be greatly appreciated.

You cannot. A member function has a different prototype to a global function. There are ways around it, but you really dont need that library to make something happen periodically. Only a couple of lines of code and one unsigned long variable.

The function prototype of a member function is completely different to that of a global function. The two are not interchangeable.
There are ways of working around it, such as "bouncing" your callback through a global function, but they're messy.
However, in this situation you are better off just ditching TimerObjects.h and doing it manually - it's not exactly difficult:
#ifndef Pump_h
#define Pump_h

class Pump
{
  public:
     Pump(char pin_, char dir_);
     void pumpstep(void);
     uint32_t ts;
     void run()
  private:
    char pin;
    char dir;
};

#endif

Pump::Pump(char pin_, char dir_)
{
    pin = pin_;
    dir = dir_;
    ts = 0;
    pinMode(pin, OUTPUT);
    pinMode(dir, OUTPUT);
}

void Pump::pumpstep(void) {
     Serial.println("Stepping");
}

void Pump::run() {
    if (millis() - ts >= 100) {
        ts += 100;
        pumpStep();
    }
}

Then in loop call:
myPump.run();

You can, of course, just combine run() and pumpstep() into one single function.


text:
Programming stepper motor move a fixed step till it reach the target
I have a stepper motor and try to program it like this but I kinda stuck since I'm new to Arduino.
1. The target is set to 2048, means motor have to move 2048 steps.
2. I program the motor to run 200 steps each time, every 200 steps will stop for a sec until it reach 2048.
I've been using AccelStepper library to program my motor, I found out it is very hard for me to program like this. I'm not asking to do my homework but I dunno where to start. Just wanted to ask what method can I use to program the motor to work like this. Thank you.

Have you tried modifying one of the examples provided with the library?

I would start with the Blocking example provided with the library. Add the delays you need, the steps/distance you want. The following is simple but crude. It is call blocking code. It can only do the following sequence, but sometimes that is good enough.
A bit better would be to have a conditional loop to get to the final target. The loop would move 200, then delay 1 second, subtract the amount moved. Loop until you use up all the required distance. But initially I suggest to keep it simple and just make it work with inline sequences.
#include <AccelStepper.h>
// Define a stepper and the pins it will use
AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
void setup()
{
    stepper.setMaxSpeed(200.0);
    stepper.setAcceleration(100.0);
}
void loop()
{
    stepper.runToNewPosition(0);
    delay(1000);
    stepper.runToNewPosition(200);
    delay(1000);
    stepper.runToNewPosition(200);
    delay(1000);
    stepper.runToNewPosition(200);
}

Thanks! I will read first. Appreciate it!


text:
Unable to get output on Arduino serial communication with ESP8266 and M6E RFID reader
I am unable to get the output on NODEMCU serial. NODEMCU is connected with Arduino Uno, and Uno is connected with M6E Nano RFID reader. Currently I am unable to understand that am i doing any mistake. Please let me know if any other thing you require.
NodeMCU and M6E Nano RFID reader pin configuration with Arduino Uno
NodeMCU         UNO
Vin             Vin
GND             GND
D2              2
D3              3

Code for Arduino Uno+M6E Nano RFID Reader
#include <SoftwareSerial.h>
SoftwareSerial softSerial(2, 3);

#include "SparkFun_UHF_RFID_Reader.h"
RFID nano;

void setup()
{
  Serial.begin(115200);
  softSerial.begin(115200);

  while (!Serial);
  Serial.println();
  Serial.println("Initializing...");
}

void loop()
{
  byte response;
  byte myTID[20]; //TIDs are 20 bytes
  char str[sizeof(myTID) * 2 + 1];
  const char* hex = "0123456789ABCDEF";

  //Read unique ID of tag
  response = nano.readTID(myTID, sizeof(myTID));
  if (response == RESPONSE_SUCCESS)
  {
    for (int i = 0; i < sizeof(myTID); i++)
    {
      str[i * 2] = hex[(myTID[i] >> 4)];
      str[i * 2 + 1] = hex[(myTID[i] & 0x0F)];
      }
    str[sizeof(str)] = 0;
    Serial.println(str);
   }
  else
    Serial.println("Failed read");
}

Code for NODEMCU
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
SoftwareSerial NodeMCU(D3,D2);

void setup()
{
  Serial.begin(9600);
  NodeMCU.begin(4800);
  pinMode(D2,OUTPUT);
  pinMode(D3,INPUT);
}

void loop(){
  String str = 0;        // stores received byte

  if(NodeMCU.available())
  {
    // get byte from USB serial port
    str = Serial.read();
    NodeMCU.write(str);
  }
delay(30);
}

Unable to find where i am doing the mistake! Thanks in advance

You have not the same baud rate on both ends.
SoftwareSerial is not reliable at 115200. use 9600 baud
SoftwareSerial on esp8266 is not reliable.

remove Uno from the project and connect the reader to NodeMcu

1, 2 Worked on the same baud rate but still does not getting any output!
3. what should I have to do! that esp8266 don't fight for interrupts with WiFi.

I just already tried(remove Uno from project) but still not getting any output! Any idea?

https://arduino.stackexchange.com/questions/57224/how-to-connect-sparkfun-m6e-nano-uhf-rfid-reader-and-esp8266-nodemcu-0-1/57229#57229


text:
Using 2 piezo buzzers to emit the same tone with phase difference
For a physics project, I want to record the effect of 2 speakers emitting 100hz at different phase differences. Trouble is, the Arduino can only send one tone() signal at a time. How do I create a phase difference effect using one Arduino?

Hint: Start by understanding how tone() works.

Since the frequency is so low, you can generate the signals in software.
That would not be as clean as timer-generated signals, but it will be
much easier. And probably clean enough for the intended purpose.
In order to generate a tone, you have to repeatedly switch the pin
connected to the piezo. This is very similar to blinking an LED, only
somewhat faster. Blinking an LED is the very first thing you learn to do
with an Arduino, but you may notice that blinking two LEDs is a
little bit trickier. The problem – and the solution – is
discussed in the Arduino tutorial Blink Without Delay. Building on
that tutorial, here is an example program that generates two 100 Hz
signals in quadrature:
const uint8_t PIN_A = 8;
const uint8_t PIN_B = 9;
const uint32_t HALF_PERIOD = 5000;  // 5000 us
const float PHASE_SHIFT = 0.25;     // 1/4 period

uint8_t state_A = LOW;
uint8_t state_B = LOW;

uint32_t last_A_toggle = 0;
uint32_t last_B_toggle = - 2 * HALF_PERIOD * PHASE_SHIFT;

void setup() {
    pinMode(PIN_A, OUTPUT);
    pinMode(PIN_B, OUTPUT);
}

void loop() {
    uint32_t now = micros();
    if (now - last_A_toggle >= HALF_PERIOD) {
        last_A_toggle += HALF_PERIOD;
        state_A = !state_A;
        digitalWrite(PIN_A, state_A);
    }
    if (now - last_B_toggle >= HALF_PERIOD) {
        last_B_toggle += HALF_PERIOD;
        state_B = !state_B;
        digitalWrite(PIN_B, state_B);
    }
}

If you compare this with the above mentioned tutorial, there are a
couple of differences worth noticing:

The timings are measured using microseconds rather than milliseconds,
for getting a better accuracy
The variables holding the times of last toggle are updated like
last_A_toggle += HALF_PERIOD rather than last_A_toggle = now (the
equivalent of previousMillis = currentMillis). This is needed to
keep an accurate average frequency. Otherwise the time taken to
execute the code would make the frequency slightly off.

There is a little trickery in the initialization of last_B_toggle,
which is an unsigned number initialized to a negative value. The
initialization is valid and works modulo 232. Using a small
positive value would have the ill effect of now - last_B_toggle
overflowing to a very large positive number on the first run of
loop(), putting last_B_toggle effectively in the distant past.

For a very simple example you can do something like this:
#define SPEAKER1_PIN    5
#define SPEAKER2_PIN    6

void setup() {
  pinMode(SPEAKER1_PIN, OUTPUT);
  pinMode(SPEAKER2_PIN, OUTPUT);
}

void loop() {
  int phase_delay = 1000;   // Phase delay (in us)
  int freq_delay = 5000;    // Half of square wave at 100Hz (5000us)

  // Generate 2 square waves (out of phase)
  while(1) {
    digitalWrite(SPEAKER1_PIN, HIGH);
    delayMicroseconds(phase_delay);
    digitalWrite(SPEAKER2_PIN, HIGH);
    delayMicroseconds(freq_delay - phase_delay);
    digitalWrite(SPEAKER1_PIN, LOW);
    delayMicroseconds(phase_delay);
    digitalWrite(SPEAKER2_PIN, LOW);
    delayMicroseconds(freq_delay - phase_delay);
    }
}

By the way, 100Hz may be to low of a frequency to get much sound out of a Piezo speaker.  You'll likely have better success by using higher frequencies.


text:
GMS send SMS text messages many times
The GSM sends many SMS text messages and does not stop. How to send only one SMS?
This is my code:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
char msg;
int vibr_pin = 7;

void setup() {
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);   // Setting the baud rate of Serial Monitor (Arduino)
  pinMode(vibr_pin, INPUT);
  delay(100);
}

void loop() {
  int a;
  a = digitalRead(vibr_pin);
  if (a == 0) {
    mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
    delay(1000);  // Delay of 1000 milli seconds or 1 second
    mySerial.println("AT+CMGS=\"+60125456758\"\r"); // Replace x with mobile number
    delay(1000);
    mySerial.println("test 1,2,3"); // The SMS text you want to send
    delay(100);
    mySerial.println((char) 26); // ASCII code of CTRL+Z
    delay(1000);
  }
}

EDIT:
After I change if (a==0) to if(a!=0), it only sends message when the vibration sensor is moving. How to send sms when sensor is not moving?

my vibration sensor sw-420

use a flag variable to remember if you sent a message

int a;
a = digitalRead(vibr_pin);
if (a == 0) {

This sends an SMS text message every time a is 0. I'm not sure what vibr_pin does, but maybe you want to check only for a trigger (from a != 0 to a == 0).
In that case, use a boolean to check if the SMS text message has been sent, and reset the boolean when a goes from !=0 to 0.

after i change if (a==0) to if(a!=0) it only send massage when the vibration sensor is moving. how to send sms when sensor not moving

Use a boolean (check when the sensor transitions from not moving to moving or vice versa). When that boolean is set (or reset) send the SMS and change the boolean.


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

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

isn't it enough to close Serial Monitor window?

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

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

Try teleplot extension in vscode

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

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


text:
Board Updating problems
I have updated Arduino AVR Boards in IDE and before I updated, ESP8266 boards were working, now after I updated, it says "Error downloading "URL for esp"" and no matter which website I listed inside the preference:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
https://github.com/esp8266/Arduino/releases/download/2.3.0/package_esp8266com_index.json

None of them are being downloaded and I cannot program ESP8266. Can I get some help? Thank you.

what? what is "updating AVR"? what is "updating esp8266"? and when do you get the "Error downloading"?

Ok, inside the Arduino IDE, when you go to tools > boards > boards manager, this is where I updated Arduino AVR boards like geniuno, nano, etc. And I have no idea when I said "update esp8266" so I wasn't sure if you were reading or not. Also the error shows up when I open boards manager. Like after the board manager loads, thats when I get an error, so it saying  ESP8266 error downloading via the website url.

ok. now I understand the question. the missing information was "in IDE" or "package". try it without the github link in Additional boards URLs

If you are using windows 10 try installing from git followimg the instruction here.
https://arduino-esp8266.readthedocs.io/en/latest/installing.html
That was how I get it to work when I found updating it through the ide didn't work


text:
Arduino Pro Micro TX and RX leds flash quikly while power drawn from VCC pin
I just got a 5V Arduino Pro Micro, which I connected to an RC RX powered from the VCC and GND pins of the board.
However, whenever I do so and power on the board from a computer USB connection or a wall adapter USB connection, the board goes into an odd mode where the red RX and TX leds flash rapidly (~0.5s on and ~0.5s off) and USB serial ceases functionality. (presumably, because the MCU isn't on anymore)
If I remove the load and power the board again, everything works as normal.
This is an odd behavior, especially since I read online that the VCC pin is rated for ~150ma max and my device (FS-iA6b) isn't a very high power device, tested by me to draw 30-50ma max.
What is happening here? I haven't even connected the 5v signal pin yet!

It would help if you included a schematic.  It sounds like your receiver is drawing too much power.  Are you powering the micro from the USB port or from the RAW pin?  Try powering the micro using the RAW pin with a 4xAA battery pack.

@JeffWahaus I'm not really sure how to upload a schematic, it's a relatively simple set of interconnects: RC RX 5v VCC pin connected to Pro Micro VCC pin, RC RX GND pin connected to Pro Micro GND.

I've been trying to avoid adding an external power source if I can avoid it. The Arduino Uno had enough power on it to power the RC RX...

A standard USB port should be able to supply up to 500mA, it seems like either something is shorted or perhaps you have a 3.3V version of the Pro Micro.

Wouldn't the 4-6v RC RX not power on if the Pro Micro was 3.3v? It does power on.

Aah, I figured it out! @JeffWahaus was correct, the RC RX was placing too great a strain on the Arduino Pro Micro. My latest working theory is that when the RC RX is in communication with the RC TX, it has current spikes that allow the system current draw to exceed that required to drop the voltage coming out of the 5V regulator below that required to shut off the ATmega32U4 MCU.
The solution I found, upon recommendation, was to move the RC RX voltage source from the VCC pin to the RAW pin which taps power from ahead of the 5V regulator and add a 10uf capacitor in parallel with the RC RX to smooth out any current spikes.

simulate this circuit – Schematic created using CircuitLab


text:
What makes this library work exclusively with Atmega328P boards?
I've been looking into libraries that read CPPM signals that I can use on my Arduino Pro Micro, and this one looked promising (github.com/jmparatte/CPPM) until I read that it only works on Atmega328P chips. Sure enough, I tried it, and it doesn't function on the Pro Micro as it does on my Arduino Uno. Why is this the case, i.e. what does it have that the Atmega32u4 doesn't?

Implementation
This library works only on ATmega328 implementation of Arduino UNO,
  Duemillanove and similar, also Leonardo. It uses the 16bit Timer1. So
  PWM analogWrite() on pin 9 and 10 are unavailable. The library Servo
  is not compatible because it also uses Timer1.

I tried to do some research on my own, to no avail:

Timer1 isn't specific to 328P, 32u4 has it
For all I can tell, there isn't any difference in the interrupt capabilities of the 32u4...
ICR1 and TCNT are, again, features that the 32u4 has
My signal is connected to the OC1A pin that is used as the CPPM source (pin 9, PB5)

I'm new to this kind of thing and really stumped as to what could be the issue here.

That library relies mostly on Timer 1 and, as you already noticed,
the Timer 1 of the ATmega32U4 is very similar, if not identical, to
the one of the 328P. At least similar enough to expect the library to
work identically.
I took a look at both datasheets and the only difference I can see that
can possibly affect the library is the pinout. The pins relevant to the
library are:
       328P  32U4
ICP1 =  PB0   PD4
OC1A =  PB1   PB5

The pinout of the 328P is hardcoded into the library. CPPM.h contains
these lines:
#define CPPM_ICP1 8 // Input Capture Pin of Arduino UNO is pin 8 - ICP1 (Atmega328 PB0)
#define CPPM_OC1A 9 // Output Compare Pin of Arduino UNO is pin 9 - OC1A (Atmega328 PB1)

CPPM.cpp has two instances (here and here)
of this:
if ((PINB & _BV(PINB1))) // rising edge ?

If you change the code in these three places to match the pinout of the
32U4, I would expect the library to work for you.
You could also change that conditionally as
#ifdef __AVR_ATmega32U4__
    ...
#else // assume ATmega328P
    ...
#endif

in order to make the library compatible with both MCUs, and then submit
a pull request to the original author.

Excellent, when I get to it today, I'll try making that change. Thanks for the theory!

Hold on, what do I replace the PINB part with?

@ifconfig: PINB & _BV(PINB1) tests the state of the PB1 pin which, on the 328P, is the same as OC1A. On the 32U4 you would use OC1A = PB5 for the same purpose. The test then becomes PINB & _BV(PINB5).


text:
Keyboard.h not found
I keep getting this error message:
"'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?"

... when I have already included Keyboard.h.
#include <Keyboard.h>

void setup() {
  pinMode(3,INPUT_PULLUP);
  pinMode(4,INPUT_PULLUP);

 Serial.begin(9600);    //begin seral comms for debugging
}

void loop() {
  Keyboard.begin();
  if (digitalRead(3) == 0) //if button 3 is pushed
   {
Keyboard.write('z');
delay(200);
}
   else if (digitalRead(4) == 0) //if button 3 is pushed
{
  Keyboard.write('x');
  delay(200);
}
  Keyboard.end();
}

Keyboard.h is already included as a default library in Arduino so I'm not sure what's wrong

Which Arduino do you have? Please tag your question with that information.

Please update your question, stating which processor and/or board you are using.

If you have Arduino/Genuino Uno selected as your board in the Tools ► Board ► menu, then you get the error. If you select Arduino Leonardo it compiles correctly.
From Can't seem to be able use Keyboard.h library, this post states:

Keyboard.h (and Mouse.h) only works on devices that use the ATmega32u4 processor, like the Leonardo or Micro.  See: https://www.arduino.cc/en/Reference/MouseKeyboard

This solution might help though

I had the same problem using Flora
This worked for me:

Tools > Boards > Boards Manager
Install TeeOnArdu (Then select that board from Boards Manager)
Tools > USB Type > Serial, Keyboard, Mouse < Joypad
Upload and run code again (might need to restart IDE)

Great... btw, what Arduino board do you have?

was using a pro micro, it is detected as an arduino leonardo same chip i guess


text:
How to fix this code so instead of having to hold button to change led, you can press?
const int buttonPin = 1; // the pin number of the pushbutton input pin
const int ledPins[] = {2, 3, 4, 5, 10, 11, 12, 13};    // variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonPressCount = 0;
int numberOfLED = 8;

void setup() {    // initialize the LED pin as an output:
  for (int i = 0; i < numberOfLED; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
  pinMode(buttonPin, INPUT);
}

void loop() {    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);    // check if the pushbutton is pressed.    // if it is, the buttonState is HIGH:
  if (buttonState  == HIGH) {
    for (int i = 0; i < numberOfLED; i++) {
      if (buttonPressCount % numberOfLED == i)
        digitalWrite(ledPins[i], HIGH);  // turn LED on
      else
        digitalWrite(ledPins[i], LOW);   // turn LED off
    }
  }
  buttonPressCount++;
  delay(300);
}

instead of changing every time the buttonState == HIGH, change it when the button state was LOW the previous time but HIGH now:
buttonState = digitalRead(buttonPin);
if (oldButtonState != buttonState && buttonState == HIGH) {
    //...
}
oldButtonState = buttonState;

However keep in mind contact bounce. Which can result in multiple transitions being detected. Most solutions for that set a minimal delay between handling transitions, dropping all others detected.


text:
Does SoftwareSerial and the servo library produce interrupt conflicts?
I'm planning a project that will involve multiple serial ports and the Arduino servo library. I have heard that this may cause interrupt conflicts. Are there any simple solutions to this

I have heard that this may cause interrupt conflicts.

Indeed. The Arduino can only run one interrupt routine at a time, and:

Servos use rapidly firing interrupts
SoftwareSerial both turns off interrupts while sending (for relatively long periods)
SoftwareSerial uses an interrupt for receiving that runs for an extended period

So really you can't use both together.
Options?

Use hardware PWM to drive the servos (There is a library for this somewhere)
Use an external servo PWM driving board (Adafruit do one IIRC)
Don't use SoftwareSerial.  IIRC AltSoftSerial is better, though no software serial implementation will ever be particularly good.

The underlying problem is that the low-end Arduinos only have on serial port. If you need to use more than one serial port then you really need to be looking at using a different Arduino - one with multiple serial ports.


text:
Do I need the Ground and 5 V pin connect to Led?
I am building an ambilight. So I bought a 3 pin LED Strip which I power with the USB hub from my TV. Next step is to connect it to the Arduino Nano. Is it OK when I only use the dataport from the Aduino and the power only from the television?

I think it is not a good idea to power the LED strip via USB.
Normally USB delivers a maximum of mA  (see below). Assuming you have 30 LEDs (minimum for a normal LED strip), and each LED gives 40 mA (maximum), this is already more than what most USB ports can deliver. This can ruin your USB port.
For the Arduino Nano you can use the 5 V, and you should connect all GNDs together.
But you will need a decent adapter anyway for the LED strip, so than you can power your Arduino Nano from the adapter you use for the LED strip.
Update
According to Wikipedia USB power

Low-power devices (such as a typical USB keyboard) may draw at most 1
  unit load (1 unit load is 100 mA for USB devices up to USB 2.0, while
  USB 3.0 defines a unit load as 150 mA), and all devices must act as
  Low-power devices when starting out as unconfigured.
High-power devices (such as a typical 2.5-inch USB Hard Drive) draw at least 1 unit load and at most 5 unit loads (500 mA) for
  devices up to USB 2.0 or 6 unit loads (900 mA) for SuperSpeed devices.

I am totaly new to this but the lightstrip got a 5v connection it is a WS2812B strip with 300 leds. I use a 3.0 usb port but an old cable witch i got long before 3.0 was out does this made any differnce?

To be honest, I don't have much experience with current from USB, but 300 LEDs * 40 mA = 12 A, 12 A * 5 V = 60 W. Of course you can software wise make sure not all LEDs are on at maximum current at the same time, but this is not so safe (in case of a programming error).

Your TV certainly cannot power a strip this long. You will blow your USB port with this (at least). Keep in mind, that even most high power USB charger will only give you a few amps. You have to buy a 5V power source, that can actually handle this current. Also you should provide the power to both sides of the strip (Start and end of the strip) to avoid it getting too hot.

Yes, you can take +5v from the TV's USB and supply data from the Arduino, as long as you connect both the TV's USB-Ground and the Arduino-Ground together.

simulate this circuit – Schematic created using CircuitLab
Can you follow this? Connect all GNDs. TV 5V can power the Arduino, connect to the 5V/VCC pin and not the Vin pin.  5V power supply only powers the LED strip.  No reason it couldn't power the Arduino as well tho, in which case there would be no need to connect to connect anything to the TV.
PC USB ports typically can only supply 500mA, only enough for 8 RGB LEDs at full white. I doubt your TV can do much more.


text:
3V Arduino options
I have an Arduino Mega board to test 3V devices. Which is the simplest way to connect those 3V devices to the Arduino Mega (it works at 5V) without burning them? I saw the Adafruit Trinket works at 3V, could be an option? Since I need many input/outputs (around 50), Arduino Mega is the most suitable in terms of input/outputs pins.
What do you suggest me to do?

You can buffer the IO to/from the 3V devices. 5V down to 3V, use CD74HC4050 powered from 3V.  3V up to 5V, SN74AHCT541 powered from 5V.

There are plenty of non-Arduno boards that both give you more power and 3.3V operation.  Personally I love the chipKIT boards (the Max32 is the chipKIT equivalent to the Mega2560).
If you want to stick with Arduino then consider the Due, which is the same footprint as the Mega2560 but again with more power and 3.3V operation.
For interfacing 3.3V devices to a 5V board, though, that can be done simply with level shifters.  You need to get the right type though:

Basic GPIO, SPI and UART etc can be done with a simple MOSFET shifter (cheaply available on eBay)
I2C requires a special I2C level shifter (I use the PCA9306) which maintains the open-drain and bidirectional operation required for I2C

The devices work exactly at 3V (no 3.3V), The suggested board is suitable? Thanks @Majenko.

What devices are you using that run at exactly 3V?  And yes, most level shifters will go down as low as 1.8V

Are industrial devices. Great!

You will probably find that connectors marked "3V" are actually 3.3V - 3V is a very strange voltage to run on.  3.3V or 2.8V are common, but 3V is almost unheard of in electronics.


text:
Weird behavior (Couldn't pull the pin LOW)
I was trying to implement my own code to control a stepper motor on arduino uno, however I noticed that the pins were always HIGH despite what was written to them. I started to erase the code to leave only the crucial part to troubleshoot it and was left with the following
#define IN1  8
#define IN2  9
#define IN3  10
#define IN4  11
long int *period;

void setup() {
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
*period=256;
}

void loop() {
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
}

The period statements were leftovers from the previous code, and didn't think of them too much but once I deleted them the code started working. More over, the code worked if the period value was below 256. Once it reached 256 the pins weren't pulling low.
The problem is solved now, however I am interested why would a value of a variable cause such a behavior?

You have created a pointer, but didn't tell the compiler where that pointer is pointing to. Then you write a value to where the pointer is pointing to.

until 255 overwrites 1 byte in random location in memory. 256 overwrites two bytes

@Juraj always 4 bytes are written (or the number of bytes that contains a long int), even if values < 256 are written (than the other MSB bytes) will be filled with 0.

@MichelKeijzers, perhaps the byte affected by 256 should be zero. with 255 it stays zero. with 256 it is 1. it simply happens that the sketch works if he uses 255 and doesn't work with 256. I explained the difference

You are creating a pointer variable, not a normal variable.
That pointer variable is, until told otherwise, pointing at address 0x00.  It covers 4 bytes.
Addresses 0x00 to 0x1F are the internal CPU registers R0 to R31.  Your pointer variable points to R0 plus three more addresses above it (a long is 4 bytes in total).
So when you write to your pointer you are directly writing to CPU registers R0, R1, R2 and R3.
According to the AVR-GCC ABI:

R0 is the scratch register
R1 is the zero register
R2 & R3 are general purpose (call-saved) registers.

So if you write 255 to your pointer variable you are doing:
R0 = 255
R1 = 0
R2 = 0
R3 = 0

And that's no big deal: some things may go a little awry, but nothing major.
However, writing 256 results in:
R0 = 0
R1 = 1
R2 = 0
R3 = 0

The big thing here is that the zero register R1 is now 1, not zero.  The ABI states:

R1 always contains zero. During an insn the content might be destroyed, e.g. by a MUL instruction that uses R0/R1 as implicit output register. If an insn destroys R1, the insn must restore R1 to zero afterwards. This register must be saved in ISR prologues and must then be set to zero because R1 might contain values other than zero. The ISR epilogue restores the value. In inline assembler you can use __zero_reg__ for the zero register.

So R1 must be zero except for a brief moment when you use it for something else.  Since you're setting it to 1 and leaving it as one, any other operations that then rely on that register being zero will have a hard time knowing just what they are doing.
Having a "zero" register is a common thing. There are many times (especially in a RISC architecture) when you want the number zero - and having a register that is guaranteed to always be zero saves a lot of time. For instance, in MIPS the register $0 is hard-wired to be zero and can never change.  AVR doesn't have that luxury, but the GCC compiler imposes the rule for R1 which you have to abide by - since there are huge amounts of library code and other auto-generated code that rely on that register being zero.
So when it's set to one, all gloves are off, and no one can ever really know just what is happening - you'd have to disassemble the code (or get an intermediate listing out of the compiler) to see just what is using R1, and work out what the effect of that being 1 instead of 0 would be.
As an example, digitalWrite has this:
        if (val == LOW) {
 370:   11 11     cpse r17, r1
 372:   05 c0     rjmp .+10          ; 0x37e <digitalWrite+0x50>

That's "COMPARE SKIP IF EQUAL".  It's looking at the value you pass (val) to see if it's equal to zero - by using R1 as the zero value. But if R1 isn't zero then it will never know that what you passed as LOW is LOW - instead it would find HIGH as LOW, since HIGH is 1 and R1 is 1.  So you've basically swapped HIGH and LOW over as far as digitalWrite is concerned.
There are also places where the number 255 is wanted.  This is easy to generate with "eor r1,r1" - exclusive-or of the zero register. EOR turns bits off that are on and on that are off - so zero becomes 255. Except if zero is actually 1, you end up with 254 not 255, and more strange things happen.

You have an uninitialized pointer:
long int *period;

It will point to zero (or a register map, see comment Edgar Bonnet below), but you write 256 to it.
Since a long pointer points to 4 bytes, if you write values upto 255 only one byte will be filled (and others are 0), when you write a value from 256, another byte will be filled with a non-zero value.
Anyway, uninitialized pointers can result in strange effects, so initialize it like:
long int period;

long int* periodPointer = .

And set the content by
*periodPointer = 256;

Re “an undetermined address”: this is not the case here. Being a global, it is guaranteed to be initialized to zero by the C runtime. On an Uno, address zero is mapped to the register file, which can indeed produce weird results.

@EdgarBonet Thanks (didn't know about the register file, I should have known about the global). Just I'm always used to initialize every variable myself.

Thanks for the info and advice! But I just don't understand how whatever the variable contains or how the pointer is initialized would affect the pin state. Is the pin register somehow affected by the code?

That can be hard to find out ... however, what is most important, you hare changing 4 bytes 'somewhere' in the Arduino. This can (in theory) mean some execution code is changed, that the pin registers are changed, that some variables used either by the program or by the library are changed. To really find it out, you should check the value of the pointer, and (manually?) create a memory map of the Arduino (if at all possible).

Addresses 0x00 to 0x1F are the internal CPU registers R0 to R31. By writing to 0x00-0x03 you are affecting R0, R1, R2 and R3. R1, according to the AVR-GCC ABI should always be 0. It can be used temporarily, but you must reset it to zero afterwards. Since 256 will set R1 to 1, R1 is no longer zero - so all future operations that assume it is zero will be incorrect. And chaos ensues.


text:
HC-05/Arduino receiving spam data
I connected everything properly. On the first try I did receive data as  I was supposed to. I then wrote some logic, re-uploaded and started receiving crazy spam.
My serial monitor is getting spammed with:

question marks if the variable is char, or;
25252525252 if the variable is int, or;
-1 if variable is String.

I'm monitoring at 38400 baud which is the same as my Serial.begin().
Any ideas ?
Code:
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define MIN_PULSE_WIDTH 650
#define MAX_PULSE_WIDTH 2350
#define DEFAULT_PULSE_WIDTH 1500
#define FREQUENCY 50

char data = 'a';

void setup()
{
  analogReference(DEFAULT);

  Serial.begin(38400);

  pwm.begin();
  pwm.setPWMFreq(FREQUENCY);
  Serial.println("hello world");
}

void loop()
{
  data = Serial.read();
  Serial.println(data);
  Serial.flush();
  if (data == 'a'){
    pwm.setPWM(0, 0, pulseWidth(90));
  }
  if (data == 's'){
    pwm.setPWM(0, 0, pulseWidth(30));
  }
  delay(1000);
  //printing time in seconds
}

int pulseWidth(int angle)
{
  int pulse_wide, analog_value;
  pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
  analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);

  return analog_value;
}

Thanks, that seems to work for the spam. I changed my variable to integer and tried sending a number. No matter what I send, I receive either 120, 128 or 248, multiple times. What's the deal ?

you should first connect the Arduino to Serial Monitor and learn the basics of Serial communication on examples

It does, but why is it the same no matter what character I send ?

I cannot use answer since I am not logged in, which I cannot do since I have my password on remember on another machine.
I changed print to write, however I still am getting weird results.
1 corresponds to "x?" (with a reverse question mark) and 2 corresponds to "???". I'm so lost.

has the BT module a baud rate 38400 baud?

Serial.read() returns -1 if no data is available. It doesn't wait for the byte. Test for -1 or use Serial.available() as any example does.
Replace Serial.print(data) with Serial.write(data) to get the data echoed back unchanged.


text:
Arduino Uno with ESP8266-01. Is that any alternative way to connect Arduino Uno to Wifi
I have bought an ESP8266-01 Wifi module last month, and I am trying to connect Arduino Uno to network so that I could connect to the MQTT broker. However, I failed to upload the sketch/communicate with ESP8266 module due to the error:
espcomm_open failed
espcomm_upload_mem failed
espcomm_upload_mem failed

I think the problem is wiring problem or power supply is unstable because the ESP8266 is required 3.3V to communicate. This is how I connect ESP8266 Wifi module to Arduino Uno, and I just simply connect Arduino Uno to USB port on my laptop:

I've been searching solutions on Internet and watching tutorials but ending up with getting the same error. In addition, I am not using any resistor, capacitor when I do the connection between ESP8266 & Arduino Uno.
These are my confusions as below:

What is the best/easiest way to connect Arduino Uno to Wifi?
How can I avoid power supply issues? Maybe a Serial Adapter Wireless development board or module?
What do I need to connect Arduino Uno to Wifi?
Is it possible to connect Arduino Uno to MQTT broker without using network? I found this Ardulink but I don't know how to deal with it
Can external wifi shield solve my problem instead of using ESP8266-01?

Thank in advance

Are you trying to program the ESP8266 or program the Uno?

@Majenko I'm trying to program ESP8266, I have selected the Generic ESP8266 Board and correct COM port before I upload the sketch.

By the way, is it possible to program Uno & ESP8266 at the same time? I mean I have code for recording student attendance and it is uploaded to Uno, and I would like to publish attendance record which is stored inside EEPROM through MQTT broker to database by using ESP8266

why do you open new question same as the previous?

your question is too broad. solve one thing at a time. if you have a sketch in Uno, did you consider to use the esp0-01 with AT firmware with WiFiEsp library? without uploading your code to esp-01.

try swapping rx and tx: tx-rx, rx-tx. you also need rst-gnd on the uno.

The Arduino board does not have enough current available to power the ESP8266. You should have a 3.3 volt supply that is capable of at least 500mA. The average current consumption is typically 80mA but the peak currents can go to 600mA during a start up calibration.
You also need to use a proper level converter to connect the RX and TX of each board. The ESP8266 is NOT 5 volt tolerant.
The ESP8266 can be programmed under the Arduino framework. This is how most people use it. (rather than using the AT command set the board comes with. This is what I suggest, but is not a requirement. If you do go that way I suggest you get a NodeMCU or a Wemos type board to learn with. Just working with the ESP8266 alone. They are cheap, they have a USB to serial converter, and they have a proper regulator for Vcc.
The ESP modules are not simple to power. You have to use a good regulator and have it electrically close to the board. No 20cm jumper wires.
Continuing on with your electrical connections. Reset is not connected to ground. It should be pulled up to 3.3 volts with a resistor, typically 10K.
And external WiFi shield is a simpler option. I prefer the ESP8266 since it has a fast processor, 80 or 160Mhz. Lots of ram and up to 1MB of program space. It is my go-to board. It is a little light on IO but that is easy to add. It is cheap, and there is a huge user base for it.

I am not really familiar with these electrical connection stuffs, is that any simple way for the beginners like me? To avoid these kind of problems like power supply issues.

By the way, thank for the reply. It's really informative

The simplest way to work with the ESP8266 is to start with a development board. The ESP-01 has too few pins and less flash memory than modules like the ESP-12F, or the boards I listed. It is OK if you need to do an interface with RX/TX as you had planned. But like I said, it needs to be 3.3V. If the 3.3 volt power/signal level is acceptable for the application I would consider doing it all with the ESP. I did a data logger for work with the ESP. SD card, a current measuring chip, LCD, 3 button input, and no WiFi, as I didn't need it. Lots of power for cheap. Check out https://www.esp8266.com/

The website I listed above is a great place to get help and answers. Some of the websites, blogs, that show how someone did something is pretty hit and miss. Some good information, and some bad. And if you don't already know the right answers then you often don't know if it is good or not. The ESP8266 with the Arduino framework has been around for a few years and it is much easier to start with it now compared to 2015 when things were starting to get developed with it. This is a good introduction https://arduino-esp8266.readthedocs.io/en/latest/ It all is pretty overwhelming at first.


text:
Learn Arduino Basics : Temperature sensor with LCD Display and Potentiometer setup
I have temperature sensor, potentiometer and LCD screen attached to mini breadboard and wired to an Arduino. My temp sensor appears to be working fine however sometimes it reads inaccurate numbers which is unusual. It only does this when I have all my components on the same mini breadboard. When I detach then reattach my temperature sensor to a separate breadboard its hasn't been noticeably inaccurate. There is no issue but I was thinking that maybe the temperature sensor is hotter because its closer other to components or maybe because the close electrical wiring range is making it hotter. My solution is putting the temp gauge on another breadboard but I was save space to use one. Any ideas as why my gauge reads random hotter temperatures more often when sharing a board?

What temperature sensor do you have?

what do you mean by hotter?

LM35 temerature sensor. By hotter I mean; when the sensor begins reading inaccurately, the degrees ranges from 5-10 degrees hotter than what it should be.

It could be measuring the heat of nearby components, or it could be a wiring issue. Breadboards are convenient but it also allows people to use poor wiring practices. Long wires, poor ground return paths, insufficient bypass capacitors.
The first thing to do is to arrange the layout so that there is little chance of the other components heating the sensor. You might also try using a fan to blow on all the components. Make it so that if there is any heat generated it does not accumulate it the parts. If that clears up the problem then look into making a better thermal layout. Maybe with the sensor physically separate from the rest of the circuit.
If the fan makes no difference then you may need to consider the way it has been wired.


text:
Alternative Rx/Tx Pins for Arduino Uno and Pro Mini
Do they have specific pins that is best to be use as Rx/Tx pins (aside from D0 and D1)? If so, what makes them special?
edit: What pin feature i should look out for when choosing the rx/tx pin? Is there any specific pins that will make it a better rx/tx pin?

https://arduino.stackexchange.com/questions/34126/whats-the-difference-between-all-the-software-serial-libraries-which-one-is-ar

Pins D0 and D1 are used for hardware serial, see Serial library reference.
You can use any other pins for virtual Rx/Tx lines employing a software serial mode, for example by using the SoftwareSerial library, see Software Serial example, or by implementing your own custom code, or custom library.

for Mega and Leonardo, there are other recommended pins for rx/tx. do they have it on uno?

The Arduino SoftwareSerial library can use any pair of pins.
AltSoftSerial uses special pins. AltSoftSerial uses a 16 bit hardware timer to generate the transmit output and measure the receive input waveforms. The timer works on pins 8 and 9 on Uno and Atmega 328p boards.

thanks. So this is alternative library to software serial is it. i will read about it first.


text:
Arduino Adafruit playground: Adafruit_CPlay_LIS3DH.cpp:27:35: fatal error: Adafruit_CPlay_LIS3DH.h: No such file or directory
I've tried installing the Arduino Adafruit playground but came across the same error.
sketch\src\Libraries\Adafruit_Circuit_Playground\utility\Adafruit_CPlay_LIS3DH.cpp:27:35: fatal error: Adafruit_CPlay_LIS3DH.h: No such file or directory

 #include <Adafruit_CPlay_LIS3DH.h>

                                   ^

compilation terminated.

exit status 1

I don't really know what else I can try. I've tried reinstalling the library and
different versions of the Arduino IDE but is doesn't seem to work.
IDE version: 1.8.7
Playground version: 1.8.1

the error start with "sketch\src". where is your "Libraries" folder located?

Sorry completely forgot about this post. Apparently I had a folder in my project with the playground library that wasn't updated. When I removed this folder everything worked fine.


text:
What are the negative PINs for on the IndustrialShield M-Duino 58 Analog
I am working as an internship on an Arduino based PLC. It is the M-Duino 58 Analog from IndustrialShields. I try to figure out how it works; Reverse Engineering. But i dont know why it has negative Digital Inputs like normal Digital Input I1.0 also has a connection -I1.0.
It is probably a simple question but i cant figure it out. Hope you guys can help me.

I guess i figured it out. Seems to be the GND connections. Should read the Manual better next time.

Looks like the cathode of an opto isolator maybe? Would need a full schematic not a pinout diagram. The manual should tell you.

Thx, i guess these are the GND connections. Did not see it when i read the manual the first time.

Yeah, I think the inputs are all opto-isolated - so the input is actually a resistor and LED, with the "input" being the anode and the "-" being the cathode. It's hard to find any real information though, documentation seems to be a little poor.

The Manufacturer's documentation is at https://www.industrialshields.com/technical-features-industrial-m-duino-plc-arduino-ethernet-58-ios-analog-digital-plus

It looks like those inputs are opto-isolated. That means that the "input" goes through a resistor and the internal LED of an opto-isolator, which then comes back out of the "-" pin:

simulate this circuit – Schematic created using CircuitLab
So "-" connects to the ground of the remote device, and the "input" connects to the signal.


text:
STM32 and NRF send & receive
This is my send and receive code in STM32 (blue board).
But i can't send and receive data . why?
I did use Enrf24.h .
Enrf24 link: https://github.com/spirilis/Enrf24
send code is:
#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setTXaddress((void*)txaddr);
}

void loop() {
  Serial.print("Sending packet: ");
  radio.print("OONN");
  radio.flush();  // Force transmit (don't wait for any more data)
  delay(1000);
  Serial.print("Sending packet: ");
  radio.print("OOFF");
  radio.flush();
  delay(1000);
}

receive code is:
#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setRXaddress((void*)rxaddr);
  radio.enableRX();  // Start listening
}

void loop() {
  char inbuf[33];
  while (!radio.available(true));
  if (radio.read(inbuf)) {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  }
}

this image can help :

And the question is?

Thanks, i can't send and receive data . why? please see my image

You did not say which library you are using, but based on the #includes, I am assuming http://maniacbug.github.io/RF24
This line in your receiver code:
  while (!radio.available(true));

does not make sense. You are passing true to the radio.available() function, but the function does not care about a parameter.
You probably mean something like:
while (!radio.available());

When you pass in a variable, you are calling a variant of the function that expects a pipe number to be given, and true is defined as 1. Your transmitter, however, is not sending on pipe number 1.

I use this library   link  . in exmaple folder you can see some example  i did use Enrf24

First of all, remove
while (!radio.available(true));

after that use
PA_5 ----> SCK
PA_6 ----> MISO
PA_7 ----> MOSI

it will work correctly.

It is better answer for some reseans
in Enrf library you can not send data with write untill txbuf_len==0

size_t Enrf24::write(uint8_t c) {
  if (txbuf_len == 32) {
  flush();  // Blocking OTA TX   }
  txbuf[txbuf_len] = c;   txbuf_len++;
  return 1; }

dont use purge then

txbuf_len = 0

this is for read dat
#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const char *str_on = "ON";
const char *str_off = "OFF";
void dump_radio_status_to_serialport(uint8_t);
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setRXaddress((void*)rxaddr);
  radio.enableRX();  // Start listening
 // radio.autoAck(false);
}

void loop() {
  char inbuf[35];
  if (radio.read(inbuf))
  {
    Serial.print("Received packet: ");
    Serial.println(inbuf);
  }
}

this is write for write data:
#include <SPI.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#define ce_nrf PB12
#define csn_nrf PB13
#define irq_nrf PA0
Enrf24 radio(ce_nrf, csn_nrf, irq_nrf);  // P2.0=CE, P2.1=CSN, P2.2=IRQ
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
void setup() {
  Serial.begin(9600);
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  radio.begin();  // Defaults 1Mbps, channel 0, max TX power
  radio.setTXaddress((void*)txaddr);
}
int i=0;
void loop() {
  i++;
  Serial.print("Sending packet: ");
  Serial.println(i);
  radio.print("1234567890123456789012--------->");
  //radio.purge();
  delay(100);
}

what is in principle the difference between the code in question an code in answer? only the removed while (available)?


text:
Using c_str() on String for IPAddress with NTPClient provides wrong values
Libraries

NTPClient

Board
Olimex ESP32-POE board
Behaviour
I have written a code that connects the board to a local NTP Server (which is an embedded board). I tried assigning the IP Address of the above NTP Server using IPAddress and then convert it to c_str() to pass into the NTPClient constructor as follows:

 WiFiUDP ntpUDP; // udp socket object for NTP

 IPAddress NTPServer(192.168.3.11); // Local NTP Server IP Address

 NTPClient timeClient(ntpUDP, NTPServer.toString().c_str(), 0, 60000);

The reason for this is because the NTPClient class uses const char* for the IP Address of the NTP Server.
The values that are obtained once the code is flashed on the board are wrong because the timestamps are have the year 2106.
On the contrary, when I use
 NTPClient timeClient(ntpUDP, "192.168.3.11", 0, 60000);

and run the code on the board, this provides me perfect values of UTC time.
Why is there some discrepancy here?
Code
#include <Wire.h>
#include <ETH.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <RTClib.h>

WiFiUDP ntpUDP;
/* IP CONF for NODE */
///////// >>>> MODIFY Values Here <<<< ////////
const IPAddress node_static_ip(192, 168, 3, 101);
const IPAddress default_gateway(192, 168, 3, 250);
const IPAddress subnet_mask(255, 255, 255, 0);
const IPAddress dns_add(192, 168, 3, 250);
const IPAddress NTPServer(192, 168, 3, 11);

NTPClient timeClient(ntpUDP, "192.168.3.11", 0, 60000); // This works
NTPClient timeClient(ntpUDP, NTPServer.toString().c_str(), 0, 60000); // This won't (provides timestamps of 2106)

void setup() {
  // put your setup code here, to run once:
  Wire.begin(I2C_SDA, I2C_SCL);
  Serial.begin(115200);
  ETH.begin();
  ETH.config(node_static_ip, default_gateway, subnet_mask, dns_add);
  delay(1000);
  if (!rtc.begin()) {
    Serial.println("No RTC");
  }
  timeClient.begin();

}
void loop() {
  // put your main code here, to run repeatedly:
  timeClient.update();
  Serial.println(timeClient.getEpochTime());
  DateTime now_time(timeClient.getEpochTime());
  Serial.print(now_time.year(), DEC);
    Serial.print('/');
    Serial.print(now_time.month(), DEC);
    Serial.print('/');
    Serial.print(now_time.day(), DEC);
    Serial.print(now_time.hour(), DEC);
    Serial.print(':');
    Serial.print(now_time.minute(), DEC);
    Serial.print(':');
    Serial.print(now_time.second(), DEC);
Serial.println();

  delay(2000);

}

Don't you mean toString().c_str(), not toString.c_str()?

Sorry Typo! I meant the latter.

I thought so, since the former doesn't compile.  A simple test of printing to serial works fine. I suggest adding that into your program to make sure it's actually converting it wrong and not something else.  Serial.println(NTPServer.toString().c_str());

The String object created as return from IPAddress.toString() as parameter to constructor of NtpClient is temporary. It contains the char array returned by c_str(). NTPClient doesn't copy the string, only stores a reference to it. And the referenced string (char array) doesn't exist at the time the NTPClient wants to use it.
class TestClass {
public:
  TestClass(const char* _ip) : ip(_ip) { }

  void test() {
    Serial.println("--");
    Serial.println(ip);
    Serial.println("--");
  }

private:
  const char* ip;
};

//String s("abc");
//TestClass Test(s.c_str()); <- this works

TestClass Test(String("abc").c_str()); // <- this can't work

void setup() {
  Serial.begin(9600);
  Test.test();
}