DEV Community

Cover image for Getting Started with Soft IoT
Kuldeep Singh
Kuldeep Singh

Posted on

Getting Started with Soft IoT

This is a submission for the 2024 Hacktoberfest Writing challenge: Maintainer Experience

Learning IoT doesn’t have to be complex, especially when starting out. In this post, we’ll explore how to get started with IoT without diving deep into hardware complexities like wiring or understanding intricate sensor details.

In an earlier article, we set up a Raspberry Pi. My son initially saw it as just another, albeit slower, computer. There was no “IoT” in it yet, just a basic device. But IoT is about more than just the device itself; it’s about integrating sensors and actuators.

In this article, we’ll take the first step to transform the Raspberry Pi into a functional IoT device — using the Grove Pi+ board to add sensors and actuators — without getting bogged down by hardware details. I call it Soft IoT — focusing on the software side of things. We’ll delve into the hardware later.

What You’ll Need:

In addition to what we used in the last article, you’ll need:

  • Grove Pi+ Board (more details here)
  • Grove LED and Universal 4-pin cable (can be found here)

⚙️ Setting up the Grove Pi+ Board

If you have already setup Raspberry Pi with an OS as mentioned earlier, then you may choose to manually configure firmware and software for Grove PI. ❌ But I don’t recommend that as it can be tedious and prone to errors (I faced many issues with my older PI, and I gave up later!).

✅ It is better we use a pre-built OS image provided by Dexter Industries, the makers of the Grove Pi+ board. This simplifies the process — just download the image from here, use the Raspberry Pi Imager and choose the downloaded zip in Operating System section to write it to SD card, and you’re ready to go with new OS image. Insert the SD card to your Raspberry Pi and boot up on new OS.

🎮 Connecting the Grove Pi+ Board

Once the OS is ready, everything is pre-installed. Now, it’s time to connect the board to the Raspberry Pi. Align the Grove Pi+ board’s pins with the Raspberry Pi’s, ensuring the pins match the right corners. The Grove Pi+ board has multiple ports (D1 to D7 for digital input/output and A1 to A3 for analog input/output).

Next, connect the Grove LED to one of the digital sockets (for instance, D4). Power up the Raspberry Pi, and you should see a green light on the Grove Pi+ board, indicating that it’s ready for use.

🧑🏻‍💻 Writing Your First Program

Now, we’ll write a simple program to control the LED and introduce you to Soft IoT.

There are already several sample programs pre-loaded, so we don’t need to reinvent the wheel. These programs simplify hardware connections and interactions by using pre-built libraries. The programs allow us to easily read from or write to specific ports, and they wrap Arduino functions that handle communication between the Raspberry Pi and Grove sensors.

Let’s understand a basic program that makes the LED blink continuously. It is available at /home/pi/Dexter/GrovePI/Software/Python/grove_led_blink.py

  • Select the Port and Mode — For this program we use a digital port, to power ON and OFF led. Below method to set a pin mode to OUTPUT.

    grovepi.pinMode(pin, "OUTPUT")
    

    Make sure you connect the grove led to respective port. It connected to to D4, then use pin = 4.

  • Power ON the LED — Power ON the LED by writing a positive non-zero value to the selected port.

    grovepi.digitalWrite(pin,1)
    

    Similarly write value zero to Power OFF the Led

    grovepi.digitalWrite(pin,0)
    
  • Blinking LED — To blink an LED we need to ON and OFF the LED in a loop.

      while True:
          grovepi.digitalWrite(pin,1) # Send HIGH to switch on LED
          print ("LED ON!")
          time.sleep(1)
          grovepi.digitalWrite(pin,0) # Send LOW to switch off LED
          print ("LED OFF!")
          time.sleep(1)
    

Thats it, and there are few more error handling and logs in the program.

💡 Running a program

You may browse and run the program in developer tools comes within the Raspberry OS, Eg. Main Menu > Programming > Thonny Python IDE or Just run the program from the terminal as follows:

pi@dex:~ $ cd Dexter/GrovePi/Software/Python/
pi@dex:~/Dexter/GrovePi/Software/Python/ $ python grove_led_blink.py
This example will blink a Grove LED connected to the GrovePi+ on the port D4.
If you're having trouble seeing the LED blink, be sure to check the LED connection and the port number.
You may also try reversing the direction of the LED on the sensor.

Connect the LED to the D4 port!
LED ON!
LED OFF!
LED ON!
LED OFF!
LED ON!
LED OFF!
LED ON!
LED OFF!
LED ON!
LED OFF!
Enter fullscreen mode Exit fullscreen mode

For fun, try experimenting with the intervals or testing other programs like grove_led_fade.py, which ask you to connect to a port that support Pulse Width Modulation (PWM) and analog writing, allows for more complex control, such as fading the LED.

⏭️ What’s Next?

This is just the beginning of your IoT journey. The Grove Pi+ significantly simplifies the complexity of interfacing with hardware and firmware by providing a range of plug-and-play sensors. From building projects like weather stations, alarms, rain sensors, and more. Grove Pi+ makes it easy for beginners and enthusiasts to dive into IoT without getting overwhelmed by technical details.

Note that IoT is much more than just connecting sensors. To create an end-to-end IoT solution, you’ll need to integrate these devices with the cloud, edge computing, and advanced technologies like AI and XR. Ref : Touchless IoT by Sri Vishnu S

In future articles, we’ll explore how IoT connects with the broader internet ecosystem, and shaping up it’s practices, and its role in the emerging metaverse. In Chapter 4 of my book 📕Exploring the Metaverse, I discuss how IoT will shape our connected future, and XR devices are the evolved IoT.

Image

☞ Click here for availability and discounts in your region

☞ Read: Exploring the Metaverse - Synopsis

Stay tuned for more! Keep learning, keep experimenting, and keep sharing.

Top comments (0)