text:
How Should I Send Data to My Laptop from Multiple Arduinos?
I'm working a project which involves reading multiple RFID tags, from multiple directions, at the same time. Because of the multiple directions, I need to use multiple antennae. Because of the multiple tags, I need to use a simultaneous RFID reader.
Unfortunately, the wiring of the simultaneous RFID reader doesn't support multiple antennae, so each antenna will need its own simultaneous RFID reader. It seems likely - although I'm waiting for confirmation on this - that each RFID reader will have to have its own Arduino as well. What's the least horrible way of sending the data those antenna-reader-Arduino combinations are gathering to a laptop?
If this makes a difference, the laptop I'm going to be sending the data to will be running Ubuntu, and I'd like to collect the data using Python's pyserial package. Once I've got the data in a Python program, we're home and dry.

Maybe SPI to get the data from the RFID  Arduinos to the main Arduino. From there simply Serial

Plug the Arduinos into a USB hub then plug the hub into your laptop. Open and read from multiple serial ports at once in your code.

An Arduino Mega might provide hardware serial channels for the RFID tag readers.

There are multiple solutions but the simplest one is probably to use Software serial, I2C, or SPI. The idea is basically the same for any of the protocols. You select one Arduino which is gonna be the master and be connected to the laptop. Than using any of those interfaces you connect the Arduino boards in to a chain. Than you can ask the slave Arduino boards if they have new data one by one. If they do they send it and the master forwards it to the laptop. In this way all the slave boards will wait until they are asked for data and thus avoid collisions of data streams.

If you have not purchased the Arduinos yet, you could consider using the ESP8266 ("Arduino-like" with embedded wifi module, and not much more expensive, depending on the project size). Then you use your laptop as a server, and each ESP8266 sends the data via wifi to the laptop.
Arduino as a client (via wifi): https://www.arduino.cc/en/Reference/WiFiClient

Here is an example of a project where I have done that although I used arduino with ethernet shield, the principle is the same. Also I used arduino as a REST server (instead of as a client). This meant that the server (PC) polls the Arduinos for data. But  this can be reversed using arduino as the client. https://www.instructables.com/id/Household-Environmental-Monitor-IoT-Solution/


text:
Reading consecutive two pulse periods continuously
I'm controlling the DC motor/fan speed by PWM through varying analog input. Using Uno or Nano.
The loop is as follows:
void loop()
{
  val = analogRead(analogPin0);  // read the analog input pin
  analogWrite(pwmPin9, map(val, 0, 1024, 0 , 255));
}

Above analogPin0 value is varied by a poti.
But I also want to output the rpm on an LCD. To do that I need to measure the period between two consecutive pulses as shown below:

How could I measure continuously "period between two consecutive pulses"? Should I use interrupt? Does anybody have any experience with that?

About what time range are we speaking here for the period?

One pulse period from minimum 4ms up to 100ms

why do you need to measure the signal? ... you know exactly the value of the parameter that you are passing to the analogWrite() function

I dont know the exact rpm just the duty cycle

did you forget to tell us about a revolution sensor? ... it is unclear how you expect to determine the fan RPM from the pulse width of the power supply voltage

I see 2 ways to go here:

You could attach a simple interrupt for rising edge to the pin with attachInterrupt() and count the rising edges with a variable. If the third rising edge is sensed, you have 1 period. To measure the time you can save the starting time of the first rising edge to a variable with micros() (which gives you the time since startup in microseconds). At the third rising edge save the time difference between start and end to another variable (declared volatile): micros()-start_time. This variable can then be displayed in your loop() function. Be sure to only copy the variable to a local variable in this part and deactivate interrupts during this operation with noInterrupts() (reactivate interrupts after that with interrupts(). Also you should use an atomic flag variable (atomic meaning, that writing or reading this variable cannot be interrupted. For example if you use byte or any other 1byte variable) to show the loop() function, that there is new data to display. Only if that's the case, the code in the loop() function would process the data.
If you want to go fancy or if you want to measure higher speeds (lower periods), You can use the hardware of Timer1 as counter. You give the Timer1 your signal as clock input. On every edge the timer value get's incremented by 1. So when the timer value is 5, one period has passed. You can use the timer in compare match mode, so that it will generate an interrupt, if a special value (here 5) is in the timers value register. In that ISR (Interrupt Service Routine) you would record the current time with micros(). On compare match the timer will generate the interrupt, set the value to zero again (if configured right) and again start to count. So the period would be the time between 2 consecutive time measurements. Displaying in the loop() function can be handled similar to the principle above.

It might also be good to directly take a mean of the period (to filter out noise in the period) by counting, until multiple periods have gone by. In the first case you could count to 11 to get 5 periods. Then divide the time difference by 5 to get 1 period. For the second case you can set the Timer1 match register to 21 to get 5 periods. Here also divide the time by 5 to get 1 period.
Since you seem to be a beginner, I would suggest the first way: Using attachInterrupt(). The second way is more if you want to dig into the microcontrollers registers and the descriptions in the datasheet.
The first way could look something like this:
const int pin = 2;

volatile byte counter = 0;
volatile unsigned long start_time;
volatile unsigned long period;
volatile byte data_flag = 0;

void speed_ISR(){
    counter++;
    if(counter==3){
        unsigned long now = micros();
        period = now - start_time;
        data_flag = 1;
        start_time = now;
        counter = 1;
    }
}

void setup(){
    pinMode(pin, INPUT);
    attachInterrupt(digitalPinToInterrupt(pin), speed_ISR, RISING);
}

void loop(){
    if(data_flag){
        noInterrupts();
        unsigned long local_period = period;
        data_flag = 0;
        interrupts();
        // Now display the period on the LCD her
    } else {
        // Print zero to the LCD
    }
}

The code gives you the opportunity to write zero to the LCD, when there is no pulse input (hence no data --> data_flag has to be zero). This may be uncomfortable to read on low pulse frequencies, if the LCD doesn't need longer to display the results as the next pulse will be measured, as it might display zero and the next measurement in fast succession. You could either use millis() to set data_flag to zero after a specified time (instead of resetting it near the LCD code), or you can limit the display rate like the blinking is done in the BlinkWithoutDelay example, that comes with the Arduino IDE.
Note that this code is not tested.

I get an error as : expected primary expression before "==" token. this is at the line if(byte==3){

will byte be counter?

And also having "'NoInterrupts' was not declared in this scope "

Ok, typing errors. Yes, the if statement in the ISR should be with counter. Also it is noInterrupts(), not notInterrupts. Sorry, I have changed my answer

And there are missing 2 semicolons in the ISR. I hope now it is structually sound

Which pins instead of pin 2 I can use?

I changed the attachInterrupt call, to make it really correct as in the documentation. You can look [here][https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/] for a table, which pins can be used. The documentation says on the Uno you can use the pins 2 or 3.

micros() should be called only once within the ISR: unsigned long now = micros(); period = now - start_time; start_time = now; ... Note that only period and data_flag need to be volatile. counter and start_time can be static locals of speed_ISR().

About the volatile variables: Yes, you are right. About micros(): Why shouldn't micros() be called multiple times? The value will not change during the ISR, since this relies on interrupts

@chris Could you update your code? Will this part be outside of ISR unsigned long now = micros();
period = now - start_time;
start_time = now;
?

The call to micros() takes a non-trivial number of cycles. And its value will change during the ISR, as it relies on a timer.

My another issue I couldn't modify the program to output zero when there is no pulse input.

if(!data_flag) would do it I guess?

@atmnt I changed the code again, since Edgar is right about micros(). Unlike millis(), micros() will also change during an ISR, since it reads directly from the timer register. I also added the requested functionality, a description about the pitfalls and how to avoid them.

An interrupt off of one of the timers sounds like the easiest way to go. To get a measurement precision of, say 3% at 4ms means sampling every (4000us * .03) = 120us (8.333 KHz). If your code has little else to do, you might get away with clock-watching - micros() ticks every 4us - but you'll need to keep anything else you do between reads of micros() to under 120us, and half of that might be a good target figure.
In this answer I described a general non-blocking procedure for managing several tasks in a timely way. If you chose such a design, one task might manage the potentiometer and analog output, another one the RPM measurement, and another the LCD. The ISR would do nothing but set a flag.
The RPM & LCD tasks can run at a relatively low rate as they're intended for human consumption only. They may have to work piece-wise, though, to meet their time restrictions.

source: Stack Exchange

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

sort: votes


text:
Controlling a servo motor with two arduinos?
I have two Arduinos, two buttons and one servo motor.
I want to control a servo motor with two Arduino's when I pressed the buttons. I linked Arduino PWM pins (first Arduino PWM pin is 9, and second one is 3) to the servo motor signal input.
When I pressed button 1 servo motor moving a few, or pressed button 2. but the signal isn't clear, and servo motor doesn't move correctly that I assigned degree.
What can I do for the solution?
My first Arduino code is here:

#include<Servo.h>

#define Buton 8

Servo myServo;

void setup() {
  pinMode(Buton, INPUT);
  myServo.attach(3);
}

void loop()
{
  if (digitalRead(Buton) == 1)
  {
    myServo.write(90);
  }
  else
  {
    myServo.write(180);
  }

}

and second arduino code is:
#include<Servo.h>

#define Buton 8

Servo myServo;

void setup() {
  pinMode(Buton, INPUT);
  myServo.attach(9);
}

void loop()
{
  if (digitalRead(Buton) == 1)
  {
    myServo.write(90);
  }
  else
  {
    myServo.write(180);
  }

}

You do you have 2 Arduino's in the first place? Do you really need both?

we have to use mcu.but it's not have to be arduino. does it change if we use a different mcu's?

that does not answer the question why you need two arduinos

You can't just connect random pins together like that. Connecting two output pins together is a recipe for disaster. Best case scenario: nothing works. Worst case scenario: you break one or both Arduinos.
Only one Arduino can control a servo. If you want a second Arduino to make something happen to the servo you have to make it tell the Arduino that is controlling the servo that something should happen.
That could be a simple output of the second Arduino connected to an input of the first Arduino, in which case it kind of acts like a button. Or you could create some kind of communication channel between them - maybe using a Serial connection, or a Wire (I2C) connection. There's many ways, and which is best depends on how much control one Arduino needs to exert over the other.

thank you for your answer @Majenko, but let me explain. we are a rocket team and we have to use two flight control system. so we use two arduinos for this rocket. first arduino is main controller and second is backup system. we have different sensors but we have one motor to deployment. we want to use second arduino if the first arduino won't work. I don't know if it's descriptive?

Then you need to have some device that sits between the two arduinos and the servo and selects which Arduino is allowed to talk to the servo. You could have one Arduino in "standby" monitoring the other Arduino and, if it fails, flip the "switch" that allows it to control the servo and have it take over.

@Giray Hakan When you are talking about backup in case of failure, you first must define the cases of failure, that you want to mitigate here. There might be many different ways, in that the system can fail and which have to be sensed and mitigated in a different way.

@Majenko what type of device? can you give a example?

You could use a MUX chip. Or a relay. There's many solutions both mechanical and silicon based.

ok, thank you, i will try.

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


text:
Arduino Bluetooth communication is slowing down because of the 'for' loop!
I'm sending data to Arduino through the mobile app. So far, all the code has been running consistently.

#include <SoftwareSerial.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#define NUM_LEDS_PER_STRIP 48
SoftwareSerial bluetooth(53,52);    // TX,RX
int bar_analog=0;
int head_analog=0;
int bar_anim=0;
int anim=0;
int motor_speed=1;
int direct=0;
int level=0;
CRGB strip1[NUM_LEDS_PER_STRIP];
CRGB strip2[NUM_LEDS_PER_STRIP];
CRGB strip3[NUM_LEDS_PER_STRIP];
CRGB strip4[NUM_LEDS_PER_STRIP];
boolean debug = true;
int IN1a=49;
int IN2a=48;
int PWM1=3;
int IN1b=22;
int IN2b=23;
int PWM2=4;
int hiz=100;
int PWM_kare=2;
int INA_kare = 51;
int INB_kare = 50; //LED '+'sı OUTPUT B'de olduğu için INB'yi  HIGH yapıyoruz.
void m1_cw() {
digitalWrite(IN1a,HIGH);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,hiz);
}
void m1_ccw() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,HIGH);
analogWrite(PWM1,hiz);
}
void m2_cw() {
digitalWrite(IN1b,HIGH);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,hiz);
}
void m2_ccw() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,HIGH);
analogWrite(PWM2,hiz);
}
void m1_stop() {
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
analogWrite(PWM1,0);
}
void m2_stop() {
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
analogWrite(PWM2,0);
}
void mast_up() {
digitalWrite(24,HIGH);
digitalWrite(25,LOW);
}
void mast_down() {
digitalWrite(24,LOW);
digitalWrite(25,HIGH);
}
void mast_stop() {
digitalWrite(24,LOW);
digitalWrite(25,LOW);
}
void kare() {
analogWrite(PWM_kare,head_analog);
digitalWrite(INB_kare, HIGH);
digitalWrite(INA_kare, LOW);
}
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show();
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show();
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show();
}
}
void setup() {
  Serial.begin(9600);
  bluetooth.begin(9600);
  Serial.println("Program is starting...");
  Serial.println("by Berke Ogulcan Parlak");
pinMode(IN1a,OUTPUT);
pinMode(IN2a,OUTPUT);
pinMode(IN1b,OUTPUT);
pinMode(IN2b,OUTPUT);
pinMode(PWM1,OUTPUT);
pinMode(PWM2,OUTPUT);
pinMode(24,OUTPUT);
pinMode(25,OUTPUT);
pinMode(INA_kare, OUTPUT);
pinMode(INB_kare, OUTPUT);
pinMode(PWM_kare, OUTPUT);
digitalWrite(IN1a,LOW);
digitalWrite(IN2a,LOW);
digitalWrite(IN1b,LOW);
digitalWrite(IN2b,LOW);
digitalWrite(PWM1,LOW);
digitalWrite(PWM2,LOW);
digitalWrite(24,LOW);
digitalWrite(25,LOW);
digitalWrite(INA_kare, LOW);
digitalWrite(INB_kare, LOW);
digitalWrite(PWM_kare, LOW);
FastLED.addLeds<NEOPIXEL, 26>(strip1, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 28>(strip2, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 30>(strip3, NUM_LEDS_PER_STRIP);
FastLED.addLeds<NEOPIXEL, 32>(strip4, NUM_LEDS_PER_STRIP);
FastLED.setBrightness(0);
}

void loop() {
  while (bluetooth.available())
    {
      bar_analog = bluetooth.parseInt();
      head_analog = bluetooth.parseInt();
      bar_anim = bluetooth.parseInt();
      anim = bluetooth.parseInt();
      motor_speed = bluetooth.parseInt();
      direct = bluetooth.parseInt();
      level = bluetooth.parseInt();
      if (debug) {
        Serial.print("Bar Brightness: ");
        Serial.println(bar_analog);
        Serial.print("Bar Animation Type: ");
        Serial.println(bar_anim);
        Serial.print("Headlight Brightness: ");
        Serial.println(head_analog);
        Serial.print("Strip Animation Type: ");
        Serial.println(anim);
        Serial.print("Motor Speed Level: ");
        Serial.println(motor_speed);
        Serial.print("Direction: ");
        Serial.println(direct);
        Serial.print("Mast Goes: ");
        Serial.println(level);
        Serial.println("--------------------------------");
      }
      if (bluetooth.read() == '\n') {

  }}
        kare();
       if(direct==1) { //ileri
  m1_ccw();
  m2_ccw();
  }
else if(direct==2) { //geri
  m1_cw();
  m2_cw();
  }
else if(direct==3) { //sol
  m1_ccw();
  m2_cw();
  }
else if(direct==4) { //sağ
  m1_cw();
  m2_ccw();
  }
else if(direct==0) { //durur
  m1_stop();
  m2_stop();
  }
if(level==1) { //mast yukarı
  mast_up();
  }
else if(level==2) { //mast aşağı
  mast_down();
  }
else if(level==0) { //mast durur
  mast_stop();
  }
if(anim==2) {
  strip_dim();
  }
else if(anim==0) {
  strip_stop();
  }
  }

But when I added the for loop to the code, all the data started to shift. (When I press the button from the application 'lag' occurs and the data is mixed.)I mentioned that part of the code below. Why does the data shift?
void strip_dim() {
for(int i=0;i<256;i=i+10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show();
}}
for(int i=255;i>=0;i=i-10) {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(i); //Parlaklık
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show();
}}
}
void strip_stop() {
for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
FastLED.setBrightness(0); //Parlaklık
strip1[j] = CRGB( 100, 172, 45); //leds[0] şeritteki 1.Ledi ifade eder. (Buradaki leds variable'dır.)
strip2[j] = CRGB( 100, 172, 45);
strip3[j] = CRGB( 100, 172, 45);
strip4[j] = CRGB( 100, 172, 45);
FastLED.show();
}
}

