Hi all,
I would like to ask you for help with code which would be able to upload stored bin file from NodeMCU v3 (ESP8266) from SPIFFS (or LittleFS) to Arduino UNO board via serial (rx, tx) communication.
I am working on a project for kids and want to avoid installing Arduino IDE, drivers etc… I just want to store couple of compiled projects (bin files produce by Arduino IDE) in SPIFFS (or LittleFS) of NodeMCU v3 (ESP8266).
My idea is to use your very interesting project published HERE and add one more functionality to it. It could be just a web button which would upload (flash) the stored bin file to Arduino Uno board (with standard bootloader in it).
Same as the PC would do. There could be a web button for every project, it is not so important for now. I would just need a bit of help with the code to extend the existing project with this functionality. The NodeMCU would be connected to Arduino Uno via serial (rx, tx) pins + reset pin, or even better to connect both boards with USB cable.
That would be the best solution to really simplify it as much as possible. I have been searching for some time if such solution already exist but did not find it yet. Please would be there somebody able to help me with this project? I would really appreciate your help.
The Arduino Uno comes with a bootloader (known as Optiboot) which implements the STK500 protocol for receiving the compiled program binaries through the UART.
Explanation on Optiboot in Updating Arduino Firmware
On reset:
Arduino reboot from bootloader and check for the cause of the reset. If it was an internal reset (eg. reset by watchdog timer), then it directly jumps to the main application program. However, if it was an external reset, it will set up a watchdog timer which will timeout in 1 second.
Listen to UART port:
If it was an external reset, the bootloader will start an infinite loop to listen to the UART port after the watchdog timer setup. If there is no valid command dedicated to the STK500 protocol received in 1 second, the watchdog timer will timeout and cause an internal reset. However, on receiving any valid command code, the watchdog timer counter will be reset to avoid unnecessary system reset from occurring. According to the application note of STK500 Communication Protocol, the format of the command is: <Command_Code> <Data (if any)> <CRC_EOP>
List of valid and useful command codes for Optiboot:
1. STK_GET_SYNC : — 0x30
2. STK_ENTER_PROGMODE : — 0x50
3. STK_LEAVE_PROGMODE : — 0x51
4. STK_LOAD_ADDRESS : — 0x55
5. STK_PROG_PAGE : — 0x64
6. CRC_EOP : — 0x20List of useful reply codes from Optiboot:
1. STK_INSYNC : — 0x14
2. STK_OK : — 0x10
Algorithm of Optiboot in receiving compiled binaries:
Programmer send <STK_ENTER_PROGMODE> <CRC_EOP> to Arduino to command for starting of programming mode. The bootloader will reply <STK_INSYNC> <STK_OK> if it is in sync with the programmer.
*Note: After reading through the source code of Optiboot, I found that this step is not necessary as there is no specific condition checking for this command. However, it could be used for checking whether the Arduino is in sync with the programmer or not. Alternatively, by sending <STK_GET_SYNC> <CRC_EOP> could also check whether it is in sync or not.
If the Arduino is in sync with the programmer, the programmer can then send <STK_LOAD_ADDRESS> <Low byte of address> <High byte of address> <CRC_EOP>. This command is for loading the starting address of flash memory which will be filled with the bytes of program binary codes that will be sent later.
* low byte of address = address & 0xFF
* high byte of address = address >> 8
** address starts from 0
If <STK_INSYNC> <STK_OK> is received, the programmer can then send <STK_PROG_PAGE> <Low byte of length> <High byte of length> <Dest type> <bytes of program of the specified length> <CRC_EOP>.
* The length specified the number of bytes of program binaries to be written in the flash memory. low byte of length = length & 0xFF high byte of length = length >> 8
* The <Dest type> specified the location (eeprom [‘E’] or flash [default]) at which the program codes to be written.
Check for reply. If <STK_INSYNC> <STK_OK> is received, update the as address := address + (length / 2), then continue the loop from step 2 until all the program binaries are sent and written into the flash memory.
* Since the address is a word pointer, so it is updated by half of the length (byte).
After sending all program binaries, the programmer then send <STK_LEAVE_PROGMODE> <CRC_EOP> for leaving programming mode.
OTA Firmware Update on Arduino Uno through ESP8266
The Arduino Uno is connected with a WiFi module to enable OTA firmware update. In this project, ESP8266 WiFi module is used. A simple ESP8266 library is developed to remotely interface with the connected Arduino Uno. This library enables the OTA firmware update functionality for the Arduino by implementing STK500 protocol (as explained above) for writing the compiled binaries to the Arduino. Besides, remote debug message logging is also enabled in this library.
On the host machine, a graphical user interface (GUI) is also developed to aid the process of remotely interfacing with the connected Arduino.
The remote interfacing process is done through MQTT protocol. So, the WiFi module and the host machine must connect to a MQTT broker for communication. The library used for establishing MQTT connection on the WiFi module here is the PubSubClient by knolleary.
Hello Renzo,
thanks a lot for all the information you have provided. I am going to explore that and do some testing with it. I will see how far I could get with my current knowledge to make the required extension. Really thanks for your time and support you are currently giving me.
Maintaining a repository (or site or forum) is a lot like tending to a garden - it requires constant care and attention to keep it thriving. If you're a skilled gardener (or coder!) and want to help keep our repository blooming, we'd love to have you on board! We're also looking for talented writers and forum moderators to help us grow our community. Interested in joining our team? Don't hesitate to reach out and let us know how you can contribute!
Are you a fan of electronics or programming? Share your knowledge with others, write a simple tutorial or how to make a great project Contact me: share_your_ideas@mischianti.org
The content displayed on this website is protected under a CC BY-NC-ND license. Visitors are prohibited from using, redistributing, or altering any content from this website for commercial purposes, including generating revenue through advertising. Any unauthorized use is a violation of the license terms and legal action may be taken against individuals or entities found to be in violation.
You must also provide the link to the source.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.