iHIS© – Example of Code (Python for A.I.)

This is an example only to program iHIS© in Python code that allows artificial intelligence to control an electronic device. This is a very interesting task.To do this, you’ll need some components and libraries:

  • A Raspberry Pi, which is an affordable and versatile mini computer that you can use to program and control electronic devices via its GPIO² ports.
  • An electronic device to be controlled, such as an LED, a motor, a sensor, etc. For simplicity, we will use an LED as an example.
  • A resistor to be connected in series to the LED to limit the current and protect the Raspberry Pi from overloads.
  • Jumper cables to connect the Raspberry Pi to the LED and resistor.
  • A breadboard, which is a perforated plate that allows you to create electronic circuits without soldering the components.
  • The PyVISA Python library, which allows you to communicate with electronic devices via interfaces such as GPIB, USB and Ethernet¹.
  • The Python library electricpy, which contains functions and constants useful for electrical engineering³. Once you have all these components, you can follow these steps to create your code:
  1. Connect the Raspberry Pi to a power source and turn it on. Make sure you have an active internet connection on the Raspberry Pi.
  2. Connect the LED to the breadboard, being careful to put the positive (longer) terminal in one row and the negative (shorter) terminal in another row.
  3. Connect the resistor to the same row as the LED’s positive lead and the other end to a free row on the breadboard.
  4. Connect a jumper wire from GPIO pin 25 (pin 22 on the Raspberry Pi’s GPIO connector) to the spare row of the breadboard where the resistor is connected.
  5. Connect another jumper wire from the GND pin (pin 6 on the Raspberry Pi’s GPIO connector) to the row where the LED’s negative terminal is connected.
  6. Open a terminal on the Raspberry Pi and install the PyVISA and electricpy libraries using the commands pip install pyvisa and pip install electricpy.
  7. Open a text editor on the Raspberry Pi and write the following code in Python:
 # We import the necessary libraries
 import pyvisa
 import electricpy
 import time

 # Let's create an object to manage communication with the Raspberry Pi
 rm = pyvisa.ResourceManager()

 # Open a session with the Raspberry Pi using its IP address
 rasp = rm.open_resource("TCPIP::192.168.0.10::inst0::INSTR")

 # We set GPIO pin 25 as a digital output
 rasp.write("GPIO 25 OUTPUT")

 # Let's create an infinite loop to turn the LED on and off
 while True:
     # We turn on the LED by sending a high signal to GPIO pin 25
     rasp.write("GPIO 25 HIGH")
     # Let's wait a second
     time.sleep(1)
     # We turn off the LED by sending a low signal to GPIO pin 25
     rasp.write("GPIO 25 LOW")
     # Let's wait another second
     time.sleep(1)
  1. Save the code with a name of your choice, for example led.py.
  2. Run the code using the python led.py command in the terminal.
  3. Watch the LED turn on and off every second. Congratulations! You’ve just created code in Python that allows artificial intelligence to control an hardware equipment.