Why are you using software serial on a Mega?!?!

Your chief problem is that FastLED turns off interrupts when sending the data. It does that because timing is critical, and with interrupts turned on that timing will get completely messed up.
So with FastLED running repeatedly in a loop there is very little time when interrupts are enabled for reception to occur over SoftwareSerial.
Unlike a real UART, which can receive and store a byte before triggering an interrupt, SoftwareSerial triggers an interrupt to at the start of receiving a byte and that interrupt routine is used to do the actual reception. So if interrupts aren't enabled at the moment a byte starts arriving on the GPIO pin it can't start receiving, so it misses the byte and it ends up a mess.
Since you are using an Arduino Mega there is absolutely no reason for you to use SoftwareSerial. You have plenty of real hardware UARTs available to connect your Bluetooth device to which will be able to receive a byte while FastLED is sending out data (as long as it's not sending out data for too long...).

Upvoted your comment, and your answer gave rise to a question from my side related to your answer. I hope you can take a short look at it. https://arduino.stackexchange.com/questions/67381/does-dmxserial-stops-interrupts

First of all, thank you for your answer, but I don't know much about UART. What kind of change should I make in code to use UART instead of SoftwareSerial?

You are creating an instance of a class a lot of times (25 * 48 * 8 + 255 * 48 * 4 = 58,560 times), and that is a costly operation.
Instead, make one instance (before the for loops), and use that to assign everywhere you need it.
Something like;
CRGB crgb( 100, 172, 45);

for(int i=0;i<256;i=i+10) {
    for(int j=0;j<NUM_LEDS_PER_STRIP;j++) {
        FastLED.setBrightness(i);
        strip1[j] = crgb;
        ...

Good point. However, if setBrightness is doing serial communications, >58,000 loop iterations is still going to take a substantial amount of time.

@DuncanC True, but I didn't want to change functionality.

Thanks for the comment but there hasn't been any change.


text:
Does DmxSerial stops interrupts?
I am trying to build a setup with an Arduino Mega, having a DMX output (using DMXSimple library), and a MIDI library (to be done).
I was wondering, if I get into problems. According to This question, where Majenko's answer mentions that FastLED holds interrupts, I wonder if I can get into problems if I try to read MIDI data from 3 serial ports while sending DMX.
Probably FastLED (for led strips) and DMX (250 kbps) have some similarity. DMXSimple works with just one data line (no UART), but MIDI is using UART (31.25 kbps), 3 UARTS.
My fear is that everything works separately (I tried it before, long time ago with MIDI), but when I try to combine it, I get timing problems.

Yes, it does disable interrupts when sending a byte:
#if defined(__AVR__)
void dmxSendByte(volatile uint8_t value)
{
  uint8_t bitCount, delCount;
  __asm__ volatile (
    "cli\n"                            <<==== DISABLE INTERRUPTS
    "ld __tmp_reg__,%a[dmxPort]\n"
    "and __tmp_reg__,%[outMask]\n"
    "st %a[dmxPort],__tmp_reg__\n"
    "ldi %[bitCount],11\n" // 11 bit intervals per transmitted byte
    "rjmp bitLoop%=\n"     // Delay 2 clock cycles.
  "bitLoop%=:\n"\
    "ldi %[delCount],%[delCountVal]\n"
  "delLoop%=:\n"
    "nop\n"
    "dec %[delCount]\n"
    "brne delLoop%=\n"
    "ld __tmp_reg__,%a[dmxPort]\n"
    "and __tmp_reg__,%[outMask]\n"
    "sec\n"
    "ror %[value]\n"
    "brcc sendzero%=\n"
    "or __tmp_reg__,%[outBit]\n"
  "sendzero%=:\n"
    "st %a[dmxPort],__tmp_reg__\n"
    "dec %[bitCount]\n"
    "brne bitLoop%=\n"
    "sei\n"                             <<==== ENABLE INTERRUPTS
    :
      [bitCount] "=&d" (bitCount),
      [delCount] "=&d" (delCount)
    :
      [dmxPort] "e" (dmxPort),
      [outMask] "r" (~dmxBit),
      [outBit] "r" (dmxBit),
      [delCountVal] "M" (F_CPU/1000000-3),
      [value] "r" (value)
  );
}

Also that routine is run from within a timer interrupt routine. On AVR with no interrupt priorities even without disabling interrupts it would still be blocking all other software from running.

Thanks for answering so fast, do you think it could give problems to MIDI input? 3 serial ports, 31 kbps? Or is this so slow, the MIDI will be handled between calls to dmxSendByte of this library?

It's not the baud rate that is a problem, but how rapidly bytes arrive. There has to be time to put the incoming byte into the RX buffer before the next byte arrives, and DMXSimple will end up creating windows where that can happen. If you have two bytes arriving between windows then one will be lost.

Ok (I hope because I use hardware UARTs, the RX buffer will be filled before this problem happens. Anyway, I will do some testing of 'simultaneous' MIDI and DMX together. Thanks for the insights.

There is (IIRC) only one byte of hardware RX buffer. It has to be emptied by the RX interrupt before the next byte arrives.

Ok ... that means thus 32 us, but that seems longer than the time for executing those 20 instructions ... so it could be ok :-)


text:
Two flow sensors, one ESP32, LCD and/or Arduino
I want to build a flow meter but the Gal/Min rating of something like this flow meter is too low. I am thinking of strapping two side by side with suitable plenums for In and Out.
I have found some sketches like this but wondering how to use the two inputs to aggregate the results to GPM and Gallons total for display on an LCD screen. I am unsure what happens if two Hall-results arrive at or about the same time but on different Data Pins.
I have priced some single sensors with a higher flow rate for the pipe size but they run to several hundred dollars. Gallons are not critical as long as I can be within about 5% error over ten minutes, our average tank fill time.
Can someone please point me at some code to get me started for an ESP32 and LCD. I'd even consider adding a Nano if that makes things easier. I imagine that would certainly prevent collision issues. Basically I need to be able to handle the flow rate to a single LCD.
Thanks

A Hall Effect Sensor like that just gives you a pulse every rotation (or two pulses per rotation, etc) of the internal vanes.
If you use interrupts to count the pulses then two pulses arriving at the same time will be handled sequentially. The interrupt flag indicating a pulse has arrived is set in hardware the moment the pulse arrives, and the CPU checks all the interrupt flags between instructions. Each flag is handled sequentially, the order determined by interrupt priority settings and a "natural" order determined by the internal wiring of the CPU.
However there is a better way on the ESP32, and that is the Pulse Counter peripheral.  This is designed to count pulses like the signals from Hall Effect sensors.
You can just leave the Pulse Counter counting your pulses, then periodically read and reset the pulse count to see how much water has flowed in that period. It looks from the documentation that you can have two inputs both making the same counter increment, so it will do the aggregating for you.

Great, thanks, but reading those docs and the example code it is a little out of my programming league. Would the 2-Inputs go to the same pin or different pins? I am not sure why they say that that two ports need to be shorted. I need to find some existing code. I seem to be able to understand it better by reading code than docs. I am old. :)

There is an example linked from that page. It's not for the Arduino IDE, but you can take most of it. The whole of the IDF SDK is included with the ESP32 core in the IDE, so all the function calls they detail there work fine.

Thanks again, that was the "code" I was referring to above. I looked at the .c page, but still unsure where and how the second input goes for it to be amalgamated in the count. I have a small version flow sensor arriving a few days to test, but would like to find some code that already uses two inputs. I am not that smart --yet.

TBH I only just found that peripheral exists. I have no clue how to use it. It seems that each counter has two "channels" which can be either count up or count down. Each channel is associated with one pin (no idea what pins). The ESP-IDF is much better documented than many frameworks though, so it shouldn't be too hard to work out.

Cross referencing that documentation with the code and the ESP32's datasheet should reveal clues.

I found a YT video that explains some uses of the PCNT and it doesn't seems to be what I am looking for. It appears to be more like a trigger system that will flag an event at a count milestone. https://www.youtube.com/watch?v=vk5QZnWdlAA but thanks for your help anyway. I guess it is back to using Interrupts and given you comments above about them being handled sequentially I think I can make that work for what I need. Thanks again for taking the time to explain stuff.

I would recommend you spend a few hours watching basic electronic tutorials than double that time watching Arduino Tutorials.


text:
Sketchy Wemos D1 mini Pro
Recently, I bought a "ThingPulse ESP2866 Wifi Color Display Kit". I bought the kit before reading the reviews and finally read them the other day. Some of the reviews seem fake but a couple of them say that the Wemos D1 mini pro is being used to "steal credit cards" and other information. The bad reviews claimed that when they plugged the wemos into a power source, a wifi network named "ESP_xxxxxx" appears and thats how their data is stolen. I plugged the Wemos that came in my kit to a power source and a wifi network starting with "ESP..." appeard. I was wondering if this is a valid concern or if its just conspiracy. I am not very informed on cybersecurity and data security so I thought this would be the best place to ask. Please let me know if you'd like anymore information.  Thank you!

It's pure conspiracy, paranoia, or people just generally not having the slightest clue what they have bought. By default the ESP8266 is in Access Point mode, and named ESP_[last 6 chars of MAC address]. It will have an IP address in the range 192.168.4.x. And that is all.
It can't do anything else until you actually program it to do something.
Part of the "problem" is probably that the ESP8266 remembers WiFi settings independently of the sketch that is running on it. It's only the WiFi settings it remembers, though - not what to do with any data that travels over WiFi. That is purely down to whatever sketch you install.
Unless you manually program it so it connects to your WiFi, or add extra hardware for other communications, the device can not, and will never be able to, send any data to anyone, anywhere, ever. Full stop.

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

Before you’ve programmed the WEMOS, it will appear like an access point. It’s one if it’s great qualities of this versatile little chip. I wouldn’t worry about it. Don’t you have a secure vault for your personal info? It’s very easy to encrypt. Just search the internet on how to protect your data. You can really go it the safe way and implement a VPN. You might have to pay a 1-2$ a month for the service, which is actually a cloud based service.


text:
No Data Received on Serial Port & Unable to DFU Reset. Advice?
Having a problem running my original code that I tested last week, which worked on multiple days last week.
I tried to do a DFU reset and update the BootLoader, but it didn't work. I checked the baudrate and board selections in the Tools tab, but those were fine.
I didn't change anything in the code, I checked the wires on the hardware setup (nothing looks loose).
Thought it could be an error with the USB cable, changed the USB cable to a different one, still same error.
Also - using a Mac. But the same issue arose on the Windows PC. Did not try to reset using the Windows computer, but reset issue has more to do with the other hardware?
Checked the serial port - and it's selected to right one.

Maybe you should choose the right serial port.

True, forgot to mention that. I did check that though, I only have one serial port (have a driver to be able to get serial data on the Mac - and that has worked). It's selected to the only valid serial port.

Clarification - to do a DFU reset - you have to make sure the DFU and ground pins are connected with a jumper wire. You click the reset button - and try to update the bootloader?

Well, the port you have selected is (the hint is in the name) a bluetooth port, not a USB port.

Whoops - okay thanks. Don't know much about UART - that specifies serial communication? The two devices use SPI and I2C.

It seems to be working. Thanks.

Step Zero - check that the port selected works.
Step Next -  if you still get the error, try the DFU reset options and follow the steps outlined in the link below.
https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/using-the-bootloader

It's OK to accept your own answer as the solution to the problem.


text:
Using CoolTerm to receive Serial Data into a saveable file
Have functional code that reads data from sensors. Found that I need to use a terminal program to grab the data from the serial output using CoolTerm by Roger Meier.
Wasn't able to test it with my code yet because of this issue: (No Data Received on Serial Port & Unable to DFU Reset. Advice?).
Watched some videos and read some tutorials - does CoolTerm only come into play once I'm running the code? Can you write code for the arduino to automatically save stuff?

CoolTerm can save incoming data to a text file. In the help section, you can read about "Received data can be recorded to textfile using Connection/Capture to Textfile.", "Capture Text Options", "Leave File open while capturing" and "Add timestamps to received data".

VE7JRO - No, I get that CoolTerm can save data to a .txt file. But you have to open the CoolTerm GUI to do that right?

The CoolTerm app has to be running to capture data. Closing the app closes the serial connection and stops data logging. I un-checked the "Leave file open while capturing" check box under options > receive so I could open the text file and read it's contents while it's logging.

VE7JRO - Cool. Will do.


text:
Turning on controller with button and turning off with a timeout
I am making a device controlled by an ESP 8266 and am wanting to save power by having it power down when not in use. The desired behavior is for a momentary button press or vibration sensor activation to cause the device to turn on and stay on until it is done being used for a period of time. The ESP 8266 can sense when the device is not in use and can reset a software or hardware timer as necessary to begin the timeout process once the device stops being used. After the timeout is complete, I would like the device to power off with as little current draw as possible.
Some of the options seem to be a circuit like this: https://www.youtube.com/watch?v=L55QrKQQZJk
That would be great but to be honest, if I could find an COTS solution, it would be much better. The best thing I found was this breakout board on Adafruit: https://www.adafruit.com/product/3435. It would take care of the powering on with the button and vibration sensor and be able to power off on command as well. The main issues I would run into is the fact that the device would power on every two hours without needing to and timeout after being on for two hours as well. Even though my software timeout will probably be around 10 minutes, if the device is used for two hours straight, I don't want it to shut off mid-operation. Are there any COTS solutions here better than what I found? Or could I easily modify the TPL5110 to do what I am wanting to do?
Thank you!

you set esp8266 to deep sleep in code. esp8266 can be wake-up from deep sleep with reset button

That's what I'm trying to avoid though, I don't want to use deep sleep for this. Stuff like the ESP 8266 still uses a fair amount of power, and even then, it would be difficult to get this to work with my desired functionality.

it is off in deep-sleep. only the RTC runs and consumes ~ 20 μA according to datasheet. same amount as the TPL5110


text:
MOSFET dimmer IR controlled
I am trying to make a group of LED dim with PWM to a MOSFET. The code seems to work for this, but the trouble is that the IR receiver will only receive the signal to turn on the lights and then IR receivers onboard LED goes to a permanent dim state (which is suppose to be off completely).  It then refuses to take input until a Arduino reset is preformed.  I purchased another IR receiver and placed it in the same configuration and it work exactly as intended I could brighten the LEDS and I saw the PWM stretch on my oscilloscope with every click of my remote.  The trouble is that the receiver quickly quit working at this point I think there is a problem with my circuit.  I am attaching the circuit diagram in hopes that someone can help.
Thanks,
Billa
#include <IRremote.h>

int led = 9;
int led2 = 10;
int brightness = 0;    // how bright the LED is
const int RECV_PIN = 7; //IR Receiver Pin
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn();

}

void loop() {

  analogWrite(led, brightness);
  analogWrite(led2, brightness);

  if(irrecv.decode(&results)) //this checks to see if a code has been received
{
    if(results.value == 0xFF906F) //if the button press equals the hex value 0xC284
    {
        Serial.println("Triggered U");
        brightness = brightness + 5;
    }

    if(results.value == 0xFFE01F) //if the button press equals the hex value 0xC284
    {
        Serial.println("Triggered D");
        brightness = brightness + 5;
    }

    irrecv.resume(); //receive the next value
}

  delay(100);
}

What is the receiver?

that sure is an ugly schematic

what's mosfet part number? why there isn't a resistor between arduino and mosfet?

I don't think, that a resistor between Arduino and MOSFET is really necessary, since a MOSFET normally has only a very small capacitance. But a current limiting resistor for the LEDs would be good

@jsotola That's what you get for using Fritzing...

@chrisl It is probably LED strips with built in resistors (since it's powered from 12V). Also the LEDs are backwards, but we'll overlook that ;)

@newbie A resistor is not strictly needed. I add a 100Ω resistor normally just to limit inrush current to the gate when switching, but then I usually use more powerful MCUs with a lower current rating on each pin than an 8-bit AVR.

The receiver is a MagicW Digital 38khz Ir Receiver. The MOSFET part number is P30NO6LE. I have also appended the code to the bottom. Sorry for the ugly schematic. If there is a recommend format for Stack Exchange schematics I'd be happy to remake it in that more readable format.

@ZackGarris - There is a recommended format for drawing schematics: https://electronics.stackexchange.com/questions/28251/rules-and-guidelines-for-drawing-good-schematics

Question about MOSFET gate resistor: https://electronics.stackexchange.com/questions/68748/question-about-mosfet-gate-resistor

@VE7JRO So you think this could be caused by Ringing (parasitic oscillation)?

The first error I see with the sketch is right under this line of code Serial.println("Triggered D");. You are incrementing the variable brightness when you probably meant to decrement it.
The second error is with your call to analogWrite(). This function accepts an integer between 0 and 255. You do not constrain the value to that range, and can see what I mean by adding this line of code Serial.println(brightness); right above this one irrecv.resume(); in your sketch. Going from 0 to -5 turns the LED from off to maximum brightness. Is this what you want it to do?
The errors with your MOSFET circuit is a "General Electronics" question, and should be asked on electronics.stackexchange.com. As I mentioned in one of my comments to your question, there is a recommended format for drawing schematics.
My other comment was regarding this Q+A at EE. You won't find a consensus on exactly how to use a MOSFET there either, but the image in this answer may be helpful to you.

Thank you for your help.  I tried the ringing solution with no luck. I'll move my question to over the General Electronics and see.


text:
Arduino as Slave on I2C bus to read data from other I2C devices
Good afternoon;
I am a bit new to the world of I2C bus. I'm trying to implement a project that have  Arduino MEGA as a master and Arduino nano as slave. I have some I2C sensors that i want the slave (Arduino nano) to read. Please how can i implement this.

Am I understanding correctly, that your I2C slave Nano should also be a master for the I2C sensors?

A uC having only one hardware i2c interface can only be master OR slave, not both at the same time.

Thank you for your response, I understand now. I'm thinking the best approach will be to use other pins of the Arduino Nano to interface the I2C sensors. But because these sensors are I2C sensors, i believe they will not just work directly with other pins except the dedicated I2C pins. Do you know how i can enable other pins of the Arduino Nano to be used for the I2C sensors?

An Arduino can be both a master and a slave.  Nick Gammon's page on I2C describes how to do it.   http://www.gammon.com.au/i2c

Communicating with other devices
So all this I2C stuff is great, you can use just two wires (plus ground) to talk to up to 119 devices. But what if you have a device (like a keypad) that doesn't support I2C? Well, the simple answer is that you can use something that does as an interface. For example, a second Arduino. My examples above do just that, using one as the master and second one to display text on LEDs.
In fact, the "master" can also act as a slave, since you can have multiple masters on one wire. The example below shows how you can send data from one Arduino to another, whilst waiting for information to be sent from the second back to the first.

See the link for code examples.

Does the Wire now support bus arbitration, so that multi master can be done without locking the bus?

No idea, I've rarely used I2C, preferring instead the much faster SPI.

Thank you for your response, I have seen what he did and it was great. However because my sensors are I2C sensors, it may not work well as he did.  I'm thinking the best approach will be to use other pins of the Arduino Nano to interface the I2C sensors. But because these sensors are I2C sensors, i believe they will not just work directly with other pins except the dedicated I2C pins. Do you know how i can enable other pins of the Arduino Nano to be used for the I2C sensors?

What are your sensors? Part numbers?

Proximity sensor, VCNL4040, Time of Flight Sensor VL6180

"VCNL4040 applies single slave address 0x60 (HEX) of 7-bit addressing following I2C protocol. "   "The VL6180X is controlled over an I2C interface. The default I2C address is 0x29 (7-bit). "  So, two different addresses. Connect both to SDA & SCL, talk to one, then talk to the other.


text:
Getting issues while using SoftwareSerial
I am trying to read string send from esp8266 esp01 to Arduino mega. When I use normal Rx and Tx ports, it works properly but when i am initializing new serial port using SoftwareSerial then nothing is being shown on the serial monitor.
Please help me as i have been stuck and trying to solve this for weeks now.
Below are the code for esp8266 and Arduino mega

Code for ARDUINO MEGA

#include<SoftwareSerial.h>

SoftwareSerial myS(4,5);

String data="true";

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
myS.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if(myS.available()){
  data=myS.readString();
  }
  Serial.println(data);
  //Serial.write(data);
  delay(2000);
}

