How to use GPIO pins as input and output on bolt

Hi,

Of the 4 GPIO pins how can I use one GPIO as input and the other three as output? If you can show be a java script for it that would be great.

I am new to java script so its kind of hard to understand how to implement digital Write, Read and Analog Read functions on javascript.

Thanks

Hi @mailtoaswinth,

Let me correct you there, the Bolt has 1 analog input, and 5 GPIOs.

To use a GPIO as an input simply configure it for monitoring in the hardware section of the product configuration.

To use any GPIO as an output, you can use the following code in the product code configurations.

    <!DOCTYPE html>

<html>

    <head>

        <title>Bolt IoT Platform</title>

        <script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js"></script>

        <script>

        setKey('{{ApiKey}}','{{Name}}');

        </script>

    </head>

    <body>

        <center>

        <button onclick="digitalWrite(0, 'HIGH');">ON</button>

        <button onclick="digitalWrite(0, 'LOW');">OFF</button>

        </center>

    </body>

</html>

You can have as many buttons in the code as you want.
The above code allows you control over pin 0, to control the other pin, just change the number β€˜0’ inside the digitalWrite function to the pin number that you want to control.

1 Like

Yup thanks for correcting me there. It took some time to crunch it out but now I understand.

So bolt cannot take any actions on its own, all the logic have to be implemented on the cloud. Say for example if I have to glow an LED when a push button is pressed. I have to check the input pin status using an API and then based on the result form API I have to use another API to toggle the status of the output pin right?

I am not much comfortable with javascript and HTML so I went with python and used the below code to blink an LED. (API key and ID have been edited)

import requests

import time

while True:

    r = requests.get('https://cloud.boltiot.com/remote/4749fe75-6c61-45f1-bee5-f9a6a1bd7103/digitalWrite?pin=0&state=HIGH&deviceName=BOLT11671968')

    time.sleep(1)

    r = requests.get('https://cloud.boltiot.com/remote/4749fe75-6c61-45f1-bee5-f9a6a1bd7103/digitalWrite?pin=0&state=LOW&deviceName=BOLT11671968')

    time.sleep(1)

    r.text

The program worked, but while I was enjoying my small victory I reached my API call limits of 200 and ended up being suspended for 6 hours.

bolt cannot take any actions on its own, all the logic have to be implemented on the cloud.

If the above stated statement is true then it can be considered as a drawback since I cannot interface much hardware on my bolt. So the GPIO, analog and PWM functions cannot be used much.

Also another drawback I could think of is, how would one implement sleep mode? It would great if we have one to use BOLT on coin cell or other battery powered applications. Sorry for deviating way out of the question just thought of sharing the info,

Anyway other than this I really enjoyed getting started with bolt and looking forward to built something cool.

Hi @mailtoaswinth,

Its great that you have put in the effort to go through our system and give us feedback regarding the Bolt IoT platform.

You should know that we also have a python library that you could use for making the API calls, though the API will still be rate limited.

Also, we would love it if you could go to the following topic and talk about what features you would like the Bolt IoT platform to have.

This feedback would greatly help us prioritize the features that we are planning to deploy.

Also, we would love it if you could go to the following topic and talk about what features you would like the Bolt IoT platform to have.

Sure will do, I am not yet done playing with wit this module. Once I explore the corners I would put then all in on thread

Thanks,
Aswinth

1 Like

I agree with you. Thanks for sharing such a great solution.

Sir,I want to create current monitoring system.
I have connected the circuit as shown below.
It is displaying 1024 instead of 0.1Ampere.
Code:I have written the code as shown in Second figure below:

Please rectify it Sir


Hardware connection