Setting up the Arduino CLI on Windows and using it to program various Arduino and ESP boards like the Arduino Zero, Mega, Uno, ESP-WROOM-32, and Wemos-based ESP32 board D1 R32 involves several steps. Also, creating a diagnostic sketch that runs a self-test is more limited than a PC's POST because microcontrollers don't have the same level of systems management.
Here's how to set everything up:
1. Install Arduino CLI:
- Download the latest version of the Arduino CLI executable from the official Arduino website: https://arduino.github.io/arduino-cli/installation/
- Unzip the downloaded file and place 'arduino-cli.exe' in a convenient location, such as
C:\arduino-cli\.
- Open a command prompt (cmd.exe) and navigate to the directory where you placed
arduino-cli.exe.
- Add the Arduino CLI to your system's PATH environment variable by running the following command, replacing the path with the actual path to your executable:
setx path "%path%;C:\arduino-cli"
Now, you can access the Arduino CLI from any command prompt.
2. Configuring Arduino CLI:
Initialize the Arduino CLI configuration:
arduino-cli config init
Update the package index (which contains the list of available platforms and libraries):
arduino-cli core update-index
Install the necessary cores for your boards:
arduino-cli core install arduino:samd // For Arduino Zero
arduino-cli core install arduino:avr // For Arduino Uno and Mega
arduino-cli core install esp32:esp32 // For ESP-WROOM-32 and Wemos ESP32
3. Create an Internal Systems Test Sketch:
A self-test sketch could check some basic things like the supply voltage and internal temperature if the microcontroller has these features—for example, the internal temperature sensor on some ESP32 boards.
Create a new .ino sketch file, include the self-test checks relevant for each board type, and save it somewhere on your system. Here is a very basic template:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Performing internal systems test...");
// Check voltage
Serial.print("Supply voltage: ");
// The function to read supply voltage would be different for each board
Serial.println(readSupplyVoltage());
// Check temperature
Serial.print("Internal temperature: ");
// The function to read temperature would also be different for each board
Serial.println(readInternalTemperature());
// Delay between each test run
delay(10000);
}
float readSupplyVoltage() {
// IMPLEMENTATION SPECIFIC TO YOUR BOARD
return 0.0; // Replace with actual code to read supply voltage
}
float readInternalTemperature() {
// IMPLEMENTATION SPECIFIC TO YOUR BOARD
return 0.0; // Replace with actual code to read internal temperature
}
You would replace readSupplyVoltage() and readInternalTemperature() with actual implementations suitable for the MCU on the board you're working with. Since not all microcontrollers have these features, you may only implement them for those that do.
4. Compile and Upload the Test Sketch:
arduino-cli compile --fqbn arduino:samd:arduino_zero_native your-sketch-folder-name
arduino-cli upload -p COM_PORT --fqbn arduino:samd:arduino_zero_native your-sketch-folder-name
- Replace
your-sketch-folder-name with your actual sketch folder path.
- Update the
--fqbn with the appropriate core for the board you’re using.
- Replace
COM_PORT with the actual COM port your board is connected to.
5. Python Sketch to View Serial Output:
To read the serial output from the microcontroller in Python, you can use the pyserial library.
Install pyserial if you haven’t already:
pip install pyserial
Python script to read and print the serial output:
import serial
import time
# Replace 'COM_PORT' with the appropriate COM port
ser = serial.Serial('COM_PORT', 9600, timeout=1)
# Wait for the connection to initialize
time.sleep(2)
try:
while True:
if ser.in_waiting:
line = ser.readline().decode('utf-8').rstrip()
print(line)
except KeyboardInterrupt:
print("Exiting...")
finally:
ser.close()
Save this file with a .py extension and run it using Python while your board is connected and after you've uploaded the test sketch. It will display the serial output from your board, which includes the results of your self-test sketch.
Remember, the self-test capabilities of microcontrollers will be pretty limited compared to a full PC POST, and not all test items might be possible depending on the specific hardware and its capabilities.