In this tutorial, we use Surilli GSM with both Arduino and Python to blink an LED ON or OFF by giving instructions from both.
STEP 1: Downloading PythonThe first step is to download the Python IDE from the official website. The installation procedure and steps mentioned in this project are relevant only for Windows 7 Operating System (might be similar to Windows 10). The setup procedure for Python on other operating systems like MAC OS and Linux will be different.The version of Python used in this tutorial is Python 2.7.14.
STEP 2: Installing Python on Your ComputerAfter downloading the installation file, proceed with installation by double clicking it. Select “Install for all users” and click on next. Do not change the default installation directory, which is “C:\Python27\” and click on next.
Next, select the “Add python.exe to path” option in the Customize Python 2.7.14 area. This will automatically add the Python directory to the Windows System Path. If you skip this step, you can add the directory to the path manually. Proceed and finish the installation.
Python is successfully installed on your computer. If you have set the system path (either manually or while installing path), you can check if the Python is successfully installed or not.
For this, run the Command Prompt with Administrator rights and just enter “python”. If python is successfully installed on your computer, you will get a response corresponding to the Python Version and type of installation.
At this point, you can start using the Python IDE by searching for “Python” in the Start Menu. You will get IDLE (Python GUI) option. IDLE stands for Integrated Development and Learning Environment, a GUI based Python IDE.
Selecting it will open the Python Shell, which lets you use the Python interpreter in an interactive mode i.e. you can type commands and see the results instantaneously.
Getting pySerial
In order to access the Serial Port of the Computer through Python, we are going to need a library called pySerial. pySerial is a Python Serial Port Extension that provides access to the Serial Port for Python running on different Operating Systems like Windows, Linux, Mac OS (OSX), etc.
In order to download the pySerial, use the attached link.
This link will download pySerial-3.4.
Extract the contents of the file to any folder like “C:\pyserial-3.4”.
NOTE: Location is important, as we have to navigate to this location and install the pySerial.
Now, run the Windows Command Prompt with Administrator privileges and navigate to the folder where pySerial is extracted to.
In order to install pySerial, type the following command in the command prompt and hit enter.
Python setup.py install
After successful installation of pySerial, you can check if it is integrated to Python or not by entering the following command in the Python IDLE.
Import serial
If everything goes well, you will not get any error.
Components Required- Surilli GSM
- Connecting wires
- LED
- 1 resistor
Make sure you have selected the right port, board and processor for the Surilli as shown in the picture below and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
The CircuitryThe circuitry is very simple. It's mostly the programming. Follow the figure below to set up your hardware.
Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload by first closing Python. After it is uploaded, open Python, enter the COM Port No from the Arduino that you have selected and run the following code below. Observe the results.
Arduino Code:
void setup() {
Serial.begin(9600); //initialize serial COM at 9600 baudrate
pinMode(13, OUTPUT); //declare the LED pin (13) as output
}
void loop() {
if (Serial.available()) //whatever the data that is coming in serially and assigning the value to the variable “data”
{
switch(Serial.read())
{
case '0': digitalWrite(13, LOW);
break;
case '1': digitalWrite(13, HIGH);
break;
default: break;
}
}
}
Python Code:
import serial
ser = serial.Serial('COM', 9600)
while 1:
val = raw_input("Enter 0 or 1 to control LED: \n");
if (val == '1'):
print("LED ON")
ser.write(val)
if (val == '0'):
print("LED OFF")
ser.write(val)
Play with the program to see how it reacts to different values and logic.
If you make something fun and interesting, do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with the Surilli family for more amazing stuff. :-)



_cME2BjKvY0.png?auto=compress%2Cformat&w=900&h=675&fit=min)









Comments