Posted on Leave a comment

How to Blink LED on Mini STM32 v3.0 Discovery Board Using STM32CubeIDE

Step 2: Configure GPIO Pins

#define LED1_Pin GPIO_PIN_2
#define LED1_GPIO_Port GPIOA
#define LED2_Pin GPIO_PIN_3
#define LED2_GPIO_Port GPIOA

In the Project Explorer pane, expand the “Src” folder and open the “main.c” file. Scroll down to the main() function and add the following code to configure the GPIO pins:

/* Configure GPIO pins */
__HAL_RCC_GPIOA_CLK_ENABLE();      // Enable GPIOA clock
GPIO_InitTypeDef GPIO_InitStruct; // GPIO configuration structure
GPIO_InitStruct.Pin = GPIO_PIN_2; // Use pin 2 on GPIOA
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; // Push-Pull output mode
GPIO_InitStruct.Pull = GPIO_NOPULL; // No pull-up or pull-down resistors
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; // Low speed
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); // Initialize GPIOA with settings

This code configures pin 2 on GPIOA as a push-pull output pin with no pull-up or pull-down resistors and low output speed.

Blink the LED using HAL_GPIO_WritePin

Add the following code inside the while(1) loop to blink the LED:

/* Blink LED */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET); // Turn LED on
HAL_Delay(1000); // Wait for 1 second
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_RESET); // Turn LED off
HAL_Delay(1000); // Wait for 1 second

This code turns the LED on by setting the state of pin 2 on GPIOA to high, waits for 1 second, turns the LED off by setting the state of pin 2 on GPIOA to low, and then waits for 1 second again. This creates a blinking effect.

Blink the LED using HAL_GPIO_TogglePin

/* Blink LED */
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_2); // Toggle the state of the LED
HAL_Delay(1000); // Wait for 1 second

This code toggles the state of pin 2 on GPIOA (which is connected to an LED on the Mini STM32 board) and then waits for 1 second before toggling it again. This creates a blinking effect.

HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_Delay(1000);
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);

Code to Blink both LED’s

HAL_GPIO_TogglePin(LED1_GPIO_Port, LED1_Pin);
HAL_Delay(1000);
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);

The first line toggles the state of an LED connected to the LED1_GPIO_Port and LED1_Pin. The second line waits for 1000 milliseconds (1 second) using the HAL_Delay() function. The third line toggles the state of another LED connected to the LED2_GPIO_Port and LED2_Pin.

Posted on Leave a comment

How to Generate Combinations of the Component from Four Text Files using Python & tkinter

This program generates a random combination of components. This can be a fun program.
It creates the combination of all the components in the four list.

For example; if each list contains 5 words. Then the total number of combinations would be 5 x 5 x 5 x 5 = 625

Code

import random
import tkinter as tk
from tkinter import messagebox
import itertools
import webbrowser


# Create the GUI window
window = tk.Tk()
window.title("List Shuffler")

# Create the text boxes for file names
micros_textbox = tk.Entry(window, width=50)
micros_textbox.insert(0, "micros.txt")
micros_textbox.grid(row = 0, column = 0, pady = 5)

sensors_textbox = tk.Entry(window, width=50)
sensors_textbox.insert(0, "sensor.txt")
sensors_textbox.grid(row = 1, column = 0, pady = 5)

inputs_textbox = tk.Entry(window, width=50)
inputs_textbox.insert(0, "inputs.txt")
inputs_textbox.grid(row = 2, column = 0, pady = 5)

displays_textbox = tk.Entry(window, width=50)
displays_textbox.insert(0, "displays.txt")
displays_textbox.grid(row = 3, column = 0, pady = 5)

# Create the label for the result
result_label = tk.Text(window, height=10, width=50)
result_label.grid(row = 0, column = 1,rowspan = 5, pady = 5)

# Define the function to shuffle the lists
def shuffle_lists():
    # Open the first file and read in its contents
    with open(micros_textbox.get(), "r") as f:
        A = f.read().splitlines()

    # Open the second file and read in its contents
    with open(sensors_textbox.get(), "r") as f:
        B = f.read().splitlines()

    # Open the third file and read in its contents
    with open(inputs_textbox.get(), "r") as f:
        C = f.read().splitlines()

    with open(displays_textbox.get(), "r") as f:
        D = f.read().splitlines()

    # Shuffle the lists
    random.shuffle(A)
    random.shuffle(B)
    random.shuffle(C)
    random.shuffle(D)

    # Select one item from each list and combine them into a string
    result = A[0] + " + " + B[0] + " + " + C[0] + " + " + D[0] +"\n\n"

    # Update the label with the result
    result_label.insert(tk.INSERT,result)
