Category Archives: Python

Controlling Brightness of Arduino LED Remotely Using PyQt and WiFi

In this lesson we will use PyQt5, UDP and WiFi to control the brightness of an Arduino LED circuit remotely. The PyQt generates a constantly updating sin wave, which it plots on a PyQt graph, and then transfers the brightness in real time to the arduino project. This lesson teaches many important skills including UDP, WiFi, PyQt5, Python, Arduino and LEDs.

When using the breadvolt, or any battery power supply on a breadboard project, do not turn the power supply on while the Arduino is connected to USB, as you could generate voltage conflicts. It is an either or. If the USB is connected, the power supply should be OFF. The schematic for the arduino circuit is shown below:

Schematic of our Arduino Uno R4 Wifi connected to an RGB LED

In the video, we develop code for the server, on the arduino, and the client, running in Python on the desktop. We present the code below for your convenience.

This is the Server code for the Arduino:

You will need to open a new tab, and save the following code as “secrets.h” with the program above.

On the Python side, this is the Client code:

 

Plot Live Data in Python Using PyQt5

In this video lesson we show you how to plot live data in Python using PyQt5. In this lesson, we generate the data in python on the fly, but in future lessons we will bring the data in from the Arduino Project over WiFi using UDP. For your convenience, the code we developed in this lesson is below:

 

Use PyQt5 to Create a Graphical User Interface for Arduino Project Over WiFi


 

In this video lesson we introduce you to creating Graphical User Interfaces (GUI) to control your arduino project over WiFi using PyQt5. For this first introduction, we show you how to create the PyQt5 Widget on your PC using Python. Then your homework will be to control your arduino using the widget over WiFi. For your convenience, the code we developed in the lesson is presented below.

 

Improved Client Server Framework for Arduino

In this lesson, we show an improved framework for creating a Client/Server connection between your Arduino and your desktop PC over WiFi. This will serve as the basis for our WiFi projects moving forward.  On the arduino side, we have the following code to create the Server:

Remember, you must create a new tab, and include the following as your ‘secrets.h’ file

And then, on the Desktop side, this will be your python ‘Client’ code:

 

Parsing Comma Delimited Data Strings in Arduino

In this lesson we are working on a client server connection. The Arduino is the server, and a python program on a desktop PC is the client. The objective is to control the color of an RGB LED from the client. The client will send data to the server as comma delimited string, like 255,0,255 for RGB. The challenge on the server side is to parse this data so we get integer values of:

R=255

G=0

B=255

In this video lesson we start by simply controlling two LED, a red and green one, from the python client. We then show how we can control an RGB LED by sending the data string from the client, and parsing it on the server side. For your convenience, we include the code here:

Server Side code for the Arduino:

The code above needs a ‘secrets.h’ file which includes your WiFi name and password. This is created in the IDE by choosing ‘Add Tab’. Call the new tab ‘secrets.h’, and edit the code below to include your WiFi name and passwords inside the quotes:

Now, on the client side, this is our standard Python client:

With this code for creating a client and server, and then parsing comma delimited text, you can easily add the code needed to control the RGB LED color to the arduino program.