Code for ESP8266

void setup() {
  Serial.begin(9600);     // Initialize the Serial interface with baud rate of 9600
}

// the loop function runs over and over again forever
void loop() {
  if(Serial.available()>0)    //Checks is there any data in buffer
  {
    Serial.print("We got:");
    Serial.print(char(Serial.read()));  //Read serial data byte and send back to serial monitor
  }
  else
  {
    Serial.println("Hello World..."); //Print Hello word every one second
    delay(1000);                      // Wait for a second
  }
}

Moreover, i have tried read() as well instead of readString(), but it does not work either. I have also tried switching Rx and TX pins meaning connecting Rx->Tx, Tx->Rx and vice versa i.e. Rx->Rx and Tx->Tx, but it does not work in any of the case.
Any help or suggestion will be appreciated.
Thanks

Why are you using SoftwareSerial on a Mega?!?!

Rx->Tx is correct, not the other way around. Also, the atmega2560 has more serial interfaces, so softwareserial is not a good choice

SoftwareSerial only works on a few select GPIO pins on the Mega. Specifically those pins that have PCINT on them.
But that is irrelevant. There is no reason to use SoftwareSerial on a Mega except in exceptional circumstances.  You have four hardware UARTs on the Mega, so there is no call to use SoftwareSerial.  Use the real UART pins and objects:
Serial -> RX(0) / TX(1)
Serial1 -> RX1(19) / TX1(18)
Serial2 -> RX2(17) / TX2(16)
Serial3 -> RX3(15) / TX3(14)