def generate_combinations():
    # Open the first file and read in its contents
    with open(micros_textbox.get(), "r") as f:
        A = f.read().splitlines()

    # Open the second file and read in its contents
    with open(sensors_textbox.get(), "r") as f:
        B = f.read().splitlines()

    # Open the third file and read in its contents
    with open(inputs_textbox.get(), "r") as f:
        C = f.read().splitlines()

    with open(displays_textbox.get(), "r") as f:
        D = f.read().splitlines()

    # Get all the combinations of the lists
    combinations = list(itertools.product(A, B, C, D))

    # Write the combinations to a text file
    with open("combinations.txt", "w") as f:
        for combination in combinations:
            f.write(' + '.join(combination) + "\n")

    # Show a message box with the number of combinations generated
    messagebox.showinfo("Combinations Generated", f"{len(combinations)} combinations were generated and saved to combinations.txt.")


# Create the button to shuffle the lists
shuffle_button = tk.Button(window, text="Shuffle", command=shuffle_lists)
shuffle_button.grid(row = 4, column = 0, pady = 5)
# Add a button to generate the combinations
generate_button = tk.Button(window, text="Generate Combinations", command=generate_combinations)
generate_button.grid(row = 5, column = 0, pady = 5)

def open_website():
    webbrowser.open_new("http://www.exasub.com")

link_label = tk.Label(window, text="exasub.com", font=("Arial", 14), fg="blue", cursor="hand2")
link_label.grid(row=6, column=0, pady=10)
link_label.bind("<Button-1>", lambda event: open_website())
# Run the GUI
window.mainloop()
Posted on Leave a comment

How to setup NodeMCU on Arduino IDE

NodeMCU is an open-source firmware and development board that is based on the ESP8266 Wi-Fi module. It is a popular platform for Internet of Things (IoT) projects due to its low cost, ease of use, and versatility. In this article, we will discuss how to set up NodeMCU on Arduino IDE.

Step 1: Install Arduino IDE
The first step is to install the Arduino IDE on your computer. You can download the latest version of Arduino IDE from the official website https://www.arduino.cc/en/software. Choose the appropriate version for your operating system and follow the installation instructions.

Step 2: Install ESP8266 Board Manager
After installing the Arduino IDE, you need to install the ESP8266 board manager. This is necessary to add the support for NodeMCU to the Arduino IDE.

To do this, open the Arduino IDE and go to File > Preferences. In the Additional Boards Manager URLs field, paste the following URL:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Click OK and go to Tools > Board > Boards Manager. In the search box, type “esp8266” and select the “esp8266” board by ESP8266 Community. Click Install.

Step 3: Select the NodeMCU Board
After the installation of the ESP8266 board manager is complete, go to Tools > Board and select “NodeMCU 1.0 (ESP-12E Module)”.

Step 4: Select the Port
Next, you need to select the port to which the NodeMCU is connected. Go to Tools > Port and select the appropriate port.

Step 5: Upload Your Sketch
Now, you are ready to upload your sketch to the NodeMCU. In the Arduino IDE, click on File > New to create a new sketch. Write your code and then click on the Upload button to upload the sketch to the NodeMCU.

Step 6: Verify Upload
Once the upload is complete, you can verify that the sketch has been successfully uploaded by opening the Serial Monitor. Go to Tools > Serial Monitor and set the baud rate to 115200. If everything is working properly, you should see the output from your sketch in the Serial Monitor.

Posted on Leave a comment

How to setup C/C++ SDK of Raspberry Pi Pico W On Raspberry Pi Model 3b+

The C/C++ SDK has development tools for both development boards.

There are various methods of the SDK. You can use this in Windows, MAC etc.
But the easiest and simplest method is the use of Raspberry Pi itself.

Step 1: Follow Chapter 1 of the Getting Started with Raspberry Pi Pico https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf

Step 2: Follow Chapter 8: Creating your own project
copy the files from pico W folder, which you will find under the pico-examples folder. The blink project will be under the wifi folder.

Step 3: add the following line to your CMakeLists.text file

set(PICO_BOARD pico_w)

Sample CMakeLists.text

cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(test_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(PICO_BOARD pico_w)
pico_sdk_init()
add_executable(test
test.c
)
pico_enable_stdio_usb(test 1)
pico_enable_stdio_uart(test 0)
pico_add_extra_outputs(test)

target_link_libraries(test 
					pico_stdlib
					pico_cyw43_arch_none
					)

NOTE: you can set the pico board to pico w. when you issue cmake ..
Only use one method of setting the pico w board.

cmake -DPICO_BOARD=pico_w ..