Category Archives: Embedded

Upload .hex file in Arduino using CMD prompt and .bin to ESP8266

Here’s how to use the CMD prompt to upload a .hex file (compiled hex file) to Arduino without using the Arduino IDE. Also, how to use the command prompt to upload a .bin file to an ESP8266 or ESP32.

If you’re not sure what .hex and .bin files are, read on. The code written in the Arduino IDE is written in C and/or C++, a high-level programming language that is easy for us to read and write. Microcontrollers are incapable of understanding high-level programming languages.

However, when you click upload, the Arduino IDE converts your code into hex or/and bin files, which are then uploaded to microcontrollers. In general these files act as your device’s firmware.

Many times, a developer would make .hex or .bin file accessible to a client because the developer put in a lot of effort to write that code and doesn’t want to show you how he did it, so the developer can just provide you with a compiled .hex or .bin file instead of programming code, and you would need to learn these steps to upload .hex and .bin file using command prompt (CMD prompt) without using Arduino IDE.

HOW TO CREATE A .hex OR .bin FILE

Select your ‘development board’ under “Tools,” then click on ‘Export compiled binary’ under “Sketch.”

    • Tools → Board: → Arduino Genuino/Uno (let)

      Select Board Arduino Genuino Uno
      Select Board Arduino Genuino/Uno
    • Sketch → Export compiled Binary

      Export Compiled Binary Arduino
      Export Compiled Binary Arduino

This will generate two hex files if you’re using an Arduino board, or bin files if you’re using an ESP8266 or ESP32 board, in the same folder (same location) where the ino file is saved.

HOW TO UPLOAD .hex FILE IN ARDUINO UNO/NANO/MEGA USING COMMAND PROMPT

Before you begin, keep in mind that you will need three things

    • avrdude location
    • avrdude.conf location
    • .hex file location
STEP 1

To begin open the Arduino IDE and go to File > Preferences, check the box upload under Show verbose output during:

Show verbose output during compilation and upload Arduino IDE
Show verbose output during compilation and upload – Arduino IDE
STEP 2

Select a board from the tools menu, in my case Arduino Genuino/Uno, and a COM port from the tools menu. Mine is COM14, but it’s possible that yours is different.

Select COM port (Communication Port)
Select COM port
STEP 3

If everything is in order, you can upload any code or sketch (either blank or any)

STEP 4

Before the red colour text began from, something like “avrdude: Version 6.3-20171130” as seen in the screenshot, after the upload was successful.

Find hex file upload command
Find hex file upload command

You’ll come across avr dude command like this, but your path may be slightly different. Have a look at these points and see if they contain -CC, -Uflash:w:\path_of_hex_file:i

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM14 -b115200 -D -Uflash:w:D:\MyCode\String_Seprator\String_Seprator.ino.standard.hex:i

Copy this line and paste into some text editor like notepad++, next 2 steps are important.

STEP 5

Replace the path between ‘w’ and ‘i’ in the last red line with the path to the hex file you intend to upload.

STEP 6

Since the CMD prompt doesn’t recognize spaces between paths see here in Program Files (x86), use double-course “” for the path This is what the command above would look like. (see below).

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega328p -carduino -PCOM14 -b115200 -D -Uflash:w:"D:\PIJA Education\String_Seprator\String_Seprator.ino.standard.hex:i"

If you don’t use double-course, you’ll get an error like this:

C Program not recognized as an internal or external command
‘C:\Program’ is not recognized as an internal or external command

‘C:\Program’ is not recognized as an internal or external command, operable program or batch file.

STEP 7

Now open a command prompt (Windows+r), type cmd in the run wizard, and click OK.

Run window - cmd
Run window – cmd
STEP 8

The path from step 6 should be copied, right-clicked, and pasted; the shortcut key ctrl + v would not work here in cmd prompt.

STEP 9

If all of the steps above are completed correctly, you can see that the upload was successful. with a message at end “avrdude done.  Thank you.

Upload hex file in Arduino using Command (cmd) prompt
Upload hex file in Arduino using cmd prompt

HOW TO UPLOAD .bin FILE IN ESP8266 USING COMMAND PROMPT

To upload .bin file to ESP8266, follow the same instructions from 1 to 3 as we did for Arduino, except board and port selection, these will be different different this time. For example board may be  NodeMCU 0.9 (ESP-12 Module) and Port is COM11.

STEP 1

Once you upload code successfully, Before the red colour text began from, something like “esptool.py v2.8” as seen in the screenshot

Find NodeMCU/ESP8266 bin file upload command
Find NodeMCU/ESP8266 bin file upload command

You’ll come across upload command like this, but your path may be slightly different.