Just replace all references in your code to the SoftwareSerial instance with Serial1 (delete the #include and the object instance constructor) and use TX1 and RX1 to connect your module:
String data="true";

void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    Serial1.begin(9600);
}

void loop() {
    // put your main code here, to run repeatedly:
    if(Serial1.available()){
        data=Serial1.readString();
    }
    Serial.println(data);
    //Serial.write(data);
    delay(2000);
}


text:
How to set cables to connect CP2102 to Pro Mini?
How to connect the cables in order to program the pro mini with the CP2102 usb interface ?
The TX RX and GND is easy, but I am not sure about the RST, DTR, DST, etc

When I try cables like this:
TX  ... RX
RX  ... TX
5V  ... VCC // my pro mini is 5V version
GND ... GND
RST ... RST

The board lits up and green starts blinking, this should be the default blinker program.
I click Upload, I get this error, and I assume the cables are not properly connected:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x89
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x89

I know some people mentioned it works by adding some resistor and capacitor, but I was hoping that is an error and it should work without that complication.

Here's what works for me:
Pro Mini  ---------   CP2102

  DTR     ---------    DTR
  RST     ---------    RST   (optional if you wish to press some buttons)

  GND     ---------    GND
  RX      ---------    TX
  TX      ---------    RX
  VCC     ---------    VCC

Tap on the image to see the HD image

RST to RST. Ignore the others, they are irrelevant.

Doesn't seem to work, I updated my questions with error details.

Pretty sure RST is Reset input to the CP2102, that will not work.
DTR to DTR (BLK on the Promini) will work, the DTR Low level goes thru the Promini's 0.1uF cap and 10K Reset pullup resistor to make a Reset pulse. That's how the FTDI Basic works when connected.
RTS (Request To Send output) might also work, that is supposedly a pulsed level.

same errors, I tried the DTR and RTS pins from USB to pins from pro mini (RST, BLK) in all combinations.

You meant to add a 10K resistor ?

The Promini's I've used http://store.yahoo.com/yhst-27389313707334/arpromi5v.html have the 0.1uF cap and 10K pullup resistor on board. All that was needed for programming was to connect an FTDI Basic directly to it, pin to pin.   http://www.tinyosshop.com/download/Pro-Mini.sch.pdf

Are you positive your Promini has a bootloader installed?

I have no ideea, it seems to have blinker program installed, does it mean the bootloader is already there ?

OK, I heard enough times about the 0.1uF cap and 10K pullup resistor [https://forum.arduino.cc/index.php?topic=231863.0], I am going to the store now :)


text:
STM32 Nucleo-L432KC can't send data to Arduino Uno via nRF24L01 module
Hello everyone.
First of all, I know you're going to tell me to send my question on the stm32duino forum. But I tried to enter the stm32duino forum and I didn't succeed (I think their forum is closed). So I'll be happy if you could try to help me here.
So, I want to use the nRF24L01 module to communicate between the STM32 Nucleo-L432KC and the Arduino Uno. such that both the STM32 Nucleo-L432KC and the Arduino Uno will be transceivers.
My nRF24L01 module pin connections are:
For the nRF24L01 module to the Arduino Uno:

CE => D7
CSN => D8
MOSI => D11
MISO => D12
SCLK => D13

For the nRF24L01 module to the STM32 Nucleo-L432KC:

CE => PB0
CSN => PB1
MOSI => D11 (Other names: PB5, SPI3_MOSI)
MISO => D12 (Other names: PB4, SPI3_MISO)
SCLK => D13 (Other names: PB3, SPI3_SCLK)

I tried to send data from the Arduino Uno to the STM32 Nucleo-L432KC, and I got the data and everything was OK.
But when I tried to send the data from the STM32 Nucleo-L432KC to the Arduino Uno board, I didn't receive the data in the Arduino Uno (I use the Serial monitor in-order to print the data I receive).
My code:
For the Slave (STM32 Nucleo-L432KC) who send the data to the Arduino Uno:
#include <nRF24L01_STM32.h>
#include <RF24_config_STM32.h>
#include <RF24_STM32.h>
#include <SPI.h>

RF24 myRadio(PB0, PB1); //CE Pin, CSN Pin
//----------------------------------
//Rest of connections to the Nucleo-L432KC:
//   nRF    Nucleo-L432KC
//  MISO      D12 (Other names: PB4, SPI3_MISO)
//  MOSI      D11 (Other names: PB5, SPI3_MOSI)
//  SCLK      D13 (Other names: PB3, SPI3_SCLK)

//My Slave (Nucleo-L432KC) and Master (Arduino Uno) addresses:
const uint64_t pipes[2] = {0xF0F0F0F0AA , 0xF0F0F0F066}; // {Master (Arduino Uno) address , Slave (Nucleo-L432KC) address}

const char test[] = "test"; // junk string to send between the slave and the master in-order to check the communication between them

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Start Serial communication
  delay(1000);
  //Init SPI config:
  SPI.begin();
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  //---------------------------

  //Init my nRF radio:
  myRadio.begin();                      //Starting the Wireless communication
  myRadio.setRetries(15, 15);
  myRadio.setChannel(0x4c);             // Set the communication channel
  myRadio.setPALevel(RF24_PA_MAX);      // Set the nRF power level. RF24_PA_MAX => maximum power
  myRadio.openWritingPipe(pipes[0]);    // Set the address of the Master (in-order to send back the requested data). Master address is: pipes[0]
  myRadio.openReadingPipe(1, pipes[1]); // Set the address of the Slave (in-order to receive the commands from the master). Slave address is: pipes[1]

  myRadio.stopListening();              // Set myRadio to transmitter mode (in-order to test the data communication: Slave send requested data to master)
  //---------------------------

}

