Author Topic: The same code+ changed board = RS communication doesnt work(solved)  (Read 1858 times)

0 Members and 1 Guest are viewing this topic.

Offline BinaryWorldTopic starter

  • Newbie
  • Posts: 9
edit: if you dont have time, read only my last post( Reply #4).
Hi everyone,
i have a problem with my project.
When i use
(1)SparkFun ESP32 Thing
https://botland.com.pl/plytki-zgodne-z-arduino-sparkfun/7911-sparkfun-esp32-thing-modul-wifi-i-bluetooth-ble-kompatybilny-z-arduino-ide.html
and(2) ESP32-DevKitC ESP32 WiFi + BT 4.2:
https://botland.com.pl/moduly-wifi/8893-esp32-devkitc-esp32-wifi-bt-42-platforma-z-modulem-esp-wroom-32-ver-2.html
all works fine(9 from 10 tries is ok, sometimes freeze).
Now i use a (1) and (3) nodemcu 32s v1.1.
Boards (2) and (3) looks the same, only GPIO2 and GPIO5 are replaced.

Code is the same, but transmission doesnt work(only sometimes, once every few tries).

I add simply test code:

Master(SparkFun ESP32 Thing)
Code: [Select]
char spr  = '\n';
unsigned int czas = 0;
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin(9600);
   }

void loop() {
  delay(300);
  Serial.println('A');

}

Slave(nodemcu-32s):
Code: [Select]
char spr  = '\n';
unsigned int czas = 0;
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin(9600);
    millis();
}

void loop() {
 
  if(Serial.available()){
    digitalWrite(LED_BUILTIN, HIGH);
    czas = millis();
  }
  while(Serial.available()) {
    spr = (char)Serial.read();
  }
  if(czas + 200 < millis()){
    digitalWrite(LED_BUILTIN, LOW);
  }

}

Master + slave powered from 1 usb. When i unplug and plug in again and again... This start works. When transmission start, its all time good(to arduino turn off or reset).

I have 2 NodeMCU boads - the same problem!

On board (1) and (2) its ok. But its 1 strange thing. Here master is (2), slave(1).
When i plug usb on(arduino power) - slave led blinking. Press and hold reset on master - led off. Relase - slave again blinking. But when i reset slave - not always start blinking(off). Why?

Thank you for all ideas
« Last Edit: February 18, 2018, 05:43:57 pm by BinaryWorld »
 

Offline BinaryWorldTopic starter

  • Newbie
  • Posts: 9
Re: The same code+ changed board = RS communication doesnt work
« Reply #1 on: February 07, 2018, 07:15:36 pm »
Nobody will help?
 

Offline Twoflower

  • Frequent Contributor
  • **
  • Posts: 737
  • Country: de
Re: The same code+ changed board = RS communication doesnt work
« Reply #2 on: February 07, 2018, 08:09:15 pm »
Not sure if I can help much. The reason for the difference could be the different UART device on both boards.

Do I understand you right that in case the problem happens the LED on the SparFUN goes on but never off? Or other wise around (it never lit). In second case it could be that the ESP goes in a different operating mode if the UART receives something during boot. See the schematics at https://cdn.sparkfun.com/assets/learn_tutorials/5/0/7/esp32-thing-schematic.pdf in the box Auto-Reset.
 

Offline BinaryWorldTopic starter

  • Newbie
  • Posts: 9
Re: The same code+ changed board = RS communication doesnt work
« Reply #3 on: February 07, 2018, 08:32:23 pm »
Thanks for your answer.
My main problem - no RS communication when i use SparkFun(master) + NodeMCU(slave).
The problem is with the NodeMCU(I checked on 2 copies).

With the above code NodeMCU not blinking(led off).
Once, for several  power on, the transmission starts (and works - I tested with led code / with my project code). In this state led blinking.

Second question.
SparkFun(1) +ESP32-DevKitC (2)  - transmission is ok. But there is on strange case . When i reset(push button on board) slave(sparkfun) sometimes transmission stop working(mayby ~ 025% of cases).

I will check what happens when I stop sending data from the master, reset the slave, and then start sending data. Maybe this is a solution to the secondary, side question.

Add:

OK. All time I use ArduinoIDE 1.8.4, with arduino-esp32 library: https://github.com/espressif/arduino-esp32/tree/master/libraries
Board: "Node32s" // or NodeMCU-32s
Flash Frequency: "80 MHz"
Upload Speed: "115200"
and this not work correctly.

I add:
Code: [Select]
#include <dummy.h> // dont know its necessary, never use this before; it's Esp32 library
and delay(2000) in setup(on master).
Now  8 out of 10 attempts its ok.

But how make 10/10?

To upload code i need unplug rx cable and press buttons enable + reset(download mode) to upload code. But it's not always work(few tries).
With other board this problem occurs less frequently.