C:\Users\abc\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1/python3 C:\Users\abc\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/upload.py --chip esp8266 --port COM11 --baud 115200 --before default_reset --after hard_reset write_flash 0x0 C:\Users\abc\AppData\Local\Temp\arduino_build_9655/test.ino.bin

Copy this line and paste into some text editor like notepad++, next 2 steps are important.

STEP 2

Replace the path in the last red line with the path to the bin file you intend to upload.

STEP 3

Since the CMD prompt doesn’t recognize spaces between paths see here in Program Files (x86), use double-course “” for the path, if space present in path. This is what the command above would look like. (see below).

C:\Users\abc\AppData\Local\Arduino15\packages\esp8266\tools\python3\3.7.2-post1/python3 C:\Users\abc\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/upload.py --chip esp8266 --port COM11 --baud 115200 --before default_reset --after hard_reset write_flash 0x0 "D:\PIJA Education\test/test.ino.nodemcu.bin"
STEP 4

Now open a command prompt (Windows+r), type cmd in the run wizard, and click OK.

Run window - cmd
Run window – cmd
STEP 5

The path from step 3 should be copiedright-clicked, and pasted; the shortcut key ctrl + v would not work here in cmd prompt.

STEP 6

If all of the steps above are completed correctly, then click enter and you can see that the upload was successful with a message at end “Hard resetting  via RTS pin…

HOW TO UPLOAD .bin FILE IN ESP8266 USING COMMAND PROMPT
Upload bin file in ESP8266 using Command (cmd) prompt

 

 

 

EEPROM IN ARDUINO AND ESP (ESP8266 and ESP32)

This article will explain what an EEPROM is and provide a brief overview of the other memories available in a microcontroller. You”ll also learn how to use EEPROM in Arduino and ESP microcontrollers (ESP8266 and ESP32).

Using the EEPROM put and EEPROM get functions, the software below illustrates how to read and write to EEPROM.

EEPROM IN ARDUINO AND ESP

MEMORY USED IN MICROCONTROLLER

There are various types of memories, including Flash memory, cache memory, RAM, and EEPROM.

Continue reading EEPROM IN ARDUINO AND ESP (ESP8266 and ESP32)

SERVO MOTOR WITH ARDUINO

In this section, you learn interfacing of servo motor with Arduino, but before this let’s start with servo motor.

A servo motor is an electrical device used to rotate objects at certain specified angles. It’s just a basic motor that runs through the mechanism of the servo.

They are used in numerous applications such as toy cars, robotics, machines etc.

Servo motors are measured in kg / cm (kilogram per centimeter). Servo motors are rated 3kg / cm or 6kg / cm etc. This kg / cm tell you how much weight your servo engine can lift at a given distance. Generally servo motor 9G SG90 is used in projects.

Servo Motor

Continue reading SERVO MOTOR WITH ARDUINO

DATA TYPE CONVERSION IN ARDUINO

This tutorial covers data type conversion in arduino. Data type conversion or typecasting means converting a value from one data type to other. For example, convert int to float, string to int etc.

Data type covered in this section are int, float, char, char array, string and const char *.

DATA TYPE CONVERSION IN ARDUINO

INT TO OTHER DATA TYPE CONVERSION

This Arduino code will convert data types from int to other, see below

  • Convert int to float in Arduino
  • Convert int to char in Arduino
  • Convert int to char array in Arduino
  • Convert int to String in Arduino

data type conversion in arduino
Data type conversion: Int to float, char, char array[] and String
Continue reading DATA TYPE CONVERSION IN ARDUINO

8X8 LED MATRIX WITH ARDUINO

In this project you will see how to Interface 8×8 led matrix with Arduino or 8×8 dot led matrix with Arduino. In this section we will connect Arduino and led matrix display and send data wirelessly using Bluetooth HC05.

REQUIRED MATERIAL

S.N.COMPONENTQUANTITY
1.Arduino Uno1
2. 8x8 LED matrix module of 41
3.Bluetooth HC051
4. Jumper wires10 (approx)

MAX7219 DOT LED MATRIX 4 in 1 MODULE

8x8 LED matrix Continue reading 8X8 LED MATRIX WITH ARDUINO

ROBOT CAR APK

This section tells you, how to use ‘Robot Car App’, designed for Bluetooth control robot car using Arduino and to receive or transmit serial data from Arduino (via Bluetooth HC05 or HC06). Download Robot car apk.

ROBOT CAR APK

Download and Install latest version of Robot car apk. and follow these steps to configure your phone with app.

  1. Turn on your android phone Bluetooth and search for the available Bluetooth devices. There you find either HC05 or any other depends on which one you are using.
  2. Now enter default password 1234 or 0000 to pair with the Bluetooth HC05 (General method to connect with any other BT device).

Bluetooth HC05 Pairing
Click to Zoom

Continue reading ROBOT CAR APK