// Send the data to the master (Arduino Uno) infinitely:
void loop() {
  delay(500);
  myRadio.write(&test, sizeof(test));
}

For the Master (Arduino Uno) who receive the data from the STM32 Nucleo-L432KC:
    // nRF24L01 libraries for Arduino platform:
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
//--------------------------
#include <SPI.h>

RF24 radio(7, 8); // CE Pin (D7), CSN Pin (D8)
//----------------------------------
//Rest of connections to the Arduino Uno:
//   nRF    Arduino Uno:
//  MISO      D12
//  MOSI      D11
//  SCLK      D13

//My Slave (Nucleo-L432KC) and Master (Arduino Uno) addresses:
const uint64_t pipes[2] = {0xF0F0F0F0AA , 0xF0F0F0F066}; // {Master (Arduino Uno) address , Slave (Nucleo-L432KC) address}

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Start Serial communication
  delay(1000);

  //Init my nRF radio:
  radio.begin();                       //Starting the Wireless communication
  radio.setRetries(15, 15);
  radio.setChannel(0x4c);              // Set the communication channel
  radio.setPALevel(RF24_PA_MAX);       // Set the nRF power level. RF24_PA_MAX => maximum power
  radio.openReadingPipe(1, pipes[0]);  // Set the address of the Master (in-order to receive back the requested data from the slave). Master (Arduino Uno) address is: pipes[0]
  radio.openWritingPipe(pipes[1]);     // Set the address of the Slave (in-order to send the commands to it from the master). Slave(Nucleo-L432KC) address is: pipes[1]

  radio.startListening();              // Set radio to receiver mode (in-order to test the data communication: Slave send data data to master)
}

// Receive the data from the slave (Nucleo-L432KC) infinitely:
void loop() {
    if (radio.available())              // Looking for the data.
  {
    char text[32] = "";
    radio.read(&text, sizeof(text));    // Saving the incoming data
    Serial.println(text);               // Printing the received data on the Serial monitor
  }
}

Both the Arduino Uno and the STM32 Nucleo-L432KC codes were compiled successfully.
Can you please help me and tell me what I'm doing wrong here and how to fix this?
Note: I use for the master and the slave a code that I found from the web (in multiple web pages).
Thank you for your help,
Reshef

I'd suggest using the bold format for really things that you need to draw attention to and NOT use it for whole sentences. It just makes the post hard to parse through. p.s. a ~picture~ (schematic) is worth a thousand words. Instead of writing down what pin is used for what, a better picture could be conveyed if the schematic of your circuit could be included here instead.

Also I would remove the header files that you listed in your post. We can see those header files in the code? Right? Then why list them again separately? p.s. you made a nice effort in formatting your post. :) !

I'm sorry to dig up a 2-years old post, but did you succeed to send data from the STM32 to the Arduino ?


text:
Breadboard arduino uno not working properly
Is there any mistake in the circuit of arduino uno on breadboard... I am using arduino uno board to program this 328p mcu and after that i remove 328p from arduino uno board and placing on breadboard as shown in circuit diagram. But mcu is not working(i.e the motors are not and other devices connected to mcu are not working) But when i connect reset,vcc,gnd pins of 328p on breadboard to arduino uno board without 328p on it then its working fine and all devices are working according to my program.. even when  i connect those reset,vcc and gnd pins to reset,vcc,gnd of  any usb asp programmer then also its working fine(*even programmer is not plugged in to pc). Its very strange behavior even if i disconnect any of these reset,vcc,gnd cables then also its not working... Is there any errors in circuit...please help me out

That schematic is very hard to follow. You should use GND and VCC symbols instead of nets for your power and ground.

@Majenko i have added another circuit of eliminating  devices connected to it.. can you have a look at it..

Does it have to have all three connections to the Uno? Have you tried all different combinations of connections to see which work and which don't?

yes reset,vcc,gnd pins of 328p on breadboard has to connect same pins of any programmer usbasp or uno board with empty 328p..

Try measuring the voltage at the reset pin. It sounds like something on your board is pulling the reset line low. Also you schematic uses a weird symbol for the reset pins pull-up resistor.

Again i have verified the reset circuit... i found that after powering on the code is not running.. i have manualy reset 328p by sorting reset pin to ground .. then the code works fines... whats the problem in my circuit? i have to manually reset every time to get it working.. is the any thing to implement in my circuit that it can automatically reset at power on..

Problem solved by adding 100nf capacitor between reset and ground.... Which enables a auto reset function after every time powering on..
from this arduino forum i got this solution
Thank you everyone


text:
Serial communication PC to Arduino using C and send via NRF
I'm trying to communicate my PC with an Arduino Mega via serial and after send the message via NRF to another Arduino.
But I don't know if the message is send correctly or if it even send the message. Because I can't debug using Serial Monitor. If it is opened the serial port appear as busy.
When I execute the code the TX led on the Arduino blinks, but nothing is send via NRF.
I made some tests using only the NRF between the Arduinos and it's working, but when I try using the PC - Arduino serial communication, nothing happens.
C Code
#include <stdio.h>
#include <string.h>

char arduinoPort[] = "/dev/ttyACM0";

int main() {

  char buffer[] = {'1'};
  int error = 10;
  FILE *usb_port;

  usb_port = fopen(arduinoPort, "rwb");

  if(!usb_port) {
    perror(arduinoPort);
    return 1;
  }

  //memcpy(buffer, &error, sizeof(error));
  fwrite(buffer, sizeof(char), sizeof(buffer), usb_port);

  fclose(usb_port);

  return 0;
}

Arduino Code
#include <nRF24L01.h>
#include <RF24.h>
#include <printf.h>
#include <RF24_config.h>

RF24 radio(7, 8); // CE, CSN

uint64_t address = 0xF0F0F0F0E1LL;

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

  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
  radio.printDetails();

}

void loop() {

  if(Serial.available() > 0) {

    char byteLido = Serial.read();

    radio.write(&byteLido, sizeof(byteLido));
    delay(1000);
  }
}

Did you stty /dev/ttyACM0 to the correct baud rate?

hmm.. i dont know how to do it on C code

could you give me some tip on how to do it?

First try from the command line, just to make sure this is the actual issue.

Sorry, but how can I do it from command line?

stty -F /dev/ttyACM0 raw -echo 9600

shows nothing on terminal but the TX led turned on for a while

Working with serial in C on Linux is not as simple as opening a file and reading from it (though in some circumstances that can work).
You should open the file using open() not fopen(), then use tcgetattr() and tcsetattr() etc to configure the port.
For example:
#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>

struct termios oldsettings, newsettings;
int fd;

// This signal handler will close the port cleanly leaving
// it in the same state it started in
void sighandler(int sig) {
    if (sig == SIGINT) {
        if (fd >= 0) {
            // Restore the settings to original
            tcsetattr(fd, TCSANOW, &oldsettings);

            // Close the port
            close(fd);

            printf("Program teminated. Thank you for playing.\n");
            // Exit the program
            exit(0);
        }
    }
}

int main(int argc, char *argv) {

    // Trap CTRL-C to close the port properly
    signal(SIGINT, &sighandler);

    fd = open("/dev/ttyACM0", O_RDWR);
    if (fd < 0) {
        fprintf(stderr, "Error opening serial port: %s\n", strerror(errno));
        return 10;
    }

    // Save the settings
    tcgetattr(fd, &oldsettings);
    // Grab the current settings again to modify
    tcgetattr(fd, &newsettings);

    // Set the baud rate
    cfsetispeed(&newsettings, B9600);
    cfsetospeed(&newsettings, B9600);

    // Make it a raw port
    cfmakeraw(&newsettings);

    // Apply the settings
    tcsetattr(fd, TCSANOW, &newsettings);

    char c;
    printf("Press CTRL-C to terminate\n");

    while (read(fd, &c, 1) == 1) {
        printf("Got character 0x%02x\n", c);
    }

    fprintf(stderr, "Reception terminated: %s\n", strerror(errno));

    return 0;
}

No one ever said programming C was easy. It makes you appreciate just how much work the Arduino API does behind the scenes for you...
Also you need to be aware that the Arduino resets (if you use an Uno, Mega, or other board with a separate USB interface chip) when you open the serial port. You need to wait about 2 seconds after opening the port before you ever send anything, or whatever you send will be completely ignored.  You can do that with:
sleep(2);

after you have opened and configured the port.

Thank you so much!


text:
How do I join two RGB ledPanel 32x64 in order to get one 64x64?
I'm making a project to make a pixelArt of 64x64 using two 64x32 RGB ledMatrix and Arduino MEGA.
This is the RGB Panel I am using.
I use ADAFruit and RGBMatrixPanel libraries in my Arduino Code and if I connect the Arduino pins to the RGB panel it works, but the problem is when I try to connect the output of the first panel to the input of the second, I saw the "same image duplicated" but with different brightness, and if I change the length of the panel seems to print random LEDs.
I know that Adafruit is thought to get a screen with max of height of 32, but I don't care, because for my purpose you can assign each pixel programmatically in order to print the proper image.
I followed this guide in order to make the connection with a panel of 64x32.
I think that I have to change my code and also my physical connections, but I don't know how, can anyone help me?
Other option that I thought was create another matrix2 instance at the same code using different PINS, but this is very weird.
This is the current connections: (I have a power supply of 5v - 10A)

This is the result that I have: (duplicated in both screens with a brighness/weird shadow in the second)

And this is the final result that I'm looking for: (this is made with two Arduino Megas)

Thanks in advance!

please provide a link to the panel datasheet

It looks like a 64x64 will actually be a 128x32.

Hi, I dont have that documentation, i guess that is an standard one?

First off, connecting the 2nd panel to the same output pins as the first one, you are simply sending same data to the 2nd panel, which is why you get the duplicate visuals. I'm guessing you are sending power that same way, which is why you are seeing the brightness dim.
Secondly, it's hard to read on the pics in the AliExpress listing, but the Sparkfun site had a better image, which shows an "Output" connection on the back of the panels.  You need to daisy chain the 2nd panel to the first panel through this "Output" connection. This should prevent you from having to create a 2nd matrix2 and use a 2nd set of pins.
Third, having a 2nd set of pins and controlling the 2nd LED matrix can make updating the image faster. It depends on your library as well as how the LED matrix is made, so it really depends on those factors, but some LED systems are designed so there is a maximum amount of pixels that can be displayed before there's a noticeable delay in LED updated. With this amount of LED pixels, you're probably fine, but if you want fast updates and expect to expand your matrix in the future, you might want to consider driving the panels separately. I'm not saying you have to now, but if you're seeing lag, this might be a good option.