This boards have a 3x UART. How to use it simply?
If i use only 1 UART, mayby change pinout in library?
When i plugin usb, arduino sends/receive data from PC only on 1 UART (Rx/Tx 1/3pins)?
Mayby if i connect boards with other UART, power on/connect to PC dont generates data on others UARTS and all works fine?
« Last Edit: February 10, 2018, 01:50:16 pm by BinaryWorld »
 

Offline BinaryWorldTopic starter

  • Newbie
  • Posts: 9
Re: The same code+ changed board = RS communication doesnt work
« Reply #4 on: February 10, 2018, 02:22:50 pm »
I found main reason  but i dont know how fix it.

I add:
Code: [Select]
   if(test + 1000 < millis()){
    test = millis();
    if(odwroc == 0){
      digitalWrite(2, HIGH);
      odwroc = 1;
    }
    else{
      digitalWrite(2, LOW);
      odwroc = 0;
    }
in main loop(in my project). Led just blinking all time.

When i send data to slave, 90% of cases board freeze... LED stay in last state(on or off) - nothing work.
In last 10% all work fine - i can again receive data(to time, when i turn off board).

At first i think while loop stops all, so i change it to "if loop" but it isn't it.
Code: [Select]
if (Serial.available()) {
    spr = (char)Serial.read();
   
    if(spr == 'A'){ 
      data = Serial.read();
    }
//if(spr == 'B') data2 etc...
    spr = '\n';
}



Edit:
On first board 9/10 tries - error.
On second 3/10 - error.
Now i check it again.

So I do something wrong or boards(2 pieces) are damaged?
« Last Edit: February 10, 2018, 02:51:10 pm by BinaryWorld »
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: The same code+ changed board = RS communication doesnt work(update topic)
« Reply #5 on: February 11, 2018, 11:40:35 am »
It might help for you to supply ALL of your code, and maybe a diagram/schematic of how things are connected.

Admittedly I know very little about Arduino type stuff, but there appears to be very little initialisation code for the UARTs, and some of those modules appear to have at least one UART...?

What other things can you do to debug your code? Can you print text back to the PC console so you can see what has been received by the slave? Can you set another LED when a certain branch of code is executed to make sure that the bits of your code that you expect to be executed do in fact get executed? Can you blink another LED in a continuous loop unrelated to the UART operations to see whether the entire device locks up, or is it just the UART related code that has a problem?
 

Offline BinaryWorldTopic starter

  • Newbie
  • Posts: 9
Re: The same code+ changed board = RS communication doesnt work(update topic)
« Reply #6 on: February 13, 2018, 11:22:49 am »
Thanks for your answer.

I think that it is easier to find an error in the simple code (and simple schematic) that generates the same problems. (my code in 2 arduino: ~1300lines).
So i made a new simply test:
Master send a 2 bytes when i press button.
Slave code:
Code: [Select]
#include <dummy.h>

const int led2 = 4;
boolean state_led2 = 0;
unsigned int time2 = 0;

char spr  = '\n';
unsigned int time1 = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(led2, OUTPUT);
    Serial.begin(9600);
    millis();
}

void loop() {

  while(Serial.available()) {
    digitalWrite(LED_BUILTIN, HIGH);
    spr = (char)Serial.read();
    time1 = millis();
  }
 
  if(time1 + 1000 < millis()){
    digitalWrite(LED_BUILTIN, LOW);
  }

  /*******/
  if(time2 + 500 < millis()){
    time2 = millis();
    state_led2 = !state_led2;
    digitalWrite(led2, state_led2);
  }
 
}

Led on board turn on 1 second when i receive data.
Led2 blinking all time.

And still the same problem:
1)reset slave and master
2) press button => send 2 byte to slave
3)IF slave dont freeze after send data(led on board turn on 1 second);
led2 still blinking
4) i can press button again and again(send 2 bytes) and slave work fine

if the first data packet freeze board, led2 stop blinking(remember last state) and LED_BUILTIN dont turn on.
Need restart slave and try again...

The connection scheme is pretty simple.


I tried to use
Code: [Select]
#include <HardwareSerial.h>with other uart pins(9 +10 or 16+17 on nodemcu 32s).
Still the same...

To see received data i need rewrote data to other uart(with HardwareSerial library).
Experience from the last code shows that it will not work (I can see data if the board does not freeze).

Check received data? ( i thinks its ok, becouse slave use it well, when board doesn't freeze).
« Last Edit: February 13, 2018, 12:00:31 pm by BinaryWorld »
 

Offline BinaryWorldTopic starter

  • Newbie
  • Posts: 9
Re: The same code+ changed board = RS communication doesnt work(update topic)
« Reply #7 on: February 18, 2018, 02:17:29 pm »
I solved the problem.
Git gui didnt update esptool.py(dont know why).
I had it in version 2.1 beta.
I deleted all and new installation give me a stable 2.1.
Now all work corretly on all my boards.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf