Not reading (digitalRead) all the pins of bolt module

I connected 5 leds to 5 pins of bolt wifi module. I switched all of them ON, and all glowed. But when I checked the reading whether they were ON/OFF using digitalRead function only one pin’s reading were high while rest all were low but all were glowing. What do I do now to solve this problem?

Hi @jerinpisac.cs22,

Could you please share the code and circuit connections you’ve implemented for the 5 LEDs connected to the Bolt WiFi module? This information will help us understand the setup and identify if there is any issues and we can help you out accordingly.

import conf
import json,time
from boltiot import Bolt
import pyautogui
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
while True:
b1 = mybolt.digitalRead(‘0’)
data = json.loads(b1)
d1 = int(data[“value”])
b2 = mybolt.digitalRead(‘1’)
data = json.loads(b2)
d2 = int(data[“value”])
b3 = mybolt.digitalRead(‘2’)
data = json.loads(b3)
d3 = int(data[“value”])
b4 = mybolt.digitalRead(‘3’)
data = json.loads(b4)
d4 = int(data[“value”])
b5 = mybolt.digitalRead(‘4’)
data = json.loads(b5)
d5 = int(data[“value”])

if d1 == 1:
    print("Up")
    pyautogui.hotkey('ctrl', 'up')

if d2 == 1:
    print("Left")
    pyautogui.press('left')

if d3 == 1:
    print("Space")
    pyautogui.typewrite(['space'], 0.2)

if d4 == 1:
    print("Right")
    pyautogui.press('right')

if d5 == 1:
    print("Down")
    pyautogui.hotkey('ctrl', 'down')
time.sleep(3)

Hi @jerinpisac.cs22,

It appears that there might be an issue with the code logic. The digitalRead function returns a dictionary with a ‘value’ key, so there’s no need to load the response into json.loads multiple times. Instead, you can directly extract the ‘value’ from the dictionary.

import conf
import json
import time
from boltiot import Bolt
import pyautogui

mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)

while True:
    b1 = mybolt.digitalRead('0')
    d1 = int(b1['value'])

    b2 = mybolt.digitalRead('1')
    d2 = int(b2['value'])

    b3 = mybolt.digitalRead('2')
    d3 = int(b3['value'])

    b4 = mybolt.digitalRead('3')
    d4 = int(b4['value'])

    b5 = mybolt.digitalRead('4')
    d5 = int(b5['value'])

    if d1 == 1:
        print("Up")
        pyautogui.hotkey('ctrl', 'up')

    if d2 == 1:
        print("Left")
        pyautogui.press('left')

    if d3 == 1:
        print("Space")
        pyautogui.typewrite(['space'], 0.2)

    if d4 == 1:
        print("Right")
        pyautogui.press('right')

    if d5 == 1:
        print("Down")
        pyautogui.hotkey('ctrl', 'down')

    time.sleep(3)

Oh. Okay Sir. But I can’t check it out because my API access has been blocked. Anyways I will try this and confirm whether it works or not. Thank you Sir.