Hi, I added some pictures of the project, as you c an see i have enought power supply for both screens (is not a brighness change, it has also a weird shadow on each character and changes the color a bit)
Thanks for your help!!! I really appreciate it.

@JorgeMartínMartí, are you talking about the diagonal lines on the Link image for the shadows? That could be a slow refresh rate or a mismatch of frame rate between the matrix and your camera. If you're talking about the "fuzz" around the pixel in the letters, that's because you don't have the white screen up against the matrix, allowing the light to bleed a little. It's also likely going to happen anyway, unless it's a polarized sheet. The white sheet will absorb some of the light/wavelengths due it it not being 100% transparent. Hopefully I'm understanding what you're describing.

BTW, that looks really good already!

No, i know that these lines is just in the photograph, but not in real view. You can oberve the differences in the image with text (the color is different), but the programing code is just the same, i mean this kind of changes in person you can see a different brightness and different color, and also a small shadow (fuzz), and this only occurs in the second (bottom) screeen that is replicating the stuff of the previous one, so we can discard the issue with the white sheet (it occurs with the isolated panel too) so should be a problem with the program or the wire connections. TY

I think I see the color difference now, but I'm still missing the shadow. The color difference could be a different random color selected for the letter. Since I can't see the code, it's just a WAG. If it was a loose wire, you wouldn't get a coherent image, since it's a digital, not analog, signal. It either works or it doesn't. The color looks good and consistent on the Link image. You might try solid colors across both panels to see if there really is a color difference. Pick specific colors and see what happens. It could be the LEDs are mis-wired. Good luck fixing that though.

Yeah, the shadow is not clear appreciable on the picture but still there with the color issue..., we can discard a wire failure (because I tried with several wires), also we can discard a random color code issue, because all of the colors are fixed, and if print an image, the same image, the colors on the second screen still different (I tried with another screens so we can discard also a screen failure). So i think that the issue is related with the code or with the wire connection. Thank you very much, i will try making some changes on my code, maybe the arduinoMega is not enough for 64x64

@JorgeMartínMartí, if possible, and if it's generated color values, I'd suggest looking at the output of the code, so you know for sure that the color values are the same. If it's hard coded values, I'd still double-check to make sure nothing got fat-fingered. As far as the shadow goes, try it without the front cover. It may be some weird reflection between that and the LED backing material. Without seeing it IRL, I'm afraid I'm out of suggestions. Good luck!


text:
Connecting multiple led strips in parallel with arduino
I am making a led panel using led strips. Each of the two led strips are 5M long containing 300 LED SMD Striplights. I have cut each of the 2 strips into many small strips of lengths of about 38 cm and connected them in parallel i.e there is  a singe pair of terminals for all the strips.I have a 12V,5A power supply. I had tried to drive the panel using Arduino Mega in combination with a MOSFET as is it is commonly done for a single led strip but I am unable to make it work.
Can anybody please help me out?
Other components being used are - PIR sensor , RTC module

Not enough info. Did you cut these strips only at the cut points? Have you tested them separately? Are they meant to run on 12? Will the MOSFET drive a single, uncut strip? What's the total power requirement for all of your strips? (Add the current requirements of the individual strips together)

If you are using a mosfet like IRFZ44N you should change that to a logic level IRLZ44N. Arduino 5V isn't enough for a normal mosfet to allow enough current pass through.

One LED strip is lots of little LED strips in parallel. One LED strip cut into sections and wired in parallel is no different to one LED strip.

If you can wire up the power to work for a single string, you should be able to "star" wire from the output side to all the other LED strips and have it still work. Star wiring is to wire the strip directly to the PSU, instead of running a common power from one strip to the next. It handles current/heat and spikes better.

Post a schematic of your circuit. Post all the specifications of your LEDs.What do you mean you can't it to work, which part?


text:
NodeMCU 1.0 - Exception 9 `Fatal exception 9(LoadStoreAlignmentCause):`
I am getting this error in my code.
Fatal exception 9(LoadStoreAlignmentCause):
Using core version 2.4.2
Stack trace
Decoding stack results
0x40213e9c: dns_gethostbyname at core/dns.c line 1472
0x40204c21: ESP8266WiFiGenericClass::hostByName(char const*, IPAddress&, unsigned int) at /home/tony/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.cpp line 468
0x40205038: WiFiClient::connect(char const*, unsigned short) at /home/tony/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/libraries/ESP8266WiFi/src/WiFiClient.cpp line 98
0x4020306b: setPostString(int, int, Array8Int, char*) at /home/tony/Arduino/sketches/tempo1_vs11e_Master_NodeMCU_Rain_Wind/tempo1_vs11e_Master_NodeMCU_Rain_Wind.ino line 516
0x40203f8a: uploadAgrigis(char const*) at /home/tony/Arduino/sketches/tempo1_vs11e_Master_NodeMCU_Rain_Wind/tempo1_vs11e_Master_NodeMCU_Rain_Wind.ino line 335
0x40209080: Print::println() at /home/tony/.arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/Print.cpp line 178
0x402048e0: loop() at /home/tony/Arduino/sketches/tempo1_vs11e_Master_NodeMCU_Rain_Wind/tempo1_vs11e_Master_NodeMCU_Rain_Wind.ino line 243

struct declaration
struct Array8Int {
    int array[8];
};

loop
char post[300] = "";
int pulseChange05m = rainCheck(slaveData);
int now10 = floor(unixtimeServer/10)*10;
Array8Int slaveData = slaveCheck(now()); // update slaveData array
setPostString(now10, pulseChange05m, slaveData, post);

functions
void setPostString(int unixtimeEvent, int pulseChange, Array8Int postData, char* postStr) {
  bool flag = true;
  float rainHour = pulseChange*0.25;
  if (hour() == 10) { // 7 AM palmital
    rainCount = 0;
    rainCount05m = 0;
  }
  rainCountHour = rainCount;
  int humidityBme280HourAvg = 0;
  int pressureBme280HourAvg = 0;
  int temperatureBme280HourAvg = 0;
  int lightSensorHourAvg = 0;
  int pressureBme280HourMin = 100000;
  int temperatureBme280HourMin = 1000;
  int temperatureBme280HourMax = -1000;
  int counterLoop = counterHour;
  for(int i=0;i<counterLoop;i++) {
    lightSensorHourAvg += lightSensorHour[i];
    pressureBme280HourAvg += pressureBme280Hour[i];
    temperatureBme280HourAvg += temperatureBme280Hour[i];
    temperatureBme280HourMax= max(temperatureBme280HourMax,temperatureBme280Hour[i]);
    pressureBme280HourMin = min(pressureBme280HourMin,pressureBme280Hour[i]);
    temperatureBme280HourMin = min(temperatureBme280HourMin,temperatureBme280Hour[i]);
    humidityBme280HourAvg += humidityBme280Hour[i];
  }
  pressureBme280HourAvg = pressureBme280HourAvg/counterLoop;
  temperatureBme280HourAvg = temperatureBme280HourAvg/counterLoop;
  lightSensorHourAvg = (int)lightSensorHourAvg/counterLoop;

  strcat(postStr, stationId);
  strcat(postStr,"&3="); // chuva hora
  strcat(postStr, dtostrf(rainHour,6,2,charDummy));
  strcat(postStr,"&8=");
  strcat(postStr, dtostrf(temperatureBme280HourAvg,6,2,charDummy));
  strcat(postStr,"&9="); //temperature avg
  strcat(postStr, dtostrf(temperatureBme280HourAvg,6,2,charDummy));
  strcat(postStr,"&10="); //temperature avg
  strcat(postStr, dtostrf(temperatureBme280HourMax,6,2,charDummy));
  strcat(postStr,"&11="); //temperature avg
  strcat(postStr, dtostrf(temperatureBme280HourMin,6,2,charDummy));
  strcat(postStr,"&20=");
  strcat(postStr, dtostrf(pressureBme280HourAvg,10,0,charDummy));
  strcat(postStr,"&22=");
  strcat(postStr, dtostrf(pressureBme280HourMin,10,0,charDummy));
  strcat(postStr,"&101=");
  strcat(postStr, dtostrf(lightSensorHourAvg,6,0,charDummy));
  strcat(postStr,"&time=");
  strcat(postStr, dtostrf(unixtimeEvent,16,0,charDummy));
  strcat(postStr,"&endline=1");
  strcat(postStr, "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n");
}
int rainCheck(Array8Int slaveData) {
  int pulseChange = slaveData.array[0];
  return pulseChange;
}

2000 lines?  maybe narrow it down...  i'd appreciate some help with the stack -> does it point to line 243 or 1472 as last executed?  tks @Juraj

at least the code around setPostString(int, int, Array8Int, char*) at /home/tony/Arduino/sketches/tempo1_vs11e_Master_NodeMCU_Rain_Wind/tempo1_vs11e_Master_NodeMCU_Rain_Wind.ino line 516

Lescanne, you are a life saver! It works!

Fatal exception 9(LoadStoreAlignmentCause):

This is caused by you (or some code you are running) attempting to read or write a 32 bit value from memory that is not "aligned" to 32 bits.  It is most often the result of trying to cast portions of a byte array (for instance a buffer received over UDP) to a 32-bit integer.  The compiler is not clever enough to know that the byte array portion you are casting isn't at a 32-bit boundary and thus doesn't know to use the 8-bit load/store instructions to access the memory.
Mapping a struct over a buffer can also have similar issues where the buffer is 8-bit aligned and the struct contains 32-bit words.
You can combat it by forcing the alignment of any buffers which you treat in such a way with the __attribute__((aligned(4)) tag:
uint8_t __attribute__((aligned(4))) buffer[128];

You can also "pack" structures to tell the compiler "These variables are mis-aligned and should not be padded to 32-bits":
struct foo {
    uint8_t bar1;
    uint32_t bar2;
} __attribute__((packed));

If in doubt, though, just pull individual bytes out of buffers (or wherever) and build up your larger integers manually with bit shifting and OR operators (<< and |), and do the reverse for filling byte buffers.

yes, i am passing a struct.  will attempt these solutions and get back here to ACCEPT or not.  UPVOTED  :)

edited in code above, AFTER you pointed the culprit out.  Good job!

I had this error including on new cards
it worked on one card and not on another
the reason is that my eeprom was not initialized
the nodemcu 8266 that was working properly, was the one I used for development. Because i was using test to write on my eeprom so the value was put in it.
I did not understand what append After, I try flashing reload original setup etc...
I read your answer and I pass this program (which is a stupid manual writing of my eeprom)
I make it running once
and after that
I could load my other programs without problems

    #include <EEPROM.h>
struct credential {
  char WIFI_SSID [39] = " ";
  char WIFI_PASSWORD [39] = " ";
  char SMTP_HOST[44] = " ";
  uint16_t SMTP_PORT = 465;
  char AUTHOR_EMAIL[39] = " ";
  char AUTHOR_PASSWORD[39] = " ";
  char RECIPIENT_EMAIL[39] = " ";
  uint16_t  NbOfProbe = 1; //number of probe 1-to 16
  char TypeOfDevice[16] = "f";// F or f fridge R freezer O hot  exemple fRoFRr
  char AlertMin [54] = "30";//with always a sign like-10+0+2 the sign act like a separator
  char AlertMax [54] = "38";//with always a sign like-10+0+2 the sign act like a separator
  uint16_t  NbOfMinNormMail = 60 ;//time to wait in sec between 2 normal messages eg 14400 sec(4 hours)
  uint16_t  PowerOffMinWait = 1 ;
  uint16_t  TempOffLimitWait = 1;
  char AlertPowerMsg[41] = "alerte coupure de courant "; //Message alerte coupure de courant
  char AlertTempMsg[41] = "alerte temperature hors limite";
  char NormalTempMsg[41] = "Tout est ok ";
  char DateMsg[16] = "vide";
};
typedef struct credential settingcredent;
settingcredent parametersEeprom;
uint addr = 0;
void setup()
{
  Serial.begin(115200);
delay (100);
/*
  // fake data
  struct {
    uint val = 0;
    char str[20] = "";
  } data;
*/
  // commit 512 bytes of ESP8266 flash (for "EEPROM" emulation)
  // this step actually loads the content (512 bytes) of flash into
  // a 512-byte-array cache in RAM
 //                                                                          EEPROM.begin(512);

  // read bytes (i.e. sizeof(data) from "EEPROM"),
  // in reality, reads from byte-array cache
  // cast bytes into structure called data
 //
 showeprom ();

  strncpy(parametersEeprom.WIFI_SSID,"myssid",39);
  strncpy(parametersEeprom.WIFI_PASSWORD,"passmyssid",39);
  strncpy(parametersEeprom.SMTP_HOST,"smtp.gmail.com",44);
  parametersEeprom.SMTP_PORT=465;
  strncpy(parametersEeprom.AUTHOR_EMAIL,"iottest@gmail.com",39);
  strncpy(parametersEeprom.AUTHOR_PASSWORD,"iottest01",39);
  strncpy(parametersEeprom.RECIPIENT_EMAIL,"johndoe@hotmail.fr",39);
  parametersEeprom.NbOfProbe = 4; //number of probe 1-to 16
  strncpy(parametersEeprom.TypeOfDevice,"rffo",16);// F or f fridge R freezer O hot  exemple fRoFRr
  strncpy(parametersEeprom.AlertMin,"-20+0+2+23",54);//with always a sign like-10+0+2 the sign act like a separator
  strncpy(parametersEeprom.AlertMax,"-15+5+7+28",54);//with always a sign like-10+0+2 the sign act like a separator
  parametersEeprom.NbOfMinNormMail = 60 ;//time to wait in sec between 2 normal messages eg 14400 sec(4 hours)
  parametersEeprom.PowerOffMinWait = 10 ;
  parametersEeprom.TempOffLimitWait = 20;
  strncpy(parametersEeprom.AlertPowerMsg,"alerte coupure de courant ",41); //Message alerte coupure de courant
  strncpy(parametersEeprom.AlertTempMsg, "alerte temperature hors limite",41);
  strncpy(parametersEeprom.NormalTempMsg, "Tout est ok ",41);
  strncpy(parametersEeprom.DateMsg,"vide",16);
  EEPROM.put(addr, parametersEeprom);
  EEPROM.commit();

  EEPROM.get(addr,parametersEeprom);
  Serial.println("New values are: "+String(parametersEeprom.WIFI_PASSWORD)+","+String(parametersEeprom.WIFI_SSID)+","+String(parametersEeprom.SMTP_HOST));
}
void showeprom ()
{
  EEPROM.begin(sizeof(parametersEeprom));
  EEPROM.get(addr, parametersEeprom); //read data from array in ram and cast it into struct called parametersEeprom

  Serial.println("-------------------------"); //Showing the details
  Serial.print("your SSID ="); Serial.println( parametersEeprom.WIFI_SSID);
  Serial.print("your password for SSID ="); Serial.println( parametersEeprom.WIFI_PASSWORD);
  Serial.print("your SMTP_HOST ="); Serial.println( parametersEeprom.SMTP_HOST);
  Serial.print("your SMTP_PORT ="); Serial.println( parametersEeprom.SMTP_PORT);
  Serial.print("Your less secure email="); Serial.println( parametersEeprom.AUTHOR_EMAIL);
  Serial.print("Your password for not secure email="); Serial.println( parametersEeprom.AUTHOR_PASSWORD);
  Serial.print("Your email that must receive msg like MeTheBoss@MyCompany.com="); Serial.println( parametersEeprom.RECIPIENT_EMAIL);
  Serial.print("The number of thermometers probe you have is ="); Serial.println( parametersEeprom.NbOfProbe);
  Serial.print("Enter in order type of device (F)ridge f(R)ezzer (O)ven like RFFO="); Serial.println( parametersEeprom.TypeOfDevice);
  Serial.print("Enter mintemp in order per device like(suppose RFFO) -22-1+5+180="); Serial.println( parametersEeprom.AlertMin);
  Serial.print("Enter maxtemp in order per device like(suppose RFFO) -16+4+10+220="); Serial.println( parametersEeprom.AlertMax);
  Serial.print("Number of sec between 2 normal mails like(4hours) 240 ="); Serial.println( parametersEeprom.NbOfMinNormMail);
  Serial.print("Number of sec to wait before sending message Power off like 5 ="); Serial.println( parametersEeprom.PowerOffMinWait);
  Serial.print("Number of sec to wait before sending message warning temp like 5 ="); Serial.println( parametersEeprom.TempOffLimitWait);
  Serial.print("Message power down(30 char) like WARNING POWER OFF GRID="); Serial.println( parametersEeprom.AlertPowerMsg);
  Serial.print("Message temperature off min/max(30 char) like WARNING TEMPERATURE ABNORMAL="); Serial.println( parametersEeprom.AlertTempMsg);
  Serial.print("Message report state of all fridges freezer Oven like Everything is OK in the kitchen ="); Serial.println( parametersEeprom.NormalTempMsg);
  Serial.print("Enter date of the modif parameters like 08/23/21-18:25="); Serial.println( parametersEeprom.DateMsg);

}
void loop()
{
  delay(10000);
  showeprom ();

}

~
~

I hope that this experiment can be usefull
I cannot explain why it work

the eeprom has a limited amount of writes, around 100K


text:
Why is Arduino I2C so sensitive to RFI/EMI?
I have a 2-motor robot project that uses a MP6050 for relative heading (yaw) measurements, and I'm having problems with the I2C bus when the motors are running.  I have done most of the things suggested here and elsewhere; 2.2K pullups vs default, shortest possible (3cm) I2C wires, MPU6050 as far away from the motor drivers as possible, reduced I2C clock speed to 100KHz, etc, etc (for additional details, see my blog post on the subject).
So, my question is, why is the I2C bus so sensitive to RFI/EMI, especially with 2.2K pullups to +5V?  Looking at the levels with my O'scope shows a 0-4.6V swing, so it's hard to believe that EMI-induced currents could be high enough across 2.2K to pull the 'high' level low enough to be considered a '0', so something else must be going on.  Maybe the EMI is getting into the MPU6050 output driver circuit, causing it to turn off?  If so, maybe capacitive bypasses on the I2C lines would help.  Any ideas?  Are other IMU modules less susceptible to motor driver EMI?
TIA,
Frank

Is it an original arduino? Have you considered ESP8266/32 as an alternative? These have shielded chips.

I had not considered this at all.  I ordered a development board from Adafruit and will give it a try ;-)

Put a ground plate between your data lines and the power+signal lines used to drive the motor. A GPS ground plate is fine, see link below. You can just cut a piece of metal sheet to fit, or even use folded metal foil connected to ground. Motors are just noisy, and I2C is sensitive. Even updating a I2C LCD can cause noise. I like to use shielded wire (like for headphone- or HDMI cable) if my data lines are more than an inch long. You can shield lines with metal foil and heatshrink, but that’s a mess.
Use an opto-isolator to turn on your motors if a ground plate is not enough. If they only drive in one direction, add a catch diode and a 330pF cap to trim the noise. But they are probably most noisy when running. Good luck with that.
https://www.imnasa.com/en/ground-plate-200x64x12mm-for-gps-etc.html


text:
Serial Port fails with speeds greater than 19200
In Arduino Mega 2560 R3, properly selecting the Serial Monitor bauds, this code works with #define R 38400, but for some reason, not with #define R 19200 (?),

#define R 38400
int rate=R;
HardwareSerial* hwSerial[]={&Serial,&Serial1,&Serial2,&Serial3};
void setup() {
    for (int i=0;i<=3;i++){
        hwSerial[i]->begin(rate);
        while (!hwSerial[i]);
    }
    hwSerial[0]->print("Hello World");
}

void loop() {
}

Both speeds should be not problematic for Arduino, what is happening?
It seems the int rate R; is problematic when changing speeds (??).

19200 is OK and 38400 fails? int can't hold 38400

Yes. And int RATE=38400; fails but #define RATE 38400 works (??)

@Juraj That is the solution... Thanks...

I made the same mistake  few days ago. Took mi 10 minutes to realize

Answer is simple. You assign 38400 to a variable of type int. The signed range of integer values that can be stored in 16 bits is −32,768 through 32,767;


text:
Decoding RC transmitter data
I would like to use my FSi6 transmitter but not the receiver that comes with it (I´m trying to save weight), for that I was planning to get one of this NRF24L01 breakout boards. The problem is, how do you interpret the incoming traffic? After some googling, I couldn´t find any information from flysky.
I would think that this is a common thing to do, as you could pair the transmitter with another receiver (perhaps other brand) so there must be a standard protocol.
Any ideas?
Thanks!

why do you think that the FSi6 can communicate with the NRF24L01?

I expect that as both use 2.4 it would be possible, I´ve been doing some more research an apparently fs uses AFHDS 2A  kind of receives, so I think I was completely wrong assuming any receiver could speak with my i6...

Unless the FSi6 (whatever that is) uses an nRF27L01+ as its transmitter, then no - you can't.
The nRF24L01+ chip will only communicate with other nRF24L01+ chips.  It contains its own custom protocol within the chip and it can only talk that protocol and no others.


text:
Maximum sampling rate of Arduino Mega2560
I'd like to know what is the maximum sampling rate achievable while using ADC on Arduino Mega2560.
Thanks

The beginning of section 26 of the datasheet for the ATMega2560 gives the following data:

• 13µs - 260µs Conversion Time
  • Up to 76.9kSPS (Up to 15kSPS at Maximum Resolution)


