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.