For one of my projects, I need to transmit data from NodeMCU to my Arduino Nano, in real time, I used S-Bus, but it quite unsatisfies me, as, slight latency is taking place. I am transmitting a JSON file, with 4 signed 16 bit integeres.
Now,I need to know, what is the fastest and most reliable way to transmit data from NodeMCU to an Arduino Nano. Any detailed description, or even suggestion will be very much helpful. Thanks in advance !
-
1what does the Nano do, what the NodeMcu can't do by itself?Juraj– Juraj ♦2020年07月19日 08:49:58 +00:00Commented Jul 19, 2020 at 8:49
-
What do you mean with "slight latency" exactly? And what S Bus library did you use? As the library, that I have found uses UART underneath, so with interface did you use at which baud rate?and do you really need to transmit JSON? using a binary protocol wiuld be way fasterchrisl– chrisl2020年07月19日 14:42:02 +00:00Commented Jul 19, 2020 at 14:42
1 Answer 1
If it comes to speed and reliability you have to choose an interface that is handled in hardware on both sides. For the arduino nano you have the following options (nodeMCU supports all of them):
- UART:
- not very fast (order of 10kbit/s), but it's full-duplex (asynchronous communication in both directions)
- implementation is trivial due to
Serial.h
- long distance (order of meters)
- I2C:
- not very fast either (order of 100kbit/s), but not full-duplex
- implementation is straight forward because both slave and master are implemented in arduino library
- only over short distance (order of cm)
- SPI:
- quite fast (>1Mbit/s), full-duplex
- implementation might require some experience (as far as I know, slave mode is not supported by
SPI.h
) - long distance (order of meters)
Which of those is the best option still depends on your specific requirements, but personally I like SPI very much because it is very fast and stable.
-
SPI is full duplex. All of those protocols can reach into the megabits-per-second (with the exception of UART if using SoftwareSerial.h which has an upper limit of about 9600 baud).Majenko– Majenko2020年07月19日 09:37:37 +00:00Commented Jul 19, 2020 at 9:37
-
@Majenko you're right about SPI being full duplex, I will edit my answer. But I doubt that you are able to run either UART or I2C in the order of Mbit/s reliably on an atmega328. Also SPI might work at >10Mbit/s, I just made conservative estimationsSim Son– Sim Son2020年07月19日 10:09:53 +00:00Commented Jul 19, 2020 at 10:09
-
Sure you can run it reliably at Mbaud. Why wouldn't you be able to? The fact that it's an 8-bit MCU doesn't mean that the hardware peripherals are slow too. It's more a question of if you can process the data you have received fast enough for Mbaud to make any real-world sense. As long as the baud rate error percentage at both ends of the connection are within tolerable amounts (which can just mean selecting the right baud rate to run at) you can go into the 1-4Mbaud range. The 16MHz clock speed limits your upper end more than anything else.Majenko– Majenko2020年07月19日 10:21:28 +00:00Commented Jul 19, 2020 at 10:21
Explore related questions
See similar questions with these tags.