text:
Can you help me figure out why my arduino code is not working
The code is made to sense were an object is and send out
int const trigPin = 10;
int const echoPin = 9;
int const buzzPin = 1;
int const LED1 = 2;
int const LED2 = 3;
int const LED3 = 4;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzPin, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop()
{
int duration, distance;
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//                                      Go
distance = (duration/2) / 29.1;
if (distance <= 1000 && distance >=0) {
digitalWrite(LED1, HIGH);
} else {
digitalWrite(buzzPin, LOW);
digitalWrite(LED1, LOW);
}
delay(60);
}
//                                      SLOW
if (distance <= 50 && distance >=0) {
digitalWrite(LED2, HIGH);
} else {
digitalWrite(buzzPin, LOW);
digitalWrite(LED2, LOW);
}
delay(60);
}
//                                      STOP
if (distance <= 50 && distance >=0) {
digitalWrite(buzzPin, HIGH);
digitalWrite(LED3, HIGH);
} else {
digitalWrite(buzzPin, LOW);
digitalWrite(LED3, LOW);
}
delay(60);
}

and send out ... send out what to where?

to an LED and or Buzzer sorry I did right it in but for some reason it was cut off

Try adding in some serial output at important code-parts. If you see that these are getting printed you can be sure that the code gets executed until that point. If it doesn't get executed it could also be a problem with the wiring so be sure to check that everythign is set up properly.
At this part:
...
void loop()
{
int duration, distance;
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//                                      Go
distance = (duration/2) / 29.1;
...

You are trying to divide an integer (wich can only hold whole numbers) with a real number. Please make sure to use a data type wich can hold more fine-grained results like double or float.
To set up a serial interface you have to add Serial.begin(9600) to you code in the setup() function. Then when you write Serial.println("Your debugging message here") it should be visible in the serial monitor after compiling. (Arduino IDE->Tools->Serial Monitor)

It's not so easy to debug code if you can't compile it at all. Maybe, at some point, he finds out why is everyone using code indentation (and sometimes even C++ Core Guidelines)

I just wanting to know but what would a debugging message be or look like because I am sort of new to Arduino and don't now about too much.

You just write as message whatever helps you. You could for example write as message:
Serial Port Started;
Sensor triggered;
Entering while loop.
It's really just up to you. Whatever helps you figuring out where your arduino is moving arround in your code right now


text:
How to save arduino serial monitor data into excel file
I am looking for the software that can help me to save arduino serial monitor data into excel file. And how to use that with your own code.

copy and paste with a limited amount of data ... otherwise, write a script in Processing to read data from serial and write the data into a csv file .... http://processing.org

use csv file format

Look for a serial terminal software which supports logging to a text file.
There are simpler ones than PuTTy.

Your computer is able to access the serial data and export it to a text file, which can then be converted to an excel file within Excel > Data > From Text. However, the data should be formatted in a way that excel can read it by separating values with a delimiter such as ",".
Once you have done this, simply run your serial data and open up your computer's console and write:
type COM(# here) >> serialdata.txt
Finally, import this text file into excel.
You could also use Excel VBA with MSCOMM to take the serial data directly into excel.
This answer is a regurgitation of a duplicate question asked earlier.


text:
NodeMCU: Wiegand not working for one device, while working for another
I'm using a NodeMCU, and a working code for reading Wiegand data, with this library.
I managed to successfully read the Wiegand signal from this device.
However, I also have this new AR-721H device, and I can't get the Wiegand to work. This is the manual for the device.
There is absolutely nothing coming to the mcu. Everything is wired identically as the working device.
According to the manual, everything should be working, but I am at a loss.
Can someone please tell me what I might be doing wrong?
The store clerk told me something about needing a controller that converts RS485 to RS232, but I have no idea what that means. I already made it work with another device...

It's quite cryptic from the little information in that (somewhat chaotic) "manual", but I interpret it that the Wiegand interface is an input port, not an output port.  It is intended to connect that port to an external card reader or keypad as a remote interface (typically the other side of the door to this unit).
For communication with your Arduino you should use the RS-485 interface. For that you need an MAX485 breakout board.

I suspect that the store clerk was talking about using RxTx for the data transmission, available in this device. He said all the programmers bought a controller to convert the signal, and I think he doesn't know what he's talking about, since the device I bought uses Wiegand, as an input at that as you said. I didn't understand your last sentence about MAX485 tho...

RS485 is a specific electrical signalling format for UART (serial) data. You need to convert that to UART using a MAX485 - then you can feed it in to the TX/RX pins (or other pins using SoftwareSerial) and communicate using Serial. You'd need to know the baud rate and protocol though to make sense of the data.

Thank you for the elaboration. In other words, the clerk is clueless... As the device I bought doesn't even have the option to use UART.

@Ivan Yes it does (or should have) - P3 is the RS-485 port.

@Ivan I can tell you that it should be running at 9600 baud - but what the data content will be I haven't managed to discern.

@Ivan Pay Dirt! https://kupdf.net/download/721-727h-protocol-en_5bfba826e2b6f5d51b0dabd5_pdf

Ok, so we've established that I am the stupid one. No problem. So the NodeMCU has RxTx pins (RS232), but that won't work with the RS485 directly (which I failed to see, thanks for that) i.e. I'd need a hardware converter as he said. Correct? Can I do this with software?

You need a MAX485 breakout board.  AR-721H <-> MAX485 <-> ESP8266. https://en.wikipedia.org/wiki/RS-485

I see... Thanks for the elaboration. I am really stupid with this stuff, and I am trying to learn. Can you please tell me what the MAX485 board does? Does it just do the conversion? I can't figure it out from Googling.

You're not stupid - you just don't have this area of knowledge yet. In one mode the MAX485 chip takes normal UART data in one side and spits out the RS485 equivalent from the other. In the other mode it receives RS485 data in one side and spits out UART data out the other. You switch modes with the DE and RI pins (which you can connect to the same GPIO pin of the ESP8266).  It's basically a transparent bridge between UART and RS485 that runs in the direction you specify. In TX mode you can Serial.write(...) data. In RX mode you can Serial.read() data.

@Ivan Actually since you're working at 3.3V you need the MAX3485 since it's the 3.3V version.

@Ivan I'm trying to update my answer with a diagram for you, but the schematic editor is being a complete arse.

I could also use a level converter with the MAX485, instead of the MAX3485, correct?

@Ivan Sure, but that gets messy then.

Yeah, a lot of wiring. I am so frustrated that I can't find a simple RFID reader with a keypad... It's either devices without keypads working with Wiegand, or the ones with Wiegand having all sorts of weird workarounds... Why is the access control area so complicated?

@Ivan https://www.supremainc.com/en/hardware/compact-outdoor-rfid-reader-xpass-d2.asp

Can you please tell me why you are specifically recommending these?

It's one I just happen to be aware of. I should have one coming some time for a job I am working on at the moment. I'll know more about working with them when the customer finally sends me one.


text:
Check if a set of events occur in a limited time period
I am making a project in which I am using 4 Infrared sensors to take an input. The way I want it to work is such that when one of the sensors is triggered, the code listens for input from the other sensors for a fixed amount of time (say 2 seconds). Based on this data, further functions are executed.
I am assigning a number to each of the sensors, and the sequence in which they are triggered is stored in an array like:
// All relevant pins of the IR sensors are set to input with names ir1,ir2,ir3,ir4
int sequence[] = {0,0,0,0}
int s1 = digitalRead(ir1); //and similarly for all other pins
int counter = 0;

if(s1==1){
  sequence[counter] = 1; //similarly 2 for s2 and so on
  counter ++;
}

What I am attempting to do is something like this:
if(s1 == 1 || s2==1 || s3 == 1 || s4 == 1){
   if(s1 == 1){
      sequence[counter] = 1;
      counter ++;

   //Start listening for other sensors
   } // similarly check which sensor is triggered first

   //Allow 2 seconds for input from all sensors (no input from either one of them is also allowed)
   // After 2 seconds execute some code based on the sequence array which got updated from inputs by different sensors
}

How do I accomplish this?

Definitely look at the timing principle shown in the BlinkWithoutDelay example, that comes with the Arduino IDE

Here's some pseudocode that might help:
   if millis() - start time >= 2000
         time is up, do what you want with the sequence so far
         maybe a boolean flag here so you only do it once
   if any button is pressed
      if counter == 0
          set start time = millis() // start the timer
          set first in sequence
      else
          add the button to the sequence

Thanks this worked. I put the code to check inputs from the sensors inside a while loop and used the millis() function as the while condition. Something like int a = millis(); int b= millis(); while(a-b <=200){...  a=millis() // updates a at the end of every loop}


text:
ESP32 OTAWebUpdater only works on mobile
I'm experiencing something strange. I opened the default ESP32 example "OTAWebUpdater" in the ArduinoIDE and modified just the network part (I created a soft AP instead). The problem is, when I connect my Android phone to the AP, I can OTA update just fine, but when I connect a laptop and try to update, it gives me an error saying "not found: serverIndex". The error occurs after selecting the .bin file and clicking the "update" button. I already tried with 3 different laptops. Any thoughts?
Below is the code:
#include <WiFiClient.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Update.h>

const char* host = "esp32";
const char* ssid = "OTAWebUpdater";
const char* password = "123456789";

WebServer server(80);

/*
 * Login page
 */

const char* loginIndex =
 "<form name='loginForm'>"
    "
"
        "
"
            ""
                "ESP32 Login Page"
                "
"
            "	"
            "
"
            "
"
        "
"
        "Username:	"
        "<input type='text' size=25 name='userid'>
	"
        "
"
        "
"
        "
"
        "
"
            "Password:	"
            "<input type='Password' size=25 name='pwd'>
	"
            "
"
            "
"
        "
"
        "
"
            "<input type='submit' onclick='check(this.form)' value='Login'>	"
        "
"
    "
"
"</form>"
"";

/*
 * Server Index Page
 */

const char* serverIndex =
""
"<form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>"
   "<input type='file' name='update'>"
        "<input type='submit' value='Update'>"
    "</form>"
 "
progress: 0%
"
 "";

/*
 * setup function
 */
void setup(void) {
  Serial.begin(115200);

  // Connect to WiFi network
  WiFi.softAP(ssid, password);

  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP());

  /*use mdns for host name resolution*/
  if (!MDNS.begin(host)) { //http://esp32.local
    Serial.println("Error setting up MDNS responder!");
    while (1) {
      delay(1000);
    }
  }
  Serial.println("mDNS responder started");
  /*return index page which is stored in serverIndex */
  server.on("/", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", loginIndex);
  });
  server.on("/serverIndex", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", serverIndex);
  });
  /*handling uploading firmware file */
  server.on("/update", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
    ESP.restart();
  }, []() {
    HTTPUpload& upload = server.upload();
    if (upload.status == UPLOAD_FILE_START) {
      Serial.printf("Update: %s\n", upload.filename.c_str());
      if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_WRITE) {
      /* flashing firmware to ESP*/
      if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_END) {
      if (Update.end(true)) { //true to set the size to the current progress
        Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
      } else {
        Update.printError(Serial);
      }
    }
  });
  server.begin();
}

void loop(void) {
  server.handleClient();
  delay(1);
}

Are you sure you wanted to use window.open('/serverIndex')? I would have thought document.location='/serverIndex' would be a better choice.

Just changed it, thanks.

Did it change the behaviour at all?