In this tutorial, we use Surilli WiFi with 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 WiFi
- 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 Circuitry:The circuitry is very simple. It's mostly the programming. Follow the figure below to set up your hardware.
Upload and Burn Code Onto Surilli:
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:
//const int led=1;
int value=0;
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
// digitalWrite (led, LOW);
Serial.println("Connection established...");
}
void loop()
{
while (Serial.available())
{
value = Serial.read();
}
if (value == '1')
digitalWrite (2, HIGH);
else if (value == '0')
digitalWrite (2, LOW);
}
Python Code:
import serial # add Serial library for Serial communication
Arduino_Serial = serial.Serial('COM15',9600) #Create Serial port object called arduinoSerialData
print (Arduino_Serial.readline()) #read the serial data and print it as line
print ("Enter 1 to ON LED and 0 to OFF LED")
while 1: #infinite loop
input_data = int(input()) #waits until user enters data
print ("you entered", input_data) #prints the data for confirmation
if (input_data == 1): #if the entered data is 1
Arduino_Serial.write(b'1') #send 1 to arduino
print ("LED ON")
if (input_data == 0): #if the entered data is 0
Arduino_Serial.write(b'0') #send 0 to arduino
print ("LED OFF")
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. :-)



